CustomScpExplorer.cpp 414 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373
  1. //---------------------------------------------------------------------------
  2. #define NO_WIN32_LEAN_AND_MEAN
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <Common.h>
  6. #include "CustomScpExplorer.h"
  7. #include <algorithm>
  8. #include <Bookmarks.h>
  9. #include <Interface.h>
  10. #include <Exceptions.h>
  11. #include <CoreMain.h>
  12. #include <FileSystems.h>
  13. #include <TextsCore.h>
  14. #include <TextsWin.h>
  15. #include <HelpWin.h>
  16. #include <VCLCommon.h>
  17. #include <Progress.h>
  18. #include <SynchronizeProgress.h>
  19. #include <DragExt.h>
  20. #include <WinApi.h>
  21. #include "NonVisual.h"
  22. #include "Glyphs.h"
  23. #include "Tools.h"
  24. #include "WinConfiguration.h"
  25. #include "TerminalManager.h"
  26. #include "EditorManager.h"
  27. #include "ProgParams.h"
  28. #include "Setup.h"
  29. #include <Consts.hpp>
  30. #include <DateUtils.hpp>
  31. #include <TB2Common.hpp>
  32. #include <DirectoryMonitor.hpp>
  33. #include <System.IOUtils.hpp>
  34. #include <System.StrUtils.hpp>
  35. //---------------------------------------------------------------------------
  36. #pragma package(smart_init)
  37. #pragma link "CustomDirView"
  38. #pragma link "CustomUnixDirView"
  39. #pragma link "IEListView"
  40. #pragma link "NortonLikeListView"
  41. #pragma link "UnixDirView"
  42. #pragma link "CustomDriveView"
  43. #pragma link "UnixDriveView"
  44. #pragma link "CustomDriveView"
  45. #pragma link "TB2Dock"
  46. #pragma link "TBXStatusBars"
  47. #pragma link "TB2Item"
  48. #pragma link "TB2Toolbar"
  49. #pragma link "ThemePageControl"
  50. #pragma link "PathLabel"
  51. #pragma resource "*.dfm"
  52. //---------------------------------------------------------------------------
  53. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  54. #define WM_PASTE_FILES (WM_WINSCP_USER + 14)
  55. static const int SessionPanelCount = 3;
  56. //---------------------------------------------------------------------------
  57. class TMutexGuard
  58. {
  59. public:
  60. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  61. int Timeout = 5000)
  62. {
  63. FMutex = NULL;
  64. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  65. if (WaitResult == WAIT_TIMEOUT)
  66. {
  67. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  68. }
  69. else
  70. {
  71. FMutex = AMutex;
  72. }
  73. }
  74. ~TMutexGuard()
  75. {
  76. if (FMutex != NULL)
  77. {
  78. ReleaseMutex(FMutex);
  79. }
  80. }
  81. private:
  82. HANDLE FMutex;
  83. };
  84. //---------------------------------------------------------------------------
  85. class TWindowLock
  86. {
  87. public:
  88. TWindowLock(TCustomScpExplorerForm * Form) :
  89. FForm(Form)
  90. {
  91. FForm->LockWindow();
  92. }
  93. ~TWindowLock()
  94. {
  95. FForm->UnlockWindow();
  96. }
  97. private:
  98. TCustomScpExplorerForm * FForm;
  99. };
  100. //---------------------------------------------------------------------------
  101. TAutoBatch::TAutoBatch(TCustomScpExplorerForm * Form) :
  102. FForm(Form)
  103. {
  104. FForm->BatchStart(FBatchStorage);
  105. }
  106. //---------------------------------------------------------------------------
  107. TAutoBatch::~TAutoBatch()
  108. {
  109. FForm->BatchEnd(FBatchStorage);
  110. }
  111. //---------------------------------------------------------------------------
  112. struct TTransferOperationParam
  113. {
  114. TTransferOperationParam();
  115. UnicodeString TargetDirectory;
  116. bool Temp;
  117. bool DragDrop;
  118. int Options;
  119. TAutoSwitch Queue;
  120. };
  121. //---------------------------------------------------------------------------
  122. TTransferOperationParam::TTransferOperationParam()
  123. {
  124. Temp = false;
  125. DragDrop = false;
  126. Options = 0;
  127. Queue = asAuto;
  128. }
  129. //---------------------------------------------------------------------------
  130. class TTransferPresetNoteData : public TObject
  131. {
  132. public:
  133. UnicodeString Message;
  134. };
  135. //---------------------------------------------------------------------------
  136. class TTerminalNoteData : public TObject
  137. {
  138. public:
  139. TManagedTerminal * Terminal;
  140. };
  141. //---------------------------------------------------------------------------
  142. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  143. FFormRestored(false),
  144. TForm(Owner)
  145. {
  146. AddStartupSequence(L"F");
  147. FInvalid = false;
  148. FCurrentSide = osRemote;
  149. FEverShown = false;
  150. FDocks = new TList();
  151. InitControls();
  152. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  153. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  154. NonVisualDataModule->ScpExplorer = this;
  155. RestoreParams();
  156. ConfigurationChanged();
  157. RemoteDirView->Invalidate();
  158. FAutoOperation = false;
  159. FOnFileOperationFinished = NULL;
  160. FPrimaryOperation = foNone;
  161. FForceExecution = false;
  162. FIgnoreNextDialogChar = 0;
  163. FErrorList = NULL;
  164. FSynchronizeProgressForm = NULL;
  165. FProgressForm = NULL;
  166. FRefreshLocalDirectory = false;
  167. FRefreshRemoteDirectory = false;
  168. FDDExtMapFile = NULL;
  169. // CreateMutexW keeps failing with ERROR_NOACCESS
  170. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  171. DebugAssert(FDDExtMutex != NULL);
  172. FDDTargetControl = NULL;
  173. FDelayedDeletionTimer = NULL;
  174. FDelayedDeletionList = new TStringList();
  175. FDDFileList = NULL;
  176. FPendingTempSpaceWarn = false;
  177. FCapturedLog = NULL;
  178. FDragDropOperation = false;
  179. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  180. FAllowTransferPresetAutoSelect = true;
  181. FSessionChanging = false;
  182. FCopyParamDefault = L"";
  183. FSynchronizeController = NULL;
  184. FPendingQueueActionItem = NULL;
  185. FLockLevel = 0;
  186. FLockSuspendLevel = 0;
  187. FDisabledOnLockSuspend = false;
  188. FAlternativeDelete = false;
  189. FTrayIcon = new ::TTrayIcon(0);
  190. FTrayIcon->OnClick = TrayIconClick;
  191. FMaxQueueLength = 0;
  192. FLastContextPopupScreenPoint = TPoint(-1, -1);
  193. FTransferResumeList = NULL;
  194. FDeletedFiles = NULL;
  195. FMoveToQueue = false;
  196. StandaloneOperation = false;
  197. FOnFeedSynchronizeError = NULL;
  198. FOnSynchronizeAbort = NULL;
  199. FSynchronizeTerminal = NULL;
  200. FNeedSession = false;
  201. FDoNotIdleCurrentTerminal = 0;
  202. FIncrementalSearching = 0;
  203. FQueueFileList.reset(new TQueueFileList());
  204. FProgressSide = osCurrent;
  205. FCalculateSizeOperation = NULL;
  206. FDownloadingFromClipboard = false;
  207. FClipboardFakeMonitorsPendingReset = false;
  208. FHiContrastTheme = NULL;
  209. InitializeRemoteThumbnailMask();
  210. FEditorManager = new TEditorManager();
  211. FEditorManager->OnFileChange = ExecutedFileChanged;
  212. FEditorManager->OnFileReload = ExecutedFileReload;
  213. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  214. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  215. FLocalEditors = new TList();
  216. FQueueStatus = NULL;
  217. FQueueStatusSection = new TCriticalSection();
  218. FQueueStatusInvalidated = false;
  219. FQueueItemInvalidated = false;
  220. FQueueStatusUpdating = false;
  221. FQueueActedItem = NULL;
  222. FQueueController = new TQueueController(QueueView3);
  223. FQueueScrollOnDragOver = new TListViewScrollOnDragOver(QueueView3, true);
  224. FUserActionTimer = new TTimer(this);
  225. FUserActionTimer->Enabled = false;
  226. FUserActionTimer->Interval = 10;
  227. FUserActionTimer->OnTimer = UserActionTimer;
  228. FNotes = new TStringList();
  229. FNoteTimer = new TTimer(this);
  230. FNoteTimer->Enabled = false;
  231. FNoteTimer->OnTimer = NoteTimer;
  232. FOnNoteClick = NULL;
  233. FOle32Library = LoadLibrary(L"Ole32.dll");
  234. FDragMoveCursor = FOle32Library != NULL ?
  235. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  236. UseSystemSettings(this);
  237. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  238. static_cast<TObject*>(GetComponent(fcTransferList)));
  239. DebugAssert(TransferList != NULL);
  240. FTransferListHoverIndex = -1;
  241. TransferList->OnChange = TransferListChange;
  242. TransferList->OnDrawItem = TransferListDrawItem;
  243. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))), true);
  244. SetSubmenu(NonVisualDataModule->ColorMenuItem, true);
  245. UseDesktopFont(SessionsPageControl);
  246. UseDesktopFont(RemoteDirView);
  247. UseDesktopFont(RemoteDriveView);
  248. UseDesktopFont(QueueView3);
  249. UseDesktopFont(QueueFileList);
  250. UseDesktopFont(QueueLabel);
  251. UseDesktopFont(RemoteStatusBar);
  252. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  253. QueueSplitter->ShowHint = true;
  254. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  255. QueueFileListSplitter->ShowHint = true;
  256. RemotePanelSplitter->ShowHint = true;
  257. UpdateImages();
  258. FCustomCommandMenu = CreateTBXPopupMenu(this);
  259. FCustomCommandLocalFileList = NULL;
  260. FCustomCommandRemoteFileList = NULL;
  261. FSessionColors = new TPngImageList(this);
  262. FSessionColors->ColorDepth = cd32Bit;
  263. AddFixedSessionImages();
  264. SessionsPageControl->Images = FSessionColors;
  265. // Needed for Explorer (Commander calls it implicitly on its own)
  266. UpdateSessionsPageControlHeight();
  267. UpdateQueueLabel();
  268. CheckStoreTransition();
  269. CreateHiddenWindow();
  270. StartUpdates();
  271. // Start loading drive data, so that they are ready once we need them for StartCreationDirectoryMonitorsOnEachDrive
  272. // (necessary for "explorer" only, as "commander" loads it for its drive menu)
  273. DriveInfo->NeedData();
  274. }
  275. //---------------------------------------------------------------------------
  276. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  277. {
  278. AppLog(L"Destroying main window");
  279. FInvalid = true;
  280. ReleaseHiContrastTheme();
  281. if (FClipboardTerminal != NULL)
  282. {
  283. ClipboardClear(); // implies ClipboardStop
  284. }
  285. // this has to be one of the very first things to do
  286. StopUpdateThread();
  287. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  288. TTerminalManager::Instance()->ScpExplorer = NULL;
  289. delete FCustomCommandLocalFileList;
  290. delete FCustomCommandRemoteFileList;
  291. delete FCustomCommandMenu;
  292. delete FTrayIcon;
  293. FTrayIcon = NULL;
  294. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  295. delete FEditorManager;
  296. ForceCloseLocalEditors();
  297. delete FLocalEditors;
  298. HideFileFindDialog();
  299. if (FDelayedDeletionTimer)
  300. {
  301. DoDelayedDeletion(NULL);
  302. SAFE_DESTROY(FDelayedDeletionTimer);
  303. }
  304. SAFE_DESTROY(FDelayedDeletionList);
  305. // sometimes we do not get DDEnd so the list is not released
  306. SAFE_DESTROY(FDDFileList);
  307. DebugAssert(FSynchronizeController == NULL);
  308. CloseHandle(FDDExtMutex);
  309. FDDExtMutex = NULL;
  310. FreeLibrary(FOle32Library);
  311. FOle32Library = NULL;
  312. FDragMoveCursor = NULL;
  313. DebugAssert(!FErrorList);
  314. if (FEverShown)
  315. {
  316. // when window is never shown (like when running command-line operation),
  317. // particularly window site is not restored correctly (BoundsRect value set
  318. // in RestoreForm gets lost during handle allocation), so we do not want
  319. // it to be stored
  320. AppLog(L"Storing main window configuration");
  321. StoreParams();
  322. }
  323. ManagedSession = NULL;
  324. Queue = NULL;
  325. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  326. NonVisualDataModule->ScpExplorer = NULL;
  327. delete FQueueScrollOnDragOver;
  328. FQueueScrollOnDragOver = NULL;
  329. delete FQueueController;
  330. FQueueController = NULL;
  331. delete FQueueStatusSection;
  332. FQueueStatusSection = NULL;
  333. delete FQueueStatus;
  334. FQueueStatus = NULL;
  335. delete FUserActionTimer;
  336. FUserActionTimer = NULL;
  337. delete FNoteTimer;
  338. delete FNotes;
  339. delete FNoteData;
  340. SAFE_DESTROY(FDocks);
  341. SessionsPageControl->Images = NULL;
  342. // only after clearing Terminal (after SessionListChanged => ... => AddSessionColor is called)
  343. SAFE_DESTROY(FSessionColors);
  344. SAFE_DESTROY(FSessionsDragDropFilesEx);
  345. SAFE_DESTROY(FHistoryMenu[0][0]);
  346. SAFE_DESTROY(FHistoryMenu[0][1]);
  347. SAFE_DESTROY(FHistoryMenu[1][0]);
  348. SAFE_DESTROY(FHistoryMenu[1][1]);
  349. if (FHiddenWindow != NULL)
  350. {
  351. DestroyWindow(FHiddenWindow);
  352. FHiddenWindow = NULL;
  353. }
  354. AppLog(L"Main window destroyed");
  355. }
  356. //---------------------------------------------------------------------------
  357. void TCustomScpExplorerForm::ReleaseHiContrastTheme()
  358. {
  359. if (FHiContrastTheme != NULL)
  360. {
  361. ReleaseTBXTheme(FHiContrastTheme);
  362. FHiContrastTheme = NULL;
  363. }
  364. }
  365. //---------------------------------------------------------------------------
  366. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  367. {
  368. std::unique_ptr<TSessionData> Data;
  369. if (!Session.IsEmpty())
  370. {
  371. bool DefaultsOnly;
  372. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  373. }
  374. TTerminalManager * Manager = TTerminalManager::Instance();
  375. for (int Index = 0; Index < Manager->Count; Index++)
  376. {
  377. TTerminal * Terminal = Manager->Sessions[Index];
  378. if (Session.IsEmpty() ||
  379. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  380. {
  381. if (Path.IsEmpty())
  382. {
  383. Terminal->ClearCaches();
  384. }
  385. else
  386. {
  387. Terminal->DirectoryModified(Path, true);
  388. }
  389. }
  390. }
  391. // We should flag a pending refresh for the background terminals or busy foreground terminals
  392. if (HasActiveTerminal() &&
  393. CanCommandLineFromAnotherInstance() &&
  394. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  395. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  396. {
  397. Terminal->ReloadDirectory();
  398. }
  399. }
  400. //---------------------------------------------------------------------------
  401. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  402. {
  403. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  404. AppLogFmt(L"Received copy data message with size %d", (int(CopyData->cbData)));
  405. size_t MessageSize = sizeof(TCopyDataMessage);
  406. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  407. if (Result)
  408. {
  409. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  410. Result = (Message.Version == TCopyDataMessage::Version1);
  411. if (Result)
  412. {
  413. switch (Message.Command)
  414. {
  415. case TCopyDataMessage::CommandCanCommandLine:
  416. Result = CanCommandLineFromAnotherInstance();
  417. if (Result)
  418. {
  419. AppLog(L"Can process command-line from other instance");
  420. }
  421. else
  422. {
  423. AppLog(L"Cannot process command-line from other instance");
  424. }
  425. break;
  426. case TCopyDataMessage::CommandCommandLine:
  427. {
  428. UnicodeString CommandLine(Message.CommandLine);
  429. Result = CommandLineFromAnotherInstance(CommandLine);
  430. }
  431. break;
  432. case TCopyDataMessage::RefreshPanel:
  433. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  434. break;
  435. case TCopyDataMessage::MainWindowCheck:
  436. Result = true;
  437. break;
  438. default:
  439. Result = false;
  440. break;
  441. }
  442. }
  443. }
  444. Message.Result = Result ? 1 : 0;
  445. }
  446. //---------------------------------------------------------------------------
  447. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  448. {
  449. WNDCLASS WindowClass = {0};
  450. WindowClass.lpfnWndProc = DefWindowProc;
  451. WindowClass.hInstance = HInstance;
  452. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  453. FHiddenWindow = NULL;
  454. if (RegisterClass(&WindowClass))
  455. {
  456. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  457. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  458. }
  459. }
  460. //---------------------------------------------------------------------------
  461. bool __fastcall TCustomScpExplorerForm::CanConsole()
  462. {
  463. return
  464. HasActiveTerminal() &&
  465. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  466. }
  467. //---------------------------------------------------------------------------
  468. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  469. {
  470. bool Result = Visible && !NonVisualDataModule->Busy;
  471. return Result;
  472. }
  473. //---------------------------------------------------------------------------
  474. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  475. const UnicodeString & CommandLine)
  476. {
  477. TProgramParams Params(CommandLine);
  478. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  479. if (Result)
  480. {
  481. NonVisualDataModule->StartBusy();
  482. try
  483. {
  484. // this action is initiated from another process,
  485. // so it's likely that our window is not visible,
  486. // and user won't see what is going on
  487. Application->BringToFront();
  488. // reload sessions as we may be asked to open a session
  489. // just stored by another instance
  490. StoredSessions->Reload();
  491. UnicodeString SessionName = Params.Param[1];
  492. std::unique_ptr<TObjectList> DataList(new TObjectList());
  493. try
  494. {
  495. UnicodeString DownloadFile; // unused
  496. int Flags = GetCommandLineParseUrlFlags(&Params);
  497. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this, Flags);
  498. }
  499. catch (EAbort &)
  500. {
  501. // Happens when opening session in PuTTY and in other situations,
  502. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  503. // to process the command-line on its own (or to pass it to yet another instance)
  504. }
  505. if (DataList->Count > 0)
  506. {
  507. TTerminalManager * Manager = TTerminalManager::Instance();
  508. Manager->ActiveSession = Manager->NewSessions(DataList.get());
  509. }
  510. }
  511. __finally
  512. {
  513. NonVisualDataModule->EndBusy();
  514. }
  515. }
  516. return Result;
  517. }
  518. //---------------------------------------------------------------------------
  519. TManagedTerminal * TCustomScpExplorerForm::GetTerminal()
  520. {
  521. TManagedTerminal * Result;
  522. if ((FManagedSession != NULL) && !FManagedSession->LocalBrowser)
  523. {
  524. Result = FManagedSession;
  525. }
  526. else
  527. {
  528. Result = NULL;
  529. }
  530. return Result;
  531. }
  532. //---------------------------------------------------------------------------
  533. void __fastcall TCustomScpExplorerForm::SetManagedSession(TManagedTerminal * value)
  534. {
  535. if (FManagedSession != value)
  536. {
  537. TWindowLock Lock(this);
  538. SessionChanging();
  539. DoSetManagedSession(value, false);
  540. }
  541. }
  542. //---------------------------------------------------------------------------
  543. void __fastcall TCustomScpExplorerForm::DoSetManagedSession(TManagedTerminal * value, bool Replace)
  544. {
  545. DebugAssert(!Replace || ((value != NULL) && !value->LocalBrowser));
  546. FManagedSession = value;
  547. {
  548. TValueRestorer<bool> AllowTransferPresetAutoSelectRestorer(FAllowTransferPresetAutoSelect, false);
  549. TAutoFlag SessionChangingFlag(FSessionChanging);
  550. SessionChanged(Replace);
  551. }
  552. if (Terminal != NULL)
  553. {
  554. TransferPresetAutoSelect();
  555. }
  556. // Update app and tab titles, prevented above by FSessionChanging.
  557. UpdateControls();
  558. }
  559. //---------------------------------------------------------------------------
  560. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  561. {
  562. FEditorManager->ProcessFiles(FileTerminalReplaced, value);
  563. DoSetManagedSession(value, true);
  564. }
  565. //---------------------------------------------------------------------------
  566. void __fastcall TCustomScpExplorerForm::SessionChanging()
  567. {
  568. if (ManagedSession != NULL)
  569. {
  570. UpdateSession(ManagedSession);
  571. }
  572. }
  573. //---------------------------------------------------------------------------
  574. void __fastcall TCustomScpExplorerForm::SessionChanged(bool Replaced)
  575. {
  576. if (ManagedSession != NULL)
  577. {
  578. UpdateSessionColor(static_cast<TColor>(ManagedSession->StateData->Color));
  579. }
  580. if (!TTerminalManager::Instance()->Updating)
  581. {
  582. SessionListChanged();
  583. }
  584. if (Terminal != NULL)
  585. {
  586. TObject * State = NULL;
  587. if (WinConfiguration->PreservePanelState)
  588. {
  589. State = Terminal->RemoteExplorerState;
  590. DirView(osRemote)->AnnounceState(State);
  591. }
  592. try
  593. {
  594. if (Replaced)
  595. {
  596. RemoteDirView->ReplaceTerminal(Terminal);
  597. }
  598. else
  599. {
  600. RemoteDirView->Terminal = Terminal;
  601. }
  602. if (Terminal->Active)
  603. {
  604. Terminal->RefreshDirectory();
  605. }
  606. if (State != NULL)
  607. {
  608. DirView(osRemote)->RestoreState(State);
  609. }
  610. }
  611. __finally
  612. {
  613. DirView(osRemote)->AnnounceState(NULL);
  614. }
  615. }
  616. else
  617. {
  618. RemoteDirView->Terminal = NULL;
  619. }
  620. InitStatusBar();
  621. UpdateTransferList();
  622. // Update panels Enable state before refreshing the labels
  623. UpdateControls();
  624. }
  625. //---------------------------------------------------------------------------
  626. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  627. {
  628. if (Queue != value)
  629. {
  630. if (FQueue != NULL)
  631. {
  632. FQueue->OnListUpdate = NULL;
  633. FQueue->OnQueueItemUpdate = NULL;
  634. }
  635. FQueue = value;
  636. if (FQueue != NULL)
  637. {
  638. DebugAssert(FQueue->OnListUpdate == NULL);
  639. FQueue->OnListUpdate = QueueListUpdate;
  640. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  641. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  642. }
  643. QueueChanged();
  644. }
  645. }
  646. //---------------------------------------------------------------------------
  647. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  648. TListItem * Item)
  649. {
  650. if (FQueueActedItem == Item)
  651. {
  652. FQueueActedItem = NULL;
  653. if ((QueueView3->PopupMenu != NULL) &&
  654. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  655. {
  656. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  657. ReleaseCapture();
  658. }
  659. }
  660. if (Item->Data == FPendingQueueActionItem)
  661. {
  662. FPendingQueueActionItem = NULL;
  663. }
  664. }
  665. //---------------------------------------------------------------------------
  666. bool TCustomScpExplorerForm::IsAnythingQueued()
  667. {
  668. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  669. }
  670. //---------------------------------------------------------------------------
  671. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  672. {
  673. {
  674. TGuard Guard(FQueueStatusSection);
  675. FQueueStatusInvalidated = false;
  676. if (FQueue != NULL)
  677. {
  678. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  679. }
  680. }
  681. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  682. {
  683. FMaxQueueLength = FQueueStatus->Count;
  684. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  685. }
  686. {
  687. TAutoFlag Flag(FQueueStatusUpdating);
  688. FQueueController->UpdateQueueStatus(FQueueStatus);
  689. }
  690. UpdateQueueFileList();
  691. SetQueueProgress();
  692. UpdateQueueView();
  693. bool IsEmpty = !IsAnythingQueued();
  694. if (IsEmpty && (Terminal != NULL))
  695. {
  696. TOnceDoneOperation OnceDoneOperation =
  697. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  698. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  699. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  700. {
  701. FQueue->Enabled = false;
  702. }
  703. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  704. {
  705. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  706. }
  707. }
  708. }
  709. //---------------------------------------------------------------------------
  710. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  711. {
  712. UnicodeString Result;
  713. if (FQueueStatus != NULL)
  714. {
  715. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  716. {
  717. TFileOperationProgressType * ProgressData =
  718. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  719. if ((ProgressData != NULL) && ProgressData->InProgress)
  720. {
  721. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  722. }
  723. }
  724. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  725. {
  726. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  727. }
  728. }
  729. return Result;
  730. }
  731. //---------------------------------------------------------------------------
  732. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  733. {
  734. ComponentVisible[fcQueueView] =
  735. !IsLocalBrowserMode() &&
  736. ((WinConfiguration->QueueView.Show == qvShow) ||
  737. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  738. (FQueueStatus != NULL) && (FQueueStatus->Count > 0)));
  739. }
  740. //---------------------------------------------------------------------------
  741. void __fastcall TCustomScpExplorerForm::QueueChanged()
  742. {
  743. if (FQueueStatus != NULL)
  744. {
  745. // UpdateFileList implementation relies on the status being recreated when session changes
  746. delete FQueueStatus;
  747. FQueueStatus = NULL;
  748. }
  749. UpdateQueueStatus(true);
  750. }
  751. //---------------------------------------------------------------------------
  752. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  753. {
  754. if (FQueue == Queue)
  755. {
  756. FQueueStatusInvalidated = true;
  757. }
  758. }
  759. //---------------------------------------------------------------------------
  760. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  761. TQueueItem * Item)
  762. {
  763. if (FQueue == Queue)
  764. {
  765. TGuard Guard(FQueueStatusSection);
  766. // this may be running in parallel with QueueChanged
  767. if (FQueueStatus != NULL)
  768. {
  769. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  770. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  771. {
  772. FRefreshLocalDirectory = (QueueItem == NULL) ||
  773. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  774. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  775. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  776. }
  777. if (QueueItem != NULL)
  778. {
  779. QueueItem->UserData = (void*)true;
  780. FQueueItemInvalidated = true;
  781. }
  782. }
  783. }
  784. }
  785. //---------------------------------------------------------------------------
  786. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  787. {
  788. // during standalone editing, we have no way to see/control queue,
  789. // so we have to always popup prompts automatically
  790. return StandaloneOperation || GUIConfiguration->QueueAutoPopup;
  791. }
  792. //---------------------------------------------------------------------------
  793. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  794. {
  795. if (FQueueStatus != NULL)
  796. {
  797. bool QueueAutoPopup = IsQueueAutoPopup();
  798. bool NeedRefresh = FQueueController->NeedRefresh();
  799. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  800. FQueueItemInvalidated = false;
  801. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  802. bool Updated = false;
  803. TQueueItemProxy * QueueItem;
  804. bool WasUserAction;
  805. for (int Index = 0; Index < Limit; Index++)
  806. {
  807. bool Update = false;
  808. QueueItem = FQueueStatus->Items[Index];
  809. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  810. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  811. (FPendingQueueActionItem == NULL))
  812. {
  813. FPendingQueueActionItem = QueueItem;
  814. FUserActionTimer->Enabled = true;
  815. }
  816. if ((bool)QueueItem->UserData)
  817. {
  818. QueueItem->UserData = (void*)false;
  819. QueueItem->Update();
  820. Updated = true;
  821. Update = true;
  822. }
  823. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  824. {
  825. Update = true;
  826. }
  827. if (Update)
  828. {
  829. FQueueController->RefreshQueueItem(QueueItem);
  830. }
  831. }
  832. if (Updated)
  833. {
  834. NonVisualDataModule->UpdateNonVisibleActions();
  835. SetQueueProgress();
  836. UpdateQueueFileList();
  837. }
  838. }
  839. }
  840. //---------------------------------------------------------------------------
  841. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  842. {
  843. if (FTaskbarList != NULL)
  844. {
  845. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  846. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  847. }
  848. }
  849. //---------------------------------------------------------------------------
  850. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  851. {
  852. if (Progress >= 0)
  853. {
  854. if (FTaskbarList != NULL)
  855. {
  856. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  857. }
  858. }
  859. else
  860. {
  861. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  862. }
  863. }
  864. //---------------------------------------------------------------------------
  865. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  866. {
  867. int OverallProgress;
  868. // FProgressForm is null when this is called from SetQueueProgress
  869. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  870. {
  871. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  872. }
  873. else if (!ProgressData->IsIndeterminate())
  874. {
  875. OverallProgress = ProgressData->OverallProgress();
  876. }
  877. else
  878. {
  879. OverallProgress = -1;
  880. }
  881. SetTaskbarListProgressValue(OverallProgress);
  882. }
  883. //---------------------------------------------------------------------------
  884. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  885. {
  886. TTerminalManager::Instance()->QueueStatusUpdated();
  887. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  888. {
  889. // Do not animate task bar button, when items are queued, but processing is disabled
  890. if ((FQueueStatus != NULL) && (FQueueStatus->ActivePrimaryCount > 0))
  891. {
  892. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  893. {
  894. TFileOperationProgressType * ProgressData = NULL;
  895. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  896. {
  897. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  898. }
  899. if ((ProgressData != NULL) &&
  900. ProgressData->InProgress)
  901. {
  902. SetTaskbarListProgressValue(ProgressData);
  903. }
  904. else
  905. {
  906. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  907. }
  908. }
  909. else
  910. {
  911. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  912. }
  913. }
  914. else
  915. {
  916. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  917. }
  918. }
  919. UpdateQueueLabel();
  920. }
  921. //---------------------------------------------------------------------------
  922. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  923. {
  924. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  925. if (FQueueStatus != NULL)
  926. {
  927. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  928. if (ActiveAndPendingPrimaryCount > 0)
  929. {
  930. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  931. }
  932. }
  933. QueueLabel->Caption = Caption;
  934. }
  935. //---------------------------------------------------------------------------
  936. void TCustomScpExplorerForm::CheckStoreTransition()
  937. {
  938. if (WinConfiguration->StoreTransition == stInit)
  939. {
  940. if (IsUWP())
  941. {
  942. WinConfiguration->StoreTransition = stStoreFresh;
  943. AppLog(L"Fresh UWP/store installation");
  944. }
  945. else
  946. {
  947. WinConfiguration->StoreTransition = stStandard;
  948. AppLog(L"Fresh standard installation");
  949. }
  950. }
  951. else if ((WinConfiguration->StoreTransition == stStandard) && IsUWP())
  952. {
  953. WinConfiguration->StoreTransition = stStoreMigrated;
  954. WinConfiguration->FirstRun = WinConfiguration->FirstRun + L"=>" + StandardDatestamp();
  955. AppLog(L"Standard installation migrated to store installation");
  956. }
  957. if (WinConfiguration->StoreTransition == stStoreMigrated)
  958. {
  959. TTBXToolbar * Toolbar = new TTBXToolbar(MessageDock);
  960. Toolbar->Parent = MessageDock;
  961. Toolbar->FullSize = true;
  962. Toolbar->Color = Application->HintColor;
  963. TTBXLabelItem * LabelItem;
  964. LabelItem = new TTBXLabelItem(Toolbar);
  965. // Convert to explicit RGB "black" color, to make sure it is contrasting even in Dark theme
  966. // (TTBXOfficeXPTheme.GetStandardColor would convert clWindow to "white" in dark theme)
  967. LabelItem->FontSettings->Color = static_cast<TColor>(GetSysColor(clWindow));
  968. LabelItem->Margin = ScaleByTextHeight(MessageDock, 2); // Is this automatically rescaled?
  969. LabelItem->Caption = LoadStr(STORE_MIGRATION_THANKS);
  970. Toolbar->Items->Add(LabelItem);
  971. TTBXCustomItem * LinkItem = new TTBXItem(Toolbar);
  972. LinkItem->FontSettings->Color = LinkColor;
  973. LinkItem->Caption = LoadStr(STORE_MIGRATION_LEARN);
  974. LinkItem->OnClick = StoreTransitionLinkClick;
  975. Toolbar->Items->Add(LinkItem);
  976. AddMenuSeparator(Toolbar->Items);
  977. TTBXCustomItem * CloseItem = new TTBXItem(Toolbar);
  978. CloseItem->FontSettings->Color = static_cast<TColor>(GetSysColor(clWindow));
  979. CloseItem->Caption = LoadStr(MESSAGE_DISMISS);
  980. CloseItem->OnClick = StoreTransitionCloseClick;
  981. Toolbar->Items->Add(CloseItem);
  982. GiveTBItemPriority(CloseItem);
  983. }
  984. }
  985. //---------------------------------------------------------------------------
  986. void __fastcall TCustomScpExplorerForm::StoreTransitionLinkClick(TObject *)
  987. {
  988. ShowHelp(HELP_STORE_TRANSITION);
  989. }
  990. //---------------------------------------------------------------------------
  991. void __fastcall TCustomScpExplorerForm::StoreTransitionCloseClick(TObject * Sender)
  992. {
  993. TTBCustomItem * Item = DebugNotNull(dynamic_cast<TTBCustomItem *>(Sender));
  994. TTBXToolbar * Toolbar = DebugNotNull(dynamic_cast<TTBXToolbar *>(DebugNotNull(DebugNotNull(Item->Parent)->ParentComponent)));
  995. delete Toolbar;
  996. WinConfiguration->StoreTransition = stStoreAcknowledged;
  997. UpdateControls();
  998. }
  999. //---------------------------------------------------------------------------
  1000. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  1001. {
  1002. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  1003. static_cast<TComponent*>(GetComponent(fcTransferList)));
  1004. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  1005. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  1006. TransferList->Strings->BeginUpdate();
  1007. try
  1008. {
  1009. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  1010. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  1011. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  1012. if (FTransferDropDownHint.IsEmpty())
  1013. {
  1014. FTransferDropDownHint = TransferDropDown->Hint;
  1015. }
  1016. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  1017. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  1018. TransferDropDown->Text = StripHotkey(Name);
  1019. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  1020. (FTransferDropDownHint, StripHotkey(Name),
  1021. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  1022. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  1023. // update the label, otherwise when it is updated only on the first draw
  1024. // of the list, it is drawn "bold" for some reason
  1025. FTransferListHoverIndex = TransferList->ItemIndex;
  1026. UpdateTransferLabel();
  1027. }
  1028. __finally
  1029. {
  1030. TransferList->Strings->EndUpdate();
  1031. }
  1032. }
  1033. //---------------------------------------------------------------------------
  1034. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  1035. {
  1036. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  1037. DebugAssert(Toolbar != NULL);
  1038. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  1039. }
  1040. //---------------------------------------------------------------------------
  1041. void __fastcall TCustomScpExplorerForm::UpdateActions()
  1042. {
  1043. TForm::UpdateActions();
  1044. if (ComponentVisible[fcCustomCommandsBand])
  1045. {
  1046. UpdateCustomCommandsToolbar();
  1047. }
  1048. }
  1049. //---------------------------------------------------------------------------
  1050. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  1051. {
  1052. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  1053. }
  1054. //---------------------------------------------------------------------------
  1055. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  1056. {
  1057. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  1058. {
  1059. DirView->RowSelect = WinConfiguration->FullRowSelect;
  1060. // Without this, the panel turns gray and unused part of header turns black
  1061. DirView->Perform(CM_COLORCHANGED, 0, 0);
  1062. }
  1063. }
  1064. //---------------------------------------------------------------------------
  1065. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  1066. {
  1067. Color = GetBtnFaceColor();
  1068. DebugAssert(Configuration && RemoteDirView);
  1069. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  1070. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  1071. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  1072. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  1073. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  1074. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  1075. RemoteDirView->AlwaysSortDirectoriesByName = WinConfiguration->AlwaysSortDirectoriesByName;
  1076. UpdateRowSelect(RemoteDirView);
  1077. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  1078. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  1079. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  1080. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  1081. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  1082. UpdateSessionsPageControlHeight();
  1083. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1084. UpdateToolbarDisplayMode();
  1085. UpdateTransferList();
  1086. if (Terminal != NULL)
  1087. {
  1088. TransferPresetAutoSelect();
  1089. }
  1090. UpdateQueueView();
  1091. UpdateControls();
  1092. // this can be called even before constuctor finishes.
  1093. if (FEditorManager != NULL)
  1094. {
  1095. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  1096. }
  1097. // this can be called even before constuctor finishes.
  1098. if (FLocalEditors != NULL)
  1099. {
  1100. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  1101. {
  1102. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  1103. }
  1104. }
  1105. if (ComponentVisible[fcCustomCommandsBand])
  1106. {
  1107. UpdateCustomCommandsToolbar();
  1108. }
  1109. // show only when keeping queue items forever,
  1110. // otherwise, it's enough to have it in the context menu
  1111. QueueDeleteAllDoneQueueToolbarItem->Visible =
  1112. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  1113. if (FFileColorsCurrent != WinConfiguration->FileColors)
  1114. {
  1115. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  1116. FFileColorsCurrent = WinConfiguration->FileColors;
  1117. FileColorsChanged();
  1118. }
  1119. if ((GetNewTabTab()->CaptionTruncation != GetNewTabTabCaptionTruncation()) &&
  1120. (FSessionColors != NULL))
  1121. {
  1122. SessionListChanged();
  1123. }
  1124. if (GlyphsModule->LargerToolbar != WinConfiguration->LargerToolbar)
  1125. {
  1126. GlyphsModule->LargerToolbar = WinConfiguration->LargerToolbar;
  1127. if (FSessionColors != NULL)
  1128. {
  1129. RegenerateSessionColorsImageList();
  1130. UpdateSessionsPageControlHeight();
  1131. }
  1132. }
  1133. }
  1134. //---------------------------------------------------------------------------
  1135. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  1136. {
  1137. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  1138. DirView->Invalidate();
  1139. }
  1140. //---------------------------------------------------------------------------
  1141. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  1142. {
  1143. DoFileColorsChanged(RemoteDirView);
  1144. }
  1145. //---------------------------------------------------------------------------
  1146. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  1147. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  1148. void * /*Arg*/)
  1149. {
  1150. if (Token != NULL)
  1151. {
  1152. TForm * Editor = dynamic_cast<TForm*>(Token);
  1153. DebugAssert(Editor != NULL);
  1154. ReconfigureEditorForm(Editor);
  1155. }
  1156. }
  1157. //---------------------------------------------------------------------------
  1158. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1159. {
  1160. WinConfiguration->DDTransferConfirmation = asOn;
  1161. }
  1162. //---------------------------------------------------------------------------
  1163. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1164. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1165. {
  1166. // noop
  1167. }
  1168. //---------------------------------------------------------------------------
  1169. bool TCustomScpExplorerForm::GetDoNotShowCopyDialogDefault(bool DragDrop)
  1170. {
  1171. return DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto);
  1172. }
  1173. //---------------------------------------------------------------------------
  1174. void TCustomScpExplorerForm::HandleDoNotShowCopyDialogAgain(bool DragDrop, bool DoNotShowAgain)
  1175. {
  1176. if (DoNotShowAgain)
  1177. {
  1178. if (DragDrop)
  1179. {
  1180. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1181. {
  1182. PopupTrayBalloon(
  1183. NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation, NULL, 0, EnableDDTransferConfirmation, NULL);
  1184. }
  1185. WinConfiguration->DDTransferConfirmation = asOff;
  1186. }
  1187. else
  1188. {
  1189. WinConfiguration->ConfirmTransferring = false;
  1190. }
  1191. }
  1192. else
  1193. {
  1194. // User explicitly unchecked "do not show again",
  1195. // so show him the dialog the next time
  1196. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1197. {
  1198. WinConfiguration->DDTransferConfirmation = asOn;
  1199. }
  1200. }
  1201. }
  1202. //---------------------------------------------------------------------------
  1203. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1204. TTransferDirection Direction, TTransferType Type, bool Temp,
  1205. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1206. bool Confirm, bool DragDrop, int Options)
  1207. {
  1208. bool Result = true;
  1209. DebugAssert(HasActiveTerminal());
  1210. // these parameters are known in advance
  1211. int Params =
  1212. FLAGMASK(Type == ttMove, cpDelete);
  1213. bool ToTemp = (Temp && (Direction == tdToLocal));
  1214. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1215. {
  1216. bool DisableNewerOnly =
  1217. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1218. ToTemp;
  1219. Options |=
  1220. FLAGMASK(ToTemp, coTemp) |
  1221. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1222. coDoNotShowAgain;
  1223. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1224. int CopyParamAttrs = (Direction == tdToRemote ?
  1225. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1226. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1227. int OutputOptions = FLAGMASK(GetDoNotShowCopyDialogDefault(DragDrop), cooDoNotShowAgain);
  1228. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1229. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1230. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1231. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1232. if (Result)
  1233. {
  1234. HandleDoNotShowCopyDialogAgain(DragDrop, FLAGSET(OutputOptions, cooDoNotShowAgain));
  1235. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1236. }
  1237. }
  1238. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1239. {
  1240. Configuration->Usage->Inc(L"TransfersOnBackground");
  1241. // these parameter are known only after transfer dialog
  1242. Params |=
  1243. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1244. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1245. Result = false;
  1246. ClearTransferSourceSelection(Direction);
  1247. }
  1248. return Result;
  1249. }
  1250. //---------------------------------------------------------------------------
  1251. void TCustomScpExplorerForm::ClearOperationSelection(TOperationSide Side)
  1252. {
  1253. if (FOnFileOperationFinished != NULL)
  1254. {
  1255. FOnFileOperationFinished(Side, UnicodeString(), true, true);
  1256. }
  1257. else
  1258. {
  1259. if (HasDirView[Side])
  1260. {
  1261. DirView(Side)->SelectAll(smNone);
  1262. }
  1263. }
  1264. }
  1265. //---------------------------------------------------------------------------
  1266. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1267. {
  1268. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1269. ClearOperationSelection(Side);
  1270. }
  1271. //---------------------------------------------------------------------------
  1272. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1273. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1274. const UnicodeString TargetDirectory, TGUICopyParamType & CopyParam,
  1275. int Params)
  1276. {
  1277. DebugAssert(Queue != NULL);
  1278. bool SingleFile = false;
  1279. if (FileList->Count == 1)
  1280. {
  1281. if (Direction == tdToRemote)
  1282. {
  1283. UnicodeString FileName = FileList->Strings[0];
  1284. SingleFile = FileExists(ApiPath(FileName));
  1285. }
  1286. else
  1287. {
  1288. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1289. SingleFile = !File->IsDirectory;
  1290. }
  1291. }
  1292. TQueueItem * QueueItem;
  1293. if (Direction == tdToRemote)
  1294. {
  1295. CopyParam.IncludeFileMask.SetRoots(FileList, TargetDirectory);
  1296. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1297. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1298. }
  1299. else
  1300. {
  1301. CopyParam.IncludeFileMask.SetRoots(TargetDirectory, FileList);
  1302. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1303. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1304. }
  1305. AddQueueItem(Queue, QueueItem, Terminal);
  1306. }
  1307. //---------------------------------------------------------------------------
  1308. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1309. {
  1310. if (Queue->IsEmpty)
  1311. {
  1312. Terminal->QueueOperationStart = Now();
  1313. }
  1314. Queue->AddItem(QueueItem);
  1315. }
  1316. //---------------------------------------------------------------------------
  1317. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1318. {
  1319. }
  1320. //---------------------------------------------------------------------------
  1321. void __fastcall TCustomScpExplorerForm::InitControls()
  1322. {
  1323. DebugAssert(FDocks != NULL);
  1324. for (int Index = 0; Index < ComponentCount; Index++)
  1325. {
  1326. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1327. if ((Dock != NULL) && (Dock->Tag == 0))
  1328. {
  1329. FDocks->Add(Dock);
  1330. }
  1331. }
  1332. CollectItemsWithTextDisplayMode(this);
  1333. }
  1334. //---------------------------------------------------------------------------
  1335. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1336. {
  1337. ConfigurationChanged();
  1338. QueuePanel->Height =
  1339. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1340. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1341. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1342. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1343. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1344. QueueFileList->Height =
  1345. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1346. if (QueueFileList->Visible)
  1347. {
  1348. AdjustQueueLayout();
  1349. }
  1350. UpdateCustomCommandsToolbar();
  1351. }
  1352. //---------------------------------------------------------------------------
  1353. void __fastcall TCustomScpExplorerForm::StoreParams()
  1354. {
  1355. int APixelsPerInch = GetControlPixelsPerInch(this);
  1356. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1357. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1358. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1359. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1360. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1361. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1362. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1363. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1364. }
  1365. //---------------------------------------------------------------------------
  1366. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1367. {
  1368. if (!FFormRestored)
  1369. {
  1370. FFormRestored = true;
  1371. RestoreFormParams();
  1372. }
  1373. TForm::CreateParams(Params);
  1374. }
  1375. //---------------------------------------------------------------------------
  1376. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1377. {
  1378. DebugAssert(FDocks != NULL);
  1379. for (int Index = 0; Index < FDocks->Count; Index++)
  1380. {
  1381. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1382. }
  1383. }
  1384. //---------------------------------------------------------------------------
  1385. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1386. {
  1387. SetDockAllowDrag(true);
  1388. while (!ButtonsStr.IsEmpty())
  1389. {
  1390. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1391. UnicodeString Name = CutToChar(S, L'=', true);
  1392. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1393. {
  1394. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1395. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1396. {
  1397. while (!S.IsEmpty())
  1398. {
  1399. UnicodeString S2 = CutToChar(S, L',', true);
  1400. UnicodeString Name = CutToChar(S2, L':', true);
  1401. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1402. {
  1403. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1404. if (SameText(GetToolbarItemName(Item), Name))
  1405. {
  1406. // forward compatibility
  1407. UnicodeString S3 = CutToChar(S2, L':', true);
  1408. bool Visible = StrToIntDef(S3, 0);
  1409. Item->Visible = Visible;
  1410. }
  1411. }
  1412. }
  1413. }
  1414. }
  1415. }
  1416. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1417. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1418. }
  1419. //---------------------------------------------------------------------------
  1420. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1421. {
  1422. UnicodeString Result;
  1423. SetDockAllowDrag(true);
  1424. Result = ::GetToolbarsLayoutStr(this);
  1425. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1426. return Result;
  1427. }
  1428. //---------------------------------------------------------------------------
  1429. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1430. {
  1431. UnicodeString Result;
  1432. if (Item->Action != NULL)
  1433. {
  1434. Result = Item->Action->Name;
  1435. Result = RemoveSuffix(Result, L"Action", true);
  1436. }
  1437. else
  1438. {
  1439. Result = Item->Name;
  1440. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1441. Result = RemoveSuffix(Result, L"Item", true);
  1442. }
  1443. return Result;
  1444. }
  1445. //---------------------------------------------------------------------------
  1446. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1447. {
  1448. UnicodeString Result;
  1449. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1450. {
  1451. UnicodeString ToolbarStr;
  1452. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1453. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1454. {
  1455. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1456. {
  1457. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1458. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1459. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1460. // and save the changes here only.
  1461. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1462. {
  1463. UnicodeString Name = GetToolbarItemName(Item);
  1464. DebugAssert(Name.Pos(L"TBX") == 0);
  1465. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1466. }
  1467. }
  1468. }
  1469. if (!ToolbarStr.IsEmpty())
  1470. {
  1471. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1472. }
  1473. }
  1474. return Result;
  1475. }
  1476. //---------------------------------------------------------------------------
  1477. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1478. {
  1479. DebugAssert(FProgressForm == NULL);
  1480. bool AllowSkip = HasActiveTerminal() ? Terminal->IsCapable[fcSkipTransfer] : false;
  1481. bool AllowMoveToQueue = (FTransferResumeList != NULL) || (FDeletedFiles != NULL);
  1482. FProgressForm = new TProgressForm(Application, AllowMoveToQueue, AllowSkip, SynchronizeProgress);
  1483. FProgressForm->DeleteLocalToRecycleBin =
  1484. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1485. FProgressForm->DeleteRemoteToRecycleBin =
  1486. HasActiveTerminal() &&
  1487. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1488. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1489. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1490. LockWindow();
  1491. // Actually, do not know what hides the progress once the operation finishes
  1492. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1493. SetTaskbarListProgressState(TBPF_NORMAL);
  1494. }
  1495. //---------------------------------------------------------------------------
  1496. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1497. {
  1498. UnlockWindow();
  1499. SAFE_DESTROY(FProgressForm);
  1500. SetQueueProgress();
  1501. }
  1502. //---------------------------------------------------------------------------
  1503. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1504. TFileOperationProgressType & ProgressData)
  1505. {
  1506. // Download to temporary local directory
  1507. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1508. {
  1509. bool Continue = true;
  1510. FPendingTempSpaceWarn = false;
  1511. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1512. if (!Continue)
  1513. {
  1514. Abort();
  1515. }
  1516. }
  1517. // operation is being executed and we still didn't show up progress form
  1518. if (ProgressData.InProgress && !FProgressForm)
  1519. {
  1520. CreateProgressForm(NULL);
  1521. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1522. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1523. }
  1524. // operation is finished (or terminated), so we hide progress form
  1525. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1526. {
  1527. DestroyProgressForm();
  1528. if (ProgressData.Operation == foCalculateSize)
  1529. {
  1530. // When calculating size before transfer, the abort caused by
  1531. // cancel flag set due to "MoveToQueue" below,
  1532. // is not propagated back to us in ExecuteFileOperation,
  1533. // as it is silently swallowed.
  1534. // So we explicitly (re)throw it here.
  1535. if (FMoveToQueue)
  1536. {
  1537. Abort();
  1538. }
  1539. }
  1540. else
  1541. {
  1542. if ((ProgressData.Cancel == csContinue) &&
  1543. !FAutoOperation)
  1544. {
  1545. OperationComplete(ProgressData.StartTime);
  1546. }
  1547. }
  1548. }
  1549. if (FProgressForm &&
  1550. // Can happen only during synchronization, when ending one of the operations
  1551. ProgressData.InProgress)
  1552. {
  1553. FProgressForm->SetProgressData(ProgressData);
  1554. DebugAssert(ProgressData.InProgress);
  1555. SetTaskbarListProgressValue(&ProgressData);
  1556. if (FProgressForm->Cancel > csContinue)
  1557. {
  1558. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1559. if (FProgressForm->Cancel == csCancelFile)
  1560. {
  1561. FProgressForm->ClearCancel();
  1562. }
  1563. // cancel cancels even the move
  1564. FMoveToQueue = false;
  1565. }
  1566. else if (FProgressForm->MoveToQueue)
  1567. {
  1568. FMoveToQueue = true;
  1569. ProgressData.SetCancelAtLeast(csCancel);
  1570. }
  1571. if ((FTransferResumeList != NULL) &&
  1572. ProgressData.InProgress &&
  1573. ProgressData.IsTransfer() &&
  1574. !ProgressData.FullFileName.IsEmpty())
  1575. {
  1576. if ((FTransferResumeList->Count == 0) ||
  1577. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1578. {
  1579. // note that we do not recognize directories from files here
  1580. FTransferResumeList->Add(ProgressData.FullFileName);
  1581. }
  1582. }
  1583. }
  1584. }
  1585. //---------------------------------------------------------------------------
  1586. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1587. const TDateTime & StartTime)
  1588. {
  1589. if (GUIConfiguration->BeepOnFinish &&
  1590. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1591. {
  1592. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1593. DWORD Sound;
  1594. if (!ExtractFileExt(BeepSound).IsEmpty())
  1595. {
  1596. Sound = SND_FILENAME;
  1597. }
  1598. else
  1599. {
  1600. Sound = SND_ALIAS;
  1601. }
  1602. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1603. }
  1604. }
  1605. //---------------------------------------------------------------------------
  1606. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1607. TFileOperationProgressType & ProgressData)
  1608. {
  1609. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1610. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1611. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1612. FileOperationProgress(ProgressData);
  1613. }
  1614. //---------------------------------------------------------------------------
  1615. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1616. {
  1617. UnicodeString Result;
  1618. if (FProgressForm != NULL)
  1619. {
  1620. Result = FProgressForm->ProgressStr();
  1621. }
  1622. return Result;
  1623. }
  1624. //---------------------------------------------------------------------------
  1625. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1626. bool DragDrop)
  1627. {
  1628. return (!DragDrop && (DropSourceControl == NULL)) ||
  1629. (DropSourceControl == DirView(osOther));
  1630. }
  1631. //---------------------------------------------------------------------------
  1632. TListItem * TCustomScpExplorerForm::VisualiseOperationFinished(TOperationSide Side, const UnicodeString & FileName, bool Unselect)
  1633. {
  1634. TCustomDirView * ADirView = DirView(Side);
  1635. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(Side));
  1636. TListItem * Item = ADirView->FindFileItem(FileNameOnly);
  1637. // this can happen when local drive is unplugged in the middle of the operation
  1638. if (Item != NULL)
  1639. {
  1640. if (Unselect)
  1641. {
  1642. Item->Selected = false;
  1643. }
  1644. ADirView->MakeProgressVisible(Item);
  1645. }
  1646. return Item;
  1647. }
  1648. //---------------------------------------------------------------------------
  1649. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1650. TFileOperation Operation, TOperationSide Side,
  1651. bool /*Temp*/, const UnicodeString & FileName, bool Success, bool NotCancelled,
  1652. TOnceDoneOperation & OnceDoneOperation)
  1653. {
  1654. if (!FAutoOperation)
  1655. {
  1656. // no selection on "/upload", form serves only as event handler
  1657. // (it is not displayed)
  1658. if (PanelOperation(Side, FDragDropOperation) && Visible &&
  1659. ((Operation == FPrimaryOperation) ||
  1660. ((Operation != foCalculateSize) && (Operation != foGetProperties) && (Operation != foCalculateChecksum))))
  1661. {
  1662. TOperationSide DViewSide;
  1663. if ((FProgressSide != osCurrent) &&
  1664. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1665. {
  1666. // assume the operation is over the focused panel
  1667. DViewSide = FProgressSide;
  1668. }
  1669. else
  1670. {
  1671. DViewSide = Side;
  1672. }
  1673. if (FOnFileOperationFinished != NULL)
  1674. {
  1675. FOnFileOperationFinished(DViewSide, FileName, Success, NotCancelled);
  1676. }
  1677. else
  1678. {
  1679. VisualiseOperationFinished(DViewSide, FileName, Success && NotCancelled);
  1680. }
  1681. }
  1682. if (TFileOperationProgressType::IsTransferOperation(Operation))
  1683. {
  1684. if (DebugAlwaysTrue(!IsLocalBrowserMode()))
  1685. {
  1686. if (Side == osLocal)
  1687. {
  1688. Configuration->Usage->Inc(L"UploadedFiles");
  1689. }
  1690. else
  1691. {
  1692. Configuration->Usage->Inc(L"DownloadedFiles");
  1693. }
  1694. }
  1695. }
  1696. }
  1697. if (Success && (FSynchronizeController != NULL))
  1698. {
  1699. DebugAssert(!IsSideLocalBrowser(osRemote));
  1700. if (Operation == foCopy)
  1701. {
  1702. DebugAssert(Side == osLocal);
  1703. FSynchronizeController->LogOperation(soUpload, FileName);
  1704. }
  1705. else if (Operation == foDelete)
  1706. {
  1707. DebugAssert(Side == osRemote);
  1708. FSynchronizeController->LogOperation(soDelete, FileName);
  1709. }
  1710. }
  1711. if (FProgressForm)
  1712. {
  1713. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1714. }
  1715. }
  1716. //---------------------------------------------------------------------------
  1717. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1718. TFileOperation Operation, TOperationSide Side,
  1719. bool Temp, const UnicodeString & FileName, bool Success, bool NotCancelled,
  1720. TOnceDoneOperation & OnceDoneOperation)
  1721. {
  1722. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1723. DoOperationFinished(Operation, Side, Temp, FileName, Success, NotCancelled, OnceDoneOperation);
  1724. }
  1725. //---------------------------------------------------------------------------
  1726. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1727. {
  1728. return false;
  1729. }
  1730. //---------------------------------------------------------------------------
  1731. bool TCustomScpExplorerForm::SupportsLocalBrowser()
  1732. {
  1733. return false;
  1734. }
  1735. //---------------------------------------------------------------------------
  1736. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1737. {
  1738. return false;
  1739. }
  1740. //---------------------------------------------------------------------------
  1741. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1742. {
  1743. return NULL;
  1744. }
  1745. //---------------------------------------------------------------------------
  1746. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1747. {
  1748. DebugAssert(GetSide(Side) == osRemote);
  1749. DebugUsedParam(Side);
  1750. return RemoteDirView;
  1751. }
  1752. //---------------------------------------------------------------------------
  1753. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1754. {
  1755. DebugAssert(GetSide(Side) == osRemote);
  1756. DebugUsedParam(Side);
  1757. return RemoteDriveView;
  1758. }
  1759. //---------------------------------------------------------------------------
  1760. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1761. {
  1762. DebugAssert(GetSide(Side) == osRemote);
  1763. DebugUsedParam(Side);
  1764. return HasActiveTerminal();
  1765. }
  1766. //---------------------------------------------------------------------------
  1767. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1768. TOperationSide Side, int FilesOnly)
  1769. {
  1770. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1771. }
  1772. //---------------------------------------------------------------------------
  1773. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1774. TOperationSide Side, int FilesOnly)
  1775. {
  1776. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1777. }
  1778. //---------------------------------------------------------------------------
  1779. struct THistoryItemData
  1780. {
  1781. short int Side;
  1782. short int Index;
  1783. };
  1784. //---------------------------------------------------------------------------
  1785. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1786. {
  1787. DirView(Side)->HistoryGo(Index);
  1788. }
  1789. //---------------------------------------------------------------------------
  1790. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1791. {
  1792. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1793. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1794. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1795. }
  1796. //---------------------------------------------------------------------------
  1797. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1798. bool Back)
  1799. {
  1800. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1801. {
  1802. TCustomDirView * DView = DirView(Side);
  1803. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1804. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1805. if (ICount > 10)
  1806. {
  1807. ICount = 10;
  1808. }
  1809. Menu->Items->Clear();
  1810. THistoryItemData Data;
  1811. Data.Side = Side;
  1812. for (short int i = 1; i <= ICount; i++)
  1813. {
  1814. TTBCustomItem * Item = new TTBXItem(Menu);
  1815. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1816. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1817. Item->Hint = DView->HistoryPath[Data.Index];
  1818. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1819. Item->Tag = *reinterpret_cast<int*>(&Data);
  1820. Item->OnClick = HistoryItemClick;
  1821. Menu->Items->Add(Item);
  1822. }
  1823. }
  1824. }
  1825. //---------------------------------------------------------------------------
  1826. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1827. TOperationSide Side, bool Back)
  1828. {
  1829. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1830. {
  1831. // workaround
  1832. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1833. // operator new allocates memory in Pascal code, but calls inline
  1834. // constructor in C++, leading in problems, the function does
  1835. // both in Pascal code
  1836. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1837. UpdateHistoryMenu(Side, Back);
  1838. }
  1839. return FHistoryMenu[Side == osLocal][Back];
  1840. }
  1841. //---------------------------------------------------------------------------
  1842. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1843. TCustomDirView *Sender)
  1844. {
  1845. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1846. UpdateHistoryMenu(Side, true);
  1847. UpdateHistoryMenu(Side, false);
  1848. }
  1849. //---------------------------------------------------------------------------
  1850. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1851. {
  1852. // remote custom commands can be executed only if the server supports shell commands
  1853. // or have secondary shell
  1854. return HasActiveTerminal() && (Terminal->IsCapable[fcSecondaryShell] || Terminal->IsCapable[fcShellAnyCommand]);
  1855. }
  1856. //---------------------------------------------------------------------------
  1857. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1858. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1859. {
  1860. // -1 = hidden, 0 = disabled, 1 = enabled
  1861. int Result;
  1862. TFileCustomCommand RemoteCustomCommand;
  1863. TLocalCustomCommand LocalCustomCommand;
  1864. TFileCustomCommand * NonInteractiveCustomCommand =
  1865. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1866. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1867. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1868. if (FLAGCLEAR(Command.Params, ccLocal))
  1869. {
  1870. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1871. // custom command that does not operate with files can be executed anytime ...
  1872. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1873. {
  1874. // ... but do not show such command in remote file menu
  1875. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1876. {
  1877. Result = AllowedState;
  1878. }
  1879. else
  1880. {
  1881. Result = -1;
  1882. }
  1883. }
  1884. else
  1885. {
  1886. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1887. {
  1888. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1889. }
  1890. else
  1891. {
  1892. Result = -1;
  1893. }
  1894. }
  1895. }
  1896. else
  1897. {
  1898. // custom command that does not operate with files can be executed anytime
  1899. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1900. {
  1901. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1902. }
  1903. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1904. {
  1905. if ((ListType == ccltAll) || (ListType == ccltFile))
  1906. {
  1907. // special case is "diff"-style command that can be executed over any side,
  1908. // if we have both sides
  1909. Result =
  1910. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1911. // directly (instead of EnableSelectedOperation) to pass
  1912. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1913. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1914. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1915. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1916. }
  1917. else if (ListType == ccltBoth)
  1918. {
  1919. DebugAssert(!IsLocalBrowserMode());
  1920. Result = 1;
  1921. }
  1922. else
  1923. {
  1924. Result = -1;
  1925. }
  1926. }
  1927. else
  1928. {
  1929. if ((ListType == ccltAll) ||
  1930. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1931. {
  1932. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1933. }
  1934. else
  1935. {
  1936. Result = -1;
  1937. }
  1938. }
  1939. if ((Result > 0) &&
  1940. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1941. !HasActiveTerminal())
  1942. {
  1943. Result = 0;
  1944. }
  1945. }
  1946. return Result;
  1947. }
  1948. //---------------------------------------------------------------------------
  1949. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1950. TStrings * FileList, const TCustomCommandType & ACommand,
  1951. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1952. {
  1953. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1954. {
  1955. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1956. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1957. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1958. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1959. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1960. bool Capture =
  1961. FLAGSET(ACommand.Params, ccShowResults) ||
  1962. FLAGSET(ACommand.Params, ccCopyResults) ||
  1963. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1964. TCaptureOutputEvent OutputEvent = NULL;
  1965. DebugAssert(FCapturedLog == NULL);
  1966. if (Capture)
  1967. {
  1968. FCapturedLog = new TStringList();
  1969. OutputEvent = TerminalCaptureLog;
  1970. }
  1971. try
  1972. {
  1973. if (!RemoteCustomCommand.IsFileCommand(Command))
  1974. {
  1975. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1976. OutputEvent);
  1977. }
  1978. else
  1979. {
  1980. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1981. }
  1982. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1983. {
  1984. if (FLAGSET(ACommand.Params, ccCopyResults))
  1985. {
  1986. CopyToClipboard(FCapturedLog);
  1987. }
  1988. if (FLAGSET(ACommand.Params, ccShowResults))
  1989. {
  1990. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1991. }
  1992. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1993. {
  1994. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1995. }
  1996. }
  1997. }
  1998. __finally
  1999. {
  2000. SAFE_DESTROY(FCapturedLog);
  2001. }
  2002. }
  2003. }
  2004. //---------------------------------------------------------------------------
  2005. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  2006. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  2007. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  2008. {
  2009. DebugAssert(!IsLocalBrowserMode());
  2010. TStrings * LocalFileList = NULL;
  2011. TStrings * RemoteFileList = NULL;
  2012. TStrings * RemoteFileListFull = NULL;
  2013. try
  2014. {
  2015. if (LocalFileCommand)
  2016. {
  2017. if (ALocalFileList == NULL)
  2018. {
  2019. DebugAssert(HasDirView[osLocal]);
  2020. // Cannot have focus on both panels, so we have to call AnyFileSelected
  2021. // directly (instead of EnableSelectedOperation) to pass
  2022. // false to FocusedFileOnlyWhenFocused
  2023. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  2024. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  2025. }
  2026. else
  2027. {
  2028. LocalFileList = ALocalFileList;
  2029. }
  2030. if (FileListCommand)
  2031. {
  2032. if (LocalFileList->Count != 1)
  2033. {
  2034. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  2035. }
  2036. }
  2037. else
  2038. {
  2039. if ((LocalFileList->Count != 1) &&
  2040. (FileList->Count != 1) &&
  2041. (LocalFileList->Count != FileList->Count))
  2042. {
  2043. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  2044. }
  2045. }
  2046. }
  2047. UnicodeString RootTempDir;
  2048. UnicodeString TempDir;
  2049. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  2050. if (!RemoteFiles)
  2051. {
  2052. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, true, true);
  2053. }
  2054. try
  2055. {
  2056. TDateTimes RemoteFileTimes;
  2057. if (RemoteFiles)
  2058. {
  2059. RemoteFileList = FileList;
  2060. }
  2061. else
  2062. {
  2063. RemoteFileList = new TStringList();
  2064. TMakeLocalFileListParams MakeFileListParam;
  2065. MakeFileListParam.FileList = RemoteFileList;
  2066. MakeFileListParam.FileTimes = &RemoteFileTimes;
  2067. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2068. MakeFileListParam.Recursive =
  2069. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  2070. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  2071. if (!MakeFileListParam.Recursive)
  2072. {
  2073. RemoteFileTimes.clear();
  2074. RemoteFileListFull = new TStringList();
  2075. MakeFileListParam.FileList = RemoteFileListFull;
  2076. MakeFileListParam.Recursive = true;
  2077. MakeFileListParam.IncludeDirs = false;
  2078. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  2079. }
  2080. else
  2081. {
  2082. RemoteFileListFull = RemoteFileList;
  2083. }
  2084. }
  2085. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  2086. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2087. if (!NonBlocking)
  2088. {
  2089. int Count;
  2090. if (FileListCommand)
  2091. {
  2092. Count = 1;
  2093. }
  2094. else if (LocalFileCommand)
  2095. {
  2096. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  2097. }
  2098. else
  2099. {
  2100. Count = RemoteFileList->Count;
  2101. }
  2102. Progress.Start(foCustomCommand, osRemote, Count);
  2103. DebugAssert(FProgressForm != NULL);
  2104. FProgressForm->ReadOnly = true;
  2105. }
  2106. try
  2107. {
  2108. if (FileListCommand)
  2109. {
  2110. UnicodeString LocalFile;
  2111. // MakeFileList does not delimit filenames
  2112. UnicodeString FileList = MakeFileList(RemoteFileList);
  2113. if (LocalFileCommand)
  2114. {
  2115. DebugAssert(LocalFileList->Count == 1);
  2116. LocalFile = LocalFileList->Strings[0];
  2117. }
  2118. TLocalCustomCommand CustomCommand(Data,
  2119. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  2120. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  2121. if (NonBlocking)
  2122. {
  2123. DebugAssert(!POutput);
  2124. ExecuteShellChecked(ShellCommand);
  2125. }
  2126. else
  2127. {
  2128. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  2129. }
  2130. }
  2131. else if (LocalFileCommand)
  2132. {
  2133. if (LocalFileList->Count == 1)
  2134. {
  2135. UnicodeString LocalFile = LocalFileList->Strings[0];
  2136. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2137. {
  2138. UnicodeString FileName = RemoteFileList->Strings[Index];
  2139. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2140. Progress.SetFile(FileNameForProgress);
  2141. TLocalCustomCommand CustomCommand(Data,
  2142. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  2143. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2144. TOnceDoneOperation OnceDoneOperation;
  2145. // Do not unselect anything, as it won't work with two panels anyway
  2146. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2147. }
  2148. }
  2149. else if (RemoteFileList->Count == 1)
  2150. {
  2151. UnicodeString FileName = RemoteFileList->Strings[0];
  2152. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2153. {
  2154. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2155. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2156. Progress.SetFile(LocalFileNameOnly);
  2157. TLocalCustomCommand CustomCommand(
  2158. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2159. FileName, LocalFileName, L"");
  2160. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2161. TOnceDoneOperation OnceDoneOperation;
  2162. // Do not unselect anything, as it won't work with two panels anyway
  2163. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2164. }
  2165. }
  2166. else
  2167. {
  2168. if (LocalFileList->Count != RemoteFileList->Count)
  2169. {
  2170. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  2171. }
  2172. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2173. {
  2174. UnicodeString FileName = RemoteFileList->Strings[Index];
  2175. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2176. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2177. Progress.SetFile(LocalFileNameOnly); // sic
  2178. TLocalCustomCommand CustomCommand(
  2179. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2180. FileName, LocalFileName, L"");
  2181. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2182. TOnceDoneOperation OnceDoneOperation;
  2183. // Do not unselect anything, as it won't work with two panels anyway
  2184. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2185. }
  2186. }
  2187. }
  2188. else
  2189. {
  2190. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2191. {
  2192. UnicodeString FileName = RemoteFileList->Strings[Index];
  2193. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2194. Progress.SetFile(FileNameForProgress);
  2195. TLocalCustomCommand CustomCommand(Data,
  2196. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2197. FileName, L"", L"");
  2198. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2199. TOnceDoneOperation OnceDoneOperation;
  2200. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2201. }
  2202. }
  2203. }
  2204. __finally
  2205. {
  2206. if (!NonBlocking)
  2207. {
  2208. Progress.Stop();
  2209. }
  2210. }
  2211. DebugAssert(!FAutoOperation);
  2212. if (!RemoteFiles)
  2213. {
  2214. TempDir = IncludeTrailingBackslash(TempDir);
  2215. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2216. {
  2217. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2218. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2219. // Skip directories, process only nested files.
  2220. // The check is redundant as FileAge fails for directories anyway.
  2221. !DirectoryExists(FileName))
  2222. {
  2223. UnicodeString RemoteDir =
  2224. UnixExtractFileDir(
  2225. UnixIncludeTrailingBackslash(Terminal->CurrentDirectory) +
  2226. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2227. TSearchRecSmart SearchRec;
  2228. if (FileSearchRec(FileName, SearchRec) &&
  2229. (SearchRec.GetLastWriteTime() != RemoteFileTimes[Index]))
  2230. {
  2231. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2232. TemporaryFileCopyParam(CopyParam);
  2233. CopyParam.FileMask = L"";
  2234. FAutoOperation = true;
  2235. FMoveToQueue = false;
  2236. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2237. TemporaryFilesList->Add(FileName);
  2238. Terminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2239. }
  2240. }
  2241. }
  2242. }
  2243. }
  2244. __finally
  2245. {
  2246. FAutoOperation = false;
  2247. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2248. {
  2249. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir));
  2250. }
  2251. }
  2252. }
  2253. __finally
  2254. {
  2255. if (RemoteFileList != FileList)
  2256. {
  2257. delete RemoteFileList;
  2258. }
  2259. if (LocalFileList != ALocalFileList)
  2260. {
  2261. delete LocalFileList;
  2262. }
  2263. if (RemoteFileListFull != RemoteFileList)
  2264. {
  2265. delete RemoteFileListFull;
  2266. }
  2267. }
  2268. }
  2269. //---------------------------------------------------------------------------
  2270. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2271. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2272. bool FileListCommand, UnicodeString * POutput)
  2273. {
  2274. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2275. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2276. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2277. {
  2278. UnicodeString FileName = SelectedFileList->Strings[Index];
  2279. if (DirectoryExists(FileName))
  2280. {
  2281. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2282. {
  2283. LocalFileList->Add(FileName);
  2284. }
  2285. if (FLAGSET(ACommand.Params, ccRecursive))
  2286. {
  2287. TMakeLocalFileListParams MakeFileListParam;
  2288. MakeFileListParam.FileList = LocalFileList.get();
  2289. MakeFileListParam.FileTimes = NULL;
  2290. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2291. MakeFileListParam.Recursive = true;
  2292. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2293. }
  2294. }
  2295. else
  2296. {
  2297. LocalFileList->Add(FileName);
  2298. }
  2299. }
  2300. UnicodeString RemotePath;
  2301. if (Terminal != NULL)
  2302. {
  2303. RemotePath = Terminal->CurrentDirectory;
  2304. }
  2305. if (FileListCommand)
  2306. {
  2307. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2308. TLocalCustomCommand CustomCommand(
  2309. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2310. L"", L"", FileList);
  2311. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2312. }
  2313. else
  2314. {
  2315. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2316. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2317. DebugAssert(FProgressForm != NULL);
  2318. FProgressForm->ReadOnly = true;
  2319. try
  2320. {
  2321. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2322. {
  2323. UnicodeString FileName = LocalFileList->Strings[Index];
  2324. Progress.SetFile(FileName);
  2325. TLocalCustomCommand CustomCommand(
  2326. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2327. FileName, L"", L"");
  2328. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2329. TOnceDoneOperation OnceDoneOperation;
  2330. Progress.Finish(FileName, true, OnceDoneOperation);
  2331. }
  2332. }
  2333. __finally
  2334. {
  2335. Progress.Stop();
  2336. }
  2337. }
  2338. }
  2339. //---------------------------------------------------------------------------
  2340. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2341. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2342. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2343. {
  2344. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2345. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2346. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2347. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2348. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2349. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2350. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2351. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2352. std::unique_ptr<UnicodeString> POutput;
  2353. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2354. FLAGSET(ACommand.Params, ccCopyResults))
  2355. {
  2356. POutput.reset(new UnicodeString());
  2357. }
  2358. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide, FCurrentSide);
  2359. if (!LocalCustomCommand.IsFileCommand(Command))
  2360. {
  2361. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2362. }
  2363. // remote files?
  2364. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2365. {
  2366. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2367. }
  2368. // local files
  2369. else
  2370. {
  2371. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2372. }
  2373. if (POutput.get() != NULL)
  2374. {
  2375. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2376. int P = POutput->Pos(sLineBreak);
  2377. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2378. {
  2379. POutput->SetLength(P - 1);
  2380. }
  2381. // Copy even empty output to clipboard
  2382. if (FLAGSET(ACommand.Params, ccCopyResults))
  2383. {
  2384. CopyToClipboard(*POutput);
  2385. }
  2386. // But do not show an empty message box.
  2387. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2388. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2389. !POutput->IsEmpty())
  2390. {
  2391. TClipboardHandler ClipboardHandler;
  2392. ClipboardHandler.Text = *POutput;
  2393. TMessageParams Params;
  2394. TQueryButtonAlias Aliases[1];
  2395. Aliases[0].Button = qaRetry;
  2396. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2397. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2398. Params.Aliases = Aliases;
  2399. Params.AliasesCount = LENOF(Aliases);
  2400. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2401. }
  2402. }
  2403. }
  2404. //---------------------------------------------------------------------------
  2405. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2406. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2407. {
  2408. TCustomCommandData Data;
  2409. UnicodeString Site;
  2410. UnicodeString RemotePath;
  2411. if (HasActiveTerminal())
  2412. {
  2413. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2414. Data = TCustomCommandData(SessionData.get());
  2415. Site = Terminal->SessionData->SessionKey;
  2416. RemotePath = Terminal->CurrentDirectory;
  2417. }
  2418. UnicodeString HelpKeyword = ACommand.HomePage;
  2419. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2420. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2421. {
  2422. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2423. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2424. {
  2425. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2426. }
  2427. else
  2428. {
  2429. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2430. }
  2431. if (!DoCustomCommandOptionsDialog(
  2432. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2433. {
  2434. Abort();
  2435. }
  2436. }
  2437. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2438. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2439. {
  2440. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2441. }
  2442. else
  2443. {
  2444. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2445. }
  2446. }
  2447. //---------------------------------------------------------------------------
  2448. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2449. const TCustomCommandType & Command)
  2450. {
  2451. DebugAssert(FCustomCommandLocalFileList != NULL);
  2452. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2453. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2454. TStrings * LocalFileList = new TStringList();
  2455. TStrings * RemoteFileList = new TStringList();
  2456. try
  2457. {
  2458. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2459. {
  2460. LocalFileList->Clear();
  2461. LocalFileList->AddObject(
  2462. FCustomCommandLocalFileList->Strings[Index],
  2463. FCustomCommandLocalFileList->Objects[Index]);
  2464. RemoteFileList->Clear();
  2465. RemoteFileList->AddObject(
  2466. FCustomCommandRemoteFileList->Strings[Index],
  2467. FCustomCommandRemoteFileList->Objects[Index]);
  2468. CustomCommand(RemoteFileList, Command, LocalFileList);
  2469. }
  2470. }
  2471. __finally
  2472. {
  2473. delete LocalFileList;
  2474. delete RemoteFileList;
  2475. }
  2476. }
  2477. //---------------------------------------------------------------------------
  2478. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2479. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2480. {
  2481. delete FCustomCommandLocalFileList;
  2482. delete FCustomCommandRemoteFileList;
  2483. // takeover ownership,
  2484. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2485. FCustomCommandLocalFileList = LocalFileList;
  2486. FCustomCommandRemoteFileList = RemoteFileList;
  2487. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2488. if (Button != NULL)
  2489. {
  2490. FCustomCommandMenu->Items->Clear();
  2491. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2492. MenuPopup(FCustomCommandMenu, Button);
  2493. }
  2494. else
  2495. {
  2496. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2497. }
  2498. }
  2499. //---------------------------------------------------------------------------
  2500. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2501. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2502. {
  2503. DebugAssert(FCapturedLog != NULL);
  2504. if ((OutputType == cotOutput) || (OutputType == cotError))
  2505. {
  2506. FCapturedLog->Add(AddedLine);
  2507. }
  2508. }
  2509. //---------------------------------------------------------------------------
  2510. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2511. TOperationSide Side)
  2512. {
  2513. return
  2514. (Side == osOther) &&
  2515. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2516. }
  2517. //---------------------------------------------------------------------------
  2518. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2519. TOperationSide Side, TTBXCustomItem * Item,
  2520. TResolvedDoubleClickAction DoubleClickAction1, TResolvedDoubleClickAction DoubleClickAction2)
  2521. {
  2522. TCustomDirView * DView = DirView(Side);
  2523. bool IsDefault = false;
  2524. if (DView->ItemFocused != NULL)
  2525. {
  2526. TTerminal * ATerminal = !IsSideLocalBrowser(Side) ? Terminal : NULL;
  2527. TResolvedDoubleClickAction DefaultAction =
  2528. WinConfiguration->ResolveDoubleClickAction(DView->ItemIsDirectory(DView->ItemFocused), ATerminal);
  2529. IsDefault = (DefaultAction == DoubleClickAction1) || (DefaultAction == DoubleClickAction2);
  2530. }
  2531. TTBItemOptions O = Item->Options;
  2532. if (IsDefault)
  2533. {
  2534. Item->Options = O << tboDefault;
  2535. }
  2536. else
  2537. {
  2538. Item->Options = O >> tboDefault;
  2539. }
  2540. }
  2541. //---------------------------------------------------------------------------
  2542. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2543. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2544. {
  2545. TCustomDirView * DView = DirView(Side);
  2546. TListItem * Item = DView->ItemFocused;
  2547. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2548. EnableFocusedOperation[Side])
  2549. {
  2550. TPoint ClientPoint;
  2551. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2552. TPoint(0, 0) : MousePos;
  2553. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2554. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2555. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2556. }
  2557. }
  2558. //---------------------------------------------------------------------------
  2559. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2560. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2561. {
  2562. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, rdcaChangeDir, rdcaOpen);
  2563. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, rdcaEdit, rdcaNone);
  2564. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, rdcaCopy, rdcaNone);
  2565. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2566. Handled = true;
  2567. }
  2568. //---------------------------------------------------------------------------
  2569. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2570. {
  2571. }
  2572. //---------------------------------------------------------------------------
  2573. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2574. {
  2575. DebugAssert(FErrorList == NULL);
  2576. if (WinConfiguration->ContinueOnError)
  2577. {
  2578. FErrorList = new TStringList();
  2579. Configuration->Usage->Inc(L"ContinuationsOnError");
  2580. }
  2581. NonVisualDataModule->StartBusy();
  2582. }
  2583. //---------------------------------------------------------------------------
  2584. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2585. {
  2586. NonVisualDataModule->EndBusy();
  2587. if (FErrorList)
  2588. {
  2589. HandleErrorList(FErrorList);
  2590. }
  2591. }
  2592. //---------------------------------------------------------------------------
  2593. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2594. const TCopyParamType & CopyParam)
  2595. {
  2596. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2597. {
  2598. Configuration->Usage->Inc(L"FileMaskUses");
  2599. }
  2600. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2601. {
  2602. Configuration->Usage->Inc(L"OperationMaskUses");
  2603. }
  2604. }
  2605. //---------------------------------------------------------------------------
  2606. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2607. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2608. {
  2609. DebugAssert(!IsLocalBrowserMode());
  2610. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2611. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2612. TTransferOperationParam DefaultParam;
  2613. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2614. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2615. switch (Param.Queue)
  2616. {
  2617. case asOn:
  2618. CopyParam.Queue = true;
  2619. break;
  2620. case asOff:
  2621. CopyParam.Queue = false;
  2622. break;
  2623. case asAuto:
  2624. default:
  2625. // keep default
  2626. break;
  2627. }
  2628. bool Result =
  2629. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2630. if (Result)
  2631. {
  2632. DebugAssert(Terminal);
  2633. bool SelectionRestored = false;
  2634. TCustomDirView * DView = NULL;
  2635. if (HasDirView[Side])
  2636. {
  2637. DView = DirView(Side);
  2638. DView->SaveSelection();
  2639. DView->SaveSelectedNames();
  2640. }
  2641. UpdateCopyParamCounters(CopyParam);
  2642. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2643. DebugAssert(FTransferResumeList == NULL);
  2644. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2645. FMoveToQueue = false;
  2646. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2647. try
  2648. {
  2649. TStrings * PermanentFileList;
  2650. std::unique_ptr<TStrings> PermanentFileListOwner;
  2651. try
  2652. {
  2653. if (Side == osLocal)
  2654. {
  2655. PermanentFileList = FileList;
  2656. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2657. CopyParam.IncludeFileMask.SetRoots(FileList, Param.TargetDirectory);
  2658. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2659. if (Operation == foMove)
  2660. {
  2661. ReloadLocalDirectory();
  2662. if (DView != NULL)
  2663. {
  2664. DView->RestoreSelection();
  2665. }
  2666. SelectionRestored = true;
  2667. }
  2668. }
  2669. else
  2670. {
  2671. // Clone the file list as it may refer to current directory files,
  2672. // which get destroyed, when the source directory is reloaded after foMove operation.
  2673. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2674. // But for a hotfix, we are not going to do such a big change.
  2675. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2676. PermanentFileList = PermanentFileListOwner.get();
  2677. try
  2678. {
  2679. CopyParam.IncludeFileMask.SetRoots(Param.TargetDirectory, FileList);
  2680. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2681. }
  2682. __finally
  2683. {
  2684. if (Operation == foMove)
  2685. {
  2686. if (DView != NULL)
  2687. {
  2688. DView->RestoreSelection();
  2689. }
  2690. SelectionRestored = true;
  2691. }
  2692. ReloadLocalDirectory(Param.TargetDirectory);
  2693. }
  2694. }
  2695. // When the transfer batch is aborted between individual file transfers, the Abort is not called.
  2696. if (FMoveToQueue)
  2697. {
  2698. Abort();
  2699. }
  2700. }
  2701. catch (EAbort &)
  2702. {
  2703. if (FMoveToQueue)
  2704. {
  2705. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2706. DebugAssert(CopyParam.TransferSkipList == NULL);
  2707. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2708. if (TransferResumeList->Count > 0)
  2709. {
  2710. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2711. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2712. }
  2713. CopyParam.TransferSkipList = TransferResumeList.release();
  2714. // not really needed, just to keep it consistent with TransferResumeList
  2715. FTransferResumeList = NULL;
  2716. FMoveToQueue = false;
  2717. Configuration->Usage->Inc("MovesToBackground");
  2718. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2719. ClearTransferSourceSelection(Direction);
  2720. }
  2721. throw;
  2722. }
  2723. }
  2724. __finally
  2725. {
  2726. if (!SelectionRestored && (DView != NULL))
  2727. {
  2728. DView->DiscardSavedSelection();
  2729. }
  2730. FTransferResumeList = NULL;
  2731. }
  2732. }
  2733. return Result;
  2734. }
  2735. //---------------------------------------------------------------------------
  2736. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2737. TOperationSide Side, TStrings * FileList, void * Param)
  2738. {
  2739. DebugAssert(FileList->Count);
  2740. // We deliberately do not toggle alternative flag (Param), but use OR,
  2741. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2742. // shortcut of CurrentDeleteAlternativeAction
  2743. bool Alternative =
  2744. bool(Param) || UseAlternativeFunction();
  2745. bool Recycle;
  2746. if (IsSideLocalBrowser(Side))
  2747. {
  2748. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2749. }
  2750. else
  2751. {
  2752. Recycle =
  2753. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2754. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2755. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2756. }
  2757. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2758. if (!Result)
  2759. {
  2760. UnicodeString Query;
  2761. if (FileList->Count == 1)
  2762. {
  2763. if (IsSideLocalBrowser(Side))
  2764. {
  2765. Query = ExtractFileName(FileList->Strings[0]);
  2766. }
  2767. else
  2768. {
  2769. Query = UnixExtractFileName(FileList->Strings[0]);
  2770. }
  2771. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2772. }
  2773. else
  2774. {
  2775. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2776. }
  2777. TMessageParams Params(mpNeverAskAgainCheck);
  2778. Params.ImageName = L"Delete file";
  2779. unsigned int Answer =
  2780. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2781. if (Answer == qaNeverAskAgain)
  2782. {
  2783. Result = true;
  2784. if (Recycle)
  2785. {
  2786. WinConfiguration->ConfirmRecycling = false;
  2787. }
  2788. else
  2789. {
  2790. WinConfiguration->ConfirmDeleting = false;
  2791. }
  2792. }
  2793. else
  2794. {
  2795. Result = (Answer == qaOK);
  2796. }
  2797. }
  2798. if (Result)
  2799. {
  2800. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2801. }
  2802. return Result;
  2803. }
  2804. //---------------------------------------------------------------------------
  2805. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2806. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2807. {
  2808. TAutoBatch AutoBatch(this);
  2809. bool Result;
  2810. if (TFileOperationProgressType::IsTransferOperation(Operation))
  2811. {
  2812. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2813. }
  2814. else if (Operation == foRename)
  2815. {
  2816. DebugAssert(DirView(Side)->ItemFocused);
  2817. DirView(Side)->ItemFocused->EditCaption();
  2818. Result = true;
  2819. }
  2820. else if (Operation == foDelete)
  2821. {
  2822. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2823. }
  2824. else if (Operation == foSetProperties)
  2825. {
  2826. DirView(osRemote)->SaveSelectedNames();
  2827. Result = SetProperties(Side, FileList);
  2828. }
  2829. else if (Operation == foCustomCommand)
  2830. {
  2831. DebugAssert(Param);
  2832. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2833. DirView(osRemote)->SaveSelectedNames();
  2834. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2835. CustomCommand(FileList, *Command, NULL);
  2836. Result = true;
  2837. }
  2838. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2839. {
  2840. DebugAssert(!IsSideLocalBrowser(Side));
  2841. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2842. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2843. }
  2844. else if (Operation == foLock)
  2845. {
  2846. DebugAssert(!IsSideLocalBrowser(Side));
  2847. LockFiles(FileList, true);
  2848. Result = true;
  2849. }
  2850. else if (Operation == foUnlock)
  2851. {
  2852. DebugAssert(!IsSideLocalBrowser(Side));
  2853. LockFiles(FileList, false);
  2854. Result = true;
  2855. }
  2856. else
  2857. {
  2858. DebugFail();
  2859. }
  2860. return Result;
  2861. }
  2862. //---------------------------------------------------------------------------
  2863. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2864. {
  2865. if (Side == osCurrent)
  2866. {
  2867. Side = FCurrentSide;
  2868. }
  2869. return Side;
  2870. }
  2871. //---------------------------------------------------------------------------
  2872. TOperationSide TCustomScpExplorerForm::GetOtherSide(TOperationSide Side)
  2873. {
  2874. TOperationSide Result;
  2875. switch (GetSide(Side))
  2876. {
  2877. case osLocal:
  2878. Result = osOther;
  2879. break;
  2880. case osOther:
  2881. Result = osLocal;
  2882. break;
  2883. default:
  2884. DebugFail();
  2885. Abort();
  2886. }
  2887. return Result;
  2888. }
  2889. //---------------------------------------------------------------------------
  2890. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2891. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2892. {
  2893. Side = GetSide(Side);
  2894. bool FullPath = IsSideLocalBrowser(Side);
  2895. TCustomDirView * ADirView = DirView(Side);
  2896. std::unique_ptr<TStringList> FileList(new TStringList());
  2897. ADirView->CreateFileList(OnFocused, FullPath, FileList.get());
  2898. bool ReloadProperties =
  2899. !IsSideLocalBrowser(Side) && (Operation == foSetProperties) &&
  2900. DebugAlwaysTrue(HasActiveTerminal()) && Terminal->IsCapable[fcLoadingAdditionalProperties];
  2901. bool Result = ExecuteFileOperation(Operation, Side, FileList.get(), NoConfirmation, Param);
  2902. if (Result && ReloadProperties)
  2903. {
  2904. std::unique_ptr<TStringList> FileList2(new TStringList());
  2905. FileList->CaseSensitive = true;
  2906. FileList->Sort();
  2907. for (int Index = 0; Index < ADirView->Items->Count; Index++)
  2908. {
  2909. TListItem * Item = ADirView->Items->Item[Index];
  2910. UnicodeString FileName = ADirView->ItemFileName(Item);
  2911. int Index2;
  2912. if (FileList->Find(FileName, Index2))
  2913. {
  2914. FileList2->AddObject(FileName, ADirView->ItemData(Item));
  2915. }
  2916. }
  2917. LoadFilesProperties(FileList2.get());
  2918. }
  2919. return Result;
  2920. }
  2921. //---------------------------------------------------------------------------
  2922. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2923. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2924. bool NoConfirmation, void * Param)
  2925. {
  2926. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2927. {
  2928. if (TFileOperationProgressType::IsTransferOperation(Operation))
  2929. {
  2930. DebugAssert(!IsLocalBrowserMode());
  2931. if (GetSide(Side) == osLocal)
  2932. {
  2933. Configuration->Usage->Inc(L"UploadsCommand");
  2934. }
  2935. else
  2936. {
  2937. Configuration->Usage->Inc(L"DownloadsCommand");
  2938. }
  2939. }
  2940. }
  2941. }
  2942. //---------------------------------------------------------------------------
  2943. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2944. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2945. {
  2946. TTransferOperationParam Param;
  2947. if ((WinConfiguration->Interface != ifCommander) ||
  2948. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2949. {
  2950. Flags &= ~cocShortCutHint;
  2951. }
  2952. TCustomDirView * DView = DirView(Side);
  2953. Param.Options =
  2954. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2955. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2956. if (FLAGSET(Flags, cocQueue))
  2957. {
  2958. Param.Queue = asOn;
  2959. }
  2960. else if (FLAGSET(Flags, cocNonQueue))
  2961. {
  2962. Param.Queue = asOff;
  2963. }
  2964. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2965. }
  2966. //---------------------------------------------------------------------------
  2967. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2968. {
  2969. int Count = ErrorList->Count;
  2970. try
  2971. {
  2972. if (ErrorList->Count)
  2973. {
  2974. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2975. if (MessageDialog(Message, qtError,
  2976. qaOK | qaCancel, HELP_NONE) == qaOK)
  2977. {
  2978. unsigned int Answer;
  2979. int Index = 0;
  2980. do
  2981. {
  2982. DebugAssert(Index >= 0 && Index < Count);
  2983. TQueryButtonAlias Aliases[2];
  2984. Aliases[0].Button = qaYes;
  2985. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2986. Aliases[1].Button = qaNo;
  2987. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2988. TMessageParams Params;
  2989. Params.Aliases = Aliases;
  2990. Params.AliasesCount = LENOF(Aliases);
  2991. int No = Index + 1;
  2992. UnicodeString Message = ErrorList->Strings[Index];
  2993. UnicodeString AMainInstructions;
  2994. UnicodeString Details;
  2995. if (ExtractMainInstructions(Message, AMainInstructions))
  2996. {
  2997. Details = Message;
  2998. Message = AMainInstructions;
  2999. }
  3000. Message = MainInstructions(FMTLOAD(ERROR_LIST_NUMBER, (No, Count, Message))) + Details;
  3001. Answer = MoreMessageDialog(
  3002. Message,
  3003. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  3004. (Index ? qaYes : 0) | (Index < Count - 1 ? qaNo : 0) |
  3005. qaOK, HELP_NONE, &Params);
  3006. if (Answer == qaNo)
  3007. {
  3008. Index++;
  3009. }
  3010. if (Answer == qaYes)
  3011. {
  3012. Index--;
  3013. }
  3014. }
  3015. while (Answer != qaOK);
  3016. }
  3017. }
  3018. }
  3019. __finally
  3020. {
  3021. TStrings * List = ErrorList;
  3022. ErrorList = NULL;
  3023. for (int i = 0; i < Count; i++)
  3024. {
  3025. delete List->Objects[i];
  3026. }
  3027. delete List;
  3028. }
  3029. }
  3030. //---------------------------------------------------------------------------
  3031. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  3032. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  3033. {
  3034. // needed for checking filemasks, as there's no directory object
  3035. // associated with the file object
  3036. File->FullFileName = FullFileName;
  3037. TFileMasks::TParams MaskParams;
  3038. MaskParams.Size = File->Size;
  3039. MaskParams.Modification = File->Modification;
  3040. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  3041. }
  3042. //---------------------------------------------------------------------------
  3043. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  3044. {
  3045. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3046. Side = GetSide(Side);
  3047. TCustomDirView * DView = DirView(Side);
  3048. TListItem * FocusedItem = DView->ItemFocused;
  3049. UnicodeString Name;
  3050. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  3051. {
  3052. Name = DView->ItemFileName(FocusedItem);
  3053. }
  3054. else
  3055. {
  3056. Name = LoadStr(NEW_FILE);
  3057. }
  3058. UnicodeString Names = Name;
  3059. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  3060. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  3061. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  3062. {
  3063. while (!Names.IsEmpty())
  3064. {
  3065. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  3066. CustomWinConfiguration->History[L"EditFile"] = History.get();
  3067. UnicodeString TargetFileName;
  3068. UnicodeString LocalFileName;
  3069. UnicodeString RootTempDir;
  3070. UnicodeString TempDir;
  3071. UnicodeString RemoteDirectory;
  3072. bool ExistingFile = false;
  3073. if (!IsSideLocalBrowser(Side))
  3074. {
  3075. Name = AbsolutePath(Terminal->CurrentDirectory, Name);
  3076. std::unique_ptr<TRemoteFile> File(Terminal->TryReadFile(Name));
  3077. if ((File.get() != NULL) &&
  3078. !File->IsDirectory)
  3079. {
  3080. ExecuteRemoteFile(Name, File.get(), efDefaultEditor);
  3081. ExistingFile = true;
  3082. }
  3083. File.reset(NULL);
  3084. if (!ExistingFile)
  3085. {
  3086. RemoteDirectory = UnixExtractFilePath(Name);
  3087. TemporaryDirectoryForRemoteFiles(
  3088. RemoteDirectory, GUIConfiguration->CurrentCopyParam, false, TempDir, RootTempDir);
  3089. TargetFileName = UnixExtractFileName(Name);
  3090. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3091. LocalFileName = TempDir +
  3092. // We probably do not want to trim the VMS version here
  3093. Terminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  3094. }
  3095. }
  3096. else
  3097. {
  3098. if (ExtractFilePath(Name).IsEmpty())
  3099. {
  3100. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  3101. }
  3102. else
  3103. {
  3104. LocalFileName = ExpandFileName(Name);
  3105. }
  3106. TargetFileName = ExtractFileName(Name);
  3107. }
  3108. if (!ExistingFile)
  3109. {
  3110. bool NewFile = !FileExists(ApiPath(LocalFileName));
  3111. if (NewFile)
  3112. {
  3113. int File = FileCreate(ApiPath(LocalFileName));
  3114. if (File < 0)
  3115. {
  3116. if (!RootTempDir.IsEmpty())
  3117. {
  3118. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir));
  3119. }
  3120. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  3121. }
  3122. else
  3123. {
  3124. FileClose(File);
  3125. }
  3126. }
  3127. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  3128. const TEditorData * ExternalEditor = NULL;
  3129. TFileMasks::TParams MaskParams; // size not known
  3130. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  3131. false, MaskParams);
  3132. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  3133. ExternalEditor, RootTempDir, RemoteDirectory, NewFile, TDateTime());
  3134. }
  3135. }
  3136. }
  3137. }
  3138. //---------------------------------------------------------------------------
  3139. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  3140. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  3141. {
  3142. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3143. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3144. DebugAssert(ExecuteFileBy != efDefaultEditor);
  3145. return
  3146. ((ExecuteFileBy == efInternalEditor)) ||
  3147. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  3148. }
  3149. //---------------------------------------------------------------------------
  3150. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  3151. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  3152. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  3153. UnicodeString RemoteDirectory, bool NewFile, const TDateTime & SourceTimestamp)
  3154. {
  3155. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3156. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3157. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3158. DebugAssert(ExecuteFileBy != efDefaultEditor);
  3159. Side = GetSide(Side);
  3160. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  3161. if (!IsSideLocalBrowser(Side))
  3162. {
  3163. Data->Terminal = Terminal;
  3164. Data->SessionData = CloneCurrentSessionData();
  3165. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  3166. Data->RemoteDirectory = RemoteDirectory;
  3167. Data->SessionName = Terminal->SessionData->SessionName;
  3168. Data->LocalRootDirectory = LocalRootDirectory;
  3169. Data->OriginalFileName = OriginalFileName;
  3170. Data->Command = L""; // will be changed later for external editor
  3171. // Empty SourceTimestamp indicates that checking was disabled when the file was opened
  3172. if (WinConfiguration->EditorCheckNotModified)
  3173. {
  3174. Data->SourceTimestamp = SourceTimestamp;
  3175. }
  3176. }
  3177. if (ExecuteFileBy == efInternalEditor)
  3178. {
  3179. if (!IsSideLocalBrowser(Side))
  3180. {
  3181. UnicodeString RemotePath = UnixCombinePaths(RemoteDirectory, OriginalFileName);
  3182. UnicodeString Caption = RemotePath + TitleSeparator + Terminal->SessionData->SessionName;
  3183. TForm * Editor;
  3184. try
  3185. {
  3186. Editor =
  3187. ShowEditorForm(
  3188. FileName, this,
  3189. FEditorManager->FileChanged, FEditorManager->FileReload, FEditorManager->FileClosed,
  3190. SaveAllInternalEditors, AnyInternalEditorModified,
  3191. Caption, StandaloneOperation, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  3192. }
  3193. catch(...)
  3194. {
  3195. if (!LocalRootDirectory.IsEmpty())
  3196. {
  3197. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory));
  3198. }
  3199. throw;
  3200. }
  3201. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  3202. AppLogFmt(L"Opened internal editor with \"%s\"", (FileName));
  3203. }
  3204. else
  3205. {
  3206. DebugAssert(!StandaloneOperation);
  3207. TForm * Editor =
  3208. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  3209. SaveAllInternalEditors, AnyInternalEditorModified,
  3210. L"", false, SessionColor, -1, NewFile);
  3211. FLocalEditors->Add(Editor);
  3212. }
  3213. }
  3214. else
  3215. {
  3216. HANDLE Process;
  3217. if (ExecuteFileBy == efExternalEditor)
  3218. {
  3219. UnicodeString Program, Params, Dir;
  3220. Data->Command = ExternalEditor->ExternalEditor;
  3221. ReformatFileNameCommand(Data->Command);
  3222. SplitCommand(Data->Command, Program, Params, Dir);
  3223. Params = ExpandFileNameCommand(Params, FileName);
  3224. Program = ExpandEnvironmentVariables(Program);
  3225. if (!ExecuteShell(Program, Params, Process))
  3226. {
  3227. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3228. }
  3229. }
  3230. else
  3231. {
  3232. DebugAssert(!IsSideLocalBrowser(Side));
  3233. if (!ExecuteShell(FileName, L"", Process))
  3234. {
  3235. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3236. }
  3237. }
  3238. if (IsSideLocalBrowser(Side) ||
  3239. ((ExecuteFileBy == efShell) &&
  3240. !WinConfiguration->Editor.SDIShellEditor) ||
  3241. ((ExecuteFileBy == efExternalEditor) &&
  3242. !ExternalEditor->SDIExternalEditor))
  3243. {
  3244. // no need for handle
  3245. if (Process != NULL)
  3246. {
  3247. DebugCheck(CloseHandle(Process));
  3248. }
  3249. Process = INVALID_HANDLE_VALUE;
  3250. }
  3251. else
  3252. {
  3253. if (Process == NULL)
  3254. {
  3255. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3256. }
  3257. }
  3258. if (!IsSideLocalBrowser(Side))
  3259. {
  3260. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3261. AppLogFmt(L"Opened external editor with remote file \"%s\".", (FileName));
  3262. }
  3263. }
  3264. }
  3265. //---------------------------------------------------------------------------
  3266. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3267. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3268. void * /*Arg*/)
  3269. {
  3270. if (Token != NULL)
  3271. {
  3272. EditorFormFileSave(static_cast<TForm *>(Token));
  3273. }
  3274. }
  3275. //---------------------------------------------------------------------------
  3276. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3277. {
  3278. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3279. {
  3280. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3281. }
  3282. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3283. }
  3284. //---------------------------------------------------------------------------
  3285. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3286. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3287. void * Arg)
  3288. {
  3289. if ((Token != NULL) &&
  3290. IsEditorFormModified(static_cast<TForm *>(Token)))
  3291. {
  3292. *static_cast<bool *>(Arg) = true;
  3293. }
  3294. }
  3295. //---------------------------------------------------------------------------
  3296. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3297. TObject * /*Sender*/, bool & Modified)
  3298. {
  3299. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3300. {
  3301. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3302. {
  3303. Modified = true;
  3304. }
  3305. }
  3306. if (!Modified)
  3307. {
  3308. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3309. }
  3310. }
  3311. //---------------------------------------------------------------------------
  3312. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3313. {
  3314. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3315. }
  3316. //---------------------------------------------------------------------------
  3317. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3318. const UnicodeString & RemoteDirectory, const TCopyParamType & CopyParam, bool Simple,
  3319. UnicodeString & Result, UnicodeString & RootDirectory)
  3320. {
  3321. if (!WinConfiguration->TemporaryDirectoryDeterministic || Simple)
  3322. {
  3323. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3324. Result = RootDirectory;
  3325. }
  3326. else
  3327. {
  3328. RootDirectory = L"";
  3329. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3330. Result = IncludeTrailingBackslash(Result);
  3331. }
  3332. if (WinConfiguration->TemporaryDirectoryAppendSession && !Simple)
  3333. {
  3334. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3335. }
  3336. if (WinConfiguration->TemporaryDirectoryAppendPath && !Simple)
  3337. {
  3338. UnicodeString ARemoteDirectory = RemoteDirectory;
  3339. if (!ARemoteDirectory.IsEmpty() && (ARemoteDirectory[1] == L'/'))
  3340. {
  3341. ARemoteDirectory.Delete(1, 1);
  3342. }
  3343. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(ARemoteDirectory)));
  3344. }
  3345. if (!ForceDirectories(ApiPath(Result)))
  3346. {
  3347. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3348. }
  3349. }
  3350. //---------------------------------------------------------------------------
  3351. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3352. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3353. bool GetTargetNames, bool AutoOperation, bool SimpleTempDir)
  3354. {
  3355. DebugAssert(!IsLocalBrowserMode());
  3356. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3357. if (ForceText)
  3358. {
  3359. CopyParam.TransferMode = tmAscii;
  3360. }
  3361. TemporaryFileCopyParam(CopyParam);
  3362. if (TempDir.IsEmpty())
  3363. {
  3364. TemporaryDirectoryForRemoteFiles(Terminal->CurrentDirectory, CopyParam, SimpleTempDir, TempDir, RootTempDir);
  3365. }
  3366. DebugAssert(!FAutoOperation);
  3367. FAutoOperation = AutoOperation;
  3368. FMoveToQueue = false;
  3369. Terminal->ExceptionOnFail = true;
  3370. try
  3371. {
  3372. try
  3373. {
  3374. // turn off confirmations, as for MDI editors we may possibly download
  3375. // the same file over
  3376. Terminal->CopyToLocal(
  3377. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3378. if (GetTargetNames)
  3379. {
  3380. for (int i = 0; i < FileList->Count; i++)
  3381. {
  3382. FileList->Strings[i] =
  3383. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3384. }
  3385. }
  3386. }
  3387. catch(...)
  3388. {
  3389. if (!RootTempDir.IsEmpty())
  3390. {
  3391. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir));
  3392. }
  3393. throw;
  3394. }
  3395. }
  3396. __finally
  3397. {
  3398. FAutoOperation = false;
  3399. Terminal->ExceptionOnFail = false;
  3400. }
  3401. }
  3402. //---------------------------------------------------------------------------
  3403. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3404. {
  3405. // Do not waste time checking for default editor list the next time,
  3406. // or testing if default editor is not notepad.
  3407. bool TryNextTime = false;
  3408. UnicodeString UsageState;
  3409. if (!WinConfiguration->EditorList->IsDefaultList())
  3410. {
  3411. UsageState = "H";
  3412. }
  3413. else
  3414. {
  3415. UnicodeString Executable;
  3416. UnicodeString ExecutableDescription;
  3417. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3418. {
  3419. UnicodeString Message =
  3420. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3421. unsigned int Answer =
  3422. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3423. if (Answer != qaOK)
  3424. {
  3425. UsageState = "R";
  3426. }
  3427. else
  3428. {
  3429. UsageState = "A";
  3430. TEditorData EditorData;
  3431. EditorData.Editor = edExternal;
  3432. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3433. EditorData.ExternalEditorOptionsAutodetect();
  3434. TEditorList EditorList;
  3435. EditorList = *WinConfiguration->EditorList;
  3436. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3437. WinConfiguration->EditorList = &EditorList;
  3438. }
  3439. }
  3440. }
  3441. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3442. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3443. }
  3444. //---------------------------------------------------------------------------
  3445. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3446. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3447. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3448. {
  3449. if (ExecuteFileBy == efDefaultEditor)
  3450. {
  3451. if (!WinConfiguration->OfferedEditorAutoConfig)
  3452. {
  3453. EditorAutoConfig();
  3454. }
  3455. const TEditorPreferences * Editor =
  3456. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3457. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3458. {
  3459. ExecuteFileBy = efInternalEditor;
  3460. ExternalEditor = NULL;
  3461. }
  3462. else if (Editor->Data->Editor == edOpen)
  3463. {
  3464. ExecuteFileBy = efShell;
  3465. ExternalEditor = NULL;
  3466. }
  3467. else
  3468. {
  3469. ExecuteFileBy = efExternalEditor;
  3470. ExternalEditor = Editor->Data;
  3471. }
  3472. }
  3473. }
  3474. //---------------------------------------------------------------------------
  3475. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3476. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3477. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3478. {
  3479. UnicodeString OriginalFileName;
  3480. UnicodeString LocalRootDirectory;
  3481. UnicodeString RemoteDirectory;
  3482. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3483. IsSideLocalBrowser(Side), MaskParams);
  3484. UnicodeString Counter;
  3485. UnicodeString LocalFileName;
  3486. bool Handled = false;
  3487. if (!IsSideLocalBrowser(Side))
  3488. {
  3489. // We need to trim VMS version here, so that we use name without version
  3490. // when uploading back to create a new version of the file
  3491. OriginalFileName = Terminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3492. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3493. TObject * Token = NULL;
  3494. UnicodeString LocalDirectory;
  3495. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3496. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3497. LocalDirectory))
  3498. {
  3499. if (Token != NULL)
  3500. {
  3501. TForm * Form = dynamic_cast<TForm *>(Token);
  3502. if (Form->WindowState == wsMinimized)
  3503. {
  3504. ShowWindow(Form->Handle, SW_RESTORE);
  3505. }
  3506. else
  3507. {
  3508. Form->SetFocus();
  3509. }
  3510. Handled = true;
  3511. }
  3512. else
  3513. {
  3514. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3515. }
  3516. }
  3517. if (!Handled)
  3518. {
  3519. TStringList * FileList1 = new TStringList();
  3520. try
  3521. {
  3522. FileList1->AddObject(FullFileName, Object);
  3523. TemporarilyDownloadFiles(FileList1,
  3524. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3525. LocalRootDirectory, LocalDirectory, true, true, false);
  3526. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3527. }
  3528. __finally
  3529. {
  3530. delete FileList1;
  3531. }
  3532. switch (ExecuteFileBy)
  3533. {
  3534. case efShell:
  3535. Counter = "RemoteFilesExecuted";
  3536. break;
  3537. case efInternalEditor:
  3538. Counter = "RemoteFilesOpenedInInternalEditor";
  3539. break;
  3540. case efExternalEditor:
  3541. Counter = "RemoteFilesOpenedInExternalEditor";
  3542. break;
  3543. default:
  3544. DebugFail();
  3545. }
  3546. }
  3547. }
  3548. else
  3549. {
  3550. LocalFileName = FullFileName;
  3551. OriginalFileName = ExtractFileName(FullFileName);
  3552. switch (ExecuteFileBy)
  3553. {
  3554. case efShell:
  3555. Counter = "LocalFilesExecuted";
  3556. break;
  3557. case efInternalEditor:
  3558. Counter = "LocalFilesOpenedInInternalEditor";
  3559. break;
  3560. case efExternalEditor:
  3561. Counter = "LocalFilesOpenedInExternalEditor";
  3562. break;
  3563. default:
  3564. DebugFail();
  3565. }
  3566. }
  3567. if (!Handled)
  3568. {
  3569. Configuration->Usage->Inc(Counter);
  3570. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3571. ExternalEditor, LocalRootDirectory, RemoteDirectory, false, MaskParams.Modification);
  3572. }
  3573. }
  3574. //---------------------------------------------------------------------------
  3575. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3576. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3577. bool AllSelected, bool OnFocused)
  3578. {
  3579. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3580. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3581. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3582. Side = GetSide(Side);
  3583. TCustomDirView * DView = DirView(Side);
  3584. TStrings * FileList =
  3585. AllSelected ?
  3586. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3587. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3588. try
  3589. {
  3590. DebugAssert(AllSelected || (FileList->Count == 1));
  3591. for (int i = 0; i < FileList->Count; i++)
  3592. {
  3593. UnicodeString ListFileName = FileList->Strings[i];
  3594. UnicodeString FileNameOnly =
  3595. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3596. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3597. if (!DView->ItemIsDirectory(Item))
  3598. {
  3599. UnicodeString FullFileName;
  3600. if (!IsSideLocalBrowser(Side))
  3601. {
  3602. FullFileName = DirView(Side)->Path + ListFileName;
  3603. }
  3604. else
  3605. {
  3606. FullFileName = ListFileName;
  3607. }
  3608. TObject * Object = FileList->Objects[i];
  3609. TFileMasks::TParams MaskParams;
  3610. MaskParams.Size = DView->ItemFileSize(Item);
  3611. TDateTimePrecision Precision;
  3612. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3613. std::unique_ptr<TRemoteFile> File;
  3614. if (!IsSideLocalBrowser(Side))
  3615. {
  3616. File.reset(Terminal->TryReadFile(FullFileName));
  3617. if (File.get() != NULL)
  3618. {
  3619. File->FullFileName = FullFileName;
  3620. Object = File.get();
  3621. MaskParams.Size = File->Size;
  3622. MaskParams.Modification = File->Modification;
  3623. }
  3624. }
  3625. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName, Object, MaskParams);
  3626. }
  3627. }
  3628. }
  3629. __finally
  3630. {
  3631. delete FileList;
  3632. }
  3633. }
  3634. //---------------------------------------------------------------------------
  3635. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3636. {
  3637. CopyParam.FileNameCase = ncNoChange;
  3638. CopyParam.PreserveRights = false;
  3639. CopyParam.PreserveReadOnly = false;
  3640. CopyParam.ReplaceInvalidChars = true;
  3641. CopyParam.IncludeFileMask = TFileMasks();
  3642. CopyParam.NewerOnly = false;
  3643. CopyParam.FileMask = L"";
  3644. }
  3645. //---------------------------------------------------------------------------
  3646. bool TCustomScpExplorerForm::EditorCheckNotModified(const TEditedFileData * Data)
  3647. {
  3648. return WinConfiguration->EditorCheckNotModified && (Data->SourceTimestamp != TDateTime());
  3649. }
  3650. //---------------------------------------------------------------------------
  3651. class TEditorUploadQueueItem : public TUploadQueueItem
  3652. {
  3653. public:
  3654. __fastcall TEditorUploadQueueItem(
  3655. TTerminal * Terminal, TStrings * FilesToCopy, const UnicodeString & TargetDir,
  3656. const TCopyParamType * CopyParam, int Params) :
  3657. TUploadQueueItem(Terminal, FilesToCopy, TargetDir, CopyParam, Params, true, false)
  3658. {
  3659. }
  3660. protected:
  3661. virtual void __fastcall DoTransferExecute(TTerminal * Terminal, TParallelOperation * ParallelOperation)
  3662. {
  3663. TUploadQueueItem::DoTransferExecute(Terminal, ParallelOperation);
  3664. TTerminalManager::Instance()->ScpExplorer->EditedFileUploaded(Terminal, CompleteEvent);
  3665. }
  3666. };
  3667. //---------------------------------------------------------------------------
  3668. void TCustomScpExplorerForm::EditedFileUploaded(TTerminal * ATerminal, HANDLE UploadCompleteEvent)
  3669. {
  3670. if (WinConfiguration->EditorCheckNotModified) // optimization
  3671. {
  3672. UnicodeString RemoteFilePath;
  3673. {
  3674. TGuard Guard(FEditorManager->Section);
  3675. TEditedFileData * Data = FEditorManager->FindByUploadCompleteEvent(UploadCompleteEvent);
  3676. if (DebugAlwaysTrue(Data != NULL) &&
  3677. EditorCheckNotModified(Data))
  3678. {
  3679. RemoteFilePath = UnixCombinePaths(Data->RemoteDirectory, Data->OriginalFileName);
  3680. }
  3681. }
  3682. if (!RemoteFilePath.IsEmpty())
  3683. {
  3684. std::unique_ptr<TRemoteFile> File(ATerminal->TryReadFile(RemoteFilePath));
  3685. if (File.get() != NULL)
  3686. {
  3687. TGuard Guard(FEditorManager->Section);
  3688. TEditedFileData * Data = FEditorManager->FindByUploadCompleteEvent(UploadCompleteEvent);
  3689. if (DebugAlwaysTrue(Data != NULL))
  3690. {
  3691. Data->SourceTimestamp = File->Modification;
  3692. AppLogFmt(L"Uploaded edited remote file timestamp: %s", (StandardTimestamp(Data->SourceTimestamp)));
  3693. }
  3694. }
  3695. }
  3696. }
  3697. }
  3698. //---------------------------------------------------------------------------
  3699. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(
  3700. const UnicodeString & FileName, TEditedFileData * Data, HANDLE UploadCompleteEvent, bool & Retry)
  3701. {
  3702. TTerminalManager * Manager = TTerminalManager::Instance();
  3703. if ((Manager->ActiveTerminal == Data->Terminal) &&
  3704. Manager->ScheduleTerminalReconnnect(Data->Terminal))
  3705. {
  3706. AppLog(L"Scheduled session reconnect, will retry the upload later");
  3707. Retry = true;
  3708. }
  3709. else if (!IsActiveTerminal(Data->Terminal))
  3710. {
  3711. if (!NonVisualDataModule->Busy)
  3712. {
  3713. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3714. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3715. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3716. if (Data->Terminal == NULL)
  3717. {
  3718. TManagedTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3719. if (SameSiteTerminal != NULL)
  3720. {
  3721. UnicodeString Message =
  3722. FMTLOAD(EDIT_SESSION_REATTACH,
  3723. (FileNameOnly, Data->SessionName, FileNameOnly));
  3724. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3725. {
  3726. Data->Terminal = SameSiteTerminal;
  3727. Data->SessionName = SameSiteTerminal->SessionData->SessionName;
  3728. // We might also overwrite session data
  3729. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3730. }
  3731. else
  3732. {
  3733. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3734. Abort();
  3735. }
  3736. }
  3737. }
  3738. // Foreground session should reconnect itself (except for those disconnected explicitly by the user)
  3739. else if (DebugAlwaysTrue(Terminal->Disconnected || (Terminal != Data->Terminal)))
  3740. {
  3741. UnicodeString Message =
  3742. MainInstructions(
  3743. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3744. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3745. {
  3746. if (Terminal->Disconnected)
  3747. {
  3748. Manager->ActiveSession = Terminal;
  3749. ReconnectSession();
  3750. // Was it reconnected? (if not, Data->Terminal should be nulled now)
  3751. if (!IsActiveTerminal(Data->Terminal) || (Terminal != Data->Terminal))
  3752. {
  3753. Abort();
  3754. }
  3755. }
  3756. else
  3757. {
  3758. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3759. }
  3760. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3761. }
  3762. else
  3763. {
  3764. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3765. Abort();
  3766. }
  3767. }
  3768. }
  3769. if (!IsActiveTerminal(Data->Terminal))
  3770. {
  3771. Configuration->Usage->Inc(L"EditInactiveSession");
  3772. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3773. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3774. (ExtractFileName(FileName), Data->SessionName)));
  3775. }
  3776. }
  3777. if (!Retry && EditorCheckNotModified(Data))
  3778. {
  3779. if (NonVisualDataModule->Busy)
  3780. {
  3781. Retry = true;
  3782. }
  3783. else
  3784. {
  3785. UnicodeString RemoteFilePath = UnixCombinePaths(Data->RemoteDirectory, Data->OriginalFileName);
  3786. std::unique_ptr<TRemoteFile> File(Terminal->TryReadFile(RemoteFilePath));
  3787. if (File.get() != NULL)
  3788. {
  3789. AppLogFmt(L"Edited remote file timestamp: %s, Original timestamp: %s", (StandardTimestamp(File->Modification), StandardTimestamp(Data->SourceTimestamp)));
  3790. if (File->Modification != Data->SourceTimestamp)
  3791. {
  3792. UnicodeString Message = MainInstructions(LoadStr(EDIT_CHANGED_EXTERNALLY));
  3793. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) != qaOK)
  3794. {
  3795. Abort();
  3796. }
  3797. }
  3798. }
  3799. }
  3800. }
  3801. if (!Retry)
  3802. {
  3803. TStrings * FileList = new TStringList();
  3804. try
  3805. {
  3806. FileList->Add(FileName);
  3807. // Consider using the same settings (preset) as when the file was downloaded.
  3808. // More over this does not reflect the actual session that will do the upload.
  3809. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3810. TemporaryFileCopyParam(CopyParam);
  3811. if (Data->ForceText)
  3812. {
  3813. CopyParam.TransferMode = tmAscii;
  3814. }
  3815. // so i do not need to worry if masking algorithm works in all cases
  3816. // ("" means "copy file name", no masking is actually done)
  3817. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3818. {
  3819. CopyParam.FileMask = L"";
  3820. }
  3821. else
  3822. {
  3823. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3824. }
  3825. int Params = cpNoConfirmation | cpTemporary;
  3826. if (Data->Terminal->IsCapable[fcBackgroundTransfers])
  3827. {
  3828. TTerminalQueue * AQueue = Manager->FindQueueForTerminal(Data->Terminal);
  3829. TQueueItem * QueueItem =
  3830. new TEditorUploadQueueItem(Data->Terminal, FileList, Data->RemoteDirectory, &CopyParam, Params);
  3831. QueueItem->CompleteEvent = UploadCompleteEvent;
  3832. AddQueueItem(AQueue, QueueItem, Data->Terminal);
  3833. }
  3834. else
  3835. {
  3836. if (NonVisualDataModule->Busy)
  3837. {
  3838. Retry = true;
  3839. }
  3840. else
  3841. {
  3842. FMoveToQueue = false;
  3843. Data->Terminal->CopyToRemote(FileList, Data->RemoteDirectory, &CopyParam, Params, NULL);
  3844. SetEvent(UploadCompleteEvent);
  3845. }
  3846. }
  3847. }
  3848. __finally
  3849. {
  3850. delete FileList;
  3851. }
  3852. }
  3853. }
  3854. //---------------------------------------------------------------------------
  3855. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3856. const UnicodeString & FileName, TEditedFileData * Data)
  3857. {
  3858. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3859. DebugAssert(!NonVisualDataModule->Busy);
  3860. if (!IsActiveTerminal(Data->Terminal))
  3861. {
  3862. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3863. (ExtractFileName(FileName), Data->SessionName)));
  3864. }
  3865. TManagedTerminal * PrevSession = TTerminalManager::Instance()->ActiveSession;
  3866. TTerminalManager::Instance()->ActiveSession = Data->Terminal;
  3867. NonVisualDataModule->StartBusy();
  3868. try
  3869. {
  3870. std::unique_ptr<TRemoteFile> File;
  3871. UnicodeString RemoteFileName =
  3872. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3873. Terminal->ExceptionOnFail = true;
  3874. try
  3875. {
  3876. File.reset(Terminal->ReadFile(RemoteFileName));
  3877. if (!File->HaveFullFileName)
  3878. {
  3879. File->FullFileName = RemoteFileName;
  3880. }
  3881. }
  3882. __finally
  3883. {
  3884. Terminal->ExceptionOnFail = false;
  3885. }
  3886. std::unique_ptr<TStrings> FileList(new TStringList());
  3887. FileList->AddObject(RemoteFileName, File.get());
  3888. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3889. UnicodeString TempDir = ExtractFilePath(FileName);
  3890. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir, TempDir, true, true, false);
  3891. if (EditorCheckNotModified(Data))
  3892. {
  3893. Data->SourceTimestamp = File->Modification;
  3894. }
  3895. // sanity check, the target file name should be still the same
  3896. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3897. }
  3898. __finally
  3899. {
  3900. NonVisualDataModule->EndBusy();
  3901. // it actually may not exist anymore...
  3902. TTerminalManager::Instance()->ActiveSession = PrevSession;
  3903. }
  3904. }
  3905. //---------------------------------------------------------------------------
  3906. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3907. const TEditedFileData * Data, bool & KeepOpen)
  3908. {
  3909. // Command is set for external editors only (not for "shell" open).
  3910. if (!Data->Command.IsEmpty())
  3911. {
  3912. bool AnyFound = false;
  3913. bool AnyMDI = false;
  3914. bool AnyNonMDI = false;
  3915. bool AnyDetect = false;
  3916. TEditorList * EditorList = new TEditorList();
  3917. try
  3918. {
  3919. *EditorList = *WinConfiguration->EditorList;
  3920. for (int i = 0; i < EditorList->Count; i++)
  3921. {
  3922. const TEditorPreferences * Editor = EditorList->Editors[i];
  3923. if ((Editor->Data->Editor == edExternal) &&
  3924. (Editor->Data->ExternalEditor == Data->Command))
  3925. {
  3926. AnyFound = true;
  3927. if (Editor->Data->SDIExternalEditor)
  3928. {
  3929. AnyNonMDI = true;
  3930. if (Editor->Data->DetectMDIExternalEditor)
  3931. {
  3932. AnyDetect = true;
  3933. }
  3934. }
  3935. else
  3936. {
  3937. AnyMDI = true;
  3938. }
  3939. }
  3940. }
  3941. bool EnableMDI = false;
  3942. bool DisableDetect = false;
  3943. if (AnyMDI)
  3944. {
  3945. KeepOpen = true;
  3946. if (AnyNonMDI)
  3947. {
  3948. // there is at least one instance of the editor with MDI support enabled,
  3949. // and one with disabled, enable it for all instances
  3950. EnableMDI = true;
  3951. }
  3952. }
  3953. else if (AnyFound && !AnyDetect)
  3954. {
  3955. // at least once instance found but all have MDI autodetection disabled
  3956. // => close the file (default action)
  3957. }
  3958. else
  3959. {
  3960. // no instance of the editor has MDI support enabled
  3961. TMessageParams Params;
  3962. if (AnyFound)
  3963. {
  3964. // there is at least one instance of the editor
  3965. Params.Params |= mpNeverAskAgainCheck;
  3966. }
  3967. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3968. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3969. switch (Answer)
  3970. {
  3971. case qaNeverAskAgain:
  3972. DisableDetect = true;
  3973. break;
  3974. case qaNo:
  3975. EnableMDI = true;
  3976. KeepOpen = true;
  3977. break;
  3978. }
  3979. }
  3980. if (AnyFound && (EnableMDI || DisableDetect))
  3981. {
  3982. bool Changed = false;
  3983. for (int i = 0; i < EditorList->Count; i++)
  3984. {
  3985. const TEditorPreferences * Editor = EditorList->Editors[i];
  3986. if ((Editor->Data->Editor == edExternal) &&
  3987. (Editor->Data->ExternalEditor == Data->Command) &&
  3988. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3989. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3990. {
  3991. Changed = true;
  3992. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3993. if (EnableMDI)
  3994. {
  3995. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3996. }
  3997. if (DisableDetect)
  3998. {
  3999. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  4000. }
  4001. EditorList->Change(i, UpdatedEditor);
  4002. }
  4003. }
  4004. if (Changed)
  4005. {
  4006. WinConfiguration->EditorList = EditorList;
  4007. }
  4008. }
  4009. }
  4010. __finally
  4011. {
  4012. delete EditorList;
  4013. }
  4014. }
  4015. else
  4016. {
  4017. // "open" case
  4018. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  4019. qaOK, HELP_APP_EARLY_CLOSED);
  4020. }
  4021. }
  4022. //---------------------------------------------------------------------------
  4023. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  4024. {
  4025. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  4026. }
  4027. //---------------------------------------------------------------------------
  4028. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  4029. {
  4030. SideEnter(osRemote);
  4031. }
  4032. //---------------------------------------------------------------------------
  4033. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  4034. {
  4035. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  4036. SideEnter(osRemote);
  4037. }
  4038. //---------------------------------------------------------------------------
  4039. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  4040. {
  4041. FCurrentSide = Side;
  4042. if (Visible)
  4043. {
  4044. UpdateControls();
  4045. }
  4046. }
  4047. //---------------------------------------------------------------------------
  4048. void __fastcall TCustomScpExplorerForm::FileDeleted(
  4049. TOperationSide Side, const UnicodeString & FileName, bool Success, bool NotCancelled)
  4050. {
  4051. VisualiseOperationFinished(Side, FileName, Success && NotCancelled);
  4052. if (DebugAlwaysTrue(FDeletedFiles != NULL) && Success)
  4053. {
  4054. FDeletedFiles->Add(FileName);
  4055. }
  4056. }
  4057. //---------------------------------------------------------------------------
  4058. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  4059. TStrings * FileList, bool Alternative)
  4060. {
  4061. TCustomDirView * DView = DirView(Side);
  4062. DView->SaveSelection();
  4063. DView->SaveSelectedNames();
  4064. DebugAssert(!FAlternativeDelete);
  4065. FAlternativeDelete = Alternative;
  4066. try
  4067. {
  4068. int Params = FLAGMASK(Alternative, dfAlternative);
  4069. bool Remote = !IsSideLocalBrowser(Side);
  4070. std::unique_ptr<TStringList> DeletedFiles;
  4071. std::unique_ptr<TStrings> PermanentFileList;
  4072. bool AllowMoveToQueue = (Terminal != NULL);
  4073. if (AllowMoveToQueue)
  4074. {
  4075. DeletedFiles.reset(new TStringList());
  4076. DeletedFiles->CaseSensitive = Remote;
  4077. }
  4078. try
  4079. {
  4080. DebugAssert(FDeletedFiles == NULL);
  4081. TValueRestorer<TStrings *> DeletedFilesRestorer(FDeletedFiles, DeletedFiles.get());
  4082. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  4083. if (AllowMoveToQueue)
  4084. {
  4085. FOnFileOperationFinished = FileDeleted;
  4086. }
  4087. FMoveToQueue = false;
  4088. if (Remote)
  4089. {
  4090. DebugAssert(AllowMoveToQueue);
  4091. // Clone the file list as it may refer to current directory files, which get destroyed, when the directory is reloaded after the operation
  4092. PermanentFileList.reset(TRemoteFileList::CloneStrings(FileList));
  4093. DebugAssert(Terminal != NULL);
  4094. Terminal->DeleteFiles(FileList, Params);
  4095. }
  4096. else
  4097. {
  4098. if (AllowMoveToQueue) // optimization)
  4099. {
  4100. PermanentFileList.reset(CloneStrings(FileList));
  4101. }
  4102. if (IsLocalBrowserMode())
  4103. {
  4104. Configuration->Usage->Inc(L"LocalLocalDeletes");
  4105. }
  4106. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide, FCurrentSide);
  4107. try
  4108. {
  4109. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, Params);
  4110. }
  4111. __finally
  4112. {
  4113. ReloadLocalDirectory();
  4114. }
  4115. }
  4116. // Probably not needed for deleting, just for consistency with transfer code
  4117. if (FMoveToQueue)
  4118. {
  4119. Abort();
  4120. }
  4121. }
  4122. catch (EAbort &)
  4123. {
  4124. if (FMoveToQueue && DebugAlwaysTrue(AllowMoveToQueue) && DebugAlwaysTrue(Terminal != NULL))
  4125. {
  4126. FMoveToQueue = false;
  4127. DeletedFiles->Sorted = true;
  4128. for (int Index = 0; Index < PermanentFileList->Count; Index++)
  4129. {
  4130. if (DeletedFiles->IndexOf(PermanentFileList->Strings[Index]) >= 0)
  4131. {
  4132. // We should always be deleting the first item => what can be used to optimize this code, if needed
  4133. DebugAssert(Index == 0);
  4134. PermanentFileList->Delete(Index);
  4135. Index--;
  4136. }
  4137. }
  4138. if (Remote)
  4139. {
  4140. Configuration->Usage->Inc("MovesToBackgroundDelete");
  4141. TQueueItem * QueueItem = new TRemoteDeleteQueueItem(Terminal, PermanentFileList.get(), Params);
  4142. AddQueueItem(Queue, QueueItem, Terminal);
  4143. }
  4144. else
  4145. {
  4146. Configuration->Usage->Inc("MovesToBackgroundDeleteLocal");
  4147. TQueueItem * QueueItem = new TLocalDeleteQueueItem(PermanentFileList.get(), Params);
  4148. AddQueueItem(Queue, QueueItem, Terminal);
  4149. }
  4150. ClearOperationSelection(Side);
  4151. }
  4152. }
  4153. FAlternativeDelete = false;
  4154. }
  4155. catch(...)
  4156. {
  4157. FAlternativeDelete = false;
  4158. DView->DiscardSavedSelection();
  4159. throw;
  4160. }
  4161. DView->RestoreSelection();
  4162. }
  4163. //---------------------------------------------------------------------------
  4164. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  4165. {
  4166. DebugAssert(Terminal);
  4167. DebugAssert(!IsLocalBrowserMode());
  4168. RemoteDirView->SaveSelection();
  4169. RemoteDirView->SaveSelectedNames();
  4170. try
  4171. {
  4172. if (Lock)
  4173. {
  4174. Terminal->LockFiles(FileList);
  4175. }
  4176. else
  4177. {
  4178. Terminal->UnlockFiles(FileList);
  4179. }
  4180. }
  4181. catch(...)
  4182. {
  4183. RemoteDirView->DiscardSavedSelection();
  4184. throw;
  4185. }
  4186. RemoteDirView->RestoreSelection();
  4187. }
  4188. //---------------------------------------------------------------------------
  4189. bool TCustomScpExplorerForm::DoDirectoryExists(void * Session, const UnicodeString & Directory)
  4190. {
  4191. TTerminal * ATerminal = (Session == NULL) ? Terminal : reinterpret_cast<TTerminal *>(Session);
  4192. bool Result =
  4193. IsActiveTerminal(ATerminal) &&
  4194. ATerminal->DirectoryExists(Directory);
  4195. return Result;
  4196. }
  4197. //---------------------------------------------------------------------------
  4198. bool TCustomScpExplorerForm::NeedSecondarySessionForRemoteCopy(TStrings * FileList)
  4199. {
  4200. bool CopyDirsOnSecondarySession = Terminal->IsCapable[fcSecondaryShell];
  4201. return
  4202. !Terminal->IsCapable[fcRemoteCopy] ||
  4203. (CopyDirsOnSecondarySession && TRemoteFileList::AnyDirectory(FileList));
  4204. }
  4205. //---------------------------------------------------------------------------
  4206. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  4207. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  4208. bool NoConfirmation, bool Move)
  4209. {
  4210. DebugAssert(Terminal != NULL);
  4211. DebugAssert(Terminal == TTerminalManager::Instance()->ActiveTerminal);
  4212. DebugAssert(!IsLocalBrowserMode());
  4213. if (Session == NULL)
  4214. {
  4215. Session = Terminal;
  4216. }
  4217. bool TargetConfirmed = false;
  4218. if (Session == Terminal)
  4219. {
  4220. if (RemoteDriveView->DropTarget != NULL)
  4221. {
  4222. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  4223. TargetConfirmed = true;
  4224. }
  4225. else if (RemoteDirView->DropTarget != NULL)
  4226. {
  4227. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  4228. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  4229. TargetConfirmed = true;
  4230. }
  4231. else
  4232. {
  4233. Target = RemoteDirView->Path;
  4234. }
  4235. }
  4236. else
  4237. {
  4238. Target = GetSessionPath(Session, osRemote);
  4239. }
  4240. Target = UnixIncludeTrailingBackslash(Target);
  4241. if (FileList->Count == 1)
  4242. {
  4243. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  4244. }
  4245. else
  4246. {
  4247. FileMask = AnyMask;
  4248. }
  4249. DirectCopy = Terminal->IsCapable[fcRemoteCopy] || Terminal->IsCapable[fcSecondaryShell];
  4250. bool Result = true;
  4251. if (!NoConfirmation)
  4252. {
  4253. bool Multi = (FileList->Count > 1);
  4254. if (Move)
  4255. {
  4256. Result = DoRemoteMoveDialog(Multi, Target, FileMask, DoDirectoryExists);
  4257. }
  4258. else
  4259. {
  4260. std::unique_ptr<TStrings> Sessions(new TStringList);
  4261. std::unique_ptr<TStrings> Directories(new TStringList);
  4262. TStrings * SessionList = TTerminalManager::Instance()->SessionList;
  4263. for (int Index = 0; Index < SessionList->Count; Index++)
  4264. {
  4265. TManagedTerminal * ASession = DebugNotNull(dynamic_cast<TManagedTerminal *>(SessionList->Objects[Index]));
  4266. if (IsActiveTerminal(ASession) && DebugAlwaysTrue(!ASession->LocalBrowser))
  4267. {
  4268. Sessions->AddObject(SessionList->Strings[Index], ASession);
  4269. Directories->Add(GetSessionPath(ASession, osRemote));
  4270. }
  4271. }
  4272. bool AnyDirectory = false;
  4273. bool CopyDirsOnSecondarySession = Terminal->IsCapable[fcSecondaryShell];
  4274. if (CopyDirsOnSecondarySession && !Terminal->CommandSessionOpened) // optimization
  4275. {
  4276. for (int Index = 0; !AnyDirectory && (Index < FileList->Count); Index++)
  4277. {
  4278. AnyDirectory = DebugNotNull(dynamic_cast<TRemoteFile *>(FileList->Objects[Index]))->IsDirectory;
  4279. }
  4280. }
  4281. TDirectRemoteCopy AllowDirectCopy;
  4282. if (Terminal->CommandSessionOpened || !NeedSecondarySessionForRemoteCopy(FileList))
  4283. {
  4284. DebugAssert(DirectCopy);
  4285. AllowDirectCopy = drcAllow;
  4286. }
  4287. else if (Terminal->IsCapable[fcSecondaryShell])
  4288. {
  4289. DebugAssert(DirectCopy);
  4290. AllowDirectCopy = Terminal->IsCapable[fcRemoteCopy] ? drcConfirmCommandSessionDirs : drcConfirmCommandSession;
  4291. }
  4292. else
  4293. {
  4294. DebugAssert(!DirectCopy);
  4295. AllowDirectCopy = drcDisallow;
  4296. }
  4297. void * ASession = Session;
  4298. Result = DoRemoteCopyDialog(
  4299. Sessions.get(), Directories.get(), AllowDirectCopy, Multi, ASession, Target, FileMask, DirectCopy, Terminal,
  4300. DoDirectoryExists, TargetConfirmed);
  4301. Session = static_cast<TManagedTerminal *>(ASession);
  4302. }
  4303. }
  4304. return Result;
  4305. }
  4306. //---------------------------------------------------------------------------
  4307. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  4308. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  4309. {
  4310. DebugAssert(!IsLocalBrowserMode());
  4311. bool DirectCopy;
  4312. UnicodeString Target, FileMask;
  4313. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  4314. if (Result)
  4315. {
  4316. if (!Move && !DirectCopy)
  4317. {
  4318. Configuration->Usage->Inc("RemoteCopyTemp");
  4319. UnicodeString RootTempDir;
  4320. UnicodeString TempDir;
  4321. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  4322. TStrings * TemporaryFilesList = new TStringList();
  4323. try
  4324. {
  4325. TMakeLocalFileListParams MakeFileListParam;
  4326. MakeFileListParam.FileList = TemporaryFilesList;
  4327. MakeFileListParam.FileTimes = NULL;
  4328. MakeFileListParam.IncludeDirs = true;
  4329. MakeFileListParam.Recursive = false;
  4330. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  4331. TTerminalManager::Instance()->ActiveSession = Session;
  4332. if (TemporaryFilesList->Count > 0)
  4333. {
  4334. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4335. CopyParam.FileMask = FileMask;
  4336. DebugAssert(!FAutoOperation);
  4337. FAutoOperation = true;
  4338. FMoveToQueue = false;
  4339. Terminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  4340. }
  4341. }
  4342. __finally
  4343. {
  4344. delete TemporaryFilesList;
  4345. FAutoOperation = false;
  4346. if (!RootTempDir.IsEmpty())
  4347. {
  4348. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir));
  4349. }
  4350. }
  4351. }
  4352. else
  4353. {
  4354. RemoteDirView->SaveSelection();
  4355. RemoteDirView->SaveSelectedNames();
  4356. try
  4357. {
  4358. if (Move)
  4359. {
  4360. Configuration->Usage->Inc("RemoteMove");
  4361. Terminal->MoveFiles(FileList, Target, FileMask, false);
  4362. }
  4363. else
  4364. {
  4365. Configuration->Usage->Inc("RemoteCopyDirect");
  4366. DebugAssert(DirectCopy);
  4367. DebugAssert(Session == Terminal);
  4368. if (!NeedSecondarySessionForRemoteCopy(FileList) ||
  4369. Terminal->CommandSessionOpened ||
  4370. CommandSessionFallback())
  4371. {
  4372. Terminal->CopyFiles(FileList, Target, FileMask, false);
  4373. }
  4374. }
  4375. }
  4376. catch(...)
  4377. {
  4378. RemoteDirView->DiscardSavedSelection();
  4379. throw;
  4380. }
  4381. RemoteDirView->RestoreSelection();
  4382. }
  4383. }
  4384. return Result;
  4385. }
  4386. //---------------------------------------------------------------------------
  4387. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  4388. const UnicodeString & Path, TRemoteProperties & Properties)
  4389. {
  4390. DebugAssert(!IsLocalBrowserMode());
  4391. Properties.Valid = Properties.Valid << vpEncrypt;
  4392. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  4393. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  4394. }
  4395. //---------------------------------------------------------------------------
  4396. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  4397. {
  4398. Side = GetSide(Side);
  4399. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  4400. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  4401. UnicodeString Name = LoadStr(NEW_FOLDER);
  4402. int AllowedChanges =
  4403. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  4404. bool SaveSettings = false;
  4405. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  4406. {
  4407. TWindowLock Lock(this);
  4408. if (!IsSideLocalBrowser(Side))
  4409. {
  4410. if (SaveSettings)
  4411. {
  4412. GUIConfiguration->NewDirectoryProperties = Properties;
  4413. }
  4414. CreateRemoteDirectory(Name, Properties);
  4415. }
  4416. else
  4417. {
  4418. DirView(Side)->CreateDirectory(Name);
  4419. }
  4420. }
  4421. }
  4422. //---------------------------------------------------------------------------
  4423. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  4424. {
  4425. TWindowLock Lock(this);
  4426. DirView(Side)->ExecuteHomeDirectory();
  4427. }
  4428. //---------------------------------------------------------------------------
  4429. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  4430. {
  4431. DoOpenDirectoryDialog(odBrowse, Side);
  4432. }
  4433. //---------------------------------------------------------------------------
  4434. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  4435. {
  4436. TOperationSide BookmarkSide = IsLocalBrowserMode() ? osLocal : Side;
  4437. UnicodeString Path = Bookmark->GetSideDirectory(BookmarkSide);
  4438. bool Result = !Path.IsEmpty();
  4439. if (Result)
  4440. {
  4441. TryOpenDirectory(Side, Path);
  4442. }
  4443. return Result;
  4444. }
  4445. //---------------------------------------------------------------------------
  4446. void __fastcall TCustomScpExplorerForm::CalculateSize(
  4447. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  4448. bool & Close)
  4449. {
  4450. // terminal can be already closed (e.g. dropped connection)
  4451. if (Terminal != NULL)
  4452. {
  4453. try
  4454. {
  4455. TCalculateSizeParams Params;
  4456. Params.Stats = &Stats;
  4457. Terminal->CalculateFilesSize(FileList, Size, Params);
  4458. }
  4459. catch(...)
  4460. {
  4461. if (!Terminal->Active)
  4462. {
  4463. Close = true;
  4464. }
  4465. throw;
  4466. }
  4467. }
  4468. }
  4469. //---------------------------------------------------------------------------
  4470. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4471. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4472. bool & Close)
  4473. {
  4474. if ((Terminal != NULL) && // terminal can be already closed (e.g. dropped connection)
  4475. EnsureCommandSessionFallback(fcCalculatingChecksum))
  4476. {
  4477. Configuration->Usage->Inc(L"ChecksumCalculated");
  4478. try
  4479. {
  4480. Terminal->CalculateFilesChecksum(Alg, FileList, OnCalculatedChecksum);
  4481. }
  4482. catch(...)
  4483. {
  4484. if (!Terminal->Active)
  4485. {
  4486. Close = true;
  4487. }
  4488. throw;
  4489. }
  4490. }
  4491. }
  4492. //---------------------------------------------------------------------------
  4493. void TCustomScpExplorerForm::LoadFilesProperties(TStrings * FileList)
  4494. {
  4495. if (Terminal->LoadFilesProperties(FileList))
  4496. {
  4497. RemoteDirView->Invalidate();
  4498. }
  4499. }
  4500. //---------------------------------------------------------------------------
  4501. bool TCustomScpExplorerForm::CanCalculateChecksum()
  4502. {
  4503. return
  4504. Terminal->IsCapable[fcCalculatingChecksum] ||
  4505. (Terminal->IsCapable[fcSecondaryShell] && !Terminal->IsEncryptingFiles());
  4506. }
  4507. //---------------------------------------------------------------------------
  4508. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4509. {
  4510. bool Result;
  4511. if (!IsSideLocalBrowser(Side))
  4512. {
  4513. TRemoteTokenList * GroupList = NULL;
  4514. TRemoteTokenList * UserList = NULL;
  4515. try
  4516. {
  4517. TRemoteProperties CurrentProperties;
  4518. LoadFilesProperties(FileList);
  4519. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4520. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4521. if (CapableGroupChanging || CapableOwnerChanging)
  4522. {
  4523. if (CapableGroupChanging)
  4524. {
  4525. GroupList = Terminal->Groups->Duplicate();
  4526. }
  4527. if (CapableOwnerChanging)
  4528. {
  4529. UserList = Terminal->Users->Duplicate();
  4530. }
  4531. TRemoteDirectory * Files = Terminal->Files;
  4532. int Count = Files->Count;
  4533. if (Count > 100)
  4534. {
  4535. Count = 100;
  4536. }
  4537. for (int Index = 0; Index < Count; Index++)
  4538. {
  4539. TRemoteFile * File = Files->Files[Index];
  4540. if (CapableGroupChanging)
  4541. {
  4542. GroupList->AddUnique(File->Group);
  4543. }
  4544. if (CapableOwnerChanging)
  4545. {
  4546. UserList->AddUnique(File->Owner);
  4547. }
  4548. }
  4549. // if we haven't collected tokens for all files in current directory,
  4550. // make sure we collect them at least for all selected files.
  4551. // (note that so far the files in FileList has to be from current direcotry)
  4552. if (Count < Files->Count)
  4553. {
  4554. for (int Index = 0; Index < FileList->Count; Index++)
  4555. {
  4556. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4557. if (CapableGroupChanging)
  4558. {
  4559. GroupList->AddUnique(File->Group);
  4560. }
  4561. if (CapableOwnerChanging)
  4562. {
  4563. UserList->AddUnique(File->Owner);
  4564. }
  4565. }
  4566. }
  4567. }
  4568. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4569. bool CapableAclChanging = Terminal->IsCapable[fcAclChangingFiles];
  4570. if (CapableAclChanging && TRemoteFileList::AnyDirectory(FileList))
  4571. {
  4572. CapableAclChanging = false;
  4573. CurrentProperties.Valid = CurrentProperties.Valid >> vpRights;
  4574. }
  4575. int Flags = 0;
  4576. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4577. if (CapableAclChanging) Flags |= cpAcl;
  4578. if (CapableOwnerChanging) Flags |= cpOwner;
  4579. if (CapableGroupChanging) Flags |= cpGroup;
  4580. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4581. if (CanCalculateChecksum())
  4582. {
  4583. CalculateChecksumEvent = CalculateChecksum;
  4584. }
  4585. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4586. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4587. TRemoteProperties NewProperties = CurrentProperties;
  4588. Result =
  4589. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4590. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4591. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4592. CalculateSize, CalculateChecksumEvent);
  4593. if (Result)
  4594. {
  4595. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4596. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4597. }
  4598. }
  4599. __finally
  4600. {
  4601. delete GroupList;
  4602. delete UserList;
  4603. }
  4604. }
  4605. else
  4606. {
  4607. DirView(Side)->DisplayPropertiesMenu();
  4608. Result = true;
  4609. }
  4610. return Result;
  4611. }
  4612. //---------------------------------------------------------------------------
  4613. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4614. {
  4615. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4616. {
  4617. FIgnoreNextDialogChar = Key;
  4618. }
  4619. Key = 0;
  4620. }
  4621. //---------------------------------------------------------------------------
  4622. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4623. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4624. {
  4625. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4626. if (Command != NULL)
  4627. {
  4628. KeyProcessed(Key, Shift);
  4629. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4630. {
  4631. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4632. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4633. false, false, const_cast<TCustomCommandType *>(Command));
  4634. }
  4635. }
  4636. }
  4637. //---------------------------------------------------------------------------
  4638. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4639. {
  4640. if (!NonVisualDataModule->Busy)
  4641. {
  4642. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4643. {
  4644. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4645. }
  4646. if ((Key != 0) && !DirView(osCurrent)->IsEditing())
  4647. {
  4648. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4649. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4650. {
  4651. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4652. // But so far it's not a problem, as it does what we want.
  4653. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4654. if (((Action->ShortCut == KeyShortCut) ||
  4655. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4656. AllowedAction(Action, aaShortCut))
  4657. {
  4658. // Has to be called before the action as the dialog char is already in queue.
  4659. // So when the action consumes message queue, we already need to have the
  4660. // FIgnoreNextDialogChar set
  4661. KeyProcessed(Key, Shift);
  4662. // Reset reference to previous component (when menu/toolbar was clicked).
  4663. // Needed to detect that action was invoked by keyboard shortcut
  4664. // in TNonVisualDataModule::ExplorerActionsExecute
  4665. Action->ActionComponent = NULL;
  4666. Action->Execute();
  4667. return;
  4668. }
  4669. }
  4670. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4671. {
  4672. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4673. {
  4674. KeyProcessed(Key, Shift);
  4675. TTerminalManager::Instance()->ActiveSessionIndex = i;
  4676. return;
  4677. }
  4678. }
  4679. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4680. {
  4681. KeyProcessed(Key, Shift);
  4682. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4683. }
  4684. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4685. if (IsCustomShortCut(CustomShortCut))
  4686. {
  4687. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4688. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4689. if (WinConfiguration->SharedBookmarks != NULL)
  4690. {
  4691. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4692. if ((Bookmark != NULL) &&
  4693. OpenBookmark(FCurrentSide, Bookmark))
  4694. {
  4695. KeyProcessed(Key, Shift);
  4696. }
  4697. }
  4698. }
  4699. }
  4700. }
  4701. TForm::KeyDown(Key, Shift);
  4702. }
  4703. //---------------------------------------------------------------------------
  4704. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4705. {
  4706. bool OpenedTerminal = false;
  4707. UnicodeString ProtocolName;
  4708. UnicodeString ProtocolNameHint;
  4709. UnicodeString SecurityProtocolName;
  4710. UnicodeString DurationHint;
  4711. // See the comment in TScpCommanderForm::UpdateControls()
  4712. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4713. if (ActiveTerminal != NULL)
  4714. {
  4715. // Active is not enough here
  4716. if (ActiveTerminal->Status == ssOpened)
  4717. {
  4718. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4719. const TFileSystemInfo & FileSystemInfo = ActiveTerminal->GetFileSystemInfo();
  4720. if (FileSystemInfo.ProtocolName.IsEmpty())
  4721. {
  4722. ProtocolName = SessionInfo.ProtocolName;
  4723. }
  4724. else
  4725. {
  4726. ProtocolName = FileSystemInfo.ProtocolName;
  4727. }
  4728. ProtocolNameHint = LoadStr(STATUS_PROTOCOL_HINT);
  4729. SecurityProtocolName = SessionInfo.SecurityProtocolName;
  4730. DurationHint = LoadStr(STATUS_DURATION_HINT);
  4731. OpenedTerminal = true;
  4732. }
  4733. else if (ActiveTerminal->Status > ssClosed)
  4734. {
  4735. ProtocolName = LoadStr(STATUS_CONNECTING);
  4736. }
  4737. else
  4738. {
  4739. ProtocolName = LoadStr(STATUS_NOT_CONNECTED2);
  4740. }
  4741. }
  4742. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4743. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4744. TTBXStatusPanel * ProtocolStatusPanel = SessionStatusBar->Panels->Items[Offset + 0];
  4745. ProtocolStatusPanel->ViewPriority = (ActiveTerminal != NULL) ? 100 : 0;
  4746. if (ProtocolStatusPanel->Caption != ProtocolName)
  4747. {
  4748. ProtocolStatusPanel->Caption = ProtocolName;
  4749. std::unique_ptr<TCanvas> Canvas(CreateControlCanvas(SessionStatusBar));
  4750. ProtocolStatusPanel->Size = Canvas->TextWidth(ProtocolName) + ScaleByTextHeight(SessionStatusBar, 32);
  4751. }
  4752. ProtocolStatusPanel->Hint = ProtocolNameHint;
  4753. TTBXStatusPanel * SecurityStatusPanel = SessionStatusBar->Panels->Items[Offset + 1];
  4754. SecurityStatusPanel->ViewPriority = OpenedTerminal ? 98 : 0;
  4755. bool SecurityEnabled = !SecurityProtocolName.IsEmpty();
  4756. SecurityStatusPanel->Enabled = SecurityEnabled;
  4757. UnicodeString SecurityProtocolHint;
  4758. if (SecurityEnabled)
  4759. {
  4760. SecurityProtocolHint = FMTLOAD(STATUS_SECURE, (SecurityProtocolName));
  4761. }
  4762. else
  4763. {
  4764. SecurityProtocolHint = LoadStr(STATUS_INSECURE);
  4765. }
  4766. SecurityStatusPanel->Hint = SecurityProtocolHint;
  4767. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[Offset + 2];
  4768. DurationStatusPanel->ViewPriority = OpenedTerminal ? 99 : 0;
  4769. DurationStatusPanel->Hint = DurationHint;
  4770. UpdateStatusBar();
  4771. }
  4772. //---------------------------------------------------------------------------
  4773. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4774. {
  4775. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4776. DebugAssert(SessionStatusBar != NULL);
  4777. TTBXStatusPanel * NoteStatusPanel = SessionStatusBar->Panels->Items[0];
  4778. if (!FNote.IsEmpty())
  4779. {
  4780. NoteStatusPanel->Caption = FNote;
  4781. }
  4782. else
  4783. {
  4784. UpdateStatusPanelText(NoteStatusPanel);
  4785. }
  4786. NoteStatusPanel->Hint = FNoteHints;
  4787. UnicodeString LoginTime;
  4788. // See the comment in TScpCommanderForm::UpdateControls()
  4789. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4790. // Active is not enough here
  4791. if ((ActiveTerminal != NULL) && (ActiveTerminal->Status == ssOpened))
  4792. {
  4793. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4794. LoginTime = FormatDateTimeSpan(Now() - SessionInfo.LoginTime);
  4795. }
  4796. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1];
  4797. DurationStatusPanel->Caption = LoginTime;
  4798. }
  4799. //---------------------------------------------------------------------------
  4800. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4801. {
  4802. Panel->Caption = L"";
  4803. }
  4804. //---------------------------------------------------------------------------
  4805. void __fastcall TCustomScpExplorerForm::Idle()
  4806. {
  4807. if (FShowing ||
  4808. // Particularly for
  4809. // - Standalone editing
  4810. // - Detecting closed connection and automatically reconnect it while waiting for changes
  4811. // while "keeping remote directory up to date".
  4812. StandaloneOperation)
  4813. {
  4814. FEditorManager->Check();
  4815. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4816. // that needs to know if queue view is visible (and it may be closed after queue update)
  4817. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4818. }
  4819. if (FShowing)
  4820. {
  4821. if (!NonVisualDataModule->Busy &&
  4822. // Menu is opened or drag&drop is going on
  4823. (Mouse->Capture == NULL))
  4824. {
  4825. if (FRefreshRemoteDirectory)
  4826. {
  4827. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4828. {
  4829. Terminal->RefreshDirectory();
  4830. }
  4831. FRefreshRemoteDirectory = false;
  4832. }
  4833. if (FRefreshLocalDirectory)
  4834. {
  4835. ReloadLocalDirectory();
  4836. FRefreshLocalDirectory = false;
  4837. }
  4838. if (WinConfiguration->RefreshRemotePanel)
  4839. {
  4840. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4841. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4842. {
  4843. RemoteDirView->ReloadDirectory();
  4844. }
  4845. }
  4846. }
  4847. // TB2 shows accels on Alt key down, but hides it only after menu modal loop finishes.
  4848. // But if Alt is used to switch apps or for keyboard shortcut, the menu modal loop does not happen and accelerators stay displayed.
  4849. // It's difficult to fix this in TB2, as there's no "up" equivalent to CM_DIALOGKEY, which shows the accels.
  4850. // And the Alt key can be released even when other window or application is active, so handling the key up in explorer window won't do either.
  4851. TTBCustomToolbar * MenuToolbar = DebugNotNull(dynamic_cast<TTBCustomToolbar *>(GetComponent(fcMenu)));
  4852. MenuToolbar->Idle();
  4853. }
  4854. if (FShowing || StandaloneOperation)
  4855. {
  4856. if (FQueueStatusInvalidated)
  4857. {
  4858. UpdateQueueStatus(false);
  4859. }
  4860. RefreshQueueItems();
  4861. }
  4862. if (FShowing)
  4863. {
  4864. UpdateStatusBar();
  4865. }
  4866. if (FClipboardFakeMonitorsPendingReset && !FDownloadingFromClipboard)
  4867. {
  4868. FClipboardFakeMonitorsPendingReset = false;
  4869. FClipboardFakeMonitors.reset(NULL);
  4870. }
  4871. FIgnoreNextDialogChar = 0;
  4872. }
  4873. //---------------------------------------------------------------------------
  4874. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4875. {
  4876. try
  4877. {
  4878. FUserActionTimer->Enabled = false;
  4879. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4880. {
  4881. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4882. {
  4883. FPendingQueueActionItem->ProcessUserAction();
  4884. }
  4885. }
  4886. }
  4887. __finally
  4888. {
  4889. FPendingQueueActionItem = NULL;
  4890. }
  4891. }
  4892. //---------------------------------------------------------------------------
  4893. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4894. {
  4895. if (WinConfiguration->MinimizeToTray)
  4896. {
  4897. UpdateTrayIcon();
  4898. FTrayIcon->Visible = true;
  4899. if (Visible)
  4900. {
  4901. ShowWindow(Handle, SW_HIDE);
  4902. }
  4903. }
  4904. }
  4905. //---------------------------------------------------------------------------
  4906. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4907. {
  4908. // WORKAROUND
  4909. // When restoring maximized window from minimization,
  4910. // rarely some controls do not align properly.
  4911. // Two instances seen (both for Commander):
  4912. // - When restoring, window is temporarily narrower (not maximized),
  4913. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4914. // Once maximized already, top dock shinks back, but the session PageControl,
  4915. // do not align up, leaving space between TopDock and PageControl.
  4916. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4917. for (int Index = 0; Index < ControlCount; Index++)
  4918. {
  4919. RealignControl(Controls[Index]);
  4920. }
  4921. if (FTrayIcon->Visible)
  4922. {
  4923. FTrayIcon->Visible = false;
  4924. if (Visible)
  4925. {
  4926. ShowWindow(Handle, SW_SHOW);
  4927. }
  4928. }
  4929. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4930. {
  4931. FNeedSession = false;
  4932. NonVisualDataModule->StartBusy();
  4933. try
  4934. {
  4935. NeedSession(true);
  4936. }
  4937. __finally
  4938. {
  4939. NonVisualDataModule->EndBusy();
  4940. }
  4941. }
  4942. }
  4943. //---------------------------------------------------------------------------
  4944. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4945. {
  4946. FTrayIcon->Hint = GetMainForm()->Caption;
  4947. }
  4948. //---------------------------------------------------------------------------
  4949. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4950. {
  4951. UpdateTrayIcon();
  4952. }
  4953. //---------------------------------------------------------------------------
  4954. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4955. {
  4956. // workaround
  4957. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4958. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4959. // But WM_ACTIVATEAPP message can be received even when
  4960. // the main window is minimized to the tray and internal editor window is focused
  4961. // (after another application was previously active)
  4962. if (::IsIconic(Handle))
  4963. {
  4964. if (!IsAppIconic())
  4965. {
  4966. SetAppIconic(true);
  4967. }
  4968. }
  4969. ::ApplicationRestore();
  4970. Application->BringToFront();
  4971. }
  4972. //---------------------------------------------------------------------------
  4973. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4974. {
  4975. RestoreApp();
  4976. }
  4977. //---------------------------------------------------------------------------
  4978. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4979. {
  4980. if (OpenInNewWindow())
  4981. {
  4982. ExecuteNewInstance(SessionUrl);
  4983. }
  4984. else
  4985. {
  4986. TTerminalManager::Instance()->NewSession(SessionUrl);
  4987. }
  4988. }
  4989. //---------------------------------------------------------------------------
  4990. void TCustomScpExplorerForm::NewTab(TOperationSide, bool)
  4991. {
  4992. NewSession();
  4993. }
  4994. //---------------------------------------------------------------------------
  4995. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4996. {
  4997. UnicodeString SessionName = StoredSessions->HiddenPrefix + ManagedSession->SessionData->SessionName;
  4998. StoredSessions->NewSession(SessionName, SessionData);
  4999. // modified only, explicit
  5000. StoredSessions->Save(false, true);
  5001. // encode session name because of slashes in hierarchical sessions
  5002. return EncodeUrlString(SessionName);
  5003. }
  5004. //---------------------------------------------------------------------------
  5005. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  5006. {
  5007. // current working directories become defaults here, what is not right
  5008. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5009. return SaveHiddenDuplicateSession(SessionData.get());
  5010. }
  5011. //---------------------------------------------------------------------------
  5012. void __fastcall TCustomScpExplorerForm::DuplicateTab()
  5013. {
  5014. if (OpenInNewWindow())
  5015. {
  5016. ExecuteNewInstance(CreateHiddenDuplicateSession());
  5017. }
  5018. else
  5019. {
  5020. // current working directories become defaults here, what is not right
  5021. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5022. TTerminalManager * Manager = TTerminalManager::Instance();
  5023. TManagedTerminal * ASession = Manager->NewManagedTerminal(SessionData.get());
  5024. DebugAssert(ASession->LocalBrowser == ManagedSession->LocalBrowser);
  5025. // We definitely want these
  5026. ASession->Disconnected = ManagedSession->Disconnected;
  5027. // Not sure about these two
  5028. ASession->Permanent = ManagedSession->Permanent;
  5029. ASession->DisconnectedTemporarily = ManagedSession->DisconnectedTemporarily;
  5030. Manager->ActiveSession = ASession;
  5031. }
  5032. }
  5033. //---------------------------------------------------------------------------
  5034. void __fastcall TCustomScpExplorerForm::RenameTab()
  5035. {
  5036. UnicodeString Name = ManagedSession->SessionData->SessionName;
  5037. if (InputDialog(LoadStr(RENAME_TAB_TITLE), LoadStr(RENAME_TAB_PROMPT), Name, HELP_TAB_RENAME) &&
  5038. // When submitting the default name, do not fix it
  5039. (Name != ManagedSession->SessionData->SessionName))
  5040. {
  5041. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  5042. TSessionData::ValidateName(Name);
  5043. // This is inconsistent with how color (for example) is handled.
  5044. ManagedSession->SessionData->Name = Name;
  5045. UpdateControls();
  5046. // Add/Remove distinguishing paths from sessions of the same name.
  5047. SessionListChanged();
  5048. }
  5049. }
  5050. //---------------------------------------------------------------------------
  5051. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  5052. {
  5053. DebugAssert(Queue != NULL);
  5054. bool Result = Queue->IsEmpty;
  5055. if (!Result)
  5056. {
  5057. SetFocus();
  5058. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  5059. }
  5060. return Result;
  5061. }
  5062. //---------------------------------------------------------------------------
  5063. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  5064. {
  5065. return CanCloseQueue(FQueue);
  5066. }
  5067. //---------------------------------------------------------------------------
  5068. void __fastcall TCustomScpExplorerForm::CloseTab()
  5069. {
  5070. if (CanCloseQueue())
  5071. {
  5072. TTerminalManager::Instance()->FreeActiveTerminal();
  5073. }
  5074. }
  5075. //---------------------------------------------------------------------------
  5076. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  5077. {
  5078. if (CanCloseQueue())
  5079. {
  5080. TTerminalManager::Instance()->DisconnectActiveTerminal();
  5081. }
  5082. }
  5083. //---------------------------------------------------------------------------
  5084. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  5085. {
  5086. DetachTerminal(Terminal);
  5087. RemoteDirView->Terminal = Terminal;
  5088. UpdateRemotePathComboBox(false);
  5089. InitStatusBar();
  5090. UpdateControls();
  5091. }
  5092. //---------------------------------------------------------------------------
  5093. void __fastcall TCustomScpExplorerForm::TerminalConnecting()
  5094. {
  5095. InitStatusBar();
  5096. }
  5097. //---------------------------------------------------------------------------
  5098. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  5099. {
  5100. if (DebugAlwaysTrue(!Terminal->Active))
  5101. {
  5102. TTerminalManager::Instance()->ReconnectActiveTerminal();
  5103. }
  5104. }
  5105. //---------------------------------------------------------------------------
  5106. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  5107. {
  5108. if (OpenInNewWindow())
  5109. {
  5110. // encode session name because of slashes in hierarchical sessions
  5111. ExecuteNewInstance(EncodeUrlString(Data->Name));
  5112. }
  5113. else
  5114. {
  5115. TTerminalManager * Manager = TTerminalManager::Instance();
  5116. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  5117. Manager->ActiveSession = Terminal;
  5118. }
  5119. }
  5120. //---------------------------------------------------------------------------
  5121. void TCustomScpExplorerForm::DoOpenFolderOrWorkspace(
  5122. const UnicodeString & Name, bool ConnectFirstTerminal, bool CheckMaxSessions)
  5123. {
  5124. TTerminalManager * Manager = TTerminalManager::Instance();
  5125. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5126. // This asks for a master password. Maybe we should postpone asking until a connection is actually opened.
  5127. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  5128. if (!CheckMaxSessions || (DataList->Count <= WinConfiguration->MaxSessions))
  5129. {
  5130. TManagedTerminal * FirstSession = Manager->NewSessions(DataList.get());
  5131. // FirstSession can be null, if none of the workspace sites exist anymore
  5132. // or if all workspace sessions are not suported by the interface
  5133. // (when trying to open all local-local workspace in "explorer" interface)
  5134. if (FirstSession != NULL)
  5135. {
  5136. if (!ConnectFirstTerminal)
  5137. {
  5138. FirstSession->Disconnected = true;
  5139. FirstSession->DisconnectedTemporarily = true;
  5140. }
  5141. Manager->ActiveSession = FirstSession;
  5142. }
  5143. }
  5144. }
  5145. //---------------------------------------------------------------------------
  5146. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  5147. {
  5148. if (OpenInNewWindow())
  5149. {
  5150. ExecuteNewInstance(Name);
  5151. }
  5152. else
  5153. {
  5154. DoOpenFolderOrWorkspace(Name, true, false);
  5155. }
  5156. }
  5157. //---------------------------------------------------------------------------
  5158. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  5159. bool &CanClose)
  5160. {
  5161. AppLog(L"Windows close query");
  5162. // See the comment in CloseApp()
  5163. if (NonVisualDataModule->Busy)
  5164. {
  5165. CanClose = false;
  5166. }
  5167. else
  5168. {
  5169. TTerminalManager * Manager = TTerminalManager::Instance();
  5170. int ActiveSessions = 0;
  5171. for (int Index = 0; Index < Manager->Count; Index++)
  5172. {
  5173. if (Manager->Sessions[Index]->Active)
  5174. {
  5175. ActiveSessions++;
  5176. }
  5177. }
  5178. // Confirm, when there's at least one active remote session or
  5179. // when there are multiple (inactive or local) sessions and auto workspace saving is not enabled.
  5180. if (((ActiveSessions > 0) || ((Manager->Count > 1) && !WinConfiguration->AutoSaveWorkspace)) &&
  5181. WinConfiguration->ConfirmClosingSession)
  5182. {
  5183. unsigned int Result;
  5184. TMessageParams Params(mpNeverAskAgainCheck);
  5185. UnicodeString Message;
  5186. int Answers = qaOK | qaCancel;
  5187. // The current session is the only active session
  5188. if ((ActiveSessions == 1) && (Terminal != NULL) && Terminal->Active)
  5189. {
  5190. if (!WinConfiguration->AutoSaveWorkspace)
  5191. {
  5192. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  5193. }
  5194. else
  5195. {
  5196. Message = LoadStr(CLOSE_SESSION);
  5197. }
  5198. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  5199. }
  5200. // Multiple active sessions or one active session, but it's not the current one
  5201. else if (ActiveSessions > 0)
  5202. {
  5203. if (!WinConfiguration->AutoSaveWorkspace)
  5204. {
  5205. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  5206. }
  5207. else
  5208. {
  5209. Message = LoadStr(CLOSE_SESSIONS);
  5210. }
  5211. }
  5212. // Multiple tabs, but all are inactive or local, and saving of worspace is not enabled
  5213. else
  5214. {
  5215. DebugAlwaysTrue(Manager->Count > 1);
  5216. DebugAlwaysTrue(!WinConfiguration->AutoSaveWorkspace);
  5217. Message = LoadStr(CLOSE_WORKSPACE);
  5218. }
  5219. UnicodeString Note;
  5220. if (WinConfiguration->AutoSaveWorkspace)
  5221. {
  5222. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  5223. }
  5224. else
  5225. {
  5226. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  5227. Answers = qaYes | qaNo | qaCancel;
  5228. }
  5229. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  5230. SetFocus();
  5231. Result = MessageDialog(Message, qtConfirmation,
  5232. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  5233. if (Result == qaNeverAskAgain)
  5234. {
  5235. WinConfiguration->ConfirmClosingSession = false;
  5236. }
  5237. if (Result == qaNo)
  5238. {
  5239. CanClose = SaveWorkspace(true);
  5240. // note that the workspace will be saved redundatly again from FormClose
  5241. }
  5242. else
  5243. {
  5244. CanClose =
  5245. (Result == qaOK) ||
  5246. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  5247. (Result == qaNeverAskAgain);
  5248. }
  5249. }
  5250. if (CanClose && HasActiveTerminal())
  5251. {
  5252. CanClose = CanCloseQueue();
  5253. }
  5254. }
  5255. if (CanClose)
  5256. {
  5257. CanClose =
  5258. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  5259. FEditorManager->CloseExternalFilesWithoutProcess();
  5260. if (CanClose)
  5261. {
  5262. while (CanClose && (FLocalEditors->Count > 0))
  5263. {
  5264. int PrevCount = FLocalEditors->Count;
  5265. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  5266. CanClose = (FLocalEditors->Count < PrevCount);
  5267. }
  5268. if (CanClose)
  5269. {
  5270. CanClose = FEditorManager->Empty(true);
  5271. if (!CanClose)
  5272. {
  5273. SetFocus();
  5274. CanClose =
  5275. (MessageDialog(
  5276. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  5277. }
  5278. }
  5279. }
  5280. }
  5281. }
  5282. //---------------------------------------------------------------------------
  5283. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  5284. {
  5285. TForm * Form = dynamic_cast<TForm *>(Sender);
  5286. DebugAssert(Form != NULL);
  5287. Form->Close();
  5288. }
  5289. //---------------------------------------------------------------------------
  5290. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  5291. {
  5292. TForm * Form = dynamic_cast<TForm *>(Sender);
  5293. delete Form;
  5294. }
  5295. //---------------------------------------------------------------------------
  5296. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  5297. {
  5298. while (FLocalEditors->Count > 0)
  5299. {
  5300. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  5301. }
  5302. }
  5303. //---------------------------------------------------------------------------
  5304. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  5305. TObject *Sender)
  5306. {
  5307. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  5308. try
  5309. {
  5310. SetProperties(osRemote, FileList);
  5311. }
  5312. __finally
  5313. {
  5314. delete FileList;
  5315. }
  5316. }
  5317. //---------------------------------------------------------------------------
  5318. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  5319. {
  5320. if (value)
  5321. {
  5322. if (Component == fcCustomCommandsBand)
  5323. {
  5324. UpdateCustomCommandsToolbar();
  5325. }
  5326. if (Component == fcQueueFileList)
  5327. {
  5328. DebugAssert(!QueueFileListSplitter->Visible);
  5329. AdjustQueueLayout();
  5330. UpdateQueueFileList();
  5331. }
  5332. }
  5333. }
  5334. //---------------------------------------------------------------------------
  5335. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  5336. {
  5337. int MinHeightLimit =
  5338. GetStaticQueuePanelComponentsHeight() +
  5339. QueueFileListSplitter->Height +
  5340. QueueFileList->Height +
  5341. GetMinQueueViewHeight();
  5342. if (QueuePanel->ClientHeight < MinHeightLimit)
  5343. {
  5344. QueuePanel->ClientHeight = MinHeightLimit;
  5345. }
  5346. }
  5347. //---------------------------------------------------------------------------
  5348. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  5349. {
  5350. TControl * Control = GetComponent(Component);
  5351. DebugAssert(Control);
  5352. bool Changed = (Control->Visible != value);
  5353. if (Changed)
  5354. {
  5355. ComponentShowing(Component, value);
  5356. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  5357. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  5358. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  5359. if (value)
  5360. {
  5361. int RemainingHeight = Control->Parent->ClientHeight;
  5362. int RemainingWidth = Control->Parent->ClientWidth;
  5363. for (int i = 0; i < Control->Parent->ControlCount; i++)
  5364. {
  5365. TControl * ChildControl = Control->Parent->Controls[i];
  5366. if (ChildControl->Visible)
  5367. {
  5368. switch (ChildControl->Align)
  5369. {
  5370. case alTop:
  5371. case alBottom:
  5372. RemainingHeight -= ChildControl->Height;
  5373. break;
  5374. case alLeft:
  5375. case alRight:
  5376. RemainingWidth -= ChildControl->Width;
  5377. break;
  5378. }
  5379. }
  5380. }
  5381. int Reserve = ScaleByTextHeight(this, 32);
  5382. // queue in explorer, trees in commander
  5383. if (Control->Height > RemainingHeight - Reserve)
  5384. {
  5385. Control->Height = RemainingHeight / 2;
  5386. }
  5387. if (Control->Width > RemainingWidth - Reserve)
  5388. {
  5389. Control->Width = RemainingWidth / 2;
  5390. }
  5391. }
  5392. Control->Visible = value;
  5393. if (WasFocused && Visible)
  5394. {
  5395. DirView(osCurrent)->SetFocus();
  5396. }
  5397. FixControlsPlacement();
  5398. }
  5399. }
  5400. //---------------------------------------------------------------------------
  5401. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  5402. {
  5403. TControl * Control = GetComponent(Component);
  5404. if (Control == NULL)
  5405. {
  5406. return false;
  5407. }
  5408. else
  5409. {
  5410. return Control->Visible;
  5411. }
  5412. }
  5413. //---------------------------------------------------------------------------
  5414. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  5415. {
  5416. bool Result;
  5417. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  5418. {
  5419. Result = !IsUWP();
  5420. }
  5421. else
  5422. {
  5423. Result = true;
  5424. }
  5425. return Result;
  5426. }
  5427. //---------------------------------------------------------------------------
  5428. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  5429. {
  5430. if (DirView->ItemFocused != NULL)
  5431. {
  5432. DirView->ItemFocused->MakeVisible(false);
  5433. }
  5434. }
  5435. //---------------------------------------------------------------------------
  5436. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  5437. {
  5438. MakeFocusedItemVisible(RemoteDirView);
  5439. QueueSplitter->Visible = QueuePanel->Visible;
  5440. QueueFileListSplitter->Visible = QueueFileList->Visible;
  5441. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  5442. TControl * TopControlsOrder[] =
  5443. { TopDock, MessageDock, SessionsPageControl };
  5444. SetVerticalControlsOrder(TopControlsOrder, LENOF(TopControlsOrder));
  5445. TControl * QueueControlsOrder[] =
  5446. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  5447. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  5448. }
  5449. //---------------------------------------------------------------------------
  5450. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  5451. {
  5452. switch (Component) {
  5453. case fcStatusBar: return RemoteStatusBar;
  5454. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  5455. case fcQueueView: return QueuePanel;
  5456. case fcQueueToolbar: return QueueDock;
  5457. case fcRemoteTree: return RemoteDrivePanel;
  5458. case fcSessionsTabs: return SessionsPageControl;
  5459. case fcQueueFileList: return QueueFileList;
  5460. default: return NULL;
  5461. }
  5462. }
  5463. //---------------------------------------------------------------------------
  5464. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  5465. TObject *Sender, TListColumn *Column, TPoint &Point)
  5466. {
  5467. DebugAssert(NonVisualDataModule && Column && Sender);
  5468. NonVisualDataModule->ListColumn = Column;
  5469. TPopupMenu * DirViewColumnMenu;
  5470. if (Sender == DirView(osOther))
  5471. {
  5472. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  5473. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible = (Column->Index == uvName);
  5474. bool SizeColumn = (Column->Index == uvSize);
  5475. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible = SizeColumn;
  5476. NonVisualDataModule->RemoteCalculateDirectorySizesPopupItem->Visible = SizeColumn;
  5477. }
  5478. else
  5479. {
  5480. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  5481. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible = (Column->Index == dvName);
  5482. bool SizeColumn = (Column->Index == dvSize);
  5483. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible = SizeColumn;
  5484. NonVisualDataModule->LocalCalculateDirectorySizesPopupItem->Visible = SizeColumn;
  5485. }
  5486. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  5487. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  5488. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  5489. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  5490. }
  5491. //---------------------------------------------------------------------------
  5492. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  5493. TObject *Sender, TListItem *Item, bool &AllowExec)
  5494. {
  5495. DoDirViewExecFile(Sender, Item, AllowExec);
  5496. }
  5497. //---------------------------------------------------------------------------
  5498. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  5499. TListItem * Item, bool & AllowExec)
  5500. {
  5501. DebugAssert(Sender && Item && Configuration);
  5502. DebugAssert(AllowExec);
  5503. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  5504. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  5505. bool Remote = !IsSideLocalBrowser(Side);
  5506. DebugAssert(Item == ADirView->ItemFocused);
  5507. bool IsDirectory = ADirView->ItemIsDirectory(Item);
  5508. TResolvedDoubleClickAction Action;
  5509. if (FForceExecution)
  5510. {
  5511. Action = IsDirectory ? rdcaChangeDir : rdcaOpen;
  5512. }
  5513. else
  5514. {
  5515. TTerminal * ATerminal = !IsSideLocalBrowser(Side) ? Terminal : NULL;
  5516. Action = WinConfiguration->ResolveDoubleClickAction(IsDirectory, ATerminal);
  5517. }
  5518. if (Action == rdcaCopy)
  5519. {
  5520. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  5521. UnlockWindow();
  5522. try
  5523. {
  5524. if (IsLocalBrowserMode())
  5525. {
  5526. LocalLocalCopy(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation, false, 0);
  5527. }
  5528. else
  5529. {
  5530. if (HasActiveTerminal())
  5531. {
  5532. ExecuteFileOperation(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  5533. }
  5534. }
  5535. }
  5536. __finally
  5537. {
  5538. LockWindow();
  5539. }
  5540. AllowExec = false;
  5541. }
  5542. else if (Action == rdcaEdit)
  5543. {
  5544. if (!Remote || !WinConfiguration->DisableOpenEdit)
  5545. {
  5546. ExecuteFile(Side, efDefaultEditor);
  5547. AllowExec = false;
  5548. }
  5549. }
  5550. else if (Action == rdcaOpen)
  5551. {
  5552. if (DebugAlwaysTrue(!IsDirectory) && Remote && !WinConfiguration->DisableOpenEdit)
  5553. {
  5554. ExecuteFile(osRemote, efShell);
  5555. AllowExec = false;
  5556. }
  5557. }
  5558. }
  5559. //---------------------------------------------------------------------------
  5560. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  5561. {
  5562. return ((Side == osRemote) || (Side == osCurrent));
  5563. }
  5564. //---------------------------------------------------------------------------
  5565. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5566. {
  5567. DebugFail();
  5568. }
  5569. //---------------------------------------------------------------------------
  5570. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5571. {
  5572. DebugFail();
  5573. }
  5574. //---------------------------------------------------------------------------
  5575. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5576. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5577. {
  5578. TSynchronizeParamType Params;
  5579. Params.LocalDirectory = LocalDirectory;
  5580. Params.RemoteDirectory = RemoteDirectory;
  5581. int UnusedParams =
  5582. (GUIConfiguration->SynchronizeParams &
  5583. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5584. TTerminal::spCaseSensitive | TTerminal::spMirror | TTerminal::spByChecksum));
  5585. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5586. Params.Options = GUIConfiguration->SynchronizeOptions;
  5587. bool SaveSettings = false;
  5588. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5589. &DoSynchronizeTooManyDirectories);
  5590. DebugAssert(FSynchronizeController == NULL);
  5591. FSynchronizeController = &Controller;
  5592. bool Result;
  5593. try
  5594. {
  5595. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5596. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5597. int Options =
  5598. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5599. DebugAssert(FOnFeedSynchronizeError == NULL);
  5600. DebugAssert(FOnSynchronizeAbort == NULL);
  5601. DebugAssert(FSynchronizeTerminal == NULL);
  5602. FSynchronizeTerminal = Terminal;
  5603. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5604. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5605. FOnFeedSynchronizeError, FOnSynchronizeAbort, SynchronizeInNewWindow, UseDefaults);
  5606. if (Result)
  5607. {
  5608. if (SaveSettings)
  5609. {
  5610. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5611. GUIConfiguration->SynchronizeOptions = Params.Options;
  5612. }
  5613. else
  5614. {
  5615. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5616. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5617. FLAGSET(Params.Options, soSynchronize))
  5618. {
  5619. GUIConfiguration->SynchronizeOptions =
  5620. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5621. soSynchronize;
  5622. }
  5623. }
  5624. LocalDirectory = Params.LocalDirectory;
  5625. RemoteDirectory = Params.RemoteDirectory;
  5626. }
  5627. }
  5628. __finally
  5629. {
  5630. FSynchronizeController = NULL;
  5631. DebugAssert(FOnFeedSynchronizeError == NULL);
  5632. FOnFeedSynchronizeError = NULL;
  5633. DebugAssert(FOnSynchronizeAbort == NULL);
  5634. FOnSynchronizeAbort = NULL;
  5635. FSynchronizeTerminal = NULL;
  5636. }
  5637. return Result;
  5638. }
  5639. //---------------------------------------------------------------------------
  5640. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5641. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5642. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5643. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5644. TSynchronizeOptions * Options, bool Full)
  5645. {
  5646. // Keep-up-to-date mode
  5647. if (Terminal->Status == ssOpened)
  5648. {
  5649. try
  5650. {
  5651. int PParams = Params.Params;
  5652. if (!Full)
  5653. {
  5654. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5655. if (FLAGSET(Params.Options, soRecurse))
  5656. {
  5657. PParams |= TTerminal::spSubDirs;
  5658. }
  5659. }
  5660. else
  5661. {
  5662. // if keepuptodate is non-recursive,
  5663. // full sync before has to be non-recursive as well
  5664. if (FLAGCLEAR(Params.Options, soRecurse))
  5665. {
  5666. PParams |= TTerminal::spNoRecurse;
  5667. }
  5668. }
  5669. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5670. PParams, Checklist, Options);
  5671. }
  5672. catch (Exception & E)
  5673. {
  5674. if (!Terminal->Active)
  5675. {
  5676. ShowExtendedExceptionEx(Terminal, &E);
  5677. // Do not abort the "keep up to date" when the session was succesfully reconnected.
  5678. if (!Terminal->Active)
  5679. {
  5680. throw;
  5681. }
  5682. }
  5683. else
  5684. {
  5685. if (FLAGSET(Params.Options, soContinueOnError) &&
  5686. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5687. {
  5688. // noop, already logged in MoreMessageDialog
  5689. }
  5690. else
  5691. {
  5692. // We get mostly EAbort here, so this is noop.
  5693. // Exception is an error when listing directories while looking for differences.
  5694. ShowExtendedExceptionEx(Terminal, &E);
  5695. throw;
  5696. }
  5697. }
  5698. }
  5699. }
  5700. }
  5701. //---------------------------------------------------------------------------
  5702. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5703. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5704. const UnicodeString ErrorStr)
  5705. {
  5706. if (!Directory.IsEmpty())
  5707. {
  5708. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5709. }
  5710. else
  5711. {
  5712. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5713. }
  5714. }
  5715. //---------------------------------------------------------------------------
  5716. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5717. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5718. {
  5719. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5720. {
  5721. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5722. }
  5723. else
  5724. {
  5725. TMessageParams Params(mpNeverAskAgainCheck);
  5726. unsigned int Result = MessageDialog(
  5727. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5728. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5729. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5730. {
  5731. MaxDirectories *= 2;
  5732. if (Result == qaNeverAskAgain)
  5733. {
  5734. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5735. }
  5736. }
  5737. else
  5738. {
  5739. Abort();
  5740. }
  5741. }
  5742. }
  5743. //---------------------------------------------------------------------------
  5744. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5745. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5746. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5747. TSynchronizeOptions * Options)
  5748. {
  5749. // Keep-up-to-date mode
  5750. DebugAssert(!FAutoOperation);
  5751. void * BatchStorage;
  5752. BatchStart(BatchStorage);
  5753. FAutoOperation = true;
  5754. bool AnyOperation = false;
  5755. TDateTime StartTime = Now();
  5756. TSynchronizeChecklist * AChecklist = NULL;
  5757. try
  5758. {
  5759. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5760. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5761. {
  5762. FSynchronizeProgressForm->Start();
  5763. }
  5764. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5765. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5766. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5767. Options);
  5768. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5769. SAFE_DESTROY(FSynchronizeProgressForm);
  5770. AnyOperation = (AChecklist->CheckedCount > 0);
  5771. if (AnyOperation)
  5772. {
  5773. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5774. CreateProgressForm(&SynchronizeProgress);
  5775. try
  5776. {
  5777. Terminal->SynchronizeApply(
  5778. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5779. SynchronizeProcessedItem, NULL, NULL, NULL);
  5780. }
  5781. __finally
  5782. {
  5783. DestroyProgressForm();
  5784. }
  5785. }
  5786. }
  5787. __finally
  5788. {
  5789. if (Checklist == NULL)
  5790. {
  5791. delete AChecklist;
  5792. }
  5793. else
  5794. {
  5795. *Checklist = AChecklist;
  5796. }
  5797. FAutoOperation = false;
  5798. SAFE_DESTROY(FSynchronizeProgressForm);
  5799. BatchEnd(BatchStorage);
  5800. ReloadLocalDirectory();
  5801. if (AnyOperation)
  5802. {
  5803. OperationComplete(StartTime);
  5804. }
  5805. }
  5806. }
  5807. //---------------------------------------------------------------------------
  5808. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5809. {
  5810. // can be called from command line
  5811. return Visible &&
  5812. ((DirView(osRemote)->SelCount > 0) ||
  5813. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5814. }
  5815. //---------------------------------------------------------------------------
  5816. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5817. {
  5818. LogSynchronizeEvent(Terminal, Message);
  5819. }
  5820. //---------------------------------------------------------------------------
  5821. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5822. int Params, TSynchronizeOptions & Options)
  5823. {
  5824. DebugAssert(!IsLocalBrowserMode());
  5825. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5826. {
  5827. Options.Filter = new TStringList();
  5828. Options.Filter->CaseSensitive = false;
  5829. Options.Filter->Duplicates = Types::dupAccept;
  5830. if (DirView(osRemote)->SelCount > 0)
  5831. {
  5832. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5833. }
  5834. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5835. {
  5836. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5837. }
  5838. Options.Filter->Sort();
  5839. }
  5840. }
  5841. //---------------------------------------------------------------------------
  5842. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5843. {
  5844. TCopyParamType Defaults;
  5845. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5846. ConfigStorage->AccessMode = smRead;
  5847. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5848. {
  5849. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5850. }
  5851. ConfigStorage.reset(NULL);
  5852. std::unique_ptr<TStringList> Options(new TStringList());
  5853. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5854. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5855. UnicodeString Result;
  5856. if (Options->Count > 0)
  5857. {
  5858. Result =
  5859. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5860. }
  5861. return Result;
  5862. }
  5863. //---------------------------------------------------------------------------
  5864. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5865. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5866. {
  5867. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5868. UnicodeString AdditionalParams =
  5869. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5870. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5871. SerializeCopyParamForCommandLine(CopyParams),
  5872. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5873. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5874. ExecuteNewInstance(SessionName, AdditionalParams);
  5875. }
  5876. //---------------------------------------------------------------------------
  5877. struct TSynchronizeParams
  5878. {
  5879. UnicodeString LocalDirectory;
  5880. UnicodeString RemoteDirectory;
  5881. TSynchronizeMode Mode;
  5882. TSynchronizeChecklist * Checklist;
  5883. int Params;
  5884. TCopyParamType * CopyParam;
  5885. TDateTime CollectElapsed;
  5886. TDateTime * StartTime;
  5887. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5888. };
  5889. //---------------------------------------------------------------------------
  5890. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5891. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5892. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5893. {
  5894. DebugAssert(!FAutoOperation);
  5895. void * BatchStorage;
  5896. BatchStart(BatchStorage);
  5897. FAutoOperation = true;
  5898. TFileOperationStatistics Statistics;
  5899. TDateTime Start = Now();
  5900. try
  5901. {
  5902. Params.OnProcessedItem = OnProcessedItem;
  5903. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5904. CreateProgressForm(&SynchronizeProgress);
  5905. Terminal->SynchronizeApply(
  5906. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5907. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5908. &Statistics);
  5909. }
  5910. __finally
  5911. {
  5912. Params.OnProcessedItem = NULL;
  5913. FAutoOperation = false;
  5914. DestroyProgressForm();
  5915. BatchEnd(BatchStorage);
  5916. ReloadLocalDirectory();
  5917. }
  5918. if (WinConfiguration->SynchronizeSummary)
  5919. {
  5920. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5921. // The statistics should be 0 anyway in this case
  5922. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5923. {
  5924. Message += L"\n";
  5925. if (Statistics.FilesUploaded > 0)
  5926. {
  5927. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5928. }
  5929. if (Statistics.FilesDownloaded > 0)
  5930. {
  5931. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5932. }
  5933. if (Statistics.FilesDeletedLocal > 0)
  5934. {
  5935. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5936. }
  5937. if (Statistics.FilesDeletedRemote > 0)
  5938. {
  5939. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5940. }
  5941. }
  5942. TDateTime Elapsed = (Now() - Start);
  5943. Message +=
  5944. L"\n" +
  5945. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Params.CollectElapsed))) + L"\n" +
  5946. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Elapsed)));
  5947. TMessageParams Params(mpNeverAskAgainCheck);
  5948. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5949. if (Result == qaNeverAskAgain)
  5950. {
  5951. WinConfiguration->SynchronizeSummary = false;
  5952. }
  5953. }
  5954. }
  5955. //---------------------------------------------------------------------------
  5956. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5957. {
  5958. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5959. {
  5960. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5961. }
  5962. // Not set in keep-up-to-date mode - Synchronize() method
  5963. if (Token != NULL)
  5964. {
  5965. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5966. if (Params.OnProcessedItem != NULL)
  5967. {
  5968. Params.OnProcessedItem(NULL, ChecklistItem);
  5969. }
  5970. }
  5971. }
  5972. //---------------------------------------------------------------------------
  5973. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5974. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5975. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5976. {
  5977. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5978. *Params.StartTime = Now();
  5979. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5980. }
  5981. //---------------------------------------------------------------------------
  5982. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5983. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5984. {
  5985. // terminal can be already closed (e.g. dropped connection)
  5986. if (Terminal != NULL)
  5987. {
  5988. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5989. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5990. }
  5991. }
  5992. //---------------------------------------------------------------------------
  5993. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5994. TOperationSide Side, TStrings * FileList, const UnicodeString & NewFileName, bool TargetIsDirectory, void * Token)
  5995. {
  5996. DebugAssert(!IsLocalBrowserMode());
  5997. TAutoBatch AutoBatch(this);
  5998. TAutoFlag AutoOperationFlag(FAutoOperation);
  5999. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  6000. if (Side == osRemote)
  6001. {
  6002. UnicodeString Target;
  6003. UnicodeString FileMask;
  6004. if (TargetIsDirectory)
  6005. {
  6006. Target = NewFileName;
  6007. Terminal->CreateTargetDirectory(Target, faDirectory, Params.CopyParam);
  6008. }
  6009. else
  6010. {
  6011. Target = UnixExtractFileDir(NewFileName);
  6012. FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  6013. }
  6014. RemoteDirView->SaveSelection();
  6015. RemoteDirView->SaveSelectedNames();
  6016. try
  6017. {
  6018. Terminal->MoveFiles(FileList, Target, FileMask, false);
  6019. }
  6020. catch(...)
  6021. {
  6022. RemoteDirView->DiscardSavedSelection();
  6023. throw;
  6024. }
  6025. RemoteDirView->RestoreSelection();
  6026. }
  6027. else if (DebugAlwaysTrue(Side == osLocal))
  6028. {
  6029. std::unique_ptr<TStrings> Directories(CreateSortedStringList());
  6030. if (TargetIsDirectory)
  6031. {
  6032. if (!ForceDirectories(ApiPath(NewFileName)))
  6033. {
  6034. throw EOSExtException(FMTLOAD(CREATE_DIR_ERROR, (NewFileName)));
  6035. }
  6036. Directories->Add(NewFileName);
  6037. }
  6038. else
  6039. {
  6040. Directories->Add(ExtractFileDir(NewFileName));
  6041. }
  6042. for (int Index = 0; Index < FileList->Count; Index++)
  6043. {
  6044. UnicodeString FileName = FileList->Strings[Index];
  6045. UnicodeString Directory = ExtractFileDir(FileName);
  6046. Directories->Add(Directory);
  6047. UnicodeString NewFilePath = NewFileName;
  6048. if (TargetIsDirectory)
  6049. {
  6050. NewFilePath = TPath::Combine(NewFilePath, ExtractFileName(FileName));
  6051. }
  6052. if (!MoveFile(ApiPath(FileName).c_str(), ApiPath(NewFilePath).c_str()))
  6053. {
  6054. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFilePath)));
  6055. }
  6056. }
  6057. for (int Index = 0; Index < Directories->Count; Index++)
  6058. {
  6059. ReloadLocalDirectory(Directories->Strings[Index]);
  6060. }
  6061. }
  6062. }
  6063. //---------------------------------------------------------------------------
  6064. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  6065. {
  6066. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  6067. if (Side == osLocal)
  6068. {
  6069. if (Action == TSynchronizeChecklist::saDownloadNew)
  6070. {
  6071. OpenFolderInExplorer(LocalPath);
  6072. }
  6073. else
  6074. {
  6075. OpenFileInExplorer(CombinePaths(LocalPath, Item->GetFileName()));
  6076. }
  6077. }
  6078. else if (DebugAlwaysTrue(Side == osRemote))
  6079. {
  6080. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  6081. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  6082. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  6083. if (!LocalPath.IsEmpty())
  6084. {
  6085. SessionData->LocalDirectory = LocalPath;
  6086. }
  6087. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  6088. ExecuteNewInstance(SessionName, FORMAT(L"%s=\"%s\"", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  6089. }
  6090. }
  6091. //---------------------------------------------------------------------------
  6092. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  6093. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  6094. const TCopyParamType * CopyParams)
  6095. {
  6096. UnicodeString SessionName = CreateHiddenDuplicateSession();
  6097. UnicodeString AdditionalParams =
  6098. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  6099. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  6100. SerializeCopyParamForCommandLine(CopyParams),
  6101. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  6102. LocalDirectory, RemoteDirectory, Mode, Params));
  6103. ExecuteNewInstance(SessionName, AdditionalParams);
  6104. }
  6105. //---------------------------------------------------------------------------
  6106. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  6107. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  6108. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  6109. {
  6110. int Result;
  6111. bool SaveSettings = false;
  6112. int Options =
  6113. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  6114. FLAGMASK(!CanCalculateChecksum(), fsoDisableByChecksum) |
  6115. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  6116. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  6117. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  6118. bool Continue =
  6119. ((UseDefaults == 0) ||
  6120. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  6121. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults)) &&
  6122. (FLAGCLEAR(Params, TTerminal::spByChecksum) || EnsureCommandSessionFallback(fcCalculatingChecksum));
  6123. if (Continue)
  6124. {
  6125. Configuration->Usage->Inc(L"Synchronizations");
  6126. CopyParam.IncludeFileMask.SetRoots(LocalDirectory, RemoteDirectory);
  6127. UpdateCopyParamCounters(CopyParam);
  6128. TSynchronizeOptions SynchronizeOptions;
  6129. GetSynchronizeOptions(Params, SynchronizeOptions);
  6130. if (SaveSettings)
  6131. {
  6132. GUIConfiguration->SynchronizeParams = Params;
  6133. }
  6134. else
  6135. {
  6136. SaveMode = false;
  6137. }
  6138. TDateTime StartTime = Now();
  6139. TSynchronizeChecklist * Checklist = NULL;
  6140. try
  6141. {
  6142. DebugAssert(!FAutoOperation);
  6143. FAutoOperation = true;
  6144. try
  6145. {
  6146. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  6147. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  6148. int Files = -1;
  6149. if (DataList->Count >= 1)
  6150. {
  6151. Files = StrToIntDef(DataList->Strings[0], Files);
  6152. }
  6153. else
  6154. {
  6155. DataList->Add(UnicodeString());
  6156. }
  6157. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  6158. FSynchronizeProgressForm->Start();
  6159. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  6160. static_cast<TTerminal::TSynchronizeMode>(Mode),
  6161. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  6162. &SynchronizeOptions);
  6163. if (Terminal->SessionData->CacheDirectories)
  6164. {
  6165. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  6166. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  6167. }
  6168. }
  6169. __finally
  6170. {
  6171. FAutoOperation = false;
  6172. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  6173. SAFE_DESTROY(FSynchronizeProgressForm);
  6174. }
  6175. TSynchronizeParams SynchronizeParams;
  6176. SynchronizeParams.LocalDirectory = LocalDirectory;
  6177. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  6178. SynchronizeParams.Mode = Mode;
  6179. SynchronizeParams.CopyParam = &CopyParam;
  6180. SynchronizeParams.Params = Params;
  6181. SynchronizeParams.Checklist = Checklist;
  6182. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  6183. SynchronizeParams.StartTime = &StartTime;
  6184. SynchronizeParams.OnProcessedItem = NULL;
  6185. Result = Checklist->Count;
  6186. if (Checklist->Count > 0)
  6187. {
  6188. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  6189. {
  6190. if (!DoSynchronizeChecklistDialog(
  6191. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  6192. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  6193. {
  6194. Result = -1;
  6195. }
  6196. }
  6197. else
  6198. {
  6199. FullSynchronize(SynchronizeParams, NULL, NULL);
  6200. }
  6201. }
  6202. else
  6203. {
  6204. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  6205. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  6206. }
  6207. }
  6208. __finally
  6209. {
  6210. delete Checklist;
  6211. }
  6212. OperationComplete(StartTime);
  6213. }
  6214. else
  6215. {
  6216. Result = -1;
  6217. }
  6218. return Result;
  6219. }
  6220. //---------------------------------------------------------------------------
  6221. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  6222. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  6223. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  6224. {
  6225. if (Collect)
  6226. {
  6227. DebugAssert(FSynchronizeProgressForm != NULL);
  6228. if (!FSynchronizeProgressForm->Started)
  6229. {
  6230. FSynchronizeProgressForm->Start();
  6231. }
  6232. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  6233. SetTaskbarListProgressValue(CompareProgress);
  6234. }
  6235. else
  6236. {
  6237. DebugAssert(FSynchronizeProgressForm == NULL);
  6238. DebugAssert(FProgressForm != NULL);
  6239. }
  6240. }
  6241. //---------------------------------------------------------------------------
  6242. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  6243. {
  6244. UnicodeString FullFileName = AbsolutePath(Terminal->CurrentDirectory, FileName);
  6245. std::unique_ptr<TRemoteFile> File(Terminal->ReadFile(FullFileName));
  6246. if (File.get() != NULL)
  6247. {
  6248. ExecuteRemoteFile(FullFileName, File.get(), efInternalEditor);
  6249. Application->ShowMainForm = false;
  6250. Application->Run();
  6251. }
  6252. }
  6253. //---------------------------------------------------------------------------
  6254. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  6255. {
  6256. DebugFail();
  6257. }
  6258. //---------------------------------------------------------------------------
  6259. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  6260. {
  6261. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  6262. SessionData->Assign(ManagedSession->SessionData);
  6263. UpdateSessionData(SessionData.get());
  6264. DebugAssert(SessionData->IsLocalBrowser == IsLocalBrowserMode());
  6265. if (IsActiveTerminal(ManagedSession))
  6266. {
  6267. ManagedSession->UpdateSessionCredentials(SessionData.get());
  6268. }
  6269. if (!ManagedSession->SessionData->HasSessionName())
  6270. {
  6271. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  6272. // once IsWorkspace is cleared
  6273. SessionData->Name = UnicodeString();
  6274. }
  6275. // Most uses of this method ends with saving the session, and we do not want to store the IsWorkspace flag.
  6276. // Particularly, with SaveHiddenDuplicateSession, it won't work as TSessionData::ParseUrl explicitly ignored workspace sessions.
  6277. SessionData->IsWorkspace = false;
  6278. return SessionData.release();
  6279. }
  6280. //---------------------------------------------------------------------------
  6281. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  6282. {
  6283. TSessionData * SessionData = CloneCurrentSessionData();
  6284. try
  6285. {
  6286. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  6287. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  6288. }
  6289. __finally
  6290. {
  6291. delete SessionData;
  6292. }
  6293. }
  6294. //---------------------------------------------------------------------------
  6295. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  6296. {
  6297. TTerminalManager * Manager = TTerminalManager::Instance();
  6298. std::unique_ptr<TObjectList> DataList(new TObjectList());
  6299. if (DebugAlwaysTrue(ManagedSession != NULL))
  6300. {
  6301. // Update ManagedSession->StateData
  6302. UpdateSession(ManagedSession);
  6303. }
  6304. Manager->SaveWorkspace(DataList.get());
  6305. return DataList.release();
  6306. }
  6307. //---------------------------------------------------------------------------
  6308. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  6309. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  6310. {
  6311. WinConfiguration->LastWorkspace = Name;
  6312. if (!SavePasswords)
  6313. {
  6314. for (int Index = 0; Index < DataList->Count; Index++)
  6315. {
  6316. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  6317. if (SessionData->Link.IsEmpty())
  6318. {
  6319. SessionData->ClearSessionPasswords();
  6320. }
  6321. }
  6322. }
  6323. StoredSessions->NewWorkspace(Name, DataList);
  6324. // modified only
  6325. StoredSessions->Save(false, Explicit);
  6326. }
  6327. //---------------------------------------------------------------------------
  6328. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  6329. {
  6330. return
  6331. DefaultStr(WinConfiguration->LastWorkspace,
  6332. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  6333. }
  6334. //---------------------------------------------------------------------------
  6335. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  6336. {
  6337. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  6338. bool AnyNonStoredSessionWithPassword = false;
  6339. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  6340. bool AllNonStoredSessionsAnonymous = true;
  6341. TTerminalManager * Manager = TTerminalManager::Instance();
  6342. for (int Index = 0; Index < DataList->Count; Index++)
  6343. {
  6344. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  6345. if (SessionData->Link.IsEmpty())
  6346. {
  6347. if (SessionData->HasAnySessionPassword())
  6348. {
  6349. AnyNonStoredSessionWithPassword = true;
  6350. if (!Manager->Sessions[Index]->SessionData->IsWorkspace)
  6351. {
  6352. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  6353. }
  6354. }
  6355. if (!SameText(SessionData->UserName, AnonymousUserName))
  6356. {
  6357. AllNonStoredSessionsAnonymous = false;
  6358. }
  6359. }
  6360. }
  6361. bool SavePasswords;
  6362. bool * PSavePasswords;
  6363. bool NotRecommendedSavingPasswords =
  6364. !CustomWinConfiguration->UseMasterPassword &&
  6365. !AllNonStoredSessionsAnonymous;
  6366. if (Configuration->DisablePasswordStoring ||
  6367. !AnyNonStoredSessionWithPassword)
  6368. {
  6369. PSavePasswords = NULL;
  6370. SavePasswords = false;
  6371. }
  6372. else
  6373. {
  6374. PSavePasswords = &SavePasswords;
  6375. SavePasswords =
  6376. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  6377. !NotRecommendedSavingPasswords;
  6378. }
  6379. UnicodeString Name = WorkspaceName();
  6380. bool CreateShortcut = false;
  6381. bool Result =
  6382. DoSaveWorkspaceDialog(
  6383. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  6384. EnableAutoSave);
  6385. if (Result)
  6386. {
  6387. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  6388. if (CreateShortcut)
  6389. {
  6390. TOperationVisualizer Visualizer;
  6391. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  6392. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  6393. }
  6394. if (EnableAutoSave)
  6395. {
  6396. WinConfiguration->AutoSaveWorkspace = true;
  6397. WinConfiguration->AutoWorkspace = Name;
  6398. if (PSavePasswords != NULL)
  6399. {
  6400. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  6401. }
  6402. }
  6403. }
  6404. return Result;
  6405. }
  6406. //---------------------------------------------------------------------------
  6407. void __fastcall TCustomScpExplorerForm::UpdateSession(TManagedTerminal * Session)
  6408. {
  6409. DebugAssert(IsLocalBrowserMode() == Session->LocalBrowser);
  6410. DebugAssert(Session == ManagedSession);
  6411. if (!IsLocalBrowserMode())
  6412. {
  6413. SAFE_DESTROY(Session->RemoteExplorerState);
  6414. if (WinConfiguration->PreservePanelState)
  6415. {
  6416. Session->RemoteExplorerState = RemoteDirView->SaveState();
  6417. }
  6418. }
  6419. UpdateSessionData(Session->StateData);
  6420. }
  6421. //---------------------------------------------------------------------------
  6422. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  6423. {
  6424. // Keep in sync with TSessionData::CopyStateData
  6425. DebugAssert(Data != NULL);
  6426. // This is inconsistent with how color (for example) is handled.
  6427. Data->Name = ManagedSession->SessionData->Name;
  6428. if (!IsLocalBrowserMode())
  6429. {
  6430. // cannot use RemoteDirView->Path, because it is empty if connection
  6431. // was already closed
  6432. // also only peek, we may not be connected at all atm
  6433. // so make sure we do not try retrieving current directory from the server
  6434. // (particularly with FTP)
  6435. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  6436. if (!ACurrentDirectory.IsEmpty())
  6437. {
  6438. Data->RemoteDirectory = ACurrentDirectory;
  6439. }
  6440. }
  6441. Data->Color = SessionColor;
  6442. }
  6443. //---------------------------------------------------------------------------
  6444. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  6445. {
  6446. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  6447. DebugAssert(Toolbar != NULL);
  6448. for (int i = 0; i < Toolbar->Items->Count; i++)
  6449. {
  6450. TTBXCustomDropDownItem * DropDownItem;
  6451. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  6452. if (DropDownItem != NULL)
  6453. {
  6454. ToolbarItemResize(DropDownItem,
  6455. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  6456. Toolbar->NonClientWidth);
  6457. break;
  6458. }
  6459. }
  6460. }
  6461. //---------------------------------------------------------------------------
  6462. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  6463. {
  6464. Item->EditWidth = Width;
  6465. }
  6466. //---------------------------------------------------------------------------
  6467. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  6468. TTBCustomToolbar * Toolbar, TPoint & ASize)
  6469. {
  6470. for (int i = 0; i < Toolbar->Items->Count; i++)
  6471. {
  6472. TTBXCustomDropDownItem * DropDownItem;
  6473. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  6474. if (DropDownItem != NULL)
  6475. {
  6476. ASize.x -= DropDownItem->EditWidth;
  6477. TControl * Control = this;
  6478. ASize.x += ScaleByTextHeight(Control, 50) /* minimal combo width */;
  6479. }
  6480. }
  6481. }
  6482. //---------------------------------------------------------------------------
  6483. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  6484. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  6485. {
  6486. if (WinConfiguration->DDWarnLackOfTempSpace)
  6487. {
  6488. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  6489. if (!ADrive.IsEmpty())
  6490. {
  6491. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  6492. DebugAssert(RequiredSpace >= 0);
  6493. __int64 RequiredWithReserve;
  6494. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  6495. if (FreeSpace < RequiredWithReserve)
  6496. {
  6497. unsigned int Result;
  6498. TMessageParams Params(mpNeverAskAgainCheck);
  6499. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  6500. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  6501. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  6502. if (Result == qaNeverAskAgain)
  6503. {
  6504. WinConfiguration->DDWarnLackOfTempSpace = false;
  6505. }
  6506. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  6507. }
  6508. }
  6509. }
  6510. }
  6511. //---------------------------------------------------------------------------
  6512. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  6513. {
  6514. DoOpenDirectoryDialog(odAddBookmark, Side);
  6515. }
  6516. //---------------------------------------------------------------------------
  6517. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  6518. {
  6519. // we should better use TCustomDirView::FCaseSensitive, but it is private
  6520. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  6521. try
  6522. {
  6523. TCustomDirView * DView = DirView(Side);
  6524. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  6525. {
  6526. VisitedDirectories->Add(DView->HistoryPath[Index]);
  6527. }
  6528. }
  6529. catch (...)
  6530. {
  6531. delete VisitedDirectories;
  6532. throw;
  6533. }
  6534. return VisitedDirectories;
  6535. }
  6536. //---------------------------------------------------------------------------
  6537. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  6538. TOpenDirectoryMode Mode, TOperationSide Side)
  6539. {
  6540. bool Continue = true;
  6541. if (Mode == odAddBookmark)
  6542. {
  6543. TMessageParams Params(mpNeverAskAgainCheck);
  6544. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  6545. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  6546. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  6547. unsigned int Answer =
  6548. MessageDialog(Message,
  6549. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  6550. if (Answer == qaNeverAskAgain)
  6551. {
  6552. Continue = true;
  6553. WinConfiguration->UseSharedBookmarks = true;
  6554. }
  6555. else if (Answer == qaOK)
  6556. {
  6557. Continue = true;
  6558. WinConfiguration->UseSharedBookmarks = false;
  6559. }
  6560. else
  6561. {
  6562. Continue = false;
  6563. }
  6564. }
  6565. if (Continue)
  6566. {
  6567. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  6568. try
  6569. {
  6570. UnicodeString Name = DirView(Side)->PathName;
  6571. bool Repeat;
  6572. do
  6573. {
  6574. Repeat = false;
  6575. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  6576. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  6577. // do not allow switching to location profiles,
  6578. // if we are not connected
  6579. HasDirView[osLocal] && IsActiveTerminal(Terminal)))
  6580. {
  6581. TWindowLock Lock(this);
  6582. if (!TryOpenDirectory(Side, Name))
  6583. {
  6584. Repeat = true;
  6585. Mode = odBrowse;
  6586. }
  6587. }
  6588. }
  6589. while (Repeat);
  6590. }
  6591. __finally
  6592. {
  6593. delete VisitedDirectories;
  6594. }
  6595. }
  6596. }
  6597. //---------------------------------------------------------------------------
  6598. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  6599. {
  6600. DebugAssert(!Terminal->CommandSessionOpened);
  6601. return TTerminalManager::Instance()->ConnectTerminal(Terminal->CommandSession);
  6602. }
  6603. //---------------------------------------------------------------------------
  6604. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  6605. {
  6606. bool Result = Terminal->IsCapable[Capability] ||
  6607. Terminal->CommandSessionOpened;
  6608. if (!Result)
  6609. {
  6610. // We might get here for example when "checksum" synchronization is requested from command-line
  6611. // on server that supports neither checksum nor shell
  6612. if (!Terminal->IsCapable[fcSecondaryShell])
  6613. {
  6614. NotSupported();
  6615. }
  6616. else if (!GUIConfiguration->ConfirmCommandSession)
  6617. {
  6618. Result = true;
  6619. }
  6620. else
  6621. {
  6622. TMessageParams Params(mpNeverAskAgainCheck);
  6623. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6624. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6625. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6626. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6627. if (Answer == qaNeverAskAgain)
  6628. {
  6629. GUIConfiguration->ConfirmCommandSession = false;
  6630. Result = true;
  6631. }
  6632. else if (Answer == qaOK)
  6633. {
  6634. Result = true;
  6635. }
  6636. }
  6637. if (Result)
  6638. {
  6639. Result = CommandSessionFallback();
  6640. }
  6641. }
  6642. return Result;
  6643. }
  6644. //---------------------------------------------------------------------------
  6645. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6646. {
  6647. if (EnsureCommandSessionFallback(fcAnyCommand))
  6648. {
  6649. DoConsoleDialog(Terminal, Command);
  6650. }
  6651. }
  6652. //---------------------------------------------------------------------------
  6653. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6654. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6655. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6656. {
  6657. if (!IsSideLocalBrowser(osRemote) &&
  6658. IsFileControl(DropSourceControl, osRemote) &&
  6659. (FDDExtMapFile != NULL))
  6660. {
  6661. Accept = true;
  6662. }
  6663. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6664. DebugAssert(FDDTargetControl != NULL);
  6665. }
  6666. //---------------------------------------------------------------------------
  6667. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6668. _di_IDataObject DataObj, int KeyState,
  6669. const TPoint & Point, int & Effect, bool & Accept)
  6670. {
  6671. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6672. }
  6673. //---------------------------------------------------------------------------
  6674. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6675. _di_IDataObject DataObj, int KeyState,
  6676. const TPoint & Point, int & Effect, bool & Accept)
  6677. {
  6678. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6679. }
  6680. //---------------------------------------------------------------------------
  6681. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6682. TObject * Sender)
  6683. {
  6684. DebugUsedParam(Sender);
  6685. DebugAssert(FDDTargetControl == Sender);
  6686. FDDTargetControl = NULL;
  6687. }
  6688. //---------------------------------------------------------------------------
  6689. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave(int)
  6690. {
  6691. FileControlDDDragLeave(SessionsPageControl);
  6692. }
  6693. //---------------------------------------------------------------------------
  6694. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave(int)
  6695. {
  6696. FileControlDDDragLeave(QueueView3);
  6697. }
  6698. //---------------------------------------------------------------------------
  6699. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6700. {
  6701. DebugAssert(!IsSideLocalBrowser(Side));
  6702. DebugUsedParam(Side);
  6703. bool Edit = false;
  6704. TRemoteFile * File = NULL;
  6705. UnicodeString FileName;
  6706. UnicodeString PointTo;
  6707. bool SymbolicLink = true;
  6708. if (RemoteDirView->ItemFocused)
  6709. {
  6710. DebugAssert(RemoteDirView->ItemFocused->Data);
  6711. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6712. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6713. if (Edit)
  6714. {
  6715. FileName = File->FileName;
  6716. PointTo = File->LinkTo;
  6717. }
  6718. else if (!File->IsParentDirectory)
  6719. {
  6720. PointTo = File->FileName;
  6721. }
  6722. }
  6723. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6724. Terminal->IsCapable[fcHardLink]))
  6725. {
  6726. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6727. if (Edit)
  6728. {
  6729. DebugAssert(File->FileName == FileName);
  6730. int Params = dfNoRecursive;
  6731. Terminal->ExceptionOnFail = true;
  6732. try
  6733. {
  6734. Terminal->DeleteFile(L"", File, &Params);
  6735. }
  6736. __finally
  6737. {
  6738. Terminal->ExceptionOnFail = false;
  6739. }
  6740. }
  6741. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6742. }
  6743. }
  6744. //---------------------------------------------------------------------------
  6745. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6746. {
  6747. return
  6748. (IsSideLocalBrowser(Side) ||
  6749. (HasActiveTerminal() &&
  6750. Terminal->ResolvingSymlinks &&
  6751. Terminal->IsCapable[fcSymbolicLink]));
  6752. }
  6753. //---------------------------------------------------------------------------
  6754. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6755. {
  6756. return
  6757. !IsSideLocalBrowser(FCurrentSide) &&
  6758. (RemoteDirView->ItemFocused != NULL) &&
  6759. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6760. Terminal->SessionData->ResolveSymlinks;
  6761. }
  6762. //---------------------------------------------------------------------------
  6763. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6764. {
  6765. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6766. FForceExecution = true;
  6767. try
  6768. {
  6769. DirView(osCurrent)->ExecuteCurrentFile();
  6770. }
  6771. __finally
  6772. {
  6773. FForceExecution = false;
  6774. }
  6775. }
  6776. //---------------------------------------------------------------------------
  6777. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6778. {
  6779. TEditorData ExternalEditor;
  6780. ExternalEditor.Editor = edExternal;
  6781. bool Remember = false;
  6782. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6783. {
  6784. if (Remember)
  6785. {
  6786. TEditorList * EditorList = new TEditorList;
  6787. try
  6788. {
  6789. *EditorList = *WinConfiguration->EditorList;
  6790. bool Found = false;
  6791. int i = 0;
  6792. while (!Found && (i < EditorList->Count))
  6793. {
  6794. const TEditorPreferences * Editor = EditorList->Editors[i];
  6795. if ((Editor->Data->Editor == edExternal) &&
  6796. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6797. {
  6798. Found = true;
  6799. }
  6800. i++;
  6801. }
  6802. if (!Found)
  6803. {
  6804. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6805. WinConfiguration->EditorList = EditorList;
  6806. }
  6807. }
  6808. __finally
  6809. {
  6810. delete EditorList;
  6811. }
  6812. }
  6813. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6814. }
  6815. }
  6816. //---------------------------------------------------------------------------
  6817. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6818. {
  6819. if (FFileFindTerminal == ATerminal)
  6820. {
  6821. FFileFindTerminal = NULL;
  6822. HideFileFindDialog();
  6823. }
  6824. if (FClipboardTerminal == ATerminal)
  6825. {
  6826. ClipboardClear(); // implies ClipboardStop
  6827. }
  6828. if ((FOnSynchronizeAbort != NULL) &&
  6829. (ATerminal == FManagedSession))
  6830. {
  6831. FOnSynchronizeAbort(NULL);
  6832. }
  6833. }
  6834. //---------------------------------------------------------------------------
  6835. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6836. {
  6837. FEditorManager->ProcessFiles(FileTerminalRemoved, Sender);
  6838. DetachTerminal(Sender);
  6839. }
  6840. //---------------------------------------------------------------------------
  6841. void __fastcall TCustomScpExplorerForm::FileTerminalReplaced(
  6842. const UnicodeString FileName, TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6843. {
  6844. TManagedTerminal * ATerminal = static_cast<TManagedTerminal *>(Arg);
  6845. if (Data->Terminal == Terminal)
  6846. {
  6847. Data->Terminal = ATerminal;
  6848. }
  6849. }
  6850. //---------------------------------------------------------------------------
  6851. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6852. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6853. {
  6854. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6855. DebugAssert(Terminal != NULL);
  6856. if (Data->Terminal == Terminal)
  6857. {
  6858. Data->Terminal = NULL;
  6859. }
  6860. }
  6861. //---------------------------------------------------------------------------
  6862. TManagedTerminal * TCustomScpExplorerForm::GetReplacementForLastSession()
  6863. {
  6864. return NULL;
  6865. }
  6866. //---------------------------------------------------------------------------
  6867. void __fastcall TCustomScpExplorerForm::LastTerminalClosed()
  6868. {
  6869. UpdateControls();
  6870. SessionColor = TColor(0);
  6871. UpdateRemotePathComboBox(false);
  6872. NeedSession(false);
  6873. }
  6874. //---------------------------------------------------------------------------
  6875. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6876. {
  6877. try
  6878. {
  6879. // Cache, as the login dialog can change its value.
  6880. // See also DoShow. Also see TTerminalManager::NewSession.
  6881. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6882. try
  6883. {
  6884. if (ShowLogin)
  6885. {
  6886. bool ReloadSessions = !Startup;
  6887. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this, true);
  6888. }
  6889. }
  6890. __finally
  6891. {
  6892. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6893. // (so there was no chance for the user to open any session yet)
  6894. if ((ShowLogin || !Startup) &&
  6895. !WinConfiguration->KeepOpenWhenNoSession &&
  6896. // this rules out the implicit Commander's local-local browser
  6897. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6898. {
  6899. TerminateApplication();
  6900. }
  6901. }
  6902. }
  6903. catch (EAbort &)
  6904. {
  6905. // swallow
  6906. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6907. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6908. }
  6909. }
  6910. //---------------------------------------------------------------------------
  6911. void __fastcall TCustomScpExplorerForm::SessionListChanged(bool ForceTruncationUpdate)
  6912. {
  6913. TTerminalManager * Manager = TTerminalManager::Instance();
  6914. DebugAssert(!Manager->Updating);
  6915. TAutoFlag UpdatingSessionTabsFlag(FUpdatingSessionTabs);
  6916. int ActiveSessionIndex = Manager->ActiveSessionIndex;
  6917. Configuration->Usage->SetMax(L"MaxOpenedSessions", Manager->Count);
  6918. SessionsPageControl->LockDrawing();
  6919. try
  6920. {
  6921. int PrevTabsWidth = SessionsPageControl->TotalTabsWidth();
  6922. while (SessionsPageControl->PageCount > Manager->Count + 1)
  6923. {
  6924. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6925. }
  6926. for (int Index = 0; Index <= Manager->Count; Index++)
  6927. {
  6928. TThemeTabSheet * TabSheet;
  6929. if (Index >= SessionsPageControl->PageCount)
  6930. {
  6931. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6932. TabSheet->PageControl = SessionsPageControl;
  6933. }
  6934. else
  6935. {
  6936. TabSheet = SessionsPageControl->Pages[Index];
  6937. }
  6938. bool IsSessionTab = (Index < Manager->Count);
  6939. if (IsSessionTab)
  6940. {
  6941. TTerminal * Terminal = Manager->Sessions[Index];
  6942. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6943. TabSheet->CaptionTruncation = WinConfiguration->SessionTabCaptionTruncation ? tttEllipsis : tttNone;
  6944. UpdateSessionTab(TabSheet);
  6945. }
  6946. else
  6947. {
  6948. TabSheet->Tag = 0; // not really needed
  6949. TabSheet->Shadowed = false;
  6950. TabSheet->Button = SupportsLocalBrowser() ? ttbDropDown : ttbNone;
  6951. TabSheet->CaptionTruncation = GetNewTabTabCaptionTruncation();
  6952. // We know that we are at the last page, otherwise we could not call this (it assumes that new session tab is the last one)
  6953. UpdateNewTabTab();
  6954. }
  6955. }
  6956. // Prevent flicker on the right side where scrolling buttons would be, unless really needed
  6957. if (ForceTruncationUpdate || (SessionsPageControl->TotalTabsWidth() != PrevTabsWidth))
  6958. {
  6959. SessionsPageControl->UpdateTabsCaptionTruncation();
  6960. }
  6961. }
  6962. __finally
  6963. {
  6964. SessionsPageControl->UnlockDrawing();
  6965. }
  6966. SessionsPageControl->ActivePageIndex = ActiveSessionIndex;
  6967. }
  6968. //---------------------------------------------------------------------------
  6969. TThemeTabCaptionTruncation TCustomScpExplorerForm::GetNewTabTabCaptionTruncation()
  6970. {
  6971. return WinConfiguration->SessionTabCaptionTruncation ? tttNoText : tttNone;
  6972. }
  6973. //---------------------------------------------------------------------------
  6974. UnicodeString TCustomScpExplorerForm::GetNewTabTabCaption()
  6975. {
  6976. return StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewTabAction->Caption));
  6977. }
  6978. //---------------------------------------------------------------------------
  6979. TThemeTabSheet * TCustomScpExplorerForm::GetNewTabTab()
  6980. {
  6981. return SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6982. }
  6983. //---------------------------------------------------------------------------
  6984. void __fastcall TCustomScpExplorerForm::UpdateNewTabTab()
  6985. {
  6986. TThemeTabSheet * TabSheet = GetNewTabTab();
  6987. UnicodeString TabCaption;
  6988. if (WinConfiguration->SelectiveToolbarText)
  6989. {
  6990. TabCaption = GetNewTabTabCaption();
  6991. }
  6992. TabSheet->BaseCaption = TabCaption;
  6993. TabSheet->ImageIndex = GetNewTabTabImageIndex(osCurrent);
  6994. }
  6995. //---------------------------------------------------------------------------
  6996. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabSession(TTabSheet * TabSheet)
  6997. {
  6998. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6999. }
  7000. //---------------------------------------------------------------------------
  7001. UnicodeString TCustomScpExplorerForm::GetLocalBrowserSessionTitle(TManagedTerminal *)
  7002. {
  7003. DebugFail();
  7004. return UnicodeString();
  7005. }
  7006. //---------------------------------------------------------------------------
  7007. void TCustomScpExplorerForm::UpdateSessionTab(TThemeTabSheet * TabSheet)
  7008. {
  7009. if (DebugAlwaysTrue(TabSheet != NULL))
  7010. {
  7011. TManagedTerminal * ASession = GetSessionTabSession(TabSheet);
  7012. if (DebugAlwaysTrue(ASession != NULL))
  7013. {
  7014. TColor Color = (ASession == Terminal) ? FSessionColor : ASession->StateData->Color;
  7015. if (ASession->LocalBrowser)
  7016. {
  7017. TabSheet->ImageIndex = FLocalBrowserTabImageIndex;
  7018. }
  7019. else
  7020. {
  7021. TabSheet->ImageIndex = AddSessionColor(Color);
  7022. }
  7023. TTerminalManager * Manager = TTerminalManager::Instance();
  7024. TabSheet->Shadowed = !ASession->Active && !ASession->LocalBrowser;
  7025. TabSheet->Button = CanCloseSession(ASession) ? ttbClose : ttbNone;
  7026. TabSheet->BaseCaption = Manager->GetSessionTitle(ASession, true);
  7027. }
  7028. }
  7029. }
  7030. //---------------------------------------------------------------------------
  7031. bool TCustomScpExplorerForm::CanCloseSession(TManagedTerminal * Session)
  7032. {
  7033. return !Session->LocalBrowser || (TTerminalManager::Instance()->Count > 1);
  7034. }
  7035. //---------------------------------------------------------------------------
  7036. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  7037. {
  7038. DebugAssert(SessionsPageControl->ActivePage != NULL);
  7039. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->ActivePage);
  7040. bool Result = (Session != NULL);
  7041. if (Result)
  7042. {
  7043. TTerminalManager::Instance()->ActiveSession = Session;
  7044. }
  7045. else
  7046. {
  7047. try
  7048. {
  7049. NewTab();
  7050. }
  7051. __finally
  7052. {
  7053. SessionListChanged();
  7054. }
  7055. FSessionsPageControlNewTabTime = Now();
  7056. }
  7057. return Result;
  7058. }
  7059. //---------------------------------------------------------------------------
  7060. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  7061. {
  7062. TWindowLock Lock(this);
  7063. SessionTabSwitched();
  7064. }
  7065. //---------------------------------------------------------------------------
  7066. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  7067. {
  7068. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  7069. DebugAssert(TransferList != NULL);
  7070. UnicodeString Name;
  7071. if (TransferList->ItemIndex <= 0)
  7072. {
  7073. Name = L"";
  7074. }
  7075. else
  7076. {
  7077. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  7078. }
  7079. if (FCopyParamAutoSelected.IsEmpty())
  7080. {
  7081. // if previous preset was not autoselected, make new preset the "default"
  7082. FCopyParamDefault = Name;
  7083. }
  7084. GUIConfiguration->CopyParamCurrent = Name;
  7085. }
  7086. //---------------------------------------------------------------------------
  7087. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  7088. {
  7089. // sanity check
  7090. bool ExistingPreset =
  7091. (FTransferListHoverIndex >= 0) &&
  7092. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  7093. DebugAssert(ExistingPreset);
  7094. if (ExistingPreset)
  7095. {
  7096. HDC DC = GetDC(0);
  7097. TCanvas * Canvas = new TCanvas();
  7098. try
  7099. {
  7100. Canvas->Handle = DC;
  7101. Canvas->Font = GetToolbarFont(this);
  7102. UnicodeString Name;
  7103. if (FTransferListHoverIndex == 0)
  7104. {
  7105. Name = L"";
  7106. }
  7107. else
  7108. {
  7109. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  7110. }
  7111. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  7112. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  7113. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  7114. static_cast<TObject*>(GetComponent(fcTransferList)));
  7115. UnicodeString InfoStr =
  7116. GUIConfiguration->CopyParamPreset[Name].
  7117. GetInfoStr(L"; ",
  7118. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  7119. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  7120. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  7121. {
  7122. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  7123. {
  7124. InfoStr.SetLength(InfoStr.Length() - 1);
  7125. }
  7126. InfoStr += Ellipsis;
  7127. }
  7128. // UpdateCaption does not cause invalidation of whole submenu, while
  7129. // setting Caption property does.
  7130. // also it probably does not resize the label, even if necessary
  7131. // (we do not want that anyway)
  7132. TransferLabel->UpdateCaption(InfoStr);
  7133. }
  7134. __finally
  7135. {
  7136. Canvas->Handle = NULL;
  7137. ReleaseDC(0, DC);
  7138. delete Canvas;
  7139. }
  7140. }
  7141. }
  7142. //---------------------------------------------------------------------------
  7143. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  7144. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  7145. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  7146. {
  7147. if (FTransferListHoverIndex != AHoverIndex)
  7148. {
  7149. FTransferListHoverIndex = AHoverIndex;
  7150. UpdateTransferLabel();
  7151. }
  7152. }
  7153. //---------------------------------------------------------------------------
  7154. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  7155. {
  7156. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  7157. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  7158. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  7159. {
  7160. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  7161. {
  7162. if (!NonVisualDataModule->Busy)
  7163. {
  7164. OpenDirectory(GetSide(osCurrent));
  7165. }
  7166. Message.Result = 1;
  7167. }
  7168. else
  7169. {
  7170. TForm::Dispatch(&Message);
  7171. }
  7172. }
  7173. else
  7174. {
  7175. TForm::Dispatch(&Message);
  7176. }
  7177. }
  7178. //---------------------------------------------------------------------------
  7179. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  7180. {
  7181. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  7182. if ((FIgnoreNextDialogChar != 0) &&
  7183. (towupper(Message.CharCode) == towupper(FIgnoreNextDialogChar)))
  7184. {
  7185. Message.Result = 1;
  7186. }
  7187. else
  7188. {
  7189. TForm::Dispatch(&Message);
  7190. }
  7191. FIgnoreNextDialogChar = 0;
  7192. }
  7193. //---------------------------------------------------------------------------
  7194. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  7195. {
  7196. // The four low-order bits are used internally by Windows
  7197. unsigned int Cmd = (Message.WParam & 0xFFF0);
  7198. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  7199. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  7200. // 61730 - restore thru double click - undocumented
  7201. // 61490 - maximize thru double click - undocumented
  7202. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  7203. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  7204. {
  7205. SysResizing(Cmd);
  7206. }
  7207. TForm::Dispatch(&Message);
  7208. }
  7209. //---------------------------------------------------------------------------
  7210. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  7211. {
  7212. AppLog(L"Windows session end query");
  7213. // We were actually never able to make ENDSESSION_CRITICAL happen.
  7214. // Also there no point returning TRUE as we are not able to
  7215. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  7216. // Hence the process termination might be safer :)
  7217. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  7218. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  7219. {
  7220. Message.Result = FALSE;
  7221. }
  7222. else
  7223. {
  7224. Message.Result = TRUE;
  7225. }
  7226. // Do not call default handling as that triggers OnCloseQuery,
  7227. // where our implementation will popup confirmation dialogs, what we do not want,
  7228. // as per Vista guidelines:
  7229. // https://learn.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  7230. }
  7231. //---------------------------------------------------------------------------
  7232. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  7233. {
  7234. AppLog(L"Windows session end");
  7235. if (Message.EndSession && IsApplicationMinimized())
  7236. {
  7237. // WORKAROUND
  7238. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  7239. // when it receives WM_ENDSESSION,
  7240. // but that sometimes (particularly when application is minimized) cause crashes.
  7241. // Crash popups message that blocks log off.
  7242. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  7243. // so we call ExitProcess() immediately, not even trying to cleanup.
  7244. // It still causes beep, so there's likely some popup, but it does not block
  7245. // log off.
  7246. ExitProcess(0);
  7247. }
  7248. TForm::Dispatch(&Message);
  7249. }
  7250. #ifdef _DEBUG
  7251. //---------------------------------------------------------------------------
  7252. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  7253. {
  7254. TForm::Dispatch(&Message);
  7255. }
  7256. #endif
  7257. //---------------------------------------------------------------------------
  7258. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  7259. {
  7260. }
  7261. //---------------------------------------------------------------------------
  7262. void __fastcall TCustomScpExplorerForm::DoShow()
  7263. {
  7264. // Called from TCustomScpExplorerForm::CMShowingChanged
  7265. // only now are the controls resized finally, so the size constraints
  7266. // will not conflict with possibly very small window size
  7267. RestoreFormParams();
  7268. // This indicates that the form was rescaled after parameters were loaded and
  7269. // as most probably the parameters were actually saved with the current form scaling
  7270. // (windows was the last time likely closed on the same monitor, where it is starting now),
  7271. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  7272. // and no rounding problems will occur.
  7273. // See also RestoreForm.
  7274. // (we should be safe to call RestoreParams unconditionally)
  7275. if (PixelsPerInch != Screen->PixelsPerInch)
  7276. {
  7277. RestoreParams();
  7278. }
  7279. FixControlsPlacement();
  7280. if (Position == poDefaultPosOnly)
  7281. {
  7282. CutFormToDesktop(this);
  7283. }
  7284. TForm::DoShow();
  7285. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  7286. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  7287. // This was previously in NeedSession, where other related code is.
  7288. // But that is called from CMShowingChanged, when the window is already visible and the local-local window state
  7289. // unpleasantly shows briefly.
  7290. if ((ManagedSession == NULL) &&
  7291. !WinConfiguration->ShowLoginWhenNoSession &&
  7292. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  7293. // This detects if workspace was saved the last time the main widow was closed
  7294. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  7295. {
  7296. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false, true);
  7297. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  7298. }
  7299. // Before main window displays
  7300. if (ManagedSession == NULL)
  7301. {
  7302. StartingWithoutSession();
  7303. }
  7304. UpdatePixelsPerInchMainWindowCounter();
  7305. FShowing = true;
  7306. }
  7307. //---------------------------------------------------------------------------
  7308. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  7309. {
  7310. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  7311. }
  7312. //---------------------------------------------------------------------------
  7313. void __fastcall TCustomScpExplorerForm::StartingWithoutSession()
  7314. {
  7315. SessionListChanged();
  7316. InitStatusBar();
  7317. UpdateControls();
  7318. }
  7319. //---------------------------------------------------------------------------
  7320. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  7321. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  7322. TNotifyEvent OnBalloonClick, TObject * UserData)
  7323. {
  7324. bool Do;
  7325. UnicodeString Message;
  7326. if (E == NULL)
  7327. {
  7328. Message = Str;
  7329. Do = true;
  7330. }
  7331. else
  7332. {
  7333. Do = ExceptionMessage(E, Message);
  7334. }
  7335. if (Do && WinConfiguration->BalloonNotifications)
  7336. {
  7337. UnicodeString Title;
  7338. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  7339. {
  7340. Message = TrimLeft(Message);
  7341. }
  7342. else
  7343. {
  7344. Message = UnformatMessage(Message);
  7345. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  7346. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  7347. Title = LoadResourceString(Captions[Type]);
  7348. if (Terminal != NULL)
  7349. {
  7350. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal->PrimaryTerminal));
  7351. Title = TTerminalManager::Instance()->GetSessionTitle(Session, true) + TitleSeparator + Title;
  7352. }
  7353. }
  7354. if (Seconds == 0)
  7355. {
  7356. Seconds = WinConfiguration->NotificationsTimeout;
  7357. }
  7358. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  7359. }
  7360. }
  7361. //---------------------------------------------------------------------------
  7362. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  7363. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  7364. UnicodeString HelpKeyword, const TMessageParams * Params,
  7365. TTerminal * Terminal)
  7366. {
  7367. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  7368. (FOnFeedSynchronizeError != NULL)) &&
  7369. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  7370. {
  7371. if (FOnFeedSynchronizeError != NULL)
  7372. {
  7373. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  7374. }
  7375. else
  7376. {
  7377. DebugAssert(FErrorList != NULL);
  7378. TStringList * MoreMessagesCopy = NULL;
  7379. if (MoreMessages)
  7380. {
  7381. MoreMessagesCopy = new TStringList();
  7382. MoreMessagesCopy->Assign(MoreMessages);
  7383. }
  7384. FErrorList->AddObject(Message, MoreMessagesCopy);
  7385. }
  7386. PopupTrayBalloon(Terminal, Message, Type);
  7387. return ContinueAnswer(Answers);
  7388. }
  7389. else
  7390. {
  7391. bool UseBalloon = FTrayIcon->Visible;
  7392. if (UseBalloon)
  7393. {
  7394. PopupTrayBalloon(Terminal, Message, Type);
  7395. }
  7396. unsigned int Result;
  7397. try
  7398. {
  7399. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  7400. }
  7401. __finally
  7402. {
  7403. // cancel only balloon we popped up, otherwise we may cancel notification
  7404. // balloon that was there before the message dialog
  7405. // (such as "dd confirmation opt in balloon)
  7406. if (UseBalloon)
  7407. {
  7408. FTrayIcon->CancelBalloon();
  7409. }
  7410. }
  7411. return Result;
  7412. }
  7413. }
  7414. //---------------------------------------------------------------------------
  7415. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  7416. TTerminal * Terminal, Exception * E)
  7417. {
  7418. if (FTrayIcon->Visible)
  7419. {
  7420. PopupTrayBalloon(Terminal, L"", qtError, E);
  7421. }
  7422. // particularly prevent opening new session from jump list,
  7423. // while exception is shown
  7424. NonVisualDataModule->StartBusy();
  7425. try
  7426. {
  7427. ShowExtendedExceptionEx(Terminal, E);
  7428. }
  7429. __finally
  7430. {
  7431. NonVisualDataModule->EndBusy();
  7432. FTrayIcon->CancelBalloon();
  7433. }
  7434. }
  7435. //---------------------------------------------------------------------------
  7436. void __fastcall TCustomScpExplorerForm::SessionReady()
  7437. {
  7438. InitStatusBar();
  7439. // cannot rely on active page being page for active terminal,
  7440. // as it can happen that active page is the "new session" page
  7441. // (e.g. when reconnecting active terminal, while login dialog
  7442. // invoked from "new session" page is modal)
  7443. int ActiveSessionIndex = TTerminalManager::Instance()->ActiveSessionIndex;
  7444. UpdateSessionTab(SessionsPageControl->Pages[ActiveSessionIndex]);
  7445. }
  7446. //---------------------------------------------------------------------------
  7447. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  7448. TTerminal * Terminal, Exception * E)
  7449. {
  7450. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  7451. if (!Terminal->Active)
  7452. {
  7453. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  7454. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  7455. {
  7456. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  7457. }
  7458. }
  7459. }
  7460. //---------------------------------------------------------------------------
  7461. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  7462. UnicodeString Message, TQueryType Type,
  7463. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  7464. {
  7465. if ((E == NULL) ||
  7466. ExceptionMessage(E, Message))
  7467. {
  7468. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  7469. if (Important)
  7470. {
  7471. Seconds *= 5;
  7472. }
  7473. UnicodeString NoteMessage(UnformatMessage(Message));
  7474. if (Terminal != NULL)
  7475. {
  7476. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  7477. NoteMessage = FORMAT(L"%s: %s",
  7478. (TTerminalManager::Instance()->GetSessionTitle(Session, true), NoteMessage));
  7479. }
  7480. if (WinConfiguration->BalloonNotifications)
  7481. {
  7482. AddNote(NoteMessage);
  7483. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  7484. }
  7485. else
  7486. {
  7487. FlashOnBackground();
  7488. PostNote(NoteMessage, Seconds, OnClick, UserData);
  7489. }
  7490. }
  7491. }
  7492. //---------------------------------------------------------------------------
  7493. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  7494. {
  7495. RestoreApp();
  7496. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  7497. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  7498. !NonVisualDataModule->Busy)
  7499. {
  7500. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  7501. TTerminalManager::Instance()->ActiveSession = Terminal;
  7502. if (!ComponentVisible[fcQueueView])
  7503. {
  7504. ToggleQueueVisibility();
  7505. GoToQueue();
  7506. }
  7507. }
  7508. }
  7509. //---------------------------------------------------------------------------
  7510. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  7511. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  7512. {
  7513. UnicodeString Message;
  7514. TNotifyEvent OnClick = NULL;
  7515. TObject * UserData = NULL;
  7516. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  7517. switch (Event)
  7518. {
  7519. case qeEmptyButMonitored:
  7520. if ((ATerminal != Terminal) || QueueInvisible)
  7521. {
  7522. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  7523. OnClick = QueueEmptyNoteClicked;
  7524. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  7525. TerminalNoteData->Terminal = ATerminal;
  7526. UserData = TerminalNoteData;
  7527. }
  7528. break;
  7529. case qeEmpty:
  7530. OperationComplete(ATerminal->QueueOperationStart);
  7531. break;
  7532. case qePendingUserAction:
  7533. if ((ATerminal != Terminal) ||
  7534. (QueueInvisible && !IsQueueAutoPopup()))
  7535. {
  7536. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  7537. }
  7538. break;
  7539. default:
  7540. DebugFail();
  7541. }
  7542. if (!Message.IsEmpty())
  7543. {
  7544. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  7545. }
  7546. }
  7547. //---------------------------------------------------------------------------
  7548. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  7549. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  7550. {
  7551. if (FDDExtMapFile != NULL)
  7552. {
  7553. CloseHandle(FDDExtMapFile);
  7554. FDDExtMapFile = NULL;
  7555. }
  7556. if (WinConfiguration->DDFakeFile)
  7557. {
  7558. DDFakeFileInitDrag(FileList, Created);
  7559. }
  7560. }
  7561. //---------------------------------------------------------------------------
  7562. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  7563. {
  7564. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  7565. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  7566. {
  7567. FFakeFileDropTarget = FileName;
  7568. }
  7569. }
  7570. //---------------------------------------------------------------------------
  7571. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  7572. {
  7573. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  7574. if (!ForceDirectories(ApiPath(Result)))
  7575. {
  7576. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  7577. }
  7578. FileSetAttr(ApiPath(Result), faHidden);
  7579. return Result;
  7580. }
  7581. //---------------------------------------------------------------------------
  7582. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  7583. bool & Created)
  7584. {
  7585. FFakeFileDropTarget = UnicodeString();
  7586. FDragFakeDirectory = CreateFakeTransferDirectory();
  7587. FileList->AddItem(NULL, FDragFakeDirectory);
  7588. Created = true;
  7589. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  7590. {
  7591. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  7592. }
  7593. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  7594. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  7595. {
  7596. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7597. TDragExtCommStruct* CommStruct;
  7598. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7599. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7600. DebugAssert(CommStruct != NULL);
  7601. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  7602. CommStruct->Dragging = true;
  7603. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  7604. LENOF(CommStruct->DropDest));
  7605. NULL_TERMINATE(CommStruct->DropDest);
  7606. UnmapViewOfFile(CommStruct);
  7607. }
  7608. }
  7609. //---------------------------------------------------------------------------
  7610. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  7611. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  7612. {
  7613. bool Result;
  7614. DebugAssert(!IsLocalBrowserMode());
  7615. if (Sender == RemoteDirView)
  7616. {
  7617. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  7618. }
  7619. else
  7620. {
  7621. DebugAssert(Sender == RemoteDriveView);
  7622. TStrings * FileList = RemoteDriveView->DragFileList();
  7623. try
  7624. {
  7625. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  7626. }
  7627. __finally
  7628. {
  7629. delete FileList;
  7630. }
  7631. }
  7632. if (FDDTargetControl == RemoteDriveView)
  7633. {
  7634. RemoteDriveView->UpdateDropTarget();
  7635. }
  7636. // foRemoteMove happens when file/dir is dragged within the remote tree view
  7637. // or from tree view to dir view.
  7638. // foMove happens when file/dir is dragged from remote tree view outside of
  7639. // application via dragex
  7640. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  7641. (DropSourceControl == RemoteDriveView))
  7642. {
  7643. RemoteDriveView->UpdateDropSource();
  7644. }
  7645. return Result;
  7646. }
  7647. //---------------------------------------------------------------------------
  7648. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  7649. {
  7650. DebugAssert(!IsLocalBrowserMode());
  7651. // This also handles drops of remote files to queue.
  7652. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  7653. SAFE_DESTROY(FDDFileList);
  7654. if (!FFakeFileDropTarget.IsEmpty())
  7655. {
  7656. RemoveDir(ApiPath(FFakeFileDropTarget));
  7657. }
  7658. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  7659. {
  7660. try
  7661. {
  7662. TDragResult DDResult = (Sender == RemoteDirView) ?
  7663. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  7664. // Focus is moved to the target application,
  7665. // but as we are going to present the UI, we need to steal the focus back.
  7666. // This most likely won't work though (windows does not allow application
  7667. // to steal focus most of the time)
  7668. Application->BringToFront();
  7669. // On older version of Windows we never got drMove here, see also comment below.
  7670. // On Windows 10, we get the "move".
  7671. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  7672. {
  7673. UnicodeString TargetDirectory;
  7674. TFileOperation Operation;
  7675. // drInvalid may mean drMove, see comment below
  7676. switch (DDResult)
  7677. {
  7678. case drCopy:
  7679. Operation = foCopy;
  7680. break;
  7681. case drMove:
  7682. Operation = foMove;
  7683. break;
  7684. default:
  7685. DebugFail();
  7686. case drInvalid:
  7687. // prefer "copy" for safety
  7688. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7689. break;
  7690. }
  7691. TTransferOperationParam Param;
  7692. UnicodeString CounterName;
  7693. bool ForceQueue;
  7694. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7695. {
  7696. // we get drInvalid both if d&d was intercepted by ddext,
  7697. // and when users drops on no-drop location.
  7698. // we tell the difference by existence of response from ddext,
  7699. // so we ignore absence of response in this case
  7700. if (DDResult != drInvalid)
  7701. {
  7702. // here we know that the extension is installed,
  7703. // as it is checked as soon as drag&drop starts from
  7704. // RemoteFileControlDDCreateDragFileList
  7705. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7706. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7707. {
  7708. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7709. }
  7710. else
  7711. {
  7712. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7713. }
  7714. }
  7715. }
  7716. else
  7717. {
  7718. // download using fake file
  7719. Param.Temp = false;
  7720. Param.DragDrop = true;
  7721. if (ForceQueue)
  7722. {
  7723. Param.Queue = asOn;
  7724. }
  7725. if (Sender == RemoteDirView)
  7726. {
  7727. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7728. }
  7729. if (RemoteFileControlFileOperation(Sender, Operation,
  7730. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7731. {
  7732. Configuration->Usage->Inc(CounterName);
  7733. }
  7734. }
  7735. }
  7736. }
  7737. __finally
  7738. {
  7739. CloseHandle(FDDExtMapFile);
  7740. FDDExtMapFile = NULL;
  7741. delete FDragFakeMonitors;
  7742. FDragFakeMonitors = NULL;
  7743. RemoveDir(ApiPath(FDragFakeDirectory));
  7744. FDragFakeDirectory = L"";
  7745. FFakeFileDropTarget = UnicodeString();
  7746. }
  7747. }
  7748. if (FDragDropSshTerminate.get() != NULL)
  7749. {
  7750. FDragDropSshTerminate->Rethrow();
  7751. }
  7752. }
  7753. //---------------------------------------------------------------------------
  7754. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7755. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7756. {
  7757. // Remember drop effect so we know (when user drops files), if we copy or move
  7758. FLastDropEffect = dwEffect;
  7759. }
  7760. //---------------------------------------------------------------------------
  7761. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7762. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7763. {
  7764. bool Result;
  7765. if (FDDTargetControl == QueueView3)
  7766. {
  7767. Directory = DefaultDownloadTargetDirectory();
  7768. Result = true;
  7769. CounterName = L"DownloadsDragDropQueue";
  7770. ForceQueue = true;
  7771. }
  7772. else if (!FFakeFileDropTarget.IsEmpty())
  7773. {
  7774. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7775. Result = true;
  7776. ForceQueue = false;
  7777. CounterName = L"DownloadsDragDropFakeFile";
  7778. }
  7779. else
  7780. {
  7781. ForceQueue = false;
  7782. Enabled = false;
  7783. try
  7784. {
  7785. int Timer = 0;
  7786. Result = false;
  7787. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7788. {
  7789. {
  7790. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7791. TDragExtCommStruct* CommStruct;
  7792. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7793. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7794. DebugAssert(CommStruct != NULL);
  7795. Result = !CommStruct->Dragging;
  7796. if (Result)
  7797. {
  7798. Directory = ExtractFilePath(CommStruct->DropDest);
  7799. CounterName = L"DownloadsDragDropExternalExt";
  7800. }
  7801. UnmapViewOfFile(CommStruct);
  7802. }
  7803. if (!Result)
  7804. {
  7805. Sleep(50);
  7806. Timer += 50;
  7807. Application->ProcessMessages();
  7808. }
  7809. }
  7810. }
  7811. __finally
  7812. {
  7813. Enabled = true;
  7814. }
  7815. }
  7816. return Result;
  7817. }
  7818. //---------------------------------------------------------------------------
  7819. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7820. const UnicodeString TempDir, int SecDelay)
  7821. {
  7822. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7823. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7824. if (FDelayedDeletionTimer == NULL)
  7825. {
  7826. DebugAssert(HandleAllocated());
  7827. FDelayedDeletionTimer = new TTimer(this);
  7828. FDelayedDeletionTimer->Interval = 10000;
  7829. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7830. }
  7831. else
  7832. {
  7833. FDelayedDeletionTimer->Enabled = true;
  7834. }
  7835. }
  7836. //---------------------------------------------------------------------------
  7837. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7838. {
  7839. DebugAssert(FDelayedDeletionList != NULL);
  7840. TDateTime N = Now();
  7841. TDateTime Alert;
  7842. UnicodeString Directory;
  7843. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7844. {
  7845. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7846. if ((N >= Alert) || (Sender == NULL))
  7847. {
  7848. Directory = FDelayedDeletionList->Strings[Index];
  7849. if (RecursiveDeleteFile(ExcludeTrailingBackslash(Directory)))
  7850. {
  7851. FDelayedDeletionList->Delete(Index);
  7852. }
  7853. }
  7854. }
  7855. if (FDelayedDeletionList->Count == 0)
  7856. {
  7857. FDelayedDeletionTimer->Enabled = false;
  7858. }
  7859. }
  7860. //---------------------------------------------------------------------------
  7861. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7862. {
  7863. DebugAssert(!IsLocalBrowserMode());
  7864. if (IsFileControl(FDDTargetControl, osRemote) ||
  7865. (FDDTargetControl == SessionsPageControl))
  7866. {
  7867. TManagedTerminal * TargetTerminal = NULL;
  7868. TFileOperation Operation = foNone;
  7869. if (FDDTargetControl == SessionsPageControl)
  7870. {
  7871. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7872. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7873. // do not allow dropping on local-local, disconnected and the "+" tab (see also SessionsDDProcessDropped)
  7874. TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  7875. if (IsActiveTerminal(TargetTerminal) && DebugAlwaysTrue(!TargetTerminal->LocalBrowser))
  7876. {
  7877. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7878. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7879. {
  7880. Operation = foRemoteMove;
  7881. }
  7882. else
  7883. {
  7884. Operation = foRemoteCopy;
  7885. }
  7886. }
  7887. }
  7888. else
  7889. {
  7890. if (FLastDropEffect == DROPEFFECT_MOVE)
  7891. {
  7892. Operation = foRemoteMove;
  7893. }
  7894. else if (FLastDropEffect == DROPEFFECT_COPY)
  7895. {
  7896. Operation = foRemoteCopy;
  7897. }
  7898. }
  7899. if (Operation != foNone)
  7900. {
  7901. RemoteFileControlFileOperation(DropSourceControl,
  7902. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7903. }
  7904. // abort drag&drop
  7905. Abort();
  7906. }
  7907. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7908. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7909. (FDDTargetControl != QueueView3))
  7910. {
  7911. DebugAssert(!FDragTempDir.IsEmpty());
  7912. TTransferType Type;
  7913. UnicodeString TempDir = FDragTempDir;
  7914. // We clear FDragTempDir before calling
  7915. // just in case it fail (raises exception)
  7916. FDragTempDir = L"";
  7917. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7918. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7919. // empty directory parameter means temp directory -> don't display it!
  7920. UnicodeString TargetDir = L"";
  7921. int Options = 0;
  7922. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7923. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7924. {
  7925. Abort();
  7926. }
  7927. // TargetDir is set when dropped on local file control
  7928. // (this was workaround for legacy dirview event handling, now it should be
  7929. // made prettier)
  7930. if (TargetDir.IsEmpty())
  7931. {
  7932. TargetDir = TempDir;
  7933. if (ForceDirectories(ApiPath(TargetDir)))
  7934. {
  7935. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7936. FPendingTempSpaceWarn = true;
  7937. try
  7938. {
  7939. FDragDropOperation = true;
  7940. int Params = cpTemporary |
  7941. (Type == ttMove ? cpDelete : 0);
  7942. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7943. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7944. }
  7945. __finally
  7946. {
  7947. FDragDropOperation = false;
  7948. FPendingTempSpaceWarn = false;
  7949. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7950. }
  7951. }
  7952. else
  7953. {
  7954. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7955. }
  7956. }
  7957. }
  7958. }
  7959. //---------------------------------------------------------------------------
  7960. void __fastcall TCustomScpExplorerForm::DDDownload(
  7961. TStrings * FilesToCopy, const UnicodeString & TargetDir, TCopyParamType * CopyParam, int Params)
  7962. {
  7963. DebugAssert(!IsLocalBrowserMode());
  7964. TAutoBatch AutoBatch(this);
  7965. CopyParam->IncludeFileMask.SetRoots(TargetDir, FilesToCopy);
  7966. UpdateCopyParamCounters(*CopyParam);
  7967. FMoveToQueue = false;
  7968. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7969. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7970. {
  7971. RemoteDriveView->UpdateDropSource();
  7972. }
  7973. }
  7974. //---------------------------------------------------------------------------
  7975. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7976. {
  7977. public:
  7978. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7979. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7980. {
  7981. }
  7982. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7983. {
  7984. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7985. TDataObjectFilesEx::AllowData(FormatEtc);
  7986. }
  7987. };
  7988. //---------------------------------------------------------------------------
  7989. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7990. TObject * Sender, TDataObject *& DataObject)
  7991. {
  7992. if (FDDExtMapFile != NULL)
  7993. {
  7994. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7995. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7996. {
  7997. Abort();
  7998. }
  7999. if (FileList->Count > 0)
  8000. {
  8001. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  8002. if (!FilesObject->IsValid(true, true))
  8003. {
  8004. FilesObject->_Release();
  8005. }
  8006. else
  8007. {
  8008. DataObject = FilesObject;
  8009. }
  8010. }
  8011. }
  8012. }
  8013. //---------------------------------------------------------------------------
  8014. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  8015. {
  8016. DebugFail();
  8017. }
  8018. //---------------------------------------------------------------------------
  8019. void __fastcall TCustomScpExplorerForm::GoToTree()
  8020. {
  8021. ComponentVisible[fcRemoteTree] = true;
  8022. DriveView(osRemote)->SetFocus();
  8023. }
  8024. //---------------------------------------------------------------------------
  8025. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  8026. TPanelExport Export)
  8027. {
  8028. TCustomDirView * DirView = this->DirView(Side);
  8029. std::unique_ptr<TStrings> ExportData(new TStringList());
  8030. switch (Export)
  8031. {
  8032. case pePath:
  8033. ExportData->Add(DirView->PathName);
  8034. break;
  8035. case peFileList:
  8036. case peFullFileList:
  8037. {
  8038. bool FullPath = (Export == peFullFileList);
  8039. DirView->CreateFileList(false, FullPath, ExportData.get());
  8040. for (int Index = 0; Index < ExportData->Count; Index++)
  8041. {
  8042. if (ExportData->Strings[Index].Pos(L" ") > 0)
  8043. {
  8044. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  8045. }
  8046. }
  8047. }
  8048. break;
  8049. default:
  8050. DebugFail();
  8051. }
  8052. return ExportData.release();
  8053. }
  8054. //---------------------------------------------------------------------------
  8055. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  8056. TPanelExport Export, TPanelExportDestination Destination)
  8057. {
  8058. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  8059. PanelExportStore(Side, Export, Destination, ExportData.get());
  8060. }
  8061. //---------------------------------------------------------------------------
  8062. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  8063. TPanelExport /*Export*/, TPanelExportDestination Destination,
  8064. TStrings * ExportData)
  8065. {
  8066. if (Destination == pedClipboard)
  8067. {
  8068. TInstantOperationVisualizer Visualizer;
  8069. CopyToClipboard(ExportData);
  8070. }
  8071. else
  8072. {
  8073. DebugFail();
  8074. }
  8075. }
  8076. //---------------------------------------------------------------------------
  8077. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  8078. {
  8079. TCustomDirView * DirView = this->DirView(Side);
  8080. UnicodeString Mask = DirView->Mask;
  8081. if (DoFilterMaskDialog(DirView, Mask))
  8082. {
  8083. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  8084. Configuration->Usage->Inc(L"Filters");
  8085. }
  8086. }
  8087. //---------------------------------------------------------------------------
  8088. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  8089. {
  8090. return FQueueController->DefaultOperation();
  8091. }
  8092. //---------------------------------------------------------------------------
  8093. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  8094. TQueueOperation Operation, void ** Param)
  8095. {
  8096. switch (Operation)
  8097. {
  8098. case qoPreferences:
  8099. return true;
  8100. case qoGoTo:
  8101. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  8102. case qoOnceEmpty:
  8103. return IsAnythingQueued();
  8104. default:
  8105. return FQueueController->AllowOperation(Operation, Param);
  8106. }
  8107. }
  8108. //---------------------------------------------------------------------------
  8109. void __fastcall TCustomScpExplorerForm::GoToQueue()
  8110. {
  8111. if (DebugAlwaysTrue(QueueView3->Visible))
  8112. {
  8113. QueueView3->SetFocus();
  8114. }
  8115. }
  8116. //---------------------------------------------------------------------------
  8117. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  8118. TQueueOperation Operation, void * Param)
  8119. {
  8120. if (Operation == qoGoTo)
  8121. {
  8122. GoToQueue();
  8123. }
  8124. else if (Operation == qoPreferences)
  8125. {
  8126. PreferencesDialog(pmQueue);
  8127. }
  8128. else
  8129. {
  8130. FQueueController->ExecuteOperation(Operation, Param);
  8131. }
  8132. }
  8133. //---------------------------------------------------------------------------
  8134. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  8135. {
  8136. return (Queue != NULL) && Queue->Enabled;
  8137. }
  8138. //---------------------------------------------------------------------------
  8139. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  8140. {
  8141. DebugAssert(Queue != NULL);
  8142. if (Queue != NULL)
  8143. {
  8144. Queue->Enabled = !Queue->Enabled;
  8145. }
  8146. }
  8147. //---------------------------------------------------------------------------
  8148. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  8149. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  8150. {
  8151. FQueueActedItem = QueueView3->ItemFocused;
  8152. }
  8153. //---------------------------------------------------------------------------
  8154. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  8155. {
  8156. return TopDock->Height + (MessageDock->Visible ? MessageDock->Height : 0) + QueueSplitter->Height;
  8157. }
  8158. //---------------------------------------------------------------------------
  8159. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  8160. {
  8161. return
  8162. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  8163. (QueueDock->Visible ? QueueDock->Height : 0) +
  8164. (QueueLabel->Visible ? QueueLabel->Height : 0);
  8165. }
  8166. //---------------------------------------------------------------------------
  8167. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  8168. {
  8169. return ScaleByTextHeight(this, 48);
  8170. }
  8171. //---------------------------------------------------------------------------
  8172. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  8173. TObject * /*Sender*/, int & NewSize, bool & Accept)
  8174. {
  8175. // when queue is hidden by double-clicking splitter, stray attempt to
  8176. // resize the panel with strange value arrives, make sure it is ignored
  8177. if (ComponentVisible[fcQueueView])
  8178. {
  8179. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  8180. if (NewSize > MaxHeightLimit)
  8181. {
  8182. NewSize = MaxHeightLimit;
  8183. }
  8184. int MinHeightLimit =
  8185. GetStaticQueuePanelComponentsHeight() +
  8186. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  8187. GetMinQueueViewHeight();
  8188. if (NewSize < MinHeightLimit)
  8189. {
  8190. NewSize = MinHeightLimit;
  8191. }
  8192. }
  8193. else
  8194. {
  8195. Accept = false;
  8196. }
  8197. }
  8198. //---------------------------------------------------------------------------
  8199. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  8200. {
  8201. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  8202. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  8203. if (QueueViewHeight < GetMinQueueViewHeight())
  8204. {
  8205. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  8206. }
  8207. }
  8208. //---------------------------------------------------------------------------
  8209. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  8210. TDragObject *& /*DragObject*/)
  8211. {
  8212. FQueueActedItem = QueueView3->ItemFocused;
  8213. FQueueScrollOnDragOver->StartDrag();
  8214. }
  8215. //---------------------------------------------------------------------------
  8216. void __fastcall TCustomScpExplorerForm::QueueView3EndDrag(
  8217. TObject *, TObject * DebugUsedArg(Target), int DebugUsedArg(X), int DebugUsedArg(Y))
  8218. {
  8219. FQueueScrollOnDragOver->EndDrag();
  8220. }
  8221. //---------------------------------------------------------------------------
  8222. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  8223. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  8224. {
  8225. Accept = true;
  8226. if (Source == QueueView3)
  8227. {
  8228. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  8229. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  8230. if (Accept)
  8231. {
  8232. TQueueItemProxy * QueueItem;
  8233. TQueueItemProxy * DestQueueItem;
  8234. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  8235. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  8236. Accept = (QueueItem != DestQueueItem) &&
  8237. (QueueItem->Status == TQueueItem::qsPending) &&
  8238. (DestQueueItem->Status == TQueueItem::qsPending);
  8239. }
  8240. FQueueScrollOnDragOver->DragOver(TPoint(X, Y));
  8241. }
  8242. }
  8243. //---------------------------------------------------------------------------
  8244. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  8245. TObject * /*Source*/, int /*X*/, int /*Y*/)
  8246. {
  8247. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  8248. {
  8249. TQueueItemProxy * QueueItem;
  8250. TQueueItemProxy * DestQueueItem;
  8251. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  8252. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  8253. QueueItem->Move(DestQueueItem);
  8254. }
  8255. }
  8256. //---------------------------------------------------------------------------
  8257. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  8258. {
  8259. if ((QueueView3->ItemFocused == NULL) &&
  8260. (QueueView3->Items->Count > 0))
  8261. {
  8262. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  8263. }
  8264. QueueLabelUpdateStatus();
  8265. }
  8266. //---------------------------------------------------------------------------
  8267. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  8268. {
  8269. QueueLabelUpdateStatus();
  8270. }
  8271. //---------------------------------------------------------------------------
  8272. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  8273. {
  8274. QueueLabel->UpdateStatus();
  8275. }
  8276. //---------------------------------------------------------------------------
  8277. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  8278. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  8279. {
  8280. if (Selected)
  8281. {
  8282. NonVisualDataModule->UpdateNonVisibleActions();
  8283. }
  8284. }
  8285. //---------------------------------------------------------------------------
  8286. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  8287. {
  8288. TDragDropFilesEx * Result = NULL;
  8289. if (Sender == SessionsPageControl)
  8290. {
  8291. Result = FSessionsDragDropFilesEx;
  8292. }
  8293. else if (Sender == QueueView3)
  8294. {
  8295. Result = FQueueDragDropFilesEx;
  8296. }
  8297. else
  8298. {
  8299. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8300. if (DirView != NULL)
  8301. {
  8302. Result = DirView->DragDropFilesEx;
  8303. }
  8304. else
  8305. {
  8306. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  8307. if (DriveView != NULL)
  8308. {
  8309. Result = DriveView->DragDropFilesEx;
  8310. }
  8311. }
  8312. }
  8313. DebugAssert(Result != NULL);
  8314. return Result;
  8315. }
  8316. //---------------------------------------------------------------------------
  8317. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  8318. {
  8319. return (DView->SelCount == DView->FilesCount);
  8320. }
  8321. //---------------------------------------------------------------------------
  8322. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  8323. {
  8324. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  8325. }
  8326. //---------------------------------------------------------------------------
  8327. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  8328. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  8329. {
  8330. DebugAssert(!IsLocalBrowserMode());
  8331. TFileOperation Operation;
  8332. switch (Effect)
  8333. {
  8334. case DROPEFFECT_MOVE:
  8335. Operation = foMove;
  8336. break;
  8337. case DROPEFFECT_COPY:
  8338. // occures on WinXP (reported by user)
  8339. default:
  8340. Operation = foCopy;
  8341. break;
  8342. };
  8343. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  8344. // see a comment in TUnixDirView::PerformItemDragDropOperation
  8345. if (DragDropFilesEx->FileList->Count > 0)
  8346. {
  8347. TStrings * FileList = new TStringList();
  8348. try
  8349. {
  8350. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  8351. {
  8352. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  8353. }
  8354. FDragDropOperation = true;
  8355. TTransferOperationParam Param;
  8356. Param.TargetDirectory = TargetPath;
  8357. // upload, no temp dirs
  8358. Param.Temp = false;
  8359. Param.DragDrop = DragDrop;
  8360. Param.Options =
  8361. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  8362. if (ForceQueue)
  8363. {
  8364. Param.Queue = asOn;
  8365. }
  8366. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  8367. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  8368. {
  8369. if (IsFileControl(DropSourceControl, osLocal))
  8370. {
  8371. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  8372. }
  8373. else
  8374. {
  8375. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  8376. }
  8377. }
  8378. }
  8379. __finally
  8380. {
  8381. FDragDropOperation = false;
  8382. delete FileList;
  8383. }
  8384. }
  8385. }
  8386. //---------------------------------------------------------------------------
  8387. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  8388. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  8389. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  8390. {
  8391. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  8392. }
  8393. //---------------------------------------------------------------------------
  8394. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  8395. TObject * Sender, int grfKeyState, int & dwEffect)
  8396. {
  8397. DebugAssert(!IsLocalBrowserMode());
  8398. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  8399. if ((dwEffect != DROPEFFECT_NONE) &&
  8400. IsFileControl(DropSourceControl, osRemote))
  8401. {
  8402. // do not allow drop on remote panel (on free space, still allow drop on directories)
  8403. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  8404. (RemoteDirView->DropTarget == NULL))
  8405. {
  8406. dwEffect = DROPEFFECT_NONE;
  8407. }
  8408. else
  8409. {
  8410. if (dwEffect == DROPEFFECT_COPY)
  8411. {
  8412. bool MoveCapable = Terminal->IsCapable[fcRemoteMove];
  8413. // currently we support copying always (at least via temporary directory);
  8414. // remove associated checks once this all proves stable and working
  8415. bool CopyCapable = true;
  8416. // if we do not support neither of operations, there's no discussion
  8417. if (!MoveCapable && !CopyCapable)
  8418. {
  8419. dwEffect = DROPEFFECT_NONE;
  8420. }
  8421. else
  8422. {
  8423. // The default effect inside remote panel is move,
  8424. // unless we do not support it, but support copy
  8425. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  8426. {
  8427. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  8428. }
  8429. else
  8430. {
  8431. // with ctrl-down, we want copy unless it is not supported
  8432. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  8433. }
  8434. }
  8435. }
  8436. }
  8437. }
  8438. }
  8439. //---------------------------------------------------------------------------
  8440. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  8441. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  8442. {
  8443. DebugAssert(!IsLocalBrowserMode());
  8444. if (FDDTotalSize >= 0)
  8445. {
  8446. if (File->IsDirectory)
  8447. {
  8448. FDDTotalSize = -1;
  8449. }
  8450. else
  8451. {
  8452. FDDTotalSize += File->Size;
  8453. }
  8454. }
  8455. DebugAssert(!FDragTempDir.IsEmpty());
  8456. // TODO: this is quite ineffective
  8457. // TODO: what if invalid character replacement is disabled?
  8458. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  8459. UnicodeString TransferFileName;
  8460. if (Sender == RemoteDriveView)
  8461. {
  8462. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  8463. }
  8464. else
  8465. {
  8466. TransferFileName = File->FileName;
  8467. }
  8468. FDDFileList->AddObject(TransferFileName, File);
  8469. }
  8470. //---------------------------------------------------------------------------
  8471. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  8472. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  8473. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  8474. {
  8475. // sometimes we do not get DDEnd so the list is not released
  8476. SAFE_DESTROY(FDDFileList);
  8477. FDDFileList = new TStringList();
  8478. FDragTempDir = WinConfiguration->TemporaryDir();
  8479. FDDTotalSize = 0;
  8480. FDragDropSshTerminate.reset(NULL);
  8481. }
  8482. //---------------------------------------------------------------------------
  8483. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  8484. TObject * /*Sender*/, LongBool /*FEscapePressed*/, int /*grfKeyState*/,
  8485. HRESULT & Result)
  8486. {
  8487. if (Result == DRAGDROP_S_DROP)
  8488. {
  8489. try
  8490. {
  8491. GlobalDragImageList->HideDragImage();
  8492. try
  8493. {
  8494. RemoteFileControlDDTargetDrop();
  8495. }
  8496. catch(ESshTerminate & E)
  8497. {
  8498. FDragDropSshTerminate.reset(E.Clone());
  8499. }
  8500. }
  8501. catch (Exception &E)
  8502. {
  8503. // If downloading fails we need to cancel drag&drop, otherwise
  8504. // Explorer shows error
  8505. // But by the way exception probably never reach this point as
  8506. // it's catched on way.
  8507. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  8508. Result = DRAGDROP_S_CANCEL;
  8509. ShowExtendedException(Terminal, &E);
  8510. }
  8511. }
  8512. }
  8513. //---------------------------------------------------------------------------
  8514. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  8515. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  8516. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  8517. {
  8518. TFileMasks::TParams MaskParams;
  8519. MaskParams.Size = Size;
  8520. MaskParams.Modification = Modification;
  8521. // this does not re-parse the mask if it is the same as the last time
  8522. FDirViewMatchMask = Masks;
  8523. bool ImplicitMatch;
  8524. Matches =
  8525. // Local and RecurseInclude parameters have no effect as there's no path.
  8526. // This should use potential MatchesFileName overload with ImplicitMatch argument.
  8527. FDirViewMatchMask.Matches(FileName, false, Directory, &MaskParams, true, ImplicitMatch) &&
  8528. (AllowImplicitMatches || !ImplicitMatch);
  8529. }
  8530. //---------------------------------------------------------------------------
  8531. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  8532. TObject * Sender, TListItem * Item, WORD & Indexes)
  8533. {
  8534. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  8535. if (GetPartialFileExtLen(DirView->ItemFileName(Item)) > 0)
  8536. {
  8537. Indexes |= oiPartial;
  8538. }
  8539. }
  8540. //---------------------------------------------------------------------------
  8541. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  8542. {
  8543. return
  8544. DirViewEnabled(osCurrent) &&
  8545. DirView(osCurrent)->CanPasteFromClipBoard();
  8546. }
  8547. //---------------------------------------------------------------------------
  8548. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  8549. {
  8550. bool Result = false;
  8551. if (CanPasteToDirViewFromClipBoard())
  8552. {
  8553. Result = true;
  8554. }
  8555. else
  8556. {
  8557. UnicodeString ClipboardText;
  8558. if (NonEmptyTextFromClipboard(ClipboardText) &&
  8559. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  8560. {
  8561. if (StoredSessions->IsUrl(ClipboardText))
  8562. {
  8563. Result = true;
  8564. }
  8565. else
  8566. {
  8567. Result = DirViewEnabled(osCurrent);
  8568. }
  8569. }
  8570. }
  8571. return Result;
  8572. }
  8573. //---------------------------------------------------------------------------
  8574. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  8575. {
  8576. // Pasting to any local panel is handled in TScpCommanderForm::PasteFromClipBoard()
  8577. if (DoesClipboardContainOurFiles())
  8578. {
  8579. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  8580. {
  8581. DebugAssert(!IsLocalBrowserMode());
  8582. TTerminalManager * Manager = TTerminalManager::Instance();
  8583. TTerminal * TargetTerminal = Manager->ActiveTerminal;
  8584. Manager->ActiveSession = FClipboardTerminal;
  8585. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TargetTerminal);
  8586. }
  8587. }
  8588. else if (CanPasteToDirViewFromClipBoard())
  8589. {
  8590. DirView(osCurrent)->PasteFromClipBoard();
  8591. }
  8592. else
  8593. {
  8594. UnicodeString ClipboardText;
  8595. if (NonEmptyTextFromClipboard(ClipboardText))
  8596. {
  8597. if (StoredSessions->IsUrl(ClipboardText))
  8598. {
  8599. NewSession(ClipboardText);
  8600. }
  8601. else
  8602. {
  8603. DirView(osCurrent)->Path = ClipboardText;
  8604. }
  8605. }
  8606. }
  8607. }
  8608. //---------------------------------------------------------------------------
  8609. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  8610. {
  8611. // TBD
  8612. }
  8613. //---------------------------------------------------------------------------
  8614. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  8615. {
  8616. TCustomDirView * ADirView = DirView(Side);
  8617. ADirView->SelectAll(Mode);
  8618. ADirView->SetFocus();
  8619. }
  8620. //---------------------------------------------------------------------------
  8621. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  8622. {
  8623. TCustomDirView * ADirView = DirView(Side);
  8624. TFileFilter Filter;
  8625. DefaultFileFilter(Filter);
  8626. if (DoSelectMaskDialog(ADirView, Select, Filter))
  8627. {
  8628. Configuration->Usage->Inc(L"MaskSelections");
  8629. ADirView->SelectFiles(Filter, Select);
  8630. ADirView->SetFocus();
  8631. }
  8632. }
  8633. //---------------------------------------------------------------------------
  8634. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  8635. {
  8636. TCustomDirView * ADirView = DirView(Side);
  8637. ADirView->RestoreSelectedNames();
  8638. ADirView->SetFocus();
  8639. }
  8640. //---------------------------------------------------------------------------
  8641. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  8642. {
  8643. TCustomDirView * CurrentDirView = DirView(osCurrent);
  8644. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  8645. {
  8646. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  8647. UnicodeString Ext;
  8648. if (!IsSideLocalBrowser(osCurrent))
  8649. {
  8650. Ext = UnixExtractFileExt(FileName);
  8651. }
  8652. else
  8653. {
  8654. Ext = ExtractFileExt(FileName);
  8655. }
  8656. if (Ext.IsEmpty())
  8657. {
  8658. Ext = L".";
  8659. }
  8660. TFileFilter Filter;
  8661. Filter.Masks = FORMAT(L"*%s", (Ext));
  8662. Filter.Directories = false;
  8663. CurrentDirView->SelectFiles(Filter, Select);
  8664. }
  8665. }
  8666. //---------------------------------------------------------------------------
  8667. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  8668. const TStatusFileInfo & FileInfo, TOperationSide Side)
  8669. {
  8670. UnicodeString Result;
  8671. if (FIncrementalSearchState.Searching && (Side == GetSide(osCurrent)))
  8672. {
  8673. Result = FormatIncrementalSearchStatus(FIncrementalSearchState);
  8674. }
  8675. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  8676. {
  8677. // noop
  8678. }
  8679. else
  8680. {
  8681. Result =
  8682. FMTLOAD(FILE_INFO_FORMAT,
  8683. (FormatBytes(FileInfo.SelectedSize),
  8684. FormatBytes(FileInfo.FilesSize),
  8685. FormatNumber(FileInfo.SelectedCount),
  8686. FormatNumber(FileInfo.FilesCount)));
  8687. }
  8688. return Result;
  8689. }
  8690. //---------------------------------------------------------------------------
  8691. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8692. TTBXStatusPanel * Panel, TOperationSide Side)
  8693. {
  8694. if (Panel->Index == 1)
  8695. {
  8696. ToggleShowHiddenFiles();
  8697. }
  8698. else if (Panel->Index == 2)
  8699. {
  8700. Filter(Side);
  8701. }
  8702. }
  8703. //---------------------------------------------------------------------------
  8704. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8705. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8706. {
  8707. DebugAssert(!StatusBar->SimplePanel);
  8708. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8709. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8710. }
  8711. //---------------------------------------------------------------------------
  8712. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8713. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8714. {
  8715. DebugAssert(StatusBar->Panels->Count >= 3);
  8716. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8717. if (FileInfo.HiddenCount > 0)
  8718. {
  8719. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8720. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8721. }
  8722. else
  8723. {
  8724. HiddenFilesPanel->ViewPriority = 0;
  8725. // not really necessary, just to cleanup no-longer-valid data
  8726. HiddenFilesPanel->Caption = L"";
  8727. }
  8728. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8729. if (FileInfo.FilteredCount > 0)
  8730. {
  8731. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8732. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8733. }
  8734. else
  8735. {
  8736. FilteredFilesPanel->ViewPriority = 0;
  8737. // not really necessary, just to cleanup no-longer-valid data
  8738. FilteredFilesPanel->Caption = L"";
  8739. }
  8740. }
  8741. //---------------------------------------------------------------------------
  8742. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8743. TObject * /*Sender*/)
  8744. {
  8745. if (DirView(osOther)->Enabled)
  8746. {
  8747. DirView(osOther)->SetFocus();
  8748. }
  8749. }
  8750. //---------------------------------------------------------------------------
  8751. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8752. {
  8753. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8754. switch (Config.Show)
  8755. {
  8756. case qvShow:
  8757. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8758. {
  8759. Config.Show = qvHide;
  8760. }
  8761. else
  8762. {
  8763. Config.Show = Config.LastHideShow;
  8764. }
  8765. break;
  8766. case qvHideWhenEmpty:
  8767. if (ComponentVisible[fcQueueView])
  8768. {
  8769. Config.Show = qvHide;
  8770. }
  8771. else
  8772. {
  8773. Config.LastHideShow = Config.Show;
  8774. Config.Show = qvShow;
  8775. }
  8776. break;
  8777. case qvHide:
  8778. Config.LastHideShow = Config.Show;
  8779. Config.Show = qvShow;
  8780. break;
  8781. }
  8782. WinConfiguration->QueueView = Config;
  8783. }
  8784. //---------------------------------------------------------------------------
  8785. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8786. {
  8787. UnicodeString Result;
  8788. if (Terminal != NULL)
  8789. {
  8790. switch (WinConfiguration->PathInCaption)
  8791. {
  8792. case picShort:
  8793. Result = ExtractShortName(Terminal->CurrentDirectory, true);
  8794. break;
  8795. case picFull:
  8796. Result = Terminal->CurrentDirectory;
  8797. break;
  8798. }
  8799. }
  8800. return Result;
  8801. }
  8802. //---------------------------------------------------------------------------
  8803. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8804. {
  8805. TColor Result = GetWindowColor(FSessionColor);
  8806. return Result;
  8807. }
  8808. //---------------------------------------------------------------------------
  8809. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8810. {
  8811. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8812. return Result;
  8813. }
  8814. //---------------------------------------------------------------------------
  8815. void TCustomScpExplorerForm::UpdatePanelControls(TCustomDirView * ADirView, TCustomDriveView * ADriveView)
  8816. {
  8817. bool UseDarkTheme = WinConfiguration->UseDarkTheme();
  8818. ADirView->DarkMode = UseDarkTheme;
  8819. ADriveView->DarkMode = UseDarkTheme;
  8820. }
  8821. //---------------------------------------------------------------------------
  8822. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8823. {
  8824. if (!FSessionChanging)
  8825. {
  8826. TTerminalManager::Instance()->UpdateAppTitle();
  8827. }
  8828. // WORKAROUND: Disabling list view when it is not showing yet does not set its
  8829. // background to gray on Windows 7 (works on Windows 10).
  8830. // See also EnableControl
  8831. if (Showing)
  8832. {
  8833. if (ManagedSession != NULL)
  8834. {
  8835. // Update path when it changes
  8836. if ((SessionsPageControl->ActivePage != NULL) &&
  8837. (GetSessionTabSession(SessionsPageControl->ActivePage) == ManagedSession))
  8838. {
  8839. UpdateSessionTab(SessionsPageControl->ActivePage);
  8840. }
  8841. }
  8842. NonVisualDataModule->ReconnectSessionAction->Update();
  8843. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8844. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8845. CenterReconnectToolbar();
  8846. bool HasTerminal = HasActiveTerminal();
  8847. RemoteDirView->Enabled = HasTerminal;
  8848. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8849. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8850. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8851. RemoteDriveView->Color = RemoteDirView->Color;
  8852. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8853. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8854. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8855. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8856. QueueFileList->Enabled = QueueView3->Enabled;
  8857. QueueFileList->Color = QueueView3->Color;
  8858. QueueFileList->Font->Color = QueueView3->Font->Color;
  8859. QueueLabelUpdateStatus();
  8860. UpdatePanelControls(RemoteDirView, RemoteDriveView);
  8861. bool UseDarkTheme = WinConfiguration->UseDarkTheme();
  8862. if (FImmersiveDarkMode != UseDarkTheme)
  8863. {
  8864. UpdateDarkMode();
  8865. }
  8866. SessionsPageControl->TabTheme = UseDarkTheme ? CurrentTheme : NULL;
  8867. UnicodeString CurrentHiContrastThemeName = (FHiContrastTheme != NULL) ? FHiContrastTheme->Name : EmptyStr;
  8868. bool HiContrast = WinConfiguration->HiContrast;
  8869. UnicodeString NewHiContrastThemeName = HiContrast ? GetThemeName(!UseDarkTheme) : EmptyStr;
  8870. if (CurrentHiContrastThemeName != NewHiContrastThemeName)
  8871. {
  8872. ReleaseHiContrastTheme();
  8873. if (!NewHiContrastThemeName.IsEmpty())
  8874. {
  8875. FHiContrastTheme = GetTBXTheme(NewHiContrastThemeName);
  8876. }
  8877. }
  8878. SessionsPageControl->ActiveTabTheme = HiContrast ? DebugNotNull(FHiContrastTheme) : NULL;
  8879. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8880. MessageDock->Visible = (MessageDock->ToolbarCount > 0);
  8881. }
  8882. }
  8883. //---------------------------------------------------------------------------
  8884. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8885. {
  8886. UpdateControls();
  8887. }
  8888. //---------------------------------------------------------------------------
  8889. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8890. TObject * Sender)
  8891. {
  8892. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8893. DebugAssert(DirView != NULL);
  8894. DoDirViewLoaded(DirView);
  8895. TransferPresetAutoSelect();
  8896. TUnixDirView * UnixDirView = dynamic_cast<TUnixDirView *>(DirView);
  8897. if (UnixDirView != NULL)
  8898. {
  8899. TManagedTerminal * ATerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(UnixDirView->Terminal));
  8900. TTerminalManager::Instance()->TerminalLoadedDirectory(ATerminal);
  8901. }
  8902. }
  8903. //---------------------------------------------------------------------------
  8904. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8905. {
  8906. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8907. // first run after installation
  8908. if (double(Updates.LastCheck) == 0)
  8909. {
  8910. AppLog(L"First run, scheduling updates check for the next run");
  8911. // make sure next time there will be an update (if enabled)
  8912. Updates.LastCheck = TDateTime(1);
  8913. WinConfiguration->Updates = Updates;
  8914. }
  8915. else
  8916. {
  8917. TDateTime Period;
  8918. if (IsUWP() && !IsOfficialPackage())
  8919. {
  8920. Period = DefaultUpdatesPeriod;
  8921. AppLog(L"Thirdparty UWP package, using default updates check period");
  8922. }
  8923. else
  8924. {
  8925. Period = Updates.Period;
  8926. }
  8927. AppLogFmt(L"Updates check period: %.2f", (double(Period)));
  8928. if (double(Period) > 0)
  8929. {
  8930. TDateTime Interval = Now() - Updates.LastCheck;
  8931. AppLogFmt(L"Interval since the last updates check: %.2f", (double(Interval)));
  8932. if (Interval >= Period)
  8933. {
  8934. StartUpdateThread(UpdatesChecked);
  8935. }
  8936. }
  8937. }
  8938. }
  8939. //---------------------------------------------------------------------------
  8940. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8941. {
  8942. AppLog(L"Updates check done");
  8943. UnicodeString Message;
  8944. bool New;
  8945. TQueryType Type;
  8946. GetUpdatesMessage(Message, New, Type, false);
  8947. if (!Message.IsEmpty())
  8948. {
  8949. AppLogFmt(L"Updates check message: %s", (Message));
  8950. if (New)
  8951. {
  8952. AppLog(L"New version detected");
  8953. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8954. }
  8955. if (!New && (Type != qtWarning))
  8956. {
  8957. AppLog(L"Posting non-critical updates note");
  8958. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8959. }
  8960. else
  8961. {
  8962. AppLog(L"Posting new version or critical message notification");
  8963. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8964. }
  8965. if (New)
  8966. {
  8967. Configuration->Usage->Inc(L"UpdateNotifications");
  8968. }
  8969. }
  8970. }
  8971. //---------------------------------------------------------------------------
  8972. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8973. {
  8974. RestoreApp();
  8975. bool CanDisplay = !NonVisualDataModule->Busy;
  8976. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8977. {
  8978. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8979. }
  8980. if (CanDisplay)
  8981. {
  8982. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8983. // Probably not needed as CheckForUpdates is blocking since we started using neon for HTTP implementation.
  8984. NonVisualDataModule->StartBusy();
  8985. try
  8986. {
  8987. CheckForUpdates(true);
  8988. }
  8989. __finally
  8990. {
  8991. NonVisualDataModule->EndBusy();
  8992. }
  8993. }
  8994. else
  8995. {
  8996. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8997. }
  8998. }
  8999. //---------------------------------------------------------------------------
  9000. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  9001. TCopyParamRuleData & Data)
  9002. {
  9003. DebugAssert(Terminal != NULL);
  9004. Data.HostName = Terminal->SessionData->HostNameExpanded;
  9005. Data.UserName = Terminal->SessionData->UserNameExpanded;
  9006. Data.RemoteDirectory = RemoteDirView->PathName;
  9007. }
  9008. //---------------------------------------------------------------------------
  9009. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  9010. {
  9011. // Terminal can be null when we are changing local directory implicitly,
  9012. // because it has been deleted, while no session is connected
  9013. // (Login dialog is open)
  9014. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  9015. {
  9016. DebugAssert(!IsLocalBrowserMode());
  9017. TCopyParamRuleData Data;
  9018. GetTransferPresetAutoSelectData(Data);
  9019. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  9020. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  9021. if (CopyParamIndex < 0)
  9022. {
  9023. // there is no preset that matches autoselection
  9024. // set preset that we consider "default"
  9025. FCopyParamAutoSelected = L""; // forget last autoselected preset
  9026. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  9027. }
  9028. else
  9029. {
  9030. // there is preset matching autoselection
  9031. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  9032. if (CopyParamName == FCopyParamAutoSelected)
  9033. {
  9034. // autoselected the same preset as the last time
  9035. // make no change (i.e. preserve custom user preset, if any)
  9036. }
  9037. else
  9038. {
  9039. // autoselected the different preset then the last time (or there
  9040. // was default preset set)
  9041. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  9042. GUIConfiguration->CopyParamCurrent = CopyParamName;
  9043. }
  9044. }
  9045. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  9046. {
  9047. if (CopyParamIndex >= 0)
  9048. {
  9049. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  9050. }
  9051. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  9052. try
  9053. {
  9054. int Fmt =
  9055. (CopyParamIndex < 0) ?
  9056. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  9057. COPY_PARAM_AUTOSELECTED;
  9058. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  9059. Data->Message = MainInstructions(Message);
  9060. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  9061. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  9062. CopyParamAttrs);
  9063. if (CopyParamIndex >= 0)
  9064. {
  9065. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  9066. Info = FORMAT(L"%s\n \n%s", (Info,
  9067. FMTLOAD(COPY_PARAM_RULE,
  9068. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  9069. }
  9070. Data->Message += L"\n\n" + Info;
  9071. if (WinConfiguration->CopyParamAutoSelectNotice)
  9072. {
  9073. TransferPresetNoteMessage(Data, true);
  9074. }
  9075. else
  9076. {
  9077. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  9078. Data = NULL; // ownership passed
  9079. }
  9080. }
  9081. __finally
  9082. {
  9083. delete Data;
  9084. }
  9085. }
  9086. }
  9087. }
  9088. //---------------------------------------------------------------------------
  9089. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  9090. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  9091. {
  9092. DebugAssert(NoteData != NULL);
  9093. DebugAssert(!IsLocalBrowserMode());
  9094. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  9095. TQueryButtonAlias Aliases[1];
  9096. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  9097. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  9098. Params.Aliases = Aliases;
  9099. Params.AliasesCount = LENOF(Aliases);
  9100. unsigned int Result =
  9101. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  9102. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  9103. switch (Result)
  9104. {
  9105. case qaNeverAskAgain:
  9106. DebugAssert(AllowNeverAskAgain);
  9107. WinConfiguration->CopyParamAutoSelectNotice = false;
  9108. break;
  9109. case qaIgnore:
  9110. PreferencesDialog(pmPresets);
  9111. break;
  9112. }
  9113. }
  9114. //---------------------------------------------------------------------------
  9115. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  9116. {
  9117. // as of now useless, as this is used for notes only, never for balloons, ...
  9118. RestoreApp();
  9119. // .. and we should never be busy here
  9120. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  9121. {
  9122. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  9123. }
  9124. }
  9125. //---------------------------------------------------------------------------
  9126. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  9127. TPreferencesMode APreferencesMode)
  9128. {
  9129. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  9130. TCopyParamRuleData Data;
  9131. if (Terminal != NULL)
  9132. {
  9133. PreferencesData.reset(new TPreferencesDialogData());
  9134. GetTransferPresetAutoSelectData(Data);
  9135. PreferencesData->CopyParamRuleData = &Data;
  9136. }
  9137. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  9138. }
  9139. //---------------------------------------------------------------------------
  9140. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  9141. const TCustomCommandType & Command)
  9142. {
  9143. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  9144. {
  9145. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  9146. }
  9147. }
  9148. //---------------------------------------------------------------------------
  9149. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  9150. {
  9151. bool RemoteAllowed = CustomCommandRemoteAllowed();
  9152. TCustomCommandType Command;
  9153. // make sure we use local custom command when remote are not supported
  9154. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  9155. {
  9156. Command = FLastCustomCommand;
  9157. }
  9158. else
  9159. {
  9160. Command.Params = Command.Params | ccLocal;
  9161. }
  9162. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  9163. FEditingFocusedAdHocCommand = OnFocused;
  9164. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  9165. int Options =
  9166. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  9167. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  9168. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  9169. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  9170. {
  9171. FLastCustomCommand = Command;
  9172. UpdateCustomCommandsToolbar();
  9173. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  9174. }
  9175. }
  9176. //---------------------------------------------------------------------------
  9177. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  9178. {
  9179. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  9180. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  9181. DebugAssert(State > 0);
  9182. if (State <= 0)
  9183. {
  9184. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  9185. }
  9186. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  9187. }
  9188. //---------------------------------------------------------------------------
  9189. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  9190. TCustomCommandType & Command, int & State)
  9191. {
  9192. bool Result = !FLastCustomCommand.Command.IsEmpty();
  9193. if (Result)
  9194. {
  9195. Command = FLastCustomCommand;
  9196. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  9197. }
  9198. return Result;
  9199. }
  9200. //---------------------------------------------------------------------------
  9201. void __fastcall TCustomScpExplorerForm::BeforeAction()
  9202. {
  9203. ResetIncrementalSearch();
  9204. }
  9205. //---------------------------------------------------------------------------
  9206. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  9207. {
  9208. DebugAssert(ComponentVisible[Component]);
  9209. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  9210. }
  9211. //---------------------------------------------------------------------------
  9212. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  9213. {
  9214. // when queue panel is resized here directly, the status bar is stretched
  9215. // over whole space the panel occupied
  9216. PostComponentHide(fcQueueView);
  9217. }
  9218. //---------------------------------------------------------------------------
  9219. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  9220. {
  9221. ComponentVisible[fcQueueFileList] = false;
  9222. }
  9223. //---------------------------------------------------------------------------
  9224. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  9225. {
  9226. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  9227. RefreshColorMode();
  9228. ResetSysDarkTheme();
  9229. ConfigurationChanged();
  9230. ConfigureInterface();
  9231. // Should be called for all controls
  9232. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  9233. }
  9234. //---------------------------------------------------------------------------
  9235. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  9236. {
  9237. // Do not handle, when shutting down anyway (maybe also when not setup completely yet?)
  9238. if (!FInvalid &&
  9239. (Message.LParam != 0) &&
  9240. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  9241. {
  9242. ThemeChanged();
  9243. }
  9244. TForm::Dispatch(&Message);
  9245. }
  9246. //---------------------------------------------------------------------------
  9247. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  9248. {
  9249. TMessage * M = static_cast<TMessage*>(Message);
  9250. switch (M->Msg)
  9251. {
  9252. case CM_DIALOGCHAR:
  9253. CMDialogChar(*M);
  9254. break;
  9255. case WM_APPCOMMAND:
  9256. WMAppCommand(*M);
  9257. break;
  9258. case WM_SYSCOMMAND:
  9259. WMSysCommand(*M);
  9260. break;
  9261. case WM_QUERYENDSESSION:
  9262. WMQueryEndSession(*M);
  9263. break;
  9264. case WM_ENDSESSION:
  9265. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  9266. break;
  9267. #ifdef _DEBUG
  9268. case WM_WINDOWPOSCHANGED:
  9269. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  9270. break;
  9271. case CM_CUSTOMSTYLECHANGED:
  9272. TForm::Dispatch(Message);
  9273. break;
  9274. #endif
  9275. case WM_COMPONENT_HIDE:
  9276. {
  9277. Byte Component = static_cast<Byte>(M->WParam);
  9278. // sanity check
  9279. if (ComponentVisible[Component])
  9280. {
  9281. // special treatment
  9282. if (Component == fcQueueView)
  9283. {
  9284. ToggleQueueVisibility();
  9285. DebugAssert(!ComponentVisible[fcQueueView]);
  9286. }
  9287. else
  9288. {
  9289. ComponentVisible[Component] = false;
  9290. }
  9291. }
  9292. }
  9293. break;
  9294. case WM_COPYDATA:
  9295. WMCopyData(*M);
  9296. break;
  9297. case WM_MANAGES_CAPTION:
  9298. // caption managed in TTerminalManager::UpdateAppTitle()
  9299. M->Result = 1;
  9300. break;
  9301. case WM_WANTS_MOUSEWHEEL:
  9302. M->Result = 1;
  9303. break;
  9304. case CM_SHOWINGCHANGED:
  9305. CMShowingChanged(*M);
  9306. break;
  9307. case WM_CLOSE:
  9308. WMClose(*M);
  9309. break;
  9310. case WM_DPICHANGED:
  9311. WMDpiChanged(*M);
  9312. break;
  9313. case WM_SETTINGCHANGE:
  9314. WMSettingChange(*M);
  9315. break;
  9316. case CM_DIALOGKEY:
  9317. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  9318. break;
  9319. case WM_PASTE_FILES:
  9320. PasteFiles();
  9321. break;
  9322. case WM_IS_HIDDEN:
  9323. // To treat master password prompt as a main window while showing it when workspace is loading while
  9324. // the exporer is showing up (Visible is true already)
  9325. M->Result = !FShowing;
  9326. break;
  9327. case WM_SHOWWINDOW:
  9328. if (M->WParam)
  9329. {
  9330. AddStartupSequence(L"J");
  9331. }
  9332. TForm::Dispatch(Message);
  9333. break;
  9334. case WM_QUEUE_CALLBACK:
  9335. WMQueueCallback(*M);
  9336. break;
  9337. default:
  9338. TForm::Dispatch(Message);
  9339. break;
  9340. }
  9341. }
  9342. //---------------------------------------------------------------------------
  9343. void __fastcall TCustomScpExplorerForm::UpdateImages()
  9344. {
  9345. // noop
  9346. }
  9347. //---------------------------------------------------------------------------
  9348. void TCustomScpExplorerForm::RegenerateSessionColorsImageList()
  9349. {
  9350. FSessionColors->Clear();
  9351. AddFixedSessionImages();
  9352. ::RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  9353. UpdateImages();
  9354. }
  9355. //---------------------------------------------------------------------------
  9356. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  9357. {
  9358. TForm::Dispatch(&Message);
  9359. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  9360. UpdatePixelsPerInchMainWindowCounter();
  9361. }
  9362. //---------------------------------------------------------------------------
  9363. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  9364. {
  9365. AppLog(L"Main window WM_CLOSE");
  9366. // Cannot close window while we are busy.
  9367. // We cannot test this in FormCloseQuery as that is called also from
  9368. // Close(), which is called by CloseApplicationAction. So we can be busy
  9369. // there already even, when it is legitimate to close the application.
  9370. // Possibly a better place to handle this would be WMSysCommand.
  9371. if (NonVisualDataModule->Busy)
  9372. {
  9373. Message.Result = 1;
  9374. }
  9375. else
  9376. {
  9377. TForm::Dispatch(&Message);
  9378. }
  9379. }
  9380. //---------------------------------------------------------------------------
  9381. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  9382. {
  9383. if (!FShowingChanged)
  9384. {
  9385. AddStartupSequence(L"D");
  9386. FShowingChanged = true;
  9387. }
  9388. // Ignoring implicit local-local browser of Commander, opened from DoShow
  9389. bool NoSession = (ManagedSession == NULL);
  9390. // This calls TCustomScpExplorerForm::DoShow
  9391. TForm::Dispatch(&Message);
  9392. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  9393. if (Showing && !FStarted)
  9394. {
  9395. FStarted = true;
  9396. InterfaceStarted();
  9397. }
  9398. if (Showing && NoSession)
  9399. {
  9400. // When we are starting minimized (i.e. from an installer),
  9401. // postpone showing Login dialog until we get restored.
  9402. // Otherwise the Login dialog (and Authentication window) show restored
  9403. // over invisible (minimized) main window.
  9404. if (WindowState == wsMinimized)
  9405. {
  9406. FNeedSession = true;
  9407. }
  9408. else
  9409. {
  9410. // This happens before application ever goes idle, so the toolbars would
  9411. // stay enabled (initial state) until the Login dialog is dismissed.
  9412. UpdateActions();
  9413. NonVisualDataModule->StartBusy();
  9414. try
  9415. {
  9416. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  9417. // otherwise the dialog does not receive focus.
  9418. // With Commander interface the ProcessMessages is called already
  9419. // by TDriveView, but with Explorer interface, we need to call it explicily
  9420. Application->ProcessMessages();
  9421. // do not reload sessions, they have been loaded just now (optimization)
  9422. NeedSession(true);
  9423. }
  9424. __finally
  9425. {
  9426. NonVisualDataModule->EndBusy();
  9427. }
  9428. }
  9429. }
  9430. }
  9431. //---------------------------------------------------------------------------
  9432. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  9433. {
  9434. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  9435. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  9436. }
  9437. //---------------------------------------------------------------------------
  9438. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  9439. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  9440. int & MaxHeight)
  9441. {
  9442. // workaround for bug in TWinControl.CalcConstraints
  9443. // Check for empty rect (restore from iconic state) is done there only after
  9444. // call to AdjustClientRect, which enlarges the rect (for forms).
  9445. TRect R = GetClientRect();
  9446. // when restoring from iconic state, place no restrictions
  9447. if (IsRectEmpty(R))
  9448. {
  9449. MinWidth = 0;
  9450. MinHeight = 0;
  9451. MaxWidth = 32000;
  9452. MaxHeight = 32000;
  9453. }
  9454. }
  9455. //---------------------------------------------------------------------------
  9456. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  9457. TSpaceAvailable & ASpaceAvailable, bool & Close)
  9458. {
  9459. // terminal can be already closed (e.g. dropped connection)
  9460. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  9461. {
  9462. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  9463. try
  9464. {
  9465. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  9466. }
  9467. catch(...)
  9468. {
  9469. if (!Terminal->Active)
  9470. {
  9471. Close = true;
  9472. }
  9473. throw;
  9474. }
  9475. }
  9476. }
  9477. //---------------------------------------------------------------------------
  9478. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  9479. {
  9480. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  9481. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  9482. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  9483. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  9484. {
  9485. OnGetSpaceAvailable = GetSpaceAvailable;
  9486. }
  9487. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  9488. OnGetSpaceAvailable);
  9489. }
  9490. //---------------------------------------------------------------------------
  9491. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  9492. {
  9493. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  9494. Terminal->FillSessionDataForCode(Data.get());
  9495. return Data.release();
  9496. }
  9497. //---------------------------------------------------------------------------
  9498. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  9499. {
  9500. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  9501. DoGenerateUrlDialog(Data.get(), Paths);
  9502. }
  9503. //---------------------------------------------------------------------------
  9504. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  9505. {
  9506. GenerateUrl(NULL);
  9507. }
  9508. //---------------------------------------------------------------------------
  9509. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  9510. {
  9511. std::unique_ptr<TStrings> Paths(new TStringList());
  9512. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  9513. GenerateUrl(Paths.get());
  9514. }
  9515. //---------------------------------------------------------------------------
  9516. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  9517. {
  9518. FSessionColor = value;
  9519. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  9520. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  9521. static_cast<TObject *>(GetComponent(fcColorMenu)));
  9522. DebugAssert(ColorItem != NULL);
  9523. ColorItem->Color = C;
  9524. NonVisualDataModule->ColorMenuItem->Color = C;
  9525. UpdateControls();
  9526. }
  9527. //---------------------------------------------------------------------------
  9528. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  9529. {
  9530. if (value != FSessionColor)
  9531. {
  9532. UpdateSessionColor(value);
  9533. // Is null when called from LastTerminalClosed
  9534. if (Terminal != NULL)
  9535. {
  9536. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  9537. }
  9538. }
  9539. }
  9540. //---------------------------------------------------------------------------
  9541. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  9542. {
  9543. bool Result = FNoteTimer->Enabled;
  9544. if (Result)
  9545. {
  9546. // cannot cancel note too early
  9547. bool NotEarly =
  9548. (Now() - FNoteShown >
  9549. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  9550. if (Force || NotEarly)
  9551. {
  9552. FNoteTimer->Enabled = false;
  9553. FNote = L"";
  9554. SAFE_DESTROY(FNoteData);
  9555. FOnNoteClick = NULL;
  9556. FNoteHints = FNotes->Text;
  9557. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  9558. UpdateStatusBar();
  9559. }
  9560. }
  9561. return Result;
  9562. }
  9563. //---------------------------------------------------------------------------
  9564. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  9565. {
  9566. DebugAssert(FNoteTimer->Enabled);
  9567. CancelNote(true);
  9568. }
  9569. //---------------------------------------------------------------------------
  9570. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  9571. {
  9572. FNoteHints = FNotes->Text.TrimRight();
  9573. }
  9574. //---------------------------------------------------------------------------
  9575. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  9576. {
  9577. int P = Note.Pos(L"\n");
  9578. if (P > 0)
  9579. {
  9580. Note.SetLength(P - 1);
  9581. }
  9582. FNotes->Add(FORMAT(L"[%s] %s",
  9583. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  9584. while (FNotes->Count > 10)
  9585. {
  9586. FNotes->Delete(0);
  9587. }
  9588. if (UpdateNow)
  9589. {
  9590. UpdateNoteHints();
  9591. UpdateStatusBar();
  9592. }
  9593. }
  9594. //---------------------------------------------------------------------------
  9595. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  9596. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  9597. {
  9598. int P = Note.Pos(L"\n");
  9599. if (P > 0)
  9600. {
  9601. Note.SetLength(P - 1);
  9602. }
  9603. UpdateNoteHints();
  9604. FNote = Note;
  9605. SAFE_DESTROY(FNoteData);
  9606. FNoteData = NoteData;
  9607. FOnNoteClick = OnNoteClick;
  9608. AddNote(Note, false);
  9609. UpdateStatusBar();
  9610. FNoteShown = Now();
  9611. FNoteTimer->Enabled = false;
  9612. if (Seconds == 0)
  9613. {
  9614. Seconds = WinConfiguration->NotificationsTimeout;
  9615. }
  9616. FNoteTimer->Interval = Seconds * MSecsPerSec;
  9617. FNoteTimer->Enabled = true;
  9618. }
  9619. //---------------------------------------------------------------------------
  9620. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  9621. {
  9622. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  9623. }
  9624. //---------------------------------------------------------------------------
  9625. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  9626. {
  9627. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  9628. {
  9629. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  9630. }
  9631. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  9632. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  9633. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  9634. 0, NULL, NULL);
  9635. }
  9636. //---------------------------------------------------------------------------
  9637. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  9638. {
  9639. bool NewShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  9640. UnicodeString Note =
  9641. FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1), (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, (NewShowHiddenFiles ? 2 : 3))));
  9642. PostNote(Note, 0, NULL, NULL);
  9643. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  9644. WinConfiguration->ShowHiddenFiles = NewShowHiddenFiles;
  9645. }
  9646. //---------------------------------------------------------------------------
  9647. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  9648. {
  9649. WinConfiguration->FormatSizeBytes = Style;
  9650. }
  9651. //---------------------------------------------------------------------------
  9652. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  9653. {
  9654. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  9655. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  9656. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  9657. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  9658. }
  9659. //---------------------------------------------------------------------------
  9660. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  9661. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  9662. {
  9663. if (Panel->Index == 0)
  9664. {
  9665. if (FOnNoteClick != NULL)
  9666. {
  9667. // prevent the user data from being freed by possible call
  9668. // to CancelNote or PostNote during call to OnNoteClick
  9669. std::unique_ptr<TObject> NoteData(FNoteData);
  9670. TNotifyEvent OnNoteClick = FOnNoteClick;
  9671. FNoteData = NULL;
  9672. // need to cancel the note as we are going to delete its user data
  9673. CancelNote(true);
  9674. OnNoteClick(NoteData.get());
  9675. }
  9676. }
  9677. if (HasActiveTerminal() &&
  9678. (Panel->Index >= Sender->Panels->Count - SessionPanelCount))
  9679. {
  9680. FileSystemInfo();
  9681. }
  9682. }
  9683. //---------------------------------------------------------------------------
  9684. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  9685. {
  9686. // workaround:
  9687. // 1) for unknown reason, disabling window, while minimized,
  9688. // prevents it from restoring, even if it was enabled again meanwhile
  9689. // 2) when disabling the main window, while another has focus
  9690. // minimize is no longer possible
  9691. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  9692. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  9693. // Shouldn't we use IsApplicationMinimized() here?
  9694. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  9695. {
  9696. Enabled = false;
  9697. }
  9698. FLockLevel++;
  9699. }
  9700. //---------------------------------------------------------------------------
  9701. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  9702. {
  9703. DebugAssert(FLockLevel > 0);
  9704. FLockLevel--;
  9705. if (FLockLevel == 0)
  9706. {
  9707. DebugAssert(FLockSuspendLevel == 0);
  9708. Enabled = true;
  9709. // VCL_COPY (TCustomForm.SetWindowFocus)
  9710. if (Active && (ActiveControl != NULL))
  9711. {
  9712. ::SetFocus(ActiveControl->Handle);
  9713. if (GetFocus() == ActiveControl->Handle)
  9714. {
  9715. ActiveControl->Perform(CM_UIACTIVATE, 0, 0);
  9716. }
  9717. }
  9718. }
  9719. }
  9720. //---------------------------------------------------------------------------
  9721. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  9722. {
  9723. // We need to make sure that window is enabled when the last modal window closes
  9724. // otherwise focus is not restored correctly.
  9725. // So we re-enable the window when modal window opens and
  9726. // disable it back after is closes
  9727. if (FLockLevel > 0)
  9728. {
  9729. // while we have nesting counter, we know that we never be called
  9730. // recursivelly as Application->OnModalBegin is called only
  9731. // for the top-level modal window
  9732. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9733. {
  9734. // won't be disabled when conditions in LockWindow() were not satisfied
  9735. FDisabledOnLockSuspend = !Enabled;
  9736. // When minimized to tray (or actually when set to SW_HIDE),
  9737. // setting Enabled makes the window focusable even when there's
  9738. // modal window over it
  9739. if (!FTrayIcon->Visible)
  9740. {
  9741. Enabled = true;
  9742. }
  9743. }
  9744. FLockSuspendLevel++;
  9745. }
  9746. }
  9747. //---------------------------------------------------------------------------
  9748. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  9749. {
  9750. if (FLockSuspendLevel > 0)
  9751. {
  9752. DebugAssert(FLockLevel > 0);
  9753. FLockSuspendLevel--;
  9754. // see comment in SuspendWindowLock
  9755. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9756. {
  9757. // Note that window can be enabled here, when we were minized to tray when
  9758. // was SuspendWindowLock() called.
  9759. // We should possibly do the same check as in LockWindow(),
  9760. // if it is ever possible that the consitions change between
  9761. // SuspendWindowLock() and ResumeWindowLock()
  9762. Enabled = !FDisabledOnLockSuspend;
  9763. }
  9764. }
  9765. }
  9766. //---------------------------------------------------------------------------
  9767. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9768. {
  9769. TTBXComboBoxItem * RemotePathComboBox =
  9770. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9771. if (!TextOnly)
  9772. {
  9773. TStrings * Items = RemotePathComboBox->Strings;
  9774. Items->BeginUpdate();
  9775. try
  9776. {
  9777. Items->Clear();
  9778. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9779. {
  9780. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9781. while (!IsUnixRootPath(APath))
  9782. {
  9783. int P = APath.LastDelimiter(L'/');
  9784. DebugAssert(P >= 0);
  9785. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9786. APath.SetLength(P - 1);
  9787. }
  9788. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9789. }
  9790. }
  9791. __finally
  9792. {
  9793. Items->EndUpdate();
  9794. }
  9795. }
  9796. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9797. // Setting ItemIndex to -1 does not reset its text
  9798. if (RemotePathComboBox->Strings->Count == 0)
  9799. {
  9800. RemotePathComboBox->Text = L"";
  9801. }
  9802. }
  9803. //---------------------------------------------------------------------------
  9804. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9805. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9806. {
  9807. if (AIndex < 0)
  9808. {
  9809. AIndex = Sender->ItemIndex;
  9810. }
  9811. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9812. }
  9813. //---------------------------------------------------------------------------
  9814. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9815. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9816. int & ImageIndex)
  9817. {
  9818. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9819. }
  9820. //---------------------------------------------------------------------------
  9821. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9822. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9823. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9824. {
  9825. if (!IsLocalBrowserMode())
  9826. {
  9827. ARect.Left += (10 * AIndex);
  9828. }
  9829. }
  9830. //---------------------------------------------------------------------------
  9831. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9832. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9833. {
  9834. AWidth += (10 * AIndex);
  9835. }
  9836. //---------------------------------------------------------------------------
  9837. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9838. {
  9839. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9840. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9841. int Index = RemotePathComboBox->ItemIndex;
  9842. while (Index < RemotePathComboBox->Strings->Count - 1)
  9843. {
  9844. APath = UnixExtractFileDir(APath);
  9845. Index++;
  9846. }
  9847. // VanDyke style paths
  9848. if (APath.IsEmpty())
  9849. {
  9850. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9851. APath = ROOTDIRECTORY;
  9852. }
  9853. if (RemoteDirView->Path != APath)
  9854. {
  9855. RemoteDirView->Path = APath;
  9856. }
  9857. }
  9858. //---------------------------------------------------------------------------
  9859. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9860. {
  9861. DoRemotePathComboBoxItemClick(Sender);
  9862. }
  9863. //---------------------------------------------------------------------------
  9864. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9865. {
  9866. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9867. DebugUsedParam(Sender);
  9868. UpdateRemotePathComboBox(true);
  9869. }
  9870. //---------------------------------------------------------------------------
  9871. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9872. {
  9873. DoRemotePathComboBoxCancel(Sender);
  9874. }
  9875. //---------------------------------------------------------------------------
  9876. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9877. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9878. {
  9879. ResetIncrementalSearch();
  9880. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9881. DebugAssert(DirView != NULL);
  9882. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9883. {
  9884. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9885. // OnEditing is called also from TCustomListView::CanEdit
  9886. if (Edit != NULL)
  9887. {
  9888. EditSelectBaseName(Edit);
  9889. }
  9890. }
  9891. }
  9892. //---------------------------------------------------------------------------
  9893. //---------------------------------------------------------------------------
  9894. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9895. {
  9896. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9897. Result->AutoDetectDnD = false;
  9898. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9899. Result->RenderDataOn = rdoEnterAndDropSync;
  9900. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9901. return Result;
  9902. }
  9903. //---------------------------------------------------------------------------
  9904. void __fastcall TCustomScpExplorerForm::UpdateDarkMode()
  9905. {
  9906. if (IsWin10Build(19041))
  9907. {
  9908. FImmersiveDarkMode = WinConfiguration->UseDarkTheme();
  9909. BOOL DarkMode = FImmersiveDarkMode ? TRUE : FALSE;
  9910. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9911. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9912. }
  9913. }
  9914. //---------------------------------------------------------------------------
  9915. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9916. {
  9917. TForm::CreateWnd();
  9918. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9919. UpdateDarkMode();
  9920. if (FSessionsDragDropFilesEx == NULL)
  9921. {
  9922. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9923. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9924. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9925. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9926. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9927. }
  9928. if (FQueueDragDropFilesEx == NULL)
  9929. {
  9930. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9931. // No need to set OnDragOver as we do not have any restrictions
  9932. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9933. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9934. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9935. }
  9936. }
  9937. //---------------------------------------------------------------------------
  9938. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9939. {
  9940. TForm::DestroyWnd();
  9941. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9942. FQueueDragDropFilesEx->DragDropControl = NULL;
  9943. }
  9944. //---------------------------------------------------------------------------
  9945. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9946. {
  9947. SideEnter(FCurrentSide);
  9948. FEverShown = true;
  9949. }
  9950. //---------------------------------------------------------------------------
  9951. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9952. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9953. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9954. {
  9955. if (!NonVisualDataModule->Busy)
  9956. {
  9957. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9958. Configuration->Usage->Inc(L"FileFinds");
  9959. LockWindow(true);
  9960. NonVisualDataModule->StartBusy();
  9961. WinConfiguration->LockedInterface = true;
  9962. try
  9963. {
  9964. Terminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9965. }
  9966. __finally
  9967. {
  9968. WinConfiguration->LockedInterface = false;
  9969. NonVisualDataModule->EndBusy();
  9970. UnlockWindow();
  9971. }
  9972. }
  9973. }
  9974. //---------------------------------------------------------------------------
  9975. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9976. {
  9977. if (!NonVisualDataModule->Busy)
  9978. {
  9979. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9980. SetFocus();
  9981. RemoteDirView->Path = UnixExtractFilePath(Path);
  9982. UnicodeString FileName = UnixExtractFileName(Path);
  9983. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9984. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9985. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9986. if (Item == NULL)
  9987. {
  9988. ReloadDirectory(osRemote);
  9989. Item = RemoteDirView->FindFileItem(FileName);
  9990. }
  9991. if (Item != NULL)
  9992. {
  9993. RemoteDirView->ItemFocused = Item;
  9994. RemoteDirView->ItemFocused->MakeVisible(false);
  9995. RemoteDirView->SetFocus();
  9996. }
  9997. }
  9998. }
  9999. //---------------------------------------------------------------------------
  10000. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  10001. {
  10002. bool Result = !NonVisualDataModule->Busy;
  10003. if (Result)
  10004. {
  10005. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  10006. }
  10007. return Result;
  10008. }
  10009. //---------------------------------------------------------------------------
  10010. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  10011. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  10012. {
  10013. if (CanOperateOnFoundFiles(ATerminal))
  10014. {
  10015. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished, OnFileOperationFinished);
  10016. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  10017. }
  10018. }
  10019. //---------------------------------------------------------------------------
  10020. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  10021. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  10022. {
  10023. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  10024. }
  10025. //---------------------------------------------------------------------------
  10026. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  10027. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  10028. {
  10029. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  10030. }
  10031. //---------------------------------------------------------------------------
  10032. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  10033. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  10034. {
  10035. if (CanOperateOnFoundFiles(ATerminal))
  10036. {
  10037. for (int Index = 0; Index < FileList->Count; Index++)
  10038. {
  10039. UnicodeString FileName = FileList->Strings[Index];
  10040. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  10041. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  10042. OnFileOperationFinished(osRemote, FileName, true, true);
  10043. }
  10044. }
  10045. }
  10046. //---------------------------------------------------------------------------
  10047. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  10048. {
  10049. FFileFindTerminal = Terminal;
  10050. ShowFileFindDialog(
  10051. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  10052. DoDownloadFoundFiles, DoEditFoundFiles);
  10053. }
  10054. //---------------------------------------------------------------------------
  10055. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  10056. {
  10057. FTaskbarList = TaskbarList;
  10058. }
  10059. //---------------------------------------------------------------------------
  10060. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  10061. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  10062. {
  10063. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  10064. if (Index >= 0)
  10065. {
  10066. if (Button == mbLeft)
  10067. {
  10068. // WORKAROUND: "Mouse down" is raised only after tab is switched.
  10069. // If switching tab (switching session) takes long enough for user
  10070. // to actually release the button, "mouse down" is still raised,
  10071. // but we do not get "mouse up" event, so dragging is not cancelled,
  10072. // prevent that by not beginning dragging in the first place.
  10073. int Key = ((GetSystemMetrics(SM_SWAPBUTTON) == 0) ? VK_LBUTTON : VK_RBUTTON);
  10074. if (IsKeyPressed(Key))
  10075. {
  10076. // when user clicks the "+", we get mouse down only after the session
  10077. // is closed, when new session tab is already on X:Y, so dragging
  10078. // starts, prevent that
  10079. if (MilliSecondsBetween(Now(), FSessionsPageControlNewTabTime) > 500)
  10080. {
  10081. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10082. if (Terminal != NULL)
  10083. {
  10084. SessionsPageControl->BeginDrag(false);
  10085. }
  10086. }
  10087. }
  10088. }
  10089. else if (Button == mbMiddle)
  10090. {
  10091. // ignore middle-click for "New session tab" and the last local-local tab
  10092. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10093. if ((Session != NULL) && CanCloseSession(Session))
  10094. {
  10095. CloseSessionTab(Index);
  10096. }
  10097. }
  10098. }
  10099. }
  10100. //---------------------------------------------------------------------------
  10101. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  10102. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  10103. {
  10104. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  10105. // do not allow dropping on the "+" tab
  10106. TTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10107. if ((TargetTerminal != NULL) &&
  10108. (SessionsPageControl->ActivePage->PageIndex != Index))
  10109. {
  10110. Configuration->Usage->Inc(L"SessionTabMoves");
  10111. // this is almost redundant as we would recreate tabs in SessionListChanged,
  10112. // but we want to actually prevent that to avoid flicker
  10113. SessionsPageControl->ActivePage->PageIndex = Index;
  10114. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->ActivePage);
  10115. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  10116. }
  10117. }
  10118. //---------------------------------------------------------------------------
  10119. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  10120. TObject * Sender, TObject * Source, int X, int Y,
  10121. TDragState /*State*/, bool & Accept)
  10122. {
  10123. Accept = (Sender == Source);
  10124. if (Accept)
  10125. {
  10126. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  10127. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10128. // do not allow dragging to the "+" tab
  10129. Accept = (Terminal != NULL);
  10130. }
  10131. }
  10132. //---------------------------------------------------------------------------
  10133. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  10134. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  10135. {
  10136. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  10137. if (Index < 0)
  10138. {
  10139. Effect = DROPEFFECT_NONE;
  10140. }
  10141. else
  10142. {
  10143. TManagedTerminal * TargetSession = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10144. // do not allow dropping on the "+" tab or on disconnected or local-local tabs
  10145. if (!IsActiveTerminal(TargetSession) || DebugAlwaysFalse(TargetSession->LocalBrowser))
  10146. {
  10147. Effect = DROPEFFECT_NONE;
  10148. }
  10149. else if ((TargetSession != Terminal) && (Effect == DROPEFFECT_MOVE))
  10150. {
  10151. Effect = DROPEFFECT_COPY;
  10152. }
  10153. }
  10154. }
  10155. //---------------------------------------------------------------------------
  10156. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  10157. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  10158. {
  10159. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  10160. // do not allow dropping on local-local, disconnected and the "+" tab
  10161. // (though we do not seem to get here in that case anyway, contrary to RemoteFileControlDDTargetDrop)
  10162. TManagedTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10163. if (DebugAlwaysTrue(IsActiveTerminal(TargetTerminal) && !TargetTerminal->LocalBrowser))
  10164. {
  10165. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  10166. if (!IsFileControl(DropSourceControl, osRemote))
  10167. {
  10168. TTerminalManager::Instance()->ActiveSession = TargetTerminal;
  10169. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  10170. // Why don't we use Terminal->CurrentDirectory directly?
  10171. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  10172. // do not force queue, drag drop
  10173. false, true);
  10174. }
  10175. }
  10176. }
  10177. //---------------------------------------------------------------------------
  10178. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  10179. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  10180. {
  10181. // Downloads are handled in RemoteFileControlDDEnd
  10182. if (!IsFileControl(DropSourceControl, osRemote))
  10183. {
  10184. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  10185. Terminal->CurrentDirectory,
  10186. // force queue, drag drop
  10187. true, true);
  10188. }
  10189. }
  10190. //---------------------------------------------------------------------------
  10191. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  10192. {
  10193. FShowing = false;
  10194. // Do not save empty workspace
  10195. if (WinConfiguration->AutoSaveWorkspace && (ManagedSession != NULL))
  10196. {
  10197. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  10198. UnicodeString Name = WorkspaceName();
  10199. DoSaveWorkspace(
  10200. Name, DataList.get(),
  10201. !Configuration->DisablePasswordStoring &&
  10202. WinConfiguration->AutoSaveWorkspacePasswords, false);
  10203. WinConfiguration->LastStoredSession = Name;
  10204. }
  10205. AppLog(L"Closing main window");
  10206. }
  10207. //---------------------------------------------------------------------------
  10208. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  10209. {
  10210. TManagedTerminal * ManagedTerminal =
  10211. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  10212. if (ManagedTerminal != NULL)
  10213. {
  10214. ManagedTerminal->DirectoryLoaded = Now();
  10215. }
  10216. }
  10217. //---------------------------------------------------------------------------
  10218. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  10219. TListItem * /*Item*/, bool /*Selected*/)
  10220. {
  10221. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  10222. switch (DirView->LastSelectMethod)
  10223. {
  10224. case smKeyboard:
  10225. Configuration->Usage->Inc(L"KeyboardSelections");
  10226. break;
  10227. case smMouse:
  10228. Configuration->Usage->Inc(L"MouseSelections");
  10229. break;
  10230. }
  10231. }
  10232. //---------------------------------------------------------------------------
  10233. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  10234. {
  10235. if (Color != 0)
  10236. {
  10237. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  10238. }
  10239. else
  10240. {
  10241. return FSessionTabImageIndex;
  10242. }
  10243. }
  10244. //---------------------------------------------------------------------------
  10245. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  10246. {
  10247. TPngImageCollectionItem * Item =
  10248. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  10249. FSessionColors->AddPng(Item->PngImage);
  10250. return FSessionColors->Count - 1;
  10251. }
  10252. //---------------------------------------------------------------------------
  10253. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  10254. {
  10255. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  10256. FNewRemoteTabTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewRemoteTabAction->ImageIndex);
  10257. FNewLocalTabTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewLocalTabAction->ImageIndex);
  10258. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  10259. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  10260. FLocalBrowserTabImageIndex = AddFixedSessionImage(LocalBrowserImageIndex);
  10261. }
  10262. //---------------------------------------------------------------------------
  10263. int TCustomScpExplorerForm::GetNewTabActionImageIndex()
  10264. {
  10265. return NonVisualDataModule->NewRemoteTabAction->ImageIndex;
  10266. }
  10267. //---------------------------------------------------------------------------
  10268. int TCustomScpExplorerForm::GetNewTabTabImageIndex(TOperationSide Side)
  10269. {
  10270. switch (Side)
  10271. {
  10272. case osLocal:
  10273. return FNewLocalTabTabImageIndex;
  10274. case osRemote:
  10275. case osCurrent:
  10276. return FNewRemoteTabTabImageIndex;
  10277. default:
  10278. DebugFail();
  10279. return -1;
  10280. }
  10281. }
  10282. //---------------------------------------------------------------------------
  10283. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  10284. {
  10285. for (int Index = 0; Index < Control->ControlCount; Index++)
  10286. {
  10287. TControl * AControl = Control->Controls[Index];
  10288. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  10289. if (WinControl != NULL)
  10290. {
  10291. CollectItemsWithTextDisplayMode(WinControl);
  10292. }
  10293. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  10294. if (Toolbar != NULL)
  10295. {
  10296. // we care for top-level items only
  10297. TTBCustomItem * Items = Toolbar->Items;
  10298. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  10299. {
  10300. TTBCustomItem * Item = Items->Items[ItemIndex];
  10301. if (((Item->DisplayMode == nbdmImageAndText) ||
  10302. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  10303. EligibleForImageDisplayMode(Item))
  10304. {
  10305. FItemsWithTextDisplayMode.insert(Item);
  10306. }
  10307. }
  10308. }
  10309. }
  10310. }
  10311. //---------------------------------------------------------------------------
  10312. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  10313. {
  10314. return true;
  10315. }
  10316. //---------------------------------------------------------------------------
  10317. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  10318. {
  10319. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  10320. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  10321. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  10322. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  10323. bool Result = true;
  10324. while (Result && (i != FItemsWithTextDisplayMode.end()))
  10325. {
  10326. TTBCustomItem * Item = *i;
  10327. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  10328. if (Label != NULL)
  10329. {
  10330. // optimization
  10331. if (Label->Visible == SelectiveToolbarText)
  10332. {
  10333. Result = false;
  10334. }
  10335. else
  10336. {
  10337. Label->Visible = SelectiveToolbarText;
  10338. }
  10339. }
  10340. else
  10341. {
  10342. // optimization
  10343. if (Item->DisplayMode == DisplayMode)
  10344. {
  10345. Result = false;
  10346. }
  10347. else
  10348. {
  10349. Item->DisplayMode = DisplayMode;
  10350. }
  10351. }
  10352. ++i;
  10353. }
  10354. UpdateNewTabTab();
  10355. return Result;
  10356. }
  10357. //---------------------------------------------------------------------------
  10358. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  10359. {
  10360. DebugFail();
  10361. }
  10362. //---------------------------------------------------------------------------
  10363. bool __fastcall TCustomScpExplorerForm::IsBusy()
  10364. {
  10365. // Among other, a lock level is non zero, while directory is being loaded,
  10366. // even when it happens as a result of dirview navigation,
  10367. // i.e. when TNonVisualDataModule is NOT FBusy.
  10368. // That's why the TNonVisualDataModule::GetBusy calls this method.
  10369. // Among other this prevents a panel auto update to occur while
  10370. // directory is changing.
  10371. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  10372. }
  10373. //---------------------------------------------------------------------------
  10374. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  10375. {
  10376. // While the window is disabled, we still seem to process menu shortcuts at least,
  10377. // so stop it at least here.
  10378. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  10379. bool Result;
  10380. if (Allowed == aaUpdate)
  10381. {
  10382. Result = true;
  10383. }
  10384. else
  10385. {
  10386. Result = !NonVisualDataModule->Busy;
  10387. if (Result && (Allowed == aaShortCut))
  10388. {
  10389. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  10390. Action->Update();
  10391. Result = Action->Enabled;
  10392. }
  10393. }
  10394. return Result;
  10395. }
  10396. //---------------------------------------------------------------------------
  10397. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  10398. {
  10399. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  10400. }
  10401. //---------------------------------------------------------------------------
  10402. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  10403. {
  10404. // This is somewhat redundant to LockWindow() call from
  10405. // TTerminalManager::TerminalReadDirectoryProgress.
  10406. // But disabling window is known not to block keyboard shorcuts
  10407. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  10408. if (Busy > 0)
  10409. {
  10410. if (NonVisualDataModule->Busy)
  10411. {
  10412. State = false;
  10413. }
  10414. else
  10415. {
  10416. NonVisualDataModule->StartBusy();
  10417. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  10418. LockWindow();
  10419. }
  10420. }
  10421. else if (Busy < 0)
  10422. {
  10423. UnlockWindow();
  10424. NonVisualDataModule->EndBusy();
  10425. }
  10426. else
  10427. {
  10428. State = NonVisualDataModule->Busy;
  10429. }
  10430. }
  10431. //---------------------------------------------------------------------------
  10432. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  10433. {
  10434. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  10435. if (Index >= 0)
  10436. {
  10437. TPopupMenu * PopupMenu = NULL;
  10438. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10439. if (Session != NULL)
  10440. {
  10441. SessionsPageControl->ActivePageIndex = Index;
  10442. if (DebugAlwaysTrue(SessionTabSwitched()))
  10443. {
  10444. // copied from TControl.WMContextMenu
  10445. SendCancelMode(SessionsPageControl);
  10446. // explicit popup instead of using PopupMenu property
  10447. // to avoid menu to popup somewhere within SessionTabSwitched above,
  10448. // while connecting yet not-connected session and hence
  10449. // allowing an access to commands over not-completely connected session
  10450. PopupMenu = Session->LocalBrowser ? NonVisualDataModule->LocalBrowserPopup : NonVisualDataModule->SessionsPopup;
  10451. }
  10452. }
  10453. else
  10454. {
  10455. if (SupportsLocalBrowser())
  10456. {
  10457. PopupMenu = NonVisualDataModule->NewTabPopup;
  10458. }
  10459. }
  10460. if (PopupMenu != NULL)
  10461. {
  10462. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  10463. PopupMenu->PopupComponent = SessionsPageControl;
  10464. PopupMenu->Popup(Point.x, Point.y);
  10465. }
  10466. }
  10467. Handled = true;
  10468. }
  10469. //---------------------------------------------------------------------------
  10470. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  10471. {
  10472. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  10473. }
  10474. //---------------------------------------------------------------------------
  10475. void __fastcall TCustomScpExplorerForm::ChangePassword()
  10476. {
  10477. Configuration->Usage->Inc(L"PasswordChanges");
  10478. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  10479. ChangePasswordData->DisableAuthentationsExceptPassword();
  10480. ChangePasswordData->ChangePassword = true;
  10481. std::unique_ptr<TTerminal> ChangePasswordSession(
  10482. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  10483. ChangePasswordSession->AutoReadDirectory = false;
  10484. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  10485. {
  10486. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  10487. }
  10488. else
  10489. {
  10490. Configuration->Usage->Inc(L"PasswordChangesFailed");
  10491. }
  10492. }
  10493. //---------------------------------------------------------------------------
  10494. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  10495. {
  10496. // No nice way to assert SSH2
  10497. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  10498. }
  10499. //---------------------------------------------------------------------------
  10500. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  10501. {
  10502. TOperationVisualizer OperationVisualizer;
  10503. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  10504. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  10505. }
  10506. //---------------------------------------------------------------------------
  10507. void __fastcall TCustomScpExplorerForm::FormAfterMonitorDpiChanged(TObject *, int OldDPI, int NewDPI)
  10508. {
  10509. DebugUsedParam(OldDPI);
  10510. DebugAssert(NewDPI == GetControlPixelsPerInch(this));
  10511. GlyphsModule->PixelsPerInch = NewDPI;
  10512. // Can be called too early when primary monitor has non-system dpi
  10513. if (FSessionColors != NULL)
  10514. {
  10515. RegenerateSessionColorsImageList();
  10516. }
  10517. UpdateTabsSize();
  10518. UpdateSessionsPageControlHeight();
  10519. QueueFileListColumnAutoSize();
  10520. }
  10521. //---------------------------------------------------------------------------
  10522. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  10523. {
  10524. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  10525. }
  10526. //---------------------------------------------------------------------
  10527. class TPublicControl : public TControl
  10528. {
  10529. friend class TCustomScpExplorerForm;
  10530. };
  10531. //---------------------------------------------------------------------------
  10532. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  10533. {
  10534. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  10535. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  10536. }
  10537. //---------------------------------------------------------------------------
  10538. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  10539. {
  10540. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  10541. OpenBookmark(Side, Bookmark);
  10542. }
  10543. //---------------------------------------------------------------------------
  10544. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  10545. {
  10546. DoBookmarkClick(osLocal, Sender);
  10547. }
  10548. //---------------------------------------------------------------------------
  10549. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  10550. {
  10551. DoBookmarkClick(osRemote, Sender);
  10552. }
  10553. //---------------------------------------------------------------------------
  10554. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  10555. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  10556. {
  10557. if (BookmarkList != NULL)
  10558. {
  10559. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  10560. if (IsLocalBrowserMode())
  10561. {
  10562. Side = osLocal;
  10563. }
  10564. if (!WinConfiguration->UseLocationProfiles)
  10565. {
  10566. std::unique_ptr<TStringList> Directories(new TStringList());
  10567. Directories->CaseSensitive = (Side == osRemote);
  10568. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10569. {
  10570. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10571. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  10572. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  10573. {
  10574. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  10575. Item->Caption = EscapeHotkey(Directory);
  10576. Item->ShortCut = Bookmark->ShortCut;
  10577. Item->OnClick = OnBookmarkClick;
  10578. Item->Tag = reinterpret_cast<int>(Bookmark);
  10579. Directories->Add(Directory);
  10580. Menu->Add(Item.release());
  10581. }
  10582. }
  10583. }
  10584. else
  10585. {
  10586. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  10587. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10588. {
  10589. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10590. if (!Bookmark->Node.IsEmpty())
  10591. {
  10592. Folders->Add(Bookmark->Node);
  10593. }
  10594. }
  10595. for (int Index = 0; Index < Folders->Count; Index++)
  10596. {
  10597. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  10598. Item->Caption = Folders->Strings[Index];
  10599. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  10600. Folders->Objects[Index] = Item.get();
  10601. Menu->Add(Item.release());
  10602. }
  10603. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10604. {
  10605. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10606. TTBCustomItem * Parent;
  10607. if (!Bookmark->Node.IsEmpty())
  10608. {
  10609. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  10610. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  10611. }
  10612. else
  10613. {
  10614. Parent = Menu;
  10615. }
  10616. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  10617. Item->Caption = Bookmark->Name;
  10618. Item->ShortCut = Bookmark->ShortCut;
  10619. Item->OnClick = OnBookmarkClick;
  10620. Item->Tag = reinterpret_cast<int>(Bookmark);
  10621. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  10622. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  10623. {
  10624. // No hint for location profiles that are actually mere "bookmarks"
  10625. }
  10626. else
  10627. {
  10628. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  10629. UnicodeString LongHint;
  10630. if (!Bookmark->Local.IsEmpty())
  10631. {
  10632. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  10633. }
  10634. if (!Bookmark->Remote.IsEmpty())
  10635. {
  10636. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  10637. }
  10638. AddToList(Hint, LongHint, L"|");
  10639. Item->Hint = Hint;
  10640. }
  10641. Parent->Add(Item.release());
  10642. }
  10643. }
  10644. AddMenuSeparator(Menu);
  10645. }
  10646. }
  10647. //---------------------------------------------------------------------------
  10648. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  10649. {
  10650. Menu->Clear();
  10651. std::unique_ptr<TTBCustomItem> Item;
  10652. Item.reset(new TTBXItem(Owner));
  10653. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  10654. Item->Options = Item->Options << tboDefault;
  10655. Menu->Add(Item.release());
  10656. AddMenuSeparator(Menu);
  10657. if (Terminal != NULL)
  10658. {
  10659. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  10660. }
  10661. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  10662. Item.reset(new TTBXItem(Owner));
  10663. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  10664. Menu->Add(Item.release());
  10665. }
  10666. //---------------------------------------------------------------------------
  10667. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  10668. {
  10669. bool Result = true;
  10670. bool Remote = !IsSideLocalBrowser(Side);
  10671. try
  10672. {
  10673. UnicodeString APath = Path;
  10674. if (Remote)
  10675. {
  10676. Terminal->ExceptionOnFail = true;
  10677. }
  10678. else
  10679. {
  10680. APath = ExpandEnvironmentVariables(Path);
  10681. }
  10682. try
  10683. {
  10684. DirView(Side)->Path = APath;
  10685. }
  10686. __finally
  10687. {
  10688. if (Remote)
  10689. {
  10690. Terminal->ExceptionOnFail = false;
  10691. }
  10692. }
  10693. }
  10694. catch (Exception & E)
  10695. {
  10696. if (!Remote || Terminal->Active)
  10697. {
  10698. ShowExtendedExceptionEx(Terminal, &E);
  10699. Result = false;
  10700. }
  10701. else
  10702. {
  10703. throw;
  10704. }
  10705. }
  10706. return Result;
  10707. }
  10708. //---------------------------------------------------------------------------
  10709. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  10710. {
  10711. // Make sure there some feedback even when loading tiny local folders
  10712. TInstantOperationVisualizer Visualizer;
  10713. DirView(Side)->ReloadDirectory();
  10714. }
  10715. //---------------------------------------------------------------------------
  10716. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  10717. {
  10718. if (Index == SessionsPageControl->TabIndex)
  10719. {
  10720. CloseTab();
  10721. }
  10722. else
  10723. {
  10724. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  10725. TTerminal * Terminal = GetSessionTabSession(TabSheet);
  10726. TTerminalManager * Manager = TTerminalManager::Instance();
  10727. if (!Terminal->Active)
  10728. {
  10729. Manager->FreeTerminal(Terminal);
  10730. }
  10731. else
  10732. {
  10733. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  10734. if (CanCloseQueue(Queue))
  10735. {
  10736. Manager->FreeTerminal(Terminal);
  10737. }
  10738. }
  10739. }
  10740. }
  10741. //---------------------------------------------------------------------------
  10742. void __fastcall TCustomScpExplorerForm::SessionsPageControlTabButtonClick(TPageControl *, int Index)
  10743. {
  10744. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10745. if (Session == NULL)
  10746. {
  10747. TRect ButtonRect = SessionsPageControl->TabButtonRect(Index);
  10748. ButtonRect = TRect(SessionsPageControl->ClientToScreen(ButtonRect.TopLeft()), SessionsPageControl->ClientToScreen(ButtonRect.BottomRight()));
  10749. //TPoint P = TPoint(ButtonRect.Left, ButtonRect.Bottom);
  10750. //P = SessionsPageControl->ClientToScreen(P);
  10751. MenuPopup(NonVisualDataModule->NewTabPopup, ButtonRect, SessionsPageControl);
  10752. }
  10753. else
  10754. {
  10755. CloseSessionTab(Index);
  10756. }
  10757. }
  10758. //---------------------------------------------------------------------------
  10759. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  10760. {
  10761. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  10762. {
  10763. TInstantOperationVisualizer Visualizer;
  10764. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  10765. // before we create a new data object
  10766. ClipboardClear();
  10767. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  10768. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  10769. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  10770. // Intermediate variable to WORKAROUND a crash in compiler
  10771. TObjectList * ClipboardFakeMonitors =
  10772. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  10773. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  10774. if (FClipboardDragDropFilesEx.get() == NULL)
  10775. {
  10776. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  10777. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  10778. }
  10779. FClipboardDragDropFilesEx->FileList->Clear();
  10780. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  10781. FClipboardDragDropFilesEx->CopyToClipboard();
  10782. FClipboardTerminal = Terminal;
  10783. // Need full paths, as cwd can be different once files are pasted
  10784. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  10785. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  10786. {
  10787. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  10788. }
  10789. AppLogFmt(L"Created fake clipboard directory \"%s\" and started drive monitors", (FClipboardFakeDirectory));
  10790. }
  10791. }
  10792. //---------------------------------------------------------------------------
  10793. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  10794. {
  10795. if (OpenClipboard(0))
  10796. {
  10797. AppLog(L"Clearing clipboard");
  10798. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  10799. CloseClipboard();
  10800. }
  10801. }
  10802. //---------------------------------------------------------------------------
  10803. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  10804. {
  10805. return !FClipboardFakeDirectory.IsEmpty();
  10806. }
  10807. //---------------------------------------------------------------------------
  10808. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  10809. {
  10810. bool Deleted = RemoveDir(ApiPath(FClipboardFakeDirectory));
  10811. AppLogFmt(L"Clearing clipboard, deleted clipboard temporary folder \"%s\" - %d", (FClipboardFakeDirectory, int(Deleted)));
  10812. FClipboardFakeDirectory = UnicodeString();
  10813. FClipboardTerminal = NULL;
  10814. if (FDownloadingFromClipboard)
  10815. {
  10816. // We are called by the monitor, so attempt to release it would deadlock
  10817. FClipboardFakeMonitorsPendingReset = true;
  10818. }
  10819. else
  10820. {
  10821. FClipboardFakeMonitors.reset(NULL);
  10822. }
  10823. }
  10824. //---------------------------------------------------------------------------
  10825. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  10826. {
  10827. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  10828. {
  10829. ClipboardStop();
  10830. }
  10831. }
  10832. //---------------------------------------------------------------------------
  10833. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  10834. {
  10835. TTerminalManager * Manager = TTerminalManager::Instance();
  10836. Manager->ActiveSession = FClipboardTerminal;
  10837. TTransferOperationParam Params;
  10838. Params.TargetDirectory = TargetDirectory;
  10839. Params.DragDrop = DragDrop;
  10840. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  10841. }
  10842. //---------------------------------------------------------------------------
  10843. void TCustomScpExplorerForm::PasteFiles()
  10844. {
  10845. // Guard against possible race conditions
  10846. if (!FClipboardPasteTarget.IsEmpty())
  10847. {
  10848. // ClipboardFakeCreated might be called while we are here, so make sure we finish operating on the same path we started with
  10849. UnicodeString Target = FClipboardPasteTarget;
  10850. FClipboardPasteTarget = EmptyStr;
  10851. // Can fail as it can be e.g. locked by AV, so we retry that later
  10852. bool Removed = RemoveDir(ApiPath(Target));
  10853. AppLogFmt(L"First attempt to delete pasted fake clipboard directory \"%s\" - %d", (Target, int(Removed)));
  10854. try
  10855. {
  10856. if (NonVisualDataModule->Busy)
  10857. {
  10858. AppLog(L"Is busy, cannot paste");
  10859. }
  10860. else
  10861. {
  10862. DebugAssert(!FClipboardFakeMonitorsPendingReset);
  10863. FClipboardFakeMonitorsPendingReset = false;
  10864. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10865. TAutoFlag Flag(FDownloadingFromClipboard);
  10866. AppLog(L"Downloading to paste target...");
  10867. ClipboardDownload(ExtractFilePath(Target), NoConfirmation, true);
  10868. AppLog(L"Downloaded to paste target...");
  10869. }
  10870. }
  10871. __finally
  10872. {
  10873. if (!Removed)
  10874. {
  10875. Removed = RemoveDir(ApiPath(Target));
  10876. AppLogFmt(L"Second attempt to delete pasted fake clipboard directory \"%s\" - %d", (Target, int(Removed)));
  10877. }
  10878. }
  10879. }
  10880. }
  10881. //---------------------------------------------------------------------------
  10882. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  10883. {
  10884. // It can actually rarelly happen that some random file is created, while we are shutting down the monitor
  10885. // (as it pumps a Windows message queue while being shutted down)
  10886. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10887. // Is can happen that creation of our temporary directory is detected (even though we are creating it before starting the monitors).
  10888. // It tent do happen with later copy-pastes, probably because everything is cached already and monitors start quickly.
  10889. !IsPathToSameFile(FClipboardFakeDirectory, FileName) &&
  10890. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10891. {
  10892. AppLogFmt(L"Fake clipboard directory pasted to \"%s\"", (FileName));
  10893. FClipboardPasteTarget = FileName;
  10894. // Particularly when pasting to external HDD, the fake directory is strangely recreated if removed here in the monitor callback.
  10895. // Postponing removing (or actually whole pasting operation) seems to help.
  10896. PostMessage(Handle, WM_PASTE_FILES, 0, 0);
  10897. }
  10898. }
  10899. //---------------------------------------------------------------------------
  10900. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10901. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10902. {
  10903. TFileMasks::TParams MaskParams;
  10904. MaskParams.Size = Size;
  10905. MaskParams.Modification = Modification;
  10906. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10907. bool Local = (dynamic_cast<TUnixDirView *>(DirView) == NULL);
  10908. // TUnixDirView::ItemFullFileName returns trailing backslash for directories, what filemask cannot deal with
  10909. if (!Local && Directory)
  10910. {
  10911. FileName = UnixExcludeTrailingBackslash(FileName);
  10912. }
  10913. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10914. {
  10915. bool ImplicitMatch;
  10916. if (Iter->FileMask.Matches(FileName, Local, Directory, &MaskParams, false, ImplicitMatch) &&
  10917. !ImplicitMatch)
  10918. {
  10919. Color = Iter->Color;
  10920. break;
  10921. }
  10922. }
  10923. }
  10924. //---------------------------------------------------------------------------
  10925. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10926. {
  10927. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10928. if (!DirView->IsEditing())
  10929. {
  10930. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10931. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10932. // while searching
  10933. if (Key == VK_BACK)
  10934. {
  10935. if (FIncrementalSearchState.Searching)
  10936. {
  10937. if (FIncrementalSearchState.Text.Length() <= 1)
  10938. {
  10939. ResetIncrementalSearch();
  10940. }
  10941. else
  10942. {
  10943. UnicodeString NewText = LeftStr(FIncrementalSearchState.Text, FIncrementalSearchState.Text.Length() - 1);
  10944. IncrementalSearch(NewText, false, false);
  10945. }
  10946. Key = 0;
  10947. }
  10948. }
  10949. }
  10950. }
  10951. //---------------------------------------------------------------------------
  10952. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10953. {
  10954. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10955. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10956. {
  10957. // Filter control sequences.
  10958. // When not searching yet, prefer use of the space for toggling file selection
  10959. // (so we cannot incrementally search for a string starting with a space).
  10960. if ((Key > VK_SPACE) ||
  10961. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearchState.Searching))
  10962. {
  10963. IncrementalSearch(FIncrementalSearchState.Text + Key, false, false);
  10964. Key = 0;
  10965. }
  10966. }
  10967. }
  10968. //---------------------------------------------------------------------------
  10969. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10970. {
  10971. if (FIncrementalSearchState.Searching)
  10972. {
  10973. FIncrementalSearchState.Reset();
  10974. DirView(osCurrent)->UpdateStatusBar();
  10975. }
  10976. }
  10977. //---------------------------------------------------------------------------
  10978. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10979. {
  10980. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10981. if (Item == NULL)
  10982. {
  10983. MessageBeep(MB_ICONHAND);
  10984. }
  10985. else
  10986. {
  10987. TCustomDirView * ADirView = DirView(osCurrent);
  10988. {
  10989. TAutoNestingCounter Guard(FIncrementalSearching);
  10990. ADirView->FocusItem(Item);
  10991. if (ADirView->NortonLike == nlOff)
  10992. {
  10993. if ((ADirView->Selected != Item) ||
  10994. (ADirView->SelCount > 1))
  10995. {
  10996. ADirView->ClearSelection();
  10997. ADirView->Selected = Item;
  10998. }
  10999. }
  11000. }
  11001. FIncrementalSearchState.Searching = true;
  11002. FIncrementalSearchState.Text = Text;
  11003. Item->MakeVisible(false);
  11004. TListItem * NextItem = SearchFile(Text, true, Reverse);
  11005. FIncrementalSearchState.HaveNext = (NextItem != NULL) && (NextItem != Item);
  11006. ADirView->UpdateStatusBar();
  11007. }
  11008. }
  11009. //---------------------------------------------------------------------------
  11010. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  11011. {
  11012. int Index = Item->Index;
  11013. if (!Reverse)
  11014. {
  11015. Index++;
  11016. if (Index >= Item->Owner->Count)
  11017. {
  11018. Index = 0;
  11019. }
  11020. }
  11021. else
  11022. {
  11023. Index--;
  11024. if (Index < 0)
  11025. {
  11026. Index = Item->Owner->Count - 1;
  11027. }
  11028. }
  11029. return Item->Owner->Item[Index];
  11030. }
  11031. //---------------------------------------------------------------------------
  11032. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  11033. {
  11034. TCustomDirView * ADirView = DirView(osCurrent);
  11035. if (ADirView->Items->Count == 0)
  11036. {
  11037. return NULL;
  11038. }
  11039. else
  11040. {
  11041. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  11042. TListItem * Item = CurrentItem;
  11043. if (SkipCurrent)
  11044. {
  11045. Item = DebugNotNull(GetNextFile(Item, Reverse));
  11046. }
  11047. while (true)
  11048. {
  11049. bool Matches = false;
  11050. switch (WinConfiguration->PanelSearch)
  11051. {
  11052. case isNameStartOnly:
  11053. Matches = ContainsTextSemiCaseSensitive(ADirView->ItemFileName(Item).SubString(1, Text.Length()), Text);
  11054. break;
  11055. case isName:
  11056. Matches = ContainsTextSemiCaseSensitive(ADirView->ItemFileName(Item), Text);
  11057. break;
  11058. case isAll:
  11059. int ColCount = (ADirView->DirViewStyle == dvsReport) ? ADirView->ColProperties->Count : 1;
  11060. int Index = 0;
  11061. while ((Index < ColCount) && !Matches)
  11062. {
  11063. bool Visible = (ADirView->DirViewStyle == dvsReport) ? ADirView->ColProperties->Visible[Index] : true;
  11064. if (Visible)
  11065. {
  11066. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  11067. }
  11068. Index++;
  11069. }
  11070. break;
  11071. }
  11072. if (Matches)
  11073. {
  11074. return Item;
  11075. }
  11076. Item = GetNextFile(Item, Reverse);
  11077. if (Item == CurrentItem)
  11078. {
  11079. return NULL;
  11080. }
  11081. }
  11082. }
  11083. }
  11084. //---------------------------------------------------------------------------
  11085. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  11086. {
  11087. ResetIncrementalSearch();
  11088. }
  11089. //---------------------------------------------------------------------------
  11090. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  11091. {
  11092. if (Message.CharCode == VK_TAB)
  11093. {
  11094. if (!FIncrementalSearchState.Text.IsEmpty())
  11095. {
  11096. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  11097. bool Reverse = Shift.Contains(ssShift);
  11098. IncrementalSearch(FIncrementalSearchState.Text, true, Reverse);
  11099. Message.Result = 1;
  11100. return;
  11101. }
  11102. }
  11103. else if (Message.CharCode == VK_ESCAPE)
  11104. {
  11105. if (FIncrementalSearchState.Searching)
  11106. {
  11107. ResetIncrementalSearch();
  11108. Message.Result = 1;
  11109. return;
  11110. }
  11111. }
  11112. TForm::Dispatch(&Message);
  11113. }
  11114. //---------------------------------------------------------------------------
  11115. void __fastcall TCustomScpExplorerForm::Deactivate()
  11116. {
  11117. TForm::Deactivate();
  11118. // E.g. when switching to an internal editor window
  11119. ResetIncrementalSearch();
  11120. }
  11121. //---------------------------------------------------------------------------
  11122. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  11123. {
  11124. // When switching to another application
  11125. ResetIncrementalSearch();
  11126. }
  11127. //---------------------------------------------------------------------------
  11128. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  11129. {
  11130. ResetIncrementalSearch();
  11131. }
  11132. //---------------------------------------------------------------------------
  11133. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  11134. {
  11135. if (FIncrementalSearching <= 0)
  11136. {
  11137. ResetIncrementalSearch();
  11138. }
  11139. }
  11140. //---------------------------------------------------------------------------
  11141. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  11142. {
  11143. CountClicksForWindowPrint(this);
  11144. }
  11145. //---------------------------------------------------------------------------
  11146. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  11147. {
  11148. CenterReconnectToolbar();
  11149. }
  11150. //---------------------------------------------------------------------------
  11151. void TCustomScpExplorerForm::DoBrowseFile(TCustomDirView * DirView, const UnicodeString & FileName)
  11152. {
  11153. if (!FileName.IsEmpty())
  11154. {
  11155. DirView->FocusByName(FileName);
  11156. if (DirView->ItemFocused != NULL)
  11157. {
  11158. DirView->ItemFocused->Selected = true;
  11159. }
  11160. }
  11161. }
  11162. //---------------------------------------------------------------------------
  11163. void __fastcall TCustomScpExplorerForm::BrowseFile(const UnicodeString & FileName)
  11164. {
  11165. DoBrowseFile(RemoteDirView, FileName);
  11166. }
  11167. //---------------------------------------------------------------------------
  11168. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  11169. {
  11170. if (!FQueueStatusUpdating)
  11171. {
  11172. bool Refresh;
  11173. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  11174. {
  11175. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  11176. }
  11177. else
  11178. {
  11179. if (FQueueFileList->GetCount() > 0)
  11180. {
  11181. FQueueFileList->Clear();
  11182. Refresh = true;
  11183. }
  11184. }
  11185. int Count = FQueueFileList->GetCount();
  11186. if (QueueFileList->Items->Count != Count)
  11187. {
  11188. DebugAssert(Refresh);
  11189. QueueFileList->Items->Count = Count;
  11190. }
  11191. if (Refresh)
  11192. {
  11193. QueueFileList->Invalidate();
  11194. }
  11195. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  11196. }
  11197. }
  11198. //---------------------------------------------------------------------------
  11199. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  11200. {
  11201. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  11202. }
  11203. //---------------------------------------------------------------------------
  11204. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  11205. {
  11206. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  11207. // See TSynchronizeChecklistDialog::UpdateTimer
  11208. if (QueueFileList->Items->Count > 0)
  11209. {
  11210. QueueFileList->Items->Item[0]->MakeVisible(false);
  11211. }
  11212. UpdateQueueFileList();
  11213. }
  11214. //---------------------------------------------------------------------------
  11215. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  11216. {
  11217. Active = QueueView3->Focused() || QueueFileList->Focused();
  11218. }
  11219. //---------------------------------------------------------------------------
  11220. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  11221. {
  11222. QueueLabelUpdateStatus();
  11223. }
  11224. //---------------------------------------------------------------------------
  11225. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  11226. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  11227. {
  11228. int State = FQueueFileList->GetState(Item->Index);
  11229. if (State == qfsProcessed)
  11230. {
  11231. Sender->Canvas->Font->Color = clGrayText;
  11232. }
  11233. }
  11234. //---------------------------------------------------------------------------
  11235. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  11236. {
  11237. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  11238. QueueFileList->Column[0]->Width =
  11239. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  11240. }
  11241. //---------------------------------------------------------------------------
  11242. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  11243. {
  11244. QueueFileListColumnAutoSize();
  11245. }
  11246. //---------------------------------------------------------------------------
  11247. void __fastcall TCustomScpExplorerForm::CloseApp()
  11248. {
  11249. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  11250. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  11251. // So we clear the flag here.
  11252. DebugAssert(NonVisualDataModule->Busy);
  11253. NonVisualDataModule->EndBusy();
  11254. try
  11255. {
  11256. Close();
  11257. }
  11258. __finally
  11259. {
  11260. NonVisualDataModule->StartBusy();
  11261. }
  11262. }
  11263. //---------------------------------------------------------------------------
  11264. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  11265. {
  11266. return (Terminal != NULL) && Terminal->Active;
  11267. }
  11268. //---------------------------------------------------------------------------
  11269. bool __fastcall TCustomScpExplorerForm::HasManagedSession()
  11270. {
  11271. return (ManagedSession != NULL);
  11272. }
  11273. //---------------------------------------------------------------------------
  11274. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  11275. {
  11276. return IsActiveTerminal(Terminal);
  11277. }
  11278. //---------------------------------------------------------------------------
  11279. void TCustomScpExplorerForm::LocalLocalCopy(
  11280. TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused), bool DebugUsedArg(NoConfirmation),
  11281. bool DebugUsedArg(DragDrop), unsigned int DebugUsedArg(Flags))
  11282. {
  11283. DebugFail();
  11284. }
  11285. //---------------------------------------------------------------------------
  11286. void TCustomScpExplorerForm::LocalLocalCopyCommand(TFileOperation Operation, TOperationSide Side, bool OnFocused, unsigned int Flags)
  11287. {
  11288. LocalLocalCopy(Operation, Side, OnFocused, !WinConfiguration->ConfirmTransferring, false, Flags);
  11289. }
  11290. //---------------------------------------------------------------------------
  11291. void TCustomScpExplorerForm::UpdateTabsSize()
  11292. {
  11293. // 1) Changing tab list triggers the OnResize.
  11294. // 2) Is called in TForm constructor, when we are not ready to call SessionListChanged (particularly when starting with colored session)
  11295. if (!FUpdatingSessionTabs && (FSessionColors != NULL))
  11296. {
  11297. // UpdateTabsCaptionTruncation should be enough
  11298. SessionListChanged(true);
  11299. }
  11300. }
  11301. //---------------------------------------------------------------------------
  11302. void __fastcall TCustomScpExplorerForm::SessionsPageControlResize(TObject *)
  11303. {
  11304. UpdateTabsSize();
  11305. }
  11306. //---------------------------------------------------------------------------
  11307. UnicodeString TCustomScpExplorerForm::GetSessionPath(TManagedTerminal * ASession, TOperationSide Side)
  11308. {
  11309. if (ASession == ManagedSession)
  11310. {
  11311. UpdateSession(ASession);
  11312. }
  11313. TSessionData * Data = ASession->StateData;
  11314. UnicodeString Result;
  11315. if (Side == osLocal)
  11316. {
  11317. Result = Data->LocalDirectory;
  11318. }
  11319. else if (DebugAlwaysTrue(Side == osOther))
  11320. {
  11321. Result = ASession->LocalBrowser ? Data->OtherLocalDirectory : Data->RemoteDirectory;
  11322. }
  11323. return Result;
  11324. }
  11325. //---------------------------------------------------------------------------
  11326. UnicodeString TCustomScpExplorerForm::GetTabHintSessionDetails(TManagedTerminal * ASession)
  11327. {
  11328. UnicodeString Title = TTerminalManager::Instance()->GetSessionTitle(ASession, false);
  11329. UnicodeString Result = ASession->SessionData->DefaultSessionName;
  11330. if (Title == Result)
  11331. {
  11332. Result = EmptyStr;
  11333. }
  11334. else
  11335. {
  11336. Result += L"\n";
  11337. }
  11338. return Result;
  11339. }
  11340. //---------------------------------------------------------------------------
  11341. UnicodeString TCustomScpExplorerForm::GetTabHintDetails(TManagedTerminal * ASession)
  11342. {
  11343. UnicodeString Result = GetTabHintSessionDetails(ASession);
  11344. if (!ASession->Active)
  11345. {
  11346. Result += LoadStr(STATUS_NOT_CONNECTED2);
  11347. }
  11348. else
  11349. {
  11350. Result += GetSessionPath(ASession, osRemote);
  11351. }
  11352. return Result;
  11353. }
  11354. //---------------------------------------------------------------------------
  11355. UnicodeString TCustomScpExplorerForm::GetNewTabHintDetails()
  11356. {
  11357. return LoadStr(NEW_REMOTE_TAB_HINT);
  11358. }
  11359. //---------------------------------------------------------------------------
  11360. void __fastcall TCustomScpExplorerForm::SessionsPageControlTabHint(TPageControl *, int Index, UnicodeString & Hint)
  11361. {
  11362. if (Index >= 0)
  11363. {
  11364. TThemeTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  11365. TManagedTerminal * TabSession = GetSessionTabSession(TabSheet);
  11366. if (TabSession == NULL)
  11367. {
  11368. UnicodeString NewTabTabCaption = GetNewTabTabCaption();
  11369. if (NewTabTabCaption != TabSheet->Caption)
  11370. {
  11371. Hint = NewTabTabCaption + L"|" + GetNewTabHintDetails();
  11372. }
  11373. }
  11374. else
  11375. {
  11376. TTerminalManager * Manager = TTerminalManager::Instance();
  11377. UnicodeString TabCaption = Manager->GetSessionTitle(TabSession, true);
  11378. Hint = TabCaption + L"|" + GetTabHintDetails(TabSession);
  11379. }
  11380. }
  11381. }
  11382. //---------------------------------------------------------------------------
  11383. typedef std::vector<TListItem *> TListItemsVector;
  11384. struct TCalculateSizeOperation
  11385. {
  11386. TCalculateSizeStats Stats;
  11387. TListItemsVector ListItems;
  11388. size_t Index;
  11389. };
  11390. //---------------------------------------------------------------------------
  11391. void TCustomScpExplorerForm::CalculateDirectorySizes(TOperationSide Side)
  11392. {
  11393. TCalculateSizeOperation CalculateSizeOperation;
  11394. Side = GetSide(Side);
  11395. TCustomDirView * ADirView = DirView(Side);
  11396. bool LocalSide = IsSideLocalBrowser(Side);
  11397. std::unique_ptr<TStrings> AllFileList(ADirView->CreateFileList(false, LocalSide, NULL, true));
  11398. std::unique_ptr<TStrings> FileList(new TStringList());
  11399. for (int Index = 0; Index < AllFileList->Count; Index++)
  11400. {
  11401. TListItem * Item = DebugNotNull(dynamic_cast<TListItem *>(AllFileList->Objects[Index]));
  11402. if (ADirView->ItemIsDirectory(Item))
  11403. {
  11404. FileList->AddObject(AllFileList->Strings[Index], ADirView->ItemData(Item));
  11405. CalculateSizeOperation.ListItems.push_back(Item);
  11406. }
  11407. }
  11408. CalculateSizeOperation.Index = 0;
  11409. __int64 Size = 0;
  11410. TValueRestorer<TCalculateSizeOperation *> DirectorySizeOperationRestorer(FCalculateSizeOperation, &CalculateSizeOperation);
  11411. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  11412. FOnFileOperationFinished = DirectorySizeCalculated;
  11413. TValueRestorer<TFileOperation> PrimaryOperationRestorer(FPrimaryOperation, foCalculateSize);
  11414. TCalculatedSizes CalculatedSizes;
  11415. CalculateSizeOperation.Stats.CalculatedSizes = &CalculatedSizes;
  11416. if (LocalSide)
  11417. {
  11418. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide, Side);
  11419. ManagedSession->CalculateLocalFilesSize(FileList.get(), Size, NULL, true, NULL, &CalculatedSizes);
  11420. }
  11421. else
  11422. {
  11423. TCalculateSizeParams Params;
  11424. Params.Stats = &CalculateSizeOperation.Stats;
  11425. Params.UseCache = true;
  11426. Terminal->CalculateFilesSize(FileList.get(), Size, Params);
  11427. }
  11428. }
  11429. //---------------------------------------------------------------------------
  11430. void __fastcall TCustomScpExplorerForm::DirectorySizeCalculated(
  11431. TOperationSide Side, const UnicodeString & FileName, bool Success, bool NotCancelled)
  11432. {
  11433. DebugAlwaysTrue(FCalculateSizeOperation != NULL);
  11434. TListItem * Item = VisualiseOperationFinished(Side, FileName, false);
  11435. TCustomDirView * ADirView = dynamic_cast<TCustomDirView *>(Item->Owner->Owner);
  11436. // optimization
  11437. bool GotExpectedItem =
  11438. (FCalculateSizeOperation->Index < FCalculateSizeOperation->ListItems.size()) &&
  11439. (FCalculateSizeOperation->ListItems[FCalculateSizeOperation->Index] == Item);
  11440. int Index = -1;
  11441. if (DebugAlwaysTrue(GotExpectedItem))
  11442. {
  11443. Index = FCalculateSizeOperation->Index;
  11444. FCalculateSizeOperation->Index++;
  11445. }
  11446. else
  11447. {
  11448. TListItemsVector::iterator I =
  11449. std::find(FCalculateSizeOperation->ListItems.begin(), FCalculateSizeOperation->ListItems.end(), Item);
  11450. if (DebugAlwaysTrue(I != FCalculateSizeOperation->ListItems.end()))
  11451. {
  11452. Index = I - FCalculateSizeOperation->ListItems.begin();
  11453. }
  11454. }
  11455. if (DebugAlwaysTrue(Index >= 0) && Success && NotCancelled)
  11456. {
  11457. __int64 Size = (*FCalculateSizeOperation->Stats.CalculatedSizes)[Index];
  11458. ADirView->SetItemCalculatedSize(Item, Size);
  11459. }
  11460. }
  11461. //---------------------------------------------------------------------------
  11462. void __fastcall TCustomScpExplorerForm::MessageDockRequestDock(TObject *, TTBCustomDockableWindow *, bool & Accept)
  11463. {
  11464. Accept = false;
  11465. }
  11466. //---------------------------------------------------------------------------
  11467. void TCustomScpExplorerForm::AutoSizeColumns(TOperationSide Side)
  11468. {
  11469. // Send Ctrl+Gray+ to the list view
  11470. TKeyboardState KeyState;
  11471. GetKeyboardState(KeyState);
  11472. TKeyboardState NewKeyState;
  11473. memset(NewKeyState, 0, sizeof(NewKeyState));
  11474. NewKeyState[VK_CONTROL] = 0x81;
  11475. SetKeyboardState(NewKeyState);
  11476. SendMessage(DirView(Side)->Handle, WM_KEYDOWN, VK_ADD, 0);
  11477. SetKeyboardState(KeyState);
  11478. }
  11479. //---------------------------------------------------------------------------
  11480. void TCustomScpExplorerForm::QueueResetLayoutColumns()
  11481. {
  11482. LoadListViewStr(QueueView3, QueueViewLayoutDefault);
  11483. }
  11484. //---------------------------------------------------------------------------
  11485. void * TCustomScpExplorerForm::SaveFocus()
  11486. {
  11487. return NULL;
  11488. }
  11489. //---------------------------------------------------------------------------
  11490. void TCustomScpExplorerForm::RestoreFocus(void * Focus)
  11491. {
  11492. DebugUsedParam(Focus);
  11493. DebugAssert(Focus == NULL);
  11494. }
  11495. //---------------------------------------------------------------------------
  11496. void TCustomScpExplorerForm::IncrementalSearchStart()
  11497. {
  11498. TCustomDirView * ADirView = DirView(osCurrent);
  11499. ADirView->SetFocus();
  11500. if (!FIncrementalSearchState.Searching)
  11501. {
  11502. FIncrementalSearchState.Searching = true;
  11503. FIncrementalSearchState.HaveNext = false;
  11504. DebugAssert(FIncrementalSearchState.Text.IsEmpty());
  11505. ADirView->UpdateStatusBar();
  11506. }
  11507. }
  11508. //---------------------------------------------------------------------------
  11509. void __fastcall TCustomScpExplorerForm::RemoteDirViewThumbnailNeeded(
  11510. TUnixDirView *, TListItem * Item, TRemoteFile * File, const TSize & Size, TBitmap *& Bitmap)
  11511. {
  11512. // though when downloading to temporary folder, encryption should not be a problem
  11513. if (Terminal->IsCapable[fcBackgroundTransfers] &&
  11514. !File->IsDirectory)
  11515. {
  11516. UnicodeString FileName = File->FullFileName;
  11517. TFileMasks::TParams MaskParams;
  11518. MaskParams.Size = File->Size;
  11519. MaskParams.Modification = File->Modification;
  11520. if ((File->Size <= static_cast<__int64>(WinConfiguration->RemoteThumbnailSizeLimit) * 1024) &&
  11521. FRemoteThumbnailMask.Matches(FileName, false, File->IsDirectory, &MaskParams))
  11522. {
  11523. Bitmap = TTerminalManager::Instance()->ThumbnailNeeded(Terminal, Item->Index, File, Size);
  11524. }
  11525. }
  11526. }
  11527. //---------------------------------------------------------------------------
  11528. TThumbnailDownloadQueueItem * TCustomScpExplorerForm::AddThumbnailDownloadQueueItem(TManagedTerminal * ATerminal)
  11529. {
  11530. DebugAssert(ATerminal == Terminal);
  11531. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  11532. TemporaryFileCopyParam(CopyParam);
  11533. CopyParam.TransferMode = tmBinary;
  11534. UnicodeString SourceDir = ATerminal->CurrentDirectory;
  11535. UnicodeString TempDir, RootTempDir;
  11536. TemporaryDirectoryForRemoteFiles(SourceDir, CopyParam, true, TempDir, RootTempDir);
  11537. TTerminalQueue * AQueue = TTerminalManager::Instance()->FindQueueForTerminal(ATerminal);
  11538. DebugAssert((Queue == NULL) || (AQueue == Queue)); // we might get here before queue is set
  11539. TThumbnailDownloadQueueItem * QueueItem =
  11540. new TThumbnailDownloadQueueItem(this, Terminal, SourceDir, TempDir, &CopyParam);
  11541. AddQueueItem(AQueue, QueueItem, ATerminal);
  11542. return QueueItem;
  11543. }
  11544. //---------------------------------------------------------------------------
  11545. enum { qccRemoteItemVisible, qccRemoteItemRedraw };
  11546. typedef std::pair<int, UnicodeString> TRemoteItemVisibleData;
  11547. //---------------------------------------------------------------------------
  11548. void TCustomScpExplorerForm::PostThumbnailVisibleQueueQuery(int Index, const UnicodeString & FileName)
  11549. {
  11550. // The queue might be destroyed before the WM_QUEUE_CALLBACK is processed
  11551. TRemoteItemVisibleData * Data = new TRemoteItemVisibleData();
  11552. Data->first = Index;
  11553. Data->second = FileName;
  11554. PostMessage(Handle, WM_QUEUE_CALLBACK, qccRemoteItemVisible, reinterpret_cast<WPARAM>(Data));
  11555. }
  11556. //---------------------------------------------------------------------------
  11557. void TCustomScpExplorerForm::PostThumbnailDrawRequest(int Index)
  11558. {
  11559. PostMessage(Handle, WM_QUEUE_CALLBACK, qccRemoteItemRedraw, Index);
  11560. }
  11561. //---------------------------------------------------------------------------
  11562. void TCustomScpExplorerForm::WMQueueCallback(TMessage & Message)
  11563. {
  11564. int Command = Message.WParam;
  11565. if (Command == qccRemoteItemVisible)
  11566. {
  11567. TRemoteItemVisibleData * Data = reinterpret_cast<TRemoteItemVisibleData *>(Message.LParam);
  11568. int Index = Data->first;
  11569. UnicodeString FileName = Data->second;
  11570. delete Data;
  11571. TGuard Guard(Terminal->ThumbnailsSection.get());
  11572. bool Visible = False;
  11573. if (Terminal->ThumbnailsEnabled &&
  11574. // though we should better also disable thumbnails once we switch to different view style
  11575. (RemoteDirView->DirViewStyle == dvsThumbnail))
  11576. {
  11577. // The message might be processed, while we are already loading a different directory
  11578. if ((Index >= 0) &&
  11579. (Index < RemoteDirView->Items->Count))
  11580. {
  11581. TListItem * Item = RemoteDirView->Items->Item[Index];
  11582. Visible =
  11583. (RemoteDirView->ItemFullFileName(Item) == FileName) &&
  11584. ListView_IsItemVisible(RemoteDirView->Handle, Index);
  11585. }
  11586. }
  11587. Terminal->ThumbnailVisible(Index, FileName, Visible);
  11588. }
  11589. else if (Command == qccRemoteItemRedraw)
  11590. {
  11591. int Index = Message.LParam;
  11592. if ((Index >= 0) &&
  11593. (Index < RemoteDirView->Items->Count))
  11594. {
  11595. RemoteDirView->InvalidateItem(RemoteDirView->Items->Item[Index]);
  11596. }
  11597. }
  11598. }
  11599. //---------------------------------------------------------------------------
  11600. void TCustomScpExplorerForm::InitializeRemoteThumbnailMask()
  11601. {
  11602. UnicodeString DefaultRemoteThumbnailMask = L"*.jpg;*.jpeg;*.gif;*.png;*.svg;*.bmp;*.raw;*.ico;*.heic";
  11603. UnicodeString RemoteThumbnailMask = WinConfiguration->RemoteThumbnailMask;
  11604. if (RemoteThumbnailMask.IsEmpty() ||
  11605. StartsStr(L"+", RemoteThumbnailMask) || StartsStr(L"-", RemoteThumbnailMask) || StartsStr(L"*", RemoteThumbnailMask))
  11606. {
  11607. std::unique_ptr<TStrings> RemoteThumbnailMasks(new TStringList());
  11608. while (!DefaultRemoteThumbnailMask.IsEmpty())
  11609. {
  11610. RemoteThumbnailMasks->Add(CutToChar(DefaultRemoteThumbnailMask, L';', true));
  11611. }
  11612. RemoteThumbnailMasks.reset(ProcessFeatures(RemoteThumbnailMasks.get(), RemoteThumbnailMask));
  11613. RemoteThumbnailMask = EmptyStr;
  11614. for (int Index = 0; Index < RemoteThumbnailMasks->Count; Index++)
  11615. {
  11616. AddToList(RemoteThumbnailMask, RemoteThumbnailMasks->Strings[Index], L";");
  11617. }
  11618. }
  11619. FRemoteThumbnailMask.Masks = RemoteThumbnailMask;
  11620. }
  11621. //---------------------------------------------------------------------------
  11622. void __fastcall TCustomScpExplorerForm::RemoteDirViewStartLoading(TObject *)
  11623. {
  11624. Terminal->StartLoadingDirectory();
  11625. }
  11626. //---------------------------------------------------------------------------
  11627. void __fastcall TCustomScpExplorerForm::RemoteDirViewStartReading(TObject *)
  11628. {
  11629. Terminal->DisableThumbnails();
  11630. }
  11631. //---------------------------------------------------------------------------
  11632. void TCustomScpExplorerForm::ChangeDirViewStyle(TOperationSide Side, TDirViewStyle DirViewStyle)
  11633. {
  11634. TCustomDirView * ADirView = DirView(Side);
  11635. if (ADirView->DirViewStyle != DirViewStyle)
  11636. {
  11637. if (DirViewStyle == dvsThumbnail)
  11638. {
  11639. if (dynamic_cast<TUnixDirView *>(ADirView) != NULL)
  11640. {
  11641. Configuration->Usage->Inc(L"ThumbnailsRemote");
  11642. }
  11643. else
  11644. {
  11645. Configuration->Usage->Inc(L"ThumbnailsLocal");
  11646. }
  11647. }
  11648. ADirView->DirViewStyle = DirViewStyle;
  11649. UpdateControls();
  11650. }
  11651. }