CustomScpExplorer.cpp 306 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473
  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. //---------------------------------------------------------------------------
  33. #pragma package(smart_init)
  34. #pragma link "CustomDirView"
  35. #pragma link "CustomUnixDirView"
  36. #pragma link "IEListView"
  37. #pragma link "NortonLikeListView"
  38. #pragma link "UnixDirView"
  39. #pragma link "CustomDriveView"
  40. #pragma link "UnixDriveView"
  41. #pragma link "CustomDriveView"
  42. #pragma link "TB2Dock"
  43. #pragma link "TBXStatusBars"
  44. #pragma link "TB2Item"
  45. #pragma link "TB2Toolbar"
  46. #pragma link "ThemePageControl"
  47. #pragma link "PathLabel"
  48. #ifndef NO_RESOURCES
  49. #pragma resource "*.dfm"
  50. #endif
  51. //---------------------------------------------------------------------------
  52. #define SAVE_SELECTION(DIRVIEW) \
  53. UnicodeString FocusFile = L""; \
  54. UnicodeString LastFocusedFile = L""; \
  55. if (DIRVIEW->ItemFocused) LastFocusedFile = DIRVIEW->ItemFocused->Caption; \
  56. { TListItem * ClosestUnselected = DIRVIEW->ClosestUnselected(DIRVIEW->ItemFocused); \
  57. if (ClosestUnselected) FocusFile = ClosestUnselected->Caption; }
  58. #define RESTORE_SELECTION(DIRVIEW) \
  59. if (!LastFocusedFile.IsEmpty() && \
  60. (!DIRVIEW->ItemFocused || (DIRVIEW->ItemFocused->Caption != LastFocusedFile))) \
  61. { \
  62. TListItem *ItemToSelect = DIRVIEW->FindFileItem(FocusFile); \
  63. if (ItemToSelect) \
  64. { \
  65. DIRVIEW->ItemFocused = ItemToSelect; \
  66. DIRVIEW->ItemFocused->MakeVisible(False); \
  67. } \
  68. }
  69. //---------------------------------------------------------------------------
  70. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  71. static const int SessionPanelCount = 4;
  72. //---------------------------------------------------------------------------
  73. class TMutexGuard
  74. {
  75. public:
  76. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  77. int Timeout = 5000)
  78. {
  79. FMutex = NULL;
  80. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  81. if (WaitResult == WAIT_TIMEOUT)
  82. {
  83. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  84. }
  85. else
  86. {
  87. FMutex = AMutex;
  88. }
  89. }
  90. ~TMutexGuard()
  91. {
  92. if (FMutex != NULL)
  93. {
  94. ReleaseMutex(FMutex);
  95. }
  96. }
  97. private:
  98. HANDLE FMutex;
  99. };
  100. //---------------------------------------------------------------------------
  101. class TWindowLock
  102. {
  103. public:
  104. TWindowLock(TCustomScpExplorerForm * Form) :
  105. FForm(Form)
  106. {
  107. FForm->LockWindow();
  108. }
  109. ~TWindowLock()
  110. {
  111. FForm->UnlockWindow();
  112. }
  113. private:
  114. TCustomScpExplorerForm * FForm;
  115. };
  116. //---------------------------------------------------------------------------
  117. struct TTransferOperationParam
  118. {
  119. TTransferOperationParam();
  120. UnicodeString TargetDirectory;
  121. bool Temp;
  122. bool DragDrop;
  123. int Options;
  124. TAutoSwitch Queue;
  125. };
  126. //---------------------------------------------------------------------------
  127. TTransferOperationParam::TTransferOperationParam()
  128. {
  129. Temp = false;
  130. DragDrop = false;
  131. Options = 0;
  132. Queue = asAuto;
  133. }
  134. //---------------------------------------------------------------------------
  135. class TTransferPresetNoteData : public TObject
  136. {
  137. public:
  138. UnicodeString Message;
  139. };
  140. //---------------------------------------------------------------------------
  141. class TTerminalNoteData : public TObject
  142. {
  143. public:
  144. TTerminal * Terminal;
  145. };
  146. //---------------------------------------------------------------------------
  147. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  148. FFormRestored(false),
  149. TForm(Owner)
  150. {
  151. FCurrentSide = osRemote;
  152. FEverShown = false;
  153. FDocks = new TList();
  154. RestoreParams();
  155. ConfigurationChanged();
  156. RemoteDirView->Invalidate();
  157. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  158. NonVisualDataModule->ScpExplorer = this;
  159. FAutoOperation = false;
  160. FOnFileOperationFinished = NULL;
  161. FForceExecution = false;
  162. FIgnoreNextDialogChar = 0;
  163. FErrorList = NULL;
  164. FSynchronizeProgressForm = NULL;
  165. FProgressForm = NULL;
  166. FRefreshLocalDirectory = false;
  167. FRefreshRemoteDirectory = false;
  168. FDDMoveSlipped = false;
  169. FDDExtMapFile = NULL;
  170. // CreateMutexW keeps failing with ERROR_NOACCESS
  171. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  172. DebugAssert(FDDExtMutex != NULL);
  173. FDDTargetControl = NULL;
  174. FDelayedDeletionTimer = NULL;
  175. FDelayedDeletionList = new TStringList();
  176. FDDFileList = NULL;
  177. FPendingTempSpaceWarn = false;
  178. FCapturedLog = NULL;
  179. FDragDropOperation = false;
  180. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  181. FAllowTransferPresetAutoSelect = true;
  182. FCopyParamDefault = L"";
  183. FSynchronizeController = NULL;
  184. FPendingQueueActionItem = NULL;
  185. FLockLevel = 0;
  186. FLockSuspendLevel = 0;
  187. FDisabledOnLockSuspend = false;
  188. FAlternativeDelete = false;
  189. FTrayIcon = new ::TTrayIcon(0);
  190. FTrayIcon->OnClick = TrayIconClick;
  191. FMaxQueueLength = 0;
  192. FLastContextPopupScreenPoint = TPoint(-1, -1);
  193. FTransferResumeList = NULL;
  194. FMoveToQueue = false;
  195. FStandaloneEditing = false;
  196. FOnFeedSynchronizeError = NULL;
  197. FNeedSession = false;
  198. FDoNotIdleCurrentTerminal = false;
  199. FEditorManager = new TEditorManager();
  200. FEditorManager->OnFileChange = ExecutedFileChanged;
  201. FEditorManager->OnFileReload = ExecutedFileReload;
  202. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  203. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  204. FLocalEditors = new TList();
  205. FQueueStatus = NULL;
  206. FQueueStatusSection = new TCriticalSection();
  207. FQueueStatusInvalidated = false;
  208. FQueueItemInvalidated = false;
  209. FQueueActedItem = NULL;
  210. FQueueController = new TQueueController(QueueView3);
  211. FUserActionTimer = new TTimer(this);
  212. FUserActionTimer->Enabled = false;
  213. FUserActionTimer->Interval = 10;
  214. FUserActionTimer->OnTimer = UserActionTimer;
  215. FNotes = new TStringList();
  216. FNoteTimer = new TTimer(this);
  217. FNoteTimer->Enabled = false;
  218. FNoteTimer->OnTimer = NoteTimer;
  219. FOnNoteClick = NULL;
  220. FOle32Library = LoadLibrary(L"Ole32.dll");
  221. FDragMoveCursor = FOle32Library != NULL ?
  222. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  223. UseSystemSettings(this);
  224. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  225. static_cast<TObject*>(GetComponent(fcTransferList)));
  226. DebugAssert(TransferList != NULL);
  227. FTransferListHoverIndex = -1;
  228. TransferList->OnChange = TransferListChange;
  229. TransferList->OnDrawItem = TransferListDrawItem;
  230. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  231. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  232. UseDesktopFont(SessionsPageControl);
  233. UpdateSessionsPageControlHeight();
  234. UseDesktopFont(RemoteDirView);
  235. UseDesktopFont(RemoteDriveView);
  236. UseDesktopFont(QueueView3);
  237. UseDesktopFont(QueueLabel);
  238. UseDesktopFont(RemoteStatusBar);
  239. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  240. QueueSplitter->ShowHint = true;
  241. RemotePanelSplitter->ShowHint = true;
  242. UpdateImages();
  243. FCustomCommandMenu = CreateTBXPopupMenu(this);
  244. FCustomCommandLocalFileList = NULL;
  245. FCustomCommandRemoteFileList = NULL;
  246. FSessionColors = new TPngImageList(this);
  247. FSessionColors->ColorDepth = cd32Bit;
  248. AddFixedSessionImages();
  249. SessionsPageControl->Images = FSessionColors;
  250. QueueLabel->FocusControl = QueueView3;
  251. UpdateQueueLabel();
  252. FRemoteDirViewWasFocused = true;
  253. CreateHiddenWindow();
  254. StartUpdates();
  255. }
  256. //---------------------------------------------------------------------------
  257. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  258. {
  259. // this has to be one of the very first things to do
  260. StopUpdateThread();
  261. SessionsPageControl->Images = NULL;
  262. SAFE_DESTROY(FSessionColors);
  263. SAFE_DESTROY(FSessionsDragDropFilesEx);
  264. delete FCustomCommandLocalFileList;
  265. delete FCustomCommandRemoteFileList;
  266. delete FCustomCommandMenu;
  267. delete FTrayIcon;
  268. FTrayIcon = NULL;
  269. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  270. delete FEditorManager;
  271. ForceCloseLocalEditors();
  272. delete FLocalEditors;
  273. HideFileFindDialog();
  274. if (FDelayedDeletionTimer)
  275. {
  276. DoDelayedDeletion(NULL);
  277. SAFE_DESTROY(FDelayedDeletionTimer);
  278. }
  279. SAFE_DESTROY(FDelayedDeletionList);
  280. // sometimes we do not get DDEnd so the list is not released
  281. SAFE_DESTROY(FDDFileList);
  282. DebugAssert(FSynchronizeController == NULL);
  283. CloseHandle(FDDExtMutex);
  284. FDDExtMutex = NULL;
  285. FreeLibrary(FOle32Library);
  286. FOle32Library = NULL;
  287. FDragMoveCursor = NULL;
  288. DebugAssert(!FErrorList);
  289. if (FEverShown)
  290. {
  291. // when window is never shown (like when running command-line operation),
  292. // particularly window site is not restored correctly (BoundsRect value set
  293. // in RestoreForm gets lost during handle allocation), so we do not want
  294. // it to be stored
  295. StoreParams();
  296. }
  297. Terminal = NULL;
  298. Queue = NULL;
  299. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  300. NonVisualDataModule->ScpExplorer = NULL;
  301. delete FQueueController;
  302. FQueueController = NULL;
  303. delete FQueueStatusSection;
  304. FQueueStatusSection = NULL;
  305. delete FQueueStatus;
  306. FQueueStatus = NULL;
  307. delete FUserActionTimer;
  308. FUserActionTimer = NULL;
  309. delete FNoteTimer;
  310. delete FNotes;
  311. delete FNoteData;
  312. SAFE_DESTROY(FDocks);
  313. SAFE_DESTROY(FHistoryMenu[0][0]);
  314. SAFE_DESTROY(FHistoryMenu[0][1]);
  315. SAFE_DESTROY(FHistoryMenu[1][0]);
  316. SAFE_DESTROY(FHistoryMenu[1][1]);
  317. if (FHiddenWindow != NULL)
  318. {
  319. DestroyWindow(FHiddenWindow);
  320. FHiddenWindow = NULL;
  321. }
  322. }
  323. //---------------------------------------------------------------------------
  324. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  325. {
  326. std::unique_ptr<TSessionData> Data;
  327. if (!Session.IsEmpty())
  328. {
  329. bool DefaultsOnly;
  330. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  331. }
  332. TTerminalManager * Manager = TTerminalManager::Instance();
  333. for (int Index = 0; Index < Manager->Count; Index++)
  334. {
  335. TTerminal * Terminal = Manager->Terminals[Index];
  336. if (Session.IsEmpty() ||
  337. Terminal->SessionData->IsSameSite(Data.get()))
  338. {
  339. if (Path.IsEmpty())
  340. {
  341. Terminal->ClearCaches();
  342. }
  343. else
  344. {
  345. Terminal->DirectoryModified(Path, true);
  346. }
  347. }
  348. }
  349. // We should flag a pending refresh for the background terminals or busy foreground terminals
  350. if ((Terminal != NULL) && Terminal->Active &&
  351. CanCommandLineFromAnotherInstance() &&
  352. (Session.IsEmpty() || Terminal->SessionData->IsSameSite(Data.get())) &&
  353. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  354. {
  355. Terminal->ReloadDirectory();
  356. }
  357. }
  358. //---------------------------------------------------------------------------
  359. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  360. {
  361. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  362. size_t MessageSize = sizeof(TCopyDataMessage);
  363. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  364. if (Result)
  365. {
  366. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  367. Result = (Message.Version == TCopyDataMessage::Version1);
  368. if (Result)
  369. {
  370. switch (Message.Command)
  371. {
  372. case TCopyDataMessage::CommandCanCommandLine:
  373. Result = CanCommandLineFromAnotherInstance();
  374. break;
  375. case TCopyDataMessage::CommandCommandLine:
  376. {
  377. UnicodeString CommandLine(Message.CommandLine);
  378. Result = CommandLineFromAnotherInstance(CommandLine);
  379. }
  380. break;
  381. case TCopyDataMessage::RefreshPanel:
  382. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  383. break;
  384. case TCopyDataMessage::MainWindowCheck:
  385. Result = true;
  386. break;
  387. default:
  388. Result = false;
  389. break;
  390. }
  391. }
  392. }
  393. Message.Result = Result ? 1 : 0;
  394. }
  395. //---------------------------------------------------------------------------
  396. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  397. {
  398. WNDCLASS WindowClass = {0};
  399. WindowClass.lpfnWndProc = DefWindowProc;
  400. WindowClass.hInstance = HInstance;
  401. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  402. FHiddenWindow = NULL;
  403. if (RegisterClass(&WindowClass))
  404. {
  405. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  406. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  407. }
  408. }
  409. //---------------------------------------------------------------------------
  410. bool __fastcall TCustomScpExplorerForm::CanConsole()
  411. {
  412. return (Terminal != NULL) && (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  413. }
  414. //---------------------------------------------------------------------------
  415. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  416. {
  417. bool Result = !NonVisualDataModule->Busy;
  418. return Result;
  419. }
  420. //---------------------------------------------------------------------------
  421. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  422. const UnicodeString & CommandLine)
  423. {
  424. TProgramParams Params(CommandLine);
  425. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  426. if (Result)
  427. {
  428. NonVisualDataModule->StartBusy();
  429. try
  430. {
  431. // this action is initiated from another process,
  432. // so it's likely that our window is not visible,
  433. // and user won't see what is going on
  434. Application->BringToFront();
  435. // reload sessions as we may be asked to open a session
  436. // just stored by another instance
  437. StoredSessions->Load();
  438. UnicodeString SessionName = Params.Param[1];
  439. std::unique_ptr<TObjectList> DataList(new TObjectList());
  440. UnicodeString DownloadFile; // unused
  441. try
  442. {
  443. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  444. }
  445. catch (EAbort &)
  446. {
  447. // Happens when opening session in PuTTY and in other situations,
  448. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  449. // to process the command-line on its own (or to pass it to yet another instance)
  450. }
  451. if (DataList->Count > 0)
  452. {
  453. TTerminalManager * Manager = TTerminalManager::Instance();
  454. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  455. }
  456. }
  457. __finally
  458. {
  459. NonVisualDataModule->EndBusy();
  460. }
  461. }
  462. return Result;
  463. }
  464. //---------------------------------------------------------------------------
  465. void __fastcall TCustomScpExplorerForm::SetTerminal(TTerminal * value)
  466. {
  467. if (FTerminal != value)
  468. {
  469. TerminalChanging();
  470. FTerminal = value;
  471. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  472. FAllowTransferPresetAutoSelect = false;
  473. try
  474. {
  475. TerminalChanged();
  476. }
  477. __finally
  478. {
  479. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  480. }
  481. if (Terminal != NULL)
  482. {
  483. TransferPresetAutoSelect();
  484. }
  485. }
  486. }
  487. //---------------------------------------------------------------------------
  488. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  489. {
  490. if (FTerminal != NULL)
  491. {
  492. UpdateTerminal(Terminal);
  493. }
  494. }
  495. //---------------------------------------------------------------------------
  496. void __fastcall TCustomScpExplorerForm::TerminalChanged()
  497. {
  498. RemoteDirView->Terminal = Terminal;
  499. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  500. TManagedTerminal * ManagedTerminal = NULL;
  501. if (Terminal != NULL)
  502. {
  503. if (Terminal->Active)
  504. {
  505. Terminal->RefreshDirectory();
  506. }
  507. ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  508. DebugAssert(ManagedTerminal != NULL);
  509. if (WinConfiguration->PreservePanelState)
  510. {
  511. if (ManagedTerminal->RemoteExplorerState != NULL)
  512. {
  513. RemoteDirView->RestoreState(ManagedTerminal->RemoteExplorerState);
  514. }
  515. else
  516. {
  517. RemoteDirView->ClearState();
  518. }
  519. }
  520. InitStatusBar();
  521. }
  522. DoTerminalListChanged(false);
  523. if (ManagedTerminal != NULL)
  524. {
  525. // this has to be set only after the tab is switched from DoTerminalListChanged,
  526. // otherwise we are changing color of wrong tab
  527. SessionColor = (TColor)ManagedTerminal->StateData->Color;
  528. }
  529. UpdateTransferList();
  530. // Update panels Enable state before refreshing the labels
  531. UpdateControls();
  532. }
  533. //---------------------------------------------------------------------------
  534. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  535. {
  536. if (Queue != value)
  537. {
  538. if (FQueue != NULL)
  539. {
  540. FQueue->OnListUpdate = NULL;
  541. FQueue->OnQueueItemUpdate = NULL;
  542. }
  543. FQueue = value;
  544. if (FQueue != NULL)
  545. {
  546. DebugAssert(FQueue->OnListUpdate == NULL);
  547. FQueue->OnListUpdate = QueueListUpdate;
  548. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  549. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  550. }
  551. QueueChanged();
  552. }
  553. }
  554. //---------------------------------------------------------------------------
  555. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  556. TListItem * Item)
  557. {
  558. if (FQueueActedItem == Item)
  559. {
  560. FQueueActedItem = NULL;
  561. if ((QueueView3->PopupMenu != NULL) &&
  562. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  563. {
  564. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  565. ReleaseCapture();
  566. }
  567. }
  568. if (Item->Data == FPendingQueueActionItem)
  569. {
  570. FPendingQueueActionItem = NULL;
  571. }
  572. }
  573. //---------------------------------------------------------------------------
  574. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  575. {
  576. {
  577. TGuard Guard(FQueueStatusSection);
  578. FQueueStatusInvalidated = false;
  579. if (FQueue != NULL)
  580. {
  581. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  582. }
  583. }
  584. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  585. {
  586. FMaxQueueLength = FQueueStatus->Count;
  587. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  588. }
  589. FQueueController->UpdateQueueStatus(FQueueStatus);
  590. SetQueueProgress();
  591. UpdateQueueView();
  592. bool IsEmpty = (FQueueStatus == NULL) || (FQueueStatus->Count == 0);
  593. if (IsEmpty && (Terminal != NULL))
  594. {
  595. TOnceDoneOperation OnceDoneOperation =
  596. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  597. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  598. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  599. {
  600. FQueue->Enabled = false;
  601. }
  602. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  603. {
  604. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  605. }
  606. }
  607. }
  608. //---------------------------------------------------------------------------
  609. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  610. {
  611. UnicodeString Result;
  612. if (FQueueStatus != NULL)
  613. {
  614. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  615. {
  616. TFileOperationProgressType * ProgressData =
  617. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  618. if ((ProgressData != NULL) && ProgressData->InProgress)
  619. {
  620. Result = TProgressForm::ProgressStr(ProgressData);
  621. }
  622. }
  623. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  624. {
  625. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  626. }
  627. }
  628. return Result;
  629. }
  630. //---------------------------------------------------------------------------
  631. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  632. {
  633. ComponentVisible[fcQueueView] =
  634. (WinConfiguration->QueueView.Show == qvShow) ||
  635. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  636. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  637. }
  638. //---------------------------------------------------------------------------
  639. void __fastcall TCustomScpExplorerForm::QueueChanged()
  640. {
  641. if (FQueueStatus != NULL)
  642. {
  643. delete FQueueStatus;
  644. FQueueStatus = NULL;
  645. }
  646. UpdateQueueStatus(true);
  647. }
  648. //---------------------------------------------------------------------------
  649. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  650. {
  651. if (FQueue == Queue)
  652. {
  653. FQueueStatusInvalidated = true;
  654. }
  655. }
  656. //---------------------------------------------------------------------------
  657. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  658. TQueueItem * Item)
  659. {
  660. if (FQueue == Queue)
  661. {
  662. TGuard Guard(FQueueStatusSection);
  663. // this may be running in parallel with QueueChanged
  664. if (FQueueStatus != NULL)
  665. {
  666. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  667. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  668. {
  669. FRefreshLocalDirectory = (QueueItem == NULL) ||
  670. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  671. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  672. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  673. }
  674. if (QueueItem != NULL)
  675. {
  676. QueueItem->UserData = (void*)true;
  677. FQueueItemInvalidated = true;
  678. }
  679. }
  680. }
  681. }
  682. //---------------------------------------------------------------------------
  683. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  684. {
  685. // during standalone editing, we have no way to see/control queue,
  686. // so we have to always popup prompts automatically
  687. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  688. }
  689. //---------------------------------------------------------------------------
  690. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  691. {
  692. if (FQueueStatus != NULL)
  693. {
  694. bool QueueAutoPopup = IsQueueAutoPopup();
  695. bool NeedRefresh = FQueueController->NeedRefresh();
  696. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  697. FQueueItemInvalidated = false;
  698. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  699. bool Updated = false;
  700. TQueueItemProxy * QueueItem;
  701. bool WasUserAction;
  702. for (int Index = 0; Index < Limit; Index++)
  703. {
  704. bool Update = false;
  705. QueueItem = FQueueStatus->Items[Index];
  706. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  707. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  708. (FPendingQueueActionItem == NULL))
  709. {
  710. FPendingQueueActionItem = QueueItem;
  711. FUserActionTimer->Enabled = true;
  712. }
  713. if ((bool)QueueItem->UserData)
  714. {
  715. QueueItem->UserData = (void*)false;
  716. QueueItem->Update();
  717. Updated = true;
  718. Update = true;
  719. }
  720. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  721. {
  722. Update = true;
  723. }
  724. if (Update)
  725. {
  726. FQueueController->RefreshQueueItem(QueueItem);
  727. }
  728. }
  729. if (Updated)
  730. {
  731. NonVisualDataModule->UpdateNonVisibleActions();
  732. SetQueueProgress();
  733. }
  734. }
  735. }
  736. //---------------------------------------------------------------------------
  737. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  738. {
  739. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  740. }
  741. //---------------------------------------------------------------------------
  742. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  743. {
  744. if (ProgressData->Operation != foCalculateSize)
  745. {
  746. // implies TBPF_NORMAL
  747. FTaskbarList->SetProgressValue(GetMainForm()->Handle, ProgressData->OverallProgress(), 100);
  748. }
  749. else
  750. {
  751. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  752. }
  753. }
  754. //---------------------------------------------------------------------------
  755. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  756. {
  757. TTerminalManager::Instance()->QueueStatusUpdated();
  758. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  759. {
  760. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  761. {
  762. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  763. {
  764. TFileOperationProgressType * ProgressData = NULL;
  765. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  766. {
  767. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  768. }
  769. if ((ProgressData != NULL) &&
  770. ProgressData->InProgress)
  771. {
  772. SetTaskbarListProgressValue(ProgressData);
  773. }
  774. else
  775. {
  776. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  777. }
  778. }
  779. else
  780. {
  781. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  782. }
  783. }
  784. else
  785. {
  786. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  787. }
  788. }
  789. UpdateQueueLabel();
  790. }
  791. //---------------------------------------------------------------------------
  792. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  793. {
  794. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  795. if (FQueueStatus != NULL)
  796. {
  797. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  798. if (ActiveAndPendingPrimaryCount > 0)
  799. {
  800. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  801. }
  802. }
  803. QueueLabel->Caption = Caption;
  804. }
  805. //---------------------------------------------------------------------------
  806. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  807. {
  808. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  809. static_cast<TComponent*>(GetComponent(fcTransferList)));
  810. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  811. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  812. TransferList->Strings->BeginUpdate();
  813. try
  814. {
  815. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  816. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  817. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  818. if (FTransferDropDownHint.IsEmpty())
  819. {
  820. FTransferDropDownHint = TransferDropDown->Hint;
  821. }
  822. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  823. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  824. TransferDropDown->Text = StripHotkey(Name);
  825. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  826. (FTransferDropDownHint, StripHotkey(Name),
  827. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  828. FLAGMASK(Terminal != NULL, Terminal->UsableCopyParamAttrs(0).General))));
  829. // update the label, otherwise when it is updated only on the first draw
  830. // of the list, it is drawn "bold" for some reason
  831. FTransferListHoverIndex = TransferList->ItemIndex;
  832. UpdateTransferLabel();
  833. }
  834. __finally
  835. {
  836. TransferList->Strings->EndUpdate();
  837. }
  838. }
  839. //---------------------------------------------------------------------------
  840. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  841. {
  842. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  843. DebugAssert(Toolbar != NULL);
  844. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  845. }
  846. //---------------------------------------------------------------------------
  847. void __fastcall TCustomScpExplorerForm::UpdateActions()
  848. {
  849. TForm::UpdateActions();
  850. if (ComponentVisible[fcCustomCommandsBand])
  851. {
  852. UpdateCustomCommandsToolbar();
  853. }
  854. }
  855. //---------------------------------------------------------------------------
  856. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  857. {
  858. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  859. }
  860. //---------------------------------------------------------------------------
  861. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  862. {
  863. DebugAssert(Configuration && RemoteDirView);
  864. RemoteDirView->DDAllowMove = WinConfiguration->DDAllowMoveInit;
  865. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  866. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  867. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  868. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  869. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  870. if (RemoteDirView->RowSelect != WinConfiguration->FullRowSelect)
  871. {
  872. RemoteDirView->RowSelect = WinConfiguration->FullRowSelect;
  873. // selection is not redrawn automatically when RowSelect changes
  874. RemoteDirView->Invalidate();
  875. }
  876. RemoteDriveView->DDAllowMove = WinConfiguration->DDAllowMoveInit;
  877. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  878. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  879. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  880. UpdateSessionsPageControlHeight();
  881. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  882. UpdateToolbarDisplayMode();
  883. UpdateTransferList();
  884. if (Terminal != NULL)
  885. {
  886. TransferPresetAutoSelect();
  887. }
  888. UpdateQueueView();
  889. UpdateControls();
  890. // this can be called even before constuctor finishes.
  891. if (FEditorManager != NULL)
  892. {
  893. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  894. }
  895. // this can be called even before constuctor finishes.
  896. if (FLocalEditors != NULL)
  897. {
  898. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  899. {
  900. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  901. }
  902. }
  903. if (ComponentVisible[fcCustomCommandsBand])
  904. {
  905. UpdateCustomCommandsToolbar();
  906. }
  907. // show only when keeping queue items forever,
  908. // otherwise, its enough to have in in the context menu
  909. QueueDeleteAllDoneQueueToolbarItem->Visible =
  910. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  911. }
  912. //---------------------------------------------------------------------------
  913. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  914. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  915. void * /*Arg*/)
  916. {
  917. if (Token != NULL)
  918. {
  919. TForm * Editor = dynamic_cast<TForm*>(Token);
  920. DebugAssert(Editor != NULL);
  921. ReconfigureEditorForm(Editor);
  922. }
  923. }
  924. //---------------------------------------------------------------------------
  925. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  926. {
  927. WinConfiguration->DDTransferConfirmation = asOn;
  928. }
  929. //---------------------------------------------------------------------------
  930. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  931. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  932. {
  933. // noop
  934. }
  935. //---------------------------------------------------------------------------
  936. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  937. TTransferDirection Direction, TTransferType Type, bool Temp,
  938. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  939. bool Confirm, bool DragDrop, int Options)
  940. {
  941. bool Result = true;
  942. DebugAssert(Terminal && Terminal->Active);
  943. // Temp means d&d here so far, may change in future!
  944. if (Temp && (Direction == tdToLocal) && (Type == ttMove) &&
  945. !WinConfiguration->DDAllowMove)
  946. {
  947. TMessageParams Params(mpNeverAskAgainCheck);
  948. unsigned int Answer = MessageDialog(LoadStr(DND_DOWNLOAD_MOVE_WARNING), qtWarning,
  949. qaOK | qaCancel, HELP_DND_DOWNLOAD_MOVE_WARNING, &Params);
  950. if (Answer == qaNeverAskAgain)
  951. {
  952. WinConfiguration->DDAllowMove = true;
  953. }
  954. else if (Answer == qaCancel)
  955. {
  956. Result = false;
  957. }
  958. }
  959. // these parameters are known in advance
  960. int Params =
  961. FLAGMASK(Type == ttMove, cpDelete);
  962. bool ToTemp = (Temp && (Direction == tdToLocal));
  963. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  964. {
  965. bool DisableNewerOnly =
  966. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  967. ToTemp;
  968. Options |=
  969. FLAGMASK(ToTemp, coTemp) |
  970. coDoNotShowAgain;
  971. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  972. int CopyParamAttrs = (Direction == tdToRemote ?
  973. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  974. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  975. int OutputOptions =
  976. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  977. cooDoNotShowAgain);
  978. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  979. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  980. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions);
  981. if (Result)
  982. {
  983. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  984. {
  985. if (DragDrop)
  986. {
  987. if (WinConfiguration->DDTransferConfirmation == asAuto)
  988. {
  989. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  990. NULL, 0, EnableDDTransferConfirmation, NULL);
  991. }
  992. WinConfiguration->DDTransferConfirmation = asOff;
  993. }
  994. else
  995. {
  996. WinConfiguration->ConfirmTransferring = false;
  997. }
  998. }
  999. else
  1000. {
  1001. // User exclicitly unchecked "do not show again",
  1002. // so show him the dialog the next time
  1003. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1004. {
  1005. WinConfiguration->DDTransferConfirmation = asOn;
  1006. }
  1007. }
  1008. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1009. }
  1010. }
  1011. if (Result && CopyParam.Queue && !ToTemp)
  1012. {
  1013. Configuration->Usage->Inc(L"TransfersOnBackground");
  1014. // these parameter are known only after transfer dialog
  1015. Params |=
  1016. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1017. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1018. Result = false;
  1019. ClearTransferSourceSelection(Direction);
  1020. }
  1021. return Result;
  1022. }
  1023. //---------------------------------------------------------------------------
  1024. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1025. {
  1026. if (FOnFileOperationFinished != NULL)
  1027. {
  1028. FOnFileOperationFinished(UnicodeString(), true);
  1029. }
  1030. else
  1031. {
  1032. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1033. if (HasDirView[Side])
  1034. {
  1035. DirView(Side)->SelectAll(smNone);
  1036. }
  1037. }
  1038. }
  1039. //---------------------------------------------------------------------------
  1040. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1041. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1042. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1043. int Params)
  1044. {
  1045. DebugAssert(Queue != NULL);
  1046. bool SingleFile = false;
  1047. if (FileList->Count == 1)
  1048. {
  1049. if (Direction == tdToRemote)
  1050. {
  1051. UnicodeString FileName = FileList->Strings[0];
  1052. SingleFile = FileExists(ApiPath(FileName));
  1053. }
  1054. else
  1055. {
  1056. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1057. SingleFile = !File->IsDirectory;
  1058. }
  1059. }
  1060. TQueueItem * QueueItem;
  1061. if (Direction == tdToRemote)
  1062. {
  1063. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1064. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1065. }
  1066. else
  1067. {
  1068. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1069. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1070. }
  1071. AddQueueItem(Queue, QueueItem, Terminal);
  1072. }
  1073. //---------------------------------------------------------------------------
  1074. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TTerminal * Terminal)
  1075. {
  1076. if (Queue->IsEmpty)
  1077. {
  1078. TManagedTerminal * ManagedTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  1079. ManagedTerminal->QueueOperationStart = Now();
  1080. }
  1081. Queue->AddItem(QueueItem);
  1082. }
  1083. //---------------------------------------------------------------------------
  1084. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1085. {
  1086. }
  1087. //---------------------------------------------------------------------------
  1088. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1089. {
  1090. DebugAssert(FDocks != NULL);
  1091. for (int Index = 0; Index < ComponentCount; Index++)
  1092. {
  1093. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1094. if ((Dock != NULL) && (Dock->Tag == 0))
  1095. {
  1096. FDocks->Add(Dock);
  1097. }
  1098. }
  1099. CollectItemsWithTextDisplayMode(this);
  1100. ConfigurationChanged();
  1101. QueuePanel->Height =
  1102. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1103. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1104. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1105. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1106. }
  1107. //---------------------------------------------------------------------------
  1108. void __fastcall TCustomScpExplorerForm::StoreParams()
  1109. {
  1110. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1111. WinConfiguration->QueueView.HeightPixelsPerInch = GetControlPixelsPerInch(this);
  1112. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1113. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1114. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1115. }
  1116. //---------------------------------------------------------------------------
  1117. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1118. {
  1119. if (!FFormRestored)
  1120. {
  1121. FFormRestored = true;
  1122. RestoreFormParams();
  1123. }
  1124. TForm::CreateParams(Params);
  1125. }
  1126. //---------------------------------------------------------------------------
  1127. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1128. {
  1129. DebugAssert(FDocks != NULL);
  1130. for (int Index = 0; Index < FDocks->Count; Index++)
  1131. {
  1132. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1133. }
  1134. }
  1135. //---------------------------------------------------------------------------
  1136. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1137. {
  1138. SetDockAllowDrag(true);
  1139. while (!ButtonsStr.IsEmpty())
  1140. {
  1141. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1142. UnicodeString Name = CutToChar(S, L'=', true);
  1143. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1144. {
  1145. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1146. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1147. {
  1148. while (!S.IsEmpty())
  1149. {
  1150. UnicodeString S2 = CutToChar(S, L',', true);
  1151. UnicodeString Name = CutToChar(S2, L':', true);
  1152. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1153. {
  1154. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1155. if (SameText(GetToolbarItemName(Item), Name))
  1156. {
  1157. // forward compatibility
  1158. UnicodeString S3 = CutToChar(S2, L':', true);
  1159. bool Visible = StrToIntDef(S3, 0);
  1160. Item->Visible = Visible;
  1161. }
  1162. }
  1163. }
  1164. }
  1165. }
  1166. }
  1167. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1168. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1169. }
  1170. //---------------------------------------------------------------------------
  1171. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1172. {
  1173. UnicodeString Result;
  1174. SetDockAllowDrag(true);
  1175. Result = ::GetToolbarsLayoutStr(this);
  1176. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1177. return Result;
  1178. }
  1179. //---------------------------------------------------------------------------
  1180. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1181. {
  1182. UnicodeString Result;
  1183. if (Item->Action != NULL)
  1184. {
  1185. Result = Item->Action->Name;
  1186. Result = RemoveSuffix(Result, L"Action");
  1187. }
  1188. else
  1189. {
  1190. Result = Item->Name;
  1191. Result = RemoveSuffix(Result, L"SubmenuItem");
  1192. Result = RemoveSuffix(Result, L"Item");
  1193. }
  1194. return Result;
  1195. }
  1196. //---------------------------------------------------------------------------
  1197. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1198. {
  1199. UnicodeString Result;
  1200. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1201. {
  1202. UnicodeString ToolbarStr;
  1203. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1204. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1205. {
  1206. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1207. {
  1208. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1209. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1210. // Once we introduce any buttons that aer hidden by default, we would have to remember their initial state
  1211. // and save the changes here only.
  1212. if (!Item->Visible)
  1213. {
  1214. UnicodeString Name = GetToolbarItemName(Item);
  1215. DebugAssert(Name.Pos(L"TBX") == 0);
  1216. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1217. }
  1218. }
  1219. }
  1220. if (!ToolbarStr.IsEmpty())
  1221. {
  1222. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1223. }
  1224. }
  1225. return Result;
  1226. }
  1227. //---------------------------------------------------------------------------
  1228. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1229. TFileOperationProgressType & ProgressData)
  1230. {
  1231. // Download to temporary local directory
  1232. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1233. {
  1234. bool Continue = true;
  1235. FPendingTempSpaceWarn = false;
  1236. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1237. if (!Continue)
  1238. {
  1239. Abort();
  1240. }
  1241. }
  1242. // operation is being executed and we still didn't show up progress form
  1243. if (ProgressData.InProgress && !FProgressForm)
  1244. {
  1245. bool AllowSkip =
  1246. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1247. Terminal->IsCapable[fsSkipTransfer];
  1248. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip);
  1249. // As progress window has delayed show now, we need to lock ourselves,
  1250. // (at least) until then
  1251. LockWindow();
  1252. FProgressForm->DeleteToRecycleBin = (ProgressData.Side == osLocal ?
  1253. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete) :
  1254. ((Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1255. !Terminal->SessionData->RecycleBinPath.IsEmpty()));
  1256. // When main window is hidden, synchronisation form does not exist,
  1257. // we suppose "/upload" or URL download mode
  1258. if (!Visible && (ProgressData.Operation != foCalculateSize) &&
  1259. (ProgressData.Operation != foCalculateChecksum) &&
  1260. (FSynchronizeProgressForm == NULL) &&
  1261. !FStandaloneEditing)
  1262. {
  1263. FProgressForm->OnceDoneOperation = odoDisconnect;
  1264. }
  1265. if (FTaskbarList != NULL)
  1266. {
  1267. // Actually, do not know what hides the progress once the operation finishes
  1268. SetTaskbarListProgressState(TBPF_NORMAL);
  1269. }
  1270. }
  1271. // operation is finished (or terminated), so we hide progress form
  1272. else if (!ProgressData.InProgress && FProgressForm)
  1273. {
  1274. UnlockWindow();
  1275. SAFE_DESTROY(FProgressForm);
  1276. SetQueueProgress();
  1277. if (ProgressData.Operation == foCalculateSize)
  1278. {
  1279. // When calculating size before transfer, the abort caused by
  1280. // cancel flag set due to "MoveToQueue" below,
  1281. // is not propagated back to us in ExecuteFileOperation,
  1282. // as it is silently swallowed.
  1283. // So we explicitly (re)throw it here.
  1284. if (FMoveToQueue)
  1285. {
  1286. Abort();
  1287. }
  1288. }
  1289. else
  1290. {
  1291. if ((ProgressData.Cancel == csContinue) &&
  1292. !FAutoOperation)
  1293. {
  1294. OperationComplete(ProgressData.StartTime);
  1295. }
  1296. }
  1297. }
  1298. if (FProgressForm)
  1299. {
  1300. FProgressForm->SetProgressData(ProgressData);
  1301. if (FTaskbarList != NULL)
  1302. {
  1303. DebugAssert(ProgressData.InProgress);
  1304. SetTaskbarListProgressValue(&ProgressData);
  1305. }
  1306. if (FProgressForm->Cancel > csContinue)
  1307. {
  1308. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1309. if (FProgressForm->Cancel == csCancelFile)
  1310. {
  1311. FProgressForm->ClearCancel();
  1312. }
  1313. // cancel cancels even the move
  1314. FMoveToQueue = false;
  1315. }
  1316. else if (FProgressForm->MoveToQueue)
  1317. {
  1318. FMoveToQueue = true;
  1319. ProgressData.SetCancelAtLeast(csCancel);
  1320. }
  1321. if ((FTransferResumeList != NULL) &&
  1322. ProgressData.InProgress &&
  1323. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1324. !ProgressData.FullFileName.IsEmpty())
  1325. {
  1326. if ((FTransferResumeList->Count == 0) ||
  1327. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1328. {
  1329. // note that we do not recognize directories from files here
  1330. FTransferResumeList->Add(ProgressData.FullFileName);
  1331. }
  1332. }
  1333. }
  1334. }
  1335. //---------------------------------------------------------------------------
  1336. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1337. const TDateTime & StartTime)
  1338. {
  1339. if (GUIConfiguration->BeepOnFinish &&
  1340. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1341. {
  1342. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1343. DWORD Sound;
  1344. if (!ExtractFileExt(BeepSound).IsEmpty())
  1345. {
  1346. Sound = SND_FILENAME;
  1347. }
  1348. else
  1349. {
  1350. Sound = SND_ALIAS;
  1351. }
  1352. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1353. }
  1354. }
  1355. //---------------------------------------------------------------------------
  1356. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1357. TFileOperationProgressType & ProgressData)
  1358. {
  1359. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1360. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1361. TAutoFlag Flag(FDoNotIdleCurrentTerminal);
  1362. FileOperationProgress(ProgressData);
  1363. }
  1364. //---------------------------------------------------------------------------
  1365. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1366. bool DragDrop)
  1367. {
  1368. return (!DragDrop && (DropSourceControl == NULL)) ||
  1369. (DropSourceControl == RemoteDirView);
  1370. }
  1371. //---------------------------------------------------------------------------
  1372. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1373. TFileOperation Operation, TOperationSide Side,
  1374. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1375. TOnceDoneOperation & OnceDoneOperation)
  1376. {
  1377. if (!FAutoOperation)
  1378. {
  1379. // no selection on "/upload", form servers only as event handler
  1380. // (it is not displayed)
  1381. if (PanelOperation(Side, FDragDropOperation) &&
  1382. Visible && (Operation != foCalculateSize) &&
  1383. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1384. {
  1385. if (FOnFileOperationFinished != NULL)
  1386. {
  1387. FOnFileOperationFinished(FileName, Success);
  1388. }
  1389. else
  1390. {
  1391. TCustomDirView * DView = DirView(Side);
  1392. UnicodeString FileNameOnly = ExtractFileName(FileName, (Side == osRemote));
  1393. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1394. // this can happen when local drive is unplugged in the middle of the operation
  1395. if (Item != NULL)
  1396. {
  1397. if (Success) Item->Selected = false;
  1398. DView->MakeProgressVisible(Item);
  1399. }
  1400. }
  1401. }
  1402. if ((Operation == foCopy) || (Operation == foMove))
  1403. {
  1404. if (Side == osLocal)
  1405. {
  1406. Configuration->Usage->Inc(L"UploadedFiles");
  1407. }
  1408. else
  1409. {
  1410. Configuration->Usage->Inc(L"DownloadedFiles");
  1411. }
  1412. }
  1413. }
  1414. if (Success && (FSynchronizeController != NULL))
  1415. {
  1416. if (Operation == foCopy)
  1417. {
  1418. DebugAssert(Side == osLocal);
  1419. FSynchronizeController->LogOperation(soUpload, FileName);
  1420. }
  1421. else if (Operation == foDelete)
  1422. {
  1423. DebugAssert(Side == osRemote);
  1424. FSynchronizeController->LogOperation(soDelete, FileName);
  1425. }
  1426. }
  1427. if (FProgressForm)
  1428. {
  1429. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1430. }
  1431. }
  1432. //---------------------------------------------------------------------------
  1433. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1434. TFileOperation Operation, TOperationSide Side,
  1435. bool Temp, const UnicodeString & FileName, Boolean Success,
  1436. TOnceDoneOperation & OnceDoneOperation)
  1437. {
  1438. TAutoFlag Flag(FDoNotIdleCurrentTerminal);
  1439. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1440. OnceDoneOperation);
  1441. }
  1442. //---------------------------------------------------------------------------
  1443. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1444. {
  1445. DebugAssert(GetSide(Side) == osRemote);
  1446. DebugUsedParam(Side);
  1447. return RemoteDirView;
  1448. }
  1449. //---------------------------------------------------------------------------
  1450. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1451. {
  1452. DebugAssert(GetSide(Side) == osRemote);
  1453. DebugUsedParam(Side);
  1454. return (Terminal != NULL);
  1455. }
  1456. //---------------------------------------------------------------------------
  1457. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1458. TOperationSide Side, int FilesOnly)
  1459. {
  1460. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1461. }
  1462. //---------------------------------------------------------------------------
  1463. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1464. TOperationSide Side, int FilesOnly)
  1465. {
  1466. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1467. }
  1468. //---------------------------------------------------------------------------
  1469. struct THistoryItemData
  1470. {
  1471. short int Side;
  1472. short int Index;
  1473. };
  1474. //---------------------------------------------------------------------------
  1475. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1476. {
  1477. DirView(Side)->HistoryGo(Index);
  1478. }
  1479. //---------------------------------------------------------------------------
  1480. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1481. {
  1482. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1483. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1484. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1485. }
  1486. //---------------------------------------------------------------------------
  1487. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1488. bool Back)
  1489. {
  1490. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1491. {
  1492. TCustomDirView * DView = DirView(Side);
  1493. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1494. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1495. if (ICount > 10)
  1496. {
  1497. ICount = 10;
  1498. }
  1499. Menu->Items->Clear();
  1500. THistoryItemData Data;
  1501. Data.Side = Side;
  1502. for (short int i = 1; i <= ICount; i++)
  1503. {
  1504. TTBCustomItem * Item = new TTBXItem(Menu);
  1505. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1506. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, (Side == osRemote));
  1507. Item->Hint = DView->HistoryPath[Data.Index];
  1508. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1509. Item->Tag = *reinterpret_cast<int*>(&Data);
  1510. Item->OnClick = HistoryItemClick;
  1511. Menu->Items->Add(Item);
  1512. }
  1513. }
  1514. }
  1515. //---------------------------------------------------------------------------
  1516. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1517. TOperationSide Side, bool Back)
  1518. {
  1519. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1520. {
  1521. // workaround
  1522. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1523. // operator new allocates memory in Pascal code, but calls inline
  1524. // contructor in C++, leading in problems, the function does
  1525. // both in Pascal code
  1526. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1527. UpdateHistoryMenu(Side, Back);
  1528. }
  1529. return FHistoryMenu[Side == osLocal][Back];
  1530. }
  1531. //---------------------------------------------------------------------------
  1532. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1533. TCustomDirView *Sender)
  1534. {
  1535. TOperationSide Side = (Sender == DirView(osRemote) ? osRemote : osLocal);
  1536. UpdateHistoryMenu(Side, true);
  1537. UpdateHistoryMenu(Side, false);
  1538. }
  1539. //---------------------------------------------------------------------------
  1540. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1541. {
  1542. // remote custom commands can be executed only if the server supports shell commands
  1543. // or have secondary shell
  1544. return (FTerminal != NULL) && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1545. }
  1546. //---------------------------------------------------------------------------
  1547. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1548. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1549. {
  1550. int Result;
  1551. TFileCustomCommand RemoteCustomCommand;
  1552. TLocalCustomCommand LocalCustomCommand;
  1553. TFileCustomCommand * NonInteractiveCustomCommand =
  1554. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1555. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1556. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1557. if (FLAGCLEAR(Command.Params, ccLocal))
  1558. {
  1559. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1560. // custom command that does not operate with files can be executed anytime ...
  1561. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1562. {
  1563. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1564. {
  1565. // ... but do not show such command in remote file menu (TODO)
  1566. Result = AllowedState;
  1567. }
  1568. else
  1569. {
  1570. Result = -1;
  1571. }
  1572. }
  1573. else
  1574. {
  1575. if ((ListType == ccltAll) || (ListType == ccltFile))
  1576. {
  1577. Result = ((FCurrentSide == osRemote) && DirView(osRemote)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1578. }
  1579. else
  1580. {
  1581. Result = -1;
  1582. }
  1583. }
  1584. }
  1585. else
  1586. {
  1587. // custom command that does not operate with files can be executed anytime
  1588. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1589. {
  1590. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1591. }
  1592. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1593. {
  1594. if ((ListType == ccltAll) || (ListType == ccltFile))
  1595. {
  1596. // special case is "diff"-style command that can be executed over any side,
  1597. // if we have both sides
  1598. Result =
  1599. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1600. // directly (instead of EnableSelectedOperation) to pass
  1601. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1602. ((HasDirView[osLocal] && DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1603. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1604. }
  1605. else if (ListType == ccltBoth)
  1606. {
  1607. Result = 1;
  1608. }
  1609. else
  1610. {
  1611. Result = -1;
  1612. }
  1613. }
  1614. else
  1615. {
  1616. if ((ListType == ccltAll) || (ListType == ccltFile))
  1617. {
  1618. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1619. }
  1620. else
  1621. {
  1622. Result = -1;
  1623. }
  1624. }
  1625. }
  1626. return Result;
  1627. }
  1628. //---------------------------------------------------------------------------
  1629. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1630. TStrings * FileList, const TCustomCommandType & ACommand,
  1631. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1632. {
  1633. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1634. {
  1635. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1636. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1637. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1638. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1639. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1640. bool Capture =
  1641. FLAGSET(ACommand.Params, ccShowResults) ||
  1642. FLAGSET(ACommand.Params, ccCopyResults) ||
  1643. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1644. TCaptureOutputEvent OutputEvent = NULL;
  1645. DebugAssert(FCapturedLog == NULL);
  1646. if (Capture)
  1647. {
  1648. FCapturedLog = new TStringList();
  1649. OutputEvent = TerminalCaptureLog;
  1650. }
  1651. try
  1652. {
  1653. if (!RemoteCustomCommand.IsFileCommand(Command))
  1654. {
  1655. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1656. OutputEvent);
  1657. }
  1658. else
  1659. {
  1660. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1661. }
  1662. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1663. {
  1664. if (FLAGSET(ACommand.Params, ccCopyResults))
  1665. {
  1666. CopyToClipboard(FCapturedLog);
  1667. }
  1668. if (FLAGSET(ACommand.Params, ccShowResults))
  1669. {
  1670. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1671. }
  1672. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1673. {
  1674. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1675. }
  1676. }
  1677. }
  1678. __finally
  1679. {
  1680. SAFE_DESTROY(FCapturedLog);
  1681. }
  1682. }
  1683. }
  1684. //---------------------------------------------------------------------------
  1685. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1686. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1687. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1688. {
  1689. TStrings * LocalFileList = NULL;
  1690. TStrings * RemoteFileList = NULL;
  1691. TStrings * RemoteFileListFull = NULL;
  1692. try
  1693. {
  1694. if (LocalFileCommand)
  1695. {
  1696. if (ALocalFileList == NULL)
  1697. {
  1698. DebugAssert(HasDirView[osLocal]);
  1699. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1700. // directly (instead of EnableSelectedOperation) to pass
  1701. // false to FocusedFileOnlyWhenFocused
  1702. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1703. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1704. }
  1705. else
  1706. {
  1707. LocalFileList = ALocalFileList;
  1708. }
  1709. if (FileListCommand)
  1710. {
  1711. if (LocalFileList->Count != 1)
  1712. {
  1713. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1714. }
  1715. }
  1716. else
  1717. {
  1718. if ((LocalFileList->Count != 1) &&
  1719. (FileList->Count != 1) &&
  1720. (LocalFileList->Count != FileList->Count))
  1721. {
  1722. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1723. }
  1724. }
  1725. }
  1726. UnicodeString RootTempDir;
  1727. UnicodeString TempDir;
  1728. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1729. if (!RemoteFiles)
  1730. {
  1731. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1732. }
  1733. try
  1734. {
  1735. TDateTimes RemoteFileTimes;
  1736. if (RemoteFiles)
  1737. {
  1738. RemoteFileList = FileList;
  1739. }
  1740. else
  1741. {
  1742. RemoteFileList = new TStringList();
  1743. TMakeLocalFileListParams MakeFileListParam;
  1744. MakeFileListParam.FileList = RemoteFileList;
  1745. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1746. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1747. MakeFileListParam.Recursive =
  1748. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1749. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1750. if (!MakeFileListParam.Recursive)
  1751. {
  1752. RemoteFileTimes.clear();
  1753. RemoteFileListFull = new TStringList();
  1754. MakeFileListParam.FileList = RemoteFileListFull;
  1755. MakeFileListParam.Recursive = true;
  1756. MakeFileListParam.IncludeDirs = false;
  1757. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1758. }
  1759. else
  1760. {
  1761. RemoteFileListFull = RemoteFileList;
  1762. }
  1763. }
  1764. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1765. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1766. if (!NonBlocking)
  1767. {
  1768. Progress.Start(foCustomCommand, osRemote, FileListCommand ? 1 : FileList->Count);
  1769. DebugAssert(FProgressForm != NULL);
  1770. FProgressForm->ReadOnly = true;
  1771. }
  1772. try
  1773. {
  1774. if (FileListCommand)
  1775. {
  1776. UnicodeString LocalFile;
  1777. // MakeFileList does not delimit filenames
  1778. UnicodeString FileList = MakeFileList(RemoteFileList);
  1779. if (LocalFileCommand)
  1780. {
  1781. DebugAssert(LocalFileList->Count == 1);
  1782. LocalFile = LocalFileList->Strings[0];
  1783. }
  1784. TLocalCustomCommand CustomCommand(Data,
  1785. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1786. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1787. if (NonBlocking)
  1788. {
  1789. DebugAssert(!POutput);
  1790. ExecuteShellChecked(ShellCommand);
  1791. }
  1792. else
  1793. {
  1794. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1795. }
  1796. }
  1797. else if (LocalFileCommand)
  1798. {
  1799. if (LocalFileList->Count == 1)
  1800. {
  1801. UnicodeString LocalFile = LocalFileList->Strings[0];
  1802. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1803. {
  1804. UnicodeString FileName = RemoteFileList->Strings[Index];
  1805. TLocalCustomCommand CustomCommand(Data,
  1806. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1807. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1808. }
  1809. }
  1810. else if (RemoteFileList->Count == 1)
  1811. {
  1812. UnicodeString FileName = RemoteFileList->Strings[0];
  1813. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1814. {
  1815. TLocalCustomCommand CustomCommand(
  1816. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1817. FileName, LocalFileList->Strings[Index], L"");
  1818. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1819. }
  1820. }
  1821. else
  1822. {
  1823. if (LocalFileList->Count != RemoteFileList->Count)
  1824. {
  1825. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1826. }
  1827. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1828. {
  1829. UnicodeString FileName = RemoteFileList->Strings[Index];
  1830. TLocalCustomCommand CustomCommand(
  1831. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1832. FileName, LocalFileList->Strings[Index], L"");
  1833. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1834. }
  1835. }
  1836. }
  1837. else
  1838. {
  1839. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1840. {
  1841. TLocalCustomCommand CustomCommand(Data,
  1842. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1843. RemoteFileList->Strings[Index], L"", L"");
  1844. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1845. }
  1846. }
  1847. }
  1848. __finally
  1849. {
  1850. if (!NonBlocking)
  1851. {
  1852. Progress.Stop();
  1853. }
  1854. }
  1855. DebugAssert(!FAutoOperation);
  1856. if (!RemoteFiles)
  1857. {
  1858. TempDir = IncludeTrailingBackslash(TempDir);
  1859. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  1860. {
  1861. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  1862. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  1863. // Skip directories, process only nested files.
  1864. // The check is redundant as FileAge fails for directories anyway.
  1865. !DirectoryExists(FileName))
  1866. {
  1867. UnicodeString RemoteDir =
  1868. UnixExtractFileDir(
  1869. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  1870. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  1871. TDateTime NewTime;
  1872. if (FileAge(FileName, NewTime) &&
  1873. (NewTime != RemoteFileTimes[Index]))
  1874. {
  1875. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  1876. TemporaryFileCopyParam(CopyParam);
  1877. CopyParam.FileMask = L"";
  1878. FAutoOperation = true;
  1879. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  1880. TemporaryFilesList->Add(FileName);
  1881. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  1882. }
  1883. }
  1884. }
  1885. }
  1886. }
  1887. __finally
  1888. {
  1889. FAutoOperation = false;
  1890. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  1891. {
  1892. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  1893. }
  1894. }
  1895. }
  1896. __finally
  1897. {
  1898. if (RemoteFileList != FileList)
  1899. {
  1900. delete RemoteFileList;
  1901. }
  1902. if (LocalFileList != ALocalFileList)
  1903. {
  1904. delete LocalFileList;
  1905. }
  1906. if (RemoteFileListFull != RemoteFileList)
  1907. {
  1908. delete RemoteFileListFull;
  1909. }
  1910. }
  1911. }
  1912. //---------------------------------------------------------------------------
  1913. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithRemoteFiles(
  1914. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  1915. bool FileListCommand, UnicodeString * POutput)
  1916. {
  1917. std::unique_ptr<TStrings> SelectedFileList(DirView(osLocal)->CreateFileList(false, true, NULL));
  1918. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  1919. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  1920. {
  1921. UnicodeString FileName = SelectedFileList->Strings[Index];
  1922. if (DirectoryExists(FileName))
  1923. {
  1924. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  1925. {
  1926. LocalFileList->Add(FileName);
  1927. }
  1928. if (FLAGSET(ACommand.Params, ccRecursive))
  1929. {
  1930. TMakeLocalFileListParams MakeFileListParam;
  1931. MakeFileListParam.FileList = LocalFileList.get();
  1932. MakeFileListParam.FileTimes = NULL;
  1933. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1934. MakeFileListParam.Recursive = true;
  1935. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  1936. }
  1937. }
  1938. else
  1939. {
  1940. LocalFileList->Add(FileName);
  1941. }
  1942. }
  1943. if (FileListCommand)
  1944. {
  1945. UnicodeString FileList = MakeFileList(LocalFileList.get());
  1946. TLocalCustomCommand CustomCommand(
  1947. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1948. L"", L"", FileList);
  1949. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1950. }
  1951. else
  1952. {
  1953. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1954. Progress.Start(foCustomCommand, osRemote, FileListCommand ? 1 : LocalFileList->Count);
  1955. DebugAssert(FProgressForm != NULL);
  1956. FProgressForm->ReadOnly = true;
  1957. try
  1958. {
  1959. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1960. {
  1961. UnicodeString FileName = LocalFileList->Strings[Index];
  1962. TLocalCustomCommand CustomCommand(
  1963. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1964. FileName, L"", L"");
  1965. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1966. }
  1967. }
  1968. __finally
  1969. {
  1970. Progress.Stop();
  1971. }
  1972. }
  1973. }
  1974. //---------------------------------------------------------------------------
  1975. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  1976. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  1977. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1978. {
  1979. TLocalCustomCommand LocalCustomCommand(Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory());
  1980. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1981. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  1982. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1983. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  1984. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  1985. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  1986. std::unique_ptr<UnicodeString> POutput;
  1987. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  1988. FLAGSET(ACommand.Params, ccCopyResults))
  1989. {
  1990. POutput.reset(new UnicodeString());
  1991. }
  1992. if (!LocalCustomCommand.IsFileCommand(Command))
  1993. {
  1994. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  1995. }
  1996. // remote files?
  1997. else if ((FCurrentSide == osRemote) || LocalFileCommand)
  1998. {
  1999. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2000. }
  2001. // local files
  2002. else
  2003. {
  2004. LocalCustomCommandWithRemoteFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2005. }
  2006. if (POutput.get() != NULL)
  2007. {
  2008. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2009. int P = POutput->Pos(sLineBreak);
  2010. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2011. {
  2012. POutput->SetLength(P - 1);
  2013. }
  2014. // Copy even empty output to clipboard
  2015. if (FLAGSET(ACommand.Params, ccCopyResults))
  2016. {
  2017. CopyToClipboard(*POutput);
  2018. }
  2019. // But do not show an empty message box.
  2020. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2021. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2022. !POutput->IsEmpty())
  2023. {
  2024. TClipboardHandler ClipboardHandler;
  2025. ClipboardHandler.Text = *POutput;
  2026. TMessageParams Params;
  2027. TQueryButtonAlias Aliases[1];
  2028. Aliases[0].Button = qaRetry;
  2029. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2030. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2031. Params.Aliases = Aliases;
  2032. Params.AliasesCount = LENOF(Aliases);
  2033. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2034. }
  2035. }
  2036. }
  2037. //---------------------------------------------------------------------------
  2038. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2039. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2040. {
  2041. TCustomCommandData Data(Terminal);
  2042. UnicodeString Site = Terminal->SessionData->SessionKey;
  2043. UnicodeString HelpKeyword = ACommand.HomePage;
  2044. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2045. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2046. {
  2047. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2048. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2049. {
  2050. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, Terminal->CurrentDirectory));
  2051. }
  2052. else
  2053. {
  2054. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory()));
  2055. }
  2056. if (!DoCustomCommandOptionsDialog(
  2057. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2058. {
  2059. Abort();
  2060. }
  2061. }
  2062. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2063. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2064. {
  2065. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2066. }
  2067. else
  2068. {
  2069. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2070. }
  2071. }
  2072. //---------------------------------------------------------------------------
  2073. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2074. const TCustomCommandType & Command)
  2075. {
  2076. DebugAssert(FCustomCommandLocalFileList != NULL);
  2077. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2078. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2079. TStrings * LocalFileList = new TStringList();
  2080. TStrings * RemoteFileList = new TStringList();
  2081. try
  2082. {
  2083. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2084. {
  2085. LocalFileList->Clear();
  2086. LocalFileList->AddObject(
  2087. FCustomCommandLocalFileList->Strings[Index],
  2088. FCustomCommandLocalFileList->Objects[Index]);
  2089. RemoteFileList->Clear();
  2090. RemoteFileList->AddObject(
  2091. FCustomCommandRemoteFileList->Strings[Index],
  2092. FCustomCommandRemoteFileList->Objects[Index]);
  2093. CustomCommand(RemoteFileList, Command, LocalFileList);
  2094. }
  2095. }
  2096. __finally
  2097. {
  2098. delete LocalFileList;
  2099. delete RemoteFileList;
  2100. }
  2101. }
  2102. //---------------------------------------------------------------------------
  2103. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2104. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2105. {
  2106. delete FCustomCommandLocalFileList;
  2107. delete FCustomCommandRemoteFileList;
  2108. // takeover ownership,
  2109. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2110. FCustomCommandLocalFileList = LocalFileList;
  2111. FCustomCommandRemoteFileList = RemoteFileList;
  2112. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2113. if (Button != NULL)
  2114. {
  2115. FCustomCommandMenu->Items->Clear();
  2116. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth);
  2117. MenuPopup(FCustomCommandMenu, Button);
  2118. }
  2119. else
  2120. {
  2121. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2122. }
  2123. }
  2124. //---------------------------------------------------------------------------
  2125. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2126. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2127. {
  2128. DebugAssert(FCapturedLog != NULL);
  2129. if ((OutputType == cotOutput) || (OutputType == cotError))
  2130. {
  2131. FCapturedLog->Add(AddedLine);
  2132. }
  2133. }
  2134. //---------------------------------------------------------------------------
  2135. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2136. TOperationSide Side)
  2137. {
  2138. return (Side == osRemote) &&
  2139. ((Control == RemoteDirView) || (Control == RemoteDriveView));
  2140. }
  2141. //---------------------------------------------------------------------------
  2142. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2143. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2144. {
  2145. TTBItemOptions O;
  2146. O = Item->Options;
  2147. TCustomDirView * DView = DirView(Side);
  2148. if ((DView->ItemFocused != NULL) &&
  2149. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2150. // when resolving links is disabled, default action is to enter the directory,
  2151. // no matter what DoubleClickAction is configured to
  2152. ((Side != osRemote) || Terminal->ResolvingSymlinks) &&
  2153. // Can only Edit files, but can Open/Copy even directories
  2154. ((DoubleClickAction != dcaEdit) ||
  2155. !DView->ItemIsDirectory(DView->ItemFocused)))
  2156. {
  2157. Item->Options = O << tboDefault;
  2158. }
  2159. else
  2160. {
  2161. Item->Options = O >> tboDefault;
  2162. }
  2163. }
  2164. //---------------------------------------------------------------------------
  2165. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2166. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2167. {
  2168. TCustomDirView * DView = DirView(Side);
  2169. TListItem * Item = DView->ItemFocused;
  2170. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2171. EnableFocusedOperation[Side])
  2172. {
  2173. TPoint ClientPoint;
  2174. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2175. TPoint(0, 0) : MousePos;
  2176. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2177. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2178. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2179. }
  2180. }
  2181. //---------------------------------------------------------------------------
  2182. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2183. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2184. {
  2185. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2186. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2187. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2188. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2189. Handled = true;
  2190. }
  2191. //---------------------------------------------------------------------------
  2192. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2193. {
  2194. }
  2195. //---------------------------------------------------------------------------
  2196. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2197. {
  2198. DebugAssert(FErrorList == NULL);
  2199. if (WinConfiguration->ContinueOnError)
  2200. {
  2201. FErrorList = new TStringList();
  2202. Configuration->Usage->Inc(L"ContinuationsOnError");
  2203. }
  2204. NonVisualDataModule->StartBusy();
  2205. }
  2206. //---------------------------------------------------------------------------
  2207. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2208. {
  2209. NonVisualDataModule->EndBusy();
  2210. if (FErrorList)
  2211. {
  2212. HandleErrorList(FErrorList);
  2213. }
  2214. }
  2215. //---------------------------------------------------------------------------
  2216. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2217. const TCopyParamType & CopyParam)
  2218. {
  2219. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2220. {
  2221. Configuration->Usage->Inc(L"FileMaskUses");
  2222. }
  2223. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2224. {
  2225. Configuration->Usage->Inc(L"OperationMaskUses");
  2226. }
  2227. }
  2228. //---------------------------------------------------------------------------
  2229. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2230. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2231. {
  2232. void * BatchStorage;
  2233. BatchStart(BatchStorage);
  2234. bool Result;
  2235. try
  2236. {
  2237. if ((Operation == foCopy) || (Operation == foMove))
  2238. {
  2239. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2240. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2241. UnicodeString TargetDirectory;
  2242. bool Temp = false;
  2243. bool DragDrop = false;
  2244. int Options = 0;
  2245. TAutoSwitch UseQueue = asAuto;
  2246. if (Param != NULL)
  2247. {
  2248. TTransferOperationParam& TParam =
  2249. *static_cast<TTransferOperationParam*>(Param);
  2250. TargetDirectory = TParam.TargetDirectory;
  2251. Temp = TParam.Temp;
  2252. DragDrop = TParam.DragDrop;
  2253. Options = TParam.Options;
  2254. UseQueue = TParam.Queue;
  2255. }
  2256. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2257. switch (UseQueue)
  2258. {
  2259. case asOn:
  2260. CopyParam.Queue = true;
  2261. break;
  2262. case asOff:
  2263. CopyParam.Queue = false;
  2264. break;
  2265. case asAuto:
  2266. default:
  2267. // keep default
  2268. break;
  2269. }
  2270. Result =
  2271. CopyParamDialog(Direction, Type, Temp, FileList, TargetDirectory,
  2272. CopyParam, !NoConfirmation, DragDrop, Options);
  2273. if (Result)
  2274. {
  2275. DebugAssert(Terminal);
  2276. bool SelectionRestored = false;
  2277. TCustomDirView * DView = NULL;
  2278. if (HasDirView[Side])
  2279. {
  2280. DView = DirView(Side);
  2281. DView->SaveSelection();
  2282. DView->SaveSelectedNames();
  2283. }
  2284. UpdateCopyParamCounters(CopyParam);
  2285. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2286. DebugAssert(FTransferResumeList == NULL);
  2287. FTransferResumeList =
  2288. Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2289. FMoveToQueue = false;
  2290. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2291. try
  2292. {
  2293. TStrings * PermanentFileList;
  2294. std::unique_ptr<TStrings> PermanentFileListOwner;
  2295. try
  2296. {
  2297. if (Side == osLocal)
  2298. {
  2299. PermanentFileList = FileList;
  2300. Params |= FLAGMASK(Temp, cpTemporary);
  2301. Terminal->CopyToRemote(FileList, TargetDirectory, &CopyParam, Params, NULL);
  2302. if (Operation == foMove)
  2303. {
  2304. ReloadLocalDirectory();
  2305. if (DView != NULL)
  2306. {
  2307. DView->RestoreSelection();
  2308. }
  2309. SelectionRestored = true;
  2310. }
  2311. }
  2312. else
  2313. {
  2314. // Clone the file list as it may refer to current directory files,
  2315. // which get destroyed, when the source directory is reloaded after foMove operation.
  2316. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2317. // But for a hotfix, we are not going to do such a big change.
  2318. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2319. PermanentFileList = PermanentFileListOwner.get();
  2320. try
  2321. {
  2322. Terminal->CopyToLocal(
  2323. FileList, TargetDirectory, &CopyParam, Params, NULL);
  2324. }
  2325. __finally
  2326. {
  2327. if (Operation == foMove)
  2328. {
  2329. if (DView != NULL)
  2330. {
  2331. DView->RestoreSelection();
  2332. }
  2333. SelectionRestored = true;
  2334. }
  2335. ReloadLocalDirectory(TargetDirectory);
  2336. }
  2337. }
  2338. }
  2339. catch (EAbort &)
  2340. {
  2341. if (FMoveToQueue)
  2342. {
  2343. Params |=
  2344. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2345. DebugAssert(CopyParam.TransferSkipList == NULL);
  2346. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2347. if (TransferResumeList->Count > 0)
  2348. {
  2349. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2350. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2351. }
  2352. CopyParam.TransferSkipList = TransferResumeList.release();
  2353. // not really needed, just to keep it consistent with TransferResumeList
  2354. FTransferResumeList = NULL;
  2355. FMoveToQueue = false;
  2356. Configuration->Usage->Inc("MovesToBackground");
  2357. AddQueueItem(Queue, Direction, PermanentFileList, TargetDirectory, CopyParam, Params);
  2358. ClearTransferSourceSelection(Direction);
  2359. }
  2360. throw;
  2361. }
  2362. }
  2363. __finally
  2364. {
  2365. if (!SelectionRestored && (DView != NULL))
  2366. {
  2367. DView->DiscardSavedSelection();
  2368. }
  2369. FTransferResumeList = NULL;
  2370. }
  2371. }
  2372. }
  2373. else if (Operation == foRename)
  2374. {
  2375. DebugAssert(DirView(Side)->ItemFocused);
  2376. DirView(Side)->ItemFocused->EditCaption();
  2377. Result = true;
  2378. }
  2379. else if (Operation == foDelete)
  2380. {
  2381. DebugAssert(FileList->Count);
  2382. // We deliberately do not toggle alternative flag (Param), but use OR,
  2383. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2384. // shortcut of CurrentDeleteAlternativeAction
  2385. bool Alternative =
  2386. bool(Param) || UseAlternativeFunction();
  2387. bool Recycle;
  2388. if (Side == osLocal)
  2389. {
  2390. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2391. }
  2392. else
  2393. {
  2394. Recycle = (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2395. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2396. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2397. }
  2398. Result =
  2399. !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2400. if (!Result)
  2401. {
  2402. UnicodeString Query;
  2403. if (FileList->Count == 1)
  2404. {
  2405. if (Side == osLocal)
  2406. {
  2407. Query = ExtractFileName(FileList->Strings[0]);
  2408. }
  2409. else
  2410. {
  2411. Query = UnixExtractFileName(FileList->Strings[0]);
  2412. }
  2413. Query = FMTLOAD(
  2414. (Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2415. }
  2416. else
  2417. {
  2418. Query = FMTLOAD(
  2419. (Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2420. }
  2421. TMessageParams Params(mpNeverAskAgainCheck);
  2422. Params.ImageName = L"Delete file";
  2423. unsigned int Answer = MessageDialog(MainInstructions(Query), qtConfirmation,
  2424. qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2425. if (Answer == qaNeverAskAgain)
  2426. {
  2427. Result = true;
  2428. if (Recycle)
  2429. {
  2430. WinConfiguration->ConfirmRecycling = false;
  2431. }
  2432. else
  2433. {
  2434. WinConfiguration->ConfirmDeleting = false;
  2435. }
  2436. }
  2437. else
  2438. {
  2439. Result = (Answer == qaOK);
  2440. }
  2441. }
  2442. if (Result)
  2443. {
  2444. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2445. }
  2446. }
  2447. else if (Operation == foSetProperties)
  2448. {
  2449. RemoteDirView->SaveSelectedNames();
  2450. Result = SetProperties(Side, FileList);
  2451. }
  2452. else if (Operation == foCustomCommand)
  2453. {
  2454. DebugAssert(Param);
  2455. DebugAssert(Side == osRemote);
  2456. RemoteDirView->SaveSelectedNames();
  2457. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2458. CustomCommand(FileList, *Command, NULL);
  2459. Result = true;
  2460. }
  2461. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2462. {
  2463. DebugAssert(Side == osRemote);
  2464. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2465. (Operation == foRemoteMove), reinterpret_cast<TTerminal *>(Param));
  2466. }
  2467. else if (Operation == foLock)
  2468. {
  2469. DebugAssert(Side == osRemote);
  2470. LockFiles(FileList, true);
  2471. Result = true;
  2472. }
  2473. else if (Operation == foUnlock)
  2474. {
  2475. DebugAssert(Side == osRemote);
  2476. LockFiles(FileList, false);
  2477. Result = true;
  2478. }
  2479. else
  2480. {
  2481. DebugFail();
  2482. }
  2483. }
  2484. __finally
  2485. {
  2486. BatchEnd(BatchStorage);
  2487. }
  2488. return Result;
  2489. }
  2490. //---------------------------------------------------------------------------
  2491. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2492. {
  2493. if (Side == osCurrent)
  2494. {
  2495. Side = FCurrentSide;
  2496. }
  2497. return Side;
  2498. }
  2499. //---------------------------------------------------------------------------
  2500. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2501. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2502. {
  2503. Side = GetSide(Side);
  2504. bool Result;
  2505. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, (Side == osLocal), NULL);
  2506. try
  2507. {
  2508. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2509. }
  2510. __finally
  2511. {
  2512. delete FileList;
  2513. }
  2514. return Result;
  2515. }
  2516. //---------------------------------------------------------------------------
  2517. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2518. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2519. bool NoConfirmation, void * Param)
  2520. {
  2521. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2522. {
  2523. if ((Operation == foCopy) || (Operation == foMove))
  2524. {
  2525. if (GetSide(Side) == osLocal)
  2526. {
  2527. Configuration->Usage->Inc(L"UploadsCommand");
  2528. }
  2529. else
  2530. {
  2531. Configuration->Usage->Inc(L"DownloadsCommand");
  2532. }
  2533. }
  2534. }
  2535. }
  2536. //---------------------------------------------------------------------------
  2537. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2538. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2539. {
  2540. TTransferOperationParam Param;
  2541. if ((WinConfiguration->Interface != ifCommander) ||
  2542. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2543. {
  2544. Flags &= ~cocShortCutHint;
  2545. }
  2546. TCustomDirView * DView = DirView(Side);
  2547. Param.Options =
  2548. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2549. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2550. if (FLAGSET(Flags, cocQueue))
  2551. {
  2552. Param.Queue = asOn;
  2553. }
  2554. else if (FLAGSET(Flags, cocNonQueue))
  2555. {
  2556. Param.Queue = asOff;
  2557. }
  2558. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2559. }
  2560. //---------------------------------------------------------------------------
  2561. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2562. {
  2563. try
  2564. {
  2565. if (ErrorList->Count)
  2566. {
  2567. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2568. if (MessageDialog(Message, qtError,
  2569. qaOK | qaCancel, HELP_NONE) == qaOK)
  2570. {
  2571. unsigned int Answer;
  2572. int Index = 0;
  2573. do
  2574. {
  2575. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2576. TQueryButtonAlias Aliases[2];
  2577. Aliases[0].Button = qaYes;
  2578. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2579. Aliases[1].Button = qaNo;
  2580. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2581. TMessageParams Params;
  2582. Params.Aliases = Aliases;
  2583. Params.AliasesCount = LENOF(Aliases);
  2584. Answer = MoreMessageDialog(
  2585. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2586. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2587. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2588. qaOK, HELP_NONE, &Params);
  2589. if (Answer == qaNo)
  2590. {
  2591. Index++;
  2592. }
  2593. if (Answer == qaYes)
  2594. {
  2595. Index--;
  2596. }
  2597. }
  2598. while (Answer != qaOK);
  2599. }
  2600. }
  2601. }
  2602. __finally
  2603. {
  2604. TStrings * List = ErrorList;
  2605. ErrorList = NULL;
  2606. for (int i = 0; i < List->Count; i++)
  2607. {
  2608. delete List->Objects[i];
  2609. }
  2610. delete List;
  2611. }
  2612. }
  2613. //---------------------------------------------------------------------------
  2614. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2615. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2616. {
  2617. // needed for checking filemasks, as there's no directory object
  2618. // associated with the file object
  2619. File->FullFileName = FullFileName;
  2620. TFileMasks::TParams MaskParams;
  2621. MaskParams.Size = File->Size;
  2622. MaskParams.Modification = File->Modification;
  2623. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2624. }
  2625. //---------------------------------------------------------------------------
  2626. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2627. {
  2628. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2629. Side = GetSide(Side);
  2630. TCustomDirView * DView = DirView(Side);
  2631. TListItem * FocusedItem = DView->ItemFocused;
  2632. UnicodeString Name;
  2633. if ((FocusedItem != NULL) && !DView->ItemIsParentDirectory(FocusedItem))
  2634. {
  2635. Name = DView->ItemFileName(FocusedItem);
  2636. }
  2637. else
  2638. {
  2639. Name = LoadStr(NEW_FILE);
  2640. }
  2641. UnicodeString Names = Name;
  2642. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2643. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2644. HELP_EDIT_NEW, History.get(), true))
  2645. {
  2646. while (!Names.IsEmpty())
  2647. {
  2648. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2649. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2650. UnicodeString TargetFileName;
  2651. UnicodeString LocalFileName;
  2652. UnicodeString RootTempDir;
  2653. UnicodeString TempDir;
  2654. UnicodeString RemoteDirectory;
  2655. bool ExistingFile = false;
  2656. if (Side == osRemote)
  2657. {
  2658. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2659. TRemoteFile * File = NULL;
  2660. if (FTerminal->FileExists(Name, &File))
  2661. {
  2662. try
  2663. {
  2664. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2665. ExistingFile = true;
  2666. }
  2667. __finally
  2668. {
  2669. delete File;
  2670. }
  2671. }
  2672. if (!ExistingFile)
  2673. {
  2674. RemoteDirectory = UnixExtractFilePath(Name);
  2675. TemporaryDirectoryForRemoteFiles(
  2676. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2677. TargetFileName = UnixExtractFileName(Name);
  2678. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2679. LocalFileName = TempDir +
  2680. // We probably do not want to trim the VMS version here
  2681. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2682. }
  2683. }
  2684. else
  2685. {
  2686. if (ExtractFilePath(Name).IsEmpty())
  2687. {
  2688. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2689. }
  2690. else
  2691. {
  2692. LocalFileName = ExpandFileName(Name);
  2693. }
  2694. TargetFileName = ExtractFileName(Name);
  2695. }
  2696. if (!ExistingFile)
  2697. {
  2698. if (!FileExists(ApiPath(LocalFileName)))
  2699. {
  2700. int File = FileCreate(ApiPath(LocalFileName));
  2701. if (File < 0)
  2702. {
  2703. if (!RootTempDir.IsEmpty())
  2704. {
  2705. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2706. }
  2707. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2708. }
  2709. else
  2710. {
  2711. FileClose(File);
  2712. }
  2713. }
  2714. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2715. const TEditorData * ExternalEditor = NULL;
  2716. TFileMasks::TParams MaskParams; // size not known
  2717. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2718. false, MaskParams);
  2719. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2720. ExternalEditor, RootTempDir, RemoteDirectory);
  2721. }
  2722. }
  2723. }
  2724. }
  2725. //---------------------------------------------------------------------------
  2726. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2727. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2728. {
  2729. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2730. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2731. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2732. return
  2733. ((ExecuteFileBy == efInternalEditor)) ||
  2734. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2735. }
  2736. //---------------------------------------------------------------------------
  2737. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2738. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2739. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2740. UnicodeString RemoteDirectory)
  2741. {
  2742. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2743. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2744. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2745. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2746. Side = GetSide(Side);
  2747. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2748. if (Side == osRemote)
  2749. {
  2750. Data->Terminal = Terminal;
  2751. Data->Queue = Queue;
  2752. Data->SessionData = CloneCurrentSessionData();
  2753. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2754. Data->RemoteDirectory = RemoteDirectory;
  2755. Data->SessionName = Terminal->SessionData->SessionName;
  2756. Data->LocalRootDirectory = LocalRootDirectory;
  2757. Data->OriginalFileName = OriginalFileName;
  2758. Data->Command = L""; // will be changed later for external editor
  2759. }
  2760. if (ExecuteFileBy == efInternalEditor)
  2761. {
  2762. if (Side == osRemote)
  2763. {
  2764. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2765. L" - " + Terminal->SessionData->SessionName;
  2766. TForm * Editor;
  2767. try
  2768. {
  2769. Editor = ShowEditorForm(FileName, this, FEditorManager->FileChanged,
  2770. FEditorManager->FileReload, FEditorManager->FileClosed,
  2771. SaveAllInternalEditors, AnyInternalEditorModified,
  2772. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding);
  2773. }
  2774. catch(...)
  2775. {
  2776. if (!LocalRootDirectory.IsEmpty())
  2777. {
  2778. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2779. }
  2780. throw;
  2781. }
  2782. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2783. }
  2784. else
  2785. {
  2786. DebugAssert(!FStandaloneEditing);
  2787. TForm * Editor =
  2788. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2789. SaveAllInternalEditors, AnyInternalEditorModified,
  2790. L"", false, SessionColor, -1);
  2791. FLocalEditors->Add(Editor);
  2792. }
  2793. }
  2794. else
  2795. {
  2796. HANDLE Process;
  2797. if (ExecuteFileBy == efExternalEditor)
  2798. {
  2799. UnicodeString Program, Params, Dir;
  2800. Data->Command = ExternalEditor->ExternalEditor;
  2801. ReformatFileNameCommand(Data->Command);
  2802. SplitCommand(Data->Command, Program, Params, Dir);
  2803. Params = ExpandFileNameCommand(Params, FileName);
  2804. Program = ExpandEnvironmentVariables(Program);
  2805. if (!ExecuteShell(Program, Params, Process))
  2806. {
  2807. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  2808. }
  2809. }
  2810. else
  2811. {
  2812. DebugAssert(Side == osRemote);
  2813. if (!ExecuteShell(FileName, L"", Process))
  2814. {
  2815. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  2816. }
  2817. }
  2818. if ((Side == osLocal) ||
  2819. ((ExecuteFileBy == efShell) &&
  2820. !WinConfiguration->Editor.SDIShellEditor) ||
  2821. ((ExecuteFileBy == efExternalEditor) &&
  2822. !ExternalEditor->SDIExternalEditor))
  2823. {
  2824. // no need for handle
  2825. if (Process != NULL)
  2826. {
  2827. DebugCheck(CloseHandle(Process));
  2828. }
  2829. Process = INVALID_HANDLE_VALUE;
  2830. }
  2831. else
  2832. {
  2833. if (Process == NULL)
  2834. {
  2835. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  2836. }
  2837. }
  2838. if (Side == osRemote)
  2839. {
  2840. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  2841. }
  2842. }
  2843. }
  2844. //---------------------------------------------------------------------------
  2845. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  2846. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  2847. void * /*Arg*/)
  2848. {
  2849. if (Token != NULL)
  2850. {
  2851. EditorFormFileSave(static_cast<TForm *>(Token));
  2852. }
  2853. }
  2854. //---------------------------------------------------------------------------
  2855. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  2856. {
  2857. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  2858. {
  2859. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  2860. }
  2861. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  2862. }
  2863. //---------------------------------------------------------------------------
  2864. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  2865. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  2866. void * Arg)
  2867. {
  2868. if ((Token != NULL) &&
  2869. IsEditorFormModified(static_cast<TForm *>(Token)))
  2870. {
  2871. *static_cast<bool *>(Arg) = true;
  2872. }
  2873. }
  2874. //---------------------------------------------------------------------------
  2875. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  2876. TObject * /*Sender*/, bool & Modified)
  2877. {
  2878. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  2879. {
  2880. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  2881. {
  2882. Modified = true;
  2883. }
  2884. }
  2885. if (!Modified)
  2886. {
  2887. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  2888. }
  2889. }
  2890. //---------------------------------------------------------------------------
  2891. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  2892. {
  2893. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  2894. }
  2895. //---------------------------------------------------------------------------
  2896. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  2897. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  2898. UnicodeString & Result, UnicodeString & RootDirectory)
  2899. {
  2900. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  2901. {
  2902. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  2903. Result = RootDirectory;
  2904. }
  2905. else
  2906. {
  2907. RootDirectory = L"";
  2908. Result = WinConfiguration->ExpandedTemporaryDirectory();
  2909. Result = IncludeTrailingBackslash(Result);
  2910. }
  2911. if (WinConfiguration->TemporaryDirectoryAppendSession)
  2912. {
  2913. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  2914. }
  2915. if (WinConfiguration->TemporaryDirectoryAppendPath)
  2916. {
  2917. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  2918. {
  2919. RemoteDirectory.Delete(1, 1);
  2920. }
  2921. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  2922. }
  2923. if (!ForceDirectories(ApiPath(Result)))
  2924. {
  2925. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  2926. }
  2927. }
  2928. //---------------------------------------------------------------------------
  2929. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  2930. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  2931. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  2932. {
  2933. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2934. if (ForceText)
  2935. {
  2936. CopyParam.TransferMode = tmAscii;
  2937. }
  2938. TemporaryFileCopyParam(CopyParam);
  2939. if (AllFiles)
  2940. {
  2941. CopyParam.IncludeFileMask = TFileMasks();
  2942. }
  2943. if (TempDir.IsEmpty())
  2944. {
  2945. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  2946. }
  2947. DebugAssert(!FAutoOperation);
  2948. FAutoOperation = AutoOperation;
  2949. Terminal->ExceptionOnFail = true;
  2950. try
  2951. {
  2952. try
  2953. {
  2954. // turn off confirmations, as for MDI editors we may possibly download
  2955. // the same file over
  2956. Terminal->CopyToLocal(
  2957. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  2958. if (GetTargetNames)
  2959. {
  2960. for (int i = 0; i < FileList->Count; i++)
  2961. {
  2962. FileList->Strings[i] =
  2963. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  2964. }
  2965. }
  2966. }
  2967. catch(...)
  2968. {
  2969. if (!RootTempDir.IsEmpty())
  2970. {
  2971. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2972. }
  2973. throw;
  2974. }
  2975. }
  2976. __finally
  2977. {
  2978. FAutoOperation = false;
  2979. Terminal->ExceptionOnFail = false;
  2980. }
  2981. }
  2982. //---------------------------------------------------------------------------
  2983. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  2984. {
  2985. // Do not waste time checking for default editor list the next time,
  2986. // or testing if default editor is not notepad.
  2987. bool TryNextTime = false;
  2988. UnicodeString UsageState;
  2989. if (!WinConfiguration->EditorList->IsDefaultList())
  2990. {
  2991. UsageState = "H";
  2992. }
  2993. else
  2994. {
  2995. UnicodeString Executable;
  2996. UnicodeString ExecutableDescription;
  2997. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  2998. {
  2999. UnicodeString Message =
  3000. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3001. unsigned int Answer =
  3002. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3003. if (Answer != qaOK)
  3004. {
  3005. UsageState = "R";
  3006. }
  3007. else
  3008. {
  3009. UsageState = "A";
  3010. TEditorData EditorData;
  3011. EditorData.Editor = edExternal;
  3012. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3013. EditorData.DecideExternalEditorText();
  3014. TEditorList EditorList;
  3015. EditorList = *WinConfiguration->EditorList;
  3016. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3017. WinConfiguration->EditorList = &EditorList;
  3018. }
  3019. }
  3020. }
  3021. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3022. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3023. }
  3024. //---------------------------------------------------------------------------
  3025. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3026. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3027. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3028. {
  3029. if (ExecuteFileBy == efDefaultEditor)
  3030. {
  3031. if (!WinConfiguration->OfferedEditorAutoConfig)
  3032. {
  3033. EditorAutoConfig();
  3034. }
  3035. const TEditorPreferences * Editor =
  3036. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3037. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3038. {
  3039. ExecuteFileBy = efInternalEditor;
  3040. ExternalEditor = NULL;
  3041. }
  3042. else if (Editor->Data->Editor == edOpen)
  3043. {
  3044. ExecuteFileBy = efShell;
  3045. ExternalEditor = NULL;
  3046. }
  3047. else
  3048. {
  3049. ExecuteFileBy = efExternalEditor;
  3050. ExternalEditor = Editor->Data;
  3051. }
  3052. }
  3053. }
  3054. //---------------------------------------------------------------------------
  3055. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3056. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3057. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3058. {
  3059. UnicodeString OriginalFileName;
  3060. UnicodeString LocalRootDirectory;
  3061. UnicodeString RemoteDirectory;
  3062. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3063. (Side == osLocal), MaskParams);
  3064. UnicodeString Counter;
  3065. UnicodeString LocalFileName;
  3066. bool Handled = false;
  3067. if (Side == osRemote)
  3068. {
  3069. // We need to trim VMS version here, so that we use name without version
  3070. // when uploading back to create a new version of the file
  3071. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3072. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3073. TObject * Token = NULL;
  3074. UnicodeString LocalDirectory;
  3075. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3076. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3077. LocalDirectory))
  3078. {
  3079. if (Token != NULL)
  3080. {
  3081. TForm * Form = dynamic_cast<TForm *>(Token);
  3082. if (Form->WindowState == wsMinimized)
  3083. {
  3084. ShowWindow(Form->Handle, SW_RESTORE);
  3085. }
  3086. else
  3087. {
  3088. Form->SetFocus();
  3089. }
  3090. Handled = true;
  3091. }
  3092. else
  3093. {
  3094. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3095. }
  3096. }
  3097. if (!Handled)
  3098. {
  3099. TStringList * FileList1 = new TStringList();
  3100. try
  3101. {
  3102. FileList1->AddObject(FullFileName, Object);
  3103. TemporarilyDownloadFiles(FileList1,
  3104. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3105. LocalRootDirectory, LocalDirectory, true, true, true);
  3106. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3107. }
  3108. __finally
  3109. {
  3110. delete FileList1;
  3111. }
  3112. switch (ExecuteFileBy)
  3113. {
  3114. case efShell:
  3115. Counter = "RemoteFilesExecuted";
  3116. break;
  3117. case efInternalEditor:
  3118. Counter = "RemoteFilesOpenedInInternalEditor";
  3119. break;
  3120. case efExternalEditor:
  3121. Counter = "RemoteFilesOpenedInExternalEditor";
  3122. break;
  3123. default:
  3124. DebugFail();
  3125. }
  3126. }
  3127. }
  3128. else
  3129. {
  3130. LocalFileName = FullFileName;
  3131. OriginalFileName = ExtractFileName(FullFileName);
  3132. switch (ExecuteFileBy)
  3133. {
  3134. case efShell:
  3135. Counter = "LocalFilesExecuted";
  3136. break;
  3137. case efInternalEditor:
  3138. Counter = "LocalFilesOpenedInInternalEditor";
  3139. break;
  3140. case efExternalEditor:
  3141. Counter = "LocalFilesOpenedInExternalEditor";
  3142. break;
  3143. default:
  3144. DebugFail();
  3145. }
  3146. }
  3147. if (!Handled)
  3148. {
  3149. Configuration->Usage->Inc(Counter);
  3150. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3151. ExternalEditor, LocalRootDirectory, RemoteDirectory);
  3152. }
  3153. }
  3154. //---------------------------------------------------------------------------
  3155. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3156. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3157. bool AllSelected, bool OnFocused)
  3158. {
  3159. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3160. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3161. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3162. Side = GetSide(Side);
  3163. TCustomDirView * DView = DirView(Side);
  3164. TStrings * FileList = AllSelected ?
  3165. DView->CreateFileList(OnFocused, Side == osLocal) :
  3166. DView->CreateFocusedFileList(Side == osLocal);
  3167. try
  3168. {
  3169. DebugAssert(AllSelected || (FileList->Count == 1));
  3170. for (int i = 0; i < FileList->Count; i++)
  3171. {
  3172. UnicodeString ListFileName = FileList->Strings[i];
  3173. UnicodeString FileNameOnly = (Side == osRemote) ?
  3174. UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3175. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3176. if (!DView->ItemIsDirectory(Item))
  3177. {
  3178. UnicodeString FullFileName;
  3179. if (Side == osRemote)
  3180. {
  3181. FullFileName = RemoteDirView->Path + ListFileName;
  3182. }
  3183. else
  3184. {
  3185. FullFileName = ListFileName;
  3186. }
  3187. TFileMasks::TParams MaskParams;
  3188. MaskParams.Size = DView->ItemFileSize(Item);
  3189. TDateTimePrecision Precision;
  3190. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3191. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3192. FileList->Objects[i], MaskParams);
  3193. }
  3194. }
  3195. }
  3196. __finally
  3197. {
  3198. delete FileList;
  3199. }
  3200. }
  3201. //---------------------------------------------------------------------------
  3202. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3203. {
  3204. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3205. CopyParam.FileNameCase = ncNoChange;
  3206. CopyParam.PreserveRights = false;
  3207. CopyParam.PreserveReadOnly = false;
  3208. CopyParam.ReplaceInvalidChars = true;
  3209. CopyParam.IncludeFileMask = TFileMasks();
  3210. CopyParam.NewerOnly = false;
  3211. CopyParam.FileMask = L"";
  3212. }
  3213. //---------------------------------------------------------------------------
  3214. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3215. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3216. {
  3217. TTerminalManager * Manager = TTerminalManager::Instance();
  3218. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3219. {
  3220. if (!NonVisualDataModule->Busy)
  3221. {
  3222. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3223. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3224. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3225. if (Data->Terminal == NULL)
  3226. {
  3227. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3228. if (SameSiteTerminal != NULL)
  3229. {
  3230. UnicodeString Message =
  3231. FMTLOAD(EDIT_SESSION_REATTACH,
  3232. (FileNameOnly, Data->SessionName, FileNameOnly));
  3233. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3234. {
  3235. Data->Terminal = Terminal;
  3236. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3237. Data->SessionName = Terminal->SessionData->SessionName;
  3238. // We might also overwrite session data
  3239. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3240. }
  3241. else
  3242. {
  3243. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3244. Abort();
  3245. }
  3246. }
  3247. }
  3248. // foreground session should reconnect itself
  3249. else if (Terminal != Data->Terminal)
  3250. {
  3251. UnicodeString Message =
  3252. MainInstructions(
  3253. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3254. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3255. {
  3256. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3257. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3258. }
  3259. else
  3260. {
  3261. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3262. Abort();
  3263. }
  3264. }
  3265. }
  3266. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3267. {
  3268. Configuration->Usage->Inc(L"EditInactiveSession");
  3269. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3270. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3271. (ExtractFileName(FileName), Data->SessionName)));
  3272. }
  3273. }
  3274. TStrings * FileList = new TStringList();
  3275. try
  3276. {
  3277. FileList->Add(FileName);
  3278. // consider using the same settings (preset) as when the file was downloaded
  3279. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3280. TemporaryFileCopyParam(CopyParam);
  3281. if (Data->ForceText)
  3282. {
  3283. CopyParam.TransferMode = tmAscii;
  3284. }
  3285. // so i do not need to worry if masking algorithm works in all cases
  3286. // ("" means "copy file name", no masking is actually done)
  3287. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3288. {
  3289. CopyParam.FileMask = L"";
  3290. }
  3291. else
  3292. {
  3293. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3294. }
  3295. DebugAssert(Data->Queue != NULL);
  3296. int Params = cpNoConfirmation | cpTemporary;
  3297. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3298. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3299. QueueItem->CompleteEvent = UploadCompleteEvent;
  3300. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3301. }
  3302. __finally
  3303. {
  3304. delete FileList;
  3305. }
  3306. }
  3307. //---------------------------------------------------------------------------
  3308. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3309. const UnicodeString FileName, const TEditedFileData * Data)
  3310. {
  3311. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3312. DebugAssert(!NonVisualDataModule->Busy);
  3313. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3314. {
  3315. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3316. (ExtractFileName(FileName), Data->SessionName)));
  3317. }
  3318. TTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3319. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3320. NonVisualDataModule->StartBusy();
  3321. try
  3322. {
  3323. std::unique_ptr<TRemoteFile> File;
  3324. UnicodeString RemoteFileName =
  3325. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3326. FTerminal->ExceptionOnFail = true;
  3327. try
  3328. {
  3329. TRemoteFile * AFile = NULL;
  3330. FTerminal->ReadFile(RemoteFileName, AFile);
  3331. File.reset(AFile);
  3332. if (!File->HaveFullFileName)
  3333. {
  3334. File->FullFileName = RemoteFileName;
  3335. }
  3336. }
  3337. __finally
  3338. {
  3339. FTerminal->ExceptionOnFail = false;
  3340. }
  3341. std::unique_ptr<TStrings> FileList(new TStringList());
  3342. FileList->AddObject(RemoteFileName, File.get());
  3343. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3344. UnicodeString TempDir = ExtractFilePath(FileName);
  3345. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3346. TempDir, true, true, true);
  3347. // sanity check, the target file name should be still the same
  3348. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3349. }
  3350. __finally
  3351. {
  3352. NonVisualDataModule->EndBusy();
  3353. // it actually may not exist anymore...
  3354. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3355. }
  3356. }
  3357. //---------------------------------------------------------------------------
  3358. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3359. const TEditedFileData * Data, bool & KeepOpen)
  3360. {
  3361. // Command is set for external editors only (not for "shell" open).
  3362. if (!Data->Command.IsEmpty())
  3363. {
  3364. bool AnyFound = false;
  3365. bool AnyMDI = false;
  3366. bool AnyNonMDI = false;
  3367. bool AnyDetect = false;
  3368. TEditorList * EditorList = new TEditorList();
  3369. try
  3370. {
  3371. *EditorList = *WinConfiguration->EditorList;
  3372. for (int i = 0; i < EditorList->Count; i++)
  3373. {
  3374. const TEditorPreferences * Editor = EditorList->Editors[i];
  3375. if ((Editor->Data->Editor == edExternal) &&
  3376. (Editor->Data->ExternalEditor == Data->Command))
  3377. {
  3378. AnyFound = true;
  3379. if (Editor->Data->SDIExternalEditor)
  3380. {
  3381. AnyNonMDI = true;
  3382. if (Editor->Data->DetectMDIExternalEditor)
  3383. {
  3384. AnyDetect = true;
  3385. }
  3386. }
  3387. else
  3388. {
  3389. AnyMDI = true;
  3390. }
  3391. }
  3392. }
  3393. bool EnableMDI = false;
  3394. bool DisableDetect = false;
  3395. if (AnyMDI)
  3396. {
  3397. KeepOpen = true;
  3398. if (AnyNonMDI)
  3399. {
  3400. // there is at least one instance of the editor with MDI support enabled,
  3401. // and one with disabled, enable it for all instances
  3402. EnableMDI = true;
  3403. }
  3404. }
  3405. else if (AnyFound && !AnyDetect)
  3406. {
  3407. // at least once instance found but all have MDI autodetection disabled
  3408. // => close the file (default action)
  3409. }
  3410. else
  3411. {
  3412. // no instance of the editor has MDI support enabled
  3413. TMessageParams Params;
  3414. if (AnyFound)
  3415. {
  3416. // there is at least one instance of the editor
  3417. Params.Params |= mpNeverAskAgainCheck;
  3418. }
  3419. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3420. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3421. switch (Answer)
  3422. {
  3423. case qaNeverAskAgain:
  3424. DisableDetect = true;
  3425. break;
  3426. case qaNo:
  3427. EnableMDI = true;
  3428. KeepOpen = true;
  3429. break;
  3430. }
  3431. }
  3432. if (AnyFound && (EnableMDI || DisableDetect))
  3433. {
  3434. bool Changed = false;
  3435. for (int i = 0; i < EditorList->Count; i++)
  3436. {
  3437. const TEditorPreferences * Editor = EditorList->Editors[i];
  3438. if ((Editor->Data->Editor == edExternal) &&
  3439. (Editor->Data->ExternalEditor == Data->Command) &&
  3440. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3441. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3442. {
  3443. Changed = true;
  3444. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3445. if (EnableMDI)
  3446. {
  3447. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3448. }
  3449. if (DisableDetect)
  3450. {
  3451. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3452. }
  3453. EditorList->Change(i, UpdatedEditor);
  3454. }
  3455. }
  3456. if (Changed)
  3457. {
  3458. WinConfiguration->EditorList = EditorList;
  3459. }
  3460. }
  3461. }
  3462. __finally
  3463. {
  3464. delete EditorList;
  3465. }
  3466. }
  3467. else
  3468. {
  3469. // "open" case
  3470. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3471. qaOK, HELP_APP_EARLY_CLOSED);
  3472. }
  3473. }
  3474. //---------------------------------------------------------------------------
  3475. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3476. {
  3477. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3478. }
  3479. //---------------------------------------------------------------------------
  3480. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3481. {
  3482. SideEnter(osRemote);
  3483. }
  3484. //---------------------------------------------------------------------------
  3485. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3486. {
  3487. MakeNextInTabOrder(RemoteDirView, RemoteDriveView);
  3488. SideEnter(osRemote);
  3489. }
  3490. //---------------------------------------------------------------------------
  3491. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3492. {
  3493. FCurrentSide = Side;
  3494. if (Visible)
  3495. {
  3496. UpdateControls();
  3497. }
  3498. }
  3499. //---------------------------------------------------------------------------
  3500. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3501. TStrings * FileList, bool Alternative)
  3502. {
  3503. TCustomDirView * DView = DirView(Side);
  3504. DView->SaveSelection();
  3505. DView->SaveSelectedNames();
  3506. DebugAssert(!FAlternativeDelete);
  3507. FAlternativeDelete = Alternative;
  3508. try
  3509. {
  3510. if (Side == osRemote)
  3511. {
  3512. DebugAssert(Terminal != NULL);
  3513. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3514. }
  3515. else
  3516. {
  3517. try
  3518. {
  3519. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3520. }
  3521. __finally
  3522. {
  3523. ReloadLocalDirectory();
  3524. }
  3525. }
  3526. FAlternativeDelete = false;
  3527. }
  3528. catch(...)
  3529. {
  3530. FAlternativeDelete = false;
  3531. DView->DiscardSavedSelection();
  3532. throw;
  3533. }
  3534. DView->RestoreSelection();
  3535. }
  3536. //---------------------------------------------------------------------------
  3537. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3538. {
  3539. DebugAssert(Terminal);
  3540. RemoteDirView->SaveSelection();
  3541. RemoteDirView->SaveSelectedNames();
  3542. try
  3543. {
  3544. if (Lock)
  3545. {
  3546. Terminal->LockFiles(FileList);
  3547. }
  3548. else
  3549. {
  3550. Terminal->UnlockFiles(FileList);
  3551. }
  3552. }
  3553. catch(...)
  3554. {
  3555. RemoteDirView->DiscardSavedSelection();
  3556. throw;
  3557. }
  3558. RemoteDirView->RestoreSelection();
  3559. }
  3560. //---------------------------------------------------------------------------
  3561. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TTerminal *& Session,
  3562. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3563. bool NoConfirmation, bool Move)
  3564. {
  3565. if (RemoteDriveView->DropTarget != NULL)
  3566. {
  3567. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3568. }
  3569. else if (RemoteDirView->DropTarget != NULL)
  3570. {
  3571. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3572. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3573. }
  3574. else
  3575. {
  3576. Target = RemoteDirView->Path;
  3577. }
  3578. if (Session == NULL)
  3579. {
  3580. Session = TTerminalManager::Instance()->ActiveTerminal;
  3581. }
  3582. Target = UnixIncludeTrailingBackslash(Target);
  3583. if (FileList->Count == 1)
  3584. {
  3585. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3586. }
  3587. else
  3588. {
  3589. FileMask = AnyMask;
  3590. }
  3591. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3592. bool Result = true;
  3593. if (!NoConfirmation)
  3594. {
  3595. bool Multi = (FileList->Count > 1);
  3596. if (Move)
  3597. {
  3598. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3599. }
  3600. else
  3601. {
  3602. DebugAssert(Terminal != NULL);
  3603. // update Terminal->StateData->RemoteDirectory
  3604. UpdateTerminal(Terminal);
  3605. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3606. TStrings * Directories = new TStringList;
  3607. try
  3608. {
  3609. for (int Index = 0; Index < Sessions->Count; Index++)
  3610. {
  3611. TManagedTerminal * Terminal =
  3612. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3613. Directories->Add(Terminal->StateData->RemoteDirectory);
  3614. }
  3615. TDirectRemoteCopy AllowDirectCopy;
  3616. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3617. {
  3618. DebugAssert(DirectCopy);
  3619. AllowDirectCopy = drcAllow;
  3620. }
  3621. else if (FTerminal->IsCapable[fcSecondaryShell])
  3622. {
  3623. DebugAssert(DirectCopy);
  3624. AllowDirectCopy = drcConfirmCommandSession;
  3625. }
  3626. else
  3627. {
  3628. DebugAssert(!DirectCopy);
  3629. AllowDirectCopy = drcDisallow;
  3630. }
  3631. void * ASession = Session;
  3632. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3633. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3634. Session = static_cast<TTerminal *>(ASession);
  3635. }
  3636. __finally
  3637. {
  3638. delete Directories;
  3639. }
  3640. }
  3641. }
  3642. return Result;
  3643. }
  3644. //---------------------------------------------------------------------------
  3645. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3646. TStrings * FileList, bool NoConfirmation, bool Move, TTerminal * Session)
  3647. {
  3648. bool DirectCopy;
  3649. UnicodeString Target, FileMask;
  3650. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3651. if (Result)
  3652. {
  3653. if (!Move && !DirectCopy)
  3654. {
  3655. Configuration->Usage->Inc("RemoteCopyTemp");
  3656. UnicodeString RootTempDir;
  3657. UnicodeString TempDir;
  3658. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3659. TStrings * TemporaryFilesList = new TStringList();
  3660. try
  3661. {
  3662. TMakeLocalFileListParams MakeFileListParam;
  3663. MakeFileListParam.FileList = TemporaryFilesList;
  3664. MakeFileListParam.FileTimes = NULL;
  3665. MakeFileListParam.IncludeDirs = true;
  3666. MakeFileListParam.Recursive = false;
  3667. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3668. TTerminalManager::Instance()->ActiveTerminal = Session;
  3669. if (TemporaryFilesList->Count > 0)
  3670. {
  3671. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3672. CopyParam.FileMask = FileMask;
  3673. DebugAssert(!FAutoOperation);
  3674. FAutoOperation = true;
  3675. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3676. }
  3677. }
  3678. __finally
  3679. {
  3680. delete TemporaryFilesList;
  3681. FAutoOperation = false;
  3682. if (!RootTempDir.IsEmpty())
  3683. {
  3684. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3685. }
  3686. }
  3687. }
  3688. else
  3689. {
  3690. RemoteDirView->SaveSelection();
  3691. RemoteDirView->SaveSelectedNames();
  3692. try
  3693. {
  3694. if (Move)
  3695. {
  3696. Configuration->Usage->Inc("RemoteMove");
  3697. Terminal->MoveFiles(FileList, Target, FileMask);
  3698. }
  3699. else
  3700. {
  3701. Configuration->Usage->Inc("RemoteCopyDirect");
  3702. DebugAssert(DirectCopy);
  3703. DebugAssert(Session == FTerminal);
  3704. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3705. FTerminal->CommandSessionOpened ||
  3706. CommandSessionFallback())
  3707. {
  3708. Terminal->CopyFiles(FileList, Target, FileMask);
  3709. }
  3710. }
  3711. }
  3712. catch(...)
  3713. {
  3714. RemoteDirView->DiscardSavedSelection();
  3715. throw;
  3716. }
  3717. RemoteDirView->RestoreSelection();
  3718. }
  3719. }
  3720. return Result;
  3721. }
  3722. //---------------------------------------------------------------------------
  3723. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3724. {
  3725. Side = GetSide(Side);
  3726. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3727. TRemoteProperties * AProperties = (Side == osRemote ? &Properties : NULL);
  3728. UnicodeString Name = LoadStr(NEW_FOLDER);
  3729. int AllowedChanges =
  3730. FLAGMASK((Side == osRemote) && Terminal->IsCapable[fcModeChanging], cpMode);
  3731. bool SaveSettings = false;
  3732. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3733. {
  3734. TWindowLock Lock(this);
  3735. if (Side == osRemote)
  3736. {
  3737. if (SaveSettings)
  3738. {
  3739. GUIConfiguration->NewDirectoryProperties = Properties;
  3740. }
  3741. RemoteDirView->CreateDirectoryEx(Name, &Properties);
  3742. }
  3743. else
  3744. {
  3745. DirView(Side)->CreateDirectory(Name);
  3746. }
  3747. }
  3748. }
  3749. //---------------------------------------------------------------------------
  3750. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3751. {
  3752. TWindowLock Lock(this);
  3753. DirView(Side)->ExecuteHomeDirectory();
  3754. }
  3755. //---------------------------------------------------------------------------
  3756. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3757. {
  3758. DoOpenDirectoryDialog(odBrowse, Side);
  3759. }
  3760. //---------------------------------------------------------------------------
  3761. bool __fastcall TCustomScpExplorerForm::OpenBookmark(UnicodeString Local, UnicodeString Remote)
  3762. {
  3763. UnicodeString Path;
  3764. if (FCurrentSide == osRemote)
  3765. {
  3766. Path = Remote;
  3767. }
  3768. else
  3769. {
  3770. Path = Local;
  3771. }
  3772. bool Result = !Path.IsEmpty();
  3773. if (Result)
  3774. {
  3775. // While we might get here when the session is closed (from location profiles),
  3776. // it's not a problem as the Path setter is noop then
  3777. DirView(FCurrentSide)->Path = Path;
  3778. }
  3779. return Result;
  3780. }
  3781. //---------------------------------------------------------------------------
  3782. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3783. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3784. bool & Close)
  3785. {
  3786. // terminal can be already closed (e.g. dropped connection)
  3787. if (Terminal != NULL)
  3788. {
  3789. try
  3790. {
  3791. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  3792. }
  3793. catch(...)
  3794. {
  3795. if (!Terminal->Active)
  3796. {
  3797. Close = true;
  3798. }
  3799. throw;
  3800. }
  3801. }
  3802. }
  3803. //---------------------------------------------------------------------------
  3804. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  3805. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  3806. bool & Close)
  3807. {
  3808. // terminal can be already closed (e.g. dropped connection)
  3809. if (Terminal != NULL)
  3810. {
  3811. Configuration->Usage->Inc(L"ChecksumCalculated");
  3812. try
  3813. {
  3814. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  3815. }
  3816. catch(...)
  3817. {
  3818. if (!Terminal->Active)
  3819. {
  3820. Close = true;
  3821. }
  3822. throw;
  3823. }
  3824. }
  3825. }
  3826. //---------------------------------------------------------------------------
  3827. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  3828. {
  3829. bool Result;
  3830. if (Side == osRemote)
  3831. {
  3832. TRemoteTokenList * GroupList = NULL;
  3833. TRemoteTokenList * UserList = NULL;
  3834. try
  3835. {
  3836. TRemoteProperties CurrentProperties;
  3837. if (Terminal->LoadFilesProperties(FileList))
  3838. {
  3839. RemoteDirView->Invalidate();
  3840. }
  3841. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  3842. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  3843. if (CapableGroupChanging || CapableOwnerChanging)
  3844. {
  3845. if (CapableGroupChanging)
  3846. {
  3847. GroupList = Terminal->Groups->Duplicate();
  3848. }
  3849. if (CapableOwnerChanging)
  3850. {
  3851. UserList = Terminal->Users->Duplicate();
  3852. }
  3853. TRemoteDirectory * Files = Terminal->Files;
  3854. int Count = Files->Count;
  3855. if (Count > 100)
  3856. {
  3857. Count = 100;
  3858. }
  3859. for (int Index = 0; Index < Count; Index++)
  3860. {
  3861. TRemoteFile * File = Files->Files[Index];
  3862. if (CapableGroupChanging)
  3863. {
  3864. GroupList->AddUnique(File->Group);
  3865. }
  3866. if (CapableOwnerChanging)
  3867. {
  3868. UserList->AddUnique(File->Owner);
  3869. }
  3870. }
  3871. // if we haven't collected tokens for all files in current directory,
  3872. // make sure we collect them at least for all selected files.
  3873. // (note that so far the files in FileList has to be from current direcotry)
  3874. if (Count < Files->Count)
  3875. {
  3876. for (int Index = 0; Index < FileList->Count; Index++)
  3877. {
  3878. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  3879. if (CapableGroupChanging)
  3880. {
  3881. GroupList->AddUnique(File->Group);
  3882. }
  3883. if (CapableOwnerChanging)
  3884. {
  3885. UserList->AddUnique(File->Owner);
  3886. }
  3887. }
  3888. }
  3889. }
  3890. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  3891. int Flags = 0;
  3892. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  3893. if (CapableOwnerChanging) Flags |= cpOwner;
  3894. if (CapableGroupChanging) Flags |= cpGroup;
  3895. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  3896. if (Terminal->IsCapable[fcCalculatingChecksum])
  3897. {
  3898. CalculateChecksumEvent = CalculateChecksum;
  3899. }
  3900. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  3901. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  3902. TRemoteProperties NewProperties = CurrentProperties;
  3903. Result =
  3904. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  3905. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  3906. Terminal->IsCapable[fcGroupOwnerChangingByID],
  3907. CalculateSize, CalculateChecksumEvent);
  3908. if (Result)
  3909. {
  3910. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  3911. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  3912. }
  3913. }
  3914. __finally
  3915. {
  3916. delete GroupList;
  3917. delete UserList;
  3918. }
  3919. }
  3920. else
  3921. {
  3922. DirView(Side)->DisplayPropertiesMenu();
  3923. Result = true;
  3924. }
  3925. return Result;
  3926. }
  3927. //---------------------------------------------------------------------------
  3928. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  3929. {
  3930. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  3931. {
  3932. FIgnoreNextDialogChar = Key;
  3933. }
  3934. Key = 0;
  3935. }
  3936. //---------------------------------------------------------------------------
  3937. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  3938. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  3939. {
  3940. const TCustomCommandType * Command = List->Find(KeyShortCut);
  3941. if (Command != NULL)
  3942. {
  3943. KeyProcessed(Key, Shift);
  3944. if (CustomCommandState(*Command, false, ccltAll) > 0)
  3945. {
  3946. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  3947. false, false, const_cast<TCustomCommandType *>(Command));
  3948. }
  3949. }
  3950. }
  3951. //---------------------------------------------------------------------------
  3952. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  3953. {
  3954. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  3955. {
  3956. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  3957. }
  3958. if (!DirView(osCurrent)->IsEditing())
  3959. {
  3960. TShortCut KeyShortCut = ShortCut(Key, Shift);
  3961. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  3962. {
  3963. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  3964. if (((Action->ShortCut == KeyShortCut) ||
  3965. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  3966. AllowedAction(Action, aaShortCut))
  3967. {
  3968. // Has to be called before the action as the dialog char is already in queue.
  3969. // So when the action consumes message queue, we already need to have the
  3970. // FIgnoreNextDialogChar set
  3971. KeyProcessed(Key, Shift);
  3972. // Reset reference to previous component (when menu/toolbar was clicked).
  3973. // Needed to detect that action was invoked by keyboard shortcut
  3974. // in TNonVisualDataModule::ExplorerActionsExecute
  3975. Action->ActionComponent = NULL;
  3976. Action->Execute();
  3977. return;
  3978. }
  3979. }
  3980. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  3981. {
  3982. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  3983. {
  3984. KeyProcessed(Key, Shift);
  3985. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  3986. return;
  3987. }
  3988. }
  3989. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  3990. {
  3991. KeyProcessed(Key, Shift);
  3992. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  3993. }
  3994. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  3995. if (IsCustomShortCut(CustomShortCut))
  3996. {
  3997. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  3998. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  3999. if (WinConfiguration->SharedBookmarks != NULL)
  4000. {
  4001. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4002. if ((Bookmark != NULL) &&
  4003. OpenBookmark(Bookmark->Local, Bookmark->Remote))
  4004. {
  4005. KeyProcessed(Key, Shift);
  4006. }
  4007. }
  4008. }
  4009. }
  4010. TForm::KeyDown(Key, Shift);
  4011. }
  4012. //---------------------------------------------------------------------------
  4013. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4014. {
  4015. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4016. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4017. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4018. DebugAssert(Terminal);
  4019. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4020. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4021. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4022. // expanded from ?: to avoid memory leaks
  4023. if (SecurityEnabled)
  4024. {
  4025. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4026. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4027. }
  4028. else
  4029. {
  4030. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4031. }
  4032. if (FileSystemInfo.ProtocolName.IsEmpty())
  4033. {
  4034. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4035. }
  4036. else
  4037. {
  4038. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4039. }
  4040. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4041. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4042. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4043. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4044. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4045. UnicodeString CompressionStr = CSCompressionStr;
  4046. if (CSCompressionStr != SCCompressionStr)
  4047. {
  4048. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4049. }
  4050. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4051. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4052. UpdateStatusBar();
  4053. }
  4054. //---------------------------------------------------------------------------
  4055. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4056. {
  4057. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4058. DebugAssert(SessionStatusBar != NULL);
  4059. if (!Terminal || !Terminal->Active || Terminal->Status < ssOpened)
  4060. {
  4061. // note: (Terminal->Status < sshReady) currently never happens here,
  4062. // so STATUS_CONNECTING is never used
  4063. SessionStatusBar->SimplePanel = true;
  4064. SessionStatusBar->SimpleText = LoadStr(
  4065. !Terminal || !Terminal->Active ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4066. }
  4067. else
  4068. {
  4069. DebugAssert(Terminal);
  4070. SessionStatusBar->SimplePanel = false;
  4071. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4072. if (!FNote.IsEmpty())
  4073. {
  4074. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4075. }
  4076. else
  4077. {
  4078. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4079. }
  4080. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4081. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4082. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4083. }
  4084. }
  4085. //---------------------------------------------------------------------------
  4086. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4087. {
  4088. Panel->Caption = L"";
  4089. }
  4090. //---------------------------------------------------------------------------
  4091. void __fastcall TCustomScpExplorerForm::Idle()
  4092. {
  4093. if (FShowing || FStandaloneEditing)
  4094. {
  4095. FEditorManager->Check();
  4096. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4097. // that needs to know if queue view is visible (and it may be closed after queue update)
  4098. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal);
  4099. }
  4100. if (FShowing)
  4101. {
  4102. if (!NonVisualDataModule->Busy &&
  4103. // Menu is opened or drag&drop is going on
  4104. (Mouse->Capture == NULL))
  4105. {
  4106. if (FRefreshRemoteDirectory)
  4107. {
  4108. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4109. {
  4110. Terminal->RefreshDirectory();
  4111. }
  4112. FRefreshRemoteDirectory = false;
  4113. }
  4114. if (FRefreshLocalDirectory)
  4115. {
  4116. ReloadLocalDirectory();
  4117. FRefreshLocalDirectory = false;
  4118. }
  4119. if (WinConfiguration->RefreshRemotePanel)
  4120. {
  4121. TManagedTerminal * ManagedTerminal =
  4122. dynamic_cast<TManagedTerminal *>(Terminal);
  4123. if ((ManagedTerminal != NULL) && (Terminal->Status == ssOpened) &&
  4124. (Now() - ManagedTerminal->DirectoryLoaded >
  4125. WinConfiguration->RefreshRemotePanelInterval))
  4126. {
  4127. RemoteDirView->ReloadDirectory();
  4128. }
  4129. }
  4130. }
  4131. }
  4132. if (FShowing || FStandaloneEditing)
  4133. {
  4134. if (FQueueStatusInvalidated)
  4135. {
  4136. UpdateQueueStatus(false);
  4137. }
  4138. RefreshQueueItems();
  4139. }
  4140. if (FShowing)
  4141. {
  4142. UpdateStatusBar();
  4143. }
  4144. FIgnoreNextDialogChar = 0;
  4145. }
  4146. //---------------------------------------------------------------------------
  4147. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4148. {
  4149. try
  4150. {
  4151. FUserActionTimer->Enabled = false;
  4152. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4153. {
  4154. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4155. {
  4156. FPendingQueueActionItem->ProcessUserAction();
  4157. }
  4158. }
  4159. }
  4160. __finally
  4161. {
  4162. FPendingQueueActionItem = NULL;
  4163. }
  4164. }
  4165. //---------------------------------------------------------------------------
  4166. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4167. {
  4168. if (WinConfiguration->MinimizeToTray)
  4169. {
  4170. UpdateTrayIcon();
  4171. FTrayIcon->Visible = true;
  4172. if (Visible)
  4173. {
  4174. ShowWindow(Handle, SW_HIDE);
  4175. }
  4176. }
  4177. }
  4178. //---------------------------------------------------------------------------
  4179. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4180. {
  4181. // WORKAROUND
  4182. // When restoring maximized window from minimization,
  4183. // rarely some controls do not align properly.
  4184. // Two instances seen (both for Commander):
  4185. // - When restoring, window is temporarily narrower (not maximized),
  4186. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4187. // Once maximized already, top dock shinks back, but the session PageControl,
  4188. // do not align up, leaving space between TopDock and PageControl.
  4189. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4190. for (int Index = 0; Index < ControlCount; Index++)
  4191. {
  4192. RealignControl(Controls[Index]);
  4193. }
  4194. if (FTrayIcon->Visible)
  4195. {
  4196. FTrayIcon->Visible = false;
  4197. if (Visible)
  4198. {
  4199. ShowWindow(Handle, SW_SHOW);
  4200. }
  4201. }
  4202. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4203. {
  4204. FNeedSession = false;
  4205. NonVisualDataModule->StartBusy();
  4206. try
  4207. {
  4208. NeedSession(false);
  4209. }
  4210. __finally
  4211. {
  4212. NonVisualDataModule->EndBusy();
  4213. }
  4214. }
  4215. }
  4216. //---------------------------------------------------------------------------
  4217. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4218. {
  4219. FTrayIcon->Hint = Caption;
  4220. }
  4221. //---------------------------------------------------------------------------
  4222. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4223. {
  4224. UpdateTrayIcon();
  4225. }
  4226. //---------------------------------------------------------------------------
  4227. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4228. {
  4229. // workaround
  4230. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4231. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4232. // But WM_ACTIVATEAPP message can be received even when
  4233. // the main window is minimized to the tray and internal editor window is focused
  4234. // (after another application was previously active)
  4235. if (::IsIconic(Handle))
  4236. {
  4237. if (!IsAppIconic())
  4238. {
  4239. SetAppIconic(true);
  4240. }
  4241. }
  4242. ::ApplicationRestore();
  4243. Application->BringToFront();
  4244. }
  4245. //---------------------------------------------------------------------------
  4246. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4247. {
  4248. RestoreApp();
  4249. }
  4250. //---------------------------------------------------------------------------
  4251. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4252. {
  4253. if (OpenInNewWindow())
  4254. {
  4255. // todo: Pass FromSite
  4256. ExecuteNewInstance(SessionUrl);
  4257. }
  4258. else
  4259. {
  4260. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4261. }
  4262. }
  4263. //---------------------------------------------------------------------------
  4264. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4265. {
  4266. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4267. // current working directories become defaults here, what is not right
  4268. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4269. StoredSessions->NewSession(SessionName, SessionData.get());
  4270. // modified only, explicit
  4271. StoredSessions->Save(false, true);
  4272. // encode session name because of slashes in hierarchical sessions
  4273. return EncodeUrlString(SessionName);
  4274. }
  4275. //---------------------------------------------------------------------------
  4276. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4277. {
  4278. if (OpenInNewWindow())
  4279. {
  4280. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4281. }
  4282. else
  4283. {
  4284. // current working directories become defaults here, what is not right
  4285. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4286. TTerminalManager * Manager = TTerminalManager::Instance();
  4287. TTerminal * Terminal = Manager->NewTerminal(SessionData.get());
  4288. Manager->ActiveTerminal = Terminal;
  4289. }
  4290. }
  4291. //---------------------------------------------------------------------------
  4292. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4293. {
  4294. DebugAssert(FQueue != NULL);
  4295. bool Result = FQueue->IsEmpty;
  4296. if (!Result)
  4297. {
  4298. SetFocus();
  4299. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4300. }
  4301. return Result;
  4302. }
  4303. //---------------------------------------------------------------------------
  4304. void __fastcall TCustomScpExplorerForm::CloseSession()
  4305. {
  4306. if (CanCloseQueue())
  4307. {
  4308. TTerminalManager::Instance()->FreeActiveTerminal();
  4309. }
  4310. }
  4311. //---------------------------------------------------------------------------
  4312. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4313. {
  4314. if (OpenInNewWindow())
  4315. {
  4316. // encode session name because of slashes in hierarchical sessions
  4317. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4318. }
  4319. else
  4320. {
  4321. TTerminalManager * Manager = TTerminalManager::Instance();
  4322. TTerminal * Terminal = Manager->NewTerminal(Data);
  4323. Manager->ActiveTerminal = Terminal;
  4324. }
  4325. }
  4326. //---------------------------------------------------------------------------
  4327. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4328. {
  4329. if (OpenInNewWindow())
  4330. {
  4331. ExecuteNewInstance(Name);
  4332. }
  4333. else
  4334. {
  4335. TTerminalManager * Manager = TTerminalManager::Instance();
  4336. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4337. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4338. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  4339. }
  4340. }
  4341. //---------------------------------------------------------------------------
  4342. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4343. bool &CanClose)
  4344. {
  4345. if (Terminal != NULL)
  4346. {
  4347. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4348. {
  4349. unsigned int Result;
  4350. TMessageParams Params(mpNeverAskAgainCheck);
  4351. UnicodeString Message;
  4352. int Answers = qaOK | qaCancel;
  4353. if (TTerminalManager::Instance()->Count > 1)
  4354. {
  4355. if (!WinConfiguration->AutoSaveWorkspace)
  4356. {
  4357. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE2);
  4358. Answers = qaYes | qaNo | qaCancel;
  4359. }
  4360. else
  4361. {
  4362. Message = MainInstructions(LoadStr(CLOSE_SESSIONS));
  4363. }
  4364. }
  4365. else
  4366. {
  4367. Message = MainInstructions(FMTLOAD(CLOSE_SESSION, (Terminal->SessionData->SessionName)));
  4368. }
  4369. if (WinConfiguration->AutoSaveWorkspace)
  4370. {
  4371. Message =
  4372. FORMAT("%s\n\n%s", (Message,
  4373. FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()))));
  4374. }
  4375. SetFocus();
  4376. Result = MessageDialog(Message, qtConfirmation,
  4377. Answers, HELP_NONE, &Params);
  4378. if (Result == qaNeverAskAgain)
  4379. {
  4380. WinConfiguration->ConfirmClosingSession = false;
  4381. }
  4382. if (Result == qaNo)
  4383. {
  4384. CanClose = SaveWorkspace(true);
  4385. // note that the workspace will be saved redundatly again from FormClose
  4386. }
  4387. else
  4388. {
  4389. CanClose =
  4390. (Result == qaOK) ||
  4391. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4392. (Result == qaNeverAskAgain);
  4393. }
  4394. }
  4395. if (CanClose)
  4396. {
  4397. CanClose = CanCloseQueue();
  4398. }
  4399. }
  4400. if (CanClose)
  4401. {
  4402. CanClose =
  4403. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4404. FEditorManager->CloseExternalFilesWithoutProcess();
  4405. if (CanClose)
  4406. {
  4407. while (CanClose && (FLocalEditors->Count > 0))
  4408. {
  4409. int PrevCount = FLocalEditors->Count;
  4410. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4411. CanClose = (FLocalEditors->Count < PrevCount);
  4412. }
  4413. if (CanClose)
  4414. {
  4415. CanClose = FEditorManager->Empty(true);
  4416. if (!CanClose)
  4417. {
  4418. SetFocus();
  4419. CanClose =
  4420. (MessageDialog(
  4421. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4422. }
  4423. }
  4424. }
  4425. }
  4426. }
  4427. //---------------------------------------------------------------------------
  4428. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4429. {
  4430. TForm * Form = dynamic_cast<TForm *>(Sender);
  4431. DebugAssert(Form != NULL);
  4432. Form->Close();
  4433. }
  4434. //---------------------------------------------------------------------------
  4435. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4436. {
  4437. TForm * Form = dynamic_cast<TForm *>(Sender);
  4438. delete Form;
  4439. }
  4440. //---------------------------------------------------------------------------
  4441. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4442. {
  4443. while (FLocalEditors->Count > 0)
  4444. {
  4445. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4446. }
  4447. }
  4448. //---------------------------------------------------------------------------
  4449. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4450. TObject *Sender)
  4451. {
  4452. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4453. try
  4454. {
  4455. SetProperties(osRemote, FileList);
  4456. }
  4457. __finally
  4458. {
  4459. delete FileList;
  4460. }
  4461. }
  4462. //---------------------------------------------------------------------------
  4463. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4464. {
  4465. if (value)
  4466. {
  4467. if (Component == fcCustomCommandsBand)
  4468. {
  4469. UpdateCustomCommandsToolbar();
  4470. }
  4471. }
  4472. }
  4473. //---------------------------------------------------------------------------
  4474. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4475. {
  4476. TControl * Control = GetComponent(Component);
  4477. DebugAssert(Control);
  4478. bool Changed = (Control->Visible != value);
  4479. if (Changed)
  4480. {
  4481. ComponentShowing(Component, value);
  4482. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4483. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4484. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4485. if (value)
  4486. {
  4487. int RemainingHeight = Control->Parent->ClientHeight;
  4488. int RemainingWidth = Control->Parent->ClientWidth;
  4489. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4490. {
  4491. TControl * ChildControl = Control->Parent->Controls[i];
  4492. if (ChildControl->Visible)
  4493. {
  4494. switch (ChildControl->Align)
  4495. {
  4496. case alTop:
  4497. case alBottom:
  4498. RemainingHeight -= ChildControl->Height;
  4499. break;
  4500. case alLeft:
  4501. case alRight:
  4502. RemainingWidth -= ChildControl->Width;
  4503. break;
  4504. }
  4505. }
  4506. }
  4507. int Reserve = ScaleByTextHeight(this, 32);
  4508. // queue in explorer, trees in commander
  4509. if (Control->Height > RemainingHeight - Reserve)
  4510. {
  4511. Control->Height = RemainingHeight / 2;
  4512. }
  4513. if (Control->Width > RemainingWidth - Reserve)
  4514. {
  4515. Control->Width = RemainingWidth / 2;
  4516. }
  4517. }
  4518. Control->Visible = value;
  4519. if (WasFocused && Visible)
  4520. {
  4521. DirView(osCurrent)->SetFocus();
  4522. }
  4523. FixControlsPlacement();
  4524. }
  4525. }
  4526. //---------------------------------------------------------------------------
  4527. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4528. {
  4529. TControl * Control = GetComponent(Component);
  4530. if (Control == NULL)
  4531. {
  4532. return false;
  4533. }
  4534. else
  4535. {
  4536. return Control->Visible;
  4537. }
  4538. }
  4539. //---------------------------------------------------------------------------
  4540. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4541. {
  4542. if (RemoteDirView->ItemFocused != NULL)
  4543. {
  4544. RemoteDirView->ItemFocused->MakeVisible(false);
  4545. }
  4546. QueueSplitter->Visible = QueuePanel->Visible;
  4547. RemotePanelSplitter->Visible = RemoteDriveView->Visible;
  4548. }
  4549. //---------------------------------------------------------------------------
  4550. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4551. {
  4552. switch (Component) {
  4553. case fcStatusBar: return RemoteStatusBar;
  4554. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4555. case fcQueueView: return QueuePanel;
  4556. case fcQueueToolbar: return QueueDock;
  4557. case fcRemoteTree: return RemoteDriveView;
  4558. case fcSessionsTabs: return SessionsPageControl;
  4559. default: return NULL;
  4560. }
  4561. }
  4562. //---------------------------------------------------------------------------
  4563. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4564. TObject *Sender, TListColumn *Column, TPoint &Point)
  4565. {
  4566. DebugAssert(NonVisualDataModule && Column && Sender);
  4567. NonVisualDataModule->ListColumn = Column;
  4568. TPopupMenu * DirViewColumnMenu;
  4569. if (Sender == RemoteDirView)
  4570. {
  4571. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4572. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4573. (Column->Index == uvName);
  4574. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4575. (Column->Index == uvSize);
  4576. }
  4577. else
  4578. {
  4579. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4580. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4581. (Column->Index == dvName);
  4582. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4583. (Column->Index == dvSize);
  4584. }
  4585. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4586. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4587. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4588. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4589. }
  4590. //---------------------------------------------------------------------------
  4591. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4592. TObject *Sender, TListItem *Item, bool &AllowExec)
  4593. {
  4594. DoDirViewExecFile(Sender, Item, AllowExec);
  4595. }
  4596. //---------------------------------------------------------------------------
  4597. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4598. TListItem * Item, bool & AllowExec)
  4599. {
  4600. DebugAssert(Sender && Item && Configuration);
  4601. DebugAssert(AllowExec);
  4602. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4603. bool Remote = (ADirView == DirView(osRemote));
  4604. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks;
  4605. TOperationSide Side = (Remote ? osRemote : osLocal);
  4606. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4607. // on files only (not directories)
  4608. // and only when symlinks are resolved (apply to remote panel only)
  4609. if (!ADirView->ItemIsDirectory(Item) &&
  4610. (ResolvedSymlinks || FForceExecution))
  4611. {
  4612. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4613. !FForceExecution &&
  4614. ResolvedSymlinks)
  4615. {
  4616. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4617. {
  4618. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4619. UnlockWindow();
  4620. try
  4621. {
  4622. ExecuteFileOperation(
  4623. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4624. }
  4625. __finally
  4626. {
  4627. LockWindow();
  4628. }
  4629. AllowExec = false;
  4630. }
  4631. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4632. {
  4633. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4634. {
  4635. ExecuteFile(Side, efDefaultEditor);
  4636. AllowExec = false;
  4637. }
  4638. }
  4639. else
  4640. {
  4641. DebugFail();
  4642. }
  4643. }
  4644. // if we have not done anything special, fall back to default behavior
  4645. if (AllowExec)
  4646. {
  4647. if (Remote && !WinConfiguration->DisableOpenEdit)
  4648. {
  4649. ExecuteFile(osRemote, efShell);
  4650. AllowExec = false;
  4651. }
  4652. }
  4653. }
  4654. }
  4655. //---------------------------------------------------------------------------
  4656. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4657. {
  4658. return ((Side == osRemote) || (Side == osCurrent));
  4659. }
  4660. //---------------------------------------------------------------------------
  4661. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  4662. {
  4663. DebugFail();
  4664. }
  4665. //---------------------------------------------------------------------------
  4666. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  4667. {
  4668. DebugFail();
  4669. }
  4670. //---------------------------------------------------------------------------
  4671. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  4672. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, bool UseDefaults)
  4673. {
  4674. TSynchronizeParamType Params;
  4675. Params.LocalDirectory = LocalDirectory;
  4676. Params.RemoteDirectory = RemoteDirectory;
  4677. int UnusedParams =
  4678. (GUIConfiguration->SynchronizeParams &
  4679. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize));
  4680. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  4681. Params.Options = GUIConfiguration->SynchronizeOptions;
  4682. bool SaveSettings = false;
  4683. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  4684. &DoSynchronizeTooManyDirectories);
  4685. DebugAssert(FSynchronizeController == NULL);
  4686. FSynchronizeController = &Controller;
  4687. bool Result;
  4688. try
  4689. {
  4690. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4691. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  4692. int Options =
  4693. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  4694. DebugAssert(FOnFeedSynchronizeError == NULL);
  4695. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  4696. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  4697. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  4698. if (Result)
  4699. {
  4700. if (SaveSettings)
  4701. {
  4702. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  4703. GUIConfiguration->SynchronizeOptions = Params.Options;
  4704. }
  4705. else
  4706. {
  4707. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  4708. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  4709. FLAGSET(Params.Options, soSynchronize))
  4710. {
  4711. GUIConfiguration->SynchronizeOptions =
  4712. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  4713. soSynchronize;
  4714. }
  4715. }
  4716. LocalDirectory = Params.LocalDirectory;
  4717. RemoteDirectory = Params.RemoteDirectory;
  4718. }
  4719. }
  4720. __finally
  4721. {
  4722. FSynchronizeController = NULL;
  4723. DebugAssert(FOnFeedSynchronizeError == NULL);
  4724. FOnFeedSynchronizeError = NULL;
  4725. }
  4726. return Result;
  4727. }
  4728. //---------------------------------------------------------------------------
  4729. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  4730. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  4731. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  4732. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  4733. TSynchronizeOptions * Options, bool Full)
  4734. {
  4735. if (Terminal->Status == ssOpened)
  4736. {
  4737. try
  4738. {
  4739. int PParams = Params.Params;
  4740. if (!Full)
  4741. {
  4742. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  4743. if (FLAGSET(Params.Options, soRecurse))
  4744. {
  4745. PParams |= TTerminal::spSubDirs;
  4746. }
  4747. }
  4748. else
  4749. {
  4750. // if keepuptodate is non-recursive,
  4751. // full sync before has to be non-recursive as well
  4752. if (FLAGCLEAR(Params.Options, soRecurse))
  4753. {
  4754. PParams |= TTerminal::spNoRecurse;
  4755. }
  4756. }
  4757. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  4758. PParams, Checklist, Options);
  4759. }
  4760. catch (Exception & E)
  4761. {
  4762. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  4763. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  4764. {
  4765. // noop, already logged in MoreMessageDialog
  4766. }
  4767. else
  4768. {
  4769. ShowExtendedExceptionEx(Terminal, &E);
  4770. throw;
  4771. }
  4772. }
  4773. }
  4774. }
  4775. //---------------------------------------------------------------------------
  4776. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  4777. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  4778. const UnicodeString ErrorStr)
  4779. {
  4780. if (!Directory.IsEmpty())
  4781. {
  4782. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  4783. }
  4784. else
  4785. {
  4786. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  4787. }
  4788. }
  4789. //---------------------------------------------------------------------------
  4790. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  4791. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  4792. {
  4793. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  4794. {
  4795. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  4796. }
  4797. else
  4798. {
  4799. TMessageParams Params(mpNeverAskAgainCheck);
  4800. unsigned int Result = MessageDialog(
  4801. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  4802. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  4803. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  4804. {
  4805. MaxDirectories *= 2;
  4806. if (Result == qaNeverAskAgain)
  4807. {
  4808. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  4809. }
  4810. }
  4811. else
  4812. {
  4813. Abort();
  4814. }
  4815. }
  4816. }
  4817. //---------------------------------------------------------------------------
  4818. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  4819. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  4820. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  4821. TSynchronizeOptions * Options)
  4822. {
  4823. DebugAssert(!FAutoOperation);
  4824. void * BatchStorage;
  4825. BatchStart(BatchStorage);
  4826. FAutoOperation = true;
  4827. bool AnyOperation = false;
  4828. TDateTime StartTime = Now();
  4829. TSynchronizeChecklist * AChecklist = NULL;
  4830. try
  4831. {
  4832. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  4833. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  4834. {
  4835. FSynchronizeProgressForm->Start();
  4836. }
  4837. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  4838. static_cast<TTerminal::TSynchronizeMode>(Mode),
  4839. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  4840. Options);
  4841. SAFE_DESTROY(FSynchronizeProgressForm);
  4842. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, false);
  4843. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  4844. {
  4845. FSynchronizeProgressForm->Start();
  4846. }
  4847. for (int Index = 0; !AnyOperation && (Index < AChecklist->Count); Index++)
  4848. {
  4849. AnyOperation = AChecklist->Item[Index]->Checked;
  4850. }
  4851. // No need to call if !AnyOperation
  4852. Terminal->SynchronizeApply(AChecklist, LocalDirectory, RemoteDirectory,
  4853. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory);
  4854. }
  4855. __finally
  4856. {
  4857. if (Checklist == NULL)
  4858. {
  4859. delete AChecklist;
  4860. }
  4861. else
  4862. {
  4863. *Checklist = AChecklist;
  4864. }
  4865. FAutoOperation = false;
  4866. SAFE_DESTROY(FSynchronizeProgressForm);
  4867. BatchEnd(BatchStorage);
  4868. ReloadLocalDirectory();
  4869. if (AnyOperation)
  4870. {
  4871. OperationComplete(StartTime);
  4872. }
  4873. }
  4874. }
  4875. //---------------------------------------------------------------------------
  4876. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  4877. {
  4878. // can be called from command line
  4879. return Visible &&
  4880. ((DirView(osRemote)->SelCount > 0) ||
  4881. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  4882. }
  4883. //---------------------------------------------------------------------------
  4884. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  4885. {
  4886. LogSynchronizeEvent(Terminal, Message);
  4887. }
  4888. //---------------------------------------------------------------------------
  4889. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  4890. int Params, TSynchronizeOptions & Options)
  4891. {
  4892. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  4893. {
  4894. Options.Filter = new TStringList();
  4895. Options.Filter->CaseSensitive = false;
  4896. Options.Filter->Duplicates = Types::dupAccept;
  4897. if (DirView(osRemote)->SelCount > 0)
  4898. {
  4899. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  4900. }
  4901. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  4902. {
  4903. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  4904. }
  4905. Options.Filter->Sort();
  4906. }
  4907. }
  4908. //---------------------------------------------------------------------------
  4909. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  4910. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  4911. {
  4912. UnicodeString SessionName = CreateHiddenDuplicateSession();
  4913. UnicodeString AdditionalParams =
  4914. FORMAT(L"%s \"%s\" \"%s\" %d %d %s", (
  4915. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  4916. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options,
  4917. TProgramParams::FormatSwitch(DEFAULTS_SWITCH)));
  4918. TCopyParamType Defaults;
  4919. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  4920. ConfigStorage->AccessMode = smRead;
  4921. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false, false))
  4922. {
  4923. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  4924. }
  4925. ConfigStorage.reset(NULL);
  4926. std::unique_ptr<TStringList> Options(new TStringList());
  4927. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  4928. GUIConfiguration->SaveCopyParam(OptionsStorage.get(), CopyParams, &Defaults);
  4929. if (Options->Count > 0)
  4930. {
  4931. AdditionalParams +=
  4932. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAW_CONFIG_SWITCH), StringsToParams(Options.get())));
  4933. }
  4934. ExecuteNewInstance(SessionName, AdditionalParams);
  4935. }
  4936. //---------------------------------------------------------------------------
  4937. bool __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  4938. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  4939. TSynchronizeMode & Mode, bool & SaveMode, bool UseDefaults)
  4940. {
  4941. bool Result;
  4942. int Params = GUIConfiguration->SynchronizeParams;
  4943. bool SaveSettings = false;
  4944. int Options =
  4945. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  4946. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  4947. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4948. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  4949. Result = UseDefaults ||
  4950. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  4951. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs);
  4952. if (Result)
  4953. {
  4954. Configuration->Usage->Inc(L"Synchronizations");
  4955. UpdateCopyParamCounters(CopyParam);
  4956. TSynchronizeOptions SynchronizeOptions;
  4957. GetSynchronizeOptions(Params, SynchronizeOptions);
  4958. if (SaveSettings)
  4959. {
  4960. GUIConfiguration->SynchronizeParams = Params;
  4961. }
  4962. else
  4963. {
  4964. SaveMode = false;
  4965. }
  4966. TDateTime StartTime = Now();
  4967. TSynchronizeChecklist * Checklist = NULL;
  4968. try
  4969. {
  4970. DebugAssert(!FAutoOperation);
  4971. FAutoOperation = true;
  4972. try
  4973. {
  4974. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  4975. FSynchronizeProgressForm->Start();
  4976. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  4977. static_cast<TTerminal::TSynchronizeMode>(Mode),
  4978. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  4979. &SynchronizeOptions);
  4980. }
  4981. __finally
  4982. {
  4983. FAutoOperation = false;
  4984. SAFE_DESTROY(FSynchronizeProgressForm);
  4985. }
  4986. if (Checklist->Count == 0)
  4987. {
  4988. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  4989. MessageDialog(Message, qtInformation, qaOK,
  4990. HELP_SYNCHRONIZE_NO_DIFFERENCES);
  4991. }
  4992. else if (FLAGCLEAR(Params, TTerminal::spPreviewChanges) ||
  4993. DoSynchronizeChecklistDialog(Checklist, Mode, Params,
  4994. LocalDirectory, RemoteDirectory, CustomCommandMenu))
  4995. {
  4996. DebugAssert(!FAutoOperation);
  4997. void * BatchStorage;
  4998. BatchStart(BatchStorage);
  4999. FAutoOperation = true;
  5000. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5001. {
  5002. StartTime = Now();
  5003. }
  5004. try
  5005. {
  5006. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, false);
  5007. FSynchronizeProgressForm->Start();
  5008. Terminal->SynchronizeApply(Checklist, LocalDirectory, RemoteDirectory,
  5009. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory);
  5010. }
  5011. __finally
  5012. {
  5013. FAutoOperation = false;
  5014. SAFE_DESTROY(FSynchronizeProgressForm);
  5015. BatchEnd(BatchStorage);
  5016. ReloadLocalDirectory();
  5017. }
  5018. }
  5019. }
  5020. __finally
  5021. {
  5022. delete Checklist;
  5023. }
  5024. OperationComplete(StartTime);
  5025. }
  5026. return Result;
  5027. }
  5028. //---------------------------------------------------------------------------
  5029. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5030. const UnicodeString LocalDirectory, const UnicodeString RemoteDirectory,
  5031. bool & Continue, bool /*Collect*/)
  5032. {
  5033. DebugAssert(FSynchronizeProgressForm != NULL);
  5034. if (!FSynchronizeProgressForm->Started)
  5035. {
  5036. FSynchronizeProgressForm->Start();
  5037. }
  5038. FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Continue);
  5039. }
  5040. //---------------------------------------------------------------------------
  5041. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5042. {
  5043. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5044. TRemoteFile * File = NULL;
  5045. Terminal->ReadFile(FullFileName, File);
  5046. if (File != NULL)
  5047. {
  5048. std::unique_ptr<TRemoteFile> FileOwner(File);
  5049. TAutoFlag Flag(FStandaloneEditing);
  5050. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5051. Application->ShowMainForm = false;
  5052. Application->Run();
  5053. }
  5054. }
  5055. //---------------------------------------------------------------------------
  5056. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5057. {
  5058. DebugFail();
  5059. }
  5060. //---------------------------------------------------------------------------
  5061. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5062. {
  5063. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5064. SessionData->Assign(Terminal->SessionData);
  5065. UpdateSessionData(SessionData.get());
  5066. TTerminalManager::Instance()->UpdateSessionCredentials(SessionData.get());
  5067. if (Terminal->SessionData->IsWorkspace)
  5068. {
  5069. // Have to reset the "Workspace/XXX" name which would become user-visible
  5070. // once IsWorkspace is cleared
  5071. SessionData->Name = UnicodeString();
  5072. SessionData->IsWorkspace = false;
  5073. }
  5074. return SessionData.release();
  5075. }
  5076. //---------------------------------------------------------------------------
  5077. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5078. {
  5079. TSessionData * SessionData = CloneCurrentSessionData();
  5080. try
  5081. {
  5082. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5083. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5084. }
  5085. __finally
  5086. {
  5087. delete SessionData;
  5088. }
  5089. }
  5090. //---------------------------------------------------------------------------
  5091. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5092. {
  5093. TTerminalManager * Manager = TTerminalManager::Instance();
  5094. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5095. if (DebugAlwaysTrue(Terminal != NULL))
  5096. {
  5097. // Update (Managed)Terminal->StateData
  5098. UpdateTerminal(Terminal);
  5099. }
  5100. Manager->SaveWorkspace(DataList.get());
  5101. return DataList.release();
  5102. }
  5103. //---------------------------------------------------------------------------
  5104. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5105. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords)
  5106. {
  5107. WinConfiguration->LastWorkspace = Name;
  5108. if (!SavePasswords)
  5109. {
  5110. for (int Index = 0; Index < DataList->Count; Index++)
  5111. {
  5112. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5113. if (SessionData->Link.IsEmpty())
  5114. {
  5115. SessionData->ClearSessionPasswords();
  5116. }
  5117. }
  5118. }
  5119. StoredSessions->NewWorkspace(Name, DataList);
  5120. // modified only, explicit
  5121. StoredSessions->Save(false, true);
  5122. }
  5123. //---------------------------------------------------------------------------
  5124. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5125. {
  5126. return
  5127. DefaultStr(WinConfiguration->LastWorkspace,
  5128. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5129. }
  5130. //---------------------------------------------------------------------------
  5131. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5132. {
  5133. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5134. bool AnyNonStoredSessionWithPassword = false;
  5135. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5136. bool AllNonStoredSessionsAnonymous = true;
  5137. TTerminalManager * Manager = TTerminalManager::Instance();
  5138. for (int Index = 0; Index < DataList->Count; Index++)
  5139. {
  5140. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5141. if (SessionData->Link.IsEmpty())
  5142. {
  5143. if (SessionData->HasAnySessionPassword())
  5144. {
  5145. AnyNonStoredSessionWithPassword = true;
  5146. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5147. {
  5148. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5149. }
  5150. }
  5151. if (!SameText(SessionData->UserName, AnonymousUserName))
  5152. {
  5153. AllNonStoredSessionsAnonymous = false;
  5154. }
  5155. }
  5156. }
  5157. bool SavePasswords;
  5158. bool * PSavePasswords;
  5159. bool NotRecommendedSavingPasswords =
  5160. !CustomWinConfiguration->UseMasterPassword &&
  5161. !AllNonStoredSessionsAnonymous;
  5162. if (Configuration->DisablePasswordStoring ||
  5163. !AnyNonStoredSessionWithPassword)
  5164. {
  5165. PSavePasswords = NULL;
  5166. SavePasswords = false;
  5167. }
  5168. else
  5169. {
  5170. PSavePasswords = &SavePasswords;
  5171. SavePasswords =
  5172. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5173. !NotRecommendedSavingPasswords;
  5174. }
  5175. UnicodeString Name = WorkspaceName();
  5176. bool CreateShortcut = false;
  5177. bool Result =
  5178. DoSaveWorkspaceDialog(
  5179. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5180. EnableAutoSave);
  5181. if (Result)
  5182. {
  5183. DoSaveWorkspace(Name, DataList.get(), SavePasswords);
  5184. if (CreateShortcut)
  5185. {
  5186. TOperationVisualizer Visualizer;
  5187. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5188. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5189. }
  5190. if (EnableAutoSave)
  5191. {
  5192. WinConfiguration->AutoSaveWorkspace = true;
  5193. WinConfiguration->AutoWorkspace = Name;
  5194. if (PSavePasswords != NULL)
  5195. {
  5196. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5197. }
  5198. }
  5199. }
  5200. return Result;
  5201. }
  5202. //---------------------------------------------------------------------------
  5203. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TTerminal * Terminal)
  5204. {
  5205. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  5206. DebugAssert(ManagedTerminal != NULL);
  5207. SAFE_DESTROY(ManagedTerminal->RemoteExplorerState);
  5208. if (WinConfiguration->PreservePanelState)
  5209. {
  5210. ManagedTerminal->RemoteExplorerState = RemoteDirView->SaveState();
  5211. }
  5212. UpdateSessionData(ManagedTerminal->StateData);
  5213. }
  5214. //---------------------------------------------------------------------------
  5215. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5216. {
  5217. // Keep in sync with TSessionData::CopyStateData
  5218. DebugAssert(Data != NULL);
  5219. // cannot use RemoteDirView->Path, because it is empty if connection
  5220. // was already closed
  5221. // also only peek, we may not be connected at all atm
  5222. // so make sure we do not try retrieving current directory from the server
  5223. // (particularly with FTP)
  5224. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5225. if (!ACurrentDirectory.IsEmpty())
  5226. {
  5227. Data->RemoteDirectory = ACurrentDirectory;
  5228. }
  5229. Data->Color = SessionColor;
  5230. }
  5231. //---------------------------------------------------------------------------
  5232. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5233. {
  5234. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5235. DebugAssert(Toolbar != NULL);
  5236. for (int i = 0; i < Toolbar->Items->Count; i++)
  5237. {
  5238. TTBXCustomDropDownItem * DropDownItem;
  5239. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5240. if (DropDownItem != NULL)
  5241. {
  5242. ToolbarItemResize(DropDownItem,
  5243. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5244. Toolbar->NonClientWidth);
  5245. break;
  5246. }
  5247. }
  5248. }
  5249. //---------------------------------------------------------------------------
  5250. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5251. {
  5252. Item->EditWidth = Width;
  5253. }
  5254. //---------------------------------------------------------------------------
  5255. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5256. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5257. {
  5258. for (int i = 0; i < Toolbar->Items->Count; i++)
  5259. {
  5260. TTBXCustomDropDownItem * DropDownItem;
  5261. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5262. if (DropDownItem != NULL)
  5263. {
  5264. ASize.x -= DropDownItem->EditWidth;
  5265. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5266. }
  5267. }
  5268. }
  5269. //---------------------------------------------------------------------------
  5270. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5271. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5272. {
  5273. if (WinConfiguration->DDWarnLackOfTempSpace)
  5274. {
  5275. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5276. if (!ADrive.IsEmpty())
  5277. {
  5278. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5279. DebugAssert(RequiredSpace >= 0);
  5280. __int64 RequiredWithReserve;
  5281. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5282. if (FreeSpace < RequiredWithReserve)
  5283. {
  5284. unsigned int Result;
  5285. TMessageParams Params(mpNeverAskAgainCheck);
  5286. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5287. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5288. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5289. if (Result == qaNeverAskAgain)
  5290. {
  5291. WinConfiguration->DDWarnLackOfTempSpace = false;
  5292. }
  5293. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5294. }
  5295. }
  5296. }
  5297. }
  5298. //---------------------------------------------------------------------------
  5299. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5300. {
  5301. DoOpenDirectoryDialog(odAddBookmark, Side);
  5302. }
  5303. //---------------------------------------------------------------------------
  5304. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5305. {
  5306. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5307. TStringList * VisitedDirectories = CreateSortedStringList((Side == osRemote));
  5308. try
  5309. {
  5310. TCustomDirView * DView = DirView(Side);
  5311. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5312. {
  5313. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5314. }
  5315. }
  5316. catch (...)
  5317. {
  5318. delete VisitedDirectories;
  5319. throw;
  5320. }
  5321. return VisitedDirectories;
  5322. }
  5323. //---------------------------------------------------------------------------
  5324. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5325. TOpenDirectoryMode Mode, TOperationSide Side)
  5326. {
  5327. bool Continue = true;
  5328. if (Mode == odAddBookmark)
  5329. {
  5330. TMessageParams Params(mpNeverAskAgainCheck);
  5331. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5332. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5333. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5334. unsigned int Answer =
  5335. MessageDialog(Message,
  5336. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5337. if (Answer == qaNeverAskAgain)
  5338. {
  5339. Continue = true;
  5340. WinConfiguration->UseSharedBookmarks = true;
  5341. }
  5342. else if (Answer == qaOK)
  5343. {
  5344. Continue = true;
  5345. WinConfiguration->UseSharedBookmarks = false;
  5346. }
  5347. else
  5348. {
  5349. Continue = false;
  5350. }
  5351. }
  5352. if (Continue)
  5353. {
  5354. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5355. try
  5356. {
  5357. UnicodeString Name = DirView(Side)->PathName;
  5358. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5359. // do not allow switching to location profiles,
  5360. // if we are not connected
  5361. HasDirView[osLocal] && (Terminal != NULL)))
  5362. {
  5363. TWindowLock Lock(this);
  5364. DirView(Side)->Path = Name;
  5365. }
  5366. }
  5367. __finally
  5368. {
  5369. delete VisitedDirectories;
  5370. }
  5371. }
  5372. }
  5373. //---------------------------------------------------------------------------
  5374. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5375. {
  5376. DebugAssert(!FTerminal->CommandSessionOpened);
  5377. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5378. }
  5379. //---------------------------------------------------------------------------
  5380. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5381. {
  5382. bool Result = FTerminal->IsCapable[Capability] ||
  5383. FTerminal->CommandSessionOpened;
  5384. if (!Result)
  5385. {
  5386. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5387. if (!GUIConfiguration->ConfirmCommandSession)
  5388. {
  5389. Result = true;
  5390. }
  5391. else
  5392. {
  5393. TMessageParams Params(mpNeverAskAgainCheck);
  5394. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5395. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5396. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5397. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5398. if (Answer == qaNeverAskAgain)
  5399. {
  5400. GUIConfiguration->ConfirmCommandSession = false;
  5401. Result = true;
  5402. }
  5403. else if (Answer == qaOK)
  5404. {
  5405. Result = true;
  5406. }
  5407. }
  5408. if (Result)
  5409. {
  5410. Result = CommandSessionFallback();
  5411. }
  5412. }
  5413. return Result;
  5414. }
  5415. //---------------------------------------------------------------------------
  5416. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  5417. {
  5418. if (EnsureCommandSessionFallback(fcAnyCommand))
  5419. {
  5420. DoConsoleDialog(Terminal, Command);
  5421. }
  5422. }
  5423. //---------------------------------------------------------------------------
  5424. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  5425. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  5426. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  5427. {
  5428. if (IsFileControl(DropSourceControl, osRemote) &&
  5429. (FDDExtMapFile != NULL))
  5430. {
  5431. Accept = true;
  5432. }
  5433. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  5434. DebugAssert(FDDTargetControl != NULL);
  5435. }
  5436. //---------------------------------------------------------------------------
  5437. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  5438. _di_IDataObject DataObj, int KeyState,
  5439. const TPoint & Point, int & Effect, bool & Accept)
  5440. {
  5441. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  5442. }
  5443. //---------------------------------------------------------------------------
  5444. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  5445. _di_IDataObject DataObj, int KeyState,
  5446. const TPoint & Point, int & Effect, bool & Accept)
  5447. {
  5448. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  5449. }
  5450. //---------------------------------------------------------------------------
  5451. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  5452. TObject * Sender)
  5453. {
  5454. DebugUsedParam(Sender);
  5455. DebugAssert(FDDTargetControl == Sender);
  5456. FDDTargetControl = NULL;
  5457. }
  5458. //---------------------------------------------------------------------------
  5459. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  5460. {
  5461. FileControlDDDragLeave(SessionsPageControl);
  5462. }
  5463. //---------------------------------------------------------------------------
  5464. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  5465. {
  5466. FileControlDDDragLeave(QueueView3);
  5467. }
  5468. //---------------------------------------------------------------------------
  5469. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  5470. {
  5471. DebugAssert(GetSide(Side) == osRemote);
  5472. DebugUsedParam(Side);
  5473. bool Edit = false;
  5474. TRemoteFile * File = NULL;
  5475. UnicodeString FileName;
  5476. UnicodeString PointTo;
  5477. bool SymbolicLink = true;
  5478. if (RemoteDirView->ItemFocused)
  5479. {
  5480. DebugAssert(RemoteDirView->ItemFocused->Data);
  5481. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  5482. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  5483. if (Edit)
  5484. {
  5485. FileName = File->FileName;
  5486. PointTo = File->LinkTo;
  5487. }
  5488. else
  5489. {
  5490. PointTo = File->FileName;
  5491. }
  5492. }
  5493. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  5494. Terminal->IsCapable[fcHardLink]))
  5495. {
  5496. Configuration->Usage->Inc(L"RemoteLinksCreated");
  5497. if (Edit)
  5498. {
  5499. DebugAssert(File->FileName == FileName);
  5500. int Params = dfNoRecursive;
  5501. Terminal->ExceptionOnFail = true;
  5502. try
  5503. {
  5504. Terminal->DeleteFile(L"", File, &Params);
  5505. }
  5506. __finally
  5507. {
  5508. Terminal->ExceptionOnFail = false;
  5509. }
  5510. }
  5511. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  5512. }
  5513. }
  5514. //---------------------------------------------------------------------------
  5515. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  5516. {
  5517. return
  5518. (Terminal != NULL) &&
  5519. ((GetSide(Side) != osRemote) ||
  5520. (Terminal->ResolvingSymlinks &&
  5521. Terminal->IsCapable[fcSymbolicLink]));
  5522. }
  5523. //---------------------------------------------------------------------------
  5524. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  5525. {
  5526. return
  5527. (FCurrentSide == osRemote) &&
  5528. (RemoteDirView->ItemFocused != NULL) &&
  5529. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  5530. Terminal->SessionData->ResolveSymlinks;
  5531. }
  5532. //---------------------------------------------------------------------------
  5533. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  5534. {
  5535. DebugAssert(!WinConfiguration->DisableOpenEdit);
  5536. FForceExecution = true;
  5537. try
  5538. {
  5539. DirView(osCurrent)->ExecuteCurrentFile();
  5540. }
  5541. __finally
  5542. {
  5543. FForceExecution = false;
  5544. }
  5545. }
  5546. //---------------------------------------------------------------------------
  5547. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  5548. {
  5549. TEditorData ExternalEditor;
  5550. ExternalEditor.Editor = edExternal;
  5551. bool Remember = false;
  5552. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc,
  5553. (GetSide(osCurrent) == osRemote)))
  5554. {
  5555. if (Remember)
  5556. {
  5557. TEditorList * EditorList = new TEditorList;
  5558. try
  5559. {
  5560. *EditorList = *WinConfiguration->EditorList;
  5561. bool Found = false;
  5562. int i = 0;
  5563. while (!Found && (i < EditorList->Count))
  5564. {
  5565. const TEditorPreferences * Editor = EditorList->Editors[i];
  5566. if ((Editor->Data->Editor == edExternal) &&
  5567. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  5568. {
  5569. Found = true;
  5570. }
  5571. i++;
  5572. }
  5573. if (!Found)
  5574. {
  5575. EditorList->Add(new TEditorPreferences(ExternalEditor));
  5576. WinConfiguration->EditorList = EditorList;
  5577. }
  5578. }
  5579. __finally
  5580. {
  5581. delete EditorList;
  5582. }
  5583. }
  5584. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  5585. }
  5586. }
  5587. //---------------------------------------------------------------------------
  5588. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  5589. {
  5590. FEditorManager->ProcessFiles(FileTerminalRemoved, Sender);
  5591. if (FFileFindTerminal == Sender)
  5592. {
  5593. FFileFindTerminal = NULL;
  5594. HideFileFindDialog();
  5595. }
  5596. }
  5597. //---------------------------------------------------------------------------
  5598. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  5599. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  5600. {
  5601. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  5602. DebugAssert(Terminal != NULL);
  5603. if (Data->Terminal == Terminal)
  5604. {
  5605. Data->Terminal = NULL;
  5606. }
  5607. }
  5608. //---------------------------------------------------------------------------
  5609. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  5610. {
  5611. UpdateControls();
  5612. SessionColor = TColor(0);
  5613. UpdateRemotePathComboBox(false);
  5614. NeedSession(true);
  5615. }
  5616. //---------------------------------------------------------------------------
  5617. void __fastcall TCustomScpExplorerForm::NeedSession(bool ReloadSessions)
  5618. {
  5619. try
  5620. {
  5621. try
  5622. {
  5623. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  5624. }
  5625. __finally
  5626. {
  5627. if (!WinConfiguration->KeepOpenWhenNoSession &&
  5628. (!Terminal || !Terminal->Active))
  5629. {
  5630. TerminateApplication();
  5631. }
  5632. }
  5633. }
  5634. catch (EAbort &)
  5635. {
  5636. // swallow
  5637. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  5638. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  5639. }
  5640. }
  5641. //---------------------------------------------------------------------------
  5642. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged(bool Force)
  5643. {
  5644. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  5645. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  5646. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  5647. bool ListChanged = Force || (TerminalList->Count + 1 != SessionsPageControl->PageCount);
  5648. if (!ListChanged)
  5649. {
  5650. int Index = 0;
  5651. while (!ListChanged && (Index < TerminalList->Count))
  5652. {
  5653. ListChanged =
  5654. (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != TerminalList->Objects[Index]) ||
  5655. (SessionsPageControl->Pages[Index]->Caption != TerminalList->Strings[Index]);
  5656. Index++;
  5657. }
  5658. }
  5659. if (ListChanged)
  5660. {
  5661. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  5662. try
  5663. {
  5664. FSessionColors->Clear();
  5665. AddFixedSessionImages();
  5666. while (SessionsPageControl->PageCount > 0)
  5667. {
  5668. delete SessionsPageControl->Pages[0];
  5669. }
  5670. for (int Index = 0; Index < TerminalList->Count; Index++)
  5671. {
  5672. TThemeTabSheet * TabSheet = new TThemeTabSheet(SessionsPageControl);
  5673. TabSheet->Caption = TerminalList->Strings[Index];
  5674. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  5675. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  5676. TabSheet->PageControl = SessionsPageControl;
  5677. UpdateSessionTab(TabSheet);
  5678. }
  5679. TTabSheet * TabSheet = new TTabSheet(SessionsPageControl);
  5680. TabSheet->PageControl = SessionsPageControl;
  5681. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  5682. UpdateNewSessionTab();
  5683. }
  5684. __finally
  5685. {
  5686. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  5687. }
  5688. }
  5689. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  5690. }
  5691. //---------------------------------------------------------------------------
  5692. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  5693. {
  5694. DoTerminalListChanged(false);
  5695. }
  5696. //---------------------------------------------------------------------------
  5697. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  5698. {
  5699. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  5700. DebugAssert(TabSheet->ImageIndex == 0);
  5701. TabSheet->Caption =
  5702. WinConfiguration->SelectiveToolbarText ?
  5703. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  5704. UnicodeString();
  5705. }
  5706. //---------------------------------------------------------------------------
  5707. TTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  5708. {
  5709. return reinterpret_cast<TTerminal *>(TabSheet->Tag);
  5710. }
  5711. //---------------------------------------------------------------------------
  5712. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  5713. {
  5714. if (DebugAlwaysTrue(TabSheet != NULL))
  5715. {
  5716. TManagedTerminal * ManagedTerminal =
  5717. dynamic_cast<TManagedTerminal *>(GetSessionTabTerminal(TabSheet));
  5718. if (DebugAlwaysTrue(ManagedTerminal != NULL))
  5719. {
  5720. TColor Color =
  5721. (ManagedTerminal == FTerminal) ? FSessionColor : ManagedTerminal->StateData->Color;
  5722. TabSheet->ImageIndex = AddSessionColor(Color);
  5723. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  5724. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  5725. {
  5726. ThemeTabSheet->Shadowed = !ManagedTerminal->Active;
  5727. }
  5728. }
  5729. }
  5730. }
  5731. //---------------------------------------------------------------------------
  5732. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  5733. {
  5734. DebugAssert(SessionsPageControl->ActivePage != NULL);
  5735. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  5736. bool Result = (Terminal != NULL);
  5737. if (Result)
  5738. {
  5739. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  5740. }
  5741. else
  5742. {
  5743. try
  5744. {
  5745. NewSession(false);
  5746. }
  5747. __finally
  5748. {
  5749. DoTerminalListChanged(false);
  5750. }
  5751. FSessionsPageControlNewSessionTime = Now();
  5752. }
  5753. return Result;
  5754. }
  5755. //---------------------------------------------------------------------------
  5756. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  5757. {
  5758. SessionTabSwitched();
  5759. }
  5760. //---------------------------------------------------------------------------
  5761. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  5762. {
  5763. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  5764. DebugAssert(TransferList != NULL);
  5765. UnicodeString Name;
  5766. if (TransferList->ItemIndex <= 0)
  5767. {
  5768. Name = L"";
  5769. }
  5770. else
  5771. {
  5772. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  5773. }
  5774. if (FCopyParamAutoSelected.IsEmpty())
  5775. {
  5776. // if previous preset was not autoselected, make new preset the "default"
  5777. FCopyParamDefault = Name;
  5778. }
  5779. GUIConfiguration->CopyParamCurrent = Name;
  5780. }
  5781. //---------------------------------------------------------------------------
  5782. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  5783. {
  5784. // sanity check
  5785. bool ExistingPreset =
  5786. (FTransferListHoverIndex >= 0) &&
  5787. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  5788. DebugAssert(ExistingPreset);
  5789. if (ExistingPreset)
  5790. {
  5791. HDC DC = GetDC(0);
  5792. TCanvas * Canvas = new TCanvas();
  5793. try
  5794. {
  5795. Canvas->Handle = DC;
  5796. Canvas->Font = GetToolbarFont(this);
  5797. UnicodeString Name;
  5798. if (FTransferListHoverIndex == 0)
  5799. {
  5800. Name = L"";
  5801. }
  5802. else
  5803. {
  5804. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  5805. }
  5806. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  5807. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  5808. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  5809. static_cast<TObject*>(GetComponent(fcTransferList)));
  5810. UnicodeString InfoStr =
  5811. GUIConfiguration->CopyParamPreset[Name].
  5812. GetInfoStr(L"; ",
  5813. FLAGMASK(Terminal != NULL, Terminal->UsableCopyParamAttrs(0).General));
  5814. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  5815. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  5816. {
  5817. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  5818. {
  5819. InfoStr.SetLength(InfoStr.Length() - 1);
  5820. }
  5821. InfoStr += Ellipsis;
  5822. }
  5823. // UpdateCaption does not cause invalidation of whole submenu, while
  5824. // setting Caption property does.
  5825. // also it probably does not resize the label, even if necessary
  5826. // (we do not want that anyway)
  5827. TransferLabel->UpdateCaption(InfoStr);
  5828. }
  5829. __finally
  5830. {
  5831. Canvas->Handle = NULL;
  5832. ReleaseDC(0, DC);
  5833. delete Canvas;
  5834. }
  5835. }
  5836. }
  5837. //---------------------------------------------------------------------------
  5838. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  5839. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  5840. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  5841. {
  5842. if (FTransferListHoverIndex != AHoverIndex)
  5843. {
  5844. FTransferListHoverIndex = AHoverIndex;
  5845. UpdateTransferLabel();
  5846. }
  5847. }
  5848. //---------------------------------------------------------------------------
  5849. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  5850. {
  5851. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  5852. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  5853. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  5854. {
  5855. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  5856. {
  5857. OpenDirectory(GetSide(osCurrent));
  5858. Message.Result = 1;
  5859. }
  5860. else
  5861. {
  5862. TForm::Dispatch(&Message);
  5863. }
  5864. }
  5865. else
  5866. {
  5867. TForm::Dispatch(&Message);
  5868. }
  5869. }
  5870. //---------------------------------------------------------------------------
  5871. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  5872. {
  5873. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  5874. if ((FIgnoreNextDialogChar != 0) &&
  5875. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  5876. {
  5877. Message.Result = 1;
  5878. }
  5879. else
  5880. {
  5881. TForm::Dispatch(&Message);
  5882. }
  5883. FIgnoreNextDialogChar = 0;
  5884. }
  5885. //---------------------------------------------------------------------------
  5886. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  5887. {
  5888. // The four low-order bits are used internally by Windows
  5889. unsigned int Cmd = (Message.WParam & 0xFFF0);
  5890. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  5891. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  5892. // 61730 - restore thru double click - undocumented
  5893. // 61490 - maximize thru double click - undocumented
  5894. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  5895. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  5896. {
  5897. SysResizing(Cmd);
  5898. }
  5899. TForm::Dispatch(&Message);
  5900. }
  5901. //---------------------------------------------------------------------------
  5902. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  5903. {
  5904. // We were actually never able to make ENDSESSION_CRITICAL happen.
  5905. // Also there no point returning TRUE as we are not able to
  5906. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  5907. // Hence the process termination might be safer :)
  5908. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  5909. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  5910. {
  5911. Message.Result = FALSE;
  5912. }
  5913. else
  5914. {
  5915. Message.Result = TRUE;
  5916. }
  5917. // Do not call default handling as that triggers OnCloseQuery,
  5918. // where our implementation will popup confirmation dialogs, what we do not want,
  5919. // as per Vista guidelines:
  5920. // https://msdn.microsoft.com/en-us/library/ms700677.aspx
  5921. }
  5922. //---------------------------------------------------------------------------
  5923. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  5924. {
  5925. if (Message.EndSession && IsApplicationMinimized())
  5926. {
  5927. // WORKAROUND
  5928. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  5929. // when it receives WM_ENDSESSION,
  5930. // but that sometimes (particularly when application is minimized) cause crashes.
  5931. // Crash popups message that blocks log off.
  5932. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  5933. // so we call ExitProcess() immediately, not even trying to cleanup.
  5934. // It still causes beep, so there's likely some popup, but it does not block
  5935. // log off.
  5936. ExitProcess(0);
  5937. }
  5938. TForm::Dispatch(&Message);
  5939. }
  5940. #ifdef _DEBUG
  5941. //---------------------------------------------------------------------------
  5942. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  5943. {
  5944. TForm::Dispatch(&Message);
  5945. }
  5946. #endif
  5947. //---------------------------------------------------------------------------
  5948. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  5949. {
  5950. }
  5951. //---------------------------------------------------------------------------
  5952. void __fastcall TCustomScpExplorerForm::DoShow()
  5953. {
  5954. // only now are the controls resized finally, so the size constraints
  5955. // will not conflict with possibly very small window size
  5956. RestoreFormParams();
  5957. FixControlsPlacement();
  5958. if (Position == poDefaultPosOnly)
  5959. {
  5960. CutFormToDesktop(this);
  5961. }
  5962. TForm::DoShow();
  5963. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  5964. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  5965. if (Terminal == NULL)
  5966. {
  5967. StartingDisconnected();
  5968. }
  5969. UpdatePixelsPerInchMainWindowCounter();
  5970. FShowing = true;
  5971. }
  5972. //---------------------------------------------------------------------------
  5973. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  5974. {
  5975. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  5976. }
  5977. //---------------------------------------------------------------------------
  5978. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  5979. {
  5980. DoTerminalListChanged(true);
  5981. }
  5982. //---------------------------------------------------------------------------
  5983. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  5984. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  5985. TNotifyEvent OnBalloonClick, TObject * UserData)
  5986. {
  5987. bool Do;
  5988. UnicodeString Message;
  5989. if (E == NULL)
  5990. {
  5991. Message = Str;
  5992. Do = true;
  5993. }
  5994. else
  5995. {
  5996. Do = ExceptionMessage(E, Message);
  5997. }
  5998. if (Do && WinConfiguration->BalloonNotifications)
  5999. {
  6000. UnicodeString Title;
  6001. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6002. {
  6003. Message = TrimLeft(Message);
  6004. }
  6005. else
  6006. {
  6007. Message = UnformatMessage(Message);
  6008. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6009. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6010. Title = LoadResourceString(Captions[Type]);
  6011. if (Terminal != NULL)
  6012. {
  6013. Title = FORMAT(L"%s - %s",
  6014. (TTerminalManager::Instance()->TerminalTitle(Terminal), Title));
  6015. }
  6016. }
  6017. if (Seconds == 0)
  6018. {
  6019. Seconds = WinConfiguration->NotificationsTimeout;
  6020. }
  6021. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6022. }
  6023. }
  6024. //---------------------------------------------------------------------------
  6025. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6026. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6027. UnicodeString HelpKeyword, const TMessageParams * Params,
  6028. TTerminal * Terminal)
  6029. {
  6030. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6031. (FOnFeedSynchronizeError != NULL)) &&
  6032. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6033. {
  6034. if (FOnFeedSynchronizeError != NULL)
  6035. {
  6036. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6037. }
  6038. else
  6039. {
  6040. DebugAssert(FErrorList != NULL);
  6041. TStringList * MoreMessagesCopy = NULL;
  6042. if (MoreMessages)
  6043. {
  6044. MoreMessagesCopy = new TStringList();
  6045. MoreMessagesCopy->Assign(MoreMessages);
  6046. }
  6047. FErrorList->AddObject(Message, MoreMessagesCopy);
  6048. }
  6049. PopupTrayBalloon(Terminal, Message, Type);
  6050. return ContinueAnswer(Answers);
  6051. }
  6052. else
  6053. {
  6054. bool UseBalloon = FTrayIcon->Visible;
  6055. if (UseBalloon)
  6056. {
  6057. PopupTrayBalloon(Terminal, Message, Type);
  6058. }
  6059. unsigned int Result;
  6060. try
  6061. {
  6062. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6063. }
  6064. __finally
  6065. {
  6066. // cancel only balloon we popped up, otherwise we may cancel notification
  6067. // balloon that was there before the message dialog
  6068. // (such as "dd confirmation opt in balloon)
  6069. if (UseBalloon)
  6070. {
  6071. FTrayIcon->CancelBalloon();
  6072. }
  6073. }
  6074. return Result;
  6075. }
  6076. }
  6077. //---------------------------------------------------------------------------
  6078. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6079. TTerminal * Terminal, Exception * E)
  6080. {
  6081. if (FTrayIcon->Visible)
  6082. {
  6083. PopupTrayBalloon(Terminal, L"", qtError, E);
  6084. }
  6085. // particularly prevent opening new session from jump list,
  6086. // while exception is shown
  6087. NonVisualDataModule->StartBusy();
  6088. try
  6089. {
  6090. ShowExtendedExceptionEx(Terminal, E);
  6091. }
  6092. __finally
  6093. {
  6094. NonVisualDataModule->EndBusy();
  6095. FTrayIcon->CancelBalloon();
  6096. }
  6097. }
  6098. //---------------------------------------------------------------------------
  6099. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6100. {
  6101. // cannot rely on active page being page for active terminal,
  6102. // as it can happen that active page is the "new session" page
  6103. // (e.g. when reconnecting active terminal, while login dialog
  6104. // invoked from "new session" page is modal)
  6105. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6106. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6107. }
  6108. //---------------------------------------------------------------------------
  6109. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6110. TTerminal * Terminal, Exception * E)
  6111. {
  6112. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6113. if (!Terminal->Active)
  6114. {
  6115. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6116. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6117. {
  6118. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6119. }
  6120. }
  6121. }
  6122. //---------------------------------------------------------------------------
  6123. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6124. UnicodeString Message, TQueryType Type,
  6125. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6126. {
  6127. if ((E == NULL) ||
  6128. ExceptionMessage(E, Message))
  6129. {
  6130. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6131. if (Important)
  6132. {
  6133. Seconds *= 5;
  6134. }
  6135. UnicodeString NoteMessage(UnformatMessage(Message));
  6136. if (Terminal != NULL)
  6137. {
  6138. NoteMessage = FORMAT(L"%s: %s",
  6139. (TTerminalManager::Instance()->TerminalTitle(Terminal), NoteMessage));
  6140. }
  6141. if (WinConfiguration->BalloonNotifications)
  6142. {
  6143. AddNote(NoteMessage);
  6144. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6145. }
  6146. else
  6147. {
  6148. FlashOnBackground();
  6149. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6150. }
  6151. }
  6152. }
  6153. //---------------------------------------------------------------------------
  6154. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6155. {
  6156. RestoreApp();
  6157. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6158. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6159. !NonVisualDataModule->Busy)
  6160. {
  6161. TTerminal * Terminal = TerminalNoteData->Terminal;
  6162. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6163. if (!ComponentVisible[fcQueueView])
  6164. {
  6165. ToggleQueueVisibility();
  6166. GoToQueue();
  6167. }
  6168. }
  6169. }
  6170. //---------------------------------------------------------------------------
  6171. void __fastcall TCustomScpExplorerForm::QueueEvent(TTerminal * ATerminal,
  6172. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6173. {
  6174. TManagedTerminal * ManagedTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  6175. UnicodeString Message;
  6176. TNotifyEvent OnClick = NULL;
  6177. TObject * UserData = NULL;
  6178. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6179. switch (Event)
  6180. {
  6181. case qeEmptyButMonitored:
  6182. if ((ATerminal != Terminal) || QueueInvisible)
  6183. {
  6184. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6185. OnClick = QueueEmptyNoteClicked;
  6186. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6187. TerminalNoteData->Terminal = ATerminal;
  6188. UserData = TerminalNoteData;
  6189. }
  6190. break;
  6191. case qeEmpty:
  6192. OperationComplete(ManagedTerminal->QueueOperationStart);
  6193. break;
  6194. case qePendingUserAction:
  6195. if ((ATerminal != Terminal) ||
  6196. (QueueInvisible && !IsQueueAutoPopup()))
  6197. {
  6198. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6199. }
  6200. break;
  6201. default:
  6202. DebugFail();
  6203. }
  6204. if (!Message.IsEmpty())
  6205. {
  6206. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6207. }
  6208. }
  6209. //---------------------------------------------------------------------------
  6210. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6211. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6212. {
  6213. if (FDDExtMapFile != NULL)
  6214. {
  6215. CloseHandle(FDDExtMapFile);
  6216. FDDExtMapFile = NULL;
  6217. }
  6218. if (WinConfiguration->DDExtEnabled)
  6219. {
  6220. if (!WinConfiguration->DDExtInstalled)
  6221. {
  6222. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtNotInstalled");
  6223. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_NOT_INSTALLED2), HELP_DRAGEXT_TARGET_NOT_INSTALLED);
  6224. }
  6225. DDExtInitDrag(FileList, Created);
  6226. }
  6227. }
  6228. //---------------------------------------------------------------------------
  6229. void __fastcall TCustomScpExplorerForm::DDExtInitDrag(TFileList * FileList,
  6230. bool & Created)
  6231. {
  6232. FDragExtFakeDirectory =
  6233. ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6234. if (!ForceDirectories(ApiPath(FDragExtFakeDirectory)))
  6235. {
  6236. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (FDragExtFakeDirectory)));
  6237. }
  6238. FileList->AddItem(NULL, FDragExtFakeDirectory);
  6239. Created = true;
  6240. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6241. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6242. {
  6243. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6244. TDragExtCommStruct* CommStruct;
  6245. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6246. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6247. DebugAssert(CommStruct != NULL);
  6248. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6249. CommStruct->Dragging = true;
  6250. wcsncpy(CommStruct->DropDest, FDragExtFakeDirectory.c_str(),
  6251. LENOF(CommStruct->DropDest));
  6252. NULL_TERMINATE(CommStruct->DropDest);
  6253. UnmapViewOfFile(CommStruct);
  6254. }
  6255. FDDMoveSlipped = false;
  6256. }
  6257. //---------------------------------------------------------------------------
  6258. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6259. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6260. {
  6261. bool Result;
  6262. if (Sender == RemoteDirView)
  6263. {
  6264. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6265. }
  6266. else
  6267. {
  6268. DebugAssert(Sender == RemoteDriveView);
  6269. TStrings * FileList = RemoteDriveView->DragFileList();
  6270. try
  6271. {
  6272. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6273. }
  6274. __finally
  6275. {
  6276. delete FileList;
  6277. }
  6278. }
  6279. if (FDDTargetControl == RemoteDriveView)
  6280. {
  6281. RemoteDriveView->UpdateDropTarget();
  6282. }
  6283. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6284. // or from tree view to dir view.
  6285. // foMove happens when file/dir is dragged from remote tree view outside of
  6286. // application via dragex
  6287. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6288. (DropSourceControl == RemoteDriveView))
  6289. {
  6290. RemoteDriveView->UpdateDropSource();
  6291. }
  6292. return Result;
  6293. }
  6294. //---------------------------------------------------------------------------
  6295. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6296. {
  6297. // This also handles drops of remote files to queue.
  6298. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6299. SAFE_DESTROY(FDDFileList);
  6300. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6301. {
  6302. try
  6303. {
  6304. TDragResult DDResult = (Sender == RemoteDirView) ?
  6305. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6306. // Focus is moved to the target application,
  6307. // but as we are going to present the UI, we need to steal the focus back.
  6308. // This most likely won't work though (windows does not allow application
  6309. // to steal focus most of the time)
  6310. Application->BringToFront();
  6311. // On older version of Windows we never got drMove here, see also comment below.
  6312. // On Windows 10, we get the "move".
  6313. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6314. {
  6315. UnicodeString TargetDirectory;
  6316. TFileOperation Operation;
  6317. // drInvalid may mean drMove, see comment below
  6318. switch (DDResult)
  6319. {
  6320. case drCopy:
  6321. Operation = foCopy;
  6322. break;
  6323. case drMove:
  6324. Operation = foMove;
  6325. break;
  6326. default:
  6327. DebugFail();
  6328. case drInvalid:
  6329. // prefer "copy" for safety
  6330. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6331. break;
  6332. }
  6333. if (FDDMoveSlipped)
  6334. {
  6335. Operation = foMove;
  6336. }
  6337. TTransferOperationParam Param;
  6338. bool Internal;
  6339. bool ForceQueue;
  6340. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, Internal))
  6341. {
  6342. // we get drInvalid both if d&d was intercepted by ddext,
  6343. // and when users drops on no-drop location.
  6344. // we tell the difference by existence of response from ddext,
  6345. // so we ignore absence of response in this case
  6346. if (DDResult != drInvalid)
  6347. {
  6348. // here we know that the extension is installed,
  6349. // as it is checked as soon as drag&drop starts from
  6350. // RemoteFileControlDDCreateDragFileList
  6351. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  6352. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  6353. }
  6354. }
  6355. else
  6356. {
  6357. // download using ddext
  6358. Param.Temp = false;
  6359. Param.DragDrop = true;
  6360. if (ForceQueue)
  6361. {
  6362. Param.Queue = asOn;
  6363. }
  6364. if (Sender == RemoteDirView)
  6365. {
  6366. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  6367. }
  6368. if (RemoteFileControlFileOperation(Sender, Operation,
  6369. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  6370. {
  6371. Configuration->Usage->Inc(
  6372. Internal ? L"DownloadsDragDropInternal" : L"DownloadsDragDropExternalExt");
  6373. }
  6374. }
  6375. }
  6376. }
  6377. __finally
  6378. {
  6379. CloseHandle(FDDExtMapFile);
  6380. FDDExtMapFile = NULL;
  6381. RemoveDir(ApiPath(FDragExtFakeDirectory));
  6382. FDragExtFakeDirectory = L"";
  6383. }
  6384. }
  6385. if (FDragDropSshTerminate.get() != NULL)
  6386. {
  6387. FDragDropSshTerminate->Rethrow();
  6388. }
  6389. }
  6390. //---------------------------------------------------------------------------
  6391. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  6392. TObject * Sender, int dwEffect, HRESULT & /*Result*/)
  6393. {
  6394. HCURSOR SlippedCopyCursor;
  6395. FDDMoveSlipped =
  6396. (FDragMoveCursor != NULL) &&
  6397. (!WinConfiguration->DDAllowMoveInit) && (dwEffect == DROPEFFECT_Copy) &&
  6398. ((IsFileControl(FDDTargetControl, osRemote) && (GetKeyState(VK_CONTROL) >= 0) &&
  6399. FTerminal->IsCapable[fcRemoteMove]) ||
  6400. (IsFileControl(FDDTargetControl, osLocal) && (GetKeyState(VK_SHIFT) < 0)));
  6401. SlippedCopyCursor = FDDMoveSlipped ? FDragMoveCursor : Dragdrop::DefaultCursor;
  6402. DragDropFiles(Sender)->CHCopy = SlippedCopyCursor;
  6403. DragDropFiles(Sender)->CHScrollCopy = SlippedCopyCursor;
  6404. // Remember drop effect so we know (when user drops files), if we copy or move
  6405. FLastDropEffect = dwEffect;
  6406. }
  6407. //---------------------------------------------------------------------------
  6408. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  6409. UnicodeString & Directory, bool & ForceQueue, bool & Internal)
  6410. {
  6411. bool Result;
  6412. if (FDDTargetControl == QueueView3)
  6413. {
  6414. Directory = DefaultDownloadTargetDirectory();
  6415. Result = true;
  6416. Internal = true;
  6417. ForceQueue = true;
  6418. }
  6419. else
  6420. {
  6421. ForceQueue = false;
  6422. Enabled = false;
  6423. try
  6424. {
  6425. int Timer = 0;
  6426. Result = false;
  6427. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  6428. {
  6429. {
  6430. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6431. TDragExtCommStruct* CommStruct;
  6432. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6433. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6434. DebugAssert(CommStruct != NULL);
  6435. Result = !CommStruct->Dragging;
  6436. if (Result)
  6437. {
  6438. Directory = ExtractFilePath(CommStruct->DropDest);
  6439. Internal = false;
  6440. }
  6441. UnmapViewOfFile(CommStruct);
  6442. }
  6443. if (!Result)
  6444. {
  6445. Sleep(50);
  6446. Timer += 50;
  6447. Application->ProcessMessages();
  6448. }
  6449. }
  6450. }
  6451. __finally
  6452. {
  6453. Enabled = true;
  6454. }
  6455. }
  6456. return Result;
  6457. }
  6458. //---------------------------------------------------------------------------
  6459. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  6460. const UnicodeString TempDir, int SecDelay)
  6461. {
  6462. TDateTime Alarm = Now() + (double)((double)SecDelay*OneMillisecond);
  6463. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  6464. if (FDelayedDeletionTimer == NULL)
  6465. {
  6466. DebugAssert(HandleAllocated());
  6467. FDelayedDeletionTimer = new TTimer(this);
  6468. FDelayedDeletionTimer->Interval = 10000;
  6469. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  6470. }
  6471. else
  6472. {
  6473. FDelayedDeletionTimer->Enabled = true;
  6474. }
  6475. }
  6476. //---------------------------------------------------------------------------
  6477. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  6478. {
  6479. DebugAssert(FDelayedDeletionList != NULL);
  6480. TDateTime N = Now();
  6481. TDateTime Alert;
  6482. UnicodeString Directory;
  6483. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  6484. {
  6485. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  6486. if ((N >= Alert) || (Sender == NULL))
  6487. {
  6488. Directory = FDelayedDeletionList->Strings[Index];
  6489. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  6490. {
  6491. FDelayedDeletionList->Delete(Index);
  6492. }
  6493. }
  6494. }
  6495. if (FDelayedDeletionList->Count == 0)
  6496. {
  6497. FDelayedDeletionTimer->Enabled = false;
  6498. }
  6499. }
  6500. //---------------------------------------------------------------------------
  6501. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  6502. {
  6503. if (IsFileControl(FDDTargetControl, osRemote) ||
  6504. (FDDTargetControl == SessionsPageControl))
  6505. {
  6506. TTerminal * TargetTerminal = NULL;
  6507. TFileOperation Operation = foNone;
  6508. if (FDDTargetControl == SessionsPageControl)
  6509. {
  6510. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  6511. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  6512. // do not allow dropping on the "+" tab
  6513. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  6514. if (TargetTerminal != NULL)
  6515. {
  6516. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  6517. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  6518. {
  6519. Operation = foRemoteMove;
  6520. }
  6521. else
  6522. {
  6523. Operation = foRemoteCopy;
  6524. }
  6525. }
  6526. }
  6527. else
  6528. {
  6529. // when move from remote side is disabled, we allow copying inside the remote
  6530. // panel, but we interpret is as moving (we also slip in the move cursor)
  6531. if ((FLastDropEffect == DROPEFFECT_MOVE) ||
  6532. (!WinConfiguration->DDAllowMoveInit && (FLastDropEffect == DROPEFFECT_COPY) &&
  6533. FDDMoveSlipped))
  6534. {
  6535. Operation = foRemoteMove;
  6536. }
  6537. else if (FLastDropEffect == DROPEFFECT_COPY)
  6538. {
  6539. Operation = foRemoteCopy;
  6540. }
  6541. }
  6542. if (Operation != foNone)
  6543. {
  6544. RemoteFileControlFileOperation(DropSourceControl,
  6545. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  6546. }
  6547. // abort drag&drop
  6548. Abort();
  6549. }
  6550. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  6551. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  6552. (FDDTargetControl != QueueView3))
  6553. {
  6554. DebugAssert(!FDragTempDir.IsEmpty());
  6555. TTransferType Type;
  6556. UnicodeString TempDir = FDragTempDir;
  6557. // We clear FDragTempDir before calling
  6558. // just in case it fail (raises exception)
  6559. FDragTempDir = L"";
  6560. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  6561. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  6562. // empty directory parameter means temp directory -> don't display it!
  6563. UnicodeString TargetDir = L"";
  6564. int Options = 0;
  6565. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  6566. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  6567. {
  6568. Abort();
  6569. }
  6570. // TargetDir is set when dropped on local file control
  6571. // (this was workaround for legacy dirview event handling, now it should be
  6572. // made prettier)
  6573. if (TargetDir.IsEmpty())
  6574. {
  6575. TargetDir = TempDir;
  6576. if (ForceDirectories(ApiPath(TargetDir)))
  6577. {
  6578. DebugAssert(Terminal && !TargetDir.IsEmpty());
  6579. FPendingTempSpaceWarn = true;
  6580. try
  6581. {
  6582. FDragDropOperation = true;
  6583. int Params = cpTemporary |
  6584. (Type == ttMove ? cpDelete : 0);
  6585. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  6586. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  6587. }
  6588. __finally
  6589. {
  6590. FDragDropOperation = false;
  6591. FPendingTempSpaceWarn = false;
  6592. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  6593. }
  6594. }
  6595. else
  6596. {
  6597. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  6598. }
  6599. }
  6600. }
  6601. }
  6602. //---------------------------------------------------------------------------
  6603. void __fastcall TCustomScpExplorerForm::DDDownload(TStrings * FilesToCopy,
  6604. const UnicodeString TargetDir, const TCopyParamType * CopyParam, int Params)
  6605. {
  6606. void * BatchStorage;
  6607. BatchStart(BatchStorage);
  6608. try
  6609. {
  6610. UpdateCopyParamCounters(*CopyParam);
  6611. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  6612. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  6613. {
  6614. RemoteDriveView->UpdateDropSource();
  6615. }
  6616. }
  6617. __finally
  6618. {
  6619. BatchEnd(BatchStorage);
  6620. }
  6621. }
  6622. //---------------------------------------------------------------------------
  6623. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  6624. {
  6625. public:
  6626. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  6627. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename)
  6628. {
  6629. }
  6630. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  6631. {
  6632. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  6633. TDataObjectFilesEx::AllowData(FormatEtc);
  6634. }
  6635. };
  6636. //---------------------------------------------------------------------------
  6637. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  6638. TObject * Sender, TDataObject *& DataObject)
  6639. {
  6640. if (FDDExtMapFile != NULL)
  6641. {
  6642. TFileList * FileList = DragDropFiles(Sender)->FileList;
  6643. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  6644. {
  6645. Abort();
  6646. }
  6647. if (FileList->Count > 0)
  6648. {
  6649. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  6650. if (!FilesObject->IsValid(true, true))
  6651. {
  6652. FilesObject->_Release();
  6653. }
  6654. else
  6655. {
  6656. DataObject = FilesObject;
  6657. }
  6658. }
  6659. }
  6660. }
  6661. //---------------------------------------------------------------------------
  6662. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  6663. {
  6664. DebugFail();
  6665. }
  6666. //---------------------------------------------------------------------------
  6667. void __fastcall TCustomScpExplorerForm::GoToTree()
  6668. {
  6669. ComponentVisible[fcRemoteTree] = true;
  6670. RemoteDriveView->SetFocus();
  6671. }
  6672. //---------------------------------------------------------------------------
  6673. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  6674. TPanelExport Export)
  6675. {
  6676. TCustomDirView * DirView = this->DirView(Side);
  6677. std::unique_ptr<TStrings> ExportData(new TStringList());
  6678. switch (Export)
  6679. {
  6680. case pePath:
  6681. ExportData->Add(DirView->PathName);
  6682. break;
  6683. case peFileList:
  6684. case peFullFileList:
  6685. {
  6686. bool FullPath = (Export == peFullFileList);
  6687. DirView->CreateFileList(false, FullPath, ExportData.get());
  6688. for (int Index = 0; Index < ExportData->Count; Index++)
  6689. {
  6690. if (ExportData->Strings[Index].Pos(L" ") > 0)
  6691. {
  6692. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  6693. }
  6694. }
  6695. }
  6696. break;
  6697. default:
  6698. DebugFail();
  6699. }
  6700. return ExportData.release();
  6701. }
  6702. //---------------------------------------------------------------------------
  6703. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  6704. TPanelExport Export, TPanelExportDestination Destination)
  6705. {
  6706. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  6707. PanelExportStore(Side, Export, Destination, ExportData.get());
  6708. }
  6709. //---------------------------------------------------------------------------
  6710. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  6711. TPanelExport /*Export*/, TPanelExportDestination Destination,
  6712. TStrings * ExportData)
  6713. {
  6714. if (Destination == pedClipboard)
  6715. {
  6716. TInstantOperationVisualizer Visualizer;
  6717. CopyToClipboard(ExportData);
  6718. }
  6719. else
  6720. {
  6721. DebugFail();
  6722. }
  6723. }
  6724. //---------------------------------------------------------------------------
  6725. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  6726. {
  6727. TCustomDirView * DirView = this->DirView(Side);
  6728. TFileFilter Filter;
  6729. DefaultFileFilter(Filter);
  6730. Filter.Masks = DirView->Mask;
  6731. if (DoFilterMaskDialog(DirView, &Filter))
  6732. {
  6733. DirView->Mask = TFileMasks::NormalizeMask(Filter.Masks);
  6734. Configuration->Usage->Inc(L"Filters");
  6735. }
  6736. }
  6737. //---------------------------------------------------------------------------
  6738. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  6739. {
  6740. return FQueueController->DefaultOperation();
  6741. }
  6742. //---------------------------------------------------------------------------
  6743. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  6744. TQueueOperation Operation, void ** Param)
  6745. {
  6746. switch (Operation)
  6747. {
  6748. case qoPreferences:
  6749. return true;
  6750. case qoGoTo:
  6751. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  6752. case qoOnceEmpty:
  6753. return !FQueueController->Empty;
  6754. default:
  6755. return FQueueController->AllowOperation(Operation, Param);
  6756. }
  6757. }
  6758. //---------------------------------------------------------------------------
  6759. void __fastcall TCustomScpExplorerForm::GoToQueue()
  6760. {
  6761. if (DebugAlwaysTrue(QueueView3->Visible))
  6762. {
  6763. QueueView3->SetFocus();
  6764. }
  6765. }
  6766. //---------------------------------------------------------------------------
  6767. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  6768. TQueueOperation Operation, void * Param)
  6769. {
  6770. if (Operation == qoGoTo)
  6771. {
  6772. GoToQueue();
  6773. }
  6774. else if (Operation == qoPreferences)
  6775. {
  6776. PreferencesDialog(pmQueue);
  6777. }
  6778. else
  6779. {
  6780. FQueueController->ExecuteOperation(Operation, Param);
  6781. }
  6782. }
  6783. //---------------------------------------------------------------------------
  6784. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  6785. {
  6786. return (Queue != NULL) && Queue->Enabled;
  6787. }
  6788. //---------------------------------------------------------------------------
  6789. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  6790. {
  6791. DebugAssert(Queue != NULL);
  6792. if (Queue != NULL)
  6793. {
  6794. Queue->Enabled = !Queue->Enabled;
  6795. }
  6796. }
  6797. //---------------------------------------------------------------------------
  6798. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  6799. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  6800. {
  6801. FQueueActedItem = QueueView3->ItemFocused;
  6802. }
  6803. //---------------------------------------------------------------------------
  6804. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  6805. {
  6806. return TopDock->Height + QueueSplitter->Height;
  6807. }
  6808. //---------------------------------------------------------------------------
  6809. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  6810. TObject * /*Sender*/, int & NewSize, bool & Accept)
  6811. {
  6812. // when queue is hidden by double-clicking splitter, stray attempt to
  6813. // resize the panel with strange value arrives, make sure it is ignored
  6814. if (ComponentVisible[fcQueueView])
  6815. {
  6816. int HeightLimit = ClientHeight - GetStaticComponentsHeight() -
  6817. RemotePanel->Constraints->MinHeight;
  6818. if (NewSize > HeightLimit)
  6819. {
  6820. NewSize = HeightLimit;
  6821. }
  6822. }
  6823. else
  6824. {
  6825. Accept = false;
  6826. }
  6827. }
  6828. //---------------------------------------------------------------------------
  6829. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  6830. TDragObject *& /*DragObject*/)
  6831. {
  6832. FQueueActedItem = QueueView3->ItemFocused;
  6833. }
  6834. //---------------------------------------------------------------------------
  6835. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  6836. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  6837. {
  6838. Accept = true;
  6839. if (Source == QueueView3)
  6840. {
  6841. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  6842. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  6843. if (Accept)
  6844. {
  6845. TQueueItemProxy * QueueItem;
  6846. TQueueItemProxy * DestQueueItem;
  6847. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  6848. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  6849. Accept = (QueueItem != DestQueueItem) &&
  6850. (QueueItem->Status == TQueueItem::qsPending) &&
  6851. (DestQueueItem->Status == TQueueItem::qsPending);
  6852. }
  6853. }
  6854. }
  6855. //---------------------------------------------------------------------------
  6856. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  6857. TObject * /*Source*/, int /*X*/, int /*Y*/)
  6858. {
  6859. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  6860. {
  6861. TQueueItemProxy * QueueItem;
  6862. TQueueItemProxy * DestQueueItem;
  6863. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  6864. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  6865. QueueItem->Move(DestQueueItem);
  6866. }
  6867. }
  6868. //---------------------------------------------------------------------------
  6869. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  6870. {
  6871. if ((QueueView3->ItemFocused == NULL) &&
  6872. (QueueView3->Items->Count > 0))
  6873. {
  6874. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  6875. }
  6876. QueueLabelUpdateStatus();
  6877. }
  6878. //---------------------------------------------------------------------------
  6879. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  6880. {
  6881. QueueLabelUpdateStatus();
  6882. }
  6883. //---------------------------------------------------------------------------
  6884. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  6885. {
  6886. QueueLabel->UpdateStatus();
  6887. }
  6888. //---------------------------------------------------------------------------
  6889. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  6890. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  6891. {
  6892. if (Selected)
  6893. {
  6894. NonVisualDataModule->UpdateNonVisibleActions();
  6895. }
  6896. }
  6897. //---------------------------------------------------------------------------
  6898. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  6899. {
  6900. TDragDropFilesEx * Result = NULL;
  6901. if (Sender == SessionsPageControl)
  6902. {
  6903. Result = FSessionsDragDropFilesEx;
  6904. }
  6905. else if (Sender == QueueView3)
  6906. {
  6907. Result = FQueueDragDropFilesEx;
  6908. }
  6909. else
  6910. {
  6911. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  6912. if (DirView != NULL)
  6913. {
  6914. Result = DirView->DragDropFilesEx;
  6915. }
  6916. else
  6917. {
  6918. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  6919. if (DriveView != NULL)
  6920. {
  6921. Result = DriveView->DragDropFilesEx;
  6922. }
  6923. }
  6924. }
  6925. DebugAssert(Result != NULL);
  6926. return Result;
  6927. }
  6928. //---------------------------------------------------------------------------
  6929. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  6930. {
  6931. return (DView->SelCount == DView->FilesCount);
  6932. }
  6933. //---------------------------------------------------------------------------
  6934. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  6935. {
  6936. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  6937. }
  6938. //---------------------------------------------------------------------------
  6939. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  6940. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue)
  6941. {
  6942. TFileOperation Operation;
  6943. switch (Effect)
  6944. {
  6945. case DROPEFFECT_MOVE:
  6946. Operation = foMove;
  6947. break;
  6948. case DROPEFFECT_COPY:
  6949. // occures on WinXP (reported by user)
  6950. default:
  6951. Operation = foCopy;
  6952. break;
  6953. };
  6954. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  6955. // see a comment in TUnixDirView::PerformItemDragDropOperation
  6956. if (DragDropFilesEx->FileList->Count > 0)
  6957. {
  6958. TStrings * FileList = new TStringList();
  6959. try
  6960. {
  6961. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  6962. {
  6963. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  6964. }
  6965. FDragDropOperation = true;
  6966. TTransferOperationParam Param;
  6967. Param.TargetDirectory = TargetPath;
  6968. // upload, no temp dirs
  6969. Param.Temp = false;
  6970. Param.DragDrop = true;
  6971. Param.Options =
  6972. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  6973. if (ForceQueue)
  6974. {
  6975. Param.Queue = asOn;
  6976. }
  6977. if (ExecuteFileOperation(Operation, osLocal, FileList,
  6978. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  6979. {
  6980. if (IsFileControl(DropSourceControl, osLocal))
  6981. {
  6982. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  6983. }
  6984. else
  6985. {
  6986. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  6987. }
  6988. }
  6989. }
  6990. __finally
  6991. {
  6992. FDragDropOperation = false;
  6993. delete FileList;
  6994. }
  6995. }
  6996. }
  6997. //---------------------------------------------------------------------------
  6998. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  6999. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7000. UnicodeString TargetPath, bool & /*DoOperation*/)
  7001. {
  7002. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false);
  7003. }
  7004. //---------------------------------------------------------------------------
  7005. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7006. TObject * Sender, int grfKeyState, int & dwEffect)
  7007. {
  7008. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7009. if ((dwEffect != DROPEFFECT_None) &&
  7010. IsFileControl(DropSourceControl, osRemote))
  7011. {
  7012. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7013. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7014. (RemoteDirView->DropTarget == NULL))
  7015. {
  7016. dwEffect = DROPEFFECT_None;
  7017. }
  7018. else
  7019. {
  7020. if (dwEffect == DROPEFFECT_Copy)
  7021. {
  7022. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7023. // currently we support copying always (at least via temporary directory);
  7024. // remove associated checks once this all proves stable and working
  7025. bool CopyCapable = true;
  7026. // if we do not support neither of operations, there's no discussion
  7027. if (!MoveCapable && !CopyCapable)
  7028. {
  7029. dwEffect = DROPEFFECT_None;
  7030. }
  7031. // when moving is disabled, we need to keep effect to "copy",
  7032. // which will be later interpretted as move (with slipped-in cursor)
  7033. else if (!WinConfiguration->DDAllowMoveInit && FLAGCLEAR(grfKeyState, MK_CONTROL))
  7034. {
  7035. // no-op, keep copy
  7036. }
  7037. else
  7038. {
  7039. // The default effect inside remote panel is move,
  7040. // unless we do not support it, but support copy
  7041. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7042. {
  7043. dwEffect = MoveCapable ? DROPEFFECT_Move : DROPEFFECT_Copy;
  7044. }
  7045. else
  7046. {
  7047. // with ctrl-down, we want copy unless it is not supported
  7048. dwEffect = CopyCapable ? DROPEFFECT_Copy : DROPEFFECT_None;
  7049. }
  7050. }
  7051. }
  7052. }
  7053. }
  7054. }
  7055. //---------------------------------------------------------------------------
  7056. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7057. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7058. {
  7059. if (FDDTotalSize >= 0)
  7060. {
  7061. if (File->IsDirectory)
  7062. {
  7063. FDDTotalSize = -1;
  7064. }
  7065. else
  7066. {
  7067. FDDTotalSize += File->Size;
  7068. }
  7069. }
  7070. DebugAssert(!FDragTempDir.IsEmpty());
  7071. // TODO: this is quite ineffective
  7072. // TODO: what if invalid character replacement is disabled?
  7073. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7074. UnicodeString TransferFileName;
  7075. if (Sender == RemoteDriveView)
  7076. {
  7077. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7078. }
  7079. else
  7080. {
  7081. TransferFileName = File->FileName;
  7082. }
  7083. FDDFileList->AddObject(TransferFileName, File);
  7084. }
  7085. //---------------------------------------------------------------------------
  7086. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7087. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7088. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7089. {
  7090. // sometimes we do not get DDEnd so the list is not released
  7091. SAFE_DESTROY(FDDFileList);
  7092. FDDFileList = new TStringList();
  7093. FDragTempDir = WinConfiguration->TemporaryDir();
  7094. FDDTotalSize = 0;
  7095. FDragDropSshTerminate.reset(NULL);
  7096. }
  7097. //---------------------------------------------------------------------------
  7098. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7099. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7100. HRESULT & Result)
  7101. {
  7102. if (Result == DRAGDROP_S_DROP)
  7103. {
  7104. try
  7105. {
  7106. GlobalDragImageList->HideDragImage();
  7107. try
  7108. {
  7109. RemoteFileControlDDTargetDrop();
  7110. }
  7111. catch(ESshTerminate & E)
  7112. {
  7113. FDragDropSshTerminate.reset(E.Clone());
  7114. }
  7115. }
  7116. catch (Exception &E)
  7117. {
  7118. // If downloading fails we need to cancel drag&drop, otherwise
  7119. // Explorer shows error
  7120. // But by the way exception probably never reach this point as
  7121. // it's catched on way.
  7122. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7123. Result = DRAGDROP_S_CANCEL;
  7124. ShowExtendedException(Terminal, &E);
  7125. }
  7126. }
  7127. }
  7128. //---------------------------------------------------------------------------
  7129. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7130. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7131. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7132. {
  7133. TFileMasks::TParams MaskParams;
  7134. MaskParams.Size = Size;
  7135. MaskParams.Modification = Modification;
  7136. // this does not re-parse the mask if it is the same as the last time
  7137. FDirViewMatchMask = Masks;
  7138. bool ImplicitMatch;
  7139. Matches =
  7140. // RecurseInclude parameter has no effect as the Path is empty
  7141. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7142. (AllowImplicitMatches || !ImplicitMatch);
  7143. }
  7144. //---------------------------------------------------------------------------
  7145. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7146. TObject * Sender, TListItem * Item, WORD & Indexes)
  7147. {
  7148. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7149. UnicodeString Ext;
  7150. if (DirView == RemoteDirView)
  7151. {
  7152. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7153. }
  7154. else
  7155. {
  7156. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7157. }
  7158. if (SameText(Ext, Configuration->PartialExt))
  7159. {
  7160. Indexes |= oiPartial;
  7161. }
  7162. }
  7163. //---------------------------------------------------------------------------
  7164. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7165. {
  7166. return
  7167. DirViewEnabled(osCurrent) &&
  7168. DirView(osCurrent)->CanPasteFromClipBoard();
  7169. }
  7170. //---------------------------------------------------------------------------
  7171. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7172. {
  7173. bool Result = false;
  7174. if (CanPasteToDirViewFromClipBoard())
  7175. {
  7176. Result = true;
  7177. }
  7178. else
  7179. {
  7180. UnicodeString ClipboardText;
  7181. if (NonEmptyTextFromClipboard(ClipboardText))
  7182. {
  7183. if (StoredSessions->IsUrl(ClipboardText))
  7184. {
  7185. Result = true;
  7186. }
  7187. else
  7188. {
  7189. Result = DirViewEnabled(osCurrent);
  7190. }
  7191. }
  7192. }
  7193. return Result;
  7194. }
  7195. //---------------------------------------------------------------------------
  7196. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7197. {
  7198. if (CanPasteToDirViewFromClipBoard())
  7199. {
  7200. DirView(osCurrent)->PasteFromClipBoard();
  7201. }
  7202. else
  7203. {
  7204. UnicodeString ClipboardText;
  7205. if (NonEmptyTextFromClipboard(ClipboardText))
  7206. {
  7207. if (StoredSessions->IsUrl(ClipboardText))
  7208. {
  7209. NewSession(false, ClipboardText);
  7210. }
  7211. else
  7212. {
  7213. DirView(osCurrent)->Path = ClipboardText;
  7214. }
  7215. }
  7216. }
  7217. }
  7218. //---------------------------------------------------------------------------
  7219. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7220. {
  7221. // TBD
  7222. }
  7223. //---------------------------------------------------------------------------
  7224. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7225. {
  7226. TCustomDirView * ADirView = DirView(Side);
  7227. ADirView->SelectAll(Mode);
  7228. ADirView->SetFocus();
  7229. }
  7230. //---------------------------------------------------------------------------
  7231. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7232. {
  7233. TCustomDirView * ADirView = DirView(Side);
  7234. TFileFilter Filter;
  7235. DefaultFileFilter(Filter);
  7236. if (DoSelectMaskDialog(ADirView, Select, &Filter, Configuration))
  7237. {
  7238. Configuration->Usage->Inc(L"MaskSelections");
  7239. ADirView->SelectFiles(Filter, Select);
  7240. ADirView->SetFocus();
  7241. }
  7242. }
  7243. //---------------------------------------------------------------------------
  7244. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7245. {
  7246. TCustomDirView * ADirView = DirView(Side);
  7247. ADirView->RestoreSelectedNames();
  7248. ADirView->SetFocus();
  7249. }
  7250. //---------------------------------------------------------------------------
  7251. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7252. {
  7253. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7254. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7255. {
  7256. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7257. UnicodeString Ext;
  7258. if (GetSide(osCurrent) == osRemote)
  7259. {
  7260. Ext = UnixExtractFileExt(FileName);
  7261. }
  7262. else
  7263. {
  7264. Ext = ExtractFileExt(FileName);
  7265. }
  7266. if (Ext.IsEmpty())
  7267. {
  7268. Ext = L".";
  7269. }
  7270. TFileFilter Filter;
  7271. Filter.Masks = FORMAT(L"*%s", (Ext));
  7272. Filter.Directories = false;
  7273. CurrentDirView->SelectFiles(Filter, Select);
  7274. }
  7275. }
  7276. //---------------------------------------------------------------------------
  7277. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7278. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7279. {
  7280. UnicodeString Result;
  7281. if ((Side == osRemote) && (Terminal == NULL))
  7282. {
  7283. // noop
  7284. }
  7285. else
  7286. {
  7287. Result =
  7288. FMTLOAD(FILE_INFO_FORMAT,
  7289. (FormatBytes(FileInfo.SelectedSize),
  7290. FormatBytes(FileInfo.FilesSize),
  7291. FormatNumber(FileInfo.SelectedCount),
  7292. FormatNumber(FileInfo.FilesCount)));
  7293. }
  7294. return Result;
  7295. }
  7296. //---------------------------------------------------------------------------
  7297. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7298. TTBXStatusPanel * Panel, TOperationSide Side)
  7299. {
  7300. if (Panel->Index == 1)
  7301. {
  7302. ToggleShowHiddenFiles();
  7303. }
  7304. else if (Panel->Index == 2)
  7305. {
  7306. Filter(Side);
  7307. }
  7308. }
  7309. //---------------------------------------------------------------------------
  7310. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  7311. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  7312. {
  7313. DebugAssert(!StatusBar->SimplePanel);
  7314. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  7315. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  7316. }
  7317. //---------------------------------------------------------------------------
  7318. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  7319. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  7320. {
  7321. DebugAssert(StatusBar->Panels->Count >= 3);
  7322. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  7323. if (FileInfo.HiddenCount > 0)
  7324. {
  7325. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  7326. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7327. }
  7328. else
  7329. {
  7330. HiddenFilesPanel->ViewPriority = 0;
  7331. // not really necessary, just to cleanup no-longer-valid data
  7332. HiddenFilesPanel->Caption = L"";
  7333. }
  7334. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  7335. if (FileInfo.FilteredCount > 0)
  7336. {
  7337. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  7338. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7339. }
  7340. else
  7341. {
  7342. FilteredFilesPanel->ViewPriority = 0;
  7343. // not really necessary, just to cleanup no-longer-valid data
  7344. FilteredFilesPanel->Caption = L"";
  7345. }
  7346. }
  7347. //---------------------------------------------------------------------------
  7348. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  7349. TObject * /*Sender*/)
  7350. {
  7351. if (RemoteDirView->Enabled)
  7352. {
  7353. RemoteDirView->SetFocus();
  7354. }
  7355. }
  7356. //---------------------------------------------------------------------------
  7357. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  7358. {
  7359. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  7360. switch (Config.Show)
  7361. {
  7362. case qvShow:
  7363. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  7364. {
  7365. Config.Show = qvHide;
  7366. }
  7367. else
  7368. {
  7369. Config.Show = Config.LastHideShow;
  7370. }
  7371. break;
  7372. case qvHideWhenEmpty:
  7373. if (ComponentVisible[fcQueueView])
  7374. {
  7375. Config.Show = qvHide;
  7376. }
  7377. else
  7378. {
  7379. Config.LastHideShow = Config.Show;
  7380. Config.Show = qvShow;
  7381. }
  7382. break;
  7383. case qvHide:
  7384. Config.LastHideShow = Config.Show;
  7385. Config.Show = qvShow;
  7386. break;
  7387. }
  7388. WinConfiguration->QueueView = Config;
  7389. }
  7390. //---------------------------------------------------------------------------
  7391. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  7392. {
  7393. UnicodeString Result;
  7394. if (FTerminal != NULL)
  7395. {
  7396. switch (WinConfiguration->PathInCaption)
  7397. {
  7398. case picShort:
  7399. {
  7400. Result = UnixExtractFileName(FTerminal->CurrentDirectory);
  7401. if (Result.IsEmpty())
  7402. {
  7403. Result = FTerminal->CurrentDirectory;
  7404. }
  7405. }
  7406. break;
  7407. case picFull:
  7408. Result = FTerminal->CurrentDirectory;
  7409. break;
  7410. }
  7411. }
  7412. return Result;
  7413. }
  7414. //---------------------------------------------------------------------------
  7415. void __fastcall TCustomScpExplorerForm::UpdateControls()
  7416. {
  7417. TTerminalManager::Instance()->UpdateAppTitle();
  7418. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  7419. // background to gray on Windows 7 (works on Windows 10).
  7420. // See also EnableControl
  7421. if (Showing)
  7422. {
  7423. bool HasTerminal = (Terminal != NULL);
  7424. if (HasTerminal)
  7425. {
  7426. if (!RemoteDirView->Enabled)
  7427. {
  7428. RemoteDirView->Enabled = true;
  7429. if (FRemoteDirViewWasFocused)
  7430. {
  7431. ActiveControl = RemoteDirView;
  7432. }
  7433. }
  7434. RemoteDriveView->Enabled = true;
  7435. RemoteDirView->Color = (FSessionColor != 0 ? FSessionColor : clWindow);
  7436. RemoteDriveView->Color = RemoteDirView->Color;
  7437. }
  7438. else
  7439. {
  7440. if (RemoteDirView->Enabled)
  7441. {
  7442. // This is first called when the form is being constructed
  7443. // (not anymore due to Showing test above)
  7444. // but the false is overriden in the constructor later.
  7445. // An even later in TScpCommanderForm::DoShow()
  7446. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  7447. EnableControl(RemoteDirView, false);
  7448. }
  7449. EnableControl(RemoteDriveView, false);
  7450. }
  7451. EnableControl(QueueView3, HasTerminal);
  7452. QueueLabelUpdateStatus();
  7453. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  7454. }
  7455. }
  7456. //---------------------------------------------------------------------------
  7457. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  7458. {
  7459. UpdateControls();
  7460. }
  7461. //---------------------------------------------------------------------------
  7462. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  7463. TObject * Sender)
  7464. {
  7465. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7466. DebugAssert(DirView != NULL);
  7467. DoDirViewLoaded(DirView);
  7468. TransferPresetAutoSelect();
  7469. }
  7470. //---------------------------------------------------------------------------
  7471. void __fastcall TCustomScpExplorerForm::StartUpdates()
  7472. {
  7473. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  7474. // first run after installation
  7475. if (double(Updates.LastCheck) == 0)
  7476. {
  7477. // make sure next time there will be an update (if enabled)
  7478. Updates.LastCheck = TDateTime(1);
  7479. WinConfiguration->Updates = Updates;
  7480. }
  7481. else if ((double(Updates.Period) > 0) &&
  7482. (Now() - Updates.LastCheck >= Updates.Period))
  7483. {
  7484. StartUpdateThread(UpdatesChecked);
  7485. }
  7486. }
  7487. //---------------------------------------------------------------------------
  7488. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  7489. {
  7490. UnicodeString Message;
  7491. bool New;
  7492. TQueryType Type;
  7493. GetUpdatesMessage(Message, New, Type, false);
  7494. if (!Message.IsEmpty())
  7495. {
  7496. if (New)
  7497. {
  7498. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  7499. }
  7500. if (!New && (Type != qtWarning))
  7501. {
  7502. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  7503. }
  7504. else
  7505. {
  7506. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  7507. }
  7508. if (New)
  7509. {
  7510. Configuration->Usage->Inc(L"UpdateNotifications");
  7511. }
  7512. }
  7513. }
  7514. //---------------------------------------------------------------------------
  7515. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  7516. {
  7517. RestoreApp();
  7518. bool CanDisplay = !NonVisualDataModule->Busy;
  7519. if (!CanDisplay && (Screen->ActiveForm != NULL))
  7520. {
  7521. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  7522. }
  7523. if (CanDisplay)
  7524. {
  7525. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  7526. CheckForUpdates(true);
  7527. }
  7528. else
  7529. {
  7530. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  7531. }
  7532. }
  7533. //---------------------------------------------------------------------------
  7534. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  7535. TCopyParamRuleData & Data)
  7536. {
  7537. DebugAssert(Terminal != NULL);
  7538. Data.HostName = Terminal->SessionData->HostNameExpanded;
  7539. Data.UserName = Terminal->SessionData->UserNameExpanded;
  7540. Data.RemoteDirectory = RemoteDirView->PathName;
  7541. }
  7542. //---------------------------------------------------------------------------
  7543. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  7544. {
  7545. // Terminal can be null when we are changing local directory implicitly,
  7546. // because it has been deleted, while no session is connected
  7547. // (Login dialog is open)
  7548. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  7549. {
  7550. TCopyParamRuleData Data;
  7551. GetTransferPresetAutoSelectData(Data);
  7552. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  7553. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  7554. if (CopyParamIndex < 0)
  7555. {
  7556. // there is no preset that matches autoselection
  7557. // set preset that we consider "default"
  7558. FCopyParamAutoSelected = L""; // forget last autoselected preset
  7559. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  7560. }
  7561. else
  7562. {
  7563. // there is preset matching autoselection
  7564. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  7565. if (CopyParamName == FCopyParamAutoSelected)
  7566. {
  7567. // autoselected the same preset as the last time
  7568. // make no change (i.e. preserve custom user preset, if any)
  7569. }
  7570. else
  7571. {
  7572. // autoselected the different preset then the last time (or there
  7573. // was default preset set)
  7574. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  7575. GUIConfiguration->CopyParamCurrent = CopyParamName;
  7576. }
  7577. }
  7578. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  7579. {
  7580. if (CopyParamIndex >= 0)
  7581. {
  7582. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  7583. }
  7584. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  7585. try
  7586. {
  7587. int Fmt =
  7588. (CopyParamIndex < 0) ?
  7589. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  7590. COPY_PARAM_AUTOSELECTED;
  7591. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  7592. Data->Message = MainInstructions(Message);
  7593. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  7594. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  7595. CopyParamAttrs);
  7596. if (CopyParamIndex >= 0)
  7597. {
  7598. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  7599. Info = FORMAT(L"%s\n \n%s", (Info,
  7600. FMTLOAD(COPY_PARAM_RULE,
  7601. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  7602. }
  7603. Data->Message += L"\n\n" + Info;
  7604. if (WinConfiguration->CopyParamAutoSelectNotice)
  7605. {
  7606. TransferPresetNoteMessage(Data, true);
  7607. }
  7608. else
  7609. {
  7610. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  7611. Data = NULL; // ownership passed
  7612. }
  7613. }
  7614. __finally
  7615. {
  7616. delete Data;
  7617. }
  7618. }
  7619. }
  7620. }
  7621. //---------------------------------------------------------------------------
  7622. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  7623. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  7624. {
  7625. DebugAssert(NoteData != NULL);
  7626. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  7627. TQueryButtonAlias Aliases[1];
  7628. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  7629. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  7630. Params.Aliases = Aliases;
  7631. Params.AliasesCount = LENOF(Aliases);
  7632. unsigned int Result =
  7633. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  7634. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  7635. switch (Result)
  7636. {
  7637. case qaNeverAskAgain:
  7638. DebugAssert(AllowNeverAskAgain);
  7639. WinConfiguration->CopyParamAutoSelectNotice = false;
  7640. break;
  7641. case qaIgnore:
  7642. PreferencesDialog(pmPresets);
  7643. break;
  7644. }
  7645. }
  7646. //---------------------------------------------------------------------------
  7647. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  7648. {
  7649. // as of now useless, as this is used for notes only, never for balloons, ...
  7650. RestoreApp();
  7651. // .. and we should never be busy here
  7652. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  7653. {
  7654. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  7655. }
  7656. }
  7657. //---------------------------------------------------------------------------
  7658. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  7659. TPreferencesMode APreferencesMode)
  7660. {
  7661. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  7662. TCopyParamRuleData Data;
  7663. if (Terminal != NULL)
  7664. {
  7665. PreferencesData.reset(new TPreferencesDialogData());
  7666. GetTransferPresetAutoSelectData(Data);
  7667. PreferencesData->CopyParamRuleData = &Data;
  7668. }
  7669. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  7670. }
  7671. //---------------------------------------------------------------------------
  7672. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  7673. const TCustomCommandType & Command)
  7674. {
  7675. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  7676. {
  7677. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (Command.Command)));
  7678. }
  7679. }
  7680. //---------------------------------------------------------------------------
  7681. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  7682. {
  7683. bool RemoteAllowed = CustomCommandRemoteAllowed();
  7684. TCustomCommandType Command;
  7685. // make sure we use local custom command when remote are not supported
  7686. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  7687. {
  7688. Command = FLastCustomCommand;
  7689. }
  7690. else
  7691. {
  7692. Command.Params = Command.Params | ccLocal;
  7693. }
  7694. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  7695. FEditingFocusedAdHocCommand = OnFocused;
  7696. bool LocalSide = (FCurrentSide == osLocal);
  7697. int Options =
  7698. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  7699. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  7700. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  7701. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  7702. {
  7703. FLastCustomCommand = Command;
  7704. UpdateCustomCommandsToolbar();
  7705. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  7706. }
  7707. }
  7708. //---------------------------------------------------------------------------
  7709. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  7710. {
  7711. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  7712. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  7713. DebugAssert(State > 0);
  7714. if (State <= 0)
  7715. {
  7716. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (FLastCustomCommand.Command)));
  7717. }
  7718. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  7719. }
  7720. //---------------------------------------------------------------------------
  7721. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  7722. TCustomCommandType & Command, int & State)
  7723. {
  7724. bool Result = !FLastCustomCommand.Command.IsEmpty();
  7725. if (Result)
  7726. {
  7727. Command = FLastCustomCommand;
  7728. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  7729. }
  7730. return Result;
  7731. }
  7732. //---------------------------------------------------------------------------
  7733. void __fastcall TCustomScpExplorerForm::BeforeAction()
  7734. {
  7735. if (RemoteDirView->ItemFocused != NULL)
  7736. {
  7737. RemoteDirView->ItemFocused->CancelEdit();
  7738. }
  7739. }
  7740. //---------------------------------------------------------------------------
  7741. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  7742. {
  7743. DebugAssert(ComponentVisible[Component]);
  7744. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  7745. }
  7746. //---------------------------------------------------------------------------
  7747. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  7748. {
  7749. // when queue panel is resized here directly, the status bar is stretched
  7750. // over whole space the panel occupied
  7751. PostComponentHide(fcQueueView);
  7752. }
  7753. //---------------------------------------------------------------------------
  7754. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  7755. {
  7756. TMessage * M = static_cast<TMessage*>(Message);
  7757. switch (M->Msg)
  7758. {
  7759. case CM_DIALOGCHAR:
  7760. CMDialogChar(*M);
  7761. break;
  7762. case WM_APPCOMMAND:
  7763. WMAppCommand(*M);
  7764. break;
  7765. case WM_SYSCOMMAND:
  7766. WMSysCommand(*M);
  7767. break;
  7768. case WM_QUERYENDSESSION:
  7769. WMQueryEndSession(*M);
  7770. break;
  7771. case WM_ENDSESSION:
  7772. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  7773. break;
  7774. #ifdef _DEBUG
  7775. case WM_WINDOWPOSCHANGED:
  7776. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  7777. break;
  7778. case CM_CUSTOMSTYLECHANGED:
  7779. TForm::Dispatch(Message);
  7780. break;
  7781. #endif
  7782. case WM_COMPONENT_HIDE:
  7783. {
  7784. Byte Component = static_cast<Byte>(M->WParam);
  7785. // sanity check
  7786. if (ComponentVisible[Component])
  7787. {
  7788. // special treatment
  7789. if (Component == fcQueueView)
  7790. {
  7791. ToggleQueueVisibility();
  7792. DebugAssert(!ComponentVisible[fcQueueView]);
  7793. }
  7794. else
  7795. {
  7796. ComponentVisible[Component] = false;
  7797. }
  7798. }
  7799. }
  7800. break;
  7801. case WM_COPYDATA:
  7802. WMCopyData(*M);
  7803. break;
  7804. case WM_MANAGES_CAPTION:
  7805. // caption managed in TTerminalManager::UpdateAppTitle()
  7806. M->Result = 1;
  7807. break;
  7808. case WM_WANTS_MOUSEWHEEL:
  7809. M->Result = 1;
  7810. break;
  7811. case CM_SHOWINGCHANGED:
  7812. CMShowingChanged(*M);
  7813. break;
  7814. case WM_CLOSE:
  7815. WMClose(*M);
  7816. break;
  7817. case WM_DPICHANGED:
  7818. WMDpiChanged(*M);
  7819. break;
  7820. case CM_DPICHANGED:
  7821. CMDpiChanged(*M);
  7822. break;
  7823. default:
  7824. TForm::Dispatch(Message);
  7825. break;
  7826. }
  7827. }
  7828. //---------------------------------------------------------------------------
  7829. void __fastcall TCustomScpExplorerForm::UpdateImages()
  7830. {
  7831. // noop
  7832. }
  7833. //---------------------------------------------------------------------------
  7834. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  7835. {
  7836. TForm::Dispatch(&Message);
  7837. // regenerate session images
  7838. DoTerminalListChanged(true);
  7839. UpdateImages();
  7840. }
  7841. //---------------------------------------------------------------------------
  7842. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  7843. {
  7844. TForm::Dispatch(&Message);
  7845. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  7846. UpdatePixelsPerInchMainWindowCounter();
  7847. }
  7848. //---------------------------------------------------------------------------
  7849. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  7850. {
  7851. // Cannot close window while we are busy.
  7852. // We cannot test this in FormCloseQuery as that is called also from
  7853. // Close(), which is called by CloseApplicationAction. So we can be busy
  7854. // there already even, when it is legitimate to close the application.
  7855. // Possibly a better place to handle this would be WMSysCommand.
  7856. if (NonVisualDataModule->Busy)
  7857. {
  7858. Message.Result = 1;
  7859. }
  7860. else
  7861. {
  7862. TForm::Dispatch(&Message);
  7863. }
  7864. }
  7865. //---------------------------------------------------------------------------
  7866. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  7867. {
  7868. TForm::Dispatch(&Message);
  7869. if (Showing && (Terminal == NULL))
  7870. {
  7871. // When we are starting minimized (i.e. from an installer),
  7872. // postpone showing Login dialog until we get restored.
  7873. // Otherwise the Login dialog (and Authentication window) show restored
  7874. // over invidible (minimized) main window.
  7875. if (WindowState == wsMinimized)
  7876. {
  7877. FNeedSession = true;
  7878. }
  7879. else
  7880. {
  7881. // This happens before application ever goes idle, so the toolbars would
  7882. // stay enabled (initial state) until the Login dialog is dismissed.
  7883. UpdateActions();
  7884. NonVisualDataModule->StartBusy();
  7885. try
  7886. {
  7887. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  7888. // otherwise the dialog does not receive focus.
  7889. // With Commander interface the ProcessMessages is called already
  7890. // by TDriveView, but with Explorer interface, we need to call it explicily
  7891. Application->ProcessMessages();
  7892. // do not reload sessions, they have been loaded just now (optimization)
  7893. NeedSession(false);
  7894. }
  7895. __finally
  7896. {
  7897. NonVisualDataModule->EndBusy();
  7898. }
  7899. }
  7900. }
  7901. }
  7902. //---------------------------------------------------------------------------
  7903. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  7904. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  7905. int & MaxHeight)
  7906. {
  7907. // workaround for bug in TWinControl.CalcConstraints
  7908. // Check for empty rect (restore from iconic state) is done there only after
  7909. // call to AdjustClientRect, which enlarges the rect (for forms).
  7910. TRect R = GetClientRect();
  7911. // when restoring from iconic state, place no restrictions
  7912. if (IsRectEmpty(R))
  7913. {
  7914. MinWidth = 0;
  7915. MinHeight = 0;
  7916. MaxWidth = 32000;
  7917. MaxHeight = 32000;
  7918. }
  7919. }
  7920. //---------------------------------------------------------------------------
  7921. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  7922. TSpaceAvailable & ASpaceAvailable, bool & Close)
  7923. {
  7924. // terminal can be already closed (e.g. dropped connection)
  7925. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  7926. {
  7927. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  7928. try
  7929. {
  7930. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  7931. }
  7932. catch(...)
  7933. {
  7934. if (!Terminal->Active)
  7935. {
  7936. Close = true;
  7937. }
  7938. throw;
  7939. }
  7940. }
  7941. }
  7942. //---------------------------------------------------------------------------
  7943. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  7944. {
  7945. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  7946. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  7947. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  7948. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  7949. {
  7950. OnGetSpaceAvailable = GetSpaceAvailable;
  7951. }
  7952. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  7953. OnGetSpaceAvailable);
  7954. }
  7955. //---------------------------------------------------------------------------
  7956. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  7957. {
  7958. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  7959. Terminal->FillSessionDataForCode(Data.get());
  7960. return Data.release();
  7961. }
  7962. //---------------------------------------------------------------------------
  7963. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  7964. {
  7965. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  7966. DoGenerateUrlDialog(Data.get(), Paths);
  7967. }
  7968. //---------------------------------------------------------------------------
  7969. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  7970. {
  7971. GenerateUrl(NULL);
  7972. }
  7973. //---------------------------------------------------------------------------
  7974. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  7975. {
  7976. std::unique_ptr<TStrings> Paths(new TStringList());
  7977. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  7978. GenerateUrl(Paths.get());
  7979. }
  7980. //---------------------------------------------------------------------------
  7981. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  7982. {
  7983. if (value != FSessionColor)
  7984. {
  7985. FSessionColor = value;
  7986. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  7987. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  7988. static_cast<TObject *>(GetComponent(fcColorMenu)));
  7989. DebugAssert(ColorItem != NULL);
  7990. ColorItem->Color = C;
  7991. NonVisualDataModule->ColorMenuItem->Color = C;
  7992. // Is null when called from LastTerminalClosed
  7993. if (Terminal != NULL)
  7994. {
  7995. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  7996. }
  7997. UpdateControls();
  7998. }
  7999. }
  8000. //---------------------------------------------------------------------------
  8001. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8002. {
  8003. bool Result = FNoteTimer->Enabled;
  8004. if (Result)
  8005. {
  8006. // cannot cancel note too early
  8007. bool NotEarly =
  8008. (Now() - FNoteShown >
  8009. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8010. if (Force || NotEarly)
  8011. {
  8012. FNoteTimer->Enabled = false;
  8013. FNote = L"";
  8014. SAFE_DESTROY(FNoteData);
  8015. FOnNoteClick = NULL;
  8016. FNoteHints = FNotes->Text;
  8017. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8018. UpdateStatusBar();
  8019. }
  8020. }
  8021. return Result;
  8022. }
  8023. //---------------------------------------------------------------------------
  8024. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8025. {
  8026. DebugAssert(FNoteTimer->Enabled);
  8027. CancelNote(true);
  8028. }
  8029. //---------------------------------------------------------------------------
  8030. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8031. {
  8032. int P = Note.Pos(L"\n");
  8033. if (P > 0)
  8034. {
  8035. Note.SetLength(P - 1);
  8036. }
  8037. FNotes->Add(FORMAT(L"[%s] %s",
  8038. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8039. while (FNotes->Count > 10)
  8040. {
  8041. FNotes->Delete(0);
  8042. }
  8043. if (UpdateNow)
  8044. {
  8045. FNoteHints = FNotes->Text;
  8046. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8047. UpdateStatusBar();
  8048. }
  8049. }
  8050. //---------------------------------------------------------------------------
  8051. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8052. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8053. {
  8054. int P = Note.Pos(L"\n");
  8055. if (P > 0)
  8056. {
  8057. Note.SetLength(P - 1);
  8058. }
  8059. FNoteHints = FNotes->Text;
  8060. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8061. FNote = Note;
  8062. SAFE_DESTROY(FNoteData);
  8063. FNoteData = NoteData;
  8064. FOnNoteClick = OnNoteClick;
  8065. AddNote(Note, false);
  8066. UpdateStatusBar();
  8067. FNoteShown = Now();
  8068. FNoteTimer->Enabled = false;
  8069. if (Seconds == 0)
  8070. {
  8071. Seconds = WinConfiguration->NotificationsTimeout;
  8072. }
  8073. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8074. FNoteTimer->Enabled = true;
  8075. }
  8076. //---------------------------------------------------------------------------
  8077. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8078. {
  8079. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8080. }
  8081. //---------------------------------------------------------------------------
  8082. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8083. {
  8084. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked)
  8085. {
  8086. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8087. }
  8088. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8089. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8090. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  8091. 0, NULL, NULL);
  8092. }
  8093. //---------------------------------------------------------------------------
  8094. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8095. {
  8096. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8097. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8098. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8099. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8100. }
  8101. //---------------------------------------------------------------------------
  8102. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8103. {
  8104. WinConfiguration->FormatSizeBytes = Style;
  8105. }
  8106. //---------------------------------------------------------------------------
  8107. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8108. {
  8109. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8110. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8111. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8112. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8113. }
  8114. //---------------------------------------------------------------------------
  8115. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8116. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8117. {
  8118. if (Panel->Index == 0)
  8119. {
  8120. if (FOnNoteClick != NULL)
  8121. {
  8122. // prevent the user data from being freed by possible call
  8123. // to CancelNote or PostNote during call to OnNoteClick
  8124. std::unique_ptr<TObject> NoteData(FNoteData);
  8125. TNotifyEvent OnNoteClick = FOnNoteClick;
  8126. FNoteData = NULL;
  8127. // need to cancel the note as we are going to delete its user data
  8128. CancelNote(true);
  8129. OnNoteClick(NoteData.get());
  8130. }
  8131. }
  8132. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8133. {
  8134. FileSystemInfo();
  8135. }
  8136. }
  8137. //---------------------------------------------------------------------------
  8138. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8139. {
  8140. // workaround:
  8141. // 1) for unknown reason, disabling window, while minimized,
  8142. // prevents it from restoring, even if it was enabled again meanwhile
  8143. // 2) when disabling the main window, while another has focus
  8144. // minimize is no longer possible
  8145. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8146. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8147. // Shouldn't we use IsApplicationMinimized() here?
  8148. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8149. {
  8150. Enabled = false;
  8151. }
  8152. FLockLevel++;
  8153. }
  8154. //---------------------------------------------------------------------------
  8155. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8156. {
  8157. DebugAssert(FLockLevel > 0);
  8158. FLockLevel--;
  8159. if (FLockLevel == 0)
  8160. {
  8161. DebugAssert(FLockSuspendLevel == 0);
  8162. Enabled = true;
  8163. }
  8164. }
  8165. //---------------------------------------------------------------------------
  8166. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8167. {
  8168. // We need to make sure that window is enabled when the last modal window closes
  8169. // otherwise focus is not restored correctly.
  8170. // So we re-enable the window when modal window opens and
  8171. // disable it back after is closes
  8172. if (FLockLevel > 0)
  8173. {
  8174. // while we have nesting counter, we know that we never be called
  8175. // recursivelly as Application->OnModalBegin is called only
  8176. // for the top-level modal window
  8177. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8178. {
  8179. // won't be disabled when conditions in LockWindow() were not satisfied
  8180. FDisabledOnLockSuspend = !Enabled;
  8181. // When minimized to tray (or actually when set to SW_HIDE),
  8182. // setting Enabled makes the window focusable even when there's
  8183. // modal window over it
  8184. if (!FTrayIcon->Visible)
  8185. {
  8186. Enabled = true;
  8187. }
  8188. }
  8189. FLockSuspendLevel++;
  8190. }
  8191. }
  8192. //---------------------------------------------------------------------------
  8193. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8194. {
  8195. if (FLockSuspendLevel > 0)
  8196. {
  8197. DebugAssert(FLockLevel > 0);
  8198. FLockSuspendLevel--;
  8199. // see comment in SuspendWindowLock
  8200. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8201. {
  8202. // Note that window can be enabled here, when we were minized to tray when
  8203. // was SuspendWindowLock() called.
  8204. // We should possibly do the same check as in LockWindow(),
  8205. // if it is ever possible that the consitions change between
  8206. // SuspendWindowLock() and ResumeWindowLock()
  8207. Enabled = !FDisabledOnLockSuspend;
  8208. }
  8209. }
  8210. }
  8211. //---------------------------------------------------------------------------
  8212. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8213. {
  8214. if (!TextOnly)
  8215. {
  8216. TTBXComboBoxItem * RemotePathComboBox =
  8217. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8218. TStrings * Items = RemotePathComboBox->Strings;
  8219. Items->BeginUpdate();
  8220. try
  8221. {
  8222. Items->Clear();
  8223. if (Terminal != NULL)
  8224. {
  8225. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8226. while (!IsUnixRootPath(APath))
  8227. {
  8228. int P = APath.LastDelimiter(L'/');
  8229. DebugAssert(P >= 0);
  8230. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8231. APath.SetLength(P - 1);
  8232. }
  8233. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8234. }
  8235. }
  8236. __finally
  8237. {
  8238. RemotePathComboBox->ItemIndex = Items->Count - 1;
  8239. // Setting ItemIndex to -1 does not reset its text
  8240. if (Items->Count == 0)
  8241. {
  8242. RemotePathComboBox->Text = L"";
  8243. }
  8244. Items->EndUpdate();
  8245. }
  8246. }
  8247. }
  8248. //---------------------------------------------------------------------------
  8249. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  8250. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  8251. int & ImageIndex)
  8252. {
  8253. if (AIndex < 0)
  8254. {
  8255. AIndex = Sender->ItemIndex;
  8256. }
  8257. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  8258. }
  8259. //---------------------------------------------------------------------------
  8260. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  8261. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  8262. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  8263. {
  8264. ARect.Left += (10 * AIndex);
  8265. }
  8266. //---------------------------------------------------------------------------
  8267. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  8268. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  8269. {
  8270. AWidth += (10 * AIndex);
  8271. }
  8272. //---------------------------------------------------------------------------
  8273. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  8274. TObject * Sender)
  8275. {
  8276. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  8277. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8278. int Index = RemotePathComboBox->ItemIndex;
  8279. while (Index < RemotePathComboBox->Strings->Count - 1)
  8280. {
  8281. APath = UnixExtractFileDir(APath);
  8282. Index++;
  8283. }
  8284. // VanDyke style paths
  8285. if (APath.IsEmpty())
  8286. {
  8287. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  8288. APath = ROOTDIRECTORY;
  8289. }
  8290. if (RemoteDirView->Path != APath)
  8291. {
  8292. RemoteDirView->Path = APath;
  8293. }
  8294. }
  8295. //---------------------------------------------------------------------------
  8296. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  8297. {
  8298. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  8299. DebugUsedParam(Sender);
  8300. UpdateRemotePathComboBox(true);
  8301. }
  8302. //---------------------------------------------------------------------------
  8303. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  8304. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  8305. {
  8306. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8307. DebugAssert(DirView != NULL);
  8308. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  8309. {
  8310. HWND Edit = ListView_GetEditControl(DirView->Handle);
  8311. // OnEditing is called also from TCustomListView::CanEdit
  8312. if (Edit != NULL)
  8313. {
  8314. EditSelectBaseName(Edit);
  8315. }
  8316. }
  8317. }
  8318. //---------------------------------------------------------------------------
  8319. //---------------------------------------------------------------------------
  8320. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  8321. {
  8322. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  8323. Result->AutoDetectDnD = false;
  8324. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  8325. Result->RenderDataOn = rdoEnterAndDropSync;
  8326. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  8327. return Result;
  8328. }
  8329. //---------------------------------------------------------------------------
  8330. void __fastcall TCustomScpExplorerForm::CreateWnd()
  8331. {
  8332. TForm::CreateWnd();
  8333. if (FSessionsDragDropFilesEx == NULL)
  8334. {
  8335. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  8336. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  8337. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  8338. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  8339. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  8340. }
  8341. if (FQueueDragDropFilesEx == NULL)
  8342. {
  8343. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  8344. // No need to set OnDragOver as we do not have any restrictions
  8345. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  8346. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  8347. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  8348. }
  8349. }
  8350. //---------------------------------------------------------------------------
  8351. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  8352. {
  8353. TForm::DestroyWnd();
  8354. FSessionsDragDropFilesEx->DragDropControl = NULL;
  8355. FQueueDragDropFilesEx->DragDropControl = NULL;
  8356. }
  8357. //---------------------------------------------------------------------------
  8358. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  8359. {
  8360. SideEnter(FCurrentSide);
  8361. FEverShown = true;
  8362. }
  8363. //---------------------------------------------------------------------------
  8364. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  8365. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  8366. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  8367. {
  8368. if (!NonVisualDataModule->Busy)
  8369. {
  8370. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8371. Configuration->Usage->Inc(L"FileFinds");
  8372. LockWindow(true);
  8373. NonVisualDataModule->StartBusy();
  8374. WinConfiguration->LockedInterface = true;
  8375. try
  8376. {
  8377. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  8378. }
  8379. __finally
  8380. {
  8381. WinConfiguration->LockedInterface = false;
  8382. NonVisualDataModule->EndBusy();
  8383. UnlockWindow();
  8384. }
  8385. }
  8386. }
  8387. //---------------------------------------------------------------------------
  8388. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  8389. {
  8390. if (!NonVisualDataModule->Busy)
  8391. {
  8392. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8393. SetFocus();
  8394. RemoteDirView->Path = UnixExtractFilePath(Path);
  8395. TListItem * Item = RemoteDirView->FindFileItem(UnixExtractFileName(Path));
  8396. if (Item != NULL)
  8397. {
  8398. RemoteDirView->ItemFocused = Item;
  8399. RemoteDirView->ItemFocused->MakeVisible(false);
  8400. RemoteDirView->SetFocus();
  8401. }
  8402. }
  8403. }
  8404. //---------------------------------------------------------------------------
  8405. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  8406. {
  8407. bool Result = !NonVisualDataModule->Busy;
  8408. if (Result)
  8409. {
  8410. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8411. }
  8412. return Result;
  8413. }
  8414. //---------------------------------------------------------------------------
  8415. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  8416. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8417. {
  8418. if (CanOperateOnFoundFiles(ATerminal))
  8419. {
  8420. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  8421. FOnFileOperationFinished = OnFileOperationFinished;
  8422. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  8423. }
  8424. }
  8425. //---------------------------------------------------------------------------
  8426. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  8427. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8428. {
  8429. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  8430. }
  8431. //---------------------------------------------------------------------------
  8432. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  8433. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8434. {
  8435. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  8436. }
  8437. //---------------------------------------------------------------------------
  8438. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  8439. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8440. {
  8441. if (CanOperateOnFoundFiles(ATerminal))
  8442. {
  8443. for (int Index = 0; Index < FileList->Count; Index++)
  8444. {
  8445. UnicodeString FileName = FileList->Strings[Index];
  8446. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  8447. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  8448. OnFileOperationFinished(FileName, true);
  8449. }
  8450. }
  8451. }
  8452. //---------------------------------------------------------------------------
  8453. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  8454. {
  8455. FFileFindTerminal = Terminal;
  8456. ShowFileFindDialog(
  8457. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  8458. DoDownloadFoundFiles, DoEditFoundFiles);
  8459. }
  8460. //---------------------------------------------------------------------------
  8461. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  8462. {
  8463. FTaskbarList = TaskbarList;
  8464. }
  8465. //---------------------------------------------------------------------------
  8466. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  8467. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  8468. {
  8469. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8470. if (Index >= 0)
  8471. {
  8472. if (Button == mbLeft)
  8473. {
  8474. // "Mouse down" is raised only after tab is switched.
  8475. // If switching tab (switching session) takes long enough for user
  8476. // to actually release the button, "mouse down" is still raised,
  8477. // but we do not get "mouse up" event, so dragging is not cancelled,
  8478. // prevent that by not beginning dragging in the first place.
  8479. if (IsKeyPressed(VK_LBUTTON))
  8480. {
  8481. // when user clicks the "+", we get mouse down only after the session
  8482. // is closed, when new session tab is already on X:Y, so dragging
  8483. // starts, prevent that
  8484. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  8485. {
  8486. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8487. if (Terminal != NULL)
  8488. {
  8489. SessionsPageControl->BeginDrag(false);
  8490. }
  8491. }
  8492. }
  8493. }
  8494. else if (Button == mbMiddle)
  8495. {
  8496. // ignore middle-click for "New session tab"
  8497. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8498. if (Terminal != NULL)
  8499. {
  8500. SessionsPageControl->ActivePageIndex = Index;
  8501. // Switch to session tab (has to be session tab, due to previous check)
  8502. if (DebugAlwaysTrue(SessionTabSwitched()))
  8503. {
  8504. CloseSession();
  8505. }
  8506. }
  8507. }
  8508. }
  8509. }
  8510. //---------------------------------------------------------------------------
  8511. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  8512. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  8513. {
  8514. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8515. // do not allow dropping on the "+" tab
  8516. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8517. if ((TargetTerminal != NULL) &&
  8518. (SessionsPageControl->ActivePage->PageIndex != Index))
  8519. {
  8520. Configuration->Usage->Inc(L"SessionTabMoves");
  8521. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  8522. // but we want to actually prevent that to avoid flicker
  8523. SessionsPageControl->ActivePage->PageIndex = Index;
  8524. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  8525. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  8526. }
  8527. }
  8528. //---------------------------------------------------------------------------
  8529. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  8530. TObject * Sender, TObject * Source, int X, int Y,
  8531. TDragState /*State*/, bool & Accept)
  8532. {
  8533. Accept = (Sender == Source);
  8534. if (Accept)
  8535. {
  8536. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8537. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8538. // do not allow dragging to the "+" tab
  8539. Accept = (Terminal != NULL);
  8540. }
  8541. }
  8542. //---------------------------------------------------------------------------
  8543. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(int /*KeyState*/,
  8544. const TPoint & Point, int & Effect)
  8545. {
  8546. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  8547. if (Index < 0)
  8548. {
  8549. Effect = DROPEFFECT_None;
  8550. }
  8551. else
  8552. {
  8553. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8554. // do not allow dropping on the "+" tab
  8555. if (TargetTerminal == NULL)
  8556. {
  8557. Effect = DROPEFFECT_None;
  8558. }
  8559. }
  8560. }
  8561. //---------------------------------------------------------------------------
  8562. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  8563. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  8564. {
  8565. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  8566. // do not allow dropping on the "+" tab
  8567. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8568. if (TargetTerminal != NULL)
  8569. {
  8570. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  8571. if (!IsFileControl(DropSourceControl, osRemote))
  8572. {
  8573. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  8574. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  8575. // Why don't we use Terminal->CurrentDirectory directly?
  8576. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory, false);
  8577. }
  8578. }
  8579. }
  8580. //---------------------------------------------------------------------------
  8581. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  8582. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  8583. {
  8584. // Downloads are handled in RemoteFileControlDDEnd
  8585. if (!IsFileControl(DropSourceControl, osRemote))
  8586. {
  8587. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  8588. Terminal->CurrentDirectory,
  8589. // force queue
  8590. true);
  8591. }
  8592. }
  8593. //---------------------------------------------------------------------------
  8594. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  8595. {
  8596. FShowing = false;
  8597. // Do not save empty workspace
  8598. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  8599. {
  8600. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  8601. UnicodeString Name = WorkspaceName();
  8602. DoSaveWorkspace(
  8603. Name, DataList.get(),
  8604. !Configuration->DisablePasswordStoring &&
  8605. WinConfiguration->AutoSaveWorkspacePasswords);
  8606. WinConfiguration->LastStoredSession = Name;
  8607. }
  8608. }
  8609. //---------------------------------------------------------------------------
  8610. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  8611. {
  8612. TManagedTerminal * ManagedTerminal =
  8613. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  8614. if (ManagedTerminal != NULL)
  8615. {
  8616. ManagedTerminal->DirectoryLoaded = Now();
  8617. }
  8618. }
  8619. //---------------------------------------------------------------------------
  8620. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  8621. TListItem * /*Item*/, bool /*Selected*/)
  8622. {
  8623. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  8624. switch (DirView->LastSelectMethod)
  8625. {
  8626. case smKeyboard:
  8627. Configuration->Usage->Inc(L"KeyboardSelections");
  8628. break;
  8629. case smMouse:
  8630. Configuration->Usage->Inc(L"MouseSelections");
  8631. break;
  8632. }
  8633. }
  8634. //---------------------------------------------------------------------------
  8635. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  8636. {
  8637. if (Color != 0)
  8638. {
  8639. AddSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  8640. return FSessionColors->Count - 1;
  8641. }
  8642. else
  8643. {
  8644. return FSessionTabImageIndex;
  8645. }
  8646. }
  8647. //---------------------------------------------------------------------------
  8648. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  8649. {
  8650. TPngImageCollectionItem * Item =
  8651. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  8652. FSessionColors->AddPng(Item->PngImage);
  8653. return FSessionColors->Count - 1;
  8654. }
  8655. //---------------------------------------------------------------------------
  8656. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  8657. {
  8658. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  8659. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  8660. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  8661. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  8662. }
  8663. //---------------------------------------------------------------------------
  8664. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  8665. {
  8666. for (int Index = 0; Index < Control->ControlCount; Index++)
  8667. {
  8668. TControl * AControl = Control->Controls[Index];
  8669. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  8670. if (WinControl != NULL)
  8671. {
  8672. CollectItemsWithTextDisplayMode(WinControl);
  8673. }
  8674. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  8675. if (Toolbar != NULL)
  8676. {
  8677. // we care for top-level items only
  8678. TTBCustomItem * Items = Toolbar->Items;
  8679. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  8680. {
  8681. TTBCustomItem * Item = Items->Items[ItemIndex];
  8682. if (((Item->DisplayMode == nbdmImageAndText) ||
  8683. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  8684. EligibleForImageDisplayMode(Item))
  8685. {
  8686. FItemsWithTextDisplayMode.insert(Item);
  8687. }
  8688. }
  8689. }
  8690. }
  8691. }
  8692. //---------------------------------------------------------------------------
  8693. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  8694. {
  8695. return true;
  8696. }
  8697. //---------------------------------------------------------------------------
  8698. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  8699. {
  8700. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  8701. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  8702. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  8703. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  8704. bool Result = true;
  8705. while (Result && (i != FItemsWithTextDisplayMode.end()))
  8706. {
  8707. TTBCustomItem * Item = *i;
  8708. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  8709. if (Label != NULL)
  8710. {
  8711. // optimization
  8712. if (Label->Visible == SelectiveToolbarText)
  8713. {
  8714. Result = false;
  8715. }
  8716. else
  8717. {
  8718. Label->Visible = SelectiveToolbarText;
  8719. }
  8720. }
  8721. else
  8722. {
  8723. // optimization
  8724. if (Item->DisplayMode == DisplayMode)
  8725. {
  8726. Result = false;
  8727. }
  8728. else
  8729. {
  8730. Item->DisplayMode = DisplayMode;
  8731. }
  8732. }
  8733. ++i;
  8734. }
  8735. if (Result)
  8736. {
  8737. UpdateNewSessionTab();
  8738. }
  8739. return Result;
  8740. }
  8741. //---------------------------------------------------------------------------
  8742. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  8743. {
  8744. DebugFail();
  8745. }
  8746. //---------------------------------------------------------------------------
  8747. bool __fastcall TCustomScpExplorerForm::IsBusy()
  8748. {
  8749. // Among other, a lock level is non zero, while directory is being loaded,
  8750. // even when it happens as a result of dirview navigation,
  8751. // i.e. when TNonVisualDataModule is NOT FBusy.
  8752. // That's why the TNonVisualDataModule::GetBusy calls this method.
  8753. // Among other this prevents a panel auto update to occur while
  8754. // directory is changing.
  8755. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  8756. }
  8757. //---------------------------------------------------------------------------
  8758. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  8759. {
  8760. // While the window is disabled, we still seem to process menu shortcuts at least,
  8761. // so stop it at least here.
  8762. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  8763. return
  8764. (Allowed == aaUpdate) ||
  8765. !NonVisualDataModule->Busy;
  8766. }
  8767. //---------------------------------------------------------------------------
  8768. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  8769. {
  8770. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  8771. }
  8772. //---------------------------------------------------------------------------
  8773. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  8774. {
  8775. // This is somewhat redundant to LockWindow() call from
  8776. // TTerminalManager::TerminalReadDirectoryProgress.
  8777. // But disabling window is known not to block keyboard shorcuts
  8778. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  8779. if (Busy > 0)
  8780. {
  8781. if (NonVisualDataModule->Busy)
  8782. {
  8783. State = false;
  8784. }
  8785. else
  8786. {
  8787. NonVisualDataModule->StartBusy();
  8788. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  8789. LockWindow();
  8790. }
  8791. }
  8792. else if (Busy < 0)
  8793. {
  8794. UnlockWindow();
  8795. NonVisualDataModule->EndBusy();
  8796. }
  8797. else
  8798. {
  8799. State = NonVisualDataModule->Busy;
  8800. }
  8801. }
  8802. //---------------------------------------------------------------------------
  8803. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  8804. {
  8805. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  8806. // no context menu for "New session tab"
  8807. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  8808. {
  8809. SessionsPageControl->ActivePageIndex = Index;
  8810. if (DebugAlwaysTrue(SessionTabSwitched()))
  8811. {
  8812. // copied from TControl.WMContextMenu
  8813. SendCancelMode(SessionsPageControl);
  8814. // explicit popup instead of using PopupMenu property
  8815. // to avoid menu to popup somewhere within SessionTabSwitched above,
  8816. // while connecting yet not-connected session and hence
  8817. // allowing an access to commands over not-completelly connected session
  8818. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  8819. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  8820. PopupMenu->PopupComponent = SessionsPageControl;
  8821. PopupMenu->Popup(Point.x, Point.y);
  8822. }
  8823. }
  8824. Handled = true;
  8825. }
  8826. //---------------------------------------------------------------------------
  8827. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  8828. {
  8829. return (Terminal != NULL) && Terminal->Active && Terminal->IsCapable[fcChangePassword];
  8830. }
  8831. //---------------------------------------------------------------------------
  8832. void __fastcall TCustomScpExplorerForm::ChangePassword()
  8833. {
  8834. Configuration->Usage->Inc(L"PasswordChanges");
  8835. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  8836. ChangePasswordData->DisableAuthentationsExceptPassword();
  8837. ChangePasswordData->ChangePassword = true;
  8838. std::unique_ptr<TTerminal> ChangePasswordSession(
  8839. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  8840. ChangePasswordSession->AutoReadDirectory = false;
  8841. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  8842. {
  8843. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  8844. }
  8845. else
  8846. {
  8847. Configuration->Usage->Inc(L"PasswordChangesFailed");
  8848. }
  8849. }
  8850. //---------------------------------------------------------------------------
  8851. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  8852. {
  8853. TForm::ChangeScale(M, D);
  8854. int APixelsPerInch = GetControlPixelsPerInch(this);
  8855. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  8856. try
  8857. {
  8858. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  8859. }
  8860. __finally
  8861. {
  8862. GUIConfiguration->ChangeResourceModule(ResourceModule);
  8863. }
  8864. }
  8865. //---------------------------------------------------------------------------
  8866. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  8867. {
  8868. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  8869. }
  8870. //---------------------------------------------------------------------
  8871. class TPublicControl : public TControl
  8872. {
  8873. friend class TCustomScpExplorerForm;
  8874. };
  8875. //---------------------------------------------------------------------------
  8876. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  8877. {
  8878. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  8879. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  8880. }
  8881. //---------------------------------------------------------------------------