CustomScpExplorer.cpp 293 KB

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