CustomScpExplorer.cpp 359 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927
  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. Terminal->SessionData->IsSameSite(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 ((Terminal != NULL) && Terminal->Active &&
  362. CanCommandLineFromAnotherInstance() &&
  363. (Session.IsEmpty() || Terminal->SessionData->IsSameSite(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. (Terminal != NULL) &&
  425. Terminal->Active &&
  426. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  427. }
  428. //---------------------------------------------------------------------------
  429. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  430. {
  431. bool Result = Visible && !NonVisualDataModule->Busy;
  432. return Result;
  433. }
  434. //---------------------------------------------------------------------------
  435. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  436. const UnicodeString & CommandLine)
  437. {
  438. TProgramParams Params(CommandLine);
  439. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  440. if (Result)
  441. {
  442. NonVisualDataModule->StartBusy();
  443. try
  444. {
  445. // this action is initiated from another process,
  446. // so it's likely that our window is not visible,
  447. // and user won't see what is going on
  448. Application->BringToFront();
  449. // reload sessions as we may be asked to open a session
  450. // just stored by another instance
  451. StoredSessions->Reload();
  452. UnicodeString SessionName = Params.Param[1];
  453. std::unique_ptr<TObjectList> DataList(new TObjectList());
  454. UnicodeString DownloadFile; // unused
  455. try
  456. {
  457. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  458. }
  459. catch (EAbort &)
  460. {
  461. // Happens when opening session in PuTTY and in other situations,
  462. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  463. // to process the command-line on its own (or to pass it to yet another instance)
  464. }
  465. if (DataList->Count > 0)
  466. {
  467. TTerminalManager * Manager = TTerminalManager::Instance();
  468. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  469. }
  470. }
  471. __finally
  472. {
  473. NonVisualDataModule->EndBusy();
  474. }
  475. }
  476. return Result;
  477. }
  478. //---------------------------------------------------------------------------
  479. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  480. {
  481. if (FTerminal != value)
  482. {
  483. TerminalChanging();
  484. DoSetTerminal(value, false);
  485. }
  486. }
  487. //---------------------------------------------------------------------------
  488. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  489. {
  490. FTerminal = value;
  491. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  492. FAllowTransferPresetAutoSelect = false;
  493. try
  494. {
  495. TerminalChanged(Replace);
  496. }
  497. __finally
  498. {
  499. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  500. }
  501. if (Terminal != NULL)
  502. {
  503. TransferPresetAutoSelect();
  504. }
  505. }
  506. //---------------------------------------------------------------------------
  507. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  508. {
  509. DoSetTerminal(value, true);
  510. }
  511. //---------------------------------------------------------------------------
  512. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  513. {
  514. if (FTerminal != NULL)
  515. {
  516. UpdateTerminal(Terminal);
  517. }
  518. }
  519. //---------------------------------------------------------------------------
  520. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  521. {
  522. if (Terminal != NULL)
  523. {
  524. UpdateSessionColor((TColor)Terminal->StateData->Color);
  525. }
  526. DoTerminalListChanged();
  527. DebugAssert(!IsLocalBrowserMode()); // TODO
  528. if (Replaced)
  529. {
  530. RemoteDirView->ReplaceTerminal(Terminal);
  531. }
  532. else
  533. {
  534. RemoteDirView->Terminal = Terminal;
  535. }
  536. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  537. if (Terminal != NULL)
  538. {
  539. if (Terminal->Active)
  540. {
  541. Terminal->RefreshDirectory();
  542. }
  543. if (WinConfiguration->PreservePanelState)
  544. {
  545. if (Terminal->RemoteExplorerState != NULL)
  546. {
  547. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  548. }
  549. else
  550. {
  551. DirView(osRemote)->ClearState();
  552. }
  553. }
  554. if (!Replaced && Terminal->Active)
  555. {
  556. InitStatusBar();
  557. }
  558. }
  559. UpdateTransferList();
  560. // Update panels Enable state before refreshing the labels
  561. UpdateControls();
  562. }
  563. //---------------------------------------------------------------------------
  564. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  565. {
  566. if (Queue != value)
  567. {
  568. if (FQueue != NULL)
  569. {
  570. FQueue->OnListUpdate = NULL;
  571. FQueue->OnQueueItemUpdate = NULL;
  572. }
  573. FQueue = value;
  574. if (FQueue != NULL)
  575. {
  576. DebugAssert(FQueue->OnListUpdate == NULL);
  577. FQueue->OnListUpdate = QueueListUpdate;
  578. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  579. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  580. }
  581. QueueChanged();
  582. }
  583. }
  584. //---------------------------------------------------------------------------
  585. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  586. TListItem * Item)
  587. {
  588. if (FQueueActedItem == Item)
  589. {
  590. FQueueActedItem = NULL;
  591. if ((QueueView3->PopupMenu != NULL) &&
  592. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  593. {
  594. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  595. ReleaseCapture();
  596. }
  597. }
  598. if (Item->Data == FPendingQueueActionItem)
  599. {
  600. FPendingQueueActionItem = NULL;
  601. }
  602. }
  603. //---------------------------------------------------------------------------
  604. bool TCustomScpExplorerForm::IsAnythingQueued()
  605. {
  606. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  607. }
  608. //---------------------------------------------------------------------------
  609. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  610. {
  611. {
  612. TGuard Guard(FQueueStatusSection);
  613. FQueueStatusInvalidated = false;
  614. if (FQueue != NULL)
  615. {
  616. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  617. }
  618. }
  619. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  620. {
  621. FMaxQueueLength = FQueueStatus->Count;
  622. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  623. }
  624. {
  625. TAutoFlag Flag(FQueueStatusUpdating);
  626. FQueueController->UpdateQueueStatus(FQueueStatus);
  627. }
  628. UpdateQueueFileList();
  629. SetQueueProgress();
  630. UpdateQueueView();
  631. bool IsEmpty = !IsAnythingQueued();
  632. if (IsEmpty && (Terminal != NULL))
  633. {
  634. TOnceDoneOperation OnceDoneOperation =
  635. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  636. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  637. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  638. {
  639. FQueue->Enabled = false;
  640. }
  641. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  642. {
  643. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  644. }
  645. }
  646. }
  647. //---------------------------------------------------------------------------
  648. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  649. {
  650. UnicodeString Result;
  651. if (FQueueStatus != NULL)
  652. {
  653. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  654. {
  655. TFileOperationProgressType * ProgressData =
  656. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  657. if ((ProgressData != NULL) && ProgressData->InProgress)
  658. {
  659. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  660. }
  661. }
  662. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  663. {
  664. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  665. }
  666. }
  667. return Result;
  668. }
  669. //---------------------------------------------------------------------------
  670. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  671. {
  672. ComponentVisible[fcQueueView] =
  673. (WinConfiguration->QueueView.Show == qvShow) ||
  674. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  675. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  676. }
  677. //---------------------------------------------------------------------------
  678. void __fastcall TCustomScpExplorerForm::QueueChanged()
  679. {
  680. if (FQueueStatus != NULL)
  681. {
  682. // UpdateFileList implementation relies on the status being recreated when session changes
  683. delete FQueueStatus;
  684. FQueueStatus = NULL;
  685. }
  686. UpdateQueueStatus(true);
  687. }
  688. //---------------------------------------------------------------------------
  689. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  690. {
  691. if (FQueue == Queue)
  692. {
  693. FQueueStatusInvalidated = true;
  694. }
  695. }
  696. //---------------------------------------------------------------------------
  697. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  698. TQueueItem * Item)
  699. {
  700. if (FQueue == Queue)
  701. {
  702. TGuard Guard(FQueueStatusSection);
  703. // this may be running in parallel with QueueChanged
  704. if (FQueueStatus != NULL)
  705. {
  706. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  707. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  708. {
  709. FRefreshLocalDirectory = (QueueItem == NULL) ||
  710. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  711. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  712. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  713. }
  714. if (QueueItem != NULL)
  715. {
  716. QueueItem->UserData = (void*)true;
  717. FQueueItemInvalidated = true;
  718. }
  719. }
  720. }
  721. }
  722. //---------------------------------------------------------------------------
  723. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  724. {
  725. // during standalone editing, we have no way to see/control queue,
  726. // so we have to always popup prompts automatically
  727. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  728. }
  729. //---------------------------------------------------------------------------
  730. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  731. {
  732. if (FQueueStatus != NULL)
  733. {
  734. bool QueueAutoPopup = IsQueueAutoPopup();
  735. bool NeedRefresh = FQueueController->NeedRefresh();
  736. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  737. FQueueItemInvalidated = false;
  738. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  739. bool Updated = false;
  740. TQueueItemProxy * QueueItem;
  741. bool WasUserAction;
  742. for (int Index = 0; Index < Limit; Index++)
  743. {
  744. bool Update = false;
  745. QueueItem = FQueueStatus->Items[Index];
  746. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  747. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  748. (FPendingQueueActionItem == NULL))
  749. {
  750. FPendingQueueActionItem = QueueItem;
  751. FUserActionTimer->Enabled = true;
  752. }
  753. if ((bool)QueueItem->UserData)
  754. {
  755. QueueItem->UserData = (void*)false;
  756. QueueItem->Update();
  757. Updated = true;
  758. Update = true;
  759. }
  760. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  761. {
  762. Update = true;
  763. }
  764. if (Update)
  765. {
  766. FQueueController->RefreshQueueItem(QueueItem);
  767. }
  768. }
  769. if (Updated)
  770. {
  771. NonVisualDataModule->UpdateNonVisibleActions();
  772. SetQueueProgress();
  773. UpdateQueueFileList();
  774. }
  775. }
  776. }
  777. //---------------------------------------------------------------------------
  778. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  779. {
  780. if (FTaskbarList != NULL)
  781. {
  782. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  783. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  784. }
  785. }
  786. //---------------------------------------------------------------------------
  787. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  788. {
  789. if (Progress >= 0)
  790. {
  791. if (FTaskbarList != NULL)
  792. {
  793. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  794. }
  795. }
  796. else
  797. {
  798. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  799. }
  800. }
  801. //---------------------------------------------------------------------------
  802. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  803. {
  804. int OverallProgress;
  805. // FProgressForm is null when this is called from SetQueueProgress
  806. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  807. {
  808. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  809. }
  810. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  811. {
  812. OverallProgress = ProgressData->OverallProgress();
  813. }
  814. else
  815. {
  816. OverallProgress = -1;
  817. }
  818. SetTaskbarListProgressValue(OverallProgress);
  819. }
  820. //---------------------------------------------------------------------------
  821. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  822. {
  823. TTerminalManager::Instance()->QueueStatusUpdated();
  824. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  825. {
  826. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  827. {
  828. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  829. {
  830. TFileOperationProgressType * ProgressData = NULL;
  831. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  832. {
  833. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  834. }
  835. if ((ProgressData != NULL) &&
  836. ProgressData->InProgress)
  837. {
  838. SetTaskbarListProgressValue(ProgressData);
  839. }
  840. else
  841. {
  842. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  843. }
  844. }
  845. else
  846. {
  847. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  848. }
  849. }
  850. else
  851. {
  852. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  853. }
  854. }
  855. UpdateQueueLabel();
  856. }
  857. //---------------------------------------------------------------------------
  858. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  859. {
  860. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  861. if (FQueueStatus != NULL)
  862. {
  863. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  864. if (ActiveAndPendingPrimaryCount > 0)
  865. {
  866. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  867. }
  868. }
  869. QueueLabel->Caption = Caption;
  870. }
  871. //---------------------------------------------------------------------------
  872. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  873. {
  874. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  875. static_cast<TComponent*>(GetComponent(fcTransferList)));
  876. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  877. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  878. TransferList->Strings->BeginUpdate();
  879. try
  880. {
  881. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  882. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  883. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  884. if (FTransferDropDownHint.IsEmpty())
  885. {
  886. FTransferDropDownHint = TransferDropDown->Hint;
  887. }
  888. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  889. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  890. TransferDropDown->Text = StripHotkey(Name);
  891. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  892. (FTransferDropDownHint, StripHotkey(Name),
  893. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  894. FLAGMASK(((Terminal != NULL) && Terminal->Active), Terminal->UsableCopyParamAttrs(0).General))));
  895. // update the label, otherwise when it is updated only on the first draw
  896. // of the list, it is drawn "bold" for some reason
  897. FTransferListHoverIndex = TransferList->ItemIndex;
  898. UpdateTransferLabel();
  899. }
  900. __finally
  901. {
  902. TransferList->Strings->EndUpdate();
  903. }
  904. }
  905. //---------------------------------------------------------------------------
  906. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  907. {
  908. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  909. DebugAssert(Toolbar != NULL);
  910. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  911. }
  912. //---------------------------------------------------------------------------
  913. void __fastcall TCustomScpExplorerForm::UpdateActions()
  914. {
  915. TForm::UpdateActions();
  916. if (ComponentVisible[fcCustomCommandsBand])
  917. {
  918. UpdateCustomCommandsToolbar();
  919. }
  920. }
  921. //---------------------------------------------------------------------------
  922. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  923. {
  924. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  925. }
  926. //---------------------------------------------------------------------------
  927. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  928. {
  929. Color = GetBtnFaceColor();
  930. DebugAssert(Configuration && RemoteDirView);
  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->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  943. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  944. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  945. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  946. UpdateSessionsPageControlHeight();
  947. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  948. UpdateToolbarDisplayMode();
  949. UpdateTransferList();
  950. if (Terminal != NULL)
  951. {
  952. TransferPresetAutoSelect();
  953. }
  954. UpdateQueueView();
  955. UpdateControls();
  956. // this can be called even before constuctor finishes.
  957. if (FEditorManager != NULL)
  958. {
  959. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  960. }
  961. // this can be called even before constuctor finishes.
  962. if (FLocalEditors != NULL)
  963. {
  964. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  965. {
  966. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  967. }
  968. }
  969. if (ComponentVisible[fcCustomCommandsBand])
  970. {
  971. UpdateCustomCommandsToolbar();
  972. }
  973. // show only when keeping queue items forever,
  974. // otherwise, its enough to have in in the context menu
  975. QueueDeleteAllDoneQueueToolbarItem->Visible =
  976. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  977. if (FFileColorsCurrent != WinConfiguration->FileColors)
  978. {
  979. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  980. FFileColorsCurrent = WinConfiguration->FileColors;
  981. FileColorsChanged();
  982. }
  983. }
  984. //---------------------------------------------------------------------------
  985. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  986. {
  987. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  988. DirView->Invalidate();
  989. }
  990. //---------------------------------------------------------------------------
  991. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  992. {
  993. DoFileColorsChanged(RemoteDirView);
  994. }
  995. //---------------------------------------------------------------------------
  996. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  997. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  998. void * /*Arg*/)
  999. {
  1000. if (Token != NULL)
  1001. {
  1002. TForm * Editor = dynamic_cast<TForm*>(Token);
  1003. DebugAssert(Editor != NULL);
  1004. ReconfigureEditorForm(Editor);
  1005. }
  1006. }
  1007. //---------------------------------------------------------------------------
  1008. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1009. {
  1010. WinConfiguration->DDTransferConfirmation = asOn;
  1011. }
  1012. //---------------------------------------------------------------------------
  1013. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1014. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1015. {
  1016. // noop
  1017. }
  1018. //---------------------------------------------------------------------------
  1019. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1020. TTransferDirection Direction, TTransferType Type, bool Temp,
  1021. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1022. bool Confirm, bool DragDrop, int Options)
  1023. {
  1024. bool Result = true;
  1025. DebugAssert(Terminal && Terminal->Active);
  1026. // these parameters are known in advance
  1027. int Params =
  1028. FLAGMASK(Type == ttMove, cpDelete);
  1029. bool ToTemp = (Temp && (Direction == tdToLocal));
  1030. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1031. {
  1032. bool DisableNewerOnly =
  1033. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1034. ToTemp;
  1035. Options |=
  1036. FLAGMASK(ToTemp, coTemp) |
  1037. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1038. coDoNotShowAgain;
  1039. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1040. int CopyParamAttrs = (Direction == tdToRemote ?
  1041. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1042. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1043. int OutputOptions =
  1044. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1045. cooDoNotShowAgain);
  1046. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1047. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1048. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1049. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1050. if (Result)
  1051. {
  1052. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1053. {
  1054. if (DragDrop)
  1055. {
  1056. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1057. {
  1058. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1059. NULL, 0, EnableDDTransferConfirmation, NULL);
  1060. }
  1061. WinConfiguration->DDTransferConfirmation = asOff;
  1062. }
  1063. else
  1064. {
  1065. WinConfiguration->ConfirmTransferring = false;
  1066. }
  1067. }
  1068. else
  1069. {
  1070. // User explicitly unchecked "do not show again",
  1071. // so show him the dialog the next time
  1072. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1073. {
  1074. WinConfiguration->DDTransferConfirmation = asOn;
  1075. }
  1076. }
  1077. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1078. }
  1079. }
  1080. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1081. {
  1082. Configuration->Usage->Inc(L"TransfersOnBackground");
  1083. // these parameter are known only after transfer dialog
  1084. Params |=
  1085. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1086. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1087. Result = false;
  1088. ClearTransferSourceSelection(Direction);
  1089. }
  1090. return Result;
  1091. }
  1092. //---------------------------------------------------------------------------
  1093. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1094. {
  1095. if (FOnFileOperationFinished != NULL)
  1096. {
  1097. FOnFileOperationFinished(UnicodeString(), true);
  1098. }
  1099. else
  1100. {
  1101. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1102. if (HasDirView[Side])
  1103. {
  1104. DirView(Side)->SelectAll(smNone);
  1105. }
  1106. }
  1107. }
  1108. //---------------------------------------------------------------------------
  1109. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1110. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1111. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1112. int Params)
  1113. {
  1114. DebugAssert(Queue != NULL);
  1115. bool SingleFile = false;
  1116. if (FileList->Count == 1)
  1117. {
  1118. if (Direction == tdToRemote)
  1119. {
  1120. UnicodeString FileName = FileList->Strings[0];
  1121. SingleFile = FileExists(ApiPath(FileName));
  1122. }
  1123. else
  1124. {
  1125. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1126. SingleFile = !File->IsDirectory;
  1127. }
  1128. }
  1129. TQueueItem * QueueItem;
  1130. if (Direction == tdToRemote)
  1131. {
  1132. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1133. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1134. }
  1135. else
  1136. {
  1137. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1138. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1139. }
  1140. AddQueueItem(Queue, QueueItem, Terminal);
  1141. }
  1142. //---------------------------------------------------------------------------
  1143. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1144. {
  1145. if (Queue->IsEmpty)
  1146. {
  1147. Terminal->QueueOperationStart = Now();
  1148. }
  1149. Queue->AddItem(QueueItem);
  1150. }
  1151. //---------------------------------------------------------------------------
  1152. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1153. {
  1154. }
  1155. //---------------------------------------------------------------------------
  1156. void __fastcall TCustomScpExplorerForm::InitControls()
  1157. {
  1158. DebugAssert(FDocks != NULL);
  1159. for (int Index = 0; Index < ComponentCount; Index++)
  1160. {
  1161. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1162. if ((Dock != NULL) && (Dock->Tag == 0))
  1163. {
  1164. FDocks->Add(Dock);
  1165. }
  1166. }
  1167. CollectItemsWithTextDisplayMode(this);
  1168. }
  1169. //---------------------------------------------------------------------------
  1170. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1171. {
  1172. ConfigurationChanged();
  1173. QueuePanel->Height =
  1174. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1175. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1176. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1177. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1178. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1179. QueueFileList->Height =
  1180. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1181. if (QueueFileList->Visible)
  1182. {
  1183. AdjustQueueLayout();
  1184. }
  1185. UpdateCustomCommandsToolbar();
  1186. }
  1187. //---------------------------------------------------------------------------
  1188. void __fastcall TCustomScpExplorerForm::StoreParams()
  1189. {
  1190. int APixelsPerInch = GetControlPixelsPerInch(this);
  1191. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1192. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1193. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1194. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1195. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1196. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1197. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1198. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1199. }
  1200. //---------------------------------------------------------------------------
  1201. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1202. {
  1203. if (!FFormRestored)
  1204. {
  1205. FFormRestored = true;
  1206. RestoreFormParams();
  1207. }
  1208. TForm::CreateParams(Params);
  1209. }
  1210. //---------------------------------------------------------------------------
  1211. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1212. {
  1213. DebugAssert(FDocks != NULL);
  1214. for (int Index = 0; Index < FDocks->Count; Index++)
  1215. {
  1216. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1217. }
  1218. }
  1219. //---------------------------------------------------------------------------
  1220. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1221. {
  1222. SetDockAllowDrag(true);
  1223. while (!ButtonsStr.IsEmpty())
  1224. {
  1225. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1226. UnicodeString Name = CutToChar(S, L'=', true);
  1227. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1228. {
  1229. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1230. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1231. {
  1232. while (!S.IsEmpty())
  1233. {
  1234. UnicodeString S2 = CutToChar(S, L',', true);
  1235. UnicodeString Name = CutToChar(S2, L':', true);
  1236. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1237. {
  1238. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1239. if (SameText(GetToolbarItemName(Item), Name))
  1240. {
  1241. // forward compatibility
  1242. UnicodeString S3 = CutToChar(S2, L':', true);
  1243. bool Visible = StrToIntDef(S3, 0);
  1244. Item->Visible = Visible;
  1245. }
  1246. }
  1247. }
  1248. }
  1249. }
  1250. }
  1251. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1252. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1253. }
  1254. //---------------------------------------------------------------------------
  1255. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1256. {
  1257. UnicodeString Result;
  1258. SetDockAllowDrag(true);
  1259. Result = ::GetToolbarsLayoutStr(this);
  1260. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1261. return Result;
  1262. }
  1263. //---------------------------------------------------------------------------
  1264. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1265. {
  1266. UnicodeString Result;
  1267. if (Item->Action != NULL)
  1268. {
  1269. Result = Item->Action->Name;
  1270. Result = RemoveSuffix(Result, L"Action");
  1271. }
  1272. else
  1273. {
  1274. Result = Item->Name;
  1275. Result = RemoveSuffix(Result, L"SubmenuItem");
  1276. Result = RemoveSuffix(Result, L"Item");
  1277. }
  1278. return Result;
  1279. }
  1280. //---------------------------------------------------------------------------
  1281. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1282. {
  1283. UnicodeString Result;
  1284. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1285. {
  1286. UnicodeString ToolbarStr;
  1287. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1288. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1289. {
  1290. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1291. {
  1292. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1293. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1294. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1295. // and save the changes here only.
  1296. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1297. {
  1298. UnicodeString Name = GetToolbarItemName(Item);
  1299. DebugAssert(Name.Pos(L"TBX") == 0);
  1300. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1301. }
  1302. }
  1303. }
  1304. if (!ToolbarStr.IsEmpty())
  1305. {
  1306. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1307. }
  1308. }
  1309. return Result;
  1310. }
  1311. //---------------------------------------------------------------------------
  1312. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1313. {
  1314. DebugAssert(FProgressForm == NULL);
  1315. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1316. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1317. FProgressForm->DeleteLocalToRecycleBin =
  1318. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1319. FProgressForm->DeleteRemoteToRecycleBin =
  1320. (Terminal != NULL) &&
  1321. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1322. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1323. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1324. LockWindow();
  1325. // Actually, do not know what hides the progress once the operation finishes
  1326. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1327. SetTaskbarListProgressState(TBPF_NORMAL);
  1328. }
  1329. //---------------------------------------------------------------------------
  1330. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1331. {
  1332. UnlockWindow();
  1333. SAFE_DESTROY(FProgressForm);
  1334. SetQueueProgress();
  1335. }
  1336. //---------------------------------------------------------------------------
  1337. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1338. TFileOperationProgressType & ProgressData)
  1339. {
  1340. // Download to temporary local directory
  1341. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1342. {
  1343. bool Continue = true;
  1344. FPendingTempSpaceWarn = false;
  1345. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1346. if (!Continue)
  1347. {
  1348. Abort();
  1349. }
  1350. }
  1351. // operation is being executed and we still didn't show up progress form
  1352. if (ProgressData.InProgress && !FProgressForm)
  1353. {
  1354. CreateProgressForm(NULL);
  1355. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1356. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1357. }
  1358. // operation is finished (or terminated), so we hide progress form
  1359. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1360. {
  1361. DestroyProgressForm();
  1362. if (ProgressData.Operation == foCalculateSize)
  1363. {
  1364. // When calculating size before transfer, the abort caused by
  1365. // cancel flag set due to "MoveToQueue" below,
  1366. // is not propagated back to us in ExecuteFileOperation,
  1367. // as it is silently swallowed.
  1368. // So we explicitly (re)throw it here.
  1369. if (FMoveToQueue)
  1370. {
  1371. Abort();
  1372. }
  1373. }
  1374. else
  1375. {
  1376. if ((ProgressData.Cancel == csContinue) &&
  1377. !FAutoOperation)
  1378. {
  1379. OperationComplete(ProgressData.StartTime);
  1380. }
  1381. }
  1382. }
  1383. if (FProgressForm &&
  1384. // Can happen only during synchronization, when ending one of the operations
  1385. ProgressData.InProgress)
  1386. {
  1387. FProgressForm->SetProgressData(ProgressData);
  1388. DebugAssert(ProgressData.InProgress);
  1389. SetTaskbarListProgressValue(&ProgressData);
  1390. if (FProgressForm->Cancel > csContinue)
  1391. {
  1392. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1393. if (FProgressForm->Cancel == csCancelFile)
  1394. {
  1395. FProgressForm->ClearCancel();
  1396. }
  1397. // cancel cancels even the move
  1398. FMoveToQueue = false;
  1399. }
  1400. else if (FProgressForm->MoveToQueue)
  1401. {
  1402. FMoveToQueue = true;
  1403. ProgressData.SetCancelAtLeast(csCancel);
  1404. }
  1405. if ((FTransferResumeList != NULL) &&
  1406. ProgressData.InProgress &&
  1407. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1408. !ProgressData.FullFileName.IsEmpty())
  1409. {
  1410. if ((FTransferResumeList->Count == 0) ||
  1411. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1412. {
  1413. // note that we do not recognize directories from files here
  1414. FTransferResumeList->Add(ProgressData.FullFileName);
  1415. }
  1416. }
  1417. }
  1418. }
  1419. //---------------------------------------------------------------------------
  1420. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1421. const TDateTime & StartTime)
  1422. {
  1423. if (GUIConfiguration->BeepOnFinish &&
  1424. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1425. {
  1426. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1427. DWORD Sound;
  1428. if (!ExtractFileExt(BeepSound).IsEmpty())
  1429. {
  1430. Sound = SND_FILENAME;
  1431. }
  1432. else
  1433. {
  1434. Sound = SND_ALIAS;
  1435. }
  1436. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1437. }
  1438. }
  1439. //---------------------------------------------------------------------------
  1440. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1441. TFileOperationProgressType & ProgressData)
  1442. {
  1443. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1444. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1445. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1446. FileOperationProgress(ProgressData);
  1447. }
  1448. //---------------------------------------------------------------------------
  1449. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1450. {
  1451. UnicodeString Result;
  1452. if (FProgressForm != NULL)
  1453. {
  1454. Result = FProgressForm->ProgressStr();
  1455. }
  1456. return Result;
  1457. }
  1458. //---------------------------------------------------------------------------
  1459. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1460. bool DragDrop)
  1461. {
  1462. return (!DragDrop && (DropSourceControl == NULL)) ||
  1463. (DropSourceControl == DirView(osOther));
  1464. }
  1465. //---------------------------------------------------------------------------
  1466. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1467. TFileOperation Operation, TOperationSide Side,
  1468. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1469. TOnceDoneOperation & OnceDoneOperation)
  1470. {
  1471. if (!FAutoOperation)
  1472. {
  1473. // no selection on "/upload", form servers only as event handler
  1474. // (it is not displayed)
  1475. if (PanelOperation(Side, FDragDropOperation) &&
  1476. Visible && (Operation != foCalculateSize) &&
  1477. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1478. {
  1479. if (FOnFileOperationFinished != NULL)
  1480. {
  1481. FOnFileOperationFinished(FileName, Success);
  1482. }
  1483. else
  1484. {
  1485. TCustomDirView * DView = DirView(Side);
  1486. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(Side));
  1487. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1488. // this can happen when local drive is unplugged in the middle of the operation
  1489. if (Item != NULL)
  1490. {
  1491. if (Success) Item->Selected = false;
  1492. DView->MakeProgressVisible(Item);
  1493. }
  1494. }
  1495. }
  1496. if ((Operation == foCopy) || (Operation == foMove))
  1497. {
  1498. DebugAssert(!IsLocalBrowserMode()); // TODO
  1499. if (Side == osLocal)
  1500. {
  1501. Configuration->Usage->Inc(L"UploadedFiles");
  1502. }
  1503. else
  1504. {
  1505. Configuration->Usage->Inc(L"DownloadedFiles");
  1506. }
  1507. }
  1508. }
  1509. if (Success && (FSynchronizeController != NULL))
  1510. {
  1511. DebugAssert(!IsSideLocalBrowser(osRemote));
  1512. if (Operation == foCopy)
  1513. {
  1514. DebugAssert(Side == osLocal);
  1515. FSynchronizeController->LogOperation(soUpload, FileName);
  1516. }
  1517. else if (Operation == foDelete)
  1518. {
  1519. DebugAssert(Side == osRemote);
  1520. FSynchronizeController->LogOperation(soDelete, FileName);
  1521. }
  1522. }
  1523. if (FProgressForm)
  1524. {
  1525. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1526. }
  1527. }
  1528. //---------------------------------------------------------------------------
  1529. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1530. TFileOperation Operation, TOperationSide Side,
  1531. bool Temp, const UnicodeString & FileName, Boolean Success,
  1532. TOnceDoneOperation & OnceDoneOperation)
  1533. {
  1534. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1535. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1536. OnceDoneOperation);
  1537. }
  1538. //---------------------------------------------------------------------------
  1539. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1540. {
  1541. return false;
  1542. }
  1543. //---------------------------------------------------------------------------
  1544. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1545. {
  1546. return false;
  1547. }
  1548. //---------------------------------------------------------------------------
  1549. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1550. {
  1551. return NULL;
  1552. }
  1553. //---------------------------------------------------------------------------
  1554. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1555. {
  1556. DebugAssert(GetSide(Side) == osRemote);
  1557. DebugUsedParam(Side);
  1558. return RemoteDirView;
  1559. }
  1560. //---------------------------------------------------------------------------
  1561. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1562. {
  1563. DebugAssert(GetSide(Side) == osRemote);
  1564. DebugUsedParam(Side);
  1565. return RemoteDriveView;
  1566. }
  1567. //---------------------------------------------------------------------------
  1568. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1569. {
  1570. DebugAssert(GetSide(Side) == osRemote);
  1571. DebugUsedParam(Side);
  1572. return (Terminal != NULL) && Terminal->Active;
  1573. }
  1574. //---------------------------------------------------------------------------
  1575. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1576. TOperationSide Side, int FilesOnly)
  1577. {
  1578. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1579. }
  1580. //---------------------------------------------------------------------------
  1581. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1582. TOperationSide Side, int FilesOnly)
  1583. {
  1584. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1585. }
  1586. //---------------------------------------------------------------------------
  1587. struct THistoryItemData
  1588. {
  1589. short int Side;
  1590. short int Index;
  1591. };
  1592. //---------------------------------------------------------------------------
  1593. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1594. {
  1595. DirView(Side)->HistoryGo(Index);
  1596. }
  1597. //---------------------------------------------------------------------------
  1598. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1599. {
  1600. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1601. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1602. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1603. }
  1604. //---------------------------------------------------------------------------
  1605. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1606. bool Back)
  1607. {
  1608. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1609. {
  1610. TCustomDirView * DView = DirView(Side);
  1611. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1612. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1613. if (ICount > 10)
  1614. {
  1615. ICount = 10;
  1616. }
  1617. Menu->Items->Clear();
  1618. THistoryItemData Data;
  1619. Data.Side = Side;
  1620. for (short int i = 1; i <= ICount; i++)
  1621. {
  1622. TTBCustomItem * Item = new TTBXItem(Menu);
  1623. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1624. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1625. Item->Hint = DView->HistoryPath[Data.Index];
  1626. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1627. Item->Tag = *reinterpret_cast<int*>(&Data);
  1628. Item->OnClick = HistoryItemClick;
  1629. Menu->Items->Add(Item);
  1630. }
  1631. }
  1632. }
  1633. //---------------------------------------------------------------------------
  1634. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1635. TOperationSide Side, bool Back)
  1636. {
  1637. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1638. {
  1639. // workaround
  1640. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1641. // operator new allocates memory in Pascal code, but calls inline
  1642. // contructor in C++, leading in problems, the function does
  1643. // both in Pascal code
  1644. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1645. UpdateHistoryMenu(Side, Back);
  1646. }
  1647. return FHistoryMenu[Side == osLocal][Back];
  1648. }
  1649. //---------------------------------------------------------------------------
  1650. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1651. TCustomDirView *Sender)
  1652. {
  1653. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1654. UpdateHistoryMenu(Side, true);
  1655. UpdateHistoryMenu(Side, false);
  1656. }
  1657. //---------------------------------------------------------------------------
  1658. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1659. {
  1660. // remote custom commands can be executed only if the server supports shell commands
  1661. // or have secondary shell
  1662. return (FTerminal != NULL) && FTerminal->Active && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1663. }
  1664. //---------------------------------------------------------------------------
  1665. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1666. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1667. {
  1668. int Result;
  1669. TFileCustomCommand RemoteCustomCommand;
  1670. TLocalCustomCommand LocalCustomCommand;
  1671. TFileCustomCommand * NonInteractiveCustomCommand =
  1672. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1673. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1674. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1675. if (FLAGCLEAR(Command.Params, ccLocal))
  1676. {
  1677. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1678. // custom command that does not operate with files can be executed anytime ...
  1679. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1680. {
  1681. // ... but do not show such command in remote file menu
  1682. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1683. {
  1684. Result = AllowedState;
  1685. }
  1686. else
  1687. {
  1688. Result = -1;
  1689. }
  1690. }
  1691. else
  1692. {
  1693. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1694. {
  1695. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1696. }
  1697. else
  1698. {
  1699. Result = -1;
  1700. }
  1701. }
  1702. }
  1703. else
  1704. {
  1705. // custom command that does not operate with files can be executed anytime
  1706. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1707. {
  1708. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1709. }
  1710. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1711. {
  1712. if ((ListType == ccltAll) || (ListType == ccltFile))
  1713. {
  1714. // special case is "diff"-style command that can be executed over any side,
  1715. // if we have both sides
  1716. Result =
  1717. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1718. // directly (instead of EnableSelectedOperation) to pass
  1719. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1720. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1721. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1722. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1723. }
  1724. else if (ListType == ccltBoth)
  1725. {
  1726. DebugAssert(!IsLocalBrowserMode());
  1727. Result = 1;
  1728. }
  1729. else
  1730. {
  1731. Result = -1;
  1732. }
  1733. }
  1734. else
  1735. {
  1736. if ((ListType == ccltAll) ||
  1737. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1738. {
  1739. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1740. }
  1741. else
  1742. {
  1743. Result = -1;
  1744. }
  1745. }
  1746. }
  1747. return Result;
  1748. }
  1749. //---------------------------------------------------------------------------
  1750. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1751. TStrings * FileList, const TCustomCommandType & ACommand,
  1752. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1753. {
  1754. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1755. {
  1756. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1757. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1758. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1759. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1760. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1761. bool Capture =
  1762. FLAGSET(ACommand.Params, ccShowResults) ||
  1763. FLAGSET(ACommand.Params, ccCopyResults) ||
  1764. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1765. TCaptureOutputEvent OutputEvent = NULL;
  1766. DebugAssert(FCapturedLog == NULL);
  1767. if (Capture)
  1768. {
  1769. FCapturedLog = new TStringList();
  1770. OutputEvent = TerminalCaptureLog;
  1771. }
  1772. try
  1773. {
  1774. if (!RemoteCustomCommand.IsFileCommand(Command))
  1775. {
  1776. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1777. OutputEvent);
  1778. }
  1779. else
  1780. {
  1781. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1782. }
  1783. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1784. {
  1785. if (FLAGSET(ACommand.Params, ccCopyResults))
  1786. {
  1787. CopyToClipboard(FCapturedLog);
  1788. }
  1789. if (FLAGSET(ACommand.Params, ccShowResults))
  1790. {
  1791. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1792. }
  1793. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1794. {
  1795. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1796. }
  1797. }
  1798. }
  1799. __finally
  1800. {
  1801. SAFE_DESTROY(FCapturedLog);
  1802. }
  1803. }
  1804. }
  1805. //---------------------------------------------------------------------------
  1806. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1807. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1808. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1809. {
  1810. DebugAssert(!IsLocalBrowserMode());
  1811. TStrings * LocalFileList = NULL;
  1812. TStrings * RemoteFileList = NULL;
  1813. TStrings * RemoteFileListFull = NULL;
  1814. try
  1815. {
  1816. if (LocalFileCommand)
  1817. {
  1818. if (ALocalFileList == NULL)
  1819. {
  1820. DebugAssert(HasDirView[osLocal]);
  1821. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1822. // directly (instead of EnableSelectedOperation) to pass
  1823. // false to FocusedFileOnlyWhenFocused
  1824. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1825. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1826. }
  1827. else
  1828. {
  1829. LocalFileList = ALocalFileList;
  1830. }
  1831. if (FileListCommand)
  1832. {
  1833. if (LocalFileList->Count != 1)
  1834. {
  1835. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1836. }
  1837. }
  1838. else
  1839. {
  1840. if ((LocalFileList->Count != 1) &&
  1841. (FileList->Count != 1) &&
  1842. (LocalFileList->Count != FileList->Count))
  1843. {
  1844. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1845. }
  1846. }
  1847. }
  1848. UnicodeString RootTempDir;
  1849. UnicodeString TempDir;
  1850. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1851. if (!RemoteFiles)
  1852. {
  1853. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1854. }
  1855. try
  1856. {
  1857. TDateTimes RemoteFileTimes;
  1858. if (RemoteFiles)
  1859. {
  1860. RemoteFileList = FileList;
  1861. }
  1862. else
  1863. {
  1864. RemoteFileList = new TStringList();
  1865. TMakeLocalFileListParams MakeFileListParam;
  1866. MakeFileListParam.FileList = RemoteFileList;
  1867. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1868. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1869. MakeFileListParam.Recursive =
  1870. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1871. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1872. if (!MakeFileListParam.Recursive)
  1873. {
  1874. RemoteFileTimes.clear();
  1875. RemoteFileListFull = new TStringList();
  1876. MakeFileListParam.FileList = RemoteFileListFull;
  1877. MakeFileListParam.Recursive = true;
  1878. MakeFileListParam.IncludeDirs = false;
  1879. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1880. }
  1881. else
  1882. {
  1883. RemoteFileListFull = RemoteFileList;
  1884. }
  1885. }
  1886. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1887. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1888. if (!NonBlocking)
  1889. {
  1890. int Count;
  1891. if (FileListCommand)
  1892. {
  1893. Count = 1;
  1894. }
  1895. else if (LocalFileCommand)
  1896. {
  1897. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1898. }
  1899. else
  1900. {
  1901. Count = RemoteFileList->Count;
  1902. }
  1903. Progress.Start(foCustomCommand, osRemote, Count);
  1904. DebugAssert(FProgressForm != NULL);
  1905. FProgressForm->ReadOnly = true;
  1906. }
  1907. try
  1908. {
  1909. if (FileListCommand)
  1910. {
  1911. UnicodeString LocalFile;
  1912. // MakeFileList does not delimit filenames
  1913. UnicodeString FileList = MakeFileList(RemoteFileList);
  1914. if (LocalFileCommand)
  1915. {
  1916. DebugAssert(LocalFileList->Count == 1);
  1917. LocalFile = LocalFileList->Strings[0];
  1918. }
  1919. TLocalCustomCommand CustomCommand(Data,
  1920. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1921. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1922. if (NonBlocking)
  1923. {
  1924. DebugAssert(!POutput);
  1925. ExecuteShellChecked(ShellCommand);
  1926. }
  1927. else
  1928. {
  1929. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1930. }
  1931. }
  1932. else if (LocalFileCommand)
  1933. {
  1934. if (LocalFileList->Count == 1)
  1935. {
  1936. UnicodeString LocalFile = LocalFileList->Strings[0];
  1937. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1938. {
  1939. UnicodeString FileName = RemoteFileList->Strings[Index];
  1940. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1941. Progress.SetFile(FileNameForProgress);
  1942. TLocalCustomCommand CustomCommand(Data,
  1943. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1944. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1945. TOnceDoneOperation OnceDoneOperation;
  1946. // Do not unselect anything, as it won't work with two panels anyway
  1947. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1948. }
  1949. }
  1950. else if (RemoteFileList->Count == 1)
  1951. {
  1952. UnicodeString FileName = RemoteFileList->Strings[0];
  1953. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1954. {
  1955. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1956. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1957. Progress.SetFile(LocalFileNameOnly);
  1958. TLocalCustomCommand CustomCommand(
  1959. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1960. FileName, LocalFileName, L"");
  1961. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1962. TOnceDoneOperation OnceDoneOperation;
  1963. // Do not unselect anything, as it won't work with two panels anyway
  1964. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1965. }
  1966. }
  1967. else
  1968. {
  1969. if (LocalFileList->Count != RemoteFileList->Count)
  1970. {
  1971. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1972. }
  1973. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1974. {
  1975. UnicodeString FileName = RemoteFileList->Strings[Index];
  1976. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1977. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1978. Progress.SetFile(LocalFileNameOnly); // sic
  1979. TLocalCustomCommand CustomCommand(
  1980. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1981. FileName, LocalFileName, L"");
  1982. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1983. TOnceDoneOperation OnceDoneOperation;
  1984. // Do not unselect anything, as it won't work with two panels anyway
  1985. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1986. }
  1987. }
  1988. }
  1989. else
  1990. {
  1991. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1992. {
  1993. UnicodeString FileName = RemoteFileList->Strings[Index];
  1994. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1995. Progress.SetFile(FileNameForProgress);
  1996. TLocalCustomCommand CustomCommand(Data,
  1997. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1998. FileName, L"", L"");
  1999. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2000. TOnceDoneOperation OnceDoneOperation;
  2001. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2002. }
  2003. }
  2004. }
  2005. __finally
  2006. {
  2007. if (!NonBlocking)
  2008. {
  2009. Progress.Stop();
  2010. }
  2011. }
  2012. DebugAssert(!FAutoOperation);
  2013. if (!RemoteFiles)
  2014. {
  2015. TempDir = IncludeTrailingBackslash(TempDir);
  2016. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2017. {
  2018. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2019. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2020. // Skip directories, process only nested files.
  2021. // The check is redundant as FileAge fails for directories anyway.
  2022. !DirectoryExists(FileName))
  2023. {
  2024. UnicodeString RemoteDir =
  2025. UnixExtractFileDir(
  2026. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2027. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2028. TDateTime NewTime;
  2029. if (FileAge(FileName, NewTime) &&
  2030. (NewTime != RemoteFileTimes[Index]))
  2031. {
  2032. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2033. TemporaryFileCopyParam(CopyParam);
  2034. CopyParam.FileMask = L"";
  2035. FAutoOperation = true;
  2036. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2037. TemporaryFilesList->Add(FileName);
  2038. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2039. }
  2040. }
  2041. }
  2042. }
  2043. }
  2044. __finally
  2045. {
  2046. FAutoOperation = false;
  2047. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2048. {
  2049. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2050. }
  2051. }
  2052. }
  2053. __finally
  2054. {
  2055. if (RemoteFileList != FileList)
  2056. {
  2057. delete RemoteFileList;
  2058. }
  2059. if (LocalFileList != ALocalFileList)
  2060. {
  2061. delete LocalFileList;
  2062. }
  2063. if (RemoteFileListFull != RemoteFileList)
  2064. {
  2065. delete RemoteFileListFull;
  2066. }
  2067. }
  2068. }
  2069. //---------------------------------------------------------------------------
  2070. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2071. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2072. bool FileListCommand, UnicodeString * POutput)
  2073. {
  2074. std::unique_ptr<TStrings> SelectedFileList(DirView(osLocal)->CreateFileList(false, true, NULL));
  2075. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2076. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2077. {
  2078. UnicodeString FileName = SelectedFileList->Strings[Index];
  2079. if (DirectoryExists(FileName))
  2080. {
  2081. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2082. {
  2083. LocalFileList->Add(FileName);
  2084. }
  2085. if (FLAGSET(ACommand.Params, ccRecursive))
  2086. {
  2087. TMakeLocalFileListParams MakeFileListParam;
  2088. MakeFileListParam.FileList = LocalFileList.get();
  2089. MakeFileListParam.FileTimes = NULL;
  2090. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2091. MakeFileListParam.Recursive = true;
  2092. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2093. }
  2094. }
  2095. else
  2096. {
  2097. LocalFileList->Add(FileName);
  2098. }
  2099. }
  2100. UnicodeString RemotePath;
  2101. if (Terminal != NULL)
  2102. {
  2103. RemotePath = Terminal->CurrentDirectory;
  2104. }
  2105. if (FileListCommand)
  2106. {
  2107. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2108. TLocalCustomCommand CustomCommand(
  2109. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2110. L"", L"", FileList);
  2111. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2112. }
  2113. else
  2114. {
  2115. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2116. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2117. DebugAssert(FProgressForm != NULL);
  2118. FProgressForm->ReadOnly = true;
  2119. try
  2120. {
  2121. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2122. {
  2123. UnicodeString FileName = LocalFileList->Strings[Index];
  2124. Progress.SetFile(FileName);
  2125. TLocalCustomCommand CustomCommand(
  2126. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2127. FileName, L"", L"");
  2128. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2129. TOnceDoneOperation OnceDoneOperation;
  2130. Progress.Finish(FileName, true, OnceDoneOperation);
  2131. }
  2132. }
  2133. __finally
  2134. {
  2135. Progress.Stop();
  2136. }
  2137. }
  2138. }
  2139. //---------------------------------------------------------------------------
  2140. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2141. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2142. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2143. {
  2144. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2145. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2146. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2147. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2148. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2149. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2150. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2151. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2152. std::unique_ptr<UnicodeString> POutput;
  2153. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2154. FLAGSET(ACommand.Params, ccCopyResults))
  2155. {
  2156. POutput.reset(new UnicodeString());
  2157. }
  2158. if (!LocalCustomCommand.IsFileCommand(Command))
  2159. {
  2160. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2161. }
  2162. // remote files?
  2163. else if ((FCurrentSide == osRemote) || LocalFileCommand)
  2164. {
  2165. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2166. }
  2167. // local files
  2168. else
  2169. {
  2170. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2171. }
  2172. if (POutput.get() != NULL)
  2173. {
  2174. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2175. int P = POutput->Pos(sLineBreak);
  2176. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2177. {
  2178. POutput->SetLength(P - 1);
  2179. }
  2180. // Copy even empty output to clipboard
  2181. if (FLAGSET(ACommand.Params, ccCopyResults))
  2182. {
  2183. CopyToClipboard(*POutput);
  2184. }
  2185. // But do not show an empty message box.
  2186. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2187. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2188. !POutput->IsEmpty())
  2189. {
  2190. TClipboardHandler ClipboardHandler;
  2191. ClipboardHandler.Text = *POutput;
  2192. TMessageParams Params;
  2193. TQueryButtonAlias Aliases[1];
  2194. Aliases[0].Button = qaRetry;
  2195. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2196. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2197. Params.Aliases = Aliases;
  2198. Params.AliasesCount = LENOF(Aliases);
  2199. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2200. }
  2201. }
  2202. }
  2203. //---------------------------------------------------------------------------
  2204. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2205. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2206. {
  2207. TCustomCommandData Data;
  2208. UnicodeString Site;
  2209. UnicodeString RemotePath;
  2210. if (Terminal != NULL)
  2211. {
  2212. Data = TCustomCommandData(Terminal);
  2213. Site = Terminal->SessionData->SessionKey;
  2214. RemotePath = Terminal->CurrentDirectory;
  2215. }
  2216. UnicodeString HelpKeyword = ACommand.HomePage;
  2217. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2218. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2219. {
  2220. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2221. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2222. {
  2223. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2224. }
  2225. else
  2226. {
  2227. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2228. }
  2229. if (!DoCustomCommandOptionsDialog(
  2230. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2231. {
  2232. Abort();
  2233. }
  2234. }
  2235. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2236. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2237. {
  2238. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2239. }
  2240. else
  2241. {
  2242. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2243. }
  2244. }
  2245. //---------------------------------------------------------------------------
  2246. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2247. const TCustomCommandType & Command)
  2248. {
  2249. DebugAssert(FCustomCommandLocalFileList != NULL);
  2250. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2251. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2252. TStrings * LocalFileList = new TStringList();
  2253. TStrings * RemoteFileList = new TStringList();
  2254. try
  2255. {
  2256. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2257. {
  2258. LocalFileList->Clear();
  2259. LocalFileList->AddObject(
  2260. FCustomCommandLocalFileList->Strings[Index],
  2261. FCustomCommandLocalFileList->Objects[Index]);
  2262. RemoteFileList->Clear();
  2263. RemoteFileList->AddObject(
  2264. FCustomCommandRemoteFileList->Strings[Index],
  2265. FCustomCommandRemoteFileList->Objects[Index]);
  2266. CustomCommand(RemoteFileList, Command, LocalFileList);
  2267. }
  2268. }
  2269. __finally
  2270. {
  2271. delete LocalFileList;
  2272. delete RemoteFileList;
  2273. }
  2274. }
  2275. //---------------------------------------------------------------------------
  2276. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2277. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2278. {
  2279. delete FCustomCommandLocalFileList;
  2280. delete FCustomCommandRemoteFileList;
  2281. // takeover ownership,
  2282. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2283. FCustomCommandLocalFileList = LocalFileList;
  2284. FCustomCommandRemoteFileList = RemoteFileList;
  2285. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2286. if (Button != NULL)
  2287. {
  2288. FCustomCommandMenu->Items->Clear();
  2289. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2290. MenuPopup(FCustomCommandMenu, Button);
  2291. }
  2292. else
  2293. {
  2294. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2295. }
  2296. }
  2297. //---------------------------------------------------------------------------
  2298. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2299. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2300. {
  2301. DebugAssert(FCapturedLog != NULL);
  2302. if ((OutputType == cotOutput) || (OutputType == cotError))
  2303. {
  2304. FCapturedLog->Add(AddedLine);
  2305. }
  2306. }
  2307. //---------------------------------------------------------------------------
  2308. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2309. TOperationSide Side)
  2310. {
  2311. return
  2312. (Side == osOther) &&
  2313. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2314. }
  2315. //---------------------------------------------------------------------------
  2316. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2317. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2318. {
  2319. TTBItemOptions O;
  2320. O = Item->Options;
  2321. TCustomDirView * DView = DirView(Side);
  2322. if ((DView->ItemFocused != NULL) &&
  2323. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2324. // when resolving links is disabled, default action is to enter the directory,
  2325. // no matter what DoubleClickAction is configured to
  2326. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2327. // Can only Edit files, but can Open/Copy even directories
  2328. ((DoubleClickAction != dcaEdit) ||
  2329. !DView->ItemIsDirectory(DView->ItemFocused)))
  2330. {
  2331. Item->Options = O << tboDefault;
  2332. }
  2333. else
  2334. {
  2335. Item->Options = O >> tboDefault;
  2336. }
  2337. }
  2338. //---------------------------------------------------------------------------
  2339. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2340. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2341. {
  2342. TCustomDirView * DView = DirView(Side);
  2343. TListItem * Item = DView->ItemFocused;
  2344. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2345. EnableFocusedOperation[Side])
  2346. {
  2347. TPoint ClientPoint;
  2348. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2349. TPoint(0, 0) : MousePos;
  2350. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2351. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2352. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2353. }
  2354. }
  2355. //---------------------------------------------------------------------------
  2356. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2357. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2358. {
  2359. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2360. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2361. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2362. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2363. Handled = true;
  2364. }
  2365. //---------------------------------------------------------------------------
  2366. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2367. {
  2368. }
  2369. //---------------------------------------------------------------------------
  2370. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2371. {
  2372. DebugAssert(FErrorList == NULL);
  2373. if (WinConfiguration->ContinueOnError)
  2374. {
  2375. FErrorList = new TStringList();
  2376. Configuration->Usage->Inc(L"ContinuationsOnError");
  2377. }
  2378. NonVisualDataModule->StartBusy();
  2379. }
  2380. //---------------------------------------------------------------------------
  2381. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2382. {
  2383. NonVisualDataModule->EndBusy();
  2384. if (FErrorList)
  2385. {
  2386. HandleErrorList(FErrorList);
  2387. }
  2388. }
  2389. //---------------------------------------------------------------------------
  2390. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2391. const TCopyParamType & CopyParam)
  2392. {
  2393. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2394. {
  2395. Configuration->Usage->Inc(L"FileMaskUses");
  2396. }
  2397. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2398. {
  2399. Configuration->Usage->Inc(L"OperationMaskUses");
  2400. }
  2401. }
  2402. //---------------------------------------------------------------------------
  2403. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2404. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2405. {
  2406. DebugAssert(!IsLocalBrowserMode());
  2407. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2408. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2409. TTransferOperationParam DefaultParam;
  2410. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2411. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2412. switch (Param.Queue)
  2413. {
  2414. case asOn:
  2415. CopyParam.Queue = true;
  2416. break;
  2417. case asOff:
  2418. CopyParam.Queue = false;
  2419. break;
  2420. case asAuto:
  2421. default:
  2422. // keep default
  2423. break;
  2424. }
  2425. bool Result =
  2426. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2427. if (Result)
  2428. {
  2429. DebugAssert(Terminal);
  2430. bool SelectionRestored = false;
  2431. TCustomDirView * DView = NULL;
  2432. if (HasDirView[Side])
  2433. {
  2434. DView = DirView(Side);
  2435. DView->SaveSelection();
  2436. DView->SaveSelectedNames();
  2437. }
  2438. UpdateCopyParamCounters(CopyParam);
  2439. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2440. DebugAssert(FTransferResumeList == NULL);
  2441. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2442. FMoveToQueue = false;
  2443. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2444. try
  2445. {
  2446. TStrings * PermanentFileList;
  2447. std::unique_ptr<TStrings> PermanentFileListOwner;
  2448. try
  2449. {
  2450. if (Side == osLocal)
  2451. {
  2452. PermanentFileList = FileList;
  2453. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2454. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2455. if (Operation == foMove)
  2456. {
  2457. ReloadLocalDirectory();
  2458. if (DView != NULL)
  2459. {
  2460. DView->RestoreSelection();
  2461. }
  2462. SelectionRestored = true;
  2463. }
  2464. }
  2465. else
  2466. {
  2467. // Clone the file list as it may refer to current directory files,
  2468. // which get destroyed, when the source directory is reloaded after foMove operation.
  2469. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2470. // But for a hotfix, we are not going to do such a big change.
  2471. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2472. PermanentFileList = PermanentFileListOwner.get();
  2473. try
  2474. {
  2475. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2476. }
  2477. __finally
  2478. {
  2479. if (Operation == foMove)
  2480. {
  2481. if (DView != NULL)
  2482. {
  2483. DView->RestoreSelection();
  2484. }
  2485. SelectionRestored = true;
  2486. }
  2487. ReloadLocalDirectory(Param.TargetDirectory);
  2488. }
  2489. }
  2490. }
  2491. catch (EAbort &)
  2492. {
  2493. if (FMoveToQueue)
  2494. {
  2495. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2496. DebugAssert(CopyParam.TransferSkipList == NULL);
  2497. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2498. if (TransferResumeList->Count > 0)
  2499. {
  2500. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2501. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2502. }
  2503. CopyParam.TransferSkipList = TransferResumeList.release();
  2504. // not really needed, just to keep it consistent with TransferResumeList
  2505. FTransferResumeList = NULL;
  2506. FMoveToQueue = false;
  2507. Configuration->Usage->Inc("MovesToBackground");
  2508. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2509. ClearTransferSourceSelection(Direction);
  2510. }
  2511. throw;
  2512. }
  2513. }
  2514. __finally
  2515. {
  2516. if (!SelectionRestored && (DView != NULL))
  2517. {
  2518. DView->DiscardSavedSelection();
  2519. }
  2520. FTransferResumeList = NULL;
  2521. }
  2522. }
  2523. return Result;
  2524. }
  2525. //---------------------------------------------------------------------------
  2526. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2527. TOperationSide Side, TStrings * FileList, void * Param)
  2528. {
  2529. DebugAssert(FileList->Count);
  2530. // We deliberately do not toggle alternative flag (Param), but use OR,
  2531. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2532. // shortcut of CurrentDeleteAlternativeAction
  2533. bool Alternative =
  2534. bool(Param) || UseAlternativeFunction();
  2535. bool Recycle;
  2536. if (IsSideLocalBrowser(Side))
  2537. {
  2538. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2539. }
  2540. else
  2541. {
  2542. Recycle =
  2543. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2544. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2545. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2546. }
  2547. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2548. if (!Result)
  2549. {
  2550. UnicodeString Query;
  2551. if (FileList->Count == 1)
  2552. {
  2553. if (IsSideLocalBrowser(Side))
  2554. {
  2555. Query = ExtractFileName(FileList->Strings[0]);
  2556. }
  2557. else
  2558. {
  2559. Query = UnixExtractFileName(FileList->Strings[0]);
  2560. }
  2561. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2562. }
  2563. else
  2564. {
  2565. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2566. }
  2567. TMessageParams Params(mpNeverAskAgainCheck);
  2568. Params.ImageName = L"Delete file";
  2569. unsigned int Answer =
  2570. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2571. if (Answer == qaNeverAskAgain)
  2572. {
  2573. Result = true;
  2574. if (Recycle)
  2575. {
  2576. WinConfiguration->ConfirmRecycling = false;
  2577. }
  2578. else
  2579. {
  2580. WinConfiguration->ConfirmDeleting = false;
  2581. }
  2582. }
  2583. else
  2584. {
  2585. Result = (Answer == qaOK);
  2586. }
  2587. }
  2588. if (Result)
  2589. {
  2590. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2591. }
  2592. return Result;
  2593. }
  2594. //---------------------------------------------------------------------------
  2595. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2596. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2597. {
  2598. TAutoBatch AutoBatch(this);
  2599. bool Result;
  2600. if ((Operation == foCopy) || (Operation == foMove))
  2601. {
  2602. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2603. }
  2604. else if (Operation == foRename)
  2605. {
  2606. DebugAssert(DirView(Side)->ItemFocused);
  2607. DirView(Side)->ItemFocused->EditCaption();
  2608. Result = true;
  2609. }
  2610. else if (Operation == foDelete)
  2611. {
  2612. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2613. }
  2614. else if (Operation == foSetProperties)
  2615. {
  2616. DirView(osRemote)->SaveSelectedNames();
  2617. Result = SetProperties(Side, FileList);
  2618. }
  2619. else if (Operation == foCustomCommand)
  2620. {
  2621. DebugAssert(Param);
  2622. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2623. DirView(osRemote)->SaveSelectedNames();
  2624. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2625. CustomCommand(FileList, *Command, NULL);
  2626. Result = true;
  2627. }
  2628. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2629. {
  2630. DebugAssert(!IsSideLocalBrowser(Side));
  2631. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2632. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2633. }
  2634. else if (Operation == foLock)
  2635. {
  2636. DebugAssert(!IsSideLocalBrowser(Side));
  2637. LockFiles(FileList, true);
  2638. Result = true;
  2639. }
  2640. else if (Operation == foUnlock)
  2641. {
  2642. DebugAssert(!IsSideLocalBrowser(Side));
  2643. LockFiles(FileList, false);
  2644. Result = true;
  2645. }
  2646. else
  2647. {
  2648. DebugFail();
  2649. }
  2650. return Result;
  2651. }
  2652. //---------------------------------------------------------------------------
  2653. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2654. {
  2655. if (Side == osCurrent)
  2656. {
  2657. Side = FCurrentSide;
  2658. }
  2659. return Side;
  2660. }
  2661. //---------------------------------------------------------------------------
  2662. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2663. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2664. {
  2665. Side = GetSide(Side);
  2666. bool Result;
  2667. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2668. try
  2669. {
  2670. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2671. }
  2672. __finally
  2673. {
  2674. delete FileList;
  2675. }
  2676. return Result;
  2677. }
  2678. //---------------------------------------------------------------------------
  2679. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2680. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2681. bool NoConfirmation, void * Param)
  2682. {
  2683. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2684. {
  2685. if ((Operation == foCopy) || (Operation == foMove))
  2686. {
  2687. DebugAssert(!IsLocalBrowserMode());
  2688. if (GetSide(Side) == osLocal)
  2689. {
  2690. Configuration->Usage->Inc(L"UploadsCommand");
  2691. }
  2692. else
  2693. {
  2694. Configuration->Usage->Inc(L"DownloadsCommand");
  2695. }
  2696. }
  2697. }
  2698. }
  2699. //---------------------------------------------------------------------------
  2700. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2701. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2702. {
  2703. TTransferOperationParam Param;
  2704. if ((WinConfiguration->Interface != ifCommander) ||
  2705. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2706. {
  2707. Flags &= ~cocShortCutHint;
  2708. }
  2709. TCustomDirView * DView = DirView(Side);
  2710. Param.Options =
  2711. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2712. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2713. if (FLAGSET(Flags, cocQueue))
  2714. {
  2715. Param.Queue = asOn;
  2716. }
  2717. else if (FLAGSET(Flags, cocNonQueue))
  2718. {
  2719. Param.Queue = asOff;
  2720. }
  2721. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2722. }
  2723. //---------------------------------------------------------------------------
  2724. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2725. {
  2726. try
  2727. {
  2728. if (ErrorList->Count)
  2729. {
  2730. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2731. if (MessageDialog(Message, qtError,
  2732. qaOK | qaCancel, HELP_NONE) == qaOK)
  2733. {
  2734. unsigned int Answer;
  2735. int Index = 0;
  2736. do
  2737. {
  2738. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2739. TQueryButtonAlias Aliases[2];
  2740. Aliases[0].Button = qaYes;
  2741. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2742. Aliases[1].Button = qaNo;
  2743. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2744. TMessageParams Params;
  2745. Params.Aliases = Aliases;
  2746. Params.AliasesCount = LENOF(Aliases);
  2747. Answer = MoreMessageDialog(
  2748. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2749. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2750. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2751. qaOK, HELP_NONE, &Params);
  2752. if (Answer == qaNo)
  2753. {
  2754. Index++;
  2755. }
  2756. if (Answer == qaYes)
  2757. {
  2758. Index--;
  2759. }
  2760. }
  2761. while (Answer != qaOK);
  2762. }
  2763. }
  2764. }
  2765. __finally
  2766. {
  2767. TStrings * List = ErrorList;
  2768. ErrorList = NULL;
  2769. for (int i = 0; i < List->Count; i++)
  2770. {
  2771. delete List->Objects[i];
  2772. }
  2773. delete List;
  2774. }
  2775. }
  2776. //---------------------------------------------------------------------------
  2777. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2778. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2779. {
  2780. // needed for checking filemasks, as there's no directory object
  2781. // associated with the file object
  2782. File->FullFileName = FullFileName;
  2783. TFileMasks::TParams MaskParams;
  2784. MaskParams.Size = File->Size;
  2785. MaskParams.Modification = File->Modification;
  2786. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2787. }
  2788. //---------------------------------------------------------------------------
  2789. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2790. {
  2791. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2792. Side = GetSide(Side);
  2793. TCustomDirView * DView = DirView(Side);
  2794. TListItem * FocusedItem = DView->ItemFocused;
  2795. UnicodeString Name;
  2796. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2797. {
  2798. Name = DView->ItemFileName(FocusedItem);
  2799. }
  2800. else
  2801. {
  2802. Name = LoadStr(NEW_FILE);
  2803. }
  2804. UnicodeString Names = Name;
  2805. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2806. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2807. HELP_EDIT_NEW, History.get(), true))
  2808. {
  2809. while (!Names.IsEmpty())
  2810. {
  2811. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2812. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2813. UnicodeString TargetFileName;
  2814. UnicodeString LocalFileName;
  2815. UnicodeString RootTempDir;
  2816. UnicodeString TempDir;
  2817. UnicodeString RemoteDirectory;
  2818. bool ExistingFile = false;
  2819. if (!IsSideLocalBrowser(Side))
  2820. {
  2821. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2822. TRemoteFile * File = NULL;
  2823. if (FTerminal->FileExists(Name, &File) &&
  2824. !File->IsDirectory)
  2825. {
  2826. try
  2827. {
  2828. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2829. ExistingFile = true;
  2830. }
  2831. __finally
  2832. {
  2833. delete File;
  2834. }
  2835. }
  2836. if (!ExistingFile)
  2837. {
  2838. RemoteDirectory = UnixExtractFilePath(Name);
  2839. TemporaryDirectoryForRemoteFiles(
  2840. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2841. TargetFileName = UnixExtractFileName(Name);
  2842. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2843. LocalFileName = TempDir +
  2844. // We probably do not want to trim the VMS version here
  2845. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2846. }
  2847. }
  2848. else
  2849. {
  2850. if (ExtractFilePath(Name).IsEmpty())
  2851. {
  2852. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2853. }
  2854. else
  2855. {
  2856. LocalFileName = ExpandFileName(Name);
  2857. }
  2858. TargetFileName = ExtractFileName(Name);
  2859. }
  2860. if (!ExistingFile)
  2861. {
  2862. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2863. if (NewFile)
  2864. {
  2865. int File = FileCreate(ApiPath(LocalFileName));
  2866. if (File < 0)
  2867. {
  2868. if (!RootTempDir.IsEmpty())
  2869. {
  2870. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2871. }
  2872. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2873. }
  2874. else
  2875. {
  2876. FileClose(File);
  2877. }
  2878. }
  2879. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2880. const TEditorData * ExternalEditor = NULL;
  2881. TFileMasks::TParams MaskParams; // size not known
  2882. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2883. false, MaskParams);
  2884. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2885. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2886. }
  2887. }
  2888. }
  2889. }
  2890. //---------------------------------------------------------------------------
  2891. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2892. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2893. {
  2894. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2895. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2896. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2897. return
  2898. ((ExecuteFileBy == efInternalEditor)) ||
  2899. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2900. }
  2901. //---------------------------------------------------------------------------
  2902. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2903. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2904. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2905. UnicodeString RemoteDirectory, bool NewFile)
  2906. {
  2907. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2908. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2909. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2910. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2911. Side = GetSide(Side);
  2912. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2913. if (!IsSideLocalBrowser(Side))
  2914. {
  2915. Data->Terminal = Terminal;
  2916. Data->Queue = Queue;
  2917. Data->SessionData = CloneCurrentSessionData();
  2918. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2919. Data->RemoteDirectory = RemoteDirectory;
  2920. Data->SessionName = Terminal->SessionData->SessionName;
  2921. Data->LocalRootDirectory = LocalRootDirectory;
  2922. Data->OriginalFileName = OriginalFileName;
  2923. Data->Command = L""; // will be changed later for external editor
  2924. }
  2925. if (ExecuteFileBy == efInternalEditor)
  2926. {
  2927. if (!IsSideLocalBrowser(Side))
  2928. {
  2929. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2930. L" - " + Terminal->SessionData->SessionName;
  2931. TForm * Editor;
  2932. try
  2933. {
  2934. TNotifyEvent OnFileChanged = NULL;
  2935. TNotifyEvent OnSaveAll = NULL;
  2936. TAnyModifiedEvent OnAnyModified = NULL;
  2937. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2938. if (Terminal->IsCapable[fcBackgroundTransfers])
  2939. {
  2940. OnFileChanged = FEditorManager->FileChanged;
  2941. OnSaveAll = SaveAllInternalEditors;
  2942. OnAnyModified = AnyInternalEditorModified;
  2943. }
  2944. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2945. FEditorManager->FileReload, FEditorManager->FileClosed,
  2946. OnSaveAll, OnAnyModified,
  2947. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2948. }
  2949. catch(...)
  2950. {
  2951. if (!LocalRootDirectory.IsEmpty())
  2952. {
  2953. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2954. }
  2955. throw;
  2956. }
  2957. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2958. }
  2959. else
  2960. {
  2961. DebugAssert(!FStandaloneEditing);
  2962. TForm * Editor =
  2963. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2964. SaveAllInternalEditors, AnyInternalEditorModified,
  2965. L"", false, SessionColor, -1, NewFile);
  2966. FLocalEditors->Add(Editor);
  2967. }
  2968. }
  2969. else
  2970. {
  2971. HANDLE Process;
  2972. if (ExecuteFileBy == efExternalEditor)
  2973. {
  2974. UnicodeString Program, Params, Dir;
  2975. Data->Command = ExternalEditor->ExternalEditor;
  2976. ReformatFileNameCommand(Data->Command);
  2977. SplitCommand(Data->Command, Program, Params, Dir);
  2978. Params = ExpandFileNameCommand(Params, FileName);
  2979. Program = ExpandEnvironmentVariables(Program);
  2980. if (!ExecuteShell(Program, Params, Process))
  2981. {
  2982. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  2983. }
  2984. }
  2985. else
  2986. {
  2987. DebugAssert(!IsSideLocalBrowser(Side));
  2988. if (!ExecuteShell(FileName, L"", Process))
  2989. {
  2990. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  2991. }
  2992. }
  2993. if (IsSideLocalBrowser(Side) ||
  2994. ((ExecuteFileBy == efShell) &&
  2995. !WinConfiguration->Editor.SDIShellEditor) ||
  2996. ((ExecuteFileBy == efExternalEditor) &&
  2997. !ExternalEditor->SDIExternalEditor))
  2998. {
  2999. // no need for handle
  3000. if (Process != NULL)
  3001. {
  3002. DebugCheck(CloseHandle(Process));
  3003. }
  3004. Process = INVALID_HANDLE_VALUE;
  3005. }
  3006. else
  3007. {
  3008. if (Process == NULL)
  3009. {
  3010. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3011. }
  3012. }
  3013. if (!IsSideLocalBrowser(Side))
  3014. {
  3015. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3016. }
  3017. }
  3018. }
  3019. //---------------------------------------------------------------------------
  3020. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3021. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3022. void * /*Arg*/)
  3023. {
  3024. if (Token != NULL)
  3025. {
  3026. EditorFormFileSave(static_cast<TForm *>(Token));
  3027. }
  3028. }
  3029. //---------------------------------------------------------------------------
  3030. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3031. {
  3032. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3033. {
  3034. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3035. }
  3036. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3037. }
  3038. //---------------------------------------------------------------------------
  3039. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3040. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3041. void * Arg)
  3042. {
  3043. if ((Token != NULL) &&
  3044. IsEditorFormModified(static_cast<TForm *>(Token)))
  3045. {
  3046. *static_cast<bool *>(Arg) = true;
  3047. }
  3048. }
  3049. //---------------------------------------------------------------------------
  3050. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3051. TObject * /*Sender*/, bool & Modified)
  3052. {
  3053. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3054. {
  3055. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3056. {
  3057. Modified = true;
  3058. }
  3059. }
  3060. if (!Modified)
  3061. {
  3062. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3063. }
  3064. }
  3065. //---------------------------------------------------------------------------
  3066. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3067. {
  3068. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3069. }
  3070. //---------------------------------------------------------------------------
  3071. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3072. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3073. UnicodeString & Result, UnicodeString & RootDirectory)
  3074. {
  3075. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3076. {
  3077. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3078. Result = RootDirectory;
  3079. }
  3080. else
  3081. {
  3082. RootDirectory = L"";
  3083. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3084. Result = IncludeTrailingBackslash(Result);
  3085. }
  3086. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3087. {
  3088. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3089. }
  3090. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3091. {
  3092. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3093. {
  3094. RemoteDirectory.Delete(1, 1);
  3095. }
  3096. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3097. }
  3098. if (!ForceDirectories(ApiPath(Result)))
  3099. {
  3100. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3101. }
  3102. }
  3103. //---------------------------------------------------------------------------
  3104. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3105. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3106. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3107. {
  3108. DebugAssert(!IsLocalBrowserMode());
  3109. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3110. if (ForceText)
  3111. {
  3112. CopyParam.TransferMode = tmAscii;
  3113. }
  3114. TemporaryFileCopyParam(CopyParam);
  3115. if (AllFiles)
  3116. {
  3117. CopyParam.IncludeFileMask = TFileMasks();
  3118. }
  3119. if (TempDir.IsEmpty())
  3120. {
  3121. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3122. }
  3123. DebugAssert(!FAutoOperation);
  3124. FAutoOperation = AutoOperation;
  3125. Terminal->ExceptionOnFail = true;
  3126. try
  3127. {
  3128. try
  3129. {
  3130. // turn off confirmations, as for MDI editors we may possibly download
  3131. // the same file over
  3132. Terminal->CopyToLocal(
  3133. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3134. if (GetTargetNames)
  3135. {
  3136. for (int i = 0; i < FileList->Count; i++)
  3137. {
  3138. FileList->Strings[i] =
  3139. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3140. }
  3141. }
  3142. }
  3143. catch(...)
  3144. {
  3145. if (!RootTempDir.IsEmpty())
  3146. {
  3147. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3148. }
  3149. throw;
  3150. }
  3151. }
  3152. __finally
  3153. {
  3154. FAutoOperation = false;
  3155. Terminal->ExceptionOnFail = false;
  3156. }
  3157. }
  3158. //---------------------------------------------------------------------------
  3159. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3160. {
  3161. // Do not waste time checking for default editor list the next time,
  3162. // or testing if default editor is not notepad.
  3163. bool TryNextTime = false;
  3164. UnicodeString UsageState;
  3165. if (!WinConfiguration->EditorList->IsDefaultList())
  3166. {
  3167. UsageState = "H";
  3168. }
  3169. else
  3170. {
  3171. UnicodeString Executable;
  3172. UnicodeString ExecutableDescription;
  3173. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3174. {
  3175. UnicodeString Message =
  3176. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3177. unsigned int Answer =
  3178. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3179. if (Answer != qaOK)
  3180. {
  3181. UsageState = "R";
  3182. }
  3183. else
  3184. {
  3185. UsageState = "A";
  3186. TEditorData EditorData;
  3187. EditorData.Editor = edExternal;
  3188. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3189. EditorData.ExternalEditorOptionsAutodetect();
  3190. TEditorList EditorList;
  3191. EditorList = *WinConfiguration->EditorList;
  3192. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3193. WinConfiguration->EditorList = &EditorList;
  3194. }
  3195. }
  3196. }
  3197. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3198. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3199. }
  3200. //---------------------------------------------------------------------------
  3201. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3202. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3203. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3204. {
  3205. if (ExecuteFileBy == efDefaultEditor)
  3206. {
  3207. if (!WinConfiguration->OfferedEditorAutoConfig)
  3208. {
  3209. EditorAutoConfig();
  3210. }
  3211. const TEditorPreferences * Editor =
  3212. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3213. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3214. {
  3215. ExecuteFileBy = efInternalEditor;
  3216. ExternalEditor = NULL;
  3217. }
  3218. else if (Editor->Data->Editor == edOpen)
  3219. {
  3220. ExecuteFileBy = efShell;
  3221. ExternalEditor = NULL;
  3222. }
  3223. else
  3224. {
  3225. ExecuteFileBy = efExternalEditor;
  3226. ExternalEditor = Editor->Data;
  3227. }
  3228. }
  3229. }
  3230. //---------------------------------------------------------------------------
  3231. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3232. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3233. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3234. {
  3235. UnicodeString OriginalFileName;
  3236. UnicodeString LocalRootDirectory;
  3237. UnicodeString RemoteDirectory;
  3238. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3239. IsSideLocalBrowser(Side), MaskParams);
  3240. UnicodeString Counter;
  3241. UnicodeString LocalFileName;
  3242. bool Handled = false;
  3243. if (!IsSideLocalBrowser(Side))
  3244. {
  3245. // We need to trim VMS version here, so that we use name without version
  3246. // when uploading back to create a new version of the file
  3247. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3248. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3249. TObject * Token = NULL;
  3250. UnicodeString LocalDirectory;
  3251. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3252. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3253. LocalDirectory))
  3254. {
  3255. if (Token != NULL)
  3256. {
  3257. TForm * Form = dynamic_cast<TForm *>(Token);
  3258. if (Form->WindowState == wsMinimized)
  3259. {
  3260. ShowWindow(Form->Handle, SW_RESTORE);
  3261. }
  3262. else
  3263. {
  3264. Form->SetFocus();
  3265. }
  3266. Handled = true;
  3267. }
  3268. else
  3269. {
  3270. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3271. }
  3272. }
  3273. if (!Handled)
  3274. {
  3275. TStringList * FileList1 = new TStringList();
  3276. try
  3277. {
  3278. FileList1->AddObject(FullFileName, Object);
  3279. TemporarilyDownloadFiles(FileList1,
  3280. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3281. LocalRootDirectory, LocalDirectory, true, true, true);
  3282. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3283. }
  3284. __finally
  3285. {
  3286. delete FileList1;
  3287. }
  3288. switch (ExecuteFileBy)
  3289. {
  3290. case efShell:
  3291. Counter = "RemoteFilesExecuted";
  3292. break;
  3293. case efInternalEditor:
  3294. Counter = "RemoteFilesOpenedInInternalEditor";
  3295. break;
  3296. case efExternalEditor:
  3297. Counter = "RemoteFilesOpenedInExternalEditor";
  3298. break;
  3299. default:
  3300. DebugFail();
  3301. }
  3302. }
  3303. }
  3304. else
  3305. {
  3306. LocalFileName = FullFileName;
  3307. OriginalFileName = ExtractFileName(FullFileName);
  3308. switch (ExecuteFileBy)
  3309. {
  3310. case efShell:
  3311. Counter = "LocalFilesExecuted";
  3312. break;
  3313. case efInternalEditor:
  3314. Counter = "LocalFilesOpenedInInternalEditor";
  3315. break;
  3316. case efExternalEditor:
  3317. Counter = "LocalFilesOpenedInExternalEditor";
  3318. break;
  3319. default:
  3320. DebugFail();
  3321. }
  3322. }
  3323. if (!Handled)
  3324. {
  3325. Configuration->Usage->Inc(Counter);
  3326. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3327. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3328. }
  3329. }
  3330. //---------------------------------------------------------------------------
  3331. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3332. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3333. bool AllSelected, bool OnFocused)
  3334. {
  3335. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3336. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3337. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3338. Side = GetSide(Side);
  3339. TCustomDirView * DView = DirView(Side);
  3340. TStrings * FileList =
  3341. AllSelected ?
  3342. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3343. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3344. try
  3345. {
  3346. DebugAssert(AllSelected || (FileList->Count == 1));
  3347. for (int i = 0; i < FileList->Count; i++)
  3348. {
  3349. UnicodeString ListFileName = FileList->Strings[i];
  3350. UnicodeString FileNameOnly =
  3351. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3352. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3353. if (!DView->ItemIsDirectory(Item))
  3354. {
  3355. UnicodeString FullFileName;
  3356. if (!IsSideLocalBrowser(Side))
  3357. {
  3358. FullFileName = DirView(Side)->Path + ListFileName;
  3359. }
  3360. else
  3361. {
  3362. FullFileName = ListFileName;
  3363. }
  3364. TFileMasks::TParams MaskParams;
  3365. MaskParams.Size = DView->ItemFileSize(Item);
  3366. TDateTimePrecision Precision;
  3367. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3368. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3369. FileList->Objects[i], MaskParams);
  3370. }
  3371. }
  3372. }
  3373. __finally
  3374. {
  3375. delete FileList;
  3376. }
  3377. }
  3378. //---------------------------------------------------------------------------
  3379. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3380. {
  3381. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3382. CopyParam.FileNameCase = ncNoChange;
  3383. CopyParam.PreserveRights = false;
  3384. CopyParam.PreserveReadOnly = false;
  3385. CopyParam.ReplaceInvalidChars = true;
  3386. CopyParam.IncludeFileMask = TFileMasks();
  3387. CopyParam.NewerOnly = false;
  3388. CopyParam.FileMask = L"";
  3389. }
  3390. //---------------------------------------------------------------------------
  3391. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3392. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3393. {
  3394. TTerminalManager * Manager = TTerminalManager::Instance();
  3395. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3396. {
  3397. if (!NonVisualDataModule->Busy)
  3398. {
  3399. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3400. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3401. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3402. if (Data->Terminal == NULL)
  3403. {
  3404. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3405. if (SameSiteTerminal != NULL)
  3406. {
  3407. UnicodeString Message =
  3408. FMTLOAD(EDIT_SESSION_REATTACH,
  3409. (FileNameOnly, Data->SessionName, FileNameOnly));
  3410. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3411. {
  3412. Data->Terminal = Terminal;
  3413. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3414. Data->SessionName = Terminal->SessionData->SessionName;
  3415. // We might also overwrite session data
  3416. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3417. }
  3418. else
  3419. {
  3420. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3421. Abort();
  3422. }
  3423. }
  3424. }
  3425. // foreground session should reconnect itself
  3426. else if (Terminal != Data->Terminal)
  3427. {
  3428. UnicodeString Message =
  3429. MainInstructions(
  3430. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3431. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3432. {
  3433. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3434. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3435. }
  3436. else
  3437. {
  3438. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3439. Abort();
  3440. }
  3441. }
  3442. }
  3443. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3444. {
  3445. Configuration->Usage->Inc(L"EditInactiveSession");
  3446. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3447. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3448. (ExtractFileName(FileName), Data->SessionName)));
  3449. }
  3450. }
  3451. TStrings * FileList = new TStringList();
  3452. try
  3453. {
  3454. FileList->Add(FileName);
  3455. // consider using the same settings (preset) as when the file was downloaded
  3456. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3457. TemporaryFileCopyParam(CopyParam);
  3458. if (Data->ForceText)
  3459. {
  3460. CopyParam.TransferMode = tmAscii;
  3461. }
  3462. // so i do not need to worry if masking algorithm works in all cases
  3463. // ("" means "copy file name", no masking is actually done)
  3464. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3465. {
  3466. CopyParam.FileMask = L"";
  3467. }
  3468. else
  3469. {
  3470. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3471. }
  3472. DebugAssert(Data->Queue != NULL);
  3473. int Params = cpNoConfirmation | cpTemporary;
  3474. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3475. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3476. QueueItem->CompleteEvent = UploadCompleteEvent;
  3477. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3478. }
  3479. __finally
  3480. {
  3481. delete FileList;
  3482. }
  3483. }
  3484. //---------------------------------------------------------------------------
  3485. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3486. const UnicodeString FileName, const TEditedFileData * Data)
  3487. {
  3488. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3489. DebugAssert(!NonVisualDataModule->Busy);
  3490. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3491. {
  3492. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3493. (ExtractFileName(FileName), Data->SessionName)));
  3494. }
  3495. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3496. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3497. NonVisualDataModule->StartBusy();
  3498. try
  3499. {
  3500. std::unique_ptr<TRemoteFile> File;
  3501. UnicodeString RemoteFileName =
  3502. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3503. FTerminal->ExceptionOnFail = true;
  3504. try
  3505. {
  3506. TRemoteFile * AFile = NULL;
  3507. FTerminal->ReadFile(RemoteFileName, AFile);
  3508. File.reset(AFile);
  3509. if (!File->HaveFullFileName)
  3510. {
  3511. File->FullFileName = RemoteFileName;
  3512. }
  3513. }
  3514. __finally
  3515. {
  3516. FTerminal->ExceptionOnFail = false;
  3517. }
  3518. std::unique_ptr<TStrings> FileList(new TStringList());
  3519. FileList->AddObject(RemoteFileName, File.get());
  3520. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3521. UnicodeString TempDir = ExtractFilePath(FileName);
  3522. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3523. TempDir, true, true, true);
  3524. // sanity check, the target file name should be still the same
  3525. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3526. }
  3527. __finally
  3528. {
  3529. NonVisualDataModule->EndBusy();
  3530. // it actually may not exist anymore...
  3531. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3532. }
  3533. }
  3534. //---------------------------------------------------------------------------
  3535. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3536. const TEditedFileData * Data, bool & KeepOpen)
  3537. {
  3538. // Command is set for external editors only (not for "shell" open).
  3539. if (!Data->Command.IsEmpty())
  3540. {
  3541. bool AnyFound = false;
  3542. bool AnyMDI = false;
  3543. bool AnyNonMDI = false;
  3544. bool AnyDetect = false;
  3545. TEditorList * EditorList = new TEditorList();
  3546. try
  3547. {
  3548. *EditorList = *WinConfiguration->EditorList;
  3549. for (int i = 0; i < EditorList->Count; i++)
  3550. {
  3551. const TEditorPreferences * Editor = EditorList->Editors[i];
  3552. if ((Editor->Data->Editor == edExternal) &&
  3553. (Editor->Data->ExternalEditor == Data->Command))
  3554. {
  3555. AnyFound = true;
  3556. if (Editor->Data->SDIExternalEditor)
  3557. {
  3558. AnyNonMDI = true;
  3559. if (Editor->Data->DetectMDIExternalEditor)
  3560. {
  3561. AnyDetect = true;
  3562. }
  3563. }
  3564. else
  3565. {
  3566. AnyMDI = true;
  3567. }
  3568. }
  3569. }
  3570. bool EnableMDI = false;
  3571. bool DisableDetect = false;
  3572. if (AnyMDI)
  3573. {
  3574. KeepOpen = true;
  3575. if (AnyNonMDI)
  3576. {
  3577. // there is at least one instance of the editor with MDI support enabled,
  3578. // and one with disabled, enable it for all instances
  3579. EnableMDI = true;
  3580. }
  3581. }
  3582. else if (AnyFound && !AnyDetect)
  3583. {
  3584. // at least once instance found but all have MDI autodetection disabled
  3585. // => close the file (default action)
  3586. }
  3587. else
  3588. {
  3589. // no instance of the editor has MDI support enabled
  3590. TMessageParams Params;
  3591. if (AnyFound)
  3592. {
  3593. // there is at least one instance of the editor
  3594. Params.Params |= mpNeverAskAgainCheck;
  3595. }
  3596. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3597. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3598. switch (Answer)
  3599. {
  3600. case qaNeverAskAgain:
  3601. DisableDetect = true;
  3602. break;
  3603. case qaNo:
  3604. EnableMDI = true;
  3605. KeepOpen = true;
  3606. break;
  3607. }
  3608. }
  3609. if (AnyFound && (EnableMDI || DisableDetect))
  3610. {
  3611. bool Changed = false;
  3612. for (int i = 0; i < EditorList->Count; i++)
  3613. {
  3614. const TEditorPreferences * Editor = EditorList->Editors[i];
  3615. if ((Editor->Data->Editor == edExternal) &&
  3616. (Editor->Data->ExternalEditor == Data->Command) &&
  3617. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3618. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3619. {
  3620. Changed = true;
  3621. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3622. if (EnableMDI)
  3623. {
  3624. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3625. }
  3626. if (DisableDetect)
  3627. {
  3628. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3629. }
  3630. EditorList->Change(i, UpdatedEditor);
  3631. }
  3632. }
  3633. if (Changed)
  3634. {
  3635. WinConfiguration->EditorList = EditorList;
  3636. }
  3637. }
  3638. }
  3639. __finally
  3640. {
  3641. delete EditorList;
  3642. }
  3643. }
  3644. else
  3645. {
  3646. // "open" case
  3647. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3648. qaOK, HELP_APP_EARLY_CLOSED);
  3649. }
  3650. }
  3651. //---------------------------------------------------------------------------
  3652. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3653. {
  3654. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3655. }
  3656. //---------------------------------------------------------------------------
  3657. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3658. {
  3659. SideEnter(osRemote);
  3660. }
  3661. //---------------------------------------------------------------------------
  3662. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3663. {
  3664. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3665. SideEnter(osRemote);
  3666. }
  3667. //---------------------------------------------------------------------------
  3668. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3669. {
  3670. FCurrentSide = Side;
  3671. if (Visible)
  3672. {
  3673. UpdateControls();
  3674. }
  3675. }
  3676. //---------------------------------------------------------------------------
  3677. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3678. TStrings * FileList, bool Alternative)
  3679. {
  3680. TCustomDirView * DView = DirView(Side);
  3681. DView->SaveSelection();
  3682. DView->SaveSelectedNames();
  3683. DebugAssert(!FAlternativeDelete);
  3684. FAlternativeDelete = Alternative;
  3685. try
  3686. {
  3687. if (!IsSideLocalBrowser(Side))
  3688. {
  3689. DebugAssert(Terminal != NULL);
  3690. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3691. }
  3692. else
  3693. {
  3694. try
  3695. {
  3696. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3697. }
  3698. __finally
  3699. {
  3700. ReloadLocalDirectory();
  3701. }
  3702. }
  3703. FAlternativeDelete = false;
  3704. }
  3705. catch(...)
  3706. {
  3707. FAlternativeDelete = false;
  3708. DView->DiscardSavedSelection();
  3709. throw;
  3710. }
  3711. DView->RestoreSelection();
  3712. }
  3713. //---------------------------------------------------------------------------
  3714. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3715. {
  3716. DebugAssert(Terminal);
  3717. DebugAssert(!IsLocalBrowserMode());
  3718. RemoteDirView->SaveSelection();
  3719. RemoteDirView->SaveSelectedNames();
  3720. try
  3721. {
  3722. if (Lock)
  3723. {
  3724. Terminal->LockFiles(FileList);
  3725. }
  3726. else
  3727. {
  3728. Terminal->UnlockFiles(FileList);
  3729. }
  3730. }
  3731. catch(...)
  3732. {
  3733. RemoteDirView->DiscardSavedSelection();
  3734. throw;
  3735. }
  3736. RemoteDirView->RestoreSelection();
  3737. }
  3738. //---------------------------------------------------------------------------
  3739. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3740. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3741. bool NoConfirmation, bool Move)
  3742. {
  3743. DebugAssert(Terminal != NULL);
  3744. DebugAssert(!IsLocalBrowserMode());
  3745. // update Terminal->StateData->RemoteDirectory
  3746. UpdateTerminal(Terminal);
  3747. if (Session == NULL)
  3748. {
  3749. Session = TTerminalManager::Instance()->ActiveTerminal;
  3750. }
  3751. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3752. {
  3753. if (RemoteDriveView->DropTarget != NULL)
  3754. {
  3755. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3756. }
  3757. else if (RemoteDirView->DropTarget != NULL)
  3758. {
  3759. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3760. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3761. }
  3762. else
  3763. {
  3764. Target = RemoteDirView->Path;
  3765. }
  3766. }
  3767. else
  3768. {
  3769. Target = Session->StateData->RemoteDirectory;
  3770. }
  3771. Target = UnixIncludeTrailingBackslash(Target);
  3772. if (FileList->Count == 1)
  3773. {
  3774. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3775. }
  3776. else
  3777. {
  3778. FileMask = AnyMask;
  3779. }
  3780. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3781. bool Result = true;
  3782. if (!NoConfirmation)
  3783. {
  3784. bool Multi = (FileList->Count > 1);
  3785. if (Move)
  3786. {
  3787. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3788. }
  3789. else
  3790. {
  3791. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3792. TStrings * Directories = new TStringList;
  3793. try
  3794. {
  3795. for (int Index = 0; Index < Sessions->Count; Index++)
  3796. {
  3797. TManagedTerminal * Terminal =
  3798. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3799. Directories->Add(Terminal->StateData->RemoteDirectory);
  3800. }
  3801. TDirectRemoteCopy AllowDirectCopy;
  3802. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3803. {
  3804. DebugAssert(DirectCopy);
  3805. AllowDirectCopy = drcAllow;
  3806. }
  3807. else if (FTerminal->IsCapable[fcSecondaryShell])
  3808. {
  3809. DebugAssert(DirectCopy);
  3810. AllowDirectCopy = drcConfirmCommandSession;
  3811. }
  3812. else
  3813. {
  3814. DebugAssert(!DirectCopy);
  3815. AllowDirectCopy = drcDisallow;
  3816. }
  3817. void * ASession = Session;
  3818. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3819. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3820. Session = static_cast<TManagedTerminal *>(ASession);
  3821. }
  3822. __finally
  3823. {
  3824. delete Directories;
  3825. }
  3826. }
  3827. }
  3828. return Result;
  3829. }
  3830. //---------------------------------------------------------------------------
  3831. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3832. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3833. {
  3834. DebugAssert(!IsLocalBrowserMode());
  3835. bool DirectCopy;
  3836. UnicodeString Target, FileMask;
  3837. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3838. if (Result)
  3839. {
  3840. if (!Move && !DirectCopy)
  3841. {
  3842. Configuration->Usage->Inc("RemoteCopyTemp");
  3843. UnicodeString RootTempDir;
  3844. UnicodeString TempDir;
  3845. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3846. TStrings * TemporaryFilesList = new TStringList();
  3847. try
  3848. {
  3849. TMakeLocalFileListParams MakeFileListParam;
  3850. MakeFileListParam.FileList = TemporaryFilesList;
  3851. MakeFileListParam.FileTimes = NULL;
  3852. MakeFileListParam.IncludeDirs = true;
  3853. MakeFileListParam.Recursive = false;
  3854. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3855. TTerminalManager::Instance()->ActiveTerminal = Session;
  3856. if (TemporaryFilesList->Count > 0)
  3857. {
  3858. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3859. CopyParam.FileMask = FileMask;
  3860. DebugAssert(!FAutoOperation);
  3861. FAutoOperation = true;
  3862. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3863. }
  3864. }
  3865. __finally
  3866. {
  3867. delete TemporaryFilesList;
  3868. FAutoOperation = false;
  3869. if (!RootTempDir.IsEmpty())
  3870. {
  3871. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3872. }
  3873. }
  3874. }
  3875. else
  3876. {
  3877. RemoteDirView->SaveSelection();
  3878. RemoteDirView->SaveSelectedNames();
  3879. try
  3880. {
  3881. if (Move)
  3882. {
  3883. Configuration->Usage->Inc("RemoteMove");
  3884. Terminal->MoveFiles(FileList, Target, FileMask);
  3885. }
  3886. else
  3887. {
  3888. Configuration->Usage->Inc("RemoteCopyDirect");
  3889. DebugAssert(DirectCopy);
  3890. DebugAssert(Session == FTerminal);
  3891. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3892. FTerminal->CommandSessionOpened ||
  3893. CommandSessionFallback())
  3894. {
  3895. Terminal->CopyFiles(FileList, Target, FileMask);
  3896. }
  3897. }
  3898. }
  3899. catch(...)
  3900. {
  3901. RemoteDirView->DiscardSavedSelection();
  3902. throw;
  3903. }
  3904. RemoteDirView->RestoreSelection();
  3905. }
  3906. }
  3907. return Result;
  3908. }
  3909. //---------------------------------------------------------------------------
  3910. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3911. const UnicodeString & Path, TRemoteProperties & Properties)
  3912. {
  3913. DebugAssert(!IsLocalBrowserMode());
  3914. Properties.Valid = Properties.Valid << vpEncrypt;
  3915. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3916. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3917. }
  3918. //---------------------------------------------------------------------------
  3919. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3920. {
  3921. Side = GetSide(Side);
  3922. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3923. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3924. UnicodeString Name = LoadStr(NEW_FOLDER);
  3925. int AllowedChanges =
  3926. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3927. bool SaveSettings = false;
  3928. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3929. {
  3930. TWindowLock Lock(this);
  3931. if (!IsSideLocalBrowser(Side))
  3932. {
  3933. if (SaveSettings)
  3934. {
  3935. GUIConfiguration->NewDirectoryProperties = Properties;
  3936. }
  3937. CreateRemoteDirectory(Name, Properties);
  3938. }
  3939. else
  3940. {
  3941. DirView(Side)->CreateDirectory(Name);
  3942. }
  3943. }
  3944. }
  3945. //---------------------------------------------------------------------------
  3946. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3947. {
  3948. TWindowLock Lock(this);
  3949. DirView(Side)->ExecuteHomeDirectory();
  3950. }
  3951. //---------------------------------------------------------------------------
  3952. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3953. {
  3954. DoOpenDirectoryDialog(odBrowse, Side);
  3955. }
  3956. //---------------------------------------------------------------------------
  3957. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3958. {
  3959. UnicodeString Path = Bookmark->GetSideDirectory(Side);
  3960. bool Result = !Path.IsEmpty();
  3961. if (Result)
  3962. {
  3963. // While we might get here when the session is closed (from location profiles),
  3964. // it's not a problem as the Path setter is noop then
  3965. DirView(Side)->Path = Path;
  3966. }
  3967. return Result;
  3968. }
  3969. //---------------------------------------------------------------------------
  3970. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3971. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3972. bool & Close)
  3973. {
  3974. // terminal can be already closed (e.g. dropped connection)
  3975. if (Terminal != NULL)
  3976. {
  3977. try
  3978. {
  3979. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  3980. }
  3981. catch(...)
  3982. {
  3983. if (!Terminal->Active)
  3984. {
  3985. Close = true;
  3986. }
  3987. throw;
  3988. }
  3989. }
  3990. }
  3991. //---------------------------------------------------------------------------
  3992. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  3993. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  3994. bool & Close)
  3995. {
  3996. // terminal can be already closed (e.g. dropped connection)
  3997. if (Terminal != NULL)
  3998. {
  3999. Configuration->Usage->Inc(L"ChecksumCalculated");
  4000. try
  4001. {
  4002. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4003. }
  4004. catch(...)
  4005. {
  4006. if (!Terminal->Active)
  4007. {
  4008. Close = true;
  4009. }
  4010. throw;
  4011. }
  4012. }
  4013. }
  4014. //---------------------------------------------------------------------------
  4015. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4016. {
  4017. bool Result;
  4018. if (!IsSideLocalBrowser(Side))
  4019. {
  4020. TRemoteTokenList * GroupList = NULL;
  4021. TRemoteTokenList * UserList = NULL;
  4022. try
  4023. {
  4024. TRemoteProperties CurrentProperties;
  4025. if (Terminal->LoadFilesProperties(FileList))
  4026. {
  4027. RemoteDirView->Invalidate();
  4028. }
  4029. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4030. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4031. if (CapableGroupChanging || CapableOwnerChanging)
  4032. {
  4033. if (CapableGroupChanging)
  4034. {
  4035. GroupList = Terminal->Groups->Duplicate();
  4036. }
  4037. if (CapableOwnerChanging)
  4038. {
  4039. UserList = Terminal->Users->Duplicate();
  4040. }
  4041. TRemoteDirectory * Files = Terminal->Files;
  4042. int Count = Files->Count;
  4043. if (Count > 100)
  4044. {
  4045. Count = 100;
  4046. }
  4047. for (int Index = 0; Index < Count; Index++)
  4048. {
  4049. TRemoteFile * File = Files->Files[Index];
  4050. if (CapableGroupChanging)
  4051. {
  4052. GroupList->AddUnique(File->Group);
  4053. }
  4054. if (CapableOwnerChanging)
  4055. {
  4056. UserList->AddUnique(File->Owner);
  4057. }
  4058. }
  4059. // if we haven't collected tokens for all files in current directory,
  4060. // make sure we collect them at least for all selected files.
  4061. // (note that so far the files in FileList has to be from current direcotry)
  4062. if (Count < Files->Count)
  4063. {
  4064. for (int Index = 0; Index < FileList->Count; Index++)
  4065. {
  4066. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4067. if (CapableGroupChanging)
  4068. {
  4069. GroupList->AddUnique(File->Group);
  4070. }
  4071. if (CapableOwnerChanging)
  4072. {
  4073. UserList->AddUnique(File->Owner);
  4074. }
  4075. }
  4076. }
  4077. }
  4078. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4079. int Flags = 0;
  4080. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4081. if (CapableOwnerChanging) Flags |= cpOwner;
  4082. if (CapableGroupChanging) Flags |= cpGroup;
  4083. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4084. if (Terminal->IsCapable[fcCalculatingChecksum])
  4085. {
  4086. CalculateChecksumEvent = CalculateChecksum;
  4087. }
  4088. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4089. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4090. TRemoteProperties NewProperties = CurrentProperties;
  4091. Result =
  4092. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4093. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4094. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4095. CalculateSize, CalculateChecksumEvent);
  4096. if (Result)
  4097. {
  4098. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4099. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4100. }
  4101. }
  4102. __finally
  4103. {
  4104. delete GroupList;
  4105. delete UserList;
  4106. }
  4107. }
  4108. else
  4109. {
  4110. DirView(Side)->DisplayPropertiesMenu();
  4111. Result = true;
  4112. }
  4113. return Result;
  4114. }
  4115. //---------------------------------------------------------------------------
  4116. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4117. {
  4118. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4119. {
  4120. FIgnoreNextDialogChar = Key;
  4121. }
  4122. Key = 0;
  4123. }
  4124. //---------------------------------------------------------------------------
  4125. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4126. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4127. {
  4128. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4129. if (Command != NULL)
  4130. {
  4131. KeyProcessed(Key, Shift);
  4132. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4133. {
  4134. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4135. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4136. false, false, const_cast<TCustomCommandType *>(Command));
  4137. }
  4138. }
  4139. }
  4140. //---------------------------------------------------------------------------
  4141. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4142. {
  4143. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4144. {
  4145. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4146. }
  4147. if (!DirView(osCurrent)->IsEditing())
  4148. {
  4149. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4150. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4151. {
  4152. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4153. if (((Action->ShortCut == KeyShortCut) ||
  4154. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4155. AllowedAction(Action, aaShortCut))
  4156. {
  4157. // Has to be called before the action as the dialog char is already in queue.
  4158. // So when the action consumes message queue, we already need to have the
  4159. // FIgnoreNextDialogChar set
  4160. KeyProcessed(Key, Shift);
  4161. // Reset reference to previous component (when menu/toolbar was clicked).
  4162. // Needed to detect that action was invoked by keyboard shortcut
  4163. // in TNonVisualDataModule::ExplorerActionsExecute
  4164. Action->ActionComponent = NULL;
  4165. Action->Execute();
  4166. return;
  4167. }
  4168. }
  4169. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4170. {
  4171. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4172. {
  4173. KeyProcessed(Key, Shift);
  4174. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4175. return;
  4176. }
  4177. }
  4178. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4179. {
  4180. KeyProcessed(Key, Shift);
  4181. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4182. }
  4183. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4184. if (IsCustomShortCut(CustomShortCut))
  4185. {
  4186. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4187. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4188. if (WinConfiguration->SharedBookmarks != NULL)
  4189. {
  4190. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4191. if ((Bookmark != NULL) &&
  4192. OpenBookmark(FCurrentSide, Bookmark))
  4193. {
  4194. KeyProcessed(Key, Shift);
  4195. }
  4196. }
  4197. }
  4198. }
  4199. TForm::KeyDown(Key, Shift);
  4200. }
  4201. //---------------------------------------------------------------------------
  4202. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4203. {
  4204. DebugAssert(Terminal != NULL);
  4205. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4206. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4207. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4208. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4209. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4210. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4211. // expanded from ?: to avoid memory leaks
  4212. if (SecurityEnabled)
  4213. {
  4214. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4215. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4216. }
  4217. else
  4218. {
  4219. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4220. }
  4221. if (FileSystemInfo.ProtocolName.IsEmpty())
  4222. {
  4223. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4224. }
  4225. else
  4226. {
  4227. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4228. }
  4229. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4230. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4231. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4232. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4233. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4234. UnicodeString CompressionStr = CSCompressionStr;
  4235. if (CSCompressionStr != SCCompressionStr)
  4236. {
  4237. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4238. }
  4239. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4240. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4241. UpdateStatusBar();
  4242. }
  4243. //---------------------------------------------------------------------------
  4244. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4245. {
  4246. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4247. DebugAssert(SessionStatusBar != NULL);
  4248. if (!Terminal || !Terminal->Active || Terminal->Status < ssOpened)
  4249. {
  4250. // note: (Terminal->Status < sshReady) currently never happens here,
  4251. // so STATUS_CONNECTING is never used
  4252. SessionStatusBar->SimplePanel = true;
  4253. SessionStatusBar->SimpleText = LoadStr(
  4254. !Terminal || !Terminal->Active ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4255. }
  4256. else
  4257. {
  4258. DebugAssert(Terminal);
  4259. SessionStatusBar->SimplePanel = false;
  4260. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4261. if (!FNote.IsEmpty())
  4262. {
  4263. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4264. }
  4265. else
  4266. {
  4267. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4268. }
  4269. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4270. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4271. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4272. }
  4273. }
  4274. //---------------------------------------------------------------------------
  4275. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4276. {
  4277. Panel->Caption = L"";
  4278. }
  4279. //---------------------------------------------------------------------------
  4280. void __fastcall TCustomScpExplorerForm::Idle()
  4281. {
  4282. if (FShowing || FStandaloneEditing)
  4283. {
  4284. FEditorManager->Check();
  4285. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4286. // that needs to know if queue view is visible (and it may be closed after queue update)
  4287. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4288. }
  4289. if (FShowing)
  4290. {
  4291. if (!NonVisualDataModule->Busy &&
  4292. // Menu is opened or drag&drop is going on
  4293. (Mouse->Capture == NULL))
  4294. {
  4295. if (FRefreshRemoteDirectory)
  4296. {
  4297. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4298. {
  4299. Terminal->RefreshDirectory();
  4300. }
  4301. FRefreshRemoteDirectory = false;
  4302. }
  4303. if (FRefreshLocalDirectory)
  4304. {
  4305. ReloadLocalDirectory();
  4306. FRefreshLocalDirectory = false;
  4307. }
  4308. if (WinConfiguration->RefreshRemotePanel)
  4309. {
  4310. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4311. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4312. {
  4313. RemoteDirView->ReloadDirectory();
  4314. }
  4315. }
  4316. }
  4317. }
  4318. if (FShowing || FStandaloneEditing)
  4319. {
  4320. if (FQueueStatusInvalidated)
  4321. {
  4322. UpdateQueueStatus(false);
  4323. }
  4324. RefreshQueueItems();
  4325. }
  4326. if (FShowing)
  4327. {
  4328. UpdateStatusBar();
  4329. }
  4330. FIgnoreNextDialogChar = 0;
  4331. }
  4332. //---------------------------------------------------------------------------
  4333. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4334. {
  4335. try
  4336. {
  4337. FUserActionTimer->Enabled = false;
  4338. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4339. {
  4340. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4341. {
  4342. FPendingQueueActionItem->ProcessUserAction();
  4343. }
  4344. }
  4345. }
  4346. __finally
  4347. {
  4348. FPendingQueueActionItem = NULL;
  4349. }
  4350. }
  4351. //---------------------------------------------------------------------------
  4352. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4353. {
  4354. if (WinConfiguration->MinimizeToTray)
  4355. {
  4356. UpdateTrayIcon();
  4357. FTrayIcon->Visible = true;
  4358. if (Visible)
  4359. {
  4360. ShowWindow(Handle, SW_HIDE);
  4361. }
  4362. }
  4363. }
  4364. //---------------------------------------------------------------------------
  4365. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4366. {
  4367. // WORKAROUND
  4368. // When restoring maximized window from minimization,
  4369. // rarely some controls do not align properly.
  4370. // Two instances seen (both for Commander):
  4371. // - When restoring, window is temporarily narrower (not maximized),
  4372. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4373. // Once maximized already, top dock shinks back, but the session PageControl,
  4374. // do not align up, leaving space between TopDock and PageControl.
  4375. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4376. for (int Index = 0; Index < ControlCount; Index++)
  4377. {
  4378. RealignControl(Controls[Index]);
  4379. }
  4380. if (FTrayIcon->Visible)
  4381. {
  4382. FTrayIcon->Visible = false;
  4383. if (Visible)
  4384. {
  4385. ShowWindow(Handle, SW_SHOW);
  4386. }
  4387. }
  4388. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4389. {
  4390. FNeedSession = false;
  4391. NonVisualDataModule->StartBusy();
  4392. try
  4393. {
  4394. NeedSession(true);
  4395. }
  4396. __finally
  4397. {
  4398. NonVisualDataModule->EndBusy();
  4399. }
  4400. }
  4401. }
  4402. //---------------------------------------------------------------------------
  4403. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4404. {
  4405. FTrayIcon->Hint = GetMainForm()->Caption;
  4406. }
  4407. //---------------------------------------------------------------------------
  4408. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4409. {
  4410. UpdateTrayIcon();
  4411. }
  4412. //---------------------------------------------------------------------------
  4413. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4414. {
  4415. // workaround
  4416. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4417. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4418. // But WM_ACTIVATEAPP message can be received even when
  4419. // the main window is minimized to the tray and internal editor window is focused
  4420. // (after another application was previously active)
  4421. if (::IsIconic(Handle))
  4422. {
  4423. if (!IsAppIconic())
  4424. {
  4425. SetAppIconic(true);
  4426. }
  4427. }
  4428. ::ApplicationRestore();
  4429. Application->BringToFront();
  4430. }
  4431. //---------------------------------------------------------------------------
  4432. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4433. {
  4434. RestoreApp();
  4435. }
  4436. //---------------------------------------------------------------------------
  4437. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4438. {
  4439. if (OpenInNewWindow())
  4440. {
  4441. // todo: Pass FromSite
  4442. ExecuteNewInstance(SessionUrl);
  4443. }
  4444. else
  4445. {
  4446. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4447. }
  4448. }
  4449. //---------------------------------------------------------------------------
  4450. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4451. {
  4452. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4453. StoredSessions->NewSession(SessionName, SessionData);
  4454. // modified only, explicit
  4455. StoredSessions->Save(false, true);
  4456. // encode session name because of slashes in hierarchical sessions
  4457. return EncodeUrlString(SessionName);
  4458. }
  4459. //---------------------------------------------------------------------------
  4460. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4461. {
  4462. // current working directories become defaults here, what is not right
  4463. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4464. return SaveHiddenDuplicateSession(SessionData.get());
  4465. }
  4466. //---------------------------------------------------------------------------
  4467. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4468. {
  4469. if (OpenInNewWindow())
  4470. {
  4471. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4472. }
  4473. else
  4474. {
  4475. // current working directories become defaults here, what is not right
  4476. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4477. TTerminalManager * Manager = TTerminalManager::Instance();
  4478. TManagedTerminal * Terminal = Manager->NewManagedTerminal(SessionData.get());
  4479. Manager->ActiveTerminal = Terminal;
  4480. }
  4481. }
  4482. //---------------------------------------------------------------------------
  4483. void __fastcall TCustomScpExplorerForm::RenameSession()
  4484. {
  4485. UnicodeString Name = Terminal->SessionData->SessionName;
  4486. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4487. {
  4488. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4489. TSessionData::ValidateName(Name);
  4490. // This is inconsistent with how color (for example) is handled.
  4491. Terminal->SessionData->Name = Name;
  4492. UpdateControls();
  4493. // Add/Remove distinguishing paths from sessions of the same name.
  4494. DoTerminalListChanged();
  4495. }
  4496. }
  4497. //---------------------------------------------------------------------------
  4498. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4499. {
  4500. DebugAssert(Queue != NULL);
  4501. bool Result = Queue->IsEmpty;
  4502. if (!Result)
  4503. {
  4504. SetFocus();
  4505. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4506. }
  4507. return Result;
  4508. }
  4509. //---------------------------------------------------------------------------
  4510. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4511. {
  4512. return CanCloseQueue(FQueue);
  4513. }
  4514. //---------------------------------------------------------------------------
  4515. void __fastcall TCustomScpExplorerForm::CloseSession()
  4516. {
  4517. if (CanCloseQueue())
  4518. {
  4519. TTerminalManager::Instance()->FreeActiveTerminal();
  4520. }
  4521. }
  4522. //---------------------------------------------------------------------------
  4523. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4524. {
  4525. if (CanCloseQueue())
  4526. {
  4527. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4528. }
  4529. }
  4530. //---------------------------------------------------------------------------
  4531. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4532. {
  4533. RemoteDirView->Terminal = Terminal;
  4534. UpdateRemotePathComboBox(false);
  4535. UpdateControls();
  4536. }
  4537. //---------------------------------------------------------------------------
  4538. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4539. {
  4540. if (DebugAlwaysTrue(!Terminal->Active))
  4541. {
  4542. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4543. }
  4544. }
  4545. //---------------------------------------------------------------------------
  4546. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4547. {
  4548. if (OpenInNewWindow())
  4549. {
  4550. // encode session name because of slashes in hierarchical sessions
  4551. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4552. }
  4553. else
  4554. {
  4555. TTerminalManager * Manager = TTerminalManager::Instance();
  4556. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4557. Manager->ActiveTerminal = Terminal;
  4558. }
  4559. }
  4560. //---------------------------------------------------------------------------
  4561. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4562. {
  4563. TTerminalManager * Manager = TTerminalManager::Instance();
  4564. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4565. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4566. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4567. // FirstTerminal can be null, if some of the
  4568. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4569. {
  4570. FirstTerminal->Disconnected = true;
  4571. FirstTerminal->DisconnectedTemporarily = true;
  4572. }
  4573. Manager->ActiveTerminal = FirstTerminal;
  4574. }
  4575. //---------------------------------------------------------------------------
  4576. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4577. {
  4578. if (OpenInNewWindow())
  4579. {
  4580. ExecuteNewInstance(Name);
  4581. }
  4582. else
  4583. {
  4584. DoOpenFolderOrWorkspace(Name, true);
  4585. }
  4586. }
  4587. //---------------------------------------------------------------------------
  4588. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4589. bool &CanClose)
  4590. {
  4591. // See the comment in CloseApp()
  4592. if (NonVisualDataModule->Busy)
  4593. {
  4594. CanClose = false;
  4595. }
  4596. else if (Terminal != NULL)
  4597. {
  4598. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4599. {
  4600. unsigned int Result;
  4601. TMessageParams Params(mpNeverAskAgainCheck);
  4602. UnicodeString Message;
  4603. int Answers = qaOK | qaCancel;
  4604. if (TTerminalManager::Instance()->Count > 1)
  4605. {
  4606. if (!WinConfiguration->AutoSaveWorkspace)
  4607. {
  4608. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4609. }
  4610. else
  4611. {
  4612. Message = LoadStr(CLOSE_SESSIONS);
  4613. }
  4614. }
  4615. else
  4616. {
  4617. if (!WinConfiguration->AutoSaveWorkspace)
  4618. {
  4619. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4620. }
  4621. else
  4622. {
  4623. Message = LoadStr(CLOSE_SESSION);
  4624. }
  4625. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4626. }
  4627. UnicodeString Note;
  4628. if (WinConfiguration->AutoSaveWorkspace)
  4629. {
  4630. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4631. }
  4632. else
  4633. {
  4634. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4635. Answers = qaYes | qaNo | qaCancel;
  4636. }
  4637. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4638. SetFocus();
  4639. Result = MessageDialog(Message, qtConfirmation,
  4640. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4641. if (Result == qaNeverAskAgain)
  4642. {
  4643. WinConfiguration->ConfirmClosingSession = false;
  4644. }
  4645. if (Result == qaNo)
  4646. {
  4647. CanClose = SaveWorkspace(true);
  4648. // note that the workspace will be saved redundatly again from FormClose
  4649. }
  4650. else
  4651. {
  4652. CanClose =
  4653. (Result == qaOK) ||
  4654. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4655. (Result == qaNeverAskAgain);
  4656. }
  4657. }
  4658. if (CanClose)
  4659. {
  4660. CanClose = CanCloseQueue();
  4661. }
  4662. }
  4663. if (CanClose)
  4664. {
  4665. CanClose =
  4666. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4667. FEditorManager->CloseExternalFilesWithoutProcess();
  4668. if (CanClose)
  4669. {
  4670. while (CanClose && (FLocalEditors->Count > 0))
  4671. {
  4672. int PrevCount = FLocalEditors->Count;
  4673. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4674. CanClose = (FLocalEditors->Count < PrevCount);
  4675. }
  4676. if (CanClose)
  4677. {
  4678. CanClose = FEditorManager->Empty(true);
  4679. if (!CanClose)
  4680. {
  4681. SetFocus();
  4682. CanClose =
  4683. (MessageDialog(
  4684. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4685. }
  4686. }
  4687. }
  4688. }
  4689. }
  4690. //---------------------------------------------------------------------------
  4691. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4692. {
  4693. TForm * Form = dynamic_cast<TForm *>(Sender);
  4694. DebugAssert(Form != NULL);
  4695. Form->Close();
  4696. }
  4697. //---------------------------------------------------------------------------
  4698. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4699. {
  4700. TForm * Form = dynamic_cast<TForm *>(Sender);
  4701. delete Form;
  4702. }
  4703. //---------------------------------------------------------------------------
  4704. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4705. {
  4706. while (FLocalEditors->Count > 0)
  4707. {
  4708. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4709. }
  4710. }
  4711. //---------------------------------------------------------------------------
  4712. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4713. TObject *Sender)
  4714. {
  4715. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4716. try
  4717. {
  4718. SetProperties(osRemote, FileList);
  4719. }
  4720. __finally
  4721. {
  4722. delete FileList;
  4723. }
  4724. }
  4725. //---------------------------------------------------------------------------
  4726. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4727. {
  4728. if (value)
  4729. {
  4730. if (Component == fcCustomCommandsBand)
  4731. {
  4732. UpdateCustomCommandsToolbar();
  4733. }
  4734. if (Component == fcQueueFileList)
  4735. {
  4736. DebugAssert(!QueueFileListSplitter->Visible);
  4737. AdjustQueueLayout();
  4738. UpdateQueueFileList();
  4739. }
  4740. }
  4741. }
  4742. //---------------------------------------------------------------------------
  4743. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4744. {
  4745. int MinHeightLimit =
  4746. GetStaticQueuePanelComponentsHeight() +
  4747. QueueFileListSplitter->Height +
  4748. QueueFileList->Height +
  4749. GetMinQueueViewHeight();
  4750. if (QueuePanel->ClientHeight < MinHeightLimit)
  4751. {
  4752. QueuePanel->ClientHeight = MinHeightLimit;
  4753. }
  4754. }
  4755. //---------------------------------------------------------------------------
  4756. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4757. {
  4758. TControl * Control = GetComponent(Component);
  4759. DebugAssert(Control);
  4760. bool Changed = (Control->Visible != value);
  4761. if (Changed)
  4762. {
  4763. ComponentShowing(Component, value);
  4764. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4765. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4766. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4767. if (value)
  4768. {
  4769. int RemainingHeight = Control->Parent->ClientHeight;
  4770. int RemainingWidth = Control->Parent->ClientWidth;
  4771. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4772. {
  4773. TControl * ChildControl = Control->Parent->Controls[i];
  4774. if (ChildControl->Visible)
  4775. {
  4776. switch (ChildControl->Align)
  4777. {
  4778. case alTop:
  4779. case alBottom:
  4780. RemainingHeight -= ChildControl->Height;
  4781. break;
  4782. case alLeft:
  4783. case alRight:
  4784. RemainingWidth -= ChildControl->Width;
  4785. break;
  4786. }
  4787. }
  4788. }
  4789. int Reserve = ScaleByTextHeight(this, 32);
  4790. // queue in explorer, trees in commander
  4791. if (Control->Height > RemainingHeight - Reserve)
  4792. {
  4793. Control->Height = RemainingHeight / 2;
  4794. }
  4795. if (Control->Width > RemainingWidth - Reserve)
  4796. {
  4797. Control->Width = RemainingWidth / 2;
  4798. }
  4799. }
  4800. Control->Visible = value;
  4801. if (WasFocused && Visible)
  4802. {
  4803. DirView(osCurrent)->SetFocus();
  4804. }
  4805. FixControlsPlacement();
  4806. }
  4807. }
  4808. //---------------------------------------------------------------------------
  4809. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4810. {
  4811. TControl * Control = GetComponent(Component);
  4812. if (Control == NULL)
  4813. {
  4814. return false;
  4815. }
  4816. else
  4817. {
  4818. return Control->Visible;
  4819. }
  4820. }
  4821. //---------------------------------------------------------------------------
  4822. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4823. {
  4824. bool Result;
  4825. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4826. {
  4827. Result = !IsUWP();
  4828. }
  4829. else
  4830. {
  4831. Result = true;
  4832. }
  4833. return Result;
  4834. }
  4835. //---------------------------------------------------------------------------
  4836. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4837. {
  4838. if (DirView(osOther)->ItemFocused != NULL)
  4839. {
  4840. DirView(osOther)->ItemFocused->MakeVisible(false);
  4841. }
  4842. QueueSplitter->Visible = QueuePanel->Visible;
  4843. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4844. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4845. TControl * QueueControlsOrder[] =
  4846. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4847. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4848. }
  4849. //---------------------------------------------------------------------------
  4850. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4851. {
  4852. switch (Component) {
  4853. case fcStatusBar: return RemoteStatusBar;
  4854. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4855. case fcQueueView: return QueuePanel;
  4856. case fcQueueToolbar: return QueueDock;
  4857. case fcRemoteTree: return RemoteDrivePanel;
  4858. case fcSessionsTabs: return SessionsPageControl;
  4859. case fcQueueFileList: return QueueFileList;
  4860. default: return NULL;
  4861. }
  4862. }
  4863. //---------------------------------------------------------------------------
  4864. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4865. TObject *Sender, TListColumn *Column, TPoint &Point)
  4866. {
  4867. DebugAssert(NonVisualDataModule && Column && Sender);
  4868. NonVisualDataModule->ListColumn = Column;
  4869. TPopupMenu * DirViewColumnMenu;
  4870. if (dynamic_cast<TUnixDirView *>(Sender) != NULL)
  4871. {
  4872. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4873. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4874. (Column->Index == uvName);
  4875. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4876. (Column->Index == uvSize);
  4877. }
  4878. else
  4879. {
  4880. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4881. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4882. (Column->Index == dvName);
  4883. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4884. (Column->Index == dvSize);
  4885. }
  4886. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4887. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4888. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4889. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4890. }
  4891. //---------------------------------------------------------------------------
  4892. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4893. TObject *Sender, TListItem *Item, bool &AllowExec)
  4894. {
  4895. DoDirViewExecFile(Sender, Item, AllowExec);
  4896. }
  4897. //---------------------------------------------------------------------------
  4898. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4899. TListItem * Item, bool & AllowExec)
  4900. {
  4901. DebugAssert(Sender && Item && Configuration);
  4902. DebugAssert(AllowExec);
  4903. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4904. bool Remote = (ADirView == DirView(osRemote)) && !IsSideLocalBrowser(osRemote);
  4905. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks;
  4906. TOperationSide Side = (Remote ? osRemote : osLocal); // TODO
  4907. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4908. // on files only (not directories)
  4909. // and only when symlinks are resolved (apply to remote panel only)
  4910. if (!ADirView->ItemIsDirectory(Item) &&
  4911. (ResolvedSymlinks || FForceExecution || Terminal->IsEncryptingFiles()))
  4912. {
  4913. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4914. !FForceExecution &&
  4915. (ResolvedSymlinks || Terminal->IsEncryptingFiles()))
  4916. {
  4917. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4918. {
  4919. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4920. UnlockWindow();
  4921. try
  4922. {
  4923. ExecuteFileOperation(
  4924. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4925. }
  4926. __finally
  4927. {
  4928. LockWindow();
  4929. }
  4930. AllowExec = false;
  4931. }
  4932. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4933. {
  4934. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4935. {
  4936. ExecuteFile(Side, efDefaultEditor);
  4937. AllowExec = false;
  4938. }
  4939. }
  4940. else
  4941. {
  4942. DebugFail();
  4943. }
  4944. }
  4945. // if we have not done anything special, fall back to default behavior
  4946. if (AllowExec)
  4947. {
  4948. if (Remote && !WinConfiguration->DisableOpenEdit)
  4949. {
  4950. ExecuteFile(osRemote, efShell);
  4951. AllowExec = false;
  4952. }
  4953. }
  4954. }
  4955. }
  4956. //---------------------------------------------------------------------------
  4957. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4958. {
  4959. return ((Side == osRemote) || (Side == osCurrent));
  4960. }
  4961. //---------------------------------------------------------------------------
  4962. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  4963. {
  4964. DebugFail();
  4965. }
  4966. //---------------------------------------------------------------------------
  4967. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  4968. {
  4969. DebugFail();
  4970. }
  4971. //---------------------------------------------------------------------------
  4972. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  4973. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  4974. {
  4975. TSynchronizeParamType Params;
  4976. Params.LocalDirectory = LocalDirectory;
  4977. Params.RemoteDirectory = RemoteDirectory;
  4978. int UnusedParams =
  4979. (GUIConfiguration->SynchronizeParams &
  4980. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize));
  4981. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  4982. Params.Options = GUIConfiguration->SynchronizeOptions;
  4983. bool SaveSettings = false;
  4984. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  4985. &DoSynchronizeTooManyDirectories);
  4986. DebugAssert(FSynchronizeController == NULL);
  4987. FSynchronizeController = &Controller;
  4988. bool Result;
  4989. try
  4990. {
  4991. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4992. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  4993. int Options =
  4994. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  4995. DebugAssert(FOnFeedSynchronizeError == NULL);
  4996. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  4997. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  4998. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  4999. if (Result)
  5000. {
  5001. if (SaveSettings)
  5002. {
  5003. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5004. GUIConfiguration->SynchronizeOptions = Params.Options;
  5005. }
  5006. else
  5007. {
  5008. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5009. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5010. FLAGSET(Params.Options, soSynchronize))
  5011. {
  5012. GUIConfiguration->SynchronizeOptions =
  5013. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5014. soSynchronize;
  5015. }
  5016. }
  5017. LocalDirectory = Params.LocalDirectory;
  5018. RemoteDirectory = Params.RemoteDirectory;
  5019. }
  5020. }
  5021. __finally
  5022. {
  5023. FSynchronizeController = NULL;
  5024. DebugAssert(FOnFeedSynchronizeError == NULL);
  5025. FOnFeedSynchronizeError = NULL;
  5026. }
  5027. return Result;
  5028. }
  5029. //---------------------------------------------------------------------------
  5030. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5031. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5032. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5033. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5034. TSynchronizeOptions * Options, bool Full)
  5035. {
  5036. // Keep-up-to-date mode
  5037. if (Terminal->Status == ssOpened)
  5038. {
  5039. try
  5040. {
  5041. int PParams = Params.Params;
  5042. if (!Full)
  5043. {
  5044. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5045. if (FLAGSET(Params.Options, soRecurse))
  5046. {
  5047. PParams |= TTerminal::spSubDirs;
  5048. }
  5049. }
  5050. else
  5051. {
  5052. // if keepuptodate is non-recursive,
  5053. // full sync before has to be non-recursive as well
  5054. if (FLAGCLEAR(Params.Options, soRecurse))
  5055. {
  5056. PParams |= TTerminal::spNoRecurse;
  5057. }
  5058. }
  5059. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5060. PParams, Checklist, Options);
  5061. }
  5062. catch (Exception & E)
  5063. {
  5064. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5065. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5066. {
  5067. // noop, already logged in MoreMessageDialog
  5068. }
  5069. else
  5070. {
  5071. ShowExtendedExceptionEx(Terminal, &E);
  5072. throw;
  5073. }
  5074. }
  5075. }
  5076. }
  5077. //---------------------------------------------------------------------------
  5078. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5079. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5080. const UnicodeString ErrorStr)
  5081. {
  5082. if (!Directory.IsEmpty())
  5083. {
  5084. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5085. }
  5086. else
  5087. {
  5088. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5089. }
  5090. }
  5091. //---------------------------------------------------------------------------
  5092. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5093. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5094. {
  5095. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5096. {
  5097. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5098. }
  5099. else
  5100. {
  5101. TMessageParams Params(mpNeverAskAgainCheck);
  5102. unsigned int Result = MessageDialog(
  5103. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5104. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5105. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5106. {
  5107. MaxDirectories *= 2;
  5108. if (Result == qaNeverAskAgain)
  5109. {
  5110. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5111. }
  5112. }
  5113. else
  5114. {
  5115. Abort();
  5116. }
  5117. }
  5118. }
  5119. //---------------------------------------------------------------------------
  5120. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5121. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5122. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5123. TSynchronizeOptions * Options)
  5124. {
  5125. // Keep-up-to-date mode
  5126. DebugAssert(!FAutoOperation);
  5127. void * BatchStorage;
  5128. BatchStart(BatchStorage);
  5129. FAutoOperation = true;
  5130. bool AnyOperation = false;
  5131. TDateTime StartTime = Now();
  5132. TSynchronizeChecklist * AChecklist = NULL;
  5133. try
  5134. {
  5135. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5136. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5137. {
  5138. FSynchronizeProgressForm->Start();
  5139. }
  5140. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5141. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5142. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5143. Options);
  5144. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5145. SAFE_DESTROY(FSynchronizeProgressForm);
  5146. AnyOperation = (AChecklist->CheckedCount > 0);
  5147. if (AnyOperation)
  5148. {
  5149. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5150. CreateProgressForm(&SynchronizeProgress);
  5151. try
  5152. {
  5153. Terminal->SynchronizeApply(
  5154. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5155. SynchronizeProcessedItem, NULL, NULL, NULL);
  5156. }
  5157. __finally
  5158. {
  5159. DestroyProgressForm();
  5160. }
  5161. }
  5162. }
  5163. __finally
  5164. {
  5165. if (Checklist == NULL)
  5166. {
  5167. delete AChecklist;
  5168. }
  5169. else
  5170. {
  5171. *Checklist = AChecklist;
  5172. }
  5173. FAutoOperation = false;
  5174. SAFE_DESTROY(FSynchronizeProgressForm);
  5175. BatchEnd(BatchStorage);
  5176. ReloadLocalDirectory();
  5177. if (AnyOperation)
  5178. {
  5179. OperationComplete(StartTime);
  5180. }
  5181. }
  5182. }
  5183. //---------------------------------------------------------------------------
  5184. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5185. {
  5186. // can be called from command line
  5187. return Visible &&
  5188. ((DirView(osRemote)->SelCount > 0) ||
  5189. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5190. }
  5191. //---------------------------------------------------------------------------
  5192. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5193. {
  5194. LogSynchronizeEvent(Terminal, Message);
  5195. }
  5196. //---------------------------------------------------------------------------
  5197. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5198. int Params, TSynchronizeOptions & Options)
  5199. {
  5200. DebugAssert(!IsLocalBrowserMode());
  5201. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5202. {
  5203. Options.Filter = new TStringList();
  5204. Options.Filter->CaseSensitive = false;
  5205. Options.Filter->Duplicates = Types::dupAccept;
  5206. if (DirView(osRemote)->SelCount > 0)
  5207. {
  5208. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5209. }
  5210. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5211. {
  5212. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5213. }
  5214. Options.Filter->Sort();
  5215. }
  5216. }
  5217. //---------------------------------------------------------------------------
  5218. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5219. {
  5220. TCopyParamType Defaults;
  5221. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5222. ConfigStorage->AccessMode = smRead;
  5223. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5224. {
  5225. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5226. }
  5227. ConfigStorage.reset(NULL);
  5228. std::unique_ptr<TStringList> Options(new TStringList());
  5229. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5230. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5231. UnicodeString Result;
  5232. if (Options->Count > 0)
  5233. {
  5234. Result =
  5235. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5236. }
  5237. return Result;
  5238. }
  5239. //---------------------------------------------------------------------------
  5240. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5241. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5242. {
  5243. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5244. UnicodeString AdditionalParams =
  5245. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5246. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5247. SerializeCopyParamForCommandLine(CopyParams),
  5248. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5249. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5250. ExecuteNewInstance(SessionName, AdditionalParams);
  5251. }
  5252. //---------------------------------------------------------------------------
  5253. struct TSynchronizeParams
  5254. {
  5255. UnicodeString LocalDirectory;
  5256. UnicodeString RemoteDirectory;
  5257. TSynchronizeMode Mode;
  5258. TSynchronizeChecklist * Checklist;
  5259. int Params;
  5260. TCopyParamType * CopyParam;
  5261. TDateTime CollectElapsed;
  5262. TDateTime * StartTime;
  5263. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5264. };
  5265. //---------------------------------------------------------------------------
  5266. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5267. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5268. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5269. {
  5270. DebugAssert(!FAutoOperation);
  5271. void * BatchStorage;
  5272. BatchStart(BatchStorage);
  5273. FAutoOperation = true;
  5274. TFileOperationStatistics Statistics;
  5275. TDateTime Start = Now();
  5276. try
  5277. {
  5278. Params.OnProcessedItem = OnProcessedItem;
  5279. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5280. CreateProgressForm(&SynchronizeProgress);
  5281. Terminal->SynchronizeApply(
  5282. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5283. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5284. &Statistics);
  5285. }
  5286. __finally
  5287. {
  5288. Params.OnProcessedItem = NULL;
  5289. FAutoOperation = false;
  5290. DestroyProgressForm();
  5291. BatchEnd(BatchStorage);
  5292. ReloadLocalDirectory();
  5293. }
  5294. if (WinConfiguration->SynchronizeSummary)
  5295. {
  5296. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5297. // The statistics should be 0 anyway in this case
  5298. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5299. {
  5300. Message += L"\n";
  5301. if (Statistics.FilesUploaded > 0)
  5302. {
  5303. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5304. }
  5305. if (Statistics.FilesDownloaded > 0)
  5306. {
  5307. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5308. }
  5309. if (Statistics.FilesDeletedLocal > 0)
  5310. {
  5311. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5312. }
  5313. if (Statistics.FilesDeletedRemote > 0)
  5314. {
  5315. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5316. }
  5317. }
  5318. TDateTime Elapsed = (Now() - Start);
  5319. Message +=
  5320. L"\n" +
  5321. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5322. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5323. TMessageParams Params(mpNeverAskAgainCheck);
  5324. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5325. if (Result == qaNeverAskAgain)
  5326. {
  5327. WinConfiguration->SynchronizeSummary = false;
  5328. }
  5329. }
  5330. }
  5331. //---------------------------------------------------------------------------
  5332. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5333. {
  5334. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5335. {
  5336. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5337. }
  5338. // Not set in keep-up-to-date mode - Synchronize() method
  5339. if (Token != NULL)
  5340. {
  5341. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5342. if (Params.OnProcessedItem != NULL)
  5343. {
  5344. Params.OnProcessedItem(NULL, ChecklistItem);
  5345. }
  5346. }
  5347. }
  5348. //---------------------------------------------------------------------------
  5349. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5350. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5351. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5352. {
  5353. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5354. *Params.StartTime = Now();
  5355. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5356. }
  5357. //---------------------------------------------------------------------------
  5358. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5359. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5360. {
  5361. // terminal can be already closed (e.g. dropped connection)
  5362. if (Terminal != NULL)
  5363. {
  5364. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5365. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5366. }
  5367. }
  5368. //---------------------------------------------------------------------------
  5369. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5370. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5371. {
  5372. DebugAssert(!IsLocalBrowserMode());
  5373. TAutoBatch AutoBatch(this);
  5374. TAutoFlag AutoOperationFlag(FAutoOperation);
  5375. if (Side == osRemote)
  5376. {
  5377. std::unique_ptr<TStrings> FileList(new TStringList());
  5378. FileList->AddObject(FileName, RemoteFile);
  5379. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5380. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5381. RemoteDirView->SaveSelection();
  5382. RemoteDirView->SaveSelectedNames();
  5383. try
  5384. {
  5385. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5386. }
  5387. catch(...)
  5388. {
  5389. RemoteDirView->DiscardSavedSelection();
  5390. throw;
  5391. }
  5392. RemoteDirView->RestoreSelection();
  5393. }
  5394. else if (DebugAlwaysTrue(Side == osLocal))
  5395. {
  5396. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5397. {
  5398. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5399. }
  5400. UnicodeString Directory = ExtractFileDir(FileName);
  5401. ReloadLocalDirectory(Directory);
  5402. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5403. if (!SamePaths(Directory, NewDirectory))
  5404. {
  5405. ReloadLocalDirectory(NewDirectory);
  5406. }
  5407. }
  5408. }
  5409. //---------------------------------------------------------------------------
  5410. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5411. {
  5412. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5413. if (Side == osLocal)
  5414. {
  5415. if (Action == TSynchronizeChecklist::saDownloadNew)
  5416. {
  5417. OpenFolderInExplorer(LocalPath);
  5418. }
  5419. else
  5420. {
  5421. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5422. }
  5423. }
  5424. else if (DebugAlwaysTrue(Side == osRemote))
  5425. {
  5426. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5427. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5428. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5429. if (!LocalPath.IsEmpty())
  5430. {
  5431. SessionData->LocalDirectory = LocalPath;
  5432. }
  5433. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5434. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5435. }
  5436. }
  5437. //---------------------------------------------------------------------------
  5438. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5439. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5440. const TCopyParamType * CopyParams)
  5441. {
  5442. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5443. UnicodeString AdditionalParams =
  5444. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5445. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5446. SerializeCopyParamForCommandLine(CopyParams),
  5447. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5448. LocalDirectory, RemoteDirectory, Mode, Params));
  5449. ExecuteNewInstance(SessionName, AdditionalParams);
  5450. }
  5451. //---------------------------------------------------------------------------
  5452. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5453. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5454. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5455. {
  5456. int Result;
  5457. bool SaveSettings = false;
  5458. int Options =
  5459. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5460. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5461. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5462. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5463. bool Continue =
  5464. (UseDefaults == 0) ||
  5465. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5466. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5467. if (Continue)
  5468. {
  5469. Configuration->Usage->Inc(L"Synchronizations");
  5470. UpdateCopyParamCounters(CopyParam);
  5471. TSynchronizeOptions SynchronizeOptions;
  5472. GetSynchronizeOptions(Params, SynchronizeOptions);
  5473. if (SaveSettings)
  5474. {
  5475. GUIConfiguration->SynchronizeParams = Params;
  5476. }
  5477. else
  5478. {
  5479. SaveMode = false;
  5480. }
  5481. TDateTime StartTime = Now();
  5482. TSynchronizeChecklist * Checklist = NULL;
  5483. try
  5484. {
  5485. DebugAssert(!FAutoOperation);
  5486. FAutoOperation = true;
  5487. try
  5488. {
  5489. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5490. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5491. int Files = -1;
  5492. if (DataList->Count >= 1)
  5493. {
  5494. Files = StrToIntDef(DataList->Strings[0], Files);
  5495. }
  5496. else
  5497. {
  5498. DataList->Add(UnicodeString());
  5499. }
  5500. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5501. FSynchronizeProgressForm->Start();
  5502. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5503. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5504. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5505. &SynchronizeOptions);
  5506. if (Terminal->SessionData->CacheDirectories)
  5507. {
  5508. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5509. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5510. }
  5511. }
  5512. __finally
  5513. {
  5514. FAutoOperation = false;
  5515. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5516. SAFE_DESTROY(FSynchronizeProgressForm);
  5517. }
  5518. TSynchronizeParams SynchronizeParams;
  5519. SynchronizeParams.LocalDirectory = LocalDirectory;
  5520. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5521. SynchronizeParams.Mode = Mode;
  5522. SynchronizeParams.CopyParam = &CopyParam;
  5523. SynchronizeParams.Params = Params;
  5524. SynchronizeParams.Checklist = Checklist;
  5525. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5526. SynchronizeParams.StartTime = &StartTime;
  5527. SynchronizeParams.OnProcessedItem = NULL;
  5528. Result = Checklist->Count;
  5529. if (Checklist->Count > 0)
  5530. {
  5531. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5532. {
  5533. if (!DoSynchronizeChecklistDialog(
  5534. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5535. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5536. {
  5537. Result = -1;
  5538. }
  5539. }
  5540. else
  5541. {
  5542. FullSynchronize(SynchronizeParams, NULL, NULL);
  5543. }
  5544. }
  5545. else
  5546. {
  5547. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5548. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5549. }
  5550. }
  5551. __finally
  5552. {
  5553. delete Checklist;
  5554. }
  5555. OperationComplete(StartTime);
  5556. }
  5557. else
  5558. {
  5559. Result = -1;
  5560. }
  5561. return Result;
  5562. }
  5563. //---------------------------------------------------------------------------
  5564. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5565. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5566. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5567. {
  5568. if (Collect)
  5569. {
  5570. DebugAssert(FSynchronizeProgressForm != NULL);
  5571. if (!FSynchronizeProgressForm->Started)
  5572. {
  5573. FSynchronizeProgressForm->Start();
  5574. }
  5575. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5576. SetTaskbarListProgressValue(CompareProgress);
  5577. }
  5578. else
  5579. {
  5580. DebugAssert(FSynchronizeProgressForm == NULL);
  5581. DebugAssert(FProgressForm != NULL);
  5582. }
  5583. }
  5584. //---------------------------------------------------------------------------
  5585. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5586. {
  5587. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5588. TRemoteFile * File = NULL;
  5589. Terminal->ReadFile(FullFileName, File);
  5590. if (File != NULL)
  5591. {
  5592. std::unique_ptr<TRemoteFile> FileOwner(File);
  5593. TAutoFlag Flag(FStandaloneEditing);
  5594. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5595. Application->ShowMainForm = false;
  5596. Application->Run();
  5597. }
  5598. }
  5599. //---------------------------------------------------------------------------
  5600. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5601. {
  5602. DebugFail();
  5603. }
  5604. //---------------------------------------------------------------------------
  5605. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5606. {
  5607. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5608. SessionData->Assign(Terminal->SessionData);
  5609. UpdateSessionData(SessionData.get());
  5610. Terminal->UpdateSessionCredentials(SessionData.get());
  5611. if (!Terminal->SessionData->HasSessionName())
  5612. {
  5613. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5614. // once IsWorkspace is cleared
  5615. SessionData->Name = UnicodeString();
  5616. SessionData->IsWorkspace = false;
  5617. }
  5618. return SessionData.release();
  5619. }
  5620. //---------------------------------------------------------------------------
  5621. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5622. {
  5623. TSessionData * SessionData = CloneCurrentSessionData();
  5624. try
  5625. {
  5626. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5627. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5628. }
  5629. __finally
  5630. {
  5631. delete SessionData;
  5632. }
  5633. }
  5634. //---------------------------------------------------------------------------
  5635. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5636. {
  5637. TTerminalManager * Manager = TTerminalManager::Instance();
  5638. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5639. if (DebugAlwaysTrue(Terminal != NULL))
  5640. {
  5641. // Update (Managed)Terminal->StateData
  5642. UpdateTerminal(Terminal);
  5643. }
  5644. Manager->SaveWorkspace(DataList.get());
  5645. return DataList.release();
  5646. }
  5647. //---------------------------------------------------------------------------
  5648. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5649. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5650. {
  5651. WinConfiguration->LastWorkspace = Name;
  5652. if (!SavePasswords)
  5653. {
  5654. for (int Index = 0; Index < DataList->Count; Index++)
  5655. {
  5656. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5657. if (SessionData->Link.IsEmpty())
  5658. {
  5659. SessionData->ClearSessionPasswords();
  5660. }
  5661. }
  5662. }
  5663. StoredSessions->NewWorkspace(Name, DataList);
  5664. // modified only
  5665. StoredSessions->Save(false, Explicit);
  5666. }
  5667. //---------------------------------------------------------------------------
  5668. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5669. {
  5670. return
  5671. DefaultStr(WinConfiguration->LastWorkspace,
  5672. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5673. }
  5674. //---------------------------------------------------------------------------
  5675. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5676. {
  5677. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5678. bool AnyNonStoredSessionWithPassword = false;
  5679. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5680. bool AllNonStoredSessionsAnonymous = true;
  5681. TTerminalManager * Manager = TTerminalManager::Instance();
  5682. for (int Index = 0; Index < DataList->Count; Index++)
  5683. {
  5684. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5685. if (SessionData->Link.IsEmpty())
  5686. {
  5687. if (SessionData->HasAnySessionPassword())
  5688. {
  5689. AnyNonStoredSessionWithPassword = true;
  5690. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5691. {
  5692. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5693. }
  5694. }
  5695. if (!SameText(SessionData->UserName, AnonymousUserName))
  5696. {
  5697. AllNonStoredSessionsAnonymous = false;
  5698. }
  5699. }
  5700. }
  5701. bool SavePasswords;
  5702. bool * PSavePasswords;
  5703. bool NotRecommendedSavingPasswords =
  5704. !CustomWinConfiguration->UseMasterPassword &&
  5705. !AllNonStoredSessionsAnonymous;
  5706. if (Configuration->DisablePasswordStoring ||
  5707. !AnyNonStoredSessionWithPassword)
  5708. {
  5709. PSavePasswords = NULL;
  5710. SavePasswords = false;
  5711. }
  5712. else
  5713. {
  5714. PSavePasswords = &SavePasswords;
  5715. SavePasswords =
  5716. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5717. !NotRecommendedSavingPasswords;
  5718. }
  5719. UnicodeString Name = WorkspaceName();
  5720. bool CreateShortcut = false;
  5721. bool Result =
  5722. DoSaveWorkspaceDialog(
  5723. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5724. EnableAutoSave);
  5725. if (Result)
  5726. {
  5727. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5728. if (CreateShortcut)
  5729. {
  5730. TOperationVisualizer Visualizer;
  5731. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5732. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5733. }
  5734. if (EnableAutoSave)
  5735. {
  5736. WinConfiguration->AutoSaveWorkspace = true;
  5737. WinConfiguration->AutoWorkspace = Name;
  5738. if (PSavePasswords != NULL)
  5739. {
  5740. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5741. }
  5742. }
  5743. }
  5744. return Result;
  5745. }
  5746. //---------------------------------------------------------------------------
  5747. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5748. {
  5749. DebugAssert(!IsLocalBrowserMode());
  5750. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5751. if (WinConfiguration->PreservePanelState)
  5752. {
  5753. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5754. }
  5755. UpdateSessionData(Terminal->StateData);
  5756. }
  5757. //---------------------------------------------------------------------------
  5758. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5759. {
  5760. // Keep in sync with TSessionData::CopyStateData
  5761. DebugAssert(!IsLocalBrowserMode());
  5762. DebugAssert(Data != NULL);
  5763. // This is inconsistent with how color (for example) is handled.
  5764. Data->Name = Terminal->SessionData->Name;
  5765. // cannot use RemoteDirView->Path, because it is empty if connection
  5766. // was already closed
  5767. // also only peek, we may not be connected at all atm
  5768. // so make sure we do not try retrieving current directory from the server
  5769. // (particularly with FTP)
  5770. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5771. if (!ACurrentDirectory.IsEmpty())
  5772. {
  5773. Data->RemoteDirectory = ACurrentDirectory;
  5774. }
  5775. Data->Color = SessionColor;
  5776. }
  5777. //---------------------------------------------------------------------------
  5778. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5779. {
  5780. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5781. DebugAssert(Toolbar != NULL);
  5782. for (int i = 0; i < Toolbar->Items->Count; i++)
  5783. {
  5784. TTBXCustomDropDownItem * DropDownItem;
  5785. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5786. if (DropDownItem != NULL)
  5787. {
  5788. ToolbarItemResize(DropDownItem,
  5789. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5790. Toolbar->NonClientWidth);
  5791. break;
  5792. }
  5793. }
  5794. }
  5795. //---------------------------------------------------------------------------
  5796. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5797. {
  5798. Item->EditWidth = Width;
  5799. }
  5800. //---------------------------------------------------------------------------
  5801. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5802. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5803. {
  5804. for (int i = 0; i < Toolbar->Items->Count; i++)
  5805. {
  5806. TTBXCustomDropDownItem * DropDownItem;
  5807. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5808. if (DropDownItem != NULL)
  5809. {
  5810. ASize.x -= DropDownItem->EditWidth;
  5811. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5812. }
  5813. }
  5814. }
  5815. //---------------------------------------------------------------------------
  5816. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5817. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5818. {
  5819. if (WinConfiguration->DDWarnLackOfTempSpace)
  5820. {
  5821. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5822. if (!ADrive.IsEmpty())
  5823. {
  5824. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5825. DebugAssert(RequiredSpace >= 0);
  5826. __int64 RequiredWithReserve;
  5827. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5828. if (FreeSpace < RequiredWithReserve)
  5829. {
  5830. unsigned int Result;
  5831. TMessageParams Params(mpNeverAskAgainCheck);
  5832. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5833. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5834. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5835. if (Result == qaNeverAskAgain)
  5836. {
  5837. WinConfiguration->DDWarnLackOfTempSpace = false;
  5838. }
  5839. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5840. }
  5841. }
  5842. }
  5843. }
  5844. //---------------------------------------------------------------------------
  5845. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5846. {
  5847. DoOpenDirectoryDialog(odAddBookmark, Side);
  5848. }
  5849. //---------------------------------------------------------------------------
  5850. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5851. {
  5852. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5853. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5854. try
  5855. {
  5856. TCustomDirView * DView = DirView(Side);
  5857. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5858. {
  5859. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5860. }
  5861. }
  5862. catch (...)
  5863. {
  5864. delete VisitedDirectories;
  5865. throw;
  5866. }
  5867. return VisitedDirectories;
  5868. }
  5869. //---------------------------------------------------------------------------
  5870. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5871. TOpenDirectoryMode Mode, TOperationSide Side)
  5872. {
  5873. bool Continue = true;
  5874. if (Mode == odAddBookmark)
  5875. {
  5876. TMessageParams Params(mpNeverAskAgainCheck);
  5877. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5878. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5879. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5880. unsigned int Answer =
  5881. MessageDialog(Message,
  5882. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5883. if (Answer == qaNeverAskAgain)
  5884. {
  5885. Continue = true;
  5886. WinConfiguration->UseSharedBookmarks = true;
  5887. }
  5888. else if (Answer == qaOK)
  5889. {
  5890. Continue = true;
  5891. WinConfiguration->UseSharedBookmarks = false;
  5892. }
  5893. else
  5894. {
  5895. Continue = false;
  5896. }
  5897. }
  5898. if (Continue)
  5899. {
  5900. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5901. try
  5902. {
  5903. UnicodeString Name = DirView(Side)->PathName;
  5904. bool Repeat;
  5905. do
  5906. {
  5907. Repeat = false;
  5908. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5909. // do not allow switching to location profiles,
  5910. // if we are not connected
  5911. HasDirView[osLocal] && (Terminal != NULL)))
  5912. {
  5913. TWindowLock Lock(this);
  5914. if (!TryOpenDirectory(Side, Name))
  5915. {
  5916. Repeat = true;
  5917. Mode = odBrowse;
  5918. }
  5919. }
  5920. }
  5921. while (Repeat);
  5922. }
  5923. __finally
  5924. {
  5925. delete VisitedDirectories;
  5926. }
  5927. }
  5928. }
  5929. //---------------------------------------------------------------------------
  5930. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5931. {
  5932. DebugAssert(!FTerminal->CommandSessionOpened);
  5933. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5934. }
  5935. //---------------------------------------------------------------------------
  5936. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5937. {
  5938. bool Result = FTerminal->IsCapable[Capability] ||
  5939. FTerminal->CommandSessionOpened;
  5940. if (!Result)
  5941. {
  5942. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5943. if (!GUIConfiguration->ConfirmCommandSession)
  5944. {
  5945. Result = true;
  5946. }
  5947. else
  5948. {
  5949. TMessageParams Params(mpNeverAskAgainCheck);
  5950. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5951. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5952. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5953. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5954. if (Answer == qaNeverAskAgain)
  5955. {
  5956. GUIConfiguration->ConfirmCommandSession = false;
  5957. Result = true;
  5958. }
  5959. else if (Answer == qaOK)
  5960. {
  5961. Result = true;
  5962. }
  5963. }
  5964. if (Result)
  5965. {
  5966. Result = CommandSessionFallback();
  5967. }
  5968. }
  5969. return Result;
  5970. }
  5971. //---------------------------------------------------------------------------
  5972. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  5973. {
  5974. if (EnsureCommandSessionFallback(fcAnyCommand))
  5975. {
  5976. DoConsoleDialog(Terminal, Command);
  5977. }
  5978. }
  5979. //---------------------------------------------------------------------------
  5980. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  5981. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  5982. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  5983. {
  5984. if (!IsSideLocalBrowser(osRemote) &&
  5985. IsFileControl(DropSourceControl, osRemote) &&
  5986. (FDDExtMapFile != NULL))
  5987. {
  5988. Accept = true;
  5989. }
  5990. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  5991. DebugAssert(FDDTargetControl != NULL);
  5992. }
  5993. //---------------------------------------------------------------------------
  5994. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  5995. _di_IDataObject DataObj, int KeyState,
  5996. const TPoint & Point, int & Effect, bool & Accept)
  5997. {
  5998. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  5999. }
  6000. //---------------------------------------------------------------------------
  6001. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6002. _di_IDataObject DataObj, int KeyState,
  6003. const TPoint & Point, int & Effect, bool & Accept)
  6004. {
  6005. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6006. }
  6007. //---------------------------------------------------------------------------
  6008. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6009. TObject * Sender)
  6010. {
  6011. DebugUsedParam(Sender);
  6012. DebugAssert(FDDTargetControl == Sender);
  6013. FDDTargetControl = NULL;
  6014. }
  6015. //---------------------------------------------------------------------------
  6016. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6017. {
  6018. FileControlDDDragLeave(SessionsPageControl);
  6019. }
  6020. //---------------------------------------------------------------------------
  6021. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6022. {
  6023. FileControlDDDragLeave(QueueView3);
  6024. }
  6025. //---------------------------------------------------------------------------
  6026. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6027. {
  6028. DebugAssert(!IsSideLocalBrowser(Side));
  6029. DebugUsedParam(Side);
  6030. bool Edit = false;
  6031. TRemoteFile * File = NULL;
  6032. UnicodeString FileName;
  6033. UnicodeString PointTo;
  6034. bool SymbolicLink = true;
  6035. if (RemoteDirView->ItemFocused)
  6036. {
  6037. DebugAssert(RemoteDirView->ItemFocused->Data);
  6038. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6039. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6040. if (Edit)
  6041. {
  6042. FileName = File->FileName;
  6043. PointTo = File->LinkTo;
  6044. }
  6045. else
  6046. {
  6047. PointTo = File->FileName;
  6048. }
  6049. }
  6050. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6051. Terminal->IsCapable[fcHardLink]))
  6052. {
  6053. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6054. if (Edit)
  6055. {
  6056. DebugAssert(File->FileName == FileName);
  6057. int Params = dfNoRecursive;
  6058. Terminal->ExceptionOnFail = true;
  6059. try
  6060. {
  6061. Terminal->DeleteFile(L"", File, &Params);
  6062. }
  6063. __finally
  6064. {
  6065. Terminal->ExceptionOnFail = false;
  6066. }
  6067. }
  6068. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6069. }
  6070. }
  6071. //---------------------------------------------------------------------------
  6072. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6073. {
  6074. return
  6075. (IsSideLocalBrowser(Side) ||
  6076. ((Terminal != NULL) &&
  6077. Terminal->Active &&
  6078. Terminal->ResolvingSymlinks &&
  6079. Terminal->IsCapable[fcSymbolicLink]));
  6080. }
  6081. //---------------------------------------------------------------------------
  6082. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6083. {
  6084. return
  6085. !IsSideLocalBrowser(FCurrentSide) &&
  6086. (RemoteDirView->ItemFocused != NULL) &&
  6087. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6088. Terminal->SessionData->ResolveSymlinks;
  6089. }
  6090. //---------------------------------------------------------------------------
  6091. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6092. {
  6093. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6094. FForceExecution = true;
  6095. try
  6096. {
  6097. DirView(osCurrent)->ExecuteCurrentFile();
  6098. }
  6099. __finally
  6100. {
  6101. FForceExecution = false;
  6102. }
  6103. }
  6104. //---------------------------------------------------------------------------
  6105. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6106. {
  6107. TEditorData ExternalEditor;
  6108. ExternalEditor.Editor = edExternal;
  6109. bool Remember = false;
  6110. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6111. {
  6112. if (Remember)
  6113. {
  6114. TEditorList * EditorList = new TEditorList;
  6115. try
  6116. {
  6117. *EditorList = *WinConfiguration->EditorList;
  6118. bool Found = false;
  6119. int i = 0;
  6120. while (!Found && (i < EditorList->Count))
  6121. {
  6122. const TEditorPreferences * Editor = EditorList->Editors[i];
  6123. if ((Editor->Data->Editor == edExternal) &&
  6124. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6125. {
  6126. Found = true;
  6127. }
  6128. i++;
  6129. }
  6130. if (!Found)
  6131. {
  6132. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6133. WinConfiguration->EditorList = EditorList;
  6134. }
  6135. }
  6136. __finally
  6137. {
  6138. delete EditorList;
  6139. }
  6140. }
  6141. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6142. }
  6143. }
  6144. //---------------------------------------------------------------------------
  6145. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6146. {
  6147. FEditorManager->ProcessFiles(FileTerminalRemoved, Sender);
  6148. if (FFileFindTerminal == Sender)
  6149. {
  6150. FFileFindTerminal = NULL;
  6151. HideFileFindDialog();
  6152. }
  6153. if (FClipboardTerminal == Sender)
  6154. {
  6155. ClipboardClear(); // implies ClipboardStop
  6156. }
  6157. }
  6158. //---------------------------------------------------------------------------
  6159. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6160. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6161. {
  6162. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6163. DebugAssert(Terminal != NULL);
  6164. if (Data->Terminal == Terminal)
  6165. {
  6166. Data->Terminal = NULL;
  6167. }
  6168. }
  6169. //---------------------------------------------------------------------------
  6170. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6171. {
  6172. UpdateControls();
  6173. SessionColor = TColor(0);
  6174. UpdateRemotePathComboBox(false);
  6175. NeedSession(false);
  6176. }
  6177. //---------------------------------------------------------------------------
  6178. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6179. {
  6180. try
  6181. {
  6182. // Cache, as the login dialog can change its value
  6183. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6184. try
  6185. {
  6186. if (ShowLogin)
  6187. {
  6188. bool ReloadSessions = !Startup;
  6189. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  6190. }
  6191. else if (Startup && WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6192. // This detects if workspace was saved the last time the main widow was closed
  6193. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6194. {
  6195. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6196. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6197. }
  6198. }
  6199. __finally
  6200. {
  6201. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6202. // (so there was no chance for the user to open any session yet)
  6203. if ((ShowLogin || !Startup) &&
  6204. !WinConfiguration->KeepOpenWhenNoSession &&
  6205. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6206. {
  6207. TerminateApplication();
  6208. }
  6209. }
  6210. }
  6211. catch (EAbort &)
  6212. {
  6213. // swallow
  6214. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6215. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6216. }
  6217. }
  6218. //---------------------------------------------------------------------------
  6219. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6220. {
  6221. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6222. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6223. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6224. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6225. try
  6226. {
  6227. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6228. // Clear the design time unthemed tab
  6229. ((SessionsPageControl->PageCount > 0) &&
  6230. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6231. {
  6232. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6233. }
  6234. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6235. {
  6236. TThemeTabSheet * TabSheet;
  6237. if (Index >= SessionsPageControl->PageCount)
  6238. {
  6239. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6240. TabSheet->PageControl = SessionsPageControl;
  6241. }
  6242. else
  6243. {
  6244. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6245. }
  6246. bool IsSessionTab = (Index < TerminalList->Count);
  6247. if (IsSessionTab)
  6248. {
  6249. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6250. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6251. UpdateSessionTab(TabSheet);
  6252. }
  6253. else
  6254. {
  6255. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6256. TabSheet->Tag = 0; // not really needed
  6257. TabSheet->Shadowed = false;
  6258. // 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)
  6259. UpdateNewSessionTab();
  6260. }
  6261. TabSheet->ShowCloseButton = IsSessionTab;
  6262. }
  6263. }
  6264. __finally
  6265. {
  6266. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6267. }
  6268. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6269. }
  6270. //---------------------------------------------------------------------------
  6271. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6272. {
  6273. DoTerminalListChanged();
  6274. }
  6275. //---------------------------------------------------------------------------
  6276. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6277. {
  6278. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6279. DebugAssert(TabSheet->ImageIndex == 0);
  6280. TabSheet->Caption =
  6281. WinConfiguration->SelectiveToolbarText ?
  6282. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6283. UnicodeString();
  6284. }
  6285. //---------------------------------------------------------------------------
  6286. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6287. {
  6288. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6289. }
  6290. //---------------------------------------------------------------------------
  6291. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6292. {
  6293. if (DebugAlwaysTrue(TabSheet != NULL))
  6294. {
  6295. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6296. if (DebugAlwaysTrue(ATerminal != NULL))
  6297. {
  6298. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6299. TabSheet->ImageIndex = AddSessionColor(Color);
  6300. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6301. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6302. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6303. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6304. {
  6305. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6306. }
  6307. }
  6308. }
  6309. }
  6310. //---------------------------------------------------------------------------
  6311. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6312. {
  6313. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6314. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6315. bool Result = (Terminal != NULL);
  6316. if (Result)
  6317. {
  6318. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6319. }
  6320. else
  6321. {
  6322. try
  6323. {
  6324. NewSession(false);
  6325. }
  6326. __finally
  6327. {
  6328. DoTerminalListChanged();
  6329. }
  6330. FSessionsPageControlNewSessionTime = Now();
  6331. }
  6332. return Result;
  6333. }
  6334. //---------------------------------------------------------------------------
  6335. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6336. {
  6337. SessionTabSwitched();
  6338. }
  6339. //---------------------------------------------------------------------------
  6340. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6341. {
  6342. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6343. DebugAssert(TransferList != NULL);
  6344. UnicodeString Name;
  6345. if (TransferList->ItemIndex <= 0)
  6346. {
  6347. Name = L"";
  6348. }
  6349. else
  6350. {
  6351. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6352. }
  6353. if (FCopyParamAutoSelected.IsEmpty())
  6354. {
  6355. // if previous preset was not autoselected, make new preset the "default"
  6356. FCopyParamDefault = Name;
  6357. }
  6358. GUIConfiguration->CopyParamCurrent = Name;
  6359. }
  6360. //---------------------------------------------------------------------------
  6361. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6362. {
  6363. // sanity check
  6364. bool ExistingPreset =
  6365. (FTransferListHoverIndex >= 0) &&
  6366. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6367. DebugAssert(ExistingPreset);
  6368. if (ExistingPreset)
  6369. {
  6370. HDC DC = GetDC(0);
  6371. TCanvas * Canvas = new TCanvas();
  6372. try
  6373. {
  6374. Canvas->Handle = DC;
  6375. Canvas->Font = GetToolbarFont(this);
  6376. UnicodeString Name;
  6377. if (FTransferListHoverIndex == 0)
  6378. {
  6379. Name = L"";
  6380. }
  6381. else
  6382. {
  6383. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6384. }
  6385. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6386. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6387. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6388. static_cast<TObject*>(GetComponent(fcTransferList)));
  6389. UnicodeString InfoStr =
  6390. GUIConfiguration->CopyParamPreset[Name].
  6391. GetInfoStr(L"; ",
  6392. FLAGMASK(((Terminal != NULL) && Terminal->Active), Terminal->UsableCopyParamAttrs(0).General));
  6393. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6394. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6395. {
  6396. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6397. {
  6398. InfoStr.SetLength(InfoStr.Length() - 1);
  6399. }
  6400. InfoStr += Ellipsis;
  6401. }
  6402. // UpdateCaption does not cause invalidation of whole submenu, while
  6403. // setting Caption property does.
  6404. // also it probably does not resize the label, even if necessary
  6405. // (we do not want that anyway)
  6406. TransferLabel->UpdateCaption(InfoStr);
  6407. }
  6408. __finally
  6409. {
  6410. Canvas->Handle = NULL;
  6411. ReleaseDC(0, DC);
  6412. delete Canvas;
  6413. }
  6414. }
  6415. }
  6416. //---------------------------------------------------------------------------
  6417. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6418. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6419. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6420. {
  6421. if (FTransferListHoverIndex != AHoverIndex)
  6422. {
  6423. FTransferListHoverIndex = AHoverIndex;
  6424. UpdateTransferLabel();
  6425. }
  6426. }
  6427. //---------------------------------------------------------------------------
  6428. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6429. {
  6430. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6431. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6432. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6433. {
  6434. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6435. {
  6436. if (!NonVisualDataModule->Busy)
  6437. {
  6438. OpenDirectory(GetSide(osCurrent));
  6439. }
  6440. Message.Result = 1;
  6441. }
  6442. else
  6443. {
  6444. TForm::Dispatch(&Message);
  6445. }
  6446. }
  6447. else
  6448. {
  6449. TForm::Dispatch(&Message);
  6450. }
  6451. }
  6452. //---------------------------------------------------------------------------
  6453. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6454. {
  6455. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6456. if ((FIgnoreNextDialogChar != 0) &&
  6457. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6458. {
  6459. Message.Result = 1;
  6460. }
  6461. else
  6462. {
  6463. TForm::Dispatch(&Message);
  6464. }
  6465. FIgnoreNextDialogChar = 0;
  6466. }
  6467. //---------------------------------------------------------------------------
  6468. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6469. {
  6470. // The four low-order bits are used internally by Windows
  6471. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6472. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6473. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6474. // 61730 - restore thru double click - undocumented
  6475. // 61490 - maximize thru double click - undocumented
  6476. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6477. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6478. {
  6479. SysResizing(Cmd);
  6480. }
  6481. TForm::Dispatch(&Message);
  6482. }
  6483. //---------------------------------------------------------------------------
  6484. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6485. {
  6486. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6487. // Also there no point returning TRUE as we are not able to
  6488. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6489. // Hence the process termination might be safer :)
  6490. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6491. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6492. {
  6493. Message.Result = FALSE;
  6494. }
  6495. else
  6496. {
  6497. Message.Result = TRUE;
  6498. }
  6499. // Do not call default handling as that triggers OnCloseQuery,
  6500. // where our implementation will popup confirmation dialogs, what we do not want,
  6501. // as per Vista guidelines:
  6502. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6503. }
  6504. //---------------------------------------------------------------------------
  6505. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6506. {
  6507. if (Message.EndSession && IsApplicationMinimized())
  6508. {
  6509. // WORKAROUND
  6510. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6511. // when it receives WM_ENDSESSION,
  6512. // but that sometimes (particularly when application is minimized) cause crashes.
  6513. // Crash popups message that blocks log off.
  6514. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6515. // so we call ExitProcess() immediately, not even trying to cleanup.
  6516. // It still causes beep, so there's likely some popup, but it does not block
  6517. // log off.
  6518. ExitProcess(0);
  6519. }
  6520. TForm::Dispatch(&Message);
  6521. }
  6522. #ifdef _DEBUG
  6523. //---------------------------------------------------------------------------
  6524. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6525. {
  6526. TForm::Dispatch(&Message);
  6527. }
  6528. #endif
  6529. //---------------------------------------------------------------------------
  6530. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6531. {
  6532. }
  6533. //---------------------------------------------------------------------------
  6534. void __fastcall TCustomScpExplorerForm::DoShow()
  6535. {
  6536. // only now are the controls resized finally, so the size constraints
  6537. // will not conflict with possibly very small window size
  6538. RestoreFormParams();
  6539. // This indicates that the form was rescaled after parameters were loaded and
  6540. // as most probably the parameters were actually saved with the current form scaling
  6541. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6542. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6543. // and no rounding problems will occur.
  6544. // See also RestoreForm.
  6545. // (we should be safe to call RestoreParams unconditionally)
  6546. if (PixelsPerInch != Screen->PixelsPerInch)
  6547. {
  6548. RestoreParams();
  6549. }
  6550. FixControlsPlacement();
  6551. if (Position == poDefaultPosOnly)
  6552. {
  6553. CutFormToDesktop(this);
  6554. }
  6555. TForm::DoShow();
  6556. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6557. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6558. if (Terminal == NULL)
  6559. {
  6560. StartingDisconnected();
  6561. }
  6562. UpdatePixelsPerInchMainWindowCounter();
  6563. FShowing = true;
  6564. }
  6565. //---------------------------------------------------------------------------
  6566. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6567. {
  6568. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6569. }
  6570. //---------------------------------------------------------------------------
  6571. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6572. {
  6573. DoTerminalListChanged();
  6574. }
  6575. //---------------------------------------------------------------------------
  6576. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6577. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6578. TNotifyEvent OnBalloonClick, TObject * UserData)
  6579. {
  6580. bool Do;
  6581. UnicodeString Message;
  6582. if (E == NULL)
  6583. {
  6584. Message = Str;
  6585. Do = true;
  6586. }
  6587. else
  6588. {
  6589. Do = ExceptionMessage(E, Message);
  6590. }
  6591. if (Do && WinConfiguration->BalloonNotifications)
  6592. {
  6593. UnicodeString Title;
  6594. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6595. {
  6596. Message = TrimLeft(Message);
  6597. }
  6598. else
  6599. {
  6600. Message = UnformatMessage(Message);
  6601. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6602. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6603. Title = LoadResourceString(Captions[Type]);
  6604. if (Terminal != NULL)
  6605. {
  6606. Title = FORMAT(L"%s - %s",
  6607. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6608. }
  6609. }
  6610. if (Seconds == 0)
  6611. {
  6612. Seconds = WinConfiguration->NotificationsTimeout;
  6613. }
  6614. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6615. }
  6616. }
  6617. //---------------------------------------------------------------------------
  6618. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6619. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6620. UnicodeString HelpKeyword, const TMessageParams * Params,
  6621. TTerminal * Terminal)
  6622. {
  6623. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6624. (FOnFeedSynchronizeError != NULL)) &&
  6625. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6626. {
  6627. if (FOnFeedSynchronizeError != NULL)
  6628. {
  6629. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6630. }
  6631. else
  6632. {
  6633. DebugAssert(FErrorList != NULL);
  6634. TStringList * MoreMessagesCopy = NULL;
  6635. if (MoreMessages)
  6636. {
  6637. MoreMessagesCopy = new TStringList();
  6638. MoreMessagesCopy->Assign(MoreMessages);
  6639. }
  6640. FErrorList->AddObject(Message, MoreMessagesCopy);
  6641. }
  6642. PopupTrayBalloon(Terminal, Message, Type);
  6643. return ContinueAnswer(Answers);
  6644. }
  6645. else
  6646. {
  6647. bool UseBalloon = FTrayIcon->Visible;
  6648. if (UseBalloon)
  6649. {
  6650. PopupTrayBalloon(Terminal, Message, Type);
  6651. }
  6652. unsigned int Result;
  6653. try
  6654. {
  6655. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6656. }
  6657. __finally
  6658. {
  6659. // cancel only balloon we popped up, otherwise we may cancel notification
  6660. // balloon that was there before the message dialog
  6661. // (such as "dd confirmation opt in balloon)
  6662. if (UseBalloon)
  6663. {
  6664. FTrayIcon->CancelBalloon();
  6665. }
  6666. }
  6667. return Result;
  6668. }
  6669. }
  6670. //---------------------------------------------------------------------------
  6671. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6672. TTerminal * Terminal, Exception * E)
  6673. {
  6674. if (FTrayIcon->Visible)
  6675. {
  6676. PopupTrayBalloon(Terminal, L"", qtError, E);
  6677. }
  6678. // particularly prevent opening new session from jump list,
  6679. // while exception is shown
  6680. NonVisualDataModule->StartBusy();
  6681. try
  6682. {
  6683. ShowExtendedExceptionEx(Terminal, E);
  6684. }
  6685. __finally
  6686. {
  6687. NonVisualDataModule->EndBusy();
  6688. FTrayIcon->CancelBalloon();
  6689. }
  6690. }
  6691. //---------------------------------------------------------------------------
  6692. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6693. {
  6694. if (Terminal->Active)
  6695. {
  6696. InitStatusBar();
  6697. }
  6698. // cannot rely on active page being page for active terminal,
  6699. // as it can happen that active page is the "new session" page
  6700. // (e.g. when reconnecting active terminal, while login dialog
  6701. // invoked from "new session" page is modal)
  6702. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6703. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6704. }
  6705. //---------------------------------------------------------------------------
  6706. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6707. TTerminal * Terminal, Exception * E)
  6708. {
  6709. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6710. if (!Terminal->Active)
  6711. {
  6712. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6713. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6714. {
  6715. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6716. }
  6717. }
  6718. }
  6719. //---------------------------------------------------------------------------
  6720. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6721. UnicodeString Message, TQueryType Type,
  6722. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6723. {
  6724. if ((E == NULL) ||
  6725. ExceptionMessage(E, Message))
  6726. {
  6727. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6728. if (Important)
  6729. {
  6730. Seconds *= 5;
  6731. }
  6732. UnicodeString NoteMessage(UnformatMessage(Message));
  6733. if (Terminal != NULL)
  6734. {
  6735. NoteMessage = FORMAT(L"%s: %s",
  6736. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6737. }
  6738. if (WinConfiguration->BalloonNotifications)
  6739. {
  6740. AddNote(NoteMessage);
  6741. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6742. }
  6743. else
  6744. {
  6745. FlashOnBackground();
  6746. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6747. }
  6748. }
  6749. }
  6750. //---------------------------------------------------------------------------
  6751. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6752. {
  6753. RestoreApp();
  6754. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6755. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6756. !NonVisualDataModule->Busy)
  6757. {
  6758. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6759. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6760. if (!ComponentVisible[fcQueueView])
  6761. {
  6762. ToggleQueueVisibility();
  6763. GoToQueue();
  6764. }
  6765. }
  6766. }
  6767. //---------------------------------------------------------------------------
  6768. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6769. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6770. {
  6771. UnicodeString Message;
  6772. TNotifyEvent OnClick = NULL;
  6773. TObject * UserData = NULL;
  6774. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6775. switch (Event)
  6776. {
  6777. case qeEmptyButMonitored:
  6778. if ((ATerminal != Terminal) || QueueInvisible)
  6779. {
  6780. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6781. OnClick = QueueEmptyNoteClicked;
  6782. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6783. TerminalNoteData->Terminal = ATerminal;
  6784. UserData = TerminalNoteData;
  6785. }
  6786. break;
  6787. case qeEmpty:
  6788. OperationComplete(ATerminal->QueueOperationStart);
  6789. break;
  6790. case qePendingUserAction:
  6791. if ((ATerminal != Terminal) ||
  6792. (QueueInvisible && !IsQueueAutoPopup()))
  6793. {
  6794. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6795. }
  6796. break;
  6797. default:
  6798. DebugFail();
  6799. }
  6800. if (!Message.IsEmpty())
  6801. {
  6802. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6803. }
  6804. }
  6805. //---------------------------------------------------------------------------
  6806. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6807. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6808. {
  6809. if (FDDExtMapFile != NULL)
  6810. {
  6811. CloseHandle(FDDExtMapFile);
  6812. FDDExtMapFile = NULL;
  6813. }
  6814. if (WinConfiguration->DDFakeFile)
  6815. {
  6816. DDFakeFileInitDrag(FileList, Created);
  6817. }
  6818. }
  6819. //---------------------------------------------------------------------------
  6820. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6821. {
  6822. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6823. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6824. {
  6825. FFakeFileDropTarget = FileName;
  6826. }
  6827. }
  6828. //---------------------------------------------------------------------------
  6829. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6830. {
  6831. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6832. if (!ForceDirectories(ApiPath(Result)))
  6833. {
  6834. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6835. }
  6836. FileSetAttr(ApiPath(Result), faHidden);
  6837. return Result;
  6838. }
  6839. //---------------------------------------------------------------------------
  6840. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6841. bool & Created)
  6842. {
  6843. FFakeFileDropTarget = UnicodeString();
  6844. FDragFakeDirectory = CreateFakeTransferDirectory();
  6845. FileList->AddItem(NULL, FDragFakeDirectory);
  6846. Created = true;
  6847. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6848. {
  6849. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6850. }
  6851. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6852. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6853. {
  6854. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6855. TDragExtCommStruct* CommStruct;
  6856. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6857. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6858. DebugAssert(CommStruct != NULL);
  6859. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6860. CommStruct->Dragging = true;
  6861. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6862. LENOF(CommStruct->DropDest));
  6863. NULL_TERMINATE(CommStruct->DropDest);
  6864. UnmapViewOfFile(CommStruct);
  6865. }
  6866. }
  6867. //---------------------------------------------------------------------------
  6868. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6869. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6870. {
  6871. bool Result;
  6872. DebugAssert(!IsLocalBrowserMode());
  6873. if (Sender == RemoteDirView)
  6874. {
  6875. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6876. }
  6877. else
  6878. {
  6879. DebugAssert(Sender == RemoteDriveView);
  6880. TStrings * FileList = RemoteDriveView->DragFileList();
  6881. try
  6882. {
  6883. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6884. }
  6885. __finally
  6886. {
  6887. delete FileList;
  6888. }
  6889. }
  6890. if (FDDTargetControl == RemoteDriveView)
  6891. {
  6892. RemoteDriveView->UpdateDropTarget();
  6893. }
  6894. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6895. // or from tree view to dir view.
  6896. // foMove happens when file/dir is dragged from remote tree view outside of
  6897. // application via dragex
  6898. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6899. (DropSourceControl == RemoteDriveView))
  6900. {
  6901. RemoteDriveView->UpdateDropSource();
  6902. }
  6903. return Result;
  6904. }
  6905. //---------------------------------------------------------------------------
  6906. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6907. {
  6908. DebugAssert(!IsLocalBrowserMode());
  6909. // This also handles drops of remote files to queue.
  6910. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6911. SAFE_DESTROY(FDDFileList);
  6912. if (!FFakeFileDropTarget.IsEmpty())
  6913. {
  6914. RemoveDir(ApiPath(FFakeFileDropTarget));
  6915. }
  6916. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6917. {
  6918. try
  6919. {
  6920. TDragResult DDResult = (Sender == RemoteDirView) ?
  6921. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6922. // Focus is moved to the target application,
  6923. // but as we are going to present the UI, we need to steal the focus back.
  6924. // This most likely won't work though (windows does not allow application
  6925. // to steal focus most of the time)
  6926. Application->BringToFront();
  6927. // On older version of Windows we never got drMove here, see also comment below.
  6928. // On Windows 10, we get the "move".
  6929. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6930. {
  6931. UnicodeString TargetDirectory;
  6932. TFileOperation Operation;
  6933. // drInvalid may mean drMove, see comment below
  6934. switch (DDResult)
  6935. {
  6936. case drCopy:
  6937. Operation = foCopy;
  6938. break;
  6939. case drMove:
  6940. Operation = foMove;
  6941. break;
  6942. default:
  6943. DebugFail();
  6944. case drInvalid:
  6945. // prefer "copy" for safety
  6946. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6947. break;
  6948. }
  6949. TTransferOperationParam Param;
  6950. UnicodeString CounterName;
  6951. bool ForceQueue;
  6952. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  6953. {
  6954. // we get drInvalid both if d&d was intercepted by ddext,
  6955. // and when users drops on no-drop location.
  6956. // we tell the difference by existence of response from ddext,
  6957. // so we ignore absence of response in this case
  6958. if (DDResult != drInvalid)
  6959. {
  6960. // here we know that the extension is installed,
  6961. // as it is checked as soon as drag&drop starts from
  6962. // RemoteFileControlDDCreateDragFileList
  6963. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  6964. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  6965. {
  6966. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  6967. }
  6968. else
  6969. {
  6970. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  6971. }
  6972. }
  6973. }
  6974. else
  6975. {
  6976. // download using fake file
  6977. Param.Temp = false;
  6978. Param.DragDrop = true;
  6979. if (ForceQueue)
  6980. {
  6981. Param.Queue = asOn;
  6982. }
  6983. if (Sender == RemoteDirView)
  6984. {
  6985. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  6986. }
  6987. if (RemoteFileControlFileOperation(Sender, Operation,
  6988. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  6989. {
  6990. Configuration->Usage->Inc(CounterName);
  6991. }
  6992. }
  6993. }
  6994. }
  6995. __finally
  6996. {
  6997. CloseHandle(FDDExtMapFile);
  6998. FDDExtMapFile = NULL;
  6999. delete FDragFakeMonitors;
  7000. FDragFakeMonitors = NULL;
  7001. RemoveDir(ApiPath(FDragFakeDirectory));
  7002. FDragFakeDirectory = L"";
  7003. FFakeFileDropTarget = UnicodeString();
  7004. }
  7005. }
  7006. if (FDragDropSshTerminate.get() != NULL)
  7007. {
  7008. FDragDropSshTerminate->Rethrow();
  7009. }
  7010. }
  7011. //---------------------------------------------------------------------------
  7012. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7013. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7014. {
  7015. // Remember drop effect so we know (when user drops files), if we copy or move
  7016. FLastDropEffect = dwEffect;
  7017. }
  7018. //---------------------------------------------------------------------------
  7019. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7020. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7021. {
  7022. bool Result;
  7023. if (FDDTargetControl == QueueView3)
  7024. {
  7025. Directory = DefaultDownloadTargetDirectory();
  7026. Result = true;
  7027. CounterName = L"DownloadsDragDropQueue";
  7028. ForceQueue = true;
  7029. }
  7030. else if (!FFakeFileDropTarget.IsEmpty())
  7031. {
  7032. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7033. Result = true;
  7034. ForceQueue = false;
  7035. CounterName = L"DownloadsDragDropFakeFile";
  7036. }
  7037. else
  7038. {
  7039. ForceQueue = false;
  7040. Enabled = false;
  7041. try
  7042. {
  7043. int Timer = 0;
  7044. Result = false;
  7045. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7046. {
  7047. {
  7048. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7049. TDragExtCommStruct* CommStruct;
  7050. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7051. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7052. DebugAssert(CommStruct != NULL);
  7053. Result = !CommStruct->Dragging;
  7054. if (Result)
  7055. {
  7056. Directory = ExtractFilePath(CommStruct->DropDest);
  7057. CounterName = L"DownloadsDragDropExternalExt";
  7058. }
  7059. UnmapViewOfFile(CommStruct);
  7060. }
  7061. if (!Result)
  7062. {
  7063. Sleep(50);
  7064. Timer += 50;
  7065. Application->ProcessMessages();
  7066. }
  7067. }
  7068. }
  7069. __finally
  7070. {
  7071. Enabled = true;
  7072. }
  7073. }
  7074. return Result;
  7075. }
  7076. //---------------------------------------------------------------------------
  7077. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7078. const UnicodeString TempDir, int SecDelay)
  7079. {
  7080. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7081. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7082. if (FDelayedDeletionTimer == NULL)
  7083. {
  7084. DebugAssert(HandleAllocated());
  7085. FDelayedDeletionTimer = new TTimer(this);
  7086. FDelayedDeletionTimer->Interval = 10000;
  7087. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7088. }
  7089. else
  7090. {
  7091. FDelayedDeletionTimer->Enabled = true;
  7092. }
  7093. }
  7094. //---------------------------------------------------------------------------
  7095. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7096. {
  7097. DebugAssert(FDelayedDeletionList != NULL);
  7098. TDateTime N = Now();
  7099. TDateTime Alert;
  7100. UnicodeString Directory;
  7101. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7102. {
  7103. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7104. if ((N >= Alert) || (Sender == NULL))
  7105. {
  7106. Directory = FDelayedDeletionList->Strings[Index];
  7107. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7108. {
  7109. FDelayedDeletionList->Delete(Index);
  7110. }
  7111. }
  7112. }
  7113. if (FDelayedDeletionList->Count == 0)
  7114. {
  7115. FDelayedDeletionTimer->Enabled = false;
  7116. }
  7117. }
  7118. //---------------------------------------------------------------------------
  7119. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7120. {
  7121. DebugAssert(!IsLocalBrowserMode());
  7122. if (IsFileControl(FDDTargetControl, osRemote) ||
  7123. (FDDTargetControl == SessionsPageControl))
  7124. {
  7125. TTerminal * TargetTerminal = NULL;
  7126. TFileOperation Operation = foNone;
  7127. if (FDDTargetControl == SessionsPageControl)
  7128. {
  7129. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7130. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7131. // do not allow dropping on the "+" tab
  7132. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7133. if (TargetTerminal != NULL)
  7134. {
  7135. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7136. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7137. {
  7138. Operation = foRemoteMove;
  7139. }
  7140. else
  7141. {
  7142. Operation = foRemoteCopy;
  7143. }
  7144. }
  7145. }
  7146. else
  7147. {
  7148. if (FLastDropEffect == DROPEFFECT_MOVE)
  7149. {
  7150. Operation = foRemoteMove;
  7151. }
  7152. else if (FLastDropEffect == DROPEFFECT_COPY)
  7153. {
  7154. Operation = foRemoteCopy;
  7155. }
  7156. }
  7157. if (Operation != foNone)
  7158. {
  7159. RemoteFileControlFileOperation(DropSourceControl,
  7160. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7161. }
  7162. // abort drag&drop
  7163. Abort();
  7164. }
  7165. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7166. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7167. (FDDTargetControl != QueueView3))
  7168. {
  7169. DebugAssert(!FDragTempDir.IsEmpty());
  7170. TTransferType Type;
  7171. UnicodeString TempDir = FDragTempDir;
  7172. // We clear FDragTempDir before calling
  7173. // just in case it fail (raises exception)
  7174. FDragTempDir = L"";
  7175. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7176. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7177. // empty directory parameter means temp directory -> don't display it!
  7178. UnicodeString TargetDir = L"";
  7179. int Options = 0;
  7180. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7181. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7182. {
  7183. Abort();
  7184. }
  7185. // TargetDir is set when dropped on local file control
  7186. // (this was workaround for legacy dirview event handling, now it should be
  7187. // made prettier)
  7188. if (TargetDir.IsEmpty())
  7189. {
  7190. TargetDir = TempDir;
  7191. if (ForceDirectories(ApiPath(TargetDir)))
  7192. {
  7193. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7194. FPendingTempSpaceWarn = true;
  7195. try
  7196. {
  7197. FDragDropOperation = true;
  7198. int Params = cpTemporary |
  7199. (Type == ttMove ? cpDelete : 0);
  7200. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7201. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7202. }
  7203. __finally
  7204. {
  7205. FDragDropOperation = false;
  7206. FPendingTempSpaceWarn = false;
  7207. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7208. }
  7209. }
  7210. else
  7211. {
  7212. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7213. }
  7214. }
  7215. }
  7216. }
  7217. //---------------------------------------------------------------------------
  7218. void __fastcall TCustomScpExplorerForm::DDDownload(
  7219. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7220. {
  7221. DebugAssert(!IsLocalBrowserMode());
  7222. TAutoBatch AutoBatch(this);
  7223. UpdateCopyParamCounters(*CopyParam);
  7224. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7225. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7226. {
  7227. RemoteDriveView->UpdateDropSource();
  7228. }
  7229. }
  7230. //---------------------------------------------------------------------------
  7231. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7232. {
  7233. public:
  7234. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7235. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7236. {
  7237. }
  7238. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7239. {
  7240. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7241. TDataObjectFilesEx::AllowData(FormatEtc);
  7242. }
  7243. };
  7244. //---------------------------------------------------------------------------
  7245. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7246. TObject * Sender, TDataObject *& DataObject)
  7247. {
  7248. if (FDDExtMapFile != NULL)
  7249. {
  7250. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7251. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7252. {
  7253. Abort();
  7254. }
  7255. if (FileList->Count > 0)
  7256. {
  7257. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7258. if (!FilesObject->IsValid(true, true))
  7259. {
  7260. FilesObject->_Release();
  7261. }
  7262. else
  7263. {
  7264. DataObject = FilesObject;
  7265. }
  7266. }
  7267. }
  7268. }
  7269. //---------------------------------------------------------------------------
  7270. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7271. {
  7272. DebugFail();
  7273. }
  7274. //---------------------------------------------------------------------------
  7275. void __fastcall TCustomScpExplorerForm::GoToTree()
  7276. {
  7277. ComponentVisible[fcRemoteTree] = true;
  7278. DriveView(osRemote)->SetFocus();
  7279. }
  7280. //---------------------------------------------------------------------------
  7281. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7282. TPanelExport Export)
  7283. {
  7284. TCustomDirView * DirView = this->DirView(Side);
  7285. std::unique_ptr<TStrings> ExportData(new TStringList());
  7286. switch (Export)
  7287. {
  7288. case pePath:
  7289. ExportData->Add(DirView->PathName);
  7290. break;
  7291. case peFileList:
  7292. case peFullFileList:
  7293. {
  7294. bool FullPath = (Export == peFullFileList);
  7295. DirView->CreateFileList(false, FullPath, ExportData.get());
  7296. for (int Index = 0; Index < ExportData->Count; Index++)
  7297. {
  7298. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7299. {
  7300. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7301. }
  7302. }
  7303. }
  7304. break;
  7305. default:
  7306. DebugFail();
  7307. }
  7308. return ExportData.release();
  7309. }
  7310. //---------------------------------------------------------------------------
  7311. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7312. TPanelExport Export, TPanelExportDestination Destination)
  7313. {
  7314. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7315. PanelExportStore(Side, Export, Destination, ExportData.get());
  7316. }
  7317. //---------------------------------------------------------------------------
  7318. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7319. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7320. TStrings * ExportData)
  7321. {
  7322. if (Destination == pedClipboard)
  7323. {
  7324. TInstantOperationVisualizer Visualizer;
  7325. CopyToClipboard(ExportData);
  7326. }
  7327. else
  7328. {
  7329. DebugFail();
  7330. }
  7331. }
  7332. //---------------------------------------------------------------------------
  7333. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7334. {
  7335. TCustomDirView * DirView = this->DirView(Side);
  7336. UnicodeString Mask = DirView->Mask;
  7337. if (DoFilterMaskDialog(DirView, Mask))
  7338. {
  7339. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7340. Configuration->Usage->Inc(L"Filters");
  7341. }
  7342. }
  7343. //---------------------------------------------------------------------------
  7344. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7345. {
  7346. return FQueueController->DefaultOperation();
  7347. }
  7348. //---------------------------------------------------------------------------
  7349. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7350. TQueueOperation Operation, void ** Param)
  7351. {
  7352. switch (Operation)
  7353. {
  7354. case qoPreferences:
  7355. return true;
  7356. case qoGoTo:
  7357. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7358. case qoOnceEmpty:
  7359. return IsAnythingQueued();
  7360. default:
  7361. return FQueueController->AllowOperation(Operation, Param);
  7362. }
  7363. }
  7364. //---------------------------------------------------------------------------
  7365. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7366. {
  7367. if (DebugAlwaysTrue(QueueView3->Visible))
  7368. {
  7369. QueueView3->SetFocus();
  7370. }
  7371. }
  7372. //---------------------------------------------------------------------------
  7373. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7374. TQueueOperation Operation, void * Param)
  7375. {
  7376. if (Operation == qoGoTo)
  7377. {
  7378. GoToQueue();
  7379. }
  7380. else if (Operation == qoPreferences)
  7381. {
  7382. PreferencesDialog(pmQueue);
  7383. }
  7384. else
  7385. {
  7386. FQueueController->ExecuteOperation(Operation, Param);
  7387. }
  7388. }
  7389. //---------------------------------------------------------------------------
  7390. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7391. {
  7392. return (Queue != NULL) && Queue->Enabled;
  7393. }
  7394. //---------------------------------------------------------------------------
  7395. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7396. {
  7397. DebugAssert(Queue != NULL);
  7398. if (Queue != NULL)
  7399. {
  7400. Queue->Enabled = !Queue->Enabled;
  7401. }
  7402. }
  7403. //---------------------------------------------------------------------------
  7404. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7405. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7406. {
  7407. FQueueActedItem = QueueView3->ItemFocused;
  7408. }
  7409. //---------------------------------------------------------------------------
  7410. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7411. {
  7412. return TopDock->Height + QueueSplitter->Height;
  7413. }
  7414. //---------------------------------------------------------------------------
  7415. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7416. {
  7417. return
  7418. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7419. (QueueDock->Visible ? QueueDock->Height : 0) +
  7420. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7421. }
  7422. //---------------------------------------------------------------------------
  7423. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7424. {
  7425. return ScaleByTextHeight(this, 48);
  7426. }
  7427. //---------------------------------------------------------------------------
  7428. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7429. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7430. {
  7431. // when queue is hidden by double-clicking splitter, stray attempt to
  7432. // resize the panel with strange value arrives, make sure it is ignored
  7433. if (ComponentVisible[fcQueueView])
  7434. {
  7435. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7436. if (NewSize > MaxHeightLimit)
  7437. {
  7438. NewSize = MaxHeightLimit;
  7439. }
  7440. int MinHeightLimit =
  7441. GetStaticQueuePanelComponentsHeight() +
  7442. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7443. GetMinQueueViewHeight();
  7444. if (NewSize < MinHeightLimit)
  7445. {
  7446. NewSize = MinHeightLimit;
  7447. }
  7448. }
  7449. else
  7450. {
  7451. Accept = false;
  7452. }
  7453. }
  7454. //---------------------------------------------------------------------------
  7455. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7456. {
  7457. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7458. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7459. if (QueueViewHeight < GetMinQueueViewHeight())
  7460. {
  7461. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7462. }
  7463. }
  7464. //---------------------------------------------------------------------------
  7465. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7466. TDragObject *& /*DragObject*/)
  7467. {
  7468. FQueueActedItem = QueueView3->ItemFocused;
  7469. }
  7470. //---------------------------------------------------------------------------
  7471. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7472. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7473. {
  7474. Accept = true;
  7475. if (Source == QueueView3)
  7476. {
  7477. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7478. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7479. if (Accept)
  7480. {
  7481. TQueueItemProxy * QueueItem;
  7482. TQueueItemProxy * DestQueueItem;
  7483. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7484. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7485. Accept = (QueueItem != DestQueueItem) &&
  7486. (QueueItem->Status == TQueueItem::qsPending) &&
  7487. (DestQueueItem->Status == TQueueItem::qsPending);
  7488. }
  7489. }
  7490. }
  7491. //---------------------------------------------------------------------------
  7492. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7493. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7494. {
  7495. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7496. {
  7497. TQueueItemProxy * QueueItem;
  7498. TQueueItemProxy * DestQueueItem;
  7499. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7500. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7501. QueueItem->Move(DestQueueItem);
  7502. }
  7503. }
  7504. //---------------------------------------------------------------------------
  7505. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7506. {
  7507. if ((QueueView3->ItemFocused == NULL) &&
  7508. (QueueView3->Items->Count > 0))
  7509. {
  7510. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7511. }
  7512. QueueLabelUpdateStatus();
  7513. }
  7514. //---------------------------------------------------------------------------
  7515. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7516. {
  7517. QueueLabelUpdateStatus();
  7518. }
  7519. //---------------------------------------------------------------------------
  7520. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7521. {
  7522. QueueLabel->UpdateStatus();
  7523. }
  7524. //---------------------------------------------------------------------------
  7525. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7526. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7527. {
  7528. if (Selected)
  7529. {
  7530. NonVisualDataModule->UpdateNonVisibleActions();
  7531. }
  7532. }
  7533. //---------------------------------------------------------------------------
  7534. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7535. {
  7536. TDragDropFilesEx * Result = NULL;
  7537. if (Sender == SessionsPageControl)
  7538. {
  7539. Result = FSessionsDragDropFilesEx;
  7540. }
  7541. else if (Sender == QueueView3)
  7542. {
  7543. Result = FQueueDragDropFilesEx;
  7544. }
  7545. else
  7546. {
  7547. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7548. if (DirView != NULL)
  7549. {
  7550. Result = DirView->DragDropFilesEx;
  7551. }
  7552. else
  7553. {
  7554. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7555. if (DriveView != NULL)
  7556. {
  7557. Result = DriveView->DragDropFilesEx;
  7558. }
  7559. }
  7560. }
  7561. DebugAssert(Result != NULL);
  7562. return Result;
  7563. }
  7564. //---------------------------------------------------------------------------
  7565. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7566. {
  7567. return (DView->SelCount == DView->FilesCount);
  7568. }
  7569. //---------------------------------------------------------------------------
  7570. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7571. {
  7572. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7573. }
  7574. //---------------------------------------------------------------------------
  7575. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7576. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7577. {
  7578. DebugAssert(!IsLocalBrowserMode());
  7579. TFileOperation Operation;
  7580. switch (Effect)
  7581. {
  7582. case DROPEFFECT_MOVE:
  7583. Operation = foMove;
  7584. break;
  7585. case DROPEFFECT_COPY:
  7586. // occures on WinXP (reported by user)
  7587. default:
  7588. Operation = foCopy;
  7589. break;
  7590. };
  7591. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7592. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7593. if (DragDropFilesEx->FileList->Count > 0)
  7594. {
  7595. TStrings * FileList = new TStringList();
  7596. try
  7597. {
  7598. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7599. {
  7600. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7601. }
  7602. FDragDropOperation = true;
  7603. TTransferOperationParam Param;
  7604. Param.TargetDirectory = TargetPath;
  7605. // upload, no temp dirs
  7606. Param.Temp = false;
  7607. Param.DragDrop = DragDrop;
  7608. Param.Options =
  7609. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7610. if (ForceQueue)
  7611. {
  7612. Param.Queue = asOn;
  7613. }
  7614. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7615. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7616. {
  7617. if (IsFileControl(DropSourceControl, osLocal))
  7618. {
  7619. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7620. }
  7621. else
  7622. {
  7623. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7624. }
  7625. }
  7626. }
  7627. __finally
  7628. {
  7629. FDragDropOperation = false;
  7630. delete FileList;
  7631. }
  7632. }
  7633. }
  7634. //---------------------------------------------------------------------------
  7635. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7636. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7637. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7638. {
  7639. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7640. }
  7641. //---------------------------------------------------------------------------
  7642. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7643. TObject * Sender, int grfKeyState, int & dwEffect)
  7644. {
  7645. DebugAssert(!IsLocalBrowserMode());
  7646. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7647. if ((dwEffect != DROPEFFECT_NONE) &&
  7648. IsFileControl(DropSourceControl, osRemote))
  7649. {
  7650. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7651. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7652. (RemoteDirView->DropTarget == NULL))
  7653. {
  7654. dwEffect = DROPEFFECT_NONE;
  7655. }
  7656. else
  7657. {
  7658. if (dwEffect == DROPEFFECT_COPY)
  7659. {
  7660. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7661. // currently we support copying always (at least via temporary directory);
  7662. // remove associated checks once this all proves stable and working
  7663. bool CopyCapable = true;
  7664. // if we do not support neither of operations, there's no discussion
  7665. if (!MoveCapable && !CopyCapable)
  7666. {
  7667. dwEffect = DROPEFFECT_NONE;
  7668. }
  7669. else
  7670. {
  7671. // The default effect inside remote panel is move,
  7672. // unless we do not support it, but support copy
  7673. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7674. {
  7675. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7676. }
  7677. else
  7678. {
  7679. // with ctrl-down, we want copy unless it is not supported
  7680. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7681. }
  7682. }
  7683. }
  7684. }
  7685. }
  7686. }
  7687. //---------------------------------------------------------------------------
  7688. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7689. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7690. {
  7691. DebugAssert(!IsLocalBrowserMode());
  7692. if (FDDTotalSize >= 0)
  7693. {
  7694. if (File->IsDirectory)
  7695. {
  7696. FDDTotalSize = -1;
  7697. }
  7698. else
  7699. {
  7700. FDDTotalSize += File->Size;
  7701. }
  7702. }
  7703. DebugAssert(!FDragTempDir.IsEmpty());
  7704. // TODO: this is quite ineffective
  7705. // TODO: what if invalid character replacement is disabled?
  7706. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7707. UnicodeString TransferFileName;
  7708. if (Sender == RemoteDriveView)
  7709. {
  7710. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7711. }
  7712. else
  7713. {
  7714. TransferFileName = File->FileName;
  7715. }
  7716. FDDFileList->AddObject(TransferFileName, File);
  7717. }
  7718. //---------------------------------------------------------------------------
  7719. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7720. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7721. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7722. {
  7723. // sometimes we do not get DDEnd so the list is not released
  7724. SAFE_DESTROY(FDDFileList);
  7725. FDDFileList = new TStringList();
  7726. FDragTempDir = WinConfiguration->TemporaryDir();
  7727. FDDTotalSize = 0;
  7728. FDragDropSshTerminate.reset(NULL);
  7729. }
  7730. //---------------------------------------------------------------------------
  7731. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7732. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7733. HRESULT & Result)
  7734. {
  7735. if (Result == DRAGDROP_S_DROP)
  7736. {
  7737. try
  7738. {
  7739. GlobalDragImageList->HideDragImage();
  7740. try
  7741. {
  7742. RemoteFileControlDDTargetDrop();
  7743. }
  7744. catch(ESshTerminate & E)
  7745. {
  7746. FDragDropSshTerminate.reset(E.Clone());
  7747. }
  7748. }
  7749. catch (Exception &E)
  7750. {
  7751. // If downloading fails we need to cancel drag&drop, otherwise
  7752. // Explorer shows error
  7753. // But by the way exception probably never reach this point as
  7754. // it's catched on way.
  7755. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7756. Result = DRAGDROP_S_CANCEL;
  7757. ShowExtendedException(Terminal, &E);
  7758. }
  7759. }
  7760. }
  7761. //---------------------------------------------------------------------------
  7762. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7763. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7764. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7765. {
  7766. TFileMasks::TParams MaskParams;
  7767. MaskParams.Size = Size;
  7768. MaskParams.Modification = Modification;
  7769. // this does not re-parse the mask if it is the same as the last time
  7770. FDirViewMatchMask = Masks;
  7771. bool ImplicitMatch;
  7772. Matches =
  7773. // RecurseInclude parameter has no effect as the Path is empty
  7774. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7775. (AllowImplicitMatches || !ImplicitMatch);
  7776. }
  7777. //---------------------------------------------------------------------------
  7778. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7779. TObject * Sender, TListItem * Item, WORD & Indexes)
  7780. {
  7781. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7782. UnicodeString Ext;
  7783. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7784. {
  7785. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7786. }
  7787. else
  7788. {
  7789. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7790. }
  7791. if (SameText(Ext, Configuration->PartialExt))
  7792. {
  7793. Indexes |= oiPartial;
  7794. }
  7795. }
  7796. //---------------------------------------------------------------------------
  7797. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7798. {
  7799. return
  7800. DirViewEnabled(osCurrent) &&
  7801. DirView(osCurrent)->CanPasteFromClipBoard();
  7802. }
  7803. //---------------------------------------------------------------------------
  7804. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7805. {
  7806. bool Result = false;
  7807. if (CanPasteToDirViewFromClipBoard())
  7808. {
  7809. Result = true;
  7810. }
  7811. else
  7812. {
  7813. UnicodeString ClipboardText;
  7814. if (NonEmptyTextFromClipboard(ClipboardText))
  7815. {
  7816. if (StoredSessions->IsUrl(ClipboardText))
  7817. {
  7818. Result = true;
  7819. }
  7820. else
  7821. {
  7822. Result = DirViewEnabled(osCurrent);
  7823. }
  7824. }
  7825. }
  7826. return Result;
  7827. }
  7828. //---------------------------------------------------------------------------
  7829. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7830. {
  7831. if (DoesClipboardContainOurFiles())
  7832. {
  7833. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7834. {
  7835. DebugAssert(!IsLocalBrowserMode());
  7836. TTerminalManager * Manager = TTerminalManager::Instance();
  7837. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7838. Manager->ActiveTerminal = FClipboardTerminal;
  7839. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7840. }
  7841. }
  7842. else if (CanPasteToDirViewFromClipBoard())
  7843. {
  7844. DirView(osCurrent)->PasteFromClipBoard();
  7845. }
  7846. else
  7847. {
  7848. UnicodeString ClipboardText;
  7849. if (NonEmptyTextFromClipboard(ClipboardText))
  7850. {
  7851. if (StoredSessions->IsUrl(ClipboardText))
  7852. {
  7853. NewSession(false, ClipboardText);
  7854. }
  7855. else
  7856. {
  7857. DirView(osCurrent)->Path = ClipboardText;
  7858. }
  7859. }
  7860. }
  7861. }
  7862. //---------------------------------------------------------------------------
  7863. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7864. {
  7865. // TBD
  7866. }
  7867. //---------------------------------------------------------------------------
  7868. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7869. {
  7870. TCustomDirView * ADirView = DirView(Side);
  7871. ADirView->SelectAll(Mode);
  7872. ADirView->SetFocus();
  7873. }
  7874. //---------------------------------------------------------------------------
  7875. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7876. {
  7877. TCustomDirView * ADirView = DirView(Side);
  7878. TFileFilter Filter;
  7879. DefaultFileFilter(Filter);
  7880. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7881. {
  7882. Configuration->Usage->Inc(L"MaskSelections");
  7883. ADirView->SelectFiles(Filter, Select);
  7884. ADirView->SetFocus();
  7885. }
  7886. }
  7887. //---------------------------------------------------------------------------
  7888. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7889. {
  7890. TCustomDirView * ADirView = DirView(Side);
  7891. ADirView->RestoreSelectedNames();
  7892. ADirView->SetFocus();
  7893. }
  7894. //---------------------------------------------------------------------------
  7895. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7896. {
  7897. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7898. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7899. {
  7900. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7901. UnicodeString Ext;
  7902. if (!IsSideLocalBrowser(osCurrent))
  7903. {
  7904. Ext = UnixExtractFileExt(FileName);
  7905. }
  7906. else
  7907. {
  7908. Ext = ExtractFileExt(FileName);
  7909. }
  7910. if (Ext.IsEmpty())
  7911. {
  7912. Ext = L".";
  7913. }
  7914. TFileFilter Filter;
  7915. Filter.Masks = FORMAT(L"*%s", (Ext));
  7916. Filter.Directories = false;
  7917. CurrentDirView->SelectFiles(Filter, Select);
  7918. }
  7919. }
  7920. //---------------------------------------------------------------------------
  7921. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7922. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7923. {
  7924. UnicodeString Result;
  7925. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7926. {
  7927. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  7928. }
  7929. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  7930. {
  7931. // noop
  7932. }
  7933. else
  7934. {
  7935. Result =
  7936. FMTLOAD(FILE_INFO_FORMAT,
  7937. (FormatBytes(FileInfo.SelectedSize),
  7938. FormatBytes(FileInfo.FilesSize),
  7939. FormatNumber(FileInfo.SelectedCount),
  7940. FormatNumber(FileInfo.FilesCount)));
  7941. }
  7942. return Result;
  7943. }
  7944. //---------------------------------------------------------------------------
  7945. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7946. TTBXStatusPanel * Panel, TOperationSide Side)
  7947. {
  7948. if (Panel->Index == 1)
  7949. {
  7950. ToggleShowHiddenFiles();
  7951. }
  7952. else if (Panel->Index == 2)
  7953. {
  7954. Filter(Side);
  7955. }
  7956. }
  7957. //---------------------------------------------------------------------------
  7958. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  7959. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  7960. {
  7961. DebugAssert(!StatusBar->SimplePanel);
  7962. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  7963. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  7964. }
  7965. //---------------------------------------------------------------------------
  7966. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  7967. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  7968. {
  7969. DebugAssert(StatusBar->Panels->Count >= 3);
  7970. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  7971. if (FileInfo.HiddenCount > 0)
  7972. {
  7973. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  7974. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7975. }
  7976. else
  7977. {
  7978. HiddenFilesPanel->ViewPriority = 0;
  7979. // not really necessary, just to cleanup no-longer-valid data
  7980. HiddenFilesPanel->Caption = L"";
  7981. }
  7982. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  7983. if (FileInfo.FilteredCount > 0)
  7984. {
  7985. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  7986. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7987. }
  7988. else
  7989. {
  7990. FilteredFilesPanel->ViewPriority = 0;
  7991. // not really necessary, just to cleanup no-longer-valid data
  7992. FilteredFilesPanel->Caption = L"";
  7993. }
  7994. }
  7995. //---------------------------------------------------------------------------
  7996. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  7997. TObject * /*Sender*/)
  7998. {
  7999. if (DirView(osRemote)->Enabled)
  8000. {
  8001. DirView(osRemote)->SetFocus();
  8002. }
  8003. }
  8004. //---------------------------------------------------------------------------
  8005. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8006. {
  8007. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8008. switch (Config.Show)
  8009. {
  8010. case qvShow:
  8011. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8012. {
  8013. Config.Show = qvHide;
  8014. }
  8015. else
  8016. {
  8017. Config.Show = Config.LastHideShow;
  8018. }
  8019. break;
  8020. case qvHideWhenEmpty:
  8021. if (ComponentVisible[fcQueueView])
  8022. {
  8023. Config.Show = qvHide;
  8024. }
  8025. else
  8026. {
  8027. Config.LastHideShow = Config.Show;
  8028. Config.Show = qvShow;
  8029. }
  8030. break;
  8031. case qvHide:
  8032. Config.LastHideShow = Config.Show;
  8033. Config.Show = qvShow;
  8034. break;
  8035. }
  8036. WinConfiguration->QueueView = Config;
  8037. }
  8038. //---------------------------------------------------------------------------
  8039. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8040. {
  8041. UnicodeString Result;
  8042. if (FTerminal != NULL)
  8043. {
  8044. switch (WinConfiguration->PathInCaption)
  8045. {
  8046. case picShort:
  8047. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8048. break;
  8049. case picFull:
  8050. Result = FTerminal->CurrentDirectory;
  8051. break;
  8052. }
  8053. }
  8054. return Result;
  8055. }
  8056. //---------------------------------------------------------------------------
  8057. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8058. {
  8059. TColor Result = GetWindowColor(FSessionColor);
  8060. return Result;
  8061. }
  8062. //---------------------------------------------------------------------------
  8063. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8064. {
  8065. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8066. return Result;
  8067. }
  8068. //---------------------------------------------------------------------------
  8069. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8070. {
  8071. TTerminalManager::Instance()->UpdateAppTitle();
  8072. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8073. // background to gray on Windows 7 (works on Windows 10).
  8074. // See also EnableControl
  8075. if (Showing)
  8076. {
  8077. if (Terminal != NULL)
  8078. {
  8079. // Update path when it changes
  8080. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8081. {
  8082. UpdateSessionTab(SessionsPageControl->ActivePage);
  8083. }
  8084. }
  8085. NonVisualDataModule->ReconnectSessionAction->Update();
  8086. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8087. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8088. CenterReconnectToolbar();
  8089. bool HasTerminal = (Terminal != NULL) && Terminal->Active;
  8090. if (HasTerminal)
  8091. {
  8092. // TODO needed yet with second local browser?
  8093. if (!RemoteDirView->Enabled)
  8094. {
  8095. RemoteDirView->Enabled = true;
  8096. if (FRemoteDirViewWasFocused)
  8097. {
  8098. ActiveControl = RemoteDirView;
  8099. }
  8100. }
  8101. RemoteDirView->Color = PanelColor();
  8102. }
  8103. else
  8104. {
  8105. if (RemoteDirView->Enabled)
  8106. {
  8107. // This is first called when the form is being constructed
  8108. // (not anymore due to Showing test above)
  8109. // but the false is overriden in the constructor later.
  8110. // An even later in TScpCommanderForm::DoShow()
  8111. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  8112. RemoteDirView->Enabled = false;
  8113. }
  8114. RemoteDirView->Color = DisabledPanelColor();
  8115. }
  8116. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8117. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8118. RemoteDriveView->Color = RemoteDirView->Color;
  8119. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8120. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8121. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8122. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8123. QueueFileList->Enabled = QueueView3->Enabled;
  8124. QueueFileList->Color = QueueView3->Color;
  8125. QueueFileList->Font->Color = QueueView3->Font->Color;
  8126. QueueLabelUpdateStatus();
  8127. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8128. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8129. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  8130. }
  8131. }
  8132. //---------------------------------------------------------------------------
  8133. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8134. {
  8135. UpdateControls();
  8136. }
  8137. //---------------------------------------------------------------------------
  8138. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8139. TObject * Sender)
  8140. {
  8141. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8142. DebugAssert(DirView != NULL);
  8143. DoDirViewLoaded(DirView);
  8144. TransferPresetAutoSelect();
  8145. }
  8146. //---------------------------------------------------------------------------
  8147. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8148. {
  8149. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8150. // first run after installation
  8151. if (double(Updates.LastCheck) == 0)
  8152. {
  8153. // make sure next time there will be an update (if enabled)
  8154. Updates.LastCheck = TDateTime(1);
  8155. WinConfiguration->Updates = Updates;
  8156. }
  8157. else if ((double(Updates.Period) > 0) &&
  8158. (Now() - Updates.LastCheck >= Updates.Period))
  8159. {
  8160. TThreadMethod OnUpdatesChecked = NULL;
  8161. if (!IsUWP())
  8162. {
  8163. OnUpdatesChecked = UpdatesChecked;
  8164. }
  8165. StartUpdateThread(OnUpdatesChecked);
  8166. }
  8167. }
  8168. //---------------------------------------------------------------------------
  8169. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8170. {
  8171. UnicodeString Message;
  8172. bool New;
  8173. TQueryType Type;
  8174. GetUpdatesMessage(Message, New, Type, false);
  8175. if (!Message.IsEmpty())
  8176. {
  8177. if (New)
  8178. {
  8179. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8180. }
  8181. if (!New && (Type != qtWarning))
  8182. {
  8183. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8184. }
  8185. else
  8186. {
  8187. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8188. }
  8189. if (New)
  8190. {
  8191. Configuration->Usage->Inc(L"UpdateNotifications");
  8192. }
  8193. }
  8194. }
  8195. //---------------------------------------------------------------------------
  8196. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8197. {
  8198. RestoreApp();
  8199. bool CanDisplay = !NonVisualDataModule->Busy;
  8200. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8201. {
  8202. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8203. }
  8204. if (CanDisplay)
  8205. {
  8206. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8207. CheckForUpdates(true);
  8208. }
  8209. else
  8210. {
  8211. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8212. }
  8213. }
  8214. //---------------------------------------------------------------------------
  8215. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8216. TCopyParamRuleData & Data)
  8217. {
  8218. DebugAssert(Terminal != NULL);
  8219. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8220. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8221. Data.RemoteDirectory = RemoteDirView->PathName;
  8222. }
  8223. //---------------------------------------------------------------------------
  8224. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8225. {
  8226. // Terminal can be null when we are changing local directory implicitly,
  8227. // because it has been deleted, while no session is connected
  8228. // (Login dialog is open)
  8229. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8230. {
  8231. DebugAssert(!IsLocalBrowserMode());
  8232. TCopyParamRuleData Data;
  8233. GetTransferPresetAutoSelectData(Data);
  8234. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8235. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8236. if (CopyParamIndex < 0)
  8237. {
  8238. // there is no preset that matches autoselection
  8239. // set preset that we consider "default"
  8240. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8241. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8242. }
  8243. else
  8244. {
  8245. // there is preset matching autoselection
  8246. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8247. if (CopyParamName == FCopyParamAutoSelected)
  8248. {
  8249. // autoselected the same preset as the last time
  8250. // make no change (i.e. preserve custom user preset, if any)
  8251. }
  8252. else
  8253. {
  8254. // autoselected the different preset then the last time (or there
  8255. // was default preset set)
  8256. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8257. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8258. }
  8259. }
  8260. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8261. {
  8262. if (CopyParamIndex >= 0)
  8263. {
  8264. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8265. }
  8266. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8267. try
  8268. {
  8269. int Fmt =
  8270. (CopyParamIndex < 0) ?
  8271. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8272. COPY_PARAM_AUTOSELECTED;
  8273. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8274. Data->Message = MainInstructions(Message);
  8275. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8276. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8277. CopyParamAttrs);
  8278. if (CopyParamIndex >= 0)
  8279. {
  8280. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8281. Info = FORMAT(L"%s\n \n%s", (Info,
  8282. FMTLOAD(COPY_PARAM_RULE,
  8283. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8284. }
  8285. Data->Message += L"\n\n" + Info;
  8286. if (WinConfiguration->CopyParamAutoSelectNotice)
  8287. {
  8288. TransferPresetNoteMessage(Data, true);
  8289. }
  8290. else
  8291. {
  8292. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8293. Data = NULL; // ownership passed
  8294. }
  8295. }
  8296. __finally
  8297. {
  8298. delete Data;
  8299. }
  8300. }
  8301. }
  8302. }
  8303. //---------------------------------------------------------------------------
  8304. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8305. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8306. {
  8307. DebugAssert(NoteData != NULL);
  8308. DebugAssert(!IsLocalBrowserMode());
  8309. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8310. TQueryButtonAlias Aliases[1];
  8311. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8312. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8313. Params.Aliases = Aliases;
  8314. Params.AliasesCount = LENOF(Aliases);
  8315. unsigned int Result =
  8316. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8317. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8318. switch (Result)
  8319. {
  8320. case qaNeverAskAgain:
  8321. DebugAssert(AllowNeverAskAgain);
  8322. WinConfiguration->CopyParamAutoSelectNotice = false;
  8323. break;
  8324. case qaIgnore:
  8325. PreferencesDialog(pmPresets);
  8326. break;
  8327. }
  8328. }
  8329. //---------------------------------------------------------------------------
  8330. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8331. {
  8332. // as of now useless, as this is used for notes only, never for balloons, ...
  8333. RestoreApp();
  8334. // .. and we should never be busy here
  8335. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8336. {
  8337. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8338. }
  8339. }
  8340. //---------------------------------------------------------------------------
  8341. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8342. TPreferencesMode APreferencesMode)
  8343. {
  8344. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8345. TCopyParamRuleData Data;
  8346. if (Terminal != NULL)
  8347. {
  8348. PreferencesData.reset(new TPreferencesDialogData());
  8349. GetTransferPresetAutoSelectData(Data);
  8350. PreferencesData->CopyParamRuleData = &Data;
  8351. }
  8352. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8353. }
  8354. //---------------------------------------------------------------------------
  8355. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8356. const TCustomCommandType & Command)
  8357. {
  8358. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8359. {
  8360. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (Command.Command)));
  8361. }
  8362. }
  8363. //---------------------------------------------------------------------------
  8364. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8365. {
  8366. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8367. TCustomCommandType Command;
  8368. // make sure we use local custom command when remote are not supported
  8369. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8370. {
  8371. Command = FLastCustomCommand;
  8372. }
  8373. else
  8374. {
  8375. Command.Params = Command.Params | ccLocal;
  8376. }
  8377. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8378. FEditingFocusedAdHocCommand = OnFocused;
  8379. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8380. int Options =
  8381. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8382. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8383. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8384. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8385. {
  8386. FLastCustomCommand = Command;
  8387. UpdateCustomCommandsToolbar();
  8388. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8389. }
  8390. }
  8391. //---------------------------------------------------------------------------
  8392. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8393. {
  8394. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8395. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8396. DebugAssert(State > 0);
  8397. if (State <= 0)
  8398. {
  8399. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (FLastCustomCommand.Command)));
  8400. }
  8401. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8402. }
  8403. //---------------------------------------------------------------------------
  8404. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8405. TCustomCommandType & Command, int & State)
  8406. {
  8407. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8408. if (Result)
  8409. {
  8410. Command = FLastCustomCommand;
  8411. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8412. }
  8413. return Result;
  8414. }
  8415. //---------------------------------------------------------------------------
  8416. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8417. {
  8418. ResetIncrementalSearch();
  8419. }
  8420. //---------------------------------------------------------------------------
  8421. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8422. {
  8423. DebugAssert(ComponentVisible[Component]);
  8424. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8425. }
  8426. //---------------------------------------------------------------------------
  8427. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8428. {
  8429. // when queue panel is resized here directly, the status bar is stretched
  8430. // over whole space the panel occupied
  8431. PostComponentHide(fcQueueView);
  8432. }
  8433. //---------------------------------------------------------------------------
  8434. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8435. {
  8436. ComponentVisible[fcQueueFileList] = false;
  8437. }
  8438. //---------------------------------------------------------------------------
  8439. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8440. {
  8441. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8442. RefreshColorMode();
  8443. WinConfiguration->ResetSysDarkTheme();
  8444. ConfigurationChanged();
  8445. ConfigureInterface();
  8446. // Should be called for all controls
  8447. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8448. }
  8449. //---------------------------------------------------------------------------
  8450. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8451. {
  8452. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8453. if (!FInvalid &&
  8454. (Message.LParam != 0) &&
  8455. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8456. {
  8457. ThemeChanged();
  8458. }
  8459. TForm::Dispatch(&Message);
  8460. }
  8461. //---------------------------------------------------------------------------
  8462. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8463. {
  8464. TMessage * M = static_cast<TMessage*>(Message);
  8465. switch (M->Msg)
  8466. {
  8467. case CM_DIALOGCHAR:
  8468. CMDialogChar(*M);
  8469. break;
  8470. case WM_APPCOMMAND:
  8471. WMAppCommand(*M);
  8472. break;
  8473. case WM_SYSCOMMAND:
  8474. WMSysCommand(*M);
  8475. break;
  8476. case WM_QUERYENDSESSION:
  8477. WMQueryEndSession(*M);
  8478. break;
  8479. case WM_ENDSESSION:
  8480. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8481. break;
  8482. #ifdef _DEBUG
  8483. case WM_WINDOWPOSCHANGED:
  8484. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8485. break;
  8486. case CM_CUSTOMSTYLECHANGED:
  8487. TForm::Dispatch(Message);
  8488. break;
  8489. #endif
  8490. case WM_COMPONENT_HIDE:
  8491. {
  8492. Byte Component = static_cast<Byte>(M->WParam);
  8493. // sanity check
  8494. if (ComponentVisible[Component])
  8495. {
  8496. // special treatment
  8497. if (Component == fcQueueView)
  8498. {
  8499. ToggleQueueVisibility();
  8500. DebugAssert(!ComponentVisible[fcQueueView]);
  8501. }
  8502. else
  8503. {
  8504. ComponentVisible[Component] = false;
  8505. }
  8506. }
  8507. }
  8508. break;
  8509. case WM_COPYDATA:
  8510. WMCopyData(*M);
  8511. break;
  8512. case WM_MANAGES_CAPTION:
  8513. // caption managed in TTerminalManager::UpdateAppTitle()
  8514. M->Result = 1;
  8515. break;
  8516. case WM_WANTS_MOUSEWHEEL:
  8517. M->Result = 1;
  8518. break;
  8519. case CM_SHOWINGCHANGED:
  8520. CMShowingChanged(*M);
  8521. break;
  8522. case WM_CLOSE:
  8523. WMClose(*M);
  8524. break;
  8525. case WM_DPICHANGED:
  8526. WMDpiChanged(*M);
  8527. break;
  8528. case CM_DPICHANGED:
  8529. CMDpiChanged(*M);
  8530. break;
  8531. case WM_SETTINGCHANGE:
  8532. WMSettingChange(*M);
  8533. break;
  8534. case CM_DIALOGKEY:
  8535. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8536. break;
  8537. default:
  8538. TForm::Dispatch(Message);
  8539. break;
  8540. }
  8541. }
  8542. //---------------------------------------------------------------------------
  8543. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8544. {
  8545. // noop
  8546. }
  8547. //---------------------------------------------------------------------------
  8548. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8549. {
  8550. TForm::Dispatch(&Message);
  8551. FSessionColors->Clear();
  8552. AddFixedSessionImages();
  8553. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8554. UpdateImages();
  8555. }
  8556. //---------------------------------------------------------------------------
  8557. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8558. {
  8559. TForm::Dispatch(&Message);
  8560. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8561. UpdatePixelsPerInchMainWindowCounter();
  8562. }
  8563. //---------------------------------------------------------------------------
  8564. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8565. {
  8566. // Cannot close window while we are busy.
  8567. // We cannot test this in FormCloseQuery as that is called also from
  8568. // Close(), which is called by CloseApplicationAction. So we can be busy
  8569. // there already even, when it is legitimate to close the application.
  8570. // Possibly a better place to handle this would be WMSysCommand.
  8571. if (NonVisualDataModule->Busy)
  8572. {
  8573. Message.Result = 1;
  8574. }
  8575. else
  8576. {
  8577. TForm::Dispatch(&Message);
  8578. }
  8579. }
  8580. //---------------------------------------------------------------------------
  8581. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8582. {
  8583. TForm::Dispatch(&Message);
  8584. if (Showing && (Terminal == NULL))
  8585. {
  8586. // When we are starting minimized (i.e. from an installer),
  8587. // postpone showing Login dialog until we get restored.
  8588. // Otherwise the Login dialog (and Authentication window) show restored
  8589. // over invisible (minimized) main window.
  8590. if (WindowState == wsMinimized)
  8591. {
  8592. FNeedSession = true;
  8593. }
  8594. else
  8595. {
  8596. // This happens before application ever goes idle, so the toolbars would
  8597. // stay enabled (initial state) until the Login dialog is dismissed.
  8598. UpdateActions();
  8599. NonVisualDataModule->StartBusy();
  8600. try
  8601. {
  8602. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8603. // otherwise the dialog does not receive focus.
  8604. // With Commander interface the ProcessMessages is called already
  8605. // by TDriveView, but with Explorer interface, we need to call it explicily
  8606. Application->ProcessMessages();
  8607. // do not reload sessions, they have been loaded just now (optimization)
  8608. NeedSession(true);
  8609. }
  8610. __finally
  8611. {
  8612. NonVisualDataModule->EndBusy();
  8613. }
  8614. }
  8615. }
  8616. }
  8617. //---------------------------------------------------------------------------
  8618. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8619. {
  8620. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8621. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8622. }
  8623. //---------------------------------------------------------------------------
  8624. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8625. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8626. int & MaxHeight)
  8627. {
  8628. // workaround for bug in TWinControl.CalcConstraints
  8629. // Check for empty rect (restore from iconic state) is done there only after
  8630. // call to AdjustClientRect, which enlarges the rect (for forms).
  8631. TRect R = GetClientRect();
  8632. // when restoring from iconic state, place no restrictions
  8633. if (IsRectEmpty(R))
  8634. {
  8635. MinWidth = 0;
  8636. MinHeight = 0;
  8637. MaxWidth = 32000;
  8638. MaxHeight = 32000;
  8639. }
  8640. }
  8641. //---------------------------------------------------------------------------
  8642. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8643. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8644. {
  8645. // terminal can be already closed (e.g. dropped connection)
  8646. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8647. {
  8648. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8649. try
  8650. {
  8651. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8652. }
  8653. catch(...)
  8654. {
  8655. if (!Terminal->Active)
  8656. {
  8657. Close = true;
  8658. }
  8659. throw;
  8660. }
  8661. }
  8662. }
  8663. //---------------------------------------------------------------------------
  8664. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8665. {
  8666. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8667. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8668. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8669. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8670. {
  8671. OnGetSpaceAvailable = GetSpaceAvailable;
  8672. }
  8673. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8674. OnGetSpaceAvailable);
  8675. }
  8676. //---------------------------------------------------------------------------
  8677. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8678. {
  8679. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8680. Terminal->FillSessionDataForCode(Data.get());
  8681. return Data.release();
  8682. }
  8683. //---------------------------------------------------------------------------
  8684. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8685. {
  8686. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8687. DoGenerateUrlDialog(Data.get(), Paths);
  8688. }
  8689. //---------------------------------------------------------------------------
  8690. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8691. {
  8692. GenerateUrl(NULL);
  8693. }
  8694. //---------------------------------------------------------------------------
  8695. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8696. {
  8697. std::unique_ptr<TStrings> Paths(new TStringList());
  8698. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8699. GenerateUrl(Paths.get());
  8700. }
  8701. //---------------------------------------------------------------------------
  8702. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8703. {
  8704. FSessionColor = value;
  8705. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8706. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8707. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8708. DebugAssert(ColorItem != NULL);
  8709. ColorItem->Color = C;
  8710. NonVisualDataModule->ColorMenuItem->Color = C;
  8711. UpdateControls();
  8712. }
  8713. //---------------------------------------------------------------------------
  8714. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8715. {
  8716. if (value != FSessionColor)
  8717. {
  8718. UpdateSessionColor(value);
  8719. // Is null when called from LastTerminalClosed
  8720. if (Terminal != NULL)
  8721. {
  8722. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8723. }
  8724. }
  8725. }
  8726. //---------------------------------------------------------------------------
  8727. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8728. {
  8729. bool Result = FNoteTimer->Enabled;
  8730. if (Result)
  8731. {
  8732. // cannot cancel note too early
  8733. bool NotEarly =
  8734. (Now() - FNoteShown >
  8735. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8736. if (Force || NotEarly)
  8737. {
  8738. FNoteTimer->Enabled = false;
  8739. FNote = L"";
  8740. SAFE_DESTROY(FNoteData);
  8741. FOnNoteClick = NULL;
  8742. FNoteHints = FNotes->Text;
  8743. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8744. UpdateStatusBar();
  8745. }
  8746. }
  8747. return Result;
  8748. }
  8749. //---------------------------------------------------------------------------
  8750. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8751. {
  8752. DebugAssert(FNoteTimer->Enabled);
  8753. CancelNote(true);
  8754. }
  8755. //---------------------------------------------------------------------------
  8756. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8757. {
  8758. int P = Note.Pos(L"\n");
  8759. if (P > 0)
  8760. {
  8761. Note.SetLength(P - 1);
  8762. }
  8763. FNotes->Add(FORMAT(L"[%s] %s",
  8764. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8765. while (FNotes->Count > 10)
  8766. {
  8767. FNotes->Delete(0);
  8768. }
  8769. if (UpdateNow)
  8770. {
  8771. FNoteHints = FNotes->Text;
  8772. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8773. UpdateStatusBar();
  8774. }
  8775. }
  8776. //---------------------------------------------------------------------------
  8777. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8778. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8779. {
  8780. int P = Note.Pos(L"\n");
  8781. if (P > 0)
  8782. {
  8783. Note.SetLength(P - 1);
  8784. }
  8785. FNoteHints = FNotes->Text;
  8786. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8787. FNote = Note;
  8788. SAFE_DESTROY(FNoteData);
  8789. FNoteData = NoteData;
  8790. FOnNoteClick = OnNoteClick;
  8791. AddNote(Note, false);
  8792. UpdateStatusBar();
  8793. FNoteShown = Now();
  8794. FNoteTimer->Enabled = false;
  8795. if (Seconds == 0)
  8796. {
  8797. Seconds = WinConfiguration->NotificationsTimeout;
  8798. }
  8799. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8800. FNoteTimer->Enabled = true;
  8801. }
  8802. //---------------------------------------------------------------------------
  8803. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8804. {
  8805. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8806. }
  8807. //---------------------------------------------------------------------------
  8808. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8809. {
  8810. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked)
  8811. {
  8812. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8813. }
  8814. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8815. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8816. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  8817. 0, NULL, NULL);
  8818. }
  8819. //---------------------------------------------------------------------------
  8820. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8821. {
  8822. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8823. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8824. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8825. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8826. }
  8827. //---------------------------------------------------------------------------
  8828. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8829. {
  8830. WinConfiguration->FormatSizeBytes = Style;
  8831. }
  8832. //---------------------------------------------------------------------------
  8833. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8834. {
  8835. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8836. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8837. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8838. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8839. }
  8840. //---------------------------------------------------------------------------
  8841. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8842. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8843. {
  8844. if (Panel->Index == 0)
  8845. {
  8846. if (FOnNoteClick != NULL)
  8847. {
  8848. // prevent the user data from being freed by possible call
  8849. // to CancelNote or PostNote during call to OnNoteClick
  8850. std::unique_ptr<TObject> NoteData(FNoteData);
  8851. TNotifyEvent OnNoteClick = FOnNoteClick;
  8852. FNoteData = NULL;
  8853. // need to cancel the note as we are going to delete its user data
  8854. CancelNote(true);
  8855. OnNoteClick(NoteData.get());
  8856. }
  8857. }
  8858. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8859. {
  8860. FileSystemInfo();
  8861. }
  8862. }
  8863. //---------------------------------------------------------------------------
  8864. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8865. {
  8866. // workaround:
  8867. // 1) for unknown reason, disabling window, while minimized,
  8868. // prevents it from restoring, even if it was enabled again meanwhile
  8869. // 2) when disabling the main window, while another has focus
  8870. // minimize is no longer possible
  8871. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8872. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8873. // Shouldn't we use IsApplicationMinimized() here?
  8874. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8875. {
  8876. Enabled = false;
  8877. }
  8878. FLockLevel++;
  8879. }
  8880. //---------------------------------------------------------------------------
  8881. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8882. {
  8883. DebugAssert(FLockLevel > 0);
  8884. FLockLevel--;
  8885. if (FLockLevel == 0)
  8886. {
  8887. DebugAssert(FLockSuspendLevel == 0);
  8888. Enabled = true;
  8889. }
  8890. }
  8891. //---------------------------------------------------------------------------
  8892. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8893. {
  8894. // We need to make sure that window is enabled when the last modal window closes
  8895. // otherwise focus is not restored correctly.
  8896. // So we re-enable the window when modal window opens and
  8897. // disable it back after is closes
  8898. if (FLockLevel > 0)
  8899. {
  8900. // while we have nesting counter, we know that we never be called
  8901. // recursivelly as Application->OnModalBegin is called only
  8902. // for the top-level modal window
  8903. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8904. {
  8905. // won't be disabled when conditions in LockWindow() were not satisfied
  8906. FDisabledOnLockSuspend = !Enabled;
  8907. // When minimized to tray (or actually when set to SW_HIDE),
  8908. // setting Enabled makes the window focusable even when there's
  8909. // modal window over it
  8910. if (!FTrayIcon->Visible)
  8911. {
  8912. Enabled = true;
  8913. }
  8914. }
  8915. FLockSuspendLevel++;
  8916. }
  8917. }
  8918. //---------------------------------------------------------------------------
  8919. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8920. {
  8921. if (FLockSuspendLevel > 0)
  8922. {
  8923. DebugAssert(FLockLevel > 0);
  8924. FLockSuspendLevel--;
  8925. // see comment in SuspendWindowLock
  8926. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8927. {
  8928. // Note that window can be enabled here, when we were minized to tray when
  8929. // was SuspendWindowLock() called.
  8930. // We should possibly do the same check as in LockWindow(),
  8931. // if it is ever possible that the consitions change between
  8932. // SuspendWindowLock() and ResumeWindowLock()
  8933. Enabled = !FDisabledOnLockSuspend;
  8934. }
  8935. }
  8936. }
  8937. //---------------------------------------------------------------------------
  8938. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8939. {
  8940. if (!TextOnly)
  8941. {
  8942. TTBXComboBoxItem * RemotePathComboBox =
  8943. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8944. TStrings * Items = RemotePathComboBox->Strings;
  8945. Items->BeginUpdate();
  8946. try
  8947. {
  8948. Items->Clear();
  8949. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  8950. {
  8951. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8952. while (!IsUnixRootPath(APath))
  8953. {
  8954. int P = APath.LastDelimiter(L'/');
  8955. DebugAssert(P >= 0);
  8956. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8957. APath.SetLength(P - 1);
  8958. }
  8959. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8960. }
  8961. }
  8962. __finally
  8963. {
  8964. RemotePathComboBox->ItemIndex = Items->Count - 1;
  8965. // Setting ItemIndex to -1 does not reset its text
  8966. if (Items->Count == 0)
  8967. {
  8968. RemotePathComboBox->Text = L"";
  8969. }
  8970. Items->EndUpdate();
  8971. }
  8972. }
  8973. }
  8974. //---------------------------------------------------------------------------
  8975. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  8976. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  8977. int & ImageIndex)
  8978. {
  8979. if (AIndex < 0)
  8980. {
  8981. AIndex = Sender->ItemIndex;
  8982. }
  8983. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  8984. }
  8985. //---------------------------------------------------------------------------
  8986. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  8987. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  8988. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  8989. {
  8990. ARect.Left += (10 * AIndex);
  8991. }
  8992. //---------------------------------------------------------------------------
  8993. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  8994. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  8995. {
  8996. AWidth += (10 * AIndex);
  8997. }
  8998. //---------------------------------------------------------------------------
  8999. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  9000. TObject * Sender)
  9001. {
  9002. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9003. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9004. int Index = RemotePathComboBox->ItemIndex;
  9005. while (Index < RemotePathComboBox->Strings->Count - 1)
  9006. {
  9007. APath = UnixExtractFileDir(APath);
  9008. Index++;
  9009. }
  9010. // VanDyke style paths
  9011. if (APath.IsEmpty())
  9012. {
  9013. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9014. APath = ROOTDIRECTORY;
  9015. }
  9016. if (RemoteDirView->Path != APath)
  9017. {
  9018. RemoteDirView->Path = APath;
  9019. }
  9020. }
  9021. //---------------------------------------------------------------------------
  9022. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9023. {
  9024. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9025. DebugUsedParam(Sender);
  9026. UpdateRemotePathComboBox(true);
  9027. }
  9028. //---------------------------------------------------------------------------
  9029. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9030. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9031. {
  9032. ResetIncrementalSearch();
  9033. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9034. DebugAssert(DirView != NULL);
  9035. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9036. {
  9037. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9038. // OnEditing is called also from TCustomListView::CanEdit
  9039. if (Edit != NULL)
  9040. {
  9041. EditSelectBaseName(Edit);
  9042. }
  9043. }
  9044. }
  9045. //---------------------------------------------------------------------------
  9046. //---------------------------------------------------------------------------
  9047. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9048. {
  9049. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9050. Result->AutoDetectDnD = false;
  9051. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9052. Result->RenderDataOn = rdoEnterAndDropSync;
  9053. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9054. return Result;
  9055. }
  9056. //---------------------------------------------------------------------------
  9057. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9058. {
  9059. TForm::CreateWnd();
  9060. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9061. if (FSessionsDragDropFilesEx == NULL)
  9062. {
  9063. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9064. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9065. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9066. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9067. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9068. }
  9069. if (FQueueDragDropFilesEx == NULL)
  9070. {
  9071. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9072. // No need to set OnDragOver as we do not have any restrictions
  9073. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9074. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9075. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9076. }
  9077. }
  9078. //---------------------------------------------------------------------------
  9079. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9080. {
  9081. TForm::DestroyWnd();
  9082. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9083. FQueueDragDropFilesEx->DragDropControl = NULL;
  9084. }
  9085. //---------------------------------------------------------------------------
  9086. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9087. {
  9088. SideEnter(FCurrentSide);
  9089. FEverShown = true;
  9090. }
  9091. //---------------------------------------------------------------------------
  9092. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9093. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9094. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9095. {
  9096. if (!NonVisualDataModule->Busy)
  9097. {
  9098. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9099. Configuration->Usage->Inc(L"FileFinds");
  9100. LockWindow(true);
  9101. NonVisualDataModule->StartBusy();
  9102. WinConfiguration->LockedInterface = true;
  9103. try
  9104. {
  9105. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9106. }
  9107. __finally
  9108. {
  9109. WinConfiguration->LockedInterface = false;
  9110. NonVisualDataModule->EndBusy();
  9111. UnlockWindow();
  9112. }
  9113. }
  9114. }
  9115. //---------------------------------------------------------------------------
  9116. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9117. {
  9118. if (!NonVisualDataModule->Busy)
  9119. {
  9120. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9121. SetFocus();
  9122. RemoteDirView->Path = UnixExtractFilePath(Path);
  9123. UnicodeString FileName = UnixExtractFileName(Path);
  9124. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9125. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9126. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9127. if (Item == NULL)
  9128. {
  9129. ReloadDirectory(osRemote);
  9130. Item = RemoteDirView->FindFileItem(FileName);
  9131. }
  9132. if (Item != NULL)
  9133. {
  9134. RemoteDirView->ItemFocused = Item;
  9135. RemoteDirView->ItemFocused->MakeVisible(false);
  9136. RemoteDirView->SetFocus();
  9137. }
  9138. }
  9139. }
  9140. //---------------------------------------------------------------------------
  9141. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9142. {
  9143. bool Result = !NonVisualDataModule->Busy;
  9144. if (Result)
  9145. {
  9146. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9147. }
  9148. return Result;
  9149. }
  9150. //---------------------------------------------------------------------------
  9151. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9152. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9153. {
  9154. if (CanOperateOnFoundFiles(ATerminal))
  9155. {
  9156. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9157. FOnFileOperationFinished = OnFileOperationFinished;
  9158. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9159. }
  9160. }
  9161. //---------------------------------------------------------------------------
  9162. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9163. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9164. {
  9165. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9166. }
  9167. //---------------------------------------------------------------------------
  9168. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9169. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9170. {
  9171. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9172. }
  9173. //---------------------------------------------------------------------------
  9174. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9175. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9176. {
  9177. if (CanOperateOnFoundFiles(ATerminal))
  9178. {
  9179. for (int Index = 0; Index < FileList->Count; Index++)
  9180. {
  9181. UnicodeString FileName = FileList->Strings[Index];
  9182. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9183. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9184. OnFileOperationFinished(FileName, true);
  9185. }
  9186. }
  9187. }
  9188. //---------------------------------------------------------------------------
  9189. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9190. {
  9191. FFileFindTerminal = Terminal;
  9192. ShowFileFindDialog(
  9193. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9194. DoDownloadFoundFiles, DoEditFoundFiles);
  9195. }
  9196. //---------------------------------------------------------------------------
  9197. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9198. {
  9199. FTaskbarList = TaskbarList;
  9200. }
  9201. //---------------------------------------------------------------------------
  9202. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9203. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9204. {
  9205. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9206. if (Index >= 0)
  9207. {
  9208. if (Button == mbLeft)
  9209. {
  9210. // "Mouse down" is raised only after tab is switched.
  9211. // If switching tab (switching session) takes long enough for user
  9212. // to actually release the button, "mouse down" is still raised,
  9213. // but we do not get "mouse up" event, so dragging is not cancelled,
  9214. // prevent that by not beginning dragging in the first place.
  9215. if (IsKeyPressed(VK_LBUTTON))
  9216. {
  9217. // when user clicks the "+", we get mouse down only after the session
  9218. // is closed, when new session tab is already on X:Y, so dragging
  9219. // starts, prevent that
  9220. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9221. {
  9222. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9223. if (Terminal != NULL)
  9224. {
  9225. SessionsPageControl->BeginDrag(false);
  9226. }
  9227. }
  9228. }
  9229. }
  9230. else if (Button == mbMiddle)
  9231. {
  9232. // ignore middle-click for "New session tab"
  9233. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9234. if (Terminal != NULL)
  9235. {
  9236. CloseSessionTab(Index);
  9237. }
  9238. }
  9239. }
  9240. }
  9241. //---------------------------------------------------------------------------
  9242. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9243. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9244. {
  9245. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9246. // do not allow dropping on the "+" tab
  9247. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9248. if ((TargetTerminal != NULL) &&
  9249. (SessionsPageControl->ActivePage->PageIndex != Index))
  9250. {
  9251. Configuration->Usage->Inc(L"SessionTabMoves");
  9252. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9253. // but we want to actually prevent that to avoid flicker
  9254. SessionsPageControl->ActivePage->PageIndex = Index;
  9255. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9256. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9257. }
  9258. }
  9259. //---------------------------------------------------------------------------
  9260. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9261. TObject * Sender, TObject * Source, int X, int Y,
  9262. TDragState /*State*/, bool & Accept)
  9263. {
  9264. Accept = (Sender == Source);
  9265. if (Accept)
  9266. {
  9267. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9268. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9269. // do not allow dragging to the "+" tab
  9270. Accept = (Terminal != NULL);
  9271. }
  9272. }
  9273. //---------------------------------------------------------------------------
  9274. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9275. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9276. {
  9277. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9278. if (Index < 0)
  9279. {
  9280. Effect = DROPEFFECT_NONE;
  9281. }
  9282. else
  9283. {
  9284. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9285. // do not allow dropping on the "+" tab
  9286. if (TargetTerminal == NULL)
  9287. {
  9288. Effect = DROPEFFECT_NONE;
  9289. }
  9290. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9291. {
  9292. Effect = DROPEFFECT_COPY;
  9293. }
  9294. }
  9295. }
  9296. //---------------------------------------------------------------------------
  9297. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9298. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9299. {
  9300. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9301. // do not allow dropping on the "+" tab
  9302. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9303. if (TargetTerminal != NULL)
  9304. {
  9305. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9306. if (!IsFileControl(DropSourceControl, osRemote))
  9307. {
  9308. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9309. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9310. // Why don't we use Terminal->CurrentDirectory directly?
  9311. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9312. // do not force queue, drag drop
  9313. false, true);
  9314. }
  9315. }
  9316. }
  9317. //---------------------------------------------------------------------------
  9318. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9319. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9320. {
  9321. // Downloads are handled in RemoteFileControlDDEnd
  9322. if (!IsFileControl(DropSourceControl, osRemote))
  9323. {
  9324. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9325. Terminal->CurrentDirectory,
  9326. // force queue, drag drop
  9327. true, true);
  9328. }
  9329. }
  9330. //---------------------------------------------------------------------------
  9331. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9332. {
  9333. FShowing = false;
  9334. // Do not save empty workspace
  9335. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9336. {
  9337. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9338. UnicodeString Name = WorkspaceName();
  9339. DoSaveWorkspace(
  9340. Name, DataList.get(),
  9341. !Configuration->DisablePasswordStoring &&
  9342. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9343. WinConfiguration->LastStoredSession = Name;
  9344. }
  9345. }
  9346. //---------------------------------------------------------------------------
  9347. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9348. {
  9349. TManagedTerminal * ManagedTerminal =
  9350. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9351. if (ManagedTerminal != NULL)
  9352. {
  9353. ManagedTerminal->DirectoryLoaded = Now();
  9354. }
  9355. }
  9356. //---------------------------------------------------------------------------
  9357. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9358. TListItem * /*Item*/, bool /*Selected*/)
  9359. {
  9360. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9361. switch (DirView->LastSelectMethod)
  9362. {
  9363. case smKeyboard:
  9364. Configuration->Usage->Inc(L"KeyboardSelections");
  9365. break;
  9366. case smMouse:
  9367. Configuration->Usage->Inc(L"MouseSelections");
  9368. break;
  9369. }
  9370. }
  9371. //---------------------------------------------------------------------------
  9372. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9373. {
  9374. if (Color != 0)
  9375. {
  9376. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9377. }
  9378. else
  9379. {
  9380. return FSessionTabImageIndex;
  9381. }
  9382. }
  9383. //---------------------------------------------------------------------------
  9384. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9385. {
  9386. TPngImageCollectionItem * Item =
  9387. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9388. FSessionColors->AddPng(Item->PngImage);
  9389. return FSessionColors->Count - 1;
  9390. }
  9391. //---------------------------------------------------------------------------
  9392. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9393. {
  9394. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9395. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9396. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9397. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9398. }
  9399. //---------------------------------------------------------------------------
  9400. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9401. {
  9402. for (int Index = 0; Index < Control->ControlCount; Index++)
  9403. {
  9404. TControl * AControl = Control->Controls[Index];
  9405. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9406. if (WinControl != NULL)
  9407. {
  9408. CollectItemsWithTextDisplayMode(WinControl);
  9409. }
  9410. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9411. if (Toolbar != NULL)
  9412. {
  9413. // we care for top-level items only
  9414. TTBCustomItem * Items = Toolbar->Items;
  9415. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9416. {
  9417. TTBCustomItem * Item = Items->Items[ItemIndex];
  9418. if (((Item->DisplayMode == nbdmImageAndText) ||
  9419. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9420. EligibleForImageDisplayMode(Item))
  9421. {
  9422. FItemsWithTextDisplayMode.insert(Item);
  9423. }
  9424. }
  9425. }
  9426. }
  9427. }
  9428. //---------------------------------------------------------------------------
  9429. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9430. {
  9431. return true;
  9432. }
  9433. //---------------------------------------------------------------------------
  9434. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9435. {
  9436. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9437. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9438. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9439. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9440. bool Result = true;
  9441. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9442. {
  9443. TTBCustomItem * Item = *i;
  9444. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9445. if (Label != NULL)
  9446. {
  9447. // optimization
  9448. if (Label->Visible == SelectiveToolbarText)
  9449. {
  9450. Result = false;
  9451. }
  9452. else
  9453. {
  9454. Label->Visible = SelectiveToolbarText;
  9455. }
  9456. }
  9457. else
  9458. {
  9459. // optimization
  9460. if (Item->DisplayMode == DisplayMode)
  9461. {
  9462. Result = false;
  9463. }
  9464. else
  9465. {
  9466. Item->DisplayMode = DisplayMode;
  9467. }
  9468. }
  9469. ++i;
  9470. }
  9471. if (Result)
  9472. {
  9473. UpdateNewSessionTab();
  9474. }
  9475. return Result;
  9476. }
  9477. //---------------------------------------------------------------------------
  9478. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9479. {
  9480. DebugFail();
  9481. }
  9482. //---------------------------------------------------------------------------
  9483. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9484. {
  9485. // Among other, a lock level is non zero, while directory is being loaded,
  9486. // even when it happens as a result of dirview navigation,
  9487. // i.e. when TNonVisualDataModule is NOT FBusy.
  9488. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9489. // Among other this prevents a panel auto update to occur while
  9490. // directory is changing.
  9491. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9492. }
  9493. //---------------------------------------------------------------------------
  9494. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  9495. {
  9496. // While the window is disabled, we still seem to process menu shortcuts at least,
  9497. // so stop it at least here.
  9498. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9499. return
  9500. (Allowed == aaUpdate) ||
  9501. !NonVisualDataModule->Busy;
  9502. }
  9503. //---------------------------------------------------------------------------
  9504. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9505. {
  9506. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9507. }
  9508. //---------------------------------------------------------------------------
  9509. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9510. {
  9511. // This is somewhat redundant to LockWindow() call from
  9512. // TTerminalManager::TerminalReadDirectoryProgress.
  9513. // But disabling window is known not to block keyboard shorcuts
  9514. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9515. if (Busy > 0)
  9516. {
  9517. if (NonVisualDataModule->Busy)
  9518. {
  9519. State = false;
  9520. }
  9521. else
  9522. {
  9523. NonVisualDataModule->StartBusy();
  9524. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9525. LockWindow();
  9526. }
  9527. }
  9528. else if (Busy < 0)
  9529. {
  9530. UnlockWindow();
  9531. NonVisualDataModule->EndBusy();
  9532. }
  9533. else
  9534. {
  9535. State = NonVisualDataModule->Busy;
  9536. }
  9537. }
  9538. //---------------------------------------------------------------------------
  9539. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9540. {
  9541. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9542. // no context menu for "New session tab"
  9543. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9544. {
  9545. SessionsPageControl->ActivePageIndex = Index;
  9546. if (DebugAlwaysTrue(SessionTabSwitched()))
  9547. {
  9548. // copied from TControl.WMContextMenu
  9549. SendCancelMode(SessionsPageControl);
  9550. // explicit popup instead of using PopupMenu property
  9551. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9552. // while connecting yet not-connected session and hence
  9553. // allowing an access to commands over not-completelly connected session
  9554. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9555. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9556. PopupMenu->PopupComponent = SessionsPageControl;
  9557. PopupMenu->Popup(Point.x, Point.y);
  9558. }
  9559. }
  9560. Handled = true;
  9561. }
  9562. //---------------------------------------------------------------------------
  9563. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9564. {
  9565. return (Terminal != NULL) && Terminal->Active && Terminal->IsCapable[fcChangePassword];
  9566. }
  9567. //---------------------------------------------------------------------------
  9568. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9569. {
  9570. Configuration->Usage->Inc(L"PasswordChanges");
  9571. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9572. ChangePasswordData->DisableAuthentationsExceptPassword();
  9573. ChangePasswordData->ChangePassword = true;
  9574. std::unique_ptr<TTerminal> ChangePasswordSession(
  9575. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9576. ChangePasswordSession->AutoReadDirectory = false;
  9577. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9578. {
  9579. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9580. }
  9581. else
  9582. {
  9583. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9584. }
  9585. }
  9586. //---------------------------------------------------------------------------
  9587. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9588. {
  9589. // No nice way to assert SSH2
  9590. return (Terminal != NULL) && Terminal->Active && (Terminal->FSProtocol == cfsSFTP);
  9591. }
  9592. //---------------------------------------------------------------------------
  9593. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9594. {
  9595. TOperationVisualizer OperationVisualizer;
  9596. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9597. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9598. }
  9599. //---------------------------------------------------------------------------
  9600. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9601. {
  9602. TForm::ChangeScale(M, D);
  9603. int APixelsPerInch = GetControlPixelsPerInch(this);
  9604. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9605. try
  9606. {
  9607. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9608. }
  9609. __finally
  9610. {
  9611. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9612. }
  9613. }
  9614. //---------------------------------------------------------------------------
  9615. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9616. {
  9617. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9618. }
  9619. //---------------------------------------------------------------------
  9620. class TPublicControl : public TControl
  9621. {
  9622. friend class TCustomScpExplorerForm;
  9623. };
  9624. //---------------------------------------------------------------------------
  9625. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9626. {
  9627. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9628. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9629. }
  9630. //---------------------------------------------------------------------------
  9631. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9632. {
  9633. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9634. OpenBookmark(Side, Bookmark);
  9635. }
  9636. //---------------------------------------------------------------------------
  9637. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9638. {
  9639. DoBookmarkClick(osLocal, Sender);
  9640. }
  9641. //---------------------------------------------------------------------------
  9642. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9643. {
  9644. DoBookmarkClick(osRemote, Sender);
  9645. }
  9646. //---------------------------------------------------------------------------
  9647. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9648. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9649. {
  9650. // TODO
  9651. if (BookmarkList != NULL)
  9652. {
  9653. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9654. if (!WinConfiguration->UseLocationProfiles)
  9655. {
  9656. std::unique_ptr<TStringList> Directories(new TStringList());
  9657. Directories->CaseSensitive = (Side == osRemote);
  9658. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9659. {
  9660. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9661. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9662. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9663. {
  9664. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9665. Item->Caption = EscapeHotkey(Directory);
  9666. Item->ShortCut = Bookmark->ShortCut;
  9667. Item->OnClick = OnBookmarkClick;
  9668. Item->Tag = reinterpret_cast<int>(Bookmark);
  9669. Directories->Add(Directory);
  9670. Menu->Add(Item.release());
  9671. }
  9672. }
  9673. }
  9674. else
  9675. {
  9676. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9677. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9678. {
  9679. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9680. if (!Bookmark->Node.IsEmpty())
  9681. {
  9682. Folders->Add(Bookmark->Node);
  9683. }
  9684. }
  9685. for (int Index = 0; Index < Folders->Count; Index++)
  9686. {
  9687. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9688. Item->Caption = Folders->Strings[Index];
  9689. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction->ImageIndex;
  9690. Folders->Objects[Index] = Item.get();
  9691. Menu->Add(Item.release());
  9692. }
  9693. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9694. {
  9695. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9696. TTBCustomItem * Parent;
  9697. if (!Bookmark->Node.IsEmpty())
  9698. {
  9699. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9700. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9701. }
  9702. else
  9703. {
  9704. Parent = Menu;
  9705. }
  9706. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9707. Item->Caption = Bookmark->Name;
  9708. Item->ShortCut = Bookmark->ShortCut;
  9709. Item->OnClick = OnBookmarkClick;
  9710. Item->Tag = reinterpret_cast<int>(Bookmark);
  9711. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9712. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9713. {
  9714. // No hint for location profiles that are actually mere "bookmarks"
  9715. }
  9716. else
  9717. {
  9718. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9719. UnicodeString LongHint;
  9720. if (!Bookmark->Local.IsEmpty())
  9721. {
  9722. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9723. }
  9724. if (!Bookmark->Remote.IsEmpty())
  9725. {
  9726. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9727. }
  9728. AddToList(Hint, LongHint, L"|");
  9729. Item->Hint = Hint;
  9730. }
  9731. Parent->Add(Item.release());
  9732. }
  9733. }
  9734. AddMenuSeparator(Menu);
  9735. }
  9736. }
  9737. //---------------------------------------------------------------------------
  9738. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9739. {
  9740. Menu->Clear();
  9741. std::unique_ptr<TTBCustomItem> Item;
  9742. Item.reset(new TTBXItem(Owner));
  9743. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9744. Item->Options = Item->Options << tboDefault;
  9745. Menu->Add(Item.release());
  9746. AddMenuSeparator(Menu);
  9747. if (Terminal != NULL)
  9748. {
  9749. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9750. }
  9751. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9752. Item.reset(new TTBXItem(Owner));
  9753. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction : NonVisualDataModule->RemoteAddBookmarkAction;
  9754. Menu->Add(Item.release());
  9755. }
  9756. //---------------------------------------------------------------------------
  9757. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9758. {
  9759. bool Result = true;
  9760. try
  9761. {
  9762. if (Side == osRemote)
  9763. {
  9764. Terminal->ExceptionOnFail = true;
  9765. }
  9766. try
  9767. {
  9768. DirView(Side)->Path = Path;
  9769. }
  9770. __finally
  9771. {
  9772. if (Side == osRemote)
  9773. {
  9774. Terminal->ExceptionOnFail = false;
  9775. }
  9776. }
  9777. }
  9778. catch (Exception & E)
  9779. {
  9780. if ((Side != osRemote) || Terminal->Active)
  9781. {
  9782. ShowExtendedExceptionEx(Terminal, &E);
  9783. Result = false;
  9784. }
  9785. else
  9786. {
  9787. throw;
  9788. }
  9789. }
  9790. return Result;
  9791. }
  9792. //---------------------------------------------------------------------------
  9793. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9794. {
  9795. // Make sure there some feedback even when loading tiny local folders
  9796. TInstantOperationVisualizer Visualizer;
  9797. DirView(Side)->ReloadDirectory();
  9798. }
  9799. //---------------------------------------------------------------------------
  9800. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9801. {
  9802. if (Index == SessionsPageControl->TabIndex)
  9803. {
  9804. CloseSession();
  9805. }
  9806. else
  9807. {
  9808. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9809. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9810. TTerminalManager * Manager = TTerminalManager::Instance();
  9811. if (!Terminal->Active)
  9812. {
  9813. Manager->FreeTerminal(Terminal);
  9814. }
  9815. else
  9816. {
  9817. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9818. if (CanCloseQueue(Queue))
  9819. {
  9820. Manager->FreeTerminal(Terminal);
  9821. }
  9822. }
  9823. }
  9824. }
  9825. //---------------------------------------------------------------------------
  9826. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9827. {
  9828. CloseSessionTab(Index);
  9829. }
  9830. //---------------------------------------------------------------------------
  9831. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9832. {
  9833. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9834. {
  9835. TInstantOperationVisualizer Visualizer;
  9836. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9837. // before we create a new data object
  9838. ClipboardClear();
  9839. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9840. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9841. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9842. // Intermediate variable to WORKAROUND a crash in compiler
  9843. TObjectList * ClipboardFakeMonitors =
  9844. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9845. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9846. if (FClipboardDragDropFilesEx.get() == NULL)
  9847. {
  9848. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9849. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9850. }
  9851. FClipboardDragDropFilesEx->FileList->Clear();
  9852. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9853. FClipboardDragDropFilesEx->CopyToClipboard();
  9854. FClipboardTerminal = FTerminal;
  9855. // Need full paths, as cwd can be different once files are pasted
  9856. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9857. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9858. {
  9859. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9860. }
  9861. }
  9862. }
  9863. //---------------------------------------------------------------------------
  9864. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9865. {
  9866. if (OpenClipboard(0))
  9867. {
  9868. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9869. CloseClipboard();
  9870. }
  9871. }
  9872. //---------------------------------------------------------------------------
  9873. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9874. {
  9875. return !FClipboardFakeDirectory.IsEmpty();
  9876. }
  9877. //---------------------------------------------------------------------------
  9878. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9879. {
  9880. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9881. FClipboardFakeDirectory = UnicodeString();
  9882. FClipboardTerminal = NULL;
  9883. // Also called in Idle()
  9884. FClipboardFakeMonitors.reset(NULL);
  9885. }
  9886. //---------------------------------------------------------------------------
  9887. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9888. {
  9889. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9890. {
  9891. ClipboardStop();
  9892. }
  9893. }
  9894. //---------------------------------------------------------------------------
  9895. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9896. {
  9897. TTerminalManager * Manager = TTerminalManager::Instance();
  9898. Manager->ActiveTerminal = FClipboardTerminal;
  9899. TTransferOperationParam Params;
  9900. Params.TargetDirectory = TargetDirectory;
  9901. Params.DragDrop = DragDrop;
  9902. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  9903. }
  9904. //---------------------------------------------------------------------------
  9905. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  9906. {
  9907. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  9908. // (as it pumps a Windows message queue while being shutted down)
  9909. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  9910. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  9911. {
  9912. // Can fail as it can be e.g. locked by AV, so we retry that later
  9913. bool Removed = RemoveDir(ApiPath(FileName));
  9914. try
  9915. {
  9916. if (!NonVisualDataModule->Busy)
  9917. {
  9918. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  9919. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  9920. }
  9921. }
  9922. __finally
  9923. {
  9924. if (!Removed)
  9925. {
  9926. RemoveDir(ApiPath(FileName));
  9927. }
  9928. }
  9929. }
  9930. }
  9931. //---------------------------------------------------------------------------
  9932. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  9933. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  9934. {
  9935. TFileMasks::TParams MaskParams;
  9936. MaskParams.Size = Size;
  9937. MaskParams.Modification = Modification;
  9938. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  9939. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  9940. {
  9941. bool ImplicitMatch;
  9942. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  9943. !ImplicitMatch)
  9944. {
  9945. Color = Iter->Color;
  9946. break;
  9947. }
  9948. }
  9949. }
  9950. //---------------------------------------------------------------------------
  9951. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  9952. {
  9953. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9954. if (!DirView->IsEditing())
  9955. {
  9956. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  9957. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  9958. // while searching
  9959. if (Key == VK_BACK)
  9960. {
  9961. if (!FIncrementalSearch.IsEmpty())
  9962. {
  9963. if (FIncrementalSearch.Length() == 1)
  9964. {
  9965. ResetIncrementalSearch();
  9966. }
  9967. else
  9968. {
  9969. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  9970. IncrementalSearch(NewText, false, false);
  9971. }
  9972. Key = 0;
  9973. }
  9974. }
  9975. }
  9976. }
  9977. //---------------------------------------------------------------------------
  9978. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  9979. {
  9980. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9981. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  9982. {
  9983. // Filter control sequences.
  9984. // When not searching yet, prefer use of the space for toggling file selection
  9985. // (so we cannot incrementally search for a string starting with a space).
  9986. if ((Key > VK_SPACE) ||
  9987. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  9988. {
  9989. IncrementalSearch(FIncrementalSearch + Key, false, false);
  9990. Key = 0;
  9991. }
  9992. }
  9993. }
  9994. //---------------------------------------------------------------------------
  9995. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  9996. {
  9997. if (!FIncrementalSearch.IsEmpty())
  9998. {
  9999. FIncrementalSearch = L"";
  10000. DirView(osCurrent)->UpdateStatusBar();
  10001. }
  10002. }
  10003. //---------------------------------------------------------------------------
  10004. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10005. {
  10006. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10007. if (Item == NULL)
  10008. {
  10009. MessageBeep(MB_ICONHAND);
  10010. }
  10011. else
  10012. {
  10013. TCustomDirView * ADirView = DirView(osCurrent);
  10014. {
  10015. TAutoNestingCounter Guard(FIncrementalSearching);
  10016. ADirView->FocusItem(Item);
  10017. if (ADirView->NortonLike == nlOff)
  10018. {
  10019. if ((ADirView->Selected != Item) ||
  10020. (ADirView->SelCount > 1))
  10021. {
  10022. ADirView->ClearSelection();
  10023. ADirView->Selected = Item;
  10024. }
  10025. }
  10026. }
  10027. FIncrementalSearch = Text;
  10028. Item->MakeVisible(false);
  10029. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10030. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10031. ADirView->UpdateStatusBar();
  10032. }
  10033. }
  10034. //---------------------------------------------------------------------------
  10035. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10036. {
  10037. int Index = Item->Index;
  10038. if (!Reverse)
  10039. {
  10040. Index++;
  10041. if (Index >= Item->Owner->Count)
  10042. {
  10043. Index = 0;
  10044. }
  10045. }
  10046. else
  10047. {
  10048. Index--;
  10049. if (Index < 0)
  10050. {
  10051. Index = Item->Owner->Count - 1;
  10052. }
  10053. }
  10054. return Item->Owner->Item[Index];
  10055. }
  10056. //---------------------------------------------------------------------------
  10057. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10058. {
  10059. TCustomDirView * ADirView = DirView(osCurrent);
  10060. if (ADirView->Items->Count == 0)
  10061. {
  10062. return NULL;
  10063. }
  10064. else
  10065. {
  10066. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10067. TListItem * Item = CurrentItem;
  10068. if (SkipCurrent)
  10069. {
  10070. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10071. }
  10072. while (true)
  10073. {
  10074. bool Matches = false;
  10075. switch (WinConfiguration->PanelSearch)
  10076. {
  10077. case isNameStartOnly:
  10078. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10079. break;
  10080. case isName:
  10081. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10082. break;
  10083. case isAll:
  10084. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10085. int Index = 0;
  10086. while ((Index < ColCount) && !Matches)
  10087. {
  10088. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10089. if (Visible)
  10090. {
  10091. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10092. }
  10093. Index++;
  10094. }
  10095. break;
  10096. }
  10097. if (Matches)
  10098. {
  10099. return Item;
  10100. }
  10101. Item = GetNextFile(Item, Reverse);
  10102. if (Item == CurrentItem)
  10103. {
  10104. return NULL;
  10105. }
  10106. }
  10107. }
  10108. }
  10109. //---------------------------------------------------------------------------
  10110. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10111. {
  10112. ResetIncrementalSearch();
  10113. }
  10114. //---------------------------------------------------------------------------
  10115. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10116. {
  10117. if (Message.CharCode == VK_TAB)
  10118. {
  10119. if (!FIncrementalSearch.IsEmpty())
  10120. {
  10121. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10122. bool Reverse = Shift.Contains(ssShift);
  10123. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10124. Message.Result = 1;
  10125. return;
  10126. }
  10127. }
  10128. else if (Message.CharCode == VK_ESCAPE)
  10129. {
  10130. if (!FIncrementalSearch.IsEmpty())
  10131. {
  10132. ResetIncrementalSearch();
  10133. Message.Result = 1;
  10134. return;
  10135. }
  10136. }
  10137. TForm::Dispatch(&Message);
  10138. }
  10139. //---------------------------------------------------------------------------
  10140. void __fastcall TCustomScpExplorerForm::Deactivate()
  10141. {
  10142. TForm::Deactivate();
  10143. // E.g. when switching to an internal editor window
  10144. ResetIncrementalSearch();
  10145. }
  10146. //---------------------------------------------------------------------------
  10147. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10148. {
  10149. // When switching to another application
  10150. ResetIncrementalSearch();
  10151. }
  10152. //---------------------------------------------------------------------------
  10153. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10154. {
  10155. ResetIncrementalSearch();
  10156. }
  10157. //---------------------------------------------------------------------------
  10158. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10159. {
  10160. if (FIncrementalSearching <= 0)
  10161. {
  10162. ResetIncrementalSearch();
  10163. }
  10164. }
  10165. //---------------------------------------------------------------------------
  10166. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10167. {
  10168. CountClicksForWindowPrint(this);
  10169. }
  10170. //---------------------------------------------------------------------------
  10171. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10172. {
  10173. CenterReconnectToolbar();
  10174. }
  10175. //---------------------------------------------------------------------------
  10176. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10177. {
  10178. if (RemoteDirView->ItemFocused != NULL)
  10179. {
  10180. RemoteDirView->ItemFocused->Selected = true;
  10181. }
  10182. }
  10183. //---------------------------------------------------------------------------
  10184. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10185. {
  10186. if (!FQueueStatusUpdating)
  10187. {
  10188. bool Refresh;
  10189. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10190. {
  10191. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10192. }
  10193. else
  10194. {
  10195. if (FQueueFileList->GetCount() > 0)
  10196. {
  10197. FQueueFileList->Clear();
  10198. Refresh = true;
  10199. }
  10200. }
  10201. int Count = FQueueFileList->GetCount();
  10202. if (QueueFileList->Items->Count != Count)
  10203. {
  10204. DebugAssert(Refresh);
  10205. QueueFileList->Items->Count = Count;
  10206. }
  10207. if (Refresh)
  10208. {
  10209. QueueFileList->Invalidate();
  10210. }
  10211. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10212. }
  10213. }
  10214. //---------------------------------------------------------------------------
  10215. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10216. {
  10217. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10218. }
  10219. //---------------------------------------------------------------------------
  10220. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10221. {
  10222. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10223. // See TSynchronizeChecklistDialog::UpdateTimer
  10224. if (QueueFileList->Items->Count > 0)
  10225. {
  10226. QueueFileList->Items->Item[0]->MakeVisible(false);
  10227. }
  10228. UpdateQueueFileList();
  10229. }
  10230. //---------------------------------------------------------------------------
  10231. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10232. {
  10233. Active = QueueView3->Focused() || QueueFileList->Focused();
  10234. }
  10235. //---------------------------------------------------------------------------
  10236. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10237. {
  10238. QueueLabelUpdateStatus();
  10239. }
  10240. //---------------------------------------------------------------------------
  10241. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10242. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10243. {
  10244. int State = FQueueFileList->GetState(Item->Index);
  10245. if (State == qfsProcessed)
  10246. {
  10247. Sender->Canvas->Font->Color = clGrayText;
  10248. }
  10249. }
  10250. //---------------------------------------------------------------------------
  10251. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10252. {
  10253. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10254. QueueFileList->Column[0]->Width =
  10255. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10256. }
  10257. //---------------------------------------------------------------------------
  10258. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10259. {
  10260. QueueFileListColumnAutoSize();
  10261. }
  10262. //---------------------------------------------------------------------------
  10263. void __fastcall TCustomScpExplorerForm::CloseApp()
  10264. {
  10265. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10266. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10267. // So we clear the flag here.
  10268. DebugAssert(NonVisualDataModule->Busy);
  10269. NonVisualDataModule->EndBusy();
  10270. try
  10271. {
  10272. Close();
  10273. }
  10274. __finally
  10275. {
  10276. NonVisualDataModule->StartBusy();
  10277. }
  10278. }