CustomScpExplorer.cpp 364 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059
  1. //---------------------------------------------------------------------------
  2. #define NO_WIN32_LEAN_AND_MEAN
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <Common.h>
  6. #include "CustomScpExplorer.h"
  7. #include <Bookmarks.h>
  8. #include <Interface.h>
  9. #include <Exceptions.h>
  10. #include <CoreMain.h>
  11. #include <FileSystems.h>
  12. #include <TextsCore.h>
  13. #include <TextsWin.h>
  14. #include <HelpWin.h>
  15. #include <VCLCommon.h>
  16. #include <Progress.h>
  17. #include <SynchronizeProgress.h>
  18. #include <DragExt.h>
  19. #include <WinApi.h>
  20. #include "GUITools.h"
  21. #include "NonVisual.h"
  22. #include "Glyphs.h"
  23. #include "Tools.h"
  24. #include "WinConfiguration.h"
  25. #include "TerminalManager.h"
  26. #include "EditorManager.h"
  27. #include "ProgParams.h"
  28. #include "Setup.h"
  29. #include <Consts.hpp>
  30. #include <DateUtils.hpp>
  31. #include <TB2Common.hpp>
  32. #include <DirectoryMonitor.hpp>
  33. #include <System.IOUtils.hpp>
  34. //---------------------------------------------------------------------------
  35. #pragma package(smart_init)
  36. #pragma link "CustomDirView"
  37. #pragma link "CustomUnixDirView"
  38. #pragma link "IEListView"
  39. #pragma link "NortonLikeListView"
  40. #pragma link "UnixDirView"
  41. #pragma link "CustomDriveView"
  42. #pragma link "UnixDriveView"
  43. #pragma link "CustomDriveView"
  44. #pragma link "TB2Dock"
  45. #pragma link "TBXStatusBars"
  46. #pragma link "TB2Item"
  47. #pragma link "TB2Toolbar"
  48. #pragma link "ThemePageControl"
  49. #pragma link "PathLabel"
  50. #pragma resource "*.dfm"
  51. //---------------------------------------------------------------------------
  52. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  53. static const int SessionPanelCount = 3;
  54. //---------------------------------------------------------------------------
  55. class TMutexGuard
  56. {
  57. public:
  58. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  59. int Timeout = 5000)
  60. {
  61. FMutex = NULL;
  62. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  63. if (WaitResult == WAIT_TIMEOUT)
  64. {
  65. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  66. }
  67. else
  68. {
  69. FMutex = AMutex;
  70. }
  71. }
  72. ~TMutexGuard()
  73. {
  74. if (FMutex != NULL)
  75. {
  76. ReleaseMutex(FMutex);
  77. }
  78. }
  79. private:
  80. HANDLE FMutex;
  81. };
  82. //---------------------------------------------------------------------------
  83. class TWindowLock
  84. {
  85. public:
  86. TWindowLock(TCustomScpExplorerForm * Form) :
  87. FForm(Form)
  88. {
  89. FForm->LockWindow();
  90. }
  91. ~TWindowLock()
  92. {
  93. FForm->UnlockWindow();
  94. }
  95. private:
  96. TCustomScpExplorerForm * FForm;
  97. };
  98. //---------------------------------------------------------------------------
  99. TAutoBatch::TAutoBatch(TCustomScpExplorerForm * Form) :
  100. FForm(Form)
  101. {
  102. FForm->BatchStart(FBatchStorage);
  103. }
  104. //---------------------------------------------------------------------------
  105. TAutoBatch::~TAutoBatch()
  106. {
  107. FForm->BatchEnd(FBatchStorage);
  108. }
  109. //---------------------------------------------------------------------------
  110. struct TTransferOperationParam
  111. {
  112. TTransferOperationParam();
  113. UnicodeString TargetDirectory;
  114. bool Temp;
  115. bool DragDrop;
  116. int Options;
  117. TAutoSwitch Queue;
  118. };
  119. //---------------------------------------------------------------------------
  120. TTransferOperationParam::TTransferOperationParam()
  121. {
  122. Temp = false;
  123. DragDrop = false;
  124. Options = 0;
  125. Queue = asAuto;
  126. }
  127. //---------------------------------------------------------------------------
  128. class TTransferPresetNoteData : public TObject
  129. {
  130. public:
  131. UnicodeString Message;
  132. };
  133. //---------------------------------------------------------------------------
  134. class TTerminalNoteData : public TObject
  135. {
  136. public:
  137. TManagedTerminal * Terminal;
  138. };
  139. //---------------------------------------------------------------------------
  140. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  141. FFormRestored(false),
  142. TForm(Owner)
  143. {
  144. FInvalid = false;
  145. FCurrentSide = osRemote;
  146. FEverShown = false;
  147. FDocks = new TList();
  148. InitControls();
  149. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  150. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  151. NonVisualDataModule->ScpExplorer = this;
  152. RestoreParams();
  153. ConfigurationChanged();
  154. RemoteDirView->Invalidate();
  155. FAutoOperation = false;
  156. FOnFileOperationFinished = NULL;
  157. FForceExecution = false;
  158. FIgnoreNextDialogChar = 0;
  159. FErrorList = NULL;
  160. FSynchronizeProgressForm = NULL;
  161. FProgressForm = NULL;
  162. FRefreshLocalDirectory = false;
  163. FRefreshRemoteDirectory = false;
  164. FDDExtMapFile = NULL;
  165. // CreateMutexW keeps failing with ERROR_NOACCESS
  166. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  167. DebugAssert(FDDExtMutex != NULL);
  168. FDDTargetControl = NULL;
  169. FDelayedDeletionTimer = NULL;
  170. FDelayedDeletionList = new TStringList();
  171. FDDFileList = NULL;
  172. FPendingTempSpaceWarn = false;
  173. FCapturedLog = NULL;
  174. FDragDropOperation = false;
  175. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  176. FAllowTransferPresetAutoSelect = true;
  177. FCopyParamDefault = L"";
  178. FSynchronizeController = NULL;
  179. FPendingQueueActionItem = NULL;
  180. FLockLevel = 0;
  181. FLockSuspendLevel = 0;
  182. FDisabledOnLockSuspend = false;
  183. FAlternativeDelete = false;
  184. FTrayIcon = new ::TTrayIcon(0);
  185. FTrayIcon->OnClick = TrayIconClick;
  186. FMaxQueueLength = 0;
  187. FLastContextPopupScreenPoint = TPoint(-1, -1);
  188. FTransferResumeList = NULL;
  189. FMoveToQueue = false;
  190. FStandaloneEditing = false;
  191. FOnFeedSynchronizeError = NULL;
  192. FNeedSession = false;
  193. FDoNotIdleCurrentTerminal = 0;
  194. FIncrementalSearching = 0;
  195. FIncrementalSearchHaveNext = false;
  196. FQueueFileList.reset(new TQueueFileList());
  197. FProgressSide = osCurrent;
  198. FEditorManager = new TEditorManager();
  199. FEditorManager->OnFileChange = ExecutedFileChanged;
  200. FEditorManager->OnFileReload = ExecutedFileReload;
  201. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  202. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  203. FLocalEditors = new TList();
  204. FQueueStatus = NULL;
  205. FQueueStatusSection = new TCriticalSection();
  206. FQueueStatusInvalidated = false;
  207. FQueueItemInvalidated = false;
  208. FQueueStatusUpdating = false;
  209. FQueueActedItem = NULL;
  210. FQueueController = new TQueueController(QueueView3);
  211. FUserActionTimer = new TTimer(this);
  212. FUserActionTimer->Enabled = false;
  213. FUserActionTimer->Interval = 10;
  214. FUserActionTimer->OnTimer = UserActionTimer;
  215. FNotes = new TStringList();
  216. FNoteTimer = new TTimer(this);
  217. FNoteTimer->Enabled = false;
  218. FNoteTimer->OnTimer = NoteTimer;
  219. FOnNoteClick = NULL;
  220. FOle32Library = LoadLibrary(L"Ole32.dll");
  221. FDragMoveCursor = FOle32Library != NULL ?
  222. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  223. UseSystemSettings(this);
  224. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  225. static_cast<TObject*>(GetComponent(fcTransferList)));
  226. DebugAssert(TransferList != NULL);
  227. FTransferListHoverIndex = -1;
  228. TransferList->OnChange = TransferListChange;
  229. TransferList->OnDrawItem = TransferListDrawItem;
  230. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  231. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  232. UseDesktopFont(SessionsPageControl);
  233. UpdateSessionsPageControlHeight();
  234. UseDesktopFont(RemoteDirView);
  235. UseDesktopFont(RemoteDriveView);
  236. UseDesktopFont(QueueView3);
  237. UseDesktopFont(QueueFileList);
  238. UseDesktopFont(QueueLabel);
  239. UseDesktopFont(RemoteStatusBar);
  240. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  241. QueueSplitter->ShowHint = true;
  242. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  243. QueueFileListSplitter->ShowHint = true;
  244. RemotePanelSplitter->ShowHint = true;
  245. UpdateImages();
  246. FCustomCommandMenu = CreateTBXPopupMenu(this);
  247. FCustomCommandLocalFileList = NULL;
  248. FCustomCommandRemoteFileList = NULL;
  249. FSessionColors = new TPngImageList(this);
  250. FSessionColors->ColorDepth = cd32Bit;
  251. AddFixedSessionImages();
  252. SessionsPageControl->Images = FSessionColors;
  253. UpdateQueueLabel();
  254. CreateHiddenWindow();
  255. StartUpdates();
  256. }
  257. //---------------------------------------------------------------------------
  258. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  259. {
  260. FInvalid = true;
  261. // this has to be one of the very first things to do
  262. StopUpdateThread();
  263. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  264. TTerminalManager::Instance()->ScpExplorer = NULL;
  265. delete FCustomCommandLocalFileList;
  266. delete FCustomCommandRemoteFileList;
  267. delete FCustomCommandMenu;
  268. delete FTrayIcon;
  269. FTrayIcon = NULL;
  270. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  271. delete FEditorManager;
  272. ForceCloseLocalEditors();
  273. delete FLocalEditors;
  274. HideFileFindDialog();
  275. if (FDelayedDeletionTimer)
  276. {
  277. DoDelayedDeletion(NULL);
  278. SAFE_DESTROY(FDelayedDeletionTimer);
  279. }
  280. SAFE_DESTROY(FDelayedDeletionList);
  281. // sometimes we do not get DDEnd so the list is not released
  282. SAFE_DESTROY(FDDFileList);
  283. DebugAssert(FSynchronizeController == NULL);
  284. CloseHandle(FDDExtMutex);
  285. FDDExtMutex = NULL;
  286. FreeLibrary(FOle32Library);
  287. FOle32Library = NULL;
  288. FDragMoveCursor = NULL;
  289. DebugAssert(!FErrorList);
  290. if (FEverShown)
  291. {
  292. // when window is never shown (like when running command-line operation),
  293. // particularly window site is not restored correctly (BoundsRect value set
  294. // in RestoreForm gets lost during handle allocation), so we do not want
  295. // it to be stored
  296. StoreParams();
  297. }
  298. Terminal = NULL;
  299. Queue = NULL;
  300. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  301. NonVisualDataModule->ScpExplorer = NULL;
  302. delete FQueueController;
  303. FQueueController = NULL;
  304. delete FQueueStatusSection;
  305. FQueueStatusSection = NULL;
  306. delete FQueueStatus;
  307. FQueueStatus = NULL;
  308. delete FUserActionTimer;
  309. FUserActionTimer = NULL;
  310. delete FNoteTimer;
  311. delete FNotes;
  312. delete FNoteData;
  313. SAFE_DESTROY(FDocks);
  314. SessionsPageControl->Images = NULL;
  315. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  316. SAFE_DESTROY(FSessionColors);
  317. SAFE_DESTROY(FSessionsDragDropFilesEx);
  318. SAFE_DESTROY(FHistoryMenu[0][0]);
  319. SAFE_DESTROY(FHistoryMenu[0][1]);
  320. SAFE_DESTROY(FHistoryMenu[1][0]);
  321. SAFE_DESTROY(FHistoryMenu[1][1]);
  322. if (FHiddenWindow != NULL)
  323. {
  324. DestroyWindow(FHiddenWindow);
  325. FHiddenWindow = NULL;
  326. }
  327. }
  328. //---------------------------------------------------------------------------
  329. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  330. {
  331. std::unique_ptr<TSessionData> Data;
  332. if (!Session.IsEmpty())
  333. {
  334. bool DefaultsOnly;
  335. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  336. }
  337. TTerminalManager * Manager = TTerminalManager::Instance();
  338. for (int Index = 0; Index < Manager->Count; Index++)
  339. {
  340. TTerminal * Terminal = Manager->Terminals[Index];
  341. if (Session.IsEmpty() ||
  342. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  343. {
  344. if (Path.IsEmpty())
  345. {
  346. Terminal->ClearCaches();
  347. }
  348. else
  349. {
  350. Terminal->DirectoryModified(Path, true);
  351. }
  352. }
  353. }
  354. // We should flag a pending refresh for the background terminals or busy foreground terminals
  355. if (HasActiveTerminal() &&
  356. CanCommandLineFromAnotherInstance() &&
  357. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  358. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  359. {
  360. Terminal->ReloadDirectory();
  361. }
  362. }
  363. //---------------------------------------------------------------------------
  364. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  365. {
  366. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  367. size_t MessageSize = sizeof(TCopyDataMessage);
  368. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  369. if (Result)
  370. {
  371. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  372. Result = (Message.Version == TCopyDataMessage::Version1);
  373. if (Result)
  374. {
  375. switch (Message.Command)
  376. {
  377. case TCopyDataMessage::CommandCanCommandLine:
  378. Result = CanCommandLineFromAnotherInstance();
  379. break;
  380. case TCopyDataMessage::CommandCommandLine:
  381. {
  382. UnicodeString CommandLine(Message.CommandLine);
  383. Result = CommandLineFromAnotherInstance(CommandLine);
  384. }
  385. break;
  386. case TCopyDataMessage::RefreshPanel:
  387. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  388. break;
  389. case TCopyDataMessage::MainWindowCheck:
  390. Result = true;
  391. break;
  392. default:
  393. Result = false;
  394. break;
  395. }
  396. }
  397. }
  398. Message.Result = Result ? 1 : 0;
  399. }
  400. //---------------------------------------------------------------------------
  401. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  402. {
  403. WNDCLASS WindowClass = {0};
  404. WindowClass.lpfnWndProc = DefWindowProc;
  405. WindowClass.hInstance = HInstance;
  406. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  407. FHiddenWindow = NULL;
  408. if (RegisterClass(&WindowClass))
  409. {
  410. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  411. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  412. }
  413. }
  414. //---------------------------------------------------------------------------
  415. bool __fastcall TCustomScpExplorerForm::CanConsole()
  416. {
  417. return
  418. HasActiveTerminal() &&
  419. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  420. }
  421. //---------------------------------------------------------------------------
  422. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  423. {
  424. bool Result = Visible && !NonVisualDataModule->Busy;
  425. return Result;
  426. }
  427. //---------------------------------------------------------------------------
  428. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  429. const UnicodeString & CommandLine)
  430. {
  431. TProgramParams Params(CommandLine);
  432. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  433. if (Result)
  434. {
  435. NonVisualDataModule->StartBusy();
  436. try
  437. {
  438. // this action is initiated from another process,
  439. // so it's likely that our window is not visible,
  440. // and user won't see what is going on
  441. Application->BringToFront();
  442. // reload sessions as we may be asked to open a session
  443. // just stored by another instance
  444. StoredSessions->Reload();
  445. UnicodeString SessionName = Params.Param[1];
  446. std::unique_ptr<TObjectList> DataList(new TObjectList());
  447. UnicodeString DownloadFile; // unused
  448. try
  449. {
  450. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  451. }
  452. catch (EAbort &)
  453. {
  454. // Happens when opening session in PuTTY and in other situations,
  455. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  456. // to process the command-line on its own (or to pass it to yet another instance)
  457. }
  458. if (DataList->Count > 0)
  459. {
  460. TTerminalManager * Manager = TTerminalManager::Instance();
  461. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  462. }
  463. }
  464. __finally
  465. {
  466. NonVisualDataModule->EndBusy();
  467. }
  468. }
  469. return Result;
  470. }
  471. //---------------------------------------------------------------------------
  472. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  473. {
  474. if (FTerminal != value)
  475. {
  476. TerminalChanging();
  477. DoSetTerminal(value, false);
  478. }
  479. }
  480. //---------------------------------------------------------------------------
  481. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  482. {
  483. FTerminal = value;
  484. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  485. FAllowTransferPresetAutoSelect = false;
  486. try
  487. {
  488. TerminalChanged(Replace);
  489. }
  490. __finally
  491. {
  492. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  493. }
  494. if (Terminal != NULL)
  495. {
  496. TransferPresetAutoSelect();
  497. }
  498. }
  499. //---------------------------------------------------------------------------
  500. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  501. {
  502. DoSetTerminal(value, true);
  503. }
  504. //---------------------------------------------------------------------------
  505. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  506. {
  507. if (FTerminal != NULL)
  508. {
  509. UpdateTerminal(Terminal);
  510. }
  511. }
  512. //---------------------------------------------------------------------------
  513. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  514. {
  515. if (Terminal != NULL)
  516. {
  517. UpdateSessionColor((TColor)Terminal->StateData->Color);
  518. }
  519. DoTerminalListChanged();
  520. DebugAssert(!IsLocalBrowserMode());
  521. if (Replaced)
  522. {
  523. RemoteDirView->ReplaceTerminal(Terminal);
  524. }
  525. else
  526. {
  527. RemoteDirView->Terminal = Terminal;
  528. }
  529. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  530. if (Terminal != NULL)
  531. {
  532. if (Terminal->Active)
  533. {
  534. Terminal->RefreshDirectory();
  535. }
  536. if (WinConfiguration->PreservePanelState)
  537. {
  538. if (Terminal->RemoteExplorerState != NULL)
  539. {
  540. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  541. }
  542. else
  543. {
  544. DirView(osRemote)->ClearState();
  545. }
  546. }
  547. }
  548. InitStatusBar();
  549. UpdateTransferList();
  550. // Update panels Enable state before refreshing the labels
  551. UpdateControls();
  552. }
  553. //---------------------------------------------------------------------------
  554. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  555. {
  556. if (Queue != value)
  557. {
  558. if (FQueue != NULL)
  559. {
  560. FQueue->OnListUpdate = NULL;
  561. FQueue->OnQueueItemUpdate = NULL;
  562. }
  563. FQueue = value;
  564. if (FQueue != NULL)
  565. {
  566. DebugAssert(FQueue->OnListUpdate == NULL);
  567. FQueue->OnListUpdate = QueueListUpdate;
  568. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  569. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  570. }
  571. QueueChanged();
  572. }
  573. }
  574. //---------------------------------------------------------------------------
  575. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  576. TListItem * Item)
  577. {
  578. if (FQueueActedItem == Item)
  579. {
  580. FQueueActedItem = NULL;
  581. if ((QueueView3->PopupMenu != NULL) &&
  582. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  583. {
  584. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  585. ReleaseCapture();
  586. }
  587. }
  588. if (Item->Data == FPendingQueueActionItem)
  589. {
  590. FPendingQueueActionItem = NULL;
  591. }
  592. }
  593. //---------------------------------------------------------------------------
  594. bool TCustomScpExplorerForm::IsAnythingQueued()
  595. {
  596. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  597. }
  598. //---------------------------------------------------------------------------
  599. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  600. {
  601. {
  602. TGuard Guard(FQueueStatusSection);
  603. FQueueStatusInvalidated = false;
  604. if (FQueue != NULL)
  605. {
  606. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  607. }
  608. }
  609. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  610. {
  611. FMaxQueueLength = FQueueStatus->Count;
  612. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  613. }
  614. {
  615. TAutoFlag Flag(FQueueStatusUpdating);
  616. FQueueController->UpdateQueueStatus(FQueueStatus);
  617. }
  618. UpdateQueueFileList();
  619. SetQueueProgress();
  620. UpdateQueueView();
  621. bool IsEmpty = !IsAnythingQueued();
  622. if (IsEmpty && (Terminal != NULL))
  623. {
  624. TOnceDoneOperation OnceDoneOperation =
  625. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  626. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  627. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  628. {
  629. FQueue->Enabled = false;
  630. }
  631. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  632. {
  633. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  634. }
  635. }
  636. }
  637. //---------------------------------------------------------------------------
  638. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  639. {
  640. UnicodeString Result;
  641. if (FQueueStatus != NULL)
  642. {
  643. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  644. {
  645. TFileOperationProgressType * ProgressData =
  646. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  647. if ((ProgressData != NULL) && ProgressData->InProgress)
  648. {
  649. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  650. }
  651. }
  652. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  653. {
  654. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  655. }
  656. }
  657. return Result;
  658. }
  659. //---------------------------------------------------------------------------
  660. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  661. {
  662. ComponentVisible[fcQueueView] =
  663. (WinConfiguration->QueueView.Show == qvShow) ||
  664. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  665. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  666. }
  667. //---------------------------------------------------------------------------
  668. void __fastcall TCustomScpExplorerForm::QueueChanged()
  669. {
  670. if (FQueueStatus != NULL)
  671. {
  672. // UpdateFileList implementation relies on the status being recreated when session changes
  673. delete FQueueStatus;
  674. FQueueStatus = NULL;
  675. }
  676. UpdateQueueStatus(true);
  677. }
  678. //---------------------------------------------------------------------------
  679. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  680. {
  681. if (FQueue == Queue)
  682. {
  683. FQueueStatusInvalidated = true;
  684. }
  685. }
  686. //---------------------------------------------------------------------------
  687. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  688. TQueueItem * Item)
  689. {
  690. if (FQueue == Queue)
  691. {
  692. TGuard Guard(FQueueStatusSection);
  693. // this may be running in parallel with QueueChanged
  694. if (FQueueStatus != NULL)
  695. {
  696. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  697. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  698. {
  699. FRefreshLocalDirectory = (QueueItem == NULL) ||
  700. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  701. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  702. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  703. }
  704. if (QueueItem != NULL)
  705. {
  706. QueueItem->UserData = (void*)true;
  707. FQueueItemInvalidated = true;
  708. }
  709. }
  710. }
  711. }
  712. //---------------------------------------------------------------------------
  713. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  714. {
  715. // during standalone editing, we have no way to see/control queue,
  716. // so we have to always popup prompts automatically
  717. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  718. }
  719. //---------------------------------------------------------------------------
  720. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  721. {
  722. if (FQueueStatus != NULL)
  723. {
  724. bool QueueAutoPopup = IsQueueAutoPopup();
  725. bool NeedRefresh = FQueueController->NeedRefresh();
  726. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  727. FQueueItemInvalidated = false;
  728. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  729. bool Updated = false;
  730. TQueueItemProxy * QueueItem;
  731. bool WasUserAction;
  732. for (int Index = 0; Index < Limit; Index++)
  733. {
  734. bool Update = false;
  735. QueueItem = FQueueStatus->Items[Index];
  736. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  737. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  738. (FPendingQueueActionItem == NULL))
  739. {
  740. FPendingQueueActionItem = QueueItem;
  741. FUserActionTimer->Enabled = true;
  742. }
  743. if ((bool)QueueItem->UserData)
  744. {
  745. QueueItem->UserData = (void*)false;
  746. QueueItem->Update();
  747. Updated = true;
  748. Update = true;
  749. }
  750. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  751. {
  752. Update = true;
  753. }
  754. if (Update)
  755. {
  756. FQueueController->RefreshQueueItem(QueueItem);
  757. }
  758. }
  759. if (Updated)
  760. {
  761. NonVisualDataModule->UpdateNonVisibleActions();
  762. SetQueueProgress();
  763. UpdateQueueFileList();
  764. }
  765. }
  766. }
  767. //---------------------------------------------------------------------------
  768. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  769. {
  770. if (FTaskbarList != NULL)
  771. {
  772. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  773. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  774. }
  775. }
  776. //---------------------------------------------------------------------------
  777. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  778. {
  779. if (Progress >= 0)
  780. {
  781. if (FTaskbarList != NULL)
  782. {
  783. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  784. }
  785. }
  786. else
  787. {
  788. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  789. }
  790. }
  791. //---------------------------------------------------------------------------
  792. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  793. {
  794. int OverallProgress;
  795. // FProgressForm is null when this is called from SetQueueProgress
  796. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  797. {
  798. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  799. }
  800. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  801. {
  802. OverallProgress = ProgressData->OverallProgress();
  803. }
  804. else
  805. {
  806. OverallProgress = -1;
  807. }
  808. SetTaskbarListProgressValue(OverallProgress);
  809. }
  810. //---------------------------------------------------------------------------
  811. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  812. {
  813. TTerminalManager::Instance()->QueueStatusUpdated();
  814. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  815. {
  816. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  817. {
  818. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  819. {
  820. TFileOperationProgressType * ProgressData = NULL;
  821. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  822. {
  823. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  824. }
  825. if ((ProgressData != NULL) &&
  826. ProgressData->InProgress)
  827. {
  828. SetTaskbarListProgressValue(ProgressData);
  829. }
  830. else
  831. {
  832. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  833. }
  834. }
  835. else
  836. {
  837. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  838. }
  839. }
  840. else
  841. {
  842. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  843. }
  844. }
  845. UpdateQueueLabel();
  846. }
  847. //---------------------------------------------------------------------------
  848. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  849. {
  850. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  851. if (FQueueStatus != NULL)
  852. {
  853. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  854. if (ActiveAndPendingPrimaryCount > 0)
  855. {
  856. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  857. }
  858. }
  859. QueueLabel->Caption = Caption;
  860. }
  861. //---------------------------------------------------------------------------
  862. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  863. {
  864. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  865. static_cast<TComponent*>(GetComponent(fcTransferList)));
  866. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  867. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  868. TransferList->Strings->BeginUpdate();
  869. try
  870. {
  871. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  872. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  873. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  874. if (FTransferDropDownHint.IsEmpty())
  875. {
  876. FTransferDropDownHint = TransferDropDown->Hint;
  877. }
  878. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  879. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  880. TransferDropDown->Text = StripHotkey(Name);
  881. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  882. (FTransferDropDownHint, StripHotkey(Name),
  883. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  884. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  885. // update the label, otherwise when it is updated only on the first draw
  886. // of the list, it is drawn "bold" for some reason
  887. FTransferListHoverIndex = TransferList->ItemIndex;
  888. UpdateTransferLabel();
  889. }
  890. __finally
  891. {
  892. TransferList->Strings->EndUpdate();
  893. }
  894. }
  895. //---------------------------------------------------------------------------
  896. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  897. {
  898. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  899. DebugAssert(Toolbar != NULL);
  900. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  901. }
  902. //---------------------------------------------------------------------------
  903. void __fastcall TCustomScpExplorerForm::UpdateActions()
  904. {
  905. TForm::UpdateActions();
  906. if (ComponentVisible[fcCustomCommandsBand])
  907. {
  908. UpdateCustomCommandsToolbar();
  909. }
  910. }
  911. //---------------------------------------------------------------------------
  912. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  913. {
  914. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  915. }
  916. //---------------------------------------------------------------------------
  917. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  918. {
  919. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  920. {
  921. DirView->RowSelect = WinConfiguration->FullRowSelect;
  922. // selection is not redrawn automatically when RowSelect changes
  923. DirView->Invalidate();
  924. }
  925. }
  926. //---------------------------------------------------------------------------
  927. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  928. {
  929. Color = GetBtnFaceColor();
  930. DebugAssert(Configuration && RemoteDirView);
  931. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  932. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  933. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  934. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  935. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  936. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  937. UpdateRowSelect(RemoteDirView);
  938. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  939. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  940. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  941. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  942. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  943. UpdateSessionsPageControlHeight();
  944. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  945. UpdateToolbarDisplayMode();
  946. UpdateTransferList();
  947. if (Terminal != NULL)
  948. {
  949. TransferPresetAutoSelect();
  950. }
  951. UpdateQueueView();
  952. UpdateControls();
  953. // this can be called even before constuctor finishes.
  954. if (FEditorManager != NULL)
  955. {
  956. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  957. }
  958. // this can be called even before constuctor finishes.
  959. if (FLocalEditors != NULL)
  960. {
  961. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  962. {
  963. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  964. }
  965. }
  966. if (ComponentVisible[fcCustomCommandsBand])
  967. {
  968. UpdateCustomCommandsToolbar();
  969. }
  970. // show only when keeping queue items forever,
  971. // otherwise, its enough to have in in the context menu
  972. QueueDeleteAllDoneQueueToolbarItem->Visible =
  973. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  974. if (FFileColorsCurrent != WinConfiguration->FileColors)
  975. {
  976. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  977. FFileColorsCurrent = WinConfiguration->FileColors;
  978. FileColorsChanged();
  979. }
  980. }
  981. //---------------------------------------------------------------------------
  982. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  983. {
  984. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  985. DirView->Invalidate();
  986. }
  987. //---------------------------------------------------------------------------
  988. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  989. {
  990. DoFileColorsChanged(RemoteDirView);
  991. }
  992. //---------------------------------------------------------------------------
  993. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  994. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  995. void * /*Arg*/)
  996. {
  997. if (Token != NULL)
  998. {
  999. TForm * Editor = dynamic_cast<TForm*>(Token);
  1000. DebugAssert(Editor != NULL);
  1001. ReconfigureEditorForm(Editor);
  1002. }
  1003. }
  1004. //---------------------------------------------------------------------------
  1005. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1006. {
  1007. WinConfiguration->DDTransferConfirmation = asOn;
  1008. }
  1009. //---------------------------------------------------------------------------
  1010. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1011. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1012. {
  1013. // noop
  1014. }
  1015. //---------------------------------------------------------------------------
  1016. bool TCustomScpExplorerForm::GetDoNotShowCopyDialogDefault(bool DragDrop)
  1017. {
  1018. return DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto);
  1019. }
  1020. //---------------------------------------------------------------------------
  1021. void TCustomScpExplorerForm::HandleDoNotShowCopyDialogAgain(bool DragDrop, bool DoNotShowAgain)
  1022. {
  1023. if (DoNotShowAgain)
  1024. {
  1025. if (DragDrop)
  1026. {
  1027. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1028. {
  1029. PopupTrayBalloon(
  1030. NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation, NULL, 0, EnableDDTransferConfirmation, NULL);
  1031. }
  1032. WinConfiguration->DDTransferConfirmation = asOff;
  1033. }
  1034. else
  1035. {
  1036. WinConfiguration->ConfirmTransferring = false;
  1037. }
  1038. }
  1039. else
  1040. {
  1041. // User explicitly unchecked "do not show again",
  1042. // so show him the dialog the next time
  1043. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1044. {
  1045. WinConfiguration->DDTransferConfirmation = asOn;
  1046. }
  1047. }
  1048. }
  1049. //---------------------------------------------------------------------------
  1050. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1051. TTransferDirection Direction, TTransferType Type, bool Temp,
  1052. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1053. bool Confirm, bool DragDrop, int Options)
  1054. {
  1055. bool Result = true;
  1056. DebugAssert(HasActiveTerminal());
  1057. // these parameters are known in advance
  1058. int Params =
  1059. FLAGMASK(Type == ttMove, cpDelete);
  1060. bool ToTemp = (Temp && (Direction == tdToLocal));
  1061. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1062. {
  1063. bool DisableNewerOnly =
  1064. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1065. ToTemp;
  1066. Options |=
  1067. FLAGMASK(ToTemp, coTemp) |
  1068. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1069. coDoNotShowAgain;
  1070. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1071. int CopyParamAttrs = (Direction == tdToRemote ?
  1072. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1073. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1074. int OutputOptions = FLAGMASK(GetDoNotShowCopyDialogDefault(DragDrop), cooDoNotShowAgain);
  1075. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1076. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1077. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1078. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1079. if (Result)
  1080. {
  1081. HandleDoNotShowCopyDialogAgain(DragDrop, FLAGSET(OutputOptions, cooDoNotShowAgain));
  1082. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1083. }
  1084. }
  1085. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1086. {
  1087. Configuration->Usage->Inc(L"TransfersOnBackground");
  1088. // these parameter are known only after transfer dialog
  1089. Params |=
  1090. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1091. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1092. Result = false;
  1093. ClearTransferSourceSelection(Direction);
  1094. }
  1095. return Result;
  1096. }
  1097. //---------------------------------------------------------------------------
  1098. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1099. {
  1100. if (FOnFileOperationFinished != NULL)
  1101. {
  1102. FOnFileOperationFinished(UnicodeString(), true);
  1103. }
  1104. else
  1105. {
  1106. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1107. if (HasDirView[Side])
  1108. {
  1109. DirView(Side)->SelectAll(smNone);
  1110. }
  1111. }
  1112. }
  1113. //---------------------------------------------------------------------------
  1114. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1115. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1116. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1117. int Params)
  1118. {
  1119. DebugAssert(Queue != NULL);
  1120. bool SingleFile = false;
  1121. if (FileList->Count == 1)
  1122. {
  1123. if (Direction == tdToRemote)
  1124. {
  1125. UnicodeString FileName = FileList->Strings[0];
  1126. SingleFile = FileExists(ApiPath(FileName));
  1127. }
  1128. else
  1129. {
  1130. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1131. SingleFile = !File->IsDirectory;
  1132. }
  1133. }
  1134. TQueueItem * QueueItem;
  1135. if (Direction == tdToRemote)
  1136. {
  1137. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1138. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1139. }
  1140. else
  1141. {
  1142. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1143. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1144. }
  1145. AddQueueItem(Queue, QueueItem, Terminal);
  1146. }
  1147. //---------------------------------------------------------------------------
  1148. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1149. {
  1150. if (Queue->IsEmpty)
  1151. {
  1152. Terminal->QueueOperationStart = Now();
  1153. }
  1154. Queue->AddItem(QueueItem);
  1155. }
  1156. //---------------------------------------------------------------------------
  1157. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1158. {
  1159. }
  1160. //---------------------------------------------------------------------------
  1161. void __fastcall TCustomScpExplorerForm::InitControls()
  1162. {
  1163. DebugAssert(FDocks != NULL);
  1164. for (int Index = 0; Index < ComponentCount; Index++)
  1165. {
  1166. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1167. if ((Dock != NULL) && (Dock->Tag == 0))
  1168. {
  1169. FDocks->Add(Dock);
  1170. }
  1171. }
  1172. CollectItemsWithTextDisplayMode(this);
  1173. }
  1174. //---------------------------------------------------------------------------
  1175. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1176. {
  1177. ConfigurationChanged();
  1178. QueuePanel->Height =
  1179. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1180. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1181. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1182. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1183. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1184. QueueFileList->Height =
  1185. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1186. if (QueueFileList->Visible)
  1187. {
  1188. AdjustQueueLayout();
  1189. }
  1190. UpdateCustomCommandsToolbar();
  1191. }
  1192. //---------------------------------------------------------------------------
  1193. void __fastcall TCustomScpExplorerForm::StoreParams()
  1194. {
  1195. int APixelsPerInch = GetControlPixelsPerInch(this);
  1196. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1197. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1198. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1199. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1200. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1201. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1202. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1203. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1204. }
  1205. //---------------------------------------------------------------------------
  1206. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1207. {
  1208. if (!FFormRestored)
  1209. {
  1210. FFormRestored = true;
  1211. RestoreFormParams();
  1212. }
  1213. TForm::CreateParams(Params);
  1214. }
  1215. //---------------------------------------------------------------------------
  1216. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1217. {
  1218. DebugAssert(FDocks != NULL);
  1219. for (int Index = 0; Index < FDocks->Count; Index++)
  1220. {
  1221. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1222. }
  1223. }
  1224. //---------------------------------------------------------------------------
  1225. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1226. {
  1227. SetDockAllowDrag(true);
  1228. while (!ButtonsStr.IsEmpty())
  1229. {
  1230. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1231. UnicodeString Name = CutToChar(S, L'=', true);
  1232. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1233. {
  1234. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1235. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1236. {
  1237. while (!S.IsEmpty())
  1238. {
  1239. UnicodeString S2 = CutToChar(S, L',', true);
  1240. UnicodeString Name = CutToChar(S2, L':', true);
  1241. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1242. {
  1243. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1244. if (SameText(GetToolbarItemName(Item), Name))
  1245. {
  1246. // forward compatibility
  1247. UnicodeString S3 = CutToChar(S2, L':', true);
  1248. bool Visible = StrToIntDef(S3, 0);
  1249. Item->Visible = Visible;
  1250. }
  1251. }
  1252. }
  1253. }
  1254. }
  1255. }
  1256. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1257. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1258. }
  1259. //---------------------------------------------------------------------------
  1260. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1261. {
  1262. UnicodeString Result;
  1263. SetDockAllowDrag(true);
  1264. Result = ::GetToolbarsLayoutStr(this);
  1265. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1266. return Result;
  1267. }
  1268. //---------------------------------------------------------------------------
  1269. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1270. {
  1271. UnicodeString Result;
  1272. if (Item->Action != NULL)
  1273. {
  1274. Result = Item->Action->Name;
  1275. Result = RemoveSuffix(Result, L"Action", true);
  1276. }
  1277. else
  1278. {
  1279. Result = Item->Name;
  1280. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1281. Result = RemoveSuffix(Result, L"Item", true);
  1282. }
  1283. return Result;
  1284. }
  1285. //---------------------------------------------------------------------------
  1286. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1287. {
  1288. UnicodeString Result;
  1289. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1290. {
  1291. UnicodeString ToolbarStr;
  1292. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1293. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1294. {
  1295. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1296. {
  1297. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1298. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1299. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1300. // and save the changes here only.
  1301. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1302. {
  1303. UnicodeString Name = GetToolbarItemName(Item);
  1304. DebugAssert(Name.Pos(L"TBX") == 0);
  1305. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1306. }
  1307. }
  1308. }
  1309. if (!ToolbarStr.IsEmpty())
  1310. {
  1311. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1312. }
  1313. }
  1314. return Result;
  1315. }
  1316. //---------------------------------------------------------------------------
  1317. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1318. {
  1319. DebugAssert(FProgressForm == NULL);
  1320. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1321. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1322. FProgressForm->DeleteLocalToRecycleBin =
  1323. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1324. FProgressForm->DeleteRemoteToRecycleBin =
  1325. (Terminal != NULL) &&
  1326. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1327. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1328. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1329. LockWindow();
  1330. // Actually, do not know what hides the progress once the operation finishes
  1331. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1332. SetTaskbarListProgressState(TBPF_NORMAL);
  1333. }
  1334. //---------------------------------------------------------------------------
  1335. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1336. {
  1337. UnlockWindow();
  1338. SAFE_DESTROY(FProgressForm);
  1339. SetQueueProgress();
  1340. }
  1341. //---------------------------------------------------------------------------
  1342. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1343. TFileOperationProgressType & ProgressData)
  1344. {
  1345. // Download to temporary local directory
  1346. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1347. {
  1348. bool Continue = true;
  1349. FPendingTempSpaceWarn = false;
  1350. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1351. if (!Continue)
  1352. {
  1353. Abort();
  1354. }
  1355. }
  1356. // operation is being executed and we still didn't show up progress form
  1357. if (ProgressData.InProgress && !FProgressForm)
  1358. {
  1359. CreateProgressForm(NULL);
  1360. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1361. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1362. }
  1363. // operation is finished (or terminated), so we hide progress form
  1364. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1365. {
  1366. DestroyProgressForm();
  1367. if (ProgressData.Operation == foCalculateSize)
  1368. {
  1369. // When calculating size before transfer, the abort caused by
  1370. // cancel flag set due to "MoveToQueue" below,
  1371. // is not propagated back to us in ExecuteFileOperation,
  1372. // as it is silently swallowed.
  1373. // So we explicitly (re)throw it here.
  1374. if (FMoveToQueue)
  1375. {
  1376. Abort();
  1377. }
  1378. }
  1379. else
  1380. {
  1381. if ((ProgressData.Cancel == csContinue) &&
  1382. !FAutoOperation)
  1383. {
  1384. OperationComplete(ProgressData.StartTime);
  1385. }
  1386. }
  1387. }
  1388. if (FProgressForm &&
  1389. // Can happen only during synchronization, when ending one of the operations
  1390. ProgressData.InProgress)
  1391. {
  1392. FProgressForm->SetProgressData(ProgressData);
  1393. DebugAssert(ProgressData.InProgress);
  1394. SetTaskbarListProgressValue(&ProgressData);
  1395. if (FProgressForm->Cancel > csContinue)
  1396. {
  1397. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1398. if (FProgressForm->Cancel == csCancelFile)
  1399. {
  1400. FProgressForm->ClearCancel();
  1401. }
  1402. // cancel cancels even the move
  1403. FMoveToQueue = false;
  1404. }
  1405. else if (FProgressForm->MoveToQueue)
  1406. {
  1407. FMoveToQueue = true;
  1408. ProgressData.SetCancelAtLeast(csCancel);
  1409. }
  1410. if ((FTransferResumeList != NULL) &&
  1411. ProgressData.InProgress &&
  1412. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1413. !ProgressData.FullFileName.IsEmpty())
  1414. {
  1415. if ((FTransferResumeList->Count == 0) ||
  1416. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1417. {
  1418. // note that we do not recognize directories from files here
  1419. FTransferResumeList->Add(ProgressData.FullFileName);
  1420. }
  1421. }
  1422. }
  1423. }
  1424. //---------------------------------------------------------------------------
  1425. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1426. const TDateTime & StartTime)
  1427. {
  1428. if (GUIConfiguration->BeepOnFinish &&
  1429. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1430. {
  1431. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1432. DWORD Sound;
  1433. if (!ExtractFileExt(BeepSound).IsEmpty())
  1434. {
  1435. Sound = SND_FILENAME;
  1436. }
  1437. else
  1438. {
  1439. Sound = SND_ALIAS;
  1440. }
  1441. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1442. }
  1443. }
  1444. //---------------------------------------------------------------------------
  1445. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1446. TFileOperationProgressType & ProgressData)
  1447. {
  1448. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1449. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1450. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1451. FileOperationProgress(ProgressData);
  1452. }
  1453. //---------------------------------------------------------------------------
  1454. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1455. {
  1456. UnicodeString Result;
  1457. if (FProgressForm != NULL)
  1458. {
  1459. Result = FProgressForm->ProgressStr();
  1460. }
  1461. return Result;
  1462. }
  1463. //---------------------------------------------------------------------------
  1464. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1465. bool DragDrop)
  1466. {
  1467. return (!DragDrop && (DropSourceControl == NULL)) ||
  1468. (DropSourceControl == DirView(osOther));
  1469. }
  1470. //---------------------------------------------------------------------------
  1471. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1472. TFileOperation Operation, TOperationSide Side,
  1473. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1474. TOnceDoneOperation & OnceDoneOperation)
  1475. {
  1476. if (!FAutoOperation)
  1477. {
  1478. // no selection on "/upload", form serves only as event handler
  1479. // (it is not displayed)
  1480. if (PanelOperation(Side, FDragDropOperation) &&
  1481. Visible && (Operation != foCalculateSize) &&
  1482. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1483. {
  1484. if (FOnFileOperationFinished != NULL)
  1485. {
  1486. FOnFileOperationFinished(FileName, Success);
  1487. }
  1488. else
  1489. {
  1490. TOperationSide DViewSide;
  1491. if ((FProgressSide != osCurrent) &&
  1492. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1493. {
  1494. // assume the operation is over the focused panel
  1495. DViewSide = FProgressSide;
  1496. }
  1497. else
  1498. {
  1499. DViewSide = Side;
  1500. }
  1501. TCustomDirView * DView = DirView(DViewSide);
  1502. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(DViewSide));
  1503. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1504. // this can happen when local drive is unplugged in the middle of the operation
  1505. if (Item != NULL)
  1506. {
  1507. if (Success) Item->Selected = false;
  1508. DView->MakeProgressVisible(Item);
  1509. }
  1510. }
  1511. }
  1512. if ((Operation == foCopy) || (Operation == foMove))
  1513. {
  1514. if (DebugAlwaysTrue(!IsLocalBrowserMode()))
  1515. {
  1516. if (Side == osLocal)
  1517. {
  1518. Configuration->Usage->Inc(L"UploadedFiles");
  1519. }
  1520. else
  1521. {
  1522. Configuration->Usage->Inc(L"DownloadedFiles");
  1523. }
  1524. }
  1525. }
  1526. }
  1527. if (Success && (FSynchronizeController != NULL))
  1528. {
  1529. DebugAssert(!IsSideLocalBrowser(osRemote));
  1530. if (Operation == foCopy)
  1531. {
  1532. DebugAssert(Side == osLocal);
  1533. FSynchronizeController->LogOperation(soUpload, FileName);
  1534. }
  1535. else if (Operation == foDelete)
  1536. {
  1537. DebugAssert(Side == osRemote);
  1538. FSynchronizeController->LogOperation(soDelete, FileName);
  1539. }
  1540. }
  1541. if (FProgressForm)
  1542. {
  1543. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1544. }
  1545. }
  1546. //---------------------------------------------------------------------------
  1547. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1548. TFileOperation Operation, TOperationSide Side,
  1549. bool Temp, const UnicodeString & FileName, Boolean Success,
  1550. TOnceDoneOperation & OnceDoneOperation)
  1551. {
  1552. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1553. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1554. OnceDoneOperation);
  1555. }
  1556. //---------------------------------------------------------------------------
  1557. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1558. {
  1559. return false;
  1560. }
  1561. //---------------------------------------------------------------------------
  1562. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1563. {
  1564. return false;
  1565. }
  1566. //---------------------------------------------------------------------------
  1567. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1568. {
  1569. return NULL;
  1570. }
  1571. //---------------------------------------------------------------------------
  1572. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1573. {
  1574. DebugAssert(GetSide(Side) == osRemote);
  1575. DebugUsedParam(Side);
  1576. return RemoteDirView;
  1577. }
  1578. //---------------------------------------------------------------------------
  1579. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1580. {
  1581. DebugAssert(GetSide(Side) == osRemote);
  1582. DebugUsedParam(Side);
  1583. return RemoteDriveView;
  1584. }
  1585. //---------------------------------------------------------------------------
  1586. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1587. {
  1588. DebugAssert(GetSide(Side) == osRemote);
  1589. DebugUsedParam(Side);
  1590. return HasActiveTerminal();
  1591. }
  1592. //---------------------------------------------------------------------------
  1593. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1594. TOperationSide Side, int FilesOnly)
  1595. {
  1596. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1597. }
  1598. //---------------------------------------------------------------------------
  1599. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1600. TOperationSide Side, int FilesOnly)
  1601. {
  1602. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1603. }
  1604. //---------------------------------------------------------------------------
  1605. struct THistoryItemData
  1606. {
  1607. short int Side;
  1608. short int Index;
  1609. };
  1610. //---------------------------------------------------------------------------
  1611. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1612. {
  1613. DirView(Side)->HistoryGo(Index);
  1614. }
  1615. //---------------------------------------------------------------------------
  1616. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1617. {
  1618. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1619. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1620. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1621. }
  1622. //---------------------------------------------------------------------------
  1623. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1624. bool Back)
  1625. {
  1626. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1627. {
  1628. TCustomDirView * DView = DirView(Side);
  1629. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1630. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1631. if (ICount > 10)
  1632. {
  1633. ICount = 10;
  1634. }
  1635. Menu->Items->Clear();
  1636. THistoryItemData Data;
  1637. Data.Side = Side;
  1638. for (short int i = 1; i <= ICount; i++)
  1639. {
  1640. TTBCustomItem * Item = new TTBXItem(Menu);
  1641. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1642. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1643. Item->Hint = DView->HistoryPath[Data.Index];
  1644. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1645. Item->Tag = *reinterpret_cast<int*>(&Data);
  1646. Item->OnClick = HistoryItemClick;
  1647. Menu->Items->Add(Item);
  1648. }
  1649. }
  1650. }
  1651. //---------------------------------------------------------------------------
  1652. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1653. TOperationSide Side, bool Back)
  1654. {
  1655. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1656. {
  1657. // workaround
  1658. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1659. // operator new allocates memory in Pascal code, but calls inline
  1660. // contructor in C++, leading in problems, the function does
  1661. // both in Pascal code
  1662. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1663. UpdateHistoryMenu(Side, Back);
  1664. }
  1665. return FHistoryMenu[Side == osLocal][Back];
  1666. }
  1667. //---------------------------------------------------------------------------
  1668. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1669. TCustomDirView *Sender)
  1670. {
  1671. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1672. UpdateHistoryMenu(Side, true);
  1673. UpdateHistoryMenu(Side, false);
  1674. }
  1675. //---------------------------------------------------------------------------
  1676. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1677. {
  1678. // remote custom commands can be executed only if the server supports shell commands
  1679. // or have secondary shell
  1680. return HasActiveTerminal() && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1681. }
  1682. //---------------------------------------------------------------------------
  1683. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1684. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1685. {
  1686. // -1 = hidden, 0 = disabled, 1 = enabled
  1687. int Result;
  1688. TFileCustomCommand RemoteCustomCommand;
  1689. TLocalCustomCommand LocalCustomCommand;
  1690. TFileCustomCommand * NonInteractiveCustomCommand =
  1691. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1692. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1693. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1694. if (FLAGCLEAR(Command.Params, ccLocal))
  1695. {
  1696. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1697. // custom command that does not operate with files can be executed anytime ...
  1698. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1699. {
  1700. // ... but do not show such command in remote file menu
  1701. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1702. {
  1703. Result = AllowedState;
  1704. }
  1705. else
  1706. {
  1707. Result = -1;
  1708. }
  1709. }
  1710. else
  1711. {
  1712. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1713. {
  1714. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1715. }
  1716. else
  1717. {
  1718. Result = -1;
  1719. }
  1720. }
  1721. }
  1722. else
  1723. {
  1724. // custom command that does not operate with files can be executed anytime
  1725. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1726. {
  1727. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1728. }
  1729. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1730. {
  1731. if ((ListType == ccltAll) || (ListType == ccltFile))
  1732. {
  1733. // special case is "diff"-style command that can be executed over any side,
  1734. // if we have both sides
  1735. Result =
  1736. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1737. // directly (instead of EnableSelectedOperation) to pass
  1738. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1739. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1740. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1741. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1742. }
  1743. else if (ListType == ccltBoth)
  1744. {
  1745. DebugAssert(!IsLocalBrowserMode());
  1746. Result = 1;
  1747. }
  1748. else
  1749. {
  1750. Result = -1;
  1751. }
  1752. }
  1753. else
  1754. {
  1755. if ((ListType == ccltAll) ||
  1756. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1757. {
  1758. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1759. }
  1760. else
  1761. {
  1762. Result = -1;
  1763. }
  1764. }
  1765. if ((Result > 0) &&
  1766. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1767. !HasActiveTerminal())
  1768. {
  1769. Result = 0;
  1770. }
  1771. }
  1772. return Result;
  1773. }
  1774. //---------------------------------------------------------------------------
  1775. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1776. TStrings * FileList, const TCustomCommandType & ACommand,
  1777. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1778. {
  1779. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1780. {
  1781. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1782. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1783. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1784. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1785. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1786. bool Capture =
  1787. FLAGSET(ACommand.Params, ccShowResults) ||
  1788. FLAGSET(ACommand.Params, ccCopyResults) ||
  1789. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1790. TCaptureOutputEvent OutputEvent = NULL;
  1791. DebugAssert(FCapturedLog == NULL);
  1792. if (Capture)
  1793. {
  1794. FCapturedLog = new TStringList();
  1795. OutputEvent = TerminalCaptureLog;
  1796. }
  1797. try
  1798. {
  1799. if (!RemoteCustomCommand.IsFileCommand(Command))
  1800. {
  1801. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1802. OutputEvent);
  1803. }
  1804. else
  1805. {
  1806. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1807. }
  1808. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1809. {
  1810. if (FLAGSET(ACommand.Params, ccCopyResults))
  1811. {
  1812. CopyToClipboard(FCapturedLog);
  1813. }
  1814. if (FLAGSET(ACommand.Params, ccShowResults))
  1815. {
  1816. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1817. }
  1818. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1819. {
  1820. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1821. }
  1822. }
  1823. }
  1824. __finally
  1825. {
  1826. SAFE_DESTROY(FCapturedLog);
  1827. }
  1828. }
  1829. }
  1830. //---------------------------------------------------------------------------
  1831. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1832. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1833. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1834. {
  1835. DebugAssert(!IsLocalBrowserMode());
  1836. TStrings * LocalFileList = NULL;
  1837. TStrings * RemoteFileList = NULL;
  1838. TStrings * RemoteFileListFull = NULL;
  1839. try
  1840. {
  1841. if (LocalFileCommand)
  1842. {
  1843. if (ALocalFileList == NULL)
  1844. {
  1845. DebugAssert(HasDirView[osLocal]);
  1846. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1847. // directly (instead of EnableSelectedOperation) to pass
  1848. // false to FocusedFileOnlyWhenFocused
  1849. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1850. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1851. }
  1852. else
  1853. {
  1854. LocalFileList = ALocalFileList;
  1855. }
  1856. if (FileListCommand)
  1857. {
  1858. if (LocalFileList->Count != 1)
  1859. {
  1860. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1861. }
  1862. }
  1863. else
  1864. {
  1865. if ((LocalFileList->Count != 1) &&
  1866. (FileList->Count != 1) &&
  1867. (LocalFileList->Count != FileList->Count))
  1868. {
  1869. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1870. }
  1871. }
  1872. }
  1873. UnicodeString RootTempDir;
  1874. UnicodeString TempDir;
  1875. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1876. if (!RemoteFiles)
  1877. {
  1878. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1879. }
  1880. try
  1881. {
  1882. TDateTimes RemoteFileTimes;
  1883. if (RemoteFiles)
  1884. {
  1885. RemoteFileList = FileList;
  1886. }
  1887. else
  1888. {
  1889. RemoteFileList = new TStringList();
  1890. TMakeLocalFileListParams MakeFileListParam;
  1891. MakeFileListParam.FileList = RemoteFileList;
  1892. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1893. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1894. MakeFileListParam.Recursive =
  1895. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1896. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1897. if (!MakeFileListParam.Recursive)
  1898. {
  1899. RemoteFileTimes.clear();
  1900. RemoteFileListFull = new TStringList();
  1901. MakeFileListParam.FileList = RemoteFileListFull;
  1902. MakeFileListParam.Recursive = true;
  1903. MakeFileListParam.IncludeDirs = false;
  1904. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1905. }
  1906. else
  1907. {
  1908. RemoteFileListFull = RemoteFileList;
  1909. }
  1910. }
  1911. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1912. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1913. if (!NonBlocking)
  1914. {
  1915. int Count;
  1916. if (FileListCommand)
  1917. {
  1918. Count = 1;
  1919. }
  1920. else if (LocalFileCommand)
  1921. {
  1922. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1923. }
  1924. else
  1925. {
  1926. Count = RemoteFileList->Count;
  1927. }
  1928. Progress.Start(foCustomCommand, osRemote, Count);
  1929. DebugAssert(FProgressForm != NULL);
  1930. FProgressForm->ReadOnly = true;
  1931. }
  1932. try
  1933. {
  1934. if (FileListCommand)
  1935. {
  1936. UnicodeString LocalFile;
  1937. // MakeFileList does not delimit filenames
  1938. UnicodeString FileList = MakeFileList(RemoteFileList);
  1939. if (LocalFileCommand)
  1940. {
  1941. DebugAssert(LocalFileList->Count == 1);
  1942. LocalFile = LocalFileList->Strings[0];
  1943. }
  1944. TLocalCustomCommand CustomCommand(Data,
  1945. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1946. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1947. if (NonBlocking)
  1948. {
  1949. DebugAssert(!POutput);
  1950. ExecuteShellChecked(ShellCommand);
  1951. }
  1952. else
  1953. {
  1954. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1955. }
  1956. }
  1957. else if (LocalFileCommand)
  1958. {
  1959. if (LocalFileList->Count == 1)
  1960. {
  1961. UnicodeString LocalFile = LocalFileList->Strings[0];
  1962. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1963. {
  1964. UnicodeString FileName = RemoteFileList->Strings[Index];
  1965. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1966. Progress.SetFile(FileNameForProgress);
  1967. TLocalCustomCommand CustomCommand(Data,
  1968. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1969. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1970. TOnceDoneOperation OnceDoneOperation;
  1971. // Do not unselect anything, as it won't work with two panels anyway
  1972. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1973. }
  1974. }
  1975. else if (RemoteFileList->Count == 1)
  1976. {
  1977. UnicodeString FileName = RemoteFileList->Strings[0];
  1978. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1979. {
  1980. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1981. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1982. Progress.SetFile(LocalFileNameOnly);
  1983. TLocalCustomCommand CustomCommand(
  1984. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1985. FileName, LocalFileName, L"");
  1986. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1987. TOnceDoneOperation OnceDoneOperation;
  1988. // Do not unselect anything, as it won't work with two panels anyway
  1989. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1990. }
  1991. }
  1992. else
  1993. {
  1994. if (LocalFileList->Count != RemoteFileList->Count)
  1995. {
  1996. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1997. }
  1998. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1999. {
  2000. UnicodeString FileName = RemoteFileList->Strings[Index];
  2001. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2002. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2003. Progress.SetFile(LocalFileNameOnly); // sic
  2004. TLocalCustomCommand CustomCommand(
  2005. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2006. FileName, LocalFileName, L"");
  2007. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2008. TOnceDoneOperation OnceDoneOperation;
  2009. // Do not unselect anything, as it won't work with two panels anyway
  2010. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2011. }
  2012. }
  2013. }
  2014. else
  2015. {
  2016. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2017. {
  2018. UnicodeString FileName = RemoteFileList->Strings[Index];
  2019. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2020. Progress.SetFile(FileNameForProgress);
  2021. TLocalCustomCommand CustomCommand(Data,
  2022. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2023. FileName, L"", L"");
  2024. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2025. TOnceDoneOperation OnceDoneOperation;
  2026. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2027. }
  2028. }
  2029. }
  2030. __finally
  2031. {
  2032. if (!NonBlocking)
  2033. {
  2034. Progress.Stop();
  2035. }
  2036. }
  2037. DebugAssert(!FAutoOperation);
  2038. if (!RemoteFiles)
  2039. {
  2040. TempDir = IncludeTrailingBackslash(TempDir);
  2041. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2042. {
  2043. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2044. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2045. // Skip directories, process only nested files.
  2046. // The check is redundant as FileAge fails for directories anyway.
  2047. !DirectoryExists(FileName))
  2048. {
  2049. UnicodeString RemoteDir =
  2050. UnixExtractFileDir(
  2051. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2052. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2053. TDateTime NewTime;
  2054. if (FileAge(FileName, NewTime) &&
  2055. (NewTime != RemoteFileTimes[Index]))
  2056. {
  2057. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2058. TemporaryFileCopyParam(CopyParam);
  2059. CopyParam.FileMask = L"";
  2060. FAutoOperation = true;
  2061. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2062. TemporaryFilesList->Add(FileName);
  2063. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2064. }
  2065. }
  2066. }
  2067. }
  2068. }
  2069. __finally
  2070. {
  2071. FAutoOperation = false;
  2072. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2073. {
  2074. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2075. }
  2076. }
  2077. }
  2078. __finally
  2079. {
  2080. if (RemoteFileList != FileList)
  2081. {
  2082. delete RemoteFileList;
  2083. }
  2084. if (LocalFileList != ALocalFileList)
  2085. {
  2086. delete LocalFileList;
  2087. }
  2088. if (RemoteFileListFull != RemoteFileList)
  2089. {
  2090. delete RemoteFileListFull;
  2091. }
  2092. }
  2093. }
  2094. //---------------------------------------------------------------------------
  2095. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2096. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2097. bool FileListCommand, UnicodeString * POutput)
  2098. {
  2099. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2100. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2101. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2102. {
  2103. UnicodeString FileName = SelectedFileList->Strings[Index];
  2104. if (DirectoryExists(FileName))
  2105. {
  2106. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2107. {
  2108. LocalFileList->Add(FileName);
  2109. }
  2110. if (FLAGSET(ACommand.Params, ccRecursive))
  2111. {
  2112. TMakeLocalFileListParams MakeFileListParam;
  2113. MakeFileListParam.FileList = LocalFileList.get();
  2114. MakeFileListParam.FileTimes = NULL;
  2115. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2116. MakeFileListParam.Recursive = true;
  2117. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2118. }
  2119. }
  2120. else
  2121. {
  2122. LocalFileList->Add(FileName);
  2123. }
  2124. }
  2125. UnicodeString RemotePath;
  2126. if (Terminal != NULL)
  2127. {
  2128. RemotePath = Terminal->CurrentDirectory;
  2129. }
  2130. if (FileListCommand)
  2131. {
  2132. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2133. TLocalCustomCommand CustomCommand(
  2134. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2135. L"", L"", FileList);
  2136. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2137. }
  2138. else
  2139. {
  2140. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2141. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2142. DebugAssert(FProgressForm != NULL);
  2143. FProgressForm->ReadOnly = true;
  2144. try
  2145. {
  2146. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2147. {
  2148. UnicodeString FileName = LocalFileList->Strings[Index];
  2149. Progress.SetFile(FileName);
  2150. TLocalCustomCommand CustomCommand(
  2151. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2152. FileName, L"", L"");
  2153. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2154. TOnceDoneOperation OnceDoneOperation;
  2155. Progress.Finish(FileName, true, OnceDoneOperation);
  2156. }
  2157. }
  2158. __finally
  2159. {
  2160. Progress.Stop();
  2161. }
  2162. }
  2163. }
  2164. //---------------------------------------------------------------------------
  2165. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2166. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2167. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2168. {
  2169. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2170. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2171. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2172. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2173. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2174. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2175. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2176. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2177. std::unique_ptr<UnicodeString> POutput;
  2178. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2179. FLAGSET(ACommand.Params, ccCopyResults))
  2180. {
  2181. POutput.reset(new UnicodeString());
  2182. }
  2183. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  2184. FProgressSide = FCurrentSide;
  2185. if (!LocalCustomCommand.IsFileCommand(Command))
  2186. {
  2187. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2188. }
  2189. // remote files?
  2190. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2191. {
  2192. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2193. }
  2194. // local files
  2195. else
  2196. {
  2197. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2198. }
  2199. if (POutput.get() != NULL)
  2200. {
  2201. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2202. int P = POutput->Pos(sLineBreak);
  2203. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2204. {
  2205. POutput->SetLength(P - 1);
  2206. }
  2207. // Copy even empty output to clipboard
  2208. if (FLAGSET(ACommand.Params, ccCopyResults))
  2209. {
  2210. CopyToClipboard(*POutput);
  2211. }
  2212. // But do not show an empty message box.
  2213. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2214. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2215. !POutput->IsEmpty())
  2216. {
  2217. TClipboardHandler ClipboardHandler;
  2218. ClipboardHandler.Text = *POutput;
  2219. TMessageParams Params;
  2220. TQueryButtonAlias Aliases[1];
  2221. Aliases[0].Button = qaRetry;
  2222. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2223. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2224. Params.Aliases = Aliases;
  2225. Params.AliasesCount = LENOF(Aliases);
  2226. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2227. }
  2228. }
  2229. }
  2230. //---------------------------------------------------------------------------
  2231. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2232. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2233. {
  2234. TCustomCommandData Data;
  2235. UnicodeString Site;
  2236. UnicodeString RemotePath;
  2237. if (HasActiveTerminal())
  2238. {
  2239. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2240. Data = TCustomCommandData(SessionData.get());
  2241. Site = Terminal->SessionData->SessionKey;
  2242. RemotePath = Terminal->CurrentDirectory;
  2243. }
  2244. UnicodeString HelpKeyword = ACommand.HomePage;
  2245. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2246. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2247. {
  2248. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2249. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2250. {
  2251. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2252. }
  2253. else
  2254. {
  2255. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2256. }
  2257. if (!DoCustomCommandOptionsDialog(
  2258. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2259. {
  2260. Abort();
  2261. }
  2262. }
  2263. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2264. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2265. {
  2266. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2267. }
  2268. else
  2269. {
  2270. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2271. }
  2272. }
  2273. //---------------------------------------------------------------------------
  2274. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2275. const TCustomCommandType & Command)
  2276. {
  2277. DebugAssert(FCustomCommandLocalFileList != NULL);
  2278. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2279. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2280. TStrings * LocalFileList = new TStringList();
  2281. TStrings * RemoteFileList = new TStringList();
  2282. try
  2283. {
  2284. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2285. {
  2286. LocalFileList->Clear();
  2287. LocalFileList->AddObject(
  2288. FCustomCommandLocalFileList->Strings[Index],
  2289. FCustomCommandLocalFileList->Objects[Index]);
  2290. RemoteFileList->Clear();
  2291. RemoteFileList->AddObject(
  2292. FCustomCommandRemoteFileList->Strings[Index],
  2293. FCustomCommandRemoteFileList->Objects[Index]);
  2294. CustomCommand(RemoteFileList, Command, LocalFileList);
  2295. }
  2296. }
  2297. __finally
  2298. {
  2299. delete LocalFileList;
  2300. delete RemoteFileList;
  2301. }
  2302. }
  2303. //---------------------------------------------------------------------------
  2304. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2305. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2306. {
  2307. delete FCustomCommandLocalFileList;
  2308. delete FCustomCommandRemoteFileList;
  2309. // takeover ownership,
  2310. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2311. FCustomCommandLocalFileList = LocalFileList;
  2312. FCustomCommandRemoteFileList = RemoteFileList;
  2313. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2314. if (Button != NULL)
  2315. {
  2316. FCustomCommandMenu->Items->Clear();
  2317. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2318. MenuPopup(FCustomCommandMenu, Button);
  2319. }
  2320. else
  2321. {
  2322. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2323. }
  2324. }
  2325. //---------------------------------------------------------------------------
  2326. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2327. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2328. {
  2329. DebugAssert(FCapturedLog != NULL);
  2330. if ((OutputType == cotOutput) || (OutputType == cotError))
  2331. {
  2332. FCapturedLog->Add(AddedLine);
  2333. }
  2334. }
  2335. //---------------------------------------------------------------------------
  2336. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2337. TOperationSide Side)
  2338. {
  2339. return
  2340. (Side == osOther) &&
  2341. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2342. }
  2343. //---------------------------------------------------------------------------
  2344. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2345. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2346. {
  2347. TTBItemOptions O;
  2348. O = Item->Options;
  2349. TCustomDirView * DView = DirView(Side);
  2350. if ((DView->ItemFocused != NULL) &&
  2351. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2352. // when resolving links is disabled, default action is to enter the directory,
  2353. // no matter what DoubleClickAction is configured to
  2354. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2355. // Can only Edit files, but can Open/Copy even directories
  2356. ((DoubleClickAction != dcaEdit) ||
  2357. !DView->ItemIsDirectory(DView->ItemFocused)))
  2358. {
  2359. Item->Options = O << tboDefault;
  2360. }
  2361. else
  2362. {
  2363. Item->Options = O >> tboDefault;
  2364. }
  2365. }
  2366. //---------------------------------------------------------------------------
  2367. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2368. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2369. {
  2370. TCustomDirView * DView = DirView(Side);
  2371. TListItem * Item = DView->ItemFocused;
  2372. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2373. EnableFocusedOperation[Side])
  2374. {
  2375. TPoint ClientPoint;
  2376. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2377. TPoint(0, 0) : MousePos;
  2378. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2379. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2380. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2381. }
  2382. }
  2383. //---------------------------------------------------------------------------
  2384. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2385. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2386. {
  2387. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2388. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2389. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2390. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2391. Handled = true;
  2392. }
  2393. //---------------------------------------------------------------------------
  2394. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2395. {
  2396. }
  2397. //---------------------------------------------------------------------------
  2398. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2399. {
  2400. DebugAssert(FErrorList == NULL);
  2401. if (WinConfiguration->ContinueOnError)
  2402. {
  2403. FErrorList = new TStringList();
  2404. Configuration->Usage->Inc(L"ContinuationsOnError");
  2405. }
  2406. NonVisualDataModule->StartBusy();
  2407. }
  2408. //---------------------------------------------------------------------------
  2409. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2410. {
  2411. NonVisualDataModule->EndBusy();
  2412. if (FErrorList)
  2413. {
  2414. HandleErrorList(FErrorList);
  2415. }
  2416. }
  2417. //---------------------------------------------------------------------------
  2418. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2419. const TCopyParamType & CopyParam)
  2420. {
  2421. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2422. {
  2423. Configuration->Usage->Inc(L"FileMaskUses");
  2424. }
  2425. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2426. {
  2427. Configuration->Usage->Inc(L"OperationMaskUses");
  2428. }
  2429. }
  2430. //---------------------------------------------------------------------------
  2431. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2432. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2433. {
  2434. DebugAssert(!IsLocalBrowserMode());
  2435. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2436. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2437. TTransferOperationParam DefaultParam;
  2438. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2439. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2440. switch (Param.Queue)
  2441. {
  2442. case asOn:
  2443. CopyParam.Queue = true;
  2444. break;
  2445. case asOff:
  2446. CopyParam.Queue = false;
  2447. break;
  2448. case asAuto:
  2449. default:
  2450. // keep default
  2451. break;
  2452. }
  2453. bool Result =
  2454. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2455. if (Result)
  2456. {
  2457. DebugAssert(Terminal);
  2458. bool SelectionRestored = false;
  2459. TCustomDirView * DView = NULL;
  2460. if (HasDirView[Side])
  2461. {
  2462. DView = DirView(Side);
  2463. DView->SaveSelection();
  2464. DView->SaveSelectedNames();
  2465. }
  2466. UpdateCopyParamCounters(CopyParam);
  2467. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2468. DebugAssert(FTransferResumeList == NULL);
  2469. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2470. FMoveToQueue = false;
  2471. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2472. try
  2473. {
  2474. TStrings * PermanentFileList;
  2475. std::unique_ptr<TStrings> PermanentFileListOwner;
  2476. try
  2477. {
  2478. if (Side == osLocal)
  2479. {
  2480. PermanentFileList = FileList;
  2481. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2482. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2483. if (Operation == foMove)
  2484. {
  2485. ReloadLocalDirectory();
  2486. if (DView != NULL)
  2487. {
  2488. DView->RestoreSelection();
  2489. }
  2490. SelectionRestored = true;
  2491. }
  2492. }
  2493. else
  2494. {
  2495. // Clone the file list as it may refer to current directory files,
  2496. // which get destroyed, when the source directory is reloaded after foMove operation.
  2497. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2498. // But for a hotfix, we are not going to do such a big change.
  2499. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2500. PermanentFileList = PermanentFileListOwner.get();
  2501. try
  2502. {
  2503. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2504. }
  2505. __finally
  2506. {
  2507. if (Operation == foMove)
  2508. {
  2509. if (DView != NULL)
  2510. {
  2511. DView->RestoreSelection();
  2512. }
  2513. SelectionRestored = true;
  2514. }
  2515. ReloadLocalDirectory(Param.TargetDirectory);
  2516. }
  2517. }
  2518. }
  2519. catch (EAbort &)
  2520. {
  2521. if (FMoveToQueue)
  2522. {
  2523. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2524. DebugAssert(CopyParam.TransferSkipList == NULL);
  2525. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2526. if (TransferResumeList->Count > 0)
  2527. {
  2528. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2529. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2530. }
  2531. CopyParam.TransferSkipList = TransferResumeList.release();
  2532. // not really needed, just to keep it consistent with TransferResumeList
  2533. FTransferResumeList = NULL;
  2534. FMoveToQueue = false;
  2535. Configuration->Usage->Inc("MovesToBackground");
  2536. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2537. ClearTransferSourceSelection(Direction);
  2538. }
  2539. throw;
  2540. }
  2541. }
  2542. __finally
  2543. {
  2544. if (!SelectionRestored && (DView != NULL))
  2545. {
  2546. DView->DiscardSavedSelection();
  2547. }
  2548. FTransferResumeList = NULL;
  2549. }
  2550. }
  2551. return Result;
  2552. }
  2553. //---------------------------------------------------------------------------
  2554. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2555. TOperationSide Side, TStrings * FileList, void * Param)
  2556. {
  2557. DebugAssert(FileList->Count);
  2558. // We deliberately do not toggle alternative flag (Param), but use OR,
  2559. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2560. // shortcut of CurrentDeleteAlternativeAction
  2561. bool Alternative =
  2562. bool(Param) || UseAlternativeFunction();
  2563. bool Recycle;
  2564. if (IsSideLocalBrowser(Side))
  2565. {
  2566. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2567. }
  2568. else
  2569. {
  2570. Recycle =
  2571. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2572. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2573. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2574. }
  2575. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2576. if (!Result)
  2577. {
  2578. UnicodeString Query;
  2579. if (FileList->Count == 1)
  2580. {
  2581. if (IsSideLocalBrowser(Side))
  2582. {
  2583. Query = ExtractFileName(FileList->Strings[0]);
  2584. }
  2585. else
  2586. {
  2587. Query = UnixExtractFileName(FileList->Strings[0]);
  2588. }
  2589. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2590. }
  2591. else
  2592. {
  2593. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2594. }
  2595. TMessageParams Params(mpNeverAskAgainCheck);
  2596. Params.ImageName = L"Delete file";
  2597. unsigned int Answer =
  2598. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2599. if (Answer == qaNeverAskAgain)
  2600. {
  2601. Result = true;
  2602. if (Recycle)
  2603. {
  2604. WinConfiguration->ConfirmRecycling = false;
  2605. }
  2606. else
  2607. {
  2608. WinConfiguration->ConfirmDeleting = false;
  2609. }
  2610. }
  2611. else
  2612. {
  2613. Result = (Answer == qaOK);
  2614. }
  2615. }
  2616. if (Result)
  2617. {
  2618. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2619. }
  2620. return Result;
  2621. }
  2622. //---------------------------------------------------------------------------
  2623. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2624. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2625. {
  2626. TAutoBatch AutoBatch(this);
  2627. bool Result;
  2628. if ((Operation == foCopy) || (Operation == foMove))
  2629. {
  2630. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2631. }
  2632. else if (Operation == foRename)
  2633. {
  2634. DebugAssert(DirView(Side)->ItemFocused);
  2635. DirView(Side)->ItemFocused->EditCaption();
  2636. Result = true;
  2637. }
  2638. else if (Operation == foDelete)
  2639. {
  2640. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2641. }
  2642. else if (Operation == foSetProperties)
  2643. {
  2644. DirView(osRemote)->SaveSelectedNames();
  2645. Result = SetProperties(Side, FileList);
  2646. }
  2647. else if (Operation == foCustomCommand)
  2648. {
  2649. DebugAssert(Param);
  2650. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2651. DirView(osRemote)->SaveSelectedNames();
  2652. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2653. CustomCommand(FileList, *Command, NULL);
  2654. Result = true;
  2655. }
  2656. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2657. {
  2658. DebugAssert(!IsSideLocalBrowser(Side));
  2659. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2660. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2661. }
  2662. else if (Operation == foLock)
  2663. {
  2664. DebugAssert(!IsSideLocalBrowser(Side));
  2665. LockFiles(FileList, true);
  2666. Result = true;
  2667. }
  2668. else if (Operation == foUnlock)
  2669. {
  2670. DebugAssert(!IsSideLocalBrowser(Side));
  2671. LockFiles(FileList, false);
  2672. Result = true;
  2673. }
  2674. else
  2675. {
  2676. DebugFail();
  2677. }
  2678. return Result;
  2679. }
  2680. //---------------------------------------------------------------------------
  2681. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2682. {
  2683. if (Side == osCurrent)
  2684. {
  2685. Side = FCurrentSide;
  2686. }
  2687. return Side;
  2688. }
  2689. //---------------------------------------------------------------------------
  2690. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2691. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2692. {
  2693. Side = GetSide(Side);
  2694. bool Result;
  2695. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2696. try
  2697. {
  2698. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2699. }
  2700. __finally
  2701. {
  2702. delete FileList;
  2703. }
  2704. return Result;
  2705. }
  2706. //---------------------------------------------------------------------------
  2707. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2708. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2709. bool NoConfirmation, void * Param)
  2710. {
  2711. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2712. {
  2713. if ((Operation == foCopy) || (Operation == foMove))
  2714. {
  2715. DebugAssert(!IsLocalBrowserMode());
  2716. if (GetSide(Side) == osLocal)
  2717. {
  2718. Configuration->Usage->Inc(L"UploadsCommand");
  2719. }
  2720. else
  2721. {
  2722. Configuration->Usage->Inc(L"DownloadsCommand");
  2723. }
  2724. }
  2725. }
  2726. }
  2727. //---------------------------------------------------------------------------
  2728. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2729. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2730. {
  2731. TTransferOperationParam Param;
  2732. if ((WinConfiguration->Interface != ifCommander) ||
  2733. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2734. {
  2735. Flags &= ~cocShortCutHint;
  2736. }
  2737. TCustomDirView * DView = DirView(Side);
  2738. Param.Options =
  2739. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2740. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2741. if (FLAGSET(Flags, cocQueue))
  2742. {
  2743. Param.Queue = asOn;
  2744. }
  2745. else if (FLAGSET(Flags, cocNonQueue))
  2746. {
  2747. Param.Queue = asOff;
  2748. }
  2749. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2750. }
  2751. //---------------------------------------------------------------------------
  2752. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2753. {
  2754. try
  2755. {
  2756. if (ErrorList->Count)
  2757. {
  2758. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2759. if (MessageDialog(Message, qtError,
  2760. qaOK | qaCancel, HELP_NONE) == qaOK)
  2761. {
  2762. unsigned int Answer;
  2763. int Index = 0;
  2764. do
  2765. {
  2766. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2767. TQueryButtonAlias Aliases[2];
  2768. Aliases[0].Button = qaYes;
  2769. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2770. Aliases[1].Button = qaNo;
  2771. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2772. TMessageParams Params;
  2773. Params.Aliases = Aliases;
  2774. Params.AliasesCount = LENOF(Aliases);
  2775. Answer = MoreMessageDialog(
  2776. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2777. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2778. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2779. qaOK, HELP_NONE, &Params);
  2780. if (Answer == qaNo)
  2781. {
  2782. Index++;
  2783. }
  2784. if (Answer == qaYes)
  2785. {
  2786. Index--;
  2787. }
  2788. }
  2789. while (Answer != qaOK);
  2790. }
  2791. }
  2792. }
  2793. __finally
  2794. {
  2795. TStrings * List = ErrorList;
  2796. ErrorList = NULL;
  2797. for (int i = 0; i < List->Count; i++)
  2798. {
  2799. delete List->Objects[i];
  2800. }
  2801. delete List;
  2802. }
  2803. }
  2804. //---------------------------------------------------------------------------
  2805. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2806. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2807. {
  2808. // needed for checking filemasks, as there's no directory object
  2809. // associated with the file object
  2810. File->FullFileName = FullFileName;
  2811. TFileMasks::TParams MaskParams;
  2812. MaskParams.Size = File->Size;
  2813. MaskParams.Modification = File->Modification;
  2814. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2815. }
  2816. //---------------------------------------------------------------------------
  2817. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2818. {
  2819. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2820. Side = GetSide(Side);
  2821. TCustomDirView * DView = DirView(Side);
  2822. TListItem * FocusedItem = DView->ItemFocused;
  2823. UnicodeString Name;
  2824. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2825. {
  2826. Name = DView->ItemFileName(FocusedItem);
  2827. }
  2828. else
  2829. {
  2830. Name = LoadStr(NEW_FILE);
  2831. }
  2832. UnicodeString Names = Name;
  2833. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2834. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2835. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  2836. {
  2837. while (!Names.IsEmpty())
  2838. {
  2839. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2840. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2841. UnicodeString TargetFileName;
  2842. UnicodeString LocalFileName;
  2843. UnicodeString RootTempDir;
  2844. UnicodeString TempDir;
  2845. UnicodeString RemoteDirectory;
  2846. bool ExistingFile = false;
  2847. if (!IsSideLocalBrowser(Side))
  2848. {
  2849. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2850. TRemoteFile * File = NULL;
  2851. if (FTerminal->FileExists(Name, &File) &&
  2852. !File->IsDirectory)
  2853. {
  2854. try
  2855. {
  2856. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2857. ExistingFile = true;
  2858. }
  2859. __finally
  2860. {
  2861. delete File;
  2862. }
  2863. }
  2864. if (!ExistingFile)
  2865. {
  2866. RemoteDirectory = UnixExtractFilePath(Name);
  2867. TemporaryDirectoryForRemoteFiles(
  2868. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2869. TargetFileName = UnixExtractFileName(Name);
  2870. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2871. LocalFileName = TempDir +
  2872. // We probably do not want to trim the VMS version here
  2873. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2874. }
  2875. }
  2876. else
  2877. {
  2878. if (ExtractFilePath(Name).IsEmpty())
  2879. {
  2880. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2881. }
  2882. else
  2883. {
  2884. LocalFileName = ExpandFileName(Name);
  2885. }
  2886. TargetFileName = ExtractFileName(Name);
  2887. }
  2888. if (!ExistingFile)
  2889. {
  2890. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2891. if (NewFile)
  2892. {
  2893. int File = FileCreate(ApiPath(LocalFileName));
  2894. if (File < 0)
  2895. {
  2896. if (!RootTempDir.IsEmpty())
  2897. {
  2898. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2899. }
  2900. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2901. }
  2902. else
  2903. {
  2904. FileClose(File);
  2905. }
  2906. }
  2907. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2908. const TEditorData * ExternalEditor = NULL;
  2909. TFileMasks::TParams MaskParams; // size not known
  2910. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2911. false, MaskParams);
  2912. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2913. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2914. }
  2915. }
  2916. }
  2917. }
  2918. //---------------------------------------------------------------------------
  2919. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2920. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2921. {
  2922. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2923. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2924. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2925. return
  2926. ((ExecuteFileBy == efInternalEditor)) ||
  2927. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2928. }
  2929. //---------------------------------------------------------------------------
  2930. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2931. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2932. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2933. UnicodeString RemoteDirectory, bool NewFile)
  2934. {
  2935. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2936. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2937. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2938. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2939. Side = GetSide(Side);
  2940. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2941. if (!IsSideLocalBrowser(Side))
  2942. {
  2943. Data->Terminal = Terminal;
  2944. Data->Queue = Queue;
  2945. Data->SessionData = CloneCurrentSessionData();
  2946. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2947. Data->RemoteDirectory = RemoteDirectory;
  2948. Data->SessionName = Terminal->SessionData->SessionName;
  2949. Data->LocalRootDirectory = LocalRootDirectory;
  2950. Data->OriginalFileName = OriginalFileName;
  2951. Data->Command = L""; // will be changed later for external editor
  2952. }
  2953. if (ExecuteFileBy == efInternalEditor)
  2954. {
  2955. if (!IsSideLocalBrowser(Side))
  2956. {
  2957. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2958. L" - " + Terminal->SessionData->SessionName;
  2959. TForm * Editor;
  2960. try
  2961. {
  2962. TNotifyEvent OnFileChanged = NULL;
  2963. TNotifyEvent OnSaveAll = NULL;
  2964. TAnyModifiedEvent OnAnyModified = NULL;
  2965. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2966. if (Terminal->IsCapable[fcBackgroundTransfers])
  2967. {
  2968. OnFileChanged = FEditorManager->FileChanged;
  2969. OnSaveAll = SaveAllInternalEditors;
  2970. OnAnyModified = AnyInternalEditorModified;
  2971. }
  2972. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2973. FEditorManager->FileReload, FEditorManager->FileClosed,
  2974. OnSaveAll, OnAnyModified,
  2975. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2976. }
  2977. catch(...)
  2978. {
  2979. if (!LocalRootDirectory.IsEmpty())
  2980. {
  2981. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2982. }
  2983. throw;
  2984. }
  2985. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2986. }
  2987. else
  2988. {
  2989. DebugAssert(!FStandaloneEditing);
  2990. TForm * Editor =
  2991. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2992. SaveAllInternalEditors, AnyInternalEditorModified,
  2993. L"", false, SessionColor, -1, NewFile);
  2994. FLocalEditors->Add(Editor);
  2995. }
  2996. }
  2997. else
  2998. {
  2999. HANDLE Process;
  3000. if (ExecuteFileBy == efExternalEditor)
  3001. {
  3002. UnicodeString Program, Params, Dir;
  3003. Data->Command = ExternalEditor->ExternalEditor;
  3004. ReformatFileNameCommand(Data->Command);
  3005. SplitCommand(Data->Command, Program, Params, Dir);
  3006. Params = ExpandFileNameCommand(Params, FileName);
  3007. Program = ExpandEnvironmentVariables(Program);
  3008. if (!ExecuteShell(Program, Params, Process))
  3009. {
  3010. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3011. }
  3012. }
  3013. else
  3014. {
  3015. DebugAssert(!IsSideLocalBrowser(Side));
  3016. if (!ExecuteShell(FileName, L"", Process))
  3017. {
  3018. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3019. }
  3020. }
  3021. if (IsSideLocalBrowser(Side) ||
  3022. ((ExecuteFileBy == efShell) &&
  3023. !WinConfiguration->Editor.SDIShellEditor) ||
  3024. ((ExecuteFileBy == efExternalEditor) &&
  3025. !ExternalEditor->SDIExternalEditor))
  3026. {
  3027. // no need for handle
  3028. if (Process != NULL)
  3029. {
  3030. DebugCheck(CloseHandle(Process));
  3031. }
  3032. Process = INVALID_HANDLE_VALUE;
  3033. }
  3034. else
  3035. {
  3036. if (Process == NULL)
  3037. {
  3038. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3039. }
  3040. }
  3041. if (!IsSideLocalBrowser(Side))
  3042. {
  3043. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3044. }
  3045. }
  3046. }
  3047. //---------------------------------------------------------------------------
  3048. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3049. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3050. void * /*Arg*/)
  3051. {
  3052. if (Token != NULL)
  3053. {
  3054. EditorFormFileSave(static_cast<TForm *>(Token));
  3055. }
  3056. }
  3057. //---------------------------------------------------------------------------
  3058. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3059. {
  3060. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3061. {
  3062. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3063. }
  3064. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3065. }
  3066. //---------------------------------------------------------------------------
  3067. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3068. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3069. void * Arg)
  3070. {
  3071. if ((Token != NULL) &&
  3072. IsEditorFormModified(static_cast<TForm *>(Token)))
  3073. {
  3074. *static_cast<bool *>(Arg) = true;
  3075. }
  3076. }
  3077. //---------------------------------------------------------------------------
  3078. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3079. TObject * /*Sender*/, bool & Modified)
  3080. {
  3081. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3082. {
  3083. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3084. {
  3085. Modified = true;
  3086. }
  3087. }
  3088. if (!Modified)
  3089. {
  3090. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3091. }
  3092. }
  3093. //---------------------------------------------------------------------------
  3094. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3095. {
  3096. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3097. }
  3098. //---------------------------------------------------------------------------
  3099. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3100. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3101. UnicodeString & Result, UnicodeString & RootDirectory)
  3102. {
  3103. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3104. {
  3105. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3106. Result = RootDirectory;
  3107. }
  3108. else
  3109. {
  3110. RootDirectory = L"";
  3111. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3112. Result = IncludeTrailingBackslash(Result);
  3113. }
  3114. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3115. {
  3116. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3117. }
  3118. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3119. {
  3120. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3121. {
  3122. RemoteDirectory.Delete(1, 1);
  3123. }
  3124. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3125. }
  3126. if (!ForceDirectories(ApiPath(Result)))
  3127. {
  3128. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3129. }
  3130. }
  3131. //---------------------------------------------------------------------------
  3132. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3133. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3134. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3135. {
  3136. DebugAssert(!IsLocalBrowserMode());
  3137. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3138. if (ForceText)
  3139. {
  3140. CopyParam.TransferMode = tmAscii;
  3141. }
  3142. TemporaryFileCopyParam(CopyParam);
  3143. if (AllFiles)
  3144. {
  3145. CopyParam.IncludeFileMask = TFileMasks();
  3146. }
  3147. if (TempDir.IsEmpty())
  3148. {
  3149. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3150. }
  3151. DebugAssert(!FAutoOperation);
  3152. FAutoOperation = AutoOperation;
  3153. Terminal->ExceptionOnFail = true;
  3154. try
  3155. {
  3156. try
  3157. {
  3158. // turn off confirmations, as for MDI editors we may possibly download
  3159. // the same file over
  3160. Terminal->CopyToLocal(
  3161. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3162. if (GetTargetNames)
  3163. {
  3164. for (int i = 0; i < FileList->Count; i++)
  3165. {
  3166. FileList->Strings[i] =
  3167. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3168. }
  3169. }
  3170. }
  3171. catch(...)
  3172. {
  3173. if (!RootTempDir.IsEmpty())
  3174. {
  3175. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3176. }
  3177. throw;
  3178. }
  3179. }
  3180. __finally
  3181. {
  3182. FAutoOperation = false;
  3183. Terminal->ExceptionOnFail = false;
  3184. }
  3185. }
  3186. //---------------------------------------------------------------------------
  3187. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3188. {
  3189. // Do not waste time checking for default editor list the next time,
  3190. // or testing if default editor is not notepad.
  3191. bool TryNextTime = false;
  3192. UnicodeString UsageState;
  3193. if (!WinConfiguration->EditorList->IsDefaultList())
  3194. {
  3195. UsageState = "H";
  3196. }
  3197. else
  3198. {
  3199. UnicodeString Executable;
  3200. UnicodeString ExecutableDescription;
  3201. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3202. {
  3203. UnicodeString Message =
  3204. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3205. unsigned int Answer =
  3206. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3207. if (Answer != qaOK)
  3208. {
  3209. UsageState = "R";
  3210. }
  3211. else
  3212. {
  3213. UsageState = "A";
  3214. TEditorData EditorData;
  3215. EditorData.Editor = edExternal;
  3216. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3217. EditorData.ExternalEditorOptionsAutodetect();
  3218. TEditorList EditorList;
  3219. EditorList = *WinConfiguration->EditorList;
  3220. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3221. WinConfiguration->EditorList = &EditorList;
  3222. }
  3223. }
  3224. }
  3225. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3226. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3227. }
  3228. //---------------------------------------------------------------------------
  3229. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3230. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3231. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3232. {
  3233. if (ExecuteFileBy == efDefaultEditor)
  3234. {
  3235. if (!WinConfiguration->OfferedEditorAutoConfig)
  3236. {
  3237. EditorAutoConfig();
  3238. }
  3239. const TEditorPreferences * Editor =
  3240. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3241. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3242. {
  3243. ExecuteFileBy = efInternalEditor;
  3244. ExternalEditor = NULL;
  3245. }
  3246. else if (Editor->Data->Editor == edOpen)
  3247. {
  3248. ExecuteFileBy = efShell;
  3249. ExternalEditor = NULL;
  3250. }
  3251. else
  3252. {
  3253. ExecuteFileBy = efExternalEditor;
  3254. ExternalEditor = Editor->Data;
  3255. }
  3256. }
  3257. }
  3258. //---------------------------------------------------------------------------
  3259. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3260. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3261. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3262. {
  3263. UnicodeString OriginalFileName;
  3264. UnicodeString LocalRootDirectory;
  3265. UnicodeString RemoteDirectory;
  3266. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3267. IsSideLocalBrowser(Side), MaskParams);
  3268. UnicodeString Counter;
  3269. UnicodeString LocalFileName;
  3270. bool Handled = false;
  3271. if (!IsSideLocalBrowser(Side))
  3272. {
  3273. // We need to trim VMS version here, so that we use name without version
  3274. // when uploading back to create a new version of the file
  3275. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3276. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3277. TObject * Token = NULL;
  3278. UnicodeString LocalDirectory;
  3279. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3280. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3281. LocalDirectory))
  3282. {
  3283. if (Token != NULL)
  3284. {
  3285. TForm * Form = dynamic_cast<TForm *>(Token);
  3286. if (Form->WindowState == wsMinimized)
  3287. {
  3288. ShowWindow(Form->Handle, SW_RESTORE);
  3289. }
  3290. else
  3291. {
  3292. Form->SetFocus();
  3293. }
  3294. Handled = true;
  3295. }
  3296. else
  3297. {
  3298. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3299. }
  3300. }
  3301. if (!Handled)
  3302. {
  3303. TStringList * FileList1 = new TStringList();
  3304. try
  3305. {
  3306. FileList1->AddObject(FullFileName, Object);
  3307. TemporarilyDownloadFiles(FileList1,
  3308. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3309. LocalRootDirectory, LocalDirectory, true, true, true);
  3310. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3311. }
  3312. __finally
  3313. {
  3314. delete FileList1;
  3315. }
  3316. switch (ExecuteFileBy)
  3317. {
  3318. case efShell:
  3319. Counter = "RemoteFilesExecuted";
  3320. break;
  3321. case efInternalEditor:
  3322. Counter = "RemoteFilesOpenedInInternalEditor";
  3323. break;
  3324. case efExternalEditor:
  3325. Counter = "RemoteFilesOpenedInExternalEditor";
  3326. break;
  3327. default:
  3328. DebugFail();
  3329. }
  3330. }
  3331. }
  3332. else
  3333. {
  3334. LocalFileName = FullFileName;
  3335. OriginalFileName = ExtractFileName(FullFileName);
  3336. switch (ExecuteFileBy)
  3337. {
  3338. case efShell:
  3339. Counter = "LocalFilesExecuted";
  3340. break;
  3341. case efInternalEditor:
  3342. Counter = "LocalFilesOpenedInInternalEditor";
  3343. break;
  3344. case efExternalEditor:
  3345. Counter = "LocalFilesOpenedInExternalEditor";
  3346. break;
  3347. default:
  3348. DebugFail();
  3349. }
  3350. }
  3351. if (!Handled)
  3352. {
  3353. Configuration->Usage->Inc(Counter);
  3354. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3355. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3356. }
  3357. }
  3358. //---------------------------------------------------------------------------
  3359. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3360. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3361. bool AllSelected, bool OnFocused)
  3362. {
  3363. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3364. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3365. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3366. Side = GetSide(Side);
  3367. TCustomDirView * DView = DirView(Side);
  3368. TStrings * FileList =
  3369. AllSelected ?
  3370. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3371. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3372. try
  3373. {
  3374. DebugAssert(AllSelected || (FileList->Count == 1));
  3375. for (int i = 0; i < FileList->Count; i++)
  3376. {
  3377. UnicodeString ListFileName = FileList->Strings[i];
  3378. UnicodeString FileNameOnly =
  3379. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3380. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3381. if (!DView->ItemIsDirectory(Item))
  3382. {
  3383. UnicodeString FullFileName;
  3384. if (!IsSideLocalBrowser(Side))
  3385. {
  3386. FullFileName = DirView(Side)->Path + ListFileName;
  3387. }
  3388. else
  3389. {
  3390. FullFileName = ListFileName;
  3391. }
  3392. TFileMasks::TParams MaskParams;
  3393. MaskParams.Size = DView->ItemFileSize(Item);
  3394. TDateTimePrecision Precision;
  3395. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3396. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3397. FileList->Objects[i], MaskParams);
  3398. }
  3399. }
  3400. }
  3401. __finally
  3402. {
  3403. delete FileList;
  3404. }
  3405. }
  3406. //---------------------------------------------------------------------------
  3407. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3408. {
  3409. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3410. CopyParam.FileNameCase = ncNoChange;
  3411. CopyParam.PreserveRights = false;
  3412. CopyParam.PreserveReadOnly = false;
  3413. CopyParam.ReplaceInvalidChars = true;
  3414. CopyParam.IncludeFileMask = TFileMasks();
  3415. CopyParam.NewerOnly = false;
  3416. CopyParam.FileMask = L"";
  3417. }
  3418. //---------------------------------------------------------------------------
  3419. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3420. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3421. {
  3422. TTerminalManager * Manager = TTerminalManager::Instance();
  3423. if (!IsActiveTerminal(Data->Terminal))
  3424. {
  3425. if (!NonVisualDataModule->Busy)
  3426. {
  3427. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3428. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3429. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3430. if (Data->Terminal == NULL)
  3431. {
  3432. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3433. if (SameSiteTerminal != NULL)
  3434. {
  3435. UnicodeString Message =
  3436. FMTLOAD(EDIT_SESSION_REATTACH,
  3437. (FileNameOnly, Data->SessionName, FileNameOnly));
  3438. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3439. {
  3440. Data->Terminal = Terminal;
  3441. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3442. Data->SessionName = Terminal->SessionData->SessionName;
  3443. // We might also overwrite session data
  3444. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3445. }
  3446. else
  3447. {
  3448. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3449. Abort();
  3450. }
  3451. }
  3452. }
  3453. // foreground session should reconnect itself
  3454. else if (Terminal != Data->Terminal)
  3455. {
  3456. UnicodeString Message =
  3457. MainInstructions(
  3458. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3459. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3460. {
  3461. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3462. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3463. }
  3464. else
  3465. {
  3466. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3467. Abort();
  3468. }
  3469. }
  3470. }
  3471. if (!IsActiveTerminal(Data->Terminal))
  3472. {
  3473. Configuration->Usage->Inc(L"EditInactiveSession");
  3474. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3475. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3476. (ExtractFileName(FileName), Data->SessionName)));
  3477. }
  3478. }
  3479. TStrings * FileList = new TStringList();
  3480. try
  3481. {
  3482. FileList->Add(FileName);
  3483. // consider using the same settings (preset) as when the file was downloaded
  3484. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3485. TemporaryFileCopyParam(CopyParam);
  3486. if (Data->ForceText)
  3487. {
  3488. CopyParam.TransferMode = tmAscii;
  3489. }
  3490. // so i do not need to worry if masking algorithm works in all cases
  3491. // ("" means "copy file name", no masking is actually done)
  3492. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3493. {
  3494. CopyParam.FileMask = L"";
  3495. }
  3496. else
  3497. {
  3498. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3499. }
  3500. DebugAssert(Data->Queue != NULL);
  3501. int Params = cpNoConfirmation | cpTemporary;
  3502. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3503. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3504. QueueItem->CompleteEvent = UploadCompleteEvent;
  3505. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3506. }
  3507. __finally
  3508. {
  3509. delete FileList;
  3510. }
  3511. }
  3512. //---------------------------------------------------------------------------
  3513. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3514. const UnicodeString FileName, const TEditedFileData * Data)
  3515. {
  3516. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3517. DebugAssert(!NonVisualDataModule->Busy);
  3518. if (!IsActiveTerminal(Data->Terminal))
  3519. {
  3520. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3521. (ExtractFileName(FileName), Data->SessionName)));
  3522. }
  3523. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3524. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3525. NonVisualDataModule->StartBusy();
  3526. try
  3527. {
  3528. std::unique_ptr<TRemoteFile> File;
  3529. UnicodeString RemoteFileName =
  3530. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3531. FTerminal->ExceptionOnFail = true;
  3532. try
  3533. {
  3534. TRemoteFile * AFile = NULL;
  3535. FTerminal->ReadFile(RemoteFileName, AFile);
  3536. File.reset(AFile);
  3537. if (!File->HaveFullFileName)
  3538. {
  3539. File->FullFileName = RemoteFileName;
  3540. }
  3541. }
  3542. __finally
  3543. {
  3544. FTerminal->ExceptionOnFail = false;
  3545. }
  3546. std::unique_ptr<TStrings> FileList(new TStringList());
  3547. FileList->AddObject(RemoteFileName, File.get());
  3548. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3549. UnicodeString TempDir = ExtractFilePath(FileName);
  3550. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3551. TempDir, true, true, true);
  3552. // sanity check, the target file name should be still the same
  3553. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3554. }
  3555. __finally
  3556. {
  3557. NonVisualDataModule->EndBusy();
  3558. // it actually may not exist anymore...
  3559. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3560. }
  3561. }
  3562. //---------------------------------------------------------------------------
  3563. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3564. const TEditedFileData * Data, bool & KeepOpen)
  3565. {
  3566. // Command is set for external editors only (not for "shell" open).
  3567. if (!Data->Command.IsEmpty())
  3568. {
  3569. bool AnyFound = false;
  3570. bool AnyMDI = false;
  3571. bool AnyNonMDI = false;
  3572. bool AnyDetect = false;
  3573. TEditorList * EditorList = new TEditorList();
  3574. try
  3575. {
  3576. *EditorList = *WinConfiguration->EditorList;
  3577. for (int i = 0; i < EditorList->Count; i++)
  3578. {
  3579. const TEditorPreferences * Editor = EditorList->Editors[i];
  3580. if ((Editor->Data->Editor == edExternal) &&
  3581. (Editor->Data->ExternalEditor == Data->Command))
  3582. {
  3583. AnyFound = true;
  3584. if (Editor->Data->SDIExternalEditor)
  3585. {
  3586. AnyNonMDI = true;
  3587. if (Editor->Data->DetectMDIExternalEditor)
  3588. {
  3589. AnyDetect = true;
  3590. }
  3591. }
  3592. else
  3593. {
  3594. AnyMDI = true;
  3595. }
  3596. }
  3597. }
  3598. bool EnableMDI = false;
  3599. bool DisableDetect = false;
  3600. if (AnyMDI)
  3601. {
  3602. KeepOpen = true;
  3603. if (AnyNonMDI)
  3604. {
  3605. // there is at least one instance of the editor with MDI support enabled,
  3606. // and one with disabled, enable it for all instances
  3607. EnableMDI = true;
  3608. }
  3609. }
  3610. else if (AnyFound && !AnyDetect)
  3611. {
  3612. // at least once instance found but all have MDI autodetection disabled
  3613. // => close the file (default action)
  3614. }
  3615. else
  3616. {
  3617. // no instance of the editor has MDI support enabled
  3618. TMessageParams Params;
  3619. if (AnyFound)
  3620. {
  3621. // there is at least one instance of the editor
  3622. Params.Params |= mpNeverAskAgainCheck;
  3623. }
  3624. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3625. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3626. switch (Answer)
  3627. {
  3628. case qaNeverAskAgain:
  3629. DisableDetect = true;
  3630. break;
  3631. case qaNo:
  3632. EnableMDI = true;
  3633. KeepOpen = true;
  3634. break;
  3635. }
  3636. }
  3637. if (AnyFound && (EnableMDI || DisableDetect))
  3638. {
  3639. bool Changed = false;
  3640. for (int i = 0; i < EditorList->Count; i++)
  3641. {
  3642. const TEditorPreferences * Editor = EditorList->Editors[i];
  3643. if ((Editor->Data->Editor == edExternal) &&
  3644. (Editor->Data->ExternalEditor == Data->Command) &&
  3645. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3646. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3647. {
  3648. Changed = true;
  3649. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3650. if (EnableMDI)
  3651. {
  3652. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3653. }
  3654. if (DisableDetect)
  3655. {
  3656. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3657. }
  3658. EditorList->Change(i, UpdatedEditor);
  3659. }
  3660. }
  3661. if (Changed)
  3662. {
  3663. WinConfiguration->EditorList = EditorList;
  3664. }
  3665. }
  3666. }
  3667. __finally
  3668. {
  3669. delete EditorList;
  3670. }
  3671. }
  3672. else
  3673. {
  3674. // "open" case
  3675. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3676. qaOK, HELP_APP_EARLY_CLOSED);
  3677. }
  3678. }
  3679. //---------------------------------------------------------------------------
  3680. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3681. {
  3682. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3683. }
  3684. //---------------------------------------------------------------------------
  3685. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3686. {
  3687. SideEnter(osRemote);
  3688. }
  3689. //---------------------------------------------------------------------------
  3690. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3691. {
  3692. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3693. SideEnter(osRemote);
  3694. }
  3695. //---------------------------------------------------------------------------
  3696. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3697. {
  3698. FCurrentSide = Side;
  3699. if (Visible)
  3700. {
  3701. UpdateControls();
  3702. }
  3703. }
  3704. //---------------------------------------------------------------------------
  3705. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3706. TStrings * FileList, bool Alternative)
  3707. {
  3708. TCustomDirView * DView = DirView(Side);
  3709. DView->SaveSelection();
  3710. DView->SaveSelectedNames();
  3711. DebugAssert(!FAlternativeDelete);
  3712. FAlternativeDelete = Alternative;
  3713. try
  3714. {
  3715. if (!IsSideLocalBrowser(Side))
  3716. {
  3717. DebugAssert(Terminal != NULL);
  3718. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3719. }
  3720. else
  3721. {
  3722. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  3723. FProgressSide = FCurrentSide;
  3724. try
  3725. {
  3726. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3727. }
  3728. __finally
  3729. {
  3730. ReloadLocalDirectory();
  3731. }
  3732. }
  3733. FAlternativeDelete = false;
  3734. }
  3735. catch(...)
  3736. {
  3737. FAlternativeDelete = false;
  3738. DView->DiscardSavedSelection();
  3739. throw;
  3740. }
  3741. DView->RestoreSelection();
  3742. }
  3743. //---------------------------------------------------------------------------
  3744. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3745. {
  3746. DebugAssert(Terminal);
  3747. DebugAssert(!IsLocalBrowserMode());
  3748. RemoteDirView->SaveSelection();
  3749. RemoteDirView->SaveSelectedNames();
  3750. try
  3751. {
  3752. if (Lock)
  3753. {
  3754. Terminal->LockFiles(FileList);
  3755. }
  3756. else
  3757. {
  3758. Terminal->UnlockFiles(FileList);
  3759. }
  3760. }
  3761. catch(...)
  3762. {
  3763. RemoteDirView->DiscardSavedSelection();
  3764. throw;
  3765. }
  3766. RemoteDirView->RestoreSelection();
  3767. }
  3768. //---------------------------------------------------------------------------
  3769. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3770. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3771. bool NoConfirmation, bool Move)
  3772. {
  3773. DebugAssert(Terminal != NULL);
  3774. DebugAssert(!IsLocalBrowserMode());
  3775. // update Terminal->StateData->RemoteDirectory
  3776. UpdateTerminal(Terminal);
  3777. if (Session == NULL)
  3778. {
  3779. Session = TTerminalManager::Instance()->ActiveTerminal;
  3780. }
  3781. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3782. {
  3783. if (RemoteDriveView->DropTarget != NULL)
  3784. {
  3785. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3786. }
  3787. else if (RemoteDirView->DropTarget != NULL)
  3788. {
  3789. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3790. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3791. }
  3792. else
  3793. {
  3794. Target = RemoteDirView->Path;
  3795. }
  3796. }
  3797. else
  3798. {
  3799. Target = Session->StateData->RemoteDirectory;
  3800. }
  3801. Target = UnixIncludeTrailingBackslash(Target);
  3802. if (FileList->Count == 1)
  3803. {
  3804. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3805. }
  3806. else
  3807. {
  3808. FileMask = AnyMask;
  3809. }
  3810. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3811. bool Result = true;
  3812. if (!NoConfirmation)
  3813. {
  3814. bool Multi = (FileList->Count > 1);
  3815. if (Move)
  3816. {
  3817. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3818. }
  3819. else
  3820. {
  3821. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3822. TStrings * Directories = new TStringList;
  3823. try
  3824. {
  3825. for (int Index = 0; Index < Sessions->Count; Index++)
  3826. {
  3827. TManagedTerminal * Terminal =
  3828. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3829. Directories->Add(Terminal->StateData->RemoteDirectory);
  3830. }
  3831. TDirectRemoteCopy AllowDirectCopy;
  3832. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3833. {
  3834. DebugAssert(DirectCopy);
  3835. AllowDirectCopy = drcAllow;
  3836. }
  3837. else if (FTerminal->IsCapable[fcSecondaryShell])
  3838. {
  3839. DebugAssert(DirectCopy);
  3840. AllowDirectCopy = drcConfirmCommandSession;
  3841. }
  3842. else
  3843. {
  3844. DebugAssert(!DirectCopy);
  3845. AllowDirectCopy = drcDisallow;
  3846. }
  3847. void * ASession = Session;
  3848. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3849. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3850. Session = static_cast<TManagedTerminal *>(ASession);
  3851. }
  3852. __finally
  3853. {
  3854. delete Directories;
  3855. }
  3856. }
  3857. }
  3858. return Result;
  3859. }
  3860. //---------------------------------------------------------------------------
  3861. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3862. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3863. {
  3864. DebugAssert(!IsLocalBrowserMode());
  3865. bool DirectCopy;
  3866. UnicodeString Target, FileMask;
  3867. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3868. if (Result)
  3869. {
  3870. if (!Move && !DirectCopy)
  3871. {
  3872. Configuration->Usage->Inc("RemoteCopyTemp");
  3873. UnicodeString RootTempDir;
  3874. UnicodeString TempDir;
  3875. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3876. TStrings * TemporaryFilesList = new TStringList();
  3877. try
  3878. {
  3879. TMakeLocalFileListParams MakeFileListParam;
  3880. MakeFileListParam.FileList = TemporaryFilesList;
  3881. MakeFileListParam.FileTimes = NULL;
  3882. MakeFileListParam.IncludeDirs = true;
  3883. MakeFileListParam.Recursive = false;
  3884. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3885. TTerminalManager::Instance()->ActiveTerminal = Session;
  3886. if (TemporaryFilesList->Count > 0)
  3887. {
  3888. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3889. CopyParam.FileMask = FileMask;
  3890. DebugAssert(!FAutoOperation);
  3891. FAutoOperation = true;
  3892. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3893. }
  3894. }
  3895. __finally
  3896. {
  3897. delete TemporaryFilesList;
  3898. FAutoOperation = false;
  3899. if (!RootTempDir.IsEmpty())
  3900. {
  3901. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3902. }
  3903. }
  3904. }
  3905. else
  3906. {
  3907. RemoteDirView->SaveSelection();
  3908. RemoteDirView->SaveSelectedNames();
  3909. try
  3910. {
  3911. if (Move)
  3912. {
  3913. Configuration->Usage->Inc("RemoteMove");
  3914. Terminal->MoveFiles(FileList, Target, FileMask);
  3915. }
  3916. else
  3917. {
  3918. Configuration->Usage->Inc("RemoteCopyDirect");
  3919. DebugAssert(DirectCopy);
  3920. DebugAssert(Session == FTerminal);
  3921. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3922. FTerminal->CommandSessionOpened ||
  3923. CommandSessionFallback())
  3924. {
  3925. Terminal->CopyFiles(FileList, Target, FileMask);
  3926. }
  3927. }
  3928. }
  3929. catch(...)
  3930. {
  3931. RemoteDirView->DiscardSavedSelection();
  3932. throw;
  3933. }
  3934. RemoteDirView->RestoreSelection();
  3935. }
  3936. }
  3937. return Result;
  3938. }
  3939. //---------------------------------------------------------------------------
  3940. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3941. const UnicodeString & Path, TRemoteProperties & Properties)
  3942. {
  3943. DebugAssert(!IsLocalBrowserMode());
  3944. Properties.Valid = Properties.Valid << vpEncrypt;
  3945. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3946. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3947. }
  3948. //---------------------------------------------------------------------------
  3949. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3950. {
  3951. Side = GetSide(Side);
  3952. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3953. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3954. UnicodeString Name = LoadStr(NEW_FOLDER);
  3955. int AllowedChanges =
  3956. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3957. bool SaveSettings = false;
  3958. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3959. {
  3960. TWindowLock Lock(this);
  3961. if (!IsSideLocalBrowser(Side))
  3962. {
  3963. if (SaveSettings)
  3964. {
  3965. GUIConfiguration->NewDirectoryProperties = Properties;
  3966. }
  3967. CreateRemoteDirectory(Name, Properties);
  3968. }
  3969. else
  3970. {
  3971. DirView(Side)->CreateDirectory(Name);
  3972. }
  3973. }
  3974. }
  3975. //---------------------------------------------------------------------------
  3976. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3977. {
  3978. TWindowLock Lock(this);
  3979. DirView(Side)->ExecuteHomeDirectory();
  3980. }
  3981. //---------------------------------------------------------------------------
  3982. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3983. {
  3984. DoOpenDirectoryDialog(odBrowse, Side);
  3985. }
  3986. //---------------------------------------------------------------------------
  3987. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3988. {
  3989. TOperationSide BookmarkSide = IsLocalBrowserMode() ? osLocal : Side;
  3990. UnicodeString Path = Bookmark->GetSideDirectory(BookmarkSide);
  3991. bool Result = !Path.IsEmpty();
  3992. if (Result)
  3993. {
  3994. // While we might get here when the session is closed (from location profiles),
  3995. // it's not a problem as the Path setter is noop then
  3996. DirView(Side)->Path = Path;
  3997. }
  3998. return Result;
  3999. }
  4000. //---------------------------------------------------------------------------
  4001. void __fastcall TCustomScpExplorerForm::CalculateSize(
  4002. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  4003. bool & Close)
  4004. {
  4005. // terminal can be already closed (e.g. dropped connection)
  4006. if (Terminal != NULL)
  4007. {
  4008. try
  4009. {
  4010. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  4011. }
  4012. catch(...)
  4013. {
  4014. if (!Terminal->Active)
  4015. {
  4016. Close = true;
  4017. }
  4018. throw;
  4019. }
  4020. }
  4021. }
  4022. //---------------------------------------------------------------------------
  4023. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4024. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4025. bool & Close)
  4026. {
  4027. // terminal can be already closed (e.g. dropped connection)
  4028. if (Terminal != NULL)
  4029. {
  4030. Configuration->Usage->Inc(L"ChecksumCalculated");
  4031. try
  4032. {
  4033. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4034. }
  4035. catch(...)
  4036. {
  4037. if (!Terminal->Active)
  4038. {
  4039. Close = true;
  4040. }
  4041. throw;
  4042. }
  4043. }
  4044. }
  4045. //---------------------------------------------------------------------------
  4046. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4047. {
  4048. bool Result;
  4049. if (!IsSideLocalBrowser(Side))
  4050. {
  4051. TRemoteTokenList * GroupList = NULL;
  4052. TRemoteTokenList * UserList = NULL;
  4053. try
  4054. {
  4055. TRemoteProperties CurrentProperties;
  4056. if (Terminal->LoadFilesProperties(FileList))
  4057. {
  4058. RemoteDirView->Invalidate();
  4059. }
  4060. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4061. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4062. if (CapableGroupChanging || CapableOwnerChanging)
  4063. {
  4064. if (CapableGroupChanging)
  4065. {
  4066. GroupList = Terminal->Groups->Duplicate();
  4067. }
  4068. if (CapableOwnerChanging)
  4069. {
  4070. UserList = Terminal->Users->Duplicate();
  4071. }
  4072. TRemoteDirectory * Files = Terminal->Files;
  4073. int Count = Files->Count;
  4074. if (Count > 100)
  4075. {
  4076. Count = 100;
  4077. }
  4078. for (int Index = 0; Index < Count; Index++)
  4079. {
  4080. TRemoteFile * File = Files->Files[Index];
  4081. if (CapableGroupChanging)
  4082. {
  4083. GroupList->AddUnique(File->Group);
  4084. }
  4085. if (CapableOwnerChanging)
  4086. {
  4087. UserList->AddUnique(File->Owner);
  4088. }
  4089. }
  4090. // if we haven't collected tokens for all files in current directory,
  4091. // make sure we collect them at least for all selected files.
  4092. // (note that so far the files in FileList has to be from current direcotry)
  4093. if (Count < Files->Count)
  4094. {
  4095. for (int Index = 0; Index < FileList->Count; Index++)
  4096. {
  4097. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4098. if (CapableGroupChanging)
  4099. {
  4100. GroupList->AddUnique(File->Group);
  4101. }
  4102. if (CapableOwnerChanging)
  4103. {
  4104. UserList->AddUnique(File->Owner);
  4105. }
  4106. }
  4107. }
  4108. }
  4109. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4110. int Flags = 0;
  4111. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4112. if (CapableOwnerChanging) Flags |= cpOwner;
  4113. if (CapableGroupChanging) Flags |= cpGroup;
  4114. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4115. if (Terminal->IsCapable[fcCalculatingChecksum])
  4116. {
  4117. CalculateChecksumEvent = CalculateChecksum;
  4118. }
  4119. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4120. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4121. TRemoteProperties NewProperties = CurrentProperties;
  4122. Result =
  4123. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4124. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4125. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4126. CalculateSize, CalculateChecksumEvent);
  4127. if (Result)
  4128. {
  4129. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4130. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4131. }
  4132. }
  4133. __finally
  4134. {
  4135. delete GroupList;
  4136. delete UserList;
  4137. }
  4138. }
  4139. else
  4140. {
  4141. DirView(Side)->DisplayPropertiesMenu();
  4142. Result = true;
  4143. }
  4144. return Result;
  4145. }
  4146. //---------------------------------------------------------------------------
  4147. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4148. {
  4149. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4150. {
  4151. FIgnoreNextDialogChar = Key;
  4152. }
  4153. Key = 0;
  4154. }
  4155. //---------------------------------------------------------------------------
  4156. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4157. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4158. {
  4159. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4160. if (Command != NULL)
  4161. {
  4162. KeyProcessed(Key, Shift);
  4163. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4164. {
  4165. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4166. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4167. false, false, const_cast<TCustomCommandType *>(Command));
  4168. }
  4169. }
  4170. }
  4171. //---------------------------------------------------------------------------
  4172. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4173. {
  4174. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4175. {
  4176. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4177. }
  4178. if (!DirView(osCurrent)->IsEditing())
  4179. {
  4180. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4181. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4182. {
  4183. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4184. // But so far it's not a problem, as it does what we want.
  4185. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4186. if (((Action->ShortCut == KeyShortCut) ||
  4187. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4188. AllowedAction(Action, aaShortCut))
  4189. {
  4190. // Has to be called before the action as the dialog char is already in queue.
  4191. // So when the action consumes message queue, we already need to have the
  4192. // FIgnoreNextDialogChar set
  4193. KeyProcessed(Key, Shift);
  4194. // Reset reference to previous component (when menu/toolbar was clicked).
  4195. // Needed to detect that action was invoked by keyboard shortcut
  4196. // in TNonVisualDataModule::ExplorerActionsExecute
  4197. Action->ActionComponent = NULL;
  4198. Action->Execute();
  4199. return;
  4200. }
  4201. }
  4202. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4203. {
  4204. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4205. {
  4206. KeyProcessed(Key, Shift);
  4207. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4208. return;
  4209. }
  4210. }
  4211. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4212. {
  4213. KeyProcessed(Key, Shift);
  4214. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4215. }
  4216. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4217. if (IsCustomShortCut(CustomShortCut))
  4218. {
  4219. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4220. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4221. if (WinConfiguration->SharedBookmarks != NULL)
  4222. {
  4223. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4224. if ((Bookmark != NULL) &&
  4225. OpenBookmark(FCurrentSide, Bookmark))
  4226. {
  4227. KeyProcessed(Key, Shift);
  4228. }
  4229. }
  4230. }
  4231. }
  4232. TForm::KeyDown(Key, Shift);
  4233. }
  4234. //---------------------------------------------------------------------------
  4235. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4236. {
  4237. bool OpenedTerminal = false;
  4238. UnicodeString ProtocolName;
  4239. UnicodeString ProtocolNameHint;
  4240. UnicodeString SecurityProtocolName;
  4241. UnicodeString DurationHint;
  4242. // See the comment in TScpCommanderForm::UpdateControls()
  4243. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4244. if (ActiveTerminal != NULL)
  4245. {
  4246. // Active is not enough here
  4247. if (ActiveTerminal->Status == ssOpened)
  4248. {
  4249. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4250. const TFileSystemInfo & FileSystemInfo = ActiveTerminal->GetFileSystemInfo();
  4251. if (FileSystemInfo.ProtocolName.IsEmpty())
  4252. {
  4253. ProtocolName = SessionInfo.ProtocolName;
  4254. }
  4255. else
  4256. {
  4257. ProtocolName = FileSystemInfo.ProtocolName;
  4258. }
  4259. ProtocolNameHint = LoadStr(STATUS_PROTOCOL_HINT);
  4260. SecurityProtocolName = SessionInfo.SecurityProtocolName;
  4261. DurationHint = LoadStr(STATUS_DURATION_HINT);
  4262. OpenedTerminal = true;
  4263. }
  4264. else if (ActiveTerminal->Status > ssClosed)
  4265. {
  4266. ProtocolName = LoadStr(STATUS_CONNECTING);
  4267. }
  4268. else
  4269. {
  4270. ProtocolName = LoadStr(STATUS_NOT_CONNECTED2);
  4271. }
  4272. }
  4273. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4274. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4275. TTBXStatusPanel * ProtocolStatusPanel = SessionStatusBar->Panels->Items[Offset + 0];
  4276. ProtocolStatusPanel->ViewPriority = (ActiveTerminal != NULL) ? 100 : 0;
  4277. if (ProtocolStatusPanel->Caption != ProtocolName)
  4278. {
  4279. ProtocolStatusPanel->Caption = ProtocolName;
  4280. std::unique_ptr<TCanvas> Canvas(CreateControlCanvas(SessionStatusBar));
  4281. ProtocolStatusPanel->Size = Canvas->TextWidth(ProtocolName) + ScaleByTextHeight(SessionStatusBar, 32);
  4282. }
  4283. ProtocolStatusPanel->Hint = ProtocolNameHint;
  4284. TTBXStatusPanel * SecurityStatusPanel = SessionStatusBar->Panels->Items[Offset + 1];
  4285. SecurityStatusPanel->ViewPriority = OpenedTerminal ? 98 : 0;
  4286. bool SecurityEnabled = !SecurityProtocolName.IsEmpty();
  4287. SecurityStatusPanel->Enabled = SecurityEnabled;
  4288. UnicodeString SecurityProtocolHint;
  4289. if (SecurityEnabled)
  4290. {
  4291. SecurityProtocolHint = FMTLOAD(STATUS_SECURE, (SecurityProtocolName));
  4292. }
  4293. else
  4294. {
  4295. SecurityProtocolHint = LoadStr(STATUS_INSECURE);
  4296. }
  4297. SecurityStatusPanel->Hint = SecurityProtocolHint;
  4298. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[Offset + 2];
  4299. DurationStatusPanel->ViewPriority = OpenedTerminal ? 99 : 0;
  4300. DurationStatusPanel->Hint = DurationHint;
  4301. UpdateStatusBar();
  4302. }
  4303. //---------------------------------------------------------------------------
  4304. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4305. {
  4306. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4307. DebugAssert(SessionStatusBar != NULL);
  4308. TTBXStatusPanel * NoteStatusPanel = SessionStatusBar->Panels->Items[0];
  4309. if (!FNote.IsEmpty())
  4310. {
  4311. NoteStatusPanel->Caption = FNote;
  4312. }
  4313. else
  4314. {
  4315. UpdateStatusPanelText(NoteStatusPanel);
  4316. }
  4317. NoteStatusPanel->Hint = FNoteHints;
  4318. UnicodeString LoginTime;
  4319. // See the comment in TScpCommanderForm::UpdateControls()
  4320. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4321. // Active is not enough here
  4322. if ((ActiveTerminal != NULL) && (ActiveTerminal->Status == ssOpened))
  4323. {
  4324. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4325. LoginTime = FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4326. }
  4327. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1];
  4328. DurationStatusPanel->Caption = LoginTime;
  4329. }
  4330. //---------------------------------------------------------------------------
  4331. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4332. {
  4333. Panel->Caption = L"";
  4334. }
  4335. //---------------------------------------------------------------------------
  4336. void __fastcall TCustomScpExplorerForm::Idle()
  4337. {
  4338. if (FShowing || FStandaloneEditing)
  4339. {
  4340. FEditorManager->Check();
  4341. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4342. // that needs to know if queue view is visible (and it may be closed after queue update)
  4343. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4344. }
  4345. if (FShowing)
  4346. {
  4347. if (!NonVisualDataModule->Busy &&
  4348. // Menu is opened or drag&drop is going on
  4349. (Mouse->Capture == NULL))
  4350. {
  4351. if (FRefreshRemoteDirectory)
  4352. {
  4353. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4354. {
  4355. Terminal->RefreshDirectory();
  4356. }
  4357. FRefreshRemoteDirectory = false;
  4358. }
  4359. if (FRefreshLocalDirectory)
  4360. {
  4361. ReloadLocalDirectory();
  4362. FRefreshLocalDirectory = false;
  4363. }
  4364. if (WinConfiguration->RefreshRemotePanel)
  4365. {
  4366. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4367. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4368. {
  4369. RemoteDirView->ReloadDirectory();
  4370. }
  4371. }
  4372. if (!FStarted)
  4373. {
  4374. FStarted = true;
  4375. InterfaceStarted();
  4376. }
  4377. }
  4378. }
  4379. if (FShowing || FStandaloneEditing)
  4380. {
  4381. if (FQueueStatusInvalidated)
  4382. {
  4383. UpdateQueueStatus(false);
  4384. }
  4385. RefreshQueueItems();
  4386. }
  4387. if (FShowing)
  4388. {
  4389. UpdateStatusBar();
  4390. }
  4391. FIgnoreNextDialogChar = 0;
  4392. }
  4393. //---------------------------------------------------------------------------
  4394. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4395. {
  4396. try
  4397. {
  4398. FUserActionTimer->Enabled = false;
  4399. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4400. {
  4401. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4402. {
  4403. FPendingQueueActionItem->ProcessUserAction();
  4404. }
  4405. }
  4406. }
  4407. __finally
  4408. {
  4409. FPendingQueueActionItem = NULL;
  4410. }
  4411. }
  4412. //---------------------------------------------------------------------------
  4413. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4414. {
  4415. if (WinConfiguration->MinimizeToTray)
  4416. {
  4417. UpdateTrayIcon();
  4418. FTrayIcon->Visible = true;
  4419. if (Visible)
  4420. {
  4421. ShowWindow(Handle, SW_HIDE);
  4422. }
  4423. }
  4424. }
  4425. //---------------------------------------------------------------------------
  4426. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4427. {
  4428. // WORKAROUND
  4429. // When restoring maximized window from minimization,
  4430. // rarely some controls do not align properly.
  4431. // Two instances seen (both for Commander):
  4432. // - When restoring, window is temporarily narrower (not maximized),
  4433. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4434. // Once maximized already, top dock shinks back, but the session PageControl,
  4435. // do not align up, leaving space between TopDock and PageControl.
  4436. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4437. for (int Index = 0; Index < ControlCount; Index++)
  4438. {
  4439. RealignControl(Controls[Index]);
  4440. }
  4441. if (FTrayIcon->Visible)
  4442. {
  4443. FTrayIcon->Visible = false;
  4444. if (Visible)
  4445. {
  4446. ShowWindow(Handle, SW_SHOW);
  4447. }
  4448. }
  4449. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4450. {
  4451. FNeedSession = false;
  4452. NonVisualDataModule->StartBusy();
  4453. try
  4454. {
  4455. NeedSession(true);
  4456. }
  4457. __finally
  4458. {
  4459. NonVisualDataModule->EndBusy();
  4460. }
  4461. }
  4462. }
  4463. //---------------------------------------------------------------------------
  4464. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4465. {
  4466. FTrayIcon->Hint = GetMainForm()->Caption;
  4467. }
  4468. //---------------------------------------------------------------------------
  4469. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4470. {
  4471. UpdateTrayIcon();
  4472. }
  4473. //---------------------------------------------------------------------------
  4474. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4475. {
  4476. // workaround
  4477. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4478. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4479. // But WM_ACTIVATEAPP message can be received even when
  4480. // the main window is minimized to the tray and internal editor window is focused
  4481. // (after another application was previously active)
  4482. if (::IsIconic(Handle))
  4483. {
  4484. if (!IsAppIconic())
  4485. {
  4486. SetAppIconic(true);
  4487. }
  4488. }
  4489. ::ApplicationRestore();
  4490. Application->BringToFront();
  4491. }
  4492. //---------------------------------------------------------------------------
  4493. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4494. {
  4495. RestoreApp();
  4496. }
  4497. //---------------------------------------------------------------------------
  4498. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4499. {
  4500. if (OpenInNewWindow())
  4501. {
  4502. // todo: Pass FromSite
  4503. ExecuteNewInstance(SessionUrl);
  4504. }
  4505. else
  4506. {
  4507. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4508. }
  4509. }
  4510. //---------------------------------------------------------------------------
  4511. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4512. {
  4513. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4514. StoredSessions->NewSession(SessionName, SessionData);
  4515. // modified only, explicit
  4516. StoredSessions->Save(false, true);
  4517. // encode session name because of slashes in hierarchical sessions
  4518. return EncodeUrlString(SessionName);
  4519. }
  4520. //---------------------------------------------------------------------------
  4521. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4522. {
  4523. // current working directories become defaults here, what is not right
  4524. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4525. return SaveHiddenDuplicateSession(SessionData.get());
  4526. }
  4527. //---------------------------------------------------------------------------
  4528. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4529. {
  4530. if (OpenInNewWindow())
  4531. {
  4532. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4533. }
  4534. else
  4535. {
  4536. // current working directories become defaults here, what is not right
  4537. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4538. TTerminalManager * Manager = TTerminalManager::Instance();
  4539. TManagedTerminal * Terminal = Manager->NewManagedTerminal(SessionData.get());
  4540. Manager->ActiveTerminal = Terminal;
  4541. }
  4542. }
  4543. //---------------------------------------------------------------------------
  4544. void __fastcall TCustomScpExplorerForm::RenameSession()
  4545. {
  4546. UnicodeString Name = Terminal->SessionData->SessionName;
  4547. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4548. {
  4549. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4550. TSessionData::ValidateName(Name);
  4551. // This is inconsistent with how color (for example) is handled.
  4552. Terminal->SessionData->Name = Name;
  4553. UpdateControls();
  4554. // Add/Remove distinguishing paths from sessions of the same name.
  4555. DoTerminalListChanged();
  4556. }
  4557. }
  4558. //---------------------------------------------------------------------------
  4559. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4560. {
  4561. DebugAssert(Queue != NULL);
  4562. bool Result = Queue->IsEmpty;
  4563. if (!Result)
  4564. {
  4565. SetFocus();
  4566. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4567. }
  4568. return Result;
  4569. }
  4570. //---------------------------------------------------------------------------
  4571. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4572. {
  4573. return CanCloseQueue(FQueue);
  4574. }
  4575. //---------------------------------------------------------------------------
  4576. void __fastcall TCustomScpExplorerForm::CloseSession()
  4577. {
  4578. if (CanCloseQueue())
  4579. {
  4580. TTerminalManager::Instance()->FreeActiveTerminal();
  4581. }
  4582. }
  4583. //---------------------------------------------------------------------------
  4584. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4585. {
  4586. if (CanCloseQueue())
  4587. {
  4588. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4589. }
  4590. }
  4591. //---------------------------------------------------------------------------
  4592. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4593. {
  4594. DetachTerminal(Terminal);
  4595. RemoteDirView->Terminal = Terminal;
  4596. UpdateRemotePathComboBox(false);
  4597. InitStatusBar();
  4598. UpdateControls();
  4599. }
  4600. //---------------------------------------------------------------------------
  4601. void __fastcall TCustomScpExplorerForm::TerminalConnecting()
  4602. {
  4603. InitStatusBar();
  4604. }
  4605. //---------------------------------------------------------------------------
  4606. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4607. {
  4608. if (DebugAlwaysTrue(!Terminal->Active))
  4609. {
  4610. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4611. }
  4612. }
  4613. //---------------------------------------------------------------------------
  4614. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4615. {
  4616. if (OpenInNewWindow())
  4617. {
  4618. // encode session name because of slashes in hierarchical sessions
  4619. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4620. }
  4621. else
  4622. {
  4623. TTerminalManager * Manager = TTerminalManager::Instance();
  4624. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4625. Manager->ActiveTerminal = Terminal;
  4626. }
  4627. }
  4628. //---------------------------------------------------------------------------
  4629. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4630. {
  4631. TTerminalManager * Manager = TTerminalManager::Instance();
  4632. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4633. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4634. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4635. // FirstTerminal can be null, if some of the
  4636. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4637. {
  4638. FirstTerminal->Disconnected = true;
  4639. FirstTerminal->DisconnectedTemporarily = true;
  4640. }
  4641. Manager->ActiveTerminal = FirstTerminal;
  4642. }
  4643. //---------------------------------------------------------------------------
  4644. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4645. {
  4646. if (OpenInNewWindow())
  4647. {
  4648. ExecuteNewInstance(Name);
  4649. }
  4650. else
  4651. {
  4652. DoOpenFolderOrWorkspace(Name, true);
  4653. }
  4654. }
  4655. //---------------------------------------------------------------------------
  4656. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4657. bool &CanClose)
  4658. {
  4659. // See the comment in CloseApp()
  4660. if (NonVisualDataModule->Busy)
  4661. {
  4662. CanClose = false;
  4663. }
  4664. else if (Terminal != NULL)
  4665. {
  4666. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4667. {
  4668. unsigned int Result;
  4669. TMessageParams Params(mpNeverAskAgainCheck);
  4670. UnicodeString Message;
  4671. int Answers = qaOK | qaCancel;
  4672. if (TTerminalManager::Instance()->Count > 1)
  4673. {
  4674. if (!WinConfiguration->AutoSaveWorkspace)
  4675. {
  4676. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4677. }
  4678. else
  4679. {
  4680. Message = LoadStr(CLOSE_SESSIONS);
  4681. }
  4682. }
  4683. else
  4684. {
  4685. if (!WinConfiguration->AutoSaveWorkspace)
  4686. {
  4687. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4688. }
  4689. else
  4690. {
  4691. Message = LoadStr(CLOSE_SESSION);
  4692. }
  4693. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4694. }
  4695. UnicodeString Note;
  4696. if (WinConfiguration->AutoSaveWorkspace)
  4697. {
  4698. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4699. }
  4700. else
  4701. {
  4702. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4703. Answers = qaYes | qaNo | qaCancel;
  4704. }
  4705. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4706. SetFocus();
  4707. Result = MessageDialog(Message, qtConfirmation,
  4708. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4709. if (Result == qaNeverAskAgain)
  4710. {
  4711. WinConfiguration->ConfirmClosingSession = false;
  4712. }
  4713. if (Result == qaNo)
  4714. {
  4715. CanClose = SaveWorkspace(true);
  4716. // note that the workspace will be saved redundatly again from FormClose
  4717. }
  4718. else
  4719. {
  4720. CanClose =
  4721. (Result == qaOK) ||
  4722. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4723. (Result == qaNeverAskAgain);
  4724. }
  4725. }
  4726. if (CanClose)
  4727. {
  4728. CanClose = CanCloseQueue();
  4729. }
  4730. }
  4731. if (CanClose)
  4732. {
  4733. CanClose =
  4734. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4735. FEditorManager->CloseExternalFilesWithoutProcess();
  4736. if (CanClose)
  4737. {
  4738. while (CanClose && (FLocalEditors->Count > 0))
  4739. {
  4740. int PrevCount = FLocalEditors->Count;
  4741. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4742. CanClose = (FLocalEditors->Count < PrevCount);
  4743. }
  4744. if (CanClose)
  4745. {
  4746. CanClose = FEditorManager->Empty(true);
  4747. if (!CanClose)
  4748. {
  4749. SetFocus();
  4750. CanClose =
  4751. (MessageDialog(
  4752. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4753. }
  4754. }
  4755. }
  4756. }
  4757. }
  4758. //---------------------------------------------------------------------------
  4759. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4760. {
  4761. TForm * Form = dynamic_cast<TForm *>(Sender);
  4762. DebugAssert(Form != NULL);
  4763. Form->Close();
  4764. }
  4765. //---------------------------------------------------------------------------
  4766. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4767. {
  4768. TForm * Form = dynamic_cast<TForm *>(Sender);
  4769. delete Form;
  4770. }
  4771. //---------------------------------------------------------------------------
  4772. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4773. {
  4774. while (FLocalEditors->Count > 0)
  4775. {
  4776. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4777. }
  4778. }
  4779. //---------------------------------------------------------------------------
  4780. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4781. TObject *Sender)
  4782. {
  4783. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4784. try
  4785. {
  4786. SetProperties(osRemote, FileList);
  4787. }
  4788. __finally
  4789. {
  4790. delete FileList;
  4791. }
  4792. }
  4793. //---------------------------------------------------------------------------
  4794. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4795. {
  4796. if (value)
  4797. {
  4798. if (Component == fcCustomCommandsBand)
  4799. {
  4800. UpdateCustomCommandsToolbar();
  4801. }
  4802. if (Component == fcQueueFileList)
  4803. {
  4804. DebugAssert(!QueueFileListSplitter->Visible);
  4805. AdjustQueueLayout();
  4806. UpdateQueueFileList();
  4807. }
  4808. }
  4809. }
  4810. //---------------------------------------------------------------------------
  4811. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4812. {
  4813. int MinHeightLimit =
  4814. GetStaticQueuePanelComponentsHeight() +
  4815. QueueFileListSplitter->Height +
  4816. QueueFileList->Height +
  4817. GetMinQueueViewHeight();
  4818. if (QueuePanel->ClientHeight < MinHeightLimit)
  4819. {
  4820. QueuePanel->ClientHeight = MinHeightLimit;
  4821. }
  4822. }
  4823. //---------------------------------------------------------------------------
  4824. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4825. {
  4826. TControl * Control = GetComponent(Component);
  4827. DebugAssert(Control);
  4828. bool Changed = (Control->Visible != value);
  4829. if (Changed)
  4830. {
  4831. ComponentShowing(Component, value);
  4832. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4833. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4834. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4835. if (value)
  4836. {
  4837. int RemainingHeight = Control->Parent->ClientHeight;
  4838. int RemainingWidth = Control->Parent->ClientWidth;
  4839. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4840. {
  4841. TControl * ChildControl = Control->Parent->Controls[i];
  4842. if (ChildControl->Visible)
  4843. {
  4844. switch (ChildControl->Align)
  4845. {
  4846. case alTop:
  4847. case alBottom:
  4848. RemainingHeight -= ChildControl->Height;
  4849. break;
  4850. case alLeft:
  4851. case alRight:
  4852. RemainingWidth -= ChildControl->Width;
  4853. break;
  4854. }
  4855. }
  4856. }
  4857. int Reserve = ScaleByTextHeight(this, 32);
  4858. // queue in explorer, trees in commander
  4859. if (Control->Height > RemainingHeight - Reserve)
  4860. {
  4861. Control->Height = RemainingHeight / 2;
  4862. }
  4863. if (Control->Width > RemainingWidth - Reserve)
  4864. {
  4865. Control->Width = RemainingWidth / 2;
  4866. }
  4867. }
  4868. Control->Visible = value;
  4869. if (WasFocused && Visible)
  4870. {
  4871. DirView(osCurrent)->SetFocus();
  4872. }
  4873. FixControlsPlacement();
  4874. }
  4875. }
  4876. //---------------------------------------------------------------------------
  4877. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4878. {
  4879. TControl * Control = GetComponent(Component);
  4880. if (Control == NULL)
  4881. {
  4882. return false;
  4883. }
  4884. else
  4885. {
  4886. return Control->Visible;
  4887. }
  4888. }
  4889. //---------------------------------------------------------------------------
  4890. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4891. {
  4892. bool Result;
  4893. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4894. {
  4895. Result = !IsUWP();
  4896. }
  4897. else
  4898. {
  4899. Result = true;
  4900. }
  4901. return Result;
  4902. }
  4903. //---------------------------------------------------------------------------
  4904. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  4905. {
  4906. if (DirView->ItemFocused != NULL)
  4907. {
  4908. DirView->ItemFocused->MakeVisible(false);
  4909. }
  4910. }
  4911. //---------------------------------------------------------------------------
  4912. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4913. {
  4914. MakeFocusedItemVisible(RemoteDirView);
  4915. QueueSplitter->Visible = QueuePanel->Visible;
  4916. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4917. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4918. TControl * QueueControlsOrder[] =
  4919. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4920. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4921. }
  4922. //---------------------------------------------------------------------------
  4923. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4924. {
  4925. switch (Component) {
  4926. case fcStatusBar: return RemoteStatusBar;
  4927. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4928. case fcQueueView: return QueuePanel;
  4929. case fcQueueToolbar: return QueueDock;
  4930. case fcRemoteTree: return RemoteDrivePanel;
  4931. case fcSessionsTabs: return SessionsPageControl;
  4932. case fcQueueFileList: return QueueFileList;
  4933. default: return NULL;
  4934. }
  4935. }
  4936. //---------------------------------------------------------------------------
  4937. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4938. TObject *Sender, TListColumn *Column, TPoint &Point)
  4939. {
  4940. DebugAssert(NonVisualDataModule && Column && Sender);
  4941. NonVisualDataModule->ListColumn = Column;
  4942. TPopupMenu * DirViewColumnMenu;
  4943. if (Sender == DirView(osOther))
  4944. {
  4945. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4946. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4947. (Column->Index == uvName);
  4948. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4949. (Column->Index == uvSize);
  4950. }
  4951. else
  4952. {
  4953. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4954. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4955. (Column->Index == dvName);
  4956. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4957. (Column->Index == dvSize);
  4958. }
  4959. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4960. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4961. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4962. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4963. }
  4964. //---------------------------------------------------------------------------
  4965. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4966. TObject *Sender, TListItem *Item, bool &AllowExec)
  4967. {
  4968. DoDirViewExecFile(Sender, Item, AllowExec);
  4969. }
  4970. //---------------------------------------------------------------------------
  4971. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4972. TListItem * Item, bool & AllowExec)
  4973. {
  4974. DebugAssert(Sender && Item && Configuration);
  4975. DebugAssert(AllowExec);
  4976. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4977. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  4978. bool Remote = !IsSideLocalBrowser(Side);
  4979. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  4980. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4981. // on files only (not directories)
  4982. // and only when symlinks are resolved (apply to remote panel only)
  4983. if (!ADirView->ItemIsDirectory(Item) &&
  4984. (ResolvedSymlinks || FForceExecution))
  4985. {
  4986. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4987. !FForceExecution && ResolvedSymlinks)
  4988. {
  4989. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4990. {
  4991. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4992. UnlockWindow();
  4993. try
  4994. {
  4995. if (IsLocalBrowserMode())
  4996. {
  4997. LocalLocalCopy(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation, false, 0);
  4998. }
  4999. else
  5000. {
  5001. ExecuteFileOperation(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  5002. }
  5003. }
  5004. __finally
  5005. {
  5006. LockWindow();
  5007. }
  5008. AllowExec = false;
  5009. }
  5010. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  5011. {
  5012. if (!Remote || !WinConfiguration->DisableOpenEdit)
  5013. {
  5014. ExecuteFile(Side, efDefaultEditor);
  5015. AllowExec = false;
  5016. }
  5017. }
  5018. else
  5019. {
  5020. DebugFail();
  5021. }
  5022. }
  5023. // if we have not done anything special, fall back to default behavior
  5024. if (AllowExec)
  5025. {
  5026. if (Remote && !WinConfiguration->DisableOpenEdit)
  5027. {
  5028. ExecuteFile(osRemote, efShell);
  5029. AllowExec = false;
  5030. }
  5031. }
  5032. }
  5033. }
  5034. //---------------------------------------------------------------------------
  5035. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  5036. {
  5037. return ((Side == osRemote) || (Side == osCurrent));
  5038. }
  5039. //---------------------------------------------------------------------------
  5040. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5041. {
  5042. DebugFail();
  5043. }
  5044. //---------------------------------------------------------------------------
  5045. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5046. {
  5047. DebugFail();
  5048. }
  5049. //---------------------------------------------------------------------------
  5050. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5051. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5052. {
  5053. TSynchronizeParamType Params;
  5054. Params.LocalDirectory = LocalDirectory;
  5055. Params.RemoteDirectory = RemoteDirectory;
  5056. int UnusedParams =
  5057. (GUIConfiguration->SynchronizeParams &
  5058. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5059. TTerminal::spCaseSensitive));
  5060. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5061. Params.Options = GUIConfiguration->SynchronizeOptions;
  5062. bool SaveSettings = false;
  5063. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5064. &DoSynchronizeTooManyDirectories);
  5065. DebugAssert(FSynchronizeController == NULL);
  5066. FSynchronizeController = &Controller;
  5067. bool Result;
  5068. try
  5069. {
  5070. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5071. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5072. int Options =
  5073. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5074. DebugAssert(FOnFeedSynchronizeError == NULL);
  5075. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5076. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5077. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5078. if (Result)
  5079. {
  5080. if (SaveSettings)
  5081. {
  5082. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5083. GUIConfiguration->SynchronizeOptions = Params.Options;
  5084. }
  5085. else
  5086. {
  5087. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5088. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5089. FLAGSET(Params.Options, soSynchronize))
  5090. {
  5091. GUIConfiguration->SynchronizeOptions =
  5092. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5093. soSynchronize;
  5094. }
  5095. }
  5096. LocalDirectory = Params.LocalDirectory;
  5097. RemoteDirectory = Params.RemoteDirectory;
  5098. }
  5099. }
  5100. __finally
  5101. {
  5102. FSynchronizeController = NULL;
  5103. DebugAssert(FOnFeedSynchronizeError == NULL);
  5104. FOnFeedSynchronizeError = NULL;
  5105. }
  5106. return Result;
  5107. }
  5108. //---------------------------------------------------------------------------
  5109. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5110. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5111. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5112. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5113. TSynchronizeOptions * Options, bool Full)
  5114. {
  5115. // Keep-up-to-date mode
  5116. if (Terminal->Status == ssOpened)
  5117. {
  5118. try
  5119. {
  5120. int PParams = Params.Params;
  5121. if (!Full)
  5122. {
  5123. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5124. if (FLAGSET(Params.Options, soRecurse))
  5125. {
  5126. PParams |= TTerminal::spSubDirs;
  5127. }
  5128. }
  5129. else
  5130. {
  5131. // if keepuptodate is non-recursive,
  5132. // full sync before has to be non-recursive as well
  5133. if (FLAGCLEAR(Params.Options, soRecurse))
  5134. {
  5135. PParams |= TTerminal::spNoRecurse;
  5136. }
  5137. }
  5138. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5139. PParams, Checklist, Options);
  5140. }
  5141. catch (Exception & E)
  5142. {
  5143. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5144. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5145. {
  5146. // noop, already logged in MoreMessageDialog
  5147. }
  5148. else
  5149. {
  5150. ShowExtendedExceptionEx(Terminal, &E);
  5151. throw;
  5152. }
  5153. }
  5154. }
  5155. }
  5156. //---------------------------------------------------------------------------
  5157. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5158. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5159. const UnicodeString ErrorStr)
  5160. {
  5161. if (!Directory.IsEmpty())
  5162. {
  5163. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5164. }
  5165. else
  5166. {
  5167. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5168. }
  5169. }
  5170. //---------------------------------------------------------------------------
  5171. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5172. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5173. {
  5174. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5175. {
  5176. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5177. }
  5178. else
  5179. {
  5180. TMessageParams Params(mpNeverAskAgainCheck);
  5181. unsigned int Result = MessageDialog(
  5182. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5183. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5184. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5185. {
  5186. MaxDirectories *= 2;
  5187. if (Result == qaNeverAskAgain)
  5188. {
  5189. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5190. }
  5191. }
  5192. else
  5193. {
  5194. Abort();
  5195. }
  5196. }
  5197. }
  5198. //---------------------------------------------------------------------------
  5199. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5200. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5201. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5202. TSynchronizeOptions * Options)
  5203. {
  5204. // Keep-up-to-date mode
  5205. DebugAssert(!FAutoOperation);
  5206. void * BatchStorage;
  5207. BatchStart(BatchStorage);
  5208. FAutoOperation = true;
  5209. bool AnyOperation = false;
  5210. TDateTime StartTime = Now();
  5211. TSynchronizeChecklist * AChecklist = NULL;
  5212. try
  5213. {
  5214. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5215. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5216. {
  5217. FSynchronizeProgressForm->Start();
  5218. }
  5219. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5220. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5221. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5222. Options);
  5223. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5224. SAFE_DESTROY(FSynchronizeProgressForm);
  5225. AnyOperation = (AChecklist->CheckedCount > 0);
  5226. if (AnyOperation)
  5227. {
  5228. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5229. CreateProgressForm(&SynchronizeProgress);
  5230. try
  5231. {
  5232. Terminal->SynchronizeApply(
  5233. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5234. SynchronizeProcessedItem, NULL, NULL, NULL);
  5235. }
  5236. __finally
  5237. {
  5238. DestroyProgressForm();
  5239. }
  5240. }
  5241. }
  5242. __finally
  5243. {
  5244. if (Checklist == NULL)
  5245. {
  5246. delete AChecklist;
  5247. }
  5248. else
  5249. {
  5250. *Checklist = AChecklist;
  5251. }
  5252. FAutoOperation = false;
  5253. SAFE_DESTROY(FSynchronizeProgressForm);
  5254. BatchEnd(BatchStorage);
  5255. ReloadLocalDirectory();
  5256. if (AnyOperation)
  5257. {
  5258. OperationComplete(StartTime);
  5259. }
  5260. }
  5261. }
  5262. //---------------------------------------------------------------------------
  5263. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5264. {
  5265. // can be called from command line
  5266. return Visible &&
  5267. ((DirView(osRemote)->SelCount > 0) ||
  5268. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5269. }
  5270. //---------------------------------------------------------------------------
  5271. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5272. {
  5273. LogSynchronizeEvent(Terminal, Message);
  5274. }
  5275. //---------------------------------------------------------------------------
  5276. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5277. int Params, TSynchronizeOptions & Options)
  5278. {
  5279. DebugAssert(!IsLocalBrowserMode());
  5280. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5281. {
  5282. Options.Filter = new TStringList();
  5283. Options.Filter->CaseSensitive = false;
  5284. Options.Filter->Duplicates = Types::dupAccept;
  5285. if (DirView(osRemote)->SelCount > 0)
  5286. {
  5287. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5288. }
  5289. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5290. {
  5291. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5292. }
  5293. Options.Filter->Sort();
  5294. }
  5295. }
  5296. //---------------------------------------------------------------------------
  5297. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5298. {
  5299. TCopyParamType Defaults;
  5300. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5301. ConfigStorage->AccessMode = smRead;
  5302. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5303. {
  5304. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5305. }
  5306. ConfigStorage.reset(NULL);
  5307. std::unique_ptr<TStringList> Options(new TStringList());
  5308. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5309. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5310. UnicodeString Result;
  5311. if (Options->Count > 0)
  5312. {
  5313. Result =
  5314. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5315. }
  5316. return Result;
  5317. }
  5318. //---------------------------------------------------------------------------
  5319. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5320. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5321. {
  5322. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5323. UnicodeString AdditionalParams =
  5324. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5325. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5326. SerializeCopyParamForCommandLine(CopyParams),
  5327. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5328. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5329. ExecuteNewInstance(SessionName, AdditionalParams);
  5330. }
  5331. //---------------------------------------------------------------------------
  5332. struct TSynchronizeParams
  5333. {
  5334. UnicodeString LocalDirectory;
  5335. UnicodeString RemoteDirectory;
  5336. TSynchronizeMode Mode;
  5337. TSynchronizeChecklist * Checklist;
  5338. int Params;
  5339. TCopyParamType * CopyParam;
  5340. TDateTime CollectElapsed;
  5341. TDateTime * StartTime;
  5342. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5343. };
  5344. //---------------------------------------------------------------------------
  5345. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5346. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5347. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5348. {
  5349. DebugAssert(!FAutoOperation);
  5350. void * BatchStorage;
  5351. BatchStart(BatchStorage);
  5352. FAutoOperation = true;
  5353. TFileOperationStatistics Statistics;
  5354. TDateTime Start = Now();
  5355. try
  5356. {
  5357. Params.OnProcessedItem = OnProcessedItem;
  5358. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5359. CreateProgressForm(&SynchronizeProgress);
  5360. Terminal->SynchronizeApply(
  5361. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5362. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5363. &Statistics);
  5364. }
  5365. __finally
  5366. {
  5367. Params.OnProcessedItem = NULL;
  5368. FAutoOperation = false;
  5369. DestroyProgressForm();
  5370. BatchEnd(BatchStorage);
  5371. ReloadLocalDirectory();
  5372. }
  5373. if (WinConfiguration->SynchronizeSummary)
  5374. {
  5375. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5376. // The statistics should be 0 anyway in this case
  5377. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5378. {
  5379. Message += L"\n";
  5380. if (Statistics.FilesUploaded > 0)
  5381. {
  5382. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5383. }
  5384. if (Statistics.FilesDownloaded > 0)
  5385. {
  5386. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5387. }
  5388. if (Statistics.FilesDeletedLocal > 0)
  5389. {
  5390. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5391. }
  5392. if (Statistics.FilesDeletedRemote > 0)
  5393. {
  5394. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5395. }
  5396. }
  5397. TDateTime Elapsed = (Now() - Start);
  5398. Message +=
  5399. L"\n" +
  5400. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5401. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5402. TMessageParams Params(mpNeverAskAgainCheck);
  5403. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5404. if (Result == qaNeverAskAgain)
  5405. {
  5406. WinConfiguration->SynchronizeSummary = false;
  5407. }
  5408. }
  5409. }
  5410. //---------------------------------------------------------------------------
  5411. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5412. {
  5413. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5414. {
  5415. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5416. }
  5417. // Not set in keep-up-to-date mode - Synchronize() method
  5418. if (Token != NULL)
  5419. {
  5420. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5421. if (Params.OnProcessedItem != NULL)
  5422. {
  5423. Params.OnProcessedItem(NULL, ChecklistItem);
  5424. }
  5425. }
  5426. }
  5427. //---------------------------------------------------------------------------
  5428. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5429. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5430. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5431. {
  5432. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5433. *Params.StartTime = Now();
  5434. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5435. }
  5436. //---------------------------------------------------------------------------
  5437. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5438. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5439. {
  5440. // terminal can be already closed (e.g. dropped connection)
  5441. if (Terminal != NULL)
  5442. {
  5443. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5444. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5445. }
  5446. }
  5447. //---------------------------------------------------------------------------
  5448. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5449. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5450. {
  5451. DebugAssert(!IsLocalBrowserMode());
  5452. TAutoBatch AutoBatch(this);
  5453. TAutoFlag AutoOperationFlag(FAutoOperation);
  5454. if (Side == osRemote)
  5455. {
  5456. std::unique_ptr<TStrings> FileList(new TStringList());
  5457. FileList->AddObject(FileName, RemoteFile);
  5458. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5459. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5460. RemoteDirView->SaveSelection();
  5461. RemoteDirView->SaveSelectedNames();
  5462. try
  5463. {
  5464. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5465. }
  5466. catch(...)
  5467. {
  5468. RemoteDirView->DiscardSavedSelection();
  5469. throw;
  5470. }
  5471. RemoteDirView->RestoreSelection();
  5472. }
  5473. else if (DebugAlwaysTrue(Side == osLocal))
  5474. {
  5475. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5476. {
  5477. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5478. }
  5479. UnicodeString Directory = ExtractFileDir(FileName);
  5480. ReloadLocalDirectory(Directory);
  5481. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5482. if (!SamePaths(Directory, NewDirectory))
  5483. {
  5484. ReloadLocalDirectory(NewDirectory);
  5485. }
  5486. }
  5487. }
  5488. //---------------------------------------------------------------------------
  5489. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5490. {
  5491. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5492. if (Side == osLocal)
  5493. {
  5494. if (Action == TSynchronizeChecklist::saDownloadNew)
  5495. {
  5496. OpenFolderInExplorer(LocalPath);
  5497. }
  5498. else
  5499. {
  5500. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5501. }
  5502. }
  5503. else if (DebugAlwaysTrue(Side == osRemote))
  5504. {
  5505. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5506. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5507. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5508. if (!LocalPath.IsEmpty())
  5509. {
  5510. SessionData->LocalDirectory = LocalPath;
  5511. }
  5512. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5513. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5514. }
  5515. }
  5516. //---------------------------------------------------------------------------
  5517. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5518. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5519. const TCopyParamType * CopyParams)
  5520. {
  5521. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5522. UnicodeString AdditionalParams =
  5523. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5524. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5525. SerializeCopyParamForCommandLine(CopyParams),
  5526. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5527. LocalDirectory, RemoteDirectory, Mode, Params));
  5528. ExecuteNewInstance(SessionName, AdditionalParams);
  5529. }
  5530. //---------------------------------------------------------------------------
  5531. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5532. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5533. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5534. {
  5535. int Result;
  5536. bool SaveSettings = false;
  5537. int Options =
  5538. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5539. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5540. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5541. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5542. bool Continue =
  5543. (UseDefaults == 0) ||
  5544. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5545. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5546. if (Continue)
  5547. {
  5548. Configuration->Usage->Inc(L"Synchronizations");
  5549. UpdateCopyParamCounters(CopyParam);
  5550. TSynchronizeOptions SynchronizeOptions;
  5551. GetSynchronizeOptions(Params, SynchronizeOptions);
  5552. if (SaveSettings)
  5553. {
  5554. GUIConfiguration->SynchronizeParams = Params;
  5555. }
  5556. else
  5557. {
  5558. SaveMode = false;
  5559. }
  5560. TDateTime StartTime = Now();
  5561. TSynchronizeChecklist * Checklist = NULL;
  5562. try
  5563. {
  5564. DebugAssert(!FAutoOperation);
  5565. FAutoOperation = true;
  5566. try
  5567. {
  5568. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5569. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5570. int Files = -1;
  5571. if (DataList->Count >= 1)
  5572. {
  5573. Files = StrToIntDef(DataList->Strings[0], Files);
  5574. }
  5575. else
  5576. {
  5577. DataList->Add(UnicodeString());
  5578. }
  5579. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5580. FSynchronizeProgressForm->Start();
  5581. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5582. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5583. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5584. &SynchronizeOptions);
  5585. if (Terminal->SessionData->CacheDirectories)
  5586. {
  5587. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5588. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5589. }
  5590. }
  5591. __finally
  5592. {
  5593. FAutoOperation = false;
  5594. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5595. SAFE_DESTROY(FSynchronizeProgressForm);
  5596. }
  5597. TSynchronizeParams SynchronizeParams;
  5598. SynchronizeParams.LocalDirectory = LocalDirectory;
  5599. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5600. SynchronizeParams.Mode = Mode;
  5601. SynchronizeParams.CopyParam = &CopyParam;
  5602. SynchronizeParams.Params = Params;
  5603. SynchronizeParams.Checklist = Checklist;
  5604. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5605. SynchronizeParams.StartTime = &StartTime;
  5606. SynchronizeParams.OnProcessedItem = NULL;
  5607. Result = Checklist->Count;
  5608. if (Checklist->Count > 0)
  5609. {
  5610. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5611. {
  5612. if (!DoSynchronizeChecklistDialog(
  5613. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5614. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5615. {
  5616. Result = -1;
  5617. }
  5618. }
  5619. else
  5620. {
  5621. FullSynchronize(SynchronizeParams, NULL, NULL);
  5622. }
  5623. }
  5624. else
  5625. {
  5626. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5627. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5628. }
  5629. }
  5630. __finally
  5631. {
  5632. delete Checklist;
  5633. }
  5634. OperationComplete(StartTime);
  5635. }
  5636. else
  5637. {
  5638. Result = -1;
  5639. }
  5640. return Result;
  5641. }
  5642. //---------------------------------------------------------------------------
  5643. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5644. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5645. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5646. {
  5647. if (Collect)
  5648. {
  5649. DebugAssert(FSynchronizeProgressForm != NULL);
  5650. if (!FSynchronizeProgressForm->Started)
  5651. {
  5652. FSynchronizeProgressForm->Start();
  5653. }
  5654. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5655. SetTaskbarListProgressValue(CompareProgress);
  5656. }
  5657. else
  5658. {
  5659. DebugAssert(FSynchronizeProgressForm == NULL);
  5660. DebugAssert(FProgressForm != NULL);
  5661. }
  5662. }
  5663. //---------------------------------------------------------------------------
  5664. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5665. {
  5666. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5667. TRemoteFile * File = NULL;
  5668. Terminal->ReadFile(FullFileName, File);
  5669. if (File != NULL)
  5670. {
  5671. std::unique_ptr<TRemoteFile> FileOwner(File);
  5672. TAutoFlag Flag(FStandaloneEditing);
  5673. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5674. Application->ShowMainForm = false;
  5675. Application->Run();
  5676. }
  5677. }
  5678. //---------------------------------------------------------------------------
  5679. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  5680. {
  5681. DebugFail();
  5682. }
  5683. //---------------------------------------------------------------------------
  5684. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5685. {
  5686. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5687. SessionData->Assign(Terminal->SessionData);
  5688. UpdateSessionData(SessionData.get());
  5689. Terminal->UpdateSessionCredentials(SessionData.get());
  5690. if (!Terminal->SessionData->HasSessionName())
  5691. {
  5692. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5693. // once IsWorkspace is cleared
  5694. SessionData->Name = UnicodeString();
  5695. SessionData->IsWorkspace = false;
  5696. }
  5697. return SessionData.release();
  5698. }
  5699. //---------------------------------------------------------------------------
  5700. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5701. {
  5702. TSessionData * SessionData = CloneCurrentSessionData();
  5703. try
  5704. {
  5705. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5706. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5707. }
  5708. __finally
  5709. {
  5710. delete SessionData;
  5711. }
  5712. }
  5713. //---------------------------------------------------------------------------
  5714. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5715. {
  5716. TTerminalManager * Manager = TTerminalManager::Instance();
  5717. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5718. if (DebugAlwaysTrue(Terminal != NULL))
  5719. {
  5720. // Update (Managed)Terminal->StateData
  5721. UpdateTerminal(Terminal);
  5722. }
  5723. Manager->SaveWorkspace(DataList.get());
  5724. return DataList.release();
  5725. }
  5726. //---------------------------------------------------------------------------
  5727. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5728. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5729. {
  5730. WinConfiguration->LastWorkspace = Name;
  5731. if (!SavePasswords)
  5732. {
  5733. for (int Index = 0; Index < DataList->Count; Index++)
  5734. {
  5735. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5736. if (SessionData->Link.IsEmpty())
  5737. {
  5738. SessionData->ClearSessionPasswords();
  5739. }
  5740. }
  5741. }
  5742. StoredSessions->NewWorkspace(Name, DataList);
  5743. // modified only
  5744. StoredSessions->Save(false, Explicit);
  5745. }
  5746. //---------------------------------------------------------------------------
  5747. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5748. {
  5749. return
  5750. DefaultStr(WinConfiguration->LastWorkspace,
  5751. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5752. }
  5753. //---------------------------------------------------------------------------
  5754. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5755. {
  5756. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5757. bool AnyNonStoredSessionWithPassword = false;
  5758. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5759. bool AllNonStoredSessionsAnonymous = true;
  5760. TTerminalManager * Manager = TTerminalManager::Instance();
  5761. for (int Index = 0; Index < DataList->Count; Index++)
  5762. {
  5763. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5764. if (SessionData->Link.IsEmpty())
  5765. {
  5766. if (SessionData->HasAnySessionPassword())
  5767. {
  5768. AnyNonStoredSessionWithPassword = true;
  5769. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5770. {
  5771. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5772. }
  5773. }
  5774. if (!SameText(SessionData->UserName, AnonymousUserName))
  5775. {
  5776. AllNonStoredSessionsAnonymous = false;
  5777. }
  5778. }
  5779. }
  5780. bool SavePasswords;
  5781. bool * PSavePasswords;
  5782. bool NotRecommendedSavingPasswords =
  5783. !CustomWinConfiguration->UseMasterPassword &&
  5784. !AllNonStoredSessionsAnonymous;
  5785. if (Configuration->DisablePasswordStoring ||
  5786. !AnyNonStoredSessionWithPassword)
  5787. {
  5788. PSavePasswords = NULL;
  5789. SavePasswords = false;
  5790. }
  5791. else
  5792. {
  5793. PSavePasswords = &SavePasswords;
  5794. SavePasswords =
  5795. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5796. !NotRecommendedSavingPasswords;
  5797. }
  5798. UnicodeString Name = WorkspaceName();
  5799. bool CreateShortcut = false;
  5800. bool Result =
  5801. DoSaveWorkspaceDialog(
  5802. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5803. EnableAutoSave);
  5804. if (Result)
  5805. {
  5806. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5807. if (CreateShortcut)
  5808. {
  5809. TOperationVisualizer Visualizer;
  5810. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5811. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5812. }
  5813. if (EnableAutoSave)
  5814. {
  5815. WinConfiguration->AutoSaveWorkspace = true;
  5816. WinConfiguration->AutoWorkspace = Name;
  5817. if (PSavePasswords != NULL)
  5818. {
  5819. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5820. }
  5821. }
  5822. }
  5823. return Result;
  5824. }
  5825. //---------------------------------------------------------------------------
  5826. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5827. {
  5828. DebugAssert(!IsLocalBrowserMode());
  5829. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5830. if (WinConfiguration->PreservePanelState)
  5831. {
  5832. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5833. }
  5834. UpdateSessionData(Terminal->StateData);
  5835. }
  5836. //---------------------------------------------------------------------------
  5837. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5838. {
  5839. // Keep in sync with TSessionData::CopyStateData
  5840. DebugAssert(!IsLocalBrowserMode());
  5841. DebugAssert(Data != NULL);
  5842. // This is inconsistent with how color (for example) is handled.
  5843. Data->Name = Terminal->SessionData->Name;
  5844. // cannot use RemoteDirView->Path, because it is empty if connection
  5845. // was already closed
  5846. // also only peek, we may not be connected at all atm
  5847. // so make sure we do not try retrieving current directory from the server
  5848. // (particularly with FTP)
  5849. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5850. if (!ACurrentDirectory.IsEmpty())
  5851. {
  5852. Data->RemoteDirectory = ACurrentDirectory;
  5853. }
  5854. Data->Color = SessionColor;
  5855. }
  5856. //---------------------------------------------------------------------------
  5857. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5858. {
  5859. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5860. DebugAssert(Toolbar != NULL);
  5861. for (int i = 0; i < Toolbar->Items->Count; i++)
  5862. {
  5863. TTBXCustomDropDownItem * DropDownItem;
  5864. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5865. if (DropDownItem != NULL)
  5866. {
  5867. ToolbarItemResize(DropDownItem,
  5868. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5869. Toolbar->NonClientWidth);
  5870. break;
  5871. }
  5872. }
  5873. }
  5874. //---------------------------------------------------------------------------
  5875. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5876. {
  5877. Item->EditWidth = Width;
  5878. }
  5879. //---------------------------------------------------------------------------
  5880. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5881. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5882. {
  5883. for (int i = 0; i < Toolbar->Items->Count; i++)
  5884. {
  5885. TTBXCustomDropDownItem * DropDownItem;
  5886. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5887. if (DropDownItem != NULL)
  5888. {
  5889. ASize.x -= DropDownItem->EditWidth;
  5890. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5891. }
  5892. }
  5893. }
  5894. //---------------------------------------------------------------------------
  5895. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5896. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5897. {
  5898. if (WinConfiguration->DDWarnLackOfTempSpace)
  5899. {
  5900. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5901. if (!ADrive.IsEmpty())
  5902. {
  5903. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5904. DebugAssert(RequiredSpace >= 0);
  5905. __int64 RequiredWithReserve;
  5906. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5907. if (FreeSpace < RequiredWithReserve)
  5908. {
  5909. unsigned int Result;
  5910. TMessageParams Params(mpNeverAskAgainCheck);
  5911. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5912. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5913. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5914. if (Result == qaNeverAskAgain)
  5915. {
  5916. WinConfiguration->DDWarnLackOfTempSpace = false;
  5917. }
  5918. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5919. }
  5920. }
  5921. }
  5922. }
  5923. //---------------------------------------------------------------------------
  5924. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5925. {
  5926. DoOpenDirectoryDialog(odAddBookmark, Side);
  5927. }
  5928. //---------------------------------------------------------------------------
  5929. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5930. {
  5931. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5932. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5933. try
  5934. {
  5935. TCustomDirView * DView = DirView(Side);
  5936. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5937. {
  5938. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5939. }
  5940. }
  5941. catch (...)
  5942. {
  5943. delete VisitedDirectories;
  5944. throw;
  5945. }
  5946. return VisitedDirectories;
  5947. }
  5948. //---------------------------------------------------------------------------
  5949. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5950. TOpenDirectoryMode Mode, TOperationSide Side)
  5951. {
  5952. bool Continue = true;
  5953. if (Mode == odAddBookmark)
  5954. {
  5955. TMessageParams Params(mpNeverAskAgainCheck);
  5956. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5957. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5958. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5959. unsigned int Answer =
  5960. MessageDialog(Message,
  5961. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5962. if (Answer == qaNeverAskAgain)
  5963. {
  5964. Continue = true;
  5965. WinConfiguration->UseSharedBookmarks = true;
  5966. }
  5967. else if (Answer == qaOK)
  5968. {
  5969. Continue = true;
  5970. WinConfiguration->UseSharedBookmarks = false;
  5971. }
  5972. else
  5973. {
  5974. Continue = false;
  5975. }
  5976. }
  5977. if (Continue)
  5978. {
  5979. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5980. try
  5981. {
  5982. UnicodeString Name = DirView(Side)->PathName;
  5983. bool Repeat;
  5984. do
  5985. {
  5986. Repeat = false;
  5987. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  5988. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  5989. // do not allow switching to location profiles,
  5990. // if we are not connected
  5991. HasDirView[osLocal] && (Terminal != NULL)))
  5992. {
  5993. TWindowLock Lock(this);
  5994. if (!TryOpenDirectory(Side, Name))
  5995. {
  5996. Repeat = true;
  5997. Mode = odBrowse;
  5998. }
  5999. }
  6000. }
  6001. while (Repeat);
  6002. }
  6003. __finally
  6004. {
  6005. delete VisitedDirectories;
  6006. }
  6007. }
  6008. }
  6009. //---------------------------------------------------------------------------
  6010. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  6011. {
  6012. DebugAssert(!FTerminal->CommandSessionOpened);
  6013. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  6014. }
  6015. //---------------------------------------------------------------------------
  6016. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  6017. {
  6018. bool Result = FTerminal->IsCapable[Capability] ||
  6019. FTerminal->CommandSessionOpened;
  6020. if (!Result)
  6021. {
  6022. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  6023. if (!GUIConfiguration->ConfirmCommandSession)
  6024. {
  6025. Result = true;
  6026. }
  6027. else
  6028. {
  6029. TMessageParams Params(mpNeverAskAgainCheck);
  6030. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6031. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6032. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6033. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6034. if (Answer == qaNeverAskAgain)
  6035. {
  6036. GUIConfiguration->ConfirmCommandSession = false;
  6037. Result = true;
  6038. }
  6039. else if (Answer == qaOK)
  6040. {
  6041. Result = true;
  6042. }
  6043. }
  6044. if (Result)
  6045. {
  6046. Result = CommandSessionFallback();
  6047. }
  6048. }
  6049. return Result;
  6050. }
  6051. //---------------------------------------------------------------------------
  6052. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6053. {
  6054. if (EnsureCommandSessionFallback(fcAnyCommand))
  6055. {
  6056. DoConsoleDialog(Terminal, Command);
  6057. }
  6058. }
  6059. //---------------------------------------------------------------------------
  6060. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6061. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6062. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6063. {
  6064. if (!IsSideLocalBrowser(osRemote) &&
  6065. IsFileControl(DropSourceControl, osRemote) &&
  6066. (FDDExtMapFile != NULL))
  6067. {
  6068. Accept = true;
  6069. }
  6070. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6071. DebugAssert(FDDTargetControl != NULL);
  6072. }
  6073. //---------------------------------------------------------------------------
  6074. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6075. _di_IDataObject DataObj, int KeyState,
  6076. const TPoint & Point, int & Effect, bool & Accept)
  6077. {
  6078. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6079. }
  6080. //---------------------------------------------------------------------------
  6081. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6082. _di_IDataObject DataObj, int KeyState,
  6083. const TPoint & Point, int & Effect, bool & Accept)
  6084. {
  6085. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6086. }
  6087. //---------------------------------------------------------------------------
  6088. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6089. TObject * Sender)
  6090. {
  6091. DebugUsedParam(Sender);
  6092. DebugAssert(FDDTargetControl == Sender);
  6093. FDDTargetControl = NULL;
  6094. }
  6095. //---------------------------------------------------------------------------
  6096. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6097. {
  6098. FileControlDDDragLeave(SessionsPageControl);
  6099. }
  6100. //---------------------------------------------------------------------------
  6101. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6102. {
  6103. FileControlDDDragLeave(QueueView3);
  6104. }
  6105. //---------------------------------------------------------------------------
  6106. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6107. {
  6108. DebugAssert(!IsSideLocalBrowser(Side));
  6109. DebugUsedParam(Side);
  6110. bool Edit = false;
  6111. TRemoteFile * File = NULL;
  6112. UnicodeString FileName;
  6113. UnicodeString PointTo;
  6114. bool SymbolicLink = true;
  6115. if (RemoteDirView->ItemFocused)
  6116. {
  6117. DebugAssert(RemoteDirView->ItemFocused->Data);
  6118. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6119. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6120. if (Edit)
  6121. {
  6122. FileName = File->FileName;
  6123. PointTo = File->LinkTo;
  6124. }
  6125. else
  6126. {
  6127. PointTo = File->FileName;
  6128. }
  6129. }
  6130. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6131. Terminal->IsCapable[fcHardLink]))
  6132. {
  6133. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6134. if (Edit)
  6135. {
  6136. DebugAssert(File->FileName == FileName);
  6137. int Params = dfNoRecursive;
  6138. Terminal->ExceptionOnFail = true;
  6139. try
  6140. {
  6141. Terminal->DeleteFile(L"", File, &Params);
  6142. }
  6143. __finally
  6144. {
  6145. Terminal->ExceptionOnFail = false;
  6146. }
  6147. }
  6148. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6149. }
  6150. }
  6151. //---------------------------------------------------------------------------
  6152. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6153. {
  6154. return
  6155. (IsSideLocalBrowser(Side) ||
  6156. (HasActiveTerminal() &&
  6157. Terminal->ResolvingSymlinks &&
  6158. Terminal->IsCapable[fcSymbolicLink]));
  6159. }
  6160. //---------------------------------------------------------------------------
  6161. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6162. {
  6163. return
  6164. !IsSideLocalBrowser(FCurrentSide) &&
  6165. (RemoteDirView->ItemFocused != NULL) &&
  6166. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6167. Terminal->SessionData->ResolveSymlinks;
  6168. }
  6169. //---------------------------------------------------------------------------
  6170. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6171. {
  6172. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6173. FForceExecution = true;
  6174. try
  6175. {
  6176. DirView(osCurrent)->ExecuteCurrentFile();
  6177. }
  6178. __finally
  6179. {
  6180. FForceExecution = false;
  6181. }
  6182. }
  6183. //---------------------------------------------------------------------------
  6184. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6185. {
  6186. TEditorData ExternalEditor;
  6187. ExternalEditor.Editor = edExternal;
  6188. bool Remember = false;
  6189. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6190. {
  6191. if (Remember)
  6192. {
  6193. TEditorList * EditorList = new TEditorList;
  6194. try
  6195. {
  6196. *EditorList = *WinConfiguration->EditorList;
  6197. bool Found = false;
  6198. int i = 0;
  6199. while (!Found && (i < EditorList->Count))
  6200. {
  6201. const TEditorPreferences * Editor = EditorList->Editors[i];
  6202. if ((Editor->Data->Editor == edExternal) &&
  6203. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6204. {
  6205. Found = true;
  6206. }
  6207. i++;
  6208. }
  6209. if (!Found)
  6210. {
  6211. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6212. WinConfiguration->EditorList = EditorList;
  6213. }
  6214. }
  6215. __finally
  6216. {
  6217. delete EditorList;
  6218. }
  6219. }
  6220. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6221. }
  6222. }
  6223. //---------------------------------------------------------------------------
  6224. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6225. {
  6226. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6227. if (FFileFindTerminal == ATerminal)
  6228. {
  6229. FFileFindTerminal = NULL;
  6230. HideFileFindDialog();
  6231. }
  6232. if (FClipboardTerminal == ATerminal)
  6233. {
  6234. ClipboardClear(); // implies ClipboardStop
  6235. }
  6236. }
  6237. //---------------------------------------------------------------------------
  6238. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6239. {
  6240. DetachTerminal(Sender);
  6241. }
  6242. //---------------------------------------------------------------------------
  6243. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6244. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6245. {
  6246. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6247. DebugAssert(Terminal != NULL);
  6248. if (Data->Terminal == Terminal)
  6249. {
  6250. Data->Terminal = NULL;
  6251. }
  6252. }
  6253. //---------------------------------------------------------------------------
  6254. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6255. {
  6256. UpdateControls();
  6257. SessionColor = TColor(0);
  6258. UpdateRemotePathComboBox(false);
  6259. NeedSession(false);
  6260. }
  6261. //---------------------------------------------------------------------------
  6262. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6263. {
  6264. try
  6265. {
  6266. // Cache, as the login dialog can change its value.
  6267. // See also DoShow.
  6268. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6269. try
  6270. {
  6271. if (ShowLogin)
  6272. {
  6273. bool ReloadSessions = !Startup;
  6274. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  6275. }
  6276. }
  6277. __finally
  6278. {
  6279. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6280. // (so there was no chance for the user to open any session yet)
  6281. if ((ShowLogin || !Startup) &&
  6282. !WinConfiguration->KeepOpenWhenNoSession &&
  6283. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6284. {
  6285. TerminateApplication();
  6286. }
  6287. }
  6288. }
  6289. catch (EAbort &)
  6290. {
  6291. // swallow
  6292. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6293. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6294. }
  6295. }
  6296. //---------------------------------------------------------------------------
  6297. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6298. {
  6299. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6300. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6301. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6302. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6303. try
  6304. {
  6305. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6306. // Clear the design time unthemed tab
  6307. ((SessionsPageControl->PageCount > 0) &&
  6308. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6309. {
  6310. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6311. }
  6312. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6313. {
  6314. TThemeTabSheet * TabSheet;
  6315. if (Index >= SessionsPageControl->PageCount)
  6316. {
  6317. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6318. TabSheet->PageControl = SessionsPageControl;
  6319. }
  6320. else
  6321. {
  6322. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6323. }
  6324. bool IsSessionTab = (Index < TerminalList->Count);
  6325. if (IsSessionTab)
  6326. {
  6327. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6328. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6329. UpdateSessionTab(TabSheet);
  6330. }
  6331. else
  6332. {
  6333. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6334. TabSheet->Tag = 0; // not really needed
  6335. TabSheet->Shadowed = false;
  6336. // 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)
  6337. UpdateNewSessionTab();
  6338. }
  6339. TabSheet->ShowCloseButton = IsSessionTab;
  6340. }
  6341. }
  6342. __finally
  6343. {
  6344. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6345. }
  6346. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6347. }
  6348. //---------------------------------------------------------------------------
  6349. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6350. {
  6351. DoTerminalListChanged();
  6352. }
  6353. //---------------------------------------------------------------------------
  6354. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6355. {
  6356. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6357. DebugAssert(TabSheet->ImageIndex == 0);
  6358. TabSheet->Caption =
  6359. WinConfiguration->SelectiveToolbarText ?
  6360. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6361. UnicodeString();
  6362. }
  6363. //---------------------------------------------------------------------------
  6364. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6365. {
  6366. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6367. }
  6368. //---------------------------------------------------------------------------
  6369. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6370. {
  6371. if (DebugAlwaysTrue(TabSheet != NULL))
  6372. {
  6373. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6374. if (DebugAlwaysTrue(ATerminal != NULL))
  6375. {
  6376. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6377. TabSheet->ImageIndex = AddSessionColor(Color);
  6378. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6379. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6380. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6381. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6382. {
  6383. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6384. }
  6385. }
  6386. }
  6387. }
  6388. //---------------------------------------------------------------------------
  6389. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6390. {
  6391. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6392. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6393. bool Result = (Terminal != NULL);
  6394. if (Result)
  6395. {
  6396. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6397. }
  6398. else
  6399. {
  6400. try
  6401. {
  6402. NewSession(false);
  6403. }
  6404. __finally
  6405. {
  6406. DoTerminalListChanged();
  6407. }
  6408. FSessionsPageControlNewSessionTime = Now();
  6409. }
  6410. return Result;
  6411. }
  6412. //---------------------------------------------------------------------------
  6413. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6414. {
  6415. SessionTabSwitched();
  6416. }
  6417. //---------------------------------------------------------------------------
  6418. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6419. {
  6420. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6421. DebugAssert(TransferList != NULL);
  6422. UnicodeString Name;
  6423. if (TransferList->ItemIndex <= 0)
  6424. {
  6425. Name = L"";
  6426. }
  6427. else
  6428. {
  6429. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6430. }
  6431. if (FCopyParamAutoSelected.IsEmpty())
  6432. {
  6433. // if previous preset was not autoselected, make new preset the "default"
  6434. FCopyParamDefault = Name;
  6435. }
  6436. GUIConfiguration->CopyParamCurrent = Name;
  6437. }
  6438. //---------------------------------------------------------------------------
  6439. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6440. {
  6441. // sanity check
  6442. bool ExistingPreset =
  6443. (FTransferListHoverIndex >= 0) &&
  6444. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6445. DebugAssert(ExistingPreset);
  6446. if (ExistingPreset)
  6447. {
  6448. HDC DC = GetDC(0);
  6449. TCanvas * Canvas = new TCanvas();
  6450. try
  6451. {
  6452. Canvas->Handle = DC;
  6453. Canvas->Font = GetToolbarFont(this);
  6454. UnicodeString Name;
  6455. if (FTransferListHoverIndex == 0)
  6456. {
  6457. Name = L"";
  6458. }
  6459. else
  6460. {
  6461. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6462. }
  6463. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6464. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6465. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6466. static_cast<TObject*>(GetComponent(fcTransferList)));
  6467. UnicodeString InfoStr =
  6468. GUIConfiguration->CopyParamPreset[Name].
  6469. GetInfoStr(L"; ",
  6470. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6471. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6472. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6473. {
  6474. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6475. {
  6476. InfoStr.SetLength(InfoStr.Length() - 1);
  6477. }
  6478. InfoStr += Ellipsis;
  6479. }
  6480. // UpdateCaption does not cause invalidation of whole submenu, while
  6481. // setting Caption property does.
  6482. // also it probably does not resize the label, even if necessary
  6483. // (we do not want that anyway)
  6484. TransferLabel->UpdateCaption(InfoStr);
  6485. }
  6486. __finally
  6487. {
  6488. Canvas->Handle = NULL;
  6489. ReleaseDC(0, DC);
  6490. delete Canvas;
  6491. }
  6492. }
  6493. }
  6494. //---------------------------------------------------------------------------
  6495. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6496. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6497. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6498. {
  6499. if (FTransferListHoverIndex != AHoverIndex)
  6500. {
  6501. FTransferListHoverIndex = AHoverIndex;
  6502. UpdateTransferLabel();
  6503. }
  6504. }
  6505. //---------------------------------------------------------------------------
  6506. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6507. {
  6508. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6509. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6510. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6511. {
  6512. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6513. {
  6514. if (!NonVisualDataModule->Busy)
  6515. {
  6516. OpenDirectory(GetSide(osCurrent));
  6517. }
  6518. Message.Result = 1;
  6519. }
  6520. else
  6521. {
  6522. TForm::Dispatch(&Message);
  6523. }
  6524. }
  6525. else
  6526. {
  6527. TForm::Dispatch(&Message);
  6528. }
  6529. }
  6530. //---------------------------------------------------------------------------
  6531. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6532. {
  6533. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6534. if ((FIgnoreNextDialogChar != 0) &&
  6535. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6536. {
  6537. Message.Result = 1;
  6538. }
  6539. else
  6540. {
  6541. TForm::Dispatch(&Message);
  6542. }
  6543. FIgnoreNextDialogChar = 0;
  6544. }
  6545. //---------------------------------------------------------------------------
  6546. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6547. {
  6548. // The four low-order bits are used internally by Windows
  6549. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6550. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6551. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6552. // 61730 - restore thru double click - undocumented
  6553. // 61490 - maximize thru double click - undocumented
  6554. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6555. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6556. {
  6557. SysResizing(Cmd);
  6558. }
  6559. TForm::Dispatch(&Message);
  6560. }
  6561. //---------------------------------------------------------------------------
  6562. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6563. {
  6564. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6565. // Also there no point returning TRUE as we are not able to
  6566. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6567. // Hence the process termination might be safer :)
  6568. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6569. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6570. {
  6571. Message.Result = FALSE;
  6572. }
  6573. else
  6574. {
  6575. Message.Result = TRUE;
  6576. }
  6577. // Do not call default handling as that triggers OnCloseQuery,
  6578. // where our implementation will popup confirmation dialogs, what we do not want,
  6579. // as per Vista guidelines:
  6580. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6581. }
  6582. //---------------------------------------------------------------------------
  6583. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6584. {
  6585. if (Message.EndSession && IsApplicationMinimized())
  6586. {
  6587. // WORKAROUND
  6588. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6589. // when it receives WM_ENDSESSION,
  6590. // but that sometimes (particularly when application is minimized) cause crashes.
  6591. // Crash popups message that blocks log off.
  6592. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6593. // so we call ExitProcess() immediately, not even trying to cleanup.
  6594. // It still causes beep, so there's likely some popup, but it does not block
  6595. // log off.
  6596. ExitProcess(0);
  6597. }
  6598. TForm::Dispatch(&Message);
  6599. }
  6600. #ifdef _DEBUG
  6601. //---------------------------------------------------------------------------
  6602. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6603. {
  6604. TForm::Dispatch(&Message);
  6605. }
  6606. #endif
  6607. //---------------------------------------------------------------------------
  6608. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6609. {
  6610. }
  6611. //---------------------------------------------------------------------------
  6612. void __fastcall TCustomScpExplorerForm::DoShow()
  6613. {
  6614. // only now are the controls resized finally, so the size constraints
  6615. // will not conflict with possibly very small window size
  6616. RestoreFormParams();
  6617. // This indicates that the form was rescaled after parameters were loaded and
  6618. // as most probably the parameters were actually saved with the current form scaling
  6619. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6620. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6621. // and no rounding problems will occur.
  6622. // See also RestoreForm.
  6623. // (we should be safe to call RestoreParams unconditionally)
  6624. if (PixelsPerInch != Screen->PixelsPerInch)
  6625. {
  6626. RestoreParams();
  6627. }
  6628. FixControlsPlacement();
  6629. if (Position == poDefaultPosOnly)
  6630. {
  6631. CutFormToDesktop(this);
  6632. }
  6633. TForm::DoShow();
  6634. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6635. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6636. // This was previously in NeedSession, where other related code is.
  6637. // But that is called form CMShowingChanged, when the window is already visible and the local-local window state
  6638. // unpleasanly shows briefly.
  6639. if (!WinConfiguration->ShowLoginWhenNoSession &&
  6640. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6641. // This detects if workspace was saved the last time the main widow was closed
  6642. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6643. {
  6644. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6645. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6646. }
  6647. if (Terminal == NULL)
  6648. {
  6649. StartingDisconnected();
  6650. }
  6651. UpdatePixelsPerInchMainWindowCounter();
  6652. FShowing = true;
  6653. }
  6654. //---------------------------------------------------------------------------
  6655. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6656. {
  6657. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6658. }
  6659. //---------------------------------------------------------------------------
  6660. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6661. {
  6662. DoTerminalListChanged();
  6663. InitStatusBar();
  6664. UpdateControls();
  6665. }
  6666. //---------------------------------------------------------------------------
  6667. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6668. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6669. TNotifyEvent OnBalloonClick, TObject * UserData)
  6670. {
  6671. bool Do;
  6672. UnicodeString Message;
  6673. if (E == NULL)
  6674. {
  6675. Message = Str;
  6676. Do = true;
  6677. }
  6678. else
  6679. {
  6680. Do = ExceptionMessage(E, Message);
  6681. }
  6682. if (Do && WinConfiguration->BalloonNotifications)
  6683. {
  6684. UnicodeString Title;
  6685. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6686. {
  6687. Message = TrimLeft(Message);
  6688. }
  6689. else
  6690. {
  6691. Message = UnformatMessage(Message);
  6692. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6693. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6694. Title = LoadResourceString(Captions[Type]);
  6695. if (Terminal != NULL)
  6696. {
  6697. Title = FORMAT(L"%s - %s",
  6698. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6699. }
  6700. }
  6701. if (Seconds == 0)
  6702. {
  6703. Seconds = WinConfiguration->NotificationsTimeout;
  6704. }
  6705. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6706. }
  6707. }
  6708. //---------------------------------------------------------------------------
  6709. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6710. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6711. UnicodeString HelpKeyword, const TMessageParams * Params,
  6712. TTerminal * Terminal)
  6713. {
  6714. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6715. (FOnFeedSynchronizeError != NULL)) &&
  6716. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6717. {
  6718. if (FOnFeedSynchronizeError != NULL)
  6719. {
  6720. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6721. }
  6722. else
  6723. {
  6724. DebugAssert(FErrorList != NULL);
  6725. TStringList * MoreMessagesCopy = NULL;
  6726. if (MoreMessages)
  6727. {
  6728. MoreMessagesCopy = new TStringList();
  6729. MoreMessagesCopy->Assign(MoreMessages);
  6730. }
  6731. FErrorList->AddObject(Message, MoreMessagesCopy);
  6732. }
  6733. PopupTrayBalloon(Terminal, Message, Type);
  6734. return ContinueAnswer(Answers);
  6735. }
  6736. else
  6737. {
  6738. bool UseBalloon = FTrayIcon->Visible;
  6739. if (UseBalloon)
  6740. {
  6741. PopupTrayBalloon(Terminal, Message, Type);
  6742. }
  6743. unsigned int Result;
  6744. try
  6745. {
  6746. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6747. }
  6748. __finally
  6749. {
  6750. // cancel only balloon we popped up, otherwise we may cancel notification
  6751. // balloon that was there before the message dialog
  6752. // (such as "dd confirmation opt in balloon)
  6753. if (UseBalloon)
  6754. {
  6755. FTrayIcon->CancelBalloon();
  6756. }
  6757. }
  6758. return Result;
  6759. }
  6760. }
  6761. //---------------------------------------------------------------------------
  6762. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6763. TTerminal * Terminal, Exception * E)
  6764. {
  6765. if (FTrayIcon->Visible)
  6766. {
  6767. PopupTrayBalloon(Terminal, L"", qtError, E);
  6768. }
  6769. // particularly prevent opening new session from jump list,
  6770. // while exception is shown
  6771. NonVisualDataModule->StartBusy();
  6772. try
  6773. {
  6774. ShowExtendedExceptionEx(Terminal, E);
  6775. }
  6776. __finally
  6777. {
  6778. NonVisualDataModule->EndBusy();
  6779. FTrayIcon->CancelBalloon();
  6780. }
  6781. }
  6782. //---------------------------------------------------------------------------
  6783. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6784. {
  6785. if (Terminal->Active)
  6786. {
  6787. InitStatusBar();
  6788. }
  6789. // cannot rely on active page being page for active terminal,
  6790. // as it can happen that active page is the "new session" page
  6791. // (e.g. when reconnecting active terminal, while login dialog
  6792. // invoked from "new session" page is modal)
  6793. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6794. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6795. }
  6796. //---------------------------------------------------------------------------
  6797. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6798. TTerminal * Terminal, Exception * E)
  6799. {
  6800. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6801. if (!Terminal->Active)
  6802. {
  6803. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6804. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6805. {
  6806. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6807. }
  6808. }
  6809. }
  6810. //---------------------------------------------------------------------------
  6811. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6812. UnicodeString Message, TQueryType Type,
  6813. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6814. {
  6815. if ((E == NULL) ||
  6816. ExceptionMessage(E, Message))
  6817. {
  6818. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6819. if (Important)
  6820. {
  6821. Seconds *= 5;
  6822. }
  6823. UnicodeString NoteMessage(UnformatMessage(Message));
  6824. if (Terminal != NULL)
  6825. {
  6826. NoteMessage = FORMAT(L"%s: %s",
  6827. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6828. }
  6829. if (WinConfiguration->BalloonNotifications)
  6830. {
  6831. AddNote(NoteMessage);
  6832. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6833. }
  6834. else
  6835. {
  6836. FlashOnBackground();
  6837. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6838. }
  6839. }
  6840. }
  6841. //---------------------------------------------------------------------------
  6842. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6843. {
  6844. RestoreApp();
  6845. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6846. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6847. !NonVisualDataModule->Busy)
  6848. {
  6849. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6850. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6851. if (!ComponentVisible[fcQueueView])
  6852. {
  6853. ToggleQueueVisibility();
  6854. GoToQueue();
  6855. }
  6856. }
  6857. }
  6858. //---------------------------------------------------------------------------
  6859. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6860. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6861. {
  6862. UnicodeString Message;
  6863. TNotifyEvent OnClick = NULL;
  6864. TObject * UserData = NULL;
  6865. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6866. switch (Event)
  6867. {
  6868. case qeEmptyButMonitored:
  6869. if ((ATerminal != Terminal) || QueueInvisible)
  6870. {
  6871. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6872. OnClick = QueueEmptyNoteClicked;
  6873. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6874. TerminalNoteData->Terminal = ATerminal;
  6875. UserData = TerminalNoteData;
  6876. }
  6877. break;
  6878. case qeEmpty:
  6879. OperationComplete(ATerminal->QueueOperationStart);
  6880. break;
  6881. case qePendingUserAction:
  6882. if ((ATerminal != Terminal) ||
  6883. (QueueInvisible && !IsQueueAutoPopup()))
  6884. {
  6885. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6886. }
  6887. break;
  6888. default:
  6889. DebugFail();
  6890. }
  6891. if (!Message.IsEmpty())
  6892. {
  6893. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6894. }
  6895. }
  6896. //---------------------------------------------------------------------------
  6897. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6898. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6899. {
  6900. if (FDDExtMapFile != NULL)
  6901. {
  6902. CloseHandle(FDDExtMapFile);
  6903. FDDExtMapFile = NULL;
  6904. }
  6905. if (WinConfiguration->DDFakeFile)
  6906. {
  6907. DDFakeFileInitDrag(FileList, Created);
  6908. }
  6909. }
  6910. //---------------------------------------------------------------------------
  6911. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6912. {
  6913. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6914. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6915. {
  6916. FFakeFileDropTarget = FileName;
  6917. }
  6918. }
  6919. //---------------------------------------------------------------------------
  6920. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6921. {
  6922. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6923. if (!ForceDirectories(ApiPath(Result)))
  6924. {
  6925. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6926. }
  6927. FileSetAttr(ApiPath(Result), faHidden);
  6928. return Result;
  6929. }
  6930. //---------------------------------------------------------------------------
  6931. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6932. bool & Created)
  6933. {
  6934. FFakeFileDropTarget = UnicodeString();
  6935. FDragFakeDirectory = CreateFakeTransferDirectory();
  6936. FileList->AddItem(NULL, FDragFakeDirectory);
  6937. Created = true;
  6938. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6939. {
  6940. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6941. }
  6942. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6943. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6944. {
  6945. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6946. TDragExtCommStruct* CommStruct;
  6947. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6948. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6949. DebugAssert(CommStruct != NULL);
  6950. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6951. CommStruct->Dragging = true;
  6952. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6953. LENOF(CommStruct->DropDest));
  6954. NULL_TERMINATE(CommStruct->DropDest);
  6955. UnmapViewOfFile(CommStruct);
  6956. }
  6957. }
  6958. //---------------------------------------------------------------------------
  6959. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6960. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6961. {
  6962. bool Result;
  6963. DebugAssert(!IsLocalBrowserMode());
  6964. if (Sender == RemoteDirView)
  6965. {
  6966. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6967. }
  6968. else
  6969. {
  6970. DebugAssert(Sender == RemoteDriveView);
  6971. TStrings * FileList = RemoteDriveView->DragFileList();
  6972. try
  6973. {
  6974. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6975. }
  6976. __finally
  6977. {
  6978. delete FileList;
  6979. }
  6980. }
  6981. if (FDDTargetControl == RemoteDriveView)
  6982. {
  6983. RemoteDriveView->UpdateDropTarget();
  6984. }
  6985. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6986. // or from tree view to dir view.
  6987. // foMove happens when file/dir is dragged from remote tree view outside of
  6988. // application via dragex
  6989. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6990. (DropSourceControl == RemoteDriveView))
  6991. {
  6992. RemoteDriveView->UpdateDropSource();
  6993. }
  6994. return Result;
  6995. }
  6996. //---------------------------------------------------------------------------
  6997. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6998. {
  6999. DebugAssert(!IsLocalBrowserMode());
  7000. // This also handles drops of remote files to queue.
  7001. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  7002. SAFE_DESTROY(FDDFileList);
  7003. if (!FFakeFileDropTarget.IsEmpty())
  7004. {
  7005. RemoveDir(ApiPath(FFakeFileDropTarget));
  7006. }
  7007. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  7008. {
  7009. try
  7010. {
  7011. TDragResult DDResult = (Sender == RemoteDirView) ?
  7012. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  7013. // Focus is moved to the target application,
  7014. // but as we are going to present the UI, we need to steal the focus back.
  7015. // This most likely won't work though (windows does not allow application
  7016. // to steal focus most of the time)
  7017. Application->BringToFront();
  7018. // On older version of Windows we never got drMove here, see also comment below.
  7019. // On Windows 10, we get the "move".
  7020. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  7021. {
  7022. UnicodeString TargetDirectory;
  7023. TFileOperation Operation;
  7024. // drInvalid may mean drMove, see comment below
  7025. switch (DDResult)
  7026. {
  7027. case drCopy:
  7028. Operation = foCopy;
  7029. break;
  7030. case drMove:
  7031. Operation = foMove;
  7032. break;
  7033. default:
  7034. DebugFail();
  7035. case drInvalid:
  7036. // prefer "copy" for safety
  7037. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7038. break;
  7039. }
  7040. TTransferOperationParam Param;
  7041. UnicodeString CounterName;
  7042. bool ForceQueue;
  7043. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7044. {
  7045. // we get drInvalid both if d&d was intercepted by ddext,
  7046. // and when users drops on no-drop location.
  7047. // we tell the difference by existence of response from ddext,
  7048. // so we ignore absence of response in this case
  7049. if (DDResult != drInvalid)
  7050. {
  7051. // here we know that the extension is installed,
  7052. // as it is checked as soon as drag&drop starts from
  7053. // RemoteFileControlDDCreateDragFileList
  7054. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7055. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7056. {
  7057. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7058. }
  7059. else
  7060. {
  7061. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7062. }
  7063. }
  7064. }
  7065. else
  7066. {
  7067. // download using fake file
  7068. Param.Temp = false;
  7069. Param.DragDrop = true;
  7070. if (ForceQueue)
  7071. {
  7072. Param.Queue = asOn;
  7073. }
  7074. if (Sender == RemoteDirView)
  7075. {
  7076. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7077. }
  7078. if (RemoteFileControlFileOperation(Sender, Operation,
  7079. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7080. {
  7081. Configuration->Usage->Inc(CounterName);
  7082. }
  7083. }
  7084. }
  7085. }
  7086. __finally
  7087. {
  7088. CloseHandle(FDDExtMapFile);
  7089. FDDExtMapFile = NULL;
  7090. delete FDragFakeMonitors;
  7091. FDragFakeMonitors = NULL;
  7092. RemoveDir(ApiPath(FDragFakeDirectory));
  7093. FDragFakeDirectory = L"";
  7094. FFakeFileDropTarget = UnicodeString();
  7095. }
  7096. }
  7097. if (FDragDropSshTerminate.get() != NULL)
  7098. {
  7099. FDragDropSshTerminate->Rethrow();
  7100. }
  7101. }
  7102. //---------------------------------------------------------------------------
  7103. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7104. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7105. {
  7106. // Remember drop effect so we know (when user drops files), if we copy or move
  7107. FLastDropEffect = dwEffect;
  7108. }
  7109. //---------------------------------------------------------------------------
  7110. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7111. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7112. {
  7113. bool Result;
  7114. if (FDDTargetControl == QueueView3)
  7115. {
  7116. Directory = DefaultDownloadTargetDirectory();
  7117. Result = true;
  7118. CounterName = L"DownloadsDragDropQueue";
  7119. ForceQueue = true;
  7120. }
  7121. else if (!FFakeFileDropTarget.IsEmpty())
  7122. {
  7123. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7124. Result = true;
  7125. ForceQueue = false;
  7126. CounterName = L"DownloadsDragDropFakeFile";
  7127. }
  7128. else
  7129. {
  7130. ForceQueue = false;
  7131. Enabled = false;
  7132. try
  7133. {
  7134. int Timer = 0;
  7135. Result = false;
  7136. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7137. {
  7138. {
  7139. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7140. TDragExtCommStruct* CommStruct;
  7141. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7142. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7143. DebugAssert(CommStruct != NULL);
  7144. Result = !CommStruct->Dragging;
  7145. if (Result)
  7146. {
  7147. Directory = ExtractFilePath(CommStruct->DropDest);
  7148. CounterName = L"DownloadsDragDropExternalExt";
  7149. }
  7150. UnmapViewOfFile(CommStruct);
  7151. }
  7152. if (!Result)
  7153. {
  7154. Sleep(50);
  7155. Timer += 50;
  7156. Application->ProcessMessages();
  7157. }
  7158. }
  7159. }
  7160. __finally
  7161. {
  7162. Enabled = true;
  7163. }
  7164. }
  7165. return Result;
  7166. }
  7167. //---------------------------------------------------------------------------
  7168. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7169. const UnicodeString TempDir, int SecDelay)
  7170. {
  7171. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7172. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7173. if (FDelayedDeletionTimer == NULL)
  7174. {
  7175. DebugAssert(HandleAllocated());
  7176. FDelayedDeletionTimer = new TTimer(this);
  7177. FDelayedDeletionTimer->Interval = 10000;
  7178. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7179. }
  7180. else
  7181. {
  7182. FDelayedDeletionTimer->Enabled = true;
  7183. }
  7184. }
  7185. //---------------------------------------------------------------------------
  7186. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7187. {
  7188. DebugAssert(FDelayedDeletionList != NULL);
  7189. TDateTime N = Now();
  7190. TDateTime Alert;
  7191. UnicodeString Directory;
  7192. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7193. {
  7194. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7195. if ((N >= Alert) || (Sender == NULL))
  7196. {
  7197. Directory = FDelayedDeletionList->Strings[Index];
  7198. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7199. {
  7200. FDelayedDeletionList->Delete(Index);
  7201. }
  7202. }
  7203. }
  7204. if (FDelayedDeletionList->Count == 0)
  7205. {
  7206. FDelayedDeletionTimer->Enabled = false;
  7207. }
  7208. }
  7209. //---------------------------------------------------------------------------
  7210. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7211. {
  7212. DebugAssert(!IsLocalBrowserMode());
  7213. if (IsFileControl(FDDTargetControl, osRemote) ||
  7214. (FDDTargetControl == SessionsPageControl))
  7215. {
  7216. TTerminal * TargetTerminal = NULL;
  7217. TFileOperation Operation = foNone;
  7218. if (FDDTargetControl == SessionsPageControl)
  7219. {
  7220. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7221. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7222. // do not allow dropping on the "+" tab
  7223. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7224. if (TargetTerminal != NULL)
  7225. {
  7226. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7227. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7228. {
  7229. Operation = foRemoteMove;
  7230. }
  7231. else
  7232. {
  7233. Operation = foRemoteCopy;
  7234. }
  7235. }
  7236. }
  7237. else
  7238. {
  7239. if (FLastDropEffect == DROPEFFECT_MOVE)
  7240. {
  7241. Operation = foRemoteMove;
  7242. }
  7243. else if (FLastDropEffect == DROPEFFECT_COPY)
  7244. {
  7245. Operation = foRemoteCopy;
  7246. }
  7247. }
  7248. if (Operation != foNone)
  7249. {
  7250. RemoteFileControlFileOperation(DropSourceControl,
  7251. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7252. }
  7253. // abort drag&drop
  7254. Abort();
  7255. }
  7256. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7257. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7258. (FDDTargetControl != QueueView3))
  7259. {
  7260. DebugAssert(!FDragTempDir.IsEmpty());
  7261. TTransferType Type;
  7262. UnicodeString TempDir = FDragTempDir;
  7263. // We clear FDragTempDir before calling
  7264. // just in case it fail (raises exception)
  7265. FDragTempDir = L"";
  7266. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7267. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7268. // empty directory parameter means temp directory -> don't display it!
  7269. UnicodeString TargetDir = L"";
  7270. int Options = 0;
  7271. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7272. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7273. {
  7274. Abort();
  7275. }
  7276. // TargetDir is set when dropped on local file control
  7277. // (this was workaround for legacy dirview event handling, now it should be
  7278. // made prettier)
  7279. if (TargetDir.IsEmpty())
  7280. {
  7281. TargetDir = TempDir;
  7282. if (ForceDirectories(ApiPath(TargetDir)))
  7283. {
  7284. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7285. FPendingTempSpaceWarn = true;
  7286. try
  7287. {
  7288. FDragDropOperation = true;
  7289. int Params = cpTemporary |
  7290. (Type == ttMove ? cpDelete : 0);
  7291. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7292. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7293. }
  7294. __finally
  7295. {
  7296. FDragDropOperation = false;
  7297. FPendingTempSpaceWarn = false;
  7298. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7299. }
  7300. }
  7301. else
  7302. {
  7303. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7304. }
  7305. }
  7306. }
  7307. }
  7308. //---------------------------------------------------------------------------
  7309. void __fastcall TCustomScpExplorerForm::DDDownload(
  7310. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7311. {
  7312. DebugAssert(!IsLocalBrowserMode());
  7313. TAutoBatch AutoBatch(this);
  7314. UpdateCopyParamCounters(*CopyParam);
  7315. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7316. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7317. {
  7318. RemoteDriveView->UpdateDropSource();
  7319. }
  7320. }
  7321. //---------------------------------------------------------------------------
  7322. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7323. {
  7324. public:
  7325. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7326. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7327. {
  7328. }
  7329. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7330. {
  7331. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7332. TDataObjectFilesEx::AllowData(FormatEtc);
  7333. }
  7334. };
  7335. //---------------------------------------------------------------------------
  7336. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7337. TObject * Sender, TDataObject *& DataObject)
  7338. {
  7339. if (FDDExtMapFile != NULL)
  7340. {
  7341. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7342. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7343. {
  7344. Abort();
  7345. }
  7346. if (FileList->Count > 0)
  7347. {
  7348. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7349. if (!FilesObject->IsValid(true, true))
  7350. {
  7351. FilesObject->_Release();
  7352. }
  7353. else
  7354. {
  7355. DataObject = FilesObject;
  7356. }
  7357. }
  7358. }
  7359. }
  7360. //---------------------------------------------------------------------------
  7361. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7362. {
  7363. DebugFail();
  7364. }
  7365. //---------------------------------------------------------------------------
  7366. void __fastcall TCustomScpExplorerForm::GoToTree()
  7367. {
  7368. ComponentVisible[fcRemoteTree] = true;
  7369. DriveView(osRemote)->SetFocus();
  7370. }
  7371. //---------------------------------------------------------------------------
  7372. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7373. TPanelExport Export)
  7374. {
  7375. TCustomDirView * DirView = this->DirView(Side);
  7376. std::unique_ptr<TStrings> ExportData(new TStringList());
  7377. switch (Export)
  7378. {
  7379. case pePath:
  7380. ExportData->Add(DirView->PathName);
  7381. break;
  7382. case peFileList:
  7383. case peFullFileList:
  7384. {
  7385. bool FullPath = (Export == peFullFileList);
  7386. DirView->CreateFileList(false, FullPath, ExportData.get());
  7387. for (int Index = 0; Index < ExportData->Count; Index++)
  7388. {
  7389. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7390. {
  7391. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7392. }
  7393. }
  7394. }
  7395. break;
  7396. default:
  7397. DebugFail();
  7398. }
  7399. return ExportData.release();
  7400. }
  7401. //---------------------------------------------------------------------------
  7402. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7403. TPanelExport Export, TPanelExportDestination Destination)
  7404. {
  7405. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7406. PanelExportStore(Side, Export, Destination, ExportData.get());
  7407. }
  7408. //---------------------------------------------------------------------------
  7409. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7410. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7411. TStrings * ExportData)
  7412. {
  7413. if (Destination == pedClipboard)
  7414. {
  7415. TInstantOperationVisualizer Visualizer;
  7416. CopyToClipboard(ExportData);
  7417. }
  7418. else
  7419. {
  7420. DebugFail();
  7421. }
  7422. }
  7423. //---------------------------------------------------------------------------
  7424. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7425. {
  7426. TCustomDirView * DirView = this->DirView(Side);
  7427. UnicodeString Mask = DirView->Mask;
  7428. if (DoFilterMaskDialog(DirView, Mask))
  7429. {
  7430. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7431. Configuration->Usage->Inc(L"Filters");
  7432. }
  7433. }
  7434. //---------------------------------------------------------------------------
  7435. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7436. {
  7437. return FQueueController->DefaultOperation();
  7438. }
  7439. //---------------------------------------------------------------------------
  7440. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7441. TQueueOperation Operation, void ** Param)
  7442. {
  7443. switch (Operation)
  7444. {
  7445. case qoPreferences:
  7446. return true;
  7447. case qoGoTo:
  7448. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7449. case qoOnceEmpty:
  7450. return IsAnythingQueued();
  7451. default:
  7452. return FQueueController->AllowOperation(Operation, Param);
  7453. }
  7454. }
  7455. //---------------------------------------------------------------------------
  7456. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7457. {
  7458. if (DebugAlwaysTrue(QueueView3->Visible))
  7459. {
  7460. QueueView3->SetFocus();
  7461. }
  7462. }
  7463. //---------------------------------------------------------------------------
  7464. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7465. TQueueOperation Operation, void * Param)
  7466. {
  7467. if (Operation == qoGoTo)
  7468. {
  7469. GoToQueue();
  7470. }
  7471. else if (Operation == qoPreferences)
  7472. {
  7473. PreferencesDialog(pmQueue);
  7474. }
  7475. else
  7476. {
  7477. FQueueController->ExecuteOperation(Operation, Param);
  7478. }
  7479. }
  7480. //---------------------------------------------------------------------------
  7481. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7482. {
  7483. return (Queue != NULL) && Queue->Enabled;
  7484. }
  7485. //---------------------------------------------------------------------------
  7486. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7487. {
  7488. DebugAssert(Queue != NULL);
  7489. if (Queue != NULL)
  7490. {
  7491. Queue->Enabled = !Queue->Enabled;
  7492. }
  7493. }
  7494. //---------------------------------------------------------------------------
  7495. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7496. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7497. {
  7498. FQueueActedItem = QueueView3->ItemFocused;
  7499. }
  7500. //---------------------------------------------------------------------------
  7501. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7502. {
  7503. return TopDock->Height + QueueSplitter->Height;
  7504. }
  7505. //---------------------------------------------------------------------------
  7506. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7507. {
  7508. return
  7509. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7510. (QueueDock->Visible ? QueueDock->Height : 0) +
  7511. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7512. }
  7513. //---------------------------------------------------------------------------
  7514. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7515. {
  7516. return ScaleByTextHeight(this, 48);
  7517. }
  7518. //---------------------------------------------------------------------------
  7519. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7520. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7521. {
  7522. // when queue is hidden by double-clicking splitter, stray attempt to
  7523. // resize the panel with strange value arrives, make sure it is ignored
  7524. if (ComponentVisible[fcQueueView])
  7525. {
  7526. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7527. if (NewSize > MaxHeightLimit)
  7528. {
  7529. NewSize = MaxHeightLimit;
  7530. }
  7531. int MinHeightLimit =
  7532. GetStaticQueuePanelComponentsHeight() +
  7533. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7534. GetMinQueueViewHeight();
  7535. if (NewSize < MinHeightLimit)
  7536. {
  7537. NewSize = MinHeightLimit;
  7538. }
  7539. }
  7540. else
  7541. {
  7542. Accept = false;
  7543. }
  7544. }
  7545. //---------------------------------------------------------------------------
  7546. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7547. {
  7548. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7549. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7550. if (QueueViewHeight < GetMinQueueViewHeight())
  7551. {
  7552. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7553. }
  7554. }
  7555. //---------------------------------------------------------------------------
  7556. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7557. TDragObject *& /*DragObject*/)
  7558. {
  7559. FQueueActedItem = QueueView3->ItemFocused;
  7560. }
  7561. //---------------------------------------------------------------------------
  7562. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7563. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7564. {
  7565. Accept = true;
  7566. if (Source == QueueView3)
  7567. {
  7568. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7569. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7570. if (Accept)
  7571. {
  7572. TQueueItemProxy * QueueItem;
  7573. TQueueItemProxy * DestQueueItem;
  7574. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7575. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7576. Accept = (QueueItem != DestQueueItem) &&
  7577. (QueueItem->Status == TQueueItem::qsPending) &&
  7578. (DestQueueItem->Status == TQueueItem::qsPending);
  7579. }
  7580. }
  7581. }
  7582. //---------------------------------------------------------------------------
  7583. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7584. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7585. {
  7586. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7587. {
  7588. TQueueItemProxy * QueueItem;
  7589. TQueueItemProxy * DestQueueItem;
  7590. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7591. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7592. QueueItem->Move(DestQueueItem);
  7593. }
  7594. }
  7595. //---------------------------------------------------------------------------
  7596. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7597. {
  7598. if ((QueueView3->ItemFocused == NULL) &&
  7599. (QueueView3->Items->Count > 0))
  7600. {
  7601. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7602. }
  7603. QueueLabelUpdateStatus();
  7604. }
  7605. //---------------------------------------------------------------------------
  7606. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7607. {
  7608. QueueLabelUpdateStatus();
  7609. }
  7610. //---------------------------------------------------------------------------
  7611. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7612. {
  7613. QueueLabel->UpdateStatus();
  7614. }
  7615. //---------------------------------------------------------------------------
  7616. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7617. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7618. {
  7619. if (Selected)
  7620. {
  7621. NonVisualDataModule->UpdateNonVisibleActions();
  7622. }
  7623. }
  7624. //---------------------------------------------------------------------------
  7625. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7626. {
  7627. TDragDropFilesEx * Result = NULL;
  7628. if (Sender == SessionsPageControl)
  7629. {
  7630. Result = FSessionsDragDropFilesEx;
  7631. }
  7632. else if (Sender == QueueView3)
  7633. {
  7634. Result = FQueueDragDropFilesEx;
  7635. }
  7636. else
  7637. {
  7638. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7639. if (DirView != NULL)
  7640. {
  7641. Result = DirView->DragDropFilesEx;
  7642. }
  7643. else
  7644. {
  7645. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7646. if (DriveView != NULL)
  7647. {
  7648. Result = DriveView->DragDropFilesEx;
  7649. }
  7650. }
  7651. }
  7652. DebugAssert(Result != NULL);
  7653. return Result;
  7654. }
  7655. //---------------------------------------------------------------------------
  7656. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7657. {
  7658. return (DView->SelCount == DView->FilesCount);
  7659. }
  7660. //---------------------------------------------------------------------------
  7661. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7662. {
  7663. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7664. }
  7665. //---------------------------------------------------------------------------
  7666. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7667. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7668. {
  7669. DebugAssert(!IsLocalBrowserMode());
  7670. TFileOperation Operation;
  7671. switch (Effect)
  7672. {
  7673. case DROPEFFECT_MOVE:
  7674. Operation = foMove;
  7675. break;
  7676. case DROPEFFECT_COPY:
  7677. // occures on WinXP (reported by user)
  7678. default:
  7679. Operation = foCopy;
  7680. break;
  7681. };
  7682. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7683. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7684. if (DragDropFilesEx->FileList->Count > 0)
  7685. {
  7686. TStrings * FileList = new TStringList();
  7687. try
  7688. {
  7689. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7690. {
  7691. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7692. }
  7693. FDragDropOperation = true;
  7694. TTransferOperationParam Param;
  7695. Param.TargetDirectory = TargetPath;
  7696. // upload, no temp dirs
  7697. Param.Temp = false;
  7698. Param.DragDrop = DragDrop;
  7699. Param.Options =
  7700. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7701. if (ForceQueue)
  7702. {
  7703. Param.Queue = asOn;
  7704. }
  7705. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7706. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7707. {
  7708. if (IsFileControl(DropSourceControl, osLocal))
  7709. {
  7710. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7711. }
  7712. else
  7713. {
  7714. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7715. }
  7716. }
  7717. }
  7718. __finally
  7719. {
  7720. FDragDropOperation = false;
  7721. delete FileList;
  7722. }
  7723. }
  7724. }
  7725. //---------------------------------------------------------------------------
  7726. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7727. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7728. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7729. {
  7730. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7731. }
  7732. //---------------------------------------------------------------------------
  7733. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7734. TObject * Sender, int grfKeyState, int & dwEffect)
  7735. {
  7736. DebugAssert(!IsLocalBrowserMode());
  7737. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7738. if ((dwEffect != DROPEFFECT_NONE) &&
  7739. IsFileControl(DropSourceControl, osRemote))
  7740. {
  7741. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7742. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7743. (RemoteDirView->DropTarget == NULL))
  7744. {
  7745. dwEffect = DROPEFFECT_NONE;
  7746. }
  7747. else
  7748. {
  7749. if (dwEffect == DROPEFFECT_COPY)
  7750. {
  7751. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7752. // currently we support copying always (at least via temporary directory);
  7753. // remove associated checks once this all proves stable and working
  7754. bool CopyCapable = true;
  7755. // if we do not support neither of operations, there's no discussion
  7756. if (!MoveCapable && !CopyCapable)
  7757. {
  7758. dwEffect = DROPEFFECT_NONE;
  7759. }
  7760. else
  7761. {
  7762. // The default effect inside remote panel is move,
  7763. // unless we do not support it, but support copy
  7764. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7765. {
  7766. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7767. }
  7768. else
  7769. {
  7770. // with ctrl-down, we want copy unless it is not supported
  7771. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7772. }
  7773. }
  7774. }
  7775. }
  7776. }
  7777. }
  7778. //---------------------------------------------------------------------------
  7779. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7780. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7781. {
  7782. DebugAssert(!IsLocalBrowserMode());
  7783. if (FDDTotalSize >= 0)
  7784. {
  7785. if (File->IsDirectory)
  7786. {
  7787. FDDTotalSize = -1;
  7788. }
  7789. else
  7790. {
  7791. FDDTotalSize += File->Size;
  7792. }
  7793. }
  7794. DebugAssert(!FDragTempDir.IsEmpty());
  7795. // TODO: this is quite ineffective
  7796. // TODO: what if invalid character replacement is disabled?
  7797. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7798. UnicodeString TransferFileName;
  7799. if (Sender == RemoteDriveView)
  7800. {
  7801. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7802. }
  7803. else
  7804. {
  7805. TransferFileName = File->FileName;
  7806. }
  7807. FDDFileList->AddObject(TransferFileName, File);
  7808. }
  7809. //---------------------------------------------------------------------------
  7810. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7811. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7812. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7813. {
  7814. // sometimes we do not get DDEnd so the list is not released
  7815. SAFE_DESTROY(FDDFileList);
  7816. FDDFileList = new TStringList();
  7817. FDragTempDir = WinConfiguration->TemporaryDir();
  7818. FDDTotalSize = 0;
  7819. FDragDropSshTerminate.reset(NULL);
  7820. }
  7821. //---------------------------------------------------------------------------
  7822. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7823. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7824. HRESULT & Result)
  7825. {
  7826. if (Result == DRAGDROP_S_DROP)
  7827. {
  7828. try
  7829. {
  7830. GlobalDragImageList->HideDragImage();
  7831. try
  7832. {
  7833. RemoteFileControlDDTargetDrop();
  7834. }
  7835. catch(ESshTerminate & E)
  7836. {
  7837. FDragDropSshTerminate.reset(E.Clone());
  7838. }
  7839. }
  7840. catch (Exception &E)
  7841. {
  7842. // If downloading fails we need to cancel drag&drop, otherwise
  7843. // Explorer shows error
  7844. // But by the way exception probably never reach this point as
  7845. // it's catched on way.
  7846. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7847. Result = DRAGDROP_S_CANCEL;
  7848. ShowExtendedException(Terminal, &E);
  7849. }
  7850. }
  7851. }
  7852. //---------------------------------------------------------------------------
  7853. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7854. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7855. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7856. {
  7857. TFileMasks::TParams MaskParams;
  7858. MaskParams.Size = Size;
  7859. MaskParams.Modification = Modification;
  7860. // this does not re-parse the mask if it is the same as the last time
  7861. FDirViewMatchMask = Masks;
  7862. bool ImplicitMatch;
  7863. Matches =
  7864. // RecurseInclude parameter has no effect as the Path is empty
  7865. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7866. (AllowImplicitMatches || !ImplicitMatch);
  7867. }
  7868. //---------------------------------------------------------------------------
  7869. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7870. TObject * Sender, TListItem * Item, WORD & Indexes)
  7871. {
  7872. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7873. UnicodeString Ext;
  7874. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7875. {
  7876. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7877. }
  7878. else
  7879. {
  7880. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7881. }
  7882. if (SameText(Ext, Configuration->PartialExt))
  7883. {
  7884. Indexes |= oiPartial;
  7885. }
  7886. }
  7887. //---------------------------------------------------------------------------
  7888. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7889. {
  7890. return
  7891. DirViewEnabled(osCurrent) &&
  7892. DirView(osCurrent)->CanPasteFromClipBoard();
  7893. }
  7894. //---------------------------------------------------------------------------
  7895. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7896. {
  7897. bool Result = false;
  7898. if (CanPasteToDirViewFromClipBoard())
  7899. {
  7900. Result = true;
  7901. }
  7902. else
  7903. {
  7904. UnicodeString ClipboardText;
  7905. if (NonEmptyTextFromClipboard(ClipboardText) &&
  7906. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  7907. {
  7908. if (StoredSessions->IsUrl(ClipboardText))
  7909. {
  7910. Result = true;
  7911. }
  7912. else
  7913. {
  7914. Result = DirViewEnabled(osCurrent);
  7915. }
  7916. }
  7917. }
  7918. return Result;
  7919. }
  7920. //---------------------------------------------------------------------------
  7921. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7922. {
  7923. if (DoesClipboardContainOurFiles())
  7924. {
  7925. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7926. {
  7927. DebugAssert(!IsLocalBrowserMode());
  7928. TTerminalManager * Manager = TTerminalManager::Instance();
  7929. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7930. Manager->ActiveTerminal = FClipboardTerminal;
  7931. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7932. }
  7933. }
  7934. else if (CanPasteToDirViewFromClipBoard())
  7935. {
  7936. DirView(osCurrent)->PasteFromClipBoard();
  7937. }
  7938. else
  7939. {
  7940. UnicodeString ClipboardText;
  7941. if (NonEmptyTextFromClipboard(ClipboardText))
  7942. {
  7943. if (StoredSessions->IsUrl(ClipboardText))
  7944. {
  7945. NewSession(false, ClipboardText);
  7946. }
  7947. else
  7948. {
  7949. DirView(osCurrent)->Path = ClipboardText;
  7950. }
  7951. }
  7952. }
  7953. }
  7954. //---------------------------------------------------------------------------
  7955. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7956. {
  7957. // TBD
  7958. }
  7959. //---------------------------------------------------------------------------
  7960. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7961. {
  7962. TCustomDirView * ADirView = DirView(Side);
  7963. ADirView->SelectAll(Mode);
  7964. ADirView->SetFocus();
  7965. }
  7966. //---------------------------------------------------------------------------
  7967. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7968. {
  7969. TCustomDirView * ADirView = DirView(Side);
  7970. TFileFilter Filter;
  7971. DefaultFileFilter(Filter);
  7972. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7973. {
  7974. Configuration->Usage->Inc(L"MaskSelections");
  7975. ADirView->SelectFiles(Filter, Select);
  7976. ADirView->SetFocus();
  7977. }
  7978. }
  7979. //---------------------------------------------------------------------------
  7980. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7981. {
  7982. TCustomDirView * ADirView = DirView(Side);
  7983. ADirView->RestoreSelectedNames();
  7984. ADirView->SetFocus();
  7985. }
  7986. //---------------------------------------------------------------------------
  7987. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7988. {
  7989. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7990. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7991. {
  7992. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7993. UnicodeString Ext;
  7994. if (!IsSideLocalBrowser(osCurrent))
  7995. {
  7996. Ext = UnixExtractFileExt(FileName);
  7997. }
  7998. else
  7999. {
  8000. Ext = ExtractFileExt(FileName);
  8001. }
  8002. if (Ext.IsEmpty())
  8003. {
  8004. Ext = L".";
  8005. }
  8006. TFileFilter Filter;
  8007. Filter.Masks = FORMAT(L"*%s", (Ext));
  8008. Filter.Directories = false;
  8009. CurrentDirView->SelectFiles(Filter, Select);
  8010. }
  8011. }
  8012. //---------------------------------------------------------------------------
  8013. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  8014. const TStatusFileInfo & FileInfo, TOperationSide Side)
  8015. {
  8016. UnicodeString Result;
  8017. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  8018. {
  8019. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  8020. }
  8021. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  8022. {
  8023. // noop
  8024. }
  8025. else
  8026. {
  8027. Result =
  8028. FMTLOAD(FILE_INFO_FORMAT,
  8029. (FormatBytes(FileInfo.SelectedSize),
  8030. FormatBytes(FileInfo.FilesSize),
  8031. FormatNumber(FileInfo.SelectedCount),
  8032. FormatNumber(FileInfo.FilesCount)));
  8033. }
  8034. return Result;
  8035. }
  8036. //---------------------------------------------------------------------------
  8037. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8038. TTBXStatusPanel * Panel, TOperationSide Side)
  8039. {
  8040. if (Panel->Index == 1)
  8041. {
  8042. ToggleShowHiddenFiles();
  8043. }
  8044. else if (Panel->Index == 2)
  8045. {
  8046. Filter(Side);
  8047. }
  8048. }
  8049. //---------------------------------------------------------------------------
  8050. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8051. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8052. {
  8053. DebugAssert(!StatusBar->SimplePanel);
  8054. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8055. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8056. }
  8057. //---------------------------------------------------------------------------
  8058. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8059. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8060. {
  8061. DebugAssert(StatusBar->Panels->Count >= 3);
  8062. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8063. if (FileInfo.HiddenCount > 0)
  8064. {
  8065. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8066. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8067. }
  8068. else
  8069. {
  8070. HiddenFilesPanel->ViewPriority = 0;
  8071. // not really necessary, just to cleanup no-longer-valid data
  8072. HiddenFilesPanel->Caption = L"";
  8073. }
  8074. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8075. if (FileInfo.FilteredCount > 0)
  8076. {
  8077. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8078. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8079. }
  8080. else
  8081. {
  8082. FilteredFilesPanel->ViewPriority = 0;
  8083. // not really necessary, just to cleanup no-longer-valid data
  8084. FilteredFilesPanel->Caption = L"";
  8085. }
  8086. }
  8087. //---------------------------------------------------------------------------
  8088. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8089. TObject * /*Sender*/)
  8090. {
  8091. if (DirView(osOther)->Enabled)
  8092. {
  8093. DirView(osOther)->SetFocus();
  8094. }
  8095. }
  8096. //---------------------------------------------------------------------------
  8097. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8098. {
  8099. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8100. switch (Config.Show)
  8101. {
  8102. case qvShow:
  8103. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8104. {
  8105. Config.Show = qvHide;
  8106. }
  8107. else
  8108. {
  8109. Config.Show = Config.LastHideShow;
  8110. }
  8111. break;
  8112. case qvHideWhenEmpty:
  8113. if (ComponentVisible[fcQueueView])
  8114. {
  8115. Config.Show = qvHide;
  8116. }
  8117. else
  8118. {
  8119. Config.LastHideShow = Config.Show;
  8120. Config.Show = qvShow;
  8121. }
  8122. break;
  8123. case qvHide:
  8124. Config.LastHideShow = Config.Show;
  8125. Config.Show = qvShow;
  8126. break;
  8127. }
  8128. WinConfiguration->QueueView = Config;
  8129. }
  8130. //---------------------------------------------------------------------------
  8131. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8132. {
  8133. UnicodeString Result;
  8134. if (FTerminal != NULL)
  8135. {
  8136. switch (WinConfiguration->PathInCaption)
  8137. {
  8138. case picShort:
  8139. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8140. break;
  8141. case picFull:
  8142. Result = FTerminal->CurrentDirectory;
  8143. break;
  8144. }
  8145. }
  8146. return Result;
  8147. }
  8148. //---------------------------------------------------------------------------
  8149. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8150. {
  8151. TColor Result = GetWindowColor(FSessionColor);
  8152. return Result;
  8153. }
  8154. //---------------------------------------------------------------------------
  8155. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8156. {
  8157. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8158. return Result;
  8159. }
  8160. //---------------------------------------------------------------------------
  8161. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8162. {
  8163. TTerminalManager::Instance()->UpdateAppTitle();
  8164. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8165. // background to gray on Windows 7 (works on Windows 10).
  8166. // See also EnableControl
  8167. if (Showing)
  8168. {
  8169. if (Terminal != NULL)
  8170. {
  8171. // Update path when it changes
  8172. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8173. {
  8174. UpdateSessionTab(SessionsPageControl->ActivePage);
  8175. }
  8176. }
  8177. NonVisualDataModule->ReconnectSessionAction->Update();
  8178. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8179. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8180. CenterReconnectToolbar();
  8181. bool HasTerminal = HasActiveTerminal();
  8182. RemoteDirView->Enabled = HasTerminal;
  8183. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8184. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8185. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8186. RemoteDriveView->Color = RemoteDirView->Color;
  8187. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8188. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8189. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8190. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8191. QueueFileList->Enabled = QueueView3->Enabled;
  8192. QueueFileList->Color = QueueView3->Color;
  8193. QueueFileList->Font->Color = QueueView3->Font->Color;
  8194. QueueLabelUpdateStatus();
  8195. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8196. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8197. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8198. }
  8199. }
  8200. //---------------------------------------------------------------------------
  8201. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8202. {
  8203. UpdateControls();
  8204. }
  8205. //---------------------------------------------------------------------------
  8206. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8207. TObject * Sender)
  8208. {
  8209. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8210. DebugAssert(DirView != NULL);
  8211. DoDirViewLoaded(DirView);
  8212. TransferPresetAutoSelect();
  8213. }
  8214. //---------------------------------------------------------------------------
  8215. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8216. {
  8217. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8218. // first run after installation
  8219. if (double(Updates.LastCheck) == 0)
  8220. {
  8221. // make sure next time there will be an update (if enabled)
  8222. Updates.LastCheck = TDateTime(1);
  8223. WinConfiguration->Updates = Updates;
  8224. }
  8225. else if ((double(Updates.Period) > 0) &&
  8226. (Now() - Updates.LastCheck >= Updates.Period))
  8227. {
  8228. TThreadMethod OnUpdatesChecked = NULL;
  8229. if (!IsUWP())
  8230. {
  8231. OnUpdatesChecked = UpdatesChecked;
  8232. }
  8233. StartUpdateThread(OnUpdatesChecked);
  8234. }
  8235. }
  8236. //---------------------------------------------------------------------------
  8237. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8238. {
  8239. UnicodeString Message;
  8240. bool New;
  8241. TQueryType Type;
  8242. GetUpdatesMessage(Message, New, Type, false);
  8243. if (!Message.IsEmpty())
  8244. {
  8245. if (New)
  8246. {
  8247. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8248. }
  8249. if (!New && (Type != qtWarning))
  8250. {
  8251. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8252. }
  8253. else
  8254. {
  8255. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8256. }
  8257. if (New)
  8258. {
  8259. Configuration->Usage->Inc(L"UpdateNotifications");
  8260. }
  8261. }
  8262. }
  8263. //---------------------------------------------------------------------------
  8264. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8265. {
  8266. RestoreApp();
  8267. bool CanDisplay = !NonVisualDataModule->Busy;
  8268. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8269. {
  8270. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8271. }
  8272. if (CanDisplay)
  8273. {
  8274. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8275. CheckForUpdates(true);
  8276. }
  8277. else
  8278. {
  8279. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8280. }
  8281. }
  8282. //---------------------------------------------------------------------------
  8283. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8284. TCopyParamRuleData & Data)
  8285. {
  8286. DebugAssert(Terminal != NULL);
  8287. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8288. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8289. Data.RemoteDirectory = RemoteDirView->PathName;
  8290. }
  8291. //---------------------------------------------------------------------------
  8292. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8293. {
  8294. // Terminal can be null when we are changing local directory implicitly,
  8295. // because it has been deleted, while no session is connected
  8296. // (Login dialog is open)
  8297. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8298. {
  8299. DebugAssert(!IsLocalBrowserMode());
  8300. TCopyParamRuleData Data;
  8301. GetTransferPresetAutoSelectData(Data);
  8302. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8303. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8304. if (CopyParamIndex < 0)
  8305. {
  8306. // there is no preset that matches autoselection
  8307. // set preset that we consider "default"
  8308. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8309. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8310. }
  8311. else
  8312. {
  8313. // there is preset matching autoselection
  8314. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8315. if (CopyParamName == FCopyParamAutoSelected)
  8316. {
  8317. // autoselected the same preset as the last time
  8318. // make no change (i.e. preserve custom user preset, if any)
  8319. }
  8320. else
  8321. {
  8322. // autoselected the different preset then the last time (or there
  8323. // was default preset set)
  8324. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8325. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8326. }
  8327. }
  8328. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8329. {
  8330. if (CopyParamIndex >= 0)
  8331. {
  8332. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8333. }
  8334. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8335. try
  8336. {
  8337. int Fmt =
  8338. (CopyParamIndex < 0) ?
  8339. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8340. COPY_PARAM_AUTOSELECTED;
  8341. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8342. Data->Message = MainInstructions(Message);
  8343. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8344. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8345. CopyParamAttrs);
  8346. if (CopyParamIndex >= 0)
  8347. {
  8348. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8349. Info = FORMAT(L"%s\n \n%s", (Info,
  8350. FMTLOAD(COPY_PARAM_RULE,
  8351. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8352. }
  8353. Data->Message += L"\n\n" + Info;
  8354. if (WinConfiguration->CopyParamAutoSelectNotice)
  8355. {
  8356. TransferPresetNoteMessage(Data, true);
  8357. }
  8358. else
  8359. {
  8360. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8361. Data = NULL; // ownership passed
  8362. }
  8363. }
  8364. __finally
  8365. {
  8366. delete Data;
  8367. }
  8368. }
  8369. }
  8370. }
  8371. //---------------------------------------------------------------------------
  8372. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8373. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8374. {
  8375. DebugAssert(NoteData != NULL);
  8376. DebugAssert(!IsLocalBrowserMode());
  8377. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8378. TQueryButtonAlias Aliases[1];
  8379. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8380. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8381. Params.Aliases = Aliases;
  8382. Params.AliasesCount = LENOF(Aliases);
  8383. unsigned int Result =
  8384. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8385. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8386. switch (Result)
  8387. {
  8388. case qaNeverAskAgain:
  8389. DebugAssert(AllowNeverAskAgain);
  8390. WinConfiguration->CopyParamAutoSelectNotice = false;
  8391. break;
  8392. case qaIgnore:
  8393. PreferencesDialog(pmPresets);
  8394. break;
  8395. }
  8396. }
  8397. //---------------------------------------------------------------------------
  8398. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8399. {
  8400. // as of now useless, as this is used for notes only, never for balloons, ...
  8401. RestoreApp();
  8402. // .. and we should never be busy here
  8403. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8404. {
  8405. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8406. }
  8407. }
  8408. //---------------------------------------------------------------------------
  8409. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8410. TPreferencesMode APreferencesMode)
  8411. {
  8412. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8413. TCopyParamRuleData Data;
  8414. if (Terminal != NULL)
  8415. {
  8416. PreferencesData.reset(new TPreferencesDialogData());
  8417. GetTransferPresetAutoSelectData(Data);
  8418. PreferencesData->CopyParamRuleData = &Data;
  8419. }
  8420. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8421. }
  8422. //---------------------------------------------------------------------------
  8423. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8424. const TCustomCommandType & Command)
  8425. {
  8426. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8427. {
  8428. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8429. }
  8430. }
  8431. //---------------------------------------------------------------------------
  8432. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8433. {
  8434. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8435. TCustomCommandType Command;
  8436. // make sure we use local custom command when remote are not supported
  8437. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8438. {
  8439. Command = FLastCustomCommand;
  8440. }
  8441. else
  8442. {
  8443. Command.Params = Command.Params | ccLocal;
  8444. }
  8445. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8446. FEditingFocusedAdHocCommand = OnFocused;
  8447. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8448. int Options =
  8449. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8450. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8451. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8452. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8453. {
  8454. FLastCustomCommand = Command;
  8455. UpdateCustomCommandsToolbar();
  8456. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8457. }
  8458. }
  8459. //---------------------------------------------------------------------------
  8460. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8461. {
  8462. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8463. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8464. DebugAssert(State > 0);
  8465. if (State <= 0)
  8466. {
  8467. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8468. }
  8469. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8470. }
  8471. //---------------------------------------------------------------------------
  8472. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8473. TCustomCommandType & Command, int & State)
  8474. {
  8475. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8476. if (Result)
  8477. {
  8478. Command = FLastCustomCommand;
  8479. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8480. }
  8481. return Result;
  8482. }
  8483. //---------------------------------------------------------------------------
  8484. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8485. {
  8486. ResetIncrementalSearch();
  8487. }
  8488. //---------------------------------------------------------------------------
  8489. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8490. {
  8491. DebugAssert(ComponentVisible[Component]);
  8492. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8493. }
  8494. //---------------------------------------------------------------------------
  8495. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8496. {
  8497. // when queue panel is resized here directly, the status bar is stretched
  8498. // over whole space the panel occupied
  8499. PostComponentHide(fcQueueView);
  8500. }
  8501. //---------------------------------------------------------------------------
  8502. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8503. {
  8504. ComponentVisible[fcQueueFileList] = false;
  8505. }
  8506. //---------------------------------------------------------------------------
  8507. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8508. {
  8509. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8510. RefreshColorMode();
  8511. ResetSysDarkTheme();
  8512. ConfigurationChanged();
  8513. ConfigureInterface();
  8514. // Should be called for all controls
  8515. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8516. }
  8517. //---------------------------------------------------------------------------
  8518. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8519. {
  8520. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8521. if (!FInvalid &&
  8522. (Message.LParam != 0) &&
  8523. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8524. {
  8525. ThemeChanged();
  8526. }
  8527. TForm::Dispatch(&Message);
  8528. }
  8529. //---------------------------------------------------------------------------
  8530. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8531. {
  8532. TMessage * M = static_cast<TMessage*>(Message);
  8533. switch (M->Msg)
  8534. {
  8535. case CM_DIALOGCHAR:
  8536. CMDialogChar(*M);
  8537. break;
  8538. case WM_APPCOMMAND:
  8539. WMAppCommand(*M);
  8540. break;
  8541. case WM_SYSCOMMAND:
  8542. WMSysCommand(*M);
  8543. break;
  8544. case WM_QUERYENDSESSION:
  8545. WMQueryEndSession(*M);
  8546. break;
  8547. case WM_ENDSESSION:
  8548. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8549. break;
  8550. #ifdef _DEBUG
  8551. case WM_WINDOWPOSCHANGED:
  8552. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8553. break;
  8554. case CM_CUSTOMSTYLECHANGED:
  8555. TForm::Dispatch(Message);
  8556. break;
  8557. #endif
  8558. case WM_COMPONENT_HIDE:
  8559. {
  8560. Byte Component = static_cast<Byte>(M->WParam);
  8561. // sanity check
  8562. if (ComponentVisible[Component])
  8563. {
  8564. // special treatment
  8565. if (Component == fcQueueView)
  8566. {
  8567. ToggleQueueVisibility();
  8568. DebugAssert(!ComponentVisible[fcQueueView]);
  8569. }
  8570. else
  8571. {
  8572. ComponentVisible[Component] = false;
  8573. }
  8574. }
  8575. }
  8576. break;
  8577. case WM_COPYDATA:
  8578. WMCopyData(*M);
  8579. break;
  8580. case WM_MANAGES_CAPTION:
  8581. // caption managed in TTerminalManager::UpdateAppTitle()
  8582. M->Result = 1;
  8583. break;
  8584. case WM_WANTS_MOUSEWHEEL:
  8585. M->Result = 1;
  8586. break;
  8587. case CM_SHOWINGCHANGED:
  8588. CMShowingChanged(*M);
  8589. break;
  8590. case WM_CLOSE:
  8591. WMClose(*M);
  8592. break;
  8593. case WM_DPICHANGED:
  8594. WMDpiChanged(*M);
  8595. break;
  8596. case CM_DPICHANGED:
  8597. CMDpiChanged(*M);
  8598. break;
  8599. case WM_SETTINGCHANGE:
  8600. WMSettingChange(*M);
  8601. break;
  8602. case CM_DIALOGKEY:
  8603. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8604. break;
  8605. default:
  8606. TForm::Dispatch(Message);
  8607. break;
  8608. }
  8609. }
  8610. //---------------------------------------------------------------------------
  8611. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8612. {
  8613. // noop
  8614. }
  8615. //---------------------------------------------------------------------------
  8616. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8617. {
  8618. TForm::Dispatch(&Message);
  8619. FSessionColors->Clear();
  8620. AddFixedSessionImages();
  8621. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8622. UpdateImages();
  8623. }
  8624. //---------------------------------------------------------------------------
  8625. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8626. {
  8627. TForm::Dispatch(&Message);
  8628. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8629. UpdatePixelsPerInchMainWindowCounter();
  8630. }
  8631. //---------------------------------------------------------------------------
  8632. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8633. {
  8634. // Cannot close window while we are busy.
  8635. // We cannot test this in FormCloseQuery as that is called also from
  8636. // Close(), which is called by CloseApplicationAction. So we can be busy
  8637. // there already even, when it is legitimate to close the application.
  8638. // Possibly a better place to handle this would be WMSysCommand.
  8639. if (NonVisualDataModule->Busy)
  8640. {
  8641. Message.Result = 1;
  8642. }
  8643. else
  8644. {
  8645. TForm::Dispatch(&Message);
  8646. }
  8647. }
  8648. //---------------------------------------------------------------------------
  8649. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8650. {
  8651. TForm::Dispatch(&Message);
  8652. if (Showing && (Terminal == NULL))
  8653. {
  8654. // When we are starting minimized (i.e. from an installer),
  8655. // postpone showing Login dialog until we get restored.
  8656. // Otherwise the Login dialog (and Authentication window) show restored
  8657. // over invisible (minimized) main window.
  8658. if (WindowState == wsMinimized)
  8659. {
  8660. FNeedSession = true;
  8661. }
  8662. else
  8663. {
  8664. // This happens before application ever goes idle, so the toolbars would
  8665. // stay enabled (initial state) until the Login dialog is dismissed.
  8666. UpdateActions();
  8667. NonVisualDataModule->StartBusy();
  8668. try
  8669. {
  8670. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8671. // otherwise the dialog does not receive focus.
  8672. // With Commander interface the ProcessMessages is called already
  8673. // by TDriveView, but with Explorer interface, we need to call it explicily
  8674. Application->ProcessMessages();
  8675. // do not reload sessions, they have been loaded just now (optimization)
  8676. NeedSession(true);
  8677. }
  8678. __finally
  8679. {
  8680. NonVisualDataModule->EndBusy();
  8681. }
  8682. }
  8683. }
  8684. }
  8685. //---------------------------------------------------------------------------
  8686. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8687. {
  8688. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8689. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8690. }
  8691. //---------------------------------------------------------------------------
  8692. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8693. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8694. int & MaxHeight)
  8695. {
  8696. // workaround for bug in TWinControl.CalcConstraints
  8697. // Check for empty rect (restore from iconic state) is done there only after
  8698. // call to AdjustClientRect, which enlarges the rect (for forms).
  8699. TRect R = GetClientRect();
  8700. // when restoring from iconic state, place no restrictions
  8701. if (IsRectEmpty(R))
  8702. {
  8703. MinWidth = 0;
  8704. MinHeight = 0;
  8705. MaxWidth = 32000;
  8706. MaxHeight = 32000;
  8707. }
  8708. }
  8709. //---------------------------------------------------------------------------
  8710. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8711. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8712. {
  8713. // terminal can be already closed (e.g. dropped connection)
  8714. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8715. {
  8716. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8717. try
  8718. {
  8719. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8720. }
  8721. catch(...)
  8722. {
  8723. if (!Terminal->Active)
  8724. {
  8725. Close = true;
  8726. }
  8727. throw;
  8728. }
  8729. }
  8730. }
  8731. //---------------------------------------------------------------------------
  8732. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8733. {
  8734. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8735. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8736. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8737. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8738. {
  8739. OnGetSpaceAvailable = GetSpaceAvailable;
  8740. }
  8741. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8742. OnGetSpaceAvailable);
  8743. }
  8744. //---------------------------------------------------------------------------
  8745. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8746. {
  8747. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8748. Terminal->FillSessionDataForCode(Data.get());
  8749. return Data.release();
  8750. }
  8751. //---------------------------------------------------------------------------
  8752. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8753. {
  8754. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8755. DoGenerateUrlDialog(Data.get(), Paths);
  8756. }
  8757. //---------------------------------------------------------------------------
  8758. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8759. {
  8760. GenerateUrl(NULL);
  8761. }
  8762. //---------------------------------------------------------------------------
  8763. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8764. {
  8765. std::unique_ptr<TStrings> Paths(new TStringList());
  8766. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8767. GenerateUrl(Paths.get());
  8768. }
  8769. //---------------------------------------------------------------------------
  8770. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8771. {
  8772. FSessionColor = value;
  8773. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8774. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8775. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8776. DebugAssert(ColorItem != NULL);
  8777. ColorItem->Color = C;
  8778. NonVisualDataModule->ColorMenuItem->Color = C;
  8779. UpdateControls();
  8780. }
  8781. //---------------------------------------------------------------------------
  8782. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8783. {
  8784. if (value != FSessionColor)
  8785. {
  8786. UpdateSessionColor(value);
  8787. // Is null when called from LastTerminalClosed
  8788. if (Terminal != NULL)
  8789. {
  8790. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8791. }
  8792. }
  8793. }
  8794. //---------------------------------------------------------------------------
  8795. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8796. {
  8797. bool Result = FNoteTimer->Enabled;
  8798. if (Result)
  8799. {
  8800. // cannot cancel note too early
  8801. bool NotEarly =
  8802. (Now() - FNoteShown >
  8803. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8804. if (Force || NotEarly)
  8805. {
  8806. FNoteTimer->Enabled = false;
  8807. FNote = L"";
  8808. SAFE_DESTROY(FNoteData);
  8809. FOnNoteClick = NULL;
  8810. FNoteHints = FNotes->Text;
  8811. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8812. UpdateStatusBar();
  8813. }
  8814. }
  8815. return Result;
  8816. }
  8817. //---------------------------------------------------------------------------
  8818. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8819. {
  8820. DebugAssert(FNoteTimer->Enabled);
  8821. CancelNote(true);
  8822. }
  8823. //---------------------------------------------------------------------------
  8824. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  8825. {
  8826. FNoteHints = FNotes->Text.TrimRight();
  8827. }
  8828. //---------------------------------------------------------------------------
  8829. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8830. {
  8831. int P = Note.Pos(L"\n");
  8832. if (P > 0)
  8833. {
  8834. Note.SetLength(P - 1);
  8835. }
  8836. FNotes->Add(FORMAT(L"[%s] %s",
  8837. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8838. while (FNotes->Count > 10)
  8839. {
  8840. FNotes->Delete(0);
  8841. }
  8842. if (UpdateNow)
  8843. {
  8844. UpdateNoteHints();
  8845. UpdateStatusBar();
  8846. }
  8847. }
  8848. //---------------------------------------------------------------------------
  8849. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8850. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8851. {
  8852. int P = Note.Pos(L"\n");
  8853. if (P > 0)
  8854. {
  8855. Note.SetLength(P - 1);
  8856. }
  8857. UpdateNoteHints();
  8858. FNote = Note;
  8859. SAFE_DESTROY(FNoteData);
  8860. FNoteData = NoteData;
  8861. FOnNoteClick = OnNoteClick;
  8862. AddNote(Note, false);
  8863. UpdateStatusBar();
  8864. FNoteShown = Now();
  8865. FNoteTimer->Enabled = false;
  8866. if (Seconds == 0)
  8867. {
  8868. Seconds = WinConfiguration->NotificationsTimeout;
  8869. }
  8870. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8871. FNoteTimer->Enabled = true;
  8872. }
  8873. //---------------------------------------------------------------------------
  8874. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8875. {
  8876. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8877. }
  8878. //---------------------------------------------------------------------------
  8879. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8880. {
  8881. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  8882. {
  8883. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8884. }
  8885. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8886. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8887. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  8888. 0, NULL, NULL);
  8889. }
  8890. //---------------------------------------------------------------------------
  8891. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8892. {
  8893. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8894. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8895. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8896. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  8897. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8898. }
  8899. //---------------------------------------------------------------------------
  8900. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8901. {
  8902. WinConfiguration->FormatSizeBytes = Style;
  8903. }
  8904. //---------------------------------------------------------------------------
  8905. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8906. {
  8907. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8908. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8909. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8910. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8911. }
  8912. //---------------------------------------------------------------------------
  8913. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8914. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8915. {
  8916. if (Panel->Index == 0)
  8917. {
  8918. if (FOnNoteClick != NULL)
  8919. {
  8920. // prevent the user data from being freed by possible call
  8921. // to CancelNote or PostNote during call to OnNoteClick
  8922. std::unique_ptr<TObject> NoteData(FNoteData);
  8923. TNotifyEvent OnNoteClick = FOnNoteClick;
  8924. FNoteData = NULL;
  8925. // need to cancel the note as we are going to delete its user data
  8926. CancelNote(true);
  8927. OnNoteClick(NoteData.get());
  8928. }
  8929. }
  8930. if (HasActiveTerminal() &&
  8931. (Panel->Index >= Sender->Panels->Count - SessionPanelCount))
  8932. {
  8933. FileSystemInfo();
  8934. }
  8935. }
  8936. //---------------------------------------------------------------------------
  8937. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8938. {
  8939. // workaround:
  8940. // 1) for unknown reason, disabling window, while minimized,
  8941. // prevents it from restoring, even if it was enabled again meanwhile
  8942. // 2) when disabling the main window, while another has focus
  8943. // minimize is no longer possible
  8944. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8945. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8946. // Shouldn't we use IsApplicationMinimized() here?
  8947. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8948. {
  8949. Enabled = false;
  8950. }
  8951. FLockLevel++;
  8952. }
  8953. //---------------------------------------------------------------------------
  8954. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8955. {
  8956. DebugAssert(FLockLevel > 0);
  8957. FLockLevel--;
  8958. if (FLockLevel == 0)
  8959. {
  8960. DebugAssert(FLockSuspendLevel == 0);
  8961. Enabled = true;
  8962. }
  8963. }
  8964. //---------------------------------------------------------------------------
  8965. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8966. {
  8967. // We need to make sure that window is enabled when the last modal window closes
  8968. // otherwise focus is not restored correctly.
  8969. // So we re-enable the window when modal window opens and
  8970. // disable it back after is closes
  8971. if (FLockLevel > 0)
  8972. {
  8973. // while we have nesting counter, we know that we never be called
  8974. // recursivelly as Application->OnModalBegin is called only
  8975. // for the top-level modal window
  8976. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8977. {
  8978. // won't be disabled when conditions in LockWindow() were not satisfied
  8979. FDisabledOnLockSuspend = !Enabled;
  8980. // When minimized to tray (or actually when set to SW_HIDE),
  8981. // setting Enabled makes the window focusable even when there's
  8982. // modal window over it
  8983. if (!FTrayIcon->Visible)
  8984. {
  8985. Enabled = true;
  8986. }
  8987. }
  8988. FLockSuspendLevel++;
  8989. }
  8990. }
  8991. //---------------------------------------------------------------------------
  8992. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8993. {
  8994. if (FLockSuspendLevel > 0)
  8995. {
  8996. DebugAssert(FLockLevel > 0);
  8997. FLockSuspendLevel--;
  8998. // see comment in SuspendWindowLock
  8999. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9000. {
  9001. // Note that window can be enabled here, when we were minized to tray when
  9002. // was SuspendWindowLock() called.
  9003. // We should possibly do the same check as in LockWindow(),
  9004. // if it is ever possible that the consitions change between
  9005. // SuspendWindowLock() and ResumeWindowLock()
  9006. Enabled = !FDisabledOnLockSuspend;
  9007. }
  9008. }
  9009. }
  9010. //---------------------------------------------------------------------------
  9011. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9012. {
  9013. TTBXComboBoxItem * RemotePathComboBox =
  9014. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9015. if (!TextOnly)
  9016. {
  9017. TStrings * Items = RemotePathComboBox->Strings;
  9018. Items->BeginUpdate();
  9019. try
  9020. {
  9021. Items->Clear();
  9022. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9023. {
  9024. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9025. while (!IsUnixRootPath(APath))
  9026. {
  9027. int P = APath.LastDelimiter(L'/');
  9028. DebugAssert(P >= 0);
  9029. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9030. APath.SetLength(P - 1);
  9031. }
  9032. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9033. }
  9034. }
  9035. __finally
  9036. {
  9037. Items->EndUpdate();
  9038. }
  9039. }
  9040. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9041. // Setting ItemIndex to -1 does not reset its text
  9042. if (RemotePathComboBox->Strings->Count == 0)
  9043. {
  9044. RemotePathComboBox->Text = L"";
  9045. }
  9046. }
  9047. //---------------------------------------------------------------------------
  9048. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9049. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9050. {
  9051. if (AIndex < 0)
  9052. {
  9053. AIndex = Sender->ItemIndex;
  9054. }
  9055. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9056. }
  9057. //---------------------------------------------------------------------------
  9058. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9059. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9060. int & ImageIndex)
  9061. {
  9062. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9063. }
  9064. //---------------------------------------------------------------------------
  9065. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9066. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9067. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9068. {
  9069. if (!IsLocalBrowserMode())
  9070. {
  9071. ARect.Left += (10 * AIndex);
  9072. }
  9073. }
  9074. //---------------------------------------------------------------------------
  9075. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9076. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9077. {
  9078. AWidth += (10 * AIndex);
  9079. }
  9080. //---------------------------------------------------------------------------
  9081. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9082. {
  9083. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9084. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9085. int Index = RemotePathComboBox->ItemIndex;
  9086. while (Index < RemotePathComboBox->Strings->Count - 1)
  9087. {
  9088. APath = UnixExtractFileDir(APath);
  9089. Index++;
  9090. }
  9091. // VanDyke style paths
  9092. if (APath.IsEmpty())
  9093. {
  9094. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9095. APath = ROOTDIRECTORY;
  9096. }
  9097. if (RemoteDirView->Path != APath)
  9098. {
  9099. RemoteDirView->Path = APath;
  9100. }
  9101. }
  9102. //---------------------------------------------------------------------------
  9103. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9104. {
  9105. DoRemotePathComboBoxItemClick(Sender);
  9106. }
  9107. //---------------------------------------------------------------------------
  9108. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9109. {
  9110. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9111. DebugUsedParam(Sender);
  9112. UpdateRemotePathComboBox(true);
  9113. }
  9114. //---------------------------------------------------------------------------
  9115. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9116. {
  9117. DoRemotePathComboBoxCancel(Sender);
  9118. }
  9119. //---------------------------------------------------------------------------
  9120. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9121. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9122. {
  9123. ResetIncrementalSearch();
  9124. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9125. DebugAssert(DirView != NULL);
  9126. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9127. {
  9128. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9129. // OnEditing is called also from TCustomListView::CanEdit
  9130. if (Edit != NULL)
  9131. {
  9132. EditSelectBaseName(Edit);
  9133. }
  9134. }
  9135. }
  9136. //---------------------------------------------------------------------------
  9137. //---------------------------------------------------------------------------
  9138. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9139. {
  9140. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9141. Result->AutoDetectDnD = false;
  9142. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9143. Result->RenderDataOn = rdoEnterAndDropSync;
  9144. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9145. return Result;
  9146. }
  9147. //---------------------------------------------------------------------------
  9148. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9149. {
  9150. TForm::CreateWnd();
  9151. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9152. if (FSessionsDragDropFilesEx == NULL)
  9153. {
  9154. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9155. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9156. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9157. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9158. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9159. }
  9160. if (FQueueDragDropFilesEx == NULL)
  9161. {
  9162. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9163. // No need to set OnDragOver as we do not have any restrictions
  9164. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9165. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9166. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9167. }
  9168. }
  9169. //---------------------------------------------------------------------------
  9170. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9171. {
  9172. TForm::DestroyWnd();
  9173. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9174. FQueueDragDropFilesEx->DragDropControl = NULL;
  9175. }
  9176. //---------------------------------------------------------------------------
  9177. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9178. {
  9179. SideEnter(FCurrentSide);
  9180. FEverShown = true;
  9181. }
  9182. //---------------------------------------------------------------------------
  9183. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9184. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9185. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9186. {
  9187. if (!NonVisualDataModule->Busy)
  9188. {
  9189. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9190. Configuration->Usage->Inc(L"FileFinds");
  9191. LockWindow(true);
  9192. NonVisualDataModule->StartBusy();
  9193. WinConfiguration->LockedInterface = true;
  9194. try
  9195. {
  9196. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9197. }
  9198. __finally
  9199. {
  9200. WinConfiguration->LockedInterface = false;
  9201. NonVisualDataModule->EndBusy();
  9202. UnlockWindow();
  9203. }
  9204. }
  9205. }
  9206. //---------------------------------------------------------------------------
  9207. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9208. {
  9209. if (!NonVisualDataModule->Busy)
  9210. {
  9211. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9212. SetFocus();
  9213. RemoteDirView->Path = UnixExtractFilePath(Path);
  9214. UnicodeString FileName = UnixExtractFileName(Path);
  9215. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9216. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9217. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9218. if (Item == NULL)
  9219. {
  9220. ReloadDirectory(osRemote);
  9221. Item = RemoteDirView->FindFileItem(FileName);
  9222. }
  9223. if (Item != NULL)
  9224. {
  9225. RemoteDirView->ItemFocused = Item;
  9226. RemoteDirView->ItemFocused->MakeVisible(false);
  9227. RemoteDirView->SetFocus();
  9228. }
  9229. }
  9230. }
  9231. //---------------------------------------------------------------------------
  9232. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9233. {
  9234. bool Result = !NonVisualDataModule->Busy;
  9235. if (Result)
  9236. {
  9237. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9238. }
  9239. return Result;
  9240. }
  9241. //---------------------------------------------------------------------------
  9242. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9243. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9244. {
  9245. if (CanOperateOnFoundFiles(ATerminal))
  9246. {
  9247. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9248. FOnFileOperationFinished = OnFileOperationFinished;
  9249. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9250. }
  9251. }
  9252. //---------------------------------------------------------------------------
  9253. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9254. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9255. {
  9256. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9257. }
  9258. //---------------------------------------------------------------------------
  9259. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9260. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9261. {
  9262. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9263. }
  9264. //---------------------------------------------------------------------------
  9265. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9266. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9267. {
  9268. if (CanOperateOnFoundFiles(ATerminal))
  9269. {
  9270. for (int Index = 0; Index < FileList->Count; Index++)
  9271. {
  9272. UnicodeString FileName = FileList->Strings[Index];
  9273. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9274. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9275. OnFileOperationFinished(FileName, true);
  9276. }
  9277. }
  9278. }
  9279. //---------------------------------------------------------------------------
  9280. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9281. {
  9282. FFileFindTerminal = Terminal;
  9283. ShowFileFindDialog(
  9284. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9285. DoDownloadFoundFiles, DoEditFoundFiles);
  9286. }
  9287. //---------------------------------------------------------------------------
  9288. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9289. {
  9290. FTaskbarList = TaskbarList;
  9291. }
  9292. //---------------------------------------------------------------------------
  9293. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9294. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9295. {
  9296. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9297. if (Index >= 0)
  9298. {
  9299. if (Button == mbLeft)
  9300. {
  9301. // "Mouse down" is raised only after tab is switched.
  9302. // If switching tab (switching session) takes long enough for user
  9303. // to actually release the button, "mouse down" is still raised,
  9304. // but we do not get "mouse up" event, so dragging is not cancelled,
  9305. // prevent that by not beginning dragging in the first place.
  9306. if (IsKeyPressed(VK_LBUTTON))
  9307. {
  9308. // when user clicks the "+", we get mouse down only after the session
  9309. // is closed, when new session tab is already on X:Y, so dragging
  9310. // starts, prevent that
  9311. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9312. {
  9313. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9314. if (Terminal != NULL)
  9315. {
  9316. SessionsPageControl->BeginDrag(false);
  9317. }
  9318. }
  9319. }
  9320. }
  9321. else if (Button == mbMiddle)
  9322. {
  9323. // ignore middle-click for "New session tab"
  9324. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9325. if (Terminal != NULL)
  9326. {
  9327. CloseSessionTab(Index);
  9328. }
  9329. }
  9330. }
  9331. }
  9332. //---------------------------------------------------------------------------
  9333. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9334. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9335. {
  9336. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9337. // do not allow dropping on the "+" tab
  9338. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9339. if ((TargetTerminal != NULL) &&
  9340. (SessionsPageControl->ActivePage->PageIndex != Index))
  9341. {
  9342. Configuration->Usage->Inc(L"SessionTabMoves");
  9343. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9344. // but we want to actually prevent that to avoid flicker
  9345. SessionsPageControl->ActivePage->PageIndex = Index;
  9346. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9347. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9348. }
  9349. }
  9350. //---------------------------------------------------------------------------
  9351. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9352. TObject * Sender, TObject * Source, int X, int Y,
  9353. TDragState /*State*/, bool & Accept)
  9354. {
  9355. Accept = (Sender == Source);
  9356. if (Accept)
  9357. {
  9358. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9359. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9360. // do not allow dragging to the "+" tab
  9361. Accept = (Terminal != NULL);
  9362. }
  9363. }
  9364. //---------------------------------------------------------------------------
  9365. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9366. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9367. {
  9368. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9369. if (Index < 0)
  9370. {
  9371. Effect = DROPEFFECT_NONE;
  9372. }
  9373. else
  9374. {
  9375. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9376. // do not allow dropping on the "+" tab
  9377. if (TargetTerminal == NULL)
  9378. {
  9379. Effect = DROPEFFECT_NONE;
  9380. }
  9381. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9382. {
  9383. Effect = DROPEFFECT_COPY;
  9384. }
  9385. }
  9386. }
  9387. //---------------------------------------------------------------------------
  9388. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9389. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9390. {
  9391. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9392. // do not allow dropping on the "+" tab
  9393. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9394. if (TargetTerminal != NULL)
  9395. {
  9396. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9397. if (!IsFileControl(DropSourceControl, osRemote))
  9398. {
  9399. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9400. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9401. // Why don't we use Terminal->CurrentDirectory directly?
  9402. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9403. // do not force queue, drag drop
  9404. false, true);
  9405. }
  9406. }
  9407. }
  9408. //---------------------------------------------------------------------------
  9409. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9410. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9411. {
  9412. // Downloads are handled in RemoteFileControlDDEnd
  9413. if (!IsFileControl(DropSourceControl, osRemote))
  9414. {
  9415. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9416. Terminal->CurrentDirectory,
  9417. // force queue, drag drop
  9418. true, true);
  9419. }
  9420. }
  9421. //---------------------------------------------------------------------------
  9422. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9423. {
  9424. FShowing = false;
  9425. // Do not save empty workspace
  9426. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9427. {
  9428. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9429. UnicodeString Name = WorkspaceName();
  9430. DoSaveWorkspace(
  9431. Name, DataList.get(),
  9432. !Configuration->DisablePasswordStoring &&
  9433. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9434. WinConfiguration->LastStoredSession = Name;
  9435. }
  9436. }
  9437. //---------------------------------------------------------------------------
  9438. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9439. {
  9440. TManagedTerminal * ManagedTerminal =
  9441. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9442. if (ManagedTerminal != NULL)
  9443. {
  9444. ManagedTerminal->DirectoryLoaded = Now();
  9445. }
  9446. }
  9447. //---------------------------------------------------------------------------
  9448. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9449. TListItem * /*Item*/, bool /*Selected*/)
  9450. {
  9451. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9452. switch (DirView->LastSelectMethod)
  9453. {
  9454. case smKeyboard:
  9455. Configuration->Usage->Inc(L"KeyboardSelections");
  9456. break;
  9457. case smMouse:
  9458. Configuration->Usage->Inc(L"MouseSelections");
  9459. break;
  9460. }
  9461. }
  9462. //---------------------------------------------------------------------------
  9463. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9464. {
  9465. if (Color != 0)
  9466. {
  9467. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9468. }
  9469. else
  9470. {
  9471. return FSessionTabImageIndex;
  9472. }
  9473. }
  9474. //---------------------------------------------------------------------------
  9475. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9476. {
  9477. TPngImageCollectionItem * Item =
  9478. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9479. FSessionColors->AddPng(Item->PngImage);
  9480. return FSessionColors->Count - 1;
  9481. }
  9482. //---------------------------------------------------------------------------
  9483. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9484. {
  9485. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9486. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9487. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9488. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9489. }
  9490. //---------------------------------------------------------------------------
  9491. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9492. {
  9493. for (int Index = 0; Index < Control->ControlCount; Index++)
  9494. {
  9495. TControl * AControl = Control->Controls[Index];
  9496. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9497. if (WinControl != NULL)
  9498. {
  9499. CollectItemsWithTextDisplayMode(WinControl);
  9500. }
  9501. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9502. if (Toolbar != NULL)
  9503. {
  9504. // we care for top-level items only
  9505. TTBCustomItem * Items = Toolbar->Items;
  9506. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9507. {
  9508. TTBCustomItem * Item = Items->Items[ItemIndex];
  9509. if (((Item->DisplayMode == nbdmImageAndText) ||
  9510. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9511. EligibleForImageDisplayMode(Item))
  9512. {
  9513. FItemsWithTextDisplayMode.insert(Item);
  9514. }
  9515. }
  9516. }
  9517. }
  9518. }
  9519. //---------------------------------------------------------------------------
  9520. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9521. {
  9522. return true;
  9523. }
  9524. //---------------------------------------------------------------------------
  9525. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9526. {
  9527. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9528. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9529. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9530. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9531. bool Result = true;
  9532. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9533. {
  9534. TTBCustomItem * Item = *i;
  9535. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9536. if (Label != NULL)
  9537. {
  9538. // optimization
  9539. if (Label->Visible == SelectiveToolbarText)
  9540. {
  9541. Result = false;
  9542. }
  9543. else
  9544. {
  9545. Label->Visible = SelectiveToolbarText;
  9546. }
  9547. }
  9548. else
  9549. {
  9550. // optimization
  9551. if (Item->DisplayMode == DisplayMode)
  9552. {
  9553. Result = false;
  9554. }
  9555. else
  9556. {
  9557. Item->DisplayMode = DisplayMode;
  9558. }
  9559. }
  9560. ++i;
  9561. }
  9562. if (Result)
  9563. {
  9564. UpdateNewSessionTab();
  9565. }
  9566. return Result;
  9567. }
  9568. //---------------------------------------------------------------------------
  9569. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9570. {
  9571. DebugFail();
  9572. }
  9573. //---------------------------------------------------------------------------
  9574. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9575. {
  9576. // Among other, a lock level is non zero, while directory is being loaded,
  9577. // even when it happens as a result of dirview navigation,
  9578. // i.e. when TNonVisualDataModule is NOT FBusy.
  9579. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9580. // Among other this prevents a panel auto update to occur while
  9581. // directory is changing.
  9582. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9583. }
  9584. //---------------------------------------------------------------------------
  9585. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  9586. {
  9587. // While the window is disabled, we still seem to process menu shortcuts at least,
  9588. // so stop it at least here.
  9589. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9590. bool Result;
  9591. if (Allowed == aaUpdate)
  9592. {
  9593. Result = true;
  9594. }
  9595. else
  9596. {
  9597. Result = !NonVisualDataModule->Busy;
  9598. if (Result && (Allowed == aaShortCut))
  9599. {
  9600. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  9601. Action->Update();
  9602. Result = Action->Enabled;
  9603. }
  9604. }
  9605. return Result;
  9606. }
  9607. //---------------------------------------------------------------------------
  9608. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9609. {
  9610. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9611. }
  9612. //---------------------------------------------------------------------------
  9613. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9614. {
  9615. // This is somewhat redundant to LockWindow() call from
  9616. // TTerminalManager::TerminalReadDirectoryProgress.
  9617. // But disabling window is known not to block keyboard shorcuts
  9618. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9619. if (Busy > 0)
  9620. {
  9621. if (NonVisualDataModule->Busy)
  9622. {
  9623. State = false;
  9624. }
  9625. else
  9626. {
  9627. NonVisualDataModule->StartBusy();
  9628. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9629. LockWindow();
  9630. }
  9631. }
  9632. else if (Busy < 0)
  9633. {
  9634. UnlockWindow();
  9635. NonVisualDataModule->EndBusy();
  9636. }
  9637. else
  9638. {
  9639. State = NonVisualDataModule->Busy;
  9640. }
  9641. }
  9642. //---------------------------------------------------------------------------
  9643. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9644. {
  9645. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9646. // no context menu for "New session tab"
  9647. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9648. {
  9649. SessionsPageControl->ActivePageIndex = Index;
  9650. if (DebugAlwaysTrue(SessionTabSwitched()))
  9651. {
  9652. // copied from TControl.WMContextMenu
  9653. SendCancelMode(SessionsPageControl);
  9654. // explicit popup instead of using PopupMenu property
  9655. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9656. // while connecting yet not-connected session and hence
  9657. // allowing an access to commands over not-completelly connected session
  9658. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9659. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9660. PopupMenu->PopupComponent = SessionsPageControl;
  9661. PopupMenu->Popup(Point.x, Point.y);
  9662. }
  9663. }
  9664. Handled = true;
  9665. }
  9666. //---------------------------------------------------------------------------
  9667. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9668. {
  9669. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9670. }
  9671. //---------------------------------------------------------------------------
  9672. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9673. {
  9674. Configuration->Usage->Inc(L"PasswordChanges");
  9675. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9676. ChangePasswordData->DisableAuthentationsExceptPassword();
  9677. ChangePasswordData->ChangePassword = true;
  9678. std::unique_ptr<TTerminal> ChangePasswordSession(
  9679. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9680. ChangePasswordSession->AutoReadDirectory = false;
  9681. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9682. {
  9683. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9684. }
  9685. else
  9686. {
  9687. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9688. }
  9689. }
  9690. //---------------------------------------------------------------------------
  9691. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9692. {
  9693. // No nice way to assert SSH2
  9694. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9695. }
  9696. //---------------------------------------------------------------------------
  9697. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9698. {
  9699. TOperationVisualizer OperationVisualizer;
  9700. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9701. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9702. }
  9703. //---------------------------------------------------------------------------
  9704. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9705. {
  9706. TForm::ChangeScale(M, D);
  9707. int APixelsPerInch = GetControlPixelsPerInch(this);
  9708. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9709. try
  9710. {
  9711. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9712. }
  9713. __finally
  9714. {
  9715. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9716. }
  9717. }
  9718. //---------------------------------------------------------------------------
  9719. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9720. {
  9721. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9722. }
  9723. //---------------------------------------------------------------------
  9724. class TPublicControl : public TControl
  9725. {
  9726. friend class TCustomScpExplorerForm;
  9727. };
  9728. //---------------------------------------------------------------------------
  9729. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9730. {
  9731. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9732. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9733. }
  9734. //---------------------------------------------------------------------------
  9735. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9736. {
  9737. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9738. OpenBookmark(Side, Bookmark);
  9739. }
  9740. //---------------------------------------------------------------------------
  9741. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9742. {
  9743. DoBookmarkClick(osLocal, Sender);
  9744. }
  9745. //---------------------------------------------------------------------------
  9746. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9747. {
  9748. DoBookmarkClick(osRemote, Sender);
  9749. }
  9750. //---------------------------------------------------------------------------
  9751. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9752. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9753. {
  9754. if (BookmarkList != NULL)
  9755. {
  9756. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9757. if (IsLocalBrowserMode())
  9758. {
  9759. Side = osLocal;
  9760. }
  9761. if (!WinConfiguration->UseLocationProfiles)
  9762. {
  9763. std::unique_ptr<TStringList> Directories(new TStringList());
  9764. Directories->CaseSensitive = (Side == osRemote);
  9765. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9766. {
  9767. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9768. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9769. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9770. {
  9771. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9772. Item->Caption = EscapeHotkey(Directory);
  9773. Item->ShortCut = Bookmark->ShortCut;
  9774. Item->OnClick = OnBookmarkClick;
  9775. Item->Tag = reinterpret_cast<int>(Bookmark);
  9776. Directories->Add(Directory);
  9777. Menu->Add(Item.release());
  9778. }
  9779. }
  9780. }
  9781. else
  9782. {
  9783. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9784. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9785. {
  9786. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9787. if (!Bookmark->Node.IsEmpty())
  9788. {
  9789. Folders->Add(Bookmark->Node);
  9790. }
  9791. }
  9792. for (int Index = 0; Index < Folders->Count; Index++)
  9793. {
  9794. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9795. Item->Caption = Folders->Strings[Index];
  9796. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  9797. Folders->Objects[Index] = Item.get();
  9798. Menu->Add(Item.release());
  9799. }
  9800. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9801. {
  9802. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9803. TTBCustomItem * Parent;
  9804. if (!Bookmark->Node.IsEmpty())
  9805. {
  9806. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9807. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9808. }
  9809. else
  9810. {
  9811. Parent = Menu;
  9812. }
  9813. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9814. Item->Caption = Bookmark->Name;
  9815. Item->ShortCut = Bookmark->ShortCut;
  9816. Item->OnClick = OnBookmarkClick;
  9817. Item->Tag = reinterpret_cast<int>(Bookmark);
  9818. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9819. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9820. {
  9821. // No hint for location profiles that are actually mere "bookmarks"
  9822. }
  9823. else
  9824. {
  9825. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9826. UnicodeString LongHint;
  9827. if (!Bookmark->Local.IsEmpty())
  9828. {
  9829. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9830. }
  9831. if (!Bookmark->Remote.IsEmpty())
  9832. {
  9833. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9834. }
  9835. AddToList(Hint, LongHint, L"|");
  9836. Item->Hint = Hint;
  9837. }
  9838. Parent->Add(Item.release());
  9839. }
  9840. }
  9841. AddMenuSeparator(Menu);
  9842. }
  9843. }
  9844. //---------------------------------------------------------------------------
  9845. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9846. {
  9847. Menu->Clear();
  9848. std::unique_ptr<TTBCustomItem> Item;
  9849. Item.reset(new TTBXItem(Owner));
  9850. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9851. Item->Options = Item->Options << tboDefault;
  9852. Menu->Add(Item.release());
  9853. AddMenuSeparator(Menu);
  9854. if (Terminal != NULL)
  9855. {
  9856. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9857. }
  9858. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9859. Item.reset(new TTBXItem(Owner));
  9860. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  9861. Menu->Add(Item.release());
  9862. }
  9863. //---------------------------------------------------------------------------
  9864. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9865. {
  9866. bool Result = true;
  9867. bool Remote = !IsSideLocalBrowser(Side);
  9868. try
  9869. {
  9870. if (Remote)
  9871. {
  9872. Terminal->ExceptionOnFail = true;
  9873. }
  9874. try
  9875. {
  9876. DirView(Side)->Path = Path;
  9877. }
  9878. __finally
  9879. {
  9880. if (Remote)
  9881. {
  9882. Terminal->ExceptionOnFail = false;
  9883. }
  9884. }
  9885. }
  9886. catch (Exception & E)
  9887. {
  9888. if (!Remote || Terminal->Active)
  9889. {
  9890. ShowExtendedExceptionEx(Terminal, &E);
  9891. Result = false;
  9892. }
  9893. else
  9894. {
  9895. throw;
  9896. }
  9897. }
  9898. return Result;
  9899. }
  9900. //---------------------------------------------------------------------------
  9901. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9902. {
  9903. // Make sure there some feedback even when loading tiny local folders
  9904. TInstantOperationVisualizer Visualizer;
  9905. DirView(Side)->ReloadDirectory();
  9906. }
  9907. //---------------------------------------------------------------------------
  9908. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9909. {
  9910. if (Index == SessionsPageControl->TabIndex)
  9911. {
  9912. CloseSession();
  9913. }
  9914. else
  9915. {
  9916. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9917. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9918. TTerminalManager * Manager = TTerminalManager::Instance();
  9919. if (!Terminal->Active)
  9920. {
  9921. Manager->FreeTerminal(Terminal);
  9922. }
  9923. else
  9924. {
  9925. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9926. if (CanCloseQueue(Queue))
  9927. {
  9928. Manager->FreeTerminal(Terminal);
  9929. }
  9930. }
  9931. }
  9932. }
  9933. //---------------------------------------------------------------------------
  9934. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9935. {
  9936. CloseSessionTab(Index);
  9937. }
  9938. //---------------------------------------------------------------------------
  9939. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9940. {
  9941. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9942. {
  9943. TInstantOperationVisualizer Visualizer;
  9944. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9945. // before we create a new data object
  9946. ClipboardClear();
  9947. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9948. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9949. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9950. // Intermediate variable to WORKAROUND a crash in compiler
  9951. TObjectList * ClipboardFakeMonitors =
  9952. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9953. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9954. if (FClipboardDragDropFilesEx.get() == NULL)
  9955. {
  9956. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9957. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9958. }
  9959. FClipboardDragDropFilesEx->FileList->Clear();
  9960. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9961. FClipboardDragDropFilesEx->CopyToClipboard();
  9962. FClipboardTerminal = FTerminal;
  9963. // Need full paths, as cwd can be different once files are pasted
  9964. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9965. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9966. {
  9967. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9968. }
  9969. }
  9970. }
  9971. //---------------------------------------------------------------------------
  9972. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9973. {
  9974. if (OpenClipboard(0))
  9975. {
  9976. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9977. CloseClipboard();
  9978. }
  9979. }
  9980. //---------------------------------------------------------------------------
  9981. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9982. {
  9983. return !FClipboardFakeDirectory.IsEmpty();
  9984. }
  9985. //---------------------------------------------------------------------------
  9986. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9987. {
  9988. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9989. FClipboardFakeDirectory = UnicodeString();
  9990. FClipboardTerminal = NULL;
  9991. // Also called in Idle()
  9992. FClipboardFakeMonitors.reset(NULL);
  9993. }
  9994. //---------------------------------------------------------------------------
  9995. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9996. {
  9997. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9998. {
  9999. ClipboardStop();
  10000. }
  10001. }
  10002. //---------------------------------------------------------------------------
  10003. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  10004. {
  10005. TTerminalManager * Manager = TTerminalManager::Instance();
  10006. Manager->ActiveTerminal = FClipboardTerminal;
  10007. TTransferOperationParam Params;
  10008. Params.TargetDirectory = TargetDirectory;
  10009. Params.DragDrop = DragDrop;
  10010. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  10011. }
  10012. //---------------------------------------------------------------------------
  10013. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  10014. {
  10015. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  10016. // (as it pumps a Windows message queue while being shutted down)
  10017. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10018. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10019. {
  10020. // Can fail as it can be e.g. locked by AV, so we retry that later
  10021. bool Removed = RemoveDir(ApiPath(FileName));
  10022. try
  10023. {
  10024. if (!NonVisualDataModule->Busy)
  10025. {
  10026. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10027. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  10028. }
  10029. }
  10030. __finally
  10031. {
  10032. if (!Removed)
  10033. {
  10034. RemoveDir(ApiPath(FileName));
  10035. }
  10036. }
  10037. }
  10038. }
  10039. //---------------------------------------------------------------------------
  10040. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10041. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10042. {
  10043. TFileMasks::TParams MaskParams;
  10044. MaskParams.Size = Size;
  10045. MaskParams.Modification = Modification;
  10046. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10047. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10048. {
  10049. bool ImplicitMatch;
  10050. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  10051. !ImplicitMatch)
  10052. {
  10053. Color = Iter->Color;
  10054. break;
  10055. }
  10056. }
  10057. }
  10058. //---------------------------------------------------------------------------
  10059. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10060. {
  10061. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10062. if (!DirView->IsEditing())
  10063. {
  10064. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10065. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10066. // while searching
  10067. if (Key == VK_BACK)
  10068. {
  10069. if (!FIncrementalSearch.IsEmpty())
  10070. {
  10071. if (FIncrementalSearch.Length() == 1)
  10072. {
  10073. ResetIncrementalSearch();
  10074. }
  10075. else
  10076. {
  10077. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10078. IncrementalSearch(NewText, false, false);
  10079. }
  10080. Key = 0;
  10081. }
  10082. }
  10083. }
  10084. }
  10085. //---------------------------------------------------------------------------
  10086. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10087. {
  10088. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10089. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10090. {
  10091. // Filter control sequences.
  10092. // When not searching yet, prefer use of the space for toggling file selection
  10093. // (so we cannot incrementally search for a string starting with a space).
  10094. if ((Key > VK_SPACE) ||
  10095. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10096. {
  10097. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10098. Key = 0;
  10099. }
  10100. }
  10101. }
  10102. //---------------------------------------------------------------------------
  10103. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10104. {
  10105. if (!FIncrementalSearch.IsEmpty())
  10106. {
  10107. FIncrementalSearch = L"";
  10108. DirView(osCurrent)->UpdateStatusBar();
  10109. }
  10110. }
  10111. //---------------------------------------------------------------------------
  10112. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10113. {
  10114. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10115. if (Item == NULL)
  10116. {
  10117. MessageBeep(MB_ICONHAND);
  10118. }
  10119. else
  10120. {
  10121. TCustomDirView * ADirView = DirView(osCurrent);
  10122. {
  10123. TAutoNestingCounter Guard(FIncrementalSearching);
  10124. ADirView->FocusItem(Item);
  10125. if (ADirView->NortonLike == nlOff)
  10126. {
  10127. if ((ADirView->Selected != Item) ||
  10128. (ADirView->SelCount > 1))
  10129. {
  10130. ADirView->ClearSelection();
  10131. ADirView->Selected = Item;
  10132. }
  10133. }
  10134. }
  10135. FIncrementalSearch = Text;
  10136. Item->MakeVisible(false);
  10137. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10138. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10139. ADirView->UpdateStatusBar();
  10140. }
  10141. }
  10142. //---------------------------------------------------------------------------
  10143. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10144. {
  10145. int Index = Item->Index;
  10146. if (!Reverse)
  10147. {
  10148. Index++;
  10149. if (Index >= Item->Owner->Count)
  10150. {
  10151. Index = 0;
  10152. }
  10153. }
  10154. else
  10155. {
  10156. Index--;
  10157. if (Index < 0)
  10158. {
  10159. Index = Item->Owner->Count - 1;
  10160. }
  10161. }
  10162. return Item->Owner->Item[Index];
  10163. }
  10164. //---------------------------------------------------------------------------
  10165. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10166. {
  10167. TCustomDirView * ADirView = DirView(osCurrent);
  10168. if (ADirView->Items->Count == 0)
  10169. {
  10170. return NULL;
  10171. }
  10172. else
  10173. {
  10174. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10175. TListItem * Item = CurrentItem;
  10176. if (SkipCurrent)
  10177. {
  10178. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10179. }
  10180. while (true)
  10181. {
  10182. bool Matches = false;
  10183. switch (WinConfiguration->PanelSearch)
  10184. {
  10185. case isNameStartOnly:
  10186. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10187. break;
  10188. case isName:
  10189. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10190. break;
  10191. case isAll:
  10192. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10193. int Index = 0;
  10194. while ((Index < ColCount) && !Matches)
  10195. {
  10196. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10197. if (Visible)
  10198. {
  10199. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10200. }
  10201. Index++;
  10202. }
  10203. break;
  10204. }
  10205. if (Matches)
  10206. {
  10207. return Item;
  10208. }
  10209. Item = GetNextFile(Item, Reverse);
  10210. if (Item == CurrentItem)
  10211. {
  10212. return NULL;
  10213. }
  10214. }
  10215. }
  10216. }
  10217. //---------------------------------------------------------------------------
  10218. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10219. {
  10220. ResetIncrementalSearch();
  10221. }
  10222. //---------------------------------------------------------------------------
  10223. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10224. {
  10225. if (Message.CharCode == VK_TAB)
  10226. {
  10227. if (!FIncrementalSearch.IsEmpty())
  10228. {
  10229. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10230. bool Reverse = Shift.Contains(ssShift);
  10231. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10232. Message.Result = 1;
  10233. return;
  10234. }
  10235. }
  10236. else if (Message.CharCode == VK_ESCAPE)
  10237. {
  10238. if (!FIncrementalSearch.IsEmpty())
  10239. {
  10240. ResetIncrementalSearch();
  10241. Message.Result = 1;
  10242. return;
  10243. }
  10244. }
  10245. TForm::Dispatch(&Message);
  10246. }
  10247. //---------------------------------------------------------------------------
  10248. void __fastcall TCustomScpExplorerForm::Deactivate()
  10249. {
  10250. TForm::Deactivate();
  10251. // E.g. when switching to an internal editor window
  10252. ResetIncrementalSearch();
  10253. }
  10254. //---------------------------------------------------------------------------
  10255. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10256. {
  10257. // When switching to another application
  10258. ResetIncrementalSearch();
  10259. }
  10260. //---------------------------------------------------------------------------
  10261. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10262. {
  10263. ResetIncrementalSearch();
  10264. }
  10265. //---------------------------------------------------------------------------
  10266. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10267. {
  10268. if (FIncrementalSearching <= 0)
  10269. {
  10270. ResetIncrementalSearch();
  10271. }
  10272. }
  10273. //---------------------------------------------------------------------------
  10274. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10275. {
  10276. CountClicksForWindowPrint(this);
  10277. }
  10278. //---------------------------------------------------------------------------
  10279. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10280. {
  10281. CenterReconnectToolbar();
  10282. }
  10283. //---------------------------------------------------------------------------
  10284. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10285. {
  10286. if (RemoteDirView->ItemFocused != NULL)
  10287. {
  10288. RemoteDirView->ItemFocused->Selected = true;
  10289. }
  10290. }
  10291. //---------------------------------------------------------------------------
  10292. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10293. {
  10294. if (!FQueueStatusUpdating)
  10295. {
  10296. bool Refresh;
  10297. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10298. {
  10299. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10300. }
  10301. else
  10302. {
  10303. if (FQueueFileList->GetCount() > 0)
  10304. {
  10305. FQueueFileList->Clear();
  10306. Refresh = true;
  10307. }
  10308. }
  10309. int Count = FQueueFileList->GetCount();
  10310. if (QueueFileList->Items->Count != Count)
  10311. {
  10312. DebugAssert(Refresh);
  10313. QueueFileList->Items->Count = Count;
  10314. }
  10315. if (Refresh)
  10316. {
  10317. QueueFileList->Invalidate();
  10318. }
  10319. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10320. }
  10321. }
  10322. //---------------------------------------------------------------------------
  10323. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10324. {
  10325. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10326. }
  10327. //---------------------------------------------------------------------------
  10328. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10329. {
  10330. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10331. // See TSynchronizeChecklistDialog::UpdateTimer
  10332. if (QueueFileList->Items->Count > 0)
  10333. {
  10334. QueueFileList->Items->Item[0]->MakeVisible(false);
  10335. }
  10336. UpdateQueueFileList();
  10337. }
  10338. //---------------------------------------------------------------------------
  10339. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10340. {
  10341. Active = QueueView3->Focused() || QueueFileList->Focused();
  10342. }
  10343. //---------------------------------------------------------------------------
  10344. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10345. {
  10346. QueueLabelUpdateStatus();
  10347. }
  10348. //---------------------------------------------------------------------------
  10349. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10350. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10351. {
  10352. int State = FQueueFileList->GetState(Item->Index);
  10353. if (State == qfsProcessed)
  10354. {
  10355. Sender->Canvas->Font->Color = clGrayText;
  10356. }
  10357. }
  10358. //---------------------------------------------------------------------------
  10359. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10360. {
  10361. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10362. QueueFileList->Column[0]->Width =
  10363. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10364. }
  10365. //---------------------------------------------------------------------------
  10366. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10367. {
  10368. QueueFileListColumnAutoSize();
  10369. }
  10370. //---------------------------------------------------------------------------
  10371. void __fastcall TCustomScpExplorerForm::CloseApp()
  10372. {
  10373. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10374. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10375. // So we clear the flag here.
  10376. DebugAssert(NonVisualDataModule->Busy);
  10377. NonVisualDataModule->EndBusy();
  10378. try
  10379. {
  10380. Close();
  10381. }
  10382. __finally
  10383. {
  10384. NonVisualDataModule->StartBusy();
  10385. }
  10386. }
  10387. //---------------------------------------------------------------------------
  10388. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10389. {
  10390. return (Terminal != NULL) && Terminal->Active;
  10391. }
  10392. //---------------------------------------------------------------------------
  10393. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10394. {
  10395. return IsActiveTerminal(Terminal);
  10396. }
  10397. //---------------------------------------------------------------------------
  10398. void TCustomScpExplorerForm::LocalLocalCopy(
  10399. TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused), bool DebugUsedArg(NoConfirmation),
  10400. bool DebugUsedArg(DragDrop), unsigned int DebugUsedArg(Flags))
  10401. {
  10402. DebugFail();
  10403. }
  10404. //---------------------------------------------------------------------------
  10405. void TCustomScpExplorerForm::LocalLocalCopyCommand(TFileOperation Operation, TOperationSide Side, bool OnFocused, unsigned int Flags)
  10406. {
  10407. LocalLocalCopy(Operation, Side, OnFocused, !WinConfiguration->ConfirmTransferring, false, Flags);
  10408. }