CustomScpExplorer.cpp 361 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984
  1. //---------------------------------------------------------------------------
  2. #define NO_WIN32_LEAN_AND_MEAN
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <Common.h>
  6. #include "CustomScpExplorer.h"
  7. #include <Bookmarks.h>
  8. #include <Interface.h>
  9. #include <Exceptions.h>
  10. #include <CoreMain.h>
  11. #include <FileSystems.h>
  12. #include <TextsCore.h>
  13. #include <TextsWin.h>
  14. #include <HelpWin.h>
  15. #include <VCLCommon.h>
  16. #include <Progress.h>
  17. #include <SynchronizeProgress.h>
  18. #include <DragExt.h>
  19. #include <WinApi.h>
  20. #include "GUITools.h"
  21. #include "NonVisual.h"
  22. #include "Glyphs.h"
  23. #include "Tools.h"
  24. #include "WinConfiguration.h"
  25. #include "TerminalManager.h"
  26. #include "EditorManager.h"
  27. #include "ProgParams.h"
  28. #include "Setup.h"
  29. #include <Consts.hpp>
  30. #include <DateUtils.hpp>
  31. #include <TB2Common.hpp>
  32. #include <DirectoryMonitor.hpp>
  33. #include <System.IOUtils.hpp>
  34. //---------------------------------------------------------------------------
  35. #pragma package(smart_init)
  36. #pragma link "CustomDirView"
  37. #pragma link "CustomUnixDirView"
  38. #pragma link "IEListView"
  39. #pragma link "NortonLikeListView"
  40. #pragma link "UnixDirView"
  41. #pragma link "CustomDriveView"
  42. #pragma link "UnixDriveView"
  43. #pragma link "CustomDriveView"
  44. #pragma link "TB2Dock"
  45. #pragma link "TBXStatusBars"
  46. #pragma link "TB2Item"
  47. #pragma link "TB2Toolbar"
  48. #pragma link "ThemePageControl"
  49. #pragma link "PathLabel"
  50. #pragma resource "*.dfm"
  51. //---------------------------------------------------------------------------
  52. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  53. static const int SessionPanelCount = 4;
  54. //---------------------------------------------------------------------------
  55. class TMutexGuard
  56. {
  57. public:
  58. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  59. int Timeout = 5000)
  60. {
  61. FMutex = NULL;
  62. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  63. if (WaitResult == WAIT_TIMEOUT)
  64. {
  65. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  66. }
  67. else
  68. {
  69. FMutex = AMutex;
  70. }
  71. }
  72. ~TMutexGuard()
  73. {
  74. if (FMutex != NULL)
  75. {
  76. ReleaseMutex(FMutex);
  77. }
  78. }
  79. private:
  80. HANDLE FMutex;
  81. };
  82. //---------------------------------------------------------------------------
  83. class TWindowLock
  84. {
  85. public:
  86. TWindowLock(TCustomScpExplorerForm * Form) :
  87. FForm(Form)
  88. {
  89. FForm->LockWindow();
  90. }
  91. ~TWindowLock()
  92. {
  93. FForm->UnlockWindow();
  94. }
  95. private:
  96. TCustomScpExplorerForm * FForm;
  97. };
  98. //---------------------------------------------------------------------------
  99. class TAutoBatch
  100. {
  101. public:
  102. TAutoBatch(TCustomScpExplorerForm * Form) :
  103. FForm(Form)
  104. {
  105. FForm->BatchStart(FBatchStorage);
  106. }
  107. ~TAutoBatch()
  108. {
  109. FForm->BatchEnd(FBatchStorage);
  110. }
  111. private:
  112. TCustomScpExplorerForm * FForm;
  113. void * FBatchStorage;
  114. };
  115. //---------------------------------------------------------------------------
  116. struct TTransferOperationParam
  117. {
  118. TTransferOperationParam();
  119. UnicodeString TargetDirectory;
  120. bool Temp;
  121. bool DragDrop;
  122. int Options;
  123. TAutoSwitch Queue;
  124. };
  125. //---------------------------------------------------------------------------
  126. TTransferOperationParam::TTransferOperationParam()
  127. {
  128. Temp = false;
  129. DragDrop = false;
  130. Options = 0;
  131. Queue = asAuto;
  132. }
  133. //---------------------------------------------------------------------------
  134. class TTransferPresetNoteData : public TObject
  135. {
  136. public:
  137. UnicodeString Message;
  138. };
  139. //---------------------------------------------------------------------------
  140. class TTerminalNoteData : public TObject
  141. {
  142. public:
  143. TManagedTerminal * Terminal;
  144. };
  145. //---------------------------------------------------------------------------
  146. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  147. FFormRestored(false),
  148. TForm(Owner)
  149. {
  150. FInvalid = false;
  151. FCurrentSide = osRemote;
  152. FEverShown = false;
  153. FDocks = new TList();
  154. InitControls();
  155. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  156. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  157. NonVisualDataModule->ScpExplorer = this;
  158. RestoreParams();
  159. ConfigurationChanged();
  160. RemoteDirView->Invalidate();
  161. FAutoOperation = false;
  162. FOnFileOperationFinished = NULL;
  163. FForceExecution = false;
  164. FIgnoreNextDialogChar = 0;
  165. FErrorList = NULL;
  166. FSynchronizeProgressForm = NULL;
  167. FProgressForm = NULL;
  168. FRefreshLocalDirectory = false;
  169. FRefreshRemoteDirectory = false;
  170. FDDExtMapFile = NULL;
  171. // CreateMutexW keeps failing with ERROR_NOACCESS
  172. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  173. DebugAssert(FDDExtMutex != NULL);
  174. FDDTargetControl = NULL;
  175. FDelayedDeletionTimer = NULL;
  176. FDelayedDeletionList = new TStringList();
  177. FDDFileList = NULL;
  178. FPendingTempSpaceWarn = false;
  179. FCapturedLog = NULL;
  180. FDragDropOperation = false;
  181. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  182. FAllowTransferPresetAutoSelect = true;
  183. FCopyParamDefault = L"";
  184. FSynchronizeController = NULL;
  185. FPendingQueueActionItem = NULL;
  186. FLockLevel = 0;
  187. FLockSuspendLevel = 0;
  188. FDisabledOnLockSuspend = false;
  189. FAlternativeDelete = false;
  190. FTrayIcon = new ::TTrayIcon(0);
  191. FTrayIcon->OnClick = TrayIconClick;
  192. FMaxQueueLength = 0;
  193. FLastContextPopupScreenPoint = TPoint(-1, -1);
  194. FTransferResumeList = NULL;
  195. FMoveToQueue = false;
  196. FStandaloneEditing = false;
  197. FOnFeedSynchronizeError = NULL;
  198. FNeedSession = false;
  199. FDoNotIdleCurrentTerminal = 0;
  200. FIncrementalSearching = 0;
  201. FIncrementalSearchHaveNext = false;
  202. FQueueFileList.reset(new TQueueFileList());
  203. FEditorManager = new TEditorManager();
  204. FEditorManager->OnFileChange = ExecutedFileChanged;
  205. FEditorManager->OnFileReload = ExecutedFileReload;
  206. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  207. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  208. FLocalEditors = new TList();
  209. FQueueStatus = NULL;
  210. FQueueStatusSection = new TCriticalSection();
  211. FQueueStatusInvalidated = false;
  212. FQueueItemInvalidated = false;
  213. FQueueStatusUpdating = false;
  214. FQueueActedItem = NULL;
  215. FQueueController = new TQueueController(QueueView3);
  216. FUserActionTimer = new TTimer(this);
  217. FUserActionTimer->Enabled = false;
  218. FUserActionTimer->Interval = 10;
  219. FUserActionTimer->OnTimer = UserActionTimer;
  220. FNotes = new TStringList();
  221. FNoteTimer = new TTimer(this);
  222. FNoteTimer->Enabled = false;
  223. FNoteTimer->OnTimer = NoteTimer;
  224. FOnNoteClick = NULL;
  225. FOle32Library = LoadLibrary(L"Ole32.dll");
  226. FDragMoveCursor = FOle32Library != NULL ?
  227. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  228. UseSystemSettings(this);
  229. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  230. static_cast<TObject*>(GetComponent(fcTransferList)));
  231. DebugAssert(TransferList != NULL);
  232. FTransferListHoverIndex = -1;
  233. TransferList->OnChange = TransferListChange;
  234. TransferList->OnDrawItem = TransferListDrawItem;
  235. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  236. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  237. UseDesktopFont(SessionsPageControl);
  238. UpdateSessionsPageControlHeight();
  239. UseDesktopFont(RemoteDirView);
  240. UseDesktopFont(RemoteDriveView);
  241. UseDesktopFont(QueueView3);
  242. UseDesktopFont(QueueFileList);
  243. UseDesktopFont(QueueLabel);
  244. UseDesktopFont(RemoteStatusBar);
  245. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  246. QueueSplitter->ShowHint = true;
  247. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  248. QueueFileListSplitter->ShowHint = true;
  249. RemotePanelSplitter->ShowHint = true;
  250. UpdateImages();
  251. FCustomCommandMenu = CreateTBXPopupMenu(this);
  252. FCustomCommandLocalFileList = NULL;
  253. FCustomCommandRemoteFileList = NULL;
  254. FSessionColors = new TPngImageList(this);
  255. FSessionColors->ColorDepth = cd32Bit;
  256. AddFixedSessionImages();
  257. SessionsPageControl->Images = FSessionColors;
  258. UpdateQueueLabel();
  259. FRemoteDirViewWasFocused = true;
  260. CreateHiddenWindow();
  261. StartUpdates();
  262. }
  263. //---------------------------------------------------------------------------
  264. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  265. {
  266. FInvalid = true;
  267. // this has to be one of the very first things to do
  268. StopUpdateThread();
  269. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  270. TTerminalManager::Instance()->ScpExplorer = NULL;
  271. delete FCustomCommandLocalFileList;
  272. delete FCustomCommandRemoteFileList;
  273. delete FCustomCommandMenu;
  274. delete FTrayIcon;
  275. FTrayIcon = NULL;
  276. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  277. delete FEditorManager;
  278. ForceCloseLocalEditors();
  279. delete FLocalEditors;
  280. HideFileFindDialog();
  281. if (FDelayedDeletionTimer)
  282. {
  283. DoDelayedDeletion(NULL);
  284. SAFE_DESTROY(FDelayedDeletionTimer);
  285. }
  286. SAFE_DESTROY(FDelayedDeletionList);
  287. // sometimes we do not get DDEnd so the list is not released
  288. SAFE_DESTROY(FDDFileList);
  289. DebugAssert(FSynchronizeController == NULL);
  290. CloseHandle(FDDExtMutex);
  291. FDDExtMutex = NULL;
  292. FreeLibrary(FOle32Library);
  293. FOle32Library = NULL;
  294. FDragMoveCursor = NULL;
  295. DebugAssert(!FErrorList);
  296. if (FEverShown)
  297. {
  298. // when window is never shown (like when running command-line operation),
  299. // particularly window site is not restored correctly (BoundsRect value set
  300. // in RestoreForm gets lost during handle allocation), so we do not want
  301. // it to be stored
  302. StoreParams();
  303. }
  304. Terminal = NULL;
  305. Queue = NULL;
  306. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  307. NonVisualDataModule->ScpExplorer = NULL;
  308. delete FQueueController;
  309. FQueueController = NULL;
  310. delete FQueueStatusSection;
  311. FQueueStatusSection = NULL;
  312. delete FQueueStatus;
  313. FQueueStatus = NULL;
  314. delete FUserActionTimer;
  315. FUserActionTimer = NULL;
  316. delete FNoteTimer;
  317. delete FNotes;
  318. delete FNoteData;
  319. SAFE_DESTROY(FDocks);
  320. SessionsPageControl->Images = NULL;
  321. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  322. SAFE_DESTROY(FSessionColors);
  323. SAFE_DESTROY(FSessionsDragDropFilesEx);
  324. SAFE_DESTROY(FHistoryMenu[0][0]);
  325. SAFE_DESTROY(FHistoryMenu[0][1]);
  326. SAFE_DESTROY(FHistoryMenu[1][0]);
  327. SAFE_DESTROY(FHistoryMenu[1][1]);
  328. if (FHiddenWindow != NULL)
  329. {
  330. DestroyWindow(FHiddenWindow);
  331. FHiddenWindow = NULL;
  332. }
  333. }
  334. //---------------------------------------------------------------------------
  335. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  336. {
  337. std::unique_ptr<TSessionData> Data;
  338. if (!Session.IsEmpty())
  339. {
  340. bool DefaultsOnly;
  341. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  342. }
  343. TTerminalManager * Manager = TTerminalManager::Instance();
  344. for (int Index = 0; Index < Manager->Count; Index++)
  345. {
  346. TTerminal * Terminal = Manager->Terminals[Index];
  347. if (Session.IsEmpty() ||
  348. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  349. {
  350. if (Path.IsEmpty())
  351. {
  352. Terminal->ClearCaches();
  353. }
  354. else
  355. {
  356. Terminal->DirectoryModified(Path, true);
  357. }
  358. }
  359. }
  360. // We should flag a pending refresh for the background terminals or busy foreground terminals
  361. if (HasActiveTerminal() &&
  362. CanCommandLineFromAnotherInstance() &&
  363. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  364. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  365. {
  366. Terminal->ReloadDirectory();
  367. }
  368. }
  369. //---------------------------------------------------------------------------
  370. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  371. {
  372. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  373. size_t MessageSize = sizeof(TCopyDataMessage);
  374. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  375. if (Result)
  376. {
  377. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  378. Result = (Message.Version == TCopyDataMessage::Version1);
  379. if (Result)
  380. {
  381. switch (Message.Command)
  382. {
  383. case TCopyDataMessage::CommandCanCommandLine:
  384. Result = CanCommandLineFromAnotherInstance();
  385. break;
  386. case TCopyDataMessage::CommandCommandLine:
  387. {
  388. UnicodeString CommandLine(Message.CommandLine);
  389. Result = CommandLineFromAnotherInstance(CommandLine);
  390. }
  391. break;
  392. case TCopyDataMessage::RefreshPanel:
  393. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  394. break;
  395. case TCopyDataMessage::MainWindowCheck:
  396. Result = true;
  397. break;
  398. default:
  399. Result = false;
  400. break;
  401. }
  402. }
  403. }
  404. Message.Result = Result ? 1 : 0;
  405. }
  406. //---------------------------------------------------------------------------
  407. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  408. {
  409. WNDCLASS WindowClass = {0};
  410. WindowClass.lpfnWndProc = DefWindowProc;
  411. WindowClass.hInstance = HInstance;
  412. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  413. FHiddenWindow = NULL;
  414. if (RegisterClass(&WindowClass))
  415. {
  416. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  417. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  418. }
  419. }
  420. //---------------------------------------------------------------------------
  421. bool __fastcall TCustomScpExplorerForm::CanConsole()
  422. {
  423. return
  424. HasActiveTerminal() &&
  425. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  426. }
  427. //---------------------------------------------------------------------------
  428. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  429. {
  430. bool Result = Visible && !NonVisualDataModule->Busy;
  431. return Result;
  432. }
  433. //---------------------------------------------------------------------------
  434. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  435. const UnicodeString & CommandLine)
  436. {
  437. TProgramParams Params(CommandLine);
  438. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  439. if (Result)
  440. {
  441. NonVisualDataModule->StartBusy();
  442. try
  443. {
  444. // this action is initiated from another process,
  445. // so it's likely that our window is not visible,
  446. // and user won't see what is going on
  447. Application->BringToFront();
  448. // reload sessions as we may be asked to open a session
  449. // just stored by another instance
  450. StoredSessions->Reload();
  451. UnicodeString SessionName = Params.Param[1];
  452. std::unique_ptr<TObjectList> DataList(new TObjectList());
  453. UnicodeString DownloadFile; // unused
  454. try
  455. {
  456. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  457. }
  458. catch (EAbort &)
  459. {
  460. // Happens when opening session in PuTTY and in other situations,
  461. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  462. // to process the command-line on its own (or to pass it to yet another instance)
  463. }
  464. if (DataList->Count > 0)
  465. {
  466. TTerminalManager * Manager = TTerminalManager::Instance();
  467. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  468. }
  469. }
  470. __finally
  471. {
  472. NonVisualDataModule->EndBusy();
  473. }
  474. }
  475. return Result;
  476. }
  477. //---------------------------------------------------------------------------
  478. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  479. {
  480. if (FTerminal != value)
  481. {
  482. TerminalChanging();
  483. DoSetTerminal(value, false);
  484. }
  485. }
  486. //---------------------------------------------------------------------------
  487. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  488. {
  489. FTerminal = value;
  490. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  491. FAllowTransferPresetAutoSelect = false;
  492. try
  493. {
  494. TerminalChanged(Replace);
  495. }
  496. __finally
  497. {
  498. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  499. }
  500. if (Terminal != NULL)
  501. {
  502. TransferPresetAutoSelect();
  503. }
  504. }
  505. //---------------------------------------------------------------------------
  506. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  507. {
  508. DoSetTerminal(value, true);
  509. }
  510. //---------------------------------------------------------------------------
  511. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  512. {
  513. if (FTerminal != NULL)
  514. {
  515. UpdateTerminal(Terminal);
  516. }
  517. }
  518. //---------------------------------------------------------------------------
  519. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  520. {
  521. if (Terminal != NULL)
  522. {
  523. UpdateSessionColor((TColor)Terminal->StateData->Color);
  524. }
  525. DoTerminalListChanged();
  526. DebugAssert(!IsLocalBrowserMode()); // TODO
  527. if (Replaced)
  528. {
  529. RemoteDirView->ReplaceTerminal(Terminal);
  530. }
  531. else
  532. {
  533. RemoteDirView->Terminal = Terminal;
  534. }
  535. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  536. if (Terminal != NULL)
  537. {
  538. if (Terminal->Active)
  539. {
  540. Terminal->RefreshDirectory();
  541. }
  542. if (WinConfiguration->PreservePanelState)
  543. {
  544. if (Terminal->RemoteExplorerState != NULL)
  545. {
  546. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  547. }
  548. else
  549. {
  550. DirView(osRemote)->ClearState();
  551. }
  552. }
  553. if (!Replaced && Terminal->Active)
  554. {
  555. InitStatusBar();
  556. }
  557. }
  558. UpdateTransferList();
  559. // Update panels Enable state before refreshing the labels
  560. UpdateControls();
  561. }
  562. //---------------------------------------------------------------------------
  563. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  564. {
  565. if (Queue != value)
  566. {
  567. if (FQueue != NULL)
  568. {
  569. FQueue->OnListUpdate = NULL;
  570. FQueue->OnQueueItemUpdate = NULL;
  571. }
  572. FQueue = value;
  573. if (FQueue != NULL)
  574. {
  575. DebugAssert(FQueue->OnListUpdate == NULL);
  576. FQueue->OnListUpdate = QueueListUpdate;
  577. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  578. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  579. }
  580. QueueChanged();
  581. }
  582. }
  583. //---------------------------------------------------------------------------
  584. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  585. TListItem * Item)
  586. {
  587. if (FQueueActedItem == Item)
  588. {
  589. FQueueActedItem = NULL;
  590. if ((QueueView3->PopupMenu != NULL) &&
  591. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  592. {
  593. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  594. ReleaseCapture();
  595. }
  596. }
  597. if (Item->Data == FPendingQueueActionItem)
  598. {
  599. FPendingQueueActionItem = NULL;
  600. }
  601. }
  602. //---------------------------------------------------------------------------
  603. bool TCustomScpExplorerForm::IsAnythingQueued()
  604. {
  605. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  606. }
  607. //---------------------------------------------------------------------------
  608. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  609. {
  610. {
  611. TGuard Guard(FQueueStatusSection);
  612. FQueueStatusInvalidated = false;
  613. if (FQueue != NULL)
  614. {
  615. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  616. }
  617. }
  618. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  619. {
  620. FMaxQueueLength = FQueueStatus->Count;
  621. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  622. }
  623. {
  624. TAutoFlag Flag(FQueueStatusUpdating);
  625. FQueueController->UpdateQueueStatus(FQueueStatus);
  626. }
  627. UpdateQueueFileList();
  628. SetQueueProgress();
  629. UpdateQueueView();
  630. bool IsEmpty = !IsAnythingQueued();
  631. if (IsEmpty && (Terminal != NULL))
  632. {
  633. TOnceDoneOperation OnceDoneOperation =
  634. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  635. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  636. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  637. {
  638. FQueue->Enabled = false;
  639. }
  640. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  641. {
  642. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  643. }
  644. }
  645. }
  646. //---------------------------------------------------------------------------
  647. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  648. {
  649. UnicodeString Result;
  650. if (FQueueStatus != NULL)
  651. {
  652. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  653. {
  654. TFileOperationProgressType * ProgressData =
  655. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  656. if ((ProgressData != NULL) && ProgressData->InProgress)
  657. {
  658. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  659. }
  660. }
  661. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  662. {
  663. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  664. }
  665. }
  666. return Result;
  667. }
  668. //---------------------------------------------------------------------------
  669. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  670. {
  671. ComponentVisible[fcQueueView] =
  672. (WinConfiguration->QueueView.Show == qvShow) ||
  673. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  674. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  675. }
  676. //---------------------------------------------------------------------------
  677. void __fastcall TCustomScpExplorerForm::QueueChanged()
  678. {
  679. if (FQueueStatus != NULL)
  680. {
  681. // UpdateFileList implementation relies on the status being recreated when session changes
  682. delete FQueueStatus;
  683. FQueueStatus = NULL;
  684. }
  685. UpdateQueueStatus(true);
  686. }
  687. //---------------------------------------------------------------------------
  688. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  689. {
  690. if (FQueue == Queue)
  691. {
  692. FQueueStatusInvalidated = true;
  693. }
  694. }
  695. //---------------------------------------------------------------------------
  696. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  697. TQueueItem * Item)
  698. {
  699. if (FQueue == Queue)
  700. {
  701. TGuard Guard(FQueueStatusSection);
  702. // this may be running in parallel with QueueChanged
  703. if (FQueueStatus != NULL)
  704. {
  705. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  706. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  707. {
  708. FRefreshLocalDirectory = (QueueItem == NULL) ||
  709. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  710. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  711. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  712. }
  713. if (QueueItem != NULL)
  714. {
  715. QueueItem->UserData = (void*)true;
  716. FQueueItemInvalidated = true;
  717. }
  718. }
  719. }
  720. }
  721. //---------------------------------------------------------------------------
  722. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  723. {
  724. // during standalone editing, we have no way to see/control queue,
  725. // so we have to always popup prompts automatically
  726. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  727. }
  728. //---------------------------------------------------------------------------
  729. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  730. {
  731. if (FQueueStatus != NULL)
  732. {
  733. bool QueueAutoPopup = IsQueueAutoPopup();
  734. bool NeedRefresh = FQueueController->NeedRefresh();
  735. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  736. FQueueItemInvalidated = false;
  737. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  738. bool Updated = false;
  739. TQueueItemProxy * QueueItem;
  740. bool WasUserAction;
  741. for (int Index = 0; Index < Limit; Index++)
  742. {
  743. bool Update = false;
  744. QueueItem = FQueueStatus->Items[Index];
  745. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  746. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  747. (FPendingQueueActionItem == NULL))
  748. {
  749. FPendingQueueActionItem = QueueItem;
  750. FUserActionTimer->Enabled = true;
  751. }
  752. if ((bool)QueueItem->UserData)
  753. {
  754. QueueItem->UserData = (void*)false;
  755. QueueItem->Update();
  756. Updated = true;
  757. Update = true;
  758. }
  759. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  760. {
  761. Update = true;
  762. }
  763. if (Update)
  764. {
  765. FQueueController->RefreshQueueItem(QueueItem);
  766. }
  767. }
  768. if (Updated)
  769. {
  770. NonVisualDataModule->UpdateNonVisibleActions();
  771. SetQueueProgress();
  772. UpdateQueueFileList();
  773. }
  774. }
  775. }
  776. //---------------------------------------------------------------------------
  777. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  778. {
  779. if (FTaskbarList != NULL)
  780. {
  781. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  782. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  783. }
  784. }
  785. //---------------------------------------------------------------------------
  786. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  787. {
  788. if (Progress >= 0)
  789. {
  790. if (FTaskbarList != NULL)
  791. {
  792. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  793. }
  794. }
  795. else
  796. {
  797. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  798. }
  799. }
  800. //---------------------------------------------------------------------------
  801. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  802. {
  803. int OverallProgress;
  804. // FProgressForm is null when this is called from SetQueueProgress
  805. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  806. {
  807. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  808. }
  809. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  810. {
  811. OverallProgress = ProgressData->OverallProgress();
  812. }
  813. else
  814. {
  815. OverallProgress = -1;
  816. }
  817. SetTaskbarListProgressValue(OverallProgress);
  818. }
  819. //---------------------------------------------------------------------------
  820. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  821. {
  822. TTerminalManager::Instance()->QueueStatusUpdated();
  823. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  824. {
  825. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  826. {
  827. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  828. {
  829. TFileOperationProgressType * ProgressData = NULL;
  830. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  831. {
  832. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  833. }
  834. if ((ProgressData != NULL) &&
  835. ProgressData->InProgress)
  836. {
  837. SetTaskbarListProgressValue(ProgressData);
  838. }
  839. else
  840. {
  841. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  842. }
  843. }
  844. else
  845. {
  846. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  847. }
  848. }
  849. else
  850. {
  851. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  852. }
  853. }
  854. UpdateQueueLabel();
  855. }
  856. //---------------------------------------------------------------------------
  857. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  858. {
  859. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  860. if (FQueueStatus != NULL)
  861. {
  862. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  863. if (ActiveAndPendingPrimaryCount > 0)
  864. {
  865. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  866. }
  867. }
  868. QueueLabel->Caption = Caption;
  869. }
  870. //---------------------------------------------------------------------------
  871. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  872. {
  873. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  874. static_cast<TComponent*>(GetComponent(fcTransferList)));
  875. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  876. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  877. TransferList->Strings->BeginUpdate();
  878. try
  879. {
  880. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  881. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  882. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  883. if (FTransferDropDownHint.IsEmpty())
  884. {
  885. FTransferDropDownHint = TransferDropDown->Hint;
  886. }
  887. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  888. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  889. TransferDropDown->Text = StripHotkey(Name);
  890. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  891. (FTransferDropDownHint, StripHotkey(Name),
  892. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  893. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  894. // update the label, otherwise when it is updated only on the first draw
  895. // of the list, it is drawn "bold" for some reason
  896. FTransferListHoverIndex = TransferList->ItemIndex;
  897. UpdateTransferLabel();
  898. }
  899. __finally
  900. {
  901. TransferList->Strings->EndUpdate();
  902. }
  903. }
  904. //---------------------------------------------------------------------------
  905. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  906. {
  907. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  908. DebugAssert(Toolbar != NULL);
  909. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  910. }
  911. //---------------------------------------------------------------------------
  912. void __fastcall TCustomScpExplorerForm::UpdateActions()
  913. {
  914. TForm::UpdateActions();
  915. if (ComponentVisible[fcCustomCommandsBand])
  916. {
  917. UpdateCustomCommandsToolbar();
  918. }
  919. }
  920. //---------------------------------------------------------------------------
  921. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  922. {
  923. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  924. }
  925. //---------------------------------------------------------------------------
  926. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  927. {
  928. Color = GetBtnFaceColor();
  929. DebugAssert(Configuration && RemoteDirView);
  930. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  931. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  932. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  933. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  934. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  935. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  936. if (RemoteDirView->RowSelect != WinConfiguration->FullRowSelect)
  937. {
  938. RemoteDirView->RowSelect = WinConfiguration->FullRowSelect;
  939. // selection is not redrawn automatically when RowSelect changes
  940. RemoteDirView->Invalidate();
  941. }
  942. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  943. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  944. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  945. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  946. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  947. UpdateSessionsPageControlHeight();
  948. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  949. UpdateToolbarDisplayMode();
  950. UpdateTransferList();
  951. if (Terminal != NULL)
  952. {
  953. TransferPresetAutoSelect();
  954. }
  955. UpdateQueueView();
  956. UpdateControls();
  957. // this can be called even before constuctor finishes.
  958. if (FEditorManager != NULL)
  959. {
  960. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  961. }
  962. // this can be called even before constuctor finishes.
  963. if (FLocalEditors != NULL)
  964. {
  965. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  966. {
  967. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  968. }
  969. }
  970. if (ComponentVisible[fcCustomCommandsBand])
  971. {
  972. UpdateCustomCommandsToolbar();
  973. }
  974. // show only when keeping queue items forever,
  975. // otherwise, its enough to have in in the context menu
  976. QueueDeleteAllDoneQueueToolbarItem->Visible =
  977. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  978. if (FFileColorsCurrent != WinConfiguration->FileColors)
  979. {
  980. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  981. FFileColorsCurrent = WinConfiguration->FileColors;
  982. FileColorsChanged();
  983. }
  984. }
  985. //---------------------------------------------------------------------------
  986. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  987. {
  988. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  989. DirView->Invalidate();
  990. }
  991. //---------------------------------------------------------------------------
  992. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  993. {
  994. DoFileColorsChanged(RemoteDirView);
  995. }
  996. //---------------------------------------------------------------------------
  997. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  998. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  999. void * /*Arg*/)
  1000. {
  1001. if (Token != NULL)
  1002. {
  1003. TForm * Editor = dynamic_cast<TForm*>(Token);
  1004. DebugAssert(Editor != NULL);
  1005. ReconfigureEditorForm(Editor);
  1006. }
  1007. }
  1008. //---------------------------------------------------------------------------
  1009. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1010. {
  1011. WinConfiguration->DDTransferConfirmation = asOn;
  1012. }
  1013. //---------------------------------------------------------------------------
  1014. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1015. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1016. {
  1017. // noop
  1018. }
  1019. //---------------------------------------------------------------------------
  1020. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1021. TTransferDirection Direction, TTransferType Type, bool Temp,
  1022. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1023. bool Confirm, bool DragDrop, int Options)
  1024. {
  1025. bool Result = true;
  1026. DebugAssert(HasActiveTerminal());
  1027. // these parameters are known in advance
  1028. int Params =
  1029. FLAGMASK(Type == ttMove, cpDelete);
  1030. bool ToTemp = (Temp && (Direction == tdToLocal));
  1031. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1032. {
  1033. bool DisableNewerOnly =
  1034. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1035. ToTemp;
  1036. Options |=
  1037. FLAGMASK(ToTemp, coTemp) |
  1038. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1039. coDoNotShowAgain;
  1040. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1041. int CopyParamAttrs = (Direction == tdToRemote ?
  1042. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1043. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1044. int OutputOptions =
  1045. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1046. cooDoNotShowAgain);
  1047. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1048. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1049. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1050. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1051. if (Result)
  1052. {
  1053. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1054. {
  1055. if (DragDrop)
  1056. {
  1057. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1058. {
  1059. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1060. NULL, 0, EnableDDTransferConfirmation, NULL);
  1061. }
  1062. WinConfiguration->DDTransferConfirmation = asOff;
  1063. }
  1064. else
  1065. {
  1066. WinConfiguration->ConfirmTransferring = false;
  1067. }
  1068. }
  1069. else
  1070. {
  1071. // User explicitly unchecked "do not show again",
  1072. // so show him the dialog the next time
  1073. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1074. {
  1075. WinConfiguration->DDTransferConfirmation = asOn;
  1076. }
  1077. }
  1078. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1079. }
  1080. }
  1081. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1082. {
  1083. Configuration->Usage->Inc(L"TransfersOnBackground");
  1084. // these parameter are known only after transfer dialog
  1085. Params |=
  1086. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1087. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1088. Result = false;
  1089. ClearTransferSourceSelection(Direction);
  1090. }
  1091. return Result;
  1092. }
  1093. //---------------------------------------------------------------------------
  1094. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1095. {
  1096. if (FOnFileOperationFinished != NULL)
  1097. {
  1098. FOnFileOperationFinished(UnicodeString(), true);
  1099. }
  1100. else
  1101. {
  1102. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1103. if (HasDirView[Side])
  1104. {
  1105. DirView(Side)->SelectAll(smNone);
  1106. }
  1107. }
  1108. }
  1109. //---------------------------------------------------------------------------
  1110. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1111. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1112. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1113. int Params)
  1114. {
  1115. DebugAssert(Queue != NULL);
  1116. bool SingleFile = false;
  1117. if (FileList->Count == 1)
  1118. {
  1119. if (Direction == tdToRemote)
  1120. {
  1121. UnicodeString FileName = FileList->Strings[0];
  1122. SingleFile = FileExists(ApiPath(FileName));
  1123. }
  1124. else
  1125. {
  1126. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1127. SingleFile = !File->IsDirectory;
  1128. }
  1129. }
  1130. TQueueItem * QueueItem;
  1131. if (Direction == tdToRemote)
  1132. {
  1133. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1134. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1135. }
  1136. else
  1137. {
  1138. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1139. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1140. }
  1141. AddQueueItem(Queue, QueueItem, Terminal);
  1142. }
  1143. //---------------------------------------------------------------------------
  1144. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1145. {
  1146. if (Queue->IsEmpty)
  1147. {
  1148. Terminal->QueueOperationStart = Now();
  1149. }
  1150. Queue->AddItem(QueueItem);
  1151. }
  1152. //---------------------------------------------------------------------------
  1153. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1154. {
  1155. }
  1156. //---------------------------------------------------------------------------
  1157. void __fastcall TCustomScpExplorerForm::InitControls()
  1158. {
  1159. DebugAssert(FDocks != NULL);
  1160. for (int Index = 0; Index < ComponentCount; Index++)
  1161. {
  1162. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1163. if ((Dock != NULL) && (Dock->Tag == 0))
  1164. {
  1165. FDocks->Add(Dock);
  1166. }
  1167. }
  1168. CollectItemsWithTextDisplayMode(this);
  1169. }
  1170. //---------------------------------------------------------------------------
  1171. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1172. {
  1173. ConfigurationChanged();
  1174. QueuePanel->Height =
  1175. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1176. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1177. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1178. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1179. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1180. QueueFileList->Height =
  1181. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1182. if (QueueFileList->Visible)
  1183. {
  1184. AdjustQueueLayout();
  1185. }
  1186. UpdateCustomCommandsToolbar();
  1187. }
  1188. //---------------------------------------------------------------------------
  1189. void __fastcall TCustomScpExplorerForm::StoreParams()
  1190. {
  1191. int APixelsPerInch = GetControlPixelsPerInch(this);
  1192. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1193. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1194. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1195. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1196. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1197. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1198. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1199. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1200. }
  1201. //---------------------------------------------------------------------------
  1202. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1203. {
  1204. if (!FFormRestored)
  1205. {
  1206. FFormRestored = true;
  1207. RestoreFormParams();
  1208. }
  1209. TForm::CreateParams(Params);
  1210. }
  1211. //---------------------------------------------------------------------------
  1212. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1213. {
  1214. DebugAssert(FDocks != NULL);
  1215. for (int Index = 0; Index < FDocks->Count; Index++)
  1216. {
  1217. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1218. }
  1219. }
  1220. //---------------------------------------------------------------------------
  1221. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1222. {
  1223. SetDockAllowDrag(true);
  1224. while (!ButtonsStr.IsEmpty())
  1225. {
  1226. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1227. UnicodeString Name = CutToChar(S, L'=', true);
  1228. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1229. {
  1230. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1231. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1232. {
  1233. while (!S.IsEmpty())
  1234. {
  1235. UnicodeString S2 = CutToChar(S, L',', true);
  1236. UnicodeString Name = CutToChar(S2, L':', true);
  1237. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1238. {
  1239. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1240. if (SameText(GetToolbarItemName(Item), Name))
  1241. {
  1242. // forward compatibility
  1243. UnicodeString S3 = CutToChar(S2, L':', true);
  1244. bool Visible = StrToIntDef(S3, 0);
  1245. Item->Visible = Visible;
  1246. }
  1247. }
  1248. }
  1249. }
  1250. }
  1251. }
  1252. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1253. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1254. }
  1255. //---------------------------------------------------------------------------
  1256. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1257. {
  1258. UnicodeString Result;
  1259. SetDockAllowDrag(true);
  1260. Result = ::GetToolbarsLayoutStr(this);
  1261. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1262. return Result;
  1263. }
  1264. //---------------------------------------------------------------------------
  1265. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1266. {
  1267. UnicodeString Result;
  1268. if (Item->Action != NULL)
  1269. {
  1270. Result = Item->Action->Name;
  1271. Result = RemoveSuffix(Result, L"Action", true);
  1272. }
  1273. else
  1274. {
  1275. Result = Item->Name;
  1276. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1277. Result = RemoveSuffix(Result, L"Item", true);
  1278. }
  1279. return Result;
  1280. }
  1281. //---------------------------------------------------------------------------
  1282. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1283. {
  1284. UnicodeString Result;
  1285. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1286. {
  1287. UnicodeString ToolbarStr;
  1288. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1289. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1290. {
  1291. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1292. {
  1293. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1294. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1295. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1296. // and save the changes here only.
  1297. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1298. {
  1299. UnicodeString Name = GetToolbarItemName(Item);
  1300. DebugAssert(Name.Pos(L"TBX") == 0);
  1301. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1302. }
  1303. }
  1304. }
  1305. if (!ToolbarStr.IsEmpty())
  1306. {
  1307. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1308. }
  1309. }
  1310. return Result;
  1311. }
  1312. //---------------------------------------------------------------------------
  1313. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1314. {
  1315. DebugAssert(FProgressForm == NULL);
  1316. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1317. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1318. FProgressForm->DeleteLocalToRecycleBin =
  1319. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1320. FProgressForm->DeleteRemoteToRecycleBin =
  1321. (Terminal != NULL) &&
  1322. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1323. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1324. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1325. LockWindow();
  1326. // Actually, do not know what hides the progress once the operation finishes
  1327. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1328. SetTaskbarListProgressState(TBPF_NORMAL);
  1329. }
  1330. //---------------------------------------------------------------------------
  1331. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1332. {
  1333. UnlockWindow();
  1334. SAFE_DESTROY(FProgressForm);
  1335. SetQueueProgress();
  1336. }
  1337. //---------------------------------------------------------------------------
  1338. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1339. TFileOperationProgressType & ProgressData)
  1340. {
  1341. // Download to temporary local directory
  1342. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1343. {
  1344. bool Continue = true;
  1345. FPendingTempSpaceWarn = false;
  1346. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1347. if (!Continue)
  1348. {
  1349. Abort();
  1350. }
  1351. }
  1352. // operation is being executed and we still didn't show up progress form
  1353. if (ProgressData.InProgress && !FProgressForm)
  1354. {
  1355. CreateProgressForm(NULL);
  1356. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1357. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1358. }
  1359. // operation is finished (or terminated), so we hide progress form
  1360. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1361. {
  1362. DestroyProgressForm();
  1363. if (ProgressData.Operation == foCalculateSize)
  1364. {
  1365. // When calculating size before transfer, the abort caused by
  1366. // cancel flag set due to "MoveToQueue" below,
  1367. // is not propagated back to us in ExecuteFileOperation,
  1368. // as it is silently swallowed.
  1369. // So we explicitly (re)throw it here.
  1370. if (FMoveToQueue)
  1371. {
  1372. Abort();
  1373. }
  1374. }
  1375. else
  1376. {
  1377. if ((ProgressData.Cancel == csContinue) &&
  1378. !FAutoOperation)
  1379. {
  1380. OperationComplete(ProgressData.StartTime);
  1381. }
  1382. }
  1383. }
  1384. if (FProgressForm &&
  1385. // Can happen only during synchronization, when ending one of the operations
  1386. ProgressData.InProgress)
  1387. {
  1388. FProgressForm->SetProgressData(ProgressData);
  1389. DebugAssert(ProgressData.InProgress);
  1390. SetTaskbarListProgressValue(&ProgressData);
  1391. if (FProgressForm->Cancel > csContinue)
  1392. {
  1393. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1394. if (FProgressForm->Cancel == csCancelFile)
  1395. {
  1396. FProgressForm->ClearCancel();
  1397. }
  1398. // cancel cancels even the move
  1399. FMoveToQueue = false;
  1400. }
  1401. else if (FProgressForm->MoveToQueue)
  1402. {
  1403. FMoveToQueue = true;
  1404. ProgressData.SetCancelAtLeast(csCancel);
  1405. }
  1406. if ((FTransferResumeList != NULL) &&
  1407. ProgressData.InProgress &&
  1408. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1409. !ProgressData.FullFileName.IsEmpty())
  1410. {
  1411. if ((FTransferResumeList->Count == 0) ||
  1412. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1413. {
  1414. // note that we do not recognize directories from files here
  1415. FTransferResumeList->Add(ProgressData.FullFileName);
  1416. }
  1417. }
  1418. }
  1419. }
  1420. //---------------------------------------------------------------------------
  1421. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1422. const TDateTime & StartTime)
  1423. {
  1424. if (GUIConfiguration->BeepOnFinish &&
  1425. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1426. {
  1427. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1428. DWORD Sound;
  1429. if (!ExtractFileExt(BeepSound).IsEmpty())
  1430. {
  1431. Sound = SND_FILENAME;
  1432. }
  1433. else
  1434. {
  1435. Sound = SND_ALIAS;
  1436. }
  1437. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1438. }
  1439. }
  1440. //---------------------------------------------------------------------------
  1441. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1442. TFileOperationProgressType & ProgressData)
  1443. {
  1444. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1445. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1446. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1447. FileOperationProgress(ProgressData);
  1448. }
  1449. //---------------------------------------------------------------------------
  1450. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1451. {
  1452. UnicodeString Result;
  1453. if (FProgressForm != NULL)
  1454. {
  1455. Result = FProgressForm->ProgressStr();
  1456. }
  1457. return Result;
  1458. }
  1459. //---------------------------------------------------------------------------
  1460. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1461. bool DragDrop)
  1462. {
  1463. return (!DragDrop && (DropSourceControl == NULL)) ||
  1464. (DropSourceControl == DirView(osOther));
  1465. }
  1466. //---------------------------------------------------------------------------
  1467. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1468. TFileOperation Operation, TOperationSide Side,
  1469. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1470. TOnceDoneOperation & OnceDoneOperation)
  1471. {
  1472. if (!FAutoOperation)
  1473. {
  1474. // no selection on "/upload", form serves only as event handler
  1475. // (it is not displayed)
  1476. if (PanelOperation(Side, FDragDropOperation) &&
  1477. Visible && (Operation != foCalculateSize) &&
  1478. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1479. {
  1480. if (FOnFileOperationFinished != NULL)
  1481. {
  1482. FOnFileOperationFinished(FileName, Success);
  1483. }
  1484. else
  1485. {
  1486. TCustomDirView * DView = DirView(Side);
  1487. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(Side));
  1488. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1489. // this can happen when local drive is unplugged in the middle of the operation
  1490. if (Item != NULL)
  1491. {
  1492. if (Success) Item->Selected = false;
  1493. DView->MakeProgressVisible(Item);
  1494. }
  1495. }
  1496. }
  1497. if ((Operation == foCopy) || (Operation == foMove))
  1498. {
  1499. DebugAssert(!IsLocalBrowserMode()); // TODO
  1500. if (Side == osLocal)
  1501. {
  1502. Configuration->Usage->Inc(L"UploadedFiles");
  1503. }
  1504. else
  1505. {
  1506. Configuration->Usage->Inc(L"DownloadedFiles");
  1507. }
  1508. }
  1509. }
  1510. if (Success && (FSynchronizeController != NULL))
  1511. {
  1512. DebugAssert(!IsSideLocalBrowser(osRemote));
  1513. if (Operation == foCopy)
  1514. {
  1515. DebugAssert(Side == osLocal);
  1516. FSynchronizeController->LogOperation(soUpload, FileName);
  1517. }
  1518. else if (Operation == foDelete)
  1519. {
  1520. DebugAssert(Side == osRemote);
  1521. FSynchronizeController->LogOperation(soDelete, FileName);
  1522. }
  1523. }
  1524. if (FProgressForm)
  1525. {
  1526. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1527. }
  1528. }
  1529. //---------------------------------------------------------------------------
  1530. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1531. TFileOperation Operation, TOperationSide Side,
  1532. bool Temp, const UnicodeString & FileName, Boolean Success,
  1533. TOnceDoneOperation & OnceDoneOperation)
  1534. {
  1535. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1536. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1537. OnceDoneOperation);
  1538. }
  1539. //---------------------------------------------------------------------------
  1540. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1541. {
  1542. return false;
  1543. }
  1544. //---------------------------------------------------------------------------
  1545. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1546. {
  1547. return false;
  1548. }
  1549. //---------------------------------------------------------------------------
  1550. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1551. {
  1552. return NULL;
  1553. }
  1554. //---------------------------------------------------------------------------
  1555. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1556. {
  1557. DebugAssert(GetSide(Side) == osRemote);
  1558. DebugUsedParam(Side);
  1559. return RemoteDirView;
  1560. }
  1561. //---------------------------------------------------------------------------
  1562. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1563. {
  1564. DebugAssert(GetSide(Side) == osRemote);
  1565. DebugUsedParam(Side);
  1566. return RemoteDriveView;
  1567. }
  1568. //---------------------------------------------------------------------------
  1569. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1570. {
  1571. DebugAssert(GetSide(Side) == osRemote);
  1572. DebugUsedParam(Side);
  1573. return HasActiveTerminal();
  1574. }
  1575. //---------------------------------------------------------------------------
  1576. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1577. TOperationSide Side, int FilesOnly)
  1578. {
  1579. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1580. }
  1581. //---------------------------------------------------------------------------
  1582. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1583. TOperationSide Side, int FilesOnly)
  1584. {
  1585. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1586. }
  1587. //---------------------------------------------------------------------------
  1588. struct THistoryItemData
  1589. {
  1590. short int Side;
  1591. short int Index;
  1592. };
  1593. //---------------------------------------------------------------------------
  1594. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1595. {
  1596. DirView(Side)->HistoryGo(Index);
  1597. }
  1598. //---------------------------------------------------------------------------
  1599. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1600. {
  1601. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1602. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1603. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1604. }
  1605. //---------------------------------------------------------------------------
  1606. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1607. bool Back)
  1608. {
  1609. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1610. {
  1611. TCustomDirView * DView = DirView(Side);
  1612. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1613. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1614. if (ICount > 10)
  1615. {
  1616. ICount = 10;
  1617. }
  1618. Menu->Items->Clear();
  1619. THistoryItemData Data;
  1620. Data.Side = Side;
  1621. for (short int i = 1; i <= ICount; i++)
  1622. {
  1623. TTBCustomItem * Item = new TTBXItem(Menu);
  1624. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1625. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1626. Item->Hint = DView->HistoryPath[Data.Index];
  1627. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1628. Item->Tag = *reinterpret_cast<int*>(&Data);
  1629. Item->OnClick = HistoryItemClick;
  1630. Menu->Items->Add(Item);
  1631. }
  1632. }
  1633. }
  1634. //---------------------------------------------------------------------------
  1635. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1636. TOperationSide Side, bool Back)
  1637. {
  1638. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1639. {
  1640. // workaround
  1641. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1642. // operator new allocates memory in Pascal code, but calls inline
  1643. // contructor in C++, leading in problems, the function does
  1644. // both in Pascal code
  1645. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1646. UpdateHistoryMenu(Side, Back);
  1647. }
  1648. return FHistoryMenu[Side == osLocal][Back];
  1649. }
  1650. //---------------------------------------------------------------------------
  1651. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1652. TCustomDirView *Sender)
  1653. {
  1654. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1655. UpdateHistoryMenu(Side, true);
  1656. UpdateHistoryMenu(Side, false);
  1657. }
  1658. //---------------------------------------------------------------------------
  1659. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1660. {
  1661. // remote custom commands can be executed only if the server supports shell commands
  1662. // or have secondary shell
  1663. return HasActiveTerminal() && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1664. }
  1665. //---------------------------------------------------------------------------
  1666. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1667. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1668. {
  1669. // -1 = hidden, 0 = disabled, 1 = enabled
  1670. int Result;
  1671. TFileCustomCommand RemoteCustomCommand;
  1672. TLocalCustomCommand LocalCustomCommand;
  1673. TFileCustomCommand * NonInteractiveCustomCommand =
  1674. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1675. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1676. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1677. if (FLAGCLEAR(Command.Params, ccLocal))
  1678. {
  1679. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1680. // custom command that does not operate with files can be executed anytime ...
  1681. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1682. {
  1683. // ... but do not show such command in remote file menu
  1684. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1685. {
  1686. Result = AllowedState;
  1687. }
  1688. else
  1689. {
  1690. Result = -1;
  1691. }
  1692. }
  1693. else
  1694. {
  1695. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1696. {
  1697. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1698. }
  1699. else
  1700. {
  1701. Result = -1;
  1702. }
  1703. }
  1704. }
  1705. else
  1706. {
  1707. // custom command that does not operate with files can be executed anytime
  1708. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1709. {
  1710. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1711. }
  1712. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1713. {
  1714. if ((ListType == ccltAll) || (ListType == ccltFile))
  1715. {
  1716. // special case is "diff"-style command that can be executed over any side,
  1717. // if we have both sides
  1718. Result =
  1719. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1720. // directly (instead of EnableSelectedOperation) to pass
  1721. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1722. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1723. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1724. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1725. }
  1726. else if (ListType == ccltBoth)
  1727. {
  1728. DebugAssert(!IsLocalBrowserMode());
  1729. Result = 1;
  1730. }
  1731. else
  1732. {
  1733. Result = -1;
  1734. }
  1735. }
  1736. else
  1737. {
  1738. if ((ListType == ccltAll) ||
  1739. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1740. {
  1741. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1742. }
  1743. else
  1744. {
  1745. Result = -1;
  1746. }
  1747. }
  1748. if ((Result > 0) &&
  1749. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1750. !HasActiveTerminal())
  1751. {
  1752. Result = 0;
  1753. }
  1754. }
  1755. return Result;
  1756. }
  1757. //---------------------------------------------------------------------------
  1758. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1759. TStrings * FileList, const TCustomCommandType & ACommand,
  1760. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1761. {
  1762. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1763. {
  1764. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1765. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1766. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1767. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1768. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1769. bool Capture =
  1770. FLAGSET(ACommand.Params, ccShowResults) ||
  1771. FLAGSET(ACommand.Params, ccCopyResults) ||
  1772. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1773. TCaptureOutputEvent OutputEvent = NULL;
  1774. DebugAssert(FCapturedLog == NULL);
  1775. if (Capture)
  1776. {
  1777. FCapturedLog = new TStringList();
  1778. OutputEvent = TerminalCaptureLog;
  1779. }
  1780. try
  1781. {
  1782. if (!RemoteCustomCommand.IsFileCommand(Command))
  1783. {
  1784. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1785. OutputEvent);
  1786. }
  1787. else
  1788. {
  1789. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1790. }
  1791. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1792. {
  1793. if (FLAGSET(ACommand.Params, ccCopyResults))
  1794. {
  1795. CopyToClipboard(FCapturedLog);
  1796. }
  1797. if (FLAGSET(ACommand.Params, ccShowResults))
  1798. {
  1799. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1800. }
  1801. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1802. {
  1803. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1804. }
  1805. }
  1806. }
  1807. __finally
  1808. {
  1809. SAFE_DESTROY(FCapturedLog);
  1810. }
  1811. }
  1812. }
  1813. //---------------------------------------------------------------------------
  1814. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1815. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1816. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1817. {
  1818. DebugAssert(!IsLocalBrowserMode());
  1819. TStrings * LocalFileList = NULL;
  1820. TStrings * RemoteFileList = NULL;
  1821. TStrings * RemoteFileListFull = NULL;
  1822. try
  1823. {
  1824. if (LocalFileCommand)
  1825. {
  1826. if (ALocalFileList == NULL)
  1827. {
  1828. DebugAssert(HasDirView[osLocal]);
  1829. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1830. // directly (instead of EnableSelectedOperation) to pass
  1831. // false to FocusedFileOnlyWhenFocused
  1832. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1833. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1834. }
  1835. else
  1836. {
  1837. LocalFileList = ALocalFileList;
  1838. }
  1839. if (FileListCommand)
  1840. {
  1841. if (LocalFileList->Count != 1)
  1842. {
  1843. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1844. }
  1845. }
  1846. else
  1847. {
  1848. if ((LocalFileList->Count != 1) &&
  1849. (FileList->Count != 1) &&
  1850. (LocalFileList->Count != FileList->Count))
  1851. {
  1852. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1853. }
  1854. }
  1855. }
  1856. UnicodeString RootTempDir;
  1857. UnicodeString TempDir;
  1858. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1859. if (!RemoteFiles)
  1860. {
  1861. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1862. }
  1863. try
  1864. {
  1865. TDateTimes RemoteFileTimes;
  1866. if (RemoteFiles)
  1867. {
  1868. RemoteFileList = FileList;
  1869. }
  1870. else
  1871. {
  1872. RemoteFileList = new TStringList();
  1873. TMakeLocalFileListParams MakeFileListParam;
  1874. MakeFileListParam.FileList = RemoteFileList;
  1875. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1876. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1877. MakeFileListParam.Recursive =
  1878. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1879. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1880. if (!MakeFileListParam.Recursive)
  1881. {
  1882. RemoteFileTimes.clear();
  1883. RemoteFileListFull = new TStringList();
  1884. MakeFileListParam.FileList = RemoteFileListFull;
  1885. MakeFileListParam.Recursive = true;
  1886. MakeFileListParam.IncludeDirs = false;
  1887. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1888. }
  1889. else
  1890. {
  1891. RemoteFileListFull = RemoteFileList;
  1892. }
  1893. }
  1894. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1895. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1896. if (!NonBlocking)
  1897. {
  1898. int Count;
  1899. if (FileListCommand)
  1900. {
  1901. Count = 1;
  1902. }
  1903. else if (LocalFileCommand)
  1904. {
  1905. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1906. }
  1907. else
  1908. {
  1909. Count = RemoteFileList->Count;
  1910. }
  1911. Progress.Start(foCustomCommand, osRemote, Count);
  1912. DebugAssert(FProgressForm != NULL);
  1913. FProgressForm->ReadOnly = true;
  1914. }
  1915. try
  1916. {
  1917. if (FileListCommand)
  1918. {
  1919. UnicodeString LocalFile;
  1920. // MakeFileList does not delimit filenames
  1921. UnicodeString FileList = MakeFileList(RemoteFileList);
  1922. if (LocalFileCommand)
  1923. {
  1924. DebugAssert(LocalFileList->Count == 1);
  1925. LocalFile = LocalFileList->Strings[0];
  1926. }
  1927. TLocalCustomCommand CustomCommand(Data,
  1928. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1929. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1930. if (NonBlocking)
  1931. {
  1932. DebugAssert(!POutput);
  1933. ExecuteShellChecked(ShellCommand);
  1934. }
  1935. else
  1936. {
  1937. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1938. }
  1939. }
  1940. else if (LocalFileCommand)
  1941. {
  1942. if (LocalFileList->Count == 1)
  1943. {
  1944. UnicodeString LocalFile = LocalFileList->Strings[0];
  1945. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1946. {
  1947. UnicodeString FileName = RemoteFileList->Strings[Index];
  1948. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1949. Progress.SetFile(FileNameForProgress);
  1950. TLocalCustomCommand CustomCommand(Data,
  1951. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1952. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1953. TOnceDoneOperation OnceDoneOperation;
  1954. // Do not unselect anything, as it won't work with two panels anyway
  1955. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1956. }
  1957. }
  1958. else if (RemoteFileList->Count == 1)
  1959. {
  1960. UnicodeString FileName = RemoteFileList->Strings[0];
  1961. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1962. {
  1963. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1964. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1965. Progress.SetFile(LocalFileNameOnly);
  1966. TLocalCustomCommand CustomCommand(
  1967. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1968. FileName, LocalFileName, L"");
  1969. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1970. TOnceDoneOperation OnceDoneOperation;
  1971. // Do not unselect anything, as it won't work with two panels anyway
  1972. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1973. }
  1974. }
  1975. else
  1976. {
  1977. if (LocalFileList->Count != RemoteFileList->Count)
  1978. {
  1979. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1980. }
  1981. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1982. {
  1983. UnicodeString FileName = RemoteFileList->Strings[Index];
  1984. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1985. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1986. Progress.SetFile(LocalFileNameOnly); // sic
  1987. TLocalCustomCommand CustomCommand(
  1988. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1989. FileName, LocalFileName, L"");
  1990. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1991. TOnceDoneOperation OnceDoneOperation;
  1992. // Do not unselect anything, as it won't work with two panels anyway
  1993. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1994. }
  1995. }
  1996. }
  1997. else
  1998. {
  1999. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2000. {
  2001. UnicodeString FileName = RemoteFileList->Strings[Index];
  2002. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2003. Progress.SetFile(FileNameForProgress);
  2004. TLocalCustomCommand CustomCommand(Data,
  2005. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2006. FileName, L"", L"");
  2007. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2008. TOnceDoneOperation OnceDoneOperation;
  2009. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2010. }
  2011. }
  2012. }
  2013. __finally
  2014. {
  2015. if (!NonBlocking)
  2016. {
  2017. Progress.Stop();
  2018. }
  2019. }
  2020. DebugAssert(!FAutoOperation);
  2021. if (!RemoteFiles)
  2022. {
  2023. TempDir = IncludeTrailingBackslash(TempDir);
  2024. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2025. {
  2026. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2027. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2028. // Skip directories, process only nested files.
  2029. // The check is redundant as FileAge fails for directories anyway.
  2030. !DirectoryExists(FileName))
  2031. {
  2032. UnicodeString RemoteDir =
  2033. UnixExtractFileDir(
  2034. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2035. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2036. TDateTime NewTime;
  2037. if (FileAge(FileName, NewTime) &&
  2038. (NewTime != RemoteFileTimes[Index]))
  2039. {
  2040. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2041. TemporaryFileCopyParam(CopyParam);
  2042. CopyParam.FileMask = L"";
  2043. FAutoOperation = true;
  2044. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2045. TemporaryFilesList->Add(FileName);
  2046. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2047. }
  2048. }
  2049. }
  2050. }
  2051. }
  2052. __finally
  2053. {
  2054. FAutoOperation = false;
  2055. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2056. {
  2057. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2058. }
  2059. }
  2060. }
  2061. __finally
  2062. {
  2063. if (RemoteFileList != FileList)
  2064. {
  2065. delete RemoteFileList;
  2066. }
  2067. if (LocalFileList != ALocalFileList)
  2068. {
  2069. delete LocalFileList;
  2070. }
  2071. if (RemoteFileListFull != RemoteFileList)
  2072. {
  2073. delete RemoteFileListFull;
  2074. }
  2075. }
  2076. }
  2077. //---------------------------------------------------------------------------
  2078. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2079. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2080. bool FileListCommand, UnicodeString * POutput)
  2081. {
  2082. std::unique_ptr<TStrings> SelectedFileList(DirView(osLocal)->CreateFileList(false, true, NULL));
  2083. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2084. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2085. {
  2086. UnicodeString FileName = SelectedFileList->Strings[Index];
  2087. if (DirectoryExists(FileName))
  2088. {
  2089. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2090. {
  2091. LocalFileList->Add(FileName);
  2092. }
  2093. if (FLAGSET(ACommand.Params, ccRecursive))
  2094. {
  2095. TMakeLocalFileListParams MakeFileListParam;
  2096. MakeFileListParam.FileList = LocalFileList.get();
  2097. MakeFileListParam.FileTimes = NULL;
  2098. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2099. MakeFileListParam.Recursive = true;
  2100. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2101. }
  2102. }
  2103. else
  2104. {
  2105. LocalFileList->Add(FileName);
  2106. }
  2107. }
  2108. UnicodeString RemotePath;
  2109. if (Terminal != NULL)
  2110. {
  2111. RemotePath = Terminal->CurrentDirectory;
  2112. }
  2113. if (FileListCommand)
  2114. {
  2115. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2116. TLocalCustomCommand CustomCommand(
  2117. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2118. L"", L"", FileList);
  2119. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2120. }
  2121. else
  2122. {
  2123. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2124. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2125. DebugAssert(FProgressForm != NULL);
  2126. FProgressForm->ReadOnly = true;
  2127. try
  2128. {
  2129. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2130. {
  2131. UnicodeString FileName = LocalFileList->Strings[Index];
  2132. Progress.SetFile(FileName);
  2133. TLocalCustomCommand CustomCommand(
  2134. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2135. FileName, L"", L"");
  2136. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2137. TOnceDoneOperation OnceDoneOperation;
  2138. Progress.Finish(FileName, true, OnceDoneOperation);
  2139. }
  2140. }
  2141. __finally
  2142. {
  2143. Progress.Stop();
  2144. }
  2145. }
  2146. }
  2147. //---------------------------------------------------------------------------
  2148. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2149. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2150. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2151. {
  2152. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2153. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2154. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2155. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2156. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2157. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2158. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2159. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2160. std::unique_ptr<UnicodeString> POutput;
  2161. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2162. FLAGSET(ACommand.Params, ccCopyResults))
  2163. {
  2164. POutput.reset(new UnicodeString());
  2165. }
  2166. if (!LocalCustomCommand.IsFileCommand(Command))
  2167. {
  2168. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2169. }
  2170. // remote files?
  2171. else if ((FCurrentSide == osRemote) || LocalFileCommand)
  2172. {
  2173. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2174. }
  2175. // local files
  2176. else
  2177. {
  2178. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2179. }
  2180. if (POutput.get() != NULL)
  2181. {
  2182. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2183. int P = POutput->Pos(sLineBreak);
  2184. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2185. {
  2186. POutput->SetLength(P - 1);
  2187. }
  2188. // Copy even empty output to clipboard
  2189. if (FLAGSET(ACommand.Params, ccCopyResults))
  2190. {
  2191. CopyToClipboard(*POutput);
  2192. }
  2193. // But do not show an empty message box.
  2194. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2195. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2196. !POutput->IsEmpty())
  2197. {
  2198. TClipboardHandler ClipboardHandler;
  2199. ClipboardHandler.Text = *POutput;
  2200. TMessageParams Params;
  2201. TQueryButtonAlias Aliases[1];
  2202. Aliases[0].Button = qaRetry;
  2203. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2204. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2205. Params.Aliases = Aliases;
  2206. Params.AliasesCount = LENOF(Aliases);
  2207. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2208. }
  2209. }
  2210. }
  2211. //---------------------------------------------------------------------------
  2212. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2213. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2214. {
  2215. TCustomCommandData Data;
  2216. UnicodeString Site;
  2217. UnicodeString RemotePath;
  2218. if (HasActiveTerminal())
  2219. {
  2220. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2221. Data = TCustomCommandData(SessionData.get());
  2222. Site = Terminal->SessionData->SessionKey;
  2223. RemotePath = Terminal->CurrentDirectory;
  2224. }
  2225. UnicodeString HelpKeyword = ACommand.HomePage;
  2226. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2227. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2228. {
  2229. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2230. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2231. {
  2232. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2233. }
  2234. else
  2235. {
  2236. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2237. }
  2238. if (!DoCustomCommandOptionsDialog(
  2239. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2240. {
  2241. Abort();
  2242. }
  2243. }
  2244. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2245. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2246. {
  2247. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2248. }
  2249. else
  2250. {
  2251. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2252. }
  2253. }
  2254. //---------------------------------------------------------------------------
  2255. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2256. const TCustomCommandType & Command)
  2257. {
  2258. DebugAssert(FCustomCommandLocalFileList != NULL);
  2259. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2260. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2261. TStrings * LocalFileList = new TStringList();
  2262. TStrings * RemoteFileList = new TStringList();
  2263. try
  2264. {
  2265. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2266. {
  2267. LocalFileList->Clear();
  2268. LocalFileList->AddObject(
  2269. FCustomCommandLocalFileList->Strings[Index],
  2270. FCustomCommandLocalFileList->Objects[Index]);
  2271. RemoteFileList->Clear();
  2272. RemoteFileList->AddObject(
  2273. FCustomCommandRemoteFileList->Strings[Index],
  2274. FCustomCommandRemoteFileList->Objects[Index]);
  2275. CustomCommand(RemoteFileList, Command, LocalFileList);
  2276. }
  2277. }
  2278. __finally
  2279. {
  2280. delete LocalFileList;
  2281. delete RemoteFileList;
  2282. }
  2283. }
  2284. //---------------------------------------------------------------------------
  2285. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2286. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2287. {
  2288. delete FCustomCommandLocalFileList;
  2289. delete FCustomCommandRemoteFileList;
  2290. // takeover ownership,
  2291. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2292. FCustomCommandLocalFileList = LocalFileList;
  2293. FCustomCommandRemoteFileList = RemoteFileList;
  2294. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2295. if (Button != NULL)
  2296. {
  2297. FCustomCommandMenu->Items->Clear();
  2298. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2299. MenuPopup(FCustomCommandMenu, Button);
  2300. }
  2301. else
  2302. {
  2303. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2304. }
  2305. }
  2306. //---------------------------------------------------------------------------
  2307. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2308. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2309. {
  2310. DebugAssert(FCapturedLog != NULL);
  2311. if ((OutputType == cotOutput) || (OutputType == cotError))
  2312. {
  2313. FCapturedLog->Add(AddedLine);
  2314. }
  2315. }
  2316. //---------------------------------------------------------------------------
  2317. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2318. TOperationSide Side)
  2319. {
  2320. return
  2321. (Side == osOther) &&
  2322. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2323. }
  2324. //---------------------------------------------------------------------------
  2325. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2326. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2327. {
  2328. TTBItemOptions O;
  2329. O = Item->Options;
  2330. TCustomDirView * DView = DirView(Side);
  2331. if ((DView->ItemFocused != NULL) &&
  2332. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2333. // when resolving links is disabled, default action is to enter the directory,
  2334. // no matter what DoubleClickAction is configured to
  2335. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2336. // Can only Edit files, but can Open/Copy even directories
  2337. ((DoubleClickAction != dcaEdit) ||
  2338. !DView->ItemIsDirectory(DView->ItemFocused)))
  2339. {
  2340. Item->Options = O << tboDefault;
  2341. }
  2342. else
  2343. {
  2344. Item->Options = O >> tboDefault;
  2345. }
  2346. }
  2347. //---------------------------------------------------------------------------
  2348. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2349. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2350. {
  2351. TCustomDirView * DView = DirView(Side);
  2352. TListItem * Item = DView->ItemFocused;
  2353. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2354. EnableFocusedOperation[Side])
  2355. {
  2356. TPoint ClientPoint;
  2357. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2358. TPoint(0, 0) : MousePos;
  2359. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2360. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2361. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2362. }
  2363. }
  2364. //---------------------------------------------------------------------------
  2365. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2366. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2367. {
  2368. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2369. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2370. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2371. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2372. Handled = true;
  2373. }
  2374. //---------------------------------------------------------------------------
  2375. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2376. {
  2377. }
  2378. //---------------------------------------------------------------------------
  2379. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2380. {
  2381. DebugAssert(FErrorList == NULL);
  2382. if (WinConfiguration->ContinueOnError)
  2383. {
  2384. FErrorList = new TStringList();
  2385. Configuration->Usage->Inc(L"ContinuationsOnError");
  2386. }
  2387. NonVisualDataModule->StartBusy();
  2388. }
  2389. //---------------------------------------------------------------------------
  2390. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2391. {
  2392. NonVisualDataModule->EndBusy();
  2393. if (FErrorList)
  2394. {
  2395. HandleErrorList(FErrorList);
  2396. }
  2397. }
  2398. //---------------------------------------------------------------------------
  2399. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2400. const TCopyParamType & CopyParam)
  2401. {
  2402. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2403. {
  2404. Configuration->Usage->Inc(L"FileMaskUses");
  2405. }
  2406. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2407. {
  2408. Configuration->Usage->Inc(L"OperationMaskUses");
  2409. }
  2410. }
  2411. //---------------------------------------------------------------------------
  2412. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2413. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2414. {
  2415. DebugAssert(!IsLocalBrowserMode());
  2416. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2417. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2418. TTransferOperationParam DefaultParam;
  2419. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2420. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2421. switch (Param.Queue)
  2422. {
  2423. case asOn:
  2424. CopyParam.Queue = true;
  2425. break;
  2426. case asOff:
  2427. CopyParam.Queue = false;
  2428. break;
  2429. case asAuto:
  2430. default:
  2431. // keep default
  2432. break;
  2433. }
  2434. bool Result =
  2435. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2436. if (Result)
  2437. {
  2438. DebugAssert(Terminal);
  2439. bool SelectionRestored = false;
  2440. TCustomDirView * DView = NULL;
  2441. if (HasDirView[Side])
  2442. {
  2443. DView = DirView(Side);
  2444. DView->SaveSelection();
  2445. DView->SaveSelectedNames();
  2446. }
  2447. UpdateCopyParamCounters(CopyParam);
  2448. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2449. DebugAssert(FTransferResumeList == NULL);
  2450. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2451. FMoveToQueue = false;
  2452. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2453. try
  2454. {
  2455. TStrings * PermanentFileList;
  2456. std::unique_ptr<TStrings> PermanentFileListOwner;
  2457. try
  2458. {
  2459. if (Side == osLocal)
  2460. {
  2461. PermanentFileList = FileList;
  2462. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2463. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2464. if (Operation == foMove)
  2465. {
  2466. ReloadLocalDirectory();
  2467. if (DView != NULL)
  2468. {
  2469. DView->RestoreSelection();
  2470. }
  2471. SelectionRestored = true;
  2472. }
  2473. }
  2474. else
  2475. {
  2476. // Clone the file list as it may refer to current directory files,
  2477. // which get destroyed, when the source directory is reloaded after foMove operation.
  2478. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2479. // But for a hotfix, we are not going to do such a big change.
  2480. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2481. PermanentFileList = PermanentFileListOwner.get();
  2482. try
  2483. {
  2484. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2485. }
  2486. __finally
  2487. {
  2488. if (Operation == foMove)
  2489. {
  2490. if (DView != NULL)
  2491. {
  2492. DView->RestoreSelection();
  2493. }
  2494. SelectionRestored = true;
  2495. }
  2496. ReloadLocalDirectory(Param.TargetDirectory);
  2497. }
  2498. }
  2499. }
  2500. catch (EAbort &)
  2501. {
  2502. if (FMoveToQueue)
  2503. {
  2504. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2505. DebugAssert(CopyParam.TransferSkipList == NULL);
  2506. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2507. if (TransferResumeList->Count > 0)
  2508. {
  2509. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2510. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2511. }
  2512. CopyParam.TransferSkipList = TransferResumeList.release();
  2513. // not really needed, just to keep it consistent with TransferResumeList
  2514. FTransferResumeList = NULL;
  2515. FMoveToQueue = false;
  2516. Configuration->Usage->Inc("MovesToBackground");
  2517. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2518. ClearTransferSourceSelection(Direction);
  2519. }
  2520. throw;
  2521. }
  2522. }
  2523. __finally
  2524. {
  2525. if (!SelectionRestored && (DView != NULL))
  2526. {
  2527. DView->DiscardSavedSelection();
  2528. }
  2529. FTransferResumeList = NULL;
  2530. }
  2531. }
  2532. return Result;
  2533. }
  2534. //---------------------------------------------------------------------------
  2535. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2536. TOperationSide Side, TStrings * FileList, void * Param)
  2537. {
  2538. DebugAssert(FileList->Count);
  2539. // We deliberately do not toggle alternative flag (Param), but use OR,
  2540. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2541. // shortcut of CurrentDeleteAlternativeAction
  2542. bool Alternative =
  2543. bool(Param) || UseAlternativeFunction();
  2544. bool Recycle;
  2545. if (IsSideLocalBrowser(Side))
  2546. {
  2547. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2548. }
  2549. else
  2550. {
  2551. Recycle =
  2552. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2553. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2554. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2555. }
  2556. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2557. if (!Result)
  2558. {
  2559. UnicodeString Query;
  2560. if (FileList->Count == 1)
  2561. {
  2562. if (IsSideLocalBrowser(Side))
  2563. {
  2564. Query = ExtractFileName(FileList->Strings[0]);
  2565. }
  2566. else
  2567. {
  2568. Query = UnixExtractFileName(FileList->Strings[0]);
  2569. }
  2570. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2571. }
  2572. else
  2573. {
  2574. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2575. }
  2576. TMessageParams Params(mpNeverAskAgainCheck);
  2577. Params.ImageName = L"Delete file";
  2578. unsigned int Answer =
  2579. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2580. if (Answer == qaNeverAskAgain)
  2581. {
  2582. Result = true;
  2583. if (Recycle)
  2584. {
  2585. WinConfiguration->ConfirmRecycling = false;
  2586. }
  2587. else
  2588. {
  2589. WinConfiguration->ConfirmDeleting = false;
  2590. }
  2591. }
  2592. else
  2593. {
  2594. Result = (Answer == qaOK);
  2595. }
  2596. }
  2597. if (Result)
  2598. {
  2599. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2600. }
  2601. return Result;
  2602. }
  2603. //---------------------------------------------------------------------------
  2604. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2605. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2606. {
  2607. TAutoBatch AutoBatch(this);
  2608. bool Result;
  2609. if ((Operation == foCopy) || (Operation == foMove))
  2610. {
  2611. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2612. }
  2613. else if (Operation == foRename)
  2614. {
  2615. DebugAssert(DirView(Side)->ItemFocused);
  2616. DirView(Side)->ItemFocused->EditCaption();
  2617. Result = true;
  2618. }
  2619. else if (Operation == foDelete)
  2620. {
  2621. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2622. }
  2623. else if (Operation == foSetProperties)
  2624. {
  2625. DirView(osRemote)->SaveSelectedNames();
  2626. Result = SetProperties(Side, FileList);
  2627. }
  2628. else if (Operation == foCustomCommand)
  2629. {
  2630. DebugAssert(Param);
  2631. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2632. DirView(osRemote)->SaveSelectedNames();
  2633. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2634. CustomCommand(FileList, *Command, NULL);
  2635. Result = true;
  2636. }
  2637. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2638. {
  2639. DebugAssert(!IsSideLocalBrowser(Side));
  2640. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2641. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2642. }
  2643. else if (Operation == foLock)
  2644. {
  2645. DebugAssert(!IsSideLocalBrowser(Side));
  2646. LockFiles(FileList, true);
  2647. Result = true;
  2648. }
  2649. else if (Operation == foUnlock)
  2650. {
  2651. DebugAssert(!IsSideLocalBrowser(Side));
  2652. LockFiles(FileList, false);
  2653. Result = true;
  2654. }
  2655. else
  2656. {
  2657. DebugFail();
  2658. }
  2659. return Result;
  2660. }
  2661. //---------------------------------------------------------------------------
  2662. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2663. {
  2664. if (Side == osCurrent)
  2665. {
  2666. Side = FCurrentSide;
  2667. }
  2668. return Side;
  2669. }
  2670. //---------------------------------------------------------------------------
  2671. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2672. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2673. {
  2674. Side = GetSide(Side);
  2675. bool Result;
  2676. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2677. try
  2678. {
  2679. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2680. }
  2681. __finally
  2682. {
  2683. delete FileList;
  2684. }
  2685. return Result;
  2686. }
  2687. //---------------------------------------------------------------------------
  2688. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2689. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2690. bool NoConfirmation, void * Param)
  2691. {
  2692. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2693. {
  2694. if ((Operation == foCopy) || (Operation == foMove))
  2695. {
  2696. DebugAssert(!IsLocalBrowserMode());
  2697. if (GetSide(Side) == osLocal)
  2698. {
  2699. Configuration->Usage->Inc(L"UploadsCommand");
  2700. }
  2701. else
  2702. {
  2703. Configuration->Usage->Inc(L"DownloadsCommand");
  2704. }
  2705. }
  2706. }
  2707. }
  2708. //---------------------------------------------------------------------------
  2709. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2710. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2711. {
  2712. TTransferOperationParam Param;
  2713. if ((WinConfiguration->Interface != ifCommander) ||
  2714. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2715. {
  2716. Flags &= ~cocShortCutHint;
  2717. }
  2718. TCustomDirView * DView = DirView(Side);
  2719. Param.Options =
  2720. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2721. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2722. if (FLAGSET(Flags, cocQueue))
  2723. {
  2724. Param.Queue = asOn;
  2725. }
  2726. else if (FLAGSET(Flags, cocNonQueue))
  2727. {
  2728. Param.Queue = asOff;
  2729. }
  2730. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2731. }
  2732. //---------------------------------------------------------------------------
  2733. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2734. {
  2735. try
  2736. {
  2737. if (ErrorList->Count)
  2738. {
  2739. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2740. if (MessageDialog(Message, qtError,
  2741. qaOK | qaCancel, HELP_NONE) == qaOK)
  2742. {
  2743. unsigned int Answer;
  2744. int Index = 0;
  2745. do
  2746. {
  2747. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2748. TQueryButtonAlias Aliases[2];
  2749. Aliases[0].Button = qaYes;
  2750. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2751. Aliases[1].Button = qaNo;
  2752. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2753. TMessageParams Params;
  2754. Params.Aliases = Aliases;
  2755. Params.AliasesCount = LENOF(Aliases);
  2756. Answer = MoreMessageDialog(
  2757. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2758. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2759. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2760. qaOK, HELP_NONE, &Params);
  2761. if (Answer == qaNo)
  2762. {
  2763. Index++;
  2764. }
  2765. if (Answer == qaYes)
  2766. {
  2767. Index--;
  2768. }
  2769. }
  2770. while (Answer != qaOK);
  2771. }
  2772. }
  2773. }
  2774. __finally
  2775. {
  2776. TStrings * List = ErrorList;
  2777. ErrorList = NULL;
  2778. for (int i = 0; i < List->Count; i++)
  2779. {
  2780. delete List->Objects[i];
  2781. }
  2782. delete List;
  2783. }
  2784. }
  2785. //---------------------------------------------------------------------------
  2786. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2787. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2788. {
  2789. // needed for checking filemasks, as there's no directory object
  2790. // associated with the file object
  2791. File->FullFileName = FullFileName;
  2792. TFileMasks::TParams MaskParams;
  2793. MaskParams.Size = File->Size;
  2794. MaskParams.Modification = File->Modification;
  2795. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2796. }
  2797. //---------------------------------------------------------------------------
  2798. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2799. {
  2800. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2801. Side = GetSide(Side);
  2802. TCustomDirView * DView = DirView(Side);
  2803. TListItem * FocusedItem = DView->ItemFocused;
  2804. UnicodeString Name;
  2805. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2806. {
  2807. Name = DView->ItemFileName(FocusedItem);
  2808. }
  2809. else
  2810. {
  2811. Name = LoadStr(NEW_FILE);
  2812. }
  2813. UnicodeString Names = Name;
  2814. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2815. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2816. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  2817. {
  2818. while (!Names.IsEmpty())
  2819. {
  2820. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2821. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2822. UnicodeString TargetFileName;
  2823. UnicodeString LocalFileName;
  2824. UnicodeString RootTempDir;
  2825. UnicodeString TempDir;
  2826. UnicodeString RemoteDirectory;
  2827. bool ExistingFile = false;
  2828. if (!IsSideLocalBrowser(Side))
  2829. {
  2830. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2831. TRemoteFile * File = NULL;
  2832. if (FTerminal->FileExists(Name, &File) &&
  2833. !File->IsDirectory)
  2834. {
  2835. try
  2836. {
  2837. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2838. ExistingFile = true;
  2839. }
  2840. __finally
  2841. {
  2842. delete File;
  2843. }
  2844. }
  2845. if (!ExistingFile)
  2846. {
  2847. RemoteDirectory = UnixExtractFilePath(Name);
  2848. TemporaryDirectoryForRemoteFiles(
  2849. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2850. TargetFileName = UnixExtractFileName(Name);
  2851. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2852. LocalFileName = TempDir +
  2853. // We probably do not want to trim the VMS version here
  2854. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2855. }
  2856. }
  2857. else
  2858. {
  2859. if (ExtractFilePath(Name).IsEmpty())
  2860. {
  2861. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2862. }
  2863. else
  2864. {
  2865. LocalFileName = ExpandFileName(Name);
  2866. }
  2867. TargetFileName = ExtractFileName(Name);
  2868. }
  2869. if (!ExistingFile)
  2870. {
  2871. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2872. if (NewFile)
  2873. {
  2874. int File = FileCreate(ApiPath(LocalFileName));
  2875. if (File < 0)
  2876. {
  2877. if (!RootTempDir.IsEmpty())
  2878. {
  2879. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2880. }
  2881. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2882. }
  2883. else
  2884. {
  2885. FileClose(File);
  2886. }
  2887. }
  2888. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2889. const TEditorData * ExternalEditor = NULL;
  2890. TFileMasks::TParams MaskParams; // size not known
  2891. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2892. false, MaskParams);
  2893. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2894. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2895. }
  2896. }
  2897. }
  2898. }
  2899. //---------------------------------------------------------------------------
  2900. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2901. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2902. {
  2903. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2904. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2905. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2906. return
  2907. ((ExecuteFileBy == efInternalEditor)) ||
  2908. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2909. }
  2910. //---------------------------------------------------------------------------
  2911. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2912. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2913. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2914. UnicodeString RemoteDirectory, bool NewFile)
  2915. {
  2916. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2917. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2918. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2919. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2920. Side = GetSide(Side);
  2921. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2922. if (!IsSideLocalBrowser(Side))
  2923. {
  2924. Data->Terminal = Terminal;
  2925. Data->Queue = Queue;
  2926. Data->SessionData = CloneCurrentSessionData();
  2927. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2928. Data->RemoteDirectory = RemoteDirectory;
  2929. Data->SessionName = Terminal->SessionData->SessionName;
  2930. Data->LocalRootDirectory = LocalRootDirectory;
  2931. Data->OriginalFileName = OriginalFileName;
  2932. Data->Command = L""; // will be changed later for external editor
  2933. }
  2934. if (ExecuteFileBy == efInternalEditor)
  2935. {
  2936. if (!IsSideLocalBrowser(Side))
  2937. {
  2938. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2939. L" - " + Terminal->SessionData->SessionName;
  2940. TForm * Editor;
  2941. try
  2942. {
  2943. TNotifyEvent OnFileChanged = NULL;
  2944. TNotifyEvent OnSaveAll = NULL;
  2945. TAnyModifiedEvent OnAnyModified = NULL;
  2946. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2947. if (Terminal->IsCapable[fcBackgroundTransfers])
  2948. {
  2949. OnFileChanged = FEditorManager->FileChanged;
  2950. OnSaveAll = SaveAllInternalEditors;
  2951. OnAnyModified = AnyInternalEditorModified;
  2952. }
  2953. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2954. FEditorManager->FileReload, FEditorManager->FileClosed,
  2955. OnSaveAll, OnAnyModified,
  2956. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2957. }
  2958. catch(...)
  2959. {
  2960. if (!LocalRootDirectory.IsEmpty())
  2961. {
  2962. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2963. }
  2964. throw;
  2965. }
  2966. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2967. }
  2968. else
  2969. {
  2970. DebugAssert(!FStandaloneEditing);
  2971. TForm * Editor =
  2972. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2973. SaveAllInternalEditors, AnyInternalEditorModified,
  2974. L"", false, SessionColor, -1, NewFile);
  2975. FLocalEditors->Add(Editor);
  2976. }
  2977. }
  2978. else
  2979. {
  2980. HANDLE Process;
  2981. if (ExecuteFileBy == efExternalEditor)
  2982. {
  2983. UnicodeString Program, Params, Dir;
  2984. Data->Command = ExternalEditor->ExternalEditor;
  2985. ReformatFileNameCommand(Data->Command);
  2986. SplitCommand(Data->Command, Program, Params, Dir);
  2987. Params = ExpandFileNameCommand(Params, FileName);
  2988. Program = ExpandEnvironmentVariables(Program);
  2989. if (!ExecuteShell(Program, Params, Process))
  2990. {
  2991. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  2992. }
  2993. }
  2994. else
  2995. {
  2996. DebugAssert(!IsSideLocalBrowser(Side));
  2997. if (!ExecuteShell(FileName, L"", Process))
  2998. {
  2999. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3000. }
  3001. }
  3002. if (IsSideLocalBrowser(Side) ||
  3003. ((ExecuteFileBy == efShell) &&
  3004. !WinConfiguration->Editor.SDIShellEditor) ||
  3005. ((ExecuteFileBy == efExternalEditor) &&
  3006. !ExternalEditor->SDIExternalEditor))
  3007. {
  3008. // no need for handle
  3009. if (Process != NULL)
  3010. {
  3011. DebugCheck(CloseHandle(Process));
  3012. }
  3013. Process = INVALID_HANDLE_VALUE;
  3014. }
  3015. else
  3016. {
  3017. if (Process == NULL)
  3018. {
  3019. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3020. }
  3021. }
  3022. if (!IsSideLocalBrowser(Side))
  3023. {
  3024. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3025. }
  3026. }
  3027. }
  3028. //---------------------------------------------------------------------------
  3029. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3030. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3031. void * /*Arg*/)
  3032. {
  3033. if (Token != NULL)
  3034. {
  3035. EditorFormFileSave(static_cast<TForm *>(Token));
  3036. }
  3037. }
  3038. //---------------------------------------------------------------------------
  3039. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3040. {
  3041. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3042. {
  3043. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3044. }
  3045. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3046. }
  3047. //---------------------------------------------------------------------------
  3048. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3049. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3050. void * Arg)
  3051. {
  3052. if ((Token != NULL) &&
  3053. IsEditorFormModified(static_cast<TForm *>(Token)))
  3054. {
  3055. *static_cast<bool *>(Arg) = true;
  3056. }
  3057. }
  3058. //---------------------------------------------------------------------------
  3059. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3060. TObject * /*Sender*/, bool & Modified)
  3061. {
  3062. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3063. {
  3064. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3065. {
  3066. Modified = true;
  3067. }
  3068. }
  3069. if (!Modified)
  3070. {
  3071. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3072. }
  3073. }
  3074. //---------------------------------------------------------------------------
  3075. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3076. {
  3077. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3078. }
  3079. //---------------------------------------------------------------------------
  3080. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3081. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3082. UnicodeString & Result, UnicodeString & RootDirectory)
  3083. {
  3084. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3085. {
  3086. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3087. Result = RootDirectory;
  3088. }
  3089. else
  3090. {
  3091. RootDirectory = L"";
  3092. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3093. Result = IncludeTrailingBackslash(Result);
  3094. }
  3095. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3096. {
  3097. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3098. }
  3099. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3100. {
  3101. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3102. {
  3103. RemoteDirectory.Delete(1, 1);
  3104. }
  3105. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3106. }
  3107. if (!ForceDirectories(ApiPath(Result)))
  3108. {
  3109. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3110. }
  3111. }
  3112. //---------------------------------------------------------------------------
  3113. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3114. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3115. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3116. {
  3117. DebugAssert(!IsLocalBrowserMode());
  3118. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3119. if (ForceText)
  3120. {
  3121. CopyParam.TransferMode = tmAscii;
  3122. }
  3123. TemporaryFileCopyParam(CopyParam);
  3124. if (AllFiles)
  3125. {
  3126. CopyParam.IncludeFileMask = TFileMasks();
  3127. }
  3128. if (TempDir.IsEmpty())
  3129. {
  3130. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3131. }
  3132. DebugAssert(!FAutoOperation);
  3133. FAutoOperation = AutoOperation;
  3134. Terminal->ExceptionOnFail = true;
  3135. try
  3136. {
  3137. try
  3138. {
  3139. // turn off confirmations, as for MDI editors we may possibly download
  3140. // the same file over
  3141. Terminal->CopyToLocal(
  3142. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3143. if (GetTargetNames)
  3144. {
  3145. for (int i = 0; i < FileList->Count; i++)
  3146. {
  3147. FileList->Strings[i] =
  3148. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3149. }
  3150. }
  3151. }
  3152. catch(...)
  3153. {
  3154. if (!RootTempDir.IsEmpty())
  3155. {
  3156. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3157. }
  3158. throw;
  3159. }
  3160. }
  3161. __finally
  3162. {
  3163. FAutoOperation = false;
  3164. Terminal->ExceptionOnFail = false;
  3165. }
  3166. }
  3167. //---------------------------------------------------------------------------
  3168. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3169. {
  3170. // Do not waste time checking for default editor list the next time,
  3171. // or testing if default editor is not notepad.
  3172. bool TryNextTime = false;
  3173. UnicodeString UsageState;
  3174. if (!WinConfiguration->EditorList->IsDefaultList())
  3175. {
  3176. UsageState = "H";
  3177. }
  3178. else
  3179. {
  3180. UnicodeString Executable;
  3181. UnicodeString ExecutableDescription;
  3182. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3183. {
  3184. UnicodeString Message =
  3185. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3186. unsigned int Answer =
  3187. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3188. if (Answer != qaOK)
  3189. {
  3190. UsageState = "R";
  3191. }
  3192. else
  3193. {
  3194. UsageState = "A";
  3195. TEditorData EditorData;
  3196. EditorData.Editor = edExternal;
  3197. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3198. EditorData.ExternalEditorOptionsAutodetect();
  3199. TEditorList EditorList;
  3200. EditorList = *WinConfiguration->EditorList;
  3201. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3202. WinConfiguration->EditorList = &EditorList;
  3203. }
  3204. }
  3205. }
  3206. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3207. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3208. }
  3209. //---------------------------------------------------------------------------
  3210. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3211. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3212. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3213. {
  3214. if (ExecuteFileBy == efDefaultEditor)
  3215. {
  3216. if (!WinConfiguration->OfferedEditorAutoConfig)
  3217. {
  3218. EditorAutoConfig();
  3219. }
  3220. const TEditorPreferences * Editor =
  3221. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3222. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3223. {
  3224. ExecuteFileBy = efInternalEditor;
  3225. ExternalEditor = NULL;
  3226. }
  3227. else if (Editor->Data->Editor == edOpen)
  3228. {
  3229. ExecuteFileBy = efShell;
  3230. ExternalEditor = NULL;
  3231. }
  3232. else
  3233. {
  3234. ExecuteFileBy = efExternalEditor;
  3235. ExternalEditor = Editor->Data;
  3236. }
  3237. }
  3238. }
  3239. //---------------------------------------------------------------------------
  3240. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3241. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3242. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3243. {
  3244. UnicodeString OriginalFileName;
  3245. UnicodeString LocalRootDirectory;
  3246. UnicodeString RemoteDirectory;
  3247. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3248. IsSideLocalBrowser(Side), MaskParams);
  3249. UnicodeString Counter;
  3250. UnicodeString LocalFileName;
  3251. bool Handled = false;
  3252. if (!IsSideLocalBrowser(Side))
  3253. {
  3254. // We need to trim VMS version here, so that we use name without version
  3255. // when uploading back to create a new version of the file
  3256. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3257. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3258. TObject * Token = NULL;
  3259. UnicodeString LocalDirectory;
  3260. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3261. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3262. LocalDirectory))
  3263. {
  3264. if (Token != NULL)
  3265. {
  3266. TForm * Form = dynamic_cast<TForm *>(Token);
  3267. if (Form->WindowState == wsMinimized)
  3268. {
  3269. ShowWindow(Form->Handle, SW_RESTORE);
  3270. }
  3271. else
  3272. {
  3273. Form->SetFocus();
  3274. }
  3275. Handled = true;
  3276. }
  3277. else
  3278. {
  3279. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3280. }
  3281. }
  3282. if (!Handled)
  3283. {
  3284. TStringList * FileList1 = new TStringList();
  3285. try
  3286. {
  3287. FileList1->AddObject(FullFileName, Object);
  3288. TemporarilyDownloadFiles(FileList1,
  3289. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3290. LocalRootDirectory, LocalDirectory, true, true, true);
  3291. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3292. }
  3293. __finally
  3294. {
  3295. delete FileList1;
  3296. }
  3297. switch (ExecuteFileBy)
  3298. {
  3299. case efShell:
  3300. Counter = "RemoteFilesExecuted";
  3301. break;
  3302. case efInternalEditor:
  3303. Counter = "RemoteFilesOpenedInInternalEditor";
  3304. break;
  3305. case efExternalEditor:
  3306. Counter = "RemoteFilesOpenedInExternalEditor";
  3307. break;
  3308. default:
  3309. DebugFail();
  3310. }
  3311. }
  3312. }
  3313. else
  3314. {
  3315. LocalFileName = FullFileName;
  3316. OriginalFileName = ExtractFileName(FullFileName);
  3317. switch (ExecuteFileBy)
  3318. {
  3319. case efShell:
  3320. Counter = "LocalFilesExecuted";
  3321. break;
  3322. case efInternalEditor:
  3323. Counter = "LocalFilesOpenedInInternalEditor";
  3324. break;
  3325. case efExternalEditor:
  3326. Counter = "LocalFilesOpenedInExternalEditor";
  3327. break;
  3328. default:
  3329. DebugFail();
  3330. }
  3331. }
  3332. if (!Handled)
  3333. {
  3334. Configuration->Usage->Inc(Counter);
  3335. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3336. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3337. }
  3338. }
  3339. //---------------------------------------------------------------------------
  3340. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3341. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3342. bool AllSelected, bool OnFocused)
  3343. {
  3344. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3345. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3346. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3347. Side = GetSide(Side);
  3348. TCustomDirView * DView = DirView(Side);
  3349. TStrings * FileList =
  3350. AllSelected ?
  3351. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3352. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3353. try
  3354. {
  3355. DebugAssert(AllSelected || (FileList->Count == 1));
  3356. for (int i = 0; i < FileList->Count; i++)
  3357. {
  3358. UnicodeString ListFileName = FileList->Strings[i];
  3359. UnicodeString FileNameOnly =
  3360. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3361. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3362. if (!DView->ItemIsDirectory(Item))
  3363. {
  3364. UnicodeString FullFileName;
  3365. if (!IsSideLocalBrowser(Side))
  3366. {
  3367. FullFileName = DirView(Side)->Path + ListFileName;
  3368. }
  3369. else
  3370. {
  3371. FullFileName = ListFileName;
  3372. }
  3373. TFileMasks::TParams MaskParams;
  3374. MaskParams.Size = DView->ItemFileSize(Item);
  3375. TDateTimePrecision Precision;
  3376. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3377. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3378. FileList->Objects[i], MaskParams);
  3379. }
  3380. }
  3381. }
  3382. __finally
  3383. {
  3384. delete FileList;
  3385. }
  3386. }
  3387. //---------------------------------------------------------------------------
  3388. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3389. {
  3390. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3391. CopyParam.FileNameCase = ncNoChange;
  3392. CopyParam.PreserveRights = false;
  3393. CopyParam.PreserveReadOnly = false;
  3394. CopyParam.ReplaceInvalidChars = true;
  3395. CopyParam.IncludeFileMask = TFileMasks();
  3396. CopyParam.NewerOnly = false;
  3397. CopyParam.FileMask = L"";
  3398. }
  3399. //---------------------------------------------------------------------------
  3400. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3401. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3402. {
  3403. TTerminalManager * Manager = TTerminalManager::Instance();
  3404. if (!IsActiveTerminal(Data->Terminal))
  3405. {
  3406. if (!NonVisualDataModule->Busy)
  3407. {
  3408. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3409. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3410. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3411. if (Data->Terminal == NULL)
  3412. {
  3413. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3414. if (SameSiteTerminal != NULL)
  3415. {
  3416. UnicodeString Message =
  3417. FMTLOAD(EDIT_SESSION_REATTACH,
  3418. (FileNameOnly, Data->SessionName, FileNameOnly));
  3419. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3420. {
  3421. Data->Terminal = Terminal;
  3422. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3423. Data->SessionName = Terminal->SessionData->SessionName;
  3424. // We might also overwrite session data
  3425. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3426. }
  3427. else
  3428. {
  3429. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3430. Abort();
  3431. }
  3432. }
  3433. }
  3434. // foreground session should reconnect itself
  3435. else if (Terminal != Data->Terminal)
  3436. {
  3437. UnicodeString Message =
  3438. MainInstructions(
  3439. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3440. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3441. {
  3442. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3443. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3444. }
  3445. else
  3446. {
  3447. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3448. Abort();
  3449. }
  3450. }
  3451. }
  3452. if (!IsActiveTerminal(Data->Terminal))
  3453. {
  3454. Configuration->Usage->Inc(L"EditInactiveSession");
  3455. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3456. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3457. (ExtractFileName(FileName), Data->SessionName)));
  3458. }
  3459. }
  3460. TStrings * FileList = new TStringList();
  3461. try
  3462. {
  3463. FileList->Add(FileName);
  3464. // consider using the same settings (preset) as when the file was downloaded
  3465. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3466. TemporaryFileCopyParam(CopyParam);
  3467. if (Data->ForceText)
  3468. {
  3469. CopyParam.TransferMode = tmAscii;
  3470. }
  3471. // so i do not need to worry if masking algorithm works in all cases
  3472. // ("" means "copy file name", no masking is actually done)
  3473. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3474. {
  3475. CopyParam.FileMask = L"";
  3476. }
  3477. else
  3478. {
  3479. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3480. }
  3481. DebugAssert(Data->Queue != NULL);
  3482. int Params = cpNoConfirmation | cpTemporary;
  3483. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3484. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3485. QueueItem->CompleteEvent = UploadCompleteEvent;
  3486. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3487. }
  3488. __finally
  3489. {
  3490. delete FileList;
  3491. }
  3492. }
  3493. //---------------------------------------------------------------------------
  3494. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3495. const UnicodeString FileName, const TEditedFileData * Data)
  3496. {
  3497. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3498. DebugAssert(!NonVisualDataModule->Busy);
  3499. if (!IsActiveTerminal(Data->Terminal))
  3500. {
  3501. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3502. (ExtractFileName(FileName), Data->SessionName)));
  3503. }
  3504. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3505. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3506. NonVisualDataModule->StartBusy();
  3507. try
  3508. {
  3509. std::unique_ptr<TRemoteFile> File;
  3510. UnicodeString RemoteFileName =
  3511. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3512. FTerminal->ExceptionOnFail = true;
  3513. try
  3514. {
  3515. TRemoteFile * AFile = NULL;
  3516. FTerminal->ReadFile(RemoteFileName, AFile);
  3517. File.reset(AFile);
  3518. if (!File->HaveFullFileName)
  3519. {
  3520. File->FullFileName = RemoteFileName;
  3521. }
  3522. }
  3523. __finally
  3524. {
  3525. FTerminal->ExceptionOnFail = false;
  3526. }
  3527. std::unique_ptr<TStrings> FileList(new TStringList());
  3528. FileList->AddObject(RemoteFileName, File.get());
  3529. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3530. UnicodeString TempDir = ExtractFilePath(FileName);
  3531. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3532. TempDir, true, true, true);
  3533. // sanity check, the target file name should be still the same
  3534. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3535. }
  3536. __finally
  3537. {
  3538. NonVisualDataModule->EndBusy();
  3539. // it actually may not exist anymore...
  3540. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3541. }
  3542. }
  3543. //---------------------------------------------------------------------------
  3544. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3545. const TEditedFileData * Data, bool & KeepOpen)
  3546. {
  3547. // Command is set for external editors only (not for "shell" open).
  3548. if (!Data->Command.IsEmpty())
  3549. {
  3550. bool AnyFound = false;
  3551. bool AnyMDI = false;
  3552. bool AnyNonMDI = false;
  3553. bool AnyDetect = false;
  3554. TEditorList * EditorList = new TEditorList();
  3555. try
  3556. {
  3557. *EditorList = *WinConfiguration->EditorList;
  3558. for (int i = 0; i < EditorList->Count; i++)
  3559. {
  3560. const TEditorPreferences * Editor = EditorList->Editors[i];
  3561. if ((Editor->Data->Editor == edExternal) &&
  3562. (Editor->Data->ExternalEditor == Data->Command))
  3563. {
  3564. AnyFound = true;
  3565. if (Editor->Data->SDIExternalEditor)
  3566. {
  3567. AnyNonMDI = true;
  3568. if (Editor->Data->DetectMDIExternalEditor)
  3569. {
  3570. AnyDetect = true;
  3571. }
  3572. }
  3573. else
  3574. {
  3575. AnyMDI = true;
  3576. }
  3577. }
  3578. }
  3579. bool EnableMDI = false;
  3580. bool DisableDetect = false;
  3581. if (AnyMDI)
  3582. {
  3583. KeepOpen = true;
  3584. if (AnyNonMDI)
  3585. {
  3586. // there is at least one instance of the editor with MDI support enabled,
  3587. // and one with disabled, enable it for all instances
  3588. EnableMDI = true;
  3589. }
  3590. }
  3591. else if (AnyFound && !AnyDetect)
  3592. {
  3593. // at least once instance found but all have MDI autodetection disabled
  3594. // => close the file (default action)
  3595. }
  3596. else
  3597. {
  3598. // no instance of the editor has MDI support enabled
  3599. TMessageParams Params;
  3600. if (AnyFound)
  3601. {
  3602. // there is at least one instance of the editor
  3603. Params.Params |= mpNeverAskAgainCheck;
  3604. }
  3605. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3606. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3607. switch (Answer)
  3608. {
  3609. case qaNeverAskAgain:
  3610. DisableDetect = true;
  3611. break;
  3612. case qaNo:
  3613. EnableMDI = true;
  3614. KeepOpen = true;
  3615. break;
  3616. }
  3617. }
  3618. if (AnyFound && (EnableMDI || DisableDetect))
  3619. {
  3620. bool Changed = false;
  3621. for (int i = 0; i < EditorList->Count; i++)
  3622. {
  3623. const TEditorPreferences * Editor = EditorList->Editors[i];
  3624. if ((Editor->Data->Editor == edExternal) &&
  3625. (Editor->Data->ExternalEditor == Data->Command) &&
  3626. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3627. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3628. {
  3629. Changed = true;
  3630. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3631. if (EnableMDI)
  3632. {
  3633. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3634. }
  3635. if (DisableDetect)
  3636. {
  3637. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3638. }
  3639. EditorList->Change(i, UpdatedEditor);
  3640. }
  3641. }
  3642. if (Changed)
  3643. {
  3644. WinConfiguration->EditorList = EditorList;
  3645. }
  3646. }
  3647. }
  3648. __finally
  3649. {
  3650. delete EditorList;
  3651. }
  3652. }
  3653. else
  3654. {
  3655. // "open" case
  3656. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3657. qaOK, HELP_APP_EARLY_CLOSED);
  3658. }
  3659. }
  3660. //---------------------------------------------------------------------------
  3661. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3662. {
  3663. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3664. }
  3665. //---------------------------------------------------------------------------
  3666. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3667. {
  3668. SideEnter(osRemote);
  3669. }
  3670. //---------------------------------------------------------------------------
  3671. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3672. {
  3673. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3674. SideEnter(osRemote);
  3675. }
  3676. //---------------------------------------------------------------------------
  3677. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3678. {
  3679. FCurrentSide = Side;
  3680. if (Visible)
  3681. {
  3682. UpdateControls();
  3683. }
  3684. }
  3685. //---------------------------------------------------------------------------
  3686. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3687. TStrings * FileList, bool Alternative)
  3688. {
  3689. TCustomDirView * DView = DirView(Side);
  3690. DView->SaveSelection();
  3691. DView->SaveSelectedNames();
  3692. DebugAssert(!FAlternativeDelete);
  3693. FAlternativeDelete = Alternative;
  3694. try
  3695. {
  3696. if (!IsSideLocalBrowser(Side))
  3697. {
  3698. DebugAssert(Terminal != NULL);
  3699. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3700. }
  3701. else
  3702. {
  3703. try
  3704. {
  3705. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3706. }
  3707. __finally
  3708. {
  3709. ReloadLocalDirectory();
  3710. }
  3711. }
  3712. FAlternativeDelete = false;
  3713. }
  3714. catch(...)
  3715. {
  3716. FAlternativeDelete = false;
  3717. DView->DiscardSavedSelection();
  3718. throw;
  3719. }
  3720. DView->RestoreSelection();
  3721. }
  3722. //---------------------------------------------------------------------------
  3723. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3724. {
  3725. DebugAssert(Terminal);
  3726. DebugAssert(!IsLocalBrowserMode());
  3727. RemoteDirView->SaveSelection();
  3728. RemoteDirView->SaveSelectedNames();
  3729. try
  3730. {
  3731. if (Lock)
  3732. {
  3733. Terminal->LockFiles(FileList);
  3734. }
  3735. else
  3736. {
  3737. Terminal->UnlockFiles(FileList);
  3738. }
  3739. }
  3740. catch(...)
  3741. {
  3742. RemoteDirView->DiscardSavedSelection();
  3743. throw;
  3744. }
  3745. RemoteDirView->RestoreSelection();
  3746. }
  3747. //---------------------------------------------------------------------------
  3748. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3749. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3750. bool NoConfirmation, bool Move)
  3751. {
  3752. DebugAssert(Terminal != NULL);
  3753. DebugAssert(!IsLocalBrowserMode());
  3754. // update Terminal->StateData->RemoteDirectory
  3755. UpdateTerminal(Terminal);
  3756. if (Session == NULL)
  3757. {
  3758. Session = TTerminalManager::Instance()->ActiveTerminal;
  3759. }
  3760. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3761. {
  3762. if (RemoteDriveView->DropTarget != NULL)
  3763. {
  3764. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3765. }
  3766. else if (RemoteDirView->DropTarget != NULL)
  3767. {
  3768. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3769. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3770. }
  3771. else
  3772. {
  3773. Target = RemoteDirView->Path;
  3774. }
  3775. }
  3776. else
  3777. {
  3778. Target = Session->StateData->RemoteDirectory;
  3779. }
  3780. Target = UnixIncludeTrailingBackslash(Target);
  3781. if (FileList->Count == 1)
  3782. {
  3783. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3784. }
  3785. else
  3786. {
  3787. FileMask = AnyMask;
  3788. }
  3789. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3790. bool Result = true;
  3791. if (!NoConfirmation)
  3792. {
  3793. bool Multi = (FileList->Count > 1);
  3794. if (Move)
  3795. {
  3796. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3797. }
  3798. else
  3799. {
  3800. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3801. TStrings * Directories = new TStringList;
  3802. try
  3803. {
  3804. for (int Index = 0; Index < Sessions->Count; Index++)
  3805. {
  3806. TManagedTerminal * Terminal =
  3807. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3808. Directories->Add(Terminal->StateData->RemoteDirectory);
  3809. }
  3810. TDirectRemoteCopy AllowDirectCopy;
  3811. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3812. {
  3813. DebugAssert(DirectCopy);
  3814. AllowDirectCopy = drcAllow;
  3815. }
  3816. else if (FTerminal->IsCapable[fcSecondaryShell])
  3817. {
  3818. DebugAssert(DirectCopy);
  3819. AllowDirectCopy = drcConfirmCommandSession;
  3820. }
  3821. else
  3822. {
  3823. DebugAssert(!DirectCopy);
  3824. AllowDirectCopy = drcDisallow;
  3825. }
  3826. void * ASession = Session;
  3827. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3828. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3829. Session = static_cast<TManagedTerminal *>(ASession);
  3830. }
  3831. __finally
  3832. {
  3833. delete Directories;
  3834. }
  3835. }
  3836. }
  3837. return Result;
  3838. }
  3839. //---------------------------------------------------------------------------
  3840. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3841. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3842. {
  3843. DebugAssert(!IsLocalBrowserMode());
  3844. bool DirectCopy;
  3845. UnicodeString Target, FileMask;
  3846. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3847. if (Result)
  3848. {
  3849. if (!Move && !DirectCopy)
  3850. {
  3851. Configuration->Usage->Inc("RemoteCopyTemp");
  3852. UnicodeString RootTempDir;
  3853. UnicodeString TempDir;
  3854. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3855. TStrings * TemporaryFilesList = new TStringList();
  3856. try
  3857. {
  3858. TMakeLocalFileListParams MakeFileListParam;
  3859. MakeFileListParam.FileList = TemporaryFilesList;
  3860. MakeFileListParam.FileTimes = NULL;
  3861. MakeFileListParam.IncludeDirs = true;
  3862. MakeFileListParam.Recursive = false;
  3863. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3864. TTerminalManager::Instance()->ActiveTerminal = Session;
  3865. if (TemporaryFilesList->Count > 0)
  3866. {
  3867. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3868. CopyParam.FileMask = FileMask;
  3869. DebugAssert(!FAutoOperation);
  3870. FAutoOperation = true;
  3871. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3872. }
  3873. }
  3874. __finally
  3875. {
  3876. delete TemporaryFilesList;
  3877. FAutoOperation = false;
  3878. if (!RootTempDir.IsEmpty())
  3879. {
  3880. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3881. }
  3882. }
  3883. }
  3884. else
  3885. {
  3886. RemoteDirView->SaveSelection();
  3887. RemoteDirView->SaveSelectedNames();
  3888. try
  3889. {
  3890. if (Move)
  3891. {
  3892. Configuration->Usage->Inc("RemoteMove");
  3893. Terminal->MoveFiles(FileList, Target, FileMask);
  3894. }
  3895. else
  3896. {
  3897. Configuration->Usage->Inc("RemoteCopyDirect");
  3898. DebugAssert(DirectCopy);
  3899. DebugAssert(Session == FTerminal);
  3900. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3901. FTerminal->CommandSessionOpened ||
  3902. CommandSessionFallback())
  3903. {
  3904. Terminal->CopyFiles(FileList, Target, FileMask);
  3905. }
  3906. }
  3907. }
  3908. catch(...)
  3909. {
  3910. RemoteDirView->DiscardSavedSelection();
  3911. throw;
  3912. }
  3913. RemoteDirView->RestoreSelection();
  3914. }
  3915. }
  3916. return Result;
  3917. }
  3918. //---------------------------------------------------------------------------
  3919. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3920. const UnicodeString & Path, TRemoteProperties & Properties)
  3921. {
  3922. DebugAssert(!IsLocalBrowserMode());
  3923. Properties.Valid = Properties.Valid << vpEncrypt;
  3924. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3925. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3926. }
  3927. //---------------------------------------------------------------------------
  3928. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3929. {
  3930. Side = GetSide(Side);
  3931. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3932. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3933. UnicodeString Name = LoadStr(NEW_FOLDER);
  3934. int AllowedChanges =
  3935. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3936. bool SaveSettings = false;
  3937. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3938. {
  3939. TWindowLock Lock(this);
  3940. if (!IsSideLocalBrowser(Side))
  3941. {
  3942. if (SaveSettings)
  3943. {
  3944. GUIConfiguration->NewDirectoryProperties = Properties;
  3945. }
  3946. CreateRemoteDirectory(Name, Properties);
  3947. }
  3948. else
  3949. {
  3950. DirView(Side)->CreateDirectory(Name);
  3951. }
  3952. }
  3953. }
  3954. //---------------------------------------------------------------------------
  3955. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3956. {
  3957. TWindowLock Lock(this);
  3958. DirView(Side)->ExecuteHomeDirectory();
  3959. }
  3960. //---------------------------------------------------------------------------
  3961. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3962. {
  3963. DoOpenDirectoryDialog(odBrowse, Side);
  3964. }
  3965. //---------------------------------------------------------------------------
  3966. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3967. {
  3968. UnicodeString Path = Bookmark->GetSideDirectory(Side);
  3969. bool Result = !Path.IsEmpty();
  3970. if (Result)
  3971. {
  3972. // While we might get here when the session is closed (from location profiles),
  3973. // it's not a problem as the Path setter is noop then
  3974. DirView(Side)->Path = Path;
  3975. }
  3976. return Result;
  3977. }
  3978. //---------------------------------------------------------------------------
  3979. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3980. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3981. bool & Close)
  3982. {
  3983. // terminal can be already closed (e.g. dropped connection)
  3984. if (Terminal != NULL)
  3985. {
  3986. try
  3987. {
  3988. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  3989. }
  3990. catch(...)
  3991. {
  3992. if (!Terminal->Active)
  3993. {
  3994. Close = true;
  3995. }
  3996. throw;
  3997. }
  3998. }
  3999. }
  4000. //---------------------------------------------------------------------------
  4001. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4002. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4003. bool & Close)
  4004. {
  4005. // terminal can be already closed (e.g. dropped connection)
  4006. if (Terminal != NULL)
  4007. {
  4008. Configuration->Usage->Inc(L"ChecksumCalculated");
  4009. try
  4010. {
  4011. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4012. }
  4013. catch(...)
  4014. {
  4015. if (!Terminal->Active)
  4016. {
  4017. Close = true;
  4018. }
  4019. throw;
  4020. }
  4021. }
  4022. }
  4023. //---------------------------------------------------------------------------
  4024. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4025. {
  4026. bool Result;
  4027. if (!IsSideLocalBrowser(Side))
  4028. {
  4029. TRemoteTokenList * GroupList = NULL;
  4030. TRemoteTokenList * UserList = NULL;
  4031. try
  4032. {
  4033. TRemoteProperties CurrentProperties;
  4034. if (Terminal->LoadFilesProperties(FileList))
  4035. {
  4036. RemoteDirView->Invalidate();
  4037. }
  4038. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4039. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4040. if (CapableGroupChanging || CapableOwnerChanging)
  4041. {
  4042. if (CapableGroupChanging)
  4043. {
  4044. GroupList = Terminal->Groups->Duplicate();
  4045. }
  4046. if (CapableOwnerChanging)
  4047. {
  4048. UserList = Terminal->Users->Duplicate();
  4049. }
  4050. TRemoteDirectory * Files = Terminal->Files;
  4051. int Count = Files->Count;
  4052. if (Count > 100)
  4053. {
  4054. Count = 100;
  4055. }
  4056. for (int Index = 0; Index < Count; Index++)
  4057. {
  4058. TRemoteFile * File = Files->Files[Index];
  4059. if (CapableGroupChanging)
  4060. {
  4061. GroupList->AddUnique(File->Group);
  4062. }
  4063. if (CapableOwnerChanging)
  4064. {
  4065. UserList->AddUnique(File->Owner);
  4066. }
  4067. }
  4068. // if we haven't collected tokens for all files in current directory,
  4069. // make sure we collect them at least for all selected files.
  4070. // (note that so far the files in FileList has to be from current direcotry)
  4071. if (Count < Files->Count)
  4072. {
  4073. for (int Index = 0; Index < FileList->Count; Index++)
  4074. {
  4075. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4076. if (CapableGroupChanging)
  4077. {
  4078. GroupList->AddUnique(File->Group);
  4079. }
  4080. if (CapableOwnerChanging)
  4081. {
  4082. UserList->AddUnique(File->Owner);
  4083. }
  4084. }
  4085. }
  4086. }
  4087. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4088. int Flags = 0;
  4089. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4090. if (CapableOwnerChanging) Flags |= cpOwner;
  4091. if (CapableGroupChanging) Flags |= cpGroup;
  4092. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4093. if (Terminal->IsCapable[fcCalculatingChecksum])
  4094. {
  4095. CalculateChecksumEvent = CalculateChecksum;
  4096. }
  4097. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4098. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4099. TRemoteProperties NewProperties = CurrentProperties;
  4100. Result =
  4101. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4102. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4103. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4104. CalculateSize, CalculateChecksumEvent);
  4105. if (Result)
  4106. {
  4107. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4108. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4109. }
  4110. }
  4111. __finally
  4112. {
  4113. delete GroupList;
  4114. delete UserList;
  4115. }
  4116. }
  4117. else
  4118. {
  4119. DirView(Side)->DisplayPropertiesMenu();
  4120. Result = true;
  4121. }
  4122. return Result;
  4123. }
  4124. //---------------------------------------------------------------------------
  4125. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4126. {
  4127. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4128. {
  4129. FIgnoreNextDialogChar = Key;
  4130. }
  4131. Key = 0;
  4132. }
  4133. //---------------------------------------------------------------------------
  4134. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4135. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4136. {
  4137. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4138. if (Command != NULL)
  4139. {
  4140. KeyProcessed(Key, Shift);
  4141. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4142. {
  4143. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4144. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4145. false, false, const_cast<TCustomCommandType *>(Command));
  4146. }
  4147. }
  4148. }
  4149. //---------------------------------------------------------------------------
  4150. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4151. {
  4152. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4153. {
  4154. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4155. }
  4156. if (!DirView(osCurrent)->IsEditing())
  4157. {
  4158. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4159. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4160. {
  4161. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4162. if (((Action->ShortCut == KeyShortCut) ||
  4163. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4164. AllowedAction(Action, aaShortCut))
  4165. {
  4166. // Has to be called before the action as the dialog char is already in queue.
  4167. // So when the action consumes message queue, we already need to have the
  4168. // FIgnoreNextDialogChar set
  4169. KeyProcessed(Key, Shift);
  4170. // Reset reference to previous component (when menu/toolbar was clicked).
  4171. // Needed to detect that action was invoked by keyboard shortcut
  4172. // in TNonVisualDataModule::ExplorerActionsExecute
  4173. Action->ActionComponent = NULL;
  4174. Action->Execute();
  4175. return;
  4176. }
  4177. }
  4178. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4179. {
  4180. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4181. {
  4182. KeyProcessed(Key, Shift);
  4183. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4184. return;
  4185. }
  4186. }
  4187. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4188. {
  4189. KeyProcessed(Key, Shift);
  4190. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4191. }
  4192. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4193. if (IsCustomShortCut(CustomShortCut))
  4194. {
  4195. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4196. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4197. if (WinConfiguration->SharedBookmarks != NULL)
  4198. {
  4199. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4200. if ((Bookmark != NULL) &&
  4201. OpenBookmark(FCurrentSide, Bookmark))
  4202. {
  4203. KeyProcessed(Key, Shift);
  4204. }
  4205. }
  4206. }
  4207. }
  4208. TForm::KeyDown(Key, Shift);
  4209. }
  4210. //---------------------------------------------------------------------------
  4211. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4212. {
  4213. DebugAssert(Terminal != NULL);
  4214. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4215. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4216. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4217. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4218. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4219. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4220. // expanded from ?: to avoid memory leaks
  4221. if (SecurityEnabled)
  4222. {
  4223. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4224. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4225. }
  4226. else
  4227. {
  4228. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4229. }
  4230. if (FileSystemInfo.ProtocolName.IsEmpty())
  4231. {
  4232. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4233. }
  4234. else
  4235. {
  4236. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4237. }
  4238. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4239. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4240. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4241. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4242. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4243. UnicodeString CompressionStr = CSCompressionStr;
  4244. if (CSCompressionStr != SCCompressionStr)
  4245. {
  4246. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4247. }
  4248. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4249. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4250. UpdateStatusBar();
  4251. }
  4252. //---------------------------------------------------------------------------
  4253. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4254. {
  4255. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4256. DebugAssert(SessionStatusBar != NULL);
  4257. if (!HasActiveTerminal() || (Terminal->Status < ssOpened))
  4258. {
  4259. // note: (Terminal->Status < sshReady) currently never happens here,
  4260. // so STATUS_CONNECTING is never used
  4261. SessionStatusBar->SimplePanel = true;
  4262. SessionStatusBar->SimpleText = LoadStr(
  4263. !HasActiveTerminal() ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4264. }
  4265. else
  4266. {
  4267. DebugAssert(Terminal);
  4268. SessionStatusBar->SimplePanel = false;
  4269. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4270. if (!FNote.IsEmpty())
  4271. {
  4272. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4273. }
  4274. else
  4275. {
  4276. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4277. }
  4278. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4279. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4280. }
  4281. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4282. }
  4283. //---------------------------------------------------------------------------
  4284. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4285. {
  4286. Panel->Caption = L"";
  4287. }
  4288. //---------------------------------------------------------------------------
  4289. void __fastcall TCustomScpExplorerForm::Idle()
  4290. {
  4291. if (FShowing || FStandaloneEditing)
  4292. {
  4293. FEditorManager->Check();
  4294. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4295. // that needs to know if queue view is visible (and it may be closed after queue update)
  4296. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4297. }
  4298. if (FShowing)
  4299. {
  4300. if (!NonVisualDataModule->Busy &&
  4301. // Menu is opened or drag&drop is going on
  4302. (Mouse->Capture == NULL))
  4303. {
  4304. if (FRefreshRemoteDirectory)
  4305. {
  4306. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4307. {
  4308. Terminal->RefreshDirectory();
  4309. }
  4310. FRefreshRemoteDirectory = false;
  4311. }
  4312. if (FRefreshLocalDirectory)
  4313. {
  4314. ReloadLocalDirectory();
  4315. FRefreshLocalDirectory = false;
  4316. }
  4317. if (WinConfiguration->RefreshRemotePanel)
  4318. {
  4319. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4320. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4321. {
  4322. RemoteDirView->ReloadDirectory();
  4323. }
  4324. }
  4325. }
  4326. }
  4327. if (FShowing || FStandaloneEditing)
  4328. {
  4329. if (FQueueStatusInvalidated)
  4330. {
  4331. UpdateQueueStatus(false);
  4332. }
  4333. RefreshQueueItems();
  4334. }
  4335. if (FShowing)
  4336. {
  4337. UpdateStatusBar();
  4338. }
  4339. FIgnoreNextDialogChar = 0;
  4340. }
  4341. //---------------------------------------------------------------------------
  4342. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4343. {
  4344. try
  4345. {
  4346. FUserActionTimer->Enabled = false;
  4347. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4348. {
  4349. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4350. {
  4351. FPendingQueueActionItem->ProcessUserAction();
  4352. }
  4353. }
  4354. }
  4355. __finally
  4356. {
  4357. FPendingQueueActionItem = NULL;
  4358. }
  4359. }
  4360. //---------------------------------------------------------------------------
  4361. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4362. {
  4363. if (WinConfiguration->MinimizeToTray)
  4364. {
  4365. UpdateTrayIcon();
  4366. FTrayIcon->Visible = true;
  4367. if (Visible)
  4368. {
  4369. ShowWindow(Handle, SW_HIDE);
  4370. }
  4371. }
  4372. }
  4373. //---------------------------------------------------------------------------
  4374. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4375. {
  4376. // WORKAROUND
  4377. // When restoring maximized window from minimization,
  4378. // rarely some controls do not align properly.
  4379. // Two instances seen (both for Commander):
  4380. // - When restoring, window is temporarily narrower (not maximized),
  4381. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4382. // Once maximized already, top dock shinks back, but the session PageControl,
  4383. // do not align up, leaving space between TopDock and PageControl.
  4384. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4385. for (int Index = 0; Index < ControlCount; Index++)
  4386. {
  4387. RealignControl(Controls[Index]);
  4388. }
  4389. if (FTrayIcon->Visible)
  4390. {
  4391. FTrayIcon->Visible = false;
  4392. if (Visible)
  4393. {
  4394. ShowWindow(Handle, SW_SHOW);
  4395. }
  4396. }
  4397. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4398. {
  4399. FNeedSession = false;
  4400. NonVisualDataModule->StartBusy();
  4401. try
  4402. {
  4403. NeedSession(true);
  4404. }
  4405. __finally
  4406. {
  4407. NonVisualDataModule->EndBusy();
  4408. }
  4409. }
  4410. }
  4411. //---------------------------------------------------------------------------
  4412. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4413. {
  4414. FTrayIcon->Hint = GetMainForm()->Caption;
  4415. }
  4416. //---------------------------------------------------------------------------
  4417. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4418. {
  4419. UpdateTrayIcon();
  4420. }
  4421. //---------------------------------------------------------------------------
  4422. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4423. {
  4424. // workaround
  4425. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4426. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4427. // But WM_ACTIVATEAPP message can be received even when
  4428. // the main window is minimized to the tray and internal editor window is focused
  4429. // (after another application was previously active)
  4430. if (::IsIconic(Handle))
  4431. {
  4432. if (!IsAppIconic())
  4433. {
  4434. SetAppIconic(true);
  4435. }
  4436. }
  4437. ::ApplicationRestore();
  4438. Application->BringToFront();
  4439. }
  4440. //---------------------------------------------------------------------------
  4441. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4442. {
  4443. RestoreApp();
  4444. }
  4445. //---------------------------------------------------------------------------
  4446. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4447. {
  4448. if (OpenInNewWindow())
  4449. {
  4450. ExecuteNewInstance(SessionUrl);
  4451. }
  4452. else
  4453. {
  4454. TTerminalManager::Instance()->NewSession(SessionUrl);
  4455. }
  4456. }
  4457. //---------------------------------------------------------------------------
  4458. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4459. {
  4460. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4461. StoredSessions->NewSession(SessionName, SessionData);
  4462. // modified only, explicit
  4463. StoredSessions->Save(false, true);
  4464. // encode session name because of slashes in hierarchical sessions
  4465. return EncodeUrlString(SessionName);
  4466. }
  4467. //---------------------------------------------------------------------------
  4468. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4469. {
  4470. // current working directories become defaults here, what is not right
  4471. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4472. return SaveHiddenDuplicateSession(SessionData.get());
  4473. }
  4474. //---------------------------------------------------------------------------
  4475. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4476. {
  4477. if (OpenInNewWindow())
  4478. {
  4479. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4480. }
  4481. else
  4482. {
  4483. // current working directories become defaults here, what is not right
  4484. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4485. TTerminalManager * Manager = TTerminalManager::Instance();
  4486. TManagedTerminal * ATerminal = Manager->NewManagedTerminal(SessionData.get());
  4487. // We definitelly want this
  4488. ATerminal->Disconnected = Terminal->Disconnected;
  4489. // Not sure about these two
  4490. ATerminal->Permanent = Terminal->Permanent;
  4491. ATerminal->DisconnectedTemporarily = Terminal->DisconnectedTemporarily; // maybe
  4492. Manager->ActiveTerminal = ATerminal;
  4493. }
  4494. }
  4495. //---------------------------------------------------------------------------
  4496. void __fastcall TCustomScpExplorerForm::RenameSession()
  4497. {
  4498. UnicodeString Name = Terminal->SessionData->SessionName;
  4499. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4500. {
  4501. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4502. TSessionData::ValidateName(Name);
  4503. // This is inconsistent with how color (for example) is handled.
  4504. Terminal->SessionData->Name = Name;
  4505. UpdateControls();
  4506. // Add/Remove distinguishing paths from sessions of the same name.
  4507. DoTerminalListChanged();
  4508. }
  4509. }
  4510. //---------------------------------------------------------------------------
  4511. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4512. {
  4513. DebugAssert(Queue != NULL);
  4514. bool Result = Queue->IsEmpty;
  4515. if (!Result)
  4516. {
  4517. SetFocus();
  4518. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4519. }
  4520. return Result;
  4521. }
  4522. //---------------------------------------------------------------------------
  4523. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4524. {
  4525. return CanCloseQueue(FQueue);
  4526. }
  4527. //---------------------------------------------------------------------------
  4528. void __fastcall TCustomScpExplorerForm::CloseSession()
  4529. {
  4530. if (CanCloseQueue())
  4531. {
  4532. TTerminalManager::Instance()->FreeActiveTerminal();
  4533. }
  4534. }
  4535. //---------------------------------------------------------------------------
  4536. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4537. {
  4538. if (CanCloseQueue())
  4539. {
  4540. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4541. }
  4542. }
  4543. //---------------------------------------------------------------------------
  4544. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4545. {
  4546. DetachTerminal(Terminal);
  4547. RemoteDirView->Terminal = Terminal;
  4548. UpdateRemotePathComboBox(false);
  4549. UpdateControls();
  4550. }
  4551. //---------------------------------------------------------------------------
  4552. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4553. {
  4554. if (DebugAlwaysTrue(!Terminal->Active))
  4555. {
  4556. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4557. }
  4558. }
  4559. //---------------------------------------------------------------------------
  4560. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4561. {
  4562. if (OpenInNewWindow())
  4563. {
  4564. // encode session name because of slashes in hierarchical sessions
  4565. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4566. }
  4567. else
  4568. {
  4569. TTerminalManager * Manager = TTerminalManager::Instance();
  4570. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4571. Manager->ActiveTerminal = Terminal;
  4572. }
  4573. }
  4574. //---------------------------------------------------------------------------
  4575. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4576. {
  4577. TTerminalManager * Manager = TTerminalManager::Instance();
  4578. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4579. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4580. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4581. // FirstTerminal can be null, if some of the
  4582. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4583. {
  4584. FirstTerminal->Disconnected = true;
  4585. FirstTerminal->DisconnectedTemporarily = true;
  4586. }
  4587. Manager->ActiveTerminal = FirstTerminal;
  4588. }
  4589. //---------------------------------------------------------------------------
  4590. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4591. {
  4592. if (OpenInNewWindow())
  4593. {
  4594. ExecuteNewInstance(Name);
  4595. }
  4596. else
  4597. {
  4598. DoOpenFolderOrWorkspace(Name, true);
  4599. }
  4600. }
  4601. //---------------------------------------------------------------------------
  4602. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4603. bool &CanClose)
  4604. {
  4605. // See the comment in CloseApp()
  4606. if (NonVisualDataModule->Busy)
  4607. {
  4608. CanClose = false;
  4609. }
  4610. else if (Terminal != NULL)
  4611. {
  4612. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4613. {
  4614. unsigned int Result;
  4615. TMessageParams Params(mpNeverAskAgainCheck);
  4616. UnicodeString Message;
  4617. int Answers = qaOK | qaCancel;
  4618. if (TTerminalManager::Instance()->Count > 1)
  4619. {
  4620. if (!WinConfiguration->AutoSaveWorkspace)
  4621. {
  4622. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4623. }
  4624. else
  4625. {
  4626. Message = LoadStr(CLOSE_SESSIONS);
  4627. }
  4628. }
  4629. else
  4630. {
  4631. if (!WinConfiguration->AutoSaveWorkspace)
  4632. {
  4633. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4634. }
  4635. else
  4636. {
  4637. Message = LoadStr(CLOSE_SESSION);
  4638. }
  4639. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4640. }
  4641. UnicodeString Note;
  4642. if (WinConfiguration->AutoSaveWorkspace)
  4643. {
  4644. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4645. }
  4646. else
  4647. {
  4648. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4649. Answers = qaYes | qaNo | qaCancel;
  4650. }
  4651. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4652. SetFocus();
  4653. Result = MessageDialog(Message, qtConfirmation,
  4654. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4655. if (Result == qaNeverAskAgain)
  4656. {
  4657. WinConfiguration->ConfirmClosingSession = false;
  4658. }
  4659. if (Result == qaNo)
  4660. {
  4661. CanClose = SaveWorkspace(true);
  4662. // note that the workspace will be saved redundatly again from FormClose
  4663. }
  4664. else
  4665. {
  4666. CanClose =
  4667. (Result == qaOK) ||
  4668. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4669. (Result == qaNeverAskAgain);
  4670. }
  4671. }
  4672. if (CanClose)
  4673. {
  4674. CanClose = CanCloseQueue();
  4675. }
  4676. }
  4677. if (CanClose)
  4678. {
  4679. CanClose =
  4680. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4681. FEditorManager->CloseExternalFilesWithoutProcess();
  4682. if (CanClose)
  4683. {
  4684. while (CanClose && (FLocalEditors->Count > 0))
  4685. {
  4686. int PrevCount = FLocalEditors->Count;
  4687. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4688. CanClose = (FLocalEditors->Count < PrevCount);
  4689. }
  4690. if (CanClose)
  4691. {
  4692. CanClose = FEditorManager->Empty(true);
  4693. if (!CanClose)
  4694. {
  4695. SetFocus();
  4696. CanClose =
  4697. (MessageDialog(
  4698. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4699. }
  4700. }
  4701. }
  4702. }
  4703. }
  4704. //---------------------------------------------------------------------------
  4705. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4706. {
  4707. TForm * Form = dynamic_cast<TForm *>(Sender);
  4708. DebugAssert(Form != NULL);
  4709. Form->Close();
  4710. }
  4711. //---------------------------------------------------------------------------
  4712. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4713. {
  4714. TForm * Form = dynamic_cast<TForm *>(Sender);
  4715. delete Form;
  4716. }
  4717. //---------------------------------------------------------------------------
  4718. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4719. {
  4720. while (FLocalEditors->Count > 0)
  4721. {
  4722. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4723. }
  4724. }
  4725. //---------------------------------------------------------------------------
  4726. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4727. TObject *Sender)
  4728. {
  4729. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4730. try
  4731. {
  4732. SetProperties(osRemote, FileList);
  4733. }
  4734. __finally
  4735. {
  4736. delete FileList;
  4737. }
  4738. }
  4739. //---------------------------------------------------------------------------
  4740. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4741. {
  4742. if (value)
  4743. {
  4744. if (Component == fcCustomCommandsBand)
  4745. {
  4746. UpdateCustomCommandsToolbar();
  4747. }
  4748. if (Component == fcQueueFileList)
  4749. {
  4750. DebugAssert(!QueueFileListSplitter->Visible);
  4751. AdjustQueueLayout();
  4752. UpdateQueueFileList();
  4753. }
  4754. }
  4755. }
  4756. //---------------------------------------------------------------------------
  4757. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4758. {
  4759. int MinHeightLimit =
  4760. GetStaticQueuePanelComponentsHeight() +
  4761. QueueFileListSplitter->Height +
  4762. QueueFileList->Height +
  4763. GetMinQueueViewHeight();
  4764. if (QueuePanel->ClientHeight < MinHeightLimit)
  4765. {
  4766. QueuePanel->ClientHeight = MinHeightLimit;
  4767. }
  4768. }
  4769. //---------------------------------------------------------------------------
  4770. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4771. {
  4772. TControl * Control = GetComponent(Component);
  4773. DebugAssert(Control);
  4774. bool Changed = (Control->Visible != value);
  4775. if (Changed)
  4776. {
  4777. ComponentShowing(Component, value);
  4778. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4779. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4780. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4781. if (value)
  4782. {
  4783. int RemainingHeight = Control->Parent->ClientHeight;
  4784. int RemainingWidth = Control->Parent->ClientWidth;
  4785. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4786. {
  4787. TControl * ChildControl = Control->Parent->Controls[i];
  4788. if (ChildControl->Visible)
  4789. {
  4790. switch (ChildControl->Align)
  4791. {
  4792. case alTop:
  4793. case alBottom:
  4794. RemainingHeight -= ChildControl->Height;
  4795. break;
  4796. case alLeft:
  4797. case alRight:
  4798. RemainingWidth -= ChildControl->Width;
  4799. break;
  4800. }
  4801. }
  4802. }
  4803. int Reserve = ScaleByTextHeight(this, 32);
  4804. // queue in explorer, trees in commander
  4805. if (Control->Height > RemainingHeight - Reserve)
  4806. {
  4807. Control->Height = RemainingHeight / 2;
  4808. }
  4809. if (Control->Width > RemainingWidth - Reserve)
  4810. {
  4811. Control->Width = RemainingWidth / 2;
  4812. }
  4813. }
  4814. Control->Visible = value;
  4815. if (WasFocused && Visible)
  4816. {
  4817. DirView(osCurrent)->SetFocus();
  4818. }
  4819. FixControlsPlacement();
  4820. }
  4821. }
  4822. //---------------------------------------------------------------------------
  4823. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4824. {
  4825. TControl * Control = GetComponent(Component);
  4826. if (Control == NULL)
  4827. {
  4828. return false;
  4829. }
  4830. else
  4831. {
  4832. return Control->Visible;
  4833. }
  4834. }
  4835. //---------------------------------------------------------------------------
  4836. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4837. {
  4838. bool Result;
  4839. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4840. {
  4841. Result = !IsUWP();
  4842. }
  4843. else
  4844. {
  4845. Result = true;
  4846. }
  4847. return Result;
  4848. }
  4849. //---------------------------------------------------------------------------
  4850. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4851. {
  4852. if (DirView(osOther)->ItemFocused != NULL)
  4853. {
  4854. DirView(osOther)->ItemFocused->MakeVisible(false);
  4855. }
  4856. QueueSplitter->Visible = QueuePanel->Visible;
  4857. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4858. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4859. TControl * QueueControlsOrder[] =
  4860. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4861. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4862. }
  4863. //---------------------------------------------------------------------------
  4864. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4865. {
  4866. switch (Component) {
  4867. case fcStatusBar: return RemoteStatusBar;
  4868. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4869. case fcQueueView: return QueuePanel;
  4870. case fcQueueToolbar: return QueueDock;
  4871. case fcRemoteTree: return RemoteDrivePanel;
  4872. case fcSessionsTabs: return SessionsPageControl;
  4873. case fcQueueFileList: return QueueFileList;
  4874. default: return NULL;
  4875. }
  4876. }
  4877. //---------------------------------------------------------------------------
  4878. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4879. TObject *Sender, TListColumn *Column, TPoint &Point)
  4880. {
  4881. DebugAssert(NonVisualDataModule && Column && Sender);
  4882. NonVisualDataModule->ListColumn = Column;
  4883. TPopupMenu * DirViewColumnMenu;
  4884. if (dynamic_cast<TUnixDirView *>(Sender) != NULL)
  4885. {
  4886. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4887. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4888. (Column->Index == uvName);
  4889. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4890. (Column->Index == uvSize);
  4891. }
  4892. else
  4893. {
  4894. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4895. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4896. (Column->Index == dvName);
  4897. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4898. (Column->Index == dvSize);
  4899. }
  4900. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4901. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4902. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4903. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4904. }
  4905. //---------------------------------------------------------------------------
  4906. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4907. TObject *Sender, TListItem *Item, bool &AllowExec)
  4908. {
  4909. DoDirViewExecFile(Sender, Item, AllowExec);
  4910. }
  4911. //---------------------------------------------------------------------------
  4912. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4913. TListItem * Item, bool & AllowExec)
  4914. {
  4915. DebugAssert(Sender && Item && Configuration);
  4916. DebugAssert(AllowExec);
  4917. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4918. bool Remote = (ADirView == DirView(osRemote)) && !IsSideLocalBrowser(osRemote);
  4919. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  4920. TOperationSide Side = (Remote ? osRemote : osLocal); // TODO
  4921. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4922. // on files only (not directories)
  4923. // and only when symlinks are resolved (apply to remote panel only)
  4924. if (!ADirView->ItemIsDirectory(Item) &&
  4925. (ResolvedSymlinks || FForceExecution))
  4926. {
  4927. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4928. !FForceExecution && ResolvedSymlinks)
  4929. {
  4930. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4931. {
  4932. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4933. UnlockWindow();
  4934. try
  4935. {
  4936. ExecuteFileOperation(
  4937. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4938. }
  4939. __finally
  4940. {
  4941. LockWindow();
  4942. }
  4943. AllowExec = false;
  4944. }
  4945. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4946. {
  4947. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4948. {
  4949. ExecuteFile(Side, efDefaultEditor);
  4950. AllowExec = false;
  4951. }
  4952. }
  4953. else
  4954. {
  4955. DebugFail();
  4956. }
  4957. }
  4958. // if we have not done anything special, fall back to default behavior
  4959. if (AllowExec)
  4960. {
  4961. if (Remote && !WinConfiguration->DisableOpenEdit)
  4962. {
  4963. ExecuteFile(osRemote, efShell);
  4964. AllowExec = false;
  4965. }
  4966. }
  4967. }
  4968. }
  4969. //---------------------------------------------------------------------------
  4970. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4971. {
  4972. return ((Side == osRemote) || (Side == osCurrent));
  4973. }
  4974. //---------------------------------------------------------------------------
  4975. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  4976. {
  4977. DebugFail();
  4978. }
  4979. //---------------------------------------------------------------------------
  4980. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  4981. {
  4982. DebugFail();
  4983. }
  4984. //---------------------------------------------------------------------------
  4985. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  4986. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  4987. {
  4988. TSynchronizeParamType Params;
  4989. Params.LocalDirectory = LocalDirectory;
  4990. Params.RemoteDirectory = RemoteDirectory;
  4991. int UnusedParams =
  4992. (GUIConfiguration->SynchronizeParams &
  4993. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  4994. TTerminal::spCaseSensitive));
  4995. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  4996. Params.Options = GUIConfiguration->SynchronizeOptions;
  4997. bool SaveSettings = false;
  4998. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  4999. &DoSynchronizeTooManyDirectories);
  5000. DebugAssert(FSynchronizeController == NULL);
  5001. FSynchronizeController = &Controller;
  5002. bool Result;
  5003. try
  5004. {
  5005. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5006. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5007. int Options =
  5008. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5009. DebugAssert(FOnFeedSynchronizeError == NULL);
  5010. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5011. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5012. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5013. if (Result)
  5014. {
  5015. if (SaveSettings)
  5016. {
  5017. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5018. GUIConfiguration->SynchronizeOptions = Params.Options;
  5019. }
  5020. else
  5021. {
  5022. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5023. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5024. FLAGSET(Params.Options, soSynchronize))
  5025. {
  5026. GUIConfiguration->SynchronizeOptions =
  5027. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5028. soSynchronize;
  5029. }
  5030. }
  5031. LocalDirectory = Params.LocalDirectory;
  5032. RemoteDirectory = Params.RemoteDirectory;
  5033. }
  5034. }
  5035. __finally
  5036. {
  5037. FSynchronizeController = NULL;
  5038. DebugAssert(FOnFeedSynchronizeError == NULL);
  5039. FOnFeedSynchronizeError = NULL;
  5040. }
  5041. return Result;
  5042. }
  5043. //---------------------------------------------------------------------------
  5044. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5045. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5046. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5047. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5048. TSynchronizeOptions * Options, bool Full)
  5049. {
  5050. // Keep-up-to-date mode
  5051. if (Terminal->Status == ssOpened)
  5052. {
  5053. try
  5054. {
  5055. int PParams = Params.Params;
  5056. if (!Full)
  5057. {
  5058. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5059. if (FLAGSET(Params.Options, soRecurse))
  5060. {
  5061. PParams |= TTerminal::spSubDirs;
  5062. }
  5063. }
  5064. else
  5065. {
  5066. // if keepuptodate is non-recursive,
  5067. // full sync before has to be non-recursive as well
  5068. if (FLAGCLEAR(Params.Options, soRecurse))
  5069. {
  5070. PParams |= TTerminal::spNoRecurse;
  5071. }
  5072. }
  5073. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5074. PParams, Checklist, Options);
  5075. }
  5076. catch (Exception & E)
  5077. {
  5078. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5079. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5080. {
  5081. // noop, already logged in MoreMessageDialog
  5082. }
  5083. else
  5084. {
  5085. ShowExtendedExceptionEx(Terminal, &E);
  5086. throw;
  5087. }
  5088. }
  5089. }
  5090. }
  5091. //---------------------------------------------------------------------------
  5092. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5093. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5094. const UnicodeString ErrorStr)
  5095. {
  5096. if (!Directory.IsEmpty())
  5097. {
  5098. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5099. }
  5100. else
  5101. {
  5102. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5103. }
  5104. }
  5105. //---------------------------------------------------------------------------
  5106. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5107. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5108. {
  5109. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5110. {
  5111. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5112. }
  5113. else
  5114. {
  5115. TMessageParams Params(mpNeverAskAgainCheck);
  5116. unsigned int Result = MessageDialog(
  5117. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5118. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5119. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5120. {
  5121. MaxDirectories *= 2;
  5122. if (Result == qaNeverAskAgain)
  5123. {
  5124. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5125. }
  5126. }
  5127. else
  5128. {
  5129. Abort();
  5130. }
  5131. }
  5132. }
  5133. //---------------------------------------------------------------------------
  5134. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5135. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5136. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5137. TSynchronizeOptions * Options)
  5138. {
  5139. // Keep-up-to-date mode
  5140. DebugAssert(!FAutoOperation);
  5141. void * BatchStorage;
  5142. BatchStart(BatchStorage);
  5143. FAutoOperation = true;
  5144. bool AnyOperation = false;
  5145. TDateTime StartTime = Now();
  5146. TSynchronizeChecklist * AChecklist = NULL;
  5147. try
  5148. {
  5149. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5150. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5151. {
  5152. FSynchronizeProgressForm->Start();
  5153. }
  5154. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5155. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5156. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5157. Options);
  5158. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5159. SAFE_DESTROY(FSynchronizeProgressForm);
  5160. AnyOperation = (AChecklist->CheckedCount > 0);
  5161. if (AnyOperation)
  5162. {
  5163. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5164. CreateProgressForm(&SynchronizeProgress);
  5165. try
  5166. {
  5167. Terminal->SynchronizeApply(
  5168. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5169. SynchronizeProcessedItem, NULL, NULL, NULL);
  5170. }
  5171. __finally
  5172. {
  5173. DestroyProgressForm();
  5174. }
  5175. }
  5176. }
  5177. __finally
  5178. {
  5179. if (Checklist == NULL)
  5180. {
  5181. delete AChecklist;
  5182. }
  5183. else
  5184. {
  5185. *Checklist = AChecklist;
  5186. }
  5187. FAutoOperation = false;
  5188. SAFE_DESTROY(FSynchronizeProgressForm);
  5189. BatchEnd(BatchStorage);
  5190. ReloadLocalDirectory();
  5191. if (AnyOperation)
  5192. {
  5193. OperationComplete(StartTime);
  5194. }
  5195. }
  5196. }
  5197. //---------------------------------------------------------------------------
  5198. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5199. {
  5200. // can be called from command line
  5201. return Visible &&
  5202. ((DirView(osRemote)->SelCount > 0) ||
  5203. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5204. }
  5205. //---------------------------------------------------------------------------
  5206. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5207. {
  5208. LogSynchronizeEvent(Terminal, Message);
  5209. }
  5210. //---------------------------------------------------------------------------
  5211. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5212. int Params, TSynchronizeOptions & Options)
  5213. {
  5214. DebugAssert(!IsLocalBrowserMode());
  5215. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5216. {
  5217. Options.Filter = new TStringList();
  5218. Options.Filter->CaseSensitive = false;
  5219. Options.Filter->Duplicates = Types::dupAccept;
  5220. if (DirView(osRemote)->SelCount > 0)
  5221. {
  5222. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5223. }
  5224. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5225. {
  5226. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5227. }
  5228. Options.Filter->Sort();
  5229. }
  5230. }
  5231. //---------------------------------------------------------------------------
  5232. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5233. {
  5234. TCopyParamType Defaults;
  5235. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5236. ConfigStorage->AccessMode = smRead;
  5237. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5238. {
  5239. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5240. }
  5241. ConfigStorage.reset(NULL);
  5242. std::unique_ptr<TStringList> Options(new TStringList());
  5243. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5244. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5245. UnicodeString Result;
  5246. if (Options->Count > 0)
  5247. {
  5248. Result =
  5249. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5250. }
  5251. return Result;
  5252. }
  5253. //---------------------------------------------------------------------------
  5254. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5255. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5256. {
  5257. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5258. UnicodeString AdditionalParams =
  5259. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5260. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5261. SerializeCopyParamForCommandLine(CopyParams),
  5262. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5263. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5264. ExecuteNewInstance(SessionName, AdditionalParams);
  5265. }
  5266. //---------------------------------------------------------------------------
  5267. struct TSynchronizeParams
  5268. {
  5269. UnicodeString LocalDirectory;
  5270. UnicodeString RemoteDirectory;
  5271. TSynchronizeMode Mode;
  5272. TSynchronizeChecklist * Checklist;
  5273. int Params;
  5274. TCopyParamType * CopyParam;
  5275. TDateTime CollectElapsed;
  5276. TDateTime * StartTime;
  5277. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5278. };
  5279. //---------------------------------------------------------------------------
  5280. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5281. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5282. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5283. {
  5284. DebugAssert(!FAutoOperation);
  5285. void * BatchStorage;
  5286. BatchStart(BatchStorage);
  5287. FAutoOperation = true;
  5288. TFileOperationStatistics Statistics;
  5289. TDateTime Start = Now();
  5290. try
  5291. {
  5292. Params.OnProcessedItem = OnProcessedItem;
  5293. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5294. CreateProgressForm(&SynchronizeProgress);
  5295. Terminal->SynchronizeApply(
  5296. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5297. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5298. &Statistics);
  5299. }
  5300. __finally
  5301. {
  5302. Params.OnProcessedItem = NULL;
  5303. FAutoOperation = false;
  5304. DestroyProgressForm();
  5305. BatchEnd(BatchStorage);
  5306. ReloadLocalDirectory();
  5307. }
  5308. if (WinConfiguration->SynchronizeSummary)
  5309. {
  5310. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5311. // The statistics should be 0 anyway in this case
  5312. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5313. {
  5314. Message += L"\n";
  5315. if (Statistics.FilesUploaded > 0)
  5316. {
  5317. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5318. }
  5319. if (Statistics.FilesDownloaded > 0)
  5320. {
  5321. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5322. }
  5323. if (Statistics.FilesDeletedLocal > 0)
  5324. {
  5325. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5326. }
  5327. if (Statistics.FilesDeletedRemote > 0)
  5328. {
  5329. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5330. }
  5331. }
  5332. TDateTime Elapsed = (Now() - Start);
  5333. Message +=
  5334. L"\n" +
  5335. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5336. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5337. TMessageParams Params(mpNeverAskAgainCheck);
  5338. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5339. if (Result == qaNeverAskAgain)
  5340. {
  5341. WinConfiguration->SynchronizeSummary = false;
  5342. }
  5343. }
  5344. }
  5345. //---------------------------------------------------------------------------
  5346. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5347. {
  5348. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5349. {
  5350. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5351. }
  5352. // Not set in keep-up-to-date mode - Synchronize() method
  5353. if (Token != NULL)
  5354. {
  5355. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5356. if (Params.OnProcessedItem != NULL)
  5357. {
  5358. Params.OnProcessedItem(NULL, ChecklistItem);
  5359. }
  5360. }
  5361. }
  5362. //---------------------------------------------------------------------------
  5363. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5364. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5365. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5366. {
  5367. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5368. *Params.StartTime = Now();
  5369. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5370. }
  5371. //---------------------------------------------------------------------------
  5372. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5373. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5374. {
  5375. // terminal can be already closed (e.g. dropped connection)
  5376. if (Terminal != NULL)
  5377. {
  5378. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5379. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5380. }
  5381. }
  5382. //---------------------------------------------------------------------------
  5383. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5384. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5385. {
  5386. DebugAssert(!IsLocalBrowserMode());
  5387. TAutoBatch AutoBatch(this);
  5388. TAutoFlag AutoOperationFlag(FAutoOperation);
  5389. if (Side == osRemote)
  5390. {
  5391. std::unique_ptr<TStrings> FileList(new TStringList());
  5392. FileList->AddObject(FileName, RemoteFile);
  5393. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5394. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5395. RemoteDirView->SaveSelection();
  5396. RemoteDirView->SaveSelectedNames();
  5397. try
  5398. {
  5399. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5400. }
  5401. catch(...)
  5402. {
  5403. RemoteDirView->DiscardSavedSelection();
  5404. throw;
  5405. }
  5406. RemoteDirView->RestoreSelection();
  5407. }
  5408. else if (DebugAlwaysTrue(Side == osLocal))
  5409. {
  5410. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5411. {
  5412. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5413. }
  5414. UnicodeString Directory = ExtractFileDir(FileName);
  5415. ReloadLocalDirectory(Directory);
  5416. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5417. if (!SamePaths(Directory, NewDirectory))
  5418. {
  5419. ReloadLocalDirectory(NewDirectory);
  5420. }
  5421. }
  5422. }
  5423. //---------------------------------------------------------------------------
  5424. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5425. {
  5426. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5427. if (Side == osLocal)
  5428. {
  5429. if (Action == TSynchronizeChecklist::saDownloadNew)
  5430. {
  5431. OpenFolderInExplorer(LocalPath);
  5432. }
  5433. else
  5434. {
  5435. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5436. }
  5437. }
  5438. else if (DebugAlwaysTrue(Side == osRemote))
  5439. {
  5440. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5441. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5442. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5443. if (!LocalPath.IsEmpty())
  5444. {
  5445. SessionData->LocalDirectory = LocalPath;
  5446. }
  5447. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5448. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5449. }
  5450. }
  5451. //---------------------------------------------------------------------------
  5452. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5453. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5454. const TCopyParamType * CopyParams)
  5455. {
  5456. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5457. UnicodeString AdditionalParams =
  5458. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5459. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5460. SerializeCopyParamForCommandLine(CopyParams),
  5461. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5462. LocalDirectory, RemoteDirectory, Mode, Params));
  5463. ExecuteNewInstance(SessionName, AdditionalParams);
  5464. }
  5465. //---------------------------------------------------------------------------
  5466. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5467. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5468. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5469. {
  5470. int Result;
  5471. bool SaveSettings = false;
  5472. int Options =
  5473. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5474. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5475. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5476. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5477. bool Continue =
  5478. (UseDefaults == 0) ||
  5479. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5480. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5481. if (Continue)
  5482. {
  5483. Configuration->Usage->Inc(L"Synchronizations");
  5484. UpdateCopyParamCounters(CopyParam);
  5485. TSynchronizeOptions SynchronizeOptions;
  5486. GetSynchronizeOptions(Params, SynchronizeOptions);
  5487. if (SaveSettings)
  5488. {
  5489. GUIConfiguration->SynchronizeParams = Params;
  5490. }
  5491. else
  5492. {
  5493. SaveMode = false;
  5494. }
  5495. TDateTime StartTime = Now();
  5496. TSynchronizeChecklist * Checklist = NULL;
  5497. try
  5498. {
  5499. DebugAssert(!FAutoOperation);
  5500. FAutoOperation = true;
  5501. try
  5502. {
  5503. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5504. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5505. int Files = -1;
  5506. if (DataList->Count >= 1)
  5507. {
  5508. Files = StrToIntDef(DataList->Strings[0], Files);
  5509. }
  5510. else
  5511. {
  5512. DataList->Add(UnicodeString());
  5513. }
  5514. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5515. FSynchronizeProgressForm->Start();
  5516. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5517. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5518. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5519. &SynchronizeOptions);
  5520. if (Terminal->SessionData->CacheDirectories)
  5521. {
  5522. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5523. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5524. }
  5525. }
  5526. __finally
  5527. {
  5528. FAutoOperation = false;
  5529. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5530. SAFE_DESTROY(FSynchronizeProgressForm);
  5531. }
  5532. TSynchronizeParams SynchronizeParams;
  5533. SynchronizeParams.LocalDirectory = LocalDirectory;
  5534. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5535. SynchronizeParams.Mode = Mode;
  5536. SynchronizeParams.CopyParam = &CopyParam;
  5537. SynchronizeParams.Params = Params;
  5538. SynchronizeParams.Checklist = Checklist;
  5539. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5540. SynchronizeParams.StartTime = &StartTime;
  5541. SynchronizeParams.OnProcessedItem = NULL;
  5542. Result = Checklist->Count;
  5543. if (Checklist->Count > 0)
  5544. {
  5545. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5546. {
  5547. if (!DoSynchronizeChecklistDialog(
  5548. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5549. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5550. {
  5551. Result = -1;
  5552. }
  5553. }
  5554. else
  5555. {
  5556. FullSynchronize(SynchronizeParams, NULL, NULL);
  5557. }
  5558. }
  5559. else
  5560. {
  5561. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5562. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5563. }
  5564. }
  5565. __finally
  5566. {
  5567. delete Checklist;
  5568. }
  5569. OperationComplete(StartTime);
  5570. }
  5571. else
  5572. {
  5573. Result = -1;
  5574. }
  5575. return Result;
  5576. }
  5577. //---------------------------------------------------------------------------
  5578. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5579. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5580. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5581. {
  5582. if (Collect)
  5583. {
  5584. DebugAssert(FSynchronizeProgressForm != NULL);
  5585. if (!FSynchronizeProgressForm->Started)
  5586. {
  5587. FSynchronizeProgressForm->Start();
  5588. }
  5589. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5590. SetTaskbarListProgressValue(CompareProgress);
  5591. }
  5592. else
  5593. {
  5594. DebugAssert(FSynchronizeProgressForm == NULL);
  5595. DebugAssert(FProgressForm != NULL);
  5596. }
  5597. }
  5598. //---------------------------------------------------------------------------
  5599. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5600. {
  5601. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5602. TRemoteFile * File = NULL;
  5603. Terminal->ReadFile(FullFileName, File);
  5604. if (File != NULL)
  5605. {
  5606. std::unique_ptr<TRemoteFile> FileOwner(File);
  5607. TAutoFlag Flag(FStandaloneEditing);
  5608. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5609. Application->ShowMainForm = false;
  5610. Application->Run();
  5611. }
  5612. }
  5613. //---------------------------------------------------------------------------
  5614. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5615. {
  5616. DebugFail();
  5617. }
  5618. //---------------------------------------------------------------------------
  5619. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5620. {
  5621. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5622. SessionData->Assign(Terminal->SessionData);
  5623. UpdateSessionData(SessionData.get());
  5624. Terminal->UpdateSessionCredentials(SessionData.get());
  5625. if (!Terminal->SessionData->HasSessionName())
  5626. {
  5627. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5628. // once IsWorkspace is cleared
  5629. SessionData->Name = UnicodeString();
  5630. SessionData->IsWorkspace = false;
  5631. }
  5632. return SessionData.release();
  5633. }
  5634. //---------------------------------------------------------------------------
  5635. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5636. {
  5637. TSessionData * SessionData = CloneCurrentSessionData();
  5638. try
  5639. {
  5640. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5641. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5642. }
  5643. __finally
  5644. {
  5645. delete SessionData;
  5646. }
  5647. }
  5648. //---------------------------------------------------------------------------
  5649. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5650. {
  5651. TTerminalManager * Manager = TTerminalManager::Instance();
  5652. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5653. if (DebugAlwaysTrue(Terminal != NULL))
  5654. {
  5655. // Update (Managed)Terminal->StateData
  5656. UpdateTerminal(Terminal);
  5657. }
  5658. Manager->SaveWorkspace(DataList.get());
  5659. return DataList.release();
  5660. }
  5661. //---------------------------------------------------------------------------
  5662. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5663. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5664. {
  5665. WinConfiguration->LastWorkspace = Name;
  5666. if (!SavePasswords)
  5667. {
  5668. for (int Index = 0; Index < DataList->Count; Index++)
  5669. {
  5670. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5671. if (SessionData->Link.IsEmpty())
  5672. {
  5673. SessionData->ClearSessionPasswords();
  5674. }
  5675. }
  5676. }
  5677. StoredSessions->NewWorkspace(Name, DataList);
  5678. // modified only
  5679. StoredSessions->Save(false, Explicit);
  5680. }
  5681. //---------------------------------------------------------------------------
  5682. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5683. {
  5684. return
  5685. DefaultStr(WinConfiguration->LastWorkspace,
  5686. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5687. }
  5688. //---------------------------------------------------------------------------
  5689. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5690. {
  5691. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5692. bool AnyNonStoredSessionWithPassword = false;
  5693. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5694. bool AllNonStoredSessionsAnonymous = true;
  5695. TTerminalManager * Manager = TTerminalManager::Instance();
  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. if (SessionData->HasAnySessionPassword())
  5702. {
  5703. AnyNonStoredSessionWithPassword = true;
  5704. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5705. {
  5706. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5707. }
  5708. }
  5709. if (!SameText(SessionData->UserName, AnonymousUserName))
  5710. {
  5711. AllNonStoredSessionsAnonymous = false;
  5712. }
  5713. }
  5714. }
  5715. bool SavePasswords;
  5716. bool * PSavePasswords;
  5717. bool NotRecommendedSavingPasswords =
  5718. !CustomWinConfiguration->UseMasterPassword &&
  5719. !AllNonStoredSessionsAnonymous;
  5720. if (Configuration->DisablePasswordStoring ||
  5721. !AnyNonStoredSessionWithPassword)
  5722. {
  5723. PSavePasswords = NULL;
  5724. SavePasswords = false;
  5725. }
  5726. else
  5727. {
  5728. PSavePasswords = &SavePasswords;
  5729. SavePasswords =
  5730. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5731. !NotRecommendedSavingPasswords;
  5732. }
  5733. UnicodeString Name = WorkspaceName();
  5734. bool CreateShortcut = false;
  5735. bool Result =
  5736. DoSaveWorkspaceDialog(
  5737. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5738. EnableAutoSave);
  5739. if (Result)
  5740. {
  5741. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5742. if (CreateShortcut)
  5743. {
  5744. TOperationVisualizer Visualizer;
  5745. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5746. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5747. }
  5748. if (EnableAutoSave)
  5749. {
  5750. WinConfiguration->AutoSaveWorkspace = true;
  5751. WinConfiguration->AutoWorkspace = Name;
  5752. if (PSavePasswords != NULL)
  5753. {
  5754. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5755. }
  5756. }
  5757. }
  5758. return Result;
  5759. }
  5760. //---------------------------------------------------------------------------
  5761. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5762. {
  5763. DebugAssert(!IsLocalBrowserMode());
  5764. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5765. if (WinConfiguration->PreservePanelState)
  5766. {
  5767. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5768. }
  5769. UpdateSessionData(Terminal->StateData);
  5770. }
  5771. //---------------------------------------------------------------------------
  5772. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5773. {
  5774. // Keep in sync with TSessionData::CopyStateData
  5775. DebugAssert(!IsLocalBrowserMode());
  5776. DebugAssert(Data != NULL);
  5777. // This is inconsistent with how color (for example) is handled.
  5778. Data->Name = Terminal->SessionData->Name;
  5779. // cannot use RemoteDirView->Path, because it is empty if connection
  5780. // was already closed
  5781. // also only peek, we may not be connected at all atm
  5782. // so make sure we do not try retrieving current directory from the server
  5783. // (particularly with FTP)
  5784. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5785. if (!ACurrentDirectory.IsEmpty())
  5786. {
  5787. Data->RemoteDirectory = ACurrentDirectory;
  5788. }
  5789. Data->Color = SessionColor;
  5790. }
  5791. //---------------------------------------------------------------------------
  5792. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5793. {
  5794. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5795. DebugAssert(Toolbar != NULL);
  5796. for (int i = 0; i < Toolbar->Items->Count; i++)
  5797. {
  5798. TTBXCustomDropDownItem * DropDownItem;
  5799. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5800. if (DropDownItem != NULL)
  5801. {
  5802. ToolbarItemResize(DropDownItem,
  5803. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5804. Toolbar->NonClientWidth);
  5805. break;
  5806. }
  5807. }
  5808. }
  5809. //---------------------------------------------------------------------------
  5810. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5811. {
  5812. Item->EditWidth = Width;
  5813. }
  5814. //---------------------------------------------------------------------------
  5815. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5816. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5817. {
  5818. for (int i = 0; i < Toolbar->Items->Count; i++)
  5819. {
  5820. TTBXCustomDropDownItem * DropDownItem;
  5821. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5822. if (DropDownItem != NULL)
  5823. {
  5824. ASize.x -= DropDownItem->EditWidth;
  5825. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5826. }
  5827. }
  5828. }
  5829. //---------------------------------------------------------------------------
  5830. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5831. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5832. {
  5833. if (WinConfiguration->DDWarnLackOfTempSpace)
  5834. {
  5835. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5836. if (!ADrive.IsEmpty())
  5837. {
  5838. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5839. DebugAssert(RequiredSpace >= 0);
  5840. __int64 RequiredWithReserve;
  5841. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5842. if (FreeSpace < RequiredWithReserve)
  5843. {
  5844. unsigned int Result;
  5845. TMessageParams Params(mpNeverAskAgainCheck);
  5846. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5847. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5848. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5849. if (Result == qaNeverAskAgain)
  5850. {
  5851. WinConfiguration->DDWarnLackOfTempSpace = false;
  5852. }
  5853. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5854. }
  5855. }
  5856. }
  5857. }
  5858. //---------------------------------------------------------------------------
  5859. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5860. {
  5861. DoOpenDirectoryDialog(odAddBookmark, Side);
  5862. }
  5863. //---------------------------------------------------------------------------
  5864. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5865. {
  5866. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5867. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5868. try
  5869. {
  5870. TCustomDirView * DView = DirView(Side);
  5871. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5872. {
  5873. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5874. }
  5875. }
  5876. catch (...)
  5877. {
  5878. delete VisitedDirectories;
  5879. throw;
  5880. }
  5881. return VisitedDirectories;
  5882. }
  5883. //---------------------------------------------------------------------------
  5884. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5885. TOpenDirectoryMode Mode, TOperationSide Side)
  5886. {
  5887. bool Continue = true;
  5888. if (Mode == odAddBookmark)
  5889. {
  5890. TMessageParams Params(mpNeverAskAgainCheck);
  5891. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5892. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5893. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5894. unsigned int Answer =
  5895. MessageDialog(Message,
  5896. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5897. if (Answer == qaNeverAskAgain)
  5898. {
  5899. Continue = true;
  5900. WinConfiguration->UseSharedBookmarks = true;
  5901. }
  5902. else if (Answer == qaOK)
  5903. {
  5904. Continue = true;
  5905. WinConfiguration->UseSharedBookmarks = false;
  5906. }
  5907. else
  5908. {
  5909. Continue = false;
  5910. }
  5911. }
  5912. if (Continue)
  5913. {
  5914. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5915. try
  5916. {
  5917. UnicodeString Name = DirView(Side)->PathName;
  5918. bool Repeat;
  5919. do
  5920. {
  5921. Repeat = false;
  5922. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5923. // do not allow switching to location profiles,
  5924. // if we are not connected
  5925. HasDirView[osLocal] && (Terminal != NULL)))
  5926. {
  5927. TWindowLock Lock(this);
  5928. if (!TryOpenDirectory(Side, Name))
  5929. {
  5930. Repeat = true;
  5931. Mode = odBrowse;
  5932. }
  5933. }
  5934. }
  5935. while (Repeat);
  5936. }
  5937. __finally
  5938. {
  5939. delete VisitedDirectories;
  5940. }
  5941. }
  5942. }
  5943. //---------------------------------------------------------------------------
  5944. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5945. {
  5946. DebugAssert(!FTerminal->CommandSessionOpened);
  5947. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5948. }
  5949. //---------------------------------------------------------------------------
  5950. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5951. {
  5952. bool Result = FTerminal->IsCapable[Capability] ||
  5953. FTerminal->CommandSessionOpened;
  5954. if (!Result)
  5955. {
  5956. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5957. if (!GUIConfiguration->ConfirmCommandSession)
  5958. {
  5959. Result = true;
  5960. }
  5961. else
  5962. {
  5963. TMessageParams Params(mpNeverAskAgainCheck);
  5964. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5965. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5966. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5967. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5968. if (Answer == qaNeverAskAgain)
  5969. {
  5970. GUIConfiguration->ConfirmCommandSession = false;
  5971. Result = true;
  5972. }
  5973. else if (Answer == qaOK)
  5974. {
  5975. Result = true;
  5976. }
  5977. }
  5978. if (Result)
  5979. {
  5980. Result = CommandSessionFallback();
  5981. }
  5982. }
  5983. return Result;
  5984. }
  5985. //---------------------------------------------------------------------------
  5986. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  5987. {
  5988. if (EnsureCommandSessionFallback(fcAnyCommand))
  5989. {
  5990. DoConsoleDialog(Terminal, Command);
  5991. }
  5992. }
  5993. //---------------------------------------------------------------------------
  5994. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  5995. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  5996. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  5997. {
  5998. if (!IsSideLocalBrowser(osRemote) &&
  5999. IsFileControl(DropSourceControl, osRemote) &&
  6000. (FDDExtMapFile != NULL))
  6001. {
  6002. Accept = true;
  6003. }
  6004. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6005. DebugAssert(FDDTargetControl != NULL);
  6006. }
  6007. //---------------------------------------------------------------------------
  6008. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6009. _di_IDataObject DataObj, int KeyState,
  6010. const TPoint & Point, int & Effect, bool & Accept)
  6011. {
  6012. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6013. }
  6014. //---------------------------------------------------------------------------
  6015. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6016. _di_IDataObject DataObj, int KeyState,
  6017. const TPoint & Point, int & Effect, bool & Accept)
  6018. {
  6019. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6020. }
  6021. //---------------------------------------------------------------------------
  6022. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6023. TObject * Sender)
  6024. {
  6025. DebugUsedParam(Sender);
  6026. DebugAssert(FDDTargetControl == Sender);
  6027. FDDTargetControl = NULL;
  6028. }
  6029. //---------------------------------------------------------------------------
  6030. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6031. {
  6032. FileControlDDDragLeave(SessionsPageControl);
  6033. }
  6034. //---------------------------------------------------------------------------
  6035. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6036. {
  6037. FileControlDDDragLeave(QueueView3);
  6038. }
  6039. //---------------------------------------------------------------------------
  6040. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6041. {
  6042. DebugAssert(!IsSideLocalBrowser(Side));
  6043. DebugUsedParam(Side);
  6044. bool Edit = false;
  6045. TRemoteFile * File = NULL;
  6046. UnicodeString FileName;
  6047. UnicodeString PointTo;
  6048. bool SymbolicLink = true;
  6049. if (RemoteDirView->ItemFocused)
  6050. {
  6051. DebugAssert(RemoteDirView->ItemFocused->Data);
  6052. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6053. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6054. if (Edit)
  6055. {
  6056. FileName = File->FileName;
  6057. PointTo = File->LinkTo;
  6058. }
  6059. else
  6060. {
  6061. PointTo = File->FileName;
  6062. }
  6063. }
  6064. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6065. Terminal->IsCapable[fcHardLink]))
  6066. {
  6067. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6068. if (Edit)
  6069. {
  6070. DebugAssert(File->FileName == FileName);
  6071. int Params = dfNoRecursive;
  6072. Terminal->ExceptionOnFail = true;
  6073. try
  6074. {
  6075. Terminal->DeleteFile(L"", File, &Params);
  6076. }
  6077. __finally
  6078. {
  6079. Terminal->ExceptionOnFail = false;
  6080. }
  6081. }
  6082. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6083. }
  6084. }
  6085. //---------------------------------------------------------------------------
  6086. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6087. {
  6088. return
  6089. (IsSideLocalBrowser(Side) ||
  6090. (HasActiveTerminal() &&
  6091. Terminal->ResolvingSymlinks &&
  6092. Terminal->IsCapable[fcSymbolicLink]));
  6093. }
  6094. //---------------------------------------------------------------------------
  6095. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6096. {
  6097. return
  6098. !IsSideLocalBrowser(FCurrentSide) &&
  6099. (RemoteDirView->ItemFocused != NULL) &&
  6100. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6101. Terminal->SessionData->ResolveSymlinks;
  6102. }
  6103. //---------------------------------------------------------------------------
  6104. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6105. {
  6106. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6107. FForceExecution = true;
  6108. try
  6109. {
  6110. DirView(osCurrent)->ExecuteCurrentFile();
  6111. }
  6112. __finally
  6113. {
  6114. FForceExecution = false;
  6115. }
  6116. }
  6117. //---------------------------------------------------------------------------
  6118. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6119. {
  6120. TEditorData ExternalEditor;
  6121. ExternalEditor.Editor = edExternal;
  6122. bool Remember = false;
  6123. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6124. {
  6125. if (Remember)
  6126. {
  6127. TEditorList * EditorList = new TEditorList;
  6128. try
  6129. {
  6130. *EditorList = *WinConfiguration->EditorList;
  6131. bool Found = false;
  6132. int i = 0;
  6133. while (!Found && (i < EditorList->Count))
  6134. {
  6135. const TEditorPreferences * Editor = EditorList->Editors[i];
  6136. if ((Editor->Data->Editor == edExternal) &&
  6137. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6138. {
  6139. Found = true;
  6140. }
  6141. i++;
  6142. }
  6143. if (!Found)
  6144. {
  6145. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6146. WinConfiguration->EditorList = EditorList;
  6147. }
  6148. }
  6149. __finally
  6150. {
  6151. delete EditorList;
  6152. }
  6153. }
  6154. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6155. }
  6156. }
  6157. //---------------------------------------------------------------------------
  6158. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6159. {
  6160. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6161. if (FFileFindTerminal == ATerminal)
  6162. {
  6163. FFileFindTerminal = NULL;
  6164. HideFileFindDialog();
  6165. }
  6166. if (FClipboardTerminal == ATerminal)
  6167. {
  6168. ClipboardClear(); // implies ClipboardStop
  6169. }
  6170. }
  6171. //---------------------------------------------------------------------------
  6172. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6173. {
  6174. DetachTerminal(Sender);
  6175. }
  6176. //---------------------------------------------------------------------------
  6177. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6178. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6179. {
  6180. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6181. DebugAssert(Terminal != NULL);
  6182. if (Data->Terminal == Terminal)
  6183. {
  6184. Data->Terminal = NULL;
  6185. }
  6186. }
  6187. //---------------------------------------------------------------------------
  6188. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6189. {
  6190. UpdateControls();
  6191. SessionColor = TColor(0);
  6192. UpdateRemotePathComboBox(false);
  6193. NeedSession(false);
  6194. }
  6195. //---------------------------------------------------------------------------
  6196. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6197. {
  6198. try
  6199. {
  6200. // Cache, as the login dialog can change its value
  6201. // See also DoShow. Also see TTerminalManager::NewSession.
  6202. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6203. try
  6204. {
  6205. if (ShowLogin)
  6206. {
  6207. bool ReloadSessions = !Startup;
  6208. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this);
  6209. }
  6210. else if (Startup && WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6211. // This detects if workspace was saved the last time the main widow was closed
  6212. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6213. {
  6214. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6215. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6216. }
  6217. }
  6218. __finally
  6219. {
  6220. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6221. // (so there was no chance for the user to open any session yet)
  6222. if ((ShowLogin || !Startup) &&
  6223. !WinConfiguration->KeepOpenWhenNoSession &&
  6224. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6225. {
  6226. TerminateApplication();
  6227. }
  6228. }
  6229. }
  6230. catch (EAbort &)
  6231. {
  6232. // swallow
  6233. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6234. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6235. }
  6236. }
  6237. //---------------------------------------------------------------------------
  6238. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6239. {
  6240. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6241. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6242. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6243. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6244. try
  6245. {
  6246. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6247. // Clear the design time unthemed tab
  6248. ((SessionsPageControl->PageCount > 0) &&
  6249. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6250. {
  6251. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6252. }
  6253. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6254. {
  6255. TThemeTabSheet * TabSheet;
  6256. if (Index >= SessionsPageControl->PageCount)
  6257. {
  6258. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6259. TabSheet->PageControl = SessionsPageControl;
  6260. }
  6261. else
  6262. {
  6263. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6264. }
  6265. bool IsSessionTab = (Index < TerminalList->Count);
  6266. if (IsSessionTab)
  6267. {
  6268. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6269. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6270. UpdateSessionTab(TabSheet);
  6271. }
  6272. else
  6273. {
  6274. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6275. TabSheet->Tag = 0; // not really needed
  6276. TabSheet->Shadowed = false;
  6277. // 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)
  6278. UpdateNewSessionTab();
  6279. }
  6280. TabSheet->ShowCloseButton = IsSessionTab;
  6281. }
  6282. }
  6283. __finally
  6284. {
  6285. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6286. }
  6287. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6288. }
  6289. //---------------------------------------------------------------------------
  6290. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6291. {
  6292. DoTerminalListChanged();
  6293. }
  6294. //---------------------------------------------------------------------------
  6295. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6296. {
  6297. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6298. DebugAssert(TabSheet->ImageIndex == 0);
  6299. TabSheet->Caption =
  6300. WinConfiguration->SelectiveToolbarText ?
  6301. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6302. UnicodeString();
  6303. }
  6304. //---------------------------------------------------------------------------
  6305. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6306. {
  6307. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6308. }
  6309. //---------------------------------------------------------------------------
  6310. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6311. {
  6312. if (DebugAlwaysTrue(TabSheet != NULL))
  6313. {
  6314. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6315. if (DebugAlwaysTrue(ATerminal != NULL))
  6316. {
  6317. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6318. TabSheet->ImageIndex = AddSessionColor(Color);
  6319. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6320. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6321. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6322. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6323. {
  6324. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6325. }
  6326. }
  6327. }
  6328. }
  6329. //---------------------------------------------------------------------------
  6330. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6331. {
  6332. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6333. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6334. bool Result = (Terminal != NULL);
  6335. if (Result)
  6336. {
  6337. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6338. }
  6339. else
  6340. {
  6341. try
  6342. {
  6343. NewSession();
  6344. }
  6345. __finally
  6346. {
  6347. DoTerminalListChanged();
  6348. }
  6349. FSessionsPageControlNewSessionTime = Now();
  6350. }
  6351. return Result;
  6352. }
  6353. //---------------------------------------------------------------------------
  6354. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6355. {
  6356. SessionTabSwitched();
  6357. }
  6358. //---------------------------------------------------------------------------
  6359. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6360. {
  6361. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6362. DebugAssert(TransferList != NULL);
  6363. UnicodeString Name;
  6364. if (TransferList->ItemIndex <= 0)
  6365. {
  6366. Name = L"";
  6367. }
  6368. else
  6369. {
  6370. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6371. }
  6372. if (FCopyParamAutoSelected.IsEmpty())
  6373. {
  6374. // if previous preset was not autoselected, make new preset the "default"
  6375. FCopyParamDefault = Name;
  6376. }
  6377. GUIConfiguration->CopyParamCurrent = Name;
  6378. }
  6379. //---------------------------------------------------------------------------
  6380. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6381. {
  6382. // sanity check
  6383. bool ExistingPreset =
  6384. (FTransferListHoverIndex >= 0) &&
  6385. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6386. DebugAssert(ExistingPreset);
  6387. if (ExistingPreset)
  6388. {
  6389. HDC DC = GetDC(0);
  6390. TCanvas * Canvas = new TCanvas();
  6391. try
  6392. {
  6393. Canvas->Handle = DC;
  6394. Canvas->Font = GetToolbarFont(this);
  6395. UnicodeString Name;
  6396. if (FTransferListHoverIndex == 0)
  6397. {
  6398. Name = L"";
  6399. }
  6400. else
  6401. {
  6402. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6403. }
  6404. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6405. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6406. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6407. static_cast<TObject*>(GetComponent(fcTransferList)));
  6408. UnicodeString InfoStr =
  6409. GUIConfiguration->CopyParamPreset[Name].
  6410. GetInfoStr(L"; ",
  6411. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6412. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6413. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6414. {
  6415. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6416. {
  6417. InfoStr.SetLength(InfoStr.Length() - 1);
  6418. }
  6419. InfoStr += Ellipsis;
  6420. }
  6421. // UpdateCaption does not cause invalidation of whole submenu, while
  6422. // setting Caption property does.
  6423. // also it probably does not resize the label, even if necessary
  6424. // (we do not want that anyway)
  6425. TransferLabel->UpdateCaption(InfoStr);
  6426. }
  6427. __finally
  6428. {
  6429. Canvas->Handle = NULL;
  6430. ReleaseDC(0, DC);
  6431. delete Canvas;
  6432. }
  6433. }
  6434. }
  6435. //---------------------------------------------------------------------------
  6436. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6437. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6438. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6439. {
  6440. if (FTransferListHoverIndex != AHoverIndex)
  6441. {
  6442. FTransferListHoverIndex = AHoverIndex;
  6443. UpdateTransferLabel();
  6444. }
  6445. }
  6446. //---------------------------------------------------------------------------
  6447. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6448. {
  6449. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6450. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6451. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6452. {
  6453. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6454. {
  6455. if (!NonVisualDataModule->Busy)
  6456. {
  6457. OpenDirectory(GetSide(osCurrent));
  6458. }
  6459. Message.Result = 1;
  6460. }
  6461. else
  6462. {
  6463. TForm::Dispatch(&Message);
  6464. }
  6465. }
  6466. else
  6467. {
  6468. TForm::Dispatch(&Message);
  6469. }
  6470. }
  6471. //---------------------------------------------------------------------------
  6472. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6473. {
  6474. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6475. if ((FIgnoreNextDialogChar != 0) &&
  6476. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6477. {
  6478. Message.Result = 1;
  6479. }
  6480. else
  6481. {
  6482. TForm::Dispatch(&Message);
  6483. }
  6484. FIgnoreNextDialogChar = 0;
  6485. }
  6486. //---------------------------------------------------------------------------
  6487. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6488. {
  6489. // The four low-order bits are used internally by Windows
  6490. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6491. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6492. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6493. // 61730 - restore thru double click - undocumented
  6494. // 61490 - maximize thru double click - undocumented
  6495. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6496. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6497. {
  6498. SysResizing(Cmd);
  6499. }
  6500. TForm::Dispatch(&Message);
  6501. }
  6502. //---------------------------------------------------------------------------
  6503. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6504. {
  6505. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6506. // Also there no point returning TRUE as we are not able to
  6507. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6508. // Hence the process termination might be safer :)
  6509. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6510. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6511. {
  6512. Message.Result = FALSE;
  6513. }
  6514. else
  6515. {
  6516. Message.Result = TRUE;
  6517. }
  6518. // Do not call default handling as that triggers OnCloseQuery,
  6519. // where our implementation will popup confirmation dialogs, what we do not want,
  6520. // as per Vista guidelines:
  6521. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6522. }
  6523. //---------------------------------------------------------------------------
  6524. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6525. {
  6526. if (Message.EndSession && IsApplicationMinimized())
  6527. {
  6528. // WORKAROUND
  6529. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6530. // when it receives WM_ENDSESSION,
  6531. // but that sometimes (particularly when application is minimized) cause crashes.
  6532. // Crash popups message that blocks log off.
  6533. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6534. // so we call ExitProcess() immediately, not even trying to cleanup.
  6535. // It still causes beep, so there's likely some popup, but it does not block
  6536. // log off.
  6537. ExitProcess(0);
  6538. }
  6539. TForm::Dispatch(&Message);
  6540. }
  6541. #ifdef _DEBUG
  6542. //---------------------------------------------------------------------------
  6543. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6544. {
  6545. TForm::Dispatch(&Message);
  6546. }
  6547. #endif
  6548. //---------------------------------------------------------------------------
  6549. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6550. {
  6551. }
  6552. //---------------------------------------------------------------------------
  6553. void __fastcall TCustomScpExplorerForm::DoShow()
  6554. {
  6555. // only now are the controls resized finally, so the size constraints
  6556. // will not conflict with possibly very small window size
  6557. RestoreFormParams();
  6558. // This indicates that the form was rescaled after parameters were loaded and
  6559. // as most probably the parameters were actually saved with the current form scaling
  6560. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6561. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6562. // and no rounding problems will occur.
  6563. // See also RestoreForm.
  6564. // (we should be safe to call RestoreParams unconditionally)
  6565. if (PixelsPerInch != Screen->PixelsPerInch)
  6566. {
  6567. RestoreParams();
  6568. }
  6569. FixControlsPlacement();
  6570. if (Position == poDefaultPosOnly)
  6571. {
  6572. CutFormToDesktop(this);
  6573. }
  6574. TForm::DoShow();
  6575. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6576. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6577. if (Terminal == NULL)
  6578. {
  6579. StartingDisconnected();
  6580. }
  6581. UpdatePixelsPerInchMainWindowCounter();
  6582. FShowing = true;
  6583. }
  6584. //---------------------------------------------------------------------------
  6585. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6586. {
  6587. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6588. }
  6589. //---------------------------------------------------------------------------
  6590. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6591. {
  6592. DoTerminalListChanged();
  6593. }
  6594. //---------------------------------------------------------------------------
  6595. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6596. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6597. TNotifyEvent OnBalloonClick, TObject * UserData)
  6598. {
  6599. bool Do;
  6600. UnicodeString Message;
  6601. if (E == NULL)
  6602. {
  6603. Message = Str;
  6604. Do = true;
  6605. }
  6606. else
  6607. {
  6608. Do = ExceptionMessage(E, Message);
  6609. }
  6610. if (Do && WinConfiguration->BalloonNotifications)
  6611. {
  6612. UnicodeString Title;
  6613. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6614. {
  6615. Message = TrimLeft(Message);
  6616. }
  6617. else
  6618. {
  6619. Message = UnformatMessage(Message);
  6620. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6621. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6622. Title = LoadResourceString(Captions[Type]);
  6623. if (Terminal != NULL)
  6624. {
  6625. Title = FORMAT(L"%s - %s",
  6626. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6627. }
  6628. }
  6629. if (Seconds == 0)
  6630. {
  6631. Seconds = WinConfiguration->NotificationsTimeout;
  6632. }
  6633. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6634. }
  6635. }
  6636. //---------------------------------------------------------------------------
  6637. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6638. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6639. UnicodeString HelpKeyword, const TMessageParams * Params,
  6640. TTerminal * Terminal)
  6641. {
  6642. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6643. (FOnFeedSynchronizeError != NULL)) &&
  6644. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6645. {
  6646. if (FOnFeedSynchronizeError != NULL)
  6647. {
  6648. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6649. }
  6650. else
  6651. {
  6652. DebugAssert(FErrorList != NULL);
  6653. TStringList * MoreMessagesCopy = NULL;
  6654. if (MoreMessages)
  6655. {
  6656. MoreMessagesCopy = new TStringList();
  6657. MoreMessagesCopy->Assign(MoreMessages);
  6658. }
  6659. FErrorList->AddObject(Message, MoreMessagesCopy);
  6660. }
  6661. PopupTrayBalloon(Terminal, Message, Type);
  6662. return ContinueAnswer(Answers);
  6663. }
  6664. else
  6665. {
  6666. bool UseBalloon = FTrayIcon->Visible;
  6667. if (UseBalloon)
  6668. {
  6669. PopupTrayBalloon(Terminal, Message, Type);
  6670. }
  6671. unsigned int Result;
  6672. try
  6673. {
  6674. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6675. }
  6676. __finally
  6677. {
  6678. // cancel only balloon we popped up, otherwise we may cancel notification
  6679. // balloon that was there before the message dialog
  6680. // (such as "dd confirmation opt in balloon)
  6681. if (UseBalloon)
  6682. {
  6683. FTrayIcon->CancelBalloon();
  6684. }
  6685. }
  6686. return Result;
  6687. }
  6688. }
  6689. //---------------------------------------------------------------------------
  6690. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6691. TTerminal * Terminal, Exception * E)
  6692. {
  6693. if (FTrayIcon->Visible)
  6694. {
  6695. PopupTrayBalloon(Terminal, L"", qtError, E);
  6696. }
  6697. // particularly prevent opening new session from jump list,
  6698. // while exception is shown
  6699. NonVisualDataModule->StartBusy();
  6700. try
  6701. {
  6702. ShowExtendedExceptionEx(Terminal, E);
  6703. }
  6704. __finally
  6705. {
  6706. NonVisualDataModule->EndBusy();
  6707. FTrayIcon->CancelBalloon();
  6708. }
  6709. }
  6710. //---------------------------------------------------------------------------
  6711. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6712. {
  6713. if (Terminal->Active)
  6714. {
  6715. InitStatusBar();
  6716. }
  6717. // cannot rely on active page being page for active terminal,
  6718. // as it can happen that active page is the "new session" page
  6719. // (e.g. when reconnecting active terminal, while login dialog
  6720. // invoked from "new session" page is modal)
  6721. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6722. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6723. }
  6724. //---------------------------------------------------------------------------
  6725. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6726. TTerminal * Terminal, Exception * E)
  6727. {
  6728. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6729. if (!Terminal->Active)
  6730. {
  6731. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6732. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6733. {
  6734. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6735. }
  6736. }
  6737. }
  6738. //---------------------------------------------------------------------------
  6739. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6740. UnicodeString Message, TQueryType Type,
  6741. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6742. {
  6743. if ((E == NULL) ||
  6744. ExceptionMessage(E, Message))
  6745. {
  6746. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6747. if (Important)
  6748. {
  6749. Seconds *= 5;
  6750. }
  6751. UnicodeString NoteMessage(UnformatMessage(Message));
  6752. if (Terminal != NULL)
  6753. {
  6754. NoteMessage = FORMAT(L"%s: %s",
  6755. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6756. }
  6757. if (WinConfiguration->BalloonNotifications)
  6758. {
  6759. AddNote(NoteMessage);
  6760. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6761. }
  6762. else
  6763. {
  6764. FlashOnBackground();
  6765. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6766. }
  6767. }
  6768. }
  6769. //---------------------------------------------------------------------------
  6770. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6771. {
  6772. RestoreApp();
  6773. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6774. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6775. !NonVisualDataModule->Busy)
  6776. {
  6777. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6778. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6779. if (!ComponentVisible[fcQueueView])
  6780. {
  6781. ToggleQueueVisibility();
  6782. GoToQueue();
  6783. }
  6784. }
  6785. }
  6786. //---------------------------------------------------------------------------
  6787. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6788. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6789. {
  6790. UnicodeString Message;
  6791. TNotifyEvent OnClick = NULL;
  6792. TObject * UserData = NULL;
  6793. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6794. switch (Event)
  6795. {
  6796. case qeEmptyButMonitored:
  6797. if ((ATerminal != Terminal) || QueueInvisible)
  6798. {
  6799. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6800. OnClick = QueueEmptyNoteClicked;
  6801. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6802. TerminalNoteData->Terminal = ATerminal;
  6803. UserData = TerminalNoteData;
  6804. }
  6805. break;
  6806. case qeEmpty:
  6807. OperationComplete(ATerminal->QueueOperationStart);
  6808. break;
  6809. case qePendingUserAction:
  6810. if ((ATerminal != Terminal) ||
  6811. (QueueInvisible && !IsQueueAutoPopup()))
  6812. {
  6813. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6814. }
  6815. break;
  6816. default:
  6817. DebugFail();
  6818. }
  6819. if (!Message.IsEmpty())
  6820. {
  6821. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6822. }
  6823. }
  6824. //---------------------------------------------------------------------------
  6825. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6826. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6827. {
  6828. if (FDDExtMapFile != NULL)
  6829. {
  6830. CloseHandle(FDDExtMapFile);
  6831. FDDExtMapFile = NULL;
  6832. }
  6833. if (WinConfiguration->DDFakeFile)
  6834. {
  6835. DDFakeFileInitDrag(FileList, Created);
  6836. }
  6837. }
  6838. //---------------------------------------------------------------------------
  6839. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6840. {
  6841. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6842. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6843. {
  6844. FFakeFileDropTarget = FileName;
  6845. }
  6846. }
  6847. //---------------------------------------------------------------------------
  6848. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6849. {
  6850. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6851. if (!ForceDirectories(ApiPath(Result)))
  6852. {
  6853. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6854. }
  6855. FileSetAttr(ApiPath(Result), faHidden);
  6856. return Result;
  6857. }
  6858. //---------------------------------------------------------------------------
  6859. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6860. bool & Created)
  6861. {
  6862. FFakeFileDropTarget = UnicodeString();
  6863. FDragFakeDirectory = CreateFakeTransferDirectory();
  6864. FileList->AddItem(NULL, FDragFakeDirectory);
  6865. Created = true;
  6866. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6867. {
  6868. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6869. }
  6870. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6871. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6872. {
  6873. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6874. TDragExtCommStruct* CommStruct;
  6875. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6876. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6877. DebugAssert(CommStruct != NULL);
  6878. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6879. CommStruct->Dragging = true;
  6880. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6881. LENOF(CommStruct->DropDest));
  6882. NULL_TERMINATE(CommStruct->DropDest);
  6883. UnmapViewOfFile(CommStruct);
  6884. }
  6885. }
  6886. //---------------------------------------------------------------------------
  6887. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6888. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6889. {
  6890. bool Result;
  6891. DebugAssert(!IsLocalBrowserMode());
  6892. if (Sender == RemoteDirView)
  6893. {
  6894. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6895. }
  6896. else
  6897. {
  6898. DebugAssert(Sender == RemoteDriveView);
  6899. TStrings * FileList = RemoteDriveView->DragFileList();
  6900. try
  6901. {
  6902. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6903. }
  6904. __finally
  6905. {
  6906. delete FileList;
  6907. }
  6908. }
  6909. if (FDDTargetControl == RemoteDriveView)
  6910. {
  6911. RemoteDriveView->UpdateDropTarget();
  6912. }
  6913. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6914. // or from tree view to dir view.
  6915. // foMove happens when file/dir is dragged from remote tree view outside of
  6916. // application via dragex
  6917. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6918. (DropSourceControl == RemoteDriveView))
  6919. {
  6920. RemoteDriveView->UpdateDropSource();
  6921. }
  6922. return Result;
  6923. }
  6924. //---------------------------------------------------------------------------
  6925. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6926. {
  6927. DebugAssert(!IsLocalBrowserMode());
  6928. // This also handles drops of remote files to queue.
  6929. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6930. SAFE_DESTROY(FDDFileList);
  6931. if (!FFakeFileDropTarget.IsEmpty())
  6932. {
  6933. RemoveDir(ApiPath(FFakeFileDropTarget));
  6934. }
  6935. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6936. {
  6937. try
  6938. {
  6939. TDragResult DDResult = (Sender == RemoteDirView) ?
  6940. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6941. // Focus is moved to the target application,
  6942. // but as we are going to present the UI, we need to steal the focus back.
  6943. // This most likely won't work though (windows does not allow application
  6944. // to steal focus most of the time)
  6945. Application->BringToFront();
  6946. // On older version of Windows we never got drMove here, see also comment below.
  6947. // On Windows 10, we get the "move".
  6948. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6949. {
  6950. UnicodeString TargetDirectory;
  6951. TFileOperation Operation;
  6952. // drInvalid may mean drMove, see comment below
  6953. switch (DDResult)
  6954. {
  6955. case drCopy:
  6956. Operation = foCopy;
  6957. break;
  6958. case drMove:
  6959. Operation = foMove;
  6960. break;
  6961. default:
  6962. DebugFail();
  6963. case drInvalid:
  6964. // prefer "copy" for safety
  6965. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6966. break;
  6967. }
  6968. TTransferOperationParam Param;
  6969. UnicodeString CounterName;
  6970. bool ForceQueue;
  6971. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  6972. {
  6973. // we get drInvalid both if d&d was intercepted by ddext,
  6974. // and when users drops on no-drop location.
  6975. // we tell the difference by existence of response from ddext,
  6976. // so we ignore absence of response in this case
  6977. if (DDResult != drInvalid)
  6978. {
  6979. // here we know that the extension is installed,
  6980. // as it is checked as soon as drag&drop starts from
  6981. // RemoteFileControlDDCreateDragFileList
  6982. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  6983. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  6984. {
  6985. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  6986. }
  6987. else
  6988. {
  6989. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  6990. }
  6991. }
  6992. }
  6993. else
  6994. {
  6995. // download using fake file
  6996. Param.Temp = false;
  6997. Param.DragDrop = true;
  6998. if (ForceQueue)
  6999. {
  7000. Param.Queue = asOn;
  7001. }
  7002. if (Sender == RemoteDirView)
  7003. {
  7004. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7005. }
  7006. if (RemoteFileControlFileOperation(Sender, Operation,
  7007. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7008. {
  7009. Configuration->Usage->Inc(CounterName);
  7010. }
  7011. }
  7012. }
  7013. }
  7014. __finally
  7015. {
  7016. CloseHandle(FDDExtMapFile);
  7017. FDDExtMapFile = NULL;
  7018. delete FDragFakeMonitors;
  7019. FDragFakeMonitors = NULL;
  7020. RemoveDir(ApiPath(FDragFakeDirectory));
  7021. FDragFakeDirectory = L"";
  7022. FFakeFileDropTarget = UnicodeString();
  7023. }
  7024. }
  7025. if (FDragDropSshTerminate.get() != NULL)
  7026. {
  7027. FDragDropSshTerminate->Rethrow();
  7028. }
  7029. }
  7030. //---------------------------------------------------------------------------
  7031. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7032. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7033. {
  7034. // Remember drop effect so we know (when user drops files), if we copy or move
  7035. FLastDropEffect = dwEffect;
  7036. }
  7037. //---------------------------------------------------------------------------
  7038. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7039. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7040. {
  7041. bool Result;
  7042. if (FDDTargetControl == QueueView3)
  7043. {
  7044. Directory = DefaultDownloadTargetDirectory();
  7045. Result = true;
  7046. CounterName = L"DownloadsDragDropQueue";
  7047. ForceQueue = true;
  7048. }
  7049. else if (!FFakeFileDropTarget.IsEmpty())
  7050. {
  7051. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7052. Result = true;
  7053. ForceQueue = false;
  7054. CounterName = L"DownloadsDragDropFakeFile";
  7055. }
  7056. else
  7057. {
  7058. ForceQueue = false;
  7059. Enabled = false;
  7060. try
  7061. {
  7062. int Timer = 0;
  7063. Result = false;
  7064. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7065. {
  7066. {
  7067. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7068. TDragExtCommStruct* CommStruct;
  7069. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7070. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7071. DebugAssert(CommStruct != NULL);
  7072. Result = !CommStruct->Dragging;
  7073. if (Result)
  7074. {
  7075. Directory = ExtractFilePath(CommStruct->DropDest);
  7076. CounterName = L"DownloadsDragDropExternalExt";
  7077. }
  7078. UnmapViewOfFile(CommStruct);
  7079. }
  7080. if (!Result)
  7081. {
  7082. Sleep(50);
  7083. Timer += 50;
  7084. Application->ProcessMessages();
  7085. }
  7086. }
  7087. }
  7088. __finally
  7089. {
  7090. Enabled = true;
  7091. }
  7092. }
  7093. return Result;
  7094. }
  7095. //---------------------------------------------------------------------------
  7096. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7097. const UnicodeString TempDir, int SecDelay)
  7098. {
  7099. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7100. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7101. if (FDelayedDeletionTimer == NULL)
  7102. {
  7103. DebugAssert(HandleAllocated());
  7104. FDelayedDeletionTimer = new TTimer(this);
  7105. FDelayedDeletionTimer->Interval = 10000;
  7106. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7107. }
  7108. else
  7109. {
  7110. FDelayedDeletionTimer->Enabled = true;
  7111. }
  7112. }
  7113. //---------------------------------------------------------------------------
  7114. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7115. {
  7116. DebugAssert(FDelayedDeletionList != NULL);
  7117. TDateTime N = Now();
  7118. TDateTime Alert;
  7119. UnicodeString Directory;
  7120. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7121. {
  7122. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7123. if ((N >= Alert) || (Sender == NULL))
  7124. {
  7125. Directory = FDelayedDeletionList->Strings[Index];
  7126. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7127. {
  7128. FDelayedDeletionList->Delete(Index);
  7129. }
  7130. }
  7131. }
  7132. if (FDelayedDeletionList->Count == 0)
  7133. {
  7134. FDelayedDeletionTimer->Enabled = false;
  7135. }
  7136. }
  7137. //---------------------------------------------------------------------------
  7138. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7139. {
  7140. DebugAssert(!IsLocalBrowserMode());
  7141. if (IsFileControl(FDDTargetControl, osRemote) ||
  7142. (FDDTargetControl == SessionsPageControl))
  7143. {
  7144. TTerminal * TargetTerminal = NULL;
  7145. TFileOperation Operation = foNone;
  7146. if (FDDTargetControl == SessionsPageControl)
  7147. {
  7148. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7149. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7150. // do not allow dropping on the "+" tab
  7151. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7152. if (TargetTerminal != NULL)
  7153. {
  7154. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7155. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7156. {
  7157. Operation = foRemoteMove;
  7158. }
  7159. else
  7160. {
  7161. Operation = foRemoteCopy;
  7162. }
  7163. }
  7164. }
  7165. else
  7166. {
  7167. if (FLastDropEffect == DROPEFFECT_MOVE)
  7168. {
  7169. Operation = foRemoteMove;
  7170. }
  7171. else if (FLastDropEffect == DROPEFFECT_COPY)
  7172. {
  7173. Operation = foRemoteCopy;
  7174. }
  7175. }
  7176. if (Operation != foNone)
  7177. {
  7178. RemoteFileControlFileOperation(DropSourceControl,
  7179. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7180. }
  7181. // abort drag&drop
  7182. Abort();
  7183. }
  7184. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7185. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7186. (FDDTargetControl != QueueView3))
  7187. {
  7188. DebugAssert(!FDragTempDir.IsEmpty());
  7189. TTransferType Type;
  7190. UnicodeString TempDir = FDragTempDir;
  7191. // We clear FDragTempDir before calling
  7192. // just in case it fail (raises exception)
  7193. FDragTempDir = L"";
  7194. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7195. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7196. // empty directory parameter means temp directory -> don't display it!
  7197. UnicodeString TargetDir = L"";
  7198. int Options = 0;
  7199. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7200. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7201. {
  7202. Abort();
  7203. }
  7204. // TargetDir is set when dropped on local file control
  7205. // (this was workaround for legacy dirview event handling, now it should be
  7206. // made prettier)
  7207. if (TargetDir.IsEmpty())
  7208. {
  7209. TargetDir = TempDir;
  7210. if (ForceDirectories(ApiPath(TargetDir)))
  7211. {
  7212. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7213. FPendingTempSpaceWarn = true;
  7214. try
  7215. {
  7216. FDragDropOperation = true;
  7217. int Params = cpTemporary |
  7218. (Type == ttMove ? cpDelete : 0);
  7219. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7220. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7221. }
  7222. __finally
  7223. {
  7224. FDragDropOperation = false;
  7225. FPendingTempSpaceWarn = false;
  7226. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7227. }
  7228. }
  7229. else
  7230. {
  7231. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7232. }
  7233. }
  7234. }
  7235. }
  7236. //---------------------------------------------------------------------------
  7237. void __fastcall TCustomScpExplorerForm::DDDownload(
  7238. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7239. {
  7240. DebugAssert(!IsLocalBrowserMode());
  7241. TAutoBatch AutoBatch(this);
  7242. UpdateCopyParamCounters(*CopyParam);
  7243. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7244. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7245. {
  7246. RemoteDriveView->UpdateDropSource();
  7247. }
  7248. }
  7249. //---------------------------------------------------------------------------
  7250. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7251. {
  7252. public:
  7253. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7254. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7255. {
  7256. }
  7257. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7258. {
  7259. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7260. TDataObjectFilesEx::AllowData(FormatEtc);
  7261. }
  7262. };
  7263. //---------------------------------------------------------------------------
  7264. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7265. TObject * Sender, TDataObject *& DataObject)
  7266. {
  7267. if (FDDExtMapFile != NULL)
  7268. {
  7269. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7270. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7271. {
  7272. Abort();
  7273. }
  7274. if (FileList->Count > 0)
  7275. {
  7276. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7277. if (!FilesObject->IsValid(true, true))
  7278. {
  7279. FilesObject->_Release();
  7280. }
  7281. else
  7282. {
  7283. DataObject = FilesObject;
  7284. }
  7285. }
  7286. }
  7287. }
  7288. //---------------------------------------------------------------------------
  7289. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7290. {
  7291. DebugFail();
  7292. }
  7293. //---------------------------------------------------------------------------
  7294. void __fastcall TCustomScpExplorerForm::GoToTree()
  7295. {
  7296. ComponentVisible[fcRemoteTree] = true;
  7297. DriveView(osRemote)->SetFocus();
  7298. }
  7299. //---------------------------------------------------------------------------
  7300. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7301. TPanelExport Export)
  7302. {
  7303. TCustomDirView * DirView = this->DirView(Side);
  7304. std::unique_ptr<TStrings> ExportData(new TStringList());
  7305. switch (Export)
  7306. {
  7307. case pePath:
  7308. ExportData->Add(DirView->PathName);
  7309. break;
  7310. case peFileList:
  7311. case peFullFileList:
  7312. {
  7313. bool FullPath = (Export == peFullFileList);
  7314. DirView->CreateFileList(false, FullPath, ExportData.get());
  7315. for (int Index = 0; Index < ExportData->Count; Index++)
  7316. {
  7317. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7318. {
  7319. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7320. }
  7321. }
  7322. }
  7323. break;
  7324. default:
  7325. DebugFail();
  7326. }
  7327. return ExportData.release();
  7328. }
  7329. //---------------------------------------------------------------------------
  7330. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7331. TPanelExport Export, TPanelExportDestination Destination)
  7332. {
  7333. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7334. PanelExportStore(Side, Export, Destination, ExportData.get());
  7335. }
  7336. //---------------------------------------------------------------------------
  7337. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7338. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7339. TStrings * ExportData)
  7340. {
  7341. if (Destination == pedClipboard)
  7342. {
  7343. TInstantOperationVisualizer Visualizer;
  7344. CopyToClipboard(ExportData);
  7345. }
  7346. else
  7347. {
  7348. DebugFail();
  7349. }
  7350. }
  7351. //---------------------------------------------------------------------------
  7352. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7353. {
  7354. TCustomDirView * DirView = this->DirView(Side);
  7355. UnicodeString Mask = DirView->Mask;
  7356. if (DoFilterMaskDialog(DirView, Mask))
  7357. {
  7358. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7359. Configuration->Usage->Inc(L"Filters");
  7360. }
  7361. }
  7362. //---------------------------------------------------------------------------
  7363. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7364. {
  7365. return FQueueController->DefaultOperation();
  7366. }
  7367. //---------------------------------------------------------------------------
  7368. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7369. TQueueOperation Operation, void ** Param)
  7370. {
  7371. switch (Operation)
  7372. {
  7373. case qoPreferences:
  7374. return true;
  7375. case qoGoTo:
  7376. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7377. case qoOnceEmpty:
  7378. return IsAnythingQueued();
  7379. default:
  7380. return FQueueController->AllowOperation(Operation, Param);
  7381. }
  7382. }
  7383. //---------------------------------------------------------------------------
  7384. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7385. {
  7386. if (DebugAlwaysTrue(QueueView3->Visible))
  7387. {
  7388. QueueView3->SetFocus();
  7389. }
  7390. }
  7391. //---------------------------------------------------------------------------
  7392. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7393. TQueueOperation Operation, void * Param)
  7394. {
  7395. if (Operation == qoGoTo)
  7396. {
  7397. GoToQueue();
  7398. }
  7399. else if (Operation == qoPreferences)
  7400. {
  7401. PreferencesDialog(pmQueue);
  7402. }
  7403. else
  7404. {
  7405. FQueueController->ExecuteOperation(Operation, Param);
  7406. }
  7407. }
  7408. //---------------------------------------------------------------------------
  7409. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7410. {
  7411. return (Queue != NULL) && Queue->Enabled;
  7412. }
  7413. //---------------------------------------------------------------------------
  7414. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7415. {
  7416. DebugAssert(Queue != NULL);
  7417. if (Queue != NULL)
  7418. {
  7419. Queue->Enabled = !Queue->Enabled;
  7420. }
  7421. }
  7422. //---------------------------------------------------------------------------
  7423. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7424. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7425. {
  7426. FQueueActedItem = QueueView3->ItemFocused;
  7427. }
  7428. //---------------------------------------------------------------------------
  7429. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7430. {
  7431. return TopDock->Height + QueueSplitter->Height;
  7432. }
  7433. //---------------------------------------------------------------------------
  7434. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7435. {
  7436. return
  7437. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7438. (QueueDock->Visible ? QueueDock->Height : 0) +
  7439. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7440. }
  7441. //---------------------------------------------------------------------------
  7442. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7443. {
  7444. return ScaleByTextHeight(this, 48);
  7445. }
  7446. //---------------------------------------------------------------------------
  7447. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7448. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7449. {
  7450. // when queue is hidden by double-clicking splitter, stray attempt to
  7451. // resize the panel with strange value arrives, make sure it is ignored
  7452. if (ComponentVisible[fcQueueView])
  7453. {
  7454. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7455. if (NewSize > MaxHeightLimit)
  7456. {
  7457. NewSize = MaxHeightLimit;
  7458. }
  7459. int MinHeightLimit =
  7460. GetStaticQueuePanelComponentsHeight() +
  7461. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7462. GetMinQueueViewHeight();
  7463. if (NewSize < MinHeightLimit)
  7464. {
  7465. NewSize = MinHeightLimit;
  7466. }
  7467. }
  7468. else
  7469. {
  7470. Accept = false;
  7471. }
  7472. }
  7473. //---------------------------------------------------------------------------
  7474. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7475. {
  7476. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7477. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7478. if (QueueViewHeight < GetMinQueueViewHeight())
  7479. {
  7480. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7481. }
  7482. }
  7483. //---------------------------------------------------------------------------
  7484. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7485. TDragObject *& /*DragObject*/)
  7486. {
  7487. FQueueActedItem = QueueView3->ItemFocused;
  7488. }
  7489. //---------------------------------------------------------------------------
  7490. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7491. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7492. {
  7493. Accept = true;
  7494. if (Source == QueueView3)
  7495. {
  7496. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7497. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7498. if (Accept)
  7499. {
  7500. TQueueItemProxy * QueueItem;
  7501. TQueueItemProxy * DestQueueItem;
  7502. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7503. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7504. Accept = (QueueItem != DestQueueItem) &&
  7505. (QueueItem->Status == TQueueItem::qsPending) &&
  7506. (DestQueueItem->Status == TQueueItem::qsPending);
  7507. }
  7508. }
  7509. }
  7510. //---------------------------------------------------------------------------
  7511. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7512. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7513. {
  7514. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7515. {
  7516. TQueueItemProxy * QueueItem;
  7517. TQueueItemProxy * DestQueueItem;
  7518. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7519. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7520. QueueItem->Move(DestQueueItem);
  7521. }
  7522. }
  7523. //---------------------------------------------------------------------------
  7524. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7525. {
  7526. if ((QueueView3->ItemFocused == NULL) &&
  7527. (QueueView3->Items->Count > 0))
  7528. {
  7529. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7530. }
  7531. QueueLabelUpdateStatus();
  7532. }
  7533. //---------------------------------------------------------------------------
  7534. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7535. {
  7536. QueueLabelUpdateStatus();
  7537. }
  7538. //---------------------------------------------------------------------------
  7539. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7540. {
  7541. QueueLabel->UpdateStatus();
  7542. }
  7543. //---------------------------------------------------------------------------
  7544. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7545. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7546. {
  7547. if (Selected)
  7548. {
  7549. NonVisualDataModule->UpdateNonVisibleActions();
  7550. }
  7551. }
  7552. //---------------------------------------------------------------------------
  7553. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7554. {
  7555. TDragDropFilesEx * Result = NULL;
  7556. if (Sender == SessionsPageControl)
  7557. {
  7558. Result = FSessionsDragDropFilesEx;
  7559. }
  7560. else if (Sender == QueueView3)
  7561. {
  7562. Result = FQueueDragDropFilesEx;
  7563. }
  7564. else
  7565. {
  7566. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7567. if (DirView != NULL)
  7568. {
  7569. Result = DirView->DragDropFilesEx;
  7570. }
  7571. else
  7572. {
  7573. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7574. if (DriveView != NULL)
  7575. {
  7576. Result = DriveView->DragDropFilesEx;
  7577. }
  7578. }
  7579. }
  7580. DebugAssert(Result != NULL);
  7581. return Result;
  7582. }
  7583. //---------------------------------------------------------------------------
  7584. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7585. {
  7586. return (DView->SelCount == DView->FilesCount);
  7587. }
  7588. //---------------------------------------------------------------------------
  7589. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7590. {
  7591. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7592. }
  7593. //---------------------------------------------------------------------------
  7594. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7595. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7596. {
  7597. DebugAssert(!IsLocalBrowserMode());
  7598. TFileOperation Operation;
  7599. switch (Effect)
  7600. {
  7601. case DROPEFFECT_MOVE:
  7602. Operation = foMove;
  7603. break;
  7604. case DROPEFFECT_COPY:
  7605. // occures on WinXP (reported by user)
  7606. default:
  7607. Operation = foCopy;
  7608. break;
  7609. };
  7610. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7611. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7612. if (DragDropFilesEx->FileList->Count > 0)
  7613. {
  7614. TStrings * FileList = new TStringList();
  7615. try
  7616. {
  7617. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7618. {
  7619. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7620. }
  7621. FDragDropOperation = true;
  7622. TTransferOperationParam Param;
  7623. Param.TargetDirectory = TargetPath;
  7624. // upload, no temp dirs
  7625. Param.Temp = false;
  7626. Param.DragDrop = DragDrop;
  7627. Param.Options =
  7628. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7629. if (ForceQueue)
  7630. {
  7631. Param.Queue = asOn;
  7632. }
  7633. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7634. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7635. {
  7636. if (IsFileControl(DropSourceControl, osLocal))
  7637. {
  7638. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7639. }
  7640. else
  7641. {
  7642. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7643. }
  7644. }
  7645. }
  7646. __finally
  7647. {
  7648. FDragDropOperation = false;
  7649. delete FileList;
  7650. }
  7651. }
  7652. }
  7653. //---------------------------------------------------------------------------
  7654. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7655. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7656. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7657. {
  7658. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7659. }
  7660. //---------------------------------------------------------------------------
  7661. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7662. TObject * Sender, int grfKeyState, int & dwEffect)
  7663. {
  7664. DebugAssert(!IsLocalBrowserMode());
  7665. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7666. if ((dwEffect != DROPEFFECT_NONE) &&
  7667. IsFileControl(DropSourceControl, osRemote))
  7668. {
  7669. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7670. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7671. (RemoteDirView->DropTarget == NULL))
  7672. {
  7673. dwEffect = DROPEFFECT_NONE;
  7674. }
  7675. else
  7676. {
  7677. if (dwEffect == DROPEFFECT_COPY)
  7678. {
  7679. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7680. // currently we support copying always (at least via temporary directory);
  7681. // remove associated checks once this all proves stable and working
  7682. bool CopyCapable = true;
  7683. // if we do not support neither of operations, there's no discussion
  7684. if (!MoveCapable && !CopyCapable)
  7685. {
  7686. dwEffect = DROPEFFECT_NONE;
  7687. }
  7688. else
  7689. {
  7690. // The default effect inside remote panel is move,
  7691. // unless we do not support it, but support copy
  7692. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7693. {
  7694. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7695. }
  7696. else
  7697. {
  7698. // with ctrl-down, we want copy unless it is not supported
  7699. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7700. }
  7701. }
  7702. }
  7703. }
  7704. }
  7705. }
  7706. //---------------------------------------------------------------------------
  7707. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7708. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7709. {
  7710. DebugAssert(!IsLocalBrowserMode());
  7711. if (FDDTotalSize >= 0)
  7712. {
  7713. if (File->IsDirectory)
  7714. {
  7715. FDDTotalSize = -1;
  7716. }
  7717. else
  7718. {
  7719. FDDTotalSize += File->Size;
  7720. }
  7721. }
  7722. DebugAssert(!FDragTempDir.IsEmpty());
  7723. // TODO: this is quite ineffective
  7724. // TODO: what if invalid character replacement is disabled?
  7725. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7726. UnicodeString TransferFileName;
  7727. if (Sender == RemoteDriveView)
  7728. {
  7729. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7730. }
  7731. else
  7732. {
  7733. TransferFileName = File->FileName;
  7734. }
  7735. FDDFileList->AddObject(TransferFileName, File);
  7736. }
  7737. //---------------------------------------------------------------------------
  7738. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7739. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7740. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7741. {
  7742. // sometimes we do not get DDEnd so the list is not released
  7743. SAFE_DESTROY(FDDFileList);
  7744. FDDFileList = new TStringList();
  7745. FDragTempDir = WinConfiguration->TemporaryDir();
  7746. FDDTotalSize = 0;
  7747. FDragDropSshTerminate.reset(NULL);
  7748. }
  7749. //---------------------------------------------------------------------------
  7750. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7751. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7752. HRESULT & Result)
  7753. {
  7754. if (Result == DRAGDROP_S_DROP)
  7755. {
  7756. try
  7757. {
  7758. GlobalDragImageList->HideDragImage();
  7759. try
  7760. {
  7761. RemoteFileControlDDTargetDrop();
  7762. }
  7763. catch(ESshTerminate & E)
  7764. {
  7765. FDragDropSshTerminate.reset(E.Clone());
  7766. }
  7767. }
  7768. catch (Exception &E)
  7769. {
  7770. // If downloading fails we need to cancel drag&drop, otherwise
  7771. // Explorer shows error
  7772. // But by the way exception probably never reach this point as
  7773. // it's catched on way.
  7774. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7775. Result = DRAGDROP_S_CANCEL;
  7776. ShowExtendedException(Terminal, &E);
  7777. }
  7778. }
  7779. }
  7780. //---------------------------------------------------------------------------
  7781. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7782. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7783. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7784. {
  7785. TFileMasks::TParams MaskParams;
  7786. MaskParams.Size = Size;
  7787. MaskParams.Modification = Modification;
  7788. // this does not re-parse the mask if it is the same as the last time
  7789. FDirViewMatchMask = Masks;
  7790. bool ImplicitMatch;
  7791. Matches =
  7792. // RecurseInclude parameter has no effect as the Path is empty
  7793. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7794. (AllowImplicitMatches || !ImplicitMatch);
  7795. }
  7796. //---------------------------------------------------------------------------
  7797. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7798. TObject * Sender, TListItem * Item, WORD & Indexes)
  7799. {
  7800. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7801. UnicodeString Ext;
  7802. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7803. {
  7804. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7805. }
  7806. else
  7807. {
  7808. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7809. }
  7810. if (SameText(Ext, Configuration->PartialExt))
  7811. {
  7812. Indexes |= oiPartial;
  7813. }
  7814. }
  7815. //---------------------------------------------------------------------------
  7816. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7817. {
  7818. return
  7819. DirViewEnabled(osCurrent) &&
  7820. DirView(osCurrent)->CanPasteFromClipBoard();
  7821. }
  7822. //---------------------------------------------------------------------------
  7823. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7824. {
  7825. bool Result = false;
  7826. if (CanPasteToDirViewFromClipBoard())
  7827. {
  7828. Result = true;
  7829. }
  7830. else
  7831. {
  7832. UnicodeString ClipboardText;
  7833. if (NonEmptyTextFromClipboard(ClipboardText) &&
  7834. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  7835. {
  7836. if (StoredSessions->IsUrl(ClipboardText))
  7837. {
  7838. Result = true;
  7839. }
  7840. else
  7841. {
  7842. Result = DirViewEnabled(osCurrent);
  7843. }
  7844. }
  7845. }
  7846. return Result;
  7847. }
  7848. //---------------------------------------------------------------------------
  7849. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7850. {
  7851. if (DoesClipboardContainOurFiles())
  7852. {
  7853. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7854. {
  7855. DebugAssert(!IsLocalBrowserMode());
  7856. TTerminalManager * Manager = TTerminalManager::Instance();
  7857. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7858. Manager->ActiveTerminal = FClipboardTerminal;
  7859. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7860. }
  7861. }
  7862. else if (CanPasteToDirViewFromClipBoard())
  7863. {
  7864. DirView(osCurrent)->PasteFromClipBoard();
  7865. }
  7866. else
  7867. {
  7868. UnicodeString ClipboardText;
  7869. if (NonEmptyTextFromClipboard(ClipboardText))
  7870. {
  7871. if (StoredSessions->IsUrl(ClipboardText))
  7872. {
  7873. NewSession(ClipboardText);
  7874. }
  7875. else
  7876. {
  7877. DirView(osCurrent)->Path = ClipboardText;
  7878. }
  7879. }
  7880. }
  7881. }
  7882. //---------------------------------------------------------------------------
  7883. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7884. {
  7885. // TBD
  7886. }
  7887. //---------------------------------------------------------------------------
  7888. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7889. {
  7890. TCustomDirView * ADirView = DirView(Side);
  7891. ADirView->SelectAll(Mode);
  7892. ADirView->SetFocus();
  7893. }
  7894. //---------------------------------------------------------------------------
  7895. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7896. {
  7897. TCustomDirView * ADirView = DirView(Side);
  7898. TFileFilter Filter;
  7899. DefaultFileFilter(Filter);
  7900. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7901. {
  7902. Configuration->Usage->Inc(L"MaskSelections");
  7903. ADirView->SelectFiles(Filter, Select);
  7904. ADirView->SetFocus();
  7905. }
  7906. }
  7907. //---------------------------------------------------------------------------
  7908. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7909. {
  7910. TCustomDirView * ADirView = DirView(Side);
  7911. ADirView->RestoreSelectedNames();
  7912. ADirView->SetFocus();
  7913. }
  7914. //---------------------------------------------------------------------------
  7915. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7916. {
  7917. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7918. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7919. {
  7920. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7921. UnicodeString Ext;
  7922. if (!IsSideLocalBrowser(osCurrent))
  7923. {
  7924. Ext = UnixExtractFileExt(FileName);
  7925. }
  7926. else
  7927. {
  7928. Ext = ExtractFileExt(FileName);
  7929. }
  7930. if (Ext.IsEmpty())
  7931. {
  7932. Ext = L".";
  7933. }
  7934. TFileFilter Filter;
  7935. Filter.Masks = FORMAT(L"*%s", (Ext));
  7936. Filter.Directories = false;
  7937. CurrentDirView->SelectFiles(Filter, Select);
  7938. }
  7939. }
  7940. //---------------------------------------------------------------------------
  7941. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7942. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7943. {
  7944. UnicodeString Result;
  7945. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7946. {
  7947. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  7948. }
  7949. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  7950. {
  7951. // noop
  7952. }
  7953. else
  7954. {
  7955. Result =
  7956. FMTLOAD(FILE_INFO_FORMAT,
  7957. (FormatBytes(FileInfo.SelectedSize),
  7958. FormatBytes(FileInfo.FilesSize),
  7959. FormatNumber(FileInfo.SelectedCount),
  7960. FormatNumber(FileInfo.FilesCount)));
  7961. }
  7962. return Result;
  7963. }
  7964. //---------------------------------------------------------------------------
  7965. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7966. TTBXStatusPanel * Panel, TOperationSide Side)
  7967. {
  7968. if (Panel->Index == 1)
  7969. {
  7970. ToggleShowHiddenFiles();
  7971. }
  7972. else if (Panel->Index == 2)
  7973. {
  7974. Filter(Side);
  7975. }
  7976. }
  7977. //---------------------------------------------------------------------------
  7978. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  7979. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  7980. {
  7981. DebugAssert(!StatusBar->SimplePanel);
  7982. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  7983. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  7984. }
  7985. //---------------------------------------------------------------------------
  7986. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  7987. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  7988. {
  7989. DebugAssert(StatusBar->Panels->Count >= 3);
  7990. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  7991. if (FileInfo.HiddenCount > 0)
  7992. {
  7993. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  7994. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7995. }
  7996. else
  7997. {
  7998. HiddenFilesPanel->ViewPriority = 0;
  7999. // not really necessary, just to cleanup no-longer-valid data
  8000. HiddenFilesPanel->Caption = L"";
  8001. }
  8002. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8003. if (FileInfo.FilteredCount > 0)
  8004. {
  8005. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8006. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8007. }
  8008. else
  8009. {
  8010. FilteredFilesPanel->ViewPriority = 0;
  8011. // not really necessary, just to cleanup no-longer-valid data
  8012. FilteredFilesPanel->Caption = L"";
  8013. }
  8014. }
  8015. //---------------------------------------------------------------------------
  8016. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8017. TObject * /*Sender*/)
  8018. {
  8019. if (DirView(osRemote)->Enabled)
  8020. {
  8021. DirView(osRemote)->SetFocus();
  8022. }
  8023. }
  8024. //---------------------------------------------------------------------------
  8025. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8026. {
  8027. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8028. switch (Config.Show)
  8029. {
  8030. case qvShow:
  8031. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8032. {
  8033. Config.Show = qvHide;
  8034. }
  8035. else
  8036. {
  8037. Config.Show = Config.LastHideShow;
  8038. }
  8039. break;
  8040. case qvHideWhenEmpty:
  8041. if (ComponentVisible[fcQueueView])
  8042. {
  8043. Config.Show = qvHide;
  8044. }
  8045. else
  8046. {
  8047. Config.LastHideShow = Config.Show;
  8048. Config.Show = qvShow;
  8049. }
  8050. break;
  8051. case qvHide:
  8052. Config.LastHideShow = Config.Show;
  8053. Config.Show = qvShow;
  8054. break;
  8055. }
  8056. WinConfiguration->QueueView = Config;
  8057. }
  8058. //---------------------------------------------------------------------------
  8059. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8060. {
  8061. UnicodeString Result;
  8062. if (FTerminal != NULL)
  8063. {
  8064. switch (WinConfiguration->PathInCaption)
  8065. {
  8066. case picShort:
  8067. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8068. break;
  8069. case picFull:
  8070. Result = FTerminal->CurrentDirectory;
  8071. break;
  8072. }
  8073. }
  8074. return Result;
  8075. }
  8076. //---------------------------------------------------------------------------
  8077. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8078. {
  8079. TColor Result = GetWindowColor(FSessionColor);
  8080. return Result;
  8081. }
  8082. //---------------------------------------------------------------------------
  8083. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8084. {
  8085. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8086. return Result;
  8087. }
  8088. //---------------------------------------------------------------------------
  8089. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8090. {
  8091. TTerminalManager::Instance()->UpdateAppTitle();
  8092. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8093. // background to gray on Windows 7 (works on Windows 10).
  8094. // See also EnableControl
  8095. if (Showing)
  8096. {
  8097. if (Terminal != NULL)
  8098. {
  8099. // Update path when it changes
  8100. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8101. {
  8102. UpdateSessionTab(SessionsPageControl->ActivePage);
  8103. }
  8104. }
  8105. NonVisualDataModule->ReconnectSessionAction->Update();
  8106. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8107. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8108. CenterReconnectToolbar();
  8109. bool HasTerminal = HasActiveTerminal();
  8110. if (HasTerminal)
  8111. {
  8112. // TODO needed yet with second local browser?
  8113. if (!RemoteDirView->Enabled)
  8114. {
  8115. RemoteDirView->Enabled = true;
  8116. if (FRemoteDirViewWasFocused)
  8117. {
  8118. ActiveControl = RemoteDirView;
  8119. }
  8120. }
  8121. RemoteDirView->Color = PanelColor();
  8122. }
  8123. else
  8124. {
  8125. if (RemoteDirView->Enabled)
  8126. {
  8127. // This is first called when the form is being constructed
  8128. // (not anymore due to Showing test above)
  8129. // but the false is overriden in the constructor later.
  8130. // An even later in TScpCommanderForm::DoShow()
  8131. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  8132. RemoteDirView->Enabled = false;
  8133. }
  8134. RemoteDirView->Color = DisabledPanelColor();
  8135. }
  8136. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8137. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8138. RemoteDriveView->Color = RemoteDirView->Color;
  8139. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8140. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8141. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8142. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8143. QueueFileList->Enabled = QueueView3->Enabled;
  8144. QueueFileList->Color = QueueView3->Color;
  8145. QueueFileList->Font->Color = QueueView3->Font->Color;
  8146. QueueLabelUpdateStatus();
  8147. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8148. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8149. if (FImmersiveDarkMode != WinConfiguration->UseDarkTheme())
  8150. {
  8151. UpdateDarkMode();
  8152. }
  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. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  8609. if (Showing && !FStarted)
  8610. {
  8611. FStarted = true;
  8612. InterfaceStarted();
  8613. }
  8614. if (Showing && (Terminal == NULL))
  8615. {
  8616. // When we are starting minimized (i.e. from an installer),
  8617. // postpone showing Login dialog until we get restored.
  8618. // Otherwise the Login dialog (and Authentication window) show restored
  8619. // over invisible (minimized) main window.
  8620. if (WindowState == wsMinimized)
  8621. {
  8622. FNeedSession = true;
  8623. }
  8624. else
  8625. {
  8626. // This happens before application ever goes idle, so the toolbars would
  8627. // stay enabled (initial state) until the Login dialog is dismissed.
  8628. UpdateActions();
  8629. NonVisualDataModule->StartBusy();
  8630. try
  8631. {
  8632. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8633. // otherwise the dialog does not receive focus.
  8634. // With Commander interface the ProcessMessages is called already
  8635. // by TDriveView, but with Explorer interface, we need to call it explicily
  8636. Application->ProcessMessages();
  8637. // do not reload sessions, they have been loaded just now (optimization)
  8638. NeedSession(true);
  8639. }
  8640. __finally
  8641. {
  8642. NonVisualDataModule->EndBusy();
  8643. }
  8644. }
  8645. }
  8646. }
  8647. //---------------------------------------------------------------------------
  8648. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8649. {
  8650. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8651. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8652. }
  8653. //---------------------------------------------------------------------------
  8654. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8655. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8656. int & MaxHeight)
  8657. {
  8658. // workaround for bug in TWinControl.CalcConstraints
  8659. // Check for empty rect (restore from iconic state) is done there only after
  8660. // call to AdjustClientRect, which enlarges the rect (for forms).
  8661. TRect R = GetClientRect();
  8662. // when restoring from iconic state, place no restrictions
  8663. if (IsRectEmpty(R))
  8664. {
  8665. MinWidth = 0;
  8666. MinHeight = 0;
  8667. MaxWidth = 32000;
  8668. MaxHeight = 32000;
  8669. }
  8670. }
  8671. //---------------------------------------------------------------------------
  8672. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8673. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8674. {
  8675. // terminal can be already closed (e.g. dropped connection)
  8676. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8677. {
  8678. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8679. try
  8680. {
  8681. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8682. }
  8683. catch(...)
  8684. {
  8685. if (!Terminal->Active)
  8686. {
  8687. Close = true;
  8688. }
  8689. throw;
  8690. }
  8691. }
  8692. }
  8693. //---------------------------------------------------------------------------
  8694. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8695. {
  8696. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8697. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8698. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8699. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8700. {
  8701. OnGetSpaceAvailable = GetSpaceAvailable;
  8702. }
  8703. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8704. OnGetSpaceAvailable);
  8705. }
  8706. //---------------------------------------------------------------------------
  8707. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8708. {
  8709. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8710. Terminal->FillSessionDataForCode(Data.get());
  8711. return Data.release();
  8712. }
  8713. //---------------------------------------------------------------------------
  8714. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8715. {
  8716. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8717. DoGenerateUrlDialog(Data.get(), Paths);
  8718. }
  8719. //---------------------------------------------------------------------------
  8720. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8721. {
  8722. GenerateUrl(NULL);
  8723. }
  8724. //---------------------------------------------------------------------------
  8725. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8726. {
  8727. std::unique_ptr<TStrings> Paths(new TStringList());
  8728. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8729. GenerateUrl(Paths.get());
  8730. }
  8731. //---------------------------------------------------------------------------
  8732. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8733. {
  8734. FSessionColor = value;
  8735. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8736. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8737. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8738. DebugAssert(ColorItem != NULL);
  8739. ColorItem->Color = C;
  8740. NonVisualDataModule->ColorMenuItem->Color = C;
  8741. UpdateControls();
  8742. }
  8743. //---------------------------------------------------------------------------
  8744. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8745. {
  8746. if (value != FSessionColor)
  8747. {
  8748. UpdateSessionColor(value);
  8749. // Is null when called from LastTerminalClosed
  8750. if (Terminal != NULL)
  8751. {
  8752. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8753. }
  8754. }
  8755. }
  8756. //---------------------------------------------------------------------------
  8757. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8758. {
  8759. bool Result = FNoteTimer->Enabled;
  8760. if (Result)
  8761. {
  8762. // cannot cancel note too early
  8763. bool NotEarly =
  8764. (Now() - FNoteShown >
  8765. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8766. if (Force || NotEarly)
  8767. {
  8768. FNoteTimer->Enabled = false;
  8769. FNote = L"";
  8770. SAFE_DESTROY(FNoteData);
  8771. FOnNoteClick = NULL;
  8772. FNoteHints = FNotes->Text;
  8773. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8774. UpdateStatusBar();
  8775. }
  8776. }
  8777. return Result;
  8778. }
  8779. //---------------------------------------------------------------------------
  8780. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8781. {
  8782. DebugAssert(FNoteTimer->Enabled);
  8783. CancelNote(true);
  8784. }
  8785. //---------------------------------------------------------------------------
  8786. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  8787. {
  8788. FNoteHints = FNotes->Text.TrimRight();
  8789. }
  8790. //---------------------------------------------------------------------------
  8791. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8792. {
  8793. int P = Note.Pos(L"\n");
  8794. if (P > 0)
  8795. {
  8796. Note.SetLength(P - 1);
  8797. }
  8798. FNotes->Add(FORMAT(L"[%s] %s",
  8799. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8800. while (FNotes->Count > 10)
  8801. {
  8802. FNotes->Delete(0);
  8803. }
  8804. if (UpdateNow)
  8805. {
  8806. UpdateNoteHints();
  8807. UpdateStatusBar();
  8808. }
  8809. }
  8810. //---------------------------------------------------------------------------
  8811. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8812. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8813. {
  8814. int P = Note.Pos(L"\n");
  8815. if (P > 0)
  8816. {
  8817. Note.SetLength(P - 1);
  8818. }
  8819. UpdateNoteHints();
  8820. FNote = Note;
  8821. SAFE_DESTROY(FNoteData);
  8822. FNoteData = NoteData;
  8823. FOnNoteClick = OnNoteClick;
  8824. AddNote(Note, false);
  8825. UpdateStatusBar();
  8826. FNoteShown = Now();
  8827. FNoteTimer->Enabled = false;
  8828. if (Seconds == 0)
  8829. {
  8830. Seconds = WinConfiguration->NotificationsTimeout;
  8831. }
  8832. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8833. FNoteTimer->Enabled = true;
  8834. }
  8835. //---------------------------------------------------------------------------
  8836. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8837. {
  8838. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8839. }
  8840. //---------------------------------------------------------------------------
  8841. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8842. {
  8843. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked)
  8844. {
  8845. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8846. }
  8847. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8848. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8849. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  8850. 0, NULL, NULL);
  8851. }
  8852. //---------------------------------------------------------------------------
  8853. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8854. {
  8855. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8856. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8857. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8858. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  8859. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8860. }
  8861. //---------------------------------------------------------------------------
  8862. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8863. {
  8864. WinConfiguration->FormatSizeBytes = Style;
  8865. }
  8866. //---------------------------------------------------------------------------
  8867. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8868. {
  8869. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8870. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8871. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8872. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8873. }
  8874. //---------------------------------------------------------------------------
  8875. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8876. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8877. {
  8878. if (Panel->Index == 0)
  8879. {
  8880. if (FOnNoteClick != NULL)
  8881. {
  8882. // prevent the user data from being freed by possible call
  8883. // to CancelNote or PostNote during call to OnNoteClick
  8884. std::unique_ptr<TObject> NoteData(FNoteData);
  8885. TNotifyEvent OnNoteClick = FOnNoteClick;
  8886. FNoteData = NULL;
  8887. // need to cancel the note as we are going to delete its user data
  8888. CancelNote(true);
  8889. OnNoteClick(NoteData.get());
  8890. }
  8891. }
  8892. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8893. {
  8894. FileSystemInfo();
  8895. }
  8896. }
  8897. //---------------------------------------------------------------------------
  8898. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8899. {
  8900. // workaround:
  8901. // 1) for unknown reason, disabling window, while minimized,
  8902. // prevents it from restoring, even if it was enabled again meanwhile
  8903. // 2) when disabling the main window, while another has focus
  8904. // minimize is no longer possible
  8905. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8906. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8907. // Shouldn't we use IsApplicationMinimized() here?
  8908. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8909. {
  8910. Enabled = false;
  8911. }
  8912. FLockLevel++;
  8913. }
  8914. //---------------------------------------------------------------------------
  8915. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8916. {
  8917. DebugAssert(FLockLevel > 0);
  8918. FLockLevel--;
  8919. if (FLockLevel == 0)
  8920. {
  8921. DebugAssert(FLockSuspendLevel == 0);
  8922. Enabled = true;
  8923. }
  8924. }
  8925. //---------------------------------------------------------------------------
  8926. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8927. {
  8928. // We need to make sure that window is enabled when the last modal window closes
  8929. // otherwise focus is not restored correctly.
  8930. // So we re-enable the window when modal window opens and
  8931. // disable it back after is closes
  8932. if (FLockLevel > 0)
  8933. {
  8934. // while we have nesting counter, we know that we never be called
  8935. // recursivelly as Application->OnModalBegin is called only
  8936. // for the top-level modal window
  8937. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8938. {
  8939. // won't be disabled when conditions in LockWindow() were not satisfied
  8940. FDisabledOnLockSuspend = !Enabled;
  8941. // When minimized to tray (or actually when set to SW_HIDE),
  8942. // setting Enabled makes the window focusable even when there's
  8943. // modal window over it
  8944. if (!FTrayIcon->Visible)
  8945. {
  8946. Enabled = true;
  8947. }
  8948. }
  8949. FLockSuspendLevel++;
  8950. }
  8951. }
  8952. //---------------------------------------------------------------------------
  8953. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8954. {
  8955. if (FLockSuspendLevel > 0)
  8956. {
  8957. DebugAssert(FLockLevel > 0);
  8958. FLockSuspendLevel--;
  8959. // see comment in SuspendWindowLock
  8960. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8961. {
  8962. // Note that window can be enabled here, when we were minized to tray when
  8963. // was SuspendWindowLock() called.
  8964. // We should possibly do the same check as in LockWindow(),
  8965. // if it is ever possible that the consitions change between
  8966. // SuspendWindowLock() and ResumeWindowLock()
  8967. Enabled = !FDisabledOnLockSuspend;
  8968. }
  8969. }
  8970. }
  8971. //---------------------------------------------------------------------------
  8972. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8973. {
  8974. TTBXComboBoxItem * RemotePathComboBox =
  8975. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8976. if (!TextOnly)
  8977. {
  8978. TStrings * Items = RemotePathComboBox->Strings;
  8979. Items->BeginUpdate();
  8980. try
  8981. {
  8982. Items->Clear();
  8983. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  8984. {
  8985. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8986. while (!IsUnixRootPath(APath))
  8987. {
  8988. int P = APath.LastDelimiter(L'/');
  8989. DebugAssert(P >= 0);
  8990. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8991. APath.SetLength(P - 1);
  8992. }
  8993. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8994. }
  8995. }
  8996. __finally
  8997. {
  8998. Items->EndUpdate();
  8999. }
  9000. }
  9001. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9002. // Setting ItemIndex to -1 does not reset its text
  9003. if (RemotePathComboBox->Strings->Count == 0)
  9004. {
  9005. RemotePathComboBox->Text = L"";
  9006. }
  9007. }
  9008. //---------------------------------------------------------------------------
  9009. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9010. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  9011. int & ImageIndex)
  9012. {
  9013. if (AIndex < 0)
  9014. {
  9015. AIndex = Sender->ItemIndex;
  9016. }
  9017. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9018. }
  9019. //---------------------------------------------------------------------------
  9020. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9021. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9022. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9023. {
  9024. ARect.Left += (10 * AIndex);
  9025. }
  9026. //---------------------------------------------------------------------------
  9027. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9028. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9029. {
  9030. AWidth += (10 * AIndex);
  9031. }
  9032. //---------------------------------------------------------------------------
  9033. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  9034. TObject * Sender)
  9035. {
  9036. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9037. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9038. int Index = RemotePathComboBox->ItemIndex;
  9039. while (Index < RemotePathComboBox->Strings->Count - 1)
  9040. {
  9041. APath = UnixExtractFileDir(APath);
  9042. Index++;
  9043. }
  9044. // VanDyke style paths
  9045. if (APath.IsEmpty())
  9046. {
  9047. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9048. APath = ROOTDIRECTORY;
  9049. }
  9050. if (RemoteDirView->Path != APath)
  9051. {
  9052. RemoteDirView->Path = APath;
  9053. }
  9054. }
  9055. //---------------------------------------------------------------------------
  9056. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9057. {
  9058. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9059. DebugUsedParam(Sender);
  9060. UpdateRemotePathComboBox(true);
  9061. }
  9062. //---------------------------------------------------------------------------
  9063. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9064. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9065. {
  9066. ResetIncrementalSearch();
  9067. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9068. DebugAssert(DirView != NULL);
  9069. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9070. {
  9071. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9072. // OnEditing is called also from TCustomListView::CanEdit
  9073. if (Edit != NULL)
  9074. {
  9075. EditSelectBaseName(Edit);
  9076. }
  9077. }
  9078. }
  9079. //---------------------------------------------------------------------------
  9080. //---------------------------------------------------------------------------
  9081. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9082. {
  9083. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9084. Result->AutoDetectDnD = false;
  9085. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9086. Result->RenderDataOn = rdoEnterAndDropSync;
  9087. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9088. return Result;
  9089. }
  9090. //---------------------------------------------------------------------------
  9091. void __fastcall TCustomScpExplorerForm::UpdateDarkMode()
  9092. {
  9093. if (IsWin10Build(2004))
  9094. {
  9095. FImmersiveDarkMode = WinConfiguration->UseDarkTheme();
  9096. BOOL DarkMode = FImmersiveDarkMode ? TRUE : FALSE;
  9097. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9098. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9099. }
  9100. }
  9101. //---------------------------------------------------------------------------
  9102. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9103. {
  9104. TForm::CreateWnd();
  9105. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9106. UpdateDarkMode();
  9107. if (FSessionsDragDropFilesEx == NULL)
  9108. {
  9109. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9110. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9111. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9112. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9113. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9114. }
  9115. if (FQueueDragDropFilesEx == NULL)
  9116. {
  9117. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9118. // No need to set OnDragOver as we do not have any restrictions
  9119. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9120. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9121. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9122. }
  9123. }
  9124. //---------------------------------------------------------------------------
  9125. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9126. {
  9127. TForm::DestroyWnd();
  9128. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9129. FQueueDragDropFilesEx->DragDropControl = NULL;
  9130. }
  9131. //---------------------------------------------------------------------------
  9132. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9133. {
  9134. SideEnter(FCurrentSide);
  9135. FEverShown = true;
  9136. }
  9137. //---------------------------------------------------------------------------
  9138. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9139. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9140. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9141. {
  9142. if (!NonVisualDataModule->Busy)
  9143. {
  9144. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9145. Configuration->Usage->Inc(L"FileFinds");
  9146. LockWindow(true);
  9147. NonVisualDataModule->StartBusy();
  9148. WinConfiguration->LockedInterface = true;
  9149. try
  9150. {
  9151. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9152. }
  9153. __finally
  9154. {
  9155. WinConfiguration->LockedInterface = false;
  9156. NonVisualDataModule->EndBusy();
  9157. UnlockWindow();
  9158. }
  9159. }
  9160. }
  9161. //---------------------------------------------------------------------------
  9162. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9163. {
  9164. if (!NonVisualDataModule->Busy)
  9165. {
  9166. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9167. SetFocus();
  9168. RemoteDirView->Path = UnixExtractFilePath(Path);
  9169. UnicodeString FileName = UnixExtractFileName(Path);
  9170. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9171. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9172. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9173. if (Item == NULL)
  9174. {
  9175. ReloadDirectory(osRemote);
  9176. Item = RemoteDirView->FindFileItem(FileName);
  9177. }
  9178. if (Item != NULL)
  9179. {
  9180. RemoteDirView->ItemFocused = Item;
  9181. RemoteDirView->ItemFocused->MakeVisible(false);
  9182. RemoteDirView->SetFocus();
  9183. }
  9184. }
  9185. }
  9186. //---------------------------------------------------------------------------
  9187. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9188. {
  9189. bool Result = !NonVisualDataModule->Busy;
  9190. if (Result)
  9191. {
  9192. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9193. }
  9194. return Result;
  9195. }
  9196. //---------------------------------------------------------------------------
  9197. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9198. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9199. {
  9200. if (CanOperateOnFoundFiles(ATerminal))
  9201. {
  9202. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9203. FOnFileOperationFinished = OnFileOperationFinished;
  9204. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9205. }
  9206. }
  9207. //---------------------------------------------------------------------------
  9208. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9209. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9210. {
  9211. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9212. }
  9213. //---------------------------------------------------------------------------
  9214. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9215. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9216. {
  9217. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9218. }
  9219. //---------------------------------------------------------------------------
  9220. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9221. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9222. {
  9223. if (CanOperateOnFoundFiles(ATerminal))
  9224. {
  9225. for (int Index = 0; Index < FileList->Count; Index++)
  9226. {
  9227. UnicodeString FileName = FileList->Strings[Index];
  9228. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9229. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9230. OnFileOperationFinished(FileName, true);
  9231. }
  9232. }
  9233. }
  9234. //---------------------------------------------------------------------------
  9235. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9236. {
  9237. FFileFindTerminal = Terminal;
  9238. ShowFileFindDialog(
  9239. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9240. DoDownloadFoundFiles, DoEditFoundFiles);
  9241. }
  9242. //---------------------------------------------------------------------------
  9243. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9244. {
  9245. FTaskbarList = TaskbarList;
  9246. }
  9247. //---------------------------------------------------------------------------
  9248. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9249. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9250. {
  9251. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9252. if (Index >= 0)
  9253. {
  9254. if (Button == mbLeft)
  9255. {
  9256. // "Mouse down" is raised only after tab is switched.
  9257. // If switching tab (switching session) takes long enough for user
  9258. // to actually release the button, "mouse down" is still raised,
  9259. // but we do not get "mouse up" event, so dragging is not cancelled,
  9260. // prevent that by not beginning dragging in the first place.
  9261. if (IsKeyPressed(VK_LBUTTON))
  9262. {
  9263. // when user clicks the "+", we get mouse down only after the session
  9264. // is closed, when new session tab is already on X:Y, so dragging
  9265. // starts, prevent that
  9266. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9267. {
  9268. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9269. if (Terminal != NULL)
  9270. {
  9271. SessionsPageControl->BeginDrag(false);
  9272. }
  9273. }
  9274. }
  9275. }
  9276. else if (Button == mbMiddle)
  9277. {
  9278. // ignore middle-click for "New session tab"
  9279. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9280. if (Terminal != NULL)
  9281. {
  9282. CloseSessionTab(Index);
  9283. }
  9284. }
  9285. }
  9286. }
  9287. //---------------------------------------------------------------------------
  9288. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9289. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9290. {
  9291. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9292. // do not allow dropping on the "+" tab
  9293. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9294. if ((TargetTerminal != NULL) &&
  9295. (SessionsPageControl->ActivePage->PageIndex != Index))
  9296. {
  9297. Configuration->Usage->Inc(L"SessionTabMoves");
  9298. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9299. // but we want to actually prevent that to avoid flicker
  9300. SessionsPageControl->ActivePage->PageIndex = Index;
  9301. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9302. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9303. }
  9304. }
  9305. //---------------------------------------------------------------------------
  9306. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9307. TObject * Sender, TObject * Source, int X, int Y,
  9308. TDragState /*State*/, bool & Accept)
  9309. {
  9310. Accept = (Sender == Source);
  9311. if (Accept)
  9312. {
  9313. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9314. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9315. // do not allow dragging to the "+" tab
  9316. Accept = (Terminal != NULL);
  9317. }
  9318. }
  9319. //---------------------------------------------------------------------------
  9320. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9321. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9322. {
  9323. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9324. if (Index < 0)
  9325. {
  9326. Effect = DROPEFFECT_NONE;
  9327. }
  9328. else
  9329. {
  9330. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9331. // do not allow dropping on the "+" tab
  9332. if (TargetTerminal == NULL)
  9333. {
  9334. Effect = DROPEFFECT_NONE;
  9335. }
  9336. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9337. {
  9338. Effect = DROPEFFECT_COPY;
  9339. }
  9340. }
  9341. }
  9342. //---------------------------------------------------------------------------
  9343. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9344. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9345. {
  9346. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9347. // do not allow dropping on the "+" tab
  9348. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9349. if (TargetTerminal != NULL)
  9350. {
  9351. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9352. if (!IsFileControl(DropSourceControl, osRemote))
  9353. {
  9354. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9355. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9356. // Why don't we use Terminal->CurrentDirectory directly?
  9357. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9358. // do not force queue, drag drop
  9359. false, true);
  9360. }
  9361. }
  9362. }
  9363. //---------------------------------------------------------------------------
  9364. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9365. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9366. {
  9367. // Downloads are handled in RemoteFileControlDDEnd
  9368. if (!IsFileControl(DropSourceControl, osRemote))
  9369. {
  9370. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9371. Terminal->CurrentDirectory,
  9372. // force queue, drag drop
  9373. true, true);
  9374. }
  9375. }
  9376. //---------------------------------------------------------------------------
  9377. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9378. {
  9379. FShowing = false;
  9380. // Do not save empty workspace
  9381. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9382. {
  9383. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9384. UnicodeString Name = WorkspaceName();
  9385. DoSaveWorkspace(
  9386. Name, DataList.get(),
  9387. !Configuration->DisablePasswordStoring &&
  9388. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9389. WinConfiguration->LastStoredSession = Name;
  9390. }
  9391. }
  9392. //---------------------------------------------------------------------------
  9393. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9394. {
  9395. TManagedTerminal * ManagedTerminal =
  9396. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9397. if (ManagedTerminal != NULL)
  9398. {
  9399. ManagedTerminal->DirectoryLoaded = Now();
  9400. }
  9401. }
  9402. //---------------------------------------------------------------------------
  9403. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9404. TListItem * /*Item*/, bool /*Selected*/)
  9405. {
  9406. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9407. switch (DirView->LastSelectMethod)
  9408. {
  9409. case smKeyboard:
  9410. Configuration->Usage->Inc(L"KeyboardSelections");
  9411. break;
  9412. case smMouse:
  9413. Configuration->Usage->Inc(L"MouseSelections");
  9414. break;
  9415. }
  9416. }
  9417. //---------------------------------------------------------------------------
  9418. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9419. {
  9420. if (Color != 0)
  9421. {
  9422. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9423. }
  9424. else
  9425. {
  9426. return FSessionTabImageIndex;
  9427. }
  9428. }
  9429. //---------------------------------------------------------------------------
  9430. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9431. {
  9432. TPngImageCollectionItem * Item =
  9433. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9434. FSessionColors->AddPng(Item->PngImage);
  9435. return FSessionColors->Count - 1;
  9436. }
  9437. //---------------------------------------------------------------------------
  9438. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9439. {
  9440. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9441. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9442. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9443. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9444. }
  9445. //---------------------------------------------------------------------------
  9446. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9447. {
  9448. for (int Index = 0; Index < Control->ControlCount; Index++)
  9449. {
  9450. TControl * AControl = Control->Controls[Index];
  9451. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9452. if (WinControl != NULL)
  9453. {
  9454. CollectItemsWithTextDisplayMode(WinControl);
  9455. }
  9456. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9457. if (Toolbar != NULL)
  9458. {
  9459. // we care for top-level items only
  9460. TTBCustomItem * Items = Toolbar->Items;
  9461. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9462. {
  9463. TTBCustomItem * Item = Items->Items[ItemIndex];
  9464. if (((Item->DisplayMode == nbdmImageAndText) ||
  9465. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9466. EligibleForImageDisplayMode(Item))
  9467. {
  9468. FItemsWithTextDisplayMode.insert(Item);
  9469. }
  9470. }
  9471. }
  9472. }
  9473. }
  9474. //---------------------------------------------------------------------------
  9475. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9476. {
  9477. return true;
  9478. }
  9479. //---------------------------------------------------------------------------
  9480. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9481. {
  9482. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9483. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9484. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9485. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9486. bool Result = true;
  9487. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9488. {
  9489. TTBCustomItem * Item = *i;
  9490. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9491. if (Label != NULL)
  9492. {
  9493. // optimization
  9494. if (Label->Visible == SelectiveToolbarText)
  9495. {
  9496. Result = false;
  9497. }
  9498. else
  9499. {
  9500. Label->Visible = SelectiveToolbarText;
  9501. }
  9502. }
  9503. else
  9504. {
  9505. // optimization
  9506. if (Item->DisplayMode == DisplayMode)
  9507. {
  9508. Result = false;
  9509. }
  9510. else
  9511. {
  9512. Item->DisplayMode = DisplayMode;
  9513. }
  9514. }
  9515. ++i;
  9516. }
  9517. if (Result)
  9518. {
  9519. UpdateNewSessionTab();
  9520. }
  9521. return Result;
  9522. }
  9523. //---------------------------------------------------------------------------
  9524. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9525. {
  9526. DebugFail();
  9527. }
  9528. //---------------------------------------------------------------------------
  9529. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9530. {
  9531. // Among other, a lock level is non zero, while directory is being loaded,
  9532. // even when it happens as a result of dirview navigation,
  9533. // i.e. when TNonVisualDataModule is NOT FBusy.
  9534. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9535. // Among other this prevents a panel auto update to occur while
  9536. // directory is changing.
  9537. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9538. }
  9539. //---------------------------------------------------------------------------
  9540. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  9541. {
  9542. // While the window is disabled, we still seem to process menu shortcuts at least,
  9543. // so stop it at least here.
  9544. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9545. return
  9546. (Allowed == aaUpdate) ||
  9547. !NonVisualDataModule->Busy;
  9548. }
  9549. //---------------------------------------------------------------------------
  9550. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9551. {
  9552. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9553. }
  9554. //---------------------------------------------------------------------------
  9555. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9556. {
  9557. // This is somewhat redundant to LockWindow() call from
  9558. // TTerminalManager::TerminalReadDirectoryProgress.
  9559. // But disabling window is known not to block keyboard shorcuts
  9560. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9561. if (Busy > 0)
  9562. {
  9563. if (NonVisualDataModule->Busy)
  9564. {
  9565. State = false;
  9566. }
  9567. else
  9568. {
  9569. NonVisualDataModule->StartBusy();
  9570. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9571. LockWindow();
  9572. }
  9573. }
  9574. else if (Busy < 0)
  9575. {
  9576. UnlockWindow();
  9577. NonVisualDataModule->EndBusy();
  9578. }
  9579. else
  9580. {
  9581. State = NonVisualDataModule->Busy;
  9582. }
  9583. }
  9584. //---------------------------------------------------------------------------
  9585. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9586. {
  9587. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9588. // no context menu for "New session tab"
  9589. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9590. {
  9591. SessionsPageControl->ActivePageIndex = Index;
  9592. if (DebugAlwaysTrue(SessionTabSwitched()))
  9593. {
  9594. // copied from TControl.WMContextMenu
  9595. SendCancelMode(SessionsPageControl);
  9596. // explicit popup instead of using PopupMenu property
  9597. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9598. // while connecting yet not-connected session and hence
  9599. // allowing an access to commands over not-completelly connected session
  9600. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9601. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9602. PopupMenu->PopupComponent = SessionsPageControl;
  9603. PopupMenu->Popup(Point.x, Point.y);
  9604. }
  9605. }
  9606. Handled = true;
  9607. }
  9608. //---------------------------------------------------------------------------
  9609. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9610. {
  9611. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9612. }
  9613. //---------------------------------------------------------------------------
  9614. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9615. {
  9616. Configuration->Usage->Inc(L"PasswordChanges");
  9617. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9618. ChangePasswordData->DisableAuthentationsExceptPassword();
  9619. ChangePasswordData->ChangePassword = true;
  9620. std::unique_ptr<TTerminal> ChangePasswordSession(
  9621. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9622. ChangePasswordSession->AutoReadDirectory = false;
  9623. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9624. {
  9625. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9626. }
  9627. else
  9628. {
  9629. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9630. }
  9631. }
  9632. //---------------------------------------------------------------------------
  9633. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9634. {
  9635. // No nice way to assert SSH2
  9636. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9637. }
  9638. //---------------------------------------------------------------------------
  9639. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9640. {
  9641. TOperationVisualizer OperationVisualizer;
  9642. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9643. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9644. }
  9645. //---------------------------------------------------------------------------
  9646. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9647. {
  9648. TForm::ChangeScale(M, D);
  9649. int APixelsPerInch = GetControlPixelsPerInch(this);
  9650. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9651. try
  9652. {
  9653. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9654. }
  9655. __finally
  9656. {
  9657. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9658. }
  9659. }
  9660. //---------------------------------------------------------------------------
  9661. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9662. {
  9663. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9664. }
  9665. //---------------------------------------------------------------------
  9666. class TPublicControl : public TControl
  9667. {
  9668. friend class TCustomScpExplorerForm;
  9669. };
  9670. //---------------------------------------------------------------------------
  9671. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9672. {
  9673. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9674. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9675. }
  9676. //---------------------------------------------------------------------------
  9677. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9678. {
  9679. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9680. OpenBookmark(Side, Bookmark);
  9681. }
  9682. //---------------------------------------------------------------------------
  9683. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9684. {
  9685. DoBookmarkClick(osLocal, Sender);
  9686. }
  9687. //---------------------------------------------------------------------------
  9688. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9689. {
  9690. DoBookmarkClick(osRemote, Sender);
  9691. }
  9692. //---------------------------------------------------------------------------
  9693. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9694. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9695. {
  9696. // TODO
  9697. if (BookmarkList != NULL)
  9698. {
  9699. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9700. if (!WinConfiguration->UseLocationProfiles)
  9701. {
  9702. std::unique_ptr<TStringList> Directories(new TStringList());
  9703. Directories->CaseSensitive = (Side == osRemote);
  9704. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9705. {
  9706. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9707. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9708. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9709. {
  9710. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9711. Item->Caption = EscapeHotkey(Directory);
  9712. Item->ShortCut = Bookmark->ShortCut;
  9713. Item->OnClick = OnBookmarkClick;
  9714. Item->Tag = reinterpret_cast<int>(Bookmark);
  9715. Directories->Add(Directory);
  9716. Menu->Add(Item.release());
  9717. }
  9718. }
  9719. }
  9720. else
  9721. {
  9722. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9723. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9724. {
  9725. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9726. if (!Bookmark->Node.IsEmpty())
  9727. {
  9728. Folders->Add(Bookmark->Node);
  9729. }
  9730. }
  9731. for (int Index = 0; Index < Folders->Count; Index++)
  9732. {
  9733. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9734. Item->Caption = Folders->Strings[Index];
  9735. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction->ImageIndex;
  9736. Folders->Objects[Index] = Item.get();
  9737. Menu->Add(Item.release());
  9738. }
  9739. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9740. {
  9741. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9742. TTBCustomItem * Parent;
  9743. if (!Bookmark->Node.IsEmpty())
  9744. {
  9745. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9746. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9747. }
  9748. else
  9749. {
  9750. Parent = Menu;
  9751. }
  9752. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9753. Item->Caption = Bookmark->Name;
  9754. Item->ShortCut = Bookmark->ShortCut;
  9755. Item->OnClick = OnBookmarkClick;
  9756. Item->Tag = reinterpret_cast<int>(Bookmark);
  9757. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9758. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9759. {
  9760. // No hint for location profiles that are actually mere "bookmarks"
  9761. }
  9762. else
  9763. {
  9764. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9765. UnicodeString LongHint;
  9766. if (!Bookmark->Local.IsEmpty())
  9767. {
  9768. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9769. }
  9770. if (!Bookmark->Remote.IsEmpty())
  9771. {
  9772. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9773. }
  9774. AddToList(Hint, LongHint, L"|");
  9775. Item->Hint = Hint;
  9776. }
  9777. Parent->Add(Item.release());
  9778. }
  9779. }
  9780. AddMenuSeparator(Menu);
  9781. }
  9782. }
  9783. //---------------------------------------------------------------------------
  9784. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9785. {
  9786. Menu->Clear();
  9787. std::unique_ptr<TTBCustomItem> Item;
  9788. Item.reset(new TTBXItem(Owner));
  9789. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9790. Item->Options = Item->Options << tboDefault;
  9791. Menu->Add(Item.release());
  9792. AddMenuSeparator(Menu);
  9793. if (Terminal != NULL)
  9794. {
  9795. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9796. }
  9797. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9798. Item.reset(new TTBXItem(Owner));
  9799. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction : NonVisualDataModule->RemoteAddBookmarkAction;
  9800. Menu->Add(Item.release());
  9801. }
  9802. //---------------------------------------------------------------------------
  9803. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9804. {
  9805. bool Result = true;
  9806. try
  9807. {
  9808. if (Side == osRemote)
  9809. {
  9810. Terminal->ExceptionOnFail = true;
  9811. }
  9812. try
  9813. {
  9814. DirView(Side)->Path = Path;
  9815. }
  9816. __finally
  9817. {
  9818. if (Side == osRemote)
  9819. {
  9820. Terminal->ExceptionOnFail = false;
  9821. }
  9822. }
  9823. }
  9824. catch (Exception & E)
  9825. {
  9826. if ((Side != osRemote) || Terminal->Active)
  9827. {
  9828. ShowExtendedExceptionEx(Terminal, &E);
  9829. Result = false;
  9830. }
  9831. else
  9832. {
  9833. throw;
  9834. }
  9835. }
  9836. return Result;
  9837. }
  9838. //---------------------------------------------------------------------------
  9839. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9840. {
  9841. // Make sure there some feedback even when loading tiny local folders
  9842. TInstantOperationVisualizer Visualizer;
  9843. DirView(Side)->ReloadDirectory();
  9844. }
  9845. //---------------------------------------------------------------------------
  9846. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9847. {
  9848. if (Index == SessionsPageControl->TabIndex)
  9849. {
  9850. CloseSession();
  9851. }
  9852. else
  9853. {
  9854. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9855. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9856. TTerminalManager * Manager = TTerminalManager::Instance();
  9857. if (!Terminal->Active)
  9858. {
  9859. Manager->FreeTerminal(Terminal);
  9860. }
  9861. else
  9862. {
  9863. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9864. if (CanCloseQueue(Queue))
  9865. {
  9866. Manager->FreeTerminal(Terminal);
  9867. }
  9868. }
  9869. }
  9870. }
  9871. //---------------------------------------------------------------------------
  9872. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9873. {
  9874. CloseSessionTab(Index);
  9875. }
  9876. //---------------------------------------------------------------------------
  9877. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9878. {
  9879. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9880. {
  9881. TInstantOperationVisualizer Visualizer;
  9882. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9883. // before we create a new data object
  9884. ClipboardClear();
  9885. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9886. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9887. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9888. // Intermediate variable to WORKAROUND a crash in compiler
  9889. TObjectList * ClipboardFakeMonitors =
  9890. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9891. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9892. if (FClipboardDragDropFilesEx.get() == NULL)
  9893. {
  9894. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9895. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9896. }
  9897. FClipboardDragDropFilesEx->FileList->Clear();
  9898. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9899. FClipboardDragDropFilesEx->CopyToClipboard();
  9900. FClipboardTerminal = FTerminal;
  9901. // Need full paths, as cwd can be different once files are pasted
  9902. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9903. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9904. {
  9905. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9906. }
  9907. }
  9908. }
  9909. //---------------------------------------------------------------------------
  9910. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9911. {
  9912. if (OpenClipboard(0))
  9913. {
  9914. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9915. CloseClipboard();
  9916. }
  9917. }
  9918. //---------------------------------------------------------------------------
  9919. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9920. {
  9921. return !FClipboardFakeDirectory.IsEmpty();
  9922. }
  9923. //---------------------------------------------------------------------------
  9924. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9925. {
  9926. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9927. FClipboardFakeDirectory = UnicodeString();
  9928. FClipboardTerminal = NULL;
  9929. // Also called in Idle()
  9930. FClipboardFakeMonitors.reset(NULL);
  9931. }
  9932. //---------------------------------------------------------------------------
  9933. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9934. {
  9935. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9936. {
  9937. ClipboardStop();
  9938. }
  9939. }
  9940. //---------------------------------------------------------------------------
  9941. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9942. {
  9943. TTerminalManager * Manager = TTerminalManager::Instance();
  9944. Manager->ActiveTerminal = FClipboardTerminal;
  9945. TTransferOperationParam Params;
  9946. Params.TargetDirectory = TargetDirectory;
  9947. Params.DragDrop = DragDrop;
  9948. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  9949. }
  9950. //---------------------------------------------------------------------------
  9951. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  9952. {
  9953. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  9954. // (as it pumps a Windows message queue while being shutted down)
  9955. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  9956. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  9957. {
  9958. // Can fail as it can be e.g. locked by AV, so we retry that later
  9959. bool Removed = RemoveDir(ApiPath(FileName));
  9960. try
  9961. {
  9962. if (!NonVisualDataModule->Busy)
  9963. {
  9964. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  9965. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  9966. }
  9967. }
  9968. __finally
  9969. {
  9970. if (!Removed)
  9971. {
  9972. RemoveDir(ApiPath(FileName));
  9973. }
  9974. }
  9975. }
  9976. }
  9977. //---------------------------------------------------------------------------
  9978. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  9979. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  9980. {
  9981. TFileMasks::TParams MaskParams;
  9982. MaskParams.Size = Size;
  9983. MaskParams.Modification = Modification;
  9984. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  9985. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  9986. {
  9987. bool ImplicitMatch;
  9988. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  9989. !ImplicitMatch)
  9990. {
  9991. Color = Iter->Color;
  9992. break;
  9993. }
  9994. }
  9995. }
  9996. //---------------------------------------------------------------------------
  9997. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  9998. {
  9999. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10000. if (!DirView->IsEditing())
  10001. {
  10002. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10003. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10004. // while searching
  10005. if (Key == VK_BACK)
  10006. {
  10007. if (!FIncrementalSearch.IsEmpty())
  10008. {
  10009. if (FIncrementalSearch.Length() == 1)
  10010. {
  10011. ResetIncrementalSearch();
  10012. }
  10013. else
  10014. {
  10015. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10016. IncrementalSearch(NewText, false, false);
  10017. }
  10018. Key = 0;
  10019. }
  10020. }
  10021. }
  10022. }
  10023. //---------------------------------------------------------------------------
  10024. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10025. {
  10026. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10027. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10028. {
  10029. // Filter control sequences.
  10030. // When not searching yet, prefer use of the space for toggling file selection
  10031. // (so we cannot incrementally search for a string starting with a space).
  10032. if ((Key > VK_SPACE) ||
  10033. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10034. {
  10035. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10036. Key = 0;
  10037. }
  10038. }
  10039. }
  10040. //---------------------------------------------------------------------------
  10041. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10042. {
  10043. if (!FIncrementalSearch.IsEmpty())
  10044. {
  10045. FIncrementalSearch = L"";
  10046. DirView(osCurrent)->UpdateStatusBar();
  10047. }
  10048. }
  10049. //---------------------------------------------------------------------------
  10050. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10051. {
  10052. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10053. if (Item == NULL)
  10054. {
  10055. MessageBeep(MB_ICONHAND);
  10056. }
  10057. else
  10058. {
  10059. TCustomDirView * ADirView = DirView(osCurrent);
  10060. {
  10061. TAutoNestingCounter Guard(FIncrementalSearching);
  10062. ADirView->FocusItem(Item);
  10063. if (ADirView->NortonLike == nlOff)
  10064. {
  10065. if ((ADirView->Selected != Item) ||
  10066. (ADirView->SelCount > 1))
  10067. {
  10068. ADirView->ClearSelection();
  10069. ADirView->Selected = Item;
  10070. }
  10071. }
  10072. }
  10073. FIncrementalSearch = Text;
  10074. Item->MakeVisible(false);
  10075. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10076. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10077. ADirView->UpdateStatusBar();
  10078. }
  10079. }
  10080. //---------------------------------------------------------------------------
  10081. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10082. {
  10083. int Index = Item->Index;
  10084. if (!Reverse)
  10085. {
  10086. Index++;
  10087. if (Index >= Item->Owner->Count)
  10088. {
  10089. Index = 0;
  10090. }
  10091. }
  10092. else
  10093. {
  10094. Index--;
  10095. if (Index < 0)
  10096. {
  10097. Index = Item->Owner->Count - 1;
  10098. }
  10099. }
  10100. return Item->Owner->Item[Index];
  10101. }
  10102. //---------------------------------------------------------------------------
  10103. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10104. {
  10105. TCustomDirView * ADirView = DirView(osCurrent);
  10106. if (ADirView->Items->Count == 0)
  10107. {
  10108. return NULL;
  10109. }
  10110. else
  10111. {
  10112. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10113. TListItem * Item = CurrentItem;
  10114. if (SkipCurrent)
  10115. {
  10116. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10117. }
  10118. while (true)
  10119. {
  10120. bool Matches = false;
  10121. switch (WinConfiguration->PanelSearch)
  10122. {
  10123. case isNameStartOnly:
  10124. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10125. break;
  10126. case isName:
  10127. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10128. break;
  10129. case isAll:
  10130. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10131. int Index = 0;
  10132. while ((Index < ColCount) && !Matches)
  10133. {
  10134. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10135. if (Visible)
  10136. {
  10137. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10138. }
  10139. Index++;
  10140. }
  10141. break;
  10142. }
  10143. if (Matches)
  10144. {
  10145. return Item;
  10146. }
  10147. Item = GetNextFile(Item, Reverse);
  10148. if (Item == CurrentItem)
  10149. {
  10150. return NULL;
  10151. }
  10152. }
  10153. }
  10154. }
  10155. //---------------------------------------------------------------------------
  10156. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10157. {
  10158. ResetIncrementalSearch();
  10159. }
  10160. //---------------------------------------------------------------------------
  10161. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10162. {
  10163. if (Message.CharCode == VK_TAB)
  10164. {
  10165. if (!FIncrementalSearch.IsEmpty())
  10166. {
  10167. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10168. bool Reverse = Shift.Contains(ssShift);
  10169. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10170. Message.Result = 1;
  10171. return;
  10172. }
  10173. }
  10174. else if (Message.CharCode == VK_ESCAPE)
  10175. {
  10176. if (!FIncrementalSearch.IsEmpty())
  10177. {
  10178. ResetIncrementalSearch();
  10179. Message.Result = 1;
  10180. return;
  10181. }
  10182. }
  10183. TForm::Dispatch(&Message);
  10184. }
  10185. //---------------------------------------------------------------------------
  10186. void __fastcall TCustomScpExplorerForm::Deactivate()
  10187. {
  10188. TForm::Deactivate();
  10189. // E.g. when switching to an internal editor window
  10190. ResetIncrementalSearch();
  10191. }
  10192. //---------------------------------------------------------------------------
  10193. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10194. {
  10195. // When switching to another application
  10196. ResetIncrementalSearch();
  10197. }
  10198. //---------------------------------------------------------------------------
  10199. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10200. {
  10201. ResetIncrementalSearch();
  10202. }
  10203. //---------------------------------------------------------------------------
  10204. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10205. {
  10206. if (FIncrementalSearching <= 0)
  10207. {
  10208. ResetIncrementalSearch();
  10209. }
  10210. }
  10211. //---------------------------------------------------------------------------
  10212. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10213. {
  10214. CountClicksForWindowPrint(this);
  10215. }
  10216. //---------------------------------------------------------------------------
  10217. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10218. {
  10219. CenterReconnectToolbar();
  10220. }
  10221. //---------------------------------------------------------------------------
  10222. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10223. {
  10224. if (RemoteDirView->ItemFocused != NULL)
  10225. {
  10226. RemoteDirView->ItemFocused->Selected = true;
  10227. }
  10228. }
  10229. //---------------------------------------------------------------------------
  10230. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10231. {
  10232. if (!FQueueStatusUpdating)
  10233. {
  10234. bool Refresh;
  10235. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10236. {
  10237. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10238. }
  10239. else
  10240. {
  10241. if (FQueueFileList->GetCount() > 0)
  10242. {
  10243. FQueueFileList->Clear();
  10244. Refresh = true;
  10245. }
  10246. }
  10247. int Count = FQueueFileList->GetCount();
  10248. if (QueueFileList->Items->Count != Count)
  10249. {
  10250. DebugAssert(Refresh);
  10251. QueueFileList->Items->Count = Count;
  10252. }
  10253. if (Refresh)
  10254. {
  10255. QueueFileList->Invalidate();
  10256. }
  10257. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10258. }
  10259. }
  10260. //---------------------------------------------------------------------------
  10261. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10262. {
  10263. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10264. }
  10265. //---------------------------------------------------------------------------
  10266. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10267. {
  10268. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10269. // See TSynchronizeChecklistDialog::UpdateTimer
  10270. if (QueueFileList->Items->Count > 0)
  10271. {
  10272. QueueFileList->Items->Item[0]->MakeVisible(false);
  10273. }
  10274. UpdateQueueFileList();
  10275. }
  10276. //---------------------------------------------------------------------------
  10277. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10278. {
  10279. Active = QueueView3->Focused() || QueueFileList->Focused();
  10280. }
  10281. //---------------------------------------------------------------------------
  10282. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10283. {
  10284. QueueLabelUpdateStatus();
  10285. }
  10286. //---------------------------------------------------------------------------
  10287. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10288. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10289. {
  10290. int State = FQueueFileList->GetState(Item->Index);
  10291. if (State == qfsProcessed)
  10292. {
  10293. Sender->Canvas->Font->Color = clGrayText;
  10294. }
  10295. }
  10296. //---------------------------------------------------------------------------
  10297. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10298. {
  10299. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10300. QueueFileList->Column[0]->Width =
  10301. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10302. }
  10303. //---------------------------------------------------------------------------
  10304. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10305. {
  10306. QueueFileListColumnAutoSize();
  10307. }
  10308. //---------------------------------------------------------------------------
  10309. void __fastcall TCustomScpExplorerForm::CloseApp()
  10310. {
  10311. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10312. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10313. // So we clear the flag here.
  10314. DebugAssert(NonVisualDataModule->Busy);
  10315. NonVisualDataModule->EndBusy();
  10316. try
  10317. {
  10318. Close();
  10319. }
  10320. __finally
  10321. {
  10322. NonVisualDataModule->StartBusy();
  10323. }
  10324. }
  10325. //---------------------------------------------------------------------------
  10326. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10327. {
  10328. return (Terminal != NULL) && Terminal->Active;
  10329. }
  10330. //---------------------------------------------------------------------------
  10331. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10332. {
  10333. return IsActiveTerminal(Terminal);
  10334. }