CustomScpExplorer.cpp 363 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035
  1. //---------------------------------------------------------------------------
  2. #define NO_WIN32_LEAN_AND_MEAN
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <Common.h>
  6. #include "CustomScpExplorer.h"
  7. #include <Bookmarks.h>
  8. #include <Interface.h>
  9. #include <Exceptions.h>
  10. #include <CoreMain.h>
  11. #include <FileSystems.h>
  12. #include <TextsCore.h>
  13. #include <TextsWin.h>
  14. #include <HelpWin.h>
  15. #include <VCLCommon.h>
  16. #include <Progress.h>
  17. #include <SynchronizeProgress.h>
  18. #include <DragExt.h>
  19. #include <WinApi.h>
  20. #include "GUITools.h"
  21. #include "NonVisual.h"
  22. #include "Glyphs.h"
  23. #include "Tools.h"
  24. #include "WinConfiguration.h"
  25. #include "TerminalManager.h"
  26. #include "EditorManager.h"
  27. #include "ProgParams.h"
  28. #include "Setup.h"
  29. #include <Consts.hpp>
  30. #include <DateUtils.hpp>
  31. #include <TB2Common.hpp>
  32. #include <DirectoryMonitor.hpp>
  33. #include <System.IOUtils.hpp>
  34. //---------------------------------------------------------------------------
  35. #pragma package(smart_init)
  36. #pragma link "CustomDirView"
  37. #pragma link "CustomUnixDirView"
  38. #pragma link "IEListView"
  39. #pragma link "NortonLikeListView"
  40. #pragma link "UnixDirView"
  41. #pragma link "CustomDriveView"
  42. #pragma link "UnixDriveView"
  43. #pragma link "CustomDriveView"
  44. #pragma link "TB2Dock"
  45. #pragma link "TBXStatusBars"
  46. #pragma link "TB2Item"
  47. #pragma link "TB2Toolbar"
  48. #pragma link "ThemePageControl"
  49. #pragma link "PathLabel"
  50. #pragma resource "*.dfm"
  51. //---------------------------------------------------------------------------
  52. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  53. static const int SessionPanelCount = 4;
  54. //---------------------------------------------------------------------------
  55. class TMutexGuard
  56. {
  57. public:
  58. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  59. int Timeout = 5000)
  60. {
  61. FMutex = NULL;
  62. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  63. if (WaitResult == WAIT_TIMEOUT)
  64. {
  65. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  66. }
  67. else
  68. {
  69. FMutex = AMutex;
  70. }
  71. }
  72. ~TMutexGuard()
  73. {
  74. if (FMutex != NULL)
  75. {
  76. ReleaseMutex(FMutex);
  77. }
  78. }
  79. private:
  80. HANDLE FMutex;
  81. };
  82. //---------------------------------------------------------------------------
  83. class TWindowLock
  84. {
  85. public:
  86. TWindowLock(TCustomScpExplorerForm * Form) :
  87. FForm(Form)
  88. {
  89. FForm->LockWindow();
  90. }
  91. ~TWindowLock()
  92. {
  93. FForm->UnlockWindow();
  94. }
  95. private:
  96. TCustomScpExplorerForm * FForm;
  97. };
  98. //---------------------------------------------------------------------------
  99. class TAutoBatch
  100. {
  101. public:
  102. TAutoBatch(TCustomScpExplorerForm * Form) :
  103. FForm(Form)
  104. {
  105. FForm->BatchStart(FBatchStorage);
  106. }
  107. ~TAutoBatch()
  108. {
  109. FForm->BatchEnd(FBatchStorage);
  110. }
  111. private:
  112. TCustomScpExplorerForm * FForm;
  113. void * FBatchStorage;
  114. };
  115. //---------------------------------------------------------------------------
  116. struct TTransferOperationParam
  117. {
  118. TTransferOperationParam();
  119. UnicodeString TargetDirectory;
  120. bool Temp;
  121. bool DragDrop;
  122. int Options;
  123. TAutoSwitch Queue;
  124. };
  125. //---------------------------------------------------------------------------
  126. TTransferOperationParam::TTransferOperationParam()
  127. {
  128. Temp = false;
  129. DragDrop = false;
  130. Options = 0;
  131. Queue = asAuto;
  132. }
  133. //---------------------------------------------------------------------------
  134. class TTransferPresetNoteData : public TObject
  135. {
  136. public:
  137. UnicodeString Message;
  138. };
  139. //---------------------------------------------------------------------------
  140. class TTerminalNoteData : public TObject
  141. {
  142. public:
  143. TManagedTerminal * Terminal;
  144. };
  145. //---------------------------------------------------------------------------
  146. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  147. FFormRestored(false),
  148. TForm(Owner)
  149. {
  150. FInvalid = false;
  151. FCurrentSide = osRemote;
  152. FEverShown = false;
  153. FDocks = new TList();
  154. InitControls();
  155. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  156. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  157. NonVisualDataModule->ScpExplorer = this;
  158. RestoreParams();
  159. ConfigurationChanged();
  160. RemoteDirView->Invalidate();
  161. FAutoOperation = false;
  162. FOnFileOperationFinished = NULL;
  163. FForceExecution = false;
  164. FIgnoreNextDialogChar = 0;
  165. FErrorList = NULL;
  166. FSynchronizeProgressForm = NULL;
  167. FProgressForm = NULL;
  168. FRefreshLocalDirectory = false;
  169. FRefreshRemoteDirectory = false;
  170. FDDExtMapFile = NULL;
  171. // CreateMutexW keeps failing with ERROR_NOACCESS
  172. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  173. DebugAssert(FDDExtMutex != NULL);
  174. FDDTargetControl = NULL;
  175. FDelayedDeletionTimer = NULL;
  176. FDelayedDeletionList = new TStringList();
  177. FDDFileList = NULL;
  178. FPendingTempSpaceWarn = false;
  179. FCapturedLog = NULL;
  180. FDragDropOperation = false;
  181. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  182. FAllowTransferPresetAutoSelect = true;
  183. FCopyParamDefault = L"";
  184. FSynchronizeController = NULL;
  185. FPendingQueueActionItem = NULL;
  186. FLockLevel = 0;
  187. FLockSuspendLevel = 0;
  188. FDisabledOnLockSuspend = false;
  189. FAlternativeDelete = false;
  190. FTrayIcon = new ::TTrayIcon(0);
  191. FTrayIcon->OnClick = TrayIconClick;
  192. FMaxQueueLength = 0;
  193. FLastContextPopupScreenPoint = TPoint(-1, -1);
  194. FTransferResumeList = NULL;
  195. FMoveToQueue = false;
  196. StandaloneOperation = false;
  197. FOnFeedSynchronizeError = NULL;
  198. FOnSynchronizeAbort = NULL;
  199. FSynchronizeTerminal = NULL;
  200. FNeedSession = false;
  201. FDoNotIdleCurrentTerminal = 0;
  202. FIncrementalSearching = 0;
  203. FIncrementalSearchHaveNext = false;
  204. FQueueFileList.reset(new TQueueFileList());
  205. FEditorManager = new TEditorManager();
  206. FEditorManager->OnFileChange = ExecutedFileChanged;
  207. FEditorManager->OnFileReload = ExecutedFileReload;
  208. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  209. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  210. FLocalEditors = new TList();
  211. FQueueStatus = NULL;
  212. FQueueStatusSection = new TCriticalSection();
  213. FQueueStatusInvalidated = false;
  214. FQueueItemInvalidated = false;
  215. FQueueStatusUpdating = false;
  216. FQueueActedItem = NULL;
  217. FQueueController = new TQueueController(QueueView3);
  218. FUserActionTimer = new TTimer(this);
  219. FUserActionTimer->Enabled = false;
  220. FUserActionTimer->Interval = 10;
  221. FUserActionTimer->OnTimer = UserActionTimer;
  222. FNotes = new TStringList();
  223. FNoteTimer = new TTimer(this);
  224. FNoteTimer->Enabled = false;
  225. FNoteTimer->OnTimer = NoteTimer;
  226. FOnNoteClick = NULL;
  227. FOle32Library = LoadLibrary(L"Ole32.dll");
  228. FDragMoveCursor = FOle32Library != NULL ?
  229. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  230. UseSystemSettings(this);
  231. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  232. static_cast<TObject*>(GetComponent(fcTransferList)));
  233. DebugAssert(TransferList != NULL);
  234. FTransferListHoverIndex = -1;
  235. TransferList->OnChange = TransferListChange;
  236. TransferList->OnDrawItem = TransferListDrawItem;
  237. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  238. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  239. UseDesktopFont(SessionsPageControl);
  240. UpdateSessionsPageControlHeight();
  241. UseDesktopFont(RemoteDirView);
  242. UseDesktopFont(RemoteDriveView);
  243. UseDesktopFont(QueueView3);
  244. UseDesktopFont(QueueFileList);
  245. UseDesktopFont(QueueLabel);
  246. UseDesktopFont(RemoteStatusBar);
  247. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  248. QueueSplitter->ShowHint = true;
  249. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  250. QueueFileListSplitter->ShowHint = true;
  251. RemotePanelSplitter->ShowHint = true;
  252. UpdateImages();
  253. FCustomCommandMenu = CreateTBXPopupMenu(this);
  254. FCustomCommandLocalFileList = NULL;
  255. FCustomCommandRemoteFileList = NULL;
  256. FSessionColors = new TPngImageList(this);
  257. FSessionColors->ColorDepth = cd32Bit;
  258. AddFixedSessionImages();
  259. SessionsPageControl->Images = FSessionColors;
  260. UpdateQueueLabel();
  261. FRemoteDirViewWasFocused = true;
  262. CreateHiddenWindow();
  263. StartUpdates();
  264. }
  265. //---------------------------------------------------------------------------
  266. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  267. {
  268. FInvalid = true;
  269. // this has to be one of the very first things to do
  270. StopUpdateThread();
  271. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  272. TTerminalManager::Instance()->ScpExplorer = NULL;
  273. delete FCustomCommandLocalFileList;
  274. delete FCustomCommandRemoteFileList;
  275. delete FCustomCommandMenu;
  276. delete FTrayIcon;
  277. FTrayIcon = NULL;
  278. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  279. delete FEditorManager;
  280. ForceCloseLocalEditors();
  281. delete FLocalEditors;
  282. HideFileFindDialog();
  283. if (FDelayedDeletionTimer)
  284. {
  285. DoDelayedDeletion(NULL);
  286. SAFE_DESTROY(FDelayedDeletionTimer);
  287. }
  288. SAFE_DESTROY(FDelayedDeletionList);
  289. // sometimes we do not get DDEnd so the list is not released
  290. SAFE_DESTROY(FDDFileList);
  291. DebugAssert(FSynchronizeController == NULL);
  292. CloseHandle(FDDExtMutex);
  293. FDDExtMutex = NULL;
  294. FreeLibrary(FOle32Library);
  295. FOle32Library = NULL;
  296. FDragMoveCursor = NULL;
  297. DebugAssert(!FErrorList);
  298. if (FEverShown)
  299. {
  300. // when window is never shown (like when running command-line operation),
  301. // particularly window site is not restored correctly (BoundsRect value set
  302. // in RestoreForm gets lost during handle allocation), so we do not want
  303. // it to be stored
  304. StoreParams();
  305. }
  306. Terminal = NULL;
  307. Queue = NULL;
  308. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  309. NonVisualDataModule->ScpExplorer = NULL;
  310. delete FQueueController;
  311. FQueueController = NULL;
  312. delete FQueueStatusSection;
  313. FQueueStatusSection = NULL;
  314. delete FQueueStatus;
  315. FQueueStatus = NULL;
  316. delete FUserActionTimer;
  317. FUserActionTimer = NULL;
  318. delete FNoteTimer;
  319. delete FNotes;
  320. delete FNoteData;
  321. SAFE_DESTROY(FDocks);
  322. SessionsPageControl->Images = NULL;
  323. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  324. SAFE_DESTROY(FSessionColors);
  325. SAFE_DESTROY(FSessionsDragDropFilesEx);
  326. SAFE_DESTROY(FHistoryMenu[0][0]);
  327. SAFE_DESTROY(FHistoryMenu[0][1]);
  328. SAFE_DESTROY(FHistoryMenu[1][0]);
  329. SAFE_DESTROY(FHistoryMenu[1][1]);
  330. if (FHiddenWindow != NULL)
  331. {
  332. DestroyWindow(FHiddenWindow);
  333. FHiddenWindow = NULL;
  334. }
  335. }
  336. //---------------------------------------------------------------------------
  337. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  338. {
  339. std::unique_ptr<TSessionData> Data;
  340. if (!Session.IsEmpty())
  341. {
  342. bool DefaultsOnly;
  343. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  344. }
  345. TTerminalManager * Manager = TTerminalManager::Instance();
  346. for (int Index = 0; Index < Manager->Count; Index++)
  347. {
  348. TTerminal * Terminal = Manager->Terminals[Index];
  349. if (Session.IsEmpty() ||
  350. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  351. {
  352. if (Path.IsEmpty())
  353. {
  354. Terminal->ClearCaches();
  355. }
  356. else
  357. {
  358. Terminal->DirectoryModified(Path, true);
  359. }
  360. }
  361. }
  362. // We should flag a pending refresh for the background terminals or busy foreground terminals
  363. if (HasActiveTerminal() &&
  364. CanCommandLineFromAnotherInstance() &&
  365. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  366. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  367. {
  368. Terminal->ReloadDirectory();
  369. }
  370. }
  371. //---------------------------------------------------------------------------
  372. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  373. {
  374. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  375. size_t MessageSize = sizeof(TCopyDataMessage);
  376. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  377. if (Result)
  378. {
  379. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  380. Result = (Message.Version == TCopyDataMessage::Version1);
  381. if (Result)
  382. {
  383. switch (Message.Command)
  384. {
  385. case TCopyDataMessage::CommandCanCommandLine:
  386. Result = CanCommandLineFromAnotherInstance();
  387. break;
  388. case TCopyDataMessage::CommandCommandLine:
  389. {
  390. UnicodeString CommandLine(Message.CommandLine);
  391. Result = CommandLineFromAnotherInstance(CommandLine);
  392. }
  393. break;
  394. case TCopyDataMessage::RefreshPanel:
  395. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  396. break;
  397. case TCopyDataMessage::MainWindowCheck:
  398. Result = true;
  399. break;
  400. default:
  401. Result = false;
  402. break;
  403. }
  404. }
  405. }
  406. Message.Result = Result ? 1 : 0;
  407. }
  408. //---------------------------------------------------------------------------
  409. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  410. {
  411. WNDCLASS WindowClass = {0};
  412. WindowClass.lpfnWndProc = DefWindowProc;
  413. WindowClass.hInstance = HInstance;
  414. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  415. FHiddenWindow = NULL;
  416. if (RegisterClass(&WindowClass))
  417. {
  418. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  419. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  420. }
  421. }
  422. //---------------------------------------------------------------------------
  423. bool __fastcall TCustomScpExplorerForm::CanConsole()
  424. {
  425. return
  426. HasActiveTerminal() &&
  427. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  428. }
  429. //---------------------------------------------------------------------------
  430. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  431. {
  432. bool Result = Visible && !NonVisualDataModule->Busy;
  433. return Result;
  434. }
  435. //---------------------------------------------------------------------------
  436. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  437. const UnicodeString & CommandLine)
  438. {
  439. TProgramParams Params(CommandLine);
  440. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  441. if (Result)
  442. {
  443. NonVisualDataModule->StartBusy();
  444. try
  445. {
  446. // this action is initiated from another process,
  447. // so it's likely that our window is not visible,
  448. // and user won't see what is going on
  449. Application->BringToFront();
  450. // reload sessions as we may be asked to open a session
  451. // just stored by another instance
  452. StoredSessions->Reload();
  453. UnicodeString SessionName = Params.Param[1];
  454. std::unique_ptr<TObjectList> DataList(new TObjectList());
  455. try
  456. {
  457. UnicodeString DownloadFile; // unused
  458. int Flags = GetCommandLineParseUrlFlags(&Params);
  459. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this, Flags);
  460. }
  461. catch (EAbort &)
  462. {
  463. // Happens when opening session in PuTTY and in other situations,
  464. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  465. // to process the command-line on its own (or to pass it to yet another instance)
  466. }
  467. if (DataList->Count > 0)
  468. {
  469. TTerminalManager * Manager = TTerminalManager::Instance();
  470. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  471. }
  472. }
  473. __finally
  474. {
  475. NonVisualDataModule->EndBusy();
  476. }
  477. }
  478. return Result;
  479. }
  480. //---------------------------------------------------------------------------
  481. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  482. {
  483. if (FTerminal != value)
  484. {
  485. TerminalChanging();
  486. DoSetTerminal(value, false);
  487. }
  488. }
  489. //---------------------------------------------------------------------------
  490. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  491. {
  492. FTerminal = value;
  493. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  494. FAllowTransferPresetAutoSelect = false;
  495. try
  496. {
  497. TerminalChanged(Replace);
  498. }
  499. __finally
  500. {
  501. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  502. }
  503. if (Terminal != NULL)
  504. {
  505. TransferPresetAutoSelect();
  506. }
  507. }
  508. //---------------------------------------------------------------------------
  509. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  510. {
  511. DoSetTerminal(value, true);
  512. }
  513. //---------------------------------------------------------------------------
  514. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  515. {
  516. if (FTerminal != NULL)
  517. {
  518. UpdateTerminal(Terminal);
  519. }
  520. }
  521. //---------------------------------------------------------------------------
  522. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  523. {
  524. if (Terminal != NULL)
  525. {
  526. UpdateSessionColor((TColor)Terminal->StateData->Color);
  527. }
  528. DoTerminalListChanged();
  529. DebugAssert(!IsLocalBrowserMode());
  530. if (Replaced)
  531. {
  532. RemoteDirView->ReplaceTerminal(Terminal);
  533. }
  534. else
  535. {
  536. RemoteDirView->Terminal = Terminal;
  537. }
  538. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  539. if (Terminal != NULL)
  540. {
  541. if (Terminal->Active)
  542. {
  543. Terminal->RefreshDirectory();
  544. }
  545. if (WinConfiguration->PreservePanelState)
  546. {
  547. if (Terminal->RemoteExplorerState != NULL)
  548. {
  549. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  550. }
  551. else
  552. {
  553. DirView(osRemote)->ClearState();
  554. }
  555. }
  556. if (!Replaced && Terminal->Active)
  557. {
  558. InitStatusBar();
  559. }
  560. }
  561. UpdateTransferList();
  562. // Update panels Enable state before refreshing the labels
  563. UpdateControls();
  564. }
  565. //---------------------------------------------------------------------------
  566. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  567. {
  568. if (Queue != value)
  569. {
  570. if (FQueue != NULL)
  571. {
  572. FQueue->OnListUpdate = NULL;
  573. FQueue->OnQueueItemUpdate = NULL;
  574. }
  575. FQueue = value;
  576. if (FQueue != NULL)
  577. {
  578. DebugAssert(FQueue->OnListUpdate == NULL);
  579. FQueue->OnListUpdate = QueueListUpdate;
  580. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  581. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  582. }
  583. QueueChanged();
  584. }
  585. }
  586. //---------------------------------------------------------------------------
  587. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  588. TListItem * Item)
  589. {
  590. if (FQueueActedItem == Item)
  591. {
  592. FQueueActedItem = NULL;
  593. if ((QueueView3->PopupMenu != NULL) &&
  594. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  595. {
  596. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  597. ReleaseCapture();
  598. }
  599. }
  600. if (Item->Data == FPendingQueueActionItem)
  601. {
  602. FPendingQueueActionItem = NULL;
  603. }
  604. }
  605. //---------------------------------------------------------------------------
  606. bool TCustomScpExplorerForm::IsAnythingQueued()
  607. {
  608. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  609. }
  610. //---------------------------------------------------------------------------
  611. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  612. {
  613. {
  614. TGuard Guard(FQueueStatusSection);
  615. FQueueStatusInvalidated = false;
  616. if (FQueue != NULL)
  617. {
  618. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  619. }
  620. }
  621. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  622. {
  623. FMaxQueueLength = FQueueStatus->Count;
  624. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  625. }
  626. {
  627. TAutoFlag Flag(FQueueStatusUpdating);
  628. FQueueController->UpdateQueueStatus(FQueueStatus);
  629. }
  630. UpdateQueueFileList();
  631. SetQueueProgress();
  632. UpdateQueueView();
  633. bool IsEmpty = !IsAnythingQueued();
  634. if (IsEmpty && (Terminal != NULL))
  635. {
  636. TOnceDoneOperation OnceDoneOperation =
  637. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  638. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  639. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  640. {
  641. FQueue->Enabled = false;
  642. }
  643. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  644. {
  645. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  646. }
  647. }
  648. }
  649. //---------------------------------------------------------------------------
  650. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  651. {
  652. UnicodeString Result;
  653. if (FQueueStatus != NULL)
  654. {
  655. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  656. {
  657. TFileOperationProgressType * ProgressData =
  658. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  659. if ((ProgressData != NULL) && ProgressData->InProgress)
  660. {
  661. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  662. }
  663. }
  664. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  665. {
  666. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  667. }
  668. }
  669. return Result;
  670. }
  671. //---------------------------------------------------------------------------
  672. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  673. {
  674. ComponentVisible[fcQueueView] =
  675. (WinConfiguration->QueueView.Show == qvShow) ||
  676. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  677. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  678. }
  679. //---------------------------------------------------------------------------
  680. void __fastcall TCustomScpExplorerForm::QueueChanged()
  681. {
  682. if (FQueueStatus != NULL)
  683. {
  684. // UpdateFileList implementation relies on the status being recreated when session changes
  685. delete FQueueStatus;
  686. FQueueStatus = NULL;
  687. }
  688. UpdateQueueStatus(true);
  689. }
  690. //---------------------------------------------------------------------------
  691. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  692. {
  693. if (FQueue == Queue)
  694. {
  695. FQueueStatusInvalidated = true;
  696. }
  697. }
  698. //---------------------------------------------------------------------------
  699. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  700. TQueueItem * Item)
  701. {
  702. if (FQueue == Queue)
  703. {
  704. TGuard Guard(FQueueStatusSection);
  705. // this may be running in parallel with QueueChanged
  706. if (FQueueStatus != NULL)
  707. {
  708. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  709. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  710. {
  711. FRefreshLocalDirectory = (QueueItem == NULL) ||
  712. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  713. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  714. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  715. }
  716. if (QueueItem != NULL)
  717. {
  718. QueueItem->UserData = (void*)true;
  719. FQueueItemInvalidated = true;
  720. }
  721. }
  722. }
  723. }
  724. //---------------------------------------------------------------------------
  725. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  726. {
  727. // during standalone editing, we have no way to see/control queue,
  728. // so we have to always popup prompts automatically
  729. return StandaloneOperation || GUIConfiguration->QueueAutoPopup;
  730. }
  731. //---------------------------------------------------------------------------
  732. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  733. {
  734. if (FQueueStatus != NULL)
  735. {
  736. bool QueueAutoPopup = IsQueueAutoPopup();
  737. bool NeedRefresh = FQueueController->NeedRefresh();
  738. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  739. FQueueItemInvalidated = false;
  740. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  741. bool Updated = false;
  742. TQueueItemProxy * QueueItem;
  743. bool WasUserAction;
  744. for (int Index = 0; Index < Limit; Index++)
  745. {
  746. bool Update = false;
  747. QueueItem = FQueueStatus->Items[Index];
  748. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  749. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  750. (FPendingQueueActionItem == NULL))
  751. {
  752. FPendingQueueActionItem = QueueItem;
  753. FUserActionTimer->Enabled = true;
  754. }
  755. if ((bool)QueueItem->UserData)
  756. {
  757. QueueItem->UserData = (void*)false;
  758. QueueItem->Update();
  759. Updated = true;
  760. Update = true;
  761. }
  762. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  763. {
  764. Update = true;
  765. }
  766. if (Update)
  767. {
  768. FQueueController->RefreshQueueItem(QueueItem);
  769. }
  770. }
  771. if (Updated)
  772. {
  773. NonVisualDataModule->UpdateNonVisibleActions();
  774. SetQueueProgress();
  775. UpdateQueueFileList();
  776. }
  777. }
  778. }
  779. //---------------------------------------------------------------------------
  780. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  781. {
  782. if (FTaskbarList != NULL)
  783. {
  784. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  785. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  786. }
  787. }
  788. //---------------------------------------------------------------------------
  789. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  790. {
  791. if (Progress >= 0)
  792. {
  793. if (FTaskbarList != NULL)
  794. {
  795. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  796. }
  797. }
  798. else
  799. {
  800. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  801. }
  802. }
  803. //---------------------------------------------------------------------------
  804. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  805. {
  806. int OverallProgress;
  807. // FProgressForm is null when this is called from SetQueueProgress
  808. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  809. {
  810. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  811. }
  812. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  813. {
  814. OverallProgress = ProgressData->OverallProgress();
  815. }
  816. else
  817. {
  818. OverallProgress = -1;
  819. }
  820. SetTaskbarListProgressValue(OverallProgress);
  821. }
  822. //---------------------------------------------------------------------------
  823. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  824. {
  825. TTerminalManager::Instance()->QueueStatusUpdated();
  826. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  827. {
  828. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  829. {
  830. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  831. {
  832. TFileOperationProgressType * ProgressData = NULL;
  833. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  834. {
  835. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  836. }
  837. if ((ProgressData != NULL) &&
  838. ProgressData->InProgress)
  839. {
  840. SetTaskbarListProgressValue(ProgressData);
  841. }
  842. else
  843. {
  844. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  845. }
  846. }
  847. else
  848. {
  849. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  850. }
  851. }
  852. else
  853. {
  854. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  855. }
  856. }
  857. UpdateQueueLabel();
  858. }
  859. //---------------------------------------------------------------------------
  860. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  861. {
  862. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  863. if (FQueueStatus != NULL)
  864. {
  865. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  866. if (ActiveAndPendingPrimaryCount > 0)
  867. {
  868. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  869. }
  870. }
  871. QueueLabel->Caption = Caption;
  872. }
  873. //---------------------------------------------------------------------------
  874. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  875. {
  876. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  877. static_cast<TComponent*>(GetComponent(fcTransferList)));
  878. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  879. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  880. TransferList->Strings->BeginUpdate();
  881. try
  882. {
  883. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  884. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  885. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  886. if (FTransferDropDownHint.IsEmpty())
  887. {
  888. FTransferDropDownHint = TransferDropDown->Hint;
  889. }
  890. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  891. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  892. TransferDropDown->Text = StripHotkey(Name);
  893. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  894. (FTransferDropDownHint, StripHotkey(Name),
  895. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  896. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  897. // update the label, otherwise when it is updated only on the first draw
  898. // of the list, it is drawn "bold" for some reason
  899. FTransferListHoverIndex = TransferList->ItemIndex;
  900. UpdateTransferLabel();
  901. }
  902. __finally
  903. {
  904. TransferList->Strings->EndUpdate();
  905. }
  906. }
  907. //---------------------------------------------------------------------------
  908. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  909. {
  910. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  911. DebugAssert(Toolbar != NULL);
  912. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  913. }
  914. //---------------------------------------------------------------------------
  915. void __fastcall TCustomScpExplorerForm::UpdateActions()
  916. {
  917. TForm::UpdateActions();
  918. if (ComponentVisible[fcCustomCommandsBand])
  919. {
  920. UpdateCustomCommandsToolbar();
  921. }
  922. }
  923. //---------------------------------------------------------------------------
  924. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  925. {
  926. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  927. }
  928. //---------------------------------------------------------------------------
  929. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  930. {
  931. Color = GetBtnFaceColor();
  932. DebugAssert(Configuration && RemoteDirView);
  933. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  934. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  935. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  936. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  937. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  938. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  939. if (RemoteDirView->RowSelect != WinConfiguration->FullRowSelect)
  940. {
  941. RemoteDirView->RowSelect = WinConfiguration->FullRowSelect;
  942. // selection is not redrawn automatically when RowSelect changes
  943. RemoteDirView->Invalidate();
  944. }
  945. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  946. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  947. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  948. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  949. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  950. UpdateSessionsPageControlHeight();
  951. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  952. UpdateToolbarDisplayMode();
  953. UpdateTransferList();
  954. if (Terminal != NULL)
  955. {
  956. TransferPresetAutoSelect();
  957. }
  958. UpdateQueueView();
  959. UpdateControls();
  960. // this can be called even before constuctor finishes.
  961. if (FEditorManager != NULL)
  962. {
  963. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  964. }
  965. // this can be called even before constuctor finishes.
  966. if (FLocalEditors != NULL)
  967. {
  968. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  969. {
  970. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  971. }
  972. }
  973. if (ComponentVisible[fcCustomCommandsBand])
  974. {
  975. UpdateCustomCommandsToolbar();
  976. }
  977. // show only when keeping queue items forever,
  978. // otherwise, its enough to have in in the context menu
  979. QueueDeleteAllDoneQueueToolbarItem->Visible =
  980. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  981. if (FFileColorsCurrent != WinConfiguration->FileColors)
  982. {
  983. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  984. FFileColorsCurrent = WinConfiguration->FileColors;
  985. FileColorsChanged();
  986. }
  987. }
  988. //---------------------------------------------------------------------------
  989. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  990. {
  991. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  992. DirView->Invalidate();
  993. }
  994. //---------------------------------------------------------------------------
  995. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  996. {
  997. DoFileColorsChanged(RemoteDirView);
  998. }
  999. //---------------------------------------------------------------------------
  1000. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  1001. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  1002. void * /*Arg*/)
  1003. {
  1004. if (Token != NULL)
  1005. {
  1006. TForm * Editor = dynamic_cast<TForm*>(Token);
  1007. DebugAssert(Editor != NULL);
  1008. ReconfigureEditorForm(Editor);
  1009. }
  1010. }
  1011. //---------------------------------------------------------------------------
  1012. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1013. {
  1014. WinConfiguration->DDTransferConfirmation = asOn;
  1015. }
  1016. //---------------------------------------------------------------------------
  1017. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1018. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1019. {
  1020. // noop
  1021. }
  1022. //---------------------------------------------------------------------------
  1023. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1024. TTransferDirection Direction, TTransferType Type, bool Temp,
  1025. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1026. bool Confirm, bool DragDrop, int Options)
  1027. {
  1028. bool Result = true;
  1029. DebugAssert(HasActiveTerminal());
  1030. // these parameters are known in advance
  1031. int Params =
  1032. FLAGMASK(Type == ttMove, cpDelete);
  1033. bool ToTemp = (Temp && (Direction == tdToLocal));
  1034. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1035. {
  1036. bool DisableNewerOnly =
  1037. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1038. ToTemp;
  1039. Options |=
  1040. FLAGMASK(ToTemp, coTemp) |
  1041. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1042. coDoNotShowAgain;
  1043. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1044. int CopyParamAttrs = (Direction == tdToRemote ?
  1045. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1046. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1047. int OutputOptions =
  1048. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1049. cooDoNotShowAgain);
  1050. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1051. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1052. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1053. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1054. if (Result)
  1055. {
  1056. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1057. {
  1058. if (DragDrop)
  1059. {
  1060. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1061. {
  1062. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1063. NULL, 0, EnableDDTransferConfirmation, NULL);
  1064. }
  1065. WinConfiguration->DDTransferConfirmation = asOff;
  1066. }
  1067. else
  1068. {
  1069. WinConfiguration->ConfirmTransferring = false;
  1070. }
  1071. }
  1072. else
  1073. {
  1074. // User explicitly unchecked "do not show again",
  1075. // so show him the dialog the next time
  1076. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1077. {
  1078. WinConfiguration->DDTransferConfirmation = asOn;
  1079. }
  1080. }
  1081. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1082. }
  1083. }
  1084. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1085. {
  1086. Configuration->Usage->Inc(L"TransfersOnBackground");
  1087. // these parameter are known only after transfer dialog
  1088. Params |=
  1089. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1090. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1091. Result = false;
  1092. ClearTransferSourceSelection(Direction);
  1093. }
  1094. return Result;
  1095. }
  1096. //---------------------------------------------------------------------------
  1097. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1098. {
  1099. if (FOnFileOperationFinished != NULL)
  1100. {
  1101. FOnFileOperationFinished(UnicodeString(), true);
  1102. }
  1103. else
  1104. {
  1105. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1106. if (HasDirView[Side])
  1107. {
  1108. DirView(Side)->SelectAll(smNone);
  1109. }
  1110. }
  1111. }
  1112. //---------------------------------------------------------------------------
  1113. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1114. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1115. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1116. int Params)
  1117. {
  1118. DebugAssert(Queue != NULL);
  1119. bool SingleFile = false;
  1120. if (FileList->Count == 1)
  1121. {
  1122. if (Direction == tdToRemote)
  1123. {
  1124. UnicodeString FileName = FileList->Strings[0];
  1125. SingleFile = FileExists(ApiPath(FileName));
  1126. }
  1127. else
  1128. {
  1129. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1130. SingleFile = !File->IsDirectory;
  1131. }
  1132. }
  1133. TQueueItem * QueueItem;
  1134. if (Direction == tdToRemote)
  1135. {
  1136. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1137. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1138. }
  1139. else
  1140. {
  1141. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1142. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1143. }
  1144. AddQueueItem(Queue, QueueItem, Terminal);
  1145. }
  1146. //---------------------------------------------------------------------------
  1147. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1148. {
  1149. if (Queue->IsEmpty)
  1150. {
  1151. Terminal->QueueOperationStart = Now();
  1152. }
  1153. Queue->AddItem(QueueItem);
  1154. }
  1155. //---------------------------------------------------------------------------
  1156. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1157. {
  1158. }
  1159. //---------------------------------------------------------------------------
  1160. void __fastcall TCustomScpExplorerForm::InitControls()
  1161. {
  1162. DebugAssert(FDocks != NULL);
  1163. for (int Index = 0; Index < ComponentCount; Index++)
  1164. {
  1165. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1166. if ((Dock != NULL) && (Dock->Tag == 0))
  1167. {
  1168. FDocks->Add(Dock);
  1169. }
  1170. }
  1171. CollectItemsWithTextDisplayMode(this);
  1172. }
  1173. //---------------------------------------------------------------------------
  1174. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1175. {
  1176. ConfigurationChanged();
  1177. QueuePanel->Height =
  1178. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1179. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1180. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1181. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1182. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1183. QueueFileList->Height =
  1184. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1185. if (QueueFileList->Visible)
  1186. {
  1187. AdjustQueueLayout();
  1188. }
  1189. UpdateCustomCommandsToolbar();
  1190. }
  1191. //---------------------------------------------------------------------------
  1192. void __fastcall TCustomScpExplorerForm::StoreParams()
  1193. {
  1194. int APixelsPerInch = GetControlPixelsPerInch(this);
  1195. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1196. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1197. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1198. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1199. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1200. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1201. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1202. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1203. }
  1204. //---------------------------------------------------------------------------
  1205. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1206. {
  1207. if (!FFormRestored)
  1208. {
  1209. FFormRestored = true;
  1210. RestoreFormParams();
  1211. }
  1212. TForm::CreateParams(Params);
  1213. }
  1214. //---------------------------------------------------------------------------
  1215. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1216. {
  1217. DebugAssert(FDocks != NULL);
  1218. for (int Index = 0; Index < FDocks->Count; Index++)
  1219. {
  1220. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1221. }
  1222. }
  1223. //---------------------------------------------------------------------------
  1224. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1225. {
  1226. SetDockAllowDrag(true);
  1227. while (!ButtonsStr.IsEmpty())
  1228. {
  1229. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1230. UnicodeString Name = CutToChar(S, L'=', true);
  1231. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1232. {
  1233. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1234. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1235. {
  1236. while (!S.IsEmpty())
  1237. {
  1238. UnicodeString S2 = CutToChar(S, L',', true);
  1239. UnicodeString Name = CutToChar(S2, L':', true);
  1240. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1241. {
  1242. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1243. if (SameText(GetToolbarItemName(Item), Name))
  1244. {
  1245. // forward compatibility
  1246. UnicodeString S3 = CutToChar(S2, L':', true);
  1247. bool Visible = StrToIntDef(S3, 0);
  1248. Item->Visible = Visible;
  1249. }
  1250. }
  1251. }
  1252. }
  1253. }
  1254. }
  1255. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1256. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1257. }
  1258. //---------------------------------------------------------------------------
  1259. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1260. {
  1261. UnicodeString Result;
  1262. SetDockAllowDrag(true);
  1263. Result = ::GetToolbarsLayoutStr(this);
  1264. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1265. return Result;
  1266. }
  1267. //---------------------------------------------------------------------------
  1268. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1269. {
  1270. UnicodeString Result;
  1271. if (Item->Action != NULL)
  1272. {
  1273. Result = Item->Action->Name;
  1274. Result = RemoveSuffix(Result, L"Action", true);
  1275. }
  1276. else
  1277. {
  1278. Result = Item->Name;
  1279. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1280. Result = RemoveSuffix(Result, L"Item", true);
  1281. }
  1282. return Result;
  1283. }
  1284. //---------------------------------------------------------------------------
  1285. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1286. {
  1287. UnicodeString Result;
  1288. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1289. {
  1290. UnicodeString ToolbarStr;
  1291. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1292. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1293. {
  1294. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1295. {
  1296. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1297. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1298. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1299. // and save the changes here only.
  1300. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1301. {
  1302. UnicodeString Name = GetToolbarItemName(Item);
  1303. DebugAssert(Name.Pos(L"TBX") == 0);
  1304. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1305. }
  1306. }
  1307. }
  1308. if (!ToolbarStr.IsEmpty())
  1309. {
  1310. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1311. }
  1312. }
  1313. return Result;
  1314. }
  1315. //---------------------------------------------------------------------------
  1316. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1317. {
  1318. DebugAssert(FProgressForm == NULL);
  1319. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1320. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1321. FProgressForm->DeleteLocalToRecycleBin =
  1322. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1323. FProgressForm->DeleteRemoteToRecycleBin =
  1324. (Terminal != NULL) &&
  1325. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1326. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1327. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1328. LockWindow();
  1329. // Actually, do not know what hides the progress once the operation finishes
  1330. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1331. SetTaskbarListProgressState(TBPF_NORMAL);
  1332. }
  1333. //---------------------------------------------------------------------------
  1334. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1335. {
  1336. UnlockWindow();
  1337. SAFE_DESTROY(FProgressForm);
  1338. SetQueueProgress();
  1339. }
  1340. //---------------------------------------------------------------------------
  1341. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1342. TFileOperationProgressType & ProgressData)
  1343. {
  1344. // Download to temporary local directory
  1345. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1346. {
  1347. bool Continue = true;
  1348. FPendingTempSpaceWarn = false;
  1349. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1350. if (!Continue)
  1351. {
  1352. Abort();
  1353. }
  1354. }
  1355. // operation is being executed and we still didn't show up progress form
  1356. if (ProgressData.InProgress && !FProgressForm)
  1357. {
  1358. CreateProgressForm(NULL);
  1359. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1360. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1361. }
  1362. // operation is finished (or terminated), so we hide progress form
  1363. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1364. {
  1365. DestroyProgressForm();
  1366. if (ProgressData.Operation == foCalculateSize)
  1367. {
  1368. // When calculating size before transfer, the abort caused by
  1369. // cancel flag set due to "MoveToQueue" below,
  1370. // is not propagated back to us in ExecuteFileOperation,
  1371. // as it is silently swallowed.
  1372. // So we explicitly (re)throw it here.
  1373. if (FMoveToQueue)
  1374. {
  1375. Abort();
  1376. }
  1377. }
  1378. else
  1379. {
  1380. if ((ProgressData.Cancel == csContinue) &&
  1381. !FAutoOperation)
  1382. {
  1383. OperationComplete(ProgressData.StartTime);
  1384. }
  1385. }
  1386. }
  1387. if (FProgressForm &&
  1388. // Can happen only during synchronization, when ending one of the operations
  1389. ProgressData.InProgress)
  1390. {
  1391. FProgressForm->SetProgressData(ProgressData);
  1392. DebugAssert(ProgressData.InProgress);
  1393. SetTaskbarListProgressValue(&ProgressData);
  1394. if (FProgressForm->Cancel > csContinue)
  1395. {
  1396. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1397. if (FProgressForm->Cancel == csCancelFile)
  1398. {
  1399. FProgressForm->ClearCancel();
  1400. }
  1401. // cancel cancels even the move
  1402. FMoveToQueue = false;
  1403. }
  1404. else if (FProgressForm->MoveToQueue)
  1405. {
  1406. FMoveToQueue = true;
  1407. ProgressData.SetCancelAtLeast(csCancel);
  1408. }
  1409. if ((FTransferResumeList != NULL) &&
  1410. ProgressData.InProgress &&
  1411. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1412. !ProgressData.FullFileName.IsEmpty())
  1413. {
  1414. if ((FTransferResumeList->Count == 0) ||
  1415. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1416. {
  1417. // note that we do not recognize directories from files here
  1418. FTransferResumeList->Add(ProgressData.FullFileName);
  1419. }
  1420. }
  1421. }
  1422. }
  1423. //---------------------------------------------------------------------------
  1424. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1425. const TDateTime & StartTime)
  1426. {
  1427. if (GUIConfiguration->BeepOnFinish &&
  1428. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1429. {
  1430. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1431. DWORD Sound;
  1432. if (!ExtractFileExt(BeepSound).IsEmpty())
  1433. {
  1434. Sound = SND_FILENAME;
  1435. }
  1436. else
  1437. {
  1438. Sound = SND_ALIAS;
  1439. }
  1440. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1441. }
  1442. }
  1443. //---------------------------------------------------------------------------
  1444. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1445. TFileOperationProgressType & ProgressData)
  1446. {
  1447. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1448. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1449. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1450. FileOperationProgress(ProgressData);
  1451. }
  1452. //---------------------------------------------------------------------------
  1453. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1454. {
  1455. UnicodeString Result;
  1456. if (FProgressForm != NULL)
  1457. {
  1458. Result = FProgressForm->ProgressStr();
  1459. }
  1460. return Result;
  1461. }
  1462. //---------------------------------------------------------------------------
  1463. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1464. bool DragDrop)
  1465. {
  1466. return (!DragDrop && (DropSourceControl == NULL)) ||
  1467. (DropSourceControl == DirView(osOther));
  1468. }
  1469. //---------------------------------------------------------------------------
  1470. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1471. TFileOperation Operation, TOperationSide Side,
  1472. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1473. TOnceDoneOperation & OnceDoneOperation)
  1474. {
  1475. if (!FAutoOperation)
  1476. {
  1477. // no selection on "/upload", form serves only as event handler
  1478. // (it is not displayed)
  1479. if (PanelOperation(Side, FDragDropOperation) &&
  1480. Visible && (Operation != foCalculateSize) &&
  1481. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1482. {
  1483. if (FOnFileOperationFinished != NULL)
  1484. {
  1485. FOnFileOperationFinished(FileName, Success);
  1486. }
  1487. else
  1488. {
  1489. TCustomDirView * DView = DirView(Side);
  1490. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(Side));
  1491. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1492. // this can happen when local drive is unplugged in the middle of the operation
  1493. if (Item != NULL)
  1494. {
  1495. if (Success) Item->Selected = false;
  1496. DView->MakeProgressVisible(Item);
  1497. }
  1498. }
  1499. }
  1500. if ((Operation == foCopy) || (Operation == foMove))
  1501. {
  1502. DebugAssert(!IsLocalBrowserMode());
  1503. if (Side == osLocal)
  1504. {
  1505. Configuration->Usage->Inc(L"UploadedFiles");
  1506. }
  1507. else
  1508. {
  1509. Configuration->Usage->Inc(L"DownloadedFiles");
  1510. }
  1511. }
  1512. }
  1513. if (Success && (FSynchronizeController != NULL))
  1514. {
  1515. DebugAssert(!IsSideLocalBrowser(osRemote));
  1516. if (Operation == foCopy)
  1517. {
  1518. DebugAssert(Side == osLocal);
  1519. FSynchronizeController->LogOperation(soUpload, FileName);
  1520. }
  1521. else if (Operation == foDelete)
  1522. {
  1523. DebugAssert(Side == osRemote);
  1524. FSynchronizeController->LogOperation(soDelete, FileName);
  1525. }
  1526. }
  1527. if (FProgressForm)
  1528. {
  1529. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1530. }
  1531. }
  1532. //---------------------------------------------------------------------------
  1533. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1534. TFileOperation Operation, TOperationSide Side,
  1535. bool Temp, const UnicodeString & FileName, Boolean Success,
  1536. TOnceDoneOperation & OnceDoneOperation)
  1537. {
  1538. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1539. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1540. OnceDoneOperation);
  1541. }
  1542. //---------------------------------------------------------------------------
  1543. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1544. {
  1545. return false;
  1546. }
  1547. //---------------------------------------------------------------------------
  1548. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1549. {
  1550. return false;
  1551. }
  1552. //---------------------------------------------------------------------------
  1553. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1554. {
  1555. return NULL;
  1556. }
  1557. //---------------------------------------------------------------------------
  1558. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1559. {
  1560. DebugAssert(GetSide(Side) == osRemote);
  1561. DebugUsedParam(Side);
  1562. return RemoteDirView;
  1563. }
  1564. //---------------------------------------------------------------------------
  1565. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1566. {
  1567. DebugAssert(GetSide(Side) == osRemote);
  1568. DebugUsedParam(Side);
  1569. return RemoteDriveView;
  1570. }
  1571. //---------------------------------------------------------------------------
  1572. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1573. {
  1574. DebugAssert(GetSide(Side) == osRemote);
  1575. DebugUsedParam(Side);
  1576. return HasActiveTerminal();
  1577. }
  1578. //---------------------------------------------------------------------------
  1579. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1580. TOperationSide Side, int FilesOnly)
  1581. {
  1582. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1583. }
  1584. //---------------------------------------------------------------------------
  1585. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1586. TOperationSide Side, int FilesOnly)
  1587. {
  1588. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1589. }
  1590. //---------------------------------------------------------------------------
  1591. struct THistoryItemData
  1592. {
  1593. short int Side;
  1594. short int Index;
  1595. };
  1596. //---------------------------------------------------------------------------
  1597. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1598. {
  1599. DirView(Side)->HistoryGo(Index);
  1600. }
  1601. //---------------------------------------------------------------------------
  1602. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1603. {
  1604. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1605. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1606. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1607. }
  1608. //---------------------------------------------------------------------------
  1609. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1610. bool Back)
  1611. {
  1612. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1613. {
  1614. TCustomDirView * DView = DirView(Side);
  1615. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1616. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1617. if (ICount > 10)
  1618. {
  1619. ICount = 10;
  1620. }
  1621. Menu->Items->Clear();
  1622. THistoryItemData Data;
  1623. Data.Side = Side;
  1624. for (short int i = 1; i <= ICount; i++)
  1625. {
  1626. TTBCustomItem * Item = new TTBXItem(Menu);
  1627. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1628. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1629. Item->Hint = DView->HistoryPath[Data.Index];
  1630. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1631. Item->Tag = *reinterpret_cast<int*>(&Data);
  1632. Item->OnClick = HistoryItemClick;
  1633. Menu->Items->Add(Item);
  1634. }
  1635. }
  1636. }
  1637. //---------------------------------------------------------------------------
  1638. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1639. TOperationSide Side, bool Back)
  1640. {
  1641. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1642. {
  1643. // workaround
  1644. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1645. // operator new allocates memory in Pascal code, but calls inline
  1646. // contructor in C++, leading in problems, the function does
  1647. // both in Pascal code
  1648. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1649. UpdateHistoryMenu(Side, Back);
  1650. }
  1651. return FHistoryMenu[Side == osLocal][Back];
  1652. }
  1653. //---------------------------------------------------------------------------
  1654. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1655. TCustomDirView *Sender)
  1656. {
  1657. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1658. UpdateHistoryMenu(Side, true);
  1659. UpdateHistoryMenu(Side, false);
  1660. }
  1661. //---------------------------------------------------------------------------
  1662. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1663. {
  1664. // remote custom commands can be executed only if the server supports shell commands
  1665. // or have secondary shell
  1666. return HasActiveTerminal() && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1667. }
  1668. //---------------------------------------------------------------------------
  1669. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1670. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1671. {
  1672. // -1 = hidden, 0 = disabled, 1 = enabled
  1673. int Result;
  1674. TFileCustomCommand RemoteCustomCommand;
  1675. TLocalCustomCommand LocalCustomCommand;
  1676. TFileCustomCommand * NonInteractiveCustomCommand =
  1677. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1678. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1679. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1680. if (FLAGCLEAR(Command.Params, ccLocal))
  1681. {
  1682. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1683. // custom command that does not operate with files can be executed anytime ...
  1684. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1685. {
  1686. // ... but do not show such command in remote file menu
  1687. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1688. {
  1689. Result = AllowedState;
  1690. }
  1691. else
  1692. {
  1693. Result = -1;
  1694. }
  1695. }
  1696. else
  1697. {
  1698. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1699. {
  1700. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1701. }
  1702. else
  1703. {
  1704. Result = -1;
  1705. }
  1706. }
  1707. }
  1708. else
  1709. {
  1710. // custom command that does not operate with files can be executed anytime
  1711. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1712. {
  1713. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1714. }
  1715. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1716. {
  1717. if ((ListType == ccltAll) || (ListType == ccltFile))
  1718. {
  1719. // special case is "diff"-style command that can be executed over any side,
  1720. // if we have both sides
  1721. Result =
  1722. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1723. // directly (instead of EnableSelectedOperation) to pass
  1724. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1725. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1726. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1727. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1728. }
  1729. else if (ListType == ccltBoth)
  1730. {
  1731. DebugAssert(!IsLocalBrowserMode());
  1732. Result = 1;
  1733. }
  1734. else
  1735. {
  1736. Result = -1;
  1737. }
  1738. }
  1739. else
  1740. {
  1741. if ((ListType == ccltAll) ||
  1742. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1743. {
  1744. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1745. }
  1746. else
  1747. {
  1748. Result = -1;
  1749. }
  1750. }
  1751. if ((Result > 0) &&
  1752. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1753. !HasActiveTerminal())
  1754. {
  1755. Result = 0;
  1756. }
  1757. }
  1758. return Result;
  1759. }
  1760. //---------------------------------------------------------------------------
  1761. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1762. TStrings * FileList, const TCustomCommandType & ACommand,
  1763. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1764. {
  1765. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1766. {
  1767. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1768. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1769. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1770. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1771. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1772. bool Capture =
  1773. FLAGSET(ACommand.Params, ccShowResults) ||
  1774. FLAGSET(ACommand.Params, ccCopyResults) ||
  1775. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1776. TCaptureOutputEvent OutputEvent = NULL;
  1777. DebugAssert(FCapturedLog == NULL);
  1778. if (Capture)
  1779. {
  1780. FCapturedLog = new TStringList();
  1781. OutputEvent = TerminalCaptureLog;
  1782. }
  1783. try
  1784. {
  1785. if (!RemoteCustomCommand.IsFileCommand(Command))
  1786. {
  1787. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1788. OutputEvent);
  1789. }
  1790. else
  1791. {
  1792. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1793. }
  1794. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1795. {
  1796. if (FLAGSET(ACommand.Params, ccCopyResults))
  1797. {
  1798. CopyToClipboard(FCapturedLog);
  1799. }
  1800. if (FLAGSET(ACommand.Params, ccShowResults))
  1801. {
  1802. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1803. }
  1804. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1805. {
  1806. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1807. }
  1808. }
  1809. }
  1810. __finally
  1811. {
  1812. SAFE_DESTROY(FCapturedLog);
  1813. }
  1814. }
  1815. }
  1816. //---------------------------------------------------------------------------
  1817. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1818. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1819. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1820. {
  1821. DebugAssert(!IsLocalBrowserMode());
  1822. TStrings * LocalFileList = NULL;
  1823. TStrings * RemoteFileList = NULL;
  1824. TStrings * RemoteFileListFull = NULL;
  1825. try
  1826. {
  1827. if (LocalFileCommand)
  1828. {
  1829. if (ALocalFileList == NULL)
  1830. {
  1831. DebugAssert(HasDirView[osLocal]);
  1832. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1833. // directly (instead of EnableSelectedOperation) to pass
  1834. // false to FocusedFileOnlyWhenFocused
  1835. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1836. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1837. }
  1838. else
  1839. {
  1840. LocalFileList = ALocalFileList;
  1841. }
  1842. if (FileListCommand)
  1843. {
  1844. if (LocalFileList->Count != 1)
  1845. {
  1846. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1847. }
  1848. }
  1849. else
  1850. {
  1851. if ((LocalFileList->Count != 1) &&
  1852. (FileList->Count != 1) &&
  1853. (LocalFileList->Count != FileList->Count))
  1854. {
  1855. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1856. }
  1857. }
  1858. }
  1859. UnicodeString RootTempDir;
  1860. UnicodeString TempDir;
  1861. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1862. if (!RemoteFiles)
  1863. {
  1864. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1865. }
  1866. try
  1867. {
  1868. TDateTimes RemoteFileTimes;
  1869. if (RemoteFiles)
  1870. {
  1871. RemoteFileList = FileList;
  1872. }
  1873. else
  1874. {
  1875. RemoteFileList = new TStringList();
  1876. TMakeLocalFileListParams MakeFileListParam;
  1877. MakeFileListParam.FileList = RemoteFileList;
  1878. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1879. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1880. MakeFileListParam.Recursive =
  1881. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1882. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1883. if (!MakeFileListParam.Recursive)
  1884. {
  1885. RemoteFileTimes.clear();
  1886. RemoteFileListFull = new TStringList();
  1887. MakeFileListParam.FileList = RemoteFileListFull;
  1888. MakeFileListParam.Recursive = true;
  1889. MakeFileListParam.IncludeDirs = false;
  1890. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1891. }
  1892. else
  1893. {
  1894. RemoteFileListFull = RemoteFileList;
  1895. }
  1896. }
  1897. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1898. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1899. if (!NonBlocking)
  1900. {
  1901. int Count;
  1902. if (FileListCommand)
  1903. {
  1904. Count = 1;
  1905. }
  1906. else if (LocalFileCommand)
  1907. {
  1908. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1909. }
  1910. else
  1911. {
  1912. Count = RemoteFileList->Count;
  1913. }
  1914. Progress.Start(foCustomCommand, osRemote, Count);
  1915. DebugAssert(FProgressForm != NULL);
  1916. FProgressForm->ReadOnly = true;
  1917. }
  1918. try
  1919. {
  1920. if (FileListCommand)
  1921. {
  1922. UnicodeString LocalFile;
  1923. // MakeFileList does not delimit filenames
  1924. UnicodeString FileList = MakeFileList(RemoteFileList);
  1925. if (LocalFileCommand)
  1926. {
  1927. DebugAssert(LocalFileList->Count == 1);
  1928. LocalFile = LocalFileList->Strings[0];
  1929. }
  1930. TLocalCustomCommand CustomCommand(Data,
  1931. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1932. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1933. if (NonBlocking)
  1934. {
  1935. DebugAssert(!POutput);
  1936. ExecuteShellChecked(ShellCommand);
  1937. }
  1938. else
  1939. {
  1940. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1941. }
  1942. }
  1943. else if (LocalFileCommand)
  1944. {
  1945. if (LocalFileList->Count == 1)
  1946. {
  1947. UnicodeString LocalFile = LocalFileList->Strings[0];
  1948. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1949. {
  1950. UnicodeString FileName = RemoteFileList->Strings[Index];
  1951. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1952. Progress.SetFile(FileNameForProgress);
  1953. TLocalCustomCommand CustomCommand(Data,
  1954. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1955. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1956. TOnceDoneOperation OnceDoneOperation;
  1957. // Do not unselect anything, as it won't work with two panels anyway
  1958. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1959. }
  1960. }
  1961. else if (RemoteFileList->Count == 1)
  1962. {
  1963. UnicodeString FileName = RemoteFileList->Strings[0];
  1964. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1965. {
  1966. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1967. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1968. Progress.SetFile(LocalFileNameOnly);
  1969. TLocalCustomCommand CustomCommand(
  1970. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1971. FileName, LocalFileName, L"");
  1972. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1973. TOnceDoneOperation OnceDoneOperation;
  1974. // Do not unselect anything, as it won't work with two panels anyway
  1975. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1976. }
  1977. }
  1978. else
  1979. {
  1980. if (LocalFileList->Count != RemoteFileList->Count)
  1981. {
  1982. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1983. }
  1984. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1985. {
  1986. UnicodeString FileName = RemoteFileList->Strings[Index];
  1987. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1988. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1989. Progress.SetFile(LocalFileNameOnly); // sic
  1990. TLocalCustomCommand CustomCommand(
  1991. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1992. FileName, LocalFileName, L"");
  1993. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1994. TOnceDoneOperation OnceDoneOperation;
  1995. // Do not unselect anything, as it won't work with two panels anyway
  1996. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1997. }
  1998. }
  1999. }
  2000. else
  2001. {
  2002. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2003. {
  2004. UnicodeString FileName = RemoteFileList->Strings[Index];
  2005. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2006. Progress.SetFile(FileNameForProgress);
  2007. TLocalCustomCommand CustomCommand(Data,
  2008. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2009. FileName, L"", L"");
  2010. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2011. TOnceDoneOperation OnceDoneOperation;
  2012. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2013. }
  2014. }
  2015. }
  2016. __finally
  2017. {
  2018. if (!NonBlocking)
  2019. {
  2020. Progress.Stop();
  2021. }
  2022. }
  2023. DebugAssert(!FAutoOperation);
  2024. if (!RemoteFiles)
  2025. {
  2026. TempDir = IncludeTrailingBackslash(TempDir);
  2027. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2028. {
  2029. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2030. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2031. // Skip directories, process only nested files.
  2032. // The check is redundant as FileAge fails for directories anyway.
  2033. !DirectoryExists(FileName))
  2034. {
  2035. UnicodeString RemoteDir =
  2036. UnixExtractFileDir(
  2037. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2038. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2039. TDateTime NewTime;
  2040. if (FileAge(FileName, NewTime) &&
  2041. (NewTime != RemoteFileTimes[Index]))
  2042. {
  2043. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2044. TemporaryFileCopyParam(CopyParam);
  2045. CopyParam.FileMask = L"";
  2046. FAutoOperation = true;
  2047. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2048. TemporaryFilesList->Add(FileName);
  2049. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2050. }
  2051. }
  2052. }
  2053. }
  2054. }
  2055. __finally
  2056. {
  2057. FAutoOperation = false;
  2058. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2059. {
  2060. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2061. }
  2062. }
  2063. }
  2064. __finally
  2065. {
  2066. if (RemoteFileList != FileList)
  2067. {
  2068. delete RemoteFileList;
  2069. }
  2070. if (LocalFileList != ALocalFileList)
  2071. {
  2072. delete LocalFileList;
  2073. }
  2074. if (RemoteFileListFull != RemoteFileList)
  2075. {
  2076. delete RemoteFileListFull;
  2077. }
  2078. }
  2079. }
  2080. //---------------------------------------------------------------------------
  2081. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2082. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2083. bool FileListCommand, UnicodeString * POutput)
  2084. {
  2085. std::unique_ptr<TStrings> SelectedFileList(DirView(osLocal)->CreateFileList(false, true, NULL));
  2086. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2087. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2088. {
  2089. UnicodeString FileName = SelectedFileList->Strings[Index];
  2090. if (DirectoryExists(FileName))
  2091. {
  2092. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2093. {
  2094. LocalFileList->Add(FileName);
  2095. }
  2096. if (FLAGSET(ACommand.Params, ccRecursive))
  2097. {
  2098. TMakeLocalFileListParams MakeFileListParam;
  2099. MakeFileListParam.FileList = LocalFileList.get();
  2100. MakeFileListParam.FileTimes = NULL;
  2101. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2102. MakeFileListParam.Recursive = true;
  2103. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2104. }
  2105. }
  2106. else
  2107. {
  2108. LocalFileList->Add(FileName);
  2109. }
  2110. }
  2111. UnicodeString RemotePath;
  2112. if (Terminal != NULL)
  2113. {
  2114. RemotePath = Terminal->CurrentDirectory;
  2115. }
  2116. if (FileListCommand)
  2117. {
  2118. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2119. TLocalCustomCommand CustomCommand(
  2120. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2121. L"", L"", FileList);
  2122. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2123. }
  2124. else
  2125. {
  2126. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2127. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2128. DebugAssert(FProgressForm != NULL);
  2129. FProgressForm->ReadOnly = true;
  2130. try
  2131. {
  2132. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2133. {
  2134. UnicodeString FileName = LocalFileList->Strings[Index];
  2135. Progress.SetFile(FileName);
  2136. TLocalCustomCommand CustomCommand(
  2137. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2138. FileName, L"", L"");
  2139. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2140. TOnceDoneOperation OnceDoneOperation;
  2141. Progress.Finish(FileName, true, OnceDoneOperation);
  2142. }
  2143. }
  2144. __finally
  2145. {
  2146. Progress.Stop();
  2147. }
  2148. }
  2149. }
  2150. //---------------------------------------------------------------------------
  2151. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2152. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2153. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2154. {
  2155. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2156. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2157. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2158. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2159. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2160. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2161. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2162. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2163. std::unique_ptr<UnicodeString> POutput;
  2164. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2165. FLAGSET(ACommand.Params, ccCopyResults))
  2166. {
  2167. POutput.reset(new UnicodeString());
  2168. }
  2169. if (!LocalCustomCommand.IsFileCommand(Command))
  2170. {
  2171. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2172. }
  2173. // remote files?
  2174. else if ((FCurrentSide == osRemote) || LocalFileCommand)
  2175. {
  2176. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2177. }
  2178. // local files
  2179. else
  2180. {
  2181. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2182. }
  2183. if (POutput.get() != NULL)
  2184. {
  2185. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2186. int P = POutput->Pos(sLineBreak);
  2187. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2188. {
  2189. POutput->SetLength(P - 1);
  2190. }
  2191. // Copy even empty output to clipboard
  2192. if (FLAGSET(ACommand.Params, ccCopyResults))
  2193. {
  2194. CopyToClipboard(*POutput);
  2195. }
  2196. // But do not show an empty message box.
  2197. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2198. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2199. !POutput->IsEmpty())
  2200. {
  2201. TClipboardHandler ClipboardHandler;
  2202. ClipboardHandler.Text = *POutput;
  2203. TMessageParams Params;
  2204. TQueryButtonAlias Aliases[1];
  2205. Aliases[0].Button = qaRetry;
  2206. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2207. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2208. Params.Aliases = Aliases;
  2209. Params.AliasesCount = LENOF(Aliases);
  2210. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2211. }
  2212. }
  2213. }
  2214. //---------------------------------------------------------------------------
  2215. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2216. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2217. {
  2218. TCustomCommandData Data;
  2219. UnicodeString Site;
  2220. UnicodeString RemotePath;
  2221. if (HasActiveTerminal())
  2222. {
  2223. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2224. Data = TCustomCommandData(SessionData.get());
  2225. Site = Terminal->SessionData->SessionKey;
  2226. RemotePath = Terminal->CurrentDirectory;
  2227. }
  2228. UnicodeString HelpKeyword = ACommand.HomePage;
  2229. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2230. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2231. {
  2232. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2233. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2234. {
  2235. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2236. }
  2237. else
  2238. {
  2239. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2240. }
  2241. if (!DoCustomCommandOptionsDialog(
  2242. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2243. {
  2244. Abort();
  2245. }
  2246. }
  2247. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2248. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2249. {
  2250. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2251. }
  2252. else
  2253. {
  2254. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2255. }
  2256. }
  2257. //---------------------------------------------------------------------------
  2258. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2259. const TCustomCommandType & Command)
  2260. {
  2261. DebugAssert(FCustomCommandLocalFileList != NULL);
  2262. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2263. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2264. TStrings * LocalFileList = new TStringList();
  2265. TStrings * RemoteFileList = new TStringList();
  2266. try
  2267. {
  2268. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2269. {
  2270. LocalFileList->Clear();
  2271. LocalFileList->AddObject(
  2272. FCustomCommandLocalFileList->Strings[Index],
  2273. FCustomCommandLocalFileList->Objects[Index]);
  2274. RemoteFileList->Clear();
  2275. RemoteFileList->AddObject(
  2276. FCustomCommandRemoteFileList->Strings[Index],
  2277. FCustomCommandRemoteFileList->Objects[Index]);
  2278. CustomCommand(RemoteFileList, Command, LocalFileList);
  2279. }
  2280. }
  2281. __finally
  2282. {
  2283. delete LocalFileList;
  2284. delete RemoteFileList;
  2285. }
  2286. }
  2287. //---------------------------------------------------------------------------
  2288. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2289. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2290. {
  2291. delete FCustomCommandLocalFileList;
  2292. delete FCustomCommandRemoteFileList;
  2293. // takeover ownership,
  2294. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2295. FCustomCommandLocalFileList = LocalFileList;
  2296. FCustomCommandRemoteFileList = RemoteFileList;
  2297. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2298. if (Button != NULL)
  2299. {
  2300. FCustomCommandMenu->Items->Clear();
  2301. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2302. MenuPopup(FCustomCommandMenu, Button);
  2303. }
  2304. else
  2305. {
  2306. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2307. }
  2308. }
  2309. //---------------------------------------------------------------------------
  2310. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2311. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2312. {
  2313. DebugAssert(FCapturedLog != NULL);
  2314. if ((OutputType == cotOutput) || (OutputType == cotError))
  2315. {
  2316. FCapturedLog->Add(AddedLine);
  2317. }
  2318. }
  2319. //---------------------------------------------------------------------------
  2320. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2321. TOperationSide Side)
  2322. {
  2323. return
  2324. (Side == osOther) &&
  2325. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2326. }
  2327. //---------------------------------------------------------------------------
  2328. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2329. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2330. {
  2331. TTBItemOptions O;
  2332. O = Item->Options;
  2333. TCustomDirView * DView = DirView(Side);
  2334. if ((DView->ItemFocused != NULL) &&
  2335. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2336. // when resolving links is disabled, default action is to enter the directory,
  2337. // no matter what DoubleClickAction is configured to
  2338. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2339. // Can only Edit files, but can Open/Copy even directories
  2340. ((DoubleClickAction != dcaEdit) ||
  2341. !DView->ItemIsDirectory(DView->ItemFocused)))
  2342. {
  2343. Item->Options = O << tboDefault;
  2344. }
  2345. else
  2346. {
  2347. Item->Options = O >> tboDefault;
  2348. }
  2349. }
  2350. //---------------------------------------------------------------------------
  2351. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2352. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2353. {
  2354. TCustomDirView * DView = DirView(Side);
  2355. TListItem * Item = DView->ItemFocused;
  2356. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2357. EnableFocusedOperation[Side])
  2358. {
  2359. TPoint ClientPoint;
  2360. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2361. TPoint(0, 0) : MousePos;
  2362. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2363. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2364. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2365. }
  2366. }
  2367. //---------------------------------------------------------------------------
  2368. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2369. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2370. {
  2371. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2372. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2373. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2374. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2375. Handled = true;
  2376. }
  2377. //---------------------------------------------------------------------------
  2378. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2379. {
  2380. }
  2381. //---------------------------------------------------------------------------
  2382. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2383. {
  2384. DebugAssert(FErrorList == NULL);
  2385. if (WinConfiguration->ContinueOnError)
  2386. {
  2387. FErrorList = new TStringList();
  2388. Configuration->Usage->Inc(L"ContinuationsOnError");
  2389. }
  2390. NonVisualDataModule->StartBusy();
  2391. }
  2392. //---------------------------------------------------------------------------
  2393. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2394. {
  2395. NonVisualDataModule->EndBusy();
  2396. if (FErrorList)
  2397. {
  2398. HandleErrorList(FErrorList);
  2399. }
  2400. }
  2401. //---------------------------------------------------------------------------
  2402. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2403. const TCopyParamType & CopyParam)
  2404. {
  2405. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2406. {
  2407. Configuration->Usage->Inc(L"FileMaskUses");
  2408. }
  2409. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2410. {
  2411. Configuration->Usage->Inc(L"OperationMaskUses");
  2412. }
  2413. }
  2414. //---------------------------------------------------------------------------
  2415. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2416. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2417. {
  2418. DebugAssert(!IsLocalBrowserMode());
  2419. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2420. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2421. TTransferOperationParam DefaultParam;
  2422. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2423. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2424. switch (Param.Queue)
  2425. {
  2426. case asOn:
  2427. CopyParam.Queue = true;
  2428. break;
  2429. case asOff:
  2430. CopyParam.Queue = false;
  2431. break;
  2432. case asAuto:
  2433. default:
  2434. // keep default
  2435. break;
  2436. }
  2437. bool Result =
  2438. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2439. if (Result)
  2440. {
  2441. DebugAssert(Terminal);
  2442. bool SelectionRestored = false;
  2443. TCustomDirView * DView = NULL;
  2444. if (HasDirView[Side])
  2445. {
  2446. DView = DirView(Side);
  2447. DView->SaveSelection();
  2448. DView->SaveSelectedNames();
  2449. }
  2450. UpdateCopyParamCounters(CopyParam);
  2451. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2452. DebugAssert(FTransferResumeList == NULL);
  2453. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2454. FMoveToQueue = false;
  2455. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2456. try
  2457. {
  2458. TStrings * PermanentFileList;
  2459. std::unique_ptr<TStrings> PermanentFileListOwner;
  2460. try
  2461. {
  2462. if (Side == osLocal)
  2463. {
  2464. PermanentFileList = FileList;
  2465. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2466. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2467. if (Operation == foMove)
  2468. {
  2469. ReloadLocalDirectory();
  2470. if (DView != NULL)
  2471. {
  2472. DView->RestoreSelection();
  2473. }
  2474. SelectionRestored = true;
  2475. }
  2476. }
  2477. else
  2478. {
  2479. // Clone the file list as it may refer to current directory files,
  2480. // which get destroyed, when the source directory is reloaded after foMove operation.
  2481. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2482. // But for a hotfix, we are not going to do such a big change.
  2483. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2484. PermanentFileList = PermanentFileListOwner.get();
  2485. try
  2486. {
  2487. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2488. }
  2489. __finally
  2490. {
  2491. if (Operation == foMove)
  2492. {
  2493. if (DView != NULL)
  2494. {
  2495. DView->RestoreSelection();
  2496. }
  2497. SelectionRestored = true;
  2498. }
  2499. ReloadLocalDirectory(Param.TargetDirectory);
  2500. }
  2501. }
  2502. // When the transfer batch is aborted between individual file transfers, the Abort is not called.
  2503. if (FMoveToQueue)
  2504. {
  2505. Abort();
  2506. }
  2507. }
  2508. catch (EAbort &)
  2509. {
  2510. if (FMoveToQueue)
  2511. {
  2512. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2513. DebugAssert(CopyParam.TransferSkipList == NULL);
  2514. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2515. if (TransferResumeList->Count > 0)
  2516. {
  2517. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2518. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2519. }
  2520. CopyParam.TransferSkipList = TransferResumeList.release();
  2521. // not really needed, just to keep it consistent with TransferResumeList
  2522. FTransferResumeList = NULL;
  2523. FMoveToQueue = false;
  2524. Configuration->Usage->Inc("MovesToBackground");
  2525. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2526. ClearTransferSourceSelection(Direction);
  2527. }
  2528. throw;
  2529. }
  2530. }
  2531. __finally
  2532. {
  2533. if (!SelectionRestored && (DView != NULL))
  2534. {
  2535. DView->DiscardSavedSelection();
  2536. }
  2537. FTransferResumeList = NULL;
  2538. }
  2539. }
  2540. return Result;
  2541. }
  2542. //---------------------------------------------------------------------------
  2543. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2544. TOperationSide Side, TStrings * FileList, void * Param)
  2545. {
  2546. DebugAssert(FileList->Count);
  2547. // We deliberately do not toggle alternative flag (Param), but use OR,
  2548. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2549. // shortcut of CurrentDeleteAlternativeAction
  2550. bool Alternative =
  2551. bool(Param) || UseAlternativeFunction();
  2552. bool Recycle;
  2553. if (IsSideLocalBrowser(Side))
  2554. {
  2555. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2556. }
  2557. else
  2558. {
  2559. Recycle =
  2560. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2561. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2562. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2563. }
  2564. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2565. if (!Result)
  2566. {
  2567. UnicodeString Query;
  2568. if (FileList->Count == 1)
  2569. {
  2570. if (IsSideLocalBrowser(Side))
  2571. {
  2572. Query = ExtractFileName(FileList->Strings[0]);
  2573. }
  2574. else
  2575. {
  2576. Query = UnixExtractFileName(FileList->Strings[0]);
  2577. }
  2578. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2579. }
  2580. else
  2581. {
  2582. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2583. }
  2584. TMessageParams Params(mpNeverAskAgainCheck);
  2585. Params.ImageName = L"Delete file";
  2586. unsigned int Answer =
  2587. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2588. if (Answer == qaNeverAskAgain)
  2589. {
  2590. Result = true;
  2591. if (Recycle)
  2592. {
  2593. WinConfiguration->ConfirmRecycling = false;
  2594. }
  2595. else
  2596. {
  2597. WinConfiguration->ConfirmDeleting = false;
  2598. }
  2599. }
  2600. else
  2601. {
  2602. Result = (Answer == qaOK);
  2603. }
  2604. }
  2605. if (Result)
  2606. {
  2607. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2608. }
  2609. return Result;
  2610. }
  2611. //---------------------------------------------------------------------------
  2612. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2613. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2614. {
  2615. TAutoBatch AutoBatch(this);
  2616. bool Result;
  2617. if ((Operation == foCopy) || (Operation == foMove))
  2618. {
  2619. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2620. }
  2621. else if (Operation == foRename)
  2622. {
  2623. DebugAssert(DirView(Side)->ItemFocused);
  2624. DirView(Side)->ItemFocused->EditCaption();
  2625. Result = true;
  2626. }
  2627. else if (Operation == foDelete)
  2628. {
  2629. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2630. }
  2631. else if (Operation == foSetProperties)
  2632. {
  2633. DirView(osRemote)->SaveSelectedNames();
  2634. Result = SetProperties(Side, FileList);
  2635. }
  2636. else if (Operation == foCustomCommand)
  2637. {
  2638. DebugAssert(Param);
  2639. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2640. DirView(osRemote)->SaveSelectedNames();
  2641. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2642. CustomCommand(FileList, *Command, NULL);
  2643. Result = true;
  2644. }
  2645. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2646. {
  2647. DebugAssert(!IsSideLocalBrowser(Side));
  2648. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2649. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2650. }
  2651. else if (Operation == foLock)
  2652. {
  2653. DebugAssert(!IsSideLocalBrowser(Side));
  2654. LockFiles(FileList, true);
  2655. Result = true;
  2656. }
  2657. else if (Operation == foUnlock)
  2658. {
  2659. DebugAssert(!IsSideLocalBrowser(Side));
  2660. LockFiles(FileList, false);
  2661. Result = true;
  2662. }
  2663. else
  2664. {
  2665. DebugFail();
  2666. }
  2667. return Result;
  2668. }
  2669. //---------------------------------------------------------------------------
  2670. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2671. {
  2672. if (Side == osCurrent)
  2673. {
  2674. Side = FCurrentSide;
  2675. }
  2676. return Side;
  2677. }
  2678. //---------------------------------------------------------------------------
  2679. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2680. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2681. {
  2682. Side = GetSide(Side);
  2683. bool Result;
  2684. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2685. try
  2686. {
  2687. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2688. }
  2689. __finally
  2690. {
  2691. delete FileList;
  2692. }
  2693. return Result;
  2694. }
  2695. //---------------------------------------------------------------------------
  2696. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2697. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2698. bool NoConfirmation, void * Param)
  2699. {
  2700. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2701. {
  2702. if ((Operation == foCopy) || (Operation == foMove))
  2703. {
  2704. DebugAssert(!IsLocalBrowserMode());
  2705. if (GetSide(Side) == osLocal)
  2706. {
  2707. Configuration->Usage->Inc(L"UploadsCommand");
  2708. }
  2709. else
  2710. {
  2711. Configuration->Usage->Inc(L"DownloadsCommand");
  2712. }
  2713. }
  2714. }
  2715. }
  2716. //---------------------------------------------------------------------------
  2717. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2718. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2719. {
  2720. TTransferOperationParam Param;
  2721. if ((WinConfiguration->Interface != ifCommander) ||
  2722. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2723. {
  2724. Flags &= ~cocShortCutHint;
  2725. }
  2726. TCustomDirView * DView = DirView(Side);
  2727. Param.Options =
  2728. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2729. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2730. if (FLAGSET(Flags, cocQueue))
  2731. {
  2732. Param.Queue = asOn;
  2733. }
  2734. else if (FLAGSET(Flags, cocNonQueue))
  2735. {
  2736. Param.Queue = asOff;
  2737. }
  2738. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2739. }
  2740. //---------------------------------------------------------------------------
  2741. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2742. {
  2743. try
  2744. {
  2745. if (ErrorList->Count)
  2746. {
  2747. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2748. if (MessageDialog(Message, qtError,
  2749. qaOK | qaCancel, HELP_NONE) == qaOK)
  2750. {
  2751. unsigned int Answer;
  2752. int Index = 0;
  2753. do
  2754. {
  2755. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2756. TQueryButtonAlias Aliases[2];
  2757. Aliases[0].Button = qaYes;
  2758. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2759. Aliases[1].Button = qaNo;
  2760. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2761. TMessageParams Params;
  2762. Params.Aliases = Aliases;
  2763. Params.AliasesCount = LENOF(Aliases);
  2764. Answer = MoreMessageDialog(
  2765. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2766. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2767. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2768. qaOK, HELP_NONE, &Params);
  2769. if (Answer == qaNo)
  2770. {
  2771. Index++;
  2772. }
  2773. if (Answer == qaYes)
  2774. {
  2775. Index--;
  2776. }
  2777. }
  2778. while (Answer != qaOK);
  2779. }
  2780. }
  2781. }
  2782. __finally
  2783. {
  2784. TStrings * List = ErrorList;
  2785. ErrorList = NULL;
  2786. for (int i = 0; i < List->Count; i++)
  2787. {
  2788. delete List->Objects[i];
  2789. }
  2790. delete List;
  2791. }
  2792. }
  2793. //---------------------------------------------------------------------------
  2794. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2795. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2796. {
  2797. // needed for checking filemasks, as there's no directory object
  2798. // associated with the file object
  2799. File->FullFileName = FullFileName;
  2800. TFileMasks::TParams MaskParams;
  2801. MaskParams.Size = File->Size;
  2802. MaskParams.Modification = File->Modification;
  2803. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2804. }
  2805. //---------------------------------------------------------------------------
  2806. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2807. {
  2808. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2809. Side = GetSide(Side);
  2810. TCustomDirView * DView = DirView(Side);
  2811. TListItem * FocusedItem = DView->ItemFocused;
  2812. UnicodeString Name;
  2813. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2814. {
  2815. Name = DView->ItemFileName(FocusedItem);
  2816. }
  2817. else
  2818. {
  2819. Name = LoadStr(NEW_FILE);
  2820. }
  2821. UnicodeString Names = Name;
  2822. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2823. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2824. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  2825. {
  2826. while (!Names.IsEmpty())
  2827. {
  2828. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2829. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2830. UnicodeString TargetFileName;
  2831. UnicodeString LocalFileName;
  2832. UnicodeString RootTempDir;
  2833. UnicodeString TempDir;
  2834. UnicodeString RemoteDirectory;
  2835. bool ExistingFile = false;
  2836. if (!IsSideLocalBrowser(Side))
  2837. {
  2838. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2839. TRemoteFile * File = NULL;
  2840. if (FTerminal->FileExists(Name, &File) &&
  2841. !File->IsDirectory)
  2842. {
  2843. try
  2844. {
  2845. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2846. ExistingFile = true;
  2847. }
  2848. __finally
  2849. {
  2850. delete File;
  2851. }
  2852. }
  2853. if (!ExistingFile)
  2854. {
  2855. RemoteDirectory = UnixExtractFilePath(Name);
  2856. TemporaryDirectoryForRemoteFiles(
  2857. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2858. TargetFileName = UnixExtractFileName(Name);
  2859. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2860. LocalFileName = TempDir +
  2861. // We probably do not want to trim the VMS version here
  2862. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2863. }
  2864. }
  2865. else
  2866. {
  2867. if (ExtractFilePath(Name).IsEmpty())
  2868. {
  2869. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2870. }
  2871. else
  2872. {
  2873. LocalFileName = ExpandFileName(Name);
  2874. }
  2875. TargetFileName = ExtractFileName(Name);
  2876. }
  2877. if (!ExistingFile)
  2878. {
  2879. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2880. if (NewFile)
  2881. {
  2882. int File = FileCreate(ApiPath(LocalFileName));
  2883. if (File < 0)
  2884. {
  2885. if (!RootTempDir.IsEmpty())
  2886. {
  2887. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2888. }
  2889. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2890. }
  2891. else
  2892. {
  2893. FileClose(File);
  2894. }
  2895. }
  2896. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2897. const TEditorData * ExternalEditor = NULL;
  2898. TFileMasks::TParams MaskParams; // size not known
  2899. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2900. false, MaskParams);
  2901. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2902. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2903. }
  2904. }
  2905. }
  2906. }
  2907. //---------------------------------------------------------------------------
  2908. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2909. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2910. {
  2911. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2912. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2913. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2914. return
  2915. ((ExecuteFileBy == efInternalEditor)) ||
  2916. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2917. }
  2918. //---------------------------------------------------------------------------
  2919. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2920. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2921. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2922. UnicodeString RemoteDirectory, bool NewFile)
  2923. {
  2924. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2925. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2926. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2927. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2928. Side = GetSide(Side);
  2929. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2930. if (!IsSideLocalBrowser(Side))
  2931. {
  2932. Data->Terminal = Terminal;
  2933. Data->Queue = Queue;
  2934. Data->SessionData = CloneCurrentSessionData();
  2935. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2936. Data->RemoteDirectory = RemoteDirectory;
  2937. Data->SessionName = Terminal->SessionData->SessionName;
  2938. Data->LocalRootDirectory = LocalRootDirectory;
  2939. Data->OriginalFileName = OriginalFileName;
  2940. Data->Command = L""; // will be changed later for external editor
  2941. }
  2942. if (ExecuteFileBy == efInternalEditor)
  2943. {
  2944. if (!IsSideLocalBrowser(Side))
  2945. {
  2946. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2947. L" - " + Terminal->SessionData->SessionName;
  2948. TForm * Editor;
  2949. try
  2950. {
  2951. TNotifyEvent OnFileChanged = NULL;
  2952. TNotifyEvent OnSaveAll = NULL;
  2953. TAnyModifiedEvent OnAnyModified = NULL;
  2954. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2955. if (Terminal->IsCapable[fcBackgroundTransfers])
  2956. {
  2957. OnFileChanged = FEditorManager->FileChanged;
  2958. OnSaveAll = SaveAllInternalEditors;
  2959. OnAnyModified = AnyInternalEditorModified;
  2960. }
  2961. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2962. FEditorManager->FileReload, FEditorManager->FileClosed,
  2963. OnSaveAll, OnAnyModified,
  2964. Caption, StandaloneOperation, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2965. }
  2966. catch(...)
  2967. {
  2968. if (!LocalRootDirectory.IsEmpty())
  2969. {
  2970. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2971. }
  2972. throw;
  2973. }
  2974. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2975. }
  2976. else
  2977. {
  2978. DebugAssert(!StandaloneOperation);
  2979. TForm * Editor =
  2980. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2981. SaveAllInternalEditors, AnyInternalEditorModified,
  2982. L"", false, SessionColor, -1, NewFile);
  2983. FLocalEditors->Add(Editor);
  2984. }
  2985. }
  2986. else
  2987. {
  2988. HANDLE Process;
  2989. if (ExecuteFileBy == efExternalEditor)
  2990. {
  2991. UnicodeString Program, Params, Dir;
  2992. Data->Command = ExternalEditor->ExternalEditor;
  2993. ReformatFileNameCommand(Data->Command);
  2994. SplitCommand(Data->Command, Program, Params, Dir);
  2995. Params = ExpandFileNameCommand(Params, FileName);
  2996. Program = ExpandEnvironmentVariables(Program);
  2997. if (!ExecuteShell(Program, Params, Process))
  2998. {
  2999. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3000. }
  3001. }
  3002. else
  3003. {
  3004. DebugAssert(!IsSideLocalBrowser(Side));
  3005. if (!ExecuteShell(FileName, L"", Process))
  3006. {
  3007. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3008. }
  3009. }
  3010. if (IsSideLocalBrowser(Side) ||
  3011. ((ExecuteFileBy == efShell) &&
  3012. !WinConfiguration->Editor.SDIShellEditor) ||
  3013. ((ExecuteFileBy == efExternalEditor) &&
  3014. !ExternalEditor->SDIExternalEditor))
  3015. {
  3016. // no need for handle
  3017. if (Process != NULL)
  3018. {
  3019. DebugCheck(CloseHandle(Process));
  3020. }
  3021. Process = INVALID_HANDLE_VALUE;
  3022. }
  3023. else
  3024. {
  3025. if (Process == NULL)
  3026. {
  3027. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3028. }
  3029. }
  3030. if (!IsSideLocalBrowser(Side))
  3031. {
  3032. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3033. }
  3034. }
  3035. }
  3036. //---------------------------------------------------------------------------
  3037. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3038. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3039. void * /*Arg*/)
  3040. {
  3041. if (Token != NULL)
  3042. {
  3043. EditorFormFileSave(static_cast<TForm *>(Token));
  3044. }
  3045. }
  3046. //---------------------------------------------------------------------------
  3047. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3048. {
  3049. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3050. {
  3051. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3052. }
  3053. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3054. }
  3055. //---------------------------------------------------------------------------
  3056. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3057. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3058. void * Arg)
  3059. {
  3060. if ((Token != NULL) &&
  3061. IsEditorFormModified(static_cast<TForm *>(Token)))
  3062. {
  3063. *static_cast<bool *>(Arg) = true;
  3064. }
  3065. }
  3066. //---------------------------------------------------------------------------
  3067. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3068. TObject * /*Sender*/, bool & Modified)
  3069. {
  3070. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3071. {
  3072. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3073. {
  3074. Modified = true;
  3075. }
  3076. }
  3077. if (!Modified)
  3078. {
  3079. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3080. }
  3081. }
  3082. //---------------------------------------------------------------------------
  3083. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3084. {
  3085. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3086. }
  3087. //---------------------------------------------------------------------------
  3088. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3089. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3090. UnicodeString & Result, UnicodeString & RootDirectory)
  3091. {
  3092. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3093. {
  3094. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3095. Result = RootDirectory;
  3096. }
  3097. else
  3098. {
  3099. RootDirectory = L"";
  3100. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3101. Result = IncludeTrailingBackslash(Result);
  3102. }
  3103. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3104. {
  3105. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3106. }
  3107. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3108. {
  3109. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3110. {
  3111. RemoteDirectory.Delete(1, 1);
  3112. }
  3113. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3114. }
  3115. if (!ForceDirectories(ApiPath(Result)))
  3116. {
  3117. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3118. }
  3119. }
  3120. //---------------------------------------------------------------------------
  3121. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3122. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3123. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3124. {
  3125. DebugAssert(!IsLocalBrowserMode());
  3126. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3127. if (ForceText)
  3128. {
  3129. CopyParam.TransferMode = tmAscii;
  3130. }
  3131. TemporaryFileCopyParam(CopyParam);
  3132. if (AllFiles)
  3133. {
  3134. CopyParam.IncludeFileMask = TFileMasks();
  3135. }
  3136. if (TempDir.IsEmpty())
  3137. {
  3138. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3139. }
  3140. DebugAssert(!FAutoOperation);
  3141. FAutoOperation = AutoOperation;
  3142. Terminal->ExceptionOnFail = true;
  3143. try
  3144. {
  3145. try
  3146. {
  3147. // turn off confirmations, as for MDI editors we may possibly download
  3148. // the same file over
  3149. Terminal->CopyToLocal(
  3150. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3151. if (GetTargetNames)
  3152. {
  3153. for (int i = 0; i < FileList->Count; i++)
  3154. {
  3155. FileList->Strings[i] =
  3156. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3157. }
  3158. }
  3159. }
  3160. catch(...)
  3161. {
  3162. if (!RootTempDir.IsEmpty())
  3163. {
  3164. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3165. }
  3166. throw;
  3167. }
  3168. }
  3169. __finally
  3170. {
  3171. FAutoOperation = false;
  3172. Terminal->ExceptionOnFail = false;
  3173. }
  3174. }
  3175. //---------------------------------------------------------------------------
  3176. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3177. {
  3178. // Do not waste time checking for default editor list the next time,
  3179. // or testing if default editor is not notepad.
  3180. bool TryNextTime = false;
  3181. UnicodeString UsageState;
  3182. if (!WinConfiguration->EditorList->IsDefaultList())
  3183. {
  3184. UsageState = "H";
  3185. }
  3186. else
  3187. {
  3188. UnicodeString Executable;
  3189. UnicodeString ExecutableDescription;
  3190. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3191. {
  3192. UnicodeString Message =
  3193. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3194. unsigned int Answer =
  3195. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3196. if (Answer != qaOK)
  3197. {
  3198. UsageState = "R";
  3199. }
  3200. else
  3201. {
  3202. UsageState = "A";
  3203. TEditorData EditorData;
  3204. EditorData.Editor = edExternal;
  3205. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3206. EditorData.ExternalEditorOptionsAutodetect();
  3207. TEditorList EditorList;
  3208. EditorList = *WinConfiguration->EditorList;
  3209. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3210. WinConfiguration->EditorList = &EditorList;
  3211. }
  3212. }
  3213. }
  3214. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3215. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3216. }
  3217. //---------------------------------------------------------------------------
  3218. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3219. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3220. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3221. {
  3222. if (ExecuteFileBy == efDefaultEditor)
  3223. {
  3224. if (!WinConfiguration->OfferedEditorAutoConfig)
  3225. {
  3226. EditorAutoConfig();
  3227. }
  3228. const TEditorPreferences * Editor =
  3229. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3230. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3231. {
  3232. ExecuteFileBy = efInternalEditor;
  3233. ExternalEditor = NULL;
  3234. }
  3235. else if (Editor->Data->Editor == edOpen)
  3236. {
  3237. ExecuteFileBy = efShell;
  3238. ExternalEditor = NULL;
  3239. }
  3240. else
  3241. {
  3242. ExecuteFileBy = efExternalEditor;
  3243. ExternalEditor = Editor->Data;
  3244. }
  3245. }
  3246. }
  3247. //---------------------------------------------------------------------------
  3248. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3249. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3250. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3251. {
  3252. UnicodeString OriginalFileName;
  3253. UnicodeString LocalRootDirectory;
  3254. UnicodeString RemoteDirectory;
  3255. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3256. IsSideLocalBrowser(Side), MaskParams);
  3257. UnicodeString Counter;
  3258. UnicodeString LocalFileName;
  3259. bool Handled = false;
  3260. if (!IsSideLocalBrowser(Side))
  3261. {
  3262. // We need to trim VMS version here, so that we use name without version
  3263. // when uploading back to create a new version of the file
  3264. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3265. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3266. TObject * Token = NULL;
  3267. UnicodeString LocalDirectory;
  3268. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3269. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3270. LocalDirectory))
  3271. {
  3272. if (Token != NULL)
  3273. {
  3274. TForm * Form = dynamic_cast<TForm *>(Token);
  3275. if (Form->WindowState == wsMinimized)
  3276. {
  3277. ShowWindow(Form->Handle, SW_RESTORE);
  3278. }
  3279. else
  3280. {
  3281. Form->SetFocus();
  3282. }
  3283. Handled = true;
  3284. }
  3285. else
  3286. {
  3287. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3288. }
  3289. }
  3290. if (!Handled)
  3291. {
  3292. TStringList * FileList1 = new TStringList();
  3293. try
  3294. {
  3295. FileList1->AddObject(FullFileName, Object);
  3296. TemporarilyDownloadFiles(FileList1,
  3297. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3298. LocalRootDirectory, LocalDirectory, true, true, true);
  3299. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3300. }
  3301. __finally
  3302. {
  3303. delete FileList1;
  3304. }
  3305. switch (ExecuteFileBy)
  3306. {
  3307. case efShell:
  3308. Counter = "RemoteFilesExecuted";
  3309. break;
  3310. case efInternalEditor:
  3311. Counter = "RemoteFilesOpenedInInternalEditor";
  3312. break;
  3313. case efExternalEditor:
  3314. Counter = "RemoteFilesOpenedInExternalEditor";
  3315. break;
  3316. default:
  3317. DebugFail();
  3318. }
  3319. }
  3320. }
  3321. else
  3322. {
  3323. LocalFileName = FullFileName;
  3324. OriginalFileName = ExtractFileName(FullFileName);
  3325. switch (ExecuteFileBy)
  3326. {
  3327. case efShell:
  3328. Counter = "LocalFilesExecuted";
  3329. break;
  3330. case efInternalEditor:
  3331. Counter = "LocalFilesOpenedInInternalEditor";
  3332. break;
  3333. case efExternalEditor:
  3334. Counter = "LocalFilesOpenedInExternalEditor";
  3335. break;
  3336. default:
  3337. DebugFail();
  3338. }
  3339. }
  3340. if (!Handled)
  3341. {
  3342. Configuration->Usage->Inc(Counter);
  3343. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3344. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3345. }
  3346. }
  3347. //---------------------------------------------------------------------------
  3348. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3349. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3350. bool AllSelected, bool OnFocused)
  3351. {
  3352. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3353. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3354. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3355. Side = GetSide(Side);
  3356. TCustomDirView * DView = DirView(Side);
  3357. TStrings * FileList =
  3358. AllSelected ?
  3359. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3360. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3361. try
  3362. {
  3363. DebugAssert(AllSelected || (FileList->Count == 1));
  3364. for (int i = 0; i < FileList->Count; i++)
  3365. {
  3366. UnicodeString ListFileName = FileList->Strings[i];
  3367. UnicodeString FileNameOnly =
  3368. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3369. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3370. if (!DView->ItemIsDirectory(Item))
  3371. {
  3372. UnicodeString FullFileName;
  3373. if (!IsSideLocalBrowser(Side))
  3374. {
  3375. FullFileName = DirView(Side)->Path + ListFileName;
  3376. }
  3377. else
  3378. {
  3379. FullFileName = ListFileName;
  3380. }
  3381. TFileMasks::TParams MaskParams;
  3382. MaskParams.Size = DView->ItemFileSize(Item);
  3383. TDateTimePrecision Precision;
  3384. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3385. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3386. FileList->Objects[i], MaskParams);
  3387. }
  3388. }
  3389. }
  3390. __finally
  3391. {
  3392. delete FileList;
  3393. }
  3394. }
  3395. //---------------------------------------------------------------------------
  3396. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3397. {
  3398. CopyParam.FileNameCase = ncNoChange;
  3399. CopyParam.PreserveRights = false;
  3400. CopyParam.PreserveReadOnly = false;
  3401. CopyParam.ReplaceInvalidChars = true;
  3402. CopyParam.IncludeFileMask = TFileMasks();
  3403. CopyParam.NewerOnly = false;
  3404. CopyParam.FileMask = L"";
  3405. }
  3406. //---------------------------------------------------------------------------
  3407. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3408. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3409. {
  3410. TTerminalManager * Manager = TTerminalManager::Instance();
  3411. if (!IsActiveTerminal(Data->Terminal))
  3412. {
  3413. if (!NonVisualDataModule->Busy)
  3414. {
  3415. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3416. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3417. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3418. if (Data->Terminal == NULL)
  3419. {
  3420. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3421. if (SameSiteTerminal != NULL)
  3422. {
  3423. UnicodeString Message =
  3424. FMTLOAD(EDIT_SESSION_REATTACH,
  3425. (FileNameOnly, Data->SessionName, FileNameOnly));
  3426. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3427. {
  3428. Data->Terminal = Terminal;
  3429. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3430. Data->SessionName = Terminal->SessionData->SessionName;
  3431. // We might also overwrite session data
  3432. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3433. }
  3434. else
  3435. {
  3436. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3437. Abort();
  3438. }
  3439. }
  3440. }
  3441. // foreground session should reconnect itself
  3442. else if (Terminal != Data->Terminal)
  3443. {
  3444. UnicodeString Message =
  3445. MainInstructions(
  3446. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3447. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3448. {
  3449. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3450. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3451. }
  3452. else
  3453. {
  3454. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3455. Abort();
  3456. }
  3457. }
  3458. }
  3459. if (!IsActiveTerminal(Data->Terminal))
  3460. {
  3461. Configuration->Usage->Inc(L"EditInactiveSession");
  3462. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3463. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3464. (ExtractFileName(FileName), Data->SessionName)));
  3465. }
  3466. }
  3467. TStrings * FileList = new TStringList();
  3468. try
  3469. {
  3470. FileList->Add(FileName);
  3471. // consider using the same settings (preset) as when the file was downloaded
  3472. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3473. TemporaryFileCopyParam(CopyParam);
  3474. if (Data->ForceText)
  3475. {
  3476. CopyParam.TransferMode = tmAscii;
  3477. }
  3478. // so i do not need to worry if masking algorithm works in all cases
  3479. // ("" means "copy file name", no masking is actually done)
  3480. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3481. {
  3482. CopyParam.FileMask = L"";
  3483. }
  3484. else
  3485. {
  3486. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3487. }
  3488. DebugAssert(Data->Queue != NULL);
  3489. int Params = cpNoConfirmation | cpTemporary;
  3490. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3491. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3492. QueueItem->CompleteEvent = UploadCompleteEvent;
  3493. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3494. }
  3495. __finally
  3496. {
  3497. delete FileList;
  3498. }
  3499. }
  3500. //---------------------------------------------------------------------------
  3501. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3502. const UnicodeString FileName, const TEditedFileData * Data)
  3503. {
  3504. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3505. DebugAssert(!NonVisualDataModule->Busy);
  3506. if (!IsActiveTerminal(Data->Terminal))
  3507. {
  3508. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3509. (ExtractFileName(FileName), Data->SessionName)));
  3510. }
  3511. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3512. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3513. NonVisualDataModule->StartBusy();
  3514. try
  3515. {
  3516. std::unique_ptr<TRemoteFile> File;
  3517. UnicodeString RemoteFileName =
  3518. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3519. FTerminal->ExceptionOnFail = true;
  3520. try
  3521. {
  3522. TRemoteFile * AFile = NULL;
  3523. FTerminal->ReadFile(RemoteFileName, AFile);
  3524. File.reset(AFile);
  3525. if (!File->HaveFullFileName)
  3526. {
  3527. File->FullFileName = RemoteFileName;
  3528. }
  3529. }
  3530. __finally
  3531. {
  3532. FTerminal->ExceptionOnFail = false;
  3533. }
  3534. std::unique_ptr<TStrings> FileList(new TStringList());
  3535. FileList->AddObject(RemoteFileName, File.get());
  3536. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3537. UnicodeString TempDir = ExtractFilePath(FileName);
  3538. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3539. TempDir, true, true, true);
  3540. // sanity check, the target file name should be still the same
  3541. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3542. }
  3543. __finally
  3544. {
  3545. NonVisualDataModule->EndBusy();
  3546. // it actually may not exist anymore...
  3547. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3548. }
  3549. }
  3550. //---------------------------------------------------------------------------
  3551. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3552. const TEditedFileData * Data, bool & KeepOpen)
  3553. {
  3554. // Command is set for external editors only (not for "shell" open).
  3555. if (!Data->Command.IsEmpty())
  3556. {
  3557. bool AnyFound = false;
  3558. bool AnyMDI = false;
  3559. bool AnyNonMDI = false;
  3560. bool AnyDetect = false;
  3561. TEditorList * EditorList = new TEditorList();
  3562. try
  3563. {
  3564. *EditorList = *WinConfiguration->EditorList;
  3565. for (int i = 0; i < EditorList->Count; i++)
  3566. {
  3567. const TEditorPreferences * Editor = EditorList->Editors[i];
  3568. if ((Editor->Data->Editor == edExternal) &&
  3569. (Editor->Data->ExternalEditor == Data->Command))
  3570. {
  3571. AnyFound = true;
  3572. if (Editor->Data->SDIExternalEditor)
  3573. {
  3574. AnyNonMDI = true;
  3575. if (Editor->Data->DetectMDIExternalEditor)
  3576. {
  3577. AnyDetect = true;
  3578. }
  3579. }
  3580. else
  3581. {
  3582. AnyMDI = true;
  3583. }
  3584. }
  3585. }
  3586. bool EnableMDI = false;
  3587. bool DisableDetect = false;
  3588. if (AnyMDI)
  3589. {
  3590. KeepOpen = true;
  3591. if (AnyNonMDI)
  3592. {
  3593. // there is at least one instance of the editor with MDI support enabled,
  3594. // and one with disabled, enable it for all instances
  3595. EnableMDI = true;
  3596. }
  3597. }
  3598. else if (AnyFound && !AnyDetect)
  3599. {
  3600. // at least once instance found but all have MDI autodetection disabled
  3601. // => close the file (default action)
  3602. }
  3603. else
  3604. {
  3605. // no instance of the editor has MDI support enabled
  3606. TMessageParams Params;
  3607. if (AnyFound)
  3608. {
  3609. // there is at least one instance of the editor
  3610. Params.Params |= mpNeverAskAgainCheck;
  3611. }
  3612. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3613. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3614. switch (Answer)
  3615. {
  3616. case qaNeverAskAgain:
  3617. DisableDetect = true;
  3618. break;
  3619. case qaNo:
  3620. EnableMDI = true;
  3621. KeepOpen = true;
  3622. break;
  3623. }
  3624. }
  3625. if (AnyFound && (EnableMDI || DisableDetect))
  3626. {
  3627. bool Changed = false;
  3628. for (int i = 0; i < EditorList->Count; i++)
  3629. {
  3630. const TEditorPreferences * Editor = EditorList->Editors[i];
  3631. if ((Editor->Data->Editor == edExternal) &&
  3632. (Editor->Data->ExternalEditor == Data->Command) &&
  3633. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3634. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3635. {
  3636. Changed = true;
  3637. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3638. if (EnableMDI)
  3639. {
  3640. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3641. }
  3642. if (DisableDetect)
  3643. {
  3644. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3645. }
  3646. EditorList->Change(i, UpdatedEditor);
  3647. }
  3648. }
  3649. if (Changed)
  3650. {
  3651. WinConfiguration->EditorList = EditorList;
  3652. }
  3653. }
  3654. }
  3655. __finally
  3656. {
  3657. delete EditorList;
  3658. }
  3659. }
  3660. else
  3661. {
  3662. // "open" case
  3663. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3664. qaOK, HELP_APP_EARLY_CLOSED);
  3665. }
  3666. }
  3667. //---------------------------------------------------------------------------
  3668. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3669. {
  3670. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3671. }
  3672. //---------------------------------------------------------------------------
  3673. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3674. {
  3675. SideEnter(osRemote);
  3676. }
  3677. //---------------------------------------------------------------------------
  3678. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3679. {
  3680. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3681. SideEnter(osRemote);
  3682. }
  3683. //---------------------------------------------------------------------------
  3684. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3685. {
  3686. FCurrentSide = Side;
  3687. if (Visible)
  3688. {
  3689. UpdateControls();
  3690. }
  3691. }
  3692. //---------------------------------------------------------------------------
  3693. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3694. TStrings * FileList, bool Alternative)
  3695. {
  3696. TCustomDirView * DView = DirView(Side);
  3697. DView->SaveSelection();
  3698. DView->SaveSelectedNames();
  3699. DebugAssert(!FAlternativeDelete);
  3700. FAlternativeDelete = Alternative;
  3701. try
  3702. {
  3703. if (!IsSideLocalBrowser(Side))
  3704. {
  3705. DebugAssert(Terminal != NULL);
  3706. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3707. }
  3708. else
  3709. {
  3710. try
  3711. {
  3712. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3713. }
  3714. __finally
  3715. {
  3716. ReloadLocalDirectory();
  3717. }
  3718. }
  3719. FAlternativeDelete = false;
  3720. }
  3721. catch(...)
  3722. {
  3723. FAlternativeDelete = false;
  3724. DView->DiscardSavedSelection();
  3725. throw;
  3726. }
  3727. DView->RestoreSelection();
  3728. }
  3729. //---------------------------------------------------------------------------
  3730. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3731. {
  3732. DebugAssert(Terminal);
  3733. DebugAssert(!IsLocalBrowserMode());
  3734. RemoteDirView->SaveSelection();
  3735. RemoteDirView->SaveSelectedNames();
  3736. try
  3737. {
  3738. if (Lock)
  3739. {
  3740. Terminal->LockFiles(FileList);
  3741. }
  3742. else
  3743. {
  3744. Terminal->UnlockFiles(FileList);
  3745. }
  3746. }
  3747. catch(...)
  3748. {
  3749. RemoteDirView->DiscardSavedSelection();
  3750. throw;
  3751. }
  3752. RemoteDirView->RestoreSelection();
  3753. }
  3754. //---------------------------------------------------------------------------
  3755. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3756. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3757. bool NoConfirmation, bool Move)
  3758. {
  3759. DebugAssert(Terminal != NULL);
  3760. DebugAssert(!IsLocalBrowserMode());
  3761. // update Terminal->StateData->RemoteDirectory
  3762. UpdateTerminal(Terminal);
  3763. if (Session == NULL)
  3764. {
  3765. Session = TTerminalManager::Instance()->ActiveTerminal;
  3766. }
  3767. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3768. {
  3769. if (RemoteDriveView->DropTarget != NULL)
  3770. {
  3771. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3772. }
  3773. else if (RemoteDirView->DropTarget != NULL)
  3774. {
  3775. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3776. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3777. }
  3778. else
  3779. {
  3780. Target = RemoteDirView->Path;
  3781. }
  3782. }
  3783. else
  3784. {
  3785. Target = Session->StateData->RemoteDirectory;
  3786. }
  3787. Target = UnixIncludeTrailingBackslash(Target);
  3788. if (FileList->Count == 1)
  3789. {
  3790. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3791. }
  3792. else
  3793. {
  3794. FileMask = AnyMask;
  3795. }
  3796. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3797. bool Result = true;
  3798. if (!NoConfirmation)
  3799. {
  3800. bool Multi = (FileList->Count > 1);
  3801. if (Move)
  3802. {
  3803. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3804. }
  3805. else
  3806. {
  3807. std::unique_ptr<TStrings> Sessions(new TStringList);
  3808. std::unique_ptr<TStrings> Directories(new TStringList);
  3809. TStrings * SessionList = TTerminalManager::Instance()->TerminalList;
  3810. for (int Index = 0; Index < SessionList->Count; Index++)
  3811. {
  3812. TManagedTerminal * ASession = DebugNotNull(dynamic_cast<TManagedTerminal *>(SessionList->Objects[Index]));
  3813. if (IsActiveTerminal(ASession))
  3814. {
  3815. Sessions->AddObject(SessionList->Strings[Index], ASession);
  3816. Directories->Add(ASession->StateData->RemoteDirectory);
  3817. }
  3818. }
  3819. TDirectRemoteCopy AllowDirectCopy;
  3820. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3821. {
  3822. DebugAssert(DirectCopy);
  3823. AllowDirectCopy = drcAllow;
  3824. }
  3825. else if (FTerminal->IsCapable[fcSecondaryShell])
  3826. {
  3827. DebugAssert(DirectCopy);
  3828. AllowDirectCopy = drcConfirmCommandSession;
  3829. }
  3830. else
  3831. {
  3832. DebugAssert(!DirectCopy);
  3833. AllowDirectCopy = drcDisallow;
  3834. }
  3835. void * ASession = Session;
  3836. Result = DoRemoteCopyDialog(
  3837. Sessions.get(), Directories.get(), AllowDirectCopy, Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3838. Session = static_cast<TManagedTerminal *>(ASession);
  3839. }
  3840. }
  3841. return Result;
  3842. }
  3843. //---------------------------------------------------------------------------
  3844. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3845. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3846. {
  3847. DebugAssert(!IsLocalBrowserMode());
  3848. bool DirectCopy;
  3849. UnicodeString Target, FileMask;
  3850. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3851. if (Result)
  3852. {
  3853. if (!Move && !DirectCopy)
  3854. {
  3855. Configuration->Usage->Inc("RemoteCopyTemp");
  3856. UnicodeString RootTempDir;
  3857. UnicodeString TempDir;
  3858. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3859. TStrings * TemporaryFilesList = new TStringList();
  3860. try
  3861. {
  3862. TMakeLocalFileListParams MakeFileListParam;
  3863. MakeFileListParam.FileList = TemporaryFilesList;
  3864. MakeFileListParam.FileTimes = NULL;
  3865. MakeFileListParam.IncludeDirs = true;
  3866. MakeFileListParam.Recursive = false;
  3867. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3868. TTerminalManager::Instance()->ActiveTerminal = Session;
  3869. if (TemporaryFilesList->Count > 0)
  3870. {
  3871. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3872. CopyParam.FileMask = FileMask;
  3873. DebugAssert(!FAutoOperation);
  3874. FAutoOperation = true;
  3875. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3876. }
  3877. }
  3878. __finally
  3879. {
  3880. delete TemporaryFilesList;
  3881. FAutoOperation = false;
  3882. if (!RootTempDir.IsEmpty())
  3883. {
  3884. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3885. }
  3886. }
  3887. }
  3888. else
  3889. {
  3890. RemoteDirView->SaveSelection();
  3891. RemoteDirView->SaveSelectedNames();
  3892. try
  3893. {
  3894. if (Move)
  3895. {
  3896. Configuration->Usage->Inc("RemoteMove");
  3897. Terminal->MoveFiles(FileList, Target, FileMask);
  3898. }
  3899. else
  3900. {
  3901. Configuration->Usage->Inc("RemoteCopyDirect");
  3902. DebugAssert(DirectCopy);
  3903. DebugAssert(Session == FTerminal);
  3904. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3905. FTerminal->CommandSessionOpened ||
  3906. CommandSessionFallback())
  3907. {
  3908. Terminal->CopyFiles(FileList, Target, FileMask);
  3909. }
  3910. }
  3911. }
  3912. catch(...)
  3913. {
  3914. RemoteDirView->DiscardSavedSelection();
  3915. throw;
  3916. }
  3917. RemoteDirView->RestoreSelection();
  3918. }
  3919. }
  3920. return Result;
  3921. }
  3922. //---------------------------------------------------------------------------
  3923. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3924. const UnicodeString & Path, TRemoteProperties & Properties)
  3925. {
  3926. DebugAssert(!IsLocalBrowserMode());
  3927. Properties.Valid = Properties.Valid << vpEncrypt;
  3928. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3929. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3930. }
  3931. //---------------------------------------------------------------------------
  3932. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3933. {
  3934. Side = GetSide(Side);
  3935. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3936. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3937. UnicodeString Name = LoadStr(NEW_FOLDER);
  3938. int AllowedChanges =
  3939. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3940. bool SaveSettings = false;
  3941. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3942. {
  3943. TWindowLock Lock(this);
  3944. if (!IsSideLocalBrowser(Side))
  3945. {
  3946. if (SaveSettings)
  3947. {
  3948. GUIConfiguration->NewDirectoryProperties = Properties;
  3949. }
  3950. CreateRemoteDirectory(Name, Properties);
  3951. }
  3952. else
  3953. {
  3954. DirView(Side)->CreateDirectory(Name);
  3955. }
  3956. }
  3957. }
  3958. //---------------------------------------------------------------------------
  3959. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3960. {
  3961. TWindowLock Lock(this);
  3962. DirView(Side)->ExecuteHomeDirectory();
  3963. }
  3964. //---------------------------------------------------------------------------
  3965. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3966. {
  3967. DoOpenDirectoryDialog(odBrowse, Side);
  3968. }
  3969. //---------------------------------------------------------------------------
  3970. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3971. {
  3972. UnicodeString Path = Bookmark->GetSideDirectory(Side);
  3973. bool Result = !Path.IsEmpty();
  3974. if (Result)
  3975. {
  3976. // While we might get here when the session is closed (from location profiles),
  3977. // it's not a problem as the Path setter is noop then
  3978. DirView(Side)->Path = Path;
  3979. }
  3980. return Result;
  3981. }
  3982. //---------------------------------------------------------------------------
  3983. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3984. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3985. bool & Close)
  3986. {
  3987. // terminal can be already closed (e.g. dropped connection)
  3988. if (Terminal != NULL)
  3989. {
  3990. try
  3991. {
  3992. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  3993. }
  3994. catch(...)
  3995. {
  3996. if (!Terminal->Active)
  3997. {
  3998. Close = true;
  3999. }
  4000. throw;
  4001. }
  4002. }
  4003. }
  4004. //---------------------------------------------------------------------------
  4005. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4006. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4007. bool & Close)
  4008. {
  4009. // terminal can be already closed (e.g. dropped connection)
  4010. if (Terminal != NULL)
  4011. {
  4012. Configuration->Usage->Inc(L"ChecksumCalculated");
  4013. try
  4014. {
  4015. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4016. }
  4017. catch(...)
  4018. {
  4019. if (!Terminal->Active)
  4020. {
  4021. Close = true;
  4022. }
  4023. throw;
  4024. }
  4025. }
  4026. }
  4027. //---------------------------------------------------------------------------
  4028. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4029. {
  4030. bool Result;
  4031. if (!IsSideLocalBrowser(Side))
  4032. {
  4033. TRemoteTokenList * GroupList = NULL;
  4034. TRemoteTokenList * UserList = NULL;
  4035. try
  4036. {
  4037. TRemoteProperties CurrentProperties;
  4038. if (Terminal->LoadFilesProperties(FileList))
  4039. {
  4040. RemoteDirView->Invalidate();
  4041. }
  4042. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4043. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4044. if (CapableGroupChanging || CapableOwnerChanging)
  4045. {
  4046. if (CapableGroupChanging)
  4047. {
  4048. GroupList = Terminal->Groups->Duplicate();
  4049. }
  4050. if (CapableOwnerChanging)
  4051. {
  4052. UserList = Terminal->Users->Duplicate();
  4053. }
  4054. TRemoteDirectory * Files = Terminal->Files;
  4055. int Count = Files->Count;
  4056. if (Count > 100)
  4057. {
  4058. Count = 100;
  4059. }
  4060. for (int Index = 0; Index < Count; Index++)
  4061. {
  4062. TRemoteFile * File = Files->Files[Index];
  4063. if (CapableGroupChanging)
  4064. {
  4065. GroupList->AddUnique(File->Group);
  4066. }
  4067. if (CapableOwnerChanging)
  4068. {
  4069. UserList->AddUnique(File->Owner);
  4070. }
  4071. }
  4072. // if we haven't collected tokens for all files in current directory,
  4073. // make sure we collect them at least for all selected files.
  4074. // (note that so far the files in FileList has to be from current direcotry)
  4075. if (Count < Files->Count)
  4076. {
  4077. for (int Index = 0; Index < FileList->Count; Index++)
  4078. {
  4079. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4080. if (CapableGroupChanging)
  4081. {
  4082. GroupList->AddUnique(File->Group);
  4083. }
  4084. if (CapableOwnerChanging)
  4085. {
  4086. UserList->AddUnique(File->Owner);
  4087. }
  4088. }
  4089. }
  4090. }
  4091. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4092. int Flags = 0;
  4093. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4094. if (CapableOwnerChanging) Flags |= cpOwner;
  4095. if (CapableGroupChanging) Flags |= cpGroup;
  4096. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4097. if (Terminal->IsCapable[fcCalculatingChecksum])
  4098. {
  4099. CalculateChecksumEvent = CalculateChecksum;
  4100. }
  4101. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4102. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4103. TRemoteProperties NewProperties = CurrentProperties;
  4104. Result =
  4105. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4106. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4107. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4108. CalculateSize, CalculateChecksumEvent);
  4109. if (Result)
  4110. {
  4111. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4112. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4113. }
  4114. }
  4115. __finally
  4116. {
  4117. delete GroupList;
  4118. delete UserList;
  4119. }
  4120. }
  4121. else
  4122. {
  4123. DirView(Side)->DisplayPropertiesMenu();
  4124. Result = true;
  4125. }
  4126. return Result;
  4127. }
  4128. //---------------------------------------------------------------------------
  4129. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4130. {
  4131. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4132. {
  4133. FIgnoreNextDialogChar = Key;
  4134. }
  4135. Key = 0;
  4136. }
  4137. //---------------------------------------------------------------------------
  4138. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4139. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4140. {
  4141. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4142. if (Command != NULL)
  4143. {
  4144. KeyProcessed(Key, Shift);
  4145. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4146. {
  4147. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4148. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4149. false, false, const_cast<TCustomCommandType *>(Command));
  4150. }
  4151. }
  4152. }
  4153. //---------------------------------------------------------------------------
  4154. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4155. {
  4156. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4157. {
  4158. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4159. }
  4160. if (!DirView(osCurrent)->IsEditing())
  4161. {
  4162. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4163. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4164. {
  4165. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4166. if (((Action->ShortCut == KeyShortCut) ||
  4167. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4168. AllowedAction(Action, aaShortCut))
  4169. {
  4170. // Has to be called before the action as the dialog char is already in queue.
  4171. // So when the action consumes message queue, we already need to have the
  4172. // FIgnoreNextDialogChar set
  4173. KeyProcessed(Key, Shift);
  4174. // Reset reference to previous component (when menu/toolbar was clicked).
  4175. // Needed to detect that action was invoked by keyboard shortcut
  4176. // in TNonVisualDataModule::ExplorerActionsExecute
  4177. Action->ActionComponent = NULL;
  4178. Action->Execute();
  4179. return;
  4180. }
  4181. }
  4182. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4183. {
  4184. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4185. {
  4186. KeyProcessed(Key, Shift);
  4187. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4188. return;
  4189. }
  4190. }
  4191. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4192. {
  4193. KeyProcessed(Key, Shift);
  4194. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4195. }
  4196. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4197. if (IsCustomShortCut(CustomShortCut))
  4198. {
  4199. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4200. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4201. if (WinConfiguration->SharedBookmarks != NULL)
  4202. {
  4203. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4204. if ((Bookmark != NULL) &&
  4205. OpenBookmark(FCurrentSide, Bookmark))
  4206. {
  4207. KeyProcessed(Key, Shift);
  4208. }
  4209. }
  4210. }
  4211. }
  4212. TForm::KeyDown(Key, Shift);
  4213. }
  4214. //---------------------------------------------------------------------------
  4215. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4216. {
  4217. DebugAssert(Terminal != NULL);
  4218. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4219. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4220. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4221. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4222. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4223. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4224. // expanded from ?: to avoid memory leaks
  4225. if (SecurityEnabled)
  4226. {
  4227. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4228. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4229. }
  4230. else
  4231. {
  4232. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4233. }
  4234. if (FileSystemInfo.ProtocolName.IsEmpty())
  4235. {
  4236. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4237. }
  4238. else
  4239. {
  4240. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4241. }
  4242. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4243. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4244. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4245. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4246. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4247. UnicodeString CompressionStr = CSCompressionStr;
  4248. if (CSCompressionStr != SCCompressionStr)
  4249. {
  4250. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4251. }
  4252. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4253. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4254. UpdateStatusBar();
  4255. }
  4256. //---------------------------------------------------------------------------
  4257. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4258. {
  4259. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4260. DebugAssert(SessionStatusBar != NULL);
  4261. if (!HasActiveTerminal() || (Terminal->Status < ssOpened))
  4262. {
  4263. // note: (Terminal->Status < sshReady) currently never happens here,
  4264. // so STATUS_CONNECTING is never used
  4265. SessionStatusBar->SimplePanel = true;
  4266. SessionStatusBar->SimpleText = LoadStr(
  4267. !HasActiveTerminal() ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4268. }
  4269. else
  4270. {
  4271. DebugAssert(Terminal);
  4272. SessionStatusBar->SimplePanel = false;
  4273. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4274. if (!FNote.IsEmpty())
  4275. {
  4276. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4277. }
  4278. else
  4279. {
  4280. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4281. }
  4282. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4283. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4284. }
  4285. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4286. }
  4287. //---------------------------------------------------------------------------
  4288. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4289. {
  4290. Panel->Caption = L"";
  4291. }
  4292. //---------------------------------------------------------------------------
  4293. void __fastcall TCustomScpExplorerForm::Idle()
  4294. {
  4295. if (FShowing ||
  4296. // Particularly to detect closed connection and automatically reconnect it while waiting for changes
  4297. // while "keeping remote directory up to date"
  4298. StandaloneOperation)
  4299. {
  4300. FEditorManager->Check();
  4301. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4302. // that needs to know if queue view is visible (and it may be closed after queue update)
  4303. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4304. }
  4305. if (FShowing)
  4306. {
  4307. if (!NonVisualDataModule->Busy &&
  4308. // Menu is opened or drag&drop is going on
  4309. (Mouse->Capture == NULL))
  4310. {
  4311. if (FRefreshRemoteDirectory)
  4312. {
  4313. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4314. {
  4315. Terminal->RefreshDirectory();
  4316. }
  4317. FRefreshRemoteDirectory = false;
  4318. }
  4319. if (FRefreshLocalDirectory)
  4320. {
  4321. ReloadLocalDirectory();
  4322. FRefreshLocalDirectory = false;
  4323. }
  4324. if (WinConfiguration->RefreshRemotePanel)
  4325. {
  4326. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4327. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4328. {
  4329. RemoteDirView->ReloadDirectory();
  4330. }
  4331. }
  4332. }
  4333. }
  4334. if (FShowing || StandaloneOperation)
  4335. {
  4336. if (FQueueStatusInvalidated)
  4337. {
  4338. UpdateQueueStatus(false);
  4339. }
  4340. RefreshQueueItems();
  4341. }
  4342. if (FShowing)
  4343. {
  4344. UpdateStatusBar();
  4345. }
  4346. FIgnoreNextDialogChar = 0;
  4347. }
  4348. //---------------------------------------------------------------------------
  4349. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4350. {
  4351. try
  4352. {
  4353. FUserActionTimer->Enabled = false;
  4354. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4355. {
  4356. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4357. {
  4358. FPendingQueueActionItem->ProcessUserAction();
  4359. }
  4360. }
  4361. }
  4362. __finally
  4363. {
  4364. FPendingQueueActionItem = NULL;
  4365. }
  4366. }
  4367. //---------------------------------------------------------------------------
  4368. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4369. {
  4370. if (WinConfiguration->MinimizeToTray)
  4371. {
  4372. UpdateTrayIcon();
  4373. FTrayIcon->Visible = true;
  4374. if (Visible)
  4375. {
  4376. ShowWindow(Handle, SW_HIDE);
  4377. }
  4378. }
  4379. }
  4380. //---------------------------------------------------------------------------
  4381. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4382. {
  4383. // WORKAROUND
  4384. // When restoring maximized window from minimization,
  4385. // rarely some controls do not align properly.
  4386. // Two instances seen (both for Commander):
  4387. // - When restoring, window is temporarily narrower (not maximized),
  4388. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4389. // Once maximized already, top dock shinks back, but the session PageControl,
  4390. // do not align up, leaving space between TopDock and PageControl.
  4391. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4392. for (int Index = 0; Index < ControlCount; Index++)
  4393. {
  4394. RealignControl(Controls[Index]);
  4395. }
  4396. if (FTrayIcon->Visible)
  4397. {
  4398. FTrayIcon->Visible = false;
  4399. if (Visible)
  4400. {
  4401. ShowWindow(Handle, SW_SHOW);
  4402. }
  4403. }
  4404. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4405. {
  4406. FNeedSession = false;
  4407. NonVisualDataModule->StartBusy();
  4408. try
  4409. {
  4410. NeedSession(true);
  4411. }
  4412. __finally
  4413. {
  4414. NonVisualDataModule->EndBusy();
  4415. }
  4416. }
  4417. }
  4418. //---------------------------------------------------------------------------
  4419. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4420. {
  4421. FTrayIcon->Hint = GetMainForm()->Caption;
  4422. }
  4423. //---------------------------------------------------------------------------
  4424. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4425. {
  4426. UpdateTrayIcon();
  4427. }
  4428. //---------------------------------------------------------------------------
  4429. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4430. {
  4431. // workaround
  4432. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4433. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4434. // But WM_ACTIVATEAPP message can be received even when
  4435. // the main window is minimized to the tray and internal editor window is focused
  4436. // (after another application was previously active)
  4437. if (::IsIconic(Handle))
  4438. {
  4439. if (!IsAppIconic())
  4440. {
  4441. SetAppIconic(true);
  4442. }
  4443. }
  4444. ::ApplicationRestore();
  4445. Application->BringToFront();
  4446. }
  4447. //---------------------------------------------------------------------------
  4448. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4449. {
  4450. RestoreApp();
  4451. }
  4452. //---------------------------------------------------------------------------
  4453. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4454. {
  4455. if (OpenInNewWindow())
  4456. {
  4457. ExecuteNewInstance(SessionUrl);
  4458. }
  4459. else
  4460. {
  4461. TTerminalManager::Instance()->NewSession(SessionUrl);
  4462. }
  4463. }
  4464. //---------------------------------------------------------------------------
  4465. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4466. {
  4467. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4468. StoredSessions->NewSession(SessionName, SessionData);
  4469. // modified only, explicit
  4470. StoredSessions->Save(false, true);
  4471. // encode session name because of slashes in hierarchical sessions
  4472. return EncodeUrlString(SessionName);
  4473. }
  4474. //---------------------------------------------------------------------------
  4475. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4476. {
  4477. // current working directories become defaults here, what is not right
  4478. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4479. return SaveHiddenDuplicateSession(SessionData.get());
  4480. }
  4481. //---------------------------------------------------------------------------
  4482. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4483. {
  4484. if (OpenInNewWindow())
  4485. {
  4486. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4487. }
  4488. else
  4489. {
  4490. // current working directories become defaults here, what is not right
  4491. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4492. TTerminalManager * Manager = TTerminalManager::Instance();
  4493. TManagedTerminal * ATerminal = Manager->NewManagedTerminal(SessionData.get());
  4494. // We definitelly want this
  4495. ATerminal->Disconnected = Terminal->Disconnected;
  4496. // Not sure about these two
  4497. ATerminal->Permanent = Terminal->Permanent;
  4498. ATerminal->DisconnectedTemporarily = Terminal->DisconnectedTemporarily; // maybe
  4499. Manager->ActiveTerminal = ATerminal;
  4500. }
  4501. }
  4502. //---------------------------------------------------------------------------
  4503. void __fastcall TCustomScpExplorerForm::RenameSession()
  4504. {
  4505. UnicodeString Name = Terminal->SessionData->SessionName;
  4506. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4507. {
  4508. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4509. TSessionData::ValidateName(Name);
  4510. // This is inconsistent with how color (for example) is handled.
  4511. Terminal->SessionData->Name = Name;
  4512. UpdateControls();
  4513. // Add/Remove distinguishing paths from sessions of the same name.
  4514. DoTerminalListChanged();
  4515. }
  4516. }
  4517. //---------------------------------------------------------------------------
  4518. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4519. {
  4520. DebugAssert(Queue != NULL);
  4521. bool Result = Queue->IsEmpty;
  4522. if (!Result)
  4523. {
  4524. SetFocus();
  4525. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4526. }
  4527. return Result;
  4528. }
  4529. //---------------------------------------------------------------------------
  4530. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4531. {
  4532. return CanCloseQueue(FQueue);
  4533. }
  4534. //---------------------------------------------------------------------------
  4535. void __fastcall TCustomScpExplorerForm::CloseSession()
  4536. {
  4537. if (CanCloseQueue())
  4538. {
  4539. TTerminalManager::Instance()->FreeActiveTerminal();
  4540. }
  4541. }
  4542. //---------------------------------------------------------------------------
  4543. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4544. {
  4545. if (CanCloseQueue())
  4546. {
  4547. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4548. }
  4549. }
  4550. //---------------------------------------------------------------------------
  4551. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4552. {
  4553. DetachTerminal(Terminal);
  4554. RemoteDirView->Terminal = Terminal;
  4555. UpdateRemotePathComboBox(false);
  4556. UpdateControls();
  4557. }
  4558. //---------------------------------------------------------------------------
  4559. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4560. {
  4561. if (DebugAlwaysTrue(!Terminal->Active))
  4562. {
  4563. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4564. }
  4565. }
  4566. //---------------------------------------------------------------------------
  4567. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4568. {
  4569. if (OpenInNewWindow())
  4570. {
  4571. // encode session name because of slashes in hierarchical sessions
  4572. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4573. }
  4574. else
  4575. {
  4576. TTerminalManager * Manager = TTerminalManager::Instance();
  4577. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4578. Manager->ActiveTerminal = Terminal;
  4579. }
  4580. }
  4581. //---------------------------------------------------------------------------
  4582. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4583. {
  4584. TTerminalManager * Manager = TTerminalManager::Instance();
  4585. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4586. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4587. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4588. // FirstTerminal can be null, if some of the
  4589. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4590. {
  4591. FirstTerminal->Disconnected = true;
  4592. FirstTerminal->DisconnectedTemporarily = true;
  4593. }
  4594. Manager->ActiveTerminal = FirstTerminal;
  4595. }
  4596. //---------------------------------------------------------------------------
  4597. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4598. {
  4599. if (OpenInNewWindow())
  4600. {
  4601. ExecuteNewInstance(Name);
  4602. }
  4603. else
  4604. {
  4605. DoOpenFolderOrWorkspace(Name, true);
  4606. }
  4607. }
  4608. //---------------------------------------------------------------------------
  4609. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4610. bool &CanClose)
  4611. {
  4612. // See the comment in CloseApp()
  4613. if (NonVisualDataModule->Busy)
  4614. {
  4615. CanClose = false;
  4616. }
  4617. else
  4618. {
  4619. TTerminalManager * Manager = TTerminalManager::Instance();
  4620. int ActiveSessions = 0;
  4621. for (int Index = 0; Index < Manager->Count; Index++)
  4622. {
  4623. if (Manager->Terminals[Index]->Active)
  4624. {
  4625. ActiveSessions++;
  4626. }
  4627. }
  4628. // Confirm, when there's at least one active remote session
  4629. if ((ActiveSessions > 0) &&
  4630. WinConfiguration->ConfirmClosingSession)
  4631. {
  4632. unsigned int Result;
  4633. TMessageParams Params(mpNeverAskAgainCheck);
  4634. UnicodeString Message;
  4635. int Answers = qaOK | qaCancel;
  4636. // The current session is the only active session
  4637. if ((ActiveSessions == 1) && (Terminal != NULL) && Terminal->Active)
  4638. {
  4639. if (!WinConfiguration->AutoSaveWorkspace)
  4640. {
  4641. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4642. }
  4643. else
  4644. {
  4645. Message = LoadStr(CLOSE_SESSION);
  4646. }
  4647. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4648. }
  4649. // Multiple active sessions or one active session, but it's not the current one
  4650. else if (DebugAlwaysTrue(ActiveSessions > 0))
  4651. {
  4652. if (!WinConfiguration->AutoSaveWorkspace)
  4653. {
  4654. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4655. }
  4656. else
  4657. {
  4658. Message = LoadStr(CLOSE_SESSIONS);
  4659. }
  4660. }
  4661. UnicodeString Note;
  4662. if (WinConfiguration->AutoSaveWorkspace)
  4663. {
  4664. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4665. }
  4666. else
  4667. {
  4668. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4669. Answers = qaYes | qaNo | qaCancel;
  4670. }
  4671. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4672. SetFocus();
  4673. Result = MessageDialog(Message, qtConfirmation,
  4674. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4675. if (Result == qaNeverAskAgain)
  4676. {
  4677. WinConfiguration->ConfirmClosingSession = false;
  4678. }
  4679. if (Result == qaNo)
  4680. {
  4681. CanClose = SaveWorkspace(true);
  4682. // note that the workspace will be saved redundatly again from FormClose
  4683. }
  4684. else
  4685. {
  4686. CanClose =
  4687. (Result == qaOK) ||
  4688. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4689. (Result == qaNeverAskAgain);
  4690. }
  4691. }
  4692. if (CanClose && HasActiveTerminal())
  4693. {
  4694. CanClose = CanCloseQueue();
  4695. }
  4696. }
  4697. if (CanClose)
  4698. {
  4699. CanClose =
  4700. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4701. FEditorManager->CloseExternalFilesWithoutProcess();
  4702. if (CanClose)
  4703. {
  4704. while (CanClose && (FLocalEditors->Count > 0))
  4705. {
  4706. int PrevCount = FLocalEditors->Count;
  4707. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4708. CanClose = (FLocalEditors->Count < PrevCount);
  4709. }
  4710. if (CanClose)
  4711. {
  4712. CanClose = FEditorManager->Empty(true);
  4713. if (!CanClose)
  4714. {
  4715. SetFocus();
  4716. CanClose =
  4717. (MessageDialog(
  4718. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4719. }
  4720. }
  4721. }
  4722. }
  4723. }
  4724. //---------------------------------------------------------------------------
  4725. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4726. {
  4727. TForm * Form = dynamic_cast<TForm *>(Sender);
  4728. DebugAssert(Form != NULL);
  4729. Form->Close();
  4730. }
  4731. //---------------------------------------------------------------------------
  4732. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4733. {
  4734. TForm * Form = dynamic_cast<TForm *>(Sender);
  4735. delete Form;
  4736. }
  4737. //---------------------------------------------------------------------------
  4738. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4739. {
  4740. while (FLocalEditors->Count > 0)
  4741. {
  4742. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4743. }
  4744. }
  4745. //---------------------------------------------------------------------------
  4746. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4747. TObject *Sender)
  4748. {
  4749. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4750. try
  4751. {
  4752. SetProperties(osRemote, FileList);
  4753. }
  4754. __finally
  4755. {
  4756. delete FileList;
  4757. }
  4758. }
  4759. //---------------------------------------------------------------------------
  4760. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4761. {
  4762. if (value)
  4763. {
  4764. if (Component == fcCustomCommandsBand)
  4765. {
  4766. UpdateCustomCommandsToolbar();
  4767. }
  4768. if (Component == fcQueueFileList)
  4769. {
  4770. DebugAssert(!QueueFileListSplitter->Visible);
  4771. AdjustQueueLayout();
  4772. UpdateQueueFileList();
  4773. }
  4774. }
  4775. }
  4776. //---------------------------------------------------------------------------
  4777. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4778. {
  4779. int MinHeightLimit =
  4780. GetStaticQueuePanelComponentsHeight() +
  4781. QueueFileListSplitter->Height +
  4782. QueueFileList->Height +
  4783. GetMinQueueViewHeight();
  4784. if (QueuePanel->ClientHeight < MinHeightLimit)
  4785. {
  4786. QueuePanel->ClientHeight = MinHeightLimit;
  4787. }
  4788. }
  4789. //---------------------------------------------------------------------------
  4790. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4791. {
  4792. TControl * Control = GetComponent(Component);
  4793. DebugAssert(Control);
  4794. bool Changed = (Control->Visible != value);
  4795. if (Changed)
  4796. {
  4797. ComponentShowing(Component, value);
  4798. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4799. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4800. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4801. if (value)
  4802. {
  4803. int RemainingHeight = Control->Parent->ClientHeight;
  4804. int RemainingWidth = Control->Parent->ClientWidth;
  4805. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4806. {
  4807. TControl * ChildControl = Control->Parent->Controls[i];
  4808. if (ChildControl->Visible)
  4809. {
  4810. switch (ChildControl->Align)
  4811. {
  4812. case alTop:
  4813. case alBottom:
  4814. RemainingHeight -= ChildControl->Height;
  4815. break;
  4816. case alLeft:
  4817. case alRight:
  4818. RemainingWidth -= ChildControl->Width;
  4819. break;
  4820. }
  4821. }
  4822. }
  4823. int Reserve = ScaleByTextHeight(this, 32);
  4824. // queue in explorer, trees in commander
  4825. if (Control->Height > RemainingHeight - Reserve)
  4826. {
  4827. Control->Height = RemainingHeight / 2;
  4828. }
  4829. if (Control->Width > RemainingWidth - Reserve)
  4830. {
  4831. Control->Width = RemainingWidth / 2;
  4832. }
  4833. }
  4834. Control->Visible = value;
  4835. if (WasFocused && Visible)
  4836. {
  4837. DirView(osCurrent)->SetFocus();
  4838. }
  4839. FixControlsPlacement();
  4840. }
  4841. }
  4842. //---------------------------------------------------------------------------
  4843. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4844. {
  4845. TControl * Control = GetComponent(Component);
  4846. if (Control == NULL)
  4847. {
  4848. return false;
  4849. }
  4850. else
  4851. {
  4852. return Control->Visible;
  4853. }
  4854. }
  4855. //---------------------------------------------------------------------------
  4856. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4857. {
  4858. bool Result;
  4859. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4860. {
  4861. Result = !IsUWP();
  4862. }
  4863. else
  4864. {
  4865. Result = true;
  4866. }
  4867. return Result;
  4868. }
  4869. //---------------------------------------------------------------------------
  4870. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4871. {
  4872. if (DirView(osOther)->ItemFocused != NULL)
  4873. {
  4874. DirView(osOther)->ItemFocused->MakeVisible(false);
  4875. }
  4876. QueueSplitter->Visible = QueuePanel->Visible;
  4877. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4878. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4879. TControl * QueueControlsOrder[] =
  4880. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4881. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4882. }
  4883. //---------------------------------------------------------------------------
  4884. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4885. {
  4886. switch (Component) {
  4887. case fcStatusBar: return RemoteStatusBar;
  4888. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4889. case fcQueueView: return QueuePanel;
  4890. case fcQueueToolbar: return QueueDock;
  4891. case fcRemoteTree: return RemoteDrivePanel;
  4892. case fcSessionsTabs: return SessionsPageControl;
  4893. case fcQueueFileList: return QueueFileList;
  4894. default: return NULL;
  4895. }
  4896. }
  4897. //---------------------------------------------------------------------------
  4898. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4899. TObject *Sender, TListColumn *Column, TPoint &Point)
  4900. {
  4901. DebugAssert(NonVisualDataModule && Column && Sender);
  4902. NonVisualDataModule->ListColumn = Column;
  4903. TPopupMenu * DirViewColumnMenu;
  4904. if (dynamic_cast<TUnixDirView *>(Sender) != NULL)
  4905. {
  4906. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4907. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4908. (Column->Index == uvName);
  4909. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4910. (Column->Index == uvSize);
  4911. }
  4912. else
  4913. {
  4914. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4915. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4916. (Column->Index == dvName);
  4917. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4918. (Column->Index == dvSize);
  4919. }
  4920. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4921. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4922. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4923. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4924. }
  4925. //---------------------------------------------------------------------------
  4926. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4927. TObject *Sender, TListItem *Item, bool &AllowExec)
  4928. {
  4929. DoDirViewExecFile(Sender, Item, AllowExec);
  4930. }
  4931. //---------------------------------------------------------------------------
  4932. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4933. TListItem * Item, bool & AllowExec)
  4934. {
  4935. DebugAssert(Sender && Item && Configuration);
  4936. DebugAssert(AllowExec);
  4937. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4938. bool Remote = (ADirView == DirView(osRemote)) && !IsSideLocalBrowser(osRemote);
  4939. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  4940. TOperationSide Side = (Remote ? osRemote : osLocal);
  4941. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4942. // on files only (not directories)
  4943. // and only when symlinks are resolved (apply to remote panel only)
  4944. if (!ADirView->ItemIsDirectory(Item) &&
  4945. (ResolvedSymlinks || FForceExecution))
  4946. {
  4947. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4948. !FForceExecution && ResolvedSymlinks)
  4949. {
  4950. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4951. {
  4952. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4953. UnlockWindow();
  4954. try
  4955. {
  4956. ExecuteFileOperation(
  4957. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4958. }
  4959. __finally
  4960. {
  4961. LockWindow();
  4962. }
  4963. AllowExec = false;
  4964. }
  4965. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4966. {
  4967. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4968. {
  4969. ExecuteFile(Side, efDefaultEditor);
  4970. AllowExec = false;
  4971. }
  4972. }
  4973. else
  4974. {
  4975. DebugFail();
  4976. }
  4977. }
  4978. // if we have not done anything special, fall back to default behavior
  4979. if (AllowExec)
  4980. {
  4981. if (Remote && !WinConfiguration->DisableOpenEdit)
  4982. {
  4983. ExecuteFile(osRemote, efShell);
  4984. AllowExec = false;
  4985. }
  4986. }
  4987. }
  4988. }
  4989. //---------------------------------------------------------------------------
  4990. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4991. {
  4992. return ((Side == osRemote) || (Side == osCurrent));
  4993. }
  4994. //---------------------------------------------------------------------------
  4995. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  4996. {
  4997. DebugFail();
  4998. }
  4999. //---------------------------------------------------------------------------
  5000. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5001. {
  5002. DebugFail();
  5003. }
  5004. //---------------------------------------------------------------------------
  5005. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5006. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5007. {
  5008. TSynchronizeParamType Params;
  5009. Params.LocalDirectory = LocalDirectory;
  5010. Params.RemoteDirectory = RemoteDirectory;
  5011. int UnusedParams =
  5012. (GUIConfiguration->SynchronizeParams &
  5013. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5014. TTerminal::spCaseSensitive));
  5015. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5016. Params.Options = GUIConfiguration->SynchronizeOptions;
  5017. bool SaveSettings = false;
  5018. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5019. &DoSynchronizeTooManyDirectories);
  5020. DebugAssert(FSynchronizeController == NULL);
  5021. FSynchronizeController = &Controller;
  5022. bool Result;
  5023. try
  5024. {
  5025. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5026. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5027. int Options =
  5028. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5029. DebugAssert(FOnFeedSynchronizeError == NULL);
  5030. DebugAssert(FOnSynchronizeAbort == NULL);
  5031. DebugAssert(FSynchronizeTerminal == NULL);
  5032. FSynchronizeTerminal = Terminal;
  5033. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5034. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5035. FOnFeedSynchronizeError, FOnSynchronizeAbort, SynchronizeInNewWindow, UseDefaults);
  5036. if (Result)
  5037. {
  5038. if (SaveSettings)
  5039. {
  5040. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5041. GUIConfiguration->SynchronizeOptions = Params.Options;
  5042. }
  5043. else
  5044. {
  5045. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5046. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5047. FLAGSET(Params.Options, soSynchronize))
  5048. {
  5049. GUIConfiguration->SynchronizeOptions =
  5050. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5051. soSynchronize;
  5052. }
  5053. }
  5054. LocalDirectory = Params.LocalDirectory;
  5055. RemoteDirectory = Params.RemoteDirectory;
  5056. }
  5057. }
  5058. __finally
  5059. {
  5060. FSynchronizeController = NULL;
  5061. DebugAssert(FOnFeedSynchronizeError == NULL);
  5062. FOnFeedSynchronizeError = NULL;
  5063. DebugAssert(FOnSynchronizeAbort == NULL);
  5064. FOnSynchronizeAbort = NULL;
  5065. FSynchronizeTerminal = NULL;
  5066. }
  5067. return Result;
  5068. }
  5069. //---------------------------------------------------------------------------
  5070. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5071. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5072. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5073. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5074. TSynchronizeOptions * Options, bool Full)
  5075. {
  5076. // Keep-up-to-date mode
  5077. if (Terminal->Status == ssOpened)
  5078. {
  5079. try
  5080. {
  5081. int PParams = Params.Params;
  5082. if (!Full)
  5083. {
  5084. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5085. if (FLAGSET(Params.Options, soRecurse))
  5086. {
  5087. PParams |= TTerminal::spSubDirs;
  5088. }
  5089. }
  5090. else
  5091. {
  5092. // if keepuptodate is non-recursive,
  5093. // full sync before has to be non-recursive as well
  5094. if (FLAGCLEAR(Params.Options, soRecurse))
  5095. {
  5096. PParams |= TTerminal::spNoRecurse;
  5097. }
  5098. }
  5099. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5100. PParams, Checklist, Options);
  5101. }
  5102. catch (Exception & E)
  5103. {
  5104. if (!Terminal->Active)
  5105. {
  5106. ShowExtendedExceptionEx(Terminal, &E);
  5107. // Do not abort the "keep up to date" when the session was succesfully reconnected.
  5108. if (!Terminal->Active)
  5109. {
  5110. throw;
  5111. }
  5112. }
  5113. else
  5114. {
  5115. if (FLAGSET(Params.Options, soContinueOnError) &&
  5116. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5117. {
  5118. // noop, already logged in MoreMessageDialog
  5119. }
  5120. else
  5121. {
  5122. // We get mostly EAbort here, so this is noop.
  5123. // Exception is an error when listing directories while looking for differences.
  5124. ShowExtendedExceptionEx(Terminal, &E);
  5125. throw;
  5126. }
  5127. }
  5128. }
  5129. }
  5130. }
  5131. //---------------------------------------------------------------------------
  5132. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5133. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5134. const UnicodeString ErrorStr)
  5135. {
  5136. if (!Directory.IsEmpty())
  5137. {
  5138. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5139. }
  5140. else
  5141. {
  5142. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5143. }
  5144. }
  5145. //---------------------------------------------------------------------------
  5146. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5147. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5148. {
  5149. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5150. {
  5151. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5152. }
  5153. else
  5154. {
  5155. TMessageParams Params(mpNeverAskAgainCheck);
  5156. unsigned int Result = MessageDialog(
  5157. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5158. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5159. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5160. {
  5161. MaxDirectories *= 2;
  5162. if (Result == qaNeverAskAgain)
  5163. {
  5164. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5165. }
  5166. }
  5167. else
  5168. {
  5169. Abort();
  5170. }
  5171. }
  5172. }
  5173. //---------------------------------------------------------------------------
  5174. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5175. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5176. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5177. TSynchronizeOptions * Options)
  5178. {
  5179. // Keep-up-to-date mode
  5180. DebugAssert(!FAutoOperation);
  5181. void * BatchStorage;
  5182. BatchStart(BatchStorage);
  5183. FAutoOperation = true;
  5184. bool AnyOperation = false;
  5185. TDateTime StartTime = Now();
  5186. TSynchronizeChecklist * AChecklist = NULL;
  5187. try
  5188. {
  5189. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5190. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5191. {
  5192. FSynchronizeProgressForm->Start();
  5193. }
  5194. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5195. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5196. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5197. Options);
  5198. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5199. SAFE_DESTROY(FSynchronizeProgressForm);
  5200. AnyOperation = (AChecklist->CheckedCount > 0);
  5201. if (AnyOperation)
  5202. {
  5203. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5204. CreateProgressForm(&SynchronizeProgress);
  5205. try
  5206. {
  5207. Terminal->SynchronizeApply(
  5208. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5209. SynchronizeProcessedItem, NULL, NULL, NULL);
  5210. }
  5211. __finally
  5212. {
  5213. DestroyProgressForm();
  5214. }
  5215. }
  5216. }
  5217. __finally
  5218. {
  5219. if (Checklist == NULL)
  5220. {
  5221. delete AChecklist;
  5222. }
  5223. else
  5224. {
  5225. *Checklist = AChecklist;
  5226. }
  5227. FAutoOperation = false;
  5228. SAFE_DESTROY(FSynchronizeProgressForm);
  5229. BatchEnd(BatchStorage);
  5230. ReloadLocalDirectory();
  5231. if (AnyOperation)
  5232. {
  5233. OperationComplete(StartTime);
  5234. }
  5235. }
  5236. }
  5237. //---------------------------------------------------------------------------
  5238. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5239. {
  5240. // can be called from command line
  5241. return Visible &&
  5242. ((DirView(osRemote)->SelCount > 0) ||
  5243. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5244. }
  5245. //---------------------------------------------------------------------------
  5246. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5247. {
  5248. LogSynchronizeEvent(Terminal, Message);
  5249. }
  5250. //---------------------------------------------------------------------------
  5251. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5252. int Params, TSynchronizeOptions & Options)
  5253. {
  5254. DebugAssert(!IsLocalBrowserMode());
  5255. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5256. {
  5257. Options.Filter = new TStringList();
  5258. Options.Filter->CaseSensitive = false;
  5259. Options.Filter->Duplicates = Types::dupAccept;
  5260. if (DirView(osRemote)->SelCount > 0)
  5261. {
  5262. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5263. }
  5264. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5265. {
  5266. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5267. }
  5268. Options.Filter->Sort();
  5269. }
  5270. }
  5271. //---------------------------------------------------------------------------
  5272. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5273. {
  5274. TCopyParamType Defaults;
  5275. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5276. ConfigStorage->AccessMode = smRead;
  5277. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5278. {
  5279. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5280. }
  5281. ConfigStorage.reset(NULL);
  5282. std::unique_ptr<TStringList> Options(new TStringList());
  5283. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5284. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5285. UnicodeString Result;
  5286. if (Options->Count > 0)
  5287. {
  5288. Result =
  5289. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5290. }
  5291. return Result;
  5292. }
  5293. //---------------------------------------------------------------------------
  5294. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5295. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5296. {
  5297. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5298. UnicodeString AdditionalParams =
  5299. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5300. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5301. SerializeCopyParamForCommandLine(CopyParams),
  5302. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5303. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5304. ExecuteNewInstance(SessionName, AdditionalParams);
  5305. }
  5306. //---------------------------------------------------------------------------
  5307. struct TSynchronizeParams
  5308. {
  5309. UnicodeString LocalDirectory;
  5310. UnicodeString RemoteDirectory;
  5311. TSynchronizeMode Mode;
  5312. TSynchronizeChecklist * Checklist;
  5313. int Params;
  5314. TCopyParamType * CopyParam;
  5315. TDateTime CollectElapsed;
  5316. TDateTime * StartTime;
  5317. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5318. };
  5319. //---------------------------------------------------------------------------
  5320. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5321. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5322. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5323. {
  5324. DebugAssert(!FAutoOperation);
  5325. void * BatchStorage;
  5326. BatchStart(BatchStorage);
  5327. FAutoOperation = true;
  5328. TFileOperationStatistics Statistics;
  5329. TDateTime Start = Now();
  5330. try
  5331. {
  5332. Params.OnProcessedItem = OnProcessedItem;
  5333. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5334. CreateProgressForm(&SynchronizeProgress);
  5335. Terminal->SynchronizeApply(
  5336. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5337. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5338. &Statistics);
  5339. }
  5340. __finally
  5341. {
  5342. Params.OnProcessedItem = NULL;
  5343. FAutoOperation = false;
  5344. DestroyProgressForm();
  5345. BatchEnd(BatchStorage);
  5346. ReloadLocalDirectory();
  5347. }
  5348. if (WinConfiguration->SynchronizeSummary)
  5349. {
  5350. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5351. // The statistics should be 0 anyway in this case
  5352. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5353. {
  5354. Message += L"\n";
  5355. if (Statistics.FilesUploaded > 0)
  5356. {
  5357. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5358. }
  5359. if (Statistics.FilesDownloaded > 0)
  5360. {
  5361. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5362. }
  5363. if (Statistics.FilesDeletedLocal > 0)
  5364. {
  5365. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5366. }
  5367. if (Statistics.FilesDeletedRemote > 0)
  5368. {
  5369. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5370. }
  5371. }
  5372. TDateTime Elapsed = (Now() - Start);
  5373. Message +=
  5374. L"\n" +
  5375. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5376. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5377. TMessageParams Params(mpNeverAskAgainCheck);
  5378. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5379. if (Result == qaNeverAskAgain)
  5380. {
  5381. WinConfiguration->SynchronizeSummary = false;
  5382. }
  5383. }
  5384. }
  5385. //---------------------------------------------------------------------------
  5386. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5387. {
  5388. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5389. {
  5390. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5391. }
  5392. // Not set in keep-up-to-date mode - Synchronize() method
  5393. if (Token != NULL)
  5394. {
  5395. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5396. if (Params.OnProcessedItem != NULL)
  5397. {
  5398. Params.OnProcessedItem(NULL, ChecklistItem);
  5399. }
  5400. }
  5401. }
  5402. //---------------------------------------------------------------------------
  5403. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5404. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5405. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5406. {
  5407. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5408. *Params.StartTime = Now();
  5409. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5410. }
  5411. //---------------------------------------------------------------------------
  5412. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5413. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5414. {
  5415. // terminal can be already closed (e.g. dropped connection)
  5416. if (Terminal != NULL)
  5417. {
  5418. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5419. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5420. }
  5421. }
  5422. //---------------------------------------------------------------------------
  5423. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5424. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5425. {
  5426. DebugAssert(!IsLocalBrowserMode());
  5427. TAutoBatch AutoBatch(this);
  5428. TAutoFlag AutoOperationFlag(FAutoOperation);
  5429. if (Side == osRemote)
  5430. {
  5431. std::unique_ptr<TStrings> FileList(new TStringList());
  5432. FileList->AddObject(FileName, RemoteFile);
  5433. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5434. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5435. RemoteDirView->SaveSelection();
  5436. RemoteDirView->SaveSelectedNames();
  5437. try
  5438. {
  5439. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5440. }
  5441. catch(...)
  5442. {
  5443. RemoteDirView->DiscardSavedSelection();
  5444. throw;
  5445. }
  5446. RemoteDirView->RestoreSelection();
  5447. }
  5448. else if (DebugAlwaysTrue(Side == osLocal))
  5449. {
  5450. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5451. {
  5452. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5453. }
  5454. UnicodeString Directory = ExtractFileDir(FileName);
  5455. ReloadLocalDirectory(Directory);
  5456. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5457. if (!SamePaths(Directory, NewDirectory))
  5458. {
  5459. ReloadLocalDirectory(NewDirectory);
  5460. }
  5461. }
  5462. }
  5463. //---------------------------------------------------------------------------
  5464. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5465. {
  5466. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5467. if (Side == osLocal)
  5468. {
  5469. if (Action == TSynchronizeChecklist::saDownloadNew)
  5470. {
  5471. OpenFolderInExplorer(LocalPath);
  5472. }
  5473. else
  5474. {
  5475. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5476. }
  5477. }
  5478. else if (DebugAlwaysTrue(Side == osRemote))
  5479. {
  5480. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5481. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5482. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5483. if (!LocalPath.IsEmpty())
  5484. {
  5485. SessionData->LocalDirectory = LocalPath;
  5486. }
  5487. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5488. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5489. }
  5490. }
  5491. //---------------------------------------------------------------------------
  5492. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5493. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5494. const TCopyParamType * CopyParams)
  5495. {
  5496. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5497. UnicodeString AdditionalParams =
  5498. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5499. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5500. SerializeCopyParamForCommandLine(CopyParams),
  5501. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5502. LocalDirectory, RemoteDirectory, Mode, Params));
  5503. ExecuteNewInstance(SessionName, AdditionalParams);
  5504. }
  5505. //---------------------------------------------------------------------------
  5506. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5507. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5508. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5509. {
  5510. int Result;
  5511. bool SaveSettings = false;
  5512. int Options =
  5513. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5514. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5515. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5516. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5517. bool Continue =
  5518. (UseDefaults == 0) ||
  5519. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5520. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5521. if (Continue)
  5522. {
  5523. Configuration->Usage->Inc(L"Synchronizations");
  5524. UpdateCopyParamCounters(CopyParam);
  5525. TSynchronizeOptions SynchronizeOptions;
  5526. GetSynchronizeOptions(Params, SynchronizeOptions);
  5527. if (SaveSettings)
  5528. {
  5529. GUIConfiguration->SynchronizeParams = Params;
  5530. }
  5531. else
  5532. {
  5533. SaveMode = false;
  5534. }
  5535. TDateTime StartTime = Now();
  5536. TSynchronizeChecklist * Checklist = NULL;
  5537. try
  5538. {
  5539. DebugAssert(!FAutoOperation);
  5540. FAutoOperation = true;
  5541. try
  5542. {
  5543. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5544. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5545. int Files = -1;
  5546. if (DataList->Count >= 1)
  5547. {
  5548. Files = StrToIntDef(DataList->Strings[0], Files);
  5549. }
  5550. else
  5551. {
  5552. DataList->Add(UnicodeString());
  5553. }
  5554. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5555. FSynchronizeProgressForm->Start();
  5556. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5557. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5558. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5559. &SynchronizeOptions);
  5560. if (Terminal->SessionData->CacheDirectories)
  5561. {
  5562. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5563. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5564. }
  5565. }
  5566. __finally
  5567. {
  5568. FAutoOperation = false;
  5569. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5570. SAFE_DESTROY(FSynchronizeProgressForm);
  5571. }
  5572. TSynchronizeParams SynchronizeParams;
  5573. SynchronizeParams.LocalDirectory = LocalDirectory;
  5574. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5575. SynchronizeParams.Mode = Mode;
  5576. SynchronizeParams.CopyParam = &CopyParam;
  5577. SynchronizeParams.Params = Params;
  5578. SynchronizeParams.Checklist = Checklist;
  5579. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5580. SynchronizeParams.StartTime = &StartTime;
  5581. SynchronizeParams.OnProcessedItem = NULL;
  5582. Result = Checklist->Count;
  5583. if (Checklist->Count > 0)
  5584. {
  5585. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5586. {
  5587. if (!DoSynchronizeChecklistDialog(
  5588. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5589. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5590. {
  5591. Result = -1;
  5592. }
  5593. }
  5594. else
  5595. {
  5596. FullSynchronize(SynchronizeParams, NULL, NULL);
  5597. }
  5598. }
  5599. else
  5600. {
  5601. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5602. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5603. }
  5604. }
  5605. __finally
  5606. {
  5607. delete Checklist;
  5608. }
  5609. OperationComplete(StartTime);
  5610. }
  5611. else
  5612. {
  5613. Result = -1;
  5614. }
  5615. return Result;
  5616. }
  5617. //---------------------------------------------------------------------------
  5618. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5619. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5620. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5621. {
  5622. if (Collect)
  5623. {
  5624. DebugAssert(FSynchronizeProgressForm != NULL);
  5625. if (!FSynchronizeProgressForm->Started)
  5626. {
  5627. FSynchronizeProgressForm->Start();
  5628. }
  5629. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5630. SetTaskbarListProgressValue(CompareProgress);
  5631. }
  5632. else
  5633. {
  5634. DebugAssert(FSynchronizeProgressForm == NULL);
  5635. DebugAssert(FProgressForm != NULL);
  5636. }
  5637. }
  5638. //---------------------------------------------------------------------------
  5639. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5640. {
  5641. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5642. TRemoteFile * File = NULL;
  5643. Terminal->ReadFile(FullFileName, File);
  5644. if (File != NULL)
  5645. {
  5646. std::unique_ptr<TRemoteFile> FileOwner(File);
  5647. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5648. Application->ShowMainForm = false;
  5649. Application->Run();
  5650. }
  5651. }
  5652. //---------------------------------------------------------------------------
  5653. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5654. {
  5655. DebugFail();
  5656. }
  5657. //---------------------------------------------------------------------------
  5658. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5659. {
  5660. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5661. SessionData->Assign(Terminal->SessionData);
  5662. UpdateSessionData(SessionData.get());
  5663. if (Terminal->Active)
  5664. {
  5665. Terminal->UpdateSessionCredentials(SessionData.get());
  5666. }
  5667. if (!Terminal->SessionData->HasSessionName())
  5668. {
  5669. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5670. // once IsWorkspace is cleared
  5671. SessionData->Name = UnicodeString();
  5672. }
  5673. // Most uses of this method ends with saving the session, and we do not want to store the IsWorkspace flag.
  5674. // Particularly, with SaveHiddenDuplicateSession, it won't work as TSessionData::ParseUrl explicitly ignored workspace sessions.
  5675. SessionData->IsWorkspace = false;
  5676. return SessionData.release();
  5677. }
  5678. //---------------------------------------------------------------------------
  5679. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5680. {
  5681. TSessionData * SessionData = CloneCurrentSessionData();
  5682. try
  5683. {
  5684. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5685. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5686. }
  5687. __finally
  5688. {
  5689. delete SessionData;
  5690. }
  5691. }
  5692. //---------------------------------------------------------------------------
  5693. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5694. {
  5695. TTerminalManager * Manager = TTerminalManager::Instance();
  5696. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5697. if (DebugAlwaysTrue(Terminal != NULL))
  5698. {
  5699. // Update (Managed)Terminal->StateData
  5700. UpdateTerminal(Terminal);
  5701. }
  5702. Manager->SaveWorkspace(DataList.get());
  5703. return DataList.release();
  5704. }
  5705. //---------------------------------------------------------------------------
  5706. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5707. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5708. {
  5709. WinConfiguration->LastWorkspace = Name;
  5710. if (!SavePasswords)
  5711. {
  5712. for (int Index = 0; Index < DataList->Count; Index++)
  5713. {
  5714. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5715. if (SessionData->Link.IsEmpty())
  5716. {
  5717. SessionData->ClearSessionPasswords();
  5718. }
  5719. }
  5720. }
  5721. StoredSessions->NewWorkspace(Name, DataList);
  5722. // modified only
  5723. StoredSessions->Save(false, Explicit);
  5724. }
  5725. //---------------------------------------------------------------------------
  5726. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5727. {
  5728. return
  5729. DefaultStr(WinConfiguration->LastWorkspace,
  5730. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5731. }
  5732. //---------------------------------------------------------------------------
  5733. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5734. {
  5735. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5736. bool AnyNonStoredSessionWithPassword = false;
  5737. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5738. bool AllNonStoredSessionsAnonymous = true;
  5739. TTerminalManager * Manager = TTerminalManager::Instance();
  5740. for (int Index = 0; Index < DataList->Count; Index++)
  5741. {
  5742. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5743. if (SessionData->Link.IsEmpty())
  5744. {
  5745. if (SessionData->HasAnySessionPassword())
  5746. {
  5747. AnyNonStoredSessionWithPassword = true;
  5748. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5749. {
  5750. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5751. }
  5752. }
  5753. if (!SameText(SessionData->UserName, AnonymousUserName))
  5754. {
  5755. AllNonStoredSessionsAnonymous = false;
  5756. }
  5757. }
  5758. }
  5759. bool SavePasswords;
  5760. bool * PSavePasswords;
  5761. bool NotRecommendedSavingPasswords =
  5762. !CustomWinConfiguration->UseMasterPassword &&
  5763. !AllNonStoredSessionsAnonymous;
  5764. if (Configuration->DisablePasswordStoring ||
  5765. !AnyNonStoredSessionWithPassword)
  5766. {
  5767. PSavePasswords = NULL;
  5768. SavePasswords = false;
  5769. }
  5770. else
  5771. {
  5772. PSavePasswords = &SavePasswords;
  5773. SavePasswords =
  5774. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5775. !NotRecommendedSavingPasswords;
  5776. }
  5777. UnicodeString Name = WorkspaceName();
  5778. bool CreateShortcut = false;
  5779. bool Result =
  5780. DoSaveWorkspaceDialog(
  5781. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5782. EnableAutoSave);
  5783. if (Result)
  5784. {
  5785. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5786. if (CreateShortcut)
  5787. {
  5788. TOperationVisualizer Visualizer;
  5789. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5790. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5791. }
  5792. if (EnableAutoSave)
  5793. {
  5794. WinConfiguration->AutoSaveWorkspace = true;
  5795. WinConfiguration->AutoWorkspace = Name;
  5796. if (PSavePasswords != NULL)
  5797. {
  5798. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5799. }
  5800. }
  5801. }
  5802. return Result;
  5803. }
  5804. //---------------------------------------------------------------------------
  5805. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5806. {
  5807. DebugAssert(!IsLocalBrowserMode());
  5808. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5809. if (WinConfiguration->PreservePanelState)
  5810. {
  5811. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5812. }
  5813. UpdateSessionData(Terminal->StateData);
  5814. }
  5815. //---------------------------------------------------------------------------
  5816. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5817. {
  5818. // Keep in sync with TSessionData::CopyStateData
  5819. DebugAssert(!IsLocalBrowserMode());
  5820. DebugAssert(Data != NULL);
  5821. // This is inconsistent with how color (for example) is handled.
  5822. Data->Name = Terminal->SessionData->Name;
  5823. // cannot use RemoteDirView->Path, because it is empty if connection
  5824. // was already closed
  5825. // also only peek, we may not be connected at all atm
  5826. // so make sure we do not try retrieving current directory from the server
  5827. // (particularly with FTP)
  5828. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5829. if (!ACurrentDirectory.IsEmpty())
  5830. {
  5831. Data->RemoteDirectory = ACurrentDirectory;
  5832. }
  5833. Data->Color = SessionColor;
  5834. }
  5835. //---------------------------------------------------------------------------
  5836. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5837. {
  5838. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5839. DebugAssert(Toolbar != NULL);
  5840. for (int i = 0; i < Toolbar->Items->Count; i++)
  5841. {
  5842. TTBXCustomDropDownItem * DropDownItem;
  5843. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5844. if (DropDownItem != NULL)
  5845. {
  5846. ToolbarItemResize(DropDownItem,
  5847. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5848. Toolbar->NonClientWidth);
  5849. break;
  5850. }
  5851. }
  5852. }
  5853. //---------------------------------------------------------------------------
  5854. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5855. {
  5856. Item->EditWidth = Width;
  5857. }
  5858. //---------------------------------------------------------------------------
  5859. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5860. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5861. {
  5862. for (int i = 0; i < Toolbar->Items->Count; i++)
  5863. {
  5864. TTBXCustomDropDownItem * DropDownItem;
  5865. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5866. if (DropDownItem != NULL)
  5867. {
  5868. ASize.x -= DropDownItem->EditWidth;
  5869. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5870. }
  5871. }
  5872. }
  5873. //---------------------------------------------------------------------------
  5874. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5875. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5876. {
  5877. if (WinConfiguration->DDWarnLackOfTempSpace)
  5878. {
  5879. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5880. if (!ADrive.IsEmpty())
  5881. {
  5882. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5883. DebugAssert(RequiredSpace >= 0);
  5884. __int64 RequiredWithReserve;
  5885. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5886. if (FreeSpace < RequiredWithReserve)
  5887. {
  5888. unsigned int Result;
  5889. TMessageParams Params(mpNeverAskAgainCheck);
  5890. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5891. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5892. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5893. if (Result == qaNeverAskAgain)
  5894. {
  5895. WinConfiguration->DDWarnLackOfTempSpace = false;
  5896. }
  5897. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5898. }
  5899. }
  5900. }
  5901. }
  5902. //---------------------------------------------------------------------------
  5903. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5904. {
  5905. DoOpenDirectoryDialog(odAddBookmark, Side);
  5906. }
  5907. //---------------------------------------------------------------------------
  5908. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5909. {
  5910. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5911. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5912. try
  5913. {
  5914. TCustomDirView * DView = DirView(Side);
  5915. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5916. {
  5917. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5918. }
  5919. }
  5920. catch (...)
  5921. {
  5922. delete VisitedDirectories;
  5923. throw;
  5924. }
  5925. return VisitedDirectories;
  5926. }
  5927. //---------------------------------------------------------------------------
  5928. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5929. TOpenDirectoryMode Mode, TOperationSide Side)
  5930. {
  5931. bool Continue = true;
  5932. if (Mode == odAddBookmark)
  5933. {
  5934. TMessageParams Params(mpNeverAskAgainCheck);
  5935. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5936. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5937. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5938. unsigned int Answer =
  5939. MessageDialog(Message,
  5940. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5941. if (Answer == qaNeverAskAgain)
  5942. {
  5943. Continue = true;
  5944. WinConfiguration->UseSharedBookmarks = true;
  5945. }
  5946. else if (Answer == qaOK)
  5947. {
  5948. Continue = true;
  5949. WinConfiguration->UseSharedBookmarks = false;
  5950. }
  5951. else
  5952. {
  5953. Continue = false;
  5954. }
  5955. }
  5956. if (Continue)
  5957. {
  5958. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5959. try
  5960. {
  5961. UnicodeString Name = DirView(Side)->PathName;
  5962. bool Repeat;
  5963. do
  5964. {
  5965. Repeat = false;
  5966. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5967. // do not allow switching to location profiles,
  5968. // if we are not connected
  5969. HasDirView[osLocal] && (Terminal != NULL)))
  5970. {
  5971. TWindowLock Lock(this);
  5972. if (!TryOpenDirectory(Side, Name))
  5973. {
  5974. Repeat = true;
  5975. Mode = odBrowse;
  5976. }
  5977. }
  5978. }
  5979. while (Repeat);
  5980. }
  5981. __finally
  5982. {
  5983. delete VisitedDirectories;
  5984. }
  5985. }
  5986. }
  5987. //---------------------------------------------------------------------------
  5988. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5989. {
  5990. DebugAssert(!FTerminal->CommandSessionOpened);
  5991. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5992. }
  5993. //---------------------------------------------------------------------------
  5994. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5995. {
  5996. bool Result = FTerminal->IsCapable[Capability] ||
  5997. FTerminal->CommandSessionOpened;
  5998. if (!Result)
  5999. {
  6000. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  6001. if (!GUIConfiguration->ConfirmCommandSession)
  6002. {
  6003. Result = true;
  6004. }
  6005. else
  6006. {
  6007. TMessageParams Params(mpNeverAskAgainCheck);
  6008. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6009. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6010. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6011. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6012. if (Answer == qaNeverAskAgain)
  6013. {
  6014. GUIConfiguration->ConfirmCommandSession = false;
  6015. Result = true;
  6016. }
  6017. else if (Answer == qaOK)
  6018. {
  6019. Result = true;
  6020. }
  6021. }
  6022. if (Result)
  6023. {
  6024. Result = CommandSessionFallback();
  6025. }
  6026. }
  6027. return Result;
  6028. }
  6029. //---------------------------------------------------------------------------
  6030. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6031. {
  6032. if (EnsureCommandSessionFallback(fcAnyCommand))
  6033. {
  6034. DoConsoleDialog(Terminal, Command);
  6035. }
  6036. }
  6037. //---------------------------------------------------------------------------
  6038. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6039. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6040. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6041. {
  6042. if (!IsSideLocalBrowser(osRemote) &&
  6043. IsFileControl(DropSourceControl, osRemote) &&
  6044. (FDDExtMapFile != NULL))
  6045. {
  6046. Accept = true;
  6047. }
  6048. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6049. DebugAssert(FDDTargetControl != NULL);
  6050. }
  6051. //---------------------------------------------------------------------------
  6052. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6053. _di_IDataObject DataObj, int KeyState,
  6054. const TPoint & Point, int & Effect, bool & Accept)
  6055. {
  6056. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6057. }
  6058. //---------------------------------------------------------------------------
  6059. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6060. _di_IDataObject DataObj, int KeyState,
  6061. const TPoint & Point, int & Effect, bool & Accept)
  6062. {
  6063. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6064. }
  6065. //---------------------------------------------------------------------------
  6066. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6067. TObject * Sender)
  6068. {
  6069. DebugUsedParam(Sender);
  6070. DebugAssert(FDDTargetControl == Sender);
  6071. FDDTargetControl = NULL;
  6072. }
  6073. //---------------------------------------------------------------------------
  6074. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6075. {
  6076. FileControlDDDragLeave(SessionsPageControl);
  6077. }
  6078. //---------------------------------------------------------------------------
  6079. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6080. {
  6081. FileControlDDDragLeave(QueueView3);
  6082. }
  6083. //---------------------------------------------------------------------------
  6084. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6085. {
  6086. DebugAssert(!IsSideLocalBrowser(Side));
  6087. DebugUsedParam(Side);
  6088. bool Edit = false;
  6089. TRemoteFile * File = NULL;
  6090. UnicodeString FileName;
  6091. UnicodeString PointTo;
  6092. bool SymbolicLink = true;
  6093. if (RemoteDirView->ItemFocused)
  6094. {
  6095. DebugAssert(RemoteDirView->ItemFocused->Data);
  6096. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6097. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6098. if (Edit)
  6099. {
  6100. FileName = File->FileName;
  6101. PointTo = File->LinkTo;
  6102. }
  6103. else
  6104. {
  6105. PointTo = File->FileName;
  6106. }
  6107. }
  6108. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6109. Terminal->IsCapable[fcHardLink]))
  6110. {
  6111. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6112. if (Edit)
  6113. {
  6114. DebugAssert(File->FileName == FileName);
  6115. int Params = dfNoRecursive;
  6116. Terminal->ExceptionOnFail = true;
  6117. try
  6118. {
  6119. Terminal->DeleteFile(L"", File, &Params);
  6120. }
  6121. __finally
  6122. {
  6123. Terminal->ExceptionOnFail = false;
  6124. }
  6125. }
  6126. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6127. }
  6128. }
  6129. //---------------------------------------------------------------------------
  6130. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6131. {
  6132. return
  6133. (IsSideLocalBrowser(Side) ||
  6134. (HasActiveTerminal() &&
  6135. Terminal->ResolvingSymlinks &&
  6136. Terminal->IsCapable[fcSymbolicLink]));
  6137. }
  6138. //---------------------------------------------------------------------------
  6139. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6140. {
  6141. return
  6142. !IsSideLocalBrowser(FCurrentSide) &&
  6143. (RemoteDirView->ItemFocused != NULL) &&
  6144. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6145. Terminal->SessionData->ResolveSymlinks;
  6146. }
  6147. //---------------------------------------------------------------------------
  6148. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6149. {
  6150. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6151. FForceExecution = true;
  6152. try
  6153. {
  6154. DirView(osCurrent)->ExecuteCurrentFile();
  6155. }
  6156. __finally
  6157. {
  6158. FForceExecution = false;
  6159. }
  6160. }
  6161. //---------------------------------------------------------------------------
  6162. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6163. {
  6164. TEditorData ExternalEditor;
  6165. ExternalEditor.Editor = edExternal;
  6166. bool Remember = false;
  6167. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6168. {
  6169. if (Remember)
  6170. {
  6171. TEditorList * EditorList = new TEditorList;
  6172. try
  6173. {
  6174. *EditorList = *WinConfiguration->EditorList;
  6175. bool Found = false;
  6176. int i = 0;
  6177. while (!Found && (i < EditorList->Count))
  6178. {
  6179. const TEditorPreferences * Editor = EditorList->Editors[i];
  6180. if ((Editor->Data->Editor == edExternal) &&
  6181. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6182. {
  6183. Found = true;
  6184. }
  6185. i++;
  6186. }
  6187. if (!Found)
  6188. {
  6189. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6190. WinConfiguration->EditorList = EditorList;
  6191. }
  6192. }
  6193. __finally
  6194. {
  6195. delete EditorList;
  6196. }
  6197. }
  6198. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6199. }
  6200. }
  6201. //---------------------------------------------------------------------------
  6202. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6203. {
  6204. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6205. if (FFileFindTerminal == ATerminal)
  6206. {
  6207. FFileFindTerminal = NULL;
  6208. HideFileFindDialog();
  6209. }
  6210. if (FClipboardTerminal == ATerminal)
  6211. {
  6212. ClipboardClear(); // implies ClipboardStop
  6213. }
  6214. if ((FOnSynchronizeAbort != NULL) &&
  6215. (ATerminal == FManagedSession))
  6216. {
  6217. FOnSynchronizeAbort(NULL);
  6218. }
  6219. }
  6220. //---------------------------------------------------------------------------
  6221. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6222. {
  6223. DetachTerminal(Sender);
  6224. }
  6225. //---------------------------------------------------------------------------
  6226. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6227. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6228. {
  6229. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6230. DebugAssert(Terminal != NULL);
  6231. if (Data->Terminal == Terminal)
  6232. {
  6233. Data->Terminal = NULL;
  6234. }
  6235. }
  6236. //---------------------------------------------------------------------------
  6237. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6238. {
  6239. UpdateControls();
  6240. SessionColor = TColor(0);
  6241. UpdateRemotePathComboBox(false);
  6242. NeedSession(false);
  6243. }
  6244. //---------------------------------------------------------------------------
  6245. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6246. {
  6247. try
  6248. {
  6249. // Cache, as the login dialog can change its value
  6250. // See also DoShow. Also see TTerminalManager::NewSession.
  6251. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6252. try
  6253. {
  6254. if (ShowLogin)
  6255. {
  6256. bool ReloadSessions = !Startup;
  6257. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this);
  6258. }
  6259. else if (Startup && WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6260. // This detects if workspace was saved the last time the main widow was closed
  6261. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6262. {
  6263. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6264. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6265. }
  6266. }
  6267. __finally
  6268. {
  6269. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6270. // (so there was no chance for the user to open any session yet)
  6271. if ((ShowLogin || !Startup) &&
  6272. !WinConfiguration->KeepOpenWhenNoSession &&
  6273. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6274. {
  6275. TerminateApplication();
  6276. }
  6277. }
  6278. }
  6279. catch (EAbort &)
  6280. {
  6281. // swallow
  6282. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6283. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6284. }
  6285. }
  6286. //---------------------------------------------------------------------------
  6287. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6288. {
  6289. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6290. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6291. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6292. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6293. try
  6294. {
  6295. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6296. // Clear the design time unthemed tab
  6297. ((SessionsPageControl->PageCount > 0) &&
  6298. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6299. {
  6300. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6301. }
  6302. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6303. {
  6304. TThemeTabSheet * TabSheet;
  6305. if (Index >= SessionsPageControl->PageCount)
  6306. {
  6307. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6308. TabSheet->PageControl = SessionsPageControl;
  6309. }
  6310. else
  6311. {
  6312. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6313. }
  6314. bool IsSessionTab = (Index < TerminalList->Count);
  6315. if (IsSessionTab)
  6316. {
  6317. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6318. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6319. UpdateSessionTab(TabSheet);
  6320. }
  6321. else
  6322. {
  6323. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6324. TabSheet->Tag = 0; // not really needed
  6325. TabSheet->Shadowed = false;
  6326. // 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)
  6327. UpdateNewSessionTab();
  6328. }
  6329. TabSheet->ShowCloseButton = IsSessionTab;
  6330. }
  6331. }
  6332. __finally
  6333. {
  6334. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6335. }
  6336. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6337. }
  6338. //---------------------------------------------------------------------------
  6339. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6340. {
  6341. DoTerminalListChanged();
  6342. }
  6343. //---------------------------------------------------------------------------
  6344. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6345. {
  6346. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6347. DebugAssert(TabSheet->ImageIndex == 0);
  6348. TabSheet->Caption =
  6349. WinConfiguration->SelectiveToolbarText ?
  6350. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6351. UnicodeString();
  6352. }
  6353. //---------------------------------------------------------------------------
  6354. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6355. {
  6356. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6357. }
  6358. //---------------------------------------------------------------------------
  6359. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6360. {
  6361. if (DebugAlwaysTrue(TabSheet != NULL))
  6362. {
  6363. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6364. if (DebugAlwaysTrue(ATerminal != NULL))
  6365. {
  6366. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6367. TabSheet->ImageIndex = AddSessionColor(Color);
  6368. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6369. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6370. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6371. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6372. {
  6373. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6374. }
  6375. }
  6376. }
  6377. }
  6378. //---------------------------------------------------------------------------
  6379. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6380. {
  6381. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6382. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6383. bool Result = (Terminal != NULL);
  6384. if (Result)
  6385. {
  6386. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6387. }
  6388. else
  6389. {
  6390. try
  6391. {
  6392. NewSession();
  6393. }
  6394. __finally
  6395. {
  6396. DoTerminalListChanged();
  6397. }
  6398. FSessionsPageControlNewSessionTime = Now();
  6399. }
  6400. return Result;
  6401. }
  6402. //---------------------------------------------------------------------------
  6403. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6404. {
  6405. SessionTabSwitched();
  6406. }
  6407. //---------------------------------------------------------------------------
  6408. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6409. {
  6410. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6411. DebugAssert(TransferList != NULL);
  6412. UnicodeString Name;
  6413. if (TransferList->ItemIndex <= 0)
  6414. {
  6415. Name = L"";
  6416. }
  6417. else
  6418. {
  6419. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6420. }
  6421. if (FCopyParamAutoSelected.IsEmpty())
  6422. {
  6423. // if previous preset was not autoselected, make new preset the "default"
  6424. FCopyParamDefault = Name;
  6425. }
  6426. GUIConfiguration->CopyParamCurrent = Name;
  6427. }
  6428. //---------------------------------------------------------------------------
  6429. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6430. {
  6431. // sanity check
  6432. bool ExistingPreset =
  6433. (FTransferListHoverIndex >= 0) &&
  6434. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6435. DebugAssert(ExistingPreset);
  6436. if (ExistingPreset)
  6437. {
  6438. HDC DC = GetDC(0);
  6439. TCanvas * Canvas = new TCanvas();
  6440. try
  6441. {
  6442. Canvas->Handle = DC;
  6443. Canvas->Font = GetToolbarFont(this);
  6444. UnicodeString Name;
  6445. if (FTransferListHoverIndex == 0)
  6446. {
  6447. Name = L"";
  6448. }
  6449. else
  6450. {
  6451. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6452. }
  6453. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6454. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6455. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6456. static_cast<TObject*>(GetComponent(fcTransferList)));
  6457. UnicodeString InfoStr =
  6458. GUIConfiguration->CopyParamPreset[Name].
  6459. GetInfoStr(L"; ",
  6460. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6461. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6462. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6463. {
  6464. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6465. {
  6466. InfoStr.SetLength(InfoStr.Length() - 1);
  6467. }
  6468. InfoStr += Ellipsis;
  6469. }
  6470. // UpdateCaption does not cause invalidation of whole submenu, while
  6471. // setting Caption property does.
  6472. // also it probably does not resize the label, even if necessary
  6473. // (we do not want that anyway)
  6474. TransferLabel->UpdateCaption(InfoStr);
  6475. }
  6476. __finally
  6477. {
  6478. Canvas->Handle = NULL;
  6479. ReleaseDC(0, DC);
  6480. delete Canvas;
  6481. }
  6482. }
  6483. }
  6484. //---------------------------------------------------------------------------
  6485. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6486. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6487. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6488. {
  6489. if (FTransferListHoverIndex != AHoverIndex)
  6490. {
  6491. FTransferListHoverIndex = AHoverIndex;
  6492. UpdateTransferLabel();
  6493. }
  6494. }
  6495. //---------------------------------------------------------------------------
  6496. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6497. {
  6498. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6499. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6500. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6501. {
  6502. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6503. {
  6504. if (!NonVisualDataModule->Busy)
  6505. {
  6506. OpenDirectory(GetSide(osCurrent));
  6507. }
  6508. Message.Result = 1;
  6509. }
  6510. else
  6511. {
  6512. TForm::Dispatch(&Message);
  6513. }
  6514. }
  6515. else
  6516. {
  6517. TForm::Dispatch(&Message);
  6518. }
  6519. }
  6520. //---------------------------------------------------------------------------
  6521. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6522. {
  6523. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6524. if ((FIgnoreNextDialogChar != 0) &&
  6525. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6526. {
  6527. Message.Result = 1;
  6528. }
  6529. else
  6530. {
  6531. TForm::Dispatch(&Message);
  6532. }
  6533. FIgnoreNextDialogChar = 0;
  6534. }
  6535. //---------------------------------------------------------------------------
  6536. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6537. {
  6538. // The four low-order bits are used internally by Windows
  6539. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6540. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6541. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6542. // 61730 - restore thru double click - undocumented
  6543. // 61490 - maximize thru double click - undocumented
  6544. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6545. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6546. {
  6547. SysResizing(Cmd);
  6548. }
  6549. TForm::Dispatch(&Message);
  6550. }
  6551. //---------------------------------------------------------------------------
  6552. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6553. {
  6554. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6555. // Also there no point returning TRUE as we are not able to
  6556. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6557. // Hence the process termination might be safer :)
  6558. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6559. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6560. {
  6561. Message.Result = FALSE;
  6562. }
  6563. else
  6564. {
  6565. Message.Result = TRUE;
  6566. }
  6567. // Do not call default handling as that triggers OnCloseQuery,
  6568. // where our implementation will popup confirmation dialogs, what we do not want,
  6569. // as per Vista guidelines:
  6570. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6571. }
  6572. //---------------------------------------------------------------------------
  6573. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6574. {
  6575. if (Message.EndSession && IsApplicationMinimized())
  6576. {
  6577. // WORKAROUND
  6578. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6579. // when it receives WM_ENDSESSION,
  6580. // but that sometimes (particularly when application is minimized) cause crashes.
  6581. // Crash popups message that blocks log off.
  6582. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6583. // so we call ExitProcess() immediately, not even trying to cleanup.
  6584. // It still causes beep, so there's likely some popup, but it does not block
  6585. // log off.
  6586. ExitProcess(0);
  6587. }
  6588. TForm::Dispatch(&Message);
  6589. }
  6590. #ifdef _DEBUG
  6591. //---------------------------------------------------------------------------
  6592. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6593. {
  6594. TForm::Dispatch(&Message);
  6595. }
  6596. #endif
  6597. //---------------------------------------------------------------------------
  6598. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6599. {
  6600. }
  6601. //---------------------------------------------------------------------------
  6602. void __fastcall TCustomScpExplorerForm::DoShow()
  6603. {
  6604. // only now are the controls resized finally, so the size constraints
  6605. // will not conflict with possibly very small window size
  6606. RestoreFormParams();
  6607. // This indicates that the form was rescaled after parameters were loaded and
  6608. // as most probably the parameters were actually saved with the current form scaling
  6609. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6610. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6611. // and no rounding problems will occur.
  6612. // See also RestoreForm.
  6613. // (we should be safe to call RestoreParams unconditionally)
  6614. if (PixelsPerInch != Screen->PixelsPerInch)
  6615. {
  6616. RestoreParams();
  6617. }
  6618. FixControlsPlacement();
  6619. if (Position == poDefaultPosOnly)
  6620. {
  6621. CutFormToDesktop(this);
  6622. }
  6623. TForm::DoShow();
  6624. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6625. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6626. if (Terminal == NULL)
  6627. {
  6628. StartingDisconnected();
  6629. }
  6630. UpdatePixelsPerInchMainWindowCounter();
  6631. FShowing = true;
  6632. }
  6633. //---------------------------------------------------------------------------
  6634. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6635. {
  6636. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6637. }
  6638. //---------------------------------------------------------------------------
  6639. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6640. {
  6641. DoTerminalListChanged();
  6642. }
  6643. //---------------------------------------------------------------------------
  6644. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6645. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6646. TNotifyEvent OnBalloonClick, TObject * UserData)
  6647. {
  6648. bool Do;
  6649. UnicodeString Message;
  6650. if (E == NULL)
  6651. {
  6652. Message = Str;
  6653. Do = true;
  6654. }
  6655. else
  6656. {
  6657. Do = ExceptionMessage(E, Message);
  6658. }
  6659. if (Do && WinConfiguration->BalloonNotifications)
  6660. {
  6661. UnicodeString Title;
  6662. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6663. {
  6664. Message = TrimLeft(Message);
  6665. }
  6666. else
  6667. {
  6668. Message = UnformatMessage(Message);
  6669. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6670. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6671. Title = LoadResourceString(Captions[Type]);
  6672. if (Terminal != NULL)
  6673. {
  6674. Title = FORMAT(L"%s - %s",
  6675. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6676. }
  6677. }
  6678. if (Seconds == 0)
  6679. {
  6680. Seconds = WinConfiguration->NotificationsTimeout;
  6681. }
  6682. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6683. }
  6684. }
  6685. //---------------------------------------------------------------------------
  6686. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6687. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6688. UnicodeString HelpKeyword, const TMessageParams * Params,
  6689. TTerminal * Terminal)
  6690. {
  6691. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6692. (FOnFeedSynchronizeError != NULL)) &&
  6693. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6694. {
  6695. if (FOnFeedSynchronizeError != NULL)
  6696. {
  6697. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6698. }
  6699. else
  6700. {
  6701. DebugAssert(FErrorList != NULL);
  6702. TStringList * MoreMessagesCopy = NULL;
  6703. if (MoreMessages)
  6704. {
  6705. MoreMessagesCopy = new TStringList();
  6706. MoreMessagesCopy->Assign(MoreMessages);
  6707. }
  6708. FErrorList->AddObject(Message, MoreMessagesCopy);
  6709. }
  6710. PopupTrayBalloon(Terminal, Message, Type);
  6711. return ContinueAnswer(Answers);
  6712. }
  6713. else
  6714. {
  6715. bool UseBalloon = FTrayIcon->Visible;
  6716. if (UseBalloon)
  6717. {
  6718. PopupTrayBalloon(Terminal, Message, Type);
  6719. }
  6720. unsigned int Result;
  6721. try
  6722. {
  6723. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6724. }
  6725. __finally
  6726. {
  6727. // cancel only balloon we popped up, otherwise we may cancel notification
  6728. // balloon that was there before the message dialog
  6729. // (such as "dd confirmation opt in balloon)
  6730. if (UseBalloon)
  6731. {
  6732. FTrayIcon->CancelBalloon();
  6733. }
  6734. }
  6735. return Result;
  6736. }
  6737. }
  6738. //---------------------------------------------------------------------------
  6739. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6740. TTerminal * Terminal, Exception * E)
  6741. {
  6742. if (FTrayIcon->Visible)
  6743. {
  6744. PopupTrayBalloon(Terminal, L"", qtError, E);
  6745. }
  6746. // particularly prevent opening new session from jump list,
  6747. // while exception is shown
  6748. NonVisualDataModule->StartBusy();
  6749. try
  6750. {
  6751. ShowExtendedExceptionEx(Terminal, E);
  6752. }
  6753. __finally
  6754. {
  6755. NonVisualDataModule->EndBusy();
  6756. FTrayIcon->CancelBalloon();
  6757. }
  6758. }
  6759. //---------------------------------------------------------------------------
  6760. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6761. {
  6762. if (Terminal->Active)
  6763. {
  6764. InitStatusBar();
  6765. }
  6766. // cannot rely on active page being page for active terminal,
  6767. // as it can happen that active page is the "new session" page
  6768. // (e.g. when reconnecting active terminal, while login dialog
  6769. // invoked from "new session" page is modal)
  6770. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6771. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6772. }
  6773. //---------------------------------------------------------------------------
  6774. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6775. TTerminal * Terminal, Exception * E)
  6776. {
  6777. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6778. if (!Terminal->Active)
  6779. {
  6780. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6781. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6782. {
  6783. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6784. }
  6785. }
  6786. }
  6787. //---------------------------------------------------------------------------
  6788. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6789. UnicodeString Message, TQueryType Type,
  6790. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6791. {
  6792. if ((E == NULL) ||
  6793. ExceptionMessage(E, Message))
  6794. {
  6795. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6796. if (Important)
  6797. {
  6798. Seconds *= 5;
  6799. }
  6800. UnicodeString NoteMessage(UnformatMessage(Message));
  6801. if (Terminal != NULL)
  6802. {
  6803. NoteMessage = FORMAT(L"%s: %s",
  6804. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6805. }
  6806. if (WinConfiguration->BalloonNotifications)
  6807. {
  6808. AddNote(NoteMessage);
  6809. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6810. }
  6811. else
  6812. {
  6813. FlashOnBackground();
  6814. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6815. }
  6816. }
  6817. }
  6818. //---------------------------------------------------------------------------
  6819. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6820. {
  6821. RestoreApp();
  6822. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6823. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6824. !NonVisualDataModule->Busy)
  6825. {
  6826. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6827. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6828. if (!ComponentVisible[fcQueueView])
  6829. {
  6830. ToggleQueueVisibility();
  6831. GoToQueue();
  6832. }
  6833. }
  6834. }
  6835. //---------------------------------------------------------------------------
  6836. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6837. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6838. {
  6839. UnicodeString Message;
  6840. TNotifyEvent OnClick = NULL;
  6841. TObject * UserData = NULL;
  6842. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6843. switch (Event)
  6844. {
  6845. case qeEmptyButMonitored:
  6846. if ((ATerminal != Terminal) || QueueInvisible)
  6847. {
  6848. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6849. OnClick = QueueEmptyNoteClicked;
  6850. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6851. TerminalNoteData->Terminal = ATerminal;
  6852. UserData = TerminalNoteData;
  6853. }
  6854. break;
  6855. case qeEmpty:
  6856. OperationComplete(ATerminal->QueueOperationStart);
  6857. break;
  6858. case qePendingUserAction:
  6859. if ((ATerminal != Terminal) ||
  6860. (QueueInvisible && !IsQueueAutoPopup()))
  6861. {
  6862. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6863. }
  6864. break;
  6865. default:
  6866. DebugFail();
  6867. }
  6868. if (!Message.IsEmpty())
  6869. {
  6870. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6871. }
  6872. }
  6873. //---------------------------------------------------------------------------
  6874. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6875. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6876. {
  6877. if (FDDExtMapFile != NULL)
  6878. {
  6879. CloseHandle(FDDExtMapFile);
  6880. FDDExtMapFile = NULL;
  6881. }
  6882. if (WinConfiguration->DDFakeFile)
  6883. {
  6884. DDFakeFileInitDrag(FileList, Created);
  6885. }
  6886. }
  6887. //---------------------------------------------------------------------------
  6888. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6889. {
  6890. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6891. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6892. {
  6893. FFakeFileDropTarget = FileName;
  6894. }
  6895. }
  6896. //---------------------------------------------------------------------------
  6897. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6898. {
  6899. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6900. if (!ForceDirectories(ApiPath(Result)))
  6901. {
  6902. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6903. }
  6904. FileSetAttr(ApiPath(Result), faHidden);
  6905. return Result;
  6906. }
  6907. //---------------------------------------------------------------------------
  6908. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6909. bool & Created)
  6910. {
  6911. FFakeFileDropTarget = UnicodeString();
  6912. FDragFakeDirectory = CreateFakeTransferDirectory();
  6913. FileList->AddItem(NULL, FDragFakeDirectory);
  6914. Created = true;
  6915. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6916. {
  6917. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6918. }
  6919. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6920. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6921. {
  6922. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6923. TDragExtCommStruct* CommStruct;
  6924. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6925. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6926. DebugAssert(CommStruct != NULL);
  6927. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6928. CommStruct->Dragging = true;
  6929. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6930. LENOF(CommStruct->DropDest));
  6931. NULL_TERMINATE(CommStruct->DropDest);
  6932. UnmapViewOfFile(CommStruct);
  6933. }
  6934. }
  6935. //---------------------------------------------------------------------------
  6936. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6937. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6938. {
  6939. bool Result;
  6940. DebugAssert(!IsLocalBrowserMode());
  6941. if (Sender == RemoteDirView)
  6942. {
  6943. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6944. }
  6945. else
  6946. {
  6947. DebugAssert(Sender == RemoteDriveView);
  6948. TStrings * FileList = RemoteDriveView->DragFileList();
  6949. try
  6950. {
  6951. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6952. }
  6953. __finally
  6954. {
  6955. delete FileList;
  6956. }
  6957. }
  6958. if (FDDTargetControl == RemoteDriveView)
  6959. {
  6960. RemoteDriveView->UpdateDropTarget();
  6961. }
  6962. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6963. // or from tree view to dir view.
  6964. // foMove happens when file/dir is dragged from remote tree view outside of
  6965. // application via dragex
  6966. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6967. (DropSourceControl == RemoteDriveView))
  6968. {
  6969. RemoteDriveView->UpdateDropSource();
  6970. }
  6971. return Result;
  6972. }
  6973. //---------------------------------------------------------------------------
  6974. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6975. {
  6976. DebugAssert(!IsLocalBrowserMode());
  6977. // This also handles drops of remote files to queue.
  6978. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6979. SAFE_DESTROY(FDDFileList);
  6980. if (!FFakeFileDropTarget.IsEmpty())
  6981. {
  6982. RemoveDir(ApiPath(FFakeFileDropTarget));
  6983. }
  6984. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6985. {
  6986. try
  6987. {
  6988. TDragResult DDResult = (Sender == RemoteDirView) ?
  6989. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6990. // Focus is moved to the target application,
  6991. // but as we are going to present the UI, we need to steal the focus back.
  6992. // This most likely won't work though (windows does not allow application
  6993. // to steal focus most of the time)
  6994. Application->BringToFront();
  6995. // On older version of Windows we never got drMove here, see also comment below.
  6996. // On Windows 10, we get the "move".
  6997. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6998. {
  6999. UnicodeString TargetDirectory;
  7000. TFileOperation Operation;
  7001. // drInvalid may mean drMove, see comment below
  7002. switch (DDResult)
  7003. {
  7004. case drCopy:
  7005. Operation = foCopy;
  7006. break;
  7007. case drMove:
  7008. Operation = foMove;
  7009. break;
  7010. default:
  7011. DebugFail();
  7012. case drInvalid:
  7013. // prefer "copy" for safety
  7014. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7015. break;
  7016. }
  7017. TTransferOperationParam Param;
  7018. UnicodeString CounterName;
  7019. bool ForceQueue;
  7020. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7021. {
  7022. // we get drInvalid both if d&d was intercepted by ddext,
  7023. // and when users drops on no-drop location.
  7024. // we tell the difference by existence of response from ddext,
  7025. // so we ignore absence of response in this case
  7026. if (DDResult != drInvalid)
  7027. {
  7028. // here we know that the extension is installed,
  7029. // as it is checked as soon as drag&drop starts from
  7030. // RemoteFileControlDDCreateDragFileList
  7031. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7032. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7033. {
  7034. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7035. }
  7036. else
  7037. {
  7038. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7039. }
  7040. }
  7041. }
  7042. else
  7043. {
  7044. // download using fake file
  7045. Param.Temp = false;
  7046. Param.DragDrop = true;
  7047. if (ForceQueue)
  7048. {
  7049. Param.Queue = asOn;
  7050. }
  7051. if (Sender == RemoteDirView)
  7052. {
  7053. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7054. }
  7055. if (RemoteFileControlFileOperation(Sender, Operation,
  7056. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7057. {
  7058. Configuration->Usage->Inc(CounterName);
  7059. }
  7060. }
  7061. }
  7062. }
  7063. __finally
  7064. {
  7065. CloseHandle(FDDExtMapFile);
  7066. FDDExtMapFile = NULL;
  7067. delete FDragFakeMonitors;
  7068. FDragFakeMonitors = NULL;
  7069. RemoveDir(ApiPath(FDragFakeDirectory));
  7070. FDragFakeDirectory = L"";
  7071. FFakeFileDropTarget = UnicodeString();
  7072. }
  7073. }
  7074. if (FDragDropSshTerminate.get() != NULL)
  7075. {
  7076. FDragDropSshTerminate->Rethrow();
  7077. }
  7078. }
  7079. //---------------------------------------------------------------------------
  7080. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7081. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7082. {
  7083. // Remember drop effect so we know (when user drops files), if we copy or move
  7084. FLastDropEffect = dwEffect;
  7085. }
  7086. //---------------------------------------------------------------------------
  7087. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7088. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7089. {
  7090. bool Result;
  7091. if (FDDTargetControl == QueueView3)
  7092. {
  7093. Directory = DefaultDownloadTargetDirectory();
  7094. Result = true;
  7095. CounterName = L"DownloadsDragDropQueue";
  7096. ForceQueue = true;
  7097. }
  7098. else if (!FFakeFileDropTarget.IsEmpty())
  7099. {
  7100. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7101. Result = true;
  7102. ForceQueue = false;
  7103. CounterName = L"DownloadsDragDropFakeFile";
  7104. }
  7105. else
  7106. {
  7107. ForceQueue = false;
  7108. Enabled = false;
  7109. try
  7110. {
  7111. int Timer = 0;
  7112. Result = false;
  7113. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7114. {
  7115. {
  7116. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7117. TDragExtCommStruct* CommStruct;
  7118. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7119. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7120. DebugAssert(CommStruct != NULL);
  7121. Result = !CommStruct->Dragging;
  7122. if (Result)
  7123. {
  7124. Directory = ExtractFilePath(CommStruct->DropDest);
  7125. CounterName = L"DownloadsDragDropExternalExt";
  7126. }
  7127. UnmapViewOfFile(CommStruct);
  7128. }
  7129. if (!Result)
  7130. {
  7131. Sleep(50);
  7132. Timer += 50;
  7133. Application->ProcessMessages();
  7134. }
  7135. }
  7136. }
  7137. __finally
  7138. {
  7139. Enabled = true;
  7140. }
  7141. }
  7142. return Result;
  7143. }
  7144. //---------------------------------------------------------------------------
  7145. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7146. const UnicodeString TempDir, int SecDelay)
  7147. {
  7148. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7149. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7150. if (FDelayedDeletionTimer == NULL)
  7151. {
  7152. DebugAssert(HandleAllocated());
  7153. FDelayedDeletionTimer = new TTimer(this);
  7154. FDelayedDeletionTimer->Interval = 10000;
  7155. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7156. }
  7157. else
  7158. {
  7159. FDelayedDeletionTimer->Enabled = true;
  7160. }
  7161. }
  7162. //---------------------------------------------------------------------------
  7163. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7164. {
  7165. DebugAssert(FDelayedDeletionList != NULL);
  7166. TDateTime N = Now();
  7167. TDateTime Alert;
  7168. UnicodeString Directory;
  7169. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7170. {
  7171. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7172. if ((N >= Alert) || (Sender == NULL))
  7173. {
  7174. Directory = FDelayedDeletionList->Strings[Index];
  7175. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7176. {
  7177. FDelayedDeletionList->Delete(Index);
  7178. }
  7179. }
  7180. }
  7181. if (FDelayedDeletionList->Count == 0)
  7182. {
  7183. FDelayedDeletionTimer->Enabled = false;
  7184. }
  7185. }
  7186. //---------------------------------------------------------------------------
  7187. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7188. {
  7189. DebugAssert(!IsLocalBrowserMode());
  7190. if (IsFileControl(FDDTargetControl, osRemote) ||
  7191. (FDDTargetControl == SessionsPageControl))
  7192. {
  7193. TTerminal * TargetTerminal = NULL;
  7194. TFileOperation Operation = foNone;
  7195. if (FDDTargetControl == SessionsPageControl)
  7196. {
  7197. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7198. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7199. // do not allow dropping on the "+" and disconnected tabs
  7200. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7201. if (IsActiveTerminal(TargetTerminal))
  7202. {
  7203. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7204. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7205. {
  7206. Operation = foRemoteMove;
  7207. }
  7208. else
  7209. {
  7210. Operation = foRemoteCopy;
  7211. }
  7212. }
  7213. }
  7214. else
  7215. {
  7216. if (FLastDropEffect == DROPEFFECT_MOVE)
  7217. {
  7218. Operation = foRemoteMove;
  7219. }
  7220. else if (FLastDropEffect == DROPEFFECT_COPY)
  7221. {
  7222. Operation = foRemoteCopy;
  7223. }
  7224. }
  7225. if (Operation != foNone)
  7226. {
  7227. RemoteFileControlFileOperation(DropSourceControl,
  7228. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7229. }
  7230. // abort drag&drop
  7231. Abort();
  7232. }
  7233. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7234. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7235. (FDDTargetControl != QueueView3))
  7236. {
  7237. DebugAssert(!FDragTempDir.IsEmpty());
  7238. TTransferType Type;
  7239. UnicodeString TempDir = FDragTempDir;
  7240. // We clear FDragTempDir before calling
  7241. // just in case it fail (raises exception)
  7242. FDragTempDir = L"";
  7243. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7244. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7245. // empty directory parameter means temp directory -> don't display it!
  7246. UnicodeString TargetDir = L"";
  7247. int Options = 0;
  7248. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7249. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7250. {
  7251. Abort();
  7252. }
  7253. // TargetDir is set when dropped on local file control
  7254. // (this was workaround for legacy dirview event handling, now it should be
  7255. // made prettier)
  7256. if (TargetDir.IsEmpty())
  7257. {
  7258. TargetDir = TempDir;
  7259. if (ForceDirectories(ApiPath(TargetDir)))
  7260. {
  7261. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7262. FPendingTempSpaceWarn = true;
  7263. try
  7264. {
  7265. FDragDropOperation = true;
  7266. int Params = cpTemporary |
  7267. (Type == ttMove ? cpDelete : 0);
  7268. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7269. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7270. }
  7271. __finally
  7272. {
  7273. FDragDropOperation = false;
  7274. FPendingTempSpaceWarn = false;
  7275. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7276. }
  7277. }
  7278. else
  7279. {
  7280. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7281. }
  7282. }
  7283. }
  7284. }
  7285. //---------------------------------------------------------------------------
  7286. void __fastcall TCustomScpExplorerForm::DDDownload(
  7287. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7288. {
  7289. DebugAssert(!IsLocalBrowserMode());
  7290. TAutoBatch AutoBatch(this);
  7291. UpdateCopyParamCounters(*CopyParam);
  7292. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7293. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7294. {
  7295. RemoteDriveView->UpdateDropSource();
  7296. }
  7297. }
  7298. //---------------------------------------------------------------------------
  7299. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7300. {
  7301. public:
  7302. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7303. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7304. {
  7305. }
  7306. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7307. {
  7308. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7309. TDataObjectFilesEx::AllowData(FormatEtc);
  7310. }
  7311. };
  7312. //---------------------------------------------------------------------------
  7313. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7314. TObject * Sender, TDataObject *& DataObject)
  7315. {
  7316. if (FDDExtMapFile != NULL)
  7317. {
  7318. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7319. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7320. {
  7321. Abort();
  7322. }
  7323. if (FileList->Count > 0)
  7324. {
  7325. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7326. if (!FilesObject->IsValid(true, true))
  7327. {
  7328. FilesObject->_Release();
  7329. }
  7330. else
  7331. {
  7332. DataObject = FilesObject;
  7333. }
  7334. }
  7335. }
  7336. }
  7337. //---------------------------------------------------------------------------
  7338. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7339. {
  7340. DebugFail();
  7341. }
  7342. //---------------------------------------------------------------------------
  7343. void __fastcall TCustomScpExplorerForm::GoToTree()
  7344. {
  7345. ComponentVisible[fcRemoteTree] = true;
  7346. DriveView(osRemote)->SetFocus();
  7347. }
  7348. //---------------------------------------------------------------------------
  7349. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7350. TPanelExport Export)
  7351. {
  7352. TCustomDirView * DirView = this->DirView(Side);
  7353. std::unique_ptr<TStrings> ExportData(new TStringList());
  7354. switch (Export)
  7355. {
  7356. case pePath:
  7357. ExportData->Add(DirView->PathName);
  7358. break;
  7359. case peFileList:
  7360. case peFullFileList:
  7361. {
  7362. bool FullPath = (Export == peFullFileList);
  7363. DirView->CreateFileList(false, FullPath, ExportData.get());
  7364. for (int Index = 0; Index < ExportData->Count; Index++)
  7365. {
  7366. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7367. {
  7368. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7369. }
  7370. }
  7371. }
  7372. break;
  7373. default:
  7374. DebugFail();
  7375. }
  7376. return ExportData.release();
  7377. }
  7378. //---------------------------------------------------------------------------
  7379. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7380. TPanelExport Export, TPanelExportDestination Destination)
  7381. {
  7382. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7383. PanelExportStore(Side, Export, Destination, ExportData.get());
  7384. }
  7385. //---------------------------------------------------------------------------
  7386. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7387. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7388. TStrings * ExportData)
  7389. {
  7390. if (Destination == pedClipboard)
  7391. {
  7392. TInstantOperationVisualizer Visualizer;
  7393. CopyToClipboard(ExportData);
  7394. }
  7395. else
  7396. {
  7397. DebugFail();
  7398. }
  7399. }
  7400. //---------------------------------------------------------------------------
  7401. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7402. {
  7403. TCustomDirView * DirView = this->DirView(Side);
  7404. UnicodeString Mask = DirView->Mask;
  7405. if (DoFilterMaskDialog(DirView, Mask))
  7406. {
  7407. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7408. Configuration->Usage->Inc(L"Filters");
  7409. }
  7410. }
  7411. //---------------------------------------------------------------------------
  7412. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7413. {
  7414. return FQueueController->DefaultOperation();
  7415. }
  7416. //---------------------------------------------------------------------------
  7417. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7418. TQueueOperation Operation, void ** Param)
  7419. {
  7420. switch (Operation)
  7421. {
  7422. case qoPreferences:
  7423. return true;
  7424. case qoGoTo:
  7425. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7426. case qoOnceEmpty:
  7427. return IsAnythingQueued();
  7428. default:
  7429. return FQueueController->AllowOperation(Operation, Param);
  7430. }
  7431. }
  7432. //---------------------------------------------------------------------------
  7433. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7434. {
  7435. if (DebugAlwaysTrue(QueueView3->Visible))
  7436. {
  7437. QueueView3->SetFocus();
  7438. }
  7439. }
  7440. //---------------------------------------------------------------------------
  7441. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7442. TQueueOperation Operation, void * Param)
  7443. {
  7444. if (Operation == qoGoTo)
  7445. {
  7446. GoToQueue();
  7447. }
  7448. else if (Operation == qoPreferences)
  7449. {
  7450. PreferencesDialog(pmQueue);
  7451. }
  7452. else
  7453. {
  7454. FQueueController->ExecuteOperation(Operation, Param);
  7455. }
  7456. }
  7457. //---------------------------------------------------------------------------
  7458. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7459. {
  7460. return (Queue != NULL) && Queue->Enabled;
  7461. }
  7462. //---------------------------------------------------------------------------
  7463. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7464. {
  7465. DebugAssert(Queue != NULL);
  7466. if (Queue != NULL)
  7467. {
  7468. Queue->Enabled = !Queue->Enabled;
  7469. }
  7470. }
  7471. //---------------------------------------------------------------------------
  7472. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7473. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7474. {
  7475. FQueueActedItem = QueueView3->ItemFocused;
  7476. }
  7477. //---------------------------------------------------------------------------
  7478. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7479. {
  7480. return TopDock->Height + QueueSplitter->Height;
  7481. }
  7482. //---------------------------------------------------------------------------
  7483. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7484. {
  7485. return
  7486. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7487. (QueueDock->Visible ? QueueDock->Height : 0) +
  7488. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7489. }
  7490. //---------------------------------------------------------------------------
  7491. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7492. {
  7493. return ScaleByTextHeight(this, 48);
  7494. }
  7495. //---------------------------------------------------------------------------
  7496. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7497. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7498. {
  7499. // when queue is hidden by double-clicking splitter, stray attempt to
  7500. // resize the panel with strange value arrives, make sure it is ignored
  7501. if (ComponentVisible[fcQueueView])
  7502. {
  7503. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7504. if (NewSize > MaxHeightLimit)
  7505. {
  7506. NewSize = MaxHeightLimit;
  7507. }
  7508. int MinHeightLimit =
  7509. GetStaticQueuePanelComponentsHeight() +
  7510. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7511. GetMinQueueViewHeight();
  7512. if (NewSize < MinHeightLimit)
  7513. {
  7514. NewSize = MinHeightLimit;
  7515. }
  7516. }
  7517. else
  7518. {
  7519. Accept = false;
  7520. }
  7521. }
  7522. //---------------------------------------------------------------------------
  7523. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7524. {
  7525. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7526. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7527. if (QueueViewHeight < GetMinQueueViewHeight())
  7528. {
  7529. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7530. }
  7531. }
  7532. //---------------------------------------------------------------------------
  7533. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7534. TDragObject *& /*DragObject*/)
  7535. {
  7536. FQueueActedItem = QueueView3->ItemFocused;
  7537. }
  7538. //---------------------------------------------------------------------------
  7539. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7540. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7541. {
  7542. Accept = true;
  7543. if (Source == QueueView3)
  7544. {
  7545. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7546. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7547. if (Accept)
  7548. {
  7549. TQueueItemProxy * QueueItem;
  7550. TQueueItemProxy * DestQueueItem;
  7551. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7552. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7553. Accept = (QueueItem != DestQueueItem) &&
  7554. (QueueItem->Status == TQueueItem::qsPending) &&
  7555. (DestQueueItem->Status == TQueueItem::qsPending);
  7556. }
  7557. }
  7558. }
  7559. //---------------------------------------------------------------------------
  7560. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7561. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7562. {
  7563. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7564. {
  7565. TQueueItemProxy * QueueItem;
  7566. TQueueItemProxy * DestQueueItem;
  7567. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7568. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7569. QueueItem->Move(DestQueueItem);
  7570. }
  7571. }
  7572. //---------------------------------------------------------------------------
  7573. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7574. {
  7575. if ((QueueView3->ItemFocused == NULL) &&
  7576. (QueueView3->Items->Count > 0))
  7577. {
  7578. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7579. }
  7580. QueueLabelUpdateStatus();
  7581. }
  7582. //---------------------------------------------------------------------------
  7583. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7584. {
  7585. QueueLabelUpdateStatus();
  7586. }
  7587. //---------------------------------------------------------------------------
  7588. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7589. {
  7590. QueueLabel->UpdateStatus();
  7591. }
  7592. //---------------------------------------------------------------------------
  7593. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7594. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7595. {
  7596. if (Selected)
  7597. {
  7598. NonVisualDataModule->UpdateNonVisibleActions();
  7599. }
  7600. }
  7601. //---------------------------------------------------------------------------
  7602. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7603. {
  7604. TDragDropFilesEx * Result = NULL;
  7605. if (Sender == SessionsPageControl)
  7606. {
  7607. Result = FSessionsDragDropFilesEx;
  7608. }
  7609. else if (Sender == QueueView3)
  7610. {
  7611. Result = FQueueDragDropFilesEx;
  7612. }
  7613. else
  7614. {
  7615. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7616. if (DirView != NULL)
  7617. {
  7618. Result = DirView->DragDropFilesEx;
  7619. }
  7620. else
  7621. {
  7622. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7623. if (DriveView != NULL)
  7624. {
  7625. Result = DriveView->DragDropFilesEx;
  7626. }
  7627. }
  7628. }
  7629. DebugAssert(Result != NULL);
  7630. return Result;
  7631. }
  7632. //---------------------------------------------------------------------------
  7633. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7634. {
  7635. return (DView->SelCount == DView->FilesCount);
  7636. }
  7637. //---------------------------------------------------------------------------
  7638. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7639. {
  7640. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7641. }
  7642. //---------------------------------------------------------------------------
  7643. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7644. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7645. {
  7646. DebugAssert(!IsLocalBrowserMode());
  7647. TFileOperation Operation;
  7648. switch (Effect)
  7649. {
  7650. case DROPEFFECT_MOVE:
  7651. Operation = foMove;
  7652. break;
  7653. case DROPEFFECT_COPY:
  7654. // occures on WinXP (reported by user)
  7655. default:
  7656. Operation = foCopy;
  7657. break;
  7658. };
  7659. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7660. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7661. if (DragDropFilesEx->FileList->Count > 0)
  7662. {
  7663. TStrings * FileList = new TStringList();
  7664. try
  7665. {
  7666. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7667. {
  7668. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7669. }
  7670. FDragDropOperation = true;
  7671. TTransferOperationParam Param;
  7672. Param.TargetDirectory = TargetPath;
  7673. // upload, no temp dirs
  7674. Param.Temp = false;
  7675. Param.DragDrop = DragDrop;
  7676. Param.Options =
  7677. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7678. if (ForceQueue)
  7679. {
  7680. Param.Queue = asOn;
  7681. }
  7682. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7683. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7684. {
  7685. if (IsFileControl(DropSourceControl, osLocal))
  7686. {
  7687. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7688. }
  7689. else
  7690. {
  7691. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7692. }
  7693. }
  7694. }
  7695. __finally
  7696. {
  7697. FDragDropOperation = false;
  7698. delete FileList;
  7699. }
  7700. }
  7701. }
  7702. //---------------------------------------------------------------------------
  7703. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7704. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7705. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7706. {
  7707. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7708. }
  7709. //---------------------------------------------------------------------------
  7710. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7711. TObject * Sender, int grfKeyState, int & dwEffect)
  7712. {
  7713. DebugAssert(!IsLocalBrowserMode());
  7714. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7715. if ((dwEffect != DROPEFFECT_NONE) &&
  7716. IsFileControl(DropSourceControl, osRemote))
  7717. {
  7718. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7719. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7720. (RemoteDirView->DropTarget == NULL))
  7721. {
  7722. dwEffect = DROPEFFECT_NONE;
  7723. }
  7724. else
  7725. {
  7726. if (dwEffect == DROPEFFECT_COPY)
  7727. {
  7728. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7729. // currently we support copying always (at least via temporary directory);
  7730. // remove associated checks once this all proves stable and working
  7731. bool CopyCapable = true;
  7732. // if we do not support neither of operations, there's no discussion
  7733. if (!MoveCapable && !CopyCapable)
  7734. {
  7735. dwEffect = DROPEFFECT_NONE;
  7736. }
  7737. else
  7738. {
  7739. // The default effect inside remote panel is move,
  7740. // unless we do not support it, but support copy
  7741. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7742. {
  7743. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7744. }
  7745. else
  7746. {
  7747. // with ctrl-down, we want copy unless it is not supported
  7748. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7749. }
  7750. }
  7751. }
  7752. }
  7753. }
  7754. }
  7755. //---------------------------------------------------------------------------
  7756. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7757. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7758. {
  7759. DebugAssert(!IsLocalBrowserMode());
  7760. if (FDDTotalSize >= 0)
  7761. {
  7762. if (File->IsDirectory)
  7763. {
  7764. FDDTotalSize = -1;
  7765. }
  7766. else
  7767. {
  7768. FDDTotalSize += File->Size;
  7769. }
  7770. }
  7771. DebugAssert(!FDragTempDir.IsEmpty());
  7772. // TODO: this is quite ineffective
  7773. // TODO: what if invalid character replacement is disabled?
  7774. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7775. UnicodeString TransferFileName;
  7776. if (Sender == RemoteDriveView)
  7777. {
  7778. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7779. }
  7780. else
  7781. {
  7782. TransferFileName = File->FileName;
  7783. }
  7784. FDDFileList->AddObject(TransferFileName, File);
  7785. }
  7786. //---------------------------------------------------------------------------
  7787. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7788. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7789. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7790. {
  7791. // sometimes we do not get DDEnd so the list is not released
  7792. SAFE_DESTROY(FDDFileList);
  7793. FDDFileList = new TStringList();
  7794. FDragTempDir = WinConfiguration->TemporaryDir();
  7795. FDDTotalSize = 0;
  7796. FDragDropSshTerminate.reset(NULL);
  7797. }
  7798. //---------------------------------------------------------------------------
  7799. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7800. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7801. HRESULT & Result)
  7802. {
  7803. if (Result == DRAGDROP_S_DROP)
  7804. {
  7805. try
  7806. {
  7807. GlobalDragImageList->HideDragImage();
  7808. try
  7809. {
  7810. RemoteFileControlDDTargetDrop();
  7811. }
  7812. catch(ESshTerminate & E)
  7813. {
  7814. FDragDropSshTerminate.reset(E.Clone());
  7815. }
  7816. }
  7817. catch (Exception &E)
  7818. {
  7819. // If downloading fails we need to cancel drag&drop, otherwise
  7820. // Explorer shows error
  7821. // But by the way exception probably never reach this point as
  7822. // it's catched on way.
  7823. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7824. Result = DRAGDROP_S_CANCEL;
  7825. ShowExtendedException(Terminal, &E);
  7826. }
  7827. }
  7828. }
  7829. //---------------------------------------------------------------------------
  7830. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7831. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7832. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7833. {
  7834. TFileMasks::TParams MaskParams;
  7835. MaskParams.Size = Size;
  7836. MaskParams.Modification = Modification;
  7837. // this does not re-parse the mask if it is the same as the last time
  7838. FDirViewMatchMask = Masks;
  7839. bool ImplicitMatch;
  7840. Matches =
  7841. // RecurseInclude parameter has no effect as the Path is empty
  7842. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7843. (AllowImplicitMatches || !ImplicitMatch);
  7844. }
  7845. //---------------------------------------------------------------------------
  7846. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7847. TObject * Sender, TListItem * Item, WORD & Indexes)
  7848. {
  7849. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7850. UnicodeString Ext;
  7851. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7852. {
  7853. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7854. }
  7855. else
  7856. {
  7857. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7858. }
  7859. if (SameText(Ext, Configuration->PartialExt))
  7860. {
  7861. Indexes |= oiPartial;
  7862. }
  7863. }
  7864. //---------------------------------------------------------------------------
  7865. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7866. {
  7867. return
  7868. DirViewEnabled(osCurrent) &&
  7869. DirView(osCurrent)->CanPasteFromClipBoard();
  7870. }
  7871. //---------------------------------------------------------------------------
  7872. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7873. {
  7874. bool Result = false;
  7875. if (CanPasteToDirViewFromClipBoard())
  7876. {
  7877. Result = true;
  7878. }
  7879. else
  7880. {
  7881. UnicodeString ClipboardText;
  7882. if (NonEmptyTextFromClipboard(ClipboardText) &&
  7883. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  7884. {
  7885. if (StoredSessions->IsUrl(ClipboardText))
  7886. {
  7887. Result = true;
  7888. }
  7889. else
  7890. {
  7891. Result = DirViewEnabled(osCurrent);
  7892. }
  7893. }
  7894. }
  7895. return Result;
  7896. }
  7897. //---------------------------------------------------------------------------
  7898. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7899. {
  7900. if (DoesClipboardContainOurFiles())
  7901. {
  7902. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7903. {
  7904. DebugAssert(!IsLocalBrowserMode());
  7905. TTerminalManager * Manager = TTerminalManager::Instance();
  7906. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7907. Manager->ActiveTerminal = FClipboardTerminal;
  7908. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7909. }
  7910. }
  7911. else if (CanPasteToDirViewFromClipBoard())
  7912. {
  7913. DirView(osCurrent)->PasteFromClipBoard();
  7914. }
  7915. else
  7916. {
  7917. UnicodeString ClipboardText;
  7918. if (NonEmptyTextFromClipboard(ClipboardText))
  7919. {
  7920. if (StoredSessions->IsUrl(ClipboardText))
  7921. {
  7922. NewSession(ClipboardText);
  7923. }
  7924. else
  7925. {
  7926. DirView(osCurrent)->Path = ClipboardText;
  7927. }
  7928. }
  7929. }
  7930. }
  7931. //---------------------------------------------------------------------------
  7932. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7933. {
  7934. // TBD
  7935. }
  7936. //---------------------------------------------------------------------------
  7937. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7938. {
  7939. TCustomDirView * ADirView = DirView(Side);
  7940. ADirView->SelectAll(Mode);
  7941. ADirView->SetFocus();
  7942. }
  7943. //---------------------------------------------------------------------------
  7944. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7945. {
  7946. TCustomDirView * ADirView = DirView(Side);
  7947. TFileFilter Filter;
  7948. DefaultFileFilter(Filter);
  7949. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7950. {
  7951. Configuration->Usage->Inc(L"MaskSelections");
  7952. ADirView->SelectFiles(Filter, Select);
  7953. ADirView->SetFocus();
  7954. }
  7955. }
  7956. //---------------------------------------------------------------------------
  7957. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7958. {
  7959. TCustomDirView * ADirView = DirView(Side);
  7960. ADirView->RestoreSelectedNames();
  7961. ADirView->SetFocus();
  7962. }
  7963. //---------------------------------------------------------------------------
  7964. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7965. {
  7966. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7967. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7968. {
  7969. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7970. UnicodeString Ext;
  7971. if (!IsSideLocalBrowser(osCurrent))
  7972. {
  7973. Ext = UnixExtractFileExt(FileName);
  7974. }
  7975. else
  7976. {
  7977. Ext = ExtractFileExt(FileName);
  7978. }
  7979. if (Ext.IsEmpty())
  7980. {
  7981. Ext = L".";
  7982. }
  7983. TFileFilter Filter;
  7984. Filter.Masks = FORMAT(L"*%s", (Ext));
  7985. Filter.Directories = false;
  7986. CurrentDirView->SelectFiles(Filter, Select);
  7987. }
  7988. }
  7989. //---------------------------------------------------------------------------
  7990. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7991. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7992. {
  7993. UnicodeString Result;
  7994. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7995. {
  7996. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  7997. }
  7998. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  7999. {
  8000. // noop
  8001. }
  8002. else
  8003. {
  8004. Result =
  8005. FMTLOAD(FILE_INFO_FORMAT,
  8006. (FormatBytes(FileInfo.SelectedSize),
  8007. FormatBytes(FileInfo.FilesSize),
  8008. FormatNumber(FileInfo.SelectedCount),
  8009. FormatNumber(FileInfo.FilesCount)));
  8010. }
  8011. return Result;
  8012. }
  8013. //---------------------------------------------------------------------------
  8014. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8015. TTBXStatusPanel * Panel, TOperationSide Side)
  8016. {
  8017. if (Panel->Index == 1)
  8018. {
  8019. ToggleShowHiddenFiles();
  8020. }
  8021. else if (Panel->Index == 2)
  8022. {
  8023. Filter(Side);
  8024. }
  8025. }
  8026. //---------------------------------------------------------------------------
  8027. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8028. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8029. {
  8030. DebugAssert(!StatusBar->SimplePanel);
  8031. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8032. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8033. }
  8034. //---------------------------------------------------------------------------
  8035. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8036. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8037. {
  8038. DebugAssert(StatusBar->Panels->Count >= 3);
  8039. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8040. if (FileInfo.HiddenCount > 0)
  8041. {
  8042. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8043. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8044. }
  8045. else
  8046. {
  8047. HiddenFilesPanel->ViewPriority = 0;
  8048. // not really necessary, just to cleanup no-longer-valid data
  8049. HiddenFilesPanel->Caption = L"";
  8050. }
  8051. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8052. if (FileInfo.FilteredCount > 0)
  8053. {
  8054. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8055. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8056. }
  8057. else
  8058. {
  8059. FilteredFilesPanel->ViewPriority = 0;
  8060. // not really necessary, just to cleanup no-longer-valid data
  8061. FilteredFilesPanel->Caption = L"";
  8062. }
  8063. }
  8064. //---------------------------------------------------------------------------
  8065. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8066. TObject * /*Sender*/)
  8067. {
  8068. if (DirView(osRemote)->Enabled)
  8069. {
  8070. DirView(osRemote)->SetFocus();
  8071. }
  8072. }
  8073. //---------------------------------------------------------------------------
  8074. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8075. {
  8076. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8077. switch (Config.Show)
  8078. {
  8079. case qvShow:
  8080. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8081. {
  8082. Config.Show = qvHide;
  8083. }
  8084. else
  8085. {
  8086. Config.Show = Config.LastHideShow;
  8087. }
  8088. break;
  8089. case qvHideWhenEmpty:
  8090. if (ComponentVisible[fcQueueView])
  8091. {
  8092. Config.Show = qvHide;
  8093. }
  8094. else
  8095. {
  8096. Config.LastHideShow = Config.Show;
  8097. Config.Show = qvShow;
  8098. }
  8099. break;
  8100. case qvHide:
  8101. Config.LastHideShow = Config.Show;
  8102. Config.Show = qvShow;
  8103. break;
  8104. }
  8105. WinConfiguration->QueueView = Config;
  8106. }
  8107. //---------------------------------------------------------------------------
  8108. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8109. {
  8110. UnicodeString Result;
  8111. if (FTerminal != NULL)
  8112. {
  8113. switch (WinConfiguration->PathInCaption)
  8114. {
  8115. case picShort:
  8116. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8117. break;
  8118. case picFull:
  8119. Result = FTerminal->CurrentDirectory;
  8120. break;
  8121. }
  8122. }
  8123. return Result;
  8124. }
  8125. //---------------------------------------------------------------------------
  8126. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8127. {
  8128. TColor Result = GetWindowColor(FSessionColor);
  8129. return Result;
  8130. }
  8131. //---------------------------------------------------------------------------
  8132. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8133. {
  8134. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8135. return Result;
  8136. }
  8137. //---------------------------------------------------------------------------
  8138. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8139. {
  8140. TTerminalManager::Instance()->UpdateAppTitle();
  8141. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8142. // background to gray on Windows 7 (works on Windows 10).
  8143. // See also EnableControl
  8144. if (Showing)
  8145. {
  8146. if (Terminal != NULL)
  8147. {
  8148. // Update path when it changes
  8149. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8150. {
  8151. UpdateSessionTab(SessionsPageControl->ActivePage);
  8152. }
  8153. }
  8154. NonVisualDataModule->ReconnectSessionAction->Update();
  8155. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8156. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8157. CenterReconnectToolbar();
  8158. bool HasTerminal = HasActiveTerminal();
  8159. if (HasTerminal)
  8160. {
  8161. if (!RemoteDirView->Enabled)
  8162. {
  8163. RemoteDirView->Enabled = true;
  8164. if (FRemoteDirViewWasFocused)
  8165. {
  8166. ActiveControl = RemoteDirView;
  8167. }
  8168. }
  8169. RemoteDirView->Color = PanelColor();
  8170. }
  8171. else
  8172. {
  8173. if (RemoteDirView->Enabled)
  8174. {
  8175. // This is first called when the form is being constructed
  8176. // (not anymore due to Showing test above)
  8177. // but the false is overriden in the constructor later.
  8178. // An even later in TScpCommanderForm::DoShow()
  8179. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  8180. RemoteDirView->Enabled = false;
  8181. }
  8182. RemoteDirView->Color = DisabledPanelColor();
  8183. }
  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. if (FImmersiveDarkMode != WinConfiguration->UseDarkTheme())
  8198. {
  8199. UpdateDarkMode();
  8200. }
  8201. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  8202. }
  8203. }
  8204. //---------------------------------------------------------------------------
  8205. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8206. {
  8207. UpdateControls();
  8208. }
  8209. //---------------------------------------------------------------------------
  8210. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8211. TObject * Sender)
  8212. {
  8213. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8214. DebugAssert(DirView != NULL);
  8215. DoDirViewLoaded(DirView);
  8216. TransferPresetAutoSelect();
  8217. }
  8218. //---------------------------------------------------------------------------
  8219. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8220. {
  8221. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8222. // first run after installation
  8223. if (double(Updates.LastCheck) == 0)
  8224. {
  8225. // make sure next time there will be an update (if enabled)
  8226. Updates.LastCheck = TDateTime(1);
  8227. WinConfiguration->Updates = Updates;
  8228. }
  8229. else if ((double(Updates.Period) > 0) &&
  8230. (Now() - Updates.LastCheck >= Updates.Period))
  8231. {
  8232. TThreadMethod OnUpdatesChecked = NULL;
  8233. if (!IsUWP())
  8234. {
  8235. OnUpdatesChecked = UpdatesChecked;
  8236. }
  8237. StartUpdateThread(OnUpdatesChecked);
  8238. }
  8239. }
  8240. //---------------------------------------------------------------------------
  8241. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8242. {
  8243. UnicodeString Message;
  8244. bool New;
  8245. TQueryType Type;
  8246. GetUpdatesMessage(Message, New, Type, false);
  8247. if (!Message.IsEmpty())
  8248. {
  8249. if (New)
  8250. {
  8251. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8252. }
  8253. if (!New && (Type != qtWarning))
  8254. {
  8255. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8256. }
  8257. else
  8258. {
  8259. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8260. }
  8261. if (New)
  8262. {
  8263. Configuration->Usage->Inc(L"UpdateNotifications");
  8264. }
  8265. }
  8266. }
  8267. //---------------------------------------------------------------------------
  8268. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8269. {
  8270. RestoreApp();
  8271. bool CanDisplay = !NonVisualDataModule->Busy;
  8272. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8273. {
  8274. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8275. }
  8276. if (CanDisplay)
  8277. {
  8278. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8279. CheckForUpdates(true);
  8280. }
  8281. else
  8282. {
  8283. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8284. }
  8285. }
  8286. //---------------------------------------------------------------------------
  8287. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8288. TCopyParamRuleData & Data)
  8289. {
  8290. DebugAssert(Terminal != NULL);
  8291. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8292. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8293. Data.RemoteDirectory = RemoteDirView->PathName;
  8294. }
  8295. //---------------------------------------------------------------------------
  8296. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8297. {
  8298. // Terminal can be null when we are changing local directory implicitly,
  8299. // because it has been deleted, while no session is connected
  8300. // (Login dialog is open)
  8301. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8302. {
  8303. DebugAssert(!IsLocalBrowserMode());
  8304. TCopyParamRuleData Data;
  8305. GetTransferPresetAutoSelectData(Data);
  8306. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8307. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8308. if (CopyParamIndex < 0)
  8309. {
  8310. // there is no preset that matches autoselection
  8311. // set preset that we consider "default"
  8312. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8313. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8314. }
  8315. else
  8316. {
  8317. // there is preset matching autoselection
  8318. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8319. if (CopyParamName == FCopyParamAutoSelected)
  8320. {
  8321. // autoselected the same preset as the last time
  8322. // make no change (i.e. preserve custom user preset, if any)
  8323. }
  8324. else
  8325. {
  8326. // autoselected the different preset then the last time (or there
  8327. // was default preset set)
  8328. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8329. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8330. }
  8331. }
  8332. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8333. {
  8334. if (CopyParamIndex >= 0)
  8335. {
  8336. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8337. }
  8338. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8339. try
  8340. {
  8341. int Fmt =
  8342. (CopyParamIndex < 0) ?
  8343. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8344. COPY_PARAM_AUTOSELECTED;
  8345. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8346. Data->Message = MainInstructions(Message);
  8347. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8348. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8349. CopyParamAttrs);
  8350. if (CopyParamIndex >= 0)
  8351. {
  8352. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8353. Info = FORMAT(L"%s\n \n%s", (Info,
  8354. FMTLOAD(COPY_PARAM_RULE,
  8355. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8356. }
  8357. Data->Message += L"\n\n" + Info;
  8358. if (WinConfiguration->CopyParamAutoSelectNotice)
  8359. {
  8360. TransferPresetNoteMessage(Data, true);
  8361. }
  8362. else
  8363. {
  8364. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8365. Data = NULL; // ownership passed
  8366. }
  8367. }
  8368. __finally
  8369. {
  8370. delete Data;
  8371. }
  8372. }
  8373. }
  8374. }
  8375. //---------------------------------------------------------------------------
  8376. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8377. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8378. {
  8379. DebugAssert(NoteData != NULL);
  8380. DebugAssert(!IsLocalBrowserMode());
  8381. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8382. TQueryButtonAlias Aliases[1];
  8383. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8384. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8385. Params.Aliases = Aliases;
  8386. Params.AliasesCount = LENOF(Aliases);
  8387. unsigned int Result =
  8388. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8389. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8390. switch (Result)
  8391. {
  8392. case qaNeverAskAgain:
  8393. DebugAssert(AllowNeverAskAgain);
  8394. WinConfiguration->CopyParamAutoSelectNotice = false;
  8395. break;
  8396. case qaIgnore:
  8397. PreferencesDialog(pmPresets);
  8398. break;
  8399. }
  8400. }
  8401. //---------------------------------------------------------------------------
  8402. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8403. {
  8404. // as of now useless, as this is used for notes only, never for balloons, ...
  8405. RestoreApp();
  8406. // .. and we should never be busy here
  8407. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8408. {
  8409. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8410. }
  8411. }
  8412. //---------------------------------------------------------------------------
  8413. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8414. TPreferencesMode APreferencesMode)
  8415. {
  8416. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8417. TCopyParamRuleData Data;
  8418. if (Terminal != NULL)
  8419. {
  8420. PreferencesData.reset(new TPreferencesDialogData());
  8421. GetTransferPresetAutoSelectData(Data);
  8422. PreferencesData->CopyParamRuleData = &Data;
  8423. }
  8424. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8425. }
  8426. //---------------------------------------------------------------------------
  8427. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8428. const TCustomCommandType & Command)
  8429. {
  8430. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8431. {
  8432. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8433. }
  8434. }
  8435. //---------------------------------------------------------------------------
  8436. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8437. {
  8438. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8439. TCustomCommandType Command;
  8440. // make sure we use local custom command when remote are not supported
  8441. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8442. {
  8443. Command = FLastCustomCommand;
  8444. }
  8445. else
  8446. {
  8447. Command.Params = Command.Params | ccLocal;
  8448. }
  8449. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8450. FEditingFocusedAdHocCommand = OnFocused;
  8451. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8452. int Options =
  8453. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8454. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8455. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8456. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8457. {
  8458. FLastCustomCommand = Command;
  8459. UpdateCustomCommandsToolbar();
  8460. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8461. }
  8462. }
  8463. //---------------------------------------------------------------------------
  8464. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8465. {
  8466. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8467. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8468. DebugAssert(State > 0);
  8469. if (State <= 0)
  8470. {
  8471. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8472. }
  8473. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8474. }
  8475. //---------------------------------------------------------------------------
  8476. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8477. TCustomCommandType & Command, int & State)
  8478. {
  8479. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8480. if (Result)
  8481. {
  8482. Command = FLastCustomCommand;
  8483. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8484. }
  8485. return Result;
  8486. }
  8487. //---------------------------------------------------------------------------
  8488. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8489. {
  8490. ResetIncrementalSearch();
  8491. }
  8492. //---------------------------------------------------------------------------
  8493. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8494. {
  8495. DebugAssert(ComponentVisible[Component]);
  8496. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8497. }
  8498. //---------------------------------------------------------------------------
  8499. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8500. {
  8501. // when queue panel is resized here directly, the status bar is stretched
  8502. // over whole space the panel occupied
  8503. PostComponentHide(fcQueueView);
  8504. }
  8505. //---------------------------------------------------------------------------
  8506. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8507. {
  8508. ComponentVisible[fcQueueFileList] = false;
  8509. }
  8510. //---------------------------------------------------------------------------
  8511. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8512. {
  8513. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8514. RefreshColorMode();
  8515. ResetSysDarkTheme();
  8516. ConfigurationChanged();
  8517. ConfigureInterface();
  8518. // Should be called for all controls
  8519. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8520. }
  8521. //---------------------------------------------------------------------------
  8522. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8523. {
  8524. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8525. if (!FInvalid &&
  8526. (Message.LParam != 0) &&
  8527. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8528. {
  8529. ThemeChanged();
  8530. }
  8531. TForm::Dispatch(&Message);
  8532. }
  8533. //---------------------------------------------------------------------------
  8534. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8535. {
  8536. TMessage * M = static_cast<TMessage*>(Message);
  8537. switch (M->Msg)
  8538. {
  8539. case CM_DIALOGCHAR:
  8540. CMDialogChar(*M);
  8541. break;
  8542. case WM_APPCOMMAND:
  8543. WMAppCommand(*M);
  8544. break;
  8545. case WM_SYSCOMMAND:
  8546. WMSysCommand(*M);
  8547. break;
  8548. case WM_QUERYENDSESSION:
  8549. WMQueryEndSession(*M);
  8550. break;
  8551. case WM_ENDSESSION:
  8552. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8553. break;
  8554. #ifdef _DEBUG
  8555. case WM_WINDOWPOSCHANGED:
  8556. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8557. break;
  8558. case CM_CUSTOMSTYLECHANGED:
  8559. TForm::Dispatch(Message);
  8560. break;
  8561. #endif
  8562. case WM_COMPONENT_HIDE:
  8563. {
  8564. Byte Component = static_cast<Byte>(M->WParam);
  8565. // sanity check
  8566. if (ComponentVisible[Component])
  8567. {
  8568. // special treatment
  8569. if (Component == fcQueueView)
  8570. {
  8571. ToggleQueueVisibility();
  8572. DebugAssert(!ComponentVisible[fcQueueView]);
  8573. }
  8574. else
  8575. {
  8576. ComponentVisible[Component] = false;
  8577. }
  8578. }
  8579. }
  8580. break;
  8581. case WM_COPYDATA:
  8582. WMCopyData(*M);
  8583. break;
  8584. case WM_MANAGES_CAPTION:
  8585. // caption managed in TTerminalManager::UpdateAppTitle()
  8586. M->Result = 1;
  8587. break;
  8588. case WM_WANTS_MOUSEWHEEL:
  8589. M->Result = 1;
  8590. break;
  8591. case CM_SHOWINGCHANGED:
  8592. CMShowingChanged(*M);
  8593. break;
  8594. case WM_CLOSE:
  8595. WMClose(*M);
  8596. break;
  8597. case WM_DPICHANGED:
  8598. WMDpiChanged(*M);
  8599. break;
  8600. case CM_DPICHANGED:
  8601. CMDpiChanged(*M);
  8602. break;
  8603. case WM_SETTINGCHANGE:
  8604. WMSettingChange(*M);
  8605. break;
  8606. case CM_DIALOGKEY:
  8607. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8608. break;
  8609. default:
  8610. TForm::Dispatch(Message);
  8611. break;
  8612. }
  8613. }
  8614. //---------------------------------------------------------------------------
  8615. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8616. {
  8617. // noop
  8618. }
  8619. //---------------------------------------------------------------------------
  8620. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8621. {
  8622. TForm::Dispatch(&Message);
  8623. FSessionColors->Clear();
  8624. AddFixedSessionImages();
  8625. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8626. UpdateImages();
  8627. }
  8628. //---------------------------------------------------------------------------
  8629. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8630. {
  8631. TForm::Dispatch(&Message);
  8632. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8633. UpdatePixelsPerInchMainWindowCounter();
  8634. }
  8635. //---------------------------------------------------------------------------
  8636. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8637. {
  8638. // Cannot close window while we are busy.
  8639. // We cannot test this in FormCloseQuery as that is called also from
  8640. // Close(), which is called by CloseApplicationAction. So we can be busy
  8641. // there already even, when it is legitimate to close the application.
  8642. // Possibly a better place to handle this would be WMSysCommand.
  8643. if (NonVisualDataModule->Busy)
  8644. {
  8645. Message.Result = 1;
  8646. }
  8647. else
  8648. {
  8649. TForm::Dispatch(&Message);
  8650. }
  8651. }
  8652. //---------------------------------------------------------------------------
  8653. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8654. {
  8655. TForm::Dispatch(&Message);
  8656. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  8657. if (Showing && !FStarted)
  8658. {
  8659. FStarted = true;
  8660. InterfaceStarted();
  8661. }
  8662. if (Showing && (Terminal == NULL))
  8663. {
  8664. // When we are starting minimized (i.e. from an installer),
  8665. // postpone showing Login dialog until we get restored.
  8666. // Otherwise the Login dialog (and Authentication window) show restored
  8667. // over invisible (minimized) main window.
  8668. if (WindowState == wsMinimized)
  8669. {
  8670. FNeedSession = true;
  8671. }
  8672. else
  8673. {
  8674. // This happens before application ever goes idle, so the toolbars would
  8675. // stay enabled (initial state) until the Login dialog is dismissed.
  8676. UpdateActions();
  8677. NonVisualDataModule->StartBusy();
  8678. try
  8679. {
  8680. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8681. // otherwise the dialog does not receive focus.
  8682. // With Commander interface the ProcessMessages is called already
  8683. // by TDriveView, but with Explorer interface, we need to call it explicily
  8684. Application->ProcessMessages();
  8685. // do not reload sessions, they have been loaded just now (optimization)
  8686. NeedSession(true);
  8687. }
  8688. __finally
  8689. {
  8690. NonVisualDataModule->EndBusy();
  8691. }
  8692. }
  8693. }
  8694. }
  8695. //---------------------------------------------------------------------------
  8696. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8697. {
  8698. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8699. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8700. }
  8701. //---------------------------------------------------------------------------
  8702. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8703. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8704. int & MaxHeight)
  8705. {
  8706. // workaround for bug in TWinControl.CalcConstraints
  8707. // Check for empty rect (restore from iconic state) is done there only after
  8708. // call to AdjustClientRect, which enlarges the rect (for forms).
  8709. TRect R = GetClientRect();
  8710. // when restoring from iconic state, place no restrictions
  8711. if (IsRectEmpty(R))
  8712. {
  8713. MinWidth = 0;
  8714. MinHeight = 0;
  8715. MaxWidth = 32000;
  8716. MaxHeight = 32000;
  8717. }
  8718. }
  8719. //---------------------------------------------------------------------------
  8720. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8721. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8722. {
  8723. // terminal can be already closed (e.g. dropped connection)
  8724. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8725. {
  8726. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8727. try
  8728. {
  8729. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8730. }
  8731. catch(...)
  8732. {
  8733. if (!Terminal->Active)
  8734. {
  8735. Close = true;
  8736. }
  8737. throw;
  8738. }
  8739. }
  8740. }
  8741. //---------------------------------------------------------------------------
  8742. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8743. {
  8744. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8745. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8746. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8747. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8748. {
  8749. OnGetSpaceAvailable = GetSpaceAvailable;
  8750. }
  8751. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8752. OnGetSpaceAvailable);
  8753. }
  8754. //---------------------------------------------------------------------------
  8755. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8756. {
  8757. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8758. Terminal->FillSessionDataForCode(Data.get());
  8759. return Data.release();
  8760. }
  8761. //---------------------------------------------------------------------------
  8762. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8763. {
  8764. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8765. DoGenerateUrlDialog(Data.get(), Paths);
  8766. }
  8767. //---------------------------------------------------------------------------
  8768. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8769. {
  8770. GenerateUrl(NULL);
  8771. }
  8772. //---------------------------------------------------------------------------
  8773. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8774. {
  8775. std::unique_ptr<TStrings> Paths(new TStringList());
  8776. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8777. GenerateUrl(Paths.get());
  8778. }
  8779. //---------------------------------------------------------------------------
  8780. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8781. {
  8782. FSessionColor = value;
  8783. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8784. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8785. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8786. DebugAssert(ColorItem != NULL);
  8787. ColorItem->Color = C;
  8788. NonVisualDataModule->ColorMenuItem->Color = C;
  8789. UpdateControls();
  8790. }
  8791. //---------------------------------------------------------------------------
  8792. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8793. {
  8794. if (value != FSessionColor)
  8795. {
  8796. UpdateSessionColor(value);
  8797. // Is null when called from LastTerminalClosed
  8798. if (Terminal != NULL)
  8799. {
  8800. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8801. }
  8802. }
  8803. }
  8804. //---------------------------------------------------------------------------
  8805. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8806. {
  8807. bool Result = FNoteTimer->Enabled;
  8808. if (Result)
  8809. {
  8810. // cannot cancel note too early
  8811. bool NotEarly =
  8812. (Now() - FNoteShown >
  8813. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8814. if (Force || NotEarly)
  8815. {
  8816. FNoteTimer->Enabled = false;
  8817. FNote = L"";
  8818. SAFE_DESTROY(FNoteData);
  8819. FOnNoteClick = NULL;
  8820. FNoteHints = FNotes->Text;
  8821. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8822. UpdateStatusBar();
  8823. }
  8824. }
  8825. return Result;
  8826. }
  8827. //---------------------------------------------------------------------------
  8828. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8829. {
  8830. DebugAssert(FNoteTimer->Enabled);
  8831. CancelNote(true);
  8832. }
  8833. //---------------------------------------------------------------------------
  8834. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  8835. {
  8836. FNoteHints = FNotes->Text.TrimRight();
  8837. }
  8838. //---------------------------------------------------------------------------
  8839. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8840. {
  8841. int P = Note.Pos(L"\n");
  8842. if (P > 0)
  8843. {
  8844. Note.SetLength(P - 1);
  8845. }
  8846. FNotes->Add(FORMAT(L"[%s] %s",
  8847. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8848. while (FNotes->Count > 10)
  8849. {
  8850. FNotes->Delete(0);
  8851. }
  8852. if (UpdateNow)
  8853. {
  8854. UpdateNoteHints();
  8855. UpdateStatusBar();
  8856. }
  8857. }
  8858. //---------------------------------------------------------------------------
  8859. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8860. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8861. {
  8862. int P = Note.Pos(L"\n");
  8863. if (P > 0)
  8864. {
  8865. Note.SetLength(P - 1);
  8866. }
  8867. UpdateNoteHints();
  8868. FNote = Note;
  8869. SAFE_DESTROY(FNoteData);
  8870. FNoteData = NoteData;
  8871. FOnNoteClick = OnNoteClick;
  8872. AddNote(Note, false);
  8873. UpdateStatusBar();
  8874. FNoteShown = Now();
  8875. FNoteTimer->Enabled = false;
  8876. if (Seconds == 0)
  8877. {
  8878. Seconds = WinConfiguration->NotificationsTimeout;
  8879. }
  8880. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8881. FNoteTimer->Enabled = true;
  8882. }
  8883. //---------------------------------------------------------------------------
  8884. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8885. {
  8886. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8887. }
  8888. //---------------------------------------------------------------------------
  8889. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8890. {
  8891. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked)
  8892. {
  8893. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8894. }
  8895. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8896. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8897. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  8898. 0, NULL, NULL);
  8899. }
  8900. //---------------------------------------------------------------------------
  8901. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8902. {
  8903. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8904. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8905. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8906. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  8907. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8908. }
  8909. //---------------------------------------------------------------------------
  8910. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8911. {
  8912. WinConfiguration->FormatSizeBytes = Style;
  8913. }
  8914. //---------------------------------------------------------------------------
  8915. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8916. {
  8917. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8918. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8919. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8920. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8921. }
  8922. //---------------------------------------------------------------------------
  8923. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8924. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8925. {
  8926. if (Panel->Index == 0)
  8927. {
  8928. if (FOnNoteClick != NULL)
  8929. {
  8930. // prevent the user data from being freed by possible call
  8931. // to CancelNote or PostNote during call to OnNoteClick
  8932. std::unique_ptr<TObject> NoteData(FNoteData);
  8933. TNotifyEvent OnNoteClick = FOnNoteClick;
  8934. FNoteData = NULL;
  8935. // need to cancel the note as we are going to delete its user data
  8936. CancelNote(true);
  8937. OnNoteClick(NoteData.get());
  8938. }
  8939. }
  8940. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8941. {
  8942. FileSystemInfo();
  8943. }
  8944. }
  8945. //---------------------------------------------------------------------------
  8946. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8947. {
  8948. // workaround:
  8949. // 1) for unknown reason, disabling window, while minimized,
  8950. // prevents it from restoring, even if it was enabled again meanwhile
  8951. // 2) when disabling the main window, while another has focus
  8952. // minimize is no longer possible
  8953. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8954. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8955. // Shouldn't we use IsApplicationMinimized() here?
  8956. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8957. {
  8958. Enabled = false;
  8959. }
  8960. FLockLevel++;
  8961. }
  8962. //---------------------------------------------------------------------------
  8963. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8964. {
  8965. DebugAssert(FLockLevel > 0);
  8966. FLockLevel--;
  8967. if (FLockLevel == 0)
  8968. {
  8969. DebugAssert(FLockSuspendLevel == 0);
  8970. Enabled = true;
  8971. }
  8972. }
  8973. //---------------------------------------------------------------------------
  8974. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8975. {
  8976. // We need to make sure that window is enabled when the last modal window closes
  8977. // otherwise focus is not restored correctly.
  8978. // So we re-enable the window when modal window opens and
  8979. // disable it back after is closes
  8980. if (FLockLevel > 0)
  8981. {
  8982. // while we have nesting counter, we know that we never be called
  8983. // recursivelly as Application->OnModalBegin is called only
  8984. // for the top-level modal window
  8985. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8986. {
  8987. // won't be disabled when conditions in LockWindow() were not satisfied
  8988. FDisabledOnLockSuspend = !Enabled;
  8989. // When minimized to tray (or actually when set to SW_HIDE),
  8990. // setting Enabled makes the window focusable even when there's
  8991. // modal window over it
  8992. if (!FTrayIcon->Visible)
  8993. {
  8994. Enabled = true;
  8995. }
  8996. }
  8997. FLockSuspendLevel++;
  8998. }
  8999. }
  9000. //---------------------------------------------------------------------------
  9001. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  9002. {
  9003. if (FLockSuspendLevel > 0)
  9004. {
  9005. DebugAssert(FLockLevel > 0);
  9006. FLockSuspendLevel--;
  9007. // see comment in SuspendWindowLock
  9008. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9009. {
  9010. // Note that window can be enabled here, when we were minized to tray when
  9011. // was SuspendWindowLock() called.
  9012. // We should possibly do the same check as in LockWindow(),
  9013. // if it is ever possible that the consitions change between
  9014. // SuspendWindowLock() and ResumeWindowLock()
  9015. Enabled = !FDisabledOnLockSuspend;
  9016. }
  9017. }
  9018. }
  9019. //---------------------------------------------------------------------------
  9020. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9021. {
  9022. TTBXComboBoxItem * RemotePathComboBox =
  9023. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9024. if (!TextOnly)
  9025. {
  9026. TStrings * Items = RemotePathComboBox->Strings;
  9027. Items->BeginUpdate();
  9028. try
  9029. {
  9030. Items->Clear();
  9031. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9032. {
  9033. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9034. while (!IsUnixRootPath(APath))
  9035. {
  9036. int P = APath.LastDelimiter(L'/');
  9037. DebugAssert(P >= 0);
  9038. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9039. APath.SetLength(P - 1);
  9040. }
  9041. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9042. }
  9043. }
  9044. __finally
  9045. {
  9046. Items->EndUpdate();
  9047. }
  9048. }
  9049. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9050. // Setting ItemIndex to -1 does not reset its text
  9051. if (RemotePathComboBox->Strings->Count == 0)
  9052. {
  9053. RemotePathComboBox->Text = L"";
  9054. }
  9055. }
  9056. //---------------------------------------------------------------------------
  9057. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9058. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  9059. int & ImageIndex)
  9060. {
  9061. if (AIndex < 0)
  9062. {
  9063. AIndex = Sender->ItemIndex;
  9064. }
  9065. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9066. }
  9067. //---------------------------------------------------------------------------
  9068. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9069. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9070. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9071. {
  9072. ARect.Left += (10 * AIndex);
  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::RemotePathComboBoxItemClick(
  9082. TObject * Sender)
  9083. {
  9084. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9085. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9086. int Index = RemotePathComboBox->ItemIndex;
  9087. while (Index < RemotePathComboBox->Strings->Count - 1)
  9088. {
  9089. APath = UnixExtractFileDir(APath);
  9090. Index++;
  9091. }
  9092. // VanDyke style paths
  9093. if (APath.IsEmpty())
  9094. {
  9095. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9096. APath = ROOTDIRECTORY;
  9097. }
  9098. if (RemoteDirView->Path != APath)
  9099. {
  9100. RemoteDirView->Path = APath;
  9101. }
  9102. }
  9103. //---------------------------------------------------------------------------
  9104. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9105. {
  9106. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9107. DebugUsedParam(Sender);
  9108. UpdateRemotePathComboBox(true);
  9109. }
  9110. //---------------------------------------------------------------------------
  9111. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9112. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9113. {
  9114. ResetIncrementalSearch();
  9115. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9116. DebugAssert(DirView != NULL);
  9117. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9118. {
  9119. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9120. // OnEditing is called also from TCustomListView::CanEdit
  9121. if (Edit != NULL)
  9122. {
  9123. EditSelectBaseName(Edit);
  9124. }
  9125. }
  9126. }
  9127. //---------------------------------------------------------------------------
  9128. //---------------------------------------------------------------------------
  9129. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9130. {
  9131. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9132. Result->AutoDetectDnD = false;
  9133. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9134. Result->RenderDataOn = rdoEnterAndDropSync;
  9135. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9136. return Result;
  9137. }
  9138. //---------------------------------------------------------------------------
  9139. void __fastcall TCustomScpExplorerForm::UpdateDarkMode()
  9140. {
  9141. if (IsWin10Build(2004))
  9142. {
  9143. FImmersiveDarkMode = WinConfiguration->UseDarkTheme();
  9144. BOOL DarkMode = FImmersiveDarkMode ? TRUE : FALSE;
  9145. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9146. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9147. }
  9148. }
  9149. //---------------------------------------------------------------------------
  9150. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9151. {
  9152. TForm::CreateWnd();
  9153. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9154. UpdateDarkMode();
  9155. if (FSessionsDragDropFilesEx == NULL)
  9156. {
  9157. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9158. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9159. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9160. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9161. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9162. }
  9163. if (FQueueDragDropFilesEx == NULL)
  9164. {
  9165. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9166. // No need to set OnDragOver as we do not have any restrictions
  9167. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9168. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9169. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9170. }
  9171. }
  9172. //---------------------------------------------------------------------------
  9173. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9174. {
  9175. TForm::DestroyWnd();
  9176. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9177. FQueueDragDropFilesEx->DragDropControl = NULL;
  9178. }
  9179. //---------------------------------------------------------------------------
  9180. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9181. {
  9182. SideEnter(FCurrentSide);
  9183. FEverShown = true;
  9184. }
  9185. //---------------------------------------------------------------------------
  9186. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9187. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9188. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9189. {
  9190. if (!NonVisualDataModule->Busy)
  9191. {
  9192. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9193. Configuration->Usage->Inc(L"FileFinds");
  9194. LockWindow(true);
  9195. NonVisualDataModule->StartBusy();
  9196. WinConfiguration->LockedInterface = true;
  9197. try
  9198. {
  9199. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9200. }
  9201. __finally
  9202. {
  9203. WinConfiguration->LockedInterface = false;
  9204. NonVisualDataModule->EndBusy();
  9205. UnlockWindow();
  9206. }
  9207. }
  9208. }
  9209. //---------------------------------------------------------------------------
  9210. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9211. {
  9212. if (!NonVisualDataModule->Busy)
  9213. {
  9214. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9215. SetFocus();
  9216. RemoteDirView->Path = UnixExtractFilePath(Path);
  9217. UnicodeString FileName = UnixExtractFileName(Path);
  9218. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9219. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9220. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9221. if (Item == NULL)
  9222. {
  9223. ReloadDirectory(osRemote);
  9224. Item = RemoteDirView->FindFileItem(FileName);
  9225. }
  9226. if (Item != NULL)
  9227. {
  9228. RemoteDirView->ItemFocused = Item;
  9229. RemoteDirView->ItemFocused->MakeVisible(false);
  9230. RemoteDirView->SetFocus();
  9231. }
  9232. }
  9233. }
  9234. //---------------------------------------------------------------------------
  9235. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9236. {
  9237. bool Result = !NonVisualDataModule->Busy;
  9238. if (Result)
  9239. {
  9240. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9241. }
  9242. return Result;
  9243. }
  9244. //---------------------------------------------------------------------------
  9245. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9246. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9247. {
  9248. if (CanOperateOnFoundFiles(ATerminal))
  9249. {
  9250. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9251. FOnFileOperationFinished = OnFileOperationFinished;
  9252. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9253. }
  9254. }
  9255. //---------------------------------------------------------------------------
  9256. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9257. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9258. {
  9259. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9260. }
  9261. //---------------------------------------------------------------------------
  9262. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9263. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9264. {
  9265. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9266. }
  9267. //---------------------------------------------------------------------------
  9268. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9269. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9270. {
  9271. if (CanOperateOnFoundFiles(ATerminal))
  9272. {
  9273. for (int Index = 0; Index < FileList->Count; Index++)
  9274. {
  9275. UnicodeString FileName = FileList->Strings[Index];
  9276. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9277. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9278. OnFileOperationFinished(FileName, true);
  9279. }
  9280. }
  9281. }
  9282. //---------------------------------------------------------------------------
  9283. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9284. {
  9285. FFileFindTerminal = Terminal;
  9286. ShowFileFindDialog(
  9287. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9288. DoDownloadFoundFiles, DoEditFoundFiles);
  9289. }
  9290. //---------------------------------------------------------------------------
  9291. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9292. {
  9293. FTaskbarList = TaskbarList;
  9294. }
  9295. //---------------------------------------------------------------------------
  9296. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9297. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9298. {
  9299. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9300. if (Index >= 0)
  9301. {
  9302. if (Button == mbLeft)
  9303. {
  9304. // "Mouse down" is raised only after tab is switched.
  9305. // If switching tab (switching session) takes long enough for user
  9306. // to actually release the button, "mouse down" is still raised,
  9307. // but we do not get "mouse up" event, so dragging is not cancelled,
  9308. // prevent that by not beginning dragging in the first place.
  9309. if (IsKeyPressed(VK_LBUTTON))
  9310. {
  9311. // when user clicks the "+", we get mouse down only after the session
  9312. // is closed, when new session tab is already on X:Y, so dragging
  9313. // starts, prevent that
  9314. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9315. {
  9316. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9317. if (Terminal != NULL)
  9318. {
  9319. SessionsPageControl->BeginDrag(false);
  9320. }
  9321. }
  9322. }
  9323. }
  9324. else if (Button == mbMiddle)
  9325. {
  9326. // ignore middle-click for "New session tab"
  9327. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9328. if (Terminal != NULL)
  9329. {
  9330. CloseSessionTab(Index);
  9331. }
  9332. }
  9333. }
  9334. }
  9335. //---------------------------------------------------------------------------
  9336. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9337. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9338. {
  9339. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9340. // do not allow dropping on the "+" tab
  9341. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9342. if ((TargetTerminal != NULL) &&
  9343. (SessionsPageControl->ActivePage->PageIndex != Index))
  9344. {
  9345. Configuration->Usage->Inc(L"SessionTabMoves");
  9346. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9347. // but we want to actually prevent that to avoid flicker
  9348. SessionsPageControl->ActivePage->PageIndex = Index;
  9349. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9350. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9351. }
  9352. }
  9353. //---------------------------------------------------------------------------
  9354. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9355. TObject * Sender, TObject * Source, int X, int Y,
  9356. TDragState /*State*/, bool & Accept)
  9357. {
  9358. Accept = (Sender == Source);
  9359. if (Accept)
  9360. {
  9361. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9362. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9363. // do not allow dragging to the "+" tab
  9364. Accept = (Terminal != NULL);
  9365. }
  9366. }
  9367. //---------------------------------------------------------------------------
  9368. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9369. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9370. {
  9371. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9372. if (Index < 0)
  9373. {
  9374. Effect = DROPEFFECT_NONE;
  9375. }
  9376. else
  9377. {
  9378. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9379. // do not allow dropping on the "+" and disconnected tabs
  9380. if (!IsActiveTerminal(TargetTerminal))
  9381. {
  9382. Effect = DROPEFFECT_NONE;
  9383. }
  9384. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9385. {
  9386. Effect = DROPEFFECT_COPY;
  9387. }
  9388. }
  9389. }
  9390. //---------------------------------------------------------------------------
  9391. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9392. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9393. {
  9394. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9395. // do not allow dropping on the "+" and disconnected tabs
  9396. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9397. if (IsActiveTerminal(TargetTerminal))
  9398. {
  9399. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9400. if (!IsFileControl(DropSourceControl, osRemote))
  9401. {
  9402. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9403. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9404. // Why don't we use Terminal->CurrentDirectory directly?
  9405. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9406. // do not force queue, drag drop
  9407. false, true);
  9408. }
  9409. }
  9410. }
  9411. //---------------------------------------------------------------------------
  9412. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9413. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9414. {
  9415. // Downloads are handled in RemoteFileControlDDEnd
  9416. if (!IsFileControl(DropSourceControl, osRemote))
  9417. {
  9418. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9419. Terminal->CurrentDirectory,
  9420. // force queue, drag drop
  9421. true, true);
  9422. }
  9423. }
  9424. //---------------------------------------------------------------------------
  9425. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9426. {
  9427. FShowing = false;
  9428. // Do not save empty workspace
  9429. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9430. {
  9431. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9432. UnicodeString Name = WorkspaceName();
  9433. DoSaveWorkspace(
  9434. Name, DataList.get(),
  9435. !Configuration->DisablePasswordStoring &&
  9436. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9437. WinConfiguration->LastStoredSession = Name;
  9438. }
  9439. }
  9440. //---------------------------------------------------------------------------
  9441. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9442. {
  9443. TManagedTerminal * ManagedTerminal =
  9444. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9445. if (ManagedTerminal != NULL)
  9446. {
  9447. ManagedTerminal->DirectoryLoaded = Now();
  9448. }
  9449. }
  9450. //---------------------------------------------------------------------------
  9451. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9452. TListItem * /*Item*/, bool /*Selected*/)
  9453. {
  9454. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9455. switch (DirView->LastSelectMethod)
  9456. {
  9457. case smKeyboard:
  9458. Configuration->Usage->Inc(L"KeyboardSelections");
  9459. break;
  9460. case smMouse:
  9461. Configuration->Usage->Inc(L"MouseSelections");
  9462. break;
  9463. }
  9464. }
  9465. //---------------------------------------------------------------------------
  9466. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9467. {
  9468. if (Color != 0)
  9469. {
  9470. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9471. }
  9472. else
  9473. {
  9474. return FSessionTabImageIndex;
  9475. }
  9476. }
  9477. //---------------------------------------------------------------------------
  9478. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9479. {
  9480. TPngImageCollectionItem * Item =
  9481. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9482. FSessionColors->AddPng(Item->PngImage);
  9483. return FSessionColors->Count - 1;
  9484. }
  9485. //---------------------------------------------------------------------------
  9486. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9487. {
  9488. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9489. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9490. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9491. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9492. }
  9493. //---------------------------------------------------------------------------
  9494. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9495. {
  9496. for (int Index = 0; Index < Control->ControlCount; Index++)
  9497. {
  9498. TControl * AControl = Control->Controls[Index];
  9499. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9500. if (WinControl != NULL)
  9501. {
  9502. CollectItemsWithTextDisplayMode(WinControl);
  9503. }
  9504. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9505. if (Toolbar != NULL)
  9506. {
  9507. // we care for top-level items only
  9508. TTBCustomItem * Items = Toolbar->Items;
  9509. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9510. {
  9511. TTBCustomItem * Item = Items->Items[ItemIndex];
  9512. if (((Item->DisplayMode == nbdmImageAndText) ||
  9513. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9514. EligibleForImageDisplayMode(Item))
  9515. {
  9516. FItemsWithTextDisplayMode.insert(Item);
  9517. }
  9518. }
  9519. }
  9520. }
  9521. }
  9522. //---------------------------------------------------------------------------
  9523. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9524. {
  9525. return true;
  9526. }
  9527. //---------------------------------------------------------------------------
  9528. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9529. {
  9530. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9531. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9532. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9533. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9534. bool Result = true;
  9535. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9536. {
  9537. TTBCustomItem * Item = *i;
  9538. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9539. if (Label != NULL)
  9540. {
  9541. // optimization
  9542. if (Label->Visible == SelectiveToolbarText)
  9543. {
  9544. Result = false;
  9545. }
  9546. else
  9547. {
  9548. Label->Visible = SelectiveToolbarText;
  9549. }
  9550. }
  9551. else
  9552. {
  9553. // optimization
  9554. if (Item->DisplayMode == DisplayMode)
  9555. {
  9556. Result = false;
  9557. }
  9558. else
  9559. {
  9560. Item->DisplayMode = DisplayMode;
  9561. }
  9562. }
  9563. ++i;
  9564. }
  9565. if (Result)
  9566. {
  9567. UpdateNewSessionTab();
  9568. }
  9569. return Result;
  9570. }
  9571. //---------------------------------------------------------------------------
  9572. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9573. {
  9574. DebugFail();
  9575. }
  9576. //---------------------------------------------------------------------------
  9577. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9578. {
  9579. // Among other, a lock level is non zero, while directory is being loaded,
  9580. // even when it happens as a result of dirview navigation,
  9581. // i.e. when TNonVisualDataModule is NOT FBusy.
  9582. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9583. // Among other this prevents a panel auto update to occur while
  9584. // directory is changing.
  9585. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9586. }
  9587. //---------------------------------------------------------------------------
  9588. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  9589. {
  9590. // While the window is disabled, we still seem to process menu shortcuts at least,
  9591. // so stop it at least here.
  9592. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9593. return
  9594. (Allowed == aaUpdate) ||
  9595. !NonVisualDataModule->Busy;
  9596. }
  9597. //---------------------------------------------------------------------------
  9598. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9599. {
  9600. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9601. }
  9602. //---------------------------------------------------------------------------
  9603. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9604. {
  9605. // This is somewhat redundant to LockWindow() call from
  9606. // TTerminalManager::TerminalReadDirectoryProgress.
  9607. // But disabling window is known not to block keyboard shorcuts
  9608. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9609. if (Busy > 0)
  9610. {
  9611. if (NonVisualDataModule->Busy)
  9612. {
  9613. State = false;
  9614. }
  9615. else
  9616. {
  9617. NonVisualDataModule->StartBusy();
  9618. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9619. LockWindow();
  9620. }
  9621. }
  9622. else if (Busy < 0)
  9623. {
  9624. UnlockWindow();
  9625. NonVisualDataModule->EndBusy();
  9626. }
  9627. else
  9628. {
  9629. State = NonVisualDataModule->Busy;
  9630. }
  9631. }
  9632. //---------------------------------------------------------------------------
  9633. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9634. {
  9635. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9636. // no context menu for "New session tab"
  9637. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9638. {
  9639. SessionsPageControl->ActivePageIndex = Index;
  9640. if (DebugAlwaysTrue(SessionTabSwitched()))
  9641. {
  9642. // copied from TControl.WMContextMenu
  9643. SendCancelMode(SessionsPageControl);
  9644. // explicit popup instead of using PopupMenu property
  9645. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9646. // while connecting yet not-connected session and hence
  9647. // allowing an access to commands over not-completelly connected session
  9648. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9649. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9650. PopupMenu->PopupComponent = SessionsPageControl;
  9651. PopupMenu->Popup(Point.x, Point.y);
  9652. }
  9653. }
  9654. Handled = true;
  9655. }
  9656. //---------------------------------------------------------------------------
  9657. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9658. {
  9659. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9660. }
  9661. //---------------------------------------------------------------------------
  9662. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9663. {
  9664. Configuration->Usage->Inc(L"PasswordChanges");
  9665. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9666. ChangePasswordData->DisableAuthentationsExceptPassword();
  9667. ChangePasswordData->ChangePassword = true;
  9668. std::unique_ptr<TTerminal> ChangePasswordSession(
  9669. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9670. ChangePasswordSession->AutoReadDirectory = false;
  9671. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9672. {
  9673. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9674. }
  9675. else
  9676. {
  9677. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9678. }
  9679. }
  9680. //---------------------------------------------------------------------------
  9681. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9682. {
  9683. // No nice way to assert SSH2
  9684. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9685. }
  9686. //---------------------------------------------------------------------------
  9687. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9688. {
  9689. TOperationVisualizer OperationVisualizer;
  9690. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9691. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9692. }
  9693. //---------------------------------------------------------------------------
  9694. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9695. {
  9696. TForm::ChangeScale(M, D);
  9697. int APixelsPerInch = GetControlPixelsPerInch(this);
  9698. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9699. try
  9700. {
  9701. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9702. }
  9703. __finally
  9704. {
  9705. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9706. }
  9707. }
  9708. //---------------------------------------------------------------------------
  9709. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9710. {
  9711. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9712. }
  9713. //---------------------------------------------------------------------
  9714. class TPublicControl : public TControl
  9715. {
  9716. friend class TCustomScpExplorerForm;
  9717. };
  9718. //---------------------------------------------------------------------------
  9719. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9720. {
  9721. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9722. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9723. }
  9724. //---------------------------------------------------------------------------
  9725. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9726. {
  9727. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9728. OpenBookmark(Side, Bookmark);
  9729. }
  9730. //---------------------------------------------------------------------------
  9731. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9732. {
  9733. DoBookmarkClick(osLocal, Sender);
  9734. }
  9735. //---------------------------------------------------------------------------
  9736. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9737. {
  9738. DoBookmarkClick(osRemote, Sender);
  9739. }
  9740. //---------------------------------------------------------------------------
  9741. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9742. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9743. {
  9744. if (BookmarkList != NULL)
  9745. {
  9746. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9747. if (!WinConfiguration->UseLocationProfiles)
  9748. {
  9749. std::unique_ptr<TStringList> Directories(new TStringList());
  9750. Directories->CaseSensitive = (Side == osRemote);
  9751. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9752. {
  9753. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9754. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9755. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9756. {
  9757. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9758. Item->Caption = EscapeHotkey(Directory);
  9759. Item->ShortCut = Bookmark->ShortCut;
  9760. Item->OnClick = OnBookmarkClick;
  9761. Item->Tag = reinterpret_cast<int>(Bookmark);
  9762. Directories->Add(Directory);
  9763. Menu->Add(Item.release());
  9764. }
  9765. }
  9766. }
  9767. else
  9768. {
  9769. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9770. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9771. {
  9772. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9773. if (!Bookmark->Node.IsEmpty())
  9774. {
  9775. Folders->Add(Bookmark->Node);
  9776. }
  9777. }
  9778. for (int Index = 0; Index < Folders->Count; Index++)
  9779. {
  9780. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9781. Item->Caption = Folders->Strings[Index];
  9782. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction->ImageIndex;
  9783. Folders->Objects[Index] = Item.get();
  9784. Menu->Add(Item.release());
  9785. }
  9786. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9787. {
  9788. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9789. TTBCustomItem * Parent;
  9790. if (!Bookmark->Node.IsEmpty())
  9791. {
  9792. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9793. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9794. }
  9795. else
  9796. {
  9797. Parent = Menu;
  9798. }
  9799. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9800. Item->Caption = Bookmark->Name;
  9801. Item->ShortCut = Bookmark->ShortCut;
  9802. Item->OnClick = OnBookmarkClick;
  9803. Item->Tag = reinterpret_cast<int>(Bookmark);
  9804. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9805. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9806. {
  9807. // No hint for location profiles that are actually mere "bookmarks"
  9808. }
  9809. else
  9810. {
  9811. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9812. UnicodeString LongHint;
  9813. if (!Bookmark->Local.IsEmpty())
  9814. {
  9815. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9816. }
  9817. if (!Bookmark->Remote.IsEmpty())
  9818. {
  9819. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9820. }
  9821. AddToList(Hint, LongHint, L"|");
  9822. Item->Hint = Hint;
  9823. }
  9824. Parent->Add(Item.release());
  9825. }
  9826. }
  9827. AddMenuSeparator(Menu);
  9828. }
  9829. }
  9830. //---------------------------------------------------------------------------
  9831. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9832. {
  9833. Menu->Clear();
  9834. std::unique_ptr<TTBCustomItem> Item;
  9835. Item.reset(new TTBXItem(Owner));
  9836. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9837. Item->Options = Item->Options << tboDefault;
  9838. Menu->Add(Item.release());
  9839. AddMenuSeparator(Menu);
  9840. if (Terminal != NULL)
  9841. {
  9842. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9843. }
  9844. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9845. Item.reset(new TTBXItem(Owner));
  9846. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction : NonVisualDataModule->RemoteAddBookmarkAction;
  9847. Menu->Add(Item.release());
  9848. }
  9849. //---------------------------------------------------------------------------
  9850. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9851. {
  9852. bool Result = true;
  9853. try
  9854. {
  9855. if (Side == osRemote)
  9856. {
  9857. Terminal->ExceptionOnFail = true;
  9858. }
  9859. try
  9860. {
  9861. DirView(Side)->Path = Path;
  9862. }
  9863. __finally
  9864. {
  9865. if (Side == osRemote)
  9866. {
  9867. Terminal->ExceptionOnFail = false;
  9868. }
  9869. }
  9870. }
  9871. catch (Exception & E)
  9872. {
  9873. if ((Side != osRemote) || Terminal->Active)
  9874. {
  9875. ShowExtendedExceptionEx(Terminal, &E);
  9876. Result = false;
  9877. }
  9878. else
  9879. {
  9880. throw;
  9881. }
  9882. }
  9883. return Result;
  9884. }
  9885. //---------------------------------------------------------------------------
  9886. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9887. {
  9888. // Make sure there some feedback even when loading tiny local folders
  9889. TInstantOperationVisualizer Visualizer;
  9890. DirView(Side)->ReloadDirectory();
  9891. }
  9892. //---------------------------------------------------------------------------
  9893. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9894. {
  9895. if (Index == SessionsPageControl->TabIndex)
  9896. {
  9897. CloseSession();
  9898. }
  9899. else
  9900. {
  9901. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9902. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9903. TTerminalManager * Manager = TTerminalManager::Instance();
  9904. if (!Terminal->Active)
  9905. {
  9906. Manager->FreeTerminal(Terminal);
  9907. }
  9908. else
  9909. {
  9910. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9911. if (CanCloseQueue(Queue))
  9912. {
  9913. Manager->FreeTerminal(Terminal);
  9914. }
  9915. }
  9916. }
  9917. }
  9918. //---------------------------------------------------------------------------
  9919. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9920. {
  9921. CloseSessionTab(Index);
  9922. }
  9923. //---------------------------------------------------------------------------
  9924. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9925. {
  9926. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9927. {
  9928. TInstantOperationVisualizer Visualizer;
  9929. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9930. // before we create a new data object
  9931. ClipboardClear();
  9932. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9933. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9934. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9935. // Intermediate variable to WORKAROUND a crash in compiler
  9936. TObjectList * ClipboardFakeMonitors =
  9937. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9938. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9939. if (FClipboardDragDropFilesEx.get() == NULL)
  9940. {
  9941. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9942. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9943. }
  9944. FClipboardDragDropFilesEx->FileList->Clear();
  9945. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9946. FClipboardDragDropFilesEx->CopyToClipboard();
  9947. FClipboardTerminal = FTerminal;
  9948. // Need full paths, as cwd can be different once files are pasted
  9949. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9950. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9951. {
  9952. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9953. }
  9954. }
  9955. }
  9956. //---------------------------------------------------------------------------
  9957. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9958. {
  9959. if (OpenClipboard(0))
  9960. {
  9961. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9962. CloseClipboard();
  9963. }
  9964. }
  9965. //---------------------------------------------------------------------------
  9966. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9967. {
  9968. return !FClipboardFakeDirectory.IsEmpty();
  9969. }
  9970. //---------------------------------------------------------------------------
  9971. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9972. {
  9973. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9974. FClipboardFakeDirectory = UnicodeString();
  9975. FClipboardTerminal = NULL;
  9976. // Also called in Idle()
  9977. FClipboardFakeMonitors.reset(NULL);
  9978. }
  9979. //---------------------------------------------------------------------------
  9980. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9981. {
  9982. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9983. {
  9984. ClipboardStop();
  9985. }
  9986. }
  9987. //---------------------------------------------------------------------------
  9988. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9989. {
  9990. TTerminalManager * Manager = TTerminalManager::Instance();
  9991. Manager->ActiveTerminal = FClipboardTerminal;
  9992. TTransferOperationParam Params;
  9993. Params.TargetDirectory = TargetDirectory;
  9994. Params.DragDrop = DragDrop;
  9995. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  9996. }
  9997. //---------------------------------------------------------------------------
  9998. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  9999. {
  10000. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  10001. // (as it pumps a Windows message queue while being shutted down)
  10002. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10003. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10004. {
  10005. // Can fail as it can be e.g. locked by AV, so we retry that later
  10006. bool Removed = RemoveDir(ApiPath(FileName));
  10007. try
  10008. {
  10009. if (!NonVisualDataModule->Busy)
  10010. {
  10011. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10012. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  10013. }
  10014. }
  10015. __finally
  10016. {
  10017. if (!Removed)
  10018. {
  10019. RemoveDir(ApiPath(FileName));
  10020. }
  10021. }
  10022. }
  10023. }
  10024. //---------------------------------------------------------------------------
  10025. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10026. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10027. {
  10028. TFileMasks::TParams MaskParams;
  10029. MaskParams.Size = Size;
  10030. MaskParams.Modification = Modification;
  10031. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10032. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10033. {
  10034. bool ImplicitMatch;
  10035. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  10036. !ImplicitMatch)
  10037. {
  10038. Color = Iter->Color;
  10039. break;
  10040. }
  10041. }
  10042. }
  10043. //---------------------------------------------------------------------------
  10044. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10045. {
  10046. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10047. if (!DirView->IsEditing())
  10048. {
  10049. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10050. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10051. // while searching
  10052. if (Key == VK_BACK)
  10053. {
  10054. if (!FIncrementalSearch.IsEmpty())
  10055. {
  10056. if (FIncrementalSearch.Length() == 1)
  10057. {
  10058. ResetIncrementalSearch();
  10059. }
  10060. else
  10061. {
  10062. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10063. IncrementalSearch(NewText, false, false);
  10064. }
  10065. Key = 0;
  10066. }
  10067. }
  10068. }
  10069. }
  10070. //---------------------------------------------------------------------------
  10071. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10072. {
  10073. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10074. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10075. {
  10076. // Filter control sequences.
  10077. // When not searching yet, prefer use of the space for toggling file selection
  10078. // (so we cannot incrementally search for a string starting with a space).
  10079. if ((Key > VK_SPACE) ||
  10080. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10081. {
  10082. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10083. Key = 0;
  10084. }
  10085. }
  10086. }
  10087. //---------------------------------------------------------------------------
  10088. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10089. {
  10090. if (!FIncrementalSearch.IsEmpty())
  10091. {
  10092. FIncrementalSearch = L"";
  10093. DirView(osCurrent)->UpdateStatusBar();
  10094. }
  10095. }
  10096. //---------------------------------------------------------------------------
  10097. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10098. {
  10099. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10100. if (Item == NULL)
  10101. {
  10102. MessageBeep(MB_ICONHAND);
  10103. }
  10104. else
  10105. {
  10106. TCustomDirView * ADirView = DirView(osCurrent);
  10107. {
  10108. TAutoNestingCounter Guard(FIncrementalSearching);
  10109. ADirView->FocusItem(Item);
  10110. if (ADirView->NortonLike == nlOff)
  10111. {
  10112. if ((ADirView->Selected != Item) ||
  10113. (ADirView->SelCount > 1))
  10114. {
  10115. ADirView->ClearSelection();
  10116. ADirView->Selected = Item;
  10117. }
  10118. }
  10119. }
  10120. FIncrementalSearch = Text;
  10121. Item->MakeVisible(false);
  10122. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10123. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10124. ADirView->UpdateStatusBar();
  10125. }
  10126. }
  10127. //---------------------------------------------------------------------------
  10128. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10129. {
  10130. int Index = Item->Index;
  10131. if (!Reverse)
  10132. {
  10133. Index++;
  10134. if (Index >= Item->Owner->Count)
  10135. {
  10136. Index = 0;
  10137. }
  10138. }
  10139. else
  10140. {
  10141. Index--;
  10142. if (Index < 0)
  10143. {
  10144. Index = Item->Owner->Count - 1;
  10145. }
  10146. }
  10147. return Item->Owner->Item[Index];
  10148. }
  10149. //---------------------------------------------------------------------------
  10150. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10151. {
  10152. TCustomDirView * ADirView = DirView(osCurrent);
  10153. if (ADirView->Items->Count == 0)
  10154. {
  10155. return NULL;
  10156. }
  10157. else
  10158. {
  10159. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10160. TListItem * Item = CurrentItem;
  10161. if (SkipCurrent)
  10162. {
  10163. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10164. }
  10165. while (true)
  10166. {
  10167. bool Matches = false;
  10168. switch (WinConfiguration->PanelSearch)
  10169. {
  10170. case isNameStartOnly:
  10171. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10172. break;
  10173. case isName:
  10174. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10175. break;
  10176. case isAll:
  10177. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10178. int Index = 0;
  10179. while ((Index < ColCount) && !Matches)
  10180. {
  10181. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10182. if (Visible)
  10183. {
  10184. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10185. }
  10186. Index++;
  10187. }
  10188. break;
  10189. }
  10190. if (Matches)
  10191. {
  10192. return Item;
  10193. }
  10194. Item = GetNextFile(Item, Reverse);
  10195. if (Item == CurrentItem)
  10196. {
  10197. return NULL;
  10198. }
  10199. }
  10200. }
  10201. }
  10202. //---------------------------------------------------------------------------
  10203. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10204. {
  10205. ResetIncrementalSearch();
  10206. }
  10207. //---------------------------------------------------------------------------
  10208. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10209. {
  10210. if (Message.CharCode == VK_TAB)
  10211. {
  10212. if (!FIncrementalSearch.IsEmpty())
  10213. {
  10214. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10215. bool Reverse = Shift.Contains(ssShift);
  10216. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10217. Message.Result = 1;
  10218. return;
  10219. }
  10220. }
  10221. else if (Message.CharCode == VK_ESCAPE)
  10222. {
  10223. if (!FIncrementalSearch.IsEmpty())
  10224. {
  10225. ResetIncrementalSearch();
  10226. Message.Result = 1;
  10227. return;
  10228. }
  10229. }
  10230. TForm::Dispatch(&Message);
  10231. }
  10232. //---------------------------------------------------------------------------
  10233. void __fastcall TCustomScpExplorerForm::Deactivate()
  10234. {
  10235. TForm::Deactivate();
  10236. // E.g. when switching to an internal editor window
  10237. ResetIncrementalSearch();
  10238. }
  10239. //---------------------------------------------------------------------------
  10240. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10241. {
  10242. // When switching to another application
  10243. ResetIncrementalSearch();
  10244. }
  10245. //---------------------------------------------------------------------------
  10246. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10247. {
  10248. ResetIncrementalSearch();
  10249. }
  10250. //---------------------------------------------------------------------------
  10251. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10252. {
  10253. if (FIncrementalSearching <= 0)
  10254. {
  10255. ResetIncrementalSearch();
  10256. }
  10257. }
  10258. //---------------------------------------------------------------------------
  10259. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10260. {
  10261. CountClicksForWindowPrint(this);
  10262. }
  10263. //---------------------------------------------------------------------------
  10264. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10265. {
  10266. CenterReconnectToolbar();
  10267. }
  10268. //---------------------------------------------------------------------------
  10269. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10270. {
  10271. if (RemoteDirView->ItemFocused != NULL)
  10272. {
  10273. RemoteDirView->ItemFocused->Selected = true;
  10274. }
  10275. }
  10276. //---------------------------------------------------------------------------
  10277. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10278. {
  10279. if (!FQueueStatusUpdating)
  10280. {
  10281. bool Refresh;
  10282. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10283. {
  10284. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10285. }
  10286. else
  10287. {
  10288. if (FQueueFileList->GetCount() > 0)
  10289. {
  10290. FQueueFileList->Clear();
  10291. Refresh = true;
  10292. }
  10293. }
  10294. int Count = FQueueFileList->GetCount();
  10295. if (QueueFileList->Items->Count != Count)
  10296. {
  10297. DebugAssert(Refresh);
  10298. QueueFileList->Items->Count = Count;
  10299. }
  10300. if (Refresh)
  10301. {
  10302. QueueFileList->Invalidate();
  10303. }
  10304. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10305. }
  10306. }
  10307. //---------------------------------------------------------------------------
  10308. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10309. {
  10310. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10311. }
  10312. //---------------------------------------------------------------------------
  10313. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10314. {
  10315. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10316. // See TSynchronizeChecklistDialog::UpdateTimer
  10317. if (QueueFileList->Items->Count > 0)
  10318. {
  10319. QueueFileList->Items->Item[0]->MakeVisible(false);
  10320. }
  10321. UpdateQueueFileList();
  10322. }
  10323. //---------------------------------------------------------------------------
  10324. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10325. {
  10326. Active = QueueView3->Focused() || QueueFileList->Focused();
  10327. }
  10328. //---------------------------------------------------------------------------
  10329. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10330. {
  10331. QueueLabelUpdateStatus();
  10332. }
  10333. //---------------------------------------------------------------------------
  10334. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10335. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10336. {
  10337. int State = FQueueFileList->GetState(Item->Index);
  10338. if (State == qfsProcessed)
  10339. {
  10340. Sender->Canvas->Font->Color = clGrayText;
  10341. }
  10342. }
  10343. //---------------------------------------------------------------------------
  10344. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10345. {
  10346. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10347. QueueFileList->Column[0]->Width =
  10348. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10349. }
  10350. //---------------------------------------------------------------------------
  10351. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10352. {
  10353. QueueFileListColumnAutoSize();
  10354. }
  10355. //---------------------------------------------------------------------------
  10356. void __fastcall TCustomScpExplorerForm::CloseApp()
  10357. {
  10358. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10359. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10360. // So we clear the flag here.
  10361. DebugAssert(NonVisualDataModule->Busy);
  10362. NonVisualDataModule->EndBusy();
  10363. try
  10364. {
  10365. Close();
  10366. }
  10367. __finally
  10368. {
  10369. NonVisualDataModule->StartBusy();
  10370. }
  10371. }
  10372. //---------------------------------------------------------------------------
  10373. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10374. {
  10375. return (Terminal != NULL) && Terminal->Active;
  10376. }
  10377. //---------------------------------------------------------------------------
  10378. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10379. {
  10380. return IsActiveTerminal(Terminal);
  10381. }