CustomScpExplorer.cpp 293 KB

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