CustomScpExplorer.cpp 342 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489
  1. //---------------------------------------------------------------------------
  2. #define NO_WIN32_LEAN_AND_MEAN
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <Common.h>
  6. #include "CustomScpExplorer.h"
  7. #include <Bookmarks.h>
  8. #include <Interface.h>
  9. #include <Exceptions.h>
  10. #include <CoreMain.h>
  11. #include <FileSystems.h>
  12. #include <TextsCore.h>
  13. #include <TextsWin.h>
  14. #include <HelpWin.h>
  15. #include <VCLCommon.h>
  16. #include <Progress.h>
  17. #include <SynchronizeProgress.h>
  18. #include <DragExt.h>
  19. #include <WinApi.h>
  20. #include "GUITools.h"
  21. #include "NonVisual.h"
  22. #include "Glyphs.h"
  23. #include "Tools.h"
  24. #include "WinConfiguration.h"
  25. #include "TerminalManager.h"
  26. #include "EditorManager.h"
  27. #include "ProgParams.h"
  28. #include "Setup.h"
  29. #include <Consts.hpp>
  30. #include <DateUtils.hpp>
  31. #include <TB2Common.hpp>
  32. #include <DirectoryMonitor.hpp>
  33. //---------------------------------------------------------------------------
  34. #pragma package(smart_init)
  35. #pragma link "CustomDirView"
  36. #pragma link "CustomUnixDirView"
  37. #pragma link "IEListView"
  38. #pragma link "NortonLikeListView"
  39. #pragma link "UnixDirView"
  40. #pragma link "CustomDriveView"
  41. #pragma link "UnixDriveView"
  42. #pragma link "CustomDriveView"
  43. #pragma link "TB2Dock"
  44. #pragma link "TBXStatusBars"
  45. #pragma link "TB2Item"
  46. #pragma link "TB2Toolbar"
  47. #pragma link "ThemePageControl"
  48. #pragma link "PathLabel"
  49. #ifndef NO_RESOURCES
  50. #pragma resource "*.dfm"
  51. #endif
  52. //---------------------------------------------------------------------------
  53. #define SAVE_SELECTION(DIRVIEW) \
  54. UnicodeString FocusFile = L""; \
  55. UnicodeString LastFocusedFile = L""; \
  56. if (DIRVIEW->ItemFocused) LastFocusedFile = DIRVIEW->ItemFocused->Caption; \
  57. { TListItem * ClosestUnselected = DIRVIEW->ClosestUnselected(DIRVIEW->ItemFocused); \
  58. if (ClosestUnselected) FocusFile = ClosestUnselected->Caption; }
  59. #define RESTORE_SELECTION(DIRVIEW) \
  60. if (!LastFocusedFile.IsEmpty() && \
  61. (!DIRVIEW->ItemFocused || (DIRVIEW->ItemFocused->Caption != LastFocusedFile))) \
  62. { \
  63. TListItem *ItemToSelect = DIRVIEW->FindFileItem(FocusFile); \
  64. if (ItemToSelect) \
  65. { \
  66. DIRVIEW->ItemFocused = ItemToSelect; \
  67. DIRVIEW->ItemFocused->MakeVisible(False); \
  68. } \
  69. }
  70. //---------------------------------------------------------------------------
  71. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  72. static const int SessionPanelCount = 4;
  73. //---------------------------------------------------------------------------
  74. class TMutexGuard
  75. {
  76. public:
  77. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  78. int Timeout = 5000)
  79. {
  80. FMutex = NULL;
  81. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  82. if (WaitResult == WAIT_TIMEOUT)
  83. {
  84. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  85. }
  86. else
  87. {
  88. FMutex = AMutex;
  89. }
  90. }
  91. ~TMutexGuard()
  92. {
  93. if (FMutex != NULL)
  94. {
  95. ReleaseMutex(FMutex);
  96. }
  97. }
  98. private:
  99. HANDLE FMutex;
  100. };
  101. //---------------------------------------------------------------------------
  102. class TWindowLock
  103. {
  104. public:
  105. TWindowLock(TCustomScpExplorerForm * Form) :
  106. FForm(Form)
  107. {
  108. FForm->LockWindow();
  109. }
  110. ~TWindowLock()
  111. {
  112. FForm->UnlockWindow();
  113. }
  114. private:
  115. TCustomScpExplorerForm * FForm;
  116. };
  117. //---------------------------------------------------------------------------
  118. class TAutoBatch
  119. {
  120. public:
  121. TAutoBatch(TCustomScpExplorerForm * Form) :
  122. FForm(Form)
  123. {
  124. FForm->BatchStart(FBatchStorage);
  125. }
  126. ~TAutoBatch()
  127. {
  128. FForm->BatchEnd(FBatchStorage);
  129. }
  130. private:
  131. TCustomScpExplorerForm * FForm;
  132. void * FBatchStorage;
  133. };
  134. //---------------------------------------------------------------------------
  135. struct TTransferOperationParam
  136. {
  137. TTransferOperationParam();
  138. UnicodeString TargetDirectory;
  139. bool Temp;
  140. bool DragDrop;
  141. int Options;
  142. TAutoSwitch Queue;
  143. };
  144. //---------------------------------------------------------------------------
  145. TTransferOperationParam::TTransferOperationParam()
  146. {
  147. Temp = false;
  148. DragDrop = false;
  149. Options = 0;
  150. Queue = asAuto;
  151. }
  152. //---------------------------------------------------------------------------
  153. class TTransferPresetNoteData : public TObject
  154. {
  155. public:
  156. UnicodeString Message;
  157. };
  158. //---------------------------------------------------------------------------
  159. class TTerminalNoteData : public TObject
  160. {
  161. public:
  162. TTerminal * Terminal;
  163. };
  164. //---------------------------------------------------------------------------
  165. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  166. FFormRestored(false),
  167. TForm(Owner)
  168. {
  169. FCurrentSide = osRemote;
  170. FEverShown = false;
  171. FDocks = new TList();
  172. RestoreParams();
  173. ConfigurationChanged();
  174. RemoteDirView->Invalidate();
  175. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  176. NonVisualDataModule->ScpExplorer = this;
  177. FAutoOperation = false;
  178. FOnFileOperationFinished = NULL;
  179. FForceExecution = false;
  180. FIgnoreNextDialogChar = 0;
  181. FErrorList = NULL;
  182. FSynchronizeProgressForm = NULL;
  183. FProgressForm = NULL;
  184. FRefreshLocalDirectory = false;
  185. FRefreshRemoteDirectory = false;
  186. FDDExtMapFile = NULL;
  187. // CreateMutexW keeps failing with ERROR_NOACCESS
  188. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  189. DebugAssert(FDDExtMutex != NULL);
  190. FDDTargetControl = NULL;
  191. FDelayedDeletionTimer = NULL;
  192. FDelayedDeletionList = new TStringList();
  193. FDDFileList = NULL;
  194. FPendingTempSpaceWarn = false;
  195. FCapturedLog = NULL;
  196. FDragDropOperation = false;
  197. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  198. FAllowTransferPresetAutoSelect = true;
  199. FCopyParamDefault = L"";
  200. FSynchronizeController = NULL;
  201. FPendingQueueActionItem = NULL;
  202. FLockLevel = 0;
  203. FLockSuspendLevel = 0;
  204. FDisabledOnLockSuspend = false;
  205. FAlternativeDelete = false;
  206. FTrayIcon = new ::TTrayIcon(0);
  207. FTrayIcon->OnClick = TrayIconClick;
  208. FMaxQueueLength = 0;
  209. FLastContextPopupScreenPoint = TPoint(-1, -1);
  210. FTransferResumeList = NULL;
  211. FMoveToQueue = false;
  212. FStandaloneEditing = false;
  213. FOnFeedSynchronizeError = NULL;
  214. FNeedSession = false;
  215. FDoNotIdleCurrentTerminal = 0;
  216. FIncrementalSearching = 0;
  217. FIncrementalSearchHaveNext = false;
  218. FEditorManager = new TEditorManager();
  219. FEditorManager->OnFileChange = ExecutedFileChanged;
  220. FEditorManager->OnFileReload = ExecutedFileReload;
  221. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  222. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  223. FLocalEditors = new TList();
  224. FQueueStatus = NULL;
  225. FQueueStatusSection = new TCriticalSection();
  226. FQueueStatusInvalidated = false;
  227. FQueueItemInvalidated = false;
  228. FQueueActedItem = NULL;
  229. FQueueController = new TQueueController(QueueView3);
  230. FUserActionTimer = new TTimer(this);
  231. FUserActionTimer->Enabled = false;
  232. FUserActionTimer->Interval = 10;
  233. FUserActionTimer->OnTimer = UserActionTimer;
  234. FNotes = new TStringList();
  235. FNoteTimer = new TTimer(this);
  236. FNoteTimer->Enabled = false;
  237. FNoteTimer->OnTimer = NoteTimer;
  238. FOnNoteClick = NULL;
  239. FOle32Library = LoadLibrary(L"Ole32.dll");
  240. FDragMoveCursor = FOle32Library != NULL ?
  241. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  242. UseSystemSettings(this);
  243. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  244. static_cast<TObject*>(GetComponent(fcTransferList)));
  245. DebugAssert(TransferList != NULL);
  246. FTransferListHoverIndex = -1;
  247. TransferList->OnChange = TransferListChange;
  248. TransferList->OnDrawItem = TransferListDrawItem;
  249. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  250. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  251. UseDesktopFont(SessionsPageControl);
  252. UpdateSessionsPageControlHeight();
  253. UseDesktopFont(RemoteDirView);
  254. UseDesktopFont(RemoteDriveView);
  255. UseDesktopFont(QueueView3);
  256. UseDesktopFont(QueueLabel);
  257. UseDesktopFont(RemoteStatusBar);
  258. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  259. QueueSplitter->ShowHint = true;
  260. RemotePanelSplitter->ShowHint = true;
  261. UpdateImages();
  262. FCustomCommandMenu = CreateTBXPopupMenu(this);
  263. FCustomCommandLocalFileList = NULL;
  264. FCustomCommandRemoteFileList = NULL;
  265. FSessionColors = new TPngImageList(this);
  266. FSessionColors->ColorDepth = cd32Bit;
  267. AddFixedSessionImages();
  268. SessionsPageControl->Images = FSessionColors;
  269. QueueLabel->FocusControl = QueueView3;
  270. UpdateQueueLabel();
  271. FRemoteDirViewWasFocused = true;
  272. CreateHiddenWindow();
  273. StartUpdates();
  274. }
  275. //---------------------------------------------------------------------------
  276. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  277. {
  278. // this has to be one of the very first things to do
  279. StopUpdateThread();
  280. delete FCustomCommandLocalFileList;
  281. delete FCustomCommandRemoteFileList;
  282. delete FCustomCommandMenu;
  283. delete FTrayIcon;
  284. FTrayIcon = NULL;
  285. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  286. delete FEditorManager;
  287. ForceCloseLocalEditors();
  288. delete FLocalEditors;
  289. HideFileFindDialog();
  290. if (FDelayedDeletionTimer)
  291. {
  292. DoDelayedDeletion(NULL);
  293. SAFE_DESTROY(FDelayedDeletionTimer);
  294. }
  295. SAFE_DESTROY(FDelayedDeletionList);
  296. // sometimes we do not get DDEnd so the list is not released
  297. SAFE_DESTROY(FDDFileList);
  298. DebugAssert(FSynchronizeController == NULL);
  299. CloseHandle(FDDExtMutex);
  300. FDDExtMutex = NULL;
  301. FreeLibrary(FOle32Library);
  302. FOle32Library = NULL;
  303. FDragMoveCursor = NULL;
  304. DebugAssert(!FErrorList);
  305. if (FEverShown)
  306. {
  307. // when window is never shown (like when running command-line operation),
  308. // particularly window site is not restored correctly (BoundsRect value set
  309. // in RestoreForm gets lost during handle allocation), so we do not want
  310. // it to be stored
  311. StoreParams();
  312. }
  313. Terminal = NULL;
  314. Queue = NULL;
  315. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  316. NonVisualDataModule->ScpExplorer = NULL;
  317. delete FQueueController;
  318. FQueueController = NULL;
  319. delete FQueueStatusSection;
  320. FQueueStatusSection = NULL;
  321. delete FQueueStatus;
  322. FQueueStatus = NULL;
  323. delete FUserActionTimer;
  324. FUserActionTimer = NULL;
  325. delete FNoteTimer;
  326. delete FNotes;
  327. delete FNoteData;
  328. SAFE_DESTROY(FDocks);
  329. SessionsPageControl->Images = NULL;
  330. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  331. SAFE_DESTROY(FSessionColors);
  332. SAFE_DESTROY(FSessionsDragDropFilesEx);
  333. SAFE_DESTROY(FHistoryMenu[0][0]);
  334. SAFE_DESTROY(FHistoryMenu[0][1]);
  335. SAFE_DESTROY(FHistoryMenu[1][0]);
  336. SAFE_DESTROY(FHistoryMenu[1][1]);
  337. if (FHiddenWindow != NULL)
  338. {
  339. DestroyWindow(FHiddenWindow);
  340. FHiddenWindow = NULL;
  341. }
  342. }
  343. //---------------------------------------------------------------------------
  344. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  345. {
  346. std::unique_ptr<TSessionData> Data;
  347. if (!Session.IsEmpty())
  348. {
  349. bool DefaultsOnly;
  350. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  351. }
  352. TTerminalManager * Manager = TTerminalManager::Instance();
  353. for (int Index = 0; Index < Manager->Count; Index++)
  354. {
  355. TTerminal * Terminal = Manager->Terminals[Index];
  356. if (Session.IsEmpty() ||
  357. Terminal->SessionData->IsSameSite(Data.get()))
  358. {
  359. if (Path.IsEmpty())
  360. {
  361. Terminal->ClearCaches();
  362. }
  363. else
  364. {
  365. Terminal->DirectoryModified(Path, true);
  366. }
  367. }
  368. }
  369. // We should flag a pending refresh for the background terminals or busy foreground terminals
  370. if ((Terminal != NULL) && Terminal->Active &&
  371. CanCommandLineFromAnotherInstance() &&
  372. (Session.IsEmpty() || Terminal->SessionData->IsSameSite(Data.get())) &&
  373. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  374. {
  375. Terminal->ReloadDirectory();
  376. }
  377. }
  378. //---------------------------------------------------------------------------
  379. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  380. {
  381. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  382. size_t MessageSize = sizeof(TCopyDataMessage);
  383. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  384. if (Result)
  385. {
  386. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  387. Result = (Message.Version == TCopyDataMessage::Version1);
  388. if (Result)
  389. {
  390. switch (Message.Command)
  391. {
  392. case TCopyDataMessage::CommandCanCommandLine:
  393. Result = CanCommandLineFromAnotherInstance();
  394. break;
  395. case TCopyDataMessage::CommandCommandLine:
  396. {
  397. UnicodeString CommandLine(Message.CommandLine);
  398. Result = CommandLineFromAnotherInstance(CommandLine);
  399. }
  400. break;
  401. case TCopyDataMessage::RefreshPanel:
  402. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  403. break;
  404. case TCopyDataMessage::MainWindowCheck:
  405. Result = true;
  406. break;
  407. default:
  408. Result = false;
  409. break;
  410. }
  411. }
  412. }
  413. Message.Result = Result ? 1 : 0;
  414. }
  415. //---------------------------------------------------------------------------
  416. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  417. {
  418. WNDCLASS WindowClass = {0};
  419. WindowClass.lpfnWndProc = DefWindowProc;
  420. WindowClass.hInstance = HInstance;
  421. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  422. FHiddenWindow = NULL;
  423. if (RegisterClass(&WindowClass))
  424. {
  425. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  426. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  427. }
  428. }
  429. //---------------------------------------------------------------------------
  430. bool __fastcall TCustomScpExplorerForm::CanConsole()
  431. {
  432. return
  433. (Terminal != NULL) &&
  434. Terminal->Active &&
  435. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  436. }
  437. //---------------------------------------------------------------------------
  438. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  439. {
  440. bool Result = Visible && !NonVisualDataModule->Busy;
  441. return Result;
  442. }
  443. //---------------------------------------------------------------------------
  444. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  445. const UnicodeString & CommandLine)
  446. {
  447. TProgramParams Params(CommandLine);
  448. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  449. if (Result)
  450. {
  451. NonVisualDataModule->StartBusy();
  452. try
  453. {
  454. // this action is initiated from another process,
  455. // so it's likely that our window is not visible,
  456. // and user won't see what is going on
  457. Application->BringToFront();
  458. // reload sessions as we may be asked to open a session
  459. // just stored by another instance
  460. StoredSessions->Reload();
  461. UnicodeString SessionName = Params.Param[1];
  462. std::unique_ptr<TObjectList> DataList(new TObjectList());
  463. UnicodeString DownloadFile; // unused
  464. try
  465. {
  466. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  467. }
  468. catch (EAbort &)
  469. {
  470. // Happens when opening session in PuTTY and in other situations,
  471. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  472. // to process the command-line on its own (or to pass it to yet another instance)
  473. }
  474. if (DataList->Count > 0)
  475. {
  476. TTerminalManager * Manager = TTerminalManager::Instance();
  477. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  478. }
  479. }
  480. __finally
  481. {
  482. NonVisualDataModule->EndBusy();
  483. }
  484. }
  485. return Result;
  486. }
  487. //---------------------------------------------------------------------------
  488. void __fastcall TCustomScpExplorerForm::SetTerminal(TTerminal * value)
  489. {
  490. if (FTerminal != value)
  491. {
  492. TerminalChanging();
  493. DoSetTerminal(value, false);
  494. }
  495. }
  496. //---------------------------------------------------------------------------
  497. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TTerminal * value, bool Replace)
  498. {
  499. FTerminal = value;
  500. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  501. FAllowTransferPresetAutoSelect = false;
  502. try
  503. {
  504. TerminalChanged(Replace);
  505. }
  506. __finally
  507. {
  508. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  509. }
  510. if (Terminal != NULL)
  511. {
  512. TransferPresetAutoSelect();
  513. }
  514. }
  515. //---------------------------------------------------------------------------
  516. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TTerminal * value)
  517. {
  518. DoSetTerminal(value, true);
  519. }
  520. //---------------------------------------------------------------------------
  521. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  522. {
  523. if (FTerminal != NULL)
  524. {
  525. UpdateTerminal(Terminal);
  526. }
  527. }
  528. //---------------------------------------------------------------------------
  529. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  530. {
  531. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  532. if (ManagedTerminal != NULL)
  533. {
  534. UpdateSessionColor((TColor)ManagedTerminal->StateData->Color);
  535. }
  536. DoTerminalListChanged();
  537. if (Replaced)
  538. {
  539. RemoteDirView->ReplaceTerminal(Terminal);
  540. }
  541. else
  542. {
  543. RemoteDirView->Terminal = Terminal;
  544. }
  545. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  546. if (Terminal != NULL)
  547. {
  548. if (Terminal->Active)
  549. {
  550. Terminal->RefreshDirectory();
  551. }
  552. DebugAssert(ManagedTerminal == Terminal);
  553. if (WinConfiguration->PreservePanelState)
  554. {
  555. if (ManagedTerminal->RemoteExplorerState != NULL)
  556. {
  557. RemoteDirView->RestoreState(ManagedTerminal->RemoteExplorerState);
  558. }
  559. else
  560. {
  561. RemoteDirView->ClearState();
  562. }
  563. }
  564. if (!Replaced)
  565. {
  566. InitStatusBar();
  567. }
  568. }
  569. UpdateTransferList();
  570. // Update panels Enable state before refreshing the labels
  571. UpdateControls();
  572. }
  573. //---------------------------------------------------------------------------
  574. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  575. {
  576. if (Queue != value)
  577. {
  578. if (FQueue != NULL)
  579. {
  580. FQueue->OnListUpdate = NULL;
  581. FQueue->OnQueueItemUpdate = NULL;
  582. }
  583. FQueue = value;
  584. if (FQueue != NULL)
  585. {
  586. DebugAssert(FQueue->OnListUpdate == NULL);
  587. FQueue->OnListUpdate = QueueListUpdate;
  588. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  589. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  590. }
  591. QueueChanged();
  592. }
  593. }
  594. //---------------------------------------------------------------------------
  595. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  596. TListItem * Item)
  597. {
  598. if (FQueueActedItem == Item)
  599. {
  600. FQueueActedItem = NULL;
  601. if ((QueueView3->PopupMenu != NULL) &&
  602. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  603. {
  604. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  605. ReleaseCapture();
  606. }
  607. }
  608. if (Item->Data == FPendingQueueActionItem)
  609. {
  610. FPendingQueueActionItem = NULL;
  611. }
  612. }
  613. //---------------------------------------------------------------------------
  614. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  615. {
  616. {
  617. TGuard Guard(FQueueStatusSection);
  618. FQueueStatusInvalidated = false;
  619. if (FQueue != NULL)
  620. {
  621. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  622. }
  623. }
  624. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  625. {
  626. FMaxQueueLength = FQueueStatus->Count;
  627. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  628. }
  629. FQueueController->UpdateQueueStatus(FQueueStatus);
  630. SetQueueProgress();
  631. UpdateQueueView();
  632. bool IsEmpty = (FQueueStatus == NULL) || (FQueueStatus->Count == 0);
  633. if (IsEmpty && (Terminal != NULL))
  634. {
  635. TOnceDoneOperation OnceDoneOperation =
  636. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  637. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  638. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  639. {
  640. FQueue->Enabled = false;
  641. }
  642. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  643. {
  644. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  645. }
  646. }
  647. }
  648. //---------------------------------------------------------------------------
  649. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  650. {
  651. UnicodeString Result;
  652. if (FQueueStatus != NULL)
  653. {
  654. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  655. {
  656. TFileOperationProgressType * ProgressData =
  657. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  658. if ((ProgressData != NULL) && ProgressData->InProgress)
  659. {
  660. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  661. }
  662. }
  663. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  664. {
  665. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  666. }
  667. }
  668. return Result;
  669. }
  670. //---------------------------------------------------------------------------
  671. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  672. {
  673. ComponentVisible[fcQueueView] =
  674. (WinConfiguration->QueueView.Show == qvShow) ||
  675. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  676. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  677. }
  678. //---------------------------------------------------------------------------
  679. void __fastcall TCustomScpExplorerForm::QueueChanged()
  680. {
  681. if (FQueueStatus != NULL)
  682. {
  683. delete FQueueStatus;
  684. FQueueStatus = NULL;
  685. }
  686. UpdateQueueStatus(true);
  687. }
  688. //---------------------------------------------------------------------------
  689. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  690. {
  691. if (FQueue == Queue)
  692. {
  693. FQueueStatusInvalidated = true;
  694. }
  695. }
  696. //---------------------------------------------------------------------------
  697. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  698. TQueueItem * Item)
  699. {
  700. if (FQueue == Queue)
  701. {
  702. TGuard Guard(FQueueStatusSection);
  703. // this may be running in parallel with QueueChanged
  704. if (FQueueStatus != NULL)
  705. {
  706. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  707. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  708. {
  709. FRefreshLocalDirectory = (QueueItem == NULL) ||
  710. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  711. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  712. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  713. }
  714. if (QueueItem != NULL)
  715. {
  716. QueueItem->UserData = (void*)true;
  717. FQueueItemInvalidated = true;
  718. }
  719. }
  720. }
  721. }
  722. //---------------------------------------------------------------------------
  723. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  724. {
  725. // during standalone editing, we have no way to see/control queue,
  726. // so we have to always popup prompts automatically
  727. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  728. }
  729. //---------------------------------------------------------------------------
  730. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  731. {
  732. if (FQueueStatus != NULL)
  733. {
  734. bool QueueAutoPopup = IsQueueAutoPopup();
  735. bool NeedRefresh = FQueueController->NeedRefresh();
  736. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  737. FQueueItemInvalidated = false;
  738. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  739. bool Updated = false;
  740. TQueueItemProxy * QueueItem;
  741. bool WasUserAction;
  742. for (int Index = 0; Index < Limit; Index++)
  743. {
  744. bool Update = false;
  745. QueueItem = FQueueStatus->Items[Index];
  746. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  747. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  748. (FPendingQueueActionItem == NULL))
  749. {
  750. FPendingQueueActionItem = QueueItem;
  751. FUserActionTimer->Enabled = true;
  752. }
  753. if ((bool)QueueItem->UserData)
  754. {
  755. QueueItem->UserData = (void*)false;
  756. QueueItem->Update();
  757. Updated = true;
  758. Update = true;
  759. }
  760. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  761. {
  762. Update = true;
  763. }
  764. if (Update)
  765. {
  766. FQueueController->RefreshQueueItem(QueueItem);
  767. }
  768. }
  769. if (Updated)
  770. {
  771. NonVisualDataModule->UpdateNonVisibleActions();
  772. SetQueueProgress();
  773. }
  774. }
  775. }
  776. //---------------------------------------------------------------------------
  777. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  778. {
  779. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  780. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  781. }
  782. //---------------------------------------------------------------------------
  783. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  784. {
  785. if (ProgressData->Operation != foCalculateSize)
  786. {
  787. int OverallProgress;
  788. // FProgressForm is null when this is called from SetQueueProgress
  789. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  790. {
  791. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  792. }
  793. else
  794. {
  795. OverallProgress = ProgressData->OverallProgress();
  796. }
  797. // implies TBPF_NORMAL
  798. FTaskbarList->SetProgressValue(GetMainForm()->Handle, OverallProgress, 100);
  799. }
  800. else
  801. {
  802. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  803. }
  804. }
  805. //---------------------------------------------------------------------------
  806. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  807. {
  808. TTerminalManager::Instance()->QueueStatusUpdated();
  809. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  810. {
  811. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  812. {
  813. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  814. {
  815. TFileOperationProgressType * ProgressData = NULL;
  816. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  817. {
  818. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  819. }
  820. if ((ProgressData != NULL) &&
  821. ProgressData->InProgress)
  822. {
  823. SetTaskbarListProgressValue(ProgressData);
  824. }
  825. else
  826. {
  827. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  828. }
  829. }
  830. else
  831. {
  832. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  833. }
  834. }
  835. else
  836. {
  837. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  838. }
  839. }
  840. UpdateQueueLabel();
  841. }
  842. //---------------------------------------------------------------------------
  843. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  844. {
  845. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  846. if (FQueueStatus != NULL)
  847. {
  848. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  849. if (ActiveAndPendingPrimaryCount > 0)
  850. {
  851. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  852. }
  853. }
  854. QueueLabel->Caption = Caption;
  855. }
  856. //---------------------------------------------------------------------------
  857. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  858. {
  859. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  860. static_cast<TComponent*>(GetComponent(fcTransferList)));
  861. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  862. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  863. TransferList->Strings->BeginUpdate();
  864. try
  865. {
  866. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  867. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  868. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  869. if (FTransferDropDownHint.IsEmpty())
  870. {
  871. FTransferDropDownHint = TransferDropDown->Hint;
  872. }
  873. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  874. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  875. TransferDropDown->Text = StripHotkey(Name);
  876. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  877. (FTransferDropDownHint, StripHotkey(Name),
  878. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  879. FLAGMASK(((Terminal != NULL) && Terminal->Active), Terminal->UsableCopyParamAttrs(0).General))));
  880. // update the label, otherwise when it is updated only on the first draw
  881. // of the list, it is drawn "bold" for some reason
  882. FTransferListHoverIndex = TransferList->ItemIndex;
  883. UpdateTransferLabel();
  884. }
  885. __finally
  886. {
  887. TransferList->Strings->EndUpdate();
  888. }
  889. }
  890. //---------------------------------------------------------------------------
  891. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  892. {
  893. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  894. DebugAssert(Toolbar != NULL);
  895. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  896. }
  897. //---------------------------------------------------------------------------
  898. void __fastcall TCustomScpExplorerForm::UpdateActions()
  899. {
  900. TForm::UpdateActions();
  901. if (ComponentVisible[fcCustomCommandsBand])
  902. {
  903. UpdateCustomCommandsToolbar();
  904. }
  905. }
  906. //---------------------------------------------------------------------------
  907. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  908. {
  909. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  910. }
  911. //---------------------------------------------------------------------------
  912. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  913. {
  914. Color = GetBtnFaceColor();
  915. DebugAssert(Configuration && RemoteDirView);
  916. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  917. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  918. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  919. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  920. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  921. if (RemoteDirView->RowSelect != WinConfiguration->FullRowSelect)
  922. {
  923. RemoteDirView->RowSelect = WinConfiguration->FullRowSelect;
  924. // selection is not redrawn automatically when RowSelect changes
  925. RemoteDirView->Invalidate();
  926. }
  927. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  928. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  929. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  930. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  931. UpdateSessionsPageControlHeight();
  932. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  933. UpdateToolbarDisplayMode();
  934. UpdateTransferList();
  935. if (Terminal != NULL)
  936. {
  937. TransferPresetAutoSelect();
  938. }
  939. UpdateQueueView();
  940. UpdateControls();
  941. // this can be called even before constuctor finishes.
  942. if (FEditorManager != NULL)
  943. {
  944. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  945. }
  946. // this can be called even before constuctor finishes.
  947. if (FLocalEditors != NULL)
  948. {
  949. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  950. {
  951. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  952. }
  953. }
  954. if (ComponentVisible[fcCustomCommandsBand])
  955. {
  956. UpdateCustomCommandsToolbar();
  957. }
  958. // show only when keeping queue items forever,
  959. // otherwise, its enough to have in in the context menu
  960. QueueDeleteAllDoneQueueToolbarItem->Visible =
  961. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  962. if (FFileColorsCurrent != WinConfiguration->FileColors)
  963. {
  964. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  965. FFileColorsCurrent = WinConfiguration->FileColors;
  966. FileColorsChanged();
  967. }
  968. }
  969. //---------------------------------------------------------------------------
  970. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  971. {
  972. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  973. DirView->Invalidate();
  974. }
  975. //---------------------------------------------------------------------------
  976. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  977. {
  978. DoFileColorsChanged(RemoteDirView);
  979. }
  980. //---------------------------------------------------------------------------
  981. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  982. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  983. void * /*Arg*/)
  984. {
  985. if (Token != NULL)
  986. {
  987. TForm * Editor = dynamic_cast<TForm*>(Token);
  988. DebugAssert(Editor != NULL);
  989. ReconfigureEditorForm(Editor);
  990. }
  991. }
  992. //---------------------------------------------------------------------------
  993. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  994. {
  995. WinConfiguration->DDTransferConfirmation = asOn;
  996. }
  997. //---------------------------------------------------------------------------
  998. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  999. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1000. {
  1001. // noop
  1002. }
  1003. //---------------------------------------------------------------------------
  1004. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1005. TTransferDirection Direction, TTransferType Type, bool Temp,
  1006. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1007. bool Confirm, bool DragDrop, int Options)
  1008. {
  1009. bool Result = true;
  1010. DebugAssert(Terminal && Terminal->Active);
  1011. // these parameters are known in advance
  1012. int Params =
  1013. FLAGMASK(Type == ttMove, cpDelete);
  1014. bool ToTemp = (Temp && (Direction == tdToLocal));
  1015. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1016. {
  1017. bool DisableNewerOnly =
  1018. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1019. ToTemp;
  1020. Options |=
  1021. FLAGMASK(ToTemp, coTemp) |
  1022. FLAGMASK(!Terminal->IsCapable[fsBackgroundTransfers], coDisableQueue) |
  1023. coDoNotShowAgain;
  1024. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1025. int CopyParamAttrs = (Direction == tdToRemote ?
  1026. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1027. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1028. int OutputOptions =
  1029. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1030. cooDoNotShowAgain);
  1031. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1032. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1033. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1034. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions);
  1035. if (Result)
  1036. {
  1037. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1038. {
  1039. if (DragDrop)
  1040. {
  1041. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1042. {
  1043. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1044. NULL, 0, EnableDDTransferConfirmation, NULL);
  1045. }
  1046. WinConfiguration->DDTransferConfirmation = asOff;
  1047. }
  1048. else
  1049. {
  1050. WinConfiguration->ConfirmTransferring = false;
  1051. }
  1052. }
  1053. else
  1054. {
  1055. // User explicitly unchecked "do not show again",
  1056. // so show him the dialog the next time
  1057. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1058. {
  1059. WinConfiguration->DDTransferConfirmation = asOn;
  1060. }
  1061. }
  1062. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1063. }
  1064. }
  1065. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fsBackgroundTransfers])
  1066. {
  1067. Configuration->Usage->Inc(L"TransfersOnBackground");
  1068. // these parameter are known only after transfer dialog
  1069. Params |=
  1070. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1071. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1072. Result = false;
  1073. ClearTransferSourceSelection(Direction);
  1074. }
  1075. return Result;
  1076. }
  1077. //---------------------------------------------------------------------------
  1078. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1079. {
  1080. if (FOnFileOperationFinished != NULL)
  1081. {
  1082. FOnFileOperationFinished(UnicodeString(), true);
  1083. }
  1084. else
  1085. {
  1086. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1087. if (HasDirView[Side])
  1088. {
  1089. DirView(Side)->SelectAll(smNone);
  1090. }
  1091. }
  1092. }
  1093. //---------------------------------------------------------------------------
  1094. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1095. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1096. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1097. int Params)
  1098. {
  1099. DebugAssert(Queue != NULL);
  1100. bool SingleFile = false;
  1101. if (FileList->Count == 1)
  1102. {
  1103. if (Direction == tdToRemote)
  1104. {
  1105. UnicodeString FileName = FileList->Strings[0];
  1106. SingleFile = FileExists(ApiPath(FileName));
  1107. }
  1108. else
  1109. {
  1110. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1111. SingleFile = !File->IsDirectory;
  1112. }
  1113. }
  1114. TQueueItem * QueueItem;
  1115. if (Direction == tdToRemote)
  1116. {
  1117. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1118. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1119. }
  1120. else
  1121. {
  1122. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1123. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1124. }
  1125. AddQueueItem(Queue, QueueItem, Terminal);
  1126. }
  1127. //---------------------------------------------------------------------------
  1128. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TTerminal * Terminal)
  1129. {
  1130. if (Queue->IsEmpty)
  1131. {
  1132. TManagedTerminal * ManagedTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  1133. ManagedTerminal->QueueOperationStart = Now();
  1134. }
  1135. Queue->AddItem(QueueItem);
  1136. }
  1137. //---------------------------------------------------------------------------
  1138. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1139. {
  1140. }
  1141. //---------------------------------------------------------------------------
  1142. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1143. {
  1144. DebugAssert(FDocks != NULL);
  1145. for (int Index = 0; Index < ComponentCount; Index++)
  1146. {
  1147. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1148. if ((Dock != NULL) && (Dock->Tag == 0))
  1149. {
  1150. FDocks->Add(Dock);
  1151. }
  1152. }
  1153. CollectItemsWithTextDisplayMode(this);
  1154. ConfigurationChanged();
  1155. QueuePanel->Height =
  1156. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1157. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1158. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1159. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1160. }
  1161. //---------------------------------------------------------------------------
  1162. void __fastcall TCustomScpExplorerForm::StoreParams()
  1163. {
  1164. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1165. WinConfiguration->QueueView.HeightPixelsPerInch = GetControlPixelsPerInch(this);
  1166. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1167. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1168. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1169. }
  1170. //---------------------------------------------------------------------------
  1171. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1172. {
  1173. if (!FFormRestored)
  1174. {
  1175. FFormRestored = true;
  1176. RestoreFormParams();
  1177. }
  1178. TForm::CreateParams(Params);
  1179. }
  1180. //---------------------------------------------------------------------------
  1181. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1182. {
  1183. DebugAssert(FDocks != NULL);
  1184. for (int Index = 0; Index < FDocks->Count; Index++)
  1185. {
  1186. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1187. }
  1188. }
  1189. //---------------------------------------------------------------------------
  1190. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1191. {
  1192. SetDockAllowDrag(true);
  1193. while (!ButtonsStr.IsEmpty())
  1194. {
  1195. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1196. UnicodeString Name = CutToChar(S, L'=', true);
  1197. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1198. {
  1199. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1200. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1201. {
  1202. while (!S.IsEmpty())
  1203. {
  1204. UnicodeString S2 = CutToChar(S, L',', true);
  1205. UnicodeString Name = CutToChar(S2, L':', true);
  1206. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1207. {
  1208. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1209. if (SameText(GetToolbarItemName(Item), Name))
  1210. {
  1211. // forward compatibility
  1212. UnicodeString S3 = CutToChar(S2, L':', true);
  1213. bool Visible = StrToIntDef(S3, 0);
  1214. Item->Visible = Visible;
  1215. }
  1216. }
  1217. }
  1218. }
  1219. }
  1220. }
  1221. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1222. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1223. }
  1224. //---------------------------------------------------------------------------
  1225. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1226. {
  1227. UnicodeString Result;
  1228. SetDockAllowDrag(true);
  1229. Result = ::GetToolbarsLayoutStr(this);
  1230. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1231. return Result;
  1232. }
  1233. //---------------------------------------------------------------------------
  1234. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1235. {
  1236. UnicodeString Result;
  1237. if (Item->Action != NULL)
  1238. {
  1239. Result = Item->Action->Name;
  1240. Result = RemoveSuffix(Result, L"Action");
  1241. }
  1242. else
  1243. {
  1244. Result = Item->Name;
  1245. Result = RemoveSuffix(Result, L"SubmenuItem");
  1246. Result = RemoveSuffix(Result, L"Item");
  1247. }
  1248. return Result;
  1249. }
  1250. //---------------------------------------------------------------------------
  1251. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1252. {
  1253. UnicodeString Result;
  1254. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1255. {
  1256. UnicodeString ToolbarStr;
  1257. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1258. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1259. {
  1260. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1261. {
  1262. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1263. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1264. // Once we introduce any buttons that aer hidden by default, we would have to remember their initial state
  1265. // and save the changes here only.
  1266. if (!Item->Visible)
  1267. {
  1268. UnicodeString Name = GetToolbarItemName(Item);
  1269. DebugAssert(Name.Pos(L"TBX") == 0);
  1270. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1271. }
  1272. }
  1273. }
  1274. if (!ToolbarStr.IsEmpty())
  1275. {
  1276. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1277. }
  1278. }
  1279. return Result;
  1280. }
  1281. //---------------------------------------------------------------------------
  1282. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1283. {
  1284. DebugAssert(FProgressForm == NULL);
  1285. FProgressForm =
  1286. new TProgressForm(Application, (FTransferResumeList != NULL), Terminal->IsCapable[fsSkipTransfer], SynchronizeProgress);
  1287. FProgressForm->DeleteLocalToRecycleBin =
  1288. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1289. FProgressForm->DeleteRemoteToRecycleBin =
  1290. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1291. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1292. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1293. LockWindow();
  1294. if (FTaskbarList != NULL)
  1295. {
  1296. // Actually, do not know what hides the progress once the operation finishes
  1297. SetTaskbarListProgressState(TBPF_NORMAL);
  1298. }
  1299. }
  1300. //---------------------------------------------------------------------------
  1301. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1302. {
  1303. UnlockWindow();
  1304. SAFE_DESTROY(FProgressForm);
  1305. SetQueueProgress();
  1306. }
  1307. //---------------------------------------------------------------------------
  1308. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1309. TFileOperationProgressType & ProgressData)
  1310. {
  1311. // Download to temporary local directory
  1312. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1313. {
  1314. bool Continue = true;
  1315. FPendingTempSpaceWarn = false;
  1316. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1317. if (!Continue)
  1318. {
  1319. Abort();
  1320. }
  1321. }
  1322. // operation is being executed and we still didn't show up progress form
  1323. if (ProgressData.InProgress && !FProgressForm)
  1324. {
  1325. CreateProgressForm(NULL);
  1326. // When main window is hidden, synchronisation form does not exist (we do not get here during synchronization - only comparing),
  1327. // we suppose "/upload" or URL download mode
  1328. if (!Visible && (ProgressData.Operation != foCalculateSize) &&
  1329. (ProgressData.Operation != foCalculateChecksum) &&
  1330. // Hack to prevent renames from DoSynchronizeMove (synchronize checklist) closing the connection
  1331. (ProgressData.Operation != foRemoteMove) &&
  1332. (FSynchronizeProgressForm == NULL) &&
  1333. !FStandaloneEditing)
  1334. {
  1335. FProgressForm->OnceDoneOperation = odoDisconnect;
  1336. }
  1337. }
  1338. // operation is finished (or terminated), so we hide progress form
  1339. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1340. {
  1341. DestroyProgressForm();
  1342. if (ProgressData.Operation == foCalculateSize)
  1343. {
  1344. // When calculating size before transfer, the abort caused by
  1345. // cancel flag set due to "MoveToQueue" below,
  1346. // is not propagated back to us in ExecuteFileOperation,
  1347. // as it is silently swallowed.
  1348. // So we explicitly (re)throw it here.
  1349. if (FMoveToQueue)
  1350. {
  1351. Abort();
  1352. }
  1353. }
  1354. else
  1355. {
  1356. if ((ProgressData.Cancel == csContinue) &&
  1357. !FAutoOperation)
  1358. {
  1359. OperationComplete(ProgressData.StartTime);
  1360. }
  1361. }
  1362. }
  1363. if (FProgressForm &&
  1364. // Can happen only during synchronization, when ending one of the operations
  1365. ProgressData.InProgress)
  1366. {
  1367. FProgressForm->SetProgressData(ProgressData);
  1368. if (FTaskbarList != NULL)
  1369. {
  1370. DebugAssert(ProgressData.InProgress);
  1371. SetTaskbarListProgressValue(&ProgressData);
  1372. }
  1373. if (FProgressForm->Cancel > csContinue)
  1374. {
  1375. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1376. if (FProgressForm->Cancel == csCancelFile)
  1377. {
  1378. FProgressForm->ClearCancel();
  1379. }
  1380. // cancel cancels even the move
  1381. FMoveToQueue = false;
  1382. }
  1383. else if (FProgressForm->MoveToQueue)
  1384. {
  1385. FMoveToQueue = true;
  1386. ProgressData.SetCancelAtLeast(csCancel);
  1387. }
  1388. if ((FTransferResumeList != NULL) &&
  1389. ProgressData.InProgress &&
  1390. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1391. !ProgressData.FullFileName.IsEmpty())
  1392. {
  1393. if ((FTransferResumeList->Count == 0) ||
  1394. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1395. {
  1396. // note that we do not recognize directories from files here
  1397. FTransferResumeList->Add(ProgressData.FullFileName);
  1398. }
  1399. }
  1400. }
  1401. }
  1402. //---------------------------------------------------------------------------
  1403. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1404. const TDateTime & StartTime)
  1405. {
  1406. if (GUIConfiguration->BeepOnFinish &&
  1407. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1408. {
  1409. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1410. DWORD Sound;
  1411. if (!ExtractFileExt(BeepSound).IsEmpty())
  1412. {
  1413. Sound = SND_FILENAME;
  1414. }
  1415. else
  1416. {
  1417. Sound = SND_ALIAS;
  1418. }
  1419. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1420. }
  1421. }
  1422. //---------------------------------------------------------------------------
  1423. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1424. TFileOperationProgressType & ProgressData)
  1425. {
  1426. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1427. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1428. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1429. FileOperationProgress(ProgressData);
  1430. }
  1431. //---------------------------------------------------------------------------
  1432. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1433. {
  1434. UnicodeString Result;
  1435. if (FProgressForm != NULL)
  1436. {
  1437. Result = FProgressForm->ProgressStr();
  1438. }
  1439. return Result;
  1440. }
  1441. //---------------------------------------------------------------------------
  1442. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1443. bool DragDrop)
  1444. {
  1445. return (!DragDrop && (DropSourceControl == NULL)) ||
  1446. (DropSourceControl == RemoteDirView);
  1447. }
  1448. //---------------------------------------------------------------------------
  1449. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1450. TFileOperation Operation, TOperationSide Side,
  1451. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1452. TOnceDoneOperation & OnceDoneOperation)
  1453. {
  1454. if (!FAutoOperation)
  1455. {
  1456. // no selection on "/upload", form servers only as event handler
  1457. // (it is not displayed)
  1458. if (PanelOperation(Side, FDragDropOperation) &&
  1459. Visible && (Operation != foCalculateSize) &&
  1460. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1461. {
  1462. if (FOnFileOperationFinished != NULL)
  1463. {
  1464. FOnFileOperationFinished(FileName, Success);
  1465. }
  1466. else
  1467. {
  1468. TCustomDirView * DView = DirView(Side);
  1469. UnicodeString FileNameOnly = ExtractFileName(FileName, (Side == osRemote));
  1470. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1471. // this can happen when local drive is unplugged in the middle of the operation
  1472. if (Item != NULL)
  1473. {
  1474. if (Success) Item->Selected = false;
  1475. DView->MakeProgressVisible(Item);
  1476. }
  1477. }
  1478. }
  1479. if ((Operation == foCopy) || (Operation == foMove))
  1480. {
  1481. if (Side == osLocal)
  1482. {
  1483. Configuration->Usage->Inc(L"UploadedFiles");
  1484. }
  1485. else
  1486. {
  1487. Configuration->Usage->Inc(L"DownloadedFiles");
  1488. }
  1489. }
  1490. }
  1491. if (Success && (FSynchronizeController != NULL))
  1492. {
  1493. if (Operation == foCopy)
  1494. {
  1495. DebugAssert(Side == osLocal);
  1496. FSynchronizeController->LogOperation(soUpload, FileName);
  1497. }
  1498. else if (Operation == foDelete)
  1499. {
  1500. DebugAssert(Side == osRemote);
  1501. FSynchronizeController->LogOperation(soDelete, FileName);
  1502. }
  1503. }
  1504. if (FProgressForm)
  1505. {
  1506. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1507. }
  1508. }
  1509. //---------------------------------------------------------------------------
  1510. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1511. TFileOperation Operation, TOperationSide Side,
  1512. bool Temp, const UnicodeString & FileName, Boolean Success,
  1513. TOnceDoneOperation & OnceDoneOperation)
  1514. {
  1515. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1516. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1517. OnceDoneOperation);
  1518. }
  1519. //---------------------------------------------------------------------------
  1520. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1521. {
  1522. DebugAssert(GetSide(Side) == osRemote);
  1523. DebugUsedParam(Side);
  1524. return RemoteDirView;
  1525. }
  1526. //---------------------------------------------------------------------------
  1527. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1528. {
  1529. DebugAssert(GetSide(Side) == osRemote);
  1530. DebugUsedParam(Side);
  1531. return (Terminal != NULL);
  1532. }
  1533. //---------------------------------------------------------------------------
  1534. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1535. TOperationSide Side, int FilesOnly)
  1536. {
  1537. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1538. }
  1539. //---------------------------------------------------------------------------
  1540. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1541. TOperationSide Side, int FilesOnly)
  1542. {
  1543. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1544. }
  1545. //---------------------------------------------------------------------------
  1546. struct THistoryItemData
  1547. {
  1548. short int Side;
  1549. short int Index;
  1550. };
  1551. //---------------------------------------------------------------------------
  1552. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1553. {
  1554. DirView(Side)->HistoryGo(Index);
  1555. }
  1556. //---------------------------------------------------------------------------
  1557. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1558. {
  1559. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1560. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1561. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1562. }
  1563. //---------------------------------------------------------------------------
  1564. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1565. bool Back)
  1566. {
  1567. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1568. {
  1569. TCustomDirView * DView = DirView(Side);
  1570. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1571. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1572. if (ICount > 10)
  1573. {
  1574. ICount = 10;
  1575. }
  1576. Menu->Items->Clear();
  1577. THistoryItemData Data;
  1578. Data.Side = Side;
  1579. for (short int i = 1; i <= ICount; i++)
  1580. {
  1581. TTBCustomItem * Item = new TTBXItem(Menu);
  1582. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1583. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, (Side == osRemote));
  1584. Item->Hint = DView->HistoryPath[Data.Index];
  1585. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1586. Item->Tag = *reinterpret_cast<int*>(&Data);
  1587. Item->OnClick = HistoryItemClick;
  1588. Menu->Items->Add(Item);
  1589. }
  1590. }
  1591. }
  1592. //---------------------------------------------------------------------------
  1593. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1594. TOperationSide Side, bool Back)
  1595. {
  1596. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1597. {
  1598. // workaround
  1599. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1600. // operator new allocates memory in Pascal code, but calls inline
  1601. // contructor in C++, leading in problems, the function does
  1602. // both in Pascal code
  1603. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1604. UpdateHistoryMenu(Side, Back);
  1605. }
  1606. return FHistoryMenu[Side == osLocal][Back];
  1607. }
  1608. //---------------------------------------------------------------------------
  1609. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1610. TCustomDirView *Sender)
  1611. {
  1612. TOperationSide Side = (Sender == DirView(osRemote) ? osRemote : osLocal);
  1613. UpdateHistoryMenu(Side, true);
  1614. UpdateHistoryMenu(Side, false);
  1615. }
  1616. //---------------------------------------------------------------------------
  1617. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1618. {
  1619. // remote custom commands can be executed only if the server supports shell commands
  1620. // or have secondary shell
  1621. return (FTerminal != NULL) && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1622. }
  1623. //---------------------------------------------------------------------------
  1624. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1625. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1626. {
  1627. int Result;
  1628. TFileCustomCommand RemoteCustomCommand;
  1629. TLocalCustomCommand LocalCustomCommand;
  1630. TFileCustomCommand * NonInteractiveCustomCommand =
  1631. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1632. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1633. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1634. if (FLAGCLEAR(Command.Params, ccLocal))
  1635. {
  1636. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1637. // custom command that does not operate with files can be executed anytime ...
  1638. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1639. {
  1640. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1641. {
  1642. // ... but do not show such command in remote file menu (TODO)
  1643. Result = AllowedState;
  1644. }
  1645. else
  1646. {
  1647. Result = -1;
  1648. }
  1649. }
  1650. else
  1651. {
  1652. if ((ListType == ccltAll) || (ListType == ccltFile))
  1653. {
  1654. Result = ((FCurrentSide == osRemote) && DirView(osRemote)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1655. }
  1656. else
  1657. {
  1658. Result = -1;
  1659. }
  1660. }
  1661. }
  1662. else
  1663. {
  1664. // custom command that does not operate with files can be executed anytime
  1665. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1666. {
  1667. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1668. }
  1669. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1670. {
  1671. if ((ListType == ccltAll) || (ListType == ccltFile))
  1672. {
  1673. // special case is "diff"-style command that can be executed over any side,
  1674. // if we have both sides
  1675. Result =
  1676. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1677. // directly (instead of EnableSelectedOperation) to pass
  1678. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1679. ((HasDirView[osLocal] && DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1680. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1681. }
  1682. else if (ListType == ccltBoth)
  1683. {
  1684. Result = 1;
  1685. }
  1686. else
  1687. {
  1688. Result = -1;
  1689. }
  1690. }
  1691. else
  1692. {
  1693. if ((ListType == ccltAll) || (ListType == ccltFile))
  1694. {
  1695. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1696. }
  1697. else
  1698. {
  1699. Result = -1;
  1700. }
  1701. }
  1702. }
  1703. return Result;
  1704. }
  1705. //---------------------------------------------------------------------------
  1706. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1707. TStrings * FileList, const TCustomCommandType & ACommand,
  1708. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1709. {
  1710. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1711. {
  1712. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1713. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1714. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1715. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1716. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1717. bool Capture =
  1718. FLAGSET(ACommand.Params, ccShowResults) ||
  1719. FLAGSET(ACommand.Params, ccCopyResults) ||
  1720. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1721. TCaptureOutputEvent OutputEvent = NULL;
  1722. DebugAssert(FCapturedLog == NULL);
  1723. if (Capture)
  1724. {
  1725. FCapturedLog = new TStringList();
  1726. OutputEvent = TerminalCaptureLog;
  1727. }
  1728. try
  1729. {
  1730. if (!RemoteCustomCommand.IsFileCommand(Command))
  1731. {
  1732. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1733. OutputEvent);
  1734. }
  1735. else
  1736. {
  1737. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1738. }
  1739. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1740. {
  1741. if (FLAGSET(ACommand.Params, ccCopyResults))
  1742. {
  1743. CopyToClipboard(FCapturedLog);
  1744. }
  1745. if (FLAGSET(ACommand.Params, ccShowResults))
  1746. {
  1747. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1748. }
  1749. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1750. {
  1751. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1752. }
  1753. }
  1754. }
  1755. __finally
  1756. {
  1757. SAFE_DESTROY(FCapturedLog);
  1758. }
  1759. }
  1760. }
  1761. //---------------------------------------------------------------------------
  1762. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1763. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1764. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1765. {
  1766. TStrings * LocalFileList = NULL;
  1767. TStrings * RemoteFileList = NULL;
  1768. TStrings * RemoteFileListFull = NULL;
  1769. try
  1770. {
  1771. if (LocalFileCommand)
  1772. {
  1773. if (ALocalFileList == NULL)
  1774. {
  1775. DebugAssert(HasDirView[osLocal]);
  1776. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1777. // directly (instead of EnableSelectedOperation) to pass
  1778. // false to FocusedFileOnlyWhenFocused
  1779. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1780. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1781. }
  1782. else
  1783. {
  1784. LocalFileList = ALocalFileList;
  1785. }
  1786. if (FileListCommand)
  1787. {
  1788. if (LocalFileList->Count != 1)
  1789. {
  1790. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1791. }
  1792. }
  1793. else
  1794. {
  1795. if ((LocalFileList->Count != 1) &&
  1796. (FileList->Count != 1) &&
  1797. (LocalFileList->Count != FileList->Count))
  1798. {
  1799. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1800. }
  1801. }
  1802. }
  1803. UnicodeString RootTempDir;
  1804. UnicodeString TempDir;
  1805. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1806. if (!RemoteFiles)
  1807. {
  1808. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1809. }
  1810. try
  1811. {
  1812. TDateTimes RemoteFileTimes;
  1813. if (RemoteFiles)
  1814. {
  1815. RemoteFileList = FileList;
  1816. }
  1817. else
  1818. {
  1819. RemoteFileList = new TStringList();
  1820. TMakeLocalFileListParams MakeFileListParam;
  1821. MakeFileListParam.FileList = RemoteFileList;
  1822. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1823. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1824. MakeFileListParam.Recursive =
  1825. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1826. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1827. if (!MakeFileListParam.Recursive)
  1828. {
  1829. RemoteFileTimes.clear();
  1830. RemoteFileListFull = new TStringList();
  1831. MakeFileListParam.FileList = RemoteFileListFull;
  1832. MakeFileListParam.Recursive = true;
  1833. MakeFileListParam.IncludeDirs = false;
  1834. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1835. }
  1836. else
  1837. {
  1838. RemoteFileListFull = RemoteFileList;
  1839. }
  1840. }
  1841. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1842. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1843. if (!NonBlocking)
  1844. {
  1845. int Count;
  1846. if (FileListCommand)
  1847. {
  1848. Count = 1;
  1849. }
  1850. else if (LocalFileCommand)
  1851. {
  1852. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1853. }
  1854. else
  1855. {
  1856. Count = RemoteFileList->Count;
  1857. }
  1858. Progress.Start(foCustomCommand, osRemote, Count);
  1859. DebugAssert(FProgressForm != NULL);
  1860. FProgressForm->ReadOnly = true;
  1861. }
  1862. try
  1863. {
  1864. if (FileListCommand)
  1865. {
  1866. UnicodeString LocalFile;
  1867. // MakeFileList does not delimit filenames
  1868. UnicodeString FileList = MakeFileList(RemoteFileList);
  1869. if (LocalFileCommand)
  1870. {
  1871. DebugAssert(LocalFileList->Count == 1);
  1872. LocalFile = LocalFileList->Strings[0];
  1873. }
  1874. TLocalCustomCommand CustomCommand(Data,
  1875. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1876. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1877. if (NonBlocking)
  1878. {
  1879. DebugAssert(!POutput);
  1880. ExecuteShellChecked(ShellCommand);
  1881. }
  1882. else
  1883. {
  1884. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1885. }
  1886. }
  1887. else if (LocalFileCommand)
  1888. {
  1889. if (LocalFileList->Count == 1)
  1890. {
  1891. UnicodeString LocalFile = LocalFileList->Strings[0];
  1892. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1893. {
  1894. UnicodeString FileName = RemoteFileList->Strings[Index];
  1895. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1896. Progress.SetFile(FileNameForProgress);
  1897. TLocalCustomCommand CustomCommand(Data,
  1898. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1899. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1900. TOnceDoneOperation OnceDoneOperation;
  1901. // Do not unselect anything, as it won't work with two panels anyway
  1902. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1903. }
  1904. }
  1905. else if (RemoteFileList->Count == 1)
  1906. {
  1907. UnicodeString FileName = RemoteFileList->Strings[0];
  1908. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1909. {
  1910. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1911. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1912. Progress.SetFile(LocalFileNameOnly);
  1913. TLocalCustomCommand CustomCommand(
  1914. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1915. FileName, LocalFileName, L"");
  1916. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1917. TOnceDoneOperation OnceDoneOperation;
  1918. // Do not unselect anything, as it won't work with two panels anyway
  1919. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1920. }
  1921. }
  1922. else
  1923. {
  1924. if (LocalFileList->Count != RemoteFileList->Count)
  1925. {
  1926. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1927. }
  1928. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1929. {
  1930. UnicodeString FileName = RemoteFileList->Strings[Index];
  1931. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1932. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1933. Progress.SetFile(LocalFileNameOnly); // sic
  1934. TLocalCustomCommand CustomCommand(
  1935. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1936. FileName, LocalFileName, L"");
  1937. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1938. TOnceDoneOperation OnceDoneOperation;
  1939. // Do not unselect anything, as it won't work with two panels anyway
  1940. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1941. }
  1942. }
  1943. }
  1944. else
  1945. {
  1946. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1947. {
  1948. UnicodeString FileName = RemoteFileList->Strings[Index];
  1949. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1950. Progress.SetFile(FileNameForProgress);
  1951. TLocalCustomCommand CustomCommand(Data,
  1952. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1953. FileName, L"", L"");
  1954. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1955. TOnceDoneOperation OnceDoneOperation;
  1956. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  1957. }
  1958. }
  1959. }
  1960. __finally
  1961. {
  1962. if (!NonBlocking)
  1963. {
  1964. Progress.Stop();
  1965. }
  1966. }
  1967. DebugAssert(!FAutoOperation);
  1968. if (!RemoteFiles)
  1969. {
  1970. TempDir = IncludeTrailingBackslash(TempDir);
  1971. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  1972. {
  1973. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  1974. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  1975. // Skip directories, process only nested files.
  1976. // The check is redundant as FileAge fails for directories anyway.
  1977. !DirectoryExists(FileName))
  1978. {
  1979. UnicodeString RemoteDir =
  1980. UnixExtractFileDir(
  1981. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  1982. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  1983. TDateTime NewTime;
  1984. if (FileAge(FileName, NewTime) &&
  1985. (NewTime != RemoteFileTimes[Index]))
  1986. {
  1987. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  1988. TemporaryFileCopyParam(CopyParam);
  1989. CopyParam.FileMask = L"";
  1990. FAutoOperation = true;
  1991. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  1992. TemporaryFilesList->Add(FileName);
  1993. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  1994. }
  1995. }
  1996. }
  1997. }
  1998. }
  1999. __finally
  2000. {
  2001. FAutoOperation = false;
  2002. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2003. {
  2004. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2005. }
  2006. }
  2007. }
  2008. __finally
  2009. {
  2010. if (RemoteFileList != FileList)
  2011. {
  2012. delete RemoteFileList;
  2013. }
  2014. if (LocalFileList != ALocalFileList)
  2015. {
  2016. delete LocalFileList;
  2017. }
  2018. if (RemoteFileListFull != RemoteFileList)
  2019. {
  2020. delete RemoteFileListFull;
  2021. }
  2022. }
  2023. }
  2024. //---------------------------------------------------------------------------
  2025. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2026. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2027. bool FileListCommand, UnicodeString * POutput)
  2028. {
  2029. std::unique_ptr<TStrings> SelectedFileList(DirView(osLocal)->CreateFileList(false, true, NULL));
  2030. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2031. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2032. {
  2033. UnicodeString FileName = SelectedFileList->Strings[Index];
  2034. if (DirectoryExists(FileName))
  2035. {
  2036. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2037. {
  2038. LocalFileList->Add(FileName);
  2039. }
  2040. if (FLAGSET(ACommand.Params, ccRecursive))
  2041. {
  2042. TMakeLocalFileListParams MakeFileListParam;
  2043. MakeFileListParam.FileList = LocalFileList.get();
  2044. MakeFileListParam.FileTimes = NULL;
  2045. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2046. MakeFileListParam.Recursive = true;
  2047. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2048. }
  2049. }
  2050. else
  2051. {
  2052. LocalFileList->Add(FileName);
  2053. }
  2054. }
  2055. if (FileListCommand)
  2056. {
  2057. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2058. TLocalCustomCommand CustomCommand(
  2059. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2060. L"", L"", FileList);
  2061. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2062. }
  2063. else
  2064. {
  2065. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2066. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2067. DebugAssert(FProgressForm != NULL);
  2068. FProgressForm->ReadOnly = true;
  2069. try
  2070. {
  2071. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2072. {
  2073. UnicodeString FileName = LocalFileList->Strings[Index];
  2074. Progress.SetFile(FileName);
  2075. TLocalCustomCommand CustomCommand(
  2076. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2077. FileName, L"", L"");
  2078. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2079. TOnceDoneOperation OnceDoneOperation;
  2080. Progress.Finish(FileName, true, OnceDoneOperation);
  2081. }
  2082. }
  2083. __finally
  2084. {
  2085. Progress.Stop();
  2086. }
  2087. }
  2088. }
  2089. //---------------------------------------------------------------------------
  2090. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2091. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2092. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2093. {
  2094. TLocalCustomCommand LocalCustomCommand(Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory());
  2095. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2096. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2097. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2098. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2099. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2100. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2101. std::unique_ptr<UnicodeString> POutput;
  2102. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2103. FLAGSET(ACommand.Params, ccCopyResults))
  2104. {
  2105. POutput.reset(new UnicodeString());
  2106. }
  2107. if (!LocalCustomCommand.IsFileCommand(Command))
  2108. {
  2109. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2110. }
  2111. // remote files?
  2112. else if ((FCurrentSide == osRemote) || LocalFileCommand)
  2113. {
  2114. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2115. }
  2116. // local files
  2117. else
  2118. {
  2119. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2120. }
  2121. if (POutput.get() != NULL)
  2122. {
  2123. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2124. int P = POutput->Pos(sLineBreak);
  2125. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2126. {
  2127. POutput->SetLength(P - 1);
  2128. }
  2129. // Copy even empty output to clipboard
  2130. if (FLAGSET(ACommand.Params, ccCopyResults))
  2131. {
  2132. CopyToClipboard(*POutput);
  2133. }
  2134. // But do not show an empty message box.
  2135. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2136. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2137. !POutput->IsEmpty())
  2138. {
  2139. TClipboardHandler ClipboardHandler;
  2140. ClipboardHandler.Text = *POutput;
  2141. TMessageParams Params;
  2142. TQueryButtonAlias Aliases[1];
  2143. Aliases[0].Button = qaRetry;
  2144. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2145. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2146. Params.Aliases = Aliases;
  2147. Params.AliasesCount = LENOF(Aliases);
  2148. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2149. }
  2150. }
  2151. }
  2152. //---------------------------------------------------------------------------
  2153. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2154. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2155. {
  2156. TCustomCommandData Data(Terminal);
  2157. UnicodeString Site = Terminal->SessionData->SessionKey;
  2158. UnicodeString HelpKeyword = ACommand.HomePage;
  2159. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2160. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2161. {
  2162. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2163. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2164. {
  2165. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, Terminal->CurrentDirectory));
  2166. }
  2167. else
  2168. {
  2169. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory()));
  2170. }
  2171. if (!DoCustomCommandOptionsDialog(
  2172. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2173. {
  2174. Abort();
  2175. }
  2176. }
  2177. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2178. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2179. {
  2180. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2181. }
  2182. else
  2183. {
  2184. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2185. }
  2186. }
  2187. //---------------------------------------------------------------------------
  2188. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2189. const TCustomCommandType & Command)
  2190. {
  2191. DebugAssert(FCustomCommandLocalFileList != NULL);
  2192. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2193. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2194. TStrings * LocalFileList = new TStringList();
  2195. TStrings * RemoteFileList = new TStringList();
  2196. try
  2197. {
  2198. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2199. {
  2200. LocalFileList->Clear();
  2201. LocalFileList->AddObject(
  2202. FCustomCommandLocalFileList->Strings[Index],
  2203. FCustomCommandLocalFileList->Objects[Index]);
  2204. RemoteFileList->Clear();
  2205. RemoteFileList->AddObject(
  2206. FCustomCommandRemoteFileList->Strings[Index],
  2207. FCustomCommandRemoteFileList->Objects[Index]);
  2208. CustomCommand(RemoteFileList, Command, LocalFileList);
  2209. }
  2210. }
  2211. __finally
  2212. {
  2213. delete LocalFileList;
  2214. delete RemoteFileList;
  2215. }
  2216. }
  2217. //---------------------------------------------------------------------------
  2218. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2219. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2220. {
  2221. delete FCustomCommandLocalFileList;
  2222. delete FCustomCommandRemoteFileList;
  2223. // takeover ownership,
  2224. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2225. FCustomCommandLocalFileList = LocalFileList;
  2226. FCustomCommandRemoteFileList = RemoteFileList;
  2227. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2228. if (Button != NULL)
  2229. {
  2230. FCustomCommandMenu->Items->Clear();
  2231. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth);
  2232. MenuPopup(FCustomCommandMenu, Button);
  2233. }
  2234. else
  2235. {
  2236. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2237. }
  2238. }
  2239. //---------------------------------------------------------------------------
  2240. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2241. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2242. {
  2243. DebugAssert(FCapturedLog != NULL);
  2244. if ((OutputType == cotOutput) || (OutputType == cotError))
  2245. {
  2246. FCapturedLog->Add(AddedLine);
  2247. }
  2248. }
  2249. //---------------------------------------------------------------------------
  2250. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2251. TOperationSide Side)
  2252. {
  2253. return (Side == osRemote) &&
  2254. ((Control == RemoteDirView) || (Control == RemoteDriveView));
  2255. }
  2256. //---------------------------------------------------------------------------
  2257. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2258. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2259. {
  2260. TTBItemOptions O;
  2261. O = Item->Options;
  2262. TCustomDirView * DView = DirView(Side);
  2263. if ((DView->ItemFocused != NULL) &&
  2264. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2265. // when resolving links is disabled, default action is to enter the directory,
  2266. // no matter what DoubleClickAction is configured to
  2267. ((Side != osRemote) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2268. // Can only Edit files, but can Open/Copy even directories
  2269. ((DoubleClickAction != dcaEdit) ||
  2270. !DView->ItemIsDirectory(DView->ItemFocused)))
  2271. {
  2272. Item->Options = O << tboDefault;
  2273. }
  2274. else
  2275. {
  2276. Item->Options = O >> tboDefault;
  2277. }
  2278. }
  2279. //---------------------------------------------------------------------------
  2280. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2281. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2282. {
  2283. TCustomDirView * DView = DirView(Side);
  2284. TListItem * Item = DView->ItemFocused;
  2285. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2286. EnableFocusedOperation[Side])
  2287. {
  2288. TPoint ClientPoint;
  2289. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2290. TPoint(0, 0) : MousePos;
  2291. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2292. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2293. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2294. }
  2295. }
  2296. //---------------------------------------------------------------------------
  2297. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2298. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2299. {
  2300. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2301. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2302. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2303. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2304. Handled = true;
  2305. }
  2306. //---------------------------------------------------------------------------
  2307. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2308. {
  2309. }
  2310. //---------------------------------------------------------------------------
  2311. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2312. {
  2313. DebugAssert(FErrorList == NULL);
  2314. if (WinConfiguration->ContinueOnError)
  2315. {
  2316. FErrorList = new TStringList();
  2317. Configuration->Usage->Inc(L"ContinuationsOnError");
  2318. }
  2319. NonVisualDataModule->StartBusy();
  2320. }
  2321. //---------------------------------------------------------------------------
  2322. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2323. {
  2324. NonVisualDataModule->EndBusy();
  2325. if (FErrorList)
  2326. {
  2327. HandleErrorList(FErrorList);
  2328. }
  2329. }
  2330. //---------------------------------------------------------------------------
  2331. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2332. const TCopyParamType & CopyParam)
  2333. {
  2334. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2335. {
  2336. Configuration->Usage->Inc(L"FileMaskUses");
  2337. }
  2338. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2339. {
  2340. Configuration->Usage->Inc(L"OperationMaskUses");
  2341. }
  2342. }
  2343. //---------------------------------------------------------------------------
  2344. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2345. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2346. {
  2347. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2348. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2349. TTransferOperationParam DefaultParam;
  2350. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2351. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2352. switch (Param.Queue)
  2353. {
  2354. case asOn:
  2355. CopyParam.Queue = true;
  2356. break;
  2357. case asOff:
  2358. CopyParam.Queue = false;
  2359. break;
  2360. case asAuto:
  2361. default:
  2362. // keep default
  2363. break;
  2364. }
  2365. bool Result =
  2366. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2367. if (Result)
  2368. {
  2369. DebugAssert(Terminal);
  2370. bool SelectionRestored = false;
  2371. TCustomDirView * DView = NULL;
  2372. if (HasDirView[Side])
  2373. {
  2374. DView = DirView(Side);
  2375. DView->SaveSelection();
  2376. DView->SaveSelectedNames();
  2377. }
  2378. UpdateCopyParamCounters(CopyParam);
  2379. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2380. DebugAssert(FTransferResumeList == NULL);
  2381. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2382. FMoveToQueue = false;
  2383. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2384. try
  2385. {
  2386. TStrings * PermanentFileList;
  2387. std::unique_ptr<TStrings> PermanentFileListOwner;
  2388. try
  2389. {
  2390. if (Side == osLocal)
  2391. {
  2392. PermanentFileList = FileList;
  2393. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2394. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2395. if (Operation == foMove)
  2396. {
  2397. ReloadLocalDirectory();
  2398. if (DView != NULL)
  2399. {
  2400. DView->RestoreSelection();
  2401. }
  2402. SelectionRestored = true;
  2403. }
  2404. }
  2405. else
  2406. {
  2407. // Clone the file list as it may refer to current directory files,
  2408. // which get destroyed, when the source directory is reloaded after foMove operation.
  2409. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2410. // But for a hotfix, we are not going to do such a big change.
  2411. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2412. PermanentFileList = PermanentFileListOwner.get();
  2413. try
  2414. {
  2415. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2416. }
  2417. __finally
  2418. {
  2419. if (Operation == foMove)
  2420. {
  2421. if (DView != NULL)
  2422. {
  2423. DView->RestoreSelection();
  2424. }
  2425. SelectionRestored = true;
  2426. }
  2427. ReloadLocalDirectory(Param.TargetDirectory);
  2428. }
  2429. }
  2430. }
  2431. catch (EAbort &)
  2432. {
  2433. if (FMoveToQueue)
  2434. {
  2435. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2436. DebugAssert(CopyParam.TransferSkipList == NULL);
  2437. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2438. if (TransferResumeList->Count > 0)
  2439. {
  2440. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2441. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2442. }
  2443. CopyParam.TransferSkipList = TransferResumeList.release();
  2444. // not really needed, just to keep it consistent with TransferResumeList
  2445. FTransferResumeList = NULL;
  2446. FMoveToQueue = false;
  2447. Configuration->Usage->Inc("MovesToBackground");
  2448. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2449. ClearTransferSourceSelection(Direction);
  2450. }
  2451. throw;
  2452. }
  2453. }
  2454. __finally
  2455. {
  2456. if (!SelectionRestored && (DView != NULL))
  2457. {
  2458. DView->DiscardSavedSelection();
  2459. }
  2460. FTransferResumeList = NULL;
  2461. }
  2462. }
  2463. return Result;
  2464. }
  2465. //---------------------------------------------------------------------------
  2466. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2467. TOperationSide Side, TStrings * FileList, void * Param)
  2468. {
  2469. DebugAssert(FileList->Count);
  2470. // We deliberately do not toggle alternative flag (Param), but use OR,
  2471. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2472. // shortcut of CurrentDeleteAlternativeAction
  2473. bool Alternative =
  2474. bool(Param) || UseAlternativeFunction();
  2475. bool Recycle;
  2476. if (Side == osLocal)
  2477. {
  2478. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2479. }
  2480. else
  2481. {
  2482. Recycle =
  2483. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2484. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2485. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2486. }
  2487. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2488. if (!Result)
  2489. {
  2490. UnicodeString Query;
  2491. if (FileList->Count == 1)
  2492. {
  2493. if (Side == osLocal)
  2494. {
  2495. Query = ExtractFileName(FileList->Strings[0]);
  2496. }
  2497. else
  2498. {
  2499. Query = UnixExtractFileName(FileList->Strings[0]);
  2500. }
  2501. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2502. }
  2503. else
  2504. {
  2505. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2506. }
  2507. TMessageParams Params(mpNeverAskAgainCheck);
  2508. Params.ImageName = L"Delete file";
  2509. unsigned int Answer =
  2510. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2511. if (Answer == qaNeverAskAgain)
  2512. {
  2513. Result = true;
  2514. if (Recycle)
  2515. {
  2516. WinConfiguration->ConfirmRecycling = false;
  2517. }
  2518. else
  2519. {
  2520. WinConfiguration->ConfirmDeleting = false;
  2521. }
  2522. }
  2523. else
  2524. {
  2525. Result = (Answer == qaOK);
  2526. }
  2527. }
  2528. if (Result)
  2529. {
  2530. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2531. }
  2532. return Result;
  2533. }
  2534. //---------------------------------------------------------------------------
  2535. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2536. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2537. {
  2538. TAutoBatch AutoBatch(this);
  2539. bool Result;
  2540. if ((Operation == foCopy) || (Operation == foMove))
  2541. {
  2542. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2543. }
  2544. else if (Operation == foRename)
  2545. {
  2546. DebugAssert(DirView(Side)->ItemFocused);
  2547. DirView(Side)->ItemFocused->EditCaption();
  2548. Result = true;
  2549. }
  2550. else if (Operation == foDelete)
  2551. {
  2552. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2553. }
  2554. else if (Operation == foSetProperties)
  2555. {
  2556. RemoteDirView->SaveSelectedNames();
  2557. Result = SetProperties(Side, FileList);
  2558. }
  2559. else if (Operation == foCustomCommand)
  2560. {
  2561. DebugAssert(Param);
  2562. DebugAssert(Side == osRemote);
  2563. RemoteDirView->SaveSelectedNames();
  2564. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2565. CustomCommand(FileList, *Command, NULL);
  2566. Result = true;
  2567. }
  2568. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2569. {
  2570. DebugAssert(Side == osRemote);
  2571. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2572. (Operation == foRemoteMove), reinterpret_cast<TTerminal *>(Param));
  2573. }
  2574. else if (Operation == foLock)
  2575. {
  2576. DebugAssert(Side == osRemote);
  2577. LockFiles(FileList, true);
  2578. Result = true;
  2579. }
  2580. else if (Operation == foUnlock)
  2581. {
  2582. DebugAssert(Side == osRemote);
  2583. LockFiles(FileList, false);
  2584. Result = true;
  2585. }
  2586. else
  2587. {
  2588. DebugFail();
  2589. }
  2590. return Result;
  2591. }
  2592. //---------------------------------------------------------------------------
  2593. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2594. {
  2595. if (Side == osCurrent)
  2596. {
  2597. Side = FCurrentSide;
  2598. }
  2599. return Side;
  2600. }
  2601. //---------------------------------------------------------------------------
  2602. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2603. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2604. {
  2605. Side = GetSide(Side);
  2606. bool Result;
  2607. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, (Side == osLocal), NULL);
  2608. try
  2609. {
  2610. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2611. }
  2612. __finally
  2613. {
  2614. delete FileList;
  2615. }
  2616. return Result;
  2617. }
  2618. //---------------------------------------------------------------------------
  2619. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2620. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2621. bool NoConfirmation, void * Param)
  2622. {
  2623. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2624. {
  2625. if ((Operation == foCopy) || (Operation == foMove))
  2626. {
  2627. if (GetSide(Side) == osLocal)
  2628. {
  2629. Configuration->Usage->Inc(L"UploadsCommand");
  2630. }
  2631. else
  2632. {
  2633. Configuration->Usage->Inc(L"DownloadsCommand");
  2634. }
  2635. }
  2636. }
  2637. }
  2638. //---------------------------------------------------------------------------
  2639. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2640. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2641. {
  2642. TTransferOperationParam Param;
  2643. if ((WinConfiguration->Interface != ifCommander) ||
  2644. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2645. {
  2646. Flags &= ~cocShortCutHint;
  2647. }
  2648. TCustomDirView * DView = DirView(Side);
  2649. Param.Options =
  2650. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2651. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2652. if (FLAGSET(Flags, cocQueue))
  2653. {
  2654. Param.Queue = asOn;
  2655. }
  2656. else if (FLAGSET(Flags, cocNonQueue))
  2657. {
  2658. Param.Queue = asOff;
  2659. }
  2660. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2661. }
  2662. //---------------------------------------------------------------------------
  2663. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2664. {
  2665. try
  2666. {
  2667. if (ErrorList->Count)
  2668. {
  2669. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2670. if (MessageDialog(Message, qtError,
  2671. qaOK | qaCancel, HELP_NONE) == qaOK)
  2672. {
  2673. unsigned int Answer;
  2674. int Index = 0;
  2675. do
  2676. {
  2677. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2678. TQueryButtonAlias Aliases[2];
  2679. Aliases[0].Button = qaYes;
  2680. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2681. Aliases[1].Button = qaNo;
  2682. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2683. TMessageParams Params;
  2684. Params.Aliases = Aliases;
  2685. Params.AliasesCount = LENOF(Aliases);
  2686. Answer = MoreMessageDialog(
  2687. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2688. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2689. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2690. qaOK, HELP_NONE, &Params);
  2691. if (Answer == qaNo)
  2692. {
  2693. Index++;
  2694. }
  2695. if (Answer == qaYes)
  2696. {
  2697. Index--;
  2698. }
  2699. }
  2700. while (Answer != qaOK);
  2701. }
  2702. }
  2703. }
  2704. __finally
  2705. {
  2706. TStrings * List = ErrorList;
  2707. ErrorList = NULL;
  2708. for (int i = 0; i < List->Count; i++)
  2709. {
  2710. delete List->Objects[i];
  2711. }
  2712. delete List;
  2713. }
  2714. }
  2715. //---------------------------------------------------------------------------
  2716. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2717. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2718. {
  2719. // needed for checking filemasks, as there's no directory object
  2720. // associated with the file object
  2721. File->FullFileName = FullFileName;
  2722. TFileMasks::TParams MaskParams;
  2723. MaskParams.Size = File->Size;
  2724. MaskParams.Modification = File->Modification;
  2725. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2726. }
  2727. //---------------------------------------------------------------------------
  2728. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2729. {
  2730. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2731. Side = GetSide(Side);
  2732. TCustomDirView * DView = DirView(Side);
  2733. TListItem * FocusedItem = DView->ItemFocused;
  2734. UnicodeString Name;
  2735. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2736. {
  2737. Name = DView->ItemFileName(FocusedItem);
  2738. }
  2739. else
  2740. {
  2741. Name = LoadStr(NEW_FILE);
  2742. }
  2743. UnicodeString Names = Name;
  2744. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2745. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2746. HELP_EDIT_NEW, History.get(), true))
  2747. {
  2748. while (!Names.IsEmpty())
  2749. {
  2750. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2751. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2752. UnicodeString TargetFileName;
  2753. UnicodeString LocalFileName;
  2754. UnicodeString RootTempDir;
  2755. UnicodeString TempDir;
  2756. UnicodeString RemoteDirectory;
  2757. bool ExistingFile = false;
  2758. if (Side == osRemote)
  2759. {
  2760. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2761. TRemoteFile * File = NULL;
  2762. if (FTerminal->FileExists(Name, &File) &&
  2763. !File->IsDirectory)
  2764. {
  2765. try
  2766. {
  2767. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2768. ExistingFile = true;
  2769. }
  2770. __finally
  2771. {
  2772. delete File;
  2773. }
  2774. }
  2775. if (!ExistingFile)
  2776. {
  2777. RemoteDirectory = UnixExtractFilePath(Name);
  2778. TemporaryDirectoryForRemoteFiles(
  2779. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2780. TargetFileName = UnixExtractFileName(Name);
  2781. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2782. LocalFileName = TempDir +
  2783. // We probably do not want to trim the VMS version here
  2784. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2785. }
  2786. }
  2787. else
  2788. {
  2789. if (ExtractFilePath(Name).IsEmpty())
  2790. {
  2791. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2792. }
  2793. else
  2794. {
  2795. LocalFileName = ExpandFileName(Name);
  2796. }
  2797. TargetFileName = ExtractFileName(Name);
  2798. }
  2799. if (!ExistingFile)
  2800. {
  2801. if (!FileExists(ApiPath(LocalFileName)))
  2802. {
  2803. int File = FileCreate(ApiPath(LocalFileName));
  2804. if (File < 0)
  2805. {
  2806. if (!RootTempDir.IsEmpty())
  2807. {
  2808. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2809. }
  2810. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2811. }
  2812. else
  2813. {
  2814. FileClose(File);
  2815. }
  2816. }
  2817. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2818. const TEditorData * ExternalEditor = NULL;
  2819. TFileMasks::TParams MaskParams; // size not known
  2820. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2821. false, MaskParams);
  2822. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2823. ExternalEditor, RootTempDir, RemoteDirectory);
  2824. }
  2825. }
  2826. }
  2827. }
  2828. //---------------------------------------------------------------------------
  2829. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2830. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2831. {
  2832. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2833. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2834. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2835. return
  2836. ((ExecuteFileBy == efInternalEditor)) ||
  2837. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2838. }
  2839. //---------------------------------------------------------------------------
  2840. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2841. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2842. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2843. UnicodeString RemoteDirectory)
  2844. {
  2845. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2846. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2847. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2848. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2849. Side = GetSide(Side);
  2850. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2851. if (Side == osRemote)
  2852. {
  2853. Data->Terminal = Terminal;
  2854. Data->Queue = Queue;
  2855. Data->SessionData = CloneCurrentSessionData();
  2856. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2857. Data->RemoteDirectory = RemoteDirectory;
  2858. Data->SessionName = Terminal->SessionData->SessionName;
  2859. Data->LocalRootDirectory = LocalRootDirectory;
  2860. Data->OriginalFileName = OriginalFileName;
  2861. Data->Command = L""; // will be changed later for external editor
  2862. }
  2863. if (ExecuteFileBy == efInternalEditor)
  2864. {
  2865. if (Side == osRemote)
  2866. {
  2867. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2868. L" - " + Terminal->SessionData->SessionName;
  2869. TForm * Editor;
  2870. try
  2871. {
  2872. TNotifyEvent OnFileChanged = NULL;
  2873. TNotifyEvent OnSaveAll = NULL;
  2874. TAnyModifiedEvent OnAnyModified = NULL;
  2875. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2876. if (Terminal->IsCapable[fsBackgroundTransfers])
  2877. {
  2878. OnFileChanged = FEditorManager->FileChanged;
  2879. OnSaveAll = SaveAllInternalEditors;
  2880. OnAnyModified = AnyInternalEditorModified;
  2881. }
  2882. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2883. FEditorManager->FileReload, FEditorManager->FileClosed,
  2884. OnSaveAll, OnAnyModified,
  2885. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding);
  2886. }
  2887. catch(...)
  2888. {
  2889. if (!LocalRootDirectory.IsEmpty())
  2890. {
  2891. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2892. }
  2893. throw;
  2894. }
  2895. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2896. }
  2897. else
  2898. {
  2899. DebugAssert(!FStandaloneEditing);
  2900. TForm * Editor =
  2901. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2902. SaveAllInternalEditors, AnyInternalEditorModified,
  2903. L"", false, SessionColor, -1);
  2904. FLocalEditors->Add(Editor);
  2905. }
  2906. }
  2907. else
  2908. {
  2909. HANDLE Process;
  2910. if (ExecuteFileBy == efExternalEditor)
  2911. {
  2912. UnicodeString Program, Params, Dir;
  2913. Data->Command = ExternalEditor->ExternalEditor;
  2914. ReformatFileNameCommand(Data->Command);
  2915. SplitCommand(Data->Command, Program, Params, Dir);
  2916. Params = ExpandFileNameCommand(Params, FileName);
  2917. Program = ExpandEnvironmentVariables(Program);
  2918. if (!ExecuteShell(Program, Params, Process))
  2919. {
  2920. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  2921. }
  2922. }
  2923. else
  2924. {
  2925. DebugAssert(Side == osRemote);
  2926. if (!ExecuteShell(FileName, L"", Process))
  2927. {
  2928. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  2929. }
  2930. }
  2931. if ((Side == osLocal) ||
  2932. ((ExecuteFileBy == efShell) &&
  2933. !WinConfiguration->Editor.SDIShellEditor) ||
  2934. ((ExecuteFileBy == efExternalEditor) &&
  2935. !ExternalEditor->SDIExternalEditor))
  2936. {
  2937. // no need for handle
  2938. if (Process != NULL)
  2939. {
  2940. DebugCheck(CloseHandle(Process));
  2941. }
  2942. Process = INVALID_HANDLE_VALUE;
  2943. }
  2944. else
  2945. {
  2946. if (Process == NULL)
  2947. {
  2948. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  2949. }
  2950. }
  2951. if (Side == osRemote)
  2952. {
  2953. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  2954. }
  2955. }
  2956. }
  2957. //---------------------------------------------------------------------------
  2958. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  2959. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  2960. void * /*Arg*/)
  2961. {
  2962. if (Token != NULL)
  2963. {
  2964. EditorFormFileSave(static_cast<TForm *>(Token));
  2965. }
  2966. }
  2967. //---------------------------------------------------------------------------
  2968. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  2969. {
  2970. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  2971. {
  2972. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  2973. }
  2974. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  2975. }
  2976. //---------------------------------------------------------------------------
  2977. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  2978. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  2979. void * Arg)
  2980. {
  2981. if ((Token != NULL) &&
  2982. IsEditorFormModified(static_cast<TForm *>(Token)))
  2983. {
  2984. *static_cast<bool *>(Arg) = true;
  2985. }
  2986. }
  2987. //---------------------------------------------------------------------------
  2988. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  2989. TObject * /*Sender*/, bool & Modified)
  2990. {
  2991. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  2992. {
  2993. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  2994. {
  2995. Modified = true;
  2996. }
  2997. }
  2998. if (!Modified)
  2999. {
  3000. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3001. }
  3002. }
  3003. //---------------------------------------------------------------------------
  3004. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3005. {
  3006. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3007. }
  3008. //---------------------------------------------------------------------------
  3009. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3010. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3011. UnicodeString & Result, UnicodeString & RootDirectory)
  3012. {
  3013. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3014. {
  3015. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3016. Result = RootDirectory;
  3017. }
  3018. else
  3019. {
  3020. RootDirectory = L"";
  3021. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3022. Result = IncludeTrailingBackslash(Result);
  3023. }
  3024. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3025. {
  3026. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3027. }
  3028. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3029. {
  3030. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3031. {
  3032. RemoteDirectory.Delete(1, 1);
  3033. }
  3034. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3035. }
  3036. if (!ForceDirectories(ApiPath(Result)))
  3037. {
  3038. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3039. }
  3040. }
  3041. //---------------------------------------------------------------------------
  3042. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3043. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3044. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3045. {
  3046. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3047. if (ForceText)
  3048. {
  3049. CopyParam.TransferMode = tmAscii;
  3050. }
  3051. TemporaryFileCopyParam(CopyParam);
  3052. if (AllFiles)
  3053. {
  3054. CopyParam.IncludeFileMask = TFileMasks();
  3055. }
  3056. if (TempDir.IsEmpty())
  3057. {
  3058. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3059. }
  3060. DebugAssert(!FAutoOperation);
  3061. FAutoOperation = AutoOperation;
  3062. Terminal->ExceptionOnFail = true;
  3063. try
  3064. {
  3065. try
  3066. {
  3067. // turn off confirmations, as for MDI editors we may possibly download
  3068. // the same file over
  3069. Terminal->CopyToLocal(
  3070. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3071. if (GetTargetNames)
  3072. {
  3073. for (int i = 0; i < FileList->Count; i++)
  3074. {
  3075. FileList->Strings[i] =
  3076. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3077. }
  3078. }
  3079. }
  3080. catch(...)
  3081. {
  3082. if (!RootTempDir.IsEmpty())
  3083. {
  3084. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3085. }
  3086. throw;
  3087. }
  3088. }
  3089. __finally
  3090. {
  3091. FAutoOperation = false;
  3092. Terminal->ExceptionOnFail = false;
  3093. }
  3094. }
  3095. //---------------------------------------------------------------------------
  3096. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3097. {
  3098. // Do not waste time checking for default editor list the next time,
  3099. // or testing if default editor is not notepad.
  3100. bool TryNextTime = false;
  3101. UnicodeString UsageState;
  3102. if (!WinConfiguration->EditorList->IsDefaultList())
  3103. {
  3104. UsageState = "H";
  3105. }
  3106. else
  3107. {
  3108. UnicodeString Executable;
  3109. UnicodeString ExecutableDescription;
  3110. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3111. {
  3112. UnicodeString Message =
  3113. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3114. unsigned int Answer =
  3115. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3116. if (Answer != qaOK)
  3117. {
  3118. UsageState = "R";
  3119. }
  3120. else
  3121. {
  3122. UsageState = "A";
  3123. TEditorData EditorData;
  3124. EditorData.Editor = edExternal;
  3125. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3126. EditorData.DecideExternalEditorText();
  3127. TEditorList EditorList;
  3128. EditorList = *WinConfiguration->EditorList;
  3129. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3130. WinConfiguration->EditorList = &EditorList;
  3131. }
  3132. }
  3133. }
  3134. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3135. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3136. }
  3137. //---------------------------------------------------------------------------
  3138. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3139. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3140. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3141. {
  3142. if (ExecuteFileBy == efDefaultEditor)
  3143. {
  3144. if (!WinConfiguration->OfferedEditorAutoConfig)
  3145. {
  3146. EditorAutoConfig();
  3147. }
  3148. const TEditorPreferences * Editor =
  3149. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3150. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3151. {
  3152. ExecuteFileBy = efInternalEditor;
  3153. ExternalEditor = NULL;
  3154. }
  3155. else if (Editor->Data->Editor == edOpen)
  3156. {
  3157. ExecuteFileBy = efShell;
  3158. ExternalEditor = NULL;
  3159. }
  3160. else
  3161. {
  3162. ExecuteFileBy = efExternalEditor;
  3163. ExternalEditor = Editor->Data;
  3164. }
  3165. }
  3166. }
  3167. //---------------------------------------------------------------------------
  3168. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3169. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3170. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3171. {
  3172. UnicodeString OriginalFileName;
  3173. UnicodeString LocalRootDirectory;
  3174. UnicodeString RemoteDirectory;
  3175. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3176. (Side == osLocal), MaskParams);
  3177. UnicodeString Counter;
  3178. UnicodeString LocalFileName;
  3179. bool Handled = false;
  3180. if (Side == osRemote)
  3181. {
  3182. // We need to trim VMS version here, so that we use name without version
  3183. // when uploading back to create a new version of the file
  3184. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3185. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3186. TObject * Token = NULL;
  3187. UnicodeString LocalDirectory;
  3188. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3189. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3190. LocalDirectory))
  3191. {
  3192. if (Token != NULL)
  3193. {
  3194. TForm * Form = dynamic_cast<TForm *>(Token);
  3195. if (Form->WindowState == wsMinimized)
  3196. {
  3197. ShowWindow(Form->Handle, SW_RESTORE);
  3198. }
  3199. else
  3200. {
  3201. Form->SetFocus();
  3202. }
  3203. Handled = true;
  3204. }
  3205. else
  3206. {
  3207. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3208. }
  3209. }
  3210. if (!Handled)
  3211. {
  3212. TStringList * FileList1 = new TStringList();
  3213. try
  3214. {
  3215. FileList1->AddObject(FullFileName, Object);
  3216. TemporarilyDownloadFiles(FileList1,
  3217. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3218. LocalRootDirectory, LocalDirectory, true, true, true);
  3219. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3220. }
  3221. __finally
  3222. {
  3223. delete FileList1;
  3224. }
  3225. switch (ExecuteFileBy)
  3226. {
  3227. case efShell:
  3228. Counter = "RemoteFilesExecuted";
  3229. break;
  3230. case efInternalEditor:
  3231. Counter = "RemoteFilesOpenedInInternalEditor";
  3232. break;
  3233. case efExternalEditor:
  3234. Counter = "RemoteFilesOpenedInExternalEditor";
  3235. break;
  3236. default:
  3237. DebugFail();
  3238. }
  3239. }
  3240. }
  3241. else
  3242. {
  3243. LocalFileName = FullFileName;
  3244. OriginalFileName = ExtractFileName(FullFileName);
  3245. switch (ExecuteFileBy)
  3246. {
  3247. case efShell:
  3248. Counter = "LocalFilesExecuted";
  3249. break;
  3250. case efInternalEditor:
  3251. Counter = "LocalFilesOpenedInInternalEditor";
  3252. break;
  3253. case efExternalEditor:
  3254. Counter = "LocalFilesOpenedInExternalEditor";
  3255. break;
  3256. default:
  3257. DebugFail();
  3258. }
  3259. }
  3260. if (!Handled)
  3261. {
  3262. Configuration->Usage->Inc(Counter);
  3263. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3264. ExternalEditor, LocalRootDirectory, RemoteDirectory);
  3265. }
  3266. }
  3267. //---------------------------------------------------------------------------
  3268. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3269. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3270. bool AllSelected, bool OnFocused)
  3271. {
  3272. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3273. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3274. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3275. Side = GetSide(Side);
  3276. TCustomDirView * DView = DirView(Side);
  3277. TStrings * FileList = AllSelected ?
  3278. DView->CreateFileList(OnFocused, Side == osLocal) :
  3279. DView->CreateFocusedFileList(Side == osLocal);
  3280. try
  3281. {
  3282. DebugAssert(AllSelected || (FileList->Count == 1));
  3283. for (int i = 0; i < FileList->Count; i++)
  3284. {
  3285. UnicodeString ListFileName = FileList->Strings[i];
  3286. UnicodeString FileNameOnly = (Side == osRemote) ?
  3287. UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3288. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3289. if (!DView->ItemIsDirectory(Item))
  3290. {
  3291. UnicodeString FullFileName;
  3292. if (Side == osRemote)
  3293. {
  3294. FullFileName = RemoteDirView->Path + ListFileName;
  3295. }
  3296. else
  3297. {
  3298. FullFileName = ListFileName;
  3299. }
  3300. TFileMasks::TParams MaskParams;
  3301. MaskParams.Size = DView->ItemFileSize(Item);
  3302. TDateTimePrecision Precision;
  3303. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3304. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3305. FileList->Objects[i], MaskParams);
  3306. }
  3307. }
  3308. }
  3309. __finally
  3310. {
  3311. delete FileList;
  3312. }
  3313. }
  3314. //---------------------------------------------------------------------------
  3315. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3316. {
  3317. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3318. CopyParam.FileNameCase = ncNoChange;
  3319. CopyParam.PreserveRights = false;
  3320. CopyParam.PreserveReadOnly = false;
  3321. CopyParam.ReplaceInvalidChars = true;
  3322. CopyParam.IncludeFileMask = TFileMasks();
  3323. CopyParam.NewerOnly = false;
  3324. CopyParam.FileMask = L"";
  3325. }
  3326. //---------------------------------------------------------------------------
  3327. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3328. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3329. {
  3330. TTerminalManager * Manager = TTerminalManager::Instance();
  3331. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3332. {
  3333. if (!NonVisualDataModule->Busy)
  3334. {
  3335. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3336. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3337. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3338. if (Data->Terminal == NULL)
  3339. {
  3340. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3341. if (SameSiteTerminal != NULL)
  3342. {
  3343. UnicodeString Message =
  3344. FMTLOAD(EDIT_SESSION_REATTACH,
  3345. (FileNameOnly, Data->SessionName, FileNameOnly));
  3346. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3347. {
  3348. Data->Terminal = Terminal;
  3349. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3350. Data->SessionName = Terminal->SessionData->SessionName;
  3351. // We might also overwrite session data
  3352. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3353. }
  3354. else
  3355. {
  3356. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3357. Abort();
  3358. }
  3359. }
  3360. }
  3361. // foreground session should reconnect itself
  3362. else if (Terminal != Data->Terminal)
  3363. {
  3364. UnicodeString Message =
  3365. MainInstructions(
  3366. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3367. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3368. {
  3369. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3370. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3371. }
  3372. else
  3373. {
  3374. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3375. Abort();
  3376. }
  3377. }
  3378. }
  3379. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3380. {
  3381. Configuration->Usage->Inc(L"EditInactiveSession");
  3382. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3383. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3384. (ExtractFileName(FileName), Data->SessionName)));
  3385. }
  3386. }
  3387. TStrings * FileList = new TStringList();
  3388. try
  3389. {
  3390. FileList->Add(FileName);
  3391. // consider using the same settings (preset) as when the file was downloaded
  3392. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3393. TemporaryFileCopyParam(CopyParam);
  3394. if (Data->ForceText)
  3395. {
  3396. CopyParam.TransferMode = tmAscii;
  3397. }
  3398. // so i do not need to worry if masking algorithm works in all cases
  3399. // ("" means "copy file name", no masking is actually done)
  3400. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3401. {
  3402. CopyParam.FileMask = L"";
  3403. }
  3404. else
  3405. {
  3406. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3407. }
  3408. DebugAssert(Data->Queue != NULL);
  3409. int Params = cpNoConfirmation | cpTemporary;
  3410. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3411. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3412. QueueItem->CompleteEvent = UploadCompleteEvent;
  3413. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3414. }
  3415. __finally
  3416. {
  3417. delete FileList;
  3418. }
  3419. }
  3420. //---------------------------------------------------------------------------
  3421. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3422. const UnicodeString FileName, const TEditedFileData * Data)
  3423. {
  3424. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3425. DebugAssert(!NonVisualDataModule->Busy);
  3426. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3427. {
  3428. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3429. (ExtractFileName(FileName), Data->SessionName)));
  3430. }
  3431. TTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3432. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3433. NonVisualDataModule->StartBusy();
  3434. try
  3435. {
  3436. std::unique_ptr<TRemoteFile> File;
  3437. UnicodeString RemoteFileName =
  3438. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3439. FTerminal->ExceptionOnFail = true;
  3440. try
  3441. {
  3442. TRemoteFile * AFile = NULL;
  3443. FTerminal->ReadFile(RemoteFileName, AFile);
  3444. File.reset(AFile);
  3445. if (!File->HaveFullFileName)
  3446. {
  3447. File->FullFileName = RemoteFileName;
  3448. }
  3449. }
  3450. __finally
  3451. {
  3452. FTerminal->ExceptionOnFail = false;
  3453. }
  3454. std::unique_ptr<TStrings> FileList(new TStringList());
  3455. FileList->AddObject(RemoteFileName, File.get());
  3456. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3457. UnicodeString TempDir = ExtractFilePath(FileName);
  3458. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3459. TempDir, true, true, true);
  3460. // sanity check, the target file name should be still the same
  3461. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3462. }
  3463. __finally
  3464. {
  3465. NonVisualDataModule->EndBusy();
  3466. // it actually may not exist anymore...
  3467. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3468. }
  3469. }
  3470. //---------------------------------------------------------------------------
  3471. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3472. const TEditedFileData * Data, bool & KeepOpen)
  3473. {
  3474. // Command is set for external editors only (not for "shell" open).
  3475. if (!Data->Command.IsEmpty())
  3476. {
  3477. bool AnyFound = false;
  3478. bool AnyMDI = false;
  3479. bool AnyNonMDI = false;
  3480. bool AnyDetect = false;
  3481. TEditorList * EditorList = new TEditorList();
  3482. try
  3483. {
  3484. *EditorList = *WinConfiguration->EditorList;
  3485. for (int i = 0; i < EditorList->Count; i++)
  3486. {
  3487. const TEditorPreferences * Editor = EditorList->Editors[i];
  3488. if ((Editor->Data->Editor == edExternal) &&
  3489. (Editor->Data->ExternalEditor == Data->Command))
  3490. {
  3491. AnyFound = true;
  3492. if (Editor->Data->SDIExternalEditor)
  3493. {
  3494. AnyNonMDI = true;
  3495. if (Editor->Data->DetectMDIExternalEditor)
  3496. {
  3497. AnyDetect = true;
  3498. }
  3499. }
  3500. else
  3501. {
  3502. AnyMDI = true;
  3503. }
  3504. }
  3505. }
  3506. bool EnableMDI = false;
  3507. bool DisableDetect = false;
  3508. if (AnyMDI)
  3509. {
  3510. KeepOpen = true;
  3511. if (AnyNonMDI)
  3512. {
  3513. // there is at least one instance of the editor with MDI support enabled,
  3514. // and one with disabled, enable it for all instances
  3515. EnableMDI = true;
  3516. }
  3517. }
  3518. else if (AnyFound && !AnyDetect)
  3519. {
  3520. // at least once instance found but all have MDI autodetection disabled
  3521. // => close the file (default action)
  3522. }
  3523. else
  3524. {
  3525. // no instance of the editor has MDI support enabled
  3526. TMessageParams Params;
  3527. if (AnyFound)
  3528. {
  3529. // there is at least one instance of the editor
  3530. Params.Params |= mpNeverAskAgainCheck;
  3531. }
  3532. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3533. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3534. switch (Answer)
  3535. {
  3536. case qaNeverAskAgain:
  3537. DisableDetect = true;
  3538. break;
  3539. case qaNo:
  3540. EnableMDI = true;
  3541. KeepOpen = true;
  3542. break;
  3543. }
  3544. }
  3545. if (AnyFound && (EnableMDI || DisableDetect))
  3546. {
  3547. bool Changed = false;
  3548. for (int i = 0; i < EditorList->Count; i++)
  3549. {
  3550. const TEditorPreferences * Editor = EditorList->Editors[i];
  3551. if ((Editor->Data->Editor == edExternal) &&
  3552. (Editor->Data->ExternalEditor == Data->Command) &&
  3553. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3554. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3555. {
  3556. Changed = true;
  3557. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3558. if (EnableMDI)
  3559. {
  3560. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3561. }
  3562. if (DisableDetect)
  3563. {
  3564. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3565. }
  3566. EditorList->Change(i, UpdatedEditor);
  3567. }
  3568. }
  3569. if (Changed)
  3570. {
  3571. WinConfiguration->EditorList = EditorList;
  3572. }
  3573. }
  3574. }
  3575. __finally
  3576. {
  3577. delete EditorList;
  3578. }
  3579. }
  3580. else
  3581. {
  3582. // "open" case
  3583. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3584. qaOK, HELP_APP_EARLY_CLOSED);
  3585. }
  3586. }
  3587. //---------------------------------------------------------------------------
  3588. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3589. {
  3590. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3591. }
  3592. //---------------------------------------------------------------------------
  3593. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3594. {
  3595. SideEnter(osRemote);
  3596. }
  3597. //---------------------------------------------------------------------------
  3598. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3599. {
  3600. MakeNextInTabOrder(RemoteDirView, RemoteDriveView);
  3601. SideEnter(osRemote);
  3602. }
  3603. //---------------------------------------------------------------------------
  3604. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3605. {
  3606. FCurrentSide = Side;
  3607. if (Visible)
  3608. {
  3609. UpdateControls();
  3610. }
  3611. }
  3612. //---------------------------------------------------------------------------
  3613. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3614. TStrings * FileList, bool Alternative)
  3615. {
  3616. TCustomDirView * DView = DirView(Side);
  3617. DView->SaveSelection();
  3618. DView->SaveSelectedNames();
  3619. DebugAssert(!FAlternativeDelete);
  3620. FAlternativeDelete = Alternative;
  3621. try
  3622. {
  3623. if (Side == osRemote)
  3624. {
  3625. DebugAssert(Terminal != NULL);
  3626. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3627. }
  3628. else
  3629. {
  3630. try
  3631. {
  3632. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3633. }
  3634. __finally
  3635. {
  3636. ReloadLocalDirectory();
  3637. }
  3638. }
  3639. FAlternativeDelete = false;
  3640. }
  3641. catch(...)
  3642. {
  3643. FAlternativeDelete = false;
  3644. DView->DiscardSavedSelection();
  3645. throw;
  3646. }
  3647. DView->RestoreSelection();
  3648. }
  3649. //---------------------------------------------------------------------------
  3650. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3651. {
  3652. DebugAssert(Terminal);
  3653. RemoteDirView->SaveSelection();
  3654. RemoteDirView->SaveSelectedNames();
  3655. try
  3656. {
  3657. if (Lock)
  3658. {
  3659. Terminal->LockFiles(FileList);
  3660. }
  3661. else
  3662. {
  3663. Terminal->UnlockFiles(FileList);
  3664. }
  3665. }
  3666. catch(...)
  3667. {
  3668. RemoteDirView->DiscardSavedSelection();
  3669. throw;
  3670. }
  3671. RemoteDirView->RestoreSelection();
  3672. }
  3673. //---------------------------------------------------------------------------
  3674. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TTerminal *& Session,
  3675. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3676. bool NoConfirmation, bool Move)
  3677. {
  3678. DebugAssert(Terminal != NULL);
  3679. // update Terminal->StateData->RemoteDirectory
  3680. UpdateTerminal(Terminal);
  3681. if (Session == NULL)
  3682. {
  3683. Session = TTerminalManager::Instance()->ActiveTerminal;
  3684. }
  3685. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3686. {
  3687. if (RemoteDriveView->DropTarget != NULL)
  3688. {
  3689. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3690. }
  3691. else if (RemoteDirView->DropTarget != NULL)
  3692. {
  3693. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3694. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3695. }
  3696. else
  3697. {
  3698. Target = RemoteDirView->Path;
  3699. }
  3700. }
  3701. else
  3702. {
  3703. TManagedTerminal * ManagedTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(Session));
  3704. Target = ManagedTerminal->StateData->RemoteDirectory;
  3705. }
  3706. Target = UnixIncludeTrailingBackslash(Target);
  3707. if (FileList->Count == 1)
  3708. {
  3709. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3710. }
  3711. else
  3712. {
  3713. FileMask = AnyMask;
  3714. }
  3715. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3716. bool Result = true;
  3717. if (!NoConfirmation)
  3718. {
  3719. bool Multi = (FileList->Count > 1);
  3720. if (Move)
  3721. {
  3722. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3723. }
  3724. else
  3725. {
  3726. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3727. TStrings * Directories = new TStringList;
  3728. try
  3729. {
  3730. for (int Index = 0; Index < Sessions->Count; Index++)
  3731. {
  3732. TManagedTerminal * Terminal =
  3733. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3734. Directories->Add(Terminal->StateData->RemoteDirectory);
  3735. }
  3736. TDirectRemoteCopy AllowDirectCopy;
  3737. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3738. {
  3739. DebugAssert(DirectCopy);
  3740. AllowDirectCopy = drcAllow;
  3741. }
  3742. else if (FTerminal->IsCapable[fcSecondaryShell])
  3743. {
  3744. DebugAssert(DirectCopy);
  3745. AllowDirectCopy = drcConfirmCommandSession;
  3746. }
  3747. else
  3748. {
  3749. DebugAssert(!DirectCopy);
  3750. AllowDirectCopy = drcDisallow;
  3751. }
  3752. void * ASession = Session;
  3753. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3754. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3755. Session = static_cast<TTerminal *>(ASession);
  3756. }
  3757. __finally
  3758. {
  3759. delete Directories;
  3760. }
  3761. }
  3762. }
  3763. return Result;
  3764. }
  3765. //---------------------------------------------------------------------------
  3766. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3767. TStrings * FileList, bool NoConfirmation, bool Move, TTerminal * Session)
  3768. {
  3769. bool DirectCopy;
  3770. UnicodeString Target, FileMask;
  3771. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3772. if (Result)
  3773. {
  3774. if (!Move && !DirectCopy)
  3775. {
  3776. Configuration->Usage->Inc("RemoteCopyTemp");
  3777. UnicodeString RootTempDir;
  3778. UnicodeString TempDir;
  3779. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3780. TStrings * TemporaryFilesList = new TStringList();
  3781. try
  3782. {
  3783. TMakeLocalFileListParams MakeFileListParam;
  3784. MakeFileListParam.FileList = TemporaryFilesList;
  3785. MakeFileListParam.FileTimes = NULL;
  3786. MakeFileListParam.IncludeDirs = true;
  3787. MakeFileListParam.Recursive = false;
  3788. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3789. TTerminalManager::Instance()->ActiveTerminal = Session;
  3790. if (TemporaryFilesList->Count > 0)
  3791. {
  3792. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3793. CopyParam.FileMask = FileMask;
  3794. DebugAssert(!FAutoOperation);
  3795. FAutoOperation = true;
  3796. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3797. }
  3798. }
  3799. __finally
  3800. {
  3801. delete TemporaryFilesList;
  3802. FAutoOperation = false;
  3803. if (!RootTempDir.IsEmpty())
  3804. {
  3805. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3806. }
  3807. }
  3808. }
  3809. else
  3810. {
  3811. RemoteDirView->SaveSelection();
  3812. RemoteDirView->SaveSelectedNames();
  3813. try
  3814. {
  3815. if (Move)
  3816. {
  3817. Configuration->Usage->Inc("RemoteMove");
  3818. Terminal->MoveFiles(FileList, Target, FileMask);
  3819. }
  3820. else
  3821. {
  3822. Configuration->Usage->Inc("RemoteCopyDirect");
  3823. DebugAssert(DirectCopy);
  3824. DebugAssert(Session == FTerminal);
  3825. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3826. FTerminal->CommandSessionOpened ||
  3827. CommandSessionFallback())
  3828. {
  3829. Terminal->CopyFiles(FileList, Target, FileMask);
  3830. }
  3831. }
  3832. }
  3833. catch(...)
  3834. {
  3835. RemoteDirView->DiscardSavedSelection();
  3836. throw;
  3837. }
  3838. RemoteDirView->RestoreSelection();
  3839. }
  3840. }
  3841. return Result;
  3842. }
  3843. //---------------------------------------------------------------------------
  3844. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3845. const UnicodeString & Path, TRemoteProperties & Properties)
  3846. {
  3847. Properties.Valid = Properties.Valid << vpEncrypt;
  3848. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3849. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3850. }
  3851. //---------------------------------------------------------------------------
  3852. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3853. {
  3854. Side = GetSide(Side);
  3855. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3856. TRemoteProperties * AProperties = (Side == osRemote ? &Properties : NULL);
  3857. UnicodeString Name = LoadStr(NEW_FOLDER);
  3858. int AllowedChanges =
  3859. FLAGMASK((Side == osRemote) && Terminal->IsCapable[fcModeChanging], cpMode);
  3860. bool SaveSettings = false;
  3861. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3862. {
  3863. TWindowLock Lock(this);
  3864. if (Side == osRemote)
  3865. {
  3866. if (SaveSettings)
  3867. {
  3868. GUIConfiguration->NewDirectoryProperties = Properties;
  3869. }
  3870. CreateRemoteDirectory(Name, Properties);
  3871. }
  3872. else
  3873. {
  3874. DirView(Side)->CreateDirectory(Name);
  3875. }
  3876. }
  3877. }
  3878. //---------------------------------------------------------------------------
  3879. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3880. {
  3881. TWindowLock Lock(this);
  3882. DirView(Side)->ExecuteHomeDirectory();
  3883. }
  3884. //---------------------------------------------------------------------------
  3885. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3886. {
  3887. DoOpenDirectoryDialog(odBrowse, Side);
  3888. }
  3889. //---------------------------------------------------------------------------
  3890. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3891. {
  3892. UnicodeString Path = Bookmark->GetSideDirectory(Side);
  3893. bool Result = !Path.IsEmpty();
  3894. if (Result)
  3895. {
  3896. // While we might get here when the session is closed (from location profiles),
  3897. // it's not a problem as the Path setter is noop then
  3898. DirView(Side)->Path = Path;
  3899. }
  3900. return Result;
  3901. }
  3902. //---------------------------------------------------------------------------
  3903. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3904. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3905. bool & Close)
  3906. {
  3907. // terminal can be already closed (e.g. dropped connection)
  3908. if (Terminal != NULL)
  3909. {
  3910. try
  3911. {
  3912. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  3913. }
  3914. catch(...)
  3915. {
  3916. if (!Terminal->Active)
  3917. {
  3918. Close = true;
  3919. }
  3920. throw;
  3921. }
  3922. }
  3923. }
  3924. //---------------------------------------------------------------------------
  3925. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  3926. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  3927. bool & Close)
  3928. {
  3929. // terminal can be already closed (e.g. dropped connection)
  3930. if (Terminal != NULL)
  3931. {
  3932. Configuration->Usage->Inc(L"ChecksumCalculated");
  3933. try
  3934. {
  3935. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  3936. }
  3937. catch(...)
  3938. {
  3939. if (!Terminal->Active)
  3940. {
  3941. Close = true;
  3942. }
  3943. throw;
  3944. }
  3945. }
  3946. }
  3947. //---------------------------------------------------------------------------
  3948. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  3949. {
  3950. bool Result;
  3951. if (Side == osRemote)
  3952. {
  3953. TRemoteTokenList * GroupList = NULL;
  3954. TRemoteTokenList * UserList = NULL;
  3955. try
  3956. {
  3957. TRemoteProperties CurrentProperties;
  3958. if (Terminal->LoadFilesProperties(FileList))
  3959. {
  3960. RemoteDirView->Invalidate();
  3961. }
  3962. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  3963. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  3964. if (CapableGroupChanging || CapableOwnerChanging)
  3965. {
  3966. if (CapableGroupChanging)
  3967. {
  3968. GroupList = Terminal->Groups->Duplicate();
  3969. }
  3970. if (CapableOwnerChanging)
  3971. {
  3972. UserList = Terminal->Users->Duplicate();
  3973. }
  3974. TRemoteDirectory * Files = Terminal->Files;
  3975. int Count = Files->Count;
  3976. if (Count > 100)
  3977. {
  3978. Count = 100;
  3979. }
  3980. for (int Index = 0; Index < Count; Index++)
  3981. {
  3982. TRemoteFile * File = Files->Files[Index];
  3983. if (CapableGroupChanging)
  3984. {
  3985. GroupList->AddUnique(File->Group);
  3986. }
  3987. if (CapableOwnerChanging)
  3988. {
  3989. UserList->AddUnique(File->Owner);
  3990. }
  3991. }
  3992. // if we haven't collected tokens for all files in current directory,
  3993. // make sure we collect them at least for all selected files.
  3994. // (note that so far the files in FileList has to be from current direcotry)
  3995. if (Count < Files->Count)
  3996. {
  3997. for (int Index = 0; Index < FileList->Count; Index++)
  3998. {
  3999. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4000. if (CapableGroupChanging)
  4001. {
  4002. GroupList->AddUnique(File->Group);
  4003. }
  4004. if (CapableOwnerChanging)
  4005. {
  4006. UserList->AddUnique(File->Owner);
  4007. }
  4008. }
  4009. }
  4010. }
  4011. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4012. int Flags = 0;
  4013. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4014. if (CapableOwnerChanging) Flags |= cpOwner;
  4015. if (CapableGroupChanging) Flags |= cpGroup;
  4016. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4017. if (Terminal->IsCapable[fcCalculatingChecksum])
  4018. {
  4019. CalculateChecksumEvent = CalculateChecksum;
  4020. }
  4021. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4022. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4023. TRemoteProperties NewProperties = CurrentProperties;
  4024. Result =
  4025. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4026. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4027. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4028. CalculateSize, CalculateChecksumEvent);
  4029. if (Result)
  4030. {
  4031. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4032. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4033. }
  4034. }
  4035. __finally
  4036. {
  4037. delete GroupList;
  4038. delete UserList;
  4039. }
  4040. }
  4041. else
  4042. {
  4043. DirView(Side)->DisplayPropertiesMenu();
  4044. Result = true;
  4045. }
  4046. return Result;
  4047. }
  4048. //---------------------------------------------------------------------------
  4049. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4050. {
  4051. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4052. {
  4053. FIgnoreNextDialogChar = Key;
  4054. }
  4055. Key = 0;
  4056. }
  4057. //---------------------------------------------------------------------------
  4058. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4059. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4060. {
  4061. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4062. if (Command != NULL)
  4063. {
  4064. KeyProcessed(Key, Shift);
  4065. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4066. {
  4067. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4068. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4069. false, false, const_cast<TCustomCommandType *>(Command));
  4070. }
  4071. }
  4072. }
  4073. //---------------------------------------------------------------------------
  4074. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4075. {
  4076. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4077. {
  4078. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4079. }
  4080. if (!DirView(osCurrent)->IsEditing())
  4081. {
  4082. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4083. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4084. {
  4085. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4086. if (((Action->ShortCut == KeyShortCut) ||
  4087. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4088. AllowedAction(Action, aaShortCut))
  4089. {
  4090. // Has to be called before the action as the dialog char is already in queue.
  4091. // So when the action consumes message queue, we already need to have the
  4092. // FIgnoreNextDialogChar set
  4093. KeyProcessed(Key, Shift);
  4094. // Reset reference to previous component (when menu/toolbar was clicked).
  4095. // Needed to detect that action was invoked by keyboard shortcut
  4096. // in TNonVisualDataModule::ExplorerActionsExecute
  4097. Action->ActionComponent = NULL;
  4098. Action->Execute();
  4099. return;
  4100. }
  4101. }
  4102. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4103. {
  4104. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4105. {
  4106. KeyProcessed(Key, Shift);
  4107. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4108. return;
  4109. }
  4110. }
  4111. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4112. {
  4113. KeyProcessed(Key, Shift);
  4114. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4115. }
  4116. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4117. if (IsCustomShortCut(CustomShortCut))
  4118. {
  4119. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4120. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4121. if (WinConfiguration->SharedBookmarks != NULL)
  4122. {
  4123. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4124. if ((Bookmark != NULL) &&
  4125. OpenBookmark(FCurrentSide, Bookmark))
  4126. {
  4127. KeyProcessed(Key, Shift);
  4128. }
  4129. }
  4130. }
  4131. }
  4132. TForm::KeyDown(Key, Shift);
  4133. }
  4134. //---------------------------------------------------------------------------
  4135. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4136. {
  4137. DebugAssert(Terminal != NULL);
  4138. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4139. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4140. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4141. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4142. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4143. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4144. // expanded from ?: to avoid memory leaks
  4145. if (SecurityEnabled)
  4146. {
  4147. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4148. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4149. }
  4150. else
  4151. {
  4152. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4153. }
  4154. if (FileSystemInfo.ProtocolName.IsEmpty())
  4155. {
  4156. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4157. }
  4158. else
  4159. {
  4160. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4161. }
  4162. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4163. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4164. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4165. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4166. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4167. UnicodeString CompressionStr = CSCompressionStr;
  4168. if (CSCompressionStr != SCCompressionStr)
  4169. {
  4170. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4171. }
  4172. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4173. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4174. UpdateStatusBar();
  4175. }
  4176. //---------------------------------------------------------------------------
  4177. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4178. {
  4179. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4180. DebugAssert(SessionStatusBar != NULL);
  4181. if (!Terminal || !Terminal->Active || Terminal->Status < ssOpened)
  4182. {
  4183. // note: (Terminal->Status < sshReady) currently never happens here,
  4184. // so STATUS_CONNECTING is never used
  4185. SessionStatusBar->SimplePanel = true;
  4186. SessionStatusBar->SimpleText = LoadStr(
  4187. !Terminal || !Terminal->Active ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4188. }
  4189. else
  4190. {
  4191. DebugAssert(Terminal);
  4192. SessionStatusBar->SimplePanel = false;
  4193. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4194. if (!FNote.IsEmpty())
  4195. {
  4196. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4197. }
  4198. else
  4199. {
  4200. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4201. }
  4202. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4203. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4204. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4205. }
  4206. }
  4207. //---------------------------------------------------------------------------
  4208. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4209. {
  4210. Panel->Caption = L"";
  4211. }
  4212. //---------------------------------------------------------------------------
  4213. void __fastcall TCustomScpExplorerForm::Idle()
  4214. {
  4215. if (FShowing || FStandaloneEditing)
  4216. {
  4217. FEditorManager->Check();
  4218. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4219. // that needs to know if queue view is visible (and it may be closed after queue update)
  4220. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4221. }
  4222. if (FShowing)
  4223. {
  4224. if (!NonVisualDataModule->Busy &&
  4225. // Menu is opened or drag&drop is going on
  4226. (Mouse->Capture == NULL))
  4227. {
  4228. if (FRefreshRemoteDirectory)
  4229. {
  4230. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4231. {
  4232. Terminal->RefreshDirectory();
  4233. }
  4234. FRefreshRemoteDirectory = false;
  4235. }
  4236. if (FRefreshLocalDirectory)
  4237. {
  4238. ReloadLocalDirectory();
  4239. FRefreshLocalDirectory = false;
  4240. }
  4241. if (WinConfiguration->RefreshRemotePanel)
  4242. {
  4243. TManagedTerminal * ManagedTerminal =
  4244. dynamic_cast<TManagedTerminal *>(Terminal);
  4245. if ((ManagedTerminal != NULL) && (Terminal->Status == ssOpened) &&
  4246. (Now() - ManagedTerminal->DirectoryLoaded >
  4247. WinConfiguration->RefreshRemotePanelInterval))
  4248. {
  4249. RemoteDirView->ReloadDirectory();
  4250. }
  4251. }
  4252. }
  4253. }
  4254. if (FShowing || FStandaloneEditing)
  4255. {
  4256. if (FQueueStatusInvalidated)
  4257. {
  4258. UpdateQueueStatus(false);
  4259. }
  4260. RefreshQueueItems();
  4261. }
  4262. if (FShowing)
  4263. {
  4264. UpdateStatusBar();
  4265. }
  4266. FIgnoreNextDialogChar = 0;
  4267. }
  4268. //---------------------------------------------------------------------------
  4269. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4270. {
  4271. try
  4272. {
  4273. FUserActionTimer->Enabled = false;
  4274. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4275. {
  4276. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4277. {
  4278. FPendingQueueActionItem->ProcessUserAction();
  4279. }
  4280. }
  4281. }
  4282. __finally
  4283. {
  4284. FPendingQueueActionItem = NULL;
  4285. }
  4286. }
  4287. //---------------------------------------------------------------------------
  4288. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4289. {
  4290. if (WinConfiguration->MinimizeToTray)
  4291. {
  4292. UpdateTrayIcon();
  4293. FTrayIcon->Visible = true;
  4294. if (Visible)
  4295. {
  4296. ShowWindow(Handle, SW_HIDE);
  4297. }
  4298. }
  4299. }
  4300. //---------------------------------------------------------------------------
  4301. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4302. {
  4303. // WORKAROUND
  4304. // When restoring maximized window from minimization,
  4305. // rarely some controls do not align properly.
  4306. // Two instances seen (both for Commander):
  4307. // - When restoring, window is temporarily narrower (not maximized),
  4308. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4309. // Once maximized already, top dock shinks back, but the session PageControl,
  4310. // do not align up, leaving space between TopDock and PageControl.
  4311. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4312. for (int Index = 0; Index < ControlCount; Index++)
  4313. {
  4314. RealignControl(Controls[Index]);
  4315. }
  4316. if (FTrayIcon->Visible)
  4317. {
  4318. FTrayIcon->Visible = false;
  4319. if (Visible)
  4320. {
  4321. ShowWindow(Handle, SW_SHOW);
  4322. }
  4323. }
  4324. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4325. {
  4326. FNeedSession = false;
  4327. NonVisualDataModule->StartBusy();
  4328. try
  4329. {
  4330. NeedSession(false);
  4331. }
  4332. __finally
  4333. {
  4334. NonVisualDataModule->EndBusy();
  4335. }
  4336. }
  4337. }
  4338. //---------------------------------------------------------------------------
  4339. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4340. {
  4341. FTrayIcon->Hint = GetMainForm()->Caption;
  4342. }
  4343. //---------------------------------------------------------------------------
  4344. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4345. {
  4346. UpdateTrayIcon();
  4347. }
  4348. //---------------------------------------------------------------------------
  4349. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4350. {
  4351. // workaround
  4352. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4353. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4354. // But WM_ACTIVATEAPP message can be received even when
  4355. // the main window is minimized to the tray and internal editor window is focused
  4356. // (after another application was previously active)
  4357. if (::IsIconic(Handle))
  4358. {
  4359. if (!IsAppIconic())
  4360. {
  4361. SetAppIconic(true);
  4362. }
  4363. }
  4364. ::ApplicationRestore();
  4365. Application->BringToFront();
  4366. }
  4367. //---------------------------------------------------------------------------
  4368. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4369. {
  4370. RestoreApp();
  4371. }
  4372. //---------------------------------------------------------------------------
  4373. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4374. {
  4375. if (OpenInNewWindow())
  4376. {
  4377. // todo: Pass FromSite
  4378. ExecuteNewInstance(SessionUrl);
  4379. }
  4380. else
  4381. {
  4382. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4383. }
  4384. }
  4385. //---------------------------------------------------------------------------
  4386. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4387. {
  4388. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4389. // current working directories become defaults here, what is not right
  4390. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4391. StoredSessions->NewSession(SessionName, SessionData.get());
  4392. // modified only, explicit
  4393. StoredSessions->Save(false, true);
  4394. // encode session name because of slashes in hierarchical sessions
  4395. return EncodeUrlString(SessionName);
  4396. }
  4397. //---------------------------------------------------------------------------
  4398. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4399. {
  4400. if (OpenInNewWindow())
  4401. {
  4402. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4403. }
  4404. else
  4405. {
  4406. // current working directories become defaults here, what is not right
  4407. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4408. TTerminalManager * Manager = TTerminalManager::Instance();
  4409. TTerminal * Terminal = Manager->NewTerminal(SessionData.get());
  4410. Manager->ActiveTerminal = Terminal;
  4411. }
  4412. }
  4413. //---------------------------------------------------------------------------
  4414. void __fastcall TCustomScpExplorerForm::RenameSession()
  4415. {
  4416. UnicodeString Name = Terminal->SessionData->Name;
  4417. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4418. {
  4419. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4420. TSessionData::ValidateName(Name);
  4421. // This is inconsistent with how color (for example) is handled.
  4422. Terminal->SessionData->Name = Name;
  4423. UpdateControls();
  4424. // Add/Remove distinguishing paths from sessions of the same name.
  4425. DoTerminalListChanged();
  4426. }
  4427. }
  4428. //---------------------------------------------------------------------------
  4429. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4430. {
  4431. DebugAssert(Queue != NULL);
  4432. bool Result = Queue->IsEmpty;
  4433. if (!Result)
  4434. {
  4435. SetFocus();
  4436. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4437. }
  4438. return Result;
  4439. }
  4440. //---------------------------------------------------------------------------
  4441. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4442. {
  4443. return CanCloseQueue(FQueue);
  4444. }
  4445. //---------------------------------------------------------------------------
  4446. void __fastcall TCustomScpExplorerForm::CloseSession()
  4447. {
  4448. if (CanCloseQueue())
  4449. {
  4450. TTerminalManager::Instance()->FreeActiveTerminal();
  4451. }
  4452. }
  4453. //---------------------------------------------------------------------------
  4454. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4455. {
  4456. if (OpenInNewWindow())
  4457. {
  4458. // encode session name because of slashes in hierarchical sessions
  4459. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4460. }
  4461. else
  4462. {
  4463. TTerminalManager * Manager = TTerminalManager::Instance();
  4464. TTerminal * Terminal = Manager->NewTerminal(Data);
  4465. Manager->ActiveTerminal = Terminal;
  4466. }
  4467. }
  4468. //---------------------------------------------------------------------------
  4469. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4470. {
  4471. if (OpenInNewWindow())
  4472. {
  4473. ExecuteNewInstance(Name);
  4474. }
  4475. else
  4476. {
  4477. TTerminalManager * Manager = TTerminalManager::Instance();
  4478. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4479. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4480. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  4481. }
  4482. }
  4483. //---------------------------------------------------------------------------
  4484. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4485. bool &CanClose)
  4486. {
  4487. if (Terminal != NULL)
  4488. {
  4489. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4490. {
  4491. unsigned int Result;
  4492. TMessageParams Params(mpNeverAskAgainCheck);
  4493. UnicodeString Message;
  4494. int Answers = qaOK | qaCancel;
  4495. if (TTerminalManager::Instance()->Count > 1)
  4496. {
  4497. if (!WinConfiguration->AutoSaveWorkspace)
  4498. {
  4499. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE2);
  4500. Answers = qaYes | qaNo | qaCancel;
  4501. }
  4502. else
  4503. {
  4504. Message = MainInstructions(LoadStr(CLOSE_SESSIONS));
  4505. }
  4506. }
  4507. else
  4508. {
  4509. Message = MainInstructions(FMTLOAD(CLOSE_SESSION, (Terminal->SessionData->SessionName)));
  4510. }
  4511. if (WinConfiguration->AutoSaveWorkspace)
  4512. {
  4513. Message =
  4514. FORMAT("%s\n\n%s", (Message,
  4515. FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()))));
  4516. }
  4517. SetFocus();
  4518. Result = MessageDialog(Message, qtConfirmation,
  4519. Answers, HELP_NONE, &Params);
  4520. if (Result == qaNeverAskAgain)
  4521. {
  4522. WinConfiguration->ConfirmClosingSession = false;
  4523. }
  4524. if (Result == qaNo)
  4525. {
  4526. CanClose = SaveWorkspace(true);
  4527. // note that the workspace will be saved redundatly again from FormClose
  4528. }
  4529. else
  4530. {
  4531. CanClose =
  4532. (Result == qaOK) ||
  4533. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4534. (Result == qaNeverAskAgain);
  4535. }
  4536. }
  4537. if (CanClose)
  4538. {
  4539. CanClose = CanCloseQueue();
  4540. }
  4541. }
  4542. if (CanClose)
  4543. {
  4544. CanClose =
  4545. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4546. FEditorManager->CloseExternalFilesWithoutProcess();
  4547. if (CanClose)
  4548. {
  4549. while (CanClose && (FLocalEditors->Count > 0))
  4550. {
  4551. int PrevCount = FLocalEditors->Count;
  4552. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4553. CanClose = (FLocalEditors->Count < PrevCount);
  4554. }
  4555. if (CanClose)
  4556. {
  4557. CanClose = FEditorManager->Empty(true);
  4558. if (!CanClose)
  4559. {
  4560. SetFocus();
  4561. CanClose =
  4562. (MessageDialog(
  4563. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4564. }
  4565. }
  4566. }
  4567. }
  4568. }
  4569. //---------------------------------------------------------------------------
  4570. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4571. {
  4572. TForm * Form = dynamic_cast<TForm *>(Sender);
  4573. DebugAssert(Form != NULL);
  4574. Form->Close();
  4575. }
  4576. //---------------------------------------------------------------------------
  4577. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4578. {
  4579. TForm * Form = dynamic_cast<TForm *>(Sender);
  4580. delete Form;
  4581. }
  4582. //---------------------------------------------------------------------------
  4583. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4584. {
  4585. while (FLocalEditors->Count > 0)
  4586. {
  4587. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4588. }
  4589. }
  4590. //---------------------------------------------------------------------------
  4591. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4592. TObject *Sender)
  4593. {
  4594. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4595. try
  4596. {
  4597. SetProperties(osRemote, FileList);
  4598. }
  4599. __finally
  4600. {
  4601. delete FileList;
  4602. }
  4603. }
  4604. //---------------------------------------------------------------------------
  4605. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4606. {
  4607. if (value)
  4608. {
  4609. if (Component == fcCustomCommandsBand)
  4610. {
  4611. UpdateCustomCommandsToolbar();
  4612. }
  4613. }
  4614. }
  4615. //---------------------------------------------------------------------------
  4616. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4617. {
  4618. TControl * Control = GetComponent(Component);
  4619. DebugAssert(Control);
  4620. bool Changed = (Control->Visible != value);
  4621. if (Changed)
  4622. {
  4623. ComponentShowing(Component, value);
  4624. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4625. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4626. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4627. if (value)
  4628. {
  4629. int RemainingHeight = Control->Parent->ClientHeight;
  4630. int RemainingWidth = Control->Parent->ClientWidth;
  4631. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4632. {
  4633. TControl * ChildControl = Control->Parent->Controls[i];
  4634. if (ChildControl->Visible)
  4635. {
  4636. switch (ChildControl->Align)
  4637. {
  4638. case alTop:
  4639. case alBottom:
  4640. RemainingHeight -= ChildControl->Height;
  4641. break;
  4642. case alLeft:
  4643. case alRight:
  4644. RemainingWidth -= ChildControl->Width;
  4645. break;
  4646. }
  4647. }
  4648. }
  4649. int Reserve = ScaleByTextHeight(this, 32);
  4650. // queue in explorer, trees in commander
  4651. if (Control->Height > RemainingHeight - Reserve)
  4652. {
  4653. Control->Height = RemainingHeight / 2;
  4654. }
  4655. if (Control->Width > RemainingWidth - Reserve)
  4656. {
  4657. Control->Width = RemainingWidth / 2;
  4658. }
  4659. }
  4660. Control->Visible = value;
  4661. if (WasFocused && Visible)
  4662. {
  4663. DirView(osCurrent)->SetFocus();
  4664. }
  4665. FixControlsPlacement();
  4666. }
  4667. }
  4668. //---------------------------------------------------------------------------
  4669. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4670. {
  4671. TControl * Control = GetComponent(Component);
  4672. if (Control == NULL)
  4673. {
  4674. return false;
  4675. }
  4676. else
  4677. {
  4678. return Control->Visible;
  4679. }
  4680. }
  4681. //---------------------------------------------------------------------------
  4682. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4683. {
  4684. bool Result;
  4685. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4686. {
  4687. Result = !IsUWP();
  4688. }
  4689. else
  4690. {
  4691. Result = true;
  4692. }
  4693. return Result;
  4694. }
  4695. //---------------------------------------------------------------------------
  4696. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4697. {
  4698. if (RemoteDirView->ItemFocused != NULL)
  4699. {
  4700. RemoteDirView->ItemFocused->MakeVisible(false);
  4701. }
  4702. QueueSplitter->Visible = QueuePanel->Visible;
  4703. RemotePanelSplitter->Visible = RemoteDriveView->Visible;
  4704. }
  4705. //---------------------------------------------------------------------------
  4706. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4707. {
  4708. switch (Component) {
  4709. case fcStatusBar: return RemoteStatusBar;
  4710. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4711. case fcQueueView: return QueuePanel;
  4712. case fcQueueToolbar: return QueueDock;
  4713. case fcRemoteTree: return RemoteDriveView;
  4714. case fcSessionsTabs: return SessionsPageControl;
  4715. default: return NULL;
  4716. }
  4717. }
  4718. //---------------------------------------------------------------------------
  4719. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4720. TObject *Sender, TListColumn *Column, TPoint &Point)
  4721. {
  4722. DebugAssert(NonVisualDataModule && Column && Sender);
  4723. NonVisualDataModule->ListColumn = Column;
  4724. TPopupMenu * DirViewColumnMenu;
  4725. if (Sender == RemoteDirView)
  4726. {
  4727. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4728. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4729. (Column->Index == uvName);
  4730. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4731. (Column->Index == uvSize);
  4732. }
  4733. else
  4734. {
  4735. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4736. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4737. (Column->Index == dvName);
  4738. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4739. (Column->Index == dvSize);
  4740. }
  4741. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4742. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4743. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4744. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4745. }
  4746. //---------------------------------------------------------------------------
  4747. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4748. TObject *Sender, TListItem *Item, bool &AllowExec)
  4749. {
  4750. DoDirViewExecFile(Sender, Item, AllowExec);
  4751. }
  4752. //---------------------------------------------------------------------------
  4753. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4754. TListItem * Item, bool & AllowExec)
  4755. {
  4756. DebugAssert(Sender && Item && Configuration);
  4757. DebugAssert(AllowExec);
  4758. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4759. bool Remote = (ADirView == DirView(osRemote));
  4760. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks;
  4761. TOperationSide Side = (Remote ? osRemote : osLocal);
  4762. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4763. // on files only (not directories)
  4764. // and only when symlinks are resolved (apply to remote panel only)
  4765. if (!ADirView->ItemIsDirectory(Item) &&
  4766. (ResolvedSymlinks || FForceExecution || Terminal->IsEncryptingFiles()))
  4767. {
  4768. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4769. !FForceExecution &&
  4770. (ResolvedSymlinks || Terminal->IsEncryptingFiles()))
  4771. {
  4772. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4773. {
  4774. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4775. UnlockWindow();
  4776. try
  4777. {
  4778. ExecuteFileOperation(
  4779. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4780. }
  4781. __finally
  4782. {
  4783. LockWindow();
  4784. }
  4785. AllowExec = false;
  4786. }
  4787. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4788. {
  4789. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4790. {
  4791. ExecuteFile(Side, efDefaultEditor);
  4792. AllowExec = false;
  4793. }
  4794. }
  4795. else
  4796. {
  4797. DebugFail();
  4798. }
  4799. }
  4800. // if we have not done anything special, fall back to default behavior
  4801. if (AllowExec)
  4802. {
  4803. if (Remote && !WinConfiguration->DisableOpenEdit)
  4804. {
  4805. ExecuteFile(osRemote, efShell);
  4806. AllowExec = false;
  4807. }
  4808. }
  4809. }
  4810. }
  4811. //---------------------------------------------------------------------------
  4812. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4813. {
  4814. return ((Side == osRemote) || (Side == osCurrent));
  4815. }
  4816. //---------------------------------------------------------------------------
  4817. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  4818. {
  4819. DebugFail();
  4820. }
  4821. //---------------------------------------------------------------------------
  4822. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  4823. {
  4824. DebugFail();
  4825. }
  4826. //---------------------------------------------------------------------------
  4827. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  4828. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, bool UseDefaults)
  4829. {
  4830. TSynchronizeParamType Params;
  4831. Params.LocalDirectory = LocalDirectory;
  4832. Params.RemoteDirectory = RemoteDirectory;
  4833. int UnusedParams =
  4834. (GUIConfiguration->SynchronizeParams &
  4835. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize));
  4836. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  4837. Params.Options = GUIConfiguration->SynchronizeOptions;
  4838. bool SaveSettings = false;
  4839. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  4840. &DoSynchronizeTooManyDirectories);
  4841. DebugAssert(FSynchronizeController == NULL);
  4842. FSynchronizeController = &Controller;
  4843. bool Result;
  4844. try
  4845. {
  4846. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4847. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  4848. int Options =
  4849. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  4850. DebugAssert(FOnFeedSynchronizeError == NULL);
  4851. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  4852. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  4853. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  4854. if (Result)
  4855. {
  4856. if (SaveSettings)
  4857. {
  4858. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  4859. GUIConfiguration->SynchronizeOptions = Params.Options;
  4860. }
  4861. else
  4862. {
  4863. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  4864. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  4865. FLAGSET(Params.Options, soSynchronize))
  4866. {
  4867. GUIConfiguration->SynchronizeOptions =
  4868. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  4869. soSynchronize;
  4870. }
  4871. }
  4872. LocalDirectory = Params.LocalDirectory;
  4873. RemoteDirectory = Params.RemoteDirectory;
  4874. }
  4875. }
  4876. __finally
  4877. {
  4878. FSynchronizeController = NULL;
  4879. DebugAssert(FOnFeedSynchronizeError == NULL);
  4880. FOnFeedSynchronizeError = NULL;
  4881. }
  4882. return Result;
  4883. }
  4884. //---------------------------------------------------------------------------
  4885. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  4886. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  4887. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  4888. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  4889. TSynchronizeOptions * Options, bool Full)
  4890. {
  4891. // Keep-up-to-date mode
  4892. if (Terminal->Status == ssOpened)
  4893. {
  4894. try
  4895. {
  4896. int PParams = Params.Params;
  4897. if (!Full)
  4898. {
  4899. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  4900. if (FLAGSET(Params.Options, soRecurse))
  4901. {
  4902. PParams |= TTerminal::spSubDirs;
  4903. }
  4904. }
  4905. else
  4906. {
  4907. // if keepuptodate is non-recursive,
  4908. // full sync before has to be non-recursive as well
  4909. if (FLAGCLEAR(Params.Options, soRecurse))
  4910. {
  4911. PParams |= TTerminal::spNoRecurse;
  4912. }
  4913. }
  4914. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  4915. PParams, Checklist, Options);
  4916. }
  4917. catch (Exception & E)
  4918. {
  4919. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  4920. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  4921. {
  4922. // noop, already logged in MoreMessageDialog
  4923. }
  4924. else
  4925. {
  4926. ShowExtendedExceptionEx(Terminal, &E);
  4927. throw;
  4928. }
  4929. }
  4930. }
  4931. }
  4932. //---------------------------------------------------------------------------
  4933. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  4934. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  4935. const UnicodeString ErrorStr)
  4936. {
  4937. if (!Directory.IsEmpty())
  4938. {
  4939. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  4940. }
  4941. else
  4942. {
  4943. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  4944. }
  4945. }
  4946. //---------------------------------------------------------------------------
  4947. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  4948. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  4949. {
  4950. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  4951. {
  4952. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  4953. }
  4954. else
  4955. {
  4956. TMessageParams Params(mpNeverAskAgainCheck);
  4957. unsigned int Result = MessageDialog(
  4958. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  4959. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  4960. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  4961. {
  4962. MaxDirectories *= 2;
  4963. if (Result == qaNeverAskAgain)
  4964. {
  4965. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  4966. }
  4967. }
  4968. else
  4969. {
  4970. Abort();
  4971. }
  4972. }
  4973. }
  4974. //---------------------------------------------------------------------------
  4975. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  4976. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  4977. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  4978. TSynchronizeOptions * Options)
  4979. {
  4980. // Keep-up-to-date mode
  4981. DebugAssert(!FAutoOperation);
  4982. void * BatchStorage;
  4983. BatchStart(BatchStorage);
  4984. FAutoOperation = true;
  4985. bool AnyOperation = false;
  4986. TDateTime StartTime = Now();
  4987. TSynchronizeChecklist * AChecklist = NULL;
  4988. try
  4989. {
  4990. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  4991. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  4992. {
  4993. FSynchronizeProgressForm->Start();
  4994. }
  4995. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  4996. static_cast<TTerminal::TSynchronizeMode>(Mode),
  4997. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  4998. Options);
  4999. SAFE_DESTROY(FSynchronizeProgressForm);
  5000. AnyOperation = (AChecklist->CheckedCount > 0);
  5001. if (AnyOperation)
  5002. {
  5003. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5004. CreateProgressForm(&SynchronizeProgress);
  5005. try
  5006. {
  5007. Terminal->SynchronizeApply(
  5008. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5009. SynchronizeProcessedItem, NULL, NULL, NULL);
  5010. }
  5011. __finally
  5012. {
  5013. DestroyProgressForm();
  5014. }
  5015. }
  5016. }
  5017. __finally
  5018. {
  5019. if (Checklist == NULL)
  5020. {
  5021. delete AChecklist;
  5022. }
  5023. else
  5024. {
  5025. *Checklist = AChecklist;
  5026. }
  5027. FAutoOperation = false;
  5028. SAFE_DESTROY(FSynchronizeProgressForm);
  5029. BatchEnd(BatchStorage);
  5030. ReloadLocalDirectory();
  5031. if (AnyOperation)
  5032. {
  5033. OperationComplete(StartTime);
  5034. }
  5035. }
  5036. }
  5037. //---------------------------------------------------------------------------
  5038. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5039. {
  5040. // can be called from command line
  5041. return Visible &&
  5042. ((DirView(osRemote)->SelCount > 0) ||
  5043. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5044. }
  5045. //---------------------------------------------------------------------------
  5046. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5047. {
  5048. LogSynchronizeEvent(Terminal, Message);
  5049. }
  5050. //---------------------------------------------------------------------------
  5051. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5052. int Params, TSynchronizeOptions & Options)
  5053. {
  5054. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5055. {
  5056. Options.Filter = new TStringList();
  5057. Options.Filter->CaseSensitive = false;
  5058. Options.Filter->Duplicates = Types::dupAccept;
  5059. if (DirView(osRemote)->SelCount > 0)
  5060. {
  5061. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5062. }
  5063. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5064. {
  5065. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5066. }
  5067. Options.Filter->Sort();
  5068. }
  5069. }
  5070. //---------------------------------------------------------------------------
  5071. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5072. {
  5073. TCopyParamType Defaults;
  5074. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5075. ConfigStorage->AccessMode = smRead;
  5076. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false, false))
  5077. {
  5078. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5079. }
  5080. ConfigStorage.reset(NULL);
  5081. std::unique_ptr<TStringList> Options(new TStringList());
  5082. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5083. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5084. UnicodeString Result;
  5085. if (Options->Count > 0)
  5086. {
  5087. Result =
  5088. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5089. }
  5090. return Result;
  5091. }
  5092. //---------------------------------------------------------------------------
  5093. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5094. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5095. {
  5096. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5097. UnicodeString AdditionalParams =
  5098. FORMAT(L"%s \"%s\" \"%s\" %d %d %s%s", (
  5099. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5100. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options,
  5101. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5102. SerializeCopyParamForCommandLine(CopyParams)));
  5103. ExecuteNewInstance(SessionName, AdditionalParams);
  5104. }
  5105. //---------------------------------------------------------------------------
  5106. struct TSynchronizeParams
  5107. {
  5108. UnicodeString LocalDirectory;
  5109. UnicodeString RemoteDirectory;
  5110. TSynchronizeMode Mode;
  5111. TSynchronizeChecklist * Checklist;
  5112. int Params;
  5113. TCopyParamType * CopyParam;
  5114. TDateTime CollectElapsed;
  5115. TDateTime * StartTime;
  5116. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5117. };
  5118. //---------------------------------------------------------------------------
  5119. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5120. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5121. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5122. {
  5123. DebugAssert(!FAutoOperation);
  5124. void * BatchStorage;
  5125. BatchStart(BatchStorage);
  5126. FAutoOperation = true;
  5127. TFileOperationStatistics Statistics;
  5128. TDateTime Start = Now();
  5129. try
  5130. {
  5131. Params.OnProcessedItem = OnProcessedItem;
  5132. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5133. CreateProgressForm(&SynchronizeProgress);
  5134. Terminal->SynchronizeApply(
  5135. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5136. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5137. &Statistics);
  5138. }
  5139. __finally
  5140. {
  5141. Params.OnProcessedItem = NULL;
  5142. FAutoOperation = false;
  5143. DestroyProgressForm();
  5144. BatchEnd(BatchStorage);
  5145. ReloadLocalDirectory();
  5146. }
  5147. if (WinConfiguration->SynchronizeSummary)
  5148. {
  5149. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5150. // The statistics should be 0 anyway in this case
  5151. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5152. {
  5153. Message += L"\n";
  5154. if (Statistics.FilesUploaded > 0)
  5155. {
  5156. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5157. }
  5158. if (Statistics.FilesDownloaded > 0)
  5159. {
  5160. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5161. }
  5162. if (Statistics.FilesDeletedLocal > 0)
  5163. {
  5164. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5165. }
  5166. if (Statistics.FilesDeletedRemote > 0)
  5167. {
  5168. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5169. }
  5170. }
  5171. TDateTime Elapsed = (Now() - Start);
  5172. Message +=
  5173. L"\n" +
  5174. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5175. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5176. TMessageParams Params(mpNeverAskAgainCheck);
  5177. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5178. if (Result == qaNeverAskAgain)
  5179. {
  5180. WinConfiguration->SynchronizeSummary = false;
  5181. }
  5182. }
  5183. }
  5184. //---------------------------------------------------------------------------
  5185. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5186. {
  5187. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5188. {
  5189. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5190. }
  5191. // Not set in keep-up-to-date mode - Synchronize() method
  5192. if (Token != NULL)
  5193. {
  5194. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5195. if (Params.OnProcessedItem != NULL)
  5196. {
  5197. Params.OnProcessedItem(NULL, ChecklistItem);
  5198. }
  5199. }
  5200. }
  5201. //---------------------------------------------------------------------------
  5202. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5203. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5204. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5205. {
  5206. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5207. *Params.StartTime = Now();
  5208. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5209. }
  5210. //---------------------------------------------------------------------------
  5211. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5212. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5213. {
  5214. // terminal can be already closed (e.g. dropped connection)
  5215. if (Terminal != NULL)
  5216. {
  5217. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5218. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5219. }
  5220. }
  5221. //---------------------------------------------------------------------------
  5222. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5223. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5224. {
  5225. TAutoBatch AutoBatch(this);
  5226. TAutoFlag AutoOperationFlag(FAutoOperation);
  5227. if (Side == osRemote)
  5228. {
  5229. std::unique_ptr<TStrings> FileList(new TStringList());
  5230. FileList->AddObject(FileName, RemoteFile);
  5231. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5232. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5233. RemoteDirView->SaveSelection();
  5234. RemoteDirView->SaveSelectedNames();
  5235. try
  5236. {
  5237. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5238. }
  5239. catch(...)
  5240. {
  5241. RemoteDirView->DiscardSavedSelection();
  5242. throw;
  5243. }
  5244. RemoteDirView->RestoreSelection();
  5245. }
  5246. else if (DebugAlwaysTrue(Side == osLocal))
  5247. {
  5248. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5249. {
  5250. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5251. }
  5252. UnicodeString Directory = ExtractFileDir(FileName);
  5253. ReloadLocalDirectory(Directory);
  5254. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5255. if (!SamePaths(Directory, NewDirectory))
  5256. {
  5257. ReloadLocalDirectory(NewDirectory);
  5258. }
  5259. }
  5260. }
  5261. //---------------------------------------------------------------------------
  5262. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5263. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5264. const TCopyParamType * CopyParams)
  5265. {
  5266. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5267. UnicodeString AdditionalParams =
  5268. FORMAT(L"%s \"%s\" \"%s\" %d %d %s%s", (
  5269. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5270. LocalDirectory, RemoteDirectory, Mode, Params,
  5271. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5272. SerializeCopyParamForCommandLine(CopyParams)));
  5273. ExecuteNewInstance(SessionName, AdditionalParams);
  5274. }
  5275. //---------------------------------------------------------------------------
  5276. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5277. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5278. TSynchronizeMode & Mode, int Params, bool & SaveMode, bool UseDefaults)
  5279. {
  5280. int Result;
  5281. bool SaveSettings = false;
  5282. int Options =
  5283. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5284. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5285. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5286. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5287. bool Continue =
  5288. UseDefaults ||
  5289. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5290. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow);
  5291. if (Continue)
  5292. {
  5293. Configuration->Usage->Inc(L"Synchronizations");
  5294. UpdateCopyParamCounters(CopyParam);
  5295. TSynchronizeOptions SynchronizeOptions;
  5296. GetSynchronizeOptions(Params, SynchronizeOptions);
  5297. if (SaveSettings)
  5298. {
  5299. GUIConfiguration->SynchronizeParams = Params;
  5300. }
  5301. else
  5302. {
  5303. SaveMode = false;
  5304. }
  5305. TDateTime StartTime = Now();
  5306. TSynchronizeChecklist * Checklist = NULL;
  5307. try
  5308. {
  5309. DebugAssert(!FAutoOperation);
  5310. FAutoOperation = true;
  5311. try
  5312. {
  5313. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  5314. FSynchronizeProgressForm->Start();
  5315. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5316. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5317. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5318. &SynchronizeOptions);
  5319. }
  5320. __finally
  5321. {
  5322. FAutoOperation = false;
  5323. SAFE_DESTROY(FSynchronizeProgressForm);
  5324. }
  5325. TSynchronizeParams SynchronizeParams;
  5326. SynchronizeParams.LocalDirectory = LocalDirectory;
  5327. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5328. SynchronizeParams.Mode = Mode;
  5329. SynchronizeParams.CopyParam = &CopyParam;
  5330. SynchronizeParams.Params = Params;
  5331. SynchronizeParams.Checklist = Checklist;
  5332. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5333. SynchronizeParams.StartTime = &StartTime;
  5334. SynchronizeParams.OnProcessedItem = NULL;
  5335. Result = Checklist->Count;
  5336. if (Checklist->Count > 0)
  5337. {
  5338. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5339. {
  5340. if (!DoSynchronizeChecklistDialog(
  5341. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5342. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, &SynchronizeParams))
  5343. {
  5344. Result = -1;
  5345. }
  5346. }
  5347. else
  5348. {
  5349. FullSynchronize(SynchronizeParams, NULL, NULL);
  5350. }
  5351. }
  5352. else
  5353. {
  5354. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5355. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5356. }
  5357. }
  5358. __finally
  5359. {
  5360. delete Checklist;
  5361. }
  5362. OperationComplete(StartTime);
  5363. }
  5364. else
  5365. {
  5366. Result = -1;
  5367. }
  5368. return Result;
  5369. }
  5370. //---------------------------------------------------------------------------
  5371. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5372. const UnicodeString LocalDirectory, const UnicodeString RemoteDirectory,
  5373. bool & Continue, bool Collect)
  5374. {
  5375. if (Collect)
  5376. {
  5377. DebugAssert(FSynchronizeProgressForm != NULL);
  5378. if (!FSynchronizeProgressForm->Started)
  5379. {
  5380. FSynchronizeProgressForm->Start();
  5381. }
  5382. FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Continue);
  5383. }
  5384. else
  5385. {
  5386. DebugAssert(FSynchronizeProgressForm == NULL);
  5387. DebugAssert(FProgressForm != NULL);
  5388. }
  5389. }
  5390. //---------------------------------------------------------------------------
  5391. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5392. {
  5393. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5394. TRemoteFile * File = NULL;
  5395. Terminal->ReadFile(FullFileName, File);
  5396. if (File != NULL)
  5397. {
  5398. std::unique_ptr<TRemoteFile> FileOwner(File);
  5399. TAutoFlag Flag(FStandaloneEditing);
  5400. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5401. Application->ShowMainForm = false;
  5402. Application->Run();
  5403. }
  5404. }
  5405. //---------------------------------------------------------------------------
  5406. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5407. {
  5408. DebugFail();
  5409. }
  5410. //---------------------------------------------------------------------------
  5411. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5412. {
  5413. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5414. SessionData->Assign(Terminal->SessionData);
  5415. UpdateSessionData(SessionData.get());
  5416. Terminal->UpdateSessionCredentials(SessionData.get());
  5417. if (!Terminal->SessionData->HasSessionName())
  5418. {
  5419. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5420. // once IsWorkspace is cleared
  5421. SessionData->Name = UnicodeString();
  5422. SessionData->IsWorkspace = false;
  5423. }
  5424. return SessionData.release();
  5425. }
  5426. //---------------------------------------------------------------------------
  5427. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5428. {
  5429. TSessionData * SessionData = CloneCurrentSessionData();
  5430. try
  5431. {
  5432. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5433. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5434. }
  5435. __finally
  5436. {
  5437. delete SessionData;
  5438. }
  5439. }
  5440. //---------------------------------------------------------------------------
  5441. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5442. {
  5443. TTerminalManager * Manager = TTerminalManager::Instance();
  5444. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5445. if (DebugAlwaysTrue(Terminal != NULL))
  5446. {
  5447. // Update (Managed)Terminal->StateData
  5448. UpdateTerminal(Terminal);
  5449. }
  5450. Manager->SaveWorkspace(DataList.get());
  5451. return DataList.release();
  5452. }
  5453. //---------------------------------------------------------------------------
  5454. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5455. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5456. {
  5457. WinConfiguration->LastWorkspace = Name;
  5458. if (!SavePasswords)
  5459. {
  5460. for (int Index = 0; Index < DataList->Count; Index++)
  5461. {
  5462. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5463. if (SessionData->Link.IsEmpty())
  5464. {
  5465. SessionData->ClearSessionPasswords();
  5466. }
  5467. }
  5468. }
  5469. StoredSessions->NewWorkspace(Name, DataList);
  5470. // modified only
  5471. StoredSessions->Save(false, Explicit);
  5472. }
  5473. //---------------------------------------------------------------------------
  5474. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5475. {
  5476. return
  5477. DefaultStr(WinConfiguration->LastWorkspace,
  5478. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5479. }
  5480. //---------------------------------------------------------------------------
  5481. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5482. {
  5483. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5484. bool AnyNonStoredSessionWithPassword = false;
  5485. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5486. bool AllNonStoredSessionsAnonymous = true;
  5487. TTerminalManager * Manager = TTerminalManager::Instance();
  5488. for (int Index = 0; Index < DataList->Count; Index++)
  5489. {
  5490. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5491. if (SessionData->Link.IsEmpty())
  5492. {
  5493. if (SessionData->HasAnySessionPassword())
  5494. {
  5495. AnyNonStoredSessionWithPassword = true;
  5496. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5497. {
  5498. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5499. }
  5500. }
  5501. if (!SameText(SessionData->UserName, AnonymousUserName))
  5502. {
  5503. AllNonStoredSessionsAnonymous = false;
  5504. }
  5505. }
  5506. }
  5507. bool SavePasswords;
  5508. bool * PSavePasswords;
  5509. bool NotRecommendedSavingPasswords =
  5510. !CustomWinConfiguration->UseMasterPassword &&
  5511. !AllNonStoredSessionsAnonymous;
  5512. if (Configuration->DisablePasswordStoring ||
  5513. !AnyNonStoredSessionWithPassword)
  5514. {
  5515. PSavePasswords = NULL;
  5516. SavePasswords = false;
  5517. }
  5518. else
  5519. {
  5520. PSavePasswords = &SavePasswords;
  5521. SavePasswords =
  5522. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5523. !NotRecommendedSavingPasswords;
  5524. }
  5525. UnicodeString Name = WorkspaceName();
  5526. bool CreateShortcut = false;
  5527. bool Result =
  5528. DoSaveWorkspaceDialog(
  5529. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5530. EnableAutoSave);
  5531. if (Result)
  5532. {
  5533. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5534. if (CreateShortcut)
  5535. {
  5536. TOperationVisualizer Visualizer;
  5537. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5538. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5539. }
  5540. if (EnableAutoSave)
  5541. {
  5542. WinConfiguration->AutoSaveWorkspace = true;
  5543. WinConfiguration->AutoWorkspace = Name;
  5544. if (PSavePasswords != NULL)
  5545. {
  5546. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5547. }
  5548. }
  5549. }
  5550. return Result;
  5551. }
  5552. //---------------------------------------------------------------------------
  5553. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TTerminal * Terminal)
  5554. {
  5555. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  5556. DebugAssert(ManagedTerminal != NULL);
  5557. SAFE_DESTROY(ManagedTerminal->RemoteExplorerState);
  5558. if (WinConfiguration->PreservePanelState)
  5559. {
  5560. ManagedTerminal->RemoteExplorerState = RemoteDirView->SaveState();
  5561. }
  5562. UpdateSessionData(ManagedTerminal->StateData);
  5563. }
  5564. //---------------------------------------------------------------------------
  5565. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5566. {
  5567. // Keep in sync with TSessionData::CopyStateData
  5568. DebugAssert(Data != NULL);
  5569. // This is inconsistent with how color (for example) is handled.
  5570. Data->Name = Terminal->SessionData->Name;
  5571. // cannot use RemoteDirView->Path, because it is empty if connection
  5572. // was already closed
  5573. // also only peek, we may not be connected at all atm
  5574. // so make sure we do not try retrieving current directory from the server
  5575. // (particularly with FTP)
  5576. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5577. if (!ACurrentDirectory.IsEmpty())
  5578. {
  5579. Data->RemoteDirectory = ACurrentDirectory;
  5580. }
  5581. Data->Color = SessionColor;
  5582. }
  5583. //---------------------------------------------------------------------------
  5584. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5585. {
  5586. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5587. DebugAssert(Toolbar != NULL);
  5588. for (int i = 0; i < Toolbar->Items->Count; i++)
  5589. {
  5590. TTBXCustomDropDownItem * DropDownItem;
  5591. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5592. if (DropDownItem != NULL)
  5593. {
  5594. ToolbarItemResize(DropDownItem,
  5595. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5596. Toolbar->NonClientWidth);
  5597. break;
  5598. }
  5599. }
  5600. }
  5601. //---------------------------------------------------------------------------
  5602. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5603. {
  5604. Item->EditWidth = Width;
  5605. }
  5606. //---------------------------------------------------------------------------
  5607. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5608. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5609. {
  5610. for (int i = 0; i < Toolbar->Items->Count; i++)
  5611. {
  5612. TTBXCustomDropDownItem * DropDownItem;
  5613. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5614. if (DropDownItem != NULL)
  5615. {
  5616. ASize.x -= DropDownItem->EditWidth;
  5617. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5618. }
  5619. }
  5620. }
  5621. //---------------------------------------------------------------------------
  5622. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5623. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5624. {
  5625. if (WinConfiguration->DDWarnLackOfTempSpace)
  5626. {
  5627. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5628. if (!ADrive.IsEmpty())
  5629. {
  5630. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5631. DebugAssert(RequiredSpace >= 0);
  5632. __int64 RequiredWithReserve;
  5633. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5634. if (FreeSpace < RequiredWithReserve)
  5635. {
  5636. unsigned int Result;
  5637. TMessageParams Params(mpNeverAskAgainCheck);
  5638. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5639. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5640. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5641. if (Result == qaNeverAskAgain)
  5642. {
  5643. WinConfiguration->DDWarnLackOfTempSpace = false;
  5644. }
  5645. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5646. }
  5647. }
  5648. }
  5649. }
  5650. //---------------------------------------------------------------------------
  5651. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5652. {
  5653. DoOpenDirectoryDialog(odAddBookmark, Side);
  5654. }
  5655. //---------------------------------------------------------------------------
  5656. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5657. {
  5658. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5659. TStringList * VisitedDirectories = CreateSortedStringList((Side == osRemote));
  5660. try
  5661. {
  5662. TCustomDirView * DView = DirView(Side);
  5663. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5664. {
  5665. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5666. }
  5667. }
  5668. catch (...)
  5669. {
  5670. delete VisitedDirectories;
  5671. throw;
  5672. }
  5673. return VisitedDirectories;
  5674. }
  5675. //---------------------------------------------------------------------------
  5676. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5677. TOpenDirectoryMode Mode, TOperationSide Side)
  5678. {
  5679. bool Continue = true;
  5680. if (Mode == odAddBookmark)
  5681. {
  5682. TMessageParams Params(mpNeverAskAgainCheck);
  5683. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5684. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5685. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5686. unsigned int Answer =
  5687. MessageDialog(Message,
  5688. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5689. if (Answer == qaNeverAskAgain)
  5690. {
  5691. Continue = true;
  5692. WinConfiguration->UseSharedBookmarks = true;
  5693. }
  5694. else if (Answer == qaOK)
  5695. {
  5696. Continue = true;
  5697. WinConfiguration->UseSharedBookmarks = false;
  5698. }
  5699. else
  5700. {
  5701. Continue = false;
  5702. }
  5703. }
  5704. if (Continue)
  5705. {
  5706. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5707. try
  5708. {
  5709. UnicodeString Name = DirView(Side)->PathName;
  5710. bool Repeat;
  5711. do
  5712. {
  5713. Repeat = false;
  5714. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5715. // do not allow switching to location profiles,
  5716. // if we are not connected
  5717. HasDirView[osLocal] && (Terminal != NULL)))
  5718. {
  5719. TWindowLock Lock(this);
  5720. if (!TryOpenDirectory(Side, Name))
  5721. {
  5722. Repeat = true;
  5723. Mode = odBrowse;
  5724. }
  5725. }
  5726. }
  5727. while (Repeat);
  5728. }
  5729. __finally
  5730. {
  5731. delete VisitedDirectories;
  5732. }
  5733. }
  5734. }
  5735. //---------------------------------------------------------------------------
  5736. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5737. {
  5738. DebugAssert(!FTerminal->CommandSessionOpened);
  5739. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5740. }
  5741. //---------------------------------------------------------------------------
  5742. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5743. {
  5744. bool Result = FTerminal->IsCapable[Capability] ||
  5745. FTerminal->CommandSessionOpened;
  5746. if (!Result)
  5747. {
  5748. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5749. if (!GUIConfiguration->ConfirmCommandSession)
  5750. {
  5751. Result = true;
  5752. }
  5753. else
  5754. {
  5755. TMessageParams Params(mpNeverAskAgainCheck);
  5756. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5757. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5758. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5759. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5760. if (Answer == qaNeverAskAgain)
  5761. {
  5762. GUIConfiguration->ConfirmCommandSession = false;
  5763. Result = true;
  5764. }
  5765. else if (Answer == qaOK)
  5766. {
  5767. Result = true;
  5768. }
  5769. }
  5770. if (Result)
  5771. {
  5772. Result = CommandSessionFallback();
  5773. }
  5774. }
  5775. return Result;
  5776. }
  5777. //---------------------------------------------------------------------------
  5778. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  5779. {
  5780. if (EnsureCommandSessionFallback(fcAnyCommand))
  5781. {
  5782. DoConsoleDialog(Terminal, Command);
  5783. }
  5784. }
  5785. //---------------------------------------------------------------------------
  5786. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  5787. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  5788. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  5789. {
  5790. if (IsFileControl(DropSourceControl, osRemote) &&
  5791. (FDDExtMapFile != NULL))
  5792. {
  5793. Accept = true;
  5794. }
  5795. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  5796. DebugAssert(FDDTargetControl != NULL);
  5797. }
  5798. //---------------------------------------------------------------------------
  5799. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  5800. _di_IDataObject DataObj, int KeyState,
  5801. const TPoint & Point, int & Effect, bool & Accept)
  5802. {
  5803. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  5804. }
  5805. //---------------------------------------------------------------------------
  5806. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  5807. _di_IDataObject DataObj, int KeyState,
  5808. const TPoint & Point, int & Effect, bool & Accept)
  5809. {
  5810. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  5811. }
  5812. //---------------------------------------------------------------------------
  5813. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  5814. TObject * Sender)
  5815. {
  5816. DebugUsedParam(Sender);
  5817. DebugAssert(FDDTargetControl == Sender);
  5818. FDDTargetControl = NULL;
  5819. }
  5820. //---------------------------------------------------------------------------
  5821. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  5822. {
  5823. FileControlDDDragLeave(SessionsPageControl);
  5824. }
  5825. //---------------------------------------------------------------------------
  5826. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  5827. {
  5828. FileControlDDDragLeave(QueueView3);
  5829. }
  5830. //---------------------------------------------------------------------------
  5831. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  5832. {
  5833. DebugAssert(GetSide(Side) == osRemote);
  5834. DebugUsedParam(Side);
  5835. bool Edit = false;
  5836. TRemoteFile * File = NULL;
  5837. UnicodeString FileName;
  5838. UnicodeString PointTo;
  5839. bool SymbolicLink = true;
  5840. if (RemoteDirView->ItemFocused)
  5841. {
  5842. DebugAssert(RemoteDirView->ItemFocused->Data);
  5843. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  5844. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  5845. if (Edit)
  5846. {
  5847. FileName = File->FileName;
  5848. PointTo = File->LinkTo;
  5849. }
  5850. else
  5851. {
  5852. PointTo = File->FileName;
  5853. }
  5854. }
  5855. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  5856. Terminal->IsCapable[fcHardLink]))
  5857. {
  5858. Configuration->Usage->Inc(L"RemoteLinksCreated");
  5859. if (Edit)
  5860. {
  5861. DebugAssert(File->FileName == FileName);
  5862. int Params = dfNoRecursive;
  5863. Terminal->ExceptionOnFail = true;
  5864. try
  5865. {
  5866. Terminal->DeleteFile(L"", File, &Params);
  5867. }
  5868. __finally
  5869. {
  5870. Terminal->ExceptionOnFail = false;
  5871. }
  5872. }
  5873. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  5874. }
  5875. }
  5876. //---------------------------------------------------------------------------
  5877. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  5878. {
  5879. return
  5880. (Terminal != NULL) &&
  5881. ((GetSide(Side) != osRemote) ||
  5882. (Terminal->ResolvingSymlinks &&
  5883. Terminal->IsCapable[fcSymbolicLink]));
  5884. }
  5885. //---------------------------------------------------------------------------
  5886. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  5887. {
  5888. return
  5889. (FCurrentSide == osRemote) &&
  5890. (RemoteDirView->ItemFocused != NULL) &&
  5891. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  5892. Terminal->SessionData->ResolveSymlinks;
  5893. }
  5894. //---------------------------------------------------------------------------
  5895. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  5896. {
  5897. DebugAssert(!WinConfiguration->DisableOpenEdit);
  5898. FForceExecution = true;
  5899. try
  5900. {
  5901. DirView(osCurrent)->ExecuteCurrentFile();
  5902. }
  5903. __finally
  5904. {
  5905. FForceExecution = false;
  5906. }
  5907. }
  5908. //---------------------------------------------------------------------------
  5909. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  5910. {
  5911. TEditorData ExternalEditor;
  5912. ExternalEditor.Editor = edExternal;
  5913. bool Remember = false;
  5914. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc,
  5915. (GetSide(osCurrent) == osRemote)))
  5916. {
  5917. if (Remember)
  5918. {
  5919. TEditorList * EditorList = new TEditorList;
  5920. try
  5921. {
  5922. *EditorList = *WinConfiguration->EditorList;
  5923. bool Found = false;
  5924. int i = 0;
  5925. while (!Found && (i < EditorList->Count))
  5926. {
  5927. const TEditorPreferences * Editor = EditorList->Editors[i];
  5928. if ((Editor->Data->Editor == edExternal) &&
  5929. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  5930. {
  5931. Found = true;
  5932. }
  5933. i++;
  5934. }
  5935. if (!Found)
  5936. {
  5937. EditorList->Add(new TEditorPreferences(ExternalEditor));
  5938. WinConfiguration->EditorList = EditorList;
  5939. }
  5940. }
  5941. __finally
  5942. {
  5943. delete EditorList;
  5944. }
  5945. }
  5946. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  5947. }
  5948. }
  5949. //---------------------------------------------------------------------------
  5950. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  5951. {
  5952. FEditorManager->ProcessFiles(FileTerminalRemoved, Sender);
  5953. if (FFileFindTerminal == Sender)
  5954. {
  5955. FFileFindTerminal = NULL;
  5956. HideFileFindDialog();
  5957. }
  5958. if (FClipboardTerminal == Sender)
  5959. {
  5960. ClipboardClear(); // implies ClipboardStop
  5961. }
  5962. }
  5963. //---------------------------------------------------------------------------
  5964. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  5965. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  5966. {
  5967. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  5968. DebugAssert(Terminal != NULL);
  5969. if (Data->Terminal == Terminal)
  5970. {
  5971. Data->Terminal = NULL;
  5972. }
  5973. }
  5974. //---------------------------------------------------------------------------
  5975. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  5976. {
  5977. UpdateControls();
  5978. SessionColor = TColor(0);
  5979. UpdateRemotePathComboBox(false);
  5980. NeedSession(true);
  5981. }
  5982. //---------------------------------------------------------------------------
  5983. void __fastcall TCustomScpExplorerForm::NeedSession(bool ReloadSessions)
  5984. {
  5985. try
  5986. {
  5987. try
  5988. {
  5989. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  5990. }
  5991. __finally
  5992. {
  5993. if (!WinConfiguration->KeepOpenWhenNoSession &&
  5994. (!Terminal || !Terminal->Active))
  5995. {
  5996. TerminateApplication();
  5997. }
  5998. }
  5999. }
  6000. catch (EAbort &)
  6001. {
  6002. // swallow
  6003. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6004. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6005. }
  6006. }
  6007. //---------------------------------------------------------------------------
  6008. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6009. {
  6010. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6011. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6012. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6013. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6014. try
  6015. {
  6016. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6017. // Clear the design time unthemed tab
  6018. ((SessionsPageControl->PageCount > 0) &&
  6019. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6020. {
  6021. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6022. }
  6023. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6024. {
  6025. TThemeTabSheet * TabSheet;
  6026. if (Index >= SessionsPageControl->PageCount)
  6027. {
  6028. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6029. TabSheet->PageControl = SessionsPageControl;
  6030. }
  6031. else
  6032. {
  6033. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6034. }
  6035. bool IsSessionTab = (Index < TerminalList->Count);
  6036. if (IsSessionTab)
  6037. {
  6038. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6039. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6040. UpdateSessionTab(TabSheet);
  6041. }
  6042. else
  6043. {
  6044. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6045. TabSheet->Tag = 0; // not really needed
  6046. // We know that we are at the last page, sotherwise we could not call this (it assumes that new session tab is the last one)
  6047. UpdateNewSessionTab();
  6048. }
  6049. TabSheet->ShowCloseButton = IsSessionTab;
  6050. }
  6051. }
  6052. __finally
  6053. {
  6054. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6055. }
  6056. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6057. }
  6058. //---------------------------------------------------------------------------
  6059. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6060. {
  6061. DoTerminalListChanged();
  6062. }
  6063. //---------------------------------------------------------------------------
  6064. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6065. {
  6066. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6067. DebugAssert(TabSheet->ImageIndex == 0);
  6068. TabSheet->Caption =
  6069. WinConfiguration->SelectiveToolbarText ?
  6070. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6071. UnicodeString();
  6072. }
  6073. //---------------------------------------------------------------------------
  6074. TTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6075. {
  6076. return reinterpret_cast<TTerminal *>(TabSheet->Tag);
  6077. }
  6078. //---------------------------------------------------------------------------
  6079. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6080. {
  6081. if (DebugAlwaysTrue(TabSheet != NULL))
  6082. {
  6083. TManagedTerminal * ManagedTerminal =
  6084. dynamic_cast<TManagedTerminal *>(GetSessionTabTerminal(TabSheet));
  6085. if (DebugAlwaysTrue(ManagedTerminal != NULL))
  6086. {
  6087. TColor Color = (ManagedTerminal == FTerminal) ? FSessionColor : ManagedTerminal->StateData->Color;
  6088. TabSheet->ImageIndex = AddSessionColor(Color);
  6089. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ManagedTerminal, true);
  6090. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6091. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6092. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6093. {
  6094. ThemeTabSheet->Shadowed = !ManagedTerminal->Active;
  6095. }
  6096. }
  6097. }
  6098. }
  6099. //---------------------------------------------------------------------------
  6100. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6101. {
  6102. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6103. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6104. bool Result = (Terminal != NULL);
  6105. if (Result)
  6106. {
  6107. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6108. }
  6109. else
  6110. {
  6111. try
  6112. {
  6113. NewSession(false);
  6114. }
  6115. __finally
  6116. {
  6117. DoTerminalListChanged();
  6118. }
  6119. FSessionsPageControlNewSessionTime = Now();
  6120. }
  6121. return Result;
  6122. }
  6123. //---------------------------------------------------------------------------
  6124. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6125. {
  6126. SessionTabSwitched();
  6127. }
  6128. //---------------------------------------------------------------------------
  6129. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6130. {
  6131. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6132. DebugAssert(TransferList != NULL);
  6133. UnicodeString Name;
  6134. if (TransferList->ItemIndex <= 0)
  6135. {
  6136. Name = L"";
  6137. }
  6138. else
  6139. {
  6140. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6141. }
  6142. if (FCopyParamAutoSelected.IsEmpty())
  6143. {
  6144. // if previous preset was not autoselected, make new preset the "default"
  6145. FCopyParamDefault = Name;
  6146. }
  6147. GUIConfiguration->CopyParamCurrent = Name;
  6148. }
  6149. //---------------------------------------------------------------------------
  6150. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6151. {
  6152. // sanity check
  6153. bool ExistingPreset =
  6154. (FTransferListHoverIndex >= 0) &&
  6155. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6156. DebugAssert(ExistingPreset);
  6157. if (ExistingPreset)
  6158. {
  6159. HDC DC = GetDC(0);
  6160. TCanvas * Canvas = new TCanvas();
  6161. try
  6162. {
  6163. Canvas->Handle = DC;
  6164. Canvas->Font = GetToolbarFont(this);
  6165. UnicodeString Name;
  6166. if (FTransferListHoverIndex == 0)
  6167. {
  6168. Name = L"";
  6169. }
  6170. else
  6171. {
  6172. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6173. }
  6174. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6175. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6176. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6177. static_cast<TObject*>(GetComponent(fcTransferList)));
  6178. UnicodeString InfoStr =
  6179. GUIConfiguration->CopyParamPreset[Name].
  6180. GetInfoStr(L"; ",
  6181. FLAGMASK(((Terminal != NULL) && Terminal->Active), Terminal->UsableCopyParamAttrs(0).General));
  6182. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6183. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6184. {
  6185. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6186. {
  6187. InfoStr.SetLength(InfoStr.Length() - 1);
  6188. }
  6189. InfoStr += Ellipsis;
  6190. }
  6191. // UpdateCaption does not cause invalidation of whole submenu, while
  6192. // setting Caption property does.
  6193. // also it probably does not resize the label, even if necessary
  6194. // (we do not want that anyway)
  6195. TransferLabel->UpdateCaption(InfoStr);
  6196. }
  6197. __finally
  6198. {
  6199. Canvas->Handle = NULL;
  6200. ReleaseDC(0, DC);
  6201. delete Canvas;
  6202. }
  6203. }
  6204. }
  6205. //---------------------------------------------------------------------------
  6206. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6207. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6208. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6209. {
  6210. if (FTransferListHoverIndex != AHoverIndex)
  6211. {
  6212. FTransferListHoverIndex = AHoverIndex;
  6213. UpdateTransferLabel();
  6214. }
  6215. }
  6216. //---------------------------------------------------------------------------
  6217. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6218. {
  6219. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6220. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6221. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6222. {
  6223. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6224. {
  6225. OpenDirectory(GetSide(osCurrent));
  6226. Message.Result = 1;
  6227. }
  6228. else
  6229. {
  6230. TForm::Dispatch(&Message);
  6231. }
  6232. }
  6233. else
  6234. {
  6235. TForm::Dispatch(&Message);
  6236. }
  6237. }
  6238. //---------------------------------------------------------------------------
  6239. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6240. {
  6241. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6242. if ((FIgnoreNextDialogChar != 0) &&
  6243. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6244. {
  6245. Message.Result = 1;
  6246. }
  6247. else
  6248. {
  6249. TForm::Dispatch(&Message);
  6250. }
  6251. FIgnoreNextDialogChar = 0;
  6252. }
  6253. //---------------------------------------------------------------------------
  6254. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6255. {
  6256. // The four low-order bits are used internally by Windows
  6257. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6258. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6259. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6260. // 61730 - restore thru double click - undocumented
  6261. // 61490 - maximize thru double click - undocumented
  6262. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6263. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6264. {
  6265. SysResizing(Cmd);
  6266. }
  6267. TForm::Dispatch(&Message);
  6268. }
  6269. //---------------------------------------------------------------------------
  6270. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6271. {
  6272. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6273. // Also there no point returning TRUE as we are not able to
  6274. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6275. // Hence the process termination might be safer :)
  6276. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6277. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6278. {
  6279. Message.Result = FALSE;
  6280. }
  6281. else
  6282. {
  6283. Message.Result = TRUE;
  6284. }
  6285. // Do not call default handling as that triggers OnCloseQuery,
  6286. // where our implementation will popup confirmation dialogs, what we do not want,
  6287. // as per Vista guidelines:
  6288. // https://docs.microsoft.com/en-us/windows/desktop/shutdown/shutting-down
  6289. }
  6290. //---------------------------------------------------------------------------
  6291. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6292. {
  6293. if (Message.EndSession && IsApplicationMinimized())
  6294. {
  6295. // WORKAROUND
  6296. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6297. // when it receives WM_ENDSESSION,
  6298. // but that sometimes (particularly when application is minimized) cause crashes.
  6299. // Crash popups message that blocks log off.
  6300. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6301. // so we call ExitProcess() immediately, not even trying to cleanup.
  6302. // It still causes beep, so there's likely some popup, but it does not block
  6303. // log off.
  6304. ExitProcess(0);
  6305. }
  6306. TForm::Dispatch(&Message);
  6307. }
  6308. #ifdef _DEBUG
  6309. //---------------------------------------------------------------------------
  6310. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6311. {
  6312. TForm::Dispatch(&Message);
  6313. }
  6314. #endif
  6315. //---------------------------------------------------------------------------
  6316. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6317. {
  6318. }
  6319. //---------------------------------------------------------------------------
  6320. void __fastcall TCustomScpExplorerForm::DoShow()
  6321. {
  6322. // only now are the controls resized finally, so the size constraints
  6323. // will not conflict with possibly very small window size
  6324. RestoreFormParams();
  6325. FixControlsPlacement();
  6326. if (Position == poDefaultPosOnly)
  6327. {
  6328. CutFormToDesktop(this);
  6329. }
  6330. TForm::DoShow();
  6331. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6332. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6333. if (Terminal == NULL)
  6334. {
  6335. StartingDisconnected();
  6336. }
  6337. UpdatePixelsPerInchMainWindowCounter();
  6338. FShowing = true;
  6339. }
  6340. //---------------------------------------------------------------------------
  6341. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6342. {
  6343. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6344. }
  6345. //---------------------------------------------------------------------------
  6346. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6347. {
  6348. DoTerminalListChanged();
  6349. }
  6350. //---------------------------------------------------------------------------
  6351. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6352. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6353. TNotifyEvent OnBalloonClick, TObject * UserData)
  6354. {
  6355. bool Do;
  6356. UnicodeString Message;
  6357. if (E == NULL)
  6358. {
  6359. Message = Str;
  6360. Do = true;
  6361. }
  6362. else
  6363. {
  6364. Do = ExceptionMessage(E, Message);
  6365. }
  6366. if (Do && WinConfiguration->BalloonNotifications)
  6367. {
  6368. UnicodeString Title;
  6369. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6370. {
  6371. Message = TrimLeft(Message);
  6372. }
  6373. else
  6374. {
  6375. Message = UnformatMessage(Message);
  6376. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6377. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6378. Title = LoadResourceString(Captions[Type]);
  6379. if (Terminal != NULL)
  6380. {
  6381. Title = FORMAT(L"%s - %s",
  6382. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6383. }
  6384. }
  6385. if (Seconds == 0)
  6386. {
  6387. Seconds = WinConfiguration->NotificationsTimeout;
  6388. }
  6389. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6390. }
  6391. }
  6392. //---------------------------------------------------------------------------
  6393. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6394. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6395. UnicodeString HelpKeyword, const TMessageParams * Params,
  6396. TTerminal * Terminal)
  6397. {
  6398. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6399. (FOnFeedSynchronizeError != NULL)) &&
  6400. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6401. {
  6402. if (FOnFeedSynchronizeError != NULL)
  6403. {
  6404. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6405. }
  6406. else
  6407. {
  6408. DebugAssert(FErrorList != NULL);
  6409. TStringList * MoreMessagesCopy = NULL;
  6410. if (MoreMessages)
  6411. {
  6412. MoreMessagesCopy = new TStringList();
  6413. MoreMessagesCopy->Assign(MoreMessages);
  6414. }
  6415. FErrorList->AddObject(Message, MoreMessagesCopy);
  6416. }
  6417. PopupTrayBalloon(Terminal, Message, Type);
  6418. return ContinueAnswer(Answers);
  6419. }
  6420. else
  6421. {
  6422. bool UseBalloon = FTrayIcon->Visible;
  6423. if (UseBalloon)
  6424. {
  6425. PopupTrayBalloon(Terminal, Message, Type);
  6426. }
  6427. unsigned int Result;
  6428. try
  6429. {
  6430. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6431. }
  6432. __finally
  6433. {
  6434. // cancel only balloon we popped up, otherwise we may cancel notification
  6435. // balloon that was there before the message dialog
  6436. // (such as "dd confirmation opt in balloon)
  6437. if (UseBalloon)
  6438. {
  6439. FTrayIcon->CancelBalloon();
  6440. }
  6441. }
  6442. return Result;
  6443. }
  6444. }
  6445. //---------------------------------------------------------------------------
  6446. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6447. TTerminal * Terminal, Exception * E)
  6448. {
  6449. if (FTrayIcon->Visible)
  6450. {
  6451. PopupTrayBalloon(Terminal, L"", qtError, E);
  6452. }
  6453. // particularly prevent opening new session from jump list,
  6454. // while exception is shown
  6455. NonVisualDataModule->StartBusy();
  6456. try
  6457. {
  6458. ShowExtendedExceptionEx(Terminal, E);
  6459. }
  6460. __finally
  6461. {
  6462. NonVisualDataModule->EndBusy();
  6463. FTrayIcon->CancelBalloon();
  6464. }
  6465. }
  6466. //---------------------------------------------------------------------------
  6467. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6468. {
  6469. // cannot rely on active page being page for active terminal,
  6470. // as it can happen that active page is the "new session" page
  6471. // (e.g. when reconnecting active terminal, while login dialog
  6472. // invoked from "new session" page is modal)
  6473. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6474. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6475. }
  6476. //---------------------------------------------------------------------------
  6477. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6478. TTerminal * Terminal, Exception * E)
  6479. {
  6480. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6481. if (!Terminal->Active)
  6482. {
  6483. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6484. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6485. {
  6486. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6487. }
  6488. }
  6489. }
  6490. //---------------------------------------------------------------------------
  6491. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6492. UnicodeString Message, TQueryType Type,
  6493. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6494. {
  6495. if ((E == NULL) ||
  6496. ExceptionMessage(E, Message))
  6497. {
  6498. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6499. if (Important)
  6500. {
  6501. Seconds *= 5;
  6502. }
  6503. UnicodeString NoteMessage(UnformatMessage(Message));
  6504. if (Terminal != NULL)
  6505. {
  6506. NoteMessage = FORMAT(L"%s: %s",
  6507. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6508. }
  6509. if (WinConfiguration->BalloonNotifications)
  6510. {
  6511. AddNote(NoteMessage);
  6512. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6513. }
  6514. else
  6515. {
  6516. FlashOnBackground();
  6517. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6518. }
  6519. }
  6520. }
  6521. //---------------------------------------------------------------------------
  6522. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6523. {
  6524. RestoreApp();
  6525. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6526. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6527. !NonVisualDataModule->Busy)
  6528. {
  6529. TTerminal * Terminal = TerminalNoteData->Terminal;
  6530. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6531. if (!ComponentVisible[fcQueueView])
  6532. {
  6533. ToggleQueueVisibility();
  6534. GoToQueue();
  6535. }
  6536. }
  6537. }
  6538. //---------------------------------------------------------------------------
  6539. void __fastcall TCustomScpExplorerForm::QueueEvent(TTerminal * ATerminal,
  6540. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6541. {
  6542. TManagedTerminal * ManagedTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  6543. UnicodeString Message;
  6544. TNotifyEvent OnClick = NULL;
  6545. TObject * UserData = NULL;
  6546. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6547. switch (Event)
  6548. {
  6549. case qeEmptyButMonitored:
  6550. if ((ATerminal != Terminal) || QueueInvisible)
  6551. {
  6552. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6553. OnClick = QueueEmptyNoteClicked;
  6554. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6555. TerminalNoteData->Terminal = ATerminal;
  6556. UserData = TerminalNoteData;
  6557. }
  6558. break;
  6559. case qeEmpty:
  6560. OperationComplete(ManagedTerminal->QueueOperationStart);
  6561. break;
  6562. case qePendingUserAction:
  6563. if ((ATerminal != Terminal) ||
  6564. (QueueInvisible && !IsQueueAutoPopup()))
  6565. {
  6566. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6567. }
  6568. break;
  6569. default:
  6570. DebugFail();
  6571. }
  6572. if (!Message.IsEmpty())
  6573. {
  6574. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6575. }
  6576. }
  6577. //---------------------------------------------------------------------------
  6578. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6579. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6580. {
  6581. if (FDDExtMapFile != NULL)
  6582. {
  6583. CloseHandle(FDDExtMapFile);
  6584. FDDExtMapFile = NULL;
  6585. }
  6586. if (WinConfiguration->DDFakeFile)
  6587. {
  6588. DDFakeFileInitDrag(FileList, Created);
  6589. }
  6590. }
  6591. //---------------------------------------------------------------------------
  6592. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6593. {
  6594. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6595. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6596. {
  6597. FFakeFileDropTarget = FileName;
  6598. }
  6599. }
  6600. //---------------------------------------------------------------------------
  6601. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6602. {
  6603. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6604. if (!ForceDirectories(ApiPath(Result)))
  6605. {
  6606. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6607. }
  6608. FileSetAttr(ApiPath(Result), faHidden);
  6609. return Result;
  6610. }
  6611. //---------------------------------------------------------------------------
  6612. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6613. bool & Created)
  6614. {
  6615. FFakeFileDropTarget = UnicodeString();
  6616. FDragFakeDirectory = CreateFakeTransferDirectory();
  6617. FileList->AddItem(NULL, FDragFakeDirectory);
  6618. Created = true;
  6619. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6620. {
  6621. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6622. }
  6623. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6624. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6625. {
  6626. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6627. TDragExtCommStruct* CommStruct;
  6628. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6629. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6630. DebugAssert(CommStruct != NULL);
  6631. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6632. CommStruct->Dragging = true;
  6633. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6634. LENOF(CommStruct->DropDest));
  6635. NULL_TERMINATE(CommStruct->DropDest);
  6636. UnmapViewOfFile(CommStruct);
  6637. }
  6638. }
  6639. //---------------------------------------------------------------------------
  6640. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6641. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6642. {
  6643. bool Result;
  6644. if (Sender == RemoteDirView)
  6645. {
  6646. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6647. }
  6648. else
  6649. {
  6650. DebugAssert(Sender == RemoteDriveView);
  6651. TStrings * FileList = RemoteDriveView->DragFileList();
  6652. try
  6653. {
  6654. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6655. }
  6656. __finally
  6657. {
  6658. delete FileList;
  6659. }
  6660. }
  6661. if (FDDTargetControl == RemoteDriveView)
  6662. {
  6663. RemoteDriveView->UpdateDropTarget();
  6664. }
  6665. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6666. // or from tree view to dir view.
  6667. // foMove happens when file/dir is dragged from remote tree view outside of
  6668. // application via dragex
  6669. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6670. (DropSourceControl == RemoteDriveView))
  6671. {
  6672. RemoteDriveView->UpdateDropSource();
  6673. }
  6674. return Result;
  6675. }
  6676. //---------------------------------------------------------------------------
  6677. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6678. {
  6679. // This also handles drops of remote files to queue.
  6680. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6681. SAFE_DESTROY(FDDFileList);
  6682. if (!FFakeFileDropTarget.IsEmpty())
  6683. {
  6684. RemoveDir(ApiPath(FFakeFileDropTarget));
  6685. }
  6686. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6687. {
  6688. try
  6689. {
  6690. TDragResult DDResult = (Sender == RemoteDirView) ?
  6691. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6692. // Focus is moved to the target application,
  6693. // but as we are going to present the UI, we need to steal the focus back.
  6694. // This most likely won't work though (windows does not allow application
  6695. // to steal focus most of the time)
  6696. Application->BringToFront();
  6697. // On older version of Windows we never got drMove here, see also comment below.
  6698. // On Windows 10, we get the "move".
  6699. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6700. {
  6701. UnicodeString TargetDirectory;
  6702. TFileOperation Operation;
  6703. // drInvalid may mean drMove, see comment below
  6704. switch (DDResult)
  6705. {
  6706. case drCopy:
  6707. Operation = foCopy;
  6708. break;
  6709. case drMove:
  6710. Operation = foMove;
  6711. break;
  6712. default:
  6713. DebugFail();
  6714. case drInvalid:
  6715. // prefer "copy" for safety
  6716. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6717. break;
  6718. }
  6719. TTransferOperationParam Param;
  6720. UnicodeString CounterName;
  6721. bool ForceQueue;
  6722. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  6723. {
  6724. // we get drInvalid both if d&d was intercepted by ddext,
  6725. // and when users drops on no-drop location.
  6726. // we tell the difference by existence of response from ddext,
  6727. // so we ignore absence of response in this case
  6728. if (DDResult != drInvalid)
  6729. {
  6730. // here we know that the extension is installed,
  6731. // as it is checked as soon as drag&drop starts from
  6732. // RemoteFileControlDDCreateDragFileList
  6733. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  6734. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  6735. {
  6736. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  6737. }
  6738. else
  6739. {
  6740. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  6741. }
  6742. }
  6743. }
  6744. else
  6745. {
  6746. // download using fake file
  6747. Param.Temp = false;
  6748. Param.DragDrop = true;
  6749. if (ForceQueue)
  6750. {
  6751. Param.Queue = asOn;
  6752. }
  6753. if (Sender == RemoteDirView)
  6754. {
  6755. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  6756. }
  6757. if (RemoteFileControlFileOperation(Sender, Operation,
  6758. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  6759. {
  6760. Configuration->Usage->Inc(CounterName);
  6761. }
  6762. }
  6763. }
  6764. }
  6765. __finally
  6766. {
  6767. CloseHandle(FDDExtMapFile);
  6768. FDDExtMapFile = NULL;
  6769. delete FDragFakeMonitors;
  6770. FDragFakeMonitors = NULL;
  6771. RemoveDir(ApiPath(FDragFakeDirectory));
  6772. FDragFakeDirectory = L"";
  6773. FFakeFileDropTarget = UnicodeString();
  6774. }
  6775. }
  6776. if (FDragDropSshTerminate.get() != NULL)
  6777. {
  6778. FDragDropSshTerminate->Rethrow();
  6779. }
  6780. }
  6781. //---------------------------------------------------------------------------
  6782. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  6783. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  6784. {
  6785. // Remember drop effect so we know (when user drops files), if we copy or move
  6786. FLastDropEffect = dwEffect;
  6787. }
  6788. //---------------------------------------------------------------------------
  6789. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  6790. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  6791. {
  6792. bool Result;
  6793. if (FDDTargetControl == QueueView3)
  6794. {
  6795. Directory = DefaultDownloadTargetDirectory();
  6796. Result = true;
  6797. CounterName = L"DownloadsDragDropQueue";
  6798. ForceQueue = true;
  6799. }
  6800. else if (!FFakeFileDropTarget.IsEmpty())
  6801. {
  6802. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  6803. Result = true;
  6804. ForceQueue = false;
  6805. CounterName = L"DownloadsDragDropFakeFile";
  6806. }
  6807. else
  6808. {
  6809. ForceQueue = false;
  6810. Enabled = false;
  6811. try
  6812. {
  6813. int Timer = 0;
  6814. Result = false;
  6815. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  6816. {
  6817. {
  6818. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6819. TDragExtCommStruct* CommStruct;
  6820. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6821. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6822. DebugAssert(CommStruct != NULL);
  6823. Result = !CommStruct->Dragging;
  6824. if (Result)
  6825. {
  6826. Directory = ExtractFilePath(CommStruct->DropDest);
  6827. CounterName = L"DownloadsDragDropExternalExt";
  6828. }
  6829. UnmapViewOfFile(CommStruct);
  6830. }
  6831. if (!Result)
  6832. {
  6833. Sleep(50);
  6834. Timer += 50;
  6835. Application->ProcessMessages();
  6836. }
  6837. }
  6838. }
  6839. __finally
  6840. {
  6841. Enabled = true;
  6842. }
  6843. }
  6844. return Result;
  6845. }
  6846. //---------------------------------------------------------------------------
  6847. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  6848. const UnicodeString TempDir, int SecDelay)
  6849. {
  6850. TDateTime Alarm = Now() + (double)((double)SecDelay*OneMillisecond);
  6851. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  6852. if (FDelayedDeletionTimer == NULL)
  6853. {
  6854. DebugAssert(HandleAllocated());
  6855. FDelayedDeletionTimer = new TTimer(this);
  6856. FDelayedDeletionTimer->Interval = 10000;
  6857. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  6858. }
  6859. else
  6860. {
  6861. FDelayedDeletionTimer->Enabled = true;
  6862. }
  6863. }
  6864. //---------------------------------------------------------------------------
  6865. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  6866. {
  6867. DebugAssert(FDelayedDeletionList != NULL);
  6868. TDateTime N = Now();
  6869. TDateTime Alert;
  6870. UnicodeString Directory;
  6871. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  6872. {
  6873. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  6874. if ((N >= Alert) || (Sender == NULL))
  6875. {
  6876. Directory = FDelayedDeletionList->Strings[Index];
  6877. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  6878. {
  6879. FDelayedDeletionList->Delete(Index);
  6880. }
  6881. }
  6882. }
  6883. if (FDelayedDeletionList->Count == 0)
  6884. {
  6885. FDelayedDeletionTimer->Enabled = false;
  6886. }
  6887. }
  6888. //---------------------------------------------------------------------------
  6889. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  6890. {
  6891. if (IsFileControl(FDDTargetControl, osRemote) ||
  6892. (FDDTargetControl == SessionsPageControl))
  6893. {
  6894. TTerminal * TargetTerminal = NULL;
  6895. TFileOperation Operation = foNone;
  6896. if (FDDTargetControl == SessionsPageControl)
  6897. {
  6898. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  6899. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  6900. // do not allow dropping on the "+" tab
  6901. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  6902. if (TargetTerminal != NULL)
  6903. {
  6904. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  6905. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  6906. {
  6907. Operation = foRemoteMove;
  6908. }
  6909. else
  6910. {
  6911. Operation = foRemoteCopy;
  6912. }
  6913. }
  6914. }
  6915. else
  6916. {
  6917. if (FLastDropEffect == DROPEFFECT_MOVE)
  6918. {
  6919. Operation = foRemoteMove;
  6920. }
  6921. else if (FLastDropEffect == DROPEFFECT_COPY)
  6922. {
  6923. Operation = foRemoteCopy;
  6924. }
  6925. }
  6926. if (Operation != foNone)
  6927. {
  6928. RemoteFileControlFileOperation(DropSourceControl,
  6929. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  6930. }
  6931. // abort drag&drop
  6932. Abort();
  6933. }
  6934. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  6935. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  6936. (FDDTargetControl != QueueView3))
  6937. {
  6938. DebugAssert(!FDragTempDir.IsEmpty());
  6939. TTransferType Type;
  6940. UnicodeString TempDir = FDragTempDir;
  6941. // We clear FDragTempDir before calling
  6942. // just in case it fail (raises exception)
  6943. FDragTempDir = L"";
  6944. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  6945. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  6946. // empty directory parameter means temp directory -> don't display it!
  6947. UnicodeString TargetDir = L"";
  6948. int Options = 0;
  6949. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  6950. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  6951. {
  6952. Abort();
  6953. }
  6954. // TargetDir is set when dropped on local file control
  6955. // (this was workaround for legacy dirview event handling, now it should be
  6956. // made prettier)
  6957. if (TargetDir.IsEmpty())
  6958. {
  6959. TargetDir = TempDir;
  6960. if (ForceDirectories(ApiPath(TargetDir)))
  6961. {
  6962. DebugAssert(Terminal && !TargetDir.IsEmpty());
  6963. FPendingTempSpaceWarn = true;
  6964. try
  6965. {
  6966. FDragDropOperation = true;
  6967. int Params = cpTemporary |
  6968. (Type == ttMove ? cpDelete : 0);
  6969. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  6970. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  6971. }
  6972. __finally
  6973. {
  6974. FDragDropOperation = false;
  6975. FPendingTempSpaceWarn = false;
  6976. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  6977. }
  6978. }
  6979. else
  6980. {
  6981. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  6982. }
  6983. }
  6984. }
  6985. }
  6986. //---------------------------------------------------------------------------
  6987. void __fastcall TCustomScpExplorerForm::DDDownload(
  6988. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  6989. {
  6990. TAutoBatch AutoBatch(this);
  6991. UpdateCopyParamCounters(*CopyParam);
  6992. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  6993. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  6994. {
  6995. RemoteDriveView->UpdateDropSource();
  6996. }
  6997. }
  6998. //---------------------------------------------------------------------------
  6999. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7000. {
  7001. public:
  7002. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7003. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7004. {
  7005. }
  7006. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7007. {
  7008. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7009. TDataObjectFilesEx::AllowData(FormatEtc);
  7010. }
  7011. };
  7012. //---------------------------------------------------------------------------
  7013. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7014. TObject * Sender, TDataObject *& DataObject)
  7015. {
  7016. if (FDDExtMapFile != NULL)
  7017. {
  7018. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7019. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7020. {
  7021. Abort();
  7022. }
  7023. if (FileList->Count > 0)
  7024. {
  7025. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7026. if (!FilesObject->IsValid(true, true))
  7027. {
  7028. FilesObject->_Release();
  7029. }
  7030. else
  7031. {
  7032. DataObject = FilesObject;
  7033. }
  7034. }
  7035. }
  7036. }
  7037. //---------------------------------------------------------------------------
  7038. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7039. {
  7040. DebugFail();
  7041. }
  7042. //---------------------------------------------------------------------------
  7043. void __fastcall TCustomScpExplorerForm::GoToTree()
  7044. {
  7045. ComponentVisible[fcRemoteTree] = true;
  7046. RemoteDriveView->SetFocus();
  7047. }
  7048. //---------------------------------------------------------------------------
  7049. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7050. TPanelExport Export)
  7051. {
  7052. TCustomDirView * DirView = this->DirView(Side);
  7053. std::unique_ptr<TStrings> ExportData(new TStringList());
  7054. switch (Export)
  7055. {
  7056. case pePath:
  7057. ExportData->Add(DirView->PathName);
  7058. break;
  7059. case peFileList:
  7060. case peFullFileList:
  7061. {
  7062. bool FullPath = (Export == peFullFileList);
  7063. DirView->CreateFileList(false, FullPath, ExportData.get());
  7064. for (int Index = 0; Index < ExportData->Count; Index++)
  7065. {
  7066. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7067. {
  7068. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7069. }
  7070. }
  7071. }
  7072. break;
  7073. default:
  7074. DebugFail();
  7075. }
  7076. return ExportData.release();
  7077. }
  7078. //---------------------------------------------------------------------------
  7079. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7080. TPanelExport Export, TPanelExportDestination Destination)
  7081. {
  7082. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7083. PanelExportStore(Side, Export, Destination, ExportData.get());
  7084. }
  7085. //---------------------------------------------------------------------------
  7086. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7087. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7088. TStrings * ExportData)
  7089. {
  7090. if (Destination == pedClipboard)
  7091. {
  7092. TInstantOperationVisualizer Visualizer;
  7093. CopyToClipboard(ExportData);
  7094. }
  7095. else
  7096. {
  7097. DebugFail();
  7098. }
  7099. }
  7100. //---------------------------------------------------------------------------
  7101. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7102. {
  7103. TCustomDirView * DirView = this->DirView(Side);
  7104. UnicodeString Mask = DirView->Mask;
  7105. if (DoFilterMaskDialog(DirView, Mask))
  7106. {
  7107. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7108. Configuration->Usage->Inc(L"Filters");
  7109. }
  7110. }
  7111. //---------------------------------------------------------------------------
  7112. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7113. {
  7114. return FQueueController->DefaultOperation();
  7115. }
  7116. //---------------------------------------------------------------------------
  7117. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7118. TQueueOperation Operation, void ** Param)
  7119. {
  7120. switch (Operation)
  7121. {
  7122. case qoPreferences:
  7123. return true;
  7124. case qoGoTo:
  7125. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7126. case qoOnceEmpty:
  7127. return !FQueueController->Empty;
  7128. default:
  7129. return FQueueController->AllowOperation(Operation, Param);
  7130. }
  7131. }
  7132. //---------------------------------------------------------------------------
  7133. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7134. {
  7135. if (DebugAlwaysTrue(QueueView3->Visible))
  7136. {
  7137. QueueView3->SetFocus();
  7138. }
  7139. }
  7140. //---------------------------------------------------------------------------
  7141. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7142. TQueueOperation Operation, void * Param)
  7143. {
  7144. if (Operation == qoGoTo)
  7145. {
  7146. GoToQueue();
  7147. }
  7148. else if (Operation == qoPreferences)
  7149. {
  7150. PreferencesDialog(pmQueue);
  7151. }
  7152. else
  7153. {
  7154. FQueueController->ExecuteOperation(Operation, Param);
  7155. }
  7156. }
  7157. //---------------------------------------------------------------------------
  7158. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7159. {
  7160. return (Queue != NULL) && Queue->Enabled;
  7161. }
  7162. //---------------------------------------------------------------------------
  7163. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7164. {
  7165. DebugAssert(Queue != NULL);
  7166. if (Queue != NULL)
  7167. {
  7168. Queue->Enabled = !Queue->Enabled;
  7169. }
  7170. }
  7171. //---------------------------------------------------------------------------
  7172. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7173. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7174. {
  7175. FQueueActedItem = QueueView3->ItemFocused;
  7176. }
  7177. //---------------------------------------------------------------------------
  7178. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7179. {
  7180. return TopDock->Height + QueueSplitter->Height;
  7181. }
  7182. //---------------------------------------------------------------------------
  7183. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7184. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7185. {
  7186. // when queue is hidden by double-clicking splitter, stray attempt to
  7187. // resize the panel with strange value arrives, make sure it is ignored
  7188. if (ComponentVisible[fcQueueView])
  7189. {
  7190. int HeightLimit = ClientHeight - GetStaticComponentsHeight() -
  7191. RemotePanel->Constraints->MinHeight;
  7192. if (NewSize > HeightLimit)
  7193. {
  7194. NewSize = HeightLimit;
  7195. }
  7196. }
  7197. else
  7198. {
  7199. Accept = false;
  7200. }
  7201. }
  7202. //---------------------------------------------------------------------------
  7203. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7204. TDragObject *& /*DragObject*/)
  7205. {
  7206. FQueueActedItem = QueueView3->ItemFocused;
  7207. }
  7208. //---------------------------------------------------------------------------
  7209. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7210. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7211. {
  7212. Accept = true;
  7213. if (Source == QueueView3)
  7214. {
  7215. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7216. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7217. if (Accept)
  7218. {
  7219. TQueueItemProxy * QueueItem;
  7220. TQueueItemProxy * DestQueueItem;
  7221. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7222. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7223. Accept = (QueueItem != DestQueueItem) &&
  7224. (QueueItem->Status == TQueueItem::qsPending) &&
  7225. (DestQueueItem->Status == TQueueItem::qsPending);
  7226. }
  7227. }
  7228. }
  7229. //---------------------------------------------------------------------------
  7230. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7231. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7232. {
  7233. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7234. {
  7235. TQueueItemProxy * QueueItem;
  7236. TQueueItemProxy * DestQueueItem;
  7237. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7238. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7239. QueueItem->Move(DestQueueItem);
  7240. }
  7241. }
  7242. //---------------------------------------------------------------------------
  7243. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7244. {
  7245. if ((QueueView3->ItemFocused == NULL) &&
  7246. (QueueView3->Items->Count > 0))
  7247. {
  7248. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7249. }
  7250. QueueLabelUpdateStatus();
  7251. }
  7252. //---------------------------------------------------------------------------
  7253. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7254. {
  7255. QueueLabelUpdateStatus();
  7256. }
  7257. //---------------------------------------------------------------------------
  7258. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7259. {
  7260. QueueLabel->UpdateStatus();
  7261. }
  7262. //---------------------------------------------------------------------------
  7263. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7264. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7265. {
  7266. if (Selected)
  7267. {
  7268. NonVisualDataModule->UpdateNonVisibleActions();
  7269. }
  7270. }
  7271. //---------------------------------------------------------------------------
  7272. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7273. {
  7274. TDragDropFilesEx * Result = NULL;
  7275. if (Sender == SessionsPageControl)
  7276. {
  7277. Result = FSessionsDragDropFilesEx;
  7278. }
  7279. else if (Sender == QueueView3)
  7280. {
  7281. Result = FQueueDragDropFilesEx;
  7282. }
  7283. else
  7284. {
  7285. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7286. if (DirView != NULL)
  7287. {
  7288. Result = DirView->DragDropFilesEx;
  7289. }
  7290. else
  7291. {
  7292. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7293. if (DriveView != NULL)
  7294. {
  7295. Result = DriveView->DragDropFilesEx;
  7296. }
  7297. }
  7298. }
  7299. DebugAssert(Result != NULL);
  7300. return Result;
  7301. }
  7302. //---------------------------------------------------------------------------
  7303. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7304. {
  7305. return (DView->SelCount == DView->FilesCount);
  7306. }
  7307. //---------------------------------------------------------------------------
  7308. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7309. {
  7310. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7311. }
  7312. //---------------------------------------------------------------------------
  7313. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7314. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7315. {
  7316. TFileOperation Operation;
  7317. switch (Effect)
  7318. {
  7319. case DROPEFFECT_MOVE:
  7320. Operation = foMove;
  7321. break;
  7322. case DROPEFFECT_COPY:
  7323. // occures on WinXP (reported by user)
  7324. default:
  7325. Operation = foCopy;
  7326. break;
  7327. };
  7328. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7329. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7330. if (DragDropFilesEx->FileList->Count > 0)
  7331. {
  7332. TStrings * FileList = new TStringList();
  7333. try
  7334. {
  7335. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7336. {
  7337. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7338. }
  7339. FDragDropOperation = true;
  7340. TTransferOperationParam Param;
  7341. Param.TargetDirectory = TargetPath;
  7342. // upload, no temp dirs
  7343. Param.Temp = false;
  7344. Param.DragDrop = DragDrop;
  7345. Param.Options =
  7346. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7347. if (ForceQueue)
  7348. {
  7349. Param.Queue = asOn;
  7350. }
  7351. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7352. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7353. {
  7354. if (IsFileControl(DropSourceControl, osLocal))
  7355. {
  7356. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7357. }
  7358. else
  7359. {
  7360. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7361. }
  7362. }
  7363. }
  7364. __finally
  7365. {
  7366. FDragDropOperation = false;
  7367. delete FileList;
  7368. }
  7369. }
  7370. }
  7371. //---------------------------------------------------------------------------
  7372. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7373. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7374. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7375. {
  7376. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7377. }
  7378. //---------------------------------------------------------------------------
  7379. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7380. TObject * Sender, int grfKeyState, int & dwEffect)
  7381. {
  7382. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7383. if ((dwEffect != DROPEFFECT_NONE) &&
  7384. IsFileControl(DropSourceControl, osRemote))
  7385. {
  7386. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7387. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7388. (RemoteDirView->DropTarget == NULL))
  7389. {
  7390. dwEffect = DROPEFFECT_NONE;
  7391. }
  7392. else
  7393. {
  7394. if (dwEffect == DROPEFFECT_COPY)
  7395. {
  7396. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7397. // currently we support copying always (at least via temporary directory);
  7398. // remove associated checks once this all proves stable and working
  7399. bool CopyCapable = true;
  7400. // if we do not support neither of operations, there's no discussion
  7401. if (!MoveCapable && !CopyCapable)
  7402. {
  7403. dwEffect = DROPEFFECT_NONE;
  7404. }
  7405. else
  7406. {
  7407. // The default effect inside remote panel is move,
  7408. // unless we do not support it, but support copy
  7409. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7410. {
  7411. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7412. }
  7413. else
  7414. {
  7415. // with ctrl-down, we want copy unless it is not supported
  7416. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7417. }
  7418. }
  7419. }
  7420. }
  7421. }
  7422. }
  7423. //---------------------------------------------------------------------------
  7424. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7425. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7426. {
  7427. if (FDDTotalSize >= 0)
  7428. {
  7429. if (File->IsDirectory)
  7430. {
  7431. FDDTotalSize = -1;
  7432. }
  7433. else
  7434. {
  7435. FDDTotalSize += File->Size;
  7436. }
  7437. }
  7438. DebugAssert(!FDragTempDir.IsEmpty());
  7439. // TODO: this is quite ineffective
  7440. // TODO: what if invalid character replacement is disabled?
  7441. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7442. UnicodeString TransferFileName;
  7443. if (Sender == RemoteDriveView)
  7444. {
  7445. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7446. }
  7447. else
  7448. {
  7449. TransferFileName = File->FileName;
  7450. }
  7451. FDDFileList->AddObject(TransferFileName, File);
  7452. }
  7453. //---------------------------------------------------------------------------
  7454. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7455. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7456. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7457. {
  7458. // sometimes we do not get DDEnd so the list is not released
  7459. SAFE_DESTROY(FDDFileList);
  7460. FDDFileList = new TStringList();
  7461. FDragTempDir = WinConfiguration->TemporaryDir();
  7462. FDDTotalSize = 0;
  7463. FDragDropSshTerminate.reset(NULL);
  7464. }
  7465. //---------------------------------------------------------------------------
  7466. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7467. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7468. HRESULT & Result)
  7469. {
  7470. if (Result == DRAGDROP_S_DROP)
  7471. {
  7472. try
  7473. {
  7474. GlobalDragImageList->HideDragImage();
  7475. try
  7476. {
  7477. RemoteFileControlDDTargetDrop();
  7478. }
  7479. catch(ESshTerminate & E)
  7480. {
  7481. FDragDropSshTerminate.reset(E.Clone());
  7482. }
  7483. }
  7484. catch (Exception &E)
  7485. {
  7486. // If downloading fails we need to cancel drag&drop, otherwise
  7487. // Explorer shows error
  7488. // But by the way exception probably never reach this point as
  7489. // it's catched on way.
  7490. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7491. Result = DRAGDROP_S_CANCEL;
  7492. ShowExtendedException(Terminal, &E);
  7493. }
  7494. }
  7495. }
  7496. //---------------------------------------------------------------------------
  7497. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7498. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7499. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7500. {
  7501. TFileMasks::TParams MaskParams;
  7502. MaskParams.Size = Size;
  7503. MaskParams.Modification = Modification;
  7504. // this does not re-parse the mask if it is the same as the last time
  7505. FDirViewMatchMask = Masks;
  7506. bool ImplicitMatch;
  7507. Matches =
  7508. // RecurseInclude parameter has no effect as the Path is empty
  7509. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7510. (AllowImplicitMatches || !ImplicitMatch);
  7511. }
  7512. //---------------------------------------------------------------------------
  7513. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7514. TObject * Sender, TListItem * Item, WORD & Indexes)
  7515. {
  7516. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7517. UnicodeString Ext;
  7518. if (DirView == RemoteDirView)
  7519. {
  7520. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7521. }
  7522. else
  7523. {
  7524. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7525. }
  7526. if (SameText(Ext, Configuration->PartialExt))
  7527. {
  7528. Indexes |= oiPartial;
  7529. }
  7530. }
  7531. //---------------------------------------------------------------------------
  7532. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7533. {
  7534. return
  7535. DirViewEnabled(osCurrent) &&
  7536. DirView(osCurrent)->CanPasteFromClipBoard();
  7537. }
  7538. //---------------------------------------------------------------------------
  7539. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7540. {
  7541. bool Result = false;
  7542. if (CanPasteToDirViewFromClipBoard())
  7543. {
  7544. Result = true;
  7545. }
  7546. else
  7547. {
  7548. UnicodeString ClipboardText;
  7549. if (NonEmptyTextFromClipboard(ClipboardText))
  7550. {
  7551. if (StoredSessions->IsUrl(ClipboardText))
  7552. {
  7553. Result = true;
  7554. }
  7555. else
  7556. {
  7557. Result = DirViewEnabled(osCurrent);
  7558. }
  7559. }
  7560. }
  7561. return Result;
  7562. }
  7563. //---------------------------------------------------------------------------
  7564. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7565. {
  7566. if (DoesClipboardContainOurFiles())
  7567. {
  7568. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7569. {
  7570. TTerminalManager * Manager = TTerminalManager::Instance();
  7571. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7572. Manager->ActiveTerminal = FClipboardTerminal;
  7573. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7574. }
  7575. }
  7576. else if (CanPasteToDirViewFromClipBoard())
  7577. {
  7578. DirView(osCurrent)->PasteFromClipBoard();
  7579. }
  7580. else
  7581. {
  7582. UnicodeString ClipboardText;
  7583. if (NonEmptyTextFromClipboard(ClipboardText))
  7584. {
  7585. if (StoredSessions->IsUrl(ClipboardText))
  7586. {
  7587. NewSession(false, ClipboardText);
  7588. }
  7589. else
  7590. {
  7591. DirView(osCurrent)->Path = ClipboardText;
  7592. }
  7593. }
  7594. }
  7595. }
  7596. //---------------------------------------------------------------------------
  7597. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7598. {
  7599. // TBD
  7600. }
  7601. //---------------------------------------------------------------------------
  7602. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7603. {
  7604. TCustomDirView * ADirView = DirView(Side);
  7605. ADirView->SelectAll(Mode);
  7606. ADirView->SetFocus();
  7607. }
  7608. //---------------------------------------------------------------------------
  7609. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7610. {
  7611. TCustomDirView * ADirView = DirView(Side);
  7612. TFileFilter Filter;
  7613. DefaultFileFilter(Filter);
  7614. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7615. {
  7616. Configuration->Usage->Inc(L"MaskSelections");
  7617. ADirView->SelectFiles(Filter, Select);
  7618. ADirView->SetFocus();
  7619. }
  7620. }
  7621. //---------------------------------------------------------------------------
  7622. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7623. {
  7624. TCustomDirView * ADirView = DirView(Side);
  7625. ADirView->RestoreSelectedNames();
  7626. ADirView->SetFocus();
  7627. }
  7628. //---------------------------------------------------------------------------
  7629. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7630. {
  7631. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7632. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7633. {
  7634. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7635. UnicodeString Ext;
  7636. if (GetSide(osCurrent) == osRemote)
  7637. {
  7638. Ext = UnixExtractFileExt(FileName);
  7639. }
  7640. else
  7641. {
  7642. Ext = ExtractFileExt(FileName);
  7643. }
  7644. if (Ext.IsEmpty())
  7645. {
  7646. Ext = L".";
  7647. }
  7648. TFileFilter Filter;
  7649. Filter.Masks = FORMAT(L"*%s", (Ext));
  7650. Filter.Directories = false;
  7651. CurrentDirView->SelectFiles(Filter, Select);
  7652. }
  7653. }
  7654. //---------------------------------------------------------------------------
  7655. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7656. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7657. {
  7658. UnicodeString Result;
  7659. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7660. {
  7661. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  7662. }
  7663. else if ((Side == osRemote) && (Terminal == NULL))
  7664. {
  7665. // noop
  7666. }
  7667. else
  7668. {
  7669. Result =
  7670. FMTLOAD(FILE_INFO_FORMAT,
  7671. (FormatBytes(FileInfo.SelectedSize),
  7672. FormatBytes(FileInfo.FilesSize),
  7673. FormatNumber(FileInfo.SelectedCount),
  7674. FormatNumber(FileInfo.FilesCount)));
  7675. }
  7676. return Result;
  7677. }
  7678. //---------------------------------------------------------------------------
  7679. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7680. TTBXStatusPanel * Panel, TOperationSide Side)
  7681. {
  7682. if (Panel->Index == 1)
  7683. {
  7684. ToggleShowHiddenFiles();
  7685. }
  7686. else if (Panel->Index == 2)
  7687. {
  7688. Filter(Side);
  7689. }
  7690. }
  7691. //---------------------------------------------------------------------------
  7692. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  7693. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  7694. {
  7695. DebugAssert(!StatusBar->SimplePanel);
  7696. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  7697. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  7698. }
  7699. //---------------------------------------------------------------------------
  7700. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  7701. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  7702. {
  7703. DebugAssert(StatusBar->Panels->Count >= 3);
  7704. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  7705. if (FileInfo.HiddenCount > 0)
  7706. {
  7707. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  7708. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7709. }
  7710. else
  7711. {
  7712. HiddenFilesPanel->ViewPriority = 0;
  7713. // not really necessary, just to cleanup no-longer-valid data
  7714. HiddenFilesPanel->Caption = L"";
  7715. }
  7716. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  7717. if (FileInfo.FilteredCount > 0)
  7718. {
  7719. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  7720. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7721. }
  7722. else
  7723. {
  7724. FilteredFilesPanel->ViewPriority = 0;
  7725. // not really necessary, just to cleanup no-longer-valid data
  7726. FilteredFilesPanel->Caption = L"";
  7727. }
  7728. }
  7729. //---------------------------------------------------------------------------
  7730. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  7731. TObject * /*Sender*/)
  7732. {
  7733. if (RemoteDirView->Enabled)
  7734. {
  7735. RemoteDirView->SetFocus();
  7736. }
  7737. }
  7738. //---------------------------------------------------------------------------
  7739. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  7740. {
  7741. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  7742. switch (Config.Show)
  7743. {
  7744. case qvShow:
  7745. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  7746. {
  7747. Config.Show = qvHide;
  7748. }
  7749. else
  7750. {
  7751. Config.Show = Config.LastHideShow;
  7752. }
  7753. break;
  7754. case qvHideWhenEmpty:
  7755. if (ComponentVisible[fcQueueView])
  7756. {
  7757. Config.Show = qvHide;
  7758. }
  7759. else
  7760. {
  7761. Config.LastHideShow = Config.Show;
  7762. Config.Show = qvShow;
  7763. }
  7764. break;
  7765. case qvHide:
  7766. Config.LastHideShow = Config.Show;
  7767. Config.Show = qvShow;
  7768. break;
  7769. }
  7770. WinConfiguration->QueueView = Config;
  7771. }
  7772. //---------------------------------------------------------------------------
  7773. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  7774. {
  7775. UnicodeString Result;
  7776. if (FTerminal != NULL)
  7777. {
  7778. switch (WinConfiguration->PathInCaption)
  7779. {
  7780. case picShort:
  7781. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  7782. break;
  7783. case picFull:
  7784. Result = FTerminal->CurrentDirectory;
  7785. break;
  7786. }
  7787. }
  7788. return Result;
  7789. }
  7790. //---------------------------------------------------------------------------
  7791. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  7792. {
  7793. TColor Result = GetWindowColor(FSessionColor);
  7794. return Result;
  7795. }
  7796. //---------------------------------------------------------------------------
  7797. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  7798. {
  7799. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  7800. return Result;
  7801. }
  7802. //---------------------------------------------------------------------------
  7803. void __fastcall TCustomScpExplorerForm::UpdateControls()
  7804. {
  7805. TTerminalManager::Instance()->UpdateAppTitle();
  7806. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  7807. // background to gray on Windows 7 (works on Windows 10).
  7808. // See also EnableControl
  7809. if (Showing)
  7810. {
  7811. bool HasTerminal = (Terminal != NULL) && Terminal->Active;
  7812. if (HasTerminal)
  7813. {
  7814. // Update path when it changes
  7815. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  7816. {
  7817. UpdateSessionTab(SessionsPageControl->ActivePage);
  7818. }
  7819. if (!RemoteDirView->Enabled)
  7820. {
  7821. RemoteDirView->Enabled = true;
  7822. if (FRemoteDirViewWasFocused)
  7823. {
  7824. ActiveControl = RemoteDirView;
  7825. }
  7826. }
  7827. RemoteDirView->Color = PanelColor();
  7828. }
  7829. else
  7830. {
  7831. if (RemoteDirView->Enabled)
  7832. {
  7833. // This is first called when the form is being constructed
  7834. // (not anymore due to Showing test above)
  7835. // but the false is overriden in the constructor later.
  7836. // An even later in TScpCommanderForm::DoShow()
  7837. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  7838. RemoteDirView->Enabled = false;
  7839. RemoteDirView->Color = DisabledPanelColor();
  7840. }
  7841. }
  7842. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  7843. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  7844. RemoteDriveView->Color = RemoteDirView->Color;
  7845. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  7846. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fsBackgroundTransfers];
  7847. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  7848. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  7849. QueueLabelUpdateStatus();
  7850. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  7851. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  7852. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  7853. }
  7854. }
  7855. //---------------------------------------------------------------------------
  7856. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  7857. {
  7858. UpdateControls();
  7859. }
  7860. //---------------------------------------------------------------------------
  7861. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  7862. TObject * Sender)
  7863. {
  7864. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7865. DebugAssert(DirView != NULL);
  7866. DoDirViewLoaded(DirView);
  7867. TransferPresetAutoSelect();
  7868. }
  7869. //---------------------------------------------------------------------------
  7870. void __fastcall TCustomScpExplorerForm::StartUpdates()
  7871. {
  7872. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  7873. // first run after installation
  7874. if (double(Updates.LastCheck) == 0)
  7875. {
  7876. // make sure next time there will be an update (if enabled)
  7877. Updates.LastCheck = TDateTime(1);
  7878. WinConfiguration->Updates = Updates;
  7879. }
  7880. else if ((double(Updates.Period) > 0) &&
  7881. (Now() - Updates.LastCheck >= Updates.Period))
  7882. {
  7883. TThreadMethod OnUpdatesChecked = NULL;
  7884. if (!IsUWP())
  7885. {
  7886. OnUpdatesChecked = UpdatesChecked;
  7887. }
  7888. StartUpdateThread(OnUpdatesChecked);
  7889. }
  7890. }
  7891. //---------------------------------------------------------------------------
  7892. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  7893. {
  7894. UnicodeString Message;
  7895. bool New;
  7896. TQueryType Type;
  7897. GetUpdatesMessage(Message, New, Type, false);
  7898. if (!Message.IsEmpty())
  7899. {
  7900. if (New)
  7901. {
  7902. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  7903. }
  7904. if (!New && (Type != qtWarning))
  7905. {
  7906. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  7907. }
  7908. else
  7909. {
  7910. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  7911. }
  7912. if (New)
  7913. {
  7914. Configuration->Usage->Inc(L"UpdateNotifications");
  7915. }
  7916. }
  7917. }
  7918. //---------------------------------------------------------------------------
  7919. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  7920. {
  7921. RestoreApp();
  7922. bool CanDisplay = !NonVisualDataModule->Busy;
  7923. if (!CanDisplay && (Screen->ActiveForm != NULL))
  7924. {
  7925. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  7926. }
  7927. if (CanDisplay)
  7928. {
  7929. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  7930. CheckForUpdates(true);
  7931. }
  7932. else
  7933. {
  7934. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  7935. }
  7936. }
  7937. //---------------------------------------------------------------------------
  7938. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  7939. TCopyParamRuleData & Data)
  7940. {
  7941. DebugAssert(Terminal != NULL);
  7942. Data.HostName = Terminal->SessionData->HostNameExpanded;
  7943. Data.UserName = Terminal->SessionData->UserNameExpanded;
  7944. Data.RemoteDirectory = RemoteDirView->PathName;
  7945. }
  7946. //---------------------------------------------------------------------------
  7947. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  7948. {
  7949. // Terminal can be null when we are changing local directory implicitly,
  7950. // because it has been deleted, while no session is connected
  7951. // (Login dialog is open)
  7952. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  7953. {
  7954. TCopyParamRuleData Data;
  7955. GetTransferPresetAutoSelectData(Data);
  7956. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  7957. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  7958. if (CopyParamIndex < 0)
  7959. {
  7960. // there is no preset that matches autoselection
  7961. // set preset that we consider "default"
  7962. FCopyParamAutoSelected = L""; // forget last autoselected preset
  7963. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  7964. }
  7965. else
  7966. {
  7967. // there is preset matching autoselection
  7968. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  7969. if (CopyParamName == FCopyParamAutoSelected)
  7970. {
  7971. // autoselected the same preset as the last time
  7972. // make no change (i.e. preserve custom user preset, if any)
  7973. }
  7974. else
  7975. {
  7976. // autoselected the different preset then the last time (or there
  7977. // was default preset set)
  7978. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  7979. GUIConfiguration->CopyParamCurrent = CopyParamName;
  7980. }
  7981. }
  7982. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  7983. {
  7984. if (CopyParamIndex >= 0)
  7985. {
  7986. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  7987. }
  7988. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  7989. try
  7990. {
  7991. int Fmt =
  7992. (CopyParamIndex < 0) ?
  7993. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  7994. COPY_PARAM_AUTOSELECTED;
  7995. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  7996. Data->Message = MainInstructions(Message);
  7997. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  7998. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  7999. CopyParamAttrs);
  8000. if (CopyParamIndex >= 0)
  8001. {
  8002. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8003. Info = FORMAT(L"%s\n \n%s", (Info,
  8004. FMTLOAD(COPY_PARAM_RULE,
  8005. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8006. }
  8007. Data->Message += L"\n\n" + Info;
  8008. if (WinConfiguration->CopyParamAutoSelectNotice)
  8009. {
  8010. TransferPresetNoteMessage(Data, true);
  8011. }
  8012. else
  8013. {
  8014. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8015. Data = NULL; // ownership passed
  8016. }
  8017. }
  8018. __finally
  8019. {
  8020. delete Data;
  8021. }
  8022. }
  8023. }
  8024. }
  8025. //---------------------------------------------------------------------------
  8026. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8027. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8028. {
  8029. DebugAssert(NoteData != NULL);
  8030. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8031. TQueryButtonAlias Aliases[1];
  8032. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8033. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8034. Params.Aliases = Aliases;
  8035. Params.AliasesCount = LENOF(Aliases);
  8036. unsigned int Result =
  8037. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8038. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8039. switch (Result)
  8040. {
  8041. case qaNeverAskAgain:
  8042. DebugAssert(AllowNeverAskAgain);
  8043. WinConfiguration->CopyParamAutoSelectNotice = false;
  8044. break;
  8045. case qaIgnore:
  8046. PreferencesDialog(pmPresets);
  8047. break;
  8048. }
  8049. }
  8050. //---------------------------------------------------------------------------
  8051. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8052. {
  8053. // as of now useless, as this is used for notes only, never for balloons, ...
  8054. RestoreApp();
  8055. // .. and we should never be busy here
  8056. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8057. {
  8058. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8059. }
  8060. }
  8061. //---------------------------------------------------------------------------
  8062. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8063. TPreferencesMode APreferencesMode)
  8064. {
  8065. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8066. TCopyParamRuleData Data;
  8067. if (Terminal != NULL)
  8068. {
  8069. PreferencesData.reset(new TPreferencesDialogData());
  8070. GetTransferPresetAutoSelectData(Data);
  8071. PreferencesData->CopyParamRuleData = &Data;
  8072. }
  8073. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8074. }
  8075. //---------------------------------------------------------------------------
  8076. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8077. const TCustomCommandType & Command)
  8078. {
  8079. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8080. {
  8081. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (Command.Command)));
  8082. }
  8083. }
  8084. //---------------------------------------------------------------------------
  8085. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8086. {
  8087. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8088. TCustomCommandType Command;
  8089. // make sure we use local custom command when remote are not supported
  8090. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8091. {
  8092. Command = FLastCustomCommand;
  8093. }
  8094. else
  8095. {
  8096. Command.Params = Command.Params | ccLocal;
  8097. }
  8098. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8099. FEditingFocusedAdHocCommand = OnFocused;
  8100. bool LocalSide = (FCurrentSide == osLocal);
  8101. int Options =
  8102. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8103. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8104. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8105. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8106. {
  8107. FLastCustomCommand = Command;
  8108. UpdateCustomCommandsToolbar();
  8109. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8110. }
  8111. }
  8112. //---------------------------------------------------------------------------
  8113. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8114. {
  8115. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8116. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8117. DebugAssert(State > 0);
  8118. if (State <= 0)
  8119. {
  8120. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (FLastCustomCommand.Command)));
  8121. }
  8122. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8123. }
  8124. //---------------------------------------------------------------------------
  8125. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8126. TCustomCommandType & Command, int & State)
  8127. {
  8128. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8129. if (Result)
  8130. {
  8131. Command = FLastCustomCommand;
  8132. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8133. }
  8134. return Result;
  8135. }
  8136. //---------------------------------------------------------------------------
  8137. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8138. {
  8139. if (RemoteDirView->ItemFocused != NULL)
  8140. {
  8141. RemoteDirView->ItemFocused->CancelEdit();
  8142. }
  8143. ResetIncrementalSearch();
  8144. }
  8145. //---------------------------------------------------------------------------
  8146. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8147. {
  8148. DebugAssert(ComponentVisible[Component]);
  8149. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8150. }
  8151. //---------------------------------------------------------------------------
  8152. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8153. {
  8154. // when queue panel is resized here directly, the status bar is stretched
  8155. // over whole space the panel occupied
  8156. PostComponentHide(fcQueueView);
  8157. }
  8158. //---------------------------------------------------------------------------
  8159. void __fastcall TCustomScpExplorerForm::WMWinIniChange(TMessage & Message)
  8160. {
  8161. WinConfiguration->ResetSysDarkTheme();
  8162. ConfigurationChanged();
  8163. ConfigureInterface();
  8164. TForm::Dispatch(&Message);
  8165. }
  8166. //---------------------------------------------------------------------------
  8167. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8168. {
  8169. TMessage * M = static_cast<TMessage*>(Message);
  8170. switch (M->Msg)
  8171. {
  8172. case CM_DIALOGCHAR:
  8173. CMDialogChar(*M);
  8174. break;
  8175. case WM_APPCOMMAND:
  8176. WMAppCommand(*M);
  8177. break;
  8178. case WM_SYSCOMMAND:
  8179. WMSysCommand(*M);
  8180. break;
  8181. case WM_QUERYENDSESSION:
  8182. WMQueryEndSession(*M);
  8183. break;
  8184. case WM_ENDSESSION:
  8185. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8186. break;
  8187. #ifdef _DEBUG
  8188. case WM_WINDOWPOSCHANGED:
  8189. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8190. break;
  8191. case CM_CUSTOMSTYLECHANGED:
  8192. TForm::Dispatch(Message);
  8193. break;
  8194. #endif
  8195. case WM_COMPONENT_HIDE:
  8196. {
  8197. Byte Component = static_cast<Byte>(M->WParam);
  8198. // sanity check
  8199. if (ComponentVisible[Component])
  8200. {
  8201. // special treatment
  8202. if (Component == fcQueueView)
  8203. {
  8204. ToggleQueueVisibility();
  8205. DebugAssert(!ComponentVisible[fcQueueView]);
  8206. }
  8207. else
  8208. {
  8209. ComponentVisible[Component] = false;
  8210. }
  8211. }
  8212. }
  8213. break;
  8214. case WM_COPYDATA:
  8215. WMCopyData(*M);
  8216. break;
  8217. case WM_MANAGES_CAPTION:
  8218. // caption managed in TTerminalManager::UpdateAppTitle()
  8219. M->Result = 1;
  8220. break;
  8221. case WM_WANTS_MOUSEWHEEL:
  8222. M->Result = 1;
  8223. break;
  8224. case CM_SHOWINGCHANGED:
  8225. CMShowingChanged(*M);
  8226. break;
  8227. case WM_CLOSE:
  8228. WMClose(*M);
  8229. break;
  8230. case WM_DPICHANGED:
  8231. WMDpiChanged(*M);
  8232. break;
  8233. case CM_DPICHANGED:
  8234. CMDpiChanged(*M);
  8235. break;
  8236. case WM_WININICHANGE:
  8237. WMWinIniChange(*M);
  8238. break;
  8239. case CM_DIALOGKEY:
  8240. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8241. break;
  8242. default:
  8243. TForm::Dispatch(Message);
  8244. break;
  8245. }
  8246. }
  8247. //---------------------------------------------------------------------------
  8248. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8249. {
  8250. // noop
  8251. }
  8252. //---------------------------------------------------------------------------
  8253. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8254. {
  8255. TForm::Dispatch(&Message);
  8256. FSessionColors->Clear();
  8257. AddFixedSessionImages();
  8258. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8259. UpdateImages();
  8260. }
  8261. //---------------------------------------------------------------------------
  8262. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8263. {
  8264. TForm::Dispatch(&Message);
  8265. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8266. UpdatePixelsPerInchMainWindowCounter();
  8267. }
  8268. //---------------------------------------------------------------------------
  8269. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8270. {
  8271. // Cannot close window while we are busy.
  8272. // We cannot test this in FormCloseQuery as that is called also from
  8273. // Close(), which is called by CloseApplicationAction. So we can be busy
  8274. // there already even, when it is legitimate to close the application.
  8275. // Possibly a better place to handle this would be WMSysCommand.
  8276. if (NonVisualDataModule->Busy)
  8277. {
  8278. Message.Result = 1;
  8279. }
  8280. else
  8281. {
  8282. TForm::Dispatch(&Message);
  8283. }
  8284. }
  8285. //---------------------------------------------------------------------------
  8286. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8287. {
  8288. TForm::Dispatch(&Message);
  8289. if (Showing && (Terminal == NULL))
  8290. {
  8291. // When we are starting minimized (i.e. from an installer),
  8292. // postpone showing Login dialog until we get restored.
  8293. // Otherwise the Login dialog (and Authentication window) show restored
  8294. // over invidible (minimized) main window.
  8295. if (WindowState == wsMinimized)
  8296. {
  8297. FNeedSession = true;
  8298. }
  8299. else
  8300. {
  8301. // This happens before application ever goes idle, so the toolbars would
  8302. // stay enabled (initial state) until the Login dialog is dismissed.
  8303. UpdateActions();
  8304. NonVisualDataModule->StartBusy();
  8305. try
  8306. {
  8307. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8308. // otherwise the dialog does not receive focus.
  8309. // With Commander interface the ProcessMessages is called already
  8310. // by TDriveView, but with Explorer interface, we need to call it explicily
  8311. Application->ProcessMessages();
  8312. // do not reload sessions, they have been loaded just now (optimization)
  8313. NeedSession(false);
  8314. }
  8315. __finally
  8316. {
  8317. NonVisualDataModule->EndBusy();
  8318. }
  8319. }
  8320. }
  8321. }
  8322. //---------------------------------------------------------------------------
  8323. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8324. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8325. int & MaxHeight)
  8326. {
  8327. // workaround for bug in TWinControl.CalcConstraints
  8328. // Check for empty rect (restore from iconic state) is done there only after
  8329. // call to AdjustClientRect, which enlarges the rect (for forms).
  8330. TRect R = GetClientRect();
  8331. // when restoring from iconic state, place no restrictions
  8332. if (IsRectEmpty(R))
  8333. {
  8334. MinWidth = 0;
  8335. MinHeight = 0;
  8336. MaxWidth = 32000;
  8337. MaxHeight = 32000;
  8338. }
  8339. }
  8340. //---------------------------------------------------------------------------
  8341. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8342. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8343. {
  8344. // terminal can be already closed (e.g. dropped connection)
  8345. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8346. {
  8347. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8348. try
  8349. {
  8350. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8351. }
  8352. catch(...)
  8353. {
  8354. if (!Terminal->Active)
  8355. {
  8356. Close = true;
  8357. }
  8358. throw;
  8359. }
  8360. }
  8361. }
  8362. //---------------------------------------------------------------------------
  8363. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8364. {
  8365. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8366. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8367. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8368. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8369. {
  8370. OnGetSpaceAvailable = GetSpaceAvailable;
  8371. }
  8372. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8373. OnGetSpaceAvailable);
  8374. }
  8375. //---------------------------------------------------------------------------
  8376. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8377. {
  8378. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8379. Terminal->FillSessionDataForCode(Data.get());
  8380. return Data.release();
  8381. }
  8382. //---------------------------------------------------------------------------
  8383. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8384. {
  8385. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8386. DoGenerateUrlDialog(Data.get(), Paths);
  8387. }
  8388. //---------------------------------------------------------------------------
  8389. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8390. {
  8391. GenerateUrl(NULL);
  8392. }
  8393. //---------------------------------------------------------------------------
  8394. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8395. {
  8396. std::unique_ptr<TStrings> Paths(new TStringList());
  8397. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8398. GenerateUrl(Paths.get());
  8399. }
  8400. //---------------------------------------------------------------------------
  8401. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8402. {
  8403. FSessionColor = value;
  8404. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8405. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8406. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8407. DebugAssert(ColorItem != NULL);
  8408. ColorItem->Color = C;
  8409. NonVisualDataModule->ColorMenuItem->Color = C;
  8410. UpdateControls();
  8411. }
  8412. //---------------------------------------------------------------------------
  8413. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8414. {
  8415. if (value != FSessionColor)
  8416. {
  8417. UpdateSessionColor(value);
  8418. // Is null when called from LastTerminalClosed
  8419. if (Terminal != NULL)
  8420. {
  8421. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8422. }
  8423. }
  8424. }
  8425. //---------------------------------------------------------------------------
  8426. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8427. {
  8428. bool Result = FNoteTimer->Enabled;
  8429. if (Result)
  8430. {
  8431. // cannot cancel note too early
  8432. bool NotEarly =
  8433. (Now() - FNoteShown >
  8434. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8435. if (Force || NotEarly)
  8436. {
  8437. FNoteTimer->Enabled = false;
  8438. FNote = L"";
  8439. SAFE_DESTROY(FNoteData);
  8440. FOnNoteClick = NULL;
  8441. FNoteHints = FNotes->Text;
  8442. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8443. UpdateStatusBar();
  8444. }
  8445. }
  8446. return Result;
  8447. }
  8448. //---------------------------------------------------------------------------
  8449. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8450. {
  8451. DebugAssert(FNoteTimer->Enabled);
  8452. CancelNote(true);
  8453. }
  8454. //---------------------------------------------------------------------------
  8455. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8456. {
  8457. int P = Note.Pos(L"\n");
  8458. if (P > 0)
  8459. {
  8460. Note.SetLength(P - 1);
  8461. }
  8462. FNotes->Add(FORMAT(L"[%s] %s",
  8463. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8464. while (FNotes->Count > 10)
  8465. {
  8466. FNotes->Delete(0);
  8467. }
  8468. if (UpdateNow)
  8469. {
  8470. FNoteHints = FNotes->Text;
  8471. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8472. UpdateStatusBar();
  8473. }
  8474. }
  8475. //---------------------------------------------------------------------------
  8476. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8477. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8478. {
  8479. int P = Note.Pos(L"\n");
  8480. if (P > 0)
  8481. {
  8482. Note.SetLength(P - 1);
  8483. }
  8484. FNoteHints = FNotes->Text;
  8485. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8486. FNote = Note;
  8487. SAFE_DESTROY(FNoteData);
  8488. FNoteData = NoteData;
  8489. FOnNoteClick = OnNoteClick;
  8490. AddNote(Note, false);
  8491. UpdateStatusBar();
  8492. FNoteShown = Now();
  8493. FNoteTimer->Enabled = false;
  8494. if (Seconds == 0)
  8495. {
  8496. Seconds = WinConfiguration->NotificationsTimeout;
  8497. }
  8498. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8499. FNoteTimer->Enabled = true;
  8500. }
  8501. //---------------------------------------------------------------------------
  8502. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8503. {
  8504. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8505. }
  8506. //---------------------------------------------------------------------------
  8507. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8508. {
  8509. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked)
  8510. {
  8511. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8512. }
  8513. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8514. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8515. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  8516. 0, NULL, NULL);
  8517. }
  8518. //---------------------------------------------------------------------------
  8519. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8520. {
  8521. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8522. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8523. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8524. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8525. }
  8526. //---------------------------------------------------------------------------
  8527. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8528. {
  8529. WinConfiguration->FormatSizeBytes = Style;
  8530. }
  8531. //---------------------------------------------------------------------------
  8532. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8533. {
  8534. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8535. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8536. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8537. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8538. }
  8539. //---------------------------------------------------------------------------
  8540. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8541. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8542. {
  8543. if (Panel->Index == 0)
  8544. {
  8545. if (FOnNoteClick != NULL)
  8546. {
  8547. // prevent the user data from being freed by possible call
  8548. // to CancelNote or PostNote during call to OnNoteClick
  8549. std::unique_ptr<TObject> NoteData(FNoteData);
  8550. TNotifyEvent OnNoteClick = FOnNoteClick;
  8551. FNoteData = NULL;
  8552. // need to cancel the note as we are going to delete its user data
  8553. CancelNote(true);
  8554. OnNoteClick(NoteData.get());
  8555. }
  8556. }
  8557. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8558. {
  8559. FileSystemInfo();
  8560. }
  8561. }
  8562. //---------------------------------------------------------------------------
  8563. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8564. {
  8565. // workaround:
  8566. // 1) for unknown reason, disabling window, while minimized,
  8567. // prevents it from restoring, even if it was enabled again meanwhile
  8568. // 2) when disabling the main window, while another has focus
  8569. // minimize is no longer possible
  8570. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8571. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8572. // Shouldn't we use IsApplicationMinimized() here?
  8573. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8574. {
  8575. Enabled = false;
  8576. }
  8577. FLockLevel++;
  8578. }
  8579. //---------------------------------------------------------------------------
  8580. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8581. {
  8582. DebugAssert(FLockLevel > 0);
  8583. FLockLevel--;
  8584. if (FLockLevel == 0)
  8585. {
  8586. DebugAssert(FLockSuspendLevel == 0);
  8587. Enabled = true;
  8588. }
  8589. }
  8590. //---------------------------------------------------------------------------
  8591. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8592. {
  8593. // We need to make sure that window is enabled when the last modal window closes
  8594. // otherwise focus is not restored correctly.
  8595. // So we re-enable the window when modal window opens and
  8596. // disable it back after is closes
  8597. if (FLockLevel > 0)
  8598. {
  8599. // while we have nesting counter, we know that we never be called
  8600. // recursivelly as Application->OnModalBegin is called only
  8601. // for the top-level modal window
  8602. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8603. {
  8604. // won't be disabled when conditions in LockWindow() were not satisfied
  8605. FDisabledOnLockSuspend = !Enabled;
  8606. // When minimized to tray (or actually when set to SW_HIDE),
  8607. // setting Enabled makes the window focusable even when there's
  8608. // modal window over it
  8609. if (!FTrayIcon->Visible)
  8610. {
  8611. Enabled = true;
  8612. }
  8613. }
  8614. FLockSuspendLevel++;
  8615. }
  8616. }
  8617. //---------------------------------------------------------------------------
  8618. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8619. {
  8620. if (FLockSuspendLevel > 0)
  8621. {
  8622. DebugAssert(FLockLevel > 0);
  8623. FLockSuspendLevel--;
  8624. // see comment in SuspendWindowLock
  8625. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8626. {
  8627. // Note that window can be enabled here, when we were minized to tray when
  8628. // was SuspendWindowLock() called.
  8629. // We should possibly do the same check as in LockWindow(),
  8630. // if it is ever possible that the consitions change between
  8631. // SuspendWindowLock() and ResumeWindowLock()
  8632. Enabled = !FDisabledOnLockSuspend;
  8633. }
  8634. }
  8635. }
  8636. //---------------------------------------------------------------------------
  8637. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8638. {
  8639. if (!TextOnly)
  8640. {
  8641. TTBXComboBoxItem * RemotePathComboBox =
  8642. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8643. TStrings * Items = RemotePathComboBox->Strings;
  8644. Items->BeginUpdate();
  8645. try
  8646. {
  8647. Items->Clear();
  8648. if (Terminal != NULL)
  8649. {
  8650. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8651. while (!IsUnixRootPath(APath))
  8652. {
  8653. int P = APath.LastDelimiter(L'/');
  8654. DebugAssert(P >= 0);
  8655. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8656. APath.SetLength(P - 1);
  8657. }
  8658. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8659. }
  8660. }
  8661. __finally
  8662. {
  8663. RemotePathComboBox->ItemIndex = Items->Count - 1;
  8664. // Setting ItemIndex to -1 does not reset its text
  8665. if (Items->Count == 0)
  8666. {
  8667. RemotePathComboBox->Text = L"";
  8668. }
  8669. Items->EndUpdate();
  8670. }
  8671. }
  8672. }
  8673. //---------------------------------------------------------------------------
  8674. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  8675. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  8676. int & ImageIndex)
  8677. {
  8678. if (AIndex < 0)
  8679. {
  8680. AIndex = Sender->ItemIndex;
  8681. }
  8682. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  8683. }
  8684. //---------------------------------------------------------------------------
  8685. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  8686. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  8687. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  8688. {
  8689. ARect.Left += (10 * AIndex);
  8690. }
  8691. //---------------------------------------------------------------------------
  8692. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  8693. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  8694. {
  8695. AWidth += (10 * AIndex);
  8696. }
  8697. //---------------------------------------------------------------------------
  8698. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  8699. TObject * Sender)
  8700. {
  8701. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  8702. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8703. int Index = RemotePathComboBox->ItemIndex;
  8704. while (Index < RemotePathComboBox->Strings->Count - 1)
  8705. {
  8706. APath = UnixExtractFileDir(APath);
  8707. Index++;
  8708. }
  8709. // VanDyke style paths
  8710. if (APath.IsEmpty())
  8711. {
  8712. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  8713. APath = ROOTDIRECTORY;
  8714. }
  8715. if (RemoteDirView->Path != APath)
  8716. {
  8717. RemoteDirView->Path = APath;
  8718. }
  8719. }
  8720. //---------------------------------------------------------------------------
  8721. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  8722. {
  8723. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  8724. DebugUsedParam(Sender);
  8725. UpdateRemotePathComboBox(true);
  8726. }
  8727. //---------------------------------------------------------------------------
  8728. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  8729. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  8730. {
  8731. ResetIncrementalSearch();
  8732. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8733. DebugAssert(DirView != NULL);
  8734. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  8735. {
  8736. HWND Edit = ListView_GetEditControl(DirView->Handle);
  8737. // OnEditing is called also from TCustomListView::CanEdit
  8738. if (Edit != NULL)
  8739. {
  8740. EditSelectBaseName(Edit);
  8741. }
  8742. }
  8743. }
  8744. //---------------------------------------------------------------------------
  8745. //---------------------------------------------------------------------------
  8746. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  8747. {
  8748. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  8749. Result->AutoDetectDnD = false;
  8750. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  8751. Result->RenderDataOn = rdoEnterAndDropSync;
  8752. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  8753. return Result;
  8754. }
  8755. //---------------------------------------------------------------------------
  8756. void __fastcall TCustomScpExplorerForm::CreateWnd()
  8757. {
  8758. TForm::CreateWnd();
  8759. if (FSessionsDragDropFilesEx == NULL)
  8760. {
  8761. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  8762. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  8763. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  8764. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  8765. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  8766. }
  8767. if (FQueueDragDropFilesEx == NULL)
  8768. {
  8769. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  8770. // No need to set OnDragOver as we do not have any restrictions
  8771. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  8772. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  8773. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  8774. }
  8775. }
  8776. //---------------------------------------------------------------------------
  8777. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  8778. {
  8779. TForm::DestroyWnd();
  8780. FSessionsDragDropFilesEx->DragDropControl = NULL;
  8781. FQueueDragDropFilesEx->DragDropControl = NULL;
  8782. }
  8783. //---------------------------------------------------------------------------
  8784. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  8785. {
  8786. SideEnter(FCurrentSide);
  8787. FEverShown = true;
  8788. }
  8789. //---------------------------------------------------------------------------
  8790. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  8791. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  8792. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  8793. {
  8794. if (!NonVisualDataModule->Busy)
  8795. {
  8796. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8797. Configuration->Usage->Inc(L"FileFinds");
  8798. LockWindow(true);
  8799. NonVisualDataModule->StartBusy();
  8800. WinConfiguration->LockedInterface = true;
  8801. try
  8802. {
  8803. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  8804. }
  8805. __finally
  8806. {
  8807. WinConfiguration->LockedInterface = false;
  8808. NonVisualDataModule->EndBusy();
  8809. UnlockWindow();
  8810. }
  8811. }
  8812. }
  8813. //---------------------------------------------------------------------------
  8814. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  8815. {
  8816. if (!NonVisualDataModule->Busy)
  8817. {
  8818. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8819. SetFocus();
  8820. RemoteDirView->Path = UnixExtractFilePath(Path);
  8821. UnicodeString FileName = UnixExtractFileName(Path);
  8822. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  8823. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  8824. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  8825. if (Item == NULL)
  8826. {
  8827. ReloadDirectory(osRemote);
  8828. Item = RemoteDirView->FindFileItem(FileName);
  8829. }
  8830. if (Item != NULL)
  8831. {
  8832. RemoteDirView->ItemFocused = Item;
  8833. RemoteDirView->ItemFocused->MakeVisible(false);
  8834. RemoteDirView->SetFocus();
  8835. }
  8836. }
  8837. }
  8838. //---------------------------------------------------------------------------
  8839. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  8840. {
  8841. bool Result = !NonVisualDataModule->Busy;
  8842. if (Result)
  8843. {
  8844. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8845. }
  8846. return Result;
  8847. }
  8848. //---------------------------------------------------------------------------
  8849. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  8850. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8851. {
  8852. if (CanOperateOnFoundFiles(ATerminal))
  8853. {
  8854. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  8855. FOnFileOperationFinished = OnFileOperationFinished;
  8856. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  8857. }
  8858. }
  8859. //---------------------------------------------------------------------------
  8860. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  8861. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8862. {
  8863. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  8864. }
  8865. //---------------------------------------------------------------------------
  8866. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  8867. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8868. {
  8869. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  8870. }
  8871. //---------------------------------------------------------------------------
  8872. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  8873. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8874. {
  8875. if (CanOperateOnFoundFiles(ATerminal))
  8876. {
  8877. for (int Index = 0; Index < FileList->Count; Index++)
  8878. {
  8879. UnicodeString FileName = FileList->Strings[Index];
  8880. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  8881. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  8882. OnFileOperationFinished(FileName, true);
  8883. }
  8884. }
  8885. }
  8886. //---------------------------------------------------------------------------
  8887. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  8888. {
  8889. FFileFindTerminal = Terminal;
  8890. ShowFileFindDialog(
  8891. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  8892. DoDownloadFoundFiles, DoEditFoundFiles);
  8893. }
  8894. //---------------------------------------------------------------------------
  8895. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  8896. {
  8897. FTaskbarList = TaskbarList;
  8898. }
  8899. //---------------------------------------------------------------------------
  8900. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  8901. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  8902. {
  8903. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8904. if (Index >= 0)
  8905. {
  8906. if (Button == mbLeft)
  8907. {
  8908. // "Mouse down" is raised only after tab is switched.
  8909. // If switching tab (switching session) takes long enough for user
  8910. // to actually release the button, "mouse down" is still raised,
  8911. // but we do not get "mouse up" event, so dragging is not cancelled,
  8912. // prevent that by not beginning dragging in the first place.
  8913. if (IsKeyPressed(VK_LBUTTON))
  8914. {
  8915. // when user clicks the "+", we get mouse down only after the session
  8916. // is closed, when new session tab is already on X:Y, so dragging
  8917. // starts, prevent that
  8918. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  8919. {
  8920. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8921. if (Terminal != NULL)
  8922. {
  8923. SessionsPageControl->BeginDrag(false);
  8924. }
  8925. }
  8926. }
  8927. }
  8928. else if (Button == mbMiddle)
  8929. {
  8930. // ignore middle-click for "New session tab"
  8931. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8932. if (Terminal != NULL)
  8933. {
  8934. CloseSessionTab(Index);
  8935. }
  8936. }
  8937. }
  8938. }
  8939. //---------------------------------------------------------------------------
  8940. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  8941. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  8942. {
  8943. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8944. // do not allow dropping on the "+" tab
  8945. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8946. if ((TargetTerminal != NULL) &&
  8947. (SessionsPageControl->ActivePage->PageIndex != Index))
  8948. {
  8949. Configuration->Usage->Inc(L"SessionTabMoves");
  8950. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  8951. // but we want to actually prevent that to avoid flicker
  8952. SessionsPageControl->ActivePage->PageIndex = Index;
  8953. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  8954. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  8955. }
  8956. }
  8957. //---------------------------------------------------------------------------
  8958. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  8959. TObject * Sender, TObject * Source, int X, int Y,
  8960. TDragState /*State*/, bool & Accept)
  8961. {
  8962. Accept = (Sender == Source);
  8963. if (Accept)
  8964. {
  8965. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8966. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8967. // do not allow dragging to the "+" tab
  8968. Accept = (Terminal != NULL);
  8969. }
  8970. }
  8971. //---------------------------------------------------------------------------
  8972. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(int /*KeyState*/,
  8973. const TPoint & Point, int & Effect)
  8974. {
  8975. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  8976. if (Index < 0)
  8977. {
  8978. Effect = DROPEFFECT_NONE;
  8979. }
  8980. else
  8981. {
  8982. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8983. // do not allow dropping on the "+" tab
  8984. if (TargetTerminal == NULL)
  8985. {
  8986. Effect = DROPEFFECT_NONE;
  8987. }
  8988. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  8989. {
  8990. Effect = DROPEFFECT_COPY;
  8991. }
  8992. }
  8993. }
  8994. //---------------------------------------------------------------------------
  8995. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  8996. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  8997. {
  8998. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  8999. // do not allow dropping on the "+" tab
  9000. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9001. if (TargetTerminal != NULL)
  9002. {
  9003. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9004. if (!IsFileControl(DropSourceControl, osRemote))
  9005. {
  9006. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9007. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9008. // Why don't we use Terminal->CurrentDirectory directly?
  9009. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9010. // do not force queue, drag drop
  9011. false, true);
  9012. }
  9013. }
  9014. }
  9015. //---------------------------------------------------------------------------
  9016. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9017. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9018. {
  9019. // Downloads are handled in RemoteFileControlDDEnd
  9020. if (!IsFileControl(DropSourceControl, osRemote))
  9021. {
  9022. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9023. Terminal->CurrentDirectory,
  9024. // force queue, drag drop
  9025. true, true);
  9026. }
  9027. }
  9028. //---------------------------------------------------------------------------
  9029. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9030. {
  9031. FShowing = false;
  9032. // Do not save empty workspace
  9033. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9034. {
  9035. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9036. UnicodeString Name = WorkspaceName();
  9037. DoSaveWorkspace(
  9038. Name, DataList.get(),
  9039. !Configuration->DisablePasswordStoring &&
  9040. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9041. WinConfiguration->LastStoredSession = Name;
  9042. }
  9043. }
  9044. //---------------------------------------------------------------------------
  9045. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9046. {
  9047. TManagedTerminal * ManagedTerminal =
  9048. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9049. if (ManagedTerminal != NULL)
  9050. {
  9051. ManagedTerminal->DirectoryLoaded = Now();
  9052. }
  9053. }
  9054. //---------------------------------------------------------------------------
  9055. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9056. TListItem * /*Item*/, bool /*Selected*/)
  9057. {
  9058. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9059. switch (DirView->LastSelectMethod)
  9060. {
  9061. case smKeyboard:
  9062. Configuration->Usage->Inc(L"KeyboardSelections");
  9063. break;
  9064. case smMouse:
  9065. Configuration->Usage->Inc(L"MouseSelections");
  9066. break;
  9067. }
  9068. }
  9069. //---------------------------------------------------------------------------
  9070. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9071. {
  9072. if (Color != 0)
  9073. {
  9074. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9075. }
  9076. else
  9077. {
  9078. return FSessionTabImageIndex;
  9079. }
  9080. }
  9081. //---------------------------------------------------------------------------
  9082. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9083. {
  9084. TPngImageCollectionItem * Item =
  9085. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9086. FSessionColors->AddPng(Item->PngImage);
  9087. return FSessionColors->Count - 1;
  9088. }
  9089. //---------------------------------------------------------------------------
  9090. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9091. {
  9092. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9093. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9094. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9095. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9096. }
  9097. //---------------------------------------------------------------------------
  9098. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9099. {
  9100. for (int Index = 0; Index < Control->ControlCount; Index++)
  9101. {
  9102. TControl * AControl = Control->Controls[Index];
  9103. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9104. if (WinControl != NULL)
  9105. {
  9106. CollectItemsWithTextDisplayMode(WinControl);
  9107. }
  9108. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9109. if (Toolbar != NULL)
  9110. {
  9111. // we care for top-level items only
  9112. TTBCustomItem * Items = Toolbar->Items;
  9113. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9114. {
  9115. TTBCustomItem * Item = Items->Items[ItemIndex];
  9116. if (((Item->DisplayMode == nbdmImageAndText) ||
  9117. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9118. EligibleForImageDisplayMode(Item))
  9119. {
  9120. FItemsWithTextDisplayMode.insert(Item);
  9121. }
  9122. }
  9123. }
  9124. }
  9125. }
  9126. //---------------------------------------------------------------------------
  9127. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9128. {
  9129. return true;
  9130. }
  9131. //---------------------------------------------------------------------------
  9132. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9133. {
  9134. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9135. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9136. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9137. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9138. bool Result = true;
  9139. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9140. {
  9141. TTBCustomItem * Item = *i;
  9142. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9143. if (Label != NULL)
  9144. {
  9145. // optimization
  9146. if (Label->Visible == SelectiveToolbarText)
  9147. {
  9148. Result = false;
  9149. }
  9150. else
  9151. {
  9152. Label->Visible = SelectiveToolbarText;
  9153. }
  9154. }
  9155. else
  9156. {
  9157. // optimization
  9158. if (Item->DisplayMode == DisplayMode)
  9159. {
  9160. Result = false;
  9161. }
  9162. else
  9163. {
  9164. Item->DisplayMode = DisplayMode;
  9165. }
  9166. }
  9167. ++i;
  9168. }
  9169. if (Result)
  9170. {
  9171. UpdateNewSessionTab();
  9172. }
  9173. return Result;
  9174. }
  9175. //---------------------------------------------------------------------------
  9176. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9177. {
  9178. DebugFail();
  9179. }
  9180. //---------------------------------------------------------------------------
  9181. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9182. {
  9183. // Among other, a lock level is non zero, while directory is being loaded,
  9184. // even when it happens as a result of dirview navigation,
  9185. // i.e. when TNonVisualDataModule is NOT FBusy.
  9186. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9187. // Among other this prevents a panel auto update to occur while
  9188. // directory is changing.
  9189. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9190. }
  9191. //---------------------------------------------------------------------------
  9192. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  9193. {
  9194. // While the window is disabled, we still seem to process menu shortcuts at least,
  9195. // so stop it at least here.
  9196. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9197. return
  9198. (Allowed == aaUpdate) ||
  9199. !NonVisualDataModule->Busy;
  9200. }
  9201. //---------------------------------------------------------------------------
  9202. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9203. {
  9204. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9205. }
  9206. //---------------------------------------------------------------------------
  9207. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9208. {
  9209. // This is somewhat redundant to LockWindow() call from
  9210. // TTerminalManager::TerminalReadDirectoryProgress.
  9211. // But disabling window is known not to block keyboard shorcuts
  9212. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9213. if (Busy > 0)
  9214. {
  9215. if (NonVisualDataModule->Busy)
  9216. {
  9217. State = false;
  9218. }
  9219. else
  9220. {
  9221. NonVisualDataModule->StartBusy();
  9222. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9223. LockWindow();
  9224. }
  9225. }
  9226. else if (Busy < 0)
  9227. {
  9228. UnlockWindow();
  9229. NonVisualDataModule->EndBusy();
  9230. }
  9231. else
  9232. {
  9233. State = NonVisualDataModule->Busy;
  9234. }
  9235. }
  9236. //---------------------------------------------------------------------------
  9237. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9238. {
  9239. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9240. // no context menu for "New session tab"
  9241. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9242. {
  9243. SessionsPageControl->ActivePageIndex = Index;
  9244. if (DebugAlwaysTrue(SessionTabSwitched()))
  9245. {
  9246. // copied from TControl.WMContextMenu
  9247. SendCancelMode(SessionsPageControl);
  9248. // explicit popup instead of using PopupMenu property
  9249. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9250. // while connecting yet not-connected session and hence
  9251. // allowing an access to commands over not-completelly connected session
  9252. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9253. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9254. PopupMenu->PopupComponent = SessionsPageControl;
  9255. PopupMenu->Popup(Point.x, Point.y);
  9256. }
  9257. }
  9258. Handled = true;
  9259. }
  9260. //---------------------------------------------------------------------------
  9261. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9262. {
  9263. return (Terminal != NULL) && Terminal->Active && Terminal->IsCapable[fcChangePassword];
  9264. }
  9265. //---------------------------------------------------------------------------
  9266. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9267. {
  9268. Configuration->Usage->Inc(L"PasswordChanges");
  9269. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9270. ChangePasswordData->DisableAuthentationsExceptPassword();
  9271. ChangePasswordData->ChangePassword = true;
  9272. std::unique_ptr<TTerminal> ChangePasswordSession(
  9273. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9274. ChangePasswordSession->AutoReadDirectory = false;
  9275. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9276. {
  9277. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9278. }
  9279. else
  9280. {
  9281. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9282. }
  9283. }
  9284. //---------------------------------------------------------------------------
  9285. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9286. {
  9287. // No nice way to assert SSH2
  9288. return (Terminal != NULL) && Terminal->Active && (Terminal->FSProtocol == cfsSFTP);
  9289. }
  9290. //---------------------------------------------------------------------------
  9291. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9292. {
  9293. TOperationVisualizer OperationVisualizer;
  9294. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9295. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9296. }
  9297. //---------------------------------------------------------------------------
  9298. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9299. {
  9300. TForm::ChangeScale(M, D);
  9301. int APixelsPerInch = GetControlPixelsPerInch(this);
  9302. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9303. try
  9304. {
  9305. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9306. }
  9307. __finally
  9308. {
  9309. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9310. }
  9311. }
  9312. //---------------------------------------------------------------------------
  9313. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9314. {
  9315. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9316. }
  9317. //---------------------------------------------------------------------
  9318. class TPublicControl : public TControl
  9319. {
  9320. friend class TCustomScpExplorerForm;
  9321. };
  9322. //---------------------------------------------------------------------------
  9323. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9324. {
  9325. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9326. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9327. }
  9328. //---------------------------------------------------------------------------
  9329. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9330. {
  9331. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9332. OpenBookmark(Side, Bookmark);
  9333. }
  9334. //---------------------------------------------------------------------------
  9335. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9336. {
  9337. DoBookmarkClick(osLocal, Sender);
  9338. }
  9339. //---------------------------------------------------------------------------
  9340. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9341. {
  9342. DoBookmarkClick(osRemote, Sender);
  9343. }
  9344. //---------------------------------------------------------------------------
  9345. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9346. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9347. {
  9348. if (BookmarkList != NULL)
  9349. {
  9350. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9351. if (!WinConfiguration->UseLocationProfiles)
  9352. {
  9353. std::unique_ptr<TStringList> Directories(new TStringList());
  9354. Directories->CaseSensitive = (Side == osRemote);
  9355. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9356. {
  9357. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9358. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9359. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9360. {
  9361. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9362. Item->Caption = EscapeHotkey(Directory);
  9363. Item->ShortCut = Bookmark->ShortCut;
  9364. Item->OnClick = OnBookmarkClick;
  9365. Item->Tag = reinterpret_cast<int>(Bookmark);
  9366. Directories->Add(Directory);
  9367. Menu->Add(Item.release());
  9368. }
  9369. }
  9370. }
  9371. else
  9372. {
  9373. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9374. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9375. {
  9376. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9377. if (!Bookmark->Node.IsEmpty())
  9378. {
  9379. Folders->Add(Bookmark->Node);
  9380. }
  9381. }
  9382. for (int Index = 0; Index < Folders->Count; Index++)
  9383. {
  9384. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9385. Item->Caption = Folders->Strings[Index];
  9386. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction->ImageIndex;
  9387. Folders->Objects[Index] = Item.get();
  9388. Menu->Add(Item.release());
  9389. }
  9390. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9391. {
  9392. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9393. TTBCustomItem * Parent;
  9394. if (!Bookmark->Node.IsEmpty())
  9395. {
  9396. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9397. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9398. }
  9399. else
  9400. {
  9401. Parent = Menu;
  9402. }
  9403. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9404. Item->Caption = Bookmark->Name;
  9405. Item->ShortCut = Bookmark->ShortCut;
  9406. Item->OnClick = OnBookmarkClick;
  9407. Item->Tag = reinterpret_cast<int>(Bookmark);
  9408. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9409. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9410. {
  9411. // No hint for location profiles that are actually mere "bookmarks"
  9412. }
  9413. else
  9414. {
  9415. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9416. UnicodeString LongHint;
  9417. if (!Bookmark->Local.IsEmpty())
  9418. {
  9419. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9420. }
  9421. if (!Bookmark->Remote.IsEmpty())
  9422. {
  9423. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9424. }
  9425. AddToList(Hint, LongHint, L"|");
  9426. Item->Hint = Hint;
  9427. }
  9428. Parent->Add(Item.release());
  9429. }
  9430. }
  9431. AddMenuSeparator(Menu);
  9432. }
  9433. }
  9434. //---------------------------------------------------------------------------
  9435. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9436. {
  9437. Menu->Clear();
  9438. std::unique_ptr<TTBCustomItem> Item;
  9439. Item.reset(new TTBXItem(Owner));
  9440. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9441. Item->Options = Item->Options << tboDefault;
  9442. Menu->Add(Item.release());
  9443. AddMenuSeparator(Menu);
  9444. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9445. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9446. Item.reset(new TTBXItem(Owner));
  9447. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction : NonVisualDataModule->RemoteAddBookmarkAction;
  9448. Menu->Add(Item.release());
  9449. }
  9450. //---------------------------------------------------------------------------
  9451. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9452. {
  9453. bool Result = true;
  9454. try
  9455. {
  9456. if (Side == osRemote)
  9457. {
  9458. Terminal->ExceptionOnFail = true;
  9459. }
  9460. try
  9461. {
  9462. DirView(Side)->Path = Path;
  9463. }
  9464. __finally
  9465. {
  9466. if (Side == osRemote)
  9467. {
  9468. Terminal->ExceptionOnFail = false;
  9469. }
  9470. }
  9471. }
  9472. catch (Exception & E)
  9473. {
  9474. if ((Side != osRemote) || Terminal->Active)
  9475. {
  9476. ShowExtendedExceptionEx(Terminal, &E);
  9477. Result = false;
  9478. }
  9479. else
  9480. {
  9481. throw;
  9482. }
  9483. }
  9484. return Result;
  9485. }
  9486. //---------------------------------------------------------------------------
  9487. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9488. {
  9489. // Make sure there some feedback even when loading tine local folders
  9490. TInstantOperationVisualizer Visualizer;
  9491. DirView(Side)->ReloadDirectory();
  9492. }
  9493. //---------------------------------------------------------------------------
  9494. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9495. {
  9496. if (Index == SessionsPageControl->TabIndex)
  9497. {
  9498. CloseSession();
  9499. }
  9500. else
  9501. {
  9502. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9503. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9504. TTerminalManager * Manager = TTerminalManager::Instance();
  9505. if (!Terminal->Active)
  9506. {
  9507. Manager->FreeTerminal(Terminal);
  9508. }
  9509. else
  9510. {
  9511. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9512. if (CanCloseQueue(Queue))
  9513. {
  9514. Manager->FreeTerminal(Terminal);
  9515. }
  9516. }
  9517. }
  9518. }
  9519. //---------------------------------------------------------------------------
  9520. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9521. {
  9522. CloseSessionTab(Index);
  9523. }
  9524. //---------------------------------------------------------------------------
  9525. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side)
  9526. {
  9527. if (DebugAlwaysTrue(GetSide(Side) == osRemote))
  9528. {
  9529. TInstantOperationVisualizer Visualizer;
  9530. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9531. // before we create a new data object
  9532. ClipboardClear();
  9533. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9534. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9535. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9536. FClipboardFakeMonitors.reset(StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated));
  9537. if (FClipboardDragDropFilesEx.get() == NULL)
  9538. {
  9539. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9540. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9541. }
  9542. FClipboardDragDropFilesEx->FileList->Clear();
  9543. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9544. FClipboardDragDropFilesEx->CopyToClipboard();
  9545. FClipboardTerminal = FTerminal;
  9546. // Need full paths, as cwd can be different once files are pasted
  9547. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(false, true)));
  9548. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9549. {
  9550. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9551. }
  9552. }
  9553. }
  9554. //---------------------------------------------------------------------------
  9555. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9556. {
  9557. if (OpenClipboard(0))
  9558. {
  9559. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9560. CloseClipboard();
  9561. }
  9562. }
  9563. //---------------------------------------------------------------------------
  9564. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9565. {
  9566. return !FClipboardFakeDirectory.IsEmpty();
  9567. }
  9568. //---------------------------------------------------------------------------
  9569. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9570. {
  9571. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9572. FClipboardFakeDirectory = UnicodeString();
  9573. FClipboardTerminal = NULL;
  9574. // Also called in Idle()
  9575. FClipboardFakeMonitors.reset(NULL);
  9576. }
  9577. //---------------------------------------------------------------------------
  9578. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9579. {
  9580. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9581. {
  9582. ClipboardStop();
  9583. }
  9584. }
  9585. //---------------------------------------------------------------------------
  9586. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9587. {
  9588. TTerminalManager * Manager = TTerminalManager::Instance();
  9589. Manager->ActiveTerminal = FClipboardTerminal;
  9590. TTransferOperationParam Params;
  9591. Params.TargetDirectory = TargetDirectory;
  9592. Params.DragDrop = DragDrop;
  9593. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  9594. }
  9595. //---------------------------------------------------------------------------
  9596. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  9597. {
  9598. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  9599. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  9600. {
  9601. RemoveDir(ApiPath(FileName));
  9602. if (!NonVisualDataModule->Busy)
  9603. {
  9604. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  9605. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  9606. }
  9607. }
  9608. }
  9609. //---------------------------------------------------------------------------
  9610. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  9611. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  9612. {
  9613. TFileMasks::TParams MaskParams;
  9614. MaskParams.Size = Size;
  9615. MaskParams.Modification = Modification;
  9616. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  9617. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  9618. {
  9619. bool ImplicitMatch;
  9620. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  9621. !ImplicitMatch)
  9622. {
  9623. Color = Iter->Color;
  9624. break;
  9625. }
  9626. }
  9627. }
  9628. //---------------------------------------------------------------------------
  9629. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  9630. {
  9631. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9632. if (!DirView->IsEditing())
  9633. {
  9634. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  9635. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  9636. // while searching
  9637. if (Key == VK_BACK)
  9638. {
  9639. if (!FIncrementalSearch.IsEmpty())
  9640. {
  9641. if (FIncrementalSearch.Length() == 1)
  9642. {
  9643. ResetIncrementalSearch();
  9644. }
  9645. else
  9646. {
  9647. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  9648. IncrementalSearch(NewText, false, false);
  9649. }
  9650. Key = 0;
  9651. }
  9652. }
  9653. }
  9654. }
  9655. //---------------------------------------------------------------------------
  9656. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  9657. {
  9658. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9659. if (!DirView->IsEditing())
  9660. {
  9661. // Filter control sequences.
  9662. // When not searching yet, prefer use of the space for toggling file selection
  9663. // (so we cannot incrementally search for a string starting with a space).
  9664. if ((Key > VK_SPACE) ||
  9665. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  9666. {
  9667. IncrementalSearch(FIncrementalSearch + Key, false, false);
  9668. Key = 0;
  9669. }
  9670. }
  9671. }
  9672. //---------------------------------------------------------------------------
  9673. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  9674. {
  9675. if (!FIncrementalSearch.IsEmpty())
  9676. {
  9677. FIncrementalSearch = L"";
  9678. DirView(osCurrent)->UpdateStatusBar();
  9679. }
  9680. }
  9681. //---------------------------------------------------------------------------
  9682. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  9683. {
  9684. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  9685. if (Item == NULL)
  9686. {
  9687. MessageBeep(MB_ICONHAND);
  9688. }
  9689. else
  9690. {
  9691. TCustomDirView * ADirView = DirView(osCurrent);
  9692. {
  9693. TAutoNestingCounter Guard(FIncrementalSearching);
  9694. ADirView->FocusItem(Item);
  9695. if (ADirView->NortonLike == nlOff)
  9696. {
  9697. if ((ADirView->Selected != Item) ||
  9698. (ADirView->SelCount > 1))
  9699. {
  9700. ADirView->ClearSelection();
  9701. ADirView->Selected = Item;
  9702. }
  9703. }
  9704. }
  9705. FIncrementalSearch = Text;
  9706. Item->MakeVisible(false);
  9707. TListItem * NextItem = SearchFile(Text, true, Reverse);
  9708. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  9709. ADirView->UpdateStatusBar();
  9710. }
  9711. }
  9712. //---------------------------------------------------------------------------
  9713. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  9714. {
  9715. int Index = Item->Index;
  9716. if (!Reverse)
  9717. {
  9718. Index++;
  9719. if (Index >= Item->Owner->Count)
  9720. {
  9721. Index = 0;
  9722. }
  9723. }
  9724. else
  9725. {
  9726. Index--;
  9727. if (Index < 0)
  9728. {
  9729. Index = Item->Owner->Count - 1;
  9730. }
  9731. }
  9732. return Item->Owner->Item[Index];
  9733. }
  9734. //---------------------------------------------------------------------------
  9735. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  9736. {
  9737. TCustomDirView * ADirView = DirView(osCurrent);
  9738. if (ADirView->Items->Count == 0)
  9739. {
  9740. return NULL;
  9741. }
  9742. else
  9743. {
  9744. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  9745. TListItem * Item = CurrentItem;
  9746. if (SkipCurrent)
  9747. {
  9748. Item = DebugNotNull(GetNextFile(Item, Reverse));
  9749. }
  9750. while (true)
  9751. {
  9752. bool Matches = false;
  9753. switch (WinConfiguration->PanelSearch)
  9754. {
  9755. case isNameStartOnly:
  9756. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  9757. break;
  9758. case isName:
  9759. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  9760. break;
  9761. case isAll:
  9762. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  9763. int Index = 0;
  9764. while ((Index < ColCount) && !Matches)
  9765. {
  9766. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  9767. if (Visible)
  9768. {
  9769. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  9770. }
  9771. Index++;
  9772. }
  9773. break;
  9774. }
  9775. if (Matches)
  9776. {
  9777. return Item;
  9778. }
  9779. Item = GetNextFile(Item, Reverse);
  9780. if (Item == CurrentItem)
  9781. {
  9782. return NULL;
  9783. }
  9784. }
  9785. }
  9786. }
  9787. //---------------------------------------------------------------------------
  9788. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  9789. {
  9790. ResetIncrementalSearch();
  9791. }
  9792. //---------------------------------------------------------------------------
  9793. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  9794. {
  9795. if (Message.CharCode == VK_TAB)
  9796. {
  9797. if (!FIncrementalSearch.IsEmpty())
  9798. {
  9799. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  9800. bool Reverse = Shift.Contains(ssShift);
  9801. IncrementalSearch(FIncrementalSearch, true, Reverse);
  9802. Message.Result = 1;
  9803. return;
  9804. }
  9805. }
  9806. else if (Message.CharCode == VK_ESCAPE)
  9807. {
  9808. if (!FIncrementalSearch.IsEmpty())
  9809. {
  9810. ResetIncrementalSearch();
  9811. Message.Result = 1;
  9812. return;
  9813. }
  9814. }
  9815. TForm::Dispatch(&Message);
  9816. }
  9817. //---------------------------------------------------------------------------
  9818. void __fastcall TCustomScpExplorerForm::Deactivate()
  9819. {
  9820. TForm::Deactivate();
  9821. // E.g. when switching to an internal editor window
  9822. ResetIncrementalSearch();
  9823. }
  9824. //---------------------------------------------------------------------------
  9825. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  9826. {
  9827. // When switching to another application
  9828. ResetIncrementalSearch();
  9829. }
  9830. //---------------------------------------------------------------------------
  9831. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  9832. {
  9833. ResetIncrementalSearch();
  9834. }
  9835. //---------------------------------------------------------------------------
  9836. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  9837. {
  9838. if (FIncrementalSearching <= 0)
  9839. {
  9840. ResetIncrementalSearch();
  9841. }
  9842. }
  9843. //---------------------------------------------------------------------------
  9844. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  9845. {
  9846. CountClicksForWindowPrint(this);
  9847. }
  9848. //---------------------------------------------------------------------------