CustomScpExplorer.cpp 288 KB

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