CustomScpExplorer.cpp 289 KB

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