CustomScpExplorer.cpp 360 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963
  1. // TODO_OTHER_LOCAL
  2. //---------------------------------------------------------------------------
  3. #define NO_WIN32_LEAN_AND_MEAN
  4. #include <vcl.h>
  5. #pragma hdrstop
  6. #include <Common.h>
  7. #include "CustomScpExplorer.h"
  8. #include <Bookmarks.h>
  9. #include <Interface.h>
  10. #include <Exceptions.h>
  11. #include <CoreMain.h>
  12. #include <FileSystems.h>
  13. #include <TextsCore.h>
  14. #include <TextsWin.h>
  15. #include <HelpWin.h>
  16. #include <VCLCommon.h>
  17. #include <Progress.h>
  18. #include <SynchronizeProgress.h>
  19. #include <DragExt.h>
  20. #include <WinApi.h>
  21. #include "GUITools.h"
  22. #include "NonVisual.h"
  23. #include "Glyphs.h"
  24. #include "Tools.h"
  25. #include "WinConfiguration.h"
  26. #include "TerminalManager.h"
  27. #include "EditorManager.h"
  28. #include "ProgParams.h"
  29. #include "Setup.h"
  30. #include <Consts.hpp>
  31. #include <DateUtils.hpp>
  32. #include <TB2Common.hpp>
  33. #include <DirectoryMonitor.hpp>
  34. #include <System.IOUtils.hpp>
  35. //---------------------------------------------------------------------------
  36. #pragma package(smart_init)
  37. #pragma link "CustomDirView"
  38. #pragma link "CustomUnixDirView"
  39. #pragma link "IEListView"
  40. #pragma link "NortonLikeListView"
  41. #pragma link "UnixDirView"
  42. #pragma link "CustomDriveView"
  43. #pragma link "UnixDriveView"
  44. #pragma link "CustomDriveView"
  45. #pragma link "TB2Dock"
  46. #pragma link "TBXStatusBars"
  47. #pragma link "TB2Item"
  48. #pragma link "TB2Toolbar"
  49. #pragma link "ThemePageControl"
  50. #pragma link "PathLabel"
  51. #pragma resource "*.dfm"
  52. //---------------------------------------------------------------------------
  53. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  54. static const int SessionPanelCount = 4;
  55. //---------------------------------------------------------------------------
  56. class TMutexGuard
  57. {
  58. public:
  59. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  60. int Timeout = 5000)
  61. {
  62. FMutex = NULL;
  63. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  64. if (WaitResult == WAIT_TIMEOUT)
  65. {
  66. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  67. }
  68. else
  69. {
  70. FMutex = AMutex;
  71. }
  72. }
  73. ~TMutexGuard()
  74. {
  75. if (FMutex != NULL)
  76. {
  77. ReleaseMutex(FMutex);
  78. }
  79. }
  80. private:
  81. HANDLE FMutex;
  82. };
  83. //---------------------------------------------------------------------------
  84. class TWindowLock
  85. {
  86. public:
  87. TWindowLock(TCustomScpExplorerForm * Form) :
  88. FForm(Form)
  89. {
  90. FForm->LockWindow();
  91. }
  92. ~TWindowLock()
  93. {
  94. FForm->UnlockWindow();
  95. }
  96. private:
  97. TCustomScpExplorerForm * FForm;
  98. };
  99. //---------------------------------------------------------------------------
  100. class TAutoBatch
  101. {
  102. public:
  103. TAutoBatch(TCustomScpExplorerForm * Form) :
  104. FForm(Form)
  105. {
  106. FForm->BatchStart(FBatchStorage);
  107. }
  108. ~TAutoBatch()
  109. {
  110. FForm->BatchEnd(FBatchStorage);
  111. }
  112. private:
  113. TCustomScpExplorerForm * FForm;
  114. void * FBatchStorage;
  115. };
  116. //---------------------------------------------------------------------------
  117. struct TTransferOperationParam
  118. {
  119. TTransferOperationParam();
  120. UnicodeString TargetDirectory;
  121. bool Temp;
  122. bool DragDrop;
  123. int Options;
  124. TAutoSwitch Queue;
  125. };
  126. //---------------------------------------------------------------------------
  127. TTransferOperationParam::TTransferOperationParam()
  128. {
  129. Temp = false;
  130. DragDrop = false;
  131. Options = 0;
  132. Queue = asAuto;
  133. }
  134. //---------------------------------------------------------------------------
  135. class TTransferPresetNoteData : public TObject
  136. {
  137. public:
  138. UnicodeString Message;
  139. };
  140. //---------------------------------------------------------------------------
  141. class TTerminalNoteData : public TObject
  142. {
  143. public:
  144. TManagedTerminal * Terminal;
  145. };
  146. //---------------------------------------------------------------------------
  147. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  148. FFormRestored(false),
  149. TForm(Owner)
  150. {
  151. FInvalid = false;
  152. FCurrentSide = osRemote;
  153. FEverShown = false;
  154. FDocks = new TList();
  155. InitControls();
  156. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  157. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  158. NonVisualDataModule->ScpExplorer = this;
  159. RestoreParams();
  160. ConfigurationChanged();
  161. RemoteDirView->Invalidate();
  162. FAutoOperation = false;
  163. FOnFileOperationFinished = NULL;
  164. FForceExecution = false;
  165. FIgnoreNextDialogChar = 0;
  166. FErrorList = NULL;
  167. FSynchronizeProgressForm = NULL;
  168. FProgressForm = NULL;
  169. FRefreshLocalDirectory = false;
  170. FRefreshRemoteDirectory = false;
  171. FDDExtMapFile = NULL;
  172. // CreateMutexW keeps failing with ERROR_NOACCESS
  173. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  174. DebugAssert(FDDExtMutex != NULL);
  175. FDDTargetControl = NULL;
  176. FDelayedDeletionTimer = NULL;
  177. FDelayedDeletionList = new TStringList();
  178. FDDFileList = NULL;
  179. FPendingTempSpaceWarn = false;
  180. FCapturedLog = NULL;
  181. FDragDropOperation = false;
  182. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  183. FAllowTransferPresetAutoSelect = true;
  184. FCopyParamDefault = L"";
  185. FSynchronizeController = NULL;
  186. FPendingQueueActionItem = NULL;
  187. FLockLevel = 0;
  188. FLockSuspendLevel = 0;
  189. FDisabledOnLockSuspend = false;
  190. FAlternativeDelete = false;
  191. FTrayIcon = new ::TTrayIcon(0);
  192. FTrayIcon->OnClick = TrayIconClick;
  193. FMaxQueueLength = 0;
  194. FLastContextPopupScreenPoint = TPoint(-1, -1);
  195. FTransferResumeList = NULL;
  196. FMoveToQueue = false;
  197. FStandaloneEditing = false;
  198. FOnFeedSynchronizeError = NULL;
  199. FNeedSession = false;
  200. FDoNotIdleCurrentTerminal = 0;
  201. FIncrementalSearching = 0;
  202. FIncrementalSearchHaveNext = false;
  203. FQueueFileList.reset(new TQueueFileList());
  204. FProgressSide = osCurrent;
  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. CreateHiddenWindow();
  262. StartUpdates();
  263. }
  264. //---------------------------------------------------------------------------
  265. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  266. {
  267. FInvalid = true;
  268. // this has to be one of the very first things to do
  269. StopUpdateThread();
  270. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  271. TTerminalManager::Instance()->ScpExplorer = NULL;
  272. delete FCustomCommandLocalFileList;
  273. delete FCustomCommandRemoteFileList;
  274. delete FCustomCommandMenu;
  275. delete FTrayIcon;
  276. FTrayIcon = NULL;
  277. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  278. delete FEditorManager;
  279. ForceCloseLocalEditors();
  280. delete FLocalEditors;
  281. HideFileFindDialog();
  282. if (FDelayedDeletionTimer)
  283. {
  284. DoDelayedDeletion(NULL);
  285. SAFE_DESTROY(FDelayedDeletionTimer);
  286. }
  287. SAFE_DESTROY(FDelayedDeletionList);
  288. // sometimes we do not get DDEnd so the list is not released
  289. SAFE_DESTROY(FDDFileList);
  290. DebugAssert(FSynchronizeController == NULL);
  291. CloseHandle(FDDExtMutex);
  292. FDDExtMutex = NULL;
  293. FreeLibrary(FOle32Library);
  294. FOle32Library = NULL;
  295. FDragMoveCursor = NULL;
  296. DebugAssert(!FErrorList);
  297. if (FEverShown)
  298. {
  299. // when window is never shown (like when running command-line operation),
  300. // particularly window site is not restored correctly (BoundsRect value set
  301. // in RestoreForm gets lost during handle allocation), so we do not want
  302. // it to be stored
  303. StoreParams();
  304. }
  305. Terminal = NULL;
  306. Queue = NULL;
  307. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  308. NonVisualDataModule->ScpExplorer = NULL;
  309. delete FQueueController;
  310. FQueueController = NULL;
  311. delete FQueueStatusSection;
  312. FQueueStatusSection = NULL;
  313. delete FQueueStatus;
  314. FQueueStatus = NULL;
  315. delete FUserActionTimer;
  316. FUserActionTimer = NULL;
  317. delete FNoteTimer;
  318. delete FNotes;
  319. delete FNoteData;
  320. SAFE_DESTROY(FDocks);
  321. SessionsPageControl->Images = NULL;
  322. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  323. SAFE_DESTROY(FSessionColors);
  324. SAFE_DESTROY(FSessionsDragDropFilesEx);
  325. SAFE_DESTROY(FHistoryMenu[0][0]);
  326. SAFE_DESTROY(FHistoryMenu[0][1]);
  327. SAFE_DESTROY(FHistoryMenu[1][0]);
  328. SAFE_DESTROY(FHistoryMenu[1][1]);
  329. if (FHiddenWindow != NULL)
  330. {
  331. DestroyWindow(FHiddenWindow);
  332. FHiddenWindow = NULL;
  333. }
  334. }
  335. //---------------------------------------------------------------------------
  336. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  337. {
  338. std::unique_ptr<TSessionData> Data;
  339. if (!Session.IsEmpty())
  340. {
  341. bool DefaultsOnly;
  342. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  343. }
  344. TTerminalManager * Manager = TTerminalManager::Instance();
  345. for (int Index = 0; Index < Manager->Count; Index++)
  346. {
  347. TTerminal * Terminal = Manager->Terminals[Index];
  348. if (Session.IsEmpty() ||
  349. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  350. {
  351. if (Path.IsEmpty())
  352. {
  353. Terminal->ClearCaches();
  354. }
  355. else
  356. {
  357. Terminal->DirectoryModified(Path, true);
  358. }
  359. }
  360. }
  361. // We should flag a pending refresh for the background terminals or busy foreground terminals
  362. if (HasActiveTerminal() &&
  363. CanCommandLineFromAnotherInstance() &&
  364. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  365. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  366. {
  367. Terminal->ReloadDirectory();
  368. }
  369. }
  370. //---------------------------------------------------------------------------
  371. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  372. {
  373. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  374. size_t MessageSize = sizeof(TCopyDataMessage);
  375. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  376. if (Result)
  377. {
  378. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  379. Result = (Message.Version == TCopyDataMessage::Version1);
  380. if (Result)
  381. {
  382. switch (Message.Command)
  383. {
  384. case TCopyDataMessage::CommandCanCommandLine:
  385. Result = CanCommandLineFromAnotherInstance();
  386. break;
  387. case TCopyDataMessage::CommandCommandLine:
  388. {
  389. UnicodeString CommandLine(Message.CommandLine);
  390. Result = CommandLineFromAnotherInstance(CommandLine);
  391. }
  392. break;
  393. case TCopyDataMessage::RefreshPanel:
  394. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  395. break;
  396. case TCopyDataMessage::MainWindowCheck:
  397. Result = true;
  398. break;
  399. default:
  400. Result = false;
  401. break;
  402. }
  403. }
  404. }
  405. Message.Result = Result ? 1 : 0;
  406. }
  407. //---------------------------------------------------------------------------
  408. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  409. {
  410. WNDCLASS WindowClass = {0};
  411. WindowClass.lpfnWndProc = DefWindowProc;
  412. WindowClass.hInstance = HInstance;
  413. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  414. FHiddenWindow = NULL;
  415. if (RegisterClass(&WindowClass))
  416. {
  417. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  418. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  419. }
  420. }
  421. //---------------------------------------------------------------------------
  422. bool __fastcall TCustomScpExplorerForm::CanConsole()
  423. {
  424. return
  425. HasActiveTerminal() &&
  426. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  427. }
  428. //---------------------------------------------------------------------------
  429. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  430. {
  431. bool Result = Visible && !NonVisualDataModule->Busy;
  432. return Result;
  433. }
  434. //---------------------------------------------------------------------------
  435. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  436. const UnicodeString & CommandLine)
  437. {
  438. TProgramParams Params(CommandLine);
  439. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  440. if (Result)
  441. {
  442. NonVisualDataModule->StartBusy();
  443. try
  444. {
  445. // this action is initiated from another process,
  446. // so it's likely that our window is not visible,
  447. // and user won't see what is going on
  448. Application->BringToFront();
  449. // reload sessions as we may be asked to open a session
  450. // just stored by another instance
  451. StoredSessions->Reload();
  452. UnicodeString SessionName = Params.Param[1];
  453. std::unique_ptr<TObjectList> DataList(new TObjectList());
  454. UnicodeString DownloadFile; // unused
  455. try
  456. {
  457. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  458. }
  459. catch (EAbort &)
  460. {
  461. // Happens when opening session in PuTTY and in other situations,
  462. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  463. // to process the command-line on its own (or to pass it to yet another instance)
  464. }
  465. if (DataList->Count > 0)
  466. {
  467. TTerminalManager * Manager = TTerminalManager::Instance();
  468. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  469. }
  470. }
  471. __finally
  472. {
  473. NonVisualDataModule->EndBusy();
  474. }
  475. }
  476. return Result;
  477. }
  478. //---------------------------------------------------------------------------
  479. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  480. {
  481. if (FTerminal != value)
  482. {
  483. TerminalChanging();
  484. DoSetTerminal(value, false);
  485. }
  486. }
  487. //---------------------------------------------------------------------------
  488. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  489. {
  490. FTerminal = value;
  491. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  492. FAllowTransferPresetAutoSelect = false;
  493. try
  494. {
  495. TerminalChanged(Replace);
  496. }
  497. __finally
  498. {
  499. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  500. }
  501. if (Terminal != NULL)
  502. {
  503. TransferPresetAutoSelect();
  504. }
  505. }
  506. //---------------------------------------------------------------------------
  507. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  508. {
  509. DoSetTerminal(value, true);
  510. }
  511. //---------------------------------------------------------------------------
  512. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  513. {
  514. if (FTerminal != NULL)
  515. {
  516. UpdateTerminal(Terminal);
  517. }
  518. }
  519. //---------------------------------------------------------------------------
  520. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  521. {
  522. if (Terminal != NULL)
  523. {
  524. UpdateSessionColor((TColor)Terminal->StateData->Color);
  525. }
  526. DoTerminalListChanged();
  527. DebugAssert(!IsLocalBrowserMode()); // TODO
  528. if (Replaced)
  529. {
  530. RemoteDirView->ReplaceTerminal(Terminal);
  531. }
  532. else
  533. {
  534. RemoteDirView->Terminal = Terminal;
  535. }
  536. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  537. if (Terminal != NULL)
  538. {
  539. if (Terminal->Active)
  540. {
  541. Terminal->RefreshDirectory();
  542. }
  543. if (WinConfiguration->PreservePanelState)
  544. {
  545. if (Terminal->RemoteExplorerState != NULL)
  546. {
  547. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  548. }
  549. else
  550. {
  551. DirView(osRemote)->ClearState();
  552. }
  553. }
  554. if (!Replaced && Terminal->Active)
  555. {
  556. InitStatusBar();
  557. }
  558. }
  559. UpdateTransferList();
  560. // Update panels Enable state before refreshing the labels
  561. UpdateControls();
  562. }
  563. //---------------------------------------------------------------------------
  564. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  565. {
  566. if (Queue != value)
  567. {
  568. if (FQueue != NULL)
  569. {
  570. FQueue->OnListUpdate = NULL;
  571. FQueue->OnQueueItemUpdate = NULL;
  572. }
  573. FQueue = value;
  574. if (FQueue != NULL)
  575. {
  576. DebugAssert(FQueue->OnListUpdate == NULL);
  577. FQueue->OnListUpdate = QueueListUpdate;
  578. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  579. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  580. }
  581. QueueChanged();
  582. }
  583. }
  584. //---------------------------------------------------------------------------
  585. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  586. TListItem * Item)
  587. {
  588. if (FQueueActedItem == Item)
  589. {
  590. FQueueActedItem = NULL;
  591. if ((QueueView3->PopupMenu != NULL) &&
  592. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  593. {
  594. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  595. ReleaseCapture();
  596. }
  597. }
  598. if (Item->Data == FPendingQueueActionItem)
  599. {
  600. FPendingQueueActionItem = NULL;
  601. }
  602. }
  603. //---------------------------------------------------------------------------
  604. bool TCustomScpExplorerForm::IsAnythingQueued()
  605. {
  606. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  607. }
  608. //---------------------------------------------------------------------------
  609. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  610. {
  611. {
  612. TGuard Guard(FQueueStatusSection);
  613. FQueueStatusInvalidated = false;
  614. if (FQueue != NULL)
  615. {
  616. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  617. }
  618. }
  619. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  620. {
  621. FMaxQueueLength = FQueueStatus->Count;
  622. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  623. }
  624. {
  625. TAutoFlag Flag(FQueueStatusUpdating);
  626. FQueueController->UpdateQueueStatus(FQueueStatus);
  627. }
  628. UpdateQueueFileList();
  629. SetQueueProgress();
  630. UpdateQueueView();
  631. bool IsEmpty = !IsAnythingQueued();
  632. if (IsEmpty && (Terminal != NULL))
  633. {
  634. TOnceDoneOperation OnceDoneOperation =
  635. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  636. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  637. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  638. {
  639. FQueue->Enabled = false;
  640. }
  641. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  642. {
  643. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  644. }
  645. }
  646. }
  647. //---------------------------------------------------------------------------
  648. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  649. {
  650. UnicodeString Result;
  651. if (FQueueStatus != NULL)
  652. {
  653. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  654. {
  655. TFileOperationProgressType * ProgressData =
  656. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  657. if ((ProgressData != NULL) && ProgressData->InProgress)
  658. {
  659. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  660. }
  661. }
  662. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  663. {
  664. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  665. }
  666. }
  667. return Result;
  668. }
  669. //---------------------------------------------------------------------------
  670. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  671. {
  672. ComponentVisible[fcQueueView] =
  673. (WinConfiguration->QueueView.Show == qvShow) ||
  674. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  675. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  676. }
  677. //---------------------------------------------------------------------------
  678. void __fastcall TCustomScpExplorerForm::QueueChanged()
  679. {
  680. if (FQueueStatus != NULL)
  681. {
  682. // UpdateFileList implementation relies on the status being recreated when session changes
  683. delete FQueueStatus;
  684. FQueueStatus = NULL;
  685. }
  686. UpdateQueueStatus(true);
  687. }
  688. //---------------------------------------------------------------------------
  689. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  690. {
  691. if (FQueue == Queue)
  692. {
  693. FQueueStatusInvalidated = true;
  694. }
  695. }
  696. //---------------------------------------------------------------------------
  697. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  698. TQueueItem * Item)
  699. {
  700. if (FQueue == Queue)
  701. {
  702. TGuard Guard(FQueueStatusSection);
  703. // this may be running in parallel with QueueChanged
  704. if (FQueueStatus != NULL)
  705. {
  706. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  707. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  708. {
  709. FRefreshLocalDirectory = (QueueItem == NULL) ||
  710. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  711. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  712. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  713. }
  714. if (QueueItem != NULL)
  715. {
  716. QueueItem->UserData = (void*)true;
  717. FQueueItemInvalidated = true;
  718. }
  719. }
  720. }
  721. }
  722. //---------------------------------------------------------------------------
  723. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  724. {
  725. // during standalone editing, we have no way to see/control queue,
  726. // so we have to always popup prompts automatically
  727. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  728. }
  729. //---------------------------------------------------------------------------
  730. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  731. {
  732. if (FQueueStatus != NULL)
  733. {
  734. bool QueueAutoPopup = IsQueueAutoPopup();
  735. bool NeedRefresh = FQueueController->NeedRefresh();
  736. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  737. FQueueItemInvalidated = false;
  738. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  739. bool Updated = false;
  740. TQueueItemProxy * QueueItem;
  741. bool WasUserAction;
  742. for (int Index = 0; Index < Limit; Index++)
  743. {
  744. bool Update = false;
  745. QueueItem = FQueueStatus->Items[Index];
  746. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  747. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  748. (FPendingQueueActionItem == NULL))
  749. {
  750. FPendingQueueActionItem = QueueItem;
  751. FUserActionTimer->Enabled = true;
  752. }
  753. if ((bool)QueueItem->UserData)
  754. {
  755. QueueItem->UserData = (void*)false;
  756. QueueItem->Update();
  757. Updated = true;
  758. Update = true;
  759. }
  760. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  761. {
  762. Update = true;
  763. }
  764. if (Update)
  765. {
  766. FQueueController->RefreshQueueItem(QueueItem);
  767. }
  768. }
  769. if (Updated)
  770. {
  771. NonVisualDataModule->UpdateNonVisibleActions();
  772. SetQueueProgress();
  773. UpdateQueueFileList();
  774. }
  775. }
  776. }
  777. //---------------------------------------------------------------------------
  778. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  779. {
  780. if (FTaskbarList != NULL)
  781. {
  782. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  783. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  784. }
  785. }
  786. //---------------------------------------------------------------------------
  787. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  788. {
  789. if (Progress >= 0)
  790. {
  791. if (FTaskbarList != NULL)
  792. {
  793. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  794. }
  795. }
  796. else
  797. {
  798. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  799. }
  800. }
  801. //---------------------------------------------------------------------------
  802. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  803. {
  804. int OverallProgress;
  805. // FProgressForm is null when this is called from SetQueueProgress
  806. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  807. {
  808. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  809. }
  810. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  811. {
  812. OverallProgress = ProgressData->OverallProgress();
  813. }
  814. else
  815. {
  816. OverallProgress = -1;
  817. }
  818. SetTaskbarListProgressValue(OverallProgress);
  819. }
  820. //---------------------------------------------------------------------------
  821. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  822. {
  823. TTerminalManager::Instance()->QueueStatusUpdated();
  824. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  825. {
  826. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  827. {
  828. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  829. {
  830. TFileOperationProgressType * ProgressData = NULL;
  831. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  832. {
  833. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  834. }
  835. if ((ProgressData != NULL) &&
  836. ProgressData->InProgress)
  837. {
  838. SetTaskbarListProgressValue(ProgressData);
  839. }
  840. else
  841. {
  842. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  843. }
  844. }
  845. else
  846. {
  847. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  848. }
  849. }
  850. else
  851. {
  852. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  853. }
  854. }
  855. UpdateQueueLabel();
  856. }
  857. //---------------------------------------------------------------------------
  858. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  859. {
  860. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  861. if (FQueueStatus != NULL)
  862. {
  863. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  864. if (ActiveAndPendingPrimaryCount > 0)
  865. {
  866. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  867. }
  868. }
  869. QueueLabel->Caption = Caption;
  870. }
  871. //---------------------------------------------------------------------------
  872. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  873. {
  874. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  875. static_cast<TComponent*>(GetComponent(fcTransferList)));
  876. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  877. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  878. TransferList->Strings->BeginUpdate();
  879. try
  880. {
  881. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  882. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  883. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  884. if (FTransferDropDownHint.IsEmpty())
  885. {
  886. FTransferDropDownHint = TransferDropDown->Hint;
  887. }
  888. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  889. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  890. TransferDropDown->Text = StripHotkey(Name);
  891. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  892. (FTransferDropDownHint, StripHotkey(Name),
  893. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  894. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  895. // update the label, otherwise when it is updated only on the first draw
  896. // of the list, it is drawn "bold" for some reason
  897. FTransferListHoverIndex = TransferList->ItemIndex;
  898. UpdateTransferLabel();
  899. }
  900. __finally
  901. {
  902. TransferList->Strings->EndUpdate();
  903. }
  904. }
  905. //---------------------------------------------------------------------------
  906. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  907. {
  908. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  909. DebugAssert(Toolbar != NULL);
  910. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  911. }
  912. //---------------------------------------------------------------------------
  913. void __fastcall TCustomScpExplorerForm::UpdateActions()
  914. {
  915. TForm::UpdateActions();
  916. if (ComponentVisible[fcCustomCommandsBand])
  917. {
  918. UpdateCustomCommandsToolbar();
  919. }
  920. }
  921. //---------------------------------------------------------------------------
  922. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  923. {
  924. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  925. }
  926. //---------------------------------------------------------------------------
  927. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  928. {
  929. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  930. {
  931. DirView->RowSelect = WinConfiguration->FullRowSelect;
  932. // selection is not redrawn automatically when RowSelect changes
  933. DirView->Invalidate();
  934. }
  935. }
  936. //---------------------------------------------------------------------------
  937. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  938. {
  939. Color = GetBtnFaceColor();
  940. DebugAssert(Configuration && RemoteDirView);
  941. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  942. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  943. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  944. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  945. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  946. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  947. UpdateRowSelect(RemoteDirView);
  948. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  949. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  950. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  951. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  952. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  953. UpdateSessionsPageControlHeight();
  954. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  955. UpdateToolbarDisplayMode();
  956. UpdateTransferList();
  957. if (Terminal != NULL)
  958. {
  959. TransferPresetAutoSelect();
  960. }
  961. UpdateQueueView();
  962. UpdateControls();
  963. // this can be called even before constuctor finishes.
  964. if (FEditorManager != NULL)
  965. {
  966. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  967. }
  968. // this can be called even before constuctor finishes.
  969. if (FLocalEditors != NULL)
  970. {
  971. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  972. {
  973. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  974. }
  975. }
  976. if (ComponentVisible[fcCustomCommandsBand])
  977. {
  978. UpdateCustomCommandsToolbar();
  979. }
  980. // show only when keeping queue items forever,
  981. // otherwise, its enough to have in in the context menu
  982. QueueDeleteAllDoneQueueToolbarItem->Visible =
  983. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  984. if (FFileColorsCurrent != WinConfiguration->FileColors)
  985. {
  986. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  987. FFileColorsCurrent = WinConfiguration->FileColors;
  988. FileColorsChanged();
  989. }
  990. }
  991. //---------------------------------------------------------------------------
  992. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  993. {
  994. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  995. DirView->Invalidate();
  996. }
  997. //---------------------------------------------------------------------------
  998. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  999. {
  1000. DoFileColorsChanged(RemoteDirView);
  1001. }
  1002. //---------------------------------------------------------------------------
  1003. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  1004. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  1005. void * /*Arg*/)
  1006. {
  1007. if (Token != NULL)
  1008. {
  1009. TForm * Editor = dynamic_cast<TForm*>(Token);
  1010. DebugAssert(Editor != NULL);
  1011. ReconfigureEditorForm(Editor);
  1012. }
  1013. }
  1014. //---------------------------------------------------------------------------
  1015. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1016. {
  1017. WinConfiguration->DDTransferConfirmation = asOn;
  1018. }
  1019. //---------------------------------------------------------------------------
  1020. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1021. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1022. {
  1023. // noop
  1024. }
  1025. //---------------------------------------------------------------------------
  1026. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1027. TTransferDirection Direction, TTransferType Type, bool Temp,
  1028. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1029. bool Confirm, bool DragDrop, int Options)
  1030. {
  1031. bool Result = true;
  1032. DebugAssert(HasActiveTerminal());
  1033. // these parameters are known in advance
  1034. int Params =
  1035. FLAGMASK(Type == ttMove, cpDelete);
  1036. bool ToTemp = (Temp && (Direction == tdToLocal));
  1037. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1038. {
  1039. bool DisableNewerOnly =
  1040. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1041. ToTemp;
  1042. Options |=
  1043. FLAGMASK(ToTemp, coTemp) |
  1044. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1045. coDoNotShowAgain;
  1046. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1047. int CopyParamAttrs = (Direction == tdToRemote ?
  1048. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1049. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1050. int OutputOptions =
  1051. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1052. cooDoNotShowAgain);
  1053. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1054. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1055. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1056. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1057. if (Result)
  1058. {
  1059. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1060. {
  1061. if (DragDrop)
  1062. {
  1063. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1064. {
  1065. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1066. NULL, 0, EnableDDTransferConfirmation, NULL);
  1067. }
  1068. WinConfiguration->DDTransferConfirmation = asOff;
  1069. }
  1070. else
  1071. {
  1072. WinConfiguration->ConfirmTransferring = false;
  1073. }
  1074. }
  1075. else
  1076. {
  1077. // User explicitly unchecked "do not show again",
  1078. // so show him the dialog the next time
  1079. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1080. {
  1081. WinConfiguration->DDTransferConfirmation = asOn;
  1082. }
  1083. }
  1084. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1085. }
  1086. }
  1087. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1088. {
  1089. Configuration->Usage->Inc(L"TransfersOnBackground");
  1090. // these parameter are known only after transfer dialog
  1091. Params |=
  1092. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1093. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1094. Result = false;
  1095. ClearTransferSourceSelection(Direction);
  1096. }
  1097. return Result;
  1098. }
  1099. //---------------------------------------------------------------------------
  1100. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1101. {
  1102. if (FOnFileOperationFinished != NULL)
  1103. {
  1104. FOnFileOperationFinished(UnicodeString(), true);
  1105. }
  1106. else
  1107. {
  1108. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1109. if (HasDirView[Side])
  1110. {
  1111. DirView(Side)->SelectAll(smNone);
  1112. }
  1113. }
  1114. }
  1115. //---------------------------------------------------------------------------
  1116. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1117. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1118. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1119. int Params)
  1120. {
  1121. DebugAssert(Queue != NULL);
  1122. bool SingleFile = false;
  1123. if (FileList->Count == 1)
  1124. {
  1125. if (Direction == tdToRemote)
  1126. {
  1127. UnicodeString FileName = FileList->Strings[0];
  1128. SingleFile = FileExists(ApiPath(FileName));
  1129. }
  1130. else
  1131. {
  1132. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1133. SingleFile = !File->IsDirectory;
  1134. }
  1135. }
  1136. TQueueItem * QueueItem;
  1137. if (Direction == tdToRemote)
  1138. {
  1139. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1140. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1141. }
  1142. else
  1143. {
  1144. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1145. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1146. }
  1147. AddQueueItem(Queue, QueueItem, Terminal);
  1148. }
  1149. //---------------------------------------------------------------------------
  1150. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1151. {
  1152. if (Queue->IsEmpty)
  1153. {
  1154. Terminal->QueueOperationStart = Now();
  1155. }
  1156. Queue->AddItem(QueueItem);
  1157. }
  1158. //---------------------------------------------------------------------------
  1159. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1160. {
  1161. }
  1162. //---------------------------------------------------------------------------
  1163. void __fastcall TCustomScpExplorerForm::InitControls()
  1164. {
  1165. DebugAssert(FDocks != NULL);
  1166. for (int Index = 0; Index < ComponentCount; Index++)
  1167. {
  1168. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1169. if ((Dock != NULL) && (Dock->Tag == 0))
  1170. {
  1171. FDocks->Add(Dock);
  1172. }
  1173. }
  1174. CollectItemsWithTextDisplayMode(this);
  1175. }
  1176. //---------------------------------------------------------------------------
  1177. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1178. {
  1179. ConfigurationChanged();
  1180. QueuePanel->Height =
  1181. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1182. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1183. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1184. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1185. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1186. QueueFileList->Height =
  1187. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1188. if (QueueFileList->Visible)
  1189. {
  1190. AdjustQueueLayout();
  1191. }
  1192. UpdateCustomCommandsToolbar();
  1193. }
  1194. //---------------------------------------------------------------------------
  1195. void __fastcall TCustomScpExplorerForm::StoreParams()
  1196. {
  1197. int APixelsPerInch = GetControlPixelsPerInch(this);
  1198. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1199. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1200. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1201. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1202. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1203. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1204. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1205. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1206. }
  1207. //---------------------------------------------------------------------------
  1208. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1209. {
  1210. if (!FFormRestored)
  1211. {
  1212. FFormRestored = true;
  1213. RestoreFormParams();
  1214. }
  1215. TForm::CreateParams(Params);
  1216. }
  1217. //---------------------------------------------------------------------------
  1218. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1219. {
  1220. DebugAssert(FDocks != NULL);
  1221. for (int Index = 0; Index < FDocks->Count; Index++)
  1222. {
  1223. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1224. }
  1225. }
  1226. //---------------------------------------------------------------------------
  1227. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1228. {
  1229. SetDockAllowDrag(true);
  1230. while (!ButtonsStr.IsEmpty())
  1231. {
  1232. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1233. UnicodeString Name = CutToChar(S, L'=', true);
  1234. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1235. {
  1236. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1237. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1238. {
  1239. while (!S.IsEmpty())
  1240. {
  1241. UnicodeString S2 = CutToChar(S, L',', true);
  1242. UnicodeString Name = CutToChar(S2, L':', true);
  1243. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1244. {
  1245. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1246. if (SameText(GetToolbarItemName(Item), Name))
  1247. {
  1248. // forward compatibility
  1249. UnicodeString S3 = CutToChar(S2, L':', true);
  1250. bool Visible = StrToIntDef(S3, 0);
  1251. Item->Visible = Visible;
  1252. }
  1253. }
  1254. }
  1255. }
  1256. }
  1257. }
  1258. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1259. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1260. }
  1261. //---------------------------------------------------------------------------
  1262. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1263. {
  1264. UnicodeString Result;
  1265. SetDockAllowDrag(true);
  1266. Result = ::GetToolbarsLayoutStr(this);
  1267. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1268. return Result;
  1269. }
  1270. //---------------------------------------------------------------------------
  1271. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1272. {
  1273. UnicodeString Result;
  1274. if (Item->Action != NULL)
  1275. {
  1276. Result = Item->Action->Name;
  1277. Result = RemoveSuffix(Result, L"Action", true);
  1278. }
  1279. else
  1280. {
  1281. Result = Item->Name;
  1282. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1283. Result = RemoveSuffix(Result, L"Item", true);
  1284. }
  1285. return Result;
  1286. }
  1287. //---------------------------------------------------------------------------
  1288. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1289. {
  1290. UnicodeString Result;
  1291. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1292. {
  1293. UnicodeString ToolbarStr;
  1294. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1295. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1296. {
  1297. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1298. {
  1299. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1300. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1301. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1302. // and save the changes here only.
  1303. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1304. {
  1305. UnicodeString Name = GetToolbarItemName(Item);
  1306. DebugAssert(Name.Pos(L"TBX") == 0);
  1307. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1308. }
  1309. }
  1310. }
  1311. if (!ToolbarStr.IsEmpty())
  1312. {
  1313. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1314. }
  1315. }
  1316. return Result;
  1317. }
  1318. //---------------------------------------------------------------------------
  1319. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1320. {
  1321. DebugAssert(FProgressForm == NULL);
  1322. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1323. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1324. FProgressForm->DeleteLocalToRecycleBin =
  1325. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1326. FProgressForm->DeleteRemoteToRecycleBin =
  1327. (Terminal != NULL) &&
  1328. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1329. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1330. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1331. LockWindow();
  1332. // Actually, do not know what hides the progress once the operation finishes
  1333. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1334. SetTaskbarListProgressState(TBPF_NORMAL);
  1335. }
  1336. //---------------------------------------------------------------------------
  1337. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1338. {
  1339. UnlockWindow();
  1340. SAFE_DESTROY(FProgressForm);
  1341. SetQueueProgress();
  1342. }
  1343. //---------------------------------------------------------------------------
  1344. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1345. TFileOperationProgressType & ProgressData)
  1346. {
  1347. // Download to temporary local directory
  1348. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1349. {
  1350. bool Continue = true;
  1351. FPendingTempSpaceWarn = false;
  1352. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1353. if (!Continue)
  1354. {
  1355. Abort();
  1356. }
  1357. }
  1358. // operation is being executed and we still didn't show up progress form
  1359. if (ProgressData.InProgress && !FProgressForm)
  1360. {
  1361. CreateProgressForm(NULL);
  1362. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1363. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1364. }
  1365. // operation is finished (or terminated), so we hide progress form
  1366. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1367. {
  1368. DestroyProgressForm();
  1369. if (ProgressData.Operation == foCalculateSize)
  1370. {
  1371. // When calculating size before transfer, the abort caused by
  1372. // cancel flag set due to "MoveToQueue" below,
  1373. // is not propagated back to us in ExecuteFileOperation,
  1374. // as it is silently swallowed.
  1375. // So we explicitly (re)throw it here.
  1376. if (FMoveToQueue)
  1377. {
  1378. Abort();
  1379. }
  1380. }
  1381. else
  1382. {
  1383. if ((ProgressData.Cancel == csContinue) &&
  1384. !FAutoOperation)
  1385. {
  1386. OperationComplete(ProgressData.StartTime);
  1387. }
  1388. }
  1389. }
  1390. if (FProgressForm &&
  1391. // Can happen only during synchronization, when ending one of the operations
  1392. ProgressData.InProgress)
  1393. {
  1394. FProgressForm->SetProgressData(ProgressData);
  1395. DebugAssert(ProgressData.InProgress);
  1396. SetTaskbarListProgressValue(&ProgressData);
  1397. if (FProgressForm->Cancel > csContinue)
  1398. {
  1399. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1400. if (FProgressForm->Cancel == csCancelFile)
  1401. {
  1402. FProgressForm->ClearCancel();
  1403. }
  1404. // cancel cancels even the move
  1405. FMoveToQueue = false;
  1406. }
  1407. else if (FProgressForm->MoveToQueue)
  1408. {
  1409. FMoveToQueue = true;
  1410. ProgressData.SetCancelAtLeast(csCancel);
  1411. }
  1412. if ((FTransferResumeList != NULL) &&
  1413. ProgressData.InProgress &&
  1414. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1415. !ProgressData.FullFileName.IsEmpty())
  1416. {
  1417. if ((FTransferResumeList->Count == 0) ||
  1418. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1419. {
  1420. // note that we do not recognize directories from files here
  1421. FTransferResumeList->Add(ProgressData.FullFileName);
  1422. }
  1423. }
  1424. }
  1425. }
  1426. //---------------------------------------------------------------------------
  1427. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1428. const TDateTime & StartTime)
  1429. {
  1430. if (GUIConfiguration->BeepOnFinish &&
  1431. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1432. {
  1433. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1434. DWORD Sound;
  1435. if (!ExtractFileExt(BeepSound).IsEmpty())
  1436. {
  1437. Sound = SND_FILENAME;
  1438. }
  1439. else
  1440. {
  1441. Sound = SND_ALIAS;
  1442. }
  1443. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1444. }
  1445. }
  1446. //---------------------------------------------------------------------------
  1447. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1448. TFileOperationProgressType & ProgressData)
  1449. {
  1450. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1451. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1452. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1453. FileOperationProgress(ProgressData);
  1454. }
  1455. //---------------------------------------------------------------------------
  1456. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1457. {
  1458. UnicodeString Result;
  1459. if (FProgressForm != NULL)
  1460. {
  1461. Result = FProgressForm->ProgressStr();
  1462. }
  1463. return Result;
  1464. }
  1465. //---------------------------------------------------------------------------
  1466. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1467. bool DragDrop)
  1468. {
  1469. return (!DragDrop && (DropSourceControl == NULL)) ||
  1470. (DropSourceControl == DirView(osOther));
  1471. }
  1472. //---------------------------------------------------------------------------
  1473. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1474. TFileOperation Operation, TOperationSide Side,
  1475. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1476. TOnceDoneOperation & OnceDoneOperation)
  1477. {
  1478. if (!FAutoOperation)
  1479. {
  1480. // no selection on "/upload", form servers only as event handler
  1481. // (it is not displayed)
  1482. if (PanelOperation(Side, FDragDropOperation) &&
  1483. Visible && (Operation != foCalculateSize) &&
  1484. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1485. {
  1486. if (FOnFileOperationFinished != NULL)
  1487. {
  1488. FOnFileOperationFinished(FileName, Success);
  1489. }
  1490. else
  1491. {
  1492. TOperationSide DViewSide;
  1493. if ((FProgressSide != osCurrent) &&
  1494. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1495. {
  1496. // assume the operation is over the focused panel
  1497. DViewSide = FProgressSide;
  1498. }
  1499. else
  1500. {
  1501. DViewSide = Side;
  1502. }
  1503. TCustomDirView * DView = DirView(DViewSide);
  1504. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(DViewSide));
  1505. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1506. // this can happen when local drive is unplugged in the middle of the operation
  1507. if (Item != NULL)
  1508. {
  1509. if (Success) Item->Selected = false;
  1510. DView->MakeProgressVisible(Item);
  1511. }
  1512. }
  1513. }
  1514. if ((Operation == foCopy) || (Operation == foMove))
  1515. {
  1516. // TODO_OTHER_LOCAL
  1517. if (!IsLocalBrowserMode())
  1518. {
  1519. if (Side == osLocal)
  1520. {
  1521. Configuration->Usage->Inc(L"UploadedFiles");
  1522. }
  1523. else
  1524. {
  1525. Configuration->Usage->Inc(L"DownloadedFiles");
  1526. }
  1527. }
  1528. }
  1529. }
  1530. if (Success && (FSynchronizeController != NULL))
  1531. {
  1532. DebugAssert(!IsSideLocalBrowser(osRemote));
  1533. if (Operation == foCopy)
  1534. {
  1535. DebugAssert(Side == osLocal);
  1536. FSynchronizeController->LogOperation(soUpload, FileName);
  1537. }
  1538. else if (Operation == foDelete)
  1539. {
  1540. DebugAssert(Side == osRemote);
  1541. FSynchronizeController->LogOperation(soDelete, FileName);
  1542. }
  1543. }
  1544. if (FProgressForm)
  1545. {
  1546. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1547. }
  1548. }
  1549. //---------------------------------------------------------------------------
  1550. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1551. TFileOperation Operation, TOperationSide Side,
  1552. bool Temp, const UnicodeString & FileName, Boolean Success,
  1553. TOnceDoneOperation & OnceDoneOperation)
  1554. {
  1555. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1556. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1557. OnceDoneOperation);
  1558. }
  1559. //---------------------------------------------------------------------------
  1560. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1561. {
  1562. return false;
  1563. }
  1564. //---------------------------------------------------------------------------
  1565. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1566. {
  1567. return false;
  1568. }
  1569. //---------------------------------------------------------------------------
  1570. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1571. {
  1572. return NULL;
  1573. }
  1574. //---------------------------------------------------------------------------
  1575. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1576. {
  1577. DebugAssert(GetSide(Side) == osRemote);
  1578. DebugUsedParam(Side);
  1579. return RemoteDirView;
  1580. }
  1581. //---------------------------------------------------------------------------
  1582. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1583. {
  1584. DebugAssert(GetSide(Side) == osRemote);
  1585. DebugUsedParam(Side);
  1586. return RemoteDriveView;
  1587. }
  1588. //---------------------------------------------------------------------------
  1589. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1590. {
  1591. DebugAssert(GetSide(Side) == osRemote);
  1592. DebugUsedParam(Side);
  1593. return HasActiveTerminal();
  1594. }
  1595. //---------------------------------------------------------------------------
  1596. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1597. TOperationSide Side, int FilesOnly)
  1598. {
  1599. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1600. }
  1601. //---------------------------------------------------------------------------
  1602. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1603. TOperationSide Side, int FilesOnly)
  1604. {
  1605. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1606. }
  1607. //---------------------------------------------------------------------------
  1608. struct THistoryItemData
  1609. {
  1610. short int Side;
  1611. short int Index;
  1612. };
  1613. //---------------------------------------------------------------------------
  1614. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1615. {
  1616. DirView(Side)->HistoryGo(Index);
  1617. }
  1618. //---------------------------------------------------------------------------
  1619. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1620. {
  1621. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1622. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1623. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1624. }
  1625. //---------------------------------------------------------------------------
  1626. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1627. bool Back)
  1628. {
  1629. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1630. {
  1631. TCustomDirView * DView = DirView(Side);
  1632. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1633. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1634. if (ICount > 10)
  1635. {
  1636. ICount = 10;
  1637. }
  1638. Menu->Items->Clear();
  1639. THistoryItemData Data;
  1640. Data.Side = Side;
  1641. for (short int i = 1; i <= ICount; i++)
  1642. {
  1643. TTBCustomItem * Item = new TTBXItem(Menu);
  1644. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1645. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1646. Item->Hint = DView->HistoryPath[Data.Index];
  1647. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1648. Item->Tag = *reinterpret_cast<int*>(&Data);
  1649. Item->OnClick = HistoryItemClick;
  1650. Menu->Items->Add(Item);
  1651. }
  1652. }
  1653. }
  1654. //---------------------------------------------------------------------------
  1655. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1656. TOperationSide Side, bool Back)
  1657. {
  1658. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1659. {
  1660. // workaround
  1661. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1662. // operator new allocates memory in Pascal code, but calls inline
  1663. // contructor in C++, leading in problems, the function does
  1664. // both in Pascal code
  1665. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1666. UpdateHistoryMenu(Side, Back);
  1667. }
  1668. return FHistoryMenu[Side == osLocal][Back];
  1669. }
  1670. //---------------------------------------------------------------------------
  1671. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1672. TCustomDirView *Sender)
  1673. {
  1674. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1675. UpdateHistoryMenu(Side, true);
  1676. UpdateHistoryMenu(Side, false);
  1677. }
  1678. //---------------------------------------------------------------------------
  1679. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1680. {
  1681. // remote custom commands can be executed only if the server supports shell commands
  1682. // or have secondary shell
  1683. return HasActiveTerminal() && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1684. }
  1685. //---------------------------------------------------------------------------
  1686. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1687. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1688. {
  1689. // -1 = hidden, 0 = disabled, 1 = enabled
  1690. int Result;
  1691. TFileCustomCommand RemoteCustomCommand;
  1692. TLocalCustomCommand LocalCustomCommand;
  1693. TFileCustomCommand * NonInteractiveCustomCommand =
  1694. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1695. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1696. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1697. if (FLAGCLEAR(Command.Params, ccLocal))
  1698. {
  1699. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1700. // custom command that does not operate with files can be executed anytime ...
  1701. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1702. {
  1703. // ... but do not show such command in remote file menu
  1704. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1705. {
  1706. Result = AllowedState;
  1707. }
  1708. else
  1709. {
  1710. Result = -1;
  1711. }
  1712. }
  1713. else
  1714. {
  1715. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1716. {
  1717. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1718. }
  1719. else
  1720. {
  1721. Result = -1;
  1722. }
  1723. }
  1724. }
  1725. else
  1726. {
  1727. // custom command that does not operate with files can be executed anytime
  1728. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1729. {
  1730. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1731. }
  1732. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1733. {
  1734. if ((ListType == ccltAll) || (ListType == ccltFile))
  1735. {
  1736. // special case is "diff"-style command that can be executed over any side,
  1737. // if we have both sides
  1738. Result =
  1739. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1740. // directly (instead of EnableSelectedOperation) to pass
  1741. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1742. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1743. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1744. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1745. }
  1746. else if (ListType == ccltBoth)
  1747. {
  1748. DebugAssert(!IsLocalBrowserMode());
  1749. Result = 1;
  1750. }
  1751. else
  1752. {
  1753. Result = -1;
  1754. }
  1755. }
  1756. else
  1757. {
  1758. if ((ListType == ccltAll) ||
  1759. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1760. {
  1761. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1762. }
  1763. else
  1764. {
  1765. Result = -1;
  1766. }
  1767. }
  1768. if ((Result > 0) &&
  1769. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1770. !HasActiveTerminal())
  1771. {
  1772. Result = 0;
  1773. }
  1774. }
  1775. return Result;
  1776. }
  1777. //---------------------------------------------------------------------------
  1778. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1779. TStrings * FileList, const TCustomCommandType & ACommand,
  1780. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1781. {
  1782. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1783. {
  1784. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1785. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1786. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1787. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1788. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1789. bool Capture =
  1790. FLAGSET(ACommand.Params, ccShowResults) ||
  1791. FLAGSET(ACommand.Params, ccCopyResults) ||
  1792. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1793. TCaptureOutputEvent OutputEvent = NULL;
  1794. DebugAssert(FCapturedLog == NULL);
  1795. if (Capture)
  1796. {
  1797. FCapturedLog = new TStringList();
  1798. OutputEvent = TerminalCaptureLog;
  1799. }
  1800. try
  1801. {
  1802. if (!RemoteCustomCommand.IsFileCommand(Command))
  1803. {
  1804. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1805. OutputEvent);
  1806. }
  1807. else
  1808. {
  1809. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1810. }
  1811. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1812. {
  1813. if (FLAGSET(ACommand.Params, ccCopyResults))
  1814. {
  1815. CopyToClipboard(FCapturedLog);
  1816. }
  1817. if (FLAGSET(ACommand.Params, ccShowResults))
  1818. {
  1819. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1820. }
  1821. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1822. {
  1823. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1824. }
  1825. }
  1826. }
  1827. __finally
  1828. {
  1829. SAFE_DESTROY(FCapturedLog);
  1830. }
  1831. }
  1832. }
  1833. //---------------------------------------------------------------------------
  1834. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1835. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1836. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1837. {
  1838. DebugAssert(!IsLocalBrowserMode());
  1839. TStrings * LocalFileList = NULL;
  1840. TStrings * RemoteFileList = NULL;
  1841. TStrings * RemoteFileListFull = NULL;
  1842. try
  1843. {
  1844. if (LocalFileCommand)
  1845. {
  1846. if (ALocalFileList == NULL)
  1847. {
  1848. DebugAssert(HasDirView[osLocal]);
  1849. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1850. // directly (instead of EnableSelectedOperation) to pass
  1851. // false to FocusedFileOnlyWhenFocused
  1852. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1853. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1854. }
  1855. else
  1856. {
  1857. LocalFileList = ALocalFileList;
  1858. }
  1859. if (FileListCommand)
  1860. {
  1861. if (LocalFileList->Count != 1)
  1862. {
  1863. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1864. }
  1865. }
  1866. else
  1867. {
  1868. if ((LocalFileList->Count != 1) &&
  1869. (FileList->Count != 1) &&
  1870. (LocalFileList->Count != FileList->Count))
  1871. {
  1872. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1873. }
  1874. }
  1875. }
  1876. UnicodeString RootTempDir;
  1877. UnicodeString TempDir;
  1878. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1879. if (!RemoteFiles)
  1880. {
  1881. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1882. }
  1883. try
  1884. {
  1885. TDateTimes RemoteFileTimes;
  1886. if (RemoteFiles)
  1887. {
  1888. RemoteFileList = FileList;
  1889. }
  1890. else
  1891. {
  1892. RemoteFileList = new TStringList();
  1893. TMakeLocalFileListParams MakeFileListParam;
  1894. MakeFileListParam.FileList = RemoteFileList;
  1895. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1896. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1897. MakeFileListParam.Recursive =
  1898. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1899. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1900. if (!MakeFileListParam.Recursive)
  1901. {
  1902. RemoteFileTimes.clear();
  1903. RemoteFileListFull = new TStringList();
  1904. MakeFileListParam.FileList = RemoteFileListFull;
  1905. MakeFileListParam.Recursive = true;
  1906. MakeFileListParam.IncludeDirs = false;
  1907. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1908. }
  1909. else
  1910. {
  1911. RemoteFileListFull = RemoteFileList;
  1912. }
  1913. }
  1914. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1915. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1916. if (!NonBlocking)
  1917. {
  1918. int Count;
  1919. if (FileListCommand)
  1920. {
  1921. Count = 1;
  1922. }
  1923. else if (LocalFileCommand)
  1924. {
  1925. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1926. }
  1927. else
  1928. {
  1929. Count = RemoteFileList->Count;
  1930. }
  1931. Progress.Start(foCustomCommand, osRemote, Count);
  1932. DebugAssert(FProgressForm != NULL);
  1933. FProgressForm->ReadOnly = true;
  1934. }
  1935. try
  1936. {
  1937. if (FileListCommand)
  1938. {
  1939. UnicodeString LocalFile;
  1940. // MakeFileList does not delimit filenames
  1941. UnicodeString FileList = MakeFileList(RemoteFileList);
  1942. if (LocalFileCommand)
  1943. {
  1944. DebugAssert(LocalFileList->Count == 1);
  1945. LocalFile = LocalFileList->Strings[0];
  1946. }
  1947. TLocalCustomCommand CustomCommand(Data,
  1948. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1949. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1950. if (NonBlocking)
  1951. {
  1952. DebugAssert(!POutput);
  1953. ExecuteShellChecked(ShellCommand);
  1954. }
  1955. else
  1956. {
  1957. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1958. }
  1959. }
  1960. else if (LocalFileCommand)
  1961. {
  1962. if (LocalFileList->Count == 1)
  1963. {
  1964. UnicodeString LocalFile = LocalFileList->Strings[0];
  1965. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1966. {
  1967. UnicodeString FileName = RemoteFileList->Strings[Index];
  1968. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1969. Progress.SetFile(FileNameForProgress);
  1970. TLocalCustomCommand CustomCommand(Data,
  1971. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, 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 if (RemoteFileList->Count == 1)
  1979. {
  1980. UnicodeString FileName = RemoteFileList->Strings[0];
  1981. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1982. {
  1983. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1984. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1985. Progress.SetFile(LocalFileNameOnly);
  1986. TLocalCustomCommand CustomCommand(
  1987. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1988. FileName, LocalFileName, L"");
  1989. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1990. TOnceDoneOperation OnceDoneOperation;
  1991. // Do not unselect anything, as it won't work with two panels anyway
  1992. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1993. }
  1994. }
  1995. else
  1996. {
  1997. if (LocalFileList->Count != RemoteFileList->Count)
  1998. {
  1999. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  2000. }
  2001. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2002. {
  2003. UnicodeString FileName = RemoteFileList->Strings[Index];
  2004. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2005. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2006. Progress.SetFile(LocalFileNameOnly); // sic
  2007. TLocalCustomCommand CustomCommand(
  2008. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2009. FileName, LocalFileName, L"");
  2010. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2011. TOnceDoneOperation OnceDoneOperation;
  2012. // Do not unselect anything, as it won't work with two panels anyway
  2013. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2014. }
  2015. }
  2016. }
  2017. else
  2018. {
  2019. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2020. {
  2021. UnicodeString FileName = RemoteFileList->Strings[Index];
  2022. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2023. Progress.SetFile(FileNameForProgress);
  2024. TLocalCustomCommand CustomCommand(Data,
  2025. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2026. FileName, L"", L"");
  2027. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2028. TOnceDoneOperation OnceDoneOperation;
  2029. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2030. }
  2031. }
  2032. }
  2033. __finally
  2034. {
  2035. if (!NonBlocking)
  2036. {
  2037. Progress.Stop();
  2038. }
  2039. }
  2040. DebugAssert(!FAutoOperation);
  2041. if (!RemoteFiles)
  2042. {
  2043. TempDir = IncludeTrailingBackslash(TempDir);
  2044. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2045. {
  2046. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2047. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2048. // Skip directories, process only nested files.
  2049. // The check is redundant as FileAge fails for directories anyway.
  2050. !DirectoryExists(FileName))
  2051. {
  2052. UnicodeString RemoteDir =
  2053. UnixExtractFileDir(
  2054. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2055. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2056. TDateTime NewTime;
  2057. if (FileAge(FileName, NewTime) &&
  2058. (NewTime != RemoteFileTimes[Index]))
  2059. {
  2060. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2061. TemporaryFileCopyParam(CopyParam);
  2062. CopyParam.FileMask = L"";
  2063. FAutoOperation = true;
  2064. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2065. TemporaryFilesList->Add(FileName);
  2066. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2067. }
  2068. }
  2069. }
  2070. }
  2071. }
  2072. __finally
  2073. {
  2074. FAutoOperation = false;
  2075. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2076. {
  2077. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2078. }
  2079. }
  2080. }
  2081. __finally
  2082. {
  2083. if (RemoteFileList != FileList)
  2084. {
  2085. delete RemoteFileList;
  2086. }
  2087. if (LocalFileList != ALocalFileList)
  2088. {
  2089. delete LocalFileList;
  2090. }
  2091. if (RemoteFileListFull != RemoteFileList)
  2092. {
  2093. delete RemoteFileListFull;
  2094. }
  2095. }
  2096. }
  2097. //---------------------------------------------------------------------------
  2098. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2099. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2100. bool FileListCommand, UnicodeString * POutput)
  2101. {
  2102. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2103. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2104. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2105. {
  2106. UnicodeString FileName = SelectedFileList->Strings[Index];
  2107. if (DirectoryExists(FileName))
  2108. {
  2109. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2110. {
  2111. LocalFileList->Add(FileName);
  2112. }
  2113. if (FLAGSET(ACommand.Params, ccRecursive))
  2114. {
  2115. TMakeLocalFileListParams MakeFileListParam;
  2116. MakeFileListParam.FileList = LocalFileList.get();
  2117. MakeFileListParam.FileTimes = NULL;
  2118. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2119. MakeFileListParam.Recursive = true;
  2120. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2121. }
  2122. }
  2123. else
  2124. {
  2125. LocalFileList->Add(FileName);
  2126. }
  2127. }
  2128. UnicodeString RemotePath;
  2129. if (Terminal != NULL)
  2130. {
  2131. RemotePath = Terminal->CurrentDirectory;
  2132. }
  2133. if (FileListCommand)
  2134. {
  2135. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2136. TLocalCustomCommand CustomCommand(
  2137. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2138. L"", L"", FileList);
  2139. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2140. }
  2141. else
  2142. {
  2143. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2144. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2145. DebugAssert(FProgressForm != NULL);
  2146. FProgressForm->ReadOnly = true;
  2147. try
  2148. {
  2149. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2150. {
  2151. UnicodeString FileName = LocalFileList->Strings[Index];
  2152. Progress.SetFile(FileName);
  2153. TLocalCustomCommand CustomCommand(
  2154. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2155. FileName, L"", L"");
  2156. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2157. TOnceDoneOperation OnceDoneOperation;
  2158. Progress.Finish(FileName, true, OnceDoneOperation);
  2159. }
  2160. }
  2161. __finally
  2162. {
  2163. Progress.Stop();
  2164. }
  2165. }
  2166. }
  2167. //---------------------------------------------------------------------------
  2168. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2169. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2170. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2171. {
  2172. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2173. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2174. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2175. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2176. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2177. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2178. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2179. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2180. std::unique_ptr<UnicodeString> POutput;
  2181. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2182. FLAGSET(ACommand.Params, ccCopyResults))
  2183. {
  2184. POutput.reset(new UnicodeString());
  2185. }
  2186. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  2187. FProgressSide = FCurrentSide;
  2188. if (!LocalCustomCommand.IsFileCommand(Command))
  2189. {
  2190. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2191. }
  2192. // remote files?
  2193. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2194. {
  2195. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2196. }
  2197. // local files
  2198. else
  2199. {
  2200. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2201. }
  2202. if (POutput.get() != NULL)
  2203. {
  2204. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2205. int P = POutput->Pos(sLineBreak);
  2206. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2207. {
  2208. POutput->SetLength(P - 1);
  2209. }
  2210. // Copy even empty output to clipboard
  2211. if (FLAGSET(ACommand.Params, ccCopyResults))
  2212. {
  2213. CopyToClipboard(*POutput);
  2214. }
  2215. // But do not show an empty message box.
  2216. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2217. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2218. !POutput->IsEmpty())
  2219. {
  2220. TClipboardHandler ClipboardHandler;
  2221. ClipboardHandler.Text = *POutput;
  2222. TMessageParams Params;
  2223. TQueryButtonAlias Aliases[1];
  2224. Aliases[0].Button = qaRetry;
  2225. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2226. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2227. Params.Aliases = Aliases;
  2228. Params.AliasesCount = LENOF(Aliases);
  2229. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2230. }
  2231. }
  2232. }
  2233. //---------------------------------------------------------------------------
  2234. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2235. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2236. {
  2237. TCustomCommandData Data;
  2238. UnicodeString Site;
  2239. UnicodeString RemotePath;
  2240. if (HasActiveTerminal())
  2241. {
  2242. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2243. Data = TCustomCommandData(SessionData.get());
  2244. Site = Terminal->SessionData->SessionKey;
  2245. RemotePath = Terminal->CurrentDirectory;
  2246. }
  2247. UnicodeString HelpKeyword = ACommand.HomePage;
  2248. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2249. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2250. {
  2251. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2252. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2253. {
  2254. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2255. }
  2256. else
  2257. {
  2258. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2259. }
  2260. if (!DoCustomCommandOptionsDialog(
  2261. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2262. {
  2263. Abort();
  2264. }
  2265. }
  2266. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2267. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2268. {
  2269. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2270. }
  2271. else
  2272. {
  2273. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2274. }
  2275. }
  2276. //---------------------------------------------------------------------------
  2277. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2278. const TCustomCommandType & Command)
  2279. {
  2280. DebugAssert(FCustomCommandLocalFileList != NULL);
  2281. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2282. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2283. TStrings * LocalFileList = new TStringList();
  2284. TStrings * RemoteFileList = new TStringList();
  2285. try
  2286. {
  2287. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2288. {
  2289. LocalFileList->Clear();
  2290. LocalFileList->AddObject(
  2291. FCustomCommandLocalFileList->Strings[Index],
  2292. FCustomCommandLocalFileList->Objects[Index]);
  2293. RemoteFileList->Clear();
  2294. RemoteFileList->AddObject(
  2295. FCustomCommandRemoteFileList->Strings[Index],
  2296. FCustomCommandRemoteFileList->Objects[Index]);
  2297. CustomCommand(RemoteFileList, Command, LocalFileList);
  2298. }
  2299. }
  2300. __finally
  2301. {
  2302. delete LocalFileList;
  2303. delete RemoteFileList;
  2304. }
  2305. }
  2306. //---------------------------------------------------------------------------
  2307. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2308. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2309. {
  2310. delete FCustomCommandLocalFileList;
  2311. delete FCustomCommandRemoteFileList;
  2312. // takeover ownership,
  2313. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2314. FCustomCommandLocalFileList = LocalFileList;
  2315. FCustomCommandRemoteFileList = RemoteFileList;
  2316. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2317. if (Button != NULL)
  2318. {
  2319. FCustomCommandMenu->Items->Clear();
  2320. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2321. MenuPopup(FCustomCommandMenu, Button);
  2322. }
  2323. else
  2324. {
  2325. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2326. }
  2327. }
  2328. //---------------------------------------------------------------------------
  2329. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2330. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2331. {
  2332. DebugAssert(FCapturedLog != NULL);
  2333. if ((OutputType == cotOutput) || (OutputType == cotError))
  2334. {
  2335. FCapturedLog->Add(AddedLine);
  2336. }
  2337. }
  2338. //---------------------------------------------------------------------------
  2339. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2340. TOperationSide Side)
  2341. {
  2342. return
  2343. (Side == osOther) &&
  2344. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2345. }
  2346. //---------------------------------------------------------------------------
  2347. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2348. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2349. {
  2350. TTBItemOptions O;
  2351. O = Item->Options;
  2352. TCustomDirView * DView = DirView(Side);
  2353. if ((DView->ItemFocused != NULL) &&
  2354. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2355. // when resolving links is disabled, default action is to enter the directory,
  2356. // no matter what DoubleClickAction is configured to
  2357. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2358. // Can only Edit files, but can Open/Copy even directories
  2359. ((DoubleClickAction != dcaEdit) ||
  2360. !DView->ItemIsDirectory(DView->ItemFocused)))
  2361. {
  2362. Item->Options = O << tboDefault;
  2363. }
  2364. else
  2365. {
  2366. Item->Options = O >> tboDefault;
  2367. }
  2368. }
  2369. //---------------------------------------------------------------------------
  2370. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2371. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2372. {
  2373. TCustomDirView * DView = DirView(Side);
  2374. TListItem * Item = DView->ItemFocused;
  2375. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2376. EnableFocusedOperation[Side])
  2377. {
  2378. TPoint ClientPoint;
  2379. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2380. TPoint(0, 0) : MousePos;
  2381. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2382. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2383. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2384. }
  2385. }
  2386. //---------------------------------------------------------------------------
  2387. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2388. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2389. {
  2390. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2391. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2392. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2393. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2394. Handled = true;
  2395. }
  2396. //---------------------------------------------------------------------------
  2397. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2398. {
  2399. }
  2400. //---------------------------------------------------------------------------
  2401. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2402. {
  2403. DebugAssert(FErrorList == NULL);
  2404. if (WinConfiguration->ContinueOnError)
  2405. {
  2406. FErrorList = new TStringList();
  2407. Configuration->Usage->Inc(L"ContinuationsOnError");
  2408. }
  2409. NonVisualDataModule->StartBusy();
  2410. }
  2411. //---------------------------------------------------------------------------
  2412. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2413. {
  2414. NonVisualDataModule->EndBusy();
  2415. if (FErrorList)
  2416. {
  2417. HandleErrorList(FErrorList);
  2418. }
  2419. }
  2420. //---------------------------------------------------------------------------
  2421. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2422. const TCopyParamType & CopyParam)
  2423. {
  2424. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2425. {
  2426. Configuration->Usage->Inc(L"FileMaskUses");
  2427. }
  2428. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2429. {
  2430. Configuration->Usage->Inc(L"OperationMaskUses");
  2431. }
  2432. }
  2433. //---------------------------------------------------------------------------
  2434. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2435. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2436. {
  2437. DebugAssert(!IsLocalBrowserMode());
  2438. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2439. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2440. TTransferOperationParam DefaultParam;
  2441. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2442. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2443. switch (Param.Queue)
  2444. {
  2445. case asOn:
  2446. CopyParam.Queue = true;
  2447. break;
  2448. case asOff:
  2449. CopyParam.Queue = false;
  2450. break;
  2451. case asAuto:
  2452. default:
  2453. // keep default
  2454. break;
  2455. }
  2456. bool Result =
  2457. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2458. if (Result)
  2459. {
  2460. DebugAssert(Terminal);
  2461. bool SelectionRestored = false;
  2462. TCustomDirView * DView = NULL;
  2463. if (HasDirView[Side])
  2464. {
  2465. DView = DirView(Side);
  2466. DView->SaveSelection();
  2467. DView->SaveSelectedNames();
  2468. }
  2469. UpdateCopyParamCounters(CopyParam);
  2470. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2471. DebugAssert(FTransferResumeList == NULL);
  2472. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2473. FMoveToQueue = false;
  2474. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2475. try
  2476. {
  2477. TStrings * PermanentFileList;
  2478. std::unique_ptr<TStrings> PermanentFileListOwner;
  2479. try
  2480. {
  2481. if (Side == osLocal)
  2482. {
  2483. PermanentFileList = FileList;
  2484. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2485. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2486. if (Operation == foMove)
  2487. {
  2488. ReloadLocalDirectory();
  2489. if (DView != NULL)
  2490. {
  2491. DView->RestoreSelection();
  2492. }
  2493. SelectionRestored = true;
  2494. }
  2495. }
  2496. else
  2497. {
  2498. // Clone the file list as it may refer to current directory files,
  2499. // which get destroyed, when the source directory is reloaded after foMove operation.
  2500. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2501. // But for a hotfix, we are not going to do such a big change.
  2502. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2503. PermanentFileList = PermanentFileListOwner.get();
  2504. try
  2505. {
  2506. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2507. }
  2508. __finally
  2509. {
  2510. if (Operation == foMove)
  2511. {
  2512. if (DView != NULL)
  2513. {
  2514. DView->RestoreSelection();
  2515. }
  2516. SelectionRestored = true;
  2517. }
  2518. ReloadLocalDirectory(Param.TargetDirectory);
  2519. }
  2520. }
  2521. }
  2522. catch (EAbort &)
  2523. {
  2524. if (FMoveToQueue)
  2525. {
  2526. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2527. DebugAssert(CopyParam.TransferSkipList == NULL);
  2528. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2529. if (TransferResumeList->Count > 0)
  2530. {
  2531. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2532. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2533. }
  2534. CopyParam.TransferSkipList = TransferResumeList.release();
  2535. // not really needed, just to keep it consistent with TransferResumeList
  2536. FTransferResumeList = NULL;
  2537. FMoveToQueue = false;
  2538. Configuration->Usage->Inc("MovesToBackground");
  2539. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2540. ClearTransferSourceSelection(Direction);
  2541. }
  2542. throw;
  2543. }
  2544. }
  2545. __finally
  2546. {
  2547. if (!SelectionRestored && (DView != NULL))
  2548. {
  2549. DView->DiscardSavedSelection();
  2550. }
  2551. FTransferResumeList = NULL;
  2552. }
  2553. }
  2554. return Result;
  2555. }
  2556. //---------------------------------------------------------------------------
  2557. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2558. TOperationSide Side, TStrings * FileList, void * Param)
  2559. {
  2560. DebugAssert(FileList->Count);
  2561. // We deliberately do not toggle alternative flag (Param), but use OR,
  2562. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2563. // shortcut of CurrentDeleteAlternativeAction
  2564. bool Alternative =
  2565. bool(Param) || UseAlternativeFunction();
  2566. bool Recycle;
  2567. if (IsSideLocalBrowser(Side))
  2568. {
  2569. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2570. }
  2571. else
  2572. {
  2573. Recycle =
  2574. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2575. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2576. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2577. }
  2578. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2579. if (!Result)
  2580. {
  2581. UnicodeString Query;
  2582. if (FileList->Count == 1)
  2583. {
  2584. if (IsSideLocalBrowser(Side))
  2585. {
  2586. Query = ExtractFileName(FileList->Strings[0]);
  2587. }
  2588. else
  2589. {
  2590. Query = UnixExtractFileName(FileList->Strings[0]);
  2591. }
  2592. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2593. }
  2594. else
  2595. {
  2596. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2597. }
  2598. TMessageParams Params(mpNeverAskAgainCheck);
  2599. Params.ImageName = L"Delete file";
  2600. unsigned int Answer =
  2601. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2602. if (Answer == qaNeverAskAgain)
  2603. {
  2604. Result = true;
  2605. if (Recycle)
  2606. {
  2607. WinConfiguration->ConfirmRecycling = false;
  2608. }
  2609. else
  2610. {
  2611. WinConfiguration->ConfirmDeleting = false;
  2612. }
  2613. }
  2614. else
  2615. {
  2616. Result = (Answer == qaOK);
  2617. }
  2618. }
  2619. if (Result)
  2620. {
  2621. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2622. }
  2623. return Result;
  2624. }
  2625. //---------------------------------------------------------------------------
  2626. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2627. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2628. {
  2629. TAutoBatch AutoBatch(this);
  2630. bool Result;
  2631. if ((Operation == foCopy) || (Operation == foMove))
  2632. {
  2633. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2634. }
  2635. else if (Operation == foRename)
  2636. {
  2637. DebugAssert(DirView(Side)->ItemFocused);
  2638. DirView(Side)->ItemFocused->EditCaption();
  2639. Result = true;
  2640. }
  2641. else if (Operation == foDelete)
  2642. {
  2643. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2644. }
  2645. else if (Operation == foSetProperties)
  2646. {
  2647. DirView(osRemote)->SaveSelectedNames();
  2648. Result = SetProperties(Side, FileList);
  2649. }
  2650. else if (Operation == foCustomCommand)
  2651. {
  2652. DebugAssert(Param);
  2653. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2654. DirView(osRemote)->SaveSelectedNames();
  2655. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2656. CustomCommand(FileList, *Command, NULL);
  2657. Result = true;
  2658. }
  2659. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2660. {
  2661. DebugAssert(!IsSideLocalBrowser(Side));
  2662. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2663. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2664. }
  2665. else if (Operation == foLock)
  2666. {
  2667. DebugAssert(!IsSideLocalBrowser(Side));
  2668. LockFiles(FileList, true);
  2669. Result = true;
  2670. }
  2671. else if (Operation == foUnlock)
  2672. {
  2673. DebugAssert(!IsSideLocalBrowser(Side));
  2674. LockFiles(FileList, false);
  2675. Result = true;
  2676. }
  2677. else
  2678. {
  2679. DebugFail();
  2680. }
  2681. return Result;
  2682. }
  2683. //---------------------------------------------------------------------------
  2684. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2685. {
  2686. if (Side == osCurrent)
  2687. {
  2688. Side = FCurrentSide;
  2689. }
  2690. return Side;
  2691. }
  2692. //---------------------------------------------------------------------------
  2693. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2694. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2695. {
  2696. Side = GetSide(Side);
  2697. bool Result;
  2698. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2699. try
  2700. {
  2701. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2702. }
  2703. __finally
  2704. {
  2705. delete FileList;
  2706. }
  2707. return Result;
  2708. }
  2709. //---------------------------------------------------------------------------
  2710. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2711. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2712. bool NoConfirmation, void * Param)
  2713. {
  2714. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2715. {
  2716. if ((Operation == foCopy) || (Operation == foMove))
  2717. {
  2718. DebugAssert(!IsLocalBrowserMode());
  2719. if (GetSide(Side) == osLocal)
  2720. {
  2721. Configuration->Usage->Inc(L"UploadsCommand");
  2722. }
  2723. else
  2724. {
  2725. Configuration->Usage->Inc(L"DownloadsCommand");
  2726. }
  2727. }
  2728. }
  2729. }
  2730. //---------------------------------------------------------------------------
  2731. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2732. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2733. {
  2734. TTransferOperationParam Param;
  2735. if ((WinConfiguration->Interface != ifCommander) ||
  2736. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2737. {
  2738. Flags &= ~cocShortCutHint;
  2739. }
  2740. TCustomDirView * DView = DirView(Side);
  2741. Param.Options =
  2742. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2743. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2744. if (FLAGSET(Flags, cocQueue))
  2745. {
  2746. Param.Queue = asOn;
  2747. }
  2748. else if (FLAGSET(Flags, cocNonQueue))
  2749. {
  2750. Param.Queue = asOff;
  2751. }
  2752. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2753. }
  2754. //---------------------------------------------------------------------------
  2755. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2756. {
  2757. try
  2758. {
  2759. if (ErrorList->Count)
  2760. {
  2761. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2762. if (MessageDialog(Message, qtError,
  2763. qaOK | qaCancel, HELP_NONE) == qaOK)
  2764. {
  2765. unsigned int Answer;
  2766. int Index = 0;
  2767. do
  2768. {
  2769. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2770. TQueryButtonAlias Aliases[2];
  2771. Aliases[0].Button = qaYes;
  2772. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2773. Aliases[1].Button = qaNo;
  2774. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2775. TMessageParams Params;
  2776. Params.Aliases = Aliases;
  2777. Params.AliasesCount = LENOF(Aliases);
  2778. Answer = MoreMessageDialog(
  2779. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2780. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2781. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2782. qaOK, HELP_NONE, &Params);
  2783. if (Answer == qaNo)
  2784. {
  2785. Index++;
  2786. }
  2787. if (Answer == qaYes)
  2788. {
  2789. Index--;
  2790. }
  2791. }
  2792. while (Answer != qaOK);
  2793. }
  2794. }
  2795. }
  2796. __finally
  2797. {
  2798. TStrings * List = ErrorList;
  2799. ErrorList = NULL;
  2800. for (int i = 0; i < List->Count; i++)
  2801. {
  2802. delete List->Objects[i];
  2803. }
  2804. delete List;
  2805. }
  2806. }
  2807. //---------------------------------------------------------------------------
  2808. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2809. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2810. {
  2811. // needed for checking filemasks, as there's no directory object
  2812. // associated with the file object
  2813. File->FullFileName = FullFileName;
  2814. TFileMasks::TParams MaskParams;
  2815. MaskParams.Size = File->Size;
  2816. MaskParams.Modification = File->Modification;
  2817. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2818. }
  2819. //---------------------------------------------------------------------------
  2820. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2821. {
  2822. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2823. Side = GetSide(Side);
  2824. TCustomDirView * DView = DirView(Side);
  2825. TListItem * FocusedItem = DView->ItemFocused;
  2826. UnicodeString Name;
  2827. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2828. {
  2829. Name = DView->ItemFileName(FocusedItem);
  2830. }
  2831. else
  2832. {
  2833. Name = LoadStr(NEW_FILE);
  2834. }
  2835. UnicodeString Names = Name;
  2836. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2837. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2838. HELP_EDIT_NEW, History.get(), true))
  2839. {
  2840. while (!Names.IsEmpty())
  2841. {
  2842. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2843. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2844. UnicodeString TargetFileName;
  2845. UnicodeString LocalFileName;
  2846. UnicodeString RootTempDir;
  2847. UnicodeString TempDir;
  2848. UnicodeString RemoteDirectory;
  2849. bool ExistingFile = false;
  2850. if (!IsSideLocalBrowser(Side))
  2851. {
  2852. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2853. TRemoteFile * File = NULL;
  2854. if (FTerminal->FileExists(Name, &File) &&
  2855. !File->IsDirectory)
  2856. {
  2857. try
  2858. {
  2859. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2860. ExistingFile = true;
  2861. }
  2862. __finally
  2863. {
  2864. delete File;
  2865. }
  2866. }
  2867. if (!ExistingFile)
  2868. {
  2869. RemoteDirectory = UnixExtractFilePath(Name);
  2870. TemporaryDirectoryForRemoteFiles(
  2871. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2872. TargetFileName = UnixExtractFileName(Name);
  2873. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2874. LocalFileName = TempDir +
  2875. // We probably do not want to trim the VMS version here
  2876. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2877. }
  2878. }
  2879. else
  2880. {
  2881. if (ExtractFilePath(Name).IsEmpty())
  2882. {
  2883. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2884. }
  2885. else
  2886. {
  2887. LocalFileName = ExpandFileName(Name);
  2888. }
  2889. TargetFileName = ExtractFileName(Name);
  2890. }
  2891. if (!ExistingFile)
  2892. {
  2893. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2894. if (NewFile)
  2895. {
  2896. int File = FileCreate(ApiPath(LocalFileName));
  2897. if (File < 0)
  2898. {
  2899. if (!RootTempDir.IsEmpty())
  2900. {
  2901. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2902. }
  2903. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2904. }
  2905. else
  2906. {
  2907. FileClose(File);
  2908. }
  2909. }
  2910. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2911. const TEditorData * ExternalEditor = NULL;
  2912. TFileMasks::TParams MaskParams; // size not known
  2913. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2914. false, MaskParams);
  2915. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2916. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2917. }
  2918. }
  2919. }
  2920. }
  2921. //---------------------------------------------------------------------------
  2922. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2923. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2924. {
  2925. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2926. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2927. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2928. return
  2929. ((ExecuteFileBy == efInternalEditor)) ||
  2930. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2931. }
  2932. //---------------------------------------------------------------------------
  2933. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2934. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2935. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2936. UnicodeString RemoteDirectory, bool NewFile)
  2937. {
  2938. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2939. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2940. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2941. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2942. Side = GetSide(Side);
  2943. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2944. if (!IsSideLocalBrowser(Side))
  2945. {
  2946. Data->Terminal = Terminal;
  2947. Data->Queue = Queue;
  2948. Data->SessionData = CloneCurrentSessionData();
  2949. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2950. Data->RemoteDirectory = RemoteDirectory;
  2951. Data->SessionName = Terminal->SessionData->SessionName;
  2952. Data->LocalRootDirectory = LocalRootDirectory;
  2953. Data->OriginalFileName = OriginalFileName;
  2954. Data->Command = L""; // will be changed later for external editor
  2955. }
  2956. if (ExecuteFileBy == efInternalEditor)
  2957. {
  2958. if (!IsSideLocalBrowser(Side))
  2959. {
  2960. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2961. L" - " + Terminal->SessionData->SessionName;
  2962. TForm * Editor;
  2963. try
  2964. {
  2965. TNotifyEvent OnFileChanged = NULL;
  2966. TNotifyEvent OnSaveAll = NULL;
  2967. TAnyModifiedEvent OnAnyModified = NULL;
  2968. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2969. if (Terminal->IsCapable[fcBackgroundTransfers])
  2970. {
  2971. OnFileChanged = FEditorManager->FileChanged;
  2972. OnSaveAll = SaveAllInternalEditors;
  2973. OnAnyModified = AnyInternalEditorModified;
  2974. }
  2975. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2976. FEditorManager->FileReload, FEditorManager->FileClosed,
  2977. OnSaveAll, OnAnyModified,
  2978. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2979. }
  2980. catch(...)
  2981. {
  2982. if (!LocalRootDirectory.IsEmpty())
  2983. {
  2984. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2985. }
  2986. throw;
  2987. }
  2988. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2989. }
  2990. else
  2991. {
  2992. DebugAssert(!FStandaloneEditing);
  2993. TForm * Editor =
  2994. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2995. SaveAllInternalEditors, AnyInternalEditorModified,
  2996. L"", false, SessionColor, -1, NewFile);
  2997. FLocalEditors->Add(Editor);
  2998. }
  2999. }
  3000. else
  3001. {
  3002. HANDLE Process;
  3003. if (ExecuteFileBy == efExternalEditor)
  3004. {
  3005. UnicodeString Program, Params, Dir;
  3006. Data->Command = ExternalEditor->ExternalEditor;
  3007. ReformatFileNameCommand(Data->Command);
  3008. SplitCommand(Data->Command, Program, Params, Dir);
  3009. Params = ExpandFileNameCommand(Params, FileName);
  3010. Program = ExpandEnvironmentVariables(Program);
  3011. if (!ExecuteShell(Program, Params, Process))
  3012. {
  3013. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3014. }
  3015. }
  3016. else
  3017. {
  3018. DebugAssert(!IsSideLocalBrowser(Side));
  3019. if (!ExecuteShell(FileName, L"", Process))
  3020. {
  3021. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3022. }
  3023. }
  3024. if (IsSideLocalBrowser(Side) ||
  3025. ((ExecuteFileBy == efShell) &&
  3026. !WinConfiguration->Editor.SDIShellEditor) ||
  3027. ((ExecuteFileBy == efExternalEditor) &&
  3028. !ExternalEditor->SDIExternalEditor))
  3029. {
  3030. // no need for handle
  3031. if (Process != NULL)
  3032. {
  3033. DebugCheck(CloseHandle(Process));
  3034. }
  3035. Process = INVALID_HANDLE_VALUE;
  3036. }
  3037. else
  3038. {
  3039. if (Process == NULL)
  3040. {
  3041. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3042. }
  3043. }
  3044. if (!IsSideLocalBrowser(Side))
  3045. {
  3046. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3047. }
  3048. }
  3049. }
  3050. //---------------------------------------------------------------------------
  3051. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3052. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3053. void * /*Arg*/)
  3054. {
  3055. if (Token != NULL)
  3056. {
  3057. EditorFormFileSave(static_cast<TForm *>(Token));
  3058. }
  3059. }
  3060. //---------------------------------------------------------------------------
  3061. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3062. {
  3063. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3064. {
  3065. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3066. }
  3067. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3068. }
  3069. //---------------------------------------------------------------------------
  3070. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3071. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3072. void * Arg)
  3073. {
  3074. if ((Token != NULL) &&
  3075. IsEditorFormModified(static_cast<TForm *>(Token)))
  3076. {
  3077. *static_cast<bool *>(Arg) = true;
  3078. }
  3079. }
  3080. //---------------------------------------------------------------------------
  3081. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3082. TObject * /*Sender*/, bool & Modified)
  3083. {
  3084. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3085. {
  3086. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3087. {
  3088. Modified = true;
  3089. }
  3090. }
  3091. if (!Modified)
  3092. {
  3093. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3094. }
  3095. }
  3096. //---------------------------------------------------------------------------
  3097. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3098. {
  3099. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3100. }
  3101. //---------------------------------------------------------------------------
  3102. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3103. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3104. UnicodeString & Result, UnicodeString & RootDirectory)
  3105. {
  3106. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3107. {
  3108. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3109. Result = RootDirectory;
  3110. }
  3111. else
  3112. {
  3113. RootDirectory = L"";
  3114. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3115. Result = IncludeTrailingBackslash(Result);
  3116. }
  3117. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3118. {
  3119. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3120. }
  3121. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3122. {
  3123. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3124. {
  3125. RemoteDirectory.Delete(1, 1);
  3126. }
  3127. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3128. }
  3129. if (!ForceDirectories(ApiPath(Result)))
  3130. {
  3131. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3132. }
  3133. }
  3134. //---------------------------------------------------------------------------
  3135. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3136. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3137. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3138. {
  3139. DebugAssert(!IsLocalBrowserMode());
  3140. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3141. if (ForceText)
  3142. {
  3143. CopyParam.TransferMode = tmAscii;
  3144. }
  3145. TemporaryFileCopyParam(CopyParam);
  3146. if (AllFiles)
  3147. {
  3148. CopyParam.IncludeFileMask = TFileMasks();
  3149. }
  3150. if (TempDir.IsEmpty())
  3151. {
  3152. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3153. }
  3154. DebugAssert(!FAutoOperation);
  3155. FAutoOperation = AutoOperation;
  3156. Terminal->ExceptionOnFail = true;
  3157. try
  3158. {
  3159. try
  3160. {
  3161. // turn off confirmations, as for MDI editors we may possibly download
  3162. // the same file over
  3163. Terminal->CopyToLocal(
  3164. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3165. if (GetTargetNames)
  3166. {
  3167. for (int i = 0; i < FileList->Count; i++)
  3168. {
  3169. FileList->Strings[i] =
  3170. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3171. }
  3172. }
  3173. }
  3174. catch(...)
  3175. {
  3176. if (!RootTempDir.IsEmpty())
  3177. {
  3178. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3179. }
  3180. throw;
  3181. }
  3182. }
  3183. __finally
  3184. {
  3185. FAutoOperation = false;
  3186. Terminal->ExceptionOnFail = false;
  3187. }
  3188. }
  3189. //---------------------------------------------------------------------------
  3190. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3191. {
  3192. // Do not waste time checking for default editor list the next time,
  3193. // or testing if default editor is not notepad.
  3194. bool TryNextTime = false;
  3195. UnicodeString UsageState;
  3196. if (!WinConfiguration->EditorList->IsDefaultList())
  3197. {
  3198. UsageState = "H";
  3199. }
  3200. else
  3201. {
  3202. UnicodeString Executable;
  3203. UnicodeString ExecutableDescription;
  3204. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3205. {
  3206. UnicodeString Message =
  3207. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3208. unsigned int Answer =
  3209. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3210. if (Answer != qaOK)
  3211. {
  3212. UsageState = "R";
  3213. }
  3214. else
  3215. {
  3216. UsageState = "A";
  3217. TEditorData EditorData;
  3218. EditorData.Editor = edExternal;
  3219. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3220. EditorData.ExternalEditorOptionsAutodetect();
  3221. TEditorList EditorList;
  3222. EditorList = *WinConfiguration->EditorList;
  3223. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3224. WinConfiguration->EditorList = &EditorList;
  3225. }
  3226. }
  3227. }
  3228. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3229. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3230. }
  3231. //---------------------------------------------------------------------------
  3232. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3233. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3234. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3235. {
  3236. if (ExecuteFileBy == efDefaultEditor)
  3237. {
  3238. if (!WinConfiguration->OfferedEditorAutoConfig)
  3239. {
  3240. EditorAutoConfig();
  3241. }
  3242. const TEditorPreferences * Editor =
  3243. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3244. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3245. {
  3246. ExecuteFileBy = efInternalEditor;
  3247. ExternalEditor = NULL;
  3248. }
  3249. else if (Editor->Data->Editor == edOpen)
  3250. {
  3251. ExecuteFileBy = efShell;
  3252. ExternalEditor = NULL;
  3253. }
  3254. else
  3255. {
  3256. ExecuteFileBy = efExternalEditor;
  3257. ExternalEditor = Editor->Data;
  3258. }
  3259. }
  3260. }
  3261. //---------------------------------------------------------------------------
  3262. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3263. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3264. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3265. {
  3266. UnicodeString OriginalFileName;
  3267. UnicodeString LocalRootDirectory;
  3268. UnicodeString RemoteDirectory;
  3269. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3270. IsSideLocalBrowser(Side), MaskParams);
  3271. UnicodeString Counter;
  3272. UnicodeString LocalFileName;
  3273. bool Handled = false;
  3274. if (!IsSideLocalBrowser(Side))
  3275. {
  3276. // We need to trim VMS version here, so that we use name without version
  3277. // when uploading back to create a new version of the file
  3278. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3279. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3280. TObject * Token = NULL;
  3281. UnicodeString LocalDirectory;
  3282. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3283. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3284. LocalDirectory))
  3285. {
  3286. if (Token != NULL)
  3287. {
  3288. TForm * Form = dynamic_cast<TForm *>(Token);
  3289. if (Form->WindowState == wsMinimized)
  3290. {
  3291. ShowWindow(Form->Handle, SW_RESTORE);
  3292. }
  3293. else
  3294. {
  3295. Form->SetFocus();
  3296. }
  3297. Handled = true;
  3298. }
  3299. else
  3300. {
  3301. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3302. }
  3303. }
  3304. if (!Handled)
  3305. {
  3306. TStringList * FileList1 = new TStringList();
  3307. try
  3308. {
  3309. FileList1->AddObject(FullFileName, Object);
  3310. TemporarilyDownloadFiles(FileList1,
  3311. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3312. LocalRootDirectory, LocalDirectory, true, true, true);
  3313. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3314. }
  3315. __finally
  3316. {
  3317. delete FileList1;
  3318. }
  3319. switch (ExecuteFileBy)
  3320. {
  3321. case efShell:
  3322. Counter = "RemoteFilesExecuted";
  3323. break;
  3324. case efInternalEditor:
  3325. Counter = "RemoteFilesOpenedInInternalEditor";
  3326. break;
  3327. case efExternalEditor:
  3328. Counter = "RemoteFilesOpenedInExternalEditor";
  3329. break;
  3330. default:
  3331. DebugFail();
  3332. }
  3333. }
  3334. }
  3335. else
  3336. {
  3337. LocalFileName = FullFileName;
  3338. OriginalFileName = ExtractFileName(FullFileName);
  3339. switch (ExecuteFileBy)
  3340. {
  3341. case efShell:
  3342. Counter = "LocalFilesExecuted";
  3343. break;
  3344. case efInternalEditor:
  3345. Counter = "LocalFilesOpenedInInternalEditor";
  3346. break;
  3347. case efExternalEditor:
  3348. Counter = "LocalFilesOpenedInExternalEditor";
  3349. break;
  3350. default:
  3351. DebugFail();
  3352. }
  3353. }
  3354. if (!Handled)
  3355. {
  3356. Configuration->Usage->Inc(Counter);
  3357. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3358. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3359. }
  3360. }
  3361. //---------------------------------------------------------------------------
  3362. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3363. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3364. bool AllSelected, bool OnFocused)
  3365. {
  3366. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3367. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3368. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3369. Side = GetSide(Side);
  3370. TCustomDirView * DView = DirView(Side);
  3371. TStrings * FileList =
  3372. AllSelected ?
  3373. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3374. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3375. try
  3376. {
  3377. DebugAssert(AllSelected || (FileList->Count == 1));
  3378. for (int i = 0; i < FileList->Count; i++)
  3379. {
  3380. UnicodeString ListFileName = FileList->Strings[i];
  3381. UnicodeString FileNameOnly =
  3382. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3383. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3384. if (!DView->ItemIsDirectory(Item))
  3385. {
  3386. UnicodeString FullFileName;
  3387. if (!IsSideLocalBrowser(Side))
  3388. {
  3389. FullFileName = DirView(Side)->Path + ListFileName;
  3390. }
  3391. else
  3392. {
  3393. FullFileName = ListFileName;
  3394. }
  3395. TFileMasks::TParams MaskParams;
  3396. MaskParams.Size = DView->ItemFileSize(Item);
  3397. TDateTimePrecision Precision;
  3398. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3399. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3400. FileList->Objects[i], MaskParams);
  3401. }
  3402. }
  3403. }
  3404. __finally
  3405. {
  3406. delete FileList;
  3407. }
  3408. }
  3409. //---------------------------------------------------------------------------
  3410. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3411. {
  3412. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3413. CopyParam.FileNameCase = ncNoChange;
  3414. CopyParam.PreserveRights = false;
  3415. CopyParam.PreserveReadOnly = false;
  3416. CopyParam.ReplaceInvalidChars = true;
  3417. CopyParam.IncludeFileMask = TFileMasks();
  3418. CopyParam.NewerOnly = false;
  3419. CopyParam.FileMask = L"";
  3420. }
  3421. //---------------------------------------------------------------------------
  3422. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3423. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3424. {
  3425. TTerminalManager * Manager = TTerminalManager::Instance();
  3426. if (!IsActiveTerminal(Data->Terminal))
  3427. {
  3428. if (!NonVisualDataModule->Busy)
  3429. {
  3430. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3431. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3432. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3433. if (Data->Terminal == NULL)
  3434. {
  3435. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3436. if (SameSiteTerminal != NULL)
  3437. {
  3438. UnicodeString Message =
  3439. FMTLOAD(EDIT_SESSION_REATTACH,
  3440. (FileNameOnly, Data->SessionName, FileNameOnly));
  3441. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3442. {
  3443. Data->Terminal = Terminal;
  3444. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3445. Data->SessionName = Terminal->SessionData->SessionName;
  3446. // We might also overwrite session data
  3447. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3448. }
  3449. else
  3450. {
  3451. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3452. Abort();
  3453. }
  3454. }
  3455. }
  3456. // foreground session should reconnect itself
  3457. else if (Terminal != Data->Terminal)
  3458. {
  3459. UnicodeString Message =
  3460. MainInstructions(
  3461. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3462. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3463. {
  3464. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3465. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3466. }
  3467. else
  3468. {
  3469. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3470. Abort();
  3471. }
  3472. }
  3473. }
  3474. if (!IsActiveTerminal(Data->Terminal))
  3475. {
  3476. Configuration->Usage->Inc(L"EditInactiveSession");
  3477. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3478. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3479. (ExtractFileName(FileName), Data->SessionName)));
  3480. }
  3481. }
  3482. TStrings * FileList = new TStringList();
  3483. try
  3484. {
  3485. FileList->Add(FileName);
  3486. // consider using the same settings (preset) as when the file was downloaded
  3487. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3488. TemporaryFileCopyParam(CopyParam);
  3489. if (Data->ForceText)
  3490. {
  3491. CopyParam.TransferMode = tmAscii;
  3492. }
  3493. // so i do not need to worry if masking algorithm works in all cases
  3494. // ("" means "copy file name", no masking is actually done)
  3495. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3496. {
  3497. CopyParam.FileMask = L"";
  3498. }
  3499. else
  3500. {
  3501. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3502. }
  3503. DebugAssert(Data->Queue != NULL);
  3504. int Params = cpNoConfirmation | cpTemporary;
  3505. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3506. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3507. QueueItem->CompleteEvent = UploadCompleteEvent;
  3508. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3509. }
  3510. __finally
  3511. {
  3512. delete FileList;
  3513. }
  3514. }
  3515. //---------------------------------------------------------------------------
  3516. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3517. const UnicodeString FileName, const TEditedFileData * Data)
  3518. {
  3519. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3520. DebugAssert(!NonVisualDataModule->Busy);
  3521. if (!IsActiveTerminal(Data->Terminal))
  3522. {
  3523. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3524. (ExtractFileName(FileName), Data->SessionName)));
  3525. }
  3526. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3527. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3528. NonVisualDataModule->StartBusy();
  3529. try
  3530. {
  3531. std::unique_ptr<TRemoteFile> File;
  3532. UnicodeString RemoteFileName =
  3533. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3534. FTerminal->ExceptionOnFail = true;
  3535. try
  3536. {
  3537. TRemoteFile * AFile = NULL;
  3538. FTerminal->ReadFile(RemoteFileName, AFile);
  3539. File.reset(AFile);
  3540. if (!File->HaveFullFileName)
  3541. {
  3542. File->FullFileName = RemoteFileName;
  3543. }
  3544. }
  3545. __finally
  3546. {
  3547. FTerminal->ExceptionOnFail = false;
  3548. }
  3549. std::unique_ptr<TStrings> FileList(new TStringList());
  3550. FileList->AddObject(RemoteFileName, File.get());
  3551. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3552. UnicodeString TempDir = ExtractFilePath(FileName);
  3553. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3554. TempDir, true, true, true);
  3555. // sanity check, the target file name should be still the same
  3556. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3557. }
  3558. __finally
  3559. {
  3560. NonVisualDataModule->EndBusy();
  3561. // it actually may not exist anymore...
  3562. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3563. }
  3564. }
  3565. //---------------------------------------------------------------------------
  3566. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3567. const TEditedFileData * Data, bool & KeepOpen)
  3568. {
  3569. // Command is set for external editors only (not for "shell" open).
  3570. if (!Data->Command.IsEmpty())
  3571. {
  3572. bool AnyFound = false;
  3573. bool AnyMDI = false;
  3574. bool AnyNonMDI = false;
  3575. bool AnyDetect = false;
  3576. TEditorList * EditorList = new TEditorList();
  3577. try
  3578. {
  3579. *EditorList = *WinConfiguration->EditorList;
  3580. for (int i = 0; i < EditorList->Count; i++)
  3581. {
  3582. const TEditorPreferences * Editor = EditorList->Editors[i];
  3583. if ((Editor->Data->Editor == edExternal) &&
  3584. (Editor->Data->ExternalEditor == Data->Command))
  3585. {
  3586. AnyFound = true;
  3587. if (Editor->Data->SDIExternalEditor)
  3588. {
  3589. AnyNonMDI = true;
  3590. if (Editor->Data->DetectMDIExternalEditor)
  3591. {
  3592. AnyDetect = true;
  3593. }
  3594. }
  3595. else
  3596. {
  3597. AnyMDI = true;
  3598. }
  3599. }
  3600. }
  3601. bool EnableMDI = false;
  3602. bool DisableDetect = false;
  3603. if (AnyMDI)
  3604. {
  3605. KeepOpen = true;
  3606. if (AnyNonMDI)
  3607. {
  3608. // there is at least one instance of the editor with MDI support enabled,
  3609. // and one with disabled, enable it for all instances
  3610. EnableMDI = true;
  3611. }
  3612. }
  3613. else if (AnyFound && !AnyDetect)
  3614. {
  3615. // at least once instance found but all have MDI autodetection disabled
  3616. // => close the file (default action)
  3617. }
  3618. else
  3619. {
  3620. // no instance of the editor has MDI support enabled
  3621. TMessageParams Params;
  3622. if (AnyFound)
  3623. {
  3624. // there is at least one instance of the editor
  3625. Params.Params |= mpNeverAskAgainCheck;
  3626. }
  3627. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3628. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3629. switch (Answer)
  3630. {
  3631. case qaNeverAskAgain:
  3632. DisableDetect = true;
  3633. break;
  3634. case qaNo:
  3635. EnableMDI = true;
  3636. KeepOpen = true;
  3637. break;
  3638. }
  3639. }
  3640. if (AnyFound && (EnableMDI || DisableDetect))
  3641. {
  3642. bool Changed = false;
  3643. for (int i = 0; i < EditorList->Count; i++)
  3644. {
  3645. const TEditorPreferences * Editor = EditorList->Editors[i];
  3646. if ((Editor->Data->Editor == edExternal) &&
  3647. (Editor->Data->ExternalEditor == Data->Command) &&
  3648. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3649. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3650. {
  3651. Changed = true;
  3652. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3653. if (EnableMDI)
  3654. {
  3655. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3656. }
  3657. if (DisableDetect)
  3658. {
  3659. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3660. }
  3661. EditorList->Change(i, UpdatedEditor);
  3662. }
  3663. }
  3664. if (Changed)
  3665. {
  3666. WinConfiguration->EditorList = EditorList;
  3667. }
  3668. }
  3669. }
  3670. __finally
  3671. {
  3672. delete EditorList;
  3673. }
  3674. }
  3675. else
  3676. {
  3677. // "open" case
  3678. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3679. qaOK, HELP_APP_EARLY_CLOSED);
  3680. }
  3681. }
  3682. //---------------------------------------------------------------------------
  3683. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3684. {
  3685. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3686. }
  3687. //---------------------------------------------------------------------------
  3688. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3689. {
  3690. SideEnter(osRemote);
  3691. }
  3692. //---------------------------------------------------------------------------
  3693. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3694. {
  3695. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3696. SideEnter(osRemote);
  3697. }
  3698. //---------------------------------------------------------------------------
  3699. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3700. {
  3701. FCurrentSide = Side;
  3702. if (Visible)
  3703. {
  3704. UpdateControls();
  3705. }
  3706. }
  3707. //---------------------------------------------------------------------------
  3708. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3709. TStrings * FileList, bool Alternative)
  3710. {
  3711. TCustomDirView * DView = DirView(Side);
  3712. DView->SaveSelection();
  3713. DView->SaveSelectedNames();
  3714. DebugAssert(!FAlternativeDelete);
  3715. FAlternativeDelete = Alternative;
  3716. try
  3717. {
  3718. if (!IsSideLocalBrowser(Side))
  3719. {
  3720. DebugAssert(Terminal != NULL);
  3721. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3722. }
  3723. else
  3724. {
  3725. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  3726. FProgressSide = FCurrentSide;
  3727. try
  3728. {
  3729. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3730. }
  3731. __finally
  3732. {
  3733. ReloadLocalDirectory();
  3734. }
  3735. }
  3736. FAlternativeDelete = false;
  3737. }
  3738. catch(...)
  3739. {
  3740. FAlternativeDelete = false;
  3741. DView->DiscardSavedSelection();
  3742. throw;
  3743. }
  3744. DView->RestoreSelection();
  3745. }
  3746. //---------------------------------------------------------------------------
  3747. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3748. {
  3749. DebugAssert(Terminal);
  3750. DebugAssert(!IsLocalBrowserMode());
  3751. RemoteDirView->SaveSelection();
  3752. RemoteDirView->SaveSelectedNames();
  3753. try
  3754. {
  3755. if (Lock)
  3756. {
  3757. Terminal->LockFiles(FileList);
  3758. }
  3759. else
  3760. {
  3761. Terminal->UnlockFiles(FileList);
  3762. }
  3763. }
  3764. catch(...)
  3765. {
  3766. RemoteDirView->DiscardSavedSelection();
  3767. throw;
  3768. }
  3769. RemoteDirView->RestoreSelection();
  3770. }
  3771. //---------------------------------------------------------------------------
  3772. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3773. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3774. bool NoConfirmation, bool Move)
  3775. {
  3776. DebugAssert(Terminal != NULL);
  3777. DebugAssert(!IsLocalBrowserMode());
  3778. // update Terminal->StateData->RemoteDirectory
  3779. UpdateTerminal(Terminal);
  3780. if (Session == NULL)
  3781. {
  3782. Session = TTerminalManager::Instance()->ActiveTerminal;
  3783. }
  3784. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3785. {
  3786. if (RemoteDriveView->DropTarget != NULL)
  3787. {
  3788. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3789. }
  3790. else if (RemoteDirView->DropTarget != NULL)
  3791. {
  3792. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3793. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3794. }
  3795. else
  3796. {
  3797. Target = RemoteDirView->Path;
  3798. }
  3799. }
  3800. else
  3801. {
  3802. Target = Session->StateData->RemoteDirectory;
  3803. }
  3804. Target = UnixIncludeTrailingBackslash(Target);
  3805. if (FileList->Count == 1)
  3806. {
  3807. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3808. }
  3809. else
  3810. {
  3811. FileMask = AnyMask;
  3812. }
  3813. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3814. bool Result = true;
  3815. if (!NoConfirmation)
  3816. {
  3817. bool Multi = (FileList->Count > 1);
  3818. if (Move)
  3819. {
  3820. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3821. }
  3822. else
  3823. {
  3824. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3825. TStrings * Directories = new TStringList;
  3826. try
  3827. {
  3828. for (int Index = 0; Index < Sessions->Count; Index++)
  3829. {
  3830. TManagedTerminal * Terminal =
  3831. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3832. Directories->Add(Terminal->StateData->RemoteDirectory);
  3833. }
  3834. TDirectRemoteCopy AllowDirectCopy;
  3835. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3836. {
  3837. DebugAssert(DirectCopy);
  3838. AllowDirectCopy = drcAllow;
  3839. }
  3840. else if (FTerminal->IsCapable[fcSecondaryShell])
  3841. {
  3842. DebugAssert(DirectCopy);
  3843. AllowDirectCopy = drcConfirmCommandSession;
  3844. }
  3845. else
  3846. {
  3847. DebugAssert(!DirectCopy);
  3848. AllowDirectCopy = drcDisallow;
  3849. }
  3850. void * ASession = Session;
  3851. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3852. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3853. Session = static_cast<TManagedTerminal *>(ASession);
  3854. }
  3855. __finally
  3856. {
  3857. delete Directories;
  3858. }
  3859. }
  3860. }
  3861. return Result;
  3862. }
  3863. //---------------------------------------------------------------------------
  3864. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3865. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3866. {
  3867. DebugAssert(!IsLocalBrowserMode());
  3868. bool DirectCopy;
  3869. UnicodeString Target, FileMask;
  3870. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3871. if (Result)
  3872. {
  3873. if (!Move && !DirectCopy)
  3874. {
  3875. Configuration->Usage->Inc("RemoteCopyTemp");
  3876. UnicodeString RootTempDir;
  3877. UnicodeString TempDir;
  3878. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3879. TStrings * TemporaryFilesList = new TStringList();
  3880. try
  3881. {
  3882. TMakeLocalFileListParams MakeFileListParam;
  3883. MakeFileListParam.FileList = TemporaryFilesList;
  3884. MakeFileListParam.FileTimes = NULL;
  3885. MakeFileListParam.IncludeDirs = true;
  3886. MakeFileListParam.Recursive = false;
  3887. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3888. TTerminalManager::Instance()->ActiveTerminal = Session;
  3889. if (TemporaryFilesList->Count > 0)
  3890. {
  3891. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3892. CopyParam.FileMask = FileMask;
  3893. DebugAssert(!FAutoOperation);
  3894. FAutoOperation = true;
  3895. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3896. }
  3897. }
  3898. __finally
  3899. {
  3900. delete TemporaryFilesList;
  3901. FAutoOperation = false;
  3902. if (!RootTempDir.IsEmpty())
  3903. {
  3904. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3905. }
  3906. }
  3907. }
  3908. else
  3909. {
  3910. RemoteDirView->SaveSelection();
  3911. RemoteDirView->SaveSelectedNames();
  3912. try
  3913. {
  3914. if (Move)
  3915. {
  3916. Configuration->Usage->Inc("RemoteMove");
  3917. Terminal->MoveFiles(FileList, Target, FileMask);
  3918. }
  3919. else
  3920. {
  3921. Configuration->Usage->Inc("RemoteCopyDirect");
  3922. DebugAssert(DirectCopy);
  3923. DebugAssert(Session == FTerminal);
  3924. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3925. FTerminal->CommandSessionOpened ||
  3926. CommandSessionFallback())
  3927. {
  3928. Terminal->CopyFiles(FileList, Target, FileMask);
  3929. }
  3930. }
  3931. }
  3932. catch(...)
  3933. {
  3934. RemoteDirView->DiscardSavedSelection();
  3935. throw;
  3936. }
  3937. RemoteDirView->RestoreSelection();
  3938. }
  3939. }
  3940. return Result;
  3941. }
  3942. //---------------------------------------------------------------------------
  3943. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3944. const UnicodeString & Path, TRemoteProperties & Properties)
  3945. {
  3946. DebugAssert(!IsLocalBrowserMode());
  3947. Properties.Valid = Properties.Valid << vpEncrypt;
  3948. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3949. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3950. }
  3951. //---------------------------------------------------------------------------
  3952. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3953. {
  3954. Side = GetSide(Side);
  3955. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3956. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3957. UnicodeString Name = LoadStr(NEW_FOLDER);
  3958. int AllowedChanges =
  3959. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3960. bool SaveSettings = false;
  3961. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3962. {
  3963. TWindowLock Lock(this);
  3964. if (!IsSideLocalBrowser(Side))
  3965. {
  3966. if (SaveSettings)
  3967. {
  3968. GUIConfiguration->NewDirectoryProperties = Properties;
  3969. }
  3970. CreateRemoteDirectory(Name, Properties);
  3971. }
  3972. else
  3973. {
  3974. DirView(Side)->CreateDirectory(Name);
  3975. }
  3976. }
  3977. }
  3978. //---------------------------------------------------------------------------
  3979. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3980. {
  3981. TWindowLock Lock(this);
  3982. DirView(Side)->ExecuteHomeDirectory();
  3983. }
  3984. //---------------------------------------------------------------------------
  3985. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3986. {
  3987. DoOpenDirectoryDialog(odBrowse, Side);
  3988. }
  3989. //---------------------------------------------------------------------------
  3990. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3991. {
  3992. UnicodeString Path = Bookmark->GetSideDirectory(Side);
  3993. bool Result = !Path.IsEmpty();
  3994. if (Result)
  3995. {
  3996. // While we might get here when the session is closed (from location profiles),
  3997. // it's not a problem as the Path setter is noop then
  3998. DirView(Side)->Path = Path;
  3999. }
  4000. return Result;
  4001. }
  4002. //---------------------------------------------------------------------------
  4003. void __fastcall TCustomScpExplorerForm::CalculateSize(
  4004. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  4005. bool & Close)
  4006. {
  4007. // terminal can be already closed (e.g. dropped connection)
  4008. if (Terminal != NULL)
  4009. {
  4010. try
  4011. {
  4012. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  4013. }
  4014. catch(...)
  4015. {
  4016. if (!Terminal->Active)
  4017. {
  4018. Close = true;
  4019. }
  4020. throw;
  4021. }
  4022. }
  4023. }
  4024. //---------------------------------------------------------------------------
  4025. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4026. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4027. bool & Close)
  4028. {
  4029. // terminal can be already closed (e.g. dropped connection)
  4030. if (Terminal != NULL)
  4031. {
  4032. Configuration->Usage->Inc(L"ChecksumCalculated");
  4033. try
  4034. {
  4035. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4036. }
  4037. catch(...)
  4038. {
  4039. if (!Terminal->Active)
  4040. {
  4041. Close = true;
  4042. }
  4043. throw;
  4044. }
  4045. }
  4046. }
  4047. //---------------------------------------------------------------------------
  4048. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4049. {
  4050. bool Result;
  4051. if (!IsSideLocalBrowser(Side))
  4052. {
  4053. TRemoteTokenList * GroupList = NULL;
  4054. TRemoteTokenList * UserList = NULL;
  4055. try
  4056. {
  4057. TRemoteProperties CurrentProperties;
  4058. if (Terminal->LoadFilesProperties(FileList))
  4059. {
  4060. RemoteDirView->Invalidate();
  4061. }
  4062. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4063. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4064. if (CapableGroupChanging || CapableOwnerChanging)
  4065. {
  4066. if (CapableGroupChanging)
  4067. {
  4068. GroupList = Terminal->Groups->Duplicate();
  4069. }
  4070. if (CapableOwnerChanging)
  4071. {
  4072. UserList = Terminal->Users->Duplicate();
  4073. }
  4074. TRemoteDirectory * Files = Terminal->Files;
  4075. int Count = Files->Count;
  4076. if (Count > 100)
  4077. {
  4078. Count = 100;
  4079. }
  4080. for (int Index = 0; Index < Count; Index++)
  4081. {
  4082. TRemoteFile * File = Files->Files[Index];
  4083. if (CapableGroupChanging)
  4084. {
  4085. GroupList->AddUnique(File->Group);
  4086. }
  4087. if (CapableOwnerChanging)
  4088. {
  4089. UserList->AddUnique(File->Owner);
  4090. }
  4091. }
  4092. // if we haven't collected tokens for all files in current directory,
  4093. // make sure we collect them at least for all selected files.
  4094. // (note that so far the files in FileList has to be from current direcotry)
  4095. if (Count < Files->Count)
  4096. {
  4097. for (int Index = 0; Index < FileList->Count; Index++)
  4098. {
  4099. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4100. if (CapableGroupChanging)
  4101. {
  4102. GroupList->AddUnique(File->Group);
  4103. }
  4104. if (CapableOwnerChanging)
  4105. {
  4106. UserList->AddUnique(File->Owner);
  4107. }
  4108. }
  4109. }
  4110. }
  4111. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4112. int Flags = 0;
  4113. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4114. if (CapableOwnerChanging) Flags |= cpOwner;
  4115. if (CapableGroupChanging) Flags |= cpGroup;
  4116. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4117. if (Terminal->IsCapable[fcCalculatingChecksum])
  4118. {
  4119. CalculateChecksumEvent = CalculateChecksum;
  4120. }
  4121. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4122. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4123. TRemoteProperties NewProperties = CurrentProperties;
  4124. Result =
  4125. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4126. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4127. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4128. CalculateSize, CalculateChecksumEvent);
  4129. if (Result)
  4130. {
  4131. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4132. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4133. }
  4134. }
  4135. __finally
  4136. {
  4137. delete GroupList;
  4138. delete UserList;
  4139. }
  4140. }
  4141. else
  4142. {
  4143. DirView(Side)->DisplayPropertiesMenu();
  4144. Result = true;
  4145. }
  4146. return Result;
  4147. }
  4148. //---------------------------------------------------------------------------
  4149. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4150. {
  4151. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4152. {
  4153. FIgnoreNextDialogChar = Key;
  4154. }
  4155. Key = 0;
  4156. }
  4157. //---------------------------------------------------------------------------
  4158. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4159. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4160. {
  4161. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4162. if (Command != NULL)
  4163. {
  4164. KeyProcessed(Key, Shift);
  4165. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4166. {
  4167. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4168. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4169. false, false, const_cast<TCustomCommandType *>(Command));
  4170. }
  4171. }
  4172. }
  4173. //---------------------------------------------------------------------------
  4174. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4175. {
  4176. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4177. {
  4178. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4179. }
  4180. if (!DirView(osCurrent)->IsEditing())
  4181. {
  4182. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4183. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4184. {
  4185. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4186. // But so far it's not a problem, as it does what we want.
  4187. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4188. if (((Action->ShortCut == KeyShortCut) ||
  4189. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4190. AllowedAction(Action, aaShortCut))
  4191. {
  4192. // Has to be called before the action as the dialog char is already in queue.
  4193. // So when the action consumes message queue, we already need to have the
  4194. // FIgnoreNextDialogChar set
  4195. KeyProcessed(Key, Shift);
  4196. // Reset reference to previous component (when menu/toolbar was clicked).
  4197. // Needed to detect that action was invoked by keyboard shortcut
  4198. // in TNonVisualDataModule::ExplorerActionsExecute
  4199. Action->ActionComponent = NULL;
  4200. Action->Execute();
  4201. return;
  4202. }
  4203. }
  4204. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4205. {
  4206. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4207. {
  4208. KeyProcessed(Key, Shift);
  4209. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4210. return;
  4211. }
  4212. }
  4213. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4214. {
  4215. KeyProcessed(Key, Shift);
  4216. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4217. }
  4218. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4219. if (IsCustomShortCut(CustomShortCut))
  4220. {
  4221. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4222. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4223. if (WinConfiguration->SharedBookmarks != NULL)
  4224. {
  4225. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4226. if ((Bookmark != NULL) &&
  4227. OpenBookmark(FCurrentSide, Bookmark))
  4228. {
  4229. KeyProcessed(Key, Shift);
  4230. }
  4231. }
  4232. }
  4233. }
  4234. TForm::KeyDown(Key, Shift);
  4235. }
  4236. //---------------------------------------------------------------------------
  4237. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4238. {
  4239. DebugAssert(Terminal != NULL);
  4240. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4241. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4242. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4243. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4244. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4245. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4246. // expanded from ?: to avoid memory leaks
  4247. if (SecurityEnabled)
  4248. {
  4249. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4250. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4251. }
  4252. else
  4253. {
  4254. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4255. }
  4256. if (FileSystemInfo.ProtocolName.IsEmpty())
  4257. {
  4258. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4259. }
  4260. else
  4261. {
  4262. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4263. }
  4264. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4265. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4266. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4267. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4268. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4269. UnicodeString CompressionStr = CSCompressionStr;
  4270. if (CSCompressionStr != SCCompressionStr)
  4271. {
  4272. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4273. }
  4274. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4275. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4276. UpdateStatusBar();
  4277. }
  4278. //---------------------------------------------------------------------------
  4279. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4280. {
  4281. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4282. DebugAssert(SessionStatusBar != NULL);
  4283. if (!HasActiveTerminal() || (Terminal->Status < ssOpened))
  4284. {
  4285. // note: (Terminal->Status < sshReady) currently never happens here,
  4286. // so STATUS_CONNECTING is never used
  4287. SessionStatusBar->SimplePanel = true;
  4288. SessionStatusBar->SimpleText = LoadStr(
  4289. !HasActiveTerminal() ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4290. }
  4291. else
  4292. {
  4293. DebugAssert(Terminal);
  4294. SessionStatusBar->SimplePanel = false;
  4295. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4296. if (!FNote.IsEmpty())
  4297. {
  4298. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4299. }
  4300. else
  4301. {
  4302. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4303. }
  4304. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4305. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4306. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4307. }
  4308. }
  4309. //---------------------------------------------------------------------------
  4310. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4311. {
  4312. Panel->Caption = L"";
  4313. }
  4314. //---------------------------------------------------------------------------
  4315. void __fastcall TCustomScpExplorerForm::Idle()
  4316. {
  4317. if (FShowing || FStandaloneEditing)
  4318. {
  4319. FEditorManager->Check();
  4320. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4321. // that needs to know if queue view is visible (and it may be closed after queue update)
  4322. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4323. }
  4324. if (FShowing)
  4325. {
  4326. if (!NonVisualDataModule->Busy &&
  4327. // Menu is opened or drag&drop is going on
  4328. (Mouse->Capture == NULL))
  4329. {
  4330. if (FRefreshRemoteDirectory)
  4331. {
  4332. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4333. {
  4334. Terminal->RefreshDirectory();
  4335. }
  4336. FRefreshRemoteDirectory = false;
  4337. }
  4338. if (FRefreshLocalDirectory)
  4339. {
  4340. ReloadLocalDirectory();
  4341. FRefreshLocalDirectory = false;
  4342. }
  4343. if (WinConfiguration->RefreshRemotePanel)
  4344. {
  4345. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4346. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4347. {
  4348. RemoteDirView->ReloadDirectory();
  4349. }
  4350. }
  4351. }
  4352. }
  4353. if (FShowing || FStandaloneEditing)
  4354. {
  4355. if (FQueueStatusInvalidated)
  4356. {
  4357. UpdateQueueStatus(false);
  4358. }
  4359. RefreshQueueItems();
  4360. }
  4361. if (FShowing)
  4362. {
  4363. UpdateStatusBar();
  4364. }
  4365. FIgnoreNextDialogChar = 0;
  4366. }
  4367. //---------------------------------------------------------------------------
  4368. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4369. {
  4370. try
  4371. {
  4372. FUserActionTimer->Enabled = false;
  4373. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4374. {
  4375. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4376. {
  4377. FPendingQueueActionItem->ProcessUserAction();
  4378. }
  4379. }
  4380. }
  4381. __finally
  4382. {
  4383. FPendingQueueActionItem = NULL;
  4384. }
  4385. }
  4386. //---------------------------------------------------------------------------
  4387. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4388. {
  4389. if (WinConfiguration->MinimizeToTray)
  4390. {
  4391. UpdateTrayIcon();
  4392. FTrayIcon->Visible = true;
  4393. if (Visible)
  4394. {
  4395. ShowWindow(Handle, SW_HIDE);
  4396. }
  4397. }
  4398. }
  4399. //---------------------------------------------------------------------------
  4400. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4401. {
  4402. // WORKAROUND
  4403. // When restoring maximized window from minimization,
  4404. // rarely some controls do not align properly.
  4405. // Two instances seen (both for Commander):
  4406. // - When restoring, window is temporarily narrower (not maximized),
  4407. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4408. // Once maximized already, top dock shinks back, but the session PageControl,
  4409. // do not align up, leaving space between TopDock and PageControl.
  4410. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4411. for (int Index = 0; Index < ControlCount; Index++)
  4412. {
  4413. RealignControl(Controls[Index]);
  4414. }
  4415. if (FTrayIcon->Visible)
  4416. {
  4417. FTrayIcon->Visible = false;
  4418. if (Visible)
  4419. {
  4420. ShowWindow(Handle, SW_SHOW);
  4421. }
  4422. }
  4423. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4424. {
  4425. FNeedSession = false;
  4426. NonVisualDataModule->StartBusy();
  4427. try
  4428. {
  4429. NeedSession(true);
  4430. }
  4431. __finally
  4432. {
  4433. NonVisualDataModule->EndBusy();
  4434. }
  4435. }
  4436. }
  4437. //---------------------------------------------------------------------------
  4438. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4439. {
  4440. FTrayIcon->Hint = GetMainForm()->Caption;
  4441. }
  4442. //---------------------------------------------------------------------------
  4443. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4444. {
  4445. UpdateTrayIcon();
  4446. }
  4447. //---------------------------------------------------------------------------
  4448. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4449. {
  4450. // workaround
  4451. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4452. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4453. // But WM_ACTIVATEAPP message can be received even when
  4454. // the main window is minimized to the tray and internal editor window is focused
  4455. // (after another application was previously active)
  4456. if (::IsIconic(Handle))
  4457. {
  4458. if (!IsAppIconic())
  4459. {
  4460. SetAppIconic(true);
  4461. }
  4462. }
  4463. ::ApplicationRestore();
  4464. Application->BringToFront();
  4465. }
  4466. //---------------------------------------------------------------------------
  4467. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4468. {
  4469. RestoreApp();
  4470. }
  4471. //---------------------------------------------------------------------------
  4472. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4473. {
  4474. if (OpenInNewWindow())
  4475. {
  4476. // todo: Pass FromSite
  4477. ExecuteNewInstance(SessionUrl);
  4478. }
  4479. else
  4480. {
  4481. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4482. }
  4483. }
  4484. //---------------------------------------------------------------------------
  4485. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4486. {
  4487. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4488. StoredSessions->NewSession(SessionName, SessionData);
  4489. // modified only, explicit
  4490. StoredSessions->Save(false, true);
  4491. // encode session name because of slashes in hierarchical sessions
  4492. return EncodeUrlString(SessionName);
  4493. }
  4494. //---------------------------------------------------------------------------
  4495. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4496. {
  4497. // current working directories become defaults here, what is not right
  4498. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4499. return SaveHiddenDuplicateSession(SessionData.get());
  4500. }
  4501. //---------------------------------------------------------------------------
  4502. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4503. {
  4504. if (OpenInNewWindow())
  4505. {
  4506. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4507. }
  4508. else
  4509. {
  4510. // current working directories become defaults here, what is not right
  4511. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4512. TTerminalManager * Manager = TTerminalManager::Instance();
  4513. TManagedTerminal * Terminal = Manager->NewManagedTerminal(SessionData.get());
  4514. Manager->ActiveTerminal = Terminal;
  4515. }
  4516. }
  4517. //---------------------------------------------------------------------------
  4518. void __fastcall TCustomScpExplorerForm::RenameSession()
  4519. {
  4520. UnicodeString Name = Terminal->SessionData->SessionName;
  4521. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4522. {
  4523. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4524. TSessionData::ValidateName(Name);
  4525. // This is inconsistent with how color (for example) is handled.
  4526. Terminal->SessionData->Name = Name;
  4527. UpdateControls();
  4528. // Add/Remove distinguishing paths from sessions of the same name.
  4529. DoTerminalListChanged();
  4530. }
  4531. }
  4532. //---------------------------------------------------------------------------
  4533. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4534. {
  4535. DebugAssert(Queue != NULL);
  4536. bool Result = Queue->IsEmpty;
  4537. if (!Result)
  4538. {
  4539. SetFocus();
  4540. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4541. }
  4542. return Result;
  4543. }
  4544. //---------------------------------------------------------------------------
  4545. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4546. {
  4547. return CanCloseQueue(FQueue);
  4548. }
  4549. //---------------------------------------------------------------------------
  4550. void __fastcall TCustomScpExplorerForm::CloseSession()
  4551. {
  4552. if (CanCloseQueue())
  4553. {
  4554. TTerminalManager::Instance()->FreeActiveTerminal();
  4555. }
  4556. }
  4557. //---------------------------------------------------------------------------
  4558. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4559. {
  4560. if (CanCloseQueue())
  4561. {
  4562. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4563. }
  4564. }
  4565. //---------------------------------------------------------------------------
  4566. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4567. {
  4568. DetachTerminal(Terminal);
  4569. RemoteDirView->Terminal = Terminal;
  4570. UpdateRemotePathComboBox(false);
  4571. UpdateControls();
  4572. }
  4573. //---------------------------------------------------------------------------
  4574. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4575. {
  4576. if (DebugAlwaysTrue(!Terminal->Active))
  4577. {
  4578. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4579. }
  4580. }
  4581. //---------------------------------------------------------------------------
  4582. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4583. {
  4584. if (OpenInNewWindow())
  4585. {
  4586. // encode session name because of slashes in hierarchical sessions
  4587. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4588. }
  4589. else
  4590. {
  4591. TTerminalManager * Manager = TTerminalManager::Instance();
  4592. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4593. Manager->ActiveTerminal = Terminal;
  4594. }
  4595. }
  4596. //---------------------------------------------------------------------------
  4597. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4598. {
  4599. TTerminalManager * Manager = TTerminalManager::Instance();
  4600. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4601. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4602. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4603. // FirstTerminal can be null, if some of the
  4604. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4605. {
  4606. FirstTerminal->Disconnected = true;
  4607. FirstTerminal->DisconnectedTemporarily = true;
  4608. }
  4609. Manager->ActiveTerminal = FirstTerminal;
  4610. }
  4611. //---------------------------------------------------------------------------
  4612. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4613. {
  4614. if (OpenInNewWindow())
  4615. {
  4616. ExecuteNewInstance(Name);
  4617. }
  4618. else
  4619. {
  4620. DoOpenFolderOrWorkspace(Name, true);
  4621. }
  4622. }
  4623. //---------------------------------------------------------------------------
  4624. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4625. bool &CanClose)
  4626. {
  4627. // See the comment in CloseApp()
  4628. if (NonVisualDataModule->Busy)
  4629. {
  4630. CanClose = false;
  4631. }
  4632. else if (Terminal != NULL)
  4633. {
  4634. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4635. {
  4636. unsigned int Result;
  4637. TMessageParams Params(mpNeverAskAgainCheck);
  4638. UnicodeString Message;
  4639. int Answers = qaOK | qaCancel;
  4640. if (TTerminalManager::Instance()->Count > 1)
  4641. {
  4642. if (!WinConfiguration->AutoSaveWorkspace)
  4643. {
  4644. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4645. }
  4646. else
  4647. {
  4648. Message = LoadStr(CLOSE_SESSIONS);
  4649. }
  4650. }
  4651. else
  4652. {
  4653. if (!WinConfiguration->AutoSaveWorkspace)
  4654. {
  4655. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4656. }
  4657. else
  4658. {
  4659. Message = LoadStr(CLOSE_SESSION);
  4660. }
  4661. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4662. }
  4663. UnicodeString Note;
  4664. if (WinConfiguration->AutoSaveWorkspace)
  4665. {
  4666. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4667. }
  4668. else
  4669. {
  4670. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4671. Answers = qaYes | qaNo | qaCancel;
  4672. }
  4673. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4674. SetFocus();
  4675. Result = MessageDialog(Message, qtConfirmation,
  4676. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4677. if (Result == qaNeverAskAgain)
  4678. {
  4679. WinConfiguration->ConfirmClosingSession = false;
  4680. }
  4681. if (Result == qaNo)
  4682. {
  4683. CanClose = SaveWorkspace(true);
  4684. // note that the workspace will be saved redundatly again from FormClose
  4685. }
  4686. else
  4687. {
  4688. CanClose =
  4689. (Result == qaOK) ||
  4690. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4691. (Result == qaNeverAskAgain);
  4692. }
  4693. }
  4694. if (CanClose)
  4695. {
  4696. CanClose = CanCloseQueue();
  4697. }
  4698. }
  4699. if (CanClose)
  4700. {
  4701. CanClose =
  4702. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4703. FEditorManager->CloseExternalFilesWithoutProcess();
  4704. if (CanClose)
  4705. {
  4706. while (CanClose && (FLocalEditors->Count > 0))
  4707. {
  4708. int PrevCount = FLocalEditors->Count;
  4709. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4710. CanClose = (FLocalEditors->Count < PrevCount);
  4711. }
  4712. if (CanClose)
  4713. {
  4714. CanClose = FEditorManager->Empty(true);
  4715. if (!CanClose)
  4716. {
  4717. SetFocus();
  4718. CanClose =
  4719. (MessageDialog(
  4720. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4721. }
  4722. }
  4723. }
  4724. }
  4725. }
  4726. //---------------------------------------------------------------------------
  4727. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4728. {
  4729. TForm * Form = dynamic_cast<TForm *>(Sender);
  4730. DebugAssert(Form != NULL);
  4731. Form->Close();
  4732. }
  4733. //---------------------------------------------------------------------------
  4734. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4735. {
  4736. TForm * Form = dynamic_cast<TForm *>(Sender);
  4737. delete Form;
  4738. }
  4739. //---------------------------------------------------------------------------
  4740. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4741. {
  4742. while (FLocalEditors->Count > 0)
  4743. {
  4744. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4745. }
  4746. }
  4747. //---------------------------------------------------------------------------
  4748. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4749. TObject *Sender)
  4750. {
  4751. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4752. try
  4753. {
  4754. SetProperties(osRemote, FileList);
  4755. }
  4756. __finally
  4757. {
  4758. delete FileList;
  4759. }
  4760. }
  4761. //---------------------------------------------------------------------------
  4762. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4763. {
  4764. if (value)
  4765. {
  4766. if (Component == fcCustomCommandsBand)
  4767. {
  4768. UpdateCustomCommandsToolbar();
  4769. }
  4770. if (Component == fcQueueFileList)
  4771. {
  4772. DebugAssert(!QueueFileListSplitter->Visible);
  4773. AdjustQueueLayout();
  4774. UpdateQueueFileList();
  4775. }
  4776. }
  4777. }
  4778. //---------------------------------------------------------------------------
  4779. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4780. {
  4781. int MinHeightLimit =
  4782. GetStaticQueuePanelComponentsHeight() +
  4783. QueueFileListSplitter->Height +
  4784. QueueFileList->Height +
  4785. GetMinQueueViewHeight();
  4786. if (QueuePanel->ClientHeight < MinHeightLimit)
  4787. {
  4788. QueuePanel->ClientHeight = MinHeightLimit;
  4789. }
  4790. }
  4791. //---------------------------------------------------------------------------
  4792. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4793. {
  4794. TControl * Control = GetComponent(Component);
  4795. DebugAssert(Control);
  4796. bool Changed = (Control->Visible != value);
  4797. if (Changed)
  4798. {
  4799. ComponentShowing(Component, value);
  4800. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4801. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4802. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4803. if (value)
  4804. {
  4805. int RemainingHeight = Control->Parent->ClientHeight;
  4806. int RemainingWidth = Control->Parent->ClientWidth;
  4807. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4808. {
  4809. TControl * ChildControl = Control->Parent->Controls[i];
  4810. if (ChildControl->Visible)
  4811. {
  4812. switch (ChildControl->Align)
  4813. {
  4814. case alTop:
  4815. case alBottom:
  4816. RemainingHeight -= ChildControl->Height;
  4817. break;
  4818. case alLeft:
  4819. case alRight:
  4820. RemainingWidth -= ChildControl->Width;
  4821. break;
  4822. }
  4823. }
  4824. }
  4825. int Reserve = ScaleByTextHeight(this, 32);
  4826. // queue in explorer, trees in commander
  4827. if (Control->Height > RemainingHeight - Reserve)
  4828. {
  4829. Control->Height = RemainingHeight / 2;
  4830. }
  4831. if (Control->Width > RemainingWidth - Reserve)
  4832. {
  4833. Control->Width = RemainingWidth / 2;
  4834. }
  4835. }
  4836. Control->Visible = value;
  4837. if (WasFocused && Visible)
  4838. {
  4839. DirView(osCurrent)->SetFocus();
  4840. }
  4841. FixControlsPlacement();
  4842. }
  4843. }
  4844. //---------------------------------------------------------------------------
  4845. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4846. {
  4847. TControl * Control = GetComponent(Component);
  4848. if (Control == NULL)
  4849. {
  4850. return false;
  4851. }
  4852. else
  4853. {
  4854. return Control->Visible;
  4855. }
  4856. }
  4857. //---------------------------------------------------------------------------
  4858. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4859. {
  4860. bool Result;
  4861. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4862. {
  4863. Result = !IsUWP();
  4864. }
  4865. else
  4866. {
  4867. Result = true;
  4868. }
  4869. return Result;
  4870. }
  4871. //---------------------------------------------------------------------------
  4872. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  4873. {
  4874. if (DirView->ItemFocused != NULL)
  4875. {
  4876. DirView->ItemFocused->MakeVisible(false);
  4877. }
  4878. }
  4879. //---------------------------------------------------------------------------
  4880. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4881. {
  4882. MakeFocusedItemVisible(RemoteDirView);
  4883. QueueSplitter->Visible = QueuePanel->Visible;
  4884. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4885. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4886. TControl * QueueControlsOrder[] =
  4887. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4888. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4889. }
  4890. //---------------------------------------------------------------------------
  4891. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4892. {
  4893. switch (Component) {
  4894. case fcStatusBar: return RemoteStatusBar;
  4895. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4896. case fcQueueView: return QueuePanel;
  4897. case fcQueueToolbar: return QueueDock;
  4898. case fcRemoteTree: return RemoteDrivePanel;
  4899. case fcSessionsTabs: return SessionsPageControl;
  4900. case fcQueueFileList: return QueueFileList;
  4901. default: return NULL;
  4902. }
  4903. }
  4904. //---------------------------------------------------------------------------
  4905. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4906. TObject *Sender, TListColumn *Column, TPoint &Point)
  4907. {
  4908. DebugAssert(NonVisualDataModule && Column && Sender);
  4909. NonVisualDataModule->ListColumn = Column;
  4910. TPopupMenu * DirViewColumnMenu;
  4911. if (Sender == DirView(osOther))
  4912. {
  4913. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4914. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4915. (Column->Index == uvName);
  4916. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4917. (Column->Index == uvSize);
  4918. }
  4919. else
  4920. {
  4921. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4922. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4923. (Column->Index == dvName);
  4924. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4925. (Column->Index == dvSize);
  4926. }
  4927. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4928. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4929. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4930. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4931. }
  4932. //---------------------------------------------------------------------------
  4933. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4934. TObject *Sender, TListItem *Item, bool &AllowExec)
  4935. {
  4936. DoDirViewExecFile(Sender, Item, AllowExec);
  4937. }
  4938. //---------------------------------------------------------------------------
  4939. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4940. TListItem * Item, bool & AllowExec)
  4941. {
  4942. DebugAssert(Sender && Item && Configuration);
  4943. DebugAssert(AllowExec);
  4944. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4945. bool Remote = (ADirView == DirView(osRemote)) && !IsSideLocalBrowser(osRemote);
  4946. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks;
  4947. TOperationSide Side = (Remote ? osRemote : osLocal); // TODO
  4948. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4949. // on files only (not directories)
  4950. // and only when symlinks are resolved (apply to remote panel only)
  4951. if (!ADirView->ItemIsDirectory(Item) &&
  4952. (ResolvedSymlinks || FForceExecution || Terminal->IsEncryptingFiles()))
  4953. {
  4954. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4955. !FForceExecution &&
  4956. (ResolvedSymlinks || Terminal->IsEncryptingFiles()))
  4957. {
  4958. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4959. {
  4960. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4961. UnlockWindow();
  4962. try
  4963. {
  4964. ExecuteFileOperation(
  4965. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4966. }
  4967. __finally
  4968. {
  4969. LockWindow();
  4970. }
  4971. AllowExec = false;
  4972. }
  4973. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4974. {
  4975. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4976. {
  4977. ExecuteFile(Side, efDefaultEditor);
  4978. AllowExec = false;
  4979. }
  4980. }
  4981. else
  4982. {
  4983. DebugFail();
  4984. }
  4985. }
  4986. // if we have not done anything special, fall back to default behavior
  4987. if (AllowExec)
  4988. {
  4989. if (Remote && !WinConfiguration->DisableOpenEdit)
  4990. {
  4991. ExecuteFile(osRemote, efShell);
  4992. AllowExec = false;
  4993. }
  4994. }
  4995. }
  4996. }
  4997. //---------------------------------------------------------------------------
  4998. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4999. {
  5000. return ((Side == osRemote) || (Side == osCurrent));
  5001. }
  5002. //---------------------------------------------------------------------------
  5003. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5004. {
  5005. DebugFail();
  5006. }
  5007. //---------------------------------------------------------------------------
  5008. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5009. {
  5010. DebugFail();
  5011. }
  5012. //---------------------------------------------------------------------------
  5013. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5014. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5015. {
  5016. TSynchronizeParamType Params;
  5017. Params.LocalDirectory = LocalDirectory;
  5018. Params.RemoteDirectory = RemoteDirectory;
  5019. int UnusedParams =
  5020. (GUIConfiguration->SynchronizeParams &
  5021. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5022. TTerminal::spCaseSensitive));
  5023. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5024. Params.Options = GUIConfiguration->SynchronizeOptions;
  5025. bool SaveSettings = false;
  5026. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5027. &DoSynchronizeTooManyDirectories);
  5028. DebugAssert(FSynchronizeController == NULL);
  5029. FSynchronizeController = &Controller;
  5030. bool Result;
  5031. try
  5032. {
  5033. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5034. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5035. int Options =
  5036. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5037. DebugAssert(FOnFeedSynchronizeError == NULL);
  5038. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5039. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5040. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5041. if (Result)
  5042. {
  5043. if (SaveSettings)
  5044. {
  5045. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5046. GUIConfiguration->SynchronizeOptions = Params.Options;
  5047. }
  5048. else
  5049. {
  5050. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5051. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5052. FLAGSET(Params.Options, soSynchronize))
  5053. {
  5054. GUIConfiguration->SynchronizeOptions =
  5055. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5056. soSynchronize;
  5057. }
  5058. }
  5059. LocalDirectory = Params.LocalDirectory;
  5060. RemoteDirectory = Params.RemoteDirectory;
  5061. }
  5062. }
  5063. __finally
  5064. {
  5065. FSynchronizeController = NULL;
  5066. DebugAssert(FOnFeedSynchronizeError == NULL);
  5067. FOnFeedSynchronizeError = NULL;
  5068. }
  5069. return Result;
  5070. }
  5071. //---------------------------------------------------------------------------
  5072. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5073. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5074. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5075. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5076. TSynchronizeOptions * Options, bool Full)
  5077. {
  5078. // Keep-up-to-date mode
  5079. if (Terminal->Status == ssOpened)
  5080. {
  5081. try
  5082. {
  5083. int PParams = Params.Params;
  5084. if (!Full)
  5085. {
  5086. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5087. if (FLAGSET(Params.Options, soRecurse))
  5088. {
  5089. PParams |= TTerminal::spSubDirs;
  5090. }
  5091. }
  5092. else
  5093. {
  5094. // if keepuptodate is non-recursive,
  5095. // full sync before has to be non-recursive as well
  5096. if (FLAGCLEAR(Params.Options, soRecurse))
  5097. {
  5098. PParams |= TTerminal::spNoRecurse;
  5099. }
  5100. }
  5101. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5102. PParams, Checklist, Options);
  5103. }
  5104. catch (Exception & E)
  5105. {
  5106. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5107. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5108. {
  5109. // noop, already logged in MoreMessageDialog
  5110. }
  5111. else
  5112. {
  5113. ShowExtendedExceptionEx(Terminal, &E);
  5114. throw;
  5115. }
  5116. }
  5117. }
  5118. }
  5119. //---------------------------------------------------------------------------
  5120. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5121. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5122. const UnicodeString ErrorStr)
  5123. {
  5124. if (!Directory.IsEmpty())
  5125. {
  5126. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5127. }
  5128. else
  5129. {
  5130. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5131. }
  5132. }
  5133. //---------------------------------------------------------------------------
  5134. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5135. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5136. {
  5137. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5138. {
  5139. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5140. }
  5141. else
  5142. {
  5143. TMessageParams Params(mpNeverAskAgainCheck);
  5144. unsigned int Result = MessageDialog(
  5145. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5146. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5147. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5148. {
  5149. MaxDirectories *= 2;
  5150. if (Result == qaNeverAskAgain)
  5151. {
  5152. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5153. }
  5154. }
  5155. else
  5156. {
  5157. Abort();
  5158. }
  5159. }
  5160. }
  5161. //---------------------------------------------------------------------------
  5162. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5163. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5164. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5165. TSynchronizeOptions * Options)
  5166. {
  5167. // Keep-up-to-date mode
  5168. DebugAssert(!FAutoOperation);
  5169. void * BatchStorage;
  5170. BatchStart(BatchStorage);
  5171. FAutoOperation = true;
  5172. bool AnyOperation = false;
  5173. TDateTime StartTime = Now();
  5174. TSynchronizeChecklist * AChecklist = NULL;
  5175. try
  5176. {
  5177. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5178. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5179. {
  5180. FSynchronizeProgressForm->Start();
  5181. }
  5182. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5183. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5184. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5185. Options);
  5186. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5187. SAFE_DESTROY(FSynchronizeProgressForm);
  5188. AnyOperation = (AChecklist->CheckedCount > 0);
  5189. if (AnyOperation)
  5190. {
  5191. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5192. CreateProgressForm(&SynchronizeProgress);
  5193. try
  5194. {
  5195. Terminal->SynchronizeApply(
  5196. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5197. SynchronizeProcessedItem, NULL, NULL, NULL);
  5198. }
  5199. __finally
  5200. {
  5201. DestroyProgressForm();
  5202. }
  5203. }
  5204. }
  5205. __finally
  5206. {
  5207. if (Checklist == NULL)
  5208. {
  5209. delete AChecklist;
  5210. }
  5211. else
  5212. {
  5213. *Checklist = AChecklist;
  5214. }
  5215. FAutoOperation = false;
  5216. SAFE_DESTROY(FSynchronizeProgressForm);
  5217. BatchEnd(BatchStorage);
  5218. ReloadLocalDirectory();
  5219. if (AnyOperation)
  5220. {
  5221. OperationComplete(StartTime);
  5222. }
  5223. }
  5224. }
  5225. //---------------------------------------------------------------------------
  5226. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5227. {
  5228. // can be called from command line
  5229. return Visible &&
  5230. ((DirView(osRemote)->SelCount > 0) ||
  5231. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5232. }
  5233. //---------------------------------------------------------------------------
  5234. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5235. {
  5236. LogSynchronizeEvent(Terminal, Message);
  5237. }
  5238. //---------------------------------------------------------------------------
  5239. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5240. int Params, TSynchronizeOptions & Options)
  5241. {
  5242. DebugAssert(!IsLocalBrowserMode());
  5243. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5244. {
  5245. Options.Filter = new TStringList();
  5246. Options.Filter->CaseSensitive = false;
  5247. Options.Filter->Duplicates = Types::dupAccept;
  5248. if (DirView(osRemote)->SelCount > 0)
  5249. {
  5250. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5251. }
  5252. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5253. {
  5254. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5255. }
  5256. Options.Filter->Sort();
  5257. }
  5258. }
  5259. //---------------------------------------------------------------------------
  5260. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5261. {
  5262. TCopyParamType Defaults;
  5263. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5264. ConfigStorage->AccessMode = smRead;
  5265. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5266. {
  5267. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5268. }
  5269. ConfigStorage.reset(NULL);
  5270. std::unique_ptr<TStringList> Options(new TStringList());
  5271. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5272. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5273. UnicodeString Result;
  5274. if (Options->Count > 0)
  5275. {
  5276. Result =
  5277. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5278. }
  5279. return Result;
  5280. }
  5281. //---------------------------------------------------------------------------
  5282. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5283. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5284. {
  5285. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5286. UnicodeString AdditionalParams =
  5287. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5288. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5289. SerializeCopyParamForCommandLine(CopyParams),
  5290. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5291. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5292. ExecuteNewInstance(SessionName, AdditionalParams);
  5293. }
  5294. //---------------------------------------------------------------------------
  5295. struct TSynchronizeParams
  5296. {
  5297. UnicodeString LocalDirectory;
  5298. UnicodeString RemoteDirectory;
  5299. TSynchronizeMode Mode;
  5300. TSynchronizeChecklist * Checklist;
  5301. int Params;
  5302. TCopyParamType * CopyParam;
  5303. TDateTime CollectElapsed;
  5304. TDateTime * StartTime;
  5305. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5306. };
  5307. //---------------------------------------------------------------------------
  5308. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5309. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5310. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5311. {
  5312. DebugAssert(!FAutoOperation);
  5313. void * BatchStorage;
  5314. BatchStart(BatchStorage);
  5315. FAutoOperation = true;
  5316. TFileOperationStatistics Statistics;
  5317. TDateTime Start = Now();
  5318. try
  5319. {
  5320. Params.OnProcessedItem = OnProcessedItem;
  5321. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5322. CreateProgressForm(&SynchronizeProgress);
  5323. Terminal->SynchronizeApply(
  5324. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5325. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5326. &Statistics);
  5327. }
  5328. __finally
  5329. {
  5330. Params.OnProcessedItem = NULL;
  5331. FAutoOperation = false;
  5332. DestroyProgressForm();
  5333. BatchEnd(BatchStorage);
  5334. ReloadLocalDirectory();
  5335. }
  5336. if (WinConfiguration->SynchronizeSummary)
  5337. {
  5338. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5339. // The statistics should be 0 anyway in this case
  5340. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5341. {
  5342. Message += L"\n";
  5343. if (Statistics.FilesUploaded > 0)
  5344. {
  5345. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5346. }
  5347. if (Statistics.FilesDownloaded > 0)
  5348. {
  5349. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5350. }
  5351. if (Statistics.FilesDeletedLocal > 0)
  5352. {
  5353. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5354. }
  5355. if (Statistics.FilesDeletedRemote > 0)
  5356. {
  5357. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5358. }
  5359. }
  5360. TDateTime Elapsed = (Now() - Start);
  5361. Message +=
  5362. L"\n" +
  5363. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5364. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5365. TMessageParams Params(mpNeverAskAgainCheck);
  5366. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5367. if (Result == qaNeverAskAgain)
  5368. {
  5369. WinConfiguration->SynchronizeSummary = false;
  5370. }
  5371. }
  5372. }
  5373. //---------------------------------------------------------------------------
  5374. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5375. {
  5376. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5377. {
  5378. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5379. }
  5380. // Not set in keep-up-to-date mode - Synchronize() method
  5381. if (Token != NULL)
  5382. {
  5383. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5384. if (Params.OnProcessedItem != NULL)
  5385. {
  5386. Params.OnProcessedItem(NULL, ChecklistItem);
  5387. }
  5388. }
  5389. }
  5390. //---------------------------------------------------------------------------
  5391. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5392. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5393. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5394. {
  5395. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5396. *Params.StartTime = Now();
  5397. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5398. }
  5399. //---------------------------------------------------------------------------
  5400. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5401. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5402. {
  5403. // terminal can be already closed (e.g. dropped connection)
  5404. if (Terminal != NULL)
  5405. {
  5406. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5407. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5408. }
  5409. }
  5410. //---------------------------------------------------------------------------
  5411. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5412. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5413. {
  5414. DebugAssert(!IsLocalBrowserMode());
  5415. TAutoBatch AutoBatch(this);
  5416. TAutoFlag AutoOperationFlag(FAutoOperation);
  5417. if (Side == osRemote)
  5418. {
  5419. std::unique_ptr<TStrings> FileList(new TStringList());
  5420. FileList->AddObject(FileName, RemoteFile);
  5421. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5422. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5423. RemoteDirView->SaveSelection();
  5424. RemoteDirView->SaveSelectedNames();
  5425. try
  5426. {
  5427. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5428. }
  5429. catch(...)
  5430. {
  5431. RemoteDirView->DiscardSavedSelection();
  5432. throw;
  5433. }
  5434. RemoteDirView->RestoreSelection();
  5435. }
  5436. else if (DebugAlwaysTrue(Side == osLocal))
  5437. {
  5438. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5439. {
  5440. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5441. }
  5442. UnicodeString Directory = ExtractFileDir(FileName);
  5443. ReloadLocalDirectory(Directory);
  5444. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5445. if (!SamePaths(Directory, NewDirectory))
  5446. {
  5447. ReloadLocalDirectory(NewDirectory);
  5448. }
  5449. }
  5450. }
  5451. //---------------------------------------------------------------------------
  5452. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5453. {
  5454. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5455. if (Side == osLocal)
  5456. {
  5457. if (Action == TSynchronizeChecklist::saDownloadNew)
  5458. {
  5459. OpenFolderInExplorer(LocalPath);
  5460. }
  5461. else
  5462. {
  5463. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5464. }
  5465. }
  5466. else if (DebugAlwaysTrue(Side == osRemote))
  5467. {
  5468. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5469. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5470. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5471. if (!LocalPath.IsEmpty())
  5472. {
  5473. SessionData->LocalDirectory = LocalPath;
  5474. }
  5475. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5476. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5477. }
  5478. }
  5479. //---------------------------------------------------------------------------
  5480. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5481. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5482. const TCopyParamType * CopyParams)
  5483. {
  5484. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5485. UnicodeString AdditionalParams =
  5486. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5487. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5488. SerializeCopyParamForCommandLine(CopyParams),
  5489. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5490. LocalDirectory, RemoteDirectory, Mode, Params));
  5491. ExecuteNewInstance(SessionName, AdditionalParams);
  5492. }
  5493. //---------------------------------------------------------------------------
  5494. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5495. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5496. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5497. {
  5498. int Result;
  5499. bool SaveSettings = false;
  5500. int Options =
  5501. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5502. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5503. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5504. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5505. bool Continue =
  5506. (UseDefaults == 0) ||
  5507. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5508. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5509. if (Continue)
  5510. {
  5511. Configuration->Usage->Inc(L"Synchronizations");
  5512. UpdateCopyParamCounters(CopyParam);
  5513. TSynchronizeOptions SynchronizeOptions;
  5514. GetSynchronizeOptions(Params, SynchronizeOptions);
  5515. if (SaveSettings)
  5516. {
  5517. GUIConfiguration->SynchronizeParams = Params;
  5518. }
  5519. else
  5520. {
  5521. SaveMode = false;
  5522. }
  5523. TDateTime StartTime = Now();
  5524. TSynchronizeChecklist * Checklist = NULL;
  5525. try
  5526. {
  5527. DebugAssert(!FAutoOperation);
  5528. FAutoOperation = true;
  5529. try
  5530. {
  5531. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5532. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5533. int Files = -1;
  5534. if (DataList->Count >= 1)
  5535. {
  5536. Files = StrToIntDef(DataList->Strings[0], Files);
  5537. }
  5538. else
  5539. {
  5540. DataList->Add(UnicodeString());
  5541. }
  5542. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5543. FSynchronizeProgressForm->Start();
  5544. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5545. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5546. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5547. &SynchronizeOptions);
  5548. if (Terminal->SessionData->CacheDirectories)
  5549. {
  5550. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5551. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5552. }
  5553. }
  5554. __finally
  5555. {
  5556. FAutoOperation = false;
  5557. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5558. SAFE_DESTROY(FSynchronizeProgressForm);
  5559. }
  5560. TSynchronizeParams SynchronizeParams;
  5561. SynchronizeParams.LocalDirectory = LocalDirectory;
  5562. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5563. SynchronizeParams.Mode = Mode;
  5564. SynchronizeParams.CopyParam = &CopyParam;
  5565. SynchronizeParams.Params = Params;
  5566. SynchronizeParams.Checklist = Checklist;
  5567. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5568. SynchronizeParams.StartTime = &StartTime;
  5569. SynchronizeParams.OnProcessedItem = NULL;
  5570. Result = Checklist->Count;
  5571. if (Checklist->Count > 0)
  5572. {
  5573. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5574. {
  5575. if (!DoSynchronizeChecklistDialog(
  5576. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5577. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5578. {
  5579. Result = -1;
  5580. }
  5581. }
  5582. else
  5583. {
  5584. FullSynchronize(SynchronizeParams, NULL, NULL);
  5585. }
  5586. }
  5587. else
  5588. {
  5589. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5590. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5591. }
  5592. }
  5593. __finally
  5594. {
  5595. delete Checklist;
  5596. }
  5597. OperationComplete(StartTime);
  5598. }
  5599. else
  5600. {
  5601. Result = -1;
  5602. }
  5603. return Result;
  5604. }
  5605. //---------------------------------------------------------------------------
  5606. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5607. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5608. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5609. {
  5610. if (Collect)
  5611. {
  5612. DebugAssert(FSynchronizeProgressForm != NULL);
  5613. if (!FSynchronizeProgressForm->Started)
  5614. {
  5615. FSynchronizeProgressForm->Start();
  5616. }
  5617. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5618. SetTaskbarListProgressValue(CompareProgress);
  5619. }
  5620. else
  5621. {
  5622. DebugAssert(FSynchronizeProgressForm == NULL);
  5623. DebugAssert(FProgressForm != NULL);
  5624. }
  5625. }
  5626. //---------------------------------------------------------------------------
  5627. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5628. {
  5629. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5630. TRemoteFile * File = NULL;
  5631. Terminal->ReadFile(FullFileName, File);
  5632. if (File != NULL)
  5633. {
  5634. std::unique_ptr<TRemoteFile> FileOwner(File);
  5635. TAutoFlag Flag(FStandaloneEditing);
  5636. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5637. Application->ShowMainForm = false;
  5638. Application->Run();
  5639. }
  5640. }
  5641. //---------------------------------------------------------------------------
  5642. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5643. {
  5644. DebugFail();
  5645. }
  5646. //---------------------------------------------------------------------------
  5647. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5648. {
  5649. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5650. SessionData->Assign(Terminal->SessionData);
  5651. UpdateSessionData(SessionData.get());
  5652. Terminal->UpdateSessionCredentials(SessionData.get());
  5653. if (!Terminal->SessionData->HasSessionName())
  5654. {
  5655. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5656. // once IsWorkspace is cleared
  5657. SessionData->Name = UnicodeString();
  5658. SessionData->IsWorkspace = false;
  5659. }
  5660. return SessionData.release();
  5661. }
  5662. //---------------------------------------------------------------------------
  5663. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5664. {
  5665. TSessionData * SessionData = CloneCurrentSessionData();
  5666. try
  5667. {
  5668. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5669. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5670. }
  5671. __finally
  5672. {
  5673. delete SessionData;
  5674. }
  5675. }
  5676. //---------------------------------------------------------------------------
  5677. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5678. {
  5679. TTerminalManager * Manager = TTerminalManager::Instance();
  5680. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5681. if (DebugAlwaysTrue(Terminal != NULL))
  5682. {
  5683. // Update (Managed)Terminal->StateData
  5684. UpdateTerminal(Terminal);
  5685. }
  5686. Manager->SaveWorkspace(DataList.get());
  5687. return DataList.release();
  5688. }
  5689. //---------------------------------------------------------------------------
  5690. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5691. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5692. {
  5693. WinConfiguration->LastWorkspace = Name;
  5694. if (!SavePasswords)
  5695. {
  5696. for (int Index = 0; Index < DataList->Count; Index++)
  5697. {
  5698. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5699. if (SessionData->Link.IsEmpty())
  5700. {
  5701. SessionData->ClearSessionPasswords();
  5702. }
  5703. }
  5704. }
  5705. StoredSessions->NewWorkspace(Name, DataList);
  5706. // modified only
  5707. StoredSessions->Save(false, Explicit);
  5708. }
  5709. //---------------------------------------------------------------------------
  5710. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5711. {
  5712. return
  5713. DefaultStr(WinConfiguration->LastWorkspace,
  5714. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5715. }
  5716. //---------------------------------------------------------------------------
  5717. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5718. {
  5719. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5720. bool AnyNonStoredSessionWithPassword = false;
  5721. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5722. bool AllNonStoredSessionsAnonymous = true;
  5723. TTerminalManager * Manager = TTerminalManager::Instance();
  5724. for (int Index = 0; Index < DataList->Count; Index++)
  5725. {
  5726. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5727. if (SessionData->Link.IsEmpty())
  5728. {
  5729. if (SessionData->HasAnySessionPassword())
  5730. {
  5731. AnyNonStoredSessionWithPassword = true;
  5732. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5733. {
  5734. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5735. }
  5736. }
  5737. if (!SameText(SessionData->UserName, AnonymousUserName))
  5738. {
  5739. AllNonStoredSessionsAnonymous = false;
  5740. }
  5741. }
  5742. }
  5743. bool SavePasswords;
  5744. bool * PSavePasswords;
  5745. bool NotRecommendedSavingPasswords =
  5746. !CustomWinConfiguration->UseMasterPassword &&
  5747. !AllNonStoredSessionsAnonymous;
  5748. if (Configuration->DisablePasswordStoring ||
  5749. !AnyNonStoredSessionWithPassword)
  5750. {
  5751. PSavePasswords = NULL;
  5752. SavePasswords = false;
  5753. }
  5754. else
  5755. {
  5756. PSavePasswords = &SavePasswords;
  5757. SavePasswords =
  5758. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5759. !NotRecommendedSavingPasswords;
  5760. }
  5761. UnicodeString Name = WorkspaceName();
  5762. bool CreateShortcut = false;
  5763. bool Result =
  5764. DoSaveWorkspaceDialog(
  5765. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5766. EnableAutoSave);
  5767. if (Result)
  5768. {
  5769. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5770. if (CreateShortcut)
  5771. {
  5772. TOperationVisualizer Visualizer;
  5773. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5774. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5775. }
  5776. if (EnableAutoSave)
  5777. {
  5778. WinConfiguration->AutoSaveWorkspace = true;
  5779. WinConfiguration->AutoWorkspace = Name;
  5780. if (PSavePasswords != NULL)
  5781. {
  5782. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5783. }
  5784. }
  5785. }
  5786. return Result;
  5787. }
  5788. //---------------------------------------------------------------------------
  5789. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5790. {
  5791. DebugAssert(!IsLocalBrowserMode());
  5792. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5793. if (WinConfiguration->PreservePanelState)
  5794. {
  5795. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5796. }
  5797. UpdateSessionData(Terminal->StateData);
  5798. }
  5799. //---------------------------------------------------------------------------
  5800. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5801. {
  5802. // Keep in sync with TSessionData::CopyStateData
  5803. DebugAssert(!IsLocalBrowserMode());
  5804. DebugAssert(Data != NULL);
  5805. // This is inconsistent with how color (for example) is handled.
  5806. Data->Name = Terminal->SessionData->Name;
  5807. // cannot use RemoteDirView->Path, because it is empty if connection
  5808. // was already closed
  5809. // also only peek, we may not be connected at all atm
  5810. // so make sure we do not try retrieving current directory from the server
  5811. // (particularly with FTP)
  5812. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5813. if (!ACurrentDirectory.IsEmpty())
  5814. {
  5815. Data->RemoteDirectory = ACurrentDirectory;
  5816. }
  5817. Data->Color = SessionColor;
  5818. }
  5819. //---------------------------------------------------------------------------
  5820. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5821. {
  5822. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5823. DebugAssert(Toolbar != NULL);
  5824. for (int i = 0; i < Toolbar->Items->Count; i++)
  5825. {
  5826. TTBXCustomDropDownItem * DropDownItem;
  5827. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5828. if (DropDownItem != NULL)
  5829. {
  5830. ToolbarItemResize(DropDownItem,
  5831. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5832. Toolbar->NonClientWidth);
  5833. break;
  5834. }
  5835. }
  5836. }
  5837. //---------------------------------------------------------------------------
  5838. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5839. {
  5840. Item->EditWidth = Width;
  5841. }
  5842. //---------------------------------------------------------------------------
  5843. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5844. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5845. {
  5846. for (int i = 0; i < Toolbar->Items->Count; i++)
  5847. {
  5848. TTBXCustomDropDownItem * DropDownItem;
  5849. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5850. if (DropDownItem != NULL)
  5851. {
  5852. ASize.x -= DropDownItem->EditWidth;
  5853. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5854. }
  5855. }
  5856. }
  5857. //---------------------------------------------------------------------------
  5858. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5859. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5860. {
  5861. if (WinConfiguration->DDWarnLackOfTempSpace)
  5862. {
  5863. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5864. if (!ADrive.IsEmpty())
  5865. {
  5866. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5867. DebugAssert(RequiredSpace >= 0);
  5868. __int64 RequiredWithReserve;
  5869. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5870. if (FreeSpace < RequiredWithReserve)
  5871. {
  5872. unsigned int Result;
  5873. TMessageParams Params(mpNeverAskAgainCheck);
  5874. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5875. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5876. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5877. if (Result == qaNeverAskAgain)
  5878. {
  5879. WinConfiguration->DDWarnLackOfTempSpace = false;
  5880. }
  5881. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5882. }
  5883. }
  5884. }
  5885. }
  5886. //---------------------------------------------------------------------------
  5887. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5888. {
  5889. DoOpenDirectoryDialog(odAddBookmark, Side);
  5890. }
  5891. //---------------------------------------------------------------------------
  5892. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5893. {
  5894. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5895. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5896. try
  5897. {
  5898. TCustomDirView * DView = DirView(Side);
  5899. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5900. {
  5901. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5902. }
  5903. }
  5904. catch (...)
  5905. {
  5906. delete VisitedDirectories;
  5907. throw;
  5908. }
  5909. return VisitedDirectories;
  5910. }
  5911. //---------------------------------------------------------------------------
  5912. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5913. TOpenDirectoryMode Mode, TOperationSide Side)
  5914. {
  5915. bool Continue = true;
  5916. if (Mode == odAddBookmark)
  5917. {
  5918. TMessageParams Params(mpNeverAskAgainCheck);
  5919. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5920. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5921. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5922. unsigned int Answer =
  5923. MessageDialog(Message,
  5924. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5925. if (Answer == qaNeverAskAgain)
  5926. {
  5927. Continue = true;
  5928. WinConfiguration->UseSharedBookmarks = true;
  5929. }
  5930. else if (Answer == qaOK)
  5931. {
  5932. Continue = true;
  5933. WinConfiguration->UseSharedBookmarks = false;
  5934. }
  5935. else
  5936. {
  5937. Continue = false;
  5938. }
  5939. }
  5940. if (Continue)
  5941. {
  5942. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5943. try
  5944. {
  5945. UnicodeString Name = DirView(Side)->PathName;
  5946. bool Repeat;
  5947. do
  5948. {
  5949. Repeat = false;
  5950. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  5951. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  5952. // do not allow switching to location profiles,
  5953. // if we are not connected
  5954. HasDirView[osLocal] && (Terminal != NULL)))
  5955. {
  5956. TWindowLock Lock(this);
  5957. if (!TryOpenDirectory(Side, Name))
  5958. {
  5959. Repeat = true;
  5960. Mode = odBrowse;
  5961. }
  5962. }
  5963. }
  5964. while (Repeat);
  5965. }
  5966. __finally
  5967. {
  5968. delete VisitedDirectories;
  5969. }
  5970. }
  5971. }
  5972. //---------------------------------------------------------------------------
  5973. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5974. {
  5975. DebugAssert(!FTerminal->CommandSessionOpened);
  5976. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5977. }
  5978. //---------------------------------------------------------------------------
  5979. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5980. {
  5981. bool Result = FTerminal->IsCapable[Capability] ||
  5982. FTerminal->CommandSessionOpened;
  5983. if (!Result)
  5984. {
  5985. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5986. if (!GUIConfiguration->ConfirmCommandSession)
  5987. {
  5988. Result = true;
  5989. }
  5990. else
  5991. {
  5992. TMessageParams Params(mpNeverAskAgainCheck);
  5993. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5994. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5995. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5996. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5997. if (Answer == qaNeverAskAgain)
  5998. {
  5999. GUIConfiguration->ConfirmCommandSession = false;
  6000. Result = true;
  6001. }
  6002. else if (Answer == qaOK)
  6003. {
  6004. Result = true;
  6005. }
  6006. }
  6007. if (Result)
  6008. {
  6009. Result = CommandSessionFallback();
  6010. }
  6011. }
  6012. return Result;
  6013. }
  6014. //---------------------------------------------------------------------------
  6015. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6016. {
  6017. if (EnsureCommandSessionFallback(fcAnyCommand))
  6018. {
  6019. DoConsoleDialog(Terminal, Command);
  6020. }
  6021. }
  6022. //---------------------------------------------------------------------------
  6023. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6024. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6025. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6026. {
  6027. if (!IsSideLocalBrowser(osRemote) &&
  6028. IsFileControl(DropSourceControl, osRemote) &&
  6029. (FDDExtMapFile != NULL))
  6030. {
  6031. Accept = true;
  6032. }
  6033. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6034. DebugAssert(FDDTargetControl != NULL);
  6035. }
  6036. //---------------------------------------------------------------------------
  6037. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6038. _di_IDataObject DataObj, int KeyState,
  6039. const TPoint & Point, int & Effect, bool & Accept)
  6040. {
  6041. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6042. }
  6043. //---------------------------------------------------------------------------
  6044. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6045. _di_IDataObject DataObj, int KeyState,
  6046. const TPoint & Point, int & Effect, bool & Accept)
  6047. {
  6048. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6049. }
  6050. //---------------------------------------------------------------------------
  6051. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6052. TObject * Sender)
  6053. {
  6054. DebugUsedParam(Sender);
  6055. DebugAssert(FDDTargetControl == Sender);
  6056. FDDTargetControl = NULL;
  6057. }
  6058. //---------------------------------------------------------------------------
  6059. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6060. {
  6061. FileControlDDDragLeave(SessionsPageControl);
  6062. }
  6063. //---------------------------------------------------------------------------
  6064. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6065. {
  6066. FileControlDDDragLeave(QueueView3);
  6067. }
  6068. //---------------------------------------------------------------------------
  6069. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6070. {
  6071. DebugAssert(!IsSideLocalBrowser(Side));
  6072. DebugUsedParam(Side);
  6073. bool Edit = false;
  6074. TRemoteFile * File = NULL;
  6075. UnicodeString FileName;
  6076. UnicodeString PointTo;
  6077. bool SymbolicLink = true;
  6078. if (RemoteDirView->ItemFocused)
  6079. {
  6080. DebugAssert(RemoteDirView->ItemFocused->Data);
  6081. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6082. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6083. if (Edit)
  6084. {
  6085. FileName = File->FileName;
  6086. PointTo = File->LinkTo;
  6087. }
  6088. else
  6089. {
  6090. PointTo = File->FileName;
  6091. }
  6092. }
  6093. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6094. Terminal->IsCapable[fcHardLink]))
  6095. {
  6096. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6097. if (Edit)
  6098. {
  6099. DebugAssert(File->FileName == FileName);
  6100. int Params = dfNoRecursive;
  6101. Terminal->ExceptionOnFail = true;
  6102. try
  6103. {
  6104. Terminal->DeleteFile(L"", File, &Params);
  6105. }
  6106. __finally
  6107. {
  6108. Terminal->ExceptionOnFail = false;
  6109. }
  6110. }
  6111. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6112. }
  6113. }
  6114. //---------------------------------------------------------------------------
  6115. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6116. {
  6117. return
  6118. (IsSideLocalBrowser(Side) ||
  6119. (HasActiveTerminal() &&
  6120. Terminal->ResolvingSymlinks &&
  6121. Terminal->IsCapable[fcSymbolicLink]));
  6122. }
  6123. //---------------------------------------------------------------------------
  6124. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6125. {
  6126. return
  6127. !IsSideLocalBrowser(FCurrentSide) &&
  6128. (RemoteDirView->ItemFocused != NULL) &&
  6129. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6130. Terminal->SessionData->ResolveSymlinks;
  6131. }
  6132. //---------------------------------------------------------------------------
  6133. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6134. {
  6135. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6136. FForceExecution = true;
  6137. try
  6138. {
  6139. DirView(osCurrent)->ExecuteCurrentFile();
  6140. }
  6141. __finally
  6142. {
  6143. FForceExecution = false;
  6144. }
  6145. }
  6146. //---------------------------------------------------------------------------
  6147. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6148. {
  6149. TEditorData ExternalEditor;
  6150. ExternalEditor.Editor = edExternal;
  6151. bool Remember = false;
  6152. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6153. {
  6154. if (Remember)
  6155. {
  6156. TEditorList * EditorList = new TEditorList;
  6157. try
  6158. {
  6159. *EditorList = *WinConfiguration->EditorList;
  6160. bool Found = false;
  6161. int i = 0;
  6162. while (!Found && (i < EditorList->Count))
  6163. {
  6164. const TEditorPreferences * Editor = EditorList->Editors[i];
  6165. if ((Editor->Data->Editor == edExternal) &&
  6166. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6167. {
  6168. Found = true;
  6169. }
  6170. i++;
  6171. }
  6172. if (!Found)
  6173. {
  6174. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6175. WinConfiguration->EditorList = EditorList;
  6176. }
  6177. }
  6178. __finally
  6179. {
  6180. delete EditorList;
  6181. }
  6182. }
  6183. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6184. }
  6185. }
  6186. //---------------------------------------------------------------------------
  6187. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6188. {
  6189. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6190. if (FFileFindTerminal == ATerminal)
  6191. {
  6192. FFileFindTerminal = NULL;
  6193. HideFileFindDialog();
  6194. }
  6195. if (FClipboardTerminal == ATerminal)
  6196. {
  6197. ClipboardClear(); // implies ClipboardStop
  6198. }
  6199. }
  6200. //---------------------------------------------------------------------------
  6201. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6202. {
  6203. DetachTerminal(Sender);
  6204. }
  6205. //---------------------------------------------------------------------------
  6206. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6207. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6208. {
  6209. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6210. DebugAssert(Terminal != NULL);
  6211. if (Data->Terminal == Terminal)
  6212. {
  6213. Data->Terminal = NULL;
  6214. }
  6215. }
  6216. //---------------------------------------------------------------------------
  6217. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6218. {
  6219. UpdateControls();
  6220. SessionColor = TColor(0);
  6221. UpdateRemotePathComboBox(false);
  6222. NeedSession(false);
  6223. }
  6224. //---------------------------------------------------------------------------
  6225. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6226. {
  6227. try
  6228. {
  6229. // Cache, as the login dialog can change its value
  6230. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6231. try
  6232. {
  6233. if (ShowLogin)
  6234. {
  6235. bool ReloadSessions = !Startup;
  6236. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  6237. }
  6238. else if (Startup && WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6239. // This detects if workspace was saved the last time the main widow was closed
  6240. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6241. {
  6242. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6243. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6244. }
  6245. }
  6246. __finally
  6247. {
  6248. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6249. // (so there was no chance for the user to open any session yet)
  6250. if ((ShowLogin || !Startup) &&
  6251. !WinConfiguration->KeepOpenWhenNoSession &&
  6252. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6253. {
  6254. TerminateApplication();
  6255. }
  6256. }
  6257. }
  6258. catch (EAbort &)
  6259. {
  6260. // swallow
  6261. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6262. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6263. }
  6264. }
  6265. //---------------------------------------------------------------------------
  6266. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6267. {
  6268. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6269. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6270. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6271. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6272. try
  6273. {
  6274. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6275. // Clear the design time unthemed tab
  6276. ((SessionsPageControl->PageCount > 0) &&
  6277. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6278. {
  6279. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6280. }
  6281. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6282. {
  6283. TThemeTabSheet * TabSheet;
  6284. if (Index >= SessionsPageControl->PageCount)
  6285. {
  6286. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6287. TabSheet->PageControl = SessionsPageControl;
  6288. }
  6289. else
  6290. {
  6291. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6292. }
  6293. bool IsSessionTab = (Index < TerminalList->Count);
  6294. if (IsSessionTab)
  6295. {
  6296. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6297. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6298. UpdateSessionTab(TabSheet);
  6299. }
  6300. else
  6301. {
  6302. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6303. TabSheet->Tag = 0; // not really needed
  6304. TabSheet->Shadowed = false;
  6305. // 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)
  6306. UpdateNewSessionTab();
  6307. }
  6308. TabSheet->ShowCloseButton = IsSessionTab;
  6309. }
  6310. }
  6311. __finally
  6312. {
  6313. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6314. }
  6315. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6316. }
  6317. //---------------------------------------------------------------------------
  6318. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6319. {
  6320. DoTerminalListChanged();
  6321. }
  6322. //---------------------------------------------------------------------------
  6323. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6324. {
  6325. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6326. DebugAssert(TabSheet->ImageIndex == 0);
  6327. TabSheet->Caption =
  6328. WinConfiguration->SelectiveToolbarText ?
  6329. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6330. UnicodeString();
  6331. }
  6332. //---------------------------------------------------------------------------
  6333. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6334. {
  6335. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6336. }
  6337. //---------------------------------------------------------------------------
  6338. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6339. {
  6340. if (DebugAlwaysTrue(TabSheet != NULL))
  6341. {
  6342. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6343. if (DebugAlwaysTrue(ATerminal != NULL))
  6344. {
  6345. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6346. TabSheet->ImageIndex = AddSessionColor(Color);
  6347. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6348. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6349. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6350. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6351. {
  6352. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6353. }
  6354. }
  6355. }
  6356. }
  6357. //---------------------------------------------------------------------------
  6358. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6359. {
  6360. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6361. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6362. bool Result = (Terminal != NULL);
  6363. if (Result)
  6364. {
  6365. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6366. }
  6367. else
  6368. {
  6369. try
  6370. {
  6371. NewSession(false);
  6372. }
  6373. __finally
  6374. {
  6375. DoTerminalListChanged();
  6376. }
  6377. FSessionsPageControlNewSessionTime = Now();
  6378. }
  6379. return Result;
  6380. }
  6381. //---------------------------------------------------------------------------
  6382. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6383. {
  6384. SessionTabSwitched();
  6385. }
  6386. //---------------------------------------------------------------------------
  6387. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6388. {
  6389. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6390. DebugAssert(TransferList != NULL);
  6391. UnicodeString Name;
  6392. if (TransferList->ItemIndex <= 0)
  6393. {
  6394. Name = L"";
  6395. }
  6396. else
  6397. {
  6398. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6399. }
  6400. if (FCopyParamAutoSelected.IsEmpty())
  6401. {
  6402. // if previous preset was not autoselected, make new preset the "default"
  6403. FCopyParamDefault = Name;
  6404. }
  6405. GUIConfiguration->CopyParamCurrent = Name;
  6406. }
  6407. //---------------------------------------------------------------------------
  6408. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6409. {
  6410. // sanity check
  6411. bool ExistingPreset =
  6412. (FTransferListHoverIndex >= 0) &&
  6413. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6414. DebugAssert(ExistingPreset);
  6415. if (ExistingPreset)
  6416. {
  6417. HDC DC = GetDC(0);
  6418. TCanvas * Canvas = new TCanvas();
  6419. try
  6420. {
  6421. Canvas->Handle = DC;
  6422. Canvas->Font = GetToolbarFont(this);
  6423. UnicodeString Name;
  6424. if (FTransferListHoverIndex == 0)
  6425. {
  6426. Name = L"";
  6427. }
  6428. else
  6429. {
  6430. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6431. }
  6432. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6433. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6434. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6435. static_cast<TObject*>(GetComponent(fcTransferList)));
  6436. UnicodeString InfoStr =
  6437. GUIConfiguration->CopyParamPreset[Name].
  6438. GetInfoStr(L"; ",
  6439. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6440. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6441. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6442. {
  6443. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6444. {
  6445. InfoStr.SetLength(InfoStr.Length() - 1);
  6446. }
  6447. InfoStr += Ellipsis;
  6448. }
  6449. // UpdateCaption does not cause invalidation of whole submenu, while
  6450. // setting Caption property does.
  6451. // also it probably does not resize the label, even if necessary
  6452. // (we do not want that anyway)
  6453. TransferLabel->UpdateCaption(InfoStr);
  6454. }
  6455. __finally
  6456. {
  6457. Canvas->Handle = NULL;
  6458. ReleaseDC(0, DC);
  6459. delete Canvas;
  6460. }
  6461. }
  6462. }
  6463. //---------------------------------------------------------------------------
  6464. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6465. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6466. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6467. {
  6468. if (FTransferListHoverIndex != AHoverIndex)
  6469. {
  6470. FTransferListHoverIndex = AHoverIndex;
  6471. UpdateTransferLabel();
  6472. }
  6473. }
  6474. //---------------------------------------------------------------------------
  6475. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6476. {
  6477. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6478. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6479. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6480. {
  6481. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6482. {
  6483. if (!NonVisualDataModule->Busy)
  6484. {
  6485. OpenDirectory(GetSide(osCurrent));
  6486. }
  6487. Message.Result = 1;
  6488. }
  6489. else
  6490. {
  6491. TForm::Dispatch(&Message);
  6492. }
  6493. }
  6494. else
  6495. {
  6496. TForm::Dispatch(&Message);
  6497. }
  6498. }
  6499. //---------------------------------------------------------------------------
  6500. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6501. {
  6502. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6503. if ((FIgnoreNextDialogChar != 0) &&
  6504. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6505. {
  6506. Message.Result = 1;
  6507. }
  6508. else
  6509. {
  6510. TForm::Dispatch(&Message);
  6511. }
  6512. FIgnoreNextDialogChar = 0;
  6513. }
  6514. //---------------------------------------------------------------------------
  6515. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6516. {
  6517. // The four low-order bits are used internally by Windows
  6518. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6519. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6520. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6521. // 61730 - restore thru double click - undocumented
  6522. // 61490 - maximize thru double click - undocumented
  6523. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6524. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6525. {
  6526. SysResizing(Cmd);
  6527. }
  6528. TForm::Dispatch(&Message);
  6529. }
  6530. //---------------------------------------------------------------------------
  6531. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6532. {
  6533. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6534. // Also there no point returning TRUE as we are not able to
  6535. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6536. // Hence the process termination might be safer :)
  6537. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6538. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6539. {
  6540. Message.Result = FALSE;
  6541. }
  6542. else
  6543. {
  6544. Message.Result = TRUE;
  6545. }
  6546. // Do not call default handling as that triggers OnCloseQuery,
  6547. // where our implementation will popup confirmation dialogs, what we do not want,
  6548. // as per Vista guidelines:
  6549. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6550. }
  6551. //---------------------------------------------------------------------------
  6552. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6553. {
  6554. if (Message.EndSession && IsApplicationMinimized())
  6555. {
  6556. // WORKAROUND
  6557. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6558. // when it receives WM_ENDSESSION,
  6559. // but that sometimes (particularly when application is minimized) cause crashes.
  6560. // Crash popups message that blocks log off.
  6561. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6562. // so we call ExitProcess() immediately, not even trying to cleanup.
  6563. // It still causes beep, so there's likely some popup, but it does not block
  6564. // log off.
  6565. ExitProcess(0);
  6566. }
  6567. TForm::Dispatch(&Message);
  6568. }
  6569. #ifdef _DEBUG
  6570. //---------------------------------------------------------------------------
  6571. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6572. {
  6573. TForm::Dispatch(&Message);
  6574. }
  6575. #endif
  6576. //---------------------------------------------------------------------------
  6577. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6578. {
  6579. }
  6580. //---------------------------------------------------------------------------
  6581. void __fastcall TCustomScpExplorerForm::DoShow()
  6582. {
  6583. // only now are the controls resized finally, so the size constraints
  6584. // will not conflict with possibly very small window size
  6585. RestoreFormParams();
  6586. // This indicates that the form was rescaled after parameters were loaded and
  6587. // as most probably the parameters were actually saved with the current form scaling
  6588. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6589. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6590. // and no rounding problems will occur.
  6591. // See also RestoreForm.
  6592. // (we should be safe to call RestoreParams unconditionally)
  6593. if (PixelsPerInch != Screen->PixelsPerInch)
  6594. {
  6595. RestoreParams();
  6596. }
  6597. FixControlsPlacement();
  6598. if (Position == poDefaultPosOnly)
  6599. {
  6600. CutFormToDesktop(this);
  6601. }
  6602. TForm::DoShow();
  6603. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6604. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6605. if (Terminal == NULL)
  6606. {
  6607. StartingDisconnected();
  6608. }
  6609. UpdatePixelsPerInchMainWindowCounter();
  6610. FShowing = true;
  6611. }
  6612. //---------------------------------------------------------------------------
  6613. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6614. {
  6615. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6616. }
  6617. //---------------------------------------------------------------------------
  6618. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6619. {
  6620. DoTerminalListChanged();
  6621. UpdateControls();
  6622. }
  6623. //---------------------------------------------------------------------------
  6624. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6625. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6626. TNotifyEvent OnBalloonClick, TObject * UserData)
  6627. {
  6628. bool Do;
  6629. UnicodeString Message;
  6630. if (E == NULL)
  6631. {
  6632. Message = Str;
  6633. Do = true;
  6634. }
  6635. else
  6636. {
  6637. Do = ExceptionMessage(E, Message);
  6638. }
  6639. if (Do && WinConfiguration->BalloonNotifications)
  6640. {
  6641. UnicodeString Title;
  6642. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6643. {
  6644. Message = TrimLeft(Message);
  6645. }
  6646. else
  6647. {
  6648. Message = UnformatMessage(Message);
  6649. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6650. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6651. Title = LoadResourceString(Captions[Type]);
  6652. if (Terminal != NULL)
  6653. {
  6654. Title = FORMAT(L"%s - %s",
  6655. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6656. }
  6657. }
  6658. if (Seconds == 0)
  6659. {
  6660. Seconds = WinConfiguration->NotificationsTimeout;
  6661. }
  6662. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6663. }
  6664. }
  6665. //---------------------------------------------------------------------------
  6666. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6667. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6668. UnicodeString HelpKeyword, const TMessageParams * Params,
  6669. TTerminal * Terminal)
  6670. {
  6671. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6672. (FOnFeedSynchronizeError != NULL)) &&
  6673. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6674. {
  6675. if (FOnFeedSynchronizeError != NULL)
  6676. {
  6677. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6678. }
  6679. else
  6680. {
  6681. DebugAssert(FErrorList != NULL);
  6682. TStringList * MoreMessagesCopy = NULL;
  6683. if (MoreMessages)
  6684. {
  6685. MoreMessagesCopy = new TStringList();
  6686. MoreMessagesCopy->Assign(MoreMessages);
  6687. }
  6688. FErrorList->AddObject(Message, MoreMessagesCopy);
  6689. }
  6690. PopupTrayBalloon(Terminal, Message, Type);
  6691. return ContinueAnswer(Answers);
  6692. }
  6693. else
  6694. {
  6695. bool UseBalloon = FTrayIcon->Visible;
  6696. if (UseBalloon)
  6697. {
  6698. PopupTrayBalloon(Terminal, Message, Type);
  6699. }
  6700. unsigned int Result;
  6701. try
  6702. {
  6703. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6704. }
  6705. __finally
  6706. {
  6707. // cancel only balloon we popped up, otherwise we may cancel notification
  6708. // balloon that was there before the message dialog
  6709. // (such as "dd confirmation opt in balloon)
  6710. if (UseBalloon)
  6711. {
  6712. FTrayIcon->CancelBalloon();
  6713. }
  6714. }
  6715. return Result;
  6716. }
  6717. }
  6718. //---------------------------------------------------------------------------
  6719. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6720. TTerminal * Terminal, Exception * E)
  6721. {
  6722. if (FTrayIcon->Visible)
  6723. {
  6724. PopupTrayBalloon(Terminal, L"", qtError, E);
  6725. }
  6726. // particularly prevent opening new session from jump list,
  6727. // while exception is shown
  6728. NonVisualDataModule->StartBusy();
  6729. try
  6730. {
  6731. ShowExtendedExceptionEx(Terminal, E);
  6732. }
  6733. __finally
  6734. {
  6735. NonVisualDataModule->EndBusy();
  6736. FTrayIcon->CancelBalloon();
  6737. }
  6738. }
  6739. //---------------------------------------------------------------------------
  6740. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6741. {
  6742. if (Terminal->Active)
  6743. {
  6744. InitStatusBar();
  6745. }
  6746. // cannot rely on active page being page for active terminal,
  6747. // as it can happen that active page is the "new session" page
  6748. // (e.g. when reconnecting active terminal, while login dialog
  6749. // invoked from "new session" page is modal)
  6750. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6751. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6752. }
  6753. //---------------------------------------------------------------------------
  6754. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6755. TTerminal * Terminal, Exception * E)
  6756. {
  6757. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6758. if (!Terminal->Active)
  6759. {
  6760. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6761. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6762. {
  6763. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6764. }
  6765. }
  6766. }
  6767. //---------------------------------------------------------------------------
  6768. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6769. UnicodeString Message, TQueryType Type,
  6770. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6771. {
  6772. if ((E == NULL) ||
  6773. ExceptionMessage(E, Message))
  6774. {
  6775. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6776. if (Important)
  6777. {
  6778. Seconds *= 5;
  6779. }
  6780. UnicodeString NoteMessage(UnformatMessage(Message));
  6781. if (Terminal != NULL)
  6782. {
  6783. NoteMessage = FORMAT(L"%s: %s",
  6784. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6785. }
  6786. if (WinConfiguration->BalloonNotifications)
  6787. {
  6788. AddNote(NoteMessage);
  6789. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6790. }
  6791. else
  6792. {
  6793. FlashOnBackground();
  6794. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6795. }
  6796. }
  6797. }
  6798. //---------------------------------------------------------------------------
  6799. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6800. {
  6801. RestoreApp();
  6802. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6803. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6804. !NonVisualDataModule->Busy)
  6805. {
  6806. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6807. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6808. if (!ComponentVisible[fcQueueView])
  6809. {
  6810. ToggleQueueVisibility();
  6811. GoToQueue();
  6812. }
  6813. }
  6814. }
  6815. //---------------------------------------------------------------------------
  6816. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6817. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6818. {
  6819. UnicodeString Message;
  6820. TNotifyEvent OnClick = NULL;
  6821. TObject * UserData = NULL;
  6822. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6823. switch (Event)
  6824. {
  6825. case qeEmptyButMonitored:
  6826. if ((ATerminal != Terminal) || QueueInvisible)
  6827. {
  6828. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6829. OnClick = QueueEmptyNoteClicked;
  6830. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6831. TerminalNoteData->Terminal = ATerminal;
  6832. UserData = TerminalNoteData;
  6833. }
  6834. break;
  6835. case qeEmpty:
  6836. OperationComplete(ATerminal->QueueOperationStart);
  6837. break;
  6838. case qePendingUserAction:
  6839. if ((ATerminal != Terminal) ||
  6840. (QueueInvisible && !IsQueueAutoPopup()))
  6841. {
  6842. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6843. }
  6844. break;
  6845. default:
  6846. DebugFail();
  6847. }
  6848. if (!Message.IsEmpty())
  6849. {
  6850. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6851. }
  6852. }
  6853. //---------------------------------------------------------------------------
  6854. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6855. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6856. {
  6857. if (FDDExtMapFile != NULL)
  6858. {
  6859. CloseHandle(FDDExtMapFile);
  6860. FDDExtMapFile = NULL;
  6861. }
  6862. if (WinConfiguration->DDFakeFile)
  6863. {
  6864. DDFakeFileInitDrag(FileList, Created);
  6865. }
  6866. }
  6867. //---------------------------------------------------------------------------
  6868. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6869. {
  6870. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6871. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6872. {
  6873. FFakeFileDropTarget = FileName;
  6874. }
  6875. }
  6876. //---------------------------------------------------------------------------
  6877. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6878. {
  6879. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6880. if (!ForceDirectories(ApiPath(Result)))
  6881. {
  6882. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6883. }
  6884. FileSetAttr(ApiPath(Result), faHidden);
  6885. return Result;
  6886. }
  6887. //---------------------------------------------------------------------------
  6888. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6889. bool & Created)
  6890. {
  6891. FFakeFileDropTarget = UnicodeString();
  6892. FDragFakeDirectory = CreateFakeTransferDirectory();
  6893. FileList->AddItem(NULL, FDragFakeDirectory);
  6894. Created = true;
  6895. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6896. {
  6897. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6898. }
  6899. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6900. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6901. {
  6902. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6903. TDragExtCommStruct* CommStruct;
  6904. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6905. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6906. DebugAssert(CommStruct != NULL);
  6907. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6908. CommStruct->Dragging = true;
  6909. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6910. LENOF(CommStruct->DropDest));
  6911. NULL_TERMINATE(CommStruct->DropDest);
  6912. UnmapViewOfFile(CommStruct);
  6913. }
  6914. }
  6915. //---------------------------------------------------------------------------
  6916. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6917. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6918. {
  6919. bool Result;
  6920. DebugAssert(!IsLocalBrowserMode());
  6921. if (Sender == RemoteDirView)
  6922. {
  6923. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6924. }
  6925. else
  6926. {
  6927. DebugAssert(Sender == RemoteDriveView);
  6928. TStrings * FileList = RemoteDriveView->DragFileList();
  6929. try
  6930. {
  6931. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6932. }
  6933. __finally
  6934. {
  6935. delete FileList;
  6936. }
  6937. }
  6938. if (FDDTargetControl == RemoteDriveView)
  6939. {
  6940. RemoteDriveView->UpdateDropTarget();
  6941. }
  6942. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6943. // or from tree view to dir view.
  6944. // foMove happens when file/dir is dragged from remote tree view outside of
  6945. // application via dragex
  6946. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6947. (DropSourceControl == RemoteDriveView))
  6948. {
  6949. RemoteDriveView->UpdateDropSource();
  6950. }
  6951. return Result;
  6952. }
  6953. //---------------------------------------------------------------------------
  6954. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6955. {
  6956. DebugAssert(!IsLocalBrowserMode());
  6957. // This also handles drops of remote files to queue.
  6958. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6959. SAFE_DESTROY(FDDFileList);
  6960. if (!FFakeFileDropTarget.IsEmpty())
  6961. {
  6962. RemoveDir(ApiPath(FFakeFileDropTarget));
  6963. }
  6964. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6965. {
  6966. try
  6967. {
  6968. TDragResult DDResult = (Sender == RemoteDirView) ?
  6969. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6970. // Focus is moved to the target application,
  6971. // but as we are going to present the UI, we need to steal the focus back.
  6972. // This most likely won't work though (windows does not allow application
  6973. // to steal focus most of the time)
  6974. Application->BringToFront();
  6975. // On older version of Windows we never got drMove here, see also comment below.
  6976. // On Windows 10, we get the "move".
  6977. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6978. {
  6979. UnicodeString TargetDirectory;
  6980. TFileOperation Operation;
  6981. // drInvalid may mean drMove, see comment below
  6982. switch (DDResult)
  6983. {
  6984. case drCopy:
  6985. Operation = foCopy;
  6986. break;
  6987. case drMove:
  6988. Operation = foMove;
  6989. break;
  6990. default:
  6991. DebugFail();
  6992. case drInvalid:
  6993. // prefer "copy" for safety
  6994. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6995. break;
  6996. }
  6997. TTransferOperationParam Param;
  6998. UnicodeString CounterName;
  6999. bool ForceQueue;
  7000. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7001. {
  7002. // we get drInvalid both if d&d was intercepted by ddext,
  7003. // and when users drops on no-drop location.
  7004. // we tell the difference by existence of response from ddext,
  7005. // so we ignore absence of response in this case
  7006. if (DDResult != drInvalid)
  7007. {
  7008. // here we know that the extension is installed,
  7009. // as it is checked as soon as drag&drop starts from
  7010. // RemoteFileControlDDCreateDragFileList
  7011. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7012. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7013. {
  7014. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7015. }
  7016. else
  7017. {
  7018. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7019. }
  7020. }
  7021. }
  7022. else
  7023. {
  7024. // download using fake file
  7025. Param.Temp = false;
  7026. Param.DragDrop = true;
  7027. if (ForceQueue)
  7028. {
  7029. Param.Queue = asOn;
  7030. }
  7031. if (Sender == RemoteDirView)
  7032. {
  7033. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7034. }
  7035. if (RemoteFileControlFileOperation(Sender, Operation,
  7036. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7037. {
  7038. Configuration->Usage->Inc(CounterName);
  7039. }
  7040. }
  7041. }
  7042. }
  7043. __finally
  7044. {
  7045. CloseHandle(FDDExtMapFile);
  7046. FDDExtMapFile = NULL;
  7047. delete FDragFakeMonitors;
  7048. FDragFakeMonitors = NULL;
  7049. RemoveDir(ApiPath(FDragFakeDirectory));
  7050. FDragFakeDirectory = L"";
  7051. FFakeFileDropTarget = UnicodeString();
  7052. }
  7053. }
  7054. if (FDragDropSshTerminate.get() != NULL)
  7055. {
  7056. FDragDropSshTerminate->Rethrow();
  7057. }
  7058. }
  7059. //---------------------------------------------------------------------------
  7060. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7061. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7062. {
  7063. // Remember drop effect so we know (when user drops files), if we copy or move
  7064. FLastDropEffect = dwEffect;
  7065. }
  7066. //---------------------------------------------------------------------------
  7067. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7068. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7069. {
  7070. bool Result;
  7071. if (FDDTargetControl == QueueView3)
  7072. {
  7073. Directory = DefaultDownloadTargetDirectory();
  7074. Result = true;
  7075. CounterName = L"DownloadsDragDropQueue";
  7076. ForceQueue = true;
  7077. }
  7078. else if (!FFakeFileDropTarget.IsEmpty())
  7079. {
  7080. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7081. Result = true;
  7082. ForceQueue = false;
  7083. CounterName = L"DownloadsDragDropFakeFile";
  7084. }
  7085. else
  7086. {
  7087. ForceQueue = false;
  7088. Enabled = false;
  7089. try
  7090. {
  7091. int Timer = 0;
  7092. Result = false;
  7093. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7094. {
  7095. {
  7096. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7097. TDragExtCommStruct* CommStruct;
  7098. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7099. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7100. DebugAssert(CommStruct != NULL);
  7101. Result = !CommStruct->Dragging;
  7102. if (Result)
  7103. {
  7104. Directory = ExtractFilePath(CommStruct->DropDest);
  7105. CounterName = L"DownloadsDragDropExternalExt";
  7106. }
  7107. UnmapViewOfFile(CommStruct);
  7108. }
  7109. if (!Result)
  7110. {
  7111. Sleep(50);
  7112. Timer += 50;
  7113. Application->ProcessMessages();
  7114. }
  7115. }
  7116. }
  7117. __finally
  7118. {
  7119. Enabled = true;
  7120. }
  7121. }
  7122. return Result;
  7123. }
  7124. //---------------------------------------------------------------------------
  7125. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7126. const UnicodeString TempDir, int SecDelay)
  7127. {
  7128. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7129. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7130. if (FDelayedDeletionTimer == NULL)
  7131. {
  7132. DebugAssert(HandleAllocated());
  7133. FDelayedDeletionTimer = new TTimer(this);
  7134. FDelayedDeletionTimer->Interval = 10000;
  7135. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7136. }
  7137. else
  7138. {
  7139. FDelayedDeletionTimer->Enabled = true;
  7140. }
  7141. }
  7142. //---------------------------------------------------------------------------
  7143. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7144. {
  7145. DebugAssert(FDelayedDeletionList != NULL);
  7146. TDateTime N = Now();
  7147. TDateTime Alert;
  7148. UnicodeString Directory;
  7149. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7150. {
  7151. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7152. if ((N >= Alert) || (Sender == NULL))
  7153. {
  7154. Directory = FDelayedDeletionList->Strings[Index];
  7155. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7156. {
  7157. FDelayedDeletionList->Delete(Index);
  7158. }
  7159. }
  7160. }
  7161. if (FDelayedDeletionList->Count == 0)
  7162. {
  7163. FDelayedDeletionTimer->Enabled = false;
  7164. }
  7165. }
  7166. //---------------------------------------------------------------------------
  7167. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7168. {
  7169. DebugAssert(!IsLocalBrowserMode());
  7170. if (IsFileControl(FDDTargetControl, osRemote) ||
  7171. (FDDTargetControl == SessionsPageControl))
  7172. {
  7173. TTerminal * TargetTerminal = NULL;
  7174. TFileOperation Operation = foNone;
  7175. if (FDDTargetControl == SessionsPageControl)
  7176. {
  7177. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7178. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7179. // do not allow dropping on the "+" tab
  7180. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7181. if (TargetTerminal != NULL)
  7182. {
  7183. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7184. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7185. {
  7186. Operation = foRemoteMove;
  7187. }
  7188. else
  7189. {
  7190. Operation = foRemoteCopy;
  7191. }
  7192. }
  7193. }
  7194. else
  7195. {
  7196. if (FLastDropEffect == DROPEFFECT_MOVE)
  7197. {
  7198. Operation = foRemoteMove;
  7199. }
  7200. else if (FLastDropEffect == DROPEFFECT_COPY)
  7201. {
  7202. Operation = foRemoteCopy;
  7203. }
  7204. }
  7205. if (Operation != foNone)
  7206. {
  7207. RemoteFileControlFileOperation(DropSourceControl,
  7208. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7209. }
  7210. // abort drag&drop
  7211. Abort();
  7212. }
  7213. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7214. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7215. (FDDTargetControl != QueueView3))
  7216. {
  7217. DebugAssert(!FDragTempDir.IsEmpty());
  7218. TTransferType Type;
  7219. UnicodeString TempDir = FDragTempDir;
  7220. // We clear FDragTempDir before calling
  7221. // just in case it fail (raises exception)
  7222. FDragTempDir = L"";
  7223. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7224. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7225. // empty directory parameter means temp directory -> don't display it!
  7226. UnicodeString TargetDir = L"";
  7227. int Options = 0;
  7228. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7229. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7230. {
  7231. Abort();
  7232. }
  7233. // TargetDir is set when dropped on local file control
  7234. // (this was workaround for legacy dirview event handling, now it should be
  7235. // made prettier)
  7236. if (TargetDir.IsEmpty())
  7237. {
  7238. TargetDir = TempDir;
  7239. if (ForceDirectories(ApiPath(TargetDir)))
  7240. {
  7241. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7242. FPendingTempSpaceWarn = true;
  7243. try
  7244. {
  7245. FDragDropOperation = true;
  7246. int Params = cpTemporary |
  7247. (Type == ttMove ? cpDelete : 0);
  7248. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7249. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7250. }
  7251. __finally
  7252. {
  7253. FDragDropOperation = false;
  7254. FPendingTempSpaceWarn = false;
  7255. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7256. }
  7257. }
  7258. else
  7259. {
  7260. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7261. }
  7262. }
  7263. }
  7264. }
  7265. //---------------------------------------------------------------------------
  7266. void __fastcall TCustomScpExplorerForm::DDDownload(
  7267. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7268. {
  7269. DebugAssert(!IsLocalBrowserMode());
  7270. TAutoBatch AutoBatch(this);
  7271. UpdateCopyParamCounters(*CopyParam);
  7272. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7273. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7274. {
  7275. RemoteDriveView->UpdateDropSource();
  7276. }
  7277. }
  7278. //---------------------------------------------------------------------------
  7279. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7280. {
  7281. public:
  7282. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7283. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7284. {
  7285. }
  7286. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7287. {
  7288. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7289. TDataObjectFilesEx::AllowData(FormatEtc);
  7290. }
  7291. };
  7292. //---------------------------------------------------------------------------
  7293. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7294. TObject * Sender, TDataObject *& DataObject)
  7295. {
  7296. if (FDDExtMapFile != NULL)
  7297. {
  7298. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7299. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7300. {
  7301. Abort();
  7302. }
  7303. if (FileList->Count > 0)
  7304. {
  7305. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7306. if (!FilesObject->IsValid(true, true))
  7307. {
  7308. FilesObject->_Release();
  7309. }
  7310. else
  7311. {
  7312. DataObject = FilesObject;
  7313. }
  7314. }
  7315. }
  7316. }
  7317. //---------------------------------------------------------------------------
  7318. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7319. {
  7320. DebugFail();
  7321. }
  7322. //---------------------------------------------------------------------------
  7323. void __fastcall TCustomScpExplorerForm::GoToTree()
  7324. {
  7325. ComponentVisible[fcRemoteTree] = true;
  7326. DriveView(osRemote)->SetFocus();
  7327. }
  7328. //---------------------------------------------------------------------------
  7329. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7330. TPanelExport Export)
  7331. {
  7332. TCustomDirView * DirView = this->DirView(Side);
  7333. std::unique_ptr<TStrings> ExportData(new TStringList());
  7334. switch (Export)
  7335. {
  7336. case pePath:
  7337. ExportData->Add(DirView->PathName);
  7338. break;
  7339. case peFileList:
  7340. case peFullFileList:
  7341. {
  7342. bool FullPath = (Export == peFullFileList);
  7343. DirView->CreateFileList(false, FullPath, ExportData.get());
  7344. for (int Index = 0; Index < ExportData->Count; Index++)
  7345. {
  7346. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7347. {
  7348. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7349. }
  7350. }
  7351. }
  7352. break;
  7353. default:
  7354. DebugFail();
  7355. }
  7356. return ExportData.release();
  7357. }
  7358. //---------------------------------------------------------------------------
  7359. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7360. TPanelExport Export, TPanelExportDestination Destination)
  7361. {
  7362. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7363. PanelExportStore(Side, Export, Destination, ExportData.get());
  7364. }
  7365. //---------------------------------------------------------------------------
  7366. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7367. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7368. TStrings * ExportData)
  7369. {
  7370. if (Destination == pedClipboard)
  7371. {
  7372. TInstantOperationVisualizer Visualizer;
  7373. CopyToClipboard(ExportData);
  7374. }
  7375. else
  7376. {
  7377. DebugFail();
  7378. }
  7379. }
  7380. //---------------------------------------------------------------------------
  7381. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7382. {
  7383. TCustomDirView * DirView = this->DirView(Side);
  7384. UnicodeString Mask = DirView->Mask;
  7385. if (DoFilterMaskDialog(DirView, Mask))
  7386. {
  7387. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7388. Configuration->Usage->Inc(L"Filters");
  7389. }
  7390. }
  7391. //---------------------------------------------------------------------------
  7392. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7393. {
  7394. return FQueueController->DefaultOperation();
  7395. }
  7396. //---------------------------------------------------------------------------
  7397. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7398. TQueueOperation Operation, void ** Param)
  7399. {
  7400. switch (Operation)
  7401. {
  7402. case qoPreferences:
  7403. return true;
  7404. case qoGoTo:
  7405. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7406. case qoOnceEmpty:
  7407. return IsAnythingQueued();
  7408. default:
  7409. return FQueueController->AllowOperation(Operation, Param);
  7410. }
  7411. }
  7412. //---------------------------------------------------------------------------
  7413. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7414. {
  7415. if (DebugAlwaysTrue(QueueView3->Visible))
  7416. {
  7417. QueueView3->SetFocus();
  7418. }
  7419. }
  7420. //---------------------------------------------------------------------------
  7421. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7422. TQueueOperation Operation, void * Param)
  7423. {
  7424. if (Operation == qoGoTo)
  7425. {
  7426. GoToQueue();
  7427. }
  7428. else if (Operation == qoPreferences)
  7429. {
  7430. PreferencesDialog(pmQueue);
  7431. }
  7432. else
  7433. {
  7434. FQueueController->ExecuteOperation(Operation, Param);
  7435. }
  7436. }
  7437. //---------------------------------------------------------------------------
  7438. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7439. {
  7440. return (Queue != NULL) && Queue->Enabled;
  7441. }
  7442. //---------------------------------------------------------------------------
  7443. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7444. {
  7445. DebugAssert(Queue != NULL);
  7446. if (Queue != NULL)
  7447. {
  7448. Queue->Enabled = !Queue->Enabled;
  7449. }
  7450. }
  7451. //---------------------------------------------------------------------------
  7452. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7453. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7454. {
  7455. FQueueActedItem = QueueView3->ItemFocused;
  7456. }
  7457. //---------------------------------------------------------------------------
  7458. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7459. {
  7460. return TopDock->Height + QueueSplitter->Height;
  7461. }
  7462. //---------------------------------------------------------------------------
  7463. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7464. {
  7465. return
  7466. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7467. (QueueDock->Visible ? QueueDock->Height : 0) +
  7468. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7469. }
  7470. //---------------------------------------------------------------------------
  7471. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7472. {
  7473. return ScaleByTextHeight(this, 48);
  7474. }
  7475. //---------------------------------------------------------------------------
  7476. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7477. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7478. {
  7479. // when queue is hidden by double-clicking splitter, stray attempt to
  7480. // resize the panel with strange value arrives, make sure it is ignored
  7481. if (ComponentVisible[fcQueueView])
  7482. {
  7483. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7484. if (NewSize > MaxHeightLimit)
  7485. {
  7486. NewSize = MaxHeightLimit;
  7487. }
  7488. int MinHeightLimit =
  7489. GetStaticQueuePanelComponentsHeight() +
  7490. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7491. GetMinQueueViewHeight();
  7492. if (NewSize < MinHeightLimit)
  7493. {
  7494. NewSize = MinHeightLimit;
  7495. }
  7496. }
  7497. else
  7498. {
  7499. Accept = false;
  7500. }
  7501. }
  7502. //---------------------------------------------------------------------------
  7503. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7504. {
  7505. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7506. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7507. if (QueueViewHeight < GetMinQueueViewHeight())
  7508. {
  7509. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7510. }
  7511. }
  7512. //---------------------------------------------------------------------------
  7513. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7514. TDragObject *& /*DragObject*/)
  7515. {
  7516. FQueueActedItem = QueueView3->ItemFocused;
  7517. }
  7518. //---------------------------------------------------------------------------
  7519. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7520. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7521. {
  7522. Accept = true;
  7523. if (Source == QueueView3)
  7524. {
  7525. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7526. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7527. if (Accept)
  7528. {
  7529. TQueueItemProxy * QueueItem;
  7530. TQueueItemProxy * DestQueueItem;
  7531. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7532. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7533. Accept = (QueueItem != DestQueueItem) &&
  7534. (QueueItem->Status == TQueueItem::qsPending) &&
  7535. (DestQueueItem->Status == TQueueItem::qsPending);
  7536. }
  7537. }
  7538. }
  7539. //---------------------------------------------------------------------------
  7540. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7541. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7542. {
  7543. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7544. {
  7545. TQueueItemProxy * QueueItem;
  7546. TQueueItemProxy * DestQueueItem;
  7547. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7548. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7549. QueueItem->Move(DestQueueItem);
  7550. }
  7551. }
  7552. //---------------------------------------------------------------------------
  7553. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7554. {
  7555. if ((QueueView3->ItemFocused == NULL) &&
  7556. (QueueView3->Items->Count > 0))
  7557. {
  7558. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7559. }
  7560. QueueLabelUpdateStatus();
  7561. }
  7562. //---------------------------------------------------------------------------
  7563. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7564. {
  7565. QueueLabelUpdateStatus();
  7566. }
  7567. //---------------------------------------------------------------------------
  7568. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7569. {
  7570. QueueLabel->UpdateStatus();
  7571. }
  7572. //---------------------------------------------------------------------------
  7573. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7574. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7575. {
  7576. if (Selected)
  7577. {
  7578. NonVisualDataModule->UpdateNonVisibleActions();
  7579. }
  7580. }
  7581. //---------------------------------------------------------------------------
  7582. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7583. {
  7584. TDragDropFilesEx * Result = NULL;
  7585. if (Sender == SessionsPageControl)
  7586. {
  7587. Result = FSessionsDragDropFilesEx;
  7588. }
  7589. else if (Sender == QueueView3)
  7590. {
  7591. Result = FQueueDragDropFilesEx;
  7592. }
  7593. else
  7594. {
  7595. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7596. if (DirView != NULL)
  7597. {
  7598. Result = DirView->DragDropFilesEx;
  7599. }
  7600. else
  7601. {
  7602. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7603. if (DriveView != NULL)
  7604. {
  7605. Result = DriveView->DragDropFilesEx;
  7606. }
  7607. }
  7608. }
  7609. DebugAssert(Result != NULL);
  7610. return Result;
  7611. }
  7612. //---------------------------------------------------------------------------
  7613. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7614. {
  7615. return (DView->SelCount == DView->FilesCount);
  7616. }
  7617. //---------------------------------------------------------------------------
  7618. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7619. {
  7620. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7621. }
  7622. //---------------------------------------------------------------------------
  7623. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7624. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7625. {
  7626. DebugAssert(!IsLocalBrowserMode());
  7627. TFileOperation Operation;
  7628. switch (Effect)
  7629. {
  7630. case DROPEFFECT_MOVE:
  7631. Operation = foMove;
  7632. break;
  7633. case DROPEFFECT_COPY:
  7634. // occures on WinXP (reported by user)
  7635. default:
  7636. Operation = foCopy;
  7637. break;
  7638. };
  7639. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7640. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7641. if (DragDropFilesEx->FileList->Count > 0)
  7642. {
  7643. TStrings * FileList = new TStringList();
  7644. try
  7645. {
  7646. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7647. {
  7648. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7649. }
  7650. FDragDropOperation = true;
  7651. TTransferOperationParam Param;
  7652. Param.TargetDirectory = TargetPath;
  7653. // upload, no temp dirs
  7654. Param.Temp = false;
  7655. Param.DragDrop = DragDrop;
  7656. Param.Options =
  7657. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7658. if (ForceQueue)
  7659. {
  7660. Param.Queue = asOn;
  7661. }
  7662. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7663. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7664. {
  7665. if (IsFileControl(DropSourceControl, osLocal))
  7666. {
  7667. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7668. }
  7669. else
  7670. {
  7671. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7672. }
  7673. }
  7674. }
  7675. __finally
  7676. {
  7677. FDragDropOperation = false;
  7678. delete FileList;
  7679. }
  7680. }
  7681. }
  7682. //---------------------------------------------------------------------------
  7683. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7684. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7685. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7686. {
  7687. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7688. }
  7689. //---------------------------------------------------------------------------
  7690. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7691. TObject * Sender, int grfKeyState, int & dwEffect)
  7692. {
  7693. DebugAssert(!IsLocalBrowserMode());
  7694. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7695. if ((dwEffect != DROPEFFECT_NONE) &&
  7696. IsFileControl(DropSourceControl, osRemote))
  7697. {
  7698. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7699. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7700. (RemoteDirView->DropTarget == NULL))
  7701. {
  7702. dwEffect = DROPEFFECT_NONE;
  7703. }
  7704. else
  7705. {
  7706. if (dwEffect == DROPEFFECT_COPY)
  7707. {
  7708. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7709. // currently we support copying always (at least via temporary directory);
  7710. // remove associated checks once this all proves stable and working
  7711. bool CopyCapable = true;
  7712. // if we do not support neither of operations, there's no discussion
  7713. if (!MoveCapable && !CopyCapable)
  7714. {
  7715. dwEffect = DROPEFFECT_NONE;
  7716. }
  7717. else
  7718. {
  7719. // The default effect inside remote panel is move,
  7720. // unless we do not support it, but support copy
  7721. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7722. {
  7723. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7724. }
  7725. else
  7726. {
  7727. // with ctrl-down, we want copy unless it is not supported
  7728. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7729. }
  7730. }
  7731. }
  7732. }
  7733. }
  7734. }
  7735. //---------------------------------------------------------------------------
  7736. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7737. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7738. {
  7739. DebugAssert(!IsLocalBrowserMode());
  7740. if (FDDTotalSize >= 0)
  7741. {
  7742. if (File->IsDirectory)
  7743. {
  7744. FDDTotalSize = -1;
  7745. }
  7746. else
  7747. {
  7748. FDDTotalSize += File->Size;
  7749. }
  7750. }
  7751. DebugAssert(!FDragTempDir.IsEmpty());
  7752. // TODO: this is quite ineffective
  7753. // TODO: what if invalid character replacement is disabled?
  7754. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7755. UnicodeString TransferFileName;
  7756. if (Sender == RemoteDriveView)
  7757. {
  7758. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7759. }
  7760. else
  7761. {
  7762. TransferFileName = File->FileName;
  7763. }
  7764. FDDFileList->AddObject(TransferFileName, File);
  7765. }
  7766. //---------------------------------------------------------------------------
  7767. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7768. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7769. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7770. {
  7771. // sometimes we do not get DDEnd so the list is not released
  7772. SAFE_DESTROY(FDDFileList);
  7773. FDDFileList = new TStringList();
  7774. FDragTempDir = WinConfiguration->TemporaryDir();
  7775. FDDTotalSize = 0;
  7776. FDragDropSshTerminate.reset(NULL);
  7777. }
  7778. //---------------------------------------------------------------------------
  7779. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7780. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7781. HRESULT & Result)
  7782. {
  7783. if (Result == DRAGDROP_S_DROP)
  7784. {
  7785. try
  7786. {
  7787. GlobalDragImageList->HideDragImage();
  7788. try
  7789. {
  7790. RemoteFileControlDDTargetDrop();
  7791. }
  7792. catch(ESshTerminate & E)
  7793. {
  7794. FDragDropSshTerminate.reset(E.Clone());
  7795. }
  7796. }
  7797. catch (Exception &E)
  7798. {
  7799. // If downloading fails we need to cancel drag&drop, otherwise
  7800. // Explorer shows error
  7801. // But by the way exception probably never reach this point as
  7802. // it's catched on way.
  7803. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7804. Result = DRAGDROP_S_CANCEL;
  7805. ShowExtendedException(Terminal, &E);
  7806. }
  7807. }
  7808. }
  7809. //---------------------------------------------------------------------------
  7810. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7811. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7812. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7813. {
  7814. TFileMasks::TParams MaskParams;
  7815. MaskParams.Size = Size;
  7816. MaskParams.Modification = Modification;
  7817. // this does not re-parse the mask if it is the same as the last time
  7818. FDirViewMatchMask = Masks;
  7819. bool ImplicitMatch;
  7820. Matches =
  7821. // RecurseInclude parameter has no effect as the Path is empty
  7822. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7823. (AllowImplicitMatches || !ImplicitMatch);
  7824. }
  7825. //---------------------------------------------------------------------------
  7826. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7827. TObject * Sender, TListItem * Item, WORD & Indexes)
  7828. {
  7829. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7830. UnicodeString Ext;
  7831. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7832. {
  7833. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7834. }
  7835. else
  7836. {
  7837. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7838. }
  7839. if (SameText(Ext, Configuration->PartialExt))
  7840. {
  7841. Indexes |= oiPartial;
  7842. }
  7843. }
  7844. //---------------------------------------------------------------------------
  7845. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7846. {
  7847. return
  7848. DirViewEnabled(osCurrent) &&
  7849. DirView(osCurrent)->CanPasteFromClipBoard();
  7850. }
  7851. //---------------------------------------------------------------------------
  7852. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7853. {
  7854. bool Result = false;
  7855. if (CanPasteToDirViewFromClipBoard())
  7856. {
  7857. Result = true;
  7858. }
  7859. else
  7860. {
  7861. UnicodeString ClipboardText;
  7862. if (NonEmptyTextFromClipboard(ClipboardText))
  7863. {
  7864. if (StoredSessions->IsUrl(ClipboardText))
  7865. {
  7866. Result = true;
  7867. }
  7868. else
  7869. {
  7870. Result = DirViewEnabled(osCurrent);
  7871. }
  7872. }
  7873. }
  7874. return Result;
  7875. }
  7876. //---------------------------------------------------------------------------
  7877. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7878. {
  7879. if (DoesClipboardContainOurFiles())
  7880. {
  7881. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7882. {
  7883. DebugAssert(!IsLocalBrowserMode());
  7884. TTerminalManager * Manager = TTerminalManager::Instance();
  7885. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7886. Manager->ActiveTerminal = FClipboardTerminal;
  7887. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7888. }
  7889. }
  7890. else if (CanPasteToDirViewFromClipBoard())
  7891. {
  7892. DirView(osCurrent)->PasteFromClipBoard();
  7893. }
  7894. else
  7895. {
  7896. UnicodeString ClipboardText;
  7897. if (NonEmptyTextFromClipboard(ClipboardText))
  7898. {
  7899. if (StoredSessions->IsUrl(ClipboardText))
  7900. {
  7901. NewSession(false, ClipboardText);
  7902. }
  7903. else
  7904. {
  7905. DirView(osCurrent)->Path = ClipboardText;
  7906. }
  7907. }
  7908. }
  7909. }
  7910. //---------------------------------------------------------------------------
  7911. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7912. {
  7913. // TBD
  7914. }
  7915. //---------------------------------------------------------------------------
  7916. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7917. {
  7918. TCustomDirView * ADirView = DirView(Side);
  7919. ADirView->SelectAll(Mode);
  7920. ADirView->SetFocus();
  7921. }
  7922. //---------------------------------------------------------------------------
  7923. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7924. {
  7925. TCustomDirView * ADirView = DirView(Side);
  7926. TFileFilter Filter;
  7927. DefaultFileFilter(Filter);
  7928. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7929. {
  7930. Configuration->Usage->Inc(L"MaskSelections");
  7931. ADirView->SelectFiles(Filter, Select);
  7932. ADirView->SetFocus();
  7933. }
  7934. }
  7935. //---------------------------------------------------------------------------
  7936. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7937. {
  7938. TCustomDirView * ADirView = DirView(Side);
  7939. ADirView->RestoreSelectedNames();
  7940. ADirView->SetFocus();
  7941. }
  7942. //---------------------------------------------------------------------------
  7943. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7944. {
  7945. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7946. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7947. {
  7948. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7949. UnicodeString Ext;
  7950. if (!IsSideLocalBrowser(osCurrent))
  7951. {
  7952. Ext = UnixExtractFileExt(FileName);
  7953. }
  7954. else
  7955. {
  7956. Ext = ExtractFileExt(FileName);
  7957. }
  7958. if (Ext.IsEmpty())
  7959. {
  7960. Ext = L".";
  7961. }
  7962. TFileFilter Filter;
  7963. Filter.Masks = FORMAT(L"*%s", (Ext));
  7964. Filter.Directories = false;
  7965. CurrentDirView->SelectFiles(Filter, Select);
  7966. }
  7967. }
  7968. //---------------------------------------------------------------------------
  7969. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7970. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7971. {
  7972. UnicodeString Result;
  7973. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7974. {
  7975. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  7976. }
  7977. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  7978. {
  7979. // noop
  7980. }
  7981. else
  7982. {
  7983. Result =
  7984. FMTLOAD(FILE_INFO_FORMAT,
  7985. (FormatBytes(FileInfo.SelectedSize),
  7986. FormatBytes(FileInfo.FilesSize),
  7987. FormatNumber(FileInfo.SelectedCount),
  7988. FormatNumber(FileInfo.FilesCount)));
  7989. }
  7990. return Result;
  7991. }
  7992. //---------------------------------------------------------------------------
  7993. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7994. TTBXStatusPanel * Panel, TOperationSide Side)
  7995. {
  7996. if (Panel->Index == 1)
  7997. {
  7998. ToggleShowHiddenFiles();
  7999. }
  8000. else if (Panel->Index == 2)
  8001. {
  8002. Filter(Side);
  8003. }
  8004. }
  8005. //---------------------------------------------------------------------------
  8006. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8007. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8008. {
  8009. DebugAssert(!StatusBar->SimplePanel);
  8010. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8011. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8012. }
  8013. //---------------------------------------------------------------------------
  8014. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8015. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8016. {
  8017. DebugAssert(StatusBar->Panels->Count >= 3);
  8018. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8019. if (FileInfo.HiddenCount > 0)
  8020. {
  8021. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8022. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8023. }
  8024. else
  8025. {
  8026. HiddenFilesPanel->ViewPriority = 0;
  8027. // not really necessary, just to cleanup no-longer-valid data
  8028. HiddenFilesPanel->Caption = L"";
  8029. }
  8030. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8031. if (FileInfo.FilteredCount > 0)
  8032. {
  8033. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8034. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8035. }
  8036. else
  8037. {
  8038. FilteredFilesPanel->ViewPriority = 0;
  8039. // not really necessary, just to cleanup no-longer-valid data
  8040. FilteredFilesPanel->Caption = L"";
  8041. }
  8042. }
  8043. //---------------------------------------------------------------------------
  8044. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8045. TObject * /*Sender*/)
  8046. {
  8047. if (DirView(osOther)->Enabled)
  8048. {
  8049. DirView(osOther)->SetFocus();
  8050. }
  8051. }
  8052. //---------------------------------------------------------------------------
  8053. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8054. {
  8055. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8056. switch (Config.Show)
  8057. {
  8058. case qvShow:
  8059. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8060. {
  8061. Config.Show = qvHide;
  8062. }
  8063. else
  8064. {
  8065. Config.Show = Config.LastHideShow;
  8066. }
  8067. break;
  8068. case qvHideWhenEmpty:
  8069. if (ComponentVisible[fcQueueView])
  8070. {
  8071. Config.Show = qvHide;
  8072. }
  8073. else
  8074. {
  8075. Config.LastHideShow = Config.Show;
  8076. Config.Show = qvShow;
  8077. }
  8078. break;
  8079. case qvHide:
  8080. Config.LastHideShow = Config.Show;
  8081. Config.Show = qvShow;
  8082. break;
  8083. }
  8084. WinConfiguration->QueueView = Config;
  8085. }
  8086. //---------------------------------------------------------------------------
  8087. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8088. {
  8089. UnicodeString Result;
  8090. if (FTerminal != NULL)
  8091. {
  8092. switch (WinConfiguration->PathInCaption)
  8093. {
  8094. case picShort:
  8095. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8096. break;
  8097. case picFull:
  8098. Result = FTerminal->CurrentDirectory;
  8099. break;
  8100. }
  8101. }
  8102. return Result;
  8103. }
  8104. //---------------------------------------------------------------------------
  8105. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8106. {
  8107. TColor Result = GetWindowColor(FSessionColor);
  8108. return Result;
  8109. }
  8110. //---------------------------------------------------------------------------
  8111. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8112. {
  8113. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8114. return Result;
  8115. }
  8116. //---------------------------------------------------------------------------
  8117. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8118. {
  8119. TTerminalManager::Instance()->UpdateAppTitle();
  8120. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8121. // background to gray on Windows 7 (works on Windows 10).
  8122. // See also EnableControl
  8123. if (Showing)
  8124. {
  8125. if (Terminal != NULL)
  8126. {
  8127. // Update path when it changes
  8128. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8129. {
  8130. UpdateSessionTab(SessionsPageControl->ActivePage);
  8131. }
  8132. }
  8133. NonVisualDataModule->ReconnectSessionAction->Update();
  8134. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8135. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8136. CenterReconnectToolbar();
  8137. bool HasTerminal = HasActiveTerminal();
  8138. RemoteDirView->Enabled = HasTerminal;
  8139. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8140. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8141. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8142. RemoteDriveView->Color = RemoteDirView->Color;
  8143. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8144. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8145. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8146. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8147. QueueFileList->Enabled = QueueView3->Enabled;
  8148. QueueFileList->Color = QueueView3->Color;
  8149. QueueFileList->Font->Color = QueueView3->Font->Color;
  8150. QueueLabelUpdateStatus();
  8151. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8152. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8153. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  8154. }
  8155. }
  8156. //---------------------------------------------------------------------------
  8157. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8158. {
  8159. UpdateControls();
  8160. }
  8161. //---------------------------------------------------------------------------
  8162. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8163. TObject * Sender)
  8164. {
  8165. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8166. DebugAssert(DirView != NULL);
  8167. DoDirViewLoaded(DirView);
  8168. TransferPresetAutoSelect();
  8169. }
  8170. //---------------------------------------------------------------------------
  8171. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8172. {
  8173. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8174. // first run after installation
  8175. if (double(Updates.LastCheck) == 0)
  8176. {
  8177. // make sure next time there will be an update (if enabled)
  8178. Updates.LastCheck = TDateTime(1);
  8179. WinConfiguration->Updates = Updates;
  8180. }
  8181. else if ((double(Updates.Period) > 0) &&
  8182. (Now() - Updates.LastCheck >= Updates.Period))
  8183. {
  8184. TThreadMethod OnUpdatesChecked = NULL;
  8185. if (!IsUWP())
  8186. {
  8187. OnUpdatesChecked = UpdatesChecked;
  8188. }
  8189. StartUpdateThread(OnUpdatesChecked);
  8190. }
  8191. }
  8192. //---------------------------------------------------------------------------
  8193. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8194. {
  8195. UnicodeString Message;
  8196. bool New;
  8197. TQueryType Type;
  8198. GetUpdatesMessage(Message, New, Type, false);
  8199. if (!Message.IsEmpty())
  8200. {
  8201. if (New)
  8202. {
  8203. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8204. }
  8205. if (!New && (Type != qtWarning))
  8206. {
  8207. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8208. }
  8209. else
  8210. {
  8211. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8212. }
  8213. if (New)
  8214. {
  8215. Configuration->Usage->Inc(L"UpdateNotifications");
  8216. }
  8217. }
  8218. }
  8219. //---------------------------------------------------------------------------
  8220. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8221. {
  8222. RestoreApp();
  8223. bool CanDisplay = !NonVisualDataModule->Busy;
  8224. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8225. {
  8226. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8227. }
  8228. if (CanDisplay)
  8229. {
  8230. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8231. CheckForUpdates(true);
  8232. }
  8233. else
  8234. {
  8235. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8236. }
  8237. }
  8238. //---------------------------------------------------------------------------
  8239. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8240. TCopyParamRuleData & Data)
  8241. {
  8242. DebugAssert(Terminal != NULL);
  8243. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8244. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8245. Data.RemoteDirectory = RemoteDirView->PathName;
  8246. }
  8247. //---------------------------------------------------------------------------
  8248. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8249. {
  8250. // Terminal can be null when we are changing local directory implicitly,
  8251. // because it has been deleted, while no session is connected
  8252. // (Login dialog is open)
  8253. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8254. {
  8255. DebugAssert(!IsLocalBrowserMode());
  8256. TCopyParamRuleData Data;
  8257. GetTransferPresetAutoSelectData(Data);
  8258. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8259. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8260. if (CopyParamIndex < 0)
  8261. {
  8262. // there is no preset that matches autoselection
  8263. // set preset that we consider "default"
  8264. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8265. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8266. }
  8267. else
  8268. {
  8269. // there is preset matching autoselection
  8270. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8271. if (CopyParamName == FCopyParamAutoSelected)
  8272. {
  8273. // autoselected the same preset as the last time
  8274. // make no change (i.e. preserve custom user preset, if any)
  8275. }
  8276. else
  8277. {
  8278. // autoselected the different preset then the last time (or there
  8279. // was default preset set)
  8280. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8281. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8282. }
  8283. }
  8284. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8285. {
  8286. if (CopyParamIndex >= 0)
  8287. {
  8288. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8289. }
  8290. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8291. try
  8292. {
  8293. int Fmt =
  8294. (CopyParamIndex < 0) ?
  8295. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8296. COPY_PARAM_AUTOSELECTED;
  8297. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8298. Data->Message = MainInstructions(Message);
  8299. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8300. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8301. CopyParamAttrs);
  8302. if (CopyParamIndex >= 0)
  8303. {
  8304. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8305. Info = FORMAT(L"%s\n \n%s", (Info,
  8306. FMTLOAD(COPY_PARAM_RULE,
  8307. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8308. }
  8309. Data->Message += L"\n\n" + Info;
  8310. if (WinConfiguration->CopyParamAutoSelectNotice)
  8311. {
  8312. TransferPresetNoteMessage(Data, true);
  8313. }
  8314. else
  8315. {
  8316. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8317. Data = NULL; // ownership passed
  8318. }
  8319. }
  8320. __finally
  8321. {
  8322. delete Data;
  8323. }
  8324. }
  8325. }
  8326. }
  8327. //---------------------------------------------------------------------------
  8328. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8329. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8330. {
  8331. DebugAssert(NoteData != NULL);
  8332. DebugAssert(!IsLocalBrowserMode());
  8333. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8334. TQueryButtonAlias Aliases[1];
  8335. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8336. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8337. Params.Aliases = Aliases;
  8338. Params.AliasesCount = LENOF(Aliases);
  8339. unsigned int Result =
  8340. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8341. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8342. switch (Result)
  8343. {
  8344. case qaNeverAskAgain:
  8345. DebugAssert(AllowNeverAskAgain);
  8346. WinConfiguration->CopyParamAutoSelectNotice = false;
  8347. break;
  8348. case qaIgnore:
  8349. PreferencesDialog(pmPresets);
  8350. break;
  8351. }
  8352. }
  8353. //---------------------------------------------------------------------------
  8354. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8355. {
  8356. // as of now useless, as this is used for notes only, never for balloons, ...
  8357. RestoreApp();
  8358. // .. and we should never be busy here
  8359. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8360. {
  8361. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8362. }
  8363. }
  8364. //---------------------------------------------------------------------------
  8365. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8366. TPreferencesMode APreferencesMode)
  8367. {
  8368. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8369. TCopyParamRuleData Data;
  8370. if (Terminal != NULL)
  8371. {
  8372. PreferencesData.reset(new TPreferencesDialogData());
  8373. GetTransferPresetAutoSelectData(Data);
  8374. PreferencesData->CopyParamRuleData = &Data;
  8375. }
  8376. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8377. }
  8378. //---------------------------------------------------------------------------
  8379. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8380. const TCustomCommandType & Command)
  8381. {
  8382. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8383. {
  8384. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8385. }
  8386. }
  8387. //---------------------------------------------------------------------------
  8388. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8389. {
  8390. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8391. TCustomCommandType Command;
  8392. // make sure we use local custom command when remote are not supported
  8393. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8394. {
  8395. Command = FLastCustomCommand;
  8396. }
  8397. else
  8398. {
  8399. Command.Params = Command.Params | ccLocal;
  8400. }
  8401. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8402. FEditingFocusedAdHocCommand = OnFocused;
  8403. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8404. int Options =
  8405. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8406. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8407. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8408. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8409. {
  8410. FLastCustomCommand = Command;
  8411. UpdateCustomCommandsToolbar();
  8412. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8413. }
  8414. }
  8415. //---------------------------------------------------------------------------
  8416. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8417. {
  8418. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8419. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8420. DebugAssert(State > 0);
  8421. if (State <= 0)
  8422. {
  8423. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8424. }
  8425. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8426. }
  8427. //---------------------------------------------------------------------------
  8428. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8429. TCustomCommandType & Command, int & State)
  8430. {
  8431. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8432. if (Result)
  8433. {
  8434. Command = FLastCustomCommand;
  8435. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8436. }
  8437. return Result;
  8438. }
  8439. //---------------------------------------------------------------------------
  8440. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8441. {
  8442. ResetIncrementalSearch();
  8443. }
  8444. //---------------------------------------------------------------------------
  8445. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8446. {
  8447. DebugAssert(ComponentVisible[Component]);
  8448. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8449. }
  8450. //---------------------------------------------------------------------------
  8451. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8452. {
  8453. // when queue panel is resized here directly, the status bar is stretched
  8454. // over whole space the panel occupied
  8455. PostComponentHide(fcQueueView);
  8456. }
  8457. //---------------------------------------------------------------------------
  8458. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8459. {
  8460. ComponentVisible[fcQueueFileList] = false;
  8461. }
  8462. //---------------------------------------------------------------------------
  8463. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8464. {
  8465. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8466. RefreshColorMode();
  8467. ResetSysDarkTheme();
  8468. ConfigurationChanged();
  8469. ConfigureInterface();
  8470. // Should be called for all controls
  8471. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8472. }
  8473. //---------------------------------------------------------------------------
  8474. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8475. {
  8476. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8477. if (!FInvalid &&
  8478. (Message.LParam != 0) &&
  8479. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8480. {
  8481. ThemeChanged();
  8482. }
  8483. TForm::Dispatch(&Message);
  8484. }
  8485. //---------------------------------------------------------------------------
  8486. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8487. {
  8488. TMessage * M = static_cast<TMessage*>(Message);
  8489. switch (M->Msg)
  8490. {
  8491. case CM_DIALOGCHAR:
  8492. CMDialogChar(*M);
  8493. break;
  8494. case WM_APPCOMMAND:
  8495. WMAppCommand(*M);
  8496. break;
  8497. case WM_SYSCOMMAND:
  8498. WMSysCommand(*M);
  8499. break;
  8500. case WM_QUERYENDSESSION:
  8501. WMQueryEndSession(*M);
  8502. break;
  8503. case WM_ENDSESSION:
  8504. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8505. break;
  8506. #ifdef _DEBUG
  8507. case WM_WINDOWPOSCHANGED:
  8508. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8509. break;
  8510. case CM_CUSTOMSTYLECHANGED:
  8511. TForm::Dispatch(Message);
  8512. break;
  8513. #endif
  8514. case WM_COMPONENT_HIDE:
  8515. {
  8516. Byte Component = static_cast<Byte>(M->WParam);
  8517. // sanity check
  8518. if (ComponentVisible[Component])
  8519. {
  8520. // special treatment
  8521. if (Component == fcQueueView)
  8522. {
  8523. ToggleQueueVisibility();
  8524. DebugAssert(!ComponentVisible[fcQueueView]);
  8525. }
  8526. else
  8527. {
  8528. ComponentVisible[Component] = false;
  8529. }
  8530. }
  8531. }
  8532. break;
  8533. case WM_COPYDATA:
  8534. WMCopyData(*M);
  8535. break;
  8536. case WM_MANAGES_CAPTION:
  8537. // caption managed in TTerminalManager::UpdateAppTitle()
  8538. M->Result = 1;
  8539. break;
  8540. case WM_WANTS_MOUSEWHEEL:
  8541. M->Result = 1;
  8542. break;
  8543. case CM_SHOWINGCHANGED:
  8544. CMShowingChanged(*M);
  8545. break;
  8546. case WM_CLOSE:
  8547. WMClose(*M);
  8548. break;
  8549. case WM_DPICHANGED:
  8550. WMDpiChanged(*M);
  8551. break;
  8552. case CM_DPICHANGED:
  8553. CMDpiChanged(*M);
  8554. break;
  8555. case WM_SETTINGCHANGE:
  8556. WMSettingChange(*M);
  8557. break;
  8558. case CM_DIALOGKEY:
  8559. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8560. break;
  8561. default:
  8562. TForm::Dispatch(Message);
  8563. break;
  8564. }
  8565. }
  8566. //---------------------------------------------------------------------------
  8567. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8568. {
  8569. // noop
  8570. }
  8571. //---------------------------------------------------------------------------
  8572. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8573. {
  8574. TForm::Dispatch(&Message);
  8575. FSessionColors->Clear();
  8576. AddFixedSessionImages();
  8577. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8578. UpdateImages();
  8579. }
  8580. //---------------------------------------------------------------------------
  8581. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8582. {
  8583. TForm::Dispatch(&Message);
  8584. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8585. UpdatePixelsPerInchMainWindowCounter();
  8586. }
  8587. //---------------------------------------------------------------------------
  8588. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8589. {
  8590. // Cannot close window while we are busy.
  8591. // We cannot test this in FormCloseQuery as that is called also from
  8592. // Close(), which is called by CloseApplicationAction. So we can be busy
  8593. // there already even, when it is legitimate to close the application.
  8594. // Possibly a better place to handle this would be WMSysCommand.
  8595. if (NonVisualDataModule->Busy)
  8596. {
  8597. Message.Result = 1;
  8598. }
  8599. else
  8600. {
  8601. TForm::Dispatch(&Message);
  8602. }
  8603. }
  8604. //---------------------------------------------------------------------------
  8605. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8606. {
  8607. TForm::Dispatch(&Message);
  8608. if (Showing && (Terminal == NULL))
  8609. {
  8610. // When we are starting minimized (i.e. from an installer),
  8611. // postpone showing Login dialog until we get restored.
  8612. // Otherwise the Login dialog (and Authentication window) show restored
  8613. // over invisible (minimized) main window.
  8614. if (WindowState == wsMinimized)
  8615. {
  8616. FNeedSession = true;
  8617. }
  8618. else
  8619. {
  8620. // This happens before application ever goes idle, so the toolbars would
  8621. // stay enabled (initial state) until the Login dialog is dismissed.
  8622. UpdateActions();
  8623. NonVisualDataModule->StartBusy();
  8624. try
  8625. {
  8626. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8627. // otherwise the dialog does not receive focus.
  8628. // With Commander interface the ProcessMessages is called already
  8629. // by TDriveView, but with Explorer interface, we need to call it explicily
  8630. Application->ProcessMessages();
  8631. // do not reload sessions, they have been loaded just now (optimization)
  8632. NeedSession(true);
  8633. }
  8634. __finally
  8635. {
  8636. NonVisualDataModule->EndBusy();
  8637. }
  8638. }
  8639. }
  8640. }
  8641. //---------------------------------------------------------------------------
  8642. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8643. {
  8644. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8645. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8646. }
  8647. //---------------------------------------------------------------------------
  8648. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8649. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8650. int & MaxHeight)
  8651. {
  8652. // workaround for bug in TWinControl.CalcConstraints
  8653. // Check for empty rect (restore from iconic state) is done there only after
  8654. // call to AdjustClientRect, which enlarges the rect (for forms).
  8655. TRect R = GetClientRect();
  8656. // when restoring from iconic state, place no restrictions
  8657. if (IsRectEmpty(R))
  8658. {
  8659. MinWidth = 0;
  8660. MinHeight = 0;
  8661. MaxWidth = 32000;
  8662. MaxHeight = 32000;
  8663. }
  8664. }
  8665. //---------------------------------------------------------------------------
  8666. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8667. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8668. {
  8669. // terminal can be already closed (e.g. dropped connection)
  8670. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8671. {
  8672. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8673. try
  8674. {
  8675. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8676. }
  8677. catch(...)
  8678. {
  8679. if (!Terminal->Active)
  8680. {
  8681. Close = true;
  8682. }
  8683. throw;
  8684. }
  8685. }
  8686. }
  8687. //---------------------------------------------------------------------------
  8688. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8689. {
  8690. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8691. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8692. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8693. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8694. {
  8695. OnGetSpaceAvailable = GetSpaceAvailable;
  8696. }
  8697. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8698. OnGetSpaceAvailable);
  8699. }
  8700. //---------------------------------------------------------------------------
  8701. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8702. {
  8703. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8704. Terminal->FillSessionDataForCode(Data.get());
  8705. return Data.release();
  8706. }
  8707. //---------------------------------------------------------------------------
  8708. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8709. {
  8710. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8711. DoGenerateUrlDialog(Data.get(), Paths);
  8712. }
  8713. //---------------------------------------------------------------------------
  8714. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8715. {
  8716. GenerateUrl(NULL);
  8717. }
  8718. //---------------------------------------------------------------------------
  8719. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8720. {
  8721. std::unique_ptr<TStrings> Paths(new TStringList());
  8722. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8723. GenerateUrl(Paths.get());
  8724. }
  8725. //---------------------------------------------------------------------------
  8726. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8727. {
  8728. FSessionColor = value;
  8729. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8730. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8731. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8732. DebugAssert(ColorItem != NULL);
  8733. ColorItem->Color = C;
  8734. NonVisualDataModule->ColorMenuItem->Color = C;
  8735. UpdateControls();
  8736. }
  8737. //---------------------------------------------------------------------------
  8738. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8739. {
  8740. if (value != FSessionColor)
  8741. {
  8742. UpdateSessionColor(value);
  8743. // Is null when called from LastTerminalClosed
  8744. if (Terminal != NULL)
  8745. {
  8746. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8747. }
  8748. }
  8749. }
  8750. //---------------------------------------------------------------------------
  8751. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8752. {
  8753. bool Result = FNoteTimer->Enabled;
  8754. if (Result)
  8755. {
  8756. // cannot cancel note too early
  8757. bool NotEarly =
  8758. (Now() - FNoteShown >
  8759. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8760. if (Force || NotEarly)
  8761. {
  8762. FNoteTimer->Enabled = false;
  8763. FNote = L"";
  8764. SAFE_DESTROY(FNoteData);
  8765. FOnNoteClick = NULL;
  8766. FNoteHints = FNotes->Text;
  8767. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8768. UpdateStatusBar();
  8769. }
  8770. }
  8771. return Result;
  8772. }
  8773. //---------------------------------------------------------------------------
  8774. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8775. {
  8776. DebugAssert(FNoteTimer->Enabled);
  8777. CancelNote(true);
  8778. }
  8779. //---------------------------------------------------------------------------
  8780. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8781. {
  8782. int P = Note.Pos(L"\n");
  8783. if (P > 0)
  8784. {
  8785. Note.SetLength(P - 1);
  8786. }
  8787. FNotes->Add(FORMAT(L"[%s] %s",
  8788. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8789. while (FNotes->Count > 10)
  8790. {
  8791. FNotes->Delete(0);
  8792. }
  8793. if (UpdateNow)
  8794. {
  8795. FNoteHints = FNotes->Text;
  8796. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8797. UpdateStatusBar();
  8798. }
  8799. }
  8800. //---------------------------------------------------------------------------
  8801. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8802. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8803. {
  8804. int P = Note.Pos(L"\n");
  8805. if (P > 0)
  8806. {
  8807. Note.SetLength(P - 1);
  8808. }
  8809. FNoteHints = FNotes->Text;
  8810. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8811. FNote = Note;
  8812. SAFE_DESTROY(FNoteData);
  8813. FNoteData = NoteData;
  8814. FOnNoteClick = OnNoteClick;
  8815. AddNote(Note, false);
  8816. UpdateStatusBar();
  8817. FNoteShown = Now();
  8818. FNoteTimer->Enabled = false;
  8819. if (Seconds == 0)
  8820. {
  8821. Seconds = WinConfiguration->NotificationsTimeout;
  8822. }
  8823. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8824. FNoteTimer->Enabled = true;
  8825. }
  8826. //---------------------------------------------------------------------------
  8827. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8828. {
  8829. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8830. }
  8831. //---------------------------------------------------------------------------
  8832. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8833. {
  8834. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  8835. {
  8836. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8837. }
  8838. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8839. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8840. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  8841. 0, NULL, NULL);
  8842. }
  8843. //---------------------------------------------------------------------------
  8844. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8845. {
  8846. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8847. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8848. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8849. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8850. }
  8851. //---------------------------------------------------------------------------
  8852. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8853. {
  8854. WinConfiguration->FormatSizeBytes = Style;
  8855. }
  8856. //---------------------------------------------------------------------------
  8857. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8858. {
  8859. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8860. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8861. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8862. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8863. }
  8864. //---------------------------------------------------------------------------
  8865. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8866. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8867. {
  8868. if (Panel->Index == 0)
  8869. {
  8870. if (FOnNoteClick != NULL)
  8871. {
  8872. // prevent the user data from being freed by possible call
  8873. // to CancelNote or PostNote during call to OnNoteClick
  8874. std::unique_ptr<TObject> NoteData(FNoteData);
  8875. TNotifyEvent OnNoteClick = FOnNoteClick;
  8876. FNoteData = NULL;
  8877. // need to cancel the note as we are going to delete its user data
  8878. CancelNote(true);
  8879. OnNoteClick(NoteData.get());
  8880. }
  8881. }
  8882. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8883. {
  8884. FileSystemInfo();
  8885. }
  8886. }
  8887. //---------------------------------------------------------------------------
  8888. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8889. {
  8890. // workaround:
  8891. // 1) for unknown reason, disabling window, while minimized,
  8892. // prevents it from restoring, even if it was enabled again meanwhile
  8893. // 2) when disabling the main window, while another has focus
  8894. // minimize is no longer possible
  8895. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8896. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8897. // Shouldn't we use IsApplicationMinimized() here?
  8898. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8899. {
  8900. Enabled = false;
  8901. }
  8902. FLockLevel++;
  8903. }
  8904. //---------------------------------------------------------------------------
  8905. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8906. {
  8907. DebugAssert(FLockLevel > 0);
  8908. FLockLevel--;
  8909. if (FLockLevel == 0)
  8910. {
  8911. DebugAssert(FLockSuspendLevel == 0);
  8912. Enabled = true;
  8913. }
  8914. }
  8915. //---------------------------------------------------------------------------
  8916. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8917. {
  8918. // We need to make sure that window is enabled when the last modal window closes
  8919. // otherwise focus is not restored correctly.
  8920. // So we re-enable the window when modal window opens and
  8921. // disable it back after is closes
  8922. if (FLockLevel > 0)
  8923. {
  8924. // while we have nesting counter, we know that we never be called
  8925. // recursivelly as Application->OnModalBegin is called only
  8926. // for the top-level modal window
  8927. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8928. {
  8929. // won't be disabled when conditions in LockWindow() were not satisfied
  8930. FDisabledOnLockSuspend = !Enabled;
  8931. // When minimized to tray (or actually when set to SW_HIDE),
  8932. // setting Enabled makes the window focusable even when there's
  8933. // modal window over it
  8934. if (!FTrayIcon->Visible)
  8935. {
  8936. Enabled = true;
  8937. }
  8938. }
  8939. FLockSuspendLevel++;
  8940. }
  8941. }
  8942. //---------------------------------------------------------------------------
  8943. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8944. {
  8945. if (FLockSuspendLevel > 0)
  8946. {
  8947. DebugAssert(FLockLevel > 0);
  8948. FLockSuspendLevel--;
  8949. // see comment in SuspendWindowLock
  8950. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8951. {
  8952. // Note that window can be enabled here, when we were minized to tray when
  8953. // was SuspendWindowLock() called.
  8954. // We should possibly do the same check as in LockWindow(),
  8955. // if it is ever possible that the consitions change between
  8956. // SuspendWindowLock() and ResumeWindowLock()
  8957. Enabled = !FDisabledOnLockSuspend;
  8958. }
  8959. }
  8960. }
  8961. //---------------------------------------------------------------------------
  8962. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8963. {
  8964. if (!TextOnly)
  8965. {
  8966. TTBXComboBoxItem * RemotePathComboBox =
  8967. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8968. TStrings * Items = RemotePathComboBox->Strings;
  8969. Items->BeginUpdate();
  8970. try
  8971. {
  8972. Items->Clear();
  8973. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  8974. {
  8975. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8976. while (!IsUnixRootPath(APath))
  8977. {
  8978. int P = APath.LastDelimiter(L'/');
  8979. DebugAssert(P >= 0);
  8980. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8981. APath.SetLength(P - 1);
  8982. }
  8983. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8984. }
  8985. }
  8986. __finally
  8987. {
  8988. RemotePathComboBox->ItemIndex = Items->Count - 1;
  8989. // Setting ItemIndex to -1 does not reset its text
  8990. if (Items->Count == 0)
  8991. {
  8992. RemotePathComboBox->Text = L"";
  8993. }
  8994. Items->EndUpdate();
  8995. }
  8996. }
  8997. }
  8998. //---------------------------------------------------------------------------
  8999. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9000. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  9001. int & ImageIndex)
  9002. {
  9003. if (AIndex < 0)
  9004. {
  9005. AIndex = Sender->ItemIndex;
  9006. }
  9007. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9008. }
  9009. //---------------------------------------------------------------------------
  9010. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9011. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9012. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9013. {
  9014. ARect.Left += (10 * AIndex);
  9015. }
  9016. //---------------------------------------------------------------------------
  9017. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9018. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9019. {
  9020. AWidth += (10 * AIndex);
  9021. }
  9022. //---------------------------------------------------------------------------
  9023. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  9024. TObject * Sender)
  9025. {
  9026. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9027. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9028. int Index = RemotePathComboBox->ItemIndex;
  9029. while (Index < RemotePathComboBox->Strings->Count - 1)
  9030. {
  9031. APath = UnixExtractFileDir(APath);
  9032. Index++;
  9033. }
  9034. // VanDyke style paths
  9035. if (APath.IsEmpty())
  9036. {
  9037. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9038. APath = ROOTDIRECTORY;
  9039. }
  9040. if (RemoteDirView->Path != APath)
  9041. {
  9042. RemoteDirView->Path = APath;
  9043. }
  9044. }
  9045. //---------------------------------------------------------------------------
  9046. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9047. {
  9048. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9049. DebugUsedParam(Sender);
  9050. UpdateRemotePathComboBox(true);
  9051. }
  9052. //---------------------------------------------------------------------------
  9053. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9054. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9055. {
  9056. ResetIncrementalSearch();
  9057. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9058. DebugAssert(DirView != NULL);
  9059. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9060. {
  9061. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9062. // OnEditing is called also from TCustomListView::CanEdit
  9063. if (Edit != NULL)
  9064. {
  9065. EditSelectBaseName(Edit);
  9066. }
  9067. }
  9068. }
  9069. //---------------------------------------------------------------------------
  9070. //---------------------------------------------------------------------------
  9071. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9072. {
  9073. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9074. Result->AutoDetectDnD = false;
  9075. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9076. Result->RenderDataOn = rdoEnterAndDropSync;
  9077. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9078. return Result;
  9079. }
  9080. //---------------------------------------------------------------------------
  9081. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9082. {
  9083. TForm::CreateWnd();
  9084. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9085. if (FSessionsDragDropFilesEx == NULL)
  9086. {
  9087. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9088. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9089. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9090. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9091. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9092. }
  9093. if (FQueueDragDropFilesEx == NULL)
  9094. {
  9095. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9096. // No need to set OnDragOver as we do not have any restrictions
  9097. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9098. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9099. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9100. }
  9101. }
  9102. //---------------------------------------------------------------------------
  9103. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9104. {
  9105. TForm::DestroyWnd();
  9106. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9107. FQueueDragDropFilesEx->DragDropControl = NULL;
  9108. }
  9109. //---------------------------------------------------------------------------
  9110. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9111. {
  9112. SideEnter(FCurrentSide);
  9113. FEverShown = true;
  9114. }
  9115. //---------------------------------------------------------------------------
  9116. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9117. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9118. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9119. {
  9120. if (!NonVisualDataModule->Busy)
  9121. {
  9122. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9123. Configuration->Usage->Inc(L"FileFinds");
  9124. LockWindow(true);
  9125. NonVisualDataModule->StartBusy();
  9126. WinConfiguration->LockedInterface = true;
  9127. try
  9128. {
  9129. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9130. }
  9131. __finally
  9132. {
  9133. WinConfiguration->LockedInterface = false;
  9134. NonVisualDataModule->EndBusy();
  9135. UnlockWindow();
  9136. }
  9137. }
  9138. }
  9139. //---------------------------------------------------------------------------
  9140. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9141. {
  9142. if (!NonVisualDataModule->Busy)
  9143. {
  9144. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9145. SetFocus();
  9146. RemoteDirView->Path = UnixExtractFilePath(Path);
  9147. UnicodeString FileName = UnixExtractFileName(Path);
  9148. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9149. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9150. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9151. if (Item == NULL)
  9152. {
  9153. ReloadDirectory(osRemote);
  9154. Item = RemoteDirView->FindFileItem(FileName);
  9155. }
  9156. if (Item != NULL)
  9157. {
  9158. RemoteDirView->ItemFocused = Item;
  9159. RemoteDirView->ItemFocused->MakeVisible(false);
  9160. RemoteDirView->SetFocus();
  9161. }
  9162. }
  9163. }
  9164. //---------------------------------------------------------------------------
  9165. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9166. {
  9167. bool Result = !NonVisualDataModule->Busy;
  9168. if (Result)
  9169. {
  9170. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9171. }
  9172. return Result;
  9173. }
  9174. //---------------------------------------------------------------------------
  9175. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9176. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9177. {
  9178. if (CanOperateOnFoundFiles(ATerminal))
  9179. {
  9180. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9181. FOnFileOperationFinished = OnFileOperationFinished;
  9182. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9183. }
  9184. }
  9185. //---------------------------------------------------------------------------
  9186. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9187. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9188. {
  9189. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9190. }
  9191. //---------------------------------------------------------------------------
  9192. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9193. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9194. {
  9195. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9196. }
  9197. //---------------------------------------------------------------------------
  9198. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9199. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9200. {
  9201. if (CanOperateOnFoundFiles(ATerminal))
  9202. {
  9203. for (int Index = 0; Index < FileList->Count; Index++)
  9204. {
  9205. UnicodeString FileName = FileList->Strings[Index];
  9206. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9207. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9208. OnFileOperationFinished(FileName, true);
  9209. }
  9210. }
  9211. }
  9212. //---------------------------------------------------------------------------
  9213. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9214. {
  9215. FFileFindTerminal = Terminal;
  9216. ShowFileFindDialog(
  9217. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9218. DoDownloadFoundFiles, DoEditFoundFiles);
  9219. }
  9220. //---------------------------------------------------------------------------
  9221. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9222. {
  9223. FTaskbarList = TaskbarList;
  9224. }
  9225. //---------------------------------------------------------------------------
  9226. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9227. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9228. {
  9229. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9230. if (Index >= 0)
  9231. {
  9232. if (Button == mbLeft)
  9233. {
  9234. // "Mouse down" is raised only after tab is switched.
  9235. // If switching tab (switching session) takes long enough for user
  9236. // to actually release the button, "mouse down" is still raised,
  9237. // but we do not get "mouse up" event, so dragging is not cancelled,
  9238. // prevent that by not beginning dragging in the first place.
  9239. if (IsKeyPressed(VK_LBUTTON))
  9240. {
  9241. // when user clicks the "+", we get mouse down only after the session
  9242. // is closed, when new session tab is already on X:Y, so dragging
  9243. // starts, prevent that
  9244. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9245. {
  9246. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9247. if (Terminal != NULL)
  9248. {
  9249. SessionsPageControl->BeginDrag(false);
  9250. }
  9251. }
  9252. }
  9253. }
  9254. else if (Button == mbMiddle)
  9255. {
  9256. // ignore middle-click for "New session tab"
  9257. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9258. if (Terminal != NULL)
  9259. {
  9260. CloseSessionTab(Index);
  9261. }
  9262. }
  9263. }
  9264. }
  9265. //---------------------------------------------------------------------------
  9266. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9267. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9268. {
  9269. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9270. // do not allow dropping on the "+" tab
  9271. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9272. if ((TargetTerminal != NULL) &&
  9273. (SessionsPageControl->ActivePage->PageIndex != Index))
  9274. {
  9275. Configuration->Usage->Inc(L"SessionTabMoves");
  9276. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9277. // but we want to actually prevent that to avoid flicker
  9278. SessionsPageControl->ActivePage->PageIndex = Index;
  9279. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9280. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9281. }
  9282. }
  9283. //---------------------------------------------------------------------------
  9284. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9285. TObject * Sender, TObject * Source, int X, int Y,
  9286. TDragState /*State*/, bool & Accept)
  9287. {
  9288. Accept = (Sender == Source);
  9289. if (Accept)
  9290. {
  9291. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9292. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9293. // do not allow dragging to the "+" tab
  9294. Accept = (Terminal != NULL);
  9295. }
  9296. }
  9297. //---------------------------------------------------------------------------
  9298. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9299. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9300. {
  9301. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9302. if (Index < 0)
  9303. {
  9304. Effect = DROPEFFECT_NONE;
  9305. }
  9306. else
  9307. {
  9308. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9309. // do not allow dropping on the "+" tab
  9310. if (TargetTerminal == NULL)
  9311. {
  9312. Effect = DROPEFFECT_NONE;
  9313. }
  9314. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9315. {
  9316. Effect = DROPEFFECT_COPY;
  9317. }
  9318. }
  9319. }
  9320. //---------------------------------------------------------------------------
  9321. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9322. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9323. {
  9324. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9325. // do not allow dropping on the "+" tab
  9326. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9327. if (TargetTerminal != NULL)
  9328. {
  9329. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9330. if (!IsFileControl(DropSourceControl, osRemote))
  9331. {
  9332. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9333. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9334. // Why don't we use Terminal->CurrentDirectory directly?
  9335. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9336. // do not force queue, drag drop
  9337. false, true);
  9338. }
  9339. }
  9340. }
  9341. //---------------------------------------------------------------------------
  9342. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9343. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9344. {
  9345. // Downloads are handled in RemoteFileControlDDEnd
  9346. if (!IsFileControl(DropSourceControl, osRemote))
  9347. {
  9348. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9349. Terminal->CurrentDirectory,
  9350. // force queue, drag drop
  9351. true, true);
  9352. }
  9353. }
  9354. //---------------------------------------------------------------------------
  9355. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9356. {
  9357. FShowing = false;
  9358. // Do not save empty workspace
  9359. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9360. {
  9361. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9362. UnicodeString Name = WorkspaceName();
  9363. DoSaveWorkspace(
  9364. Name, DataList.get(),
  9365. !Configuration->DisablePasswordStoring &&
  9366. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9367. WinConfiguration->LastStoredSession = Name;
  9368. }
  9369. }
  9370. //---------------------------------------------------------------------------
  9371. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9372. {
  9373. TManagedTerminal * ManagedTerminal =
  9374. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9375. if (ManagedTerminal != NULL)
  9376. {
  9377. ManagedTerminal->DirectoryLoaded = Now();
  9378. }
  9379. }
  9380. //---------------------------------------------------------------------------
  9381. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9382. TListItem * /*Item*/, bool /*Selected*/)
  9383. {
  9384. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9385. switch (DirView->LastSelectMethod)
  9386. {
  9387. case smKeyboard:
  9388. Configuration->Usage->Inc(L"KeyboardSelections");
  9389. break;
  9390. case smMouse:
  9391. Configuration->Usage->Inc(L"MouseSelections");
  9392. break;
  9393. }
  9394. }
  9395. //---------------------------------------------------------------------------
  9396. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9397. {
  9398. if (Color != 0)
  9399. {
  9400. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9401. }
  9402. else
  9403. {
  9404. return FSessionTabImageIndex;
  9405. }
  9406. }
  9407. //---------------------------------------------------------------------------
  9408. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9409. {
  9410. TPngImageCollectionItem * Item =
  9411. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9412. FSessionColors->AddPng(Item->PngImage);
  9413. return FSessionColors->Count - 1;
  9414. }
  9415. //---------------------------------------------------------------------------
  9416. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9417. {
  9418. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9419. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9420. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9421. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9422. }
  9423. //---------------------------------------------------------------------------
  9424. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9425. {
  9426. for (int Index = 0; Index < Control->ControlCount; Index++)
  9427. {
  9428. TControl * AControl = Control->Controls[Index];
  9429. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9430. if (WinControl != NULL)
  9431. {
  9432. CollectItemsWithTextDisplayMode(WinControl);
  9433. }
  9434. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9435. if (Toolbar != NULL)
  9436. {
  9437. // we care for top-level items only
  9438. TTBCustomItem * Items = Toolbar->Items;
  9439. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9440. {
  9441. TTBCustomItem * Item = Items->Items[ItemIndex];
  9442. if (((Item->DisplayMode == nbdmImageAndText) ||
  9443. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9444. EligibleForImageDisplayMode(Item))
  9445. {
  9446. FItemsWithTextDisplayMode.insert(Item);
  9447. }
  9448. }
  9449. }
  9450. }
  9451. }
  9452. //---------------------------------------------------------------------------
  9453. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9454. {
  9455. return true;
  9456. }
  9457. //---------------------------------------------------------------------------
  9458. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9459. {
  9460. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9461. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9462. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9463. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9464. bool Result = true;
  9465. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9466. {
  9467. TTBCustomItem * Item = *i;
  9468. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9469. if (Label != NULL)
  9470. {
  9471. // optimization
  9472. if (Label->Visible == SelectiveToolbarText)
  9473. {
  9474. Result = false;
  9475. }
  9476. else
  9477. {
  9478. Label->Visible = SelectiveToolbarText;
  9479. }
  9480. }
  9481. else
  9482. {
  9483. // optimization
  9484. if (Item->DisplayMode == DisplayMode)
  9485. {
  9486. Result = false;
  9487. }
  9488. else
  9489. {
  9490. Item->DisplayMode = DisplayMode;
  9491. }
  9492. }
  9493. ++i;
  9494. }
  9495. if (Result)
  9496. {
  9497. UpdateNewSessionTab();
  9498. }
  9499. return Result;
  9500. }
  9501. //---------------------------------------------------------------------------
  9502. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9503. {
  9504. DebugFail();
  9505. }
  9506. //---------------------------------------------------------------------------
  9507. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9508. {
  9509. // Among other, a lock level is non zero, while directory is being loaded,
  9510. // even when it happens as a result of dirview navigation,
  9511. // i.e. when TNonVisualDataModule is NOT FBusy.
  9512. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9513. // Among other this prevents a panel auto update to occur while
  9514. // directory is changing.
  9515. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9516. }
  9517. //---------------------------------------------------------------------------
  9518. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  9519. {
  9520. // While the window is disabled, we still seem to process menu shortcuts at least,
  9521. // so stop it at least here.
  9522. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9523. return
  9524. (Allowed == aaUpdate) ||
  9525. !NonVisualDataModule->Busy;
  9526. }
  9527. //---------------------------------------------------------------------------
  9528. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9529. {
  9530. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9531. }
  9532. //---------------------------------------------------------------------------
  9533. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9534. {
  9535. // This is somewhat redundant to LockWindow() call from
  9536. // TTerminalManager::TerminalReadDirectoryProgress.
  9537. // But disabling window is known not to block keyboard shorcuts
  9538. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9539. if (Busy > 0)
  9540. {
  9541. if (NonVisualDataModule->Busy)
  9542. {
  9543. State = false;
  9544. }
  9545. else
  9546. {
  9547. NonVisualDataModule->StartBusy();
  9548. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9549. LockWindow();
  9550. }
  9551. }
  9552. else if (Busy < 0)
  9553. {
  9554. UnlockWindow();
  9555. NonVisualDataModule->EndBusy();
  9556. }
  9557. else
  9558. {
  9559. State = NonVisualDataModule->Busy;
  9560. }
  9561. }
  9562. //---------------------------------------------------------------------------
  9563. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9564. {
  9565. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9566. // no context menu for "New session tab"
  9567. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9568. {
  9569. SessionsPageControl->ActivePageIndex = Index;
  9570. if (DebugAlwaysTrue(SessionTabSwitched()))
  9571. {
  9572. // copied from TControl.WMContextMenu
  9573. SendCancelMode(SessionsPageControl);
  9574. // explicit popup instead of using PopupMenu property
  9575. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9576. // while connecting yet not-connected session and hence
  9577. // allowing an access to commands over not-completelly connected session
  9578. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9579. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9580. PopupMenu->PopupComponent = SessionsPageControl;
  9581. PopupMenu->Popup(Point.x, Point.y);
  9582. }
  9583. }
  9584. Handled = true;
  9585. }
  9586. //---------------------------------------------------------------------------
  9587. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9588. {
  9589. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9590. }
  9591. //---------------------------------------------------------------------------
  9592. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9593. {
  9594. Configuration->Usage->Inc(L"PasswordChanges");
  9595. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9596. ChangePasswordData->DisableAuthentationsExceptPassword();
  9597. ChangePasswordData->ChangePassword = true;
  9598. std::unique_ptr<TTerminal> ChangePasswordSession(
  9599. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9600. ChangePasswordSession->AutoReadDirectory = false;
  9601. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9602. {
  9603. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9604. }
  9605. else
  9606. {
  9607. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9608. }
  9609. }
  9610. //---------------------------------------------------------------------------
  9611. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9612. {
  9613. // No nice way to assert SSH2
  9614. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9615. }
  9616. //---------------------------------------------------------------------------
  9617. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9618. {
  9619. TOperationVisualizer OperationVisualizer;
  9620. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9621. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9622. }
  9623. //---------------------------------------------------------------------------
  9624. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9625. {
  9626. TForm::ChangeScale(M, D);
  9627. int APixelsPerInch = GetControlPixelsPerInch(this);
  9628. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9629. try
  9630. {
  9631. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9632. }
  9633. __finally
  9634. {
  9635. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9636. }
  9637. }
  9638. //---------------------------------------------------------------------------
  9639. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9640. {
  9641. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9642. }
  9643. //---------------------------------------------------------------------
  9644. class TPublicControl : public TControl
  9645. {
  9646. friend class TCustomScpExplorerForm;
  9647. };
  9648. //---------------------------------------------------------------------------
  9649. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9650. {
  9651. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9652. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9653. }
  9654. //---------------------------------------------------------------------------
  9655. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9656. {
  9657. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9658. OpenBookmark(Side, Bookmark);
  9659. }
  9660. //---------------------------------------------------------------------------
  9661. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9662. {
  9663. DoBookmarkClick(osLocal, Sender);
  9664. }
  9665. //---------------------------------------------------------------------------
  9666. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9667. {
  9668. DoBookmarkClick(osRemote, Sender);
  9669. }
  9670. //---------------------------------------------------------------------------
  9671. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9672. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9673. {
  9674. // TODO
  9675. if (BookmarkList != NULL)
  9676. {
  9677. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9678. if (!WinConfiguration->UseLocationProfiles)
  9679. {
  9680. std::unique_ptr<TStringList> Directories(new TStringList());
  9681. Directories->CaseSensitive = (Side == osRemote);
  9682. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9683. {
  9684. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9685. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9686. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9687. {
  9688. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9689. Item->Caption = EscapeHotkey(Directory);
  9690. Item->ShortCut = Bookmark->ShortCut;
  9691. Item->OnClick = OnBookmarkClick;
  9692. Item->Tag = reinterpret_cast<int>(Bookmark);
  9693. Directories->Add(Directory);
  9694. Menu->Add(Item.release());
  9695. }
  9696. }
  9697. }
  9698. else
  9699. {
  9700. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9701. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9702. {
  9703. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9704. if (!Bookmark->Node.IsEmpty())
  9705. {
  9706. Folders->Add(Bookmark->Node);
  9707. }
  9708. }
  9709. for (int Index = 0; Index < Folders->Count; Index++)
  9710. {
  9711. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9712. Item->Caption = Folders->Strings[Index];
  9713. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  9714. Folders->Objects[Index] = Item.get();
  9715. Menu->Add(Item.release());
  9716. }
  9717. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9718. {
  9719. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9720. TTBCustomItem * Parent;
  9721. if (!Bookmark->Node.IsEmpty())
  9722. {
  9723. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9724. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9725. }
  9726. else
  9727. {
  9728. Parent = Menu;
  9729. }
  9730. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9731. Item->Caption = Bookmark->Name;
  9732. Item->ShortCut = Bookmark->ShortCut;
  9733. Item->OnClick = OnBookmarkClick;
  9734. Item->Tag = reinterpret_cast<int>(Bookmark);
  9735. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9736. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9737. {
  9738. // No hint for location profiles that are actually mere "bookmarks"
  9739. }
  9740. else
  9741. {
  9742. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9743. UnicodeString LongHint;
  9744. if (!Bookmark->Local.IsEmpty())
  9745. {
  9746. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9747. }
  9748. if (!Bookmark->Remote.IsEmpty())
  9749. {
  9750. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9751. }
  9752. AddToList(Hint, LongHint, L"|");
  9753. Item->Hint = Hint;
  9754. }
  9755. Parent->Add(Item.release());
  9756. }
  9757. }
  9758. AddMenuSeparator(Menu);
  9759. }
  9760. }
  9761. //---------------------------------------------------------------------------
  9762. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9763. {
  9764. Menu->Clear();
  9765. std::unique_ptr<TTBCustomItem> Item;
  9766. Item.reset(new TTBXItem(Owner));
  9767. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9768. Item->Options = Item->Options << tboDefault;
  9769. Menu->Add(Item.release());
  9770. AddMenuSeparator(Menu);
  9771. if (Terminal != NULL)
  9772. {
  9773. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9774. }
  9775. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9776. Item.reset(new TTBXItem(Owner));
  9777. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  9778. Menu->Add(Item.release());
  9779. }
  9780. //---------------------------------------------------------------------------
  9781. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9782. {
  9783. bool Result = true;
  9784. bool Remote = !IsSideLocalBrowser(Side);
  9785. try
  9786. {
  9787. if (Remote)
  9788. {
  9789. Terminal->ExceptionOnFail = true;
  9790. }
  9791. try
  9792. {
  9793. DirView(Side)->Path = Path;
  9794. }
  9795. __finally
  9796. {
  9797. if (Remote)
  9798. {
  9799. Terminal->ExceptionOnFail = false;
  9800. }
  9801. }
  9802. }
  9803. catch (Exception & E)
  9804. {
  9805. if (!Remote || Terminal->Active)
  9806. {
  9807. ShowExtendedExceptionEx(Terminal, &E);
  9808. Result = false;
  9809. }
  9810. else
  9811. {
  9812. throw;
  9813. }
  9814. }
  9815. return Result;
  9816. }
  9817. //---------------------------------------------------------------------------
  9818. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9819. {
  9820. // Make sure there some feedback even when loading tiny local folders
  9821. TInstantOperationVisualizer Visualizer;
  9822. DirView(Side)->ReloadDirectory();
  9823. }
  9824. //---------------------------------------------------------------------------
  9825. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9826. {
  9827. if (Index == SessionsPageControl->TabIndex)
  9828. {
  9829. CloseSession();
  9830. }
  9831. else
  9832. {
  9833. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9834. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9835. TTerminalManager * Manager = TTerminalManager::Instance();
  9836. if (!Terminal->Active)
  9837. {
  9838. Manager->FreeTerminal(Terminal);
  9839. }
  9840. else
  9841. {
  9842. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9843. if (CanCloseQueue(Queue))
  9844. {
  9845. Manager->FreeTerminal(Terminal);
  9846. }
  9847. }
  9848. }
  9849. }
  9850. //---------------------------------------------------------------------------
  9851. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9852. {
  9853. CloseSessionTab(Index);
  9854. }
  9855. //---------------------------------------------------------------------------
  9856. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9857. {
  9858. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9859. {
  9860. TInstantOperationVisualizer Visualizer;
  9861. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9862. // before we create a new data object
  9863. ClipboardClear();
  9864. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9865. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9866. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9867. // Intermediate variable to WORKAROUND a crash in compiler
  9868. TObjectList * ClipboardFakeMonitors =
  9869. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9870. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9871. if (FClipboardDragDropFilesEx.get() == NULL)
  9872. {
  9873. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9874. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9875. }
  9876. FClipboardDragDropFilesEx->FileList->Clear();
  9877. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9878. FClipboardDragDropFilesEx->CopyToClipboard();
  9879. FClipboardTerminal = FTerminal;
  9880. // Need full paths, as cwd can be different once files are pasted
  9881. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9882. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9883. {
  9884. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9885. }
  9886. }
  9887. }
  9888. //---------------------------------------------------------------------------
  9889. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9890. {
  9891. if (OpenClipboard(0))
  9892. {
  9893. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9894. CloseClipboard();
  9895. }
  9896. }
  9897. //---------------------------------------------------------------------------
  9898. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9899. {
  9900. return !FClipboardFakeDirectory.IsEmpty();
  9901. }
  9902. //---------------------------------------------------------------------------
  9903. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9904. {
  9905. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9906. FClipboardFakeDirectory = UnicodeString();
  9907. FClipboardTerminal = NULL;
  9908. // Also called in Idle()
  9909. FClipboardFakeMonitors.reset(NULL);
  9910. }
  9911. //---------------------------------------------------------------------------
  9912. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9913. {
  9914. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9915. {
  9916. ClipboardStop();
  9917. }
  9918. }
  9919. //---------------------------------------------------------------------------
  9920. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9921. {
  9922. TTerminalManager * Manager = TTerminalManager::Instance();
  9923. Manager->ActiveTerminal = FClipboardTerminal;
  9924. TTransferOperationParam Params;
  9925. Params.TargetDirectory = TargetDirectory;
  9926. Params.DragDrop = DragDrop;
  9927. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  9928. }
  9929. //---------------------------------------------------------------------------
  9930. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  9931. {
  9932. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  9933. // (as it pumps a Windows message queue while being shutted down)
  9934. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  9935. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  9936. {
  9937. // Can fail as it can be e.g. locked by AV, so we retry that later
  9938. bool Removed = RemoveDir(ApiPath(FileName));
  9939. try
  9940. {
  9941. if (!NonVisualDataModule->Busy)
  9942. {
  9943. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  9944. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  9945. }
  9946. }
  9947. __finally
  9948. {
  9949. if (!Removed)
  9950. {
  9951. RemoveDir(ApiPath(FileName));
  9952. }
  9953. }
  9954. }
  9955. }
  9956. //---------------------------------------------------------------------------
  9957. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  9958. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  9959. {
  9960. TFileMasks::TParams MaskParams;
  9961. MaskParams.Size = Size;
  9962. MaskParams.Modification = Modification;
  9963. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  9964. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  9965. {
  9966. bool ImplicitMatch;
  9967. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  9968. !ImplicitMatch)
  9969. {
  9970. Color = Iter->Color;
  9971. break;
  9972. }
  9973. }
  9974. }
  9975. //---------------------------------------------------------------------------
  9976. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  9977. {
  9978. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9979. if (!DirView->IsEditing())
  9980. {
  9981. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  9982. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  9983. // while searching
  9984. if (Key == VK_BACK)
  9985. {
  9986. if (!FIncrementalSearch.IsEmpty())
  9987. {
  9988. if (FIncrementalSearch.Length() == 1)
  9989. {
  9990. ResetIncrementalSearch();
  9991. }
  9992. else
  9993. {
  9994. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  9995. IncrementalSearch(NewText, false, false);
  9996. }
  9997. Key = 0;
  9998. }
  9999. }
  10000. }
  10001. }
  10002. //---------------------------------------------------------------------------
  10003. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10004. {
  10005. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10006. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10007. {
  10008. // Filter control sequences.
  10009. // When not searching yet, prefer use of the space for toggling file selection
  10010. // (so we cannot incrementally search for a string starting with a space).
  10011. if ((Key > VK_SPACE) ||
  10012. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10013. {
  10014. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10015. Key = 0;
  10016. }
  10017. }
  10018. }
  10019. //---------------------------------------------------------------------------
  10020. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10021. {
  10022. if (!FIncrementalSearch.IsEmpty())
  10023. {
  10024. FIncrementalSearch = L"";
  10025. DirView(osCurrent)->UpdateStatusBar();
  10026. }
  10027. }
  10028. //---------------------------------------------------------------------------
  10029. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10030. {
  10031. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10032. if (Item == NULL)
  10033. {
  10034. MessageBeep(MB_ICONHAND);
  10035. }
  10036. else
  10037. {
  10038. TCustomDirView * ADirView = DirView(osCurrent);
  10039. {
  10040. TAutoNestingCounter Guard(FIncrementalSearching);
  10041. ADirView->FocusItem(Item);
  10042. if (ADirView->NortonLike == nlOff)
  10043. {
  10044. if ((ADirView->Selected != Item) ||
  10045. (ADirView->SelCount > 1))
  10046. {
  10047. ADirView->ClearSelection();
  10048. ADirView->Selected = Item;
  10049. }
  10050. }
  10051. }
  10052. FIncrementalSearch = Text;
  10053. Item->MakeVisible(false);
  10054. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10055. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10056. ADirView->UpdateStatusBar();
  10057. }
  10058. }
  10059. //---------------------------------------------------------------------------
  10060. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10061. {
  10062. int Index = Item->Index;
  10063. if (!Reverse)
  10064. {
  10065. Index++;
  10066. if (Index >= Item->Owner->Count)
  10067. {
  10068. Index = 0;
  10069. }
  10070. }
  10071. else
  10072. {
  10073. Index--;
  10074. if (Index < 0)
  10075. {
  10076. Index = Item->Owner->Count - 1;
  10077. }
  10078. }
  10079. return Item->Owner->Item[Index];
  10080. }
  10081. //---------------------------------------------------------------------------
  10082. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10083. {
  10084. TCustomDirView * ADirView = DirView(osCurrent);
  10085. if (ADirView->Items->Count == 0)
  10086. {
  10087. return NULL;
  10088. }
  10089. else
  10090. {
  10091. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10092. TListItem * Item = CurrentItem;
  10093. if (SkipCurrent)
  10094. {
  10095. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10096. }
  10097. while (true)
  10098. {
  10099. bool Matches = false;
  10100. switch (WinConfiguration->PanelSearch)
  10101. {
  10102. case isNameStartOnly:
  10103. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10104. break;
  10105. case isName:
  10106. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10107. break;
  10108. case isAll:
  10109. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10110. int Index = 0;
  10111. while ((Index < ColCount) && !Matches)
  10112. {
  10113. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10114. if (Visible)
  10115. {
  10116. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10117. }
  10118. Index++;
  10119. }
  10120. break;
  10121. }
  10122. if (Matches)
  10123. {
  10124. return Item;
  10125. }
  10126. Item = GetNextFile(Item, Reverse);
  10127. if (Item == CurrentItem)
  10128. {
  10129. return NULL;
  10130. }
  10131. }
  10132. }
  10133. }
  10134. //---------------------------------------------------------------------------
  10135. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10136. {
  10137. ResetIncrementalSearch();
  10138. }
  10139. //---------------------------------------------------------------------------
  10140. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10141. {
  10142. if (Message.CharCode == VK_TAB)
  10143. {
  10144. if (!FIncrementalSearch.IsEmpty())
  10145. {
  10146. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10147. bool Reverse = Shift.Contains(ssShift);
  10148. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10149. Message.Result = 1;
  10150. return;
  10151. }
  10152. }
  10153. else if (Message.CharCode == VK_ESCAPE)
  10154. {
  10155. if (!FIncrementalSearch.IsEmpty())
  10156. {
  10157. ResetIncrementalSearch();
  10158. Message.Result = 1;
  10159. return;
  10160. }
  10161. }
  10162. TForm::Dispatch(&Message);
  10163. }
  10164. //---------------------------------------------------------------------------
  10165. void __fastcall TCustomScpExplorerForm::Deactivate()
  10166. {
  10167. TForm::Deactivate();
  10168. // E.g. when switching to an internal editor window
  10169. ResetIncrementalSearch();
  10170. }
  10171. //---------------------------------------------------------------------------
  10172. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10173. {
  10174. // When switching to another application
  10175. ResetIncrementalSearch();
  10176. }
  10177. //---------------------------------------------------------------------------
  10178. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10179. {
  10180. ResetIncrementalSearch();
  10181. }
  10182. //---------------------------------------------------------------------------
  10183. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10184. {
  10185. if (FIncrementalSearching <= 0)
  10186. {
  10187. ResetIncrementalSearch();
  10188. }
  10189. }
  10190. //---------------------------------------------------------------------------
  10191. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10192. {
  10193. CountClicksForWindowPrint(this);
  10194. }
  10195. //---------------------------------------------------------------------------
  10196. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10197. {
  10198. CenterReconnectToolbar();
  10199. }
  10200. //---------------------------------------------------------------------------
  10201. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10202. {
  10203. if (RemoteDirView->ItemFocused != NULL)
  10204. {
  10205. RemoteDirView->ItemFocused->Selected = true;
  10206. }
  10207. }
  10208. //---------------------------------------------------------------------------
  10209. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10210. {
  10211. if (!FQueueStatusUpdating)
  10212. {
  10213. bool Refresh;
  10214. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10215. {
  10216. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10217. }
  10218. else
  10219. {
  10220. if (FQueueFileList->GetCount() > 0)
  10221. {
  10222. FQueueFileList->Clear();
  10223. Refresh = true;
  10224. }
  10225. }
  10226. int Count = FQueueFileList->GetCount();
  10227. if (QueueFileList->Items->Count != Count)
  10228. {
  10229. DebugAssert(Refresh);
  10230. QueueFileList->Items->Count = Count;
  10231. }
  10232. if (Refresh)
  10233. {
  10234. QueueFileList->Invalidate();
  10235. }
  10236. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10237. }
  10238. }
  10239. //---------------------------------------------------------------------------
  10240. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10241. {
  10242. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10243. }
  10244. //---------------------------------------------------------------------------
  10245. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10246. {
  10247. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10248. // See TSynchronizeChecklistDialog::UpdateTimer
  10249. if (QueueFileList->Items->Count > 0)
  10250. {
  10251. QueueFileList->Items->Item[0]->MakeVisible(false);
  10252. }
  10253. UpdateQueueFileList();
  10254. }
  10255. //---------------------------------------------------------------------------
  10256. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10257. {
  10258. Active = QueueView3->Focused() || QueueFileList->Focused();
  10259. }
  10260. //---------------------------------------------------------------------------
  10261. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10262. {
  10263. QueueLabelUpdateStatus();
  10264. }
  10265. //---------------------------------------------------------------------------
  10266. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10267. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10268. {
  10269. int State = FQueueFileList->GetState(Item->Index);
  10270. if (State == qfsProcessed)
  10271. {
  10272. Sender->Canvas->Font->Color = clGrayText;
  10273. }
  10274. }
  10275. //---------------------------------------------------------------------------
  10276. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10277. {
  10278. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10279. QueueFileList->Column[0]->Width =
  10280. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10281. }
  10282. //---------------------------------------------------------------------------
  10283. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10284. {
  10285. QueueFileListColumnAutoSize();
  10286. }
  10287. //---------------------------------------------------------------------------
  10288. void __fastcall TCustomScpExplorerForm::CloseApp()
  10289. {
  10290. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10291. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10292. // So we clear the flag here.
  10293. DebugAssert(NonVisualDataModule->Busy);
  10294. NonVisualDataModule->EndBusy();
  10295. try
  10296. {
  10297. Close();
  10298. }
  10299. __finally
  10300. {
  10301. NonVisualDataModule->StartBusy();
  10302. }
  10303. }
  10304. //---------------------------------------------------------------------------
  10305. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10306. {
  10307. return (Terminal != NULL) && Terminal->Active;
  10308. }
  10309. //---------------------------------------------------------------------------
  10310. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10311. {
  10312. return IsActiveTerminal(Terminal);
  10313. }