CustomScpExplorer.cpp 383 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590
  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 <algorithm>
  8. #include <Bookmarks.h>
  9. #include <Interface.h>
  10. #include <Exceptions.h>
  11. #include <CoreMain.h>
  12. #include <FileSystems.h>
  13. #include <TextsCore.h>
  14. #include <TextsWin.h>
  15. #include <HelpWin.h>
  16. #include <VCLCommon.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. #include <DirectoryMonitor.hpp>
  34. #include <System.IOUtils.hpp>
  35. //---------------------------------------------------------------------------
  36. #pragma package(smart_init)
  37. #pragma link "CustomDirView"
  38. #pragma link "CustomUnixDirView"
  39. #pragma link "IEListView"
  40. #pragma link "NortonLikeListView"
  41. #pragma link "UnixDirView"
  42. #pragma link "CustomDriveView"
  43. #pragma link "UnixDriveView"
  44. #pragma link "CustomDriveView"
  45. #pragma link "TB2Dock"
  46. #pragma link "TBXStatusBars"
  47. #pragma link "TB2Item"
  48. #pragma link "TB2Toolbar"
  49. #pragma link "ThemePageControl"
  50. #pragma link "PathLabel"
  51. #pragma resource "*.dfm"
  52. //---------------------------------------------------------------------------
  53. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  54. static const int SessionPanelCount = 3;
  55. //---------------------------------------------------------------------------
  56. class TMutexGuard
  57. {
  58. public:
  59. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  60. int Timeout = 5000)
  61. {
  62. FMutex = NULL;
  63. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  64. if (WaitResult == WAIT_TIMEOUT)
  65. {
  66. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  67. }
  68. else
  69. {
  70. FMutex = AMutex;
  71. }
  72. }
  73. ~TMutexGuard()
  74. {
  75. if (FMutex != NULL)
  76. {
  77. ReleaseMutex(FMutex);
  78. }
  79. }
  80. private:
  81. HANDLE FMutex;
  82. };
  83. //---------------------------------------------------------------------------
  84. class TWindowLock
  85. {
  86. public:
  87. TWindowLock(TCustomScpExplorerForm * Form) :
  88. FForm(Form)
  89. {
  90. FForm->LockWindow();
  91. }
  92. ~TWindowLock()
  93. {
  94. FForm->UnlockWindow();
  95. }
  96. private:
  97. TCustomScpExplorerForm * FForm;
  98. };
  99. //---------------------------------------------------------------------------
  100. TAutoBatch::TAutoBatch(TCustomScpExplorerForm * Form) :
  101. FForm(Form)
  102. {
  103. FForm->BatchStart(FBatchStorage);
  104. }
  105. //---------------------------------------------------------------------------
  106. TAutoBatch::~TAutoBatch()
  107. {
  108. FForm->BatchEnd(FBatchStorage);
  109. }
  110. //---------------------------------------------------------------------------
  111. struct TTransferOperationParam
  112. {
  113. TTransferOperationParam();
  114. UnicodeString TargetDirectory;
  115. bool Temp;
  116. bool DragDrop;
  117. int Options;
  118. TAutoSwitch Queue;
  119. };
  120. //---------------------------------------------------------------------------
  121. TTransferOperationParam::TTransferOperationParam()
  122. {
  123. Temp = false;
  124. DragDrop = false;
  125. Options = 0;
  126. Queue = asAuto;
  127. }
  128. //---------------------------------------------------------------------------
  129. class TTransferPresetNoteData : public TObject
  130. {
  131. public:
  132. UnicodeString Message;
  133. };
  134. //---------------------------------------------------------------------------
  135. class TTerminalNoteData : public TObject
  136. {
  137. public:
  138. TManagedTerminal * Terminal;
  139. };
  140. //---------------------------------------------------------------------------
  141. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  142. FFormRestored(false),
  143. TForm(Owner)
  144. {
  145. FInvalid = false;
  146. FCurrentSide = osRemote;
  147. FEverShown = false;
  148. FDocks = new TList();
  149. InitControls();
  150. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  151. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  152. NonVisualDataModule->ScpExplorer = this;
  153. RestoreParams();
  154. ConfigurationChanged();
  155. RemoteDirView->Invalidate();
  156. FAutoOperation = false;
  157. FOnFileOperationFinished = NULL;
  158. FPrimaryOperation = foNone;
  159. FForceExecution = false;
  160. FIgnoreNextDialogChar = 0;
  161. FErrorList = NULL;
  162. FSynchronizeProgressForm = NULL;
  163. FProgressForm = NULL;
  164. FRefreshLocalDirectory = false;
  165. FRefreshRemoteDirectory = false;
  166. FDDExtMapFile = NULL;
  167. // CreateMutexW keeps failing with ERROR_NOACCESS
  168. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  169. DebugAssert(FDDExtMutex != NULL);
  170. FDDTargetControl = NULL;
  171. FDelayedDeletionTimer = NULL;
  172. FDelayedDeletionList = new TStringList();
  173. FDDFileList = NULL;
  174. FPendingTempSpaceWarn = false;
  175. FCapturedLog = NULL;
  176. FDragDropOperation = false;
  177. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  178. FAllowTransferPresetAutoSelect = true;
  179. FSessionChanging = false;
  180. FCopyParamDefault = L"";
  181. FSynchronizeController = NULL;
  182. FPendingQueueActionItem = NULL;
  183. FLockLevel = 0;
  184. FLockSuspendLevel = 0;
  185. FDisabledOnLockSuspend = false;
  186. FAlternativeDelete = false;
  187. FTrayIcon = new ::TTrayIcon(0);
  188. FTrayIcon->OnClick = TrayIconClick;
  189. FMaxQueueLength = 0;
  190. FLastContextPopupScreenPoint = TPoint(-1, -1);
  191. FTransferResumeList = NULL;
  192. FDeletedFiles = NULL;
  193. FMoveToQueue = false;
  194. StandaloneOperation = false;
  195. FOnFeedSynchronizeError = NULL;
  196. FOnSynchronizeAbort = NULL;
  197. FSynchronizeTerminal = NULL;
  198. FNeedSession = false;
  199. FDoNotIdleCurrentTerminal = 0;
  200. FIncrementalSearching = 0;
  201. FIncrementalSearchHaveNext = false;
  202. FQueueFileList.reset(new TQueueFileList());
  203. FProgressSide = osCurrent;
  204. FCalculateSizeOperation = NULL;
  205. FDownloadingFromClipboard = false;
  206. FClipboardFakeMonitorsPendingReset = false;
  207. FEditorManager = new TEditorManager();
  208. FEditorManager->OnFileChange = ExecutedFileChanged;
  209. FEditorManager->OnFileReload = ExecutedFileReload;
  210. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  211. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  212. FLocalEditors = new TList();
  213. FQueueStatus = NULL;
  214. FQueueStatusSection = new TCriticalSection();
  215. FQueueStatusInvalidated = false;
  216. FQueueItemInvalidated = false;
  217. FQueueStatusUpdating = false;
  218. FQueueActedItem = NULL;
  219. FQueueController = new TQueueController(QueueView3);
  220. FUserActionTimer = new TTimer(this);
  221. FUserActionTimer->Enabled = false;
  222. FUserActionTimer->Interval = 10;
  223. FUserActionTimer->OnTimer = UserActionTimer;
  224. FNotes = new TStringList();
  225. FNoteTimer = new TTimer(this);
  226. FNoteTimer->Enabled = false;
  227. FNoteTimer->OnTimer = NoteTimer;
  228. FOnNoteClick = NULL;
  229. FOle32Library = LoadLibrary(L"Ole32.dll");
  230. FDragMoveCursor = FOle32Library != NULL ?
  231. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  232. UseSystemSettings(this);
  233. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  234. static_cast<TObject*>(GetComponent(fcTransferList)));
  235. DebugAssert(TransferList != NULL);
  236. FTransferListHoverIndex = -1;
  237. TransferList->OnChange = TransferListChange;
  238. TransferList->OnDrawItem = TransferListDrawItem;
  239. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))), true);
  240. SetSubmenu(NonVisualDataModule->ColorMenuItem, true);
  241. UseDesktopFont(SessionsPageControl);
  242. UpdateSessionsPageControlHeight();
  243. UseDesktopFont(RemoteDirView);
  244. UseDesktopFont(RemoteDriveView);
  245. UseDesktopFont(QueueView3);
  246. UseDesktopFont(QueueFileList);
  247. UseDesktopFont(QueueLabel);
  248. UseDesktopFont(RemoteStatusBar);
  249. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  250. QueueSplitter->ShowHint = true;
  251. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  252. QueueFileListSplitter->ShowHint = true;
  253. RemotePanelSplitter->ShowHint = true;
  254. UpdateImages();
  255. FCustomCommandMenu = CreateTBXPopupMenu(this);
  256. FCustomCommandLocalFileList = NULL;
  257. FCustomCommandRemoteFileList = NULL;
  258. FSessionColors = new TPngImageList(this);
  259. FSessionColors->ColorDepth = cd32Bit;
  260. AddFixedSessionImages();
  261. SessionsPageControl->Images = FSessionColors;
  262. UpdateQueueLabel();
  263. CreateHiddenWindow();
  264. StartUpdates();
  265. }
  266. //---------------------------------------------------------------------------
  267. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  268. {
  269. FInvalid = true;
  270. // this has to be one of the very first things to do
  271. StopUpdateThread();
  272. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  273. TTerminalManager::Instance()->ScpExplorer = NULL;
  274. delete FCustomCommandLocalFileList;
  275. delete FCustomCommandRemoteFileList;
  276. delete FCustomCommandMenu;
  277. delete FTrayIcon;
  278. FTrayIcon = NULL;
  279. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  280. delete FEditorManager;
  281. ForceCloseLocalEditors();
  282. delete FLocalEditors;
  283. HideFileFindDialog();
  284. if (FDelayedDeletionTimer)
  285. {
  286. DoDelayedDeletion(NULL);
  287. SAFE_DESTROY(FDelayedDeletionTimer);
  288. }
  289. SAFE_DESTROY(FDelayedDeletionList);
  290. // sometimes we do not get DDEnd so the list is not released
  291. SAFE_DESTROY(FDDFileList);
  292. DebugAssert(FSynchronizeController == NULL);
  293. CloseHandle(FDDExtMutex);
  294. FDDExtMutex = NULL;
  295. FreeLibrary(FOle32Library);
  296. FOle32Library = NULL;
  297. FDragMoveCursor = NULL;
  298. DebugAssert(!FErrorList);
  299. if (FEverShown)
  300. {
  301. // when window is never shown (like when running command-line operation),
  302. // particularly window site is not restored correctly (BoundsRect value set
  303. // in RestoreForm gets lost during handle allocation), so we do not want
  304. // it to be stored
  305. StoreParams();
  306. }
  307. ManagedSession = NULL;
  308. Queue = NULL;
  309. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  310. NonVisualDataModule->ScpExplorer = NULL;
  311. delete FQueueController;
  312. FQueueController = NULL;
  313. delete FQueueStatusSection;
  314. FQueueStatusSection = NULL;
  315. delete FQueueStatus;
  316. FQueueStatus = NULL;
  317. delete FUserActionTimer;
  318. FUserActionTimer = NULL;
  319. delete FNoteTimer;
  320. delete FNotes;
  321. delete FNoteData;
  322. SAFE_DESTROY(FDocks);
  323. SessionsPageControl->Images = NULL;
  324. // only after clearing Terminal (after SessionListChanged => ... => AddSessionColor is called)
  325. SAFE_DESTROY(FSessionColors);
  326. SAFE_DESTROY(FSessionsDragDropFilesEx);
  327. SAFE_DESTROY(FHistoryMenu[0][0]);
  328. SAFE_DESTROY(FHistoryMenu[0][1]);
  329. SAFE_DESTROY(FHistoryMenu[1][0]);
  330. SAFE_DESTROY(FHistoryMenu[1][1]);
  331. if (FHiddenWindow != NULL)
  332. {
  333. DestroyWindow(FHiddenWindow);
  334. FHiddenWindow = NULL;
  335. }
  336. }
  337. //---------------------------------------------------------------------------
  338. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  339. {
  340. std::unique_ptr<TSessionData> Data;
  341. if (!Session.IsEmpty())
  342. {
  343. bool DefaultsOnly;
  344. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  345. }
  346. TTerminalManager * Manager = TTerminalManager::Instance();
  347. for (int Index = 0; Index < Manager->Count; Index++)
  348. {
  349. TTerminal * Terminal = Manager->Sessions[Index];
  350. if (Session.IsEmpty() ||
  351. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  352. {
  353. if (Path.IsEmpty())
  354. {
  355. Terminal->ClearCaches();
  356. }
  357. else
  358. {
  359. Terminal->DirectoryModified(Path, true);
  360. }
  361. }
  362. }
  363. // We should flag a pending refresh for the background terminals or busy foreground terminals
  364. if (HasActiveTerminal() &&
  365. CanCommandLineFromAnotherInstance() &&
  366. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  367. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  368. {
  369. Terminal->ReloadDirectory();
  370. }
  371. }
  372. //---------------------------------------------------------------------------
  373. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  374. {
  375. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  376. size_t MessageSize = sizeof(TCopyDataMessage);
  377. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  378. if (Result)
  379. {
  380. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  381. Result = (Message.Version == TCopyDataMessage::Version1);
  382. if (Result)
  383. {
  384. switch (Message.Command)
  385. {
  386. case TCopyDataMessage::CommandCanCommandLine:
  387. Result = CanCommandLineFromAnotherInstance();
  388. break;
  389. case TCopyDataMessage::CommandCommandLine:
  390. {
  391. UnicodeString CommandLine(Message.CommandLine);
  392. Result = CommandLineFromAnotherInstance(CommandLine);
  393. }
  394. break;
  395. case TCopyDataMessage::RefreshPanel:
  396. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  397. break;
  398. case TCopyDataMessage::MainWindowCheck:
  399. Result = true;
  400. break;
  401. default:
  402. Result = false;
  403. break;
  404. }
  405. }
  406. }
  407. Message.Result = Result ? 1 : 0;
  408. }
  409. //---------------------------------------------------------------------------
  410. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  411. {
  412. WNDCLASS WindowClass = {0};
  413. WindowClass.lpfnWndProc = DefWindowProc;
  414. WindowClass.hInstance = HInstance;
  415. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  416. FHiddenWindow = NULL;
  417. if (RegisterClass(&WindowClass))
  418. {
  419. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  420. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  421. }
  422. }
  423. //---------------------------------------------------------------------------
  424. bool __fastcall TCustomScpExplorerForm::CanConsole()
  425. {
  426. return
  427. HasActiveTerminal() &&
  428. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  429. }
  430. //---------------------------------------------------------------------------
  431. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  432. {
  433. bool Result = Visible && !NonVisualDataModule->Busy;
  434. return Result;
  435. }
  436. //---------------------------------------------------------------------------
  437. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  438. const UnicodeString & CommandLine)
  439. {
  440. TProgramParams Params(CommandLine);
  441. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  442. if (Result)
  443. {
  444. NonVisualDataModule->StartBusy();
  445. try
  446. {
  447. // this action is initiated from another process,
  448. // so it's likely that our window is not visible,
  449. // and user won't see what is going on
  450. Application->BringToFront();
  451. // reload sessions as we may be asked to open a session
  452. // just stored by another instance
  453. StoredSessions->Reload();
  454. UnicodeString SessionName = Params.Param[1];
  455. std::unique_ptr<TObjectList> DataList(new TObjectList());
  456. try
  457. {
  458. UnicodeString DownloadFile; // unused
  459. int Flags = GetCommandLineParseUrlFlags(&Params);
  460. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this, Flags);
  461. }
  462. catch (EAbort &)
  463. {
  464. // Happens when opening session in PuTTY and in other situations,
  465. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  466. // to process the command-line on its own (or to pass it to yet another instance)
  467. }
  468. if (DataList->Count > 0)
  469. {
  470. TTerminalManager * Manager = TTerminalManager::Instance();
  471. Manager->ActiveSession = Manager->NewSessions(DataList.get());
  472. }
  473. }
  474. __finally
  475. {
  476. NonVisualDataModule->EndBusy();
  477. }
  478. }
  479. return Result;
  480. }
  481. //---------------------------------------------------------------------------
  482. TManagedTerminal * TCustomScpExplorerForm::GetTerminal()
  483. {
  484. TManagedTerminal * Result;
  485. if ((FManagedSession != NULL) && !FManagedSession->LocalBrowser)
  486. {
  487. Result = FManagedSession;
  488. }
  489. else
  490. {
  491. Result = NULL;
  492. }
  493. return Result;
  494. }
  495. //---------------------------------------------------------------------------
  496. void __fastcall TCustomScpExplorerForm::SetManagedSession(TManagedTerminal * value)
  497. {
  498. if (FManagedSession != value)
  499. {
  500. SessionChanging();
  501. DoSetManagedSession(value, false);
  502. }
  503. }
  504. //---------------------------------------------------------------------------
  505. void __fastcall TCustomScpExplorerForm::DoSetManagedSession(TManagedTerminal * value, bool Replace)
  506. {
  507. DebugAssert(!Replace || ((value != NULL) && !value->LocalBrowser));
  508. FManagedSession = value;
  509. {
  510. TValueRestorer<bool> AllowTransferPresetAutoSelectRestorer(FAllowTransferPresetAutoSelect);
  511. FAllowTransferPresetAutoSelect = false;
  512. TAutoFlag SessionChangingFlag(FSessionChanging);
  513. SessionChanged(Replace);
  514. }
  515. if (Terminal != NULL)
  516. {
  517. TransferPresetAutoSelect();
  518. }
  519. // Update app and tab titles, prevented above by FSessionChanging.
  520. UpdateControls();
  521. }
  522. //---------------------------------------------------------------------------
  523. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  524. {
  525. DoSetManagedSession(value, true);
  526. }
  527. //---------------------------------------------------------------------------
  528. void __fastcall TCustomScpExplorerForm::SessionChanging()
  529. {
  530. if (ManagedSession != NULL)
  531. {
  532. UpdateSession(ManagedSession);
  533. }
  534. }
  535. //---------------------------------------------------------------------------
  536. void __fastcall TCustomScpExplorerForm::SessionChanged(bool Replaced)
  537. {
  538. if (Terminal != NULL)
  539. {
  540. UpdateSessionColor((TColor)Terminal->StateData->Color);
  541. }
  542. if (!TTerminalManager::Instance()->Updating)
  543. {
  544. SessionListChanged();
  545. }
  546. if (Terminal != NULL)
  547. {
  548. TObject * State = NULL;
  549. if (WinConfiguration->PreservePanelState)
  550. {
  551. State = Terminal->RemoteExplorerState;
  552. DirView(osRemote)->AnnounceState(State);
  553. }
  554. try
  555. {
  556. if (Replaced)
  557. {
  558. RemoteDirView->ReplaceTerminal(Terminal);
  559. }
  560. else
  561. {
  562. RemoteDirView->Terminal = Terminal;
  563. }
  564. if (Terminal->Active)
  565. {
  566. Terminal->RefreshDirectory();
  567. }
  568. if (State != NULL)
  569. {
  570. DirView(osRemote)->RestoreState(State);
  571. }
  572. }
  573. __finally
  574. {
  575. DirView(osRemote)->AnnounceState(NULL);
  576. }
  577. }
  578. else
  579. {
  580. RemoteDirView->Terminal = NULL;
  581. }
  582. InitStatusBar();
  583. UpdateTransferList();
  584. // Update panels Enable state before refreshing the labels
  585. UpdateControls();
  586. }
  587. //---------------------------------------------------------------------------
  588. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  589. {
  590. if (Queue != value)
  591. {
  592. if (FQueue != NULL)
  593. {
  594. FQueue->OnListUpdate = NULL;
  595. FQueue->OnQueueItemUpdate = NULL;
  596. }
  597. FQueue = value;
  598. if (FQueue != NULL)
  599. {
  600. DebugAssert(FQueue->OnListUpdate == NULL);
  601. FQueue->OnListUpdate = QueueListUpdate;
  602. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  603. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  604. }
  605. QueueChanged();
  606. }
  607. }
  608. //---------------------------------------------------------------------------
  609. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  610. TListItem * Item)
  611. {
  612. if (FQueueActedItem == Item)
  613. {
  614. FQueueActedItem = NULL;
  615. if ((QueueView3->PopupMenu != NULL) &&
  616. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  617. {
  618. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  619. ReleaseCapture();
  620. }
  621. }
  622. if (Item->Data == FPendingQueueActionItem)
  623. {
  624. FPendingQueueActionItem = NULL;
  625. }
  626. }
  627. //---------------------------------------------------------------------------
  628. bool TCustomScpExplorerForm::IsAnythingQueued()
  629. {
  630. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  631. }
  632. //---------------------------------------------------------------------------
  633. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  634. {
  635. {
  636. TGuard Guard(FQueueStatusSection);
  637. FQueueStatusInvalidated = false;
  638. if (FQueue != NULL)
  639. {
  640. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  641. }
  642. }
  643. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  644. {
  645. FMaxQueueLength = FQueueStatus->Count;
  646. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  647. }
  648. {
  649. TAutoFlag Flag(FQueueStatusUpdating);
  650. FQueueController->UpdateQueueStatus(FQueueStatus);
  651. }
  652. UpdateQueueFileList();
  653. SetQueueProgress();
  654. UpdateQueueView();
  655. bool IsEmpty = !IsAnythingQueued();
  656. if (IsEmpty && (Terminal != NULL))
  657. {
  658. TOnceDoneOperation OnceDoneOperation =
  659. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  660. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  661. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  662. {
  663. FQueue->Enabled = false;
  664. }
  665. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  666. {
  667. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  668. }
  669. }
  670. }
  671. //---------------------------------------------------------------------------
  672. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  673. {
  674. UnicodeString Result;
  675. if (FQueueStatus != NULL)
  676. {
  677. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  678. {
  679. TFileOperationProgressType * ProgressData =
  680. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  681. if ((ProgressData != NULL) && ProgressData->InProgress)
  682. {
  683. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  684. }
  685. }
  686. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  687. {
  688. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  689. }
  690. }
  691. return Result;
  692. }
  693. //---------------------------------------------------------------------------
  694. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  695. {
  696. ComponentVisible[fcQueueView] =
  697. !IsLocalBrowserMode() &&
  698. ((WinConfiguration->QueueView.Show == qvShow) ||
  699. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  700. (FQueueStatus != NULL) && (FQueueStatus->Count > 0)));
  701. }
  702. //---------------------------------------------------------------------------
  703. void __fastcall TCustomScpExplorerForm::QueueChanged()
  704. {
  705. if (FQueueStatus != NULL)
  706. {
  707. // UpdateFileList implementation relies on the status being recreated when session changes
  708. delete FQueueStatus;
  709. FQueueStatus = NULL;
  710. }
  711. UpdateQueueStatus(true);
  712. }
  713. //---------------------------------------------------------------------------
  714. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  715. {
  716. if (FQueue == Queue)
  717. {
  718. FQueueStatusInvalidated = true;
  719. }
  720. }
  721. //---------------------------------------------------------------------------
  722. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  723. TQueueItem * Item)
  724. {
  725. if (FQueue == Queue)
  726. {
  727. TGuard Guard(FQueueStatusSection);
  728. // this may be running in parallel with QueueChanged
  729. if (FQueueStatus != NULL)
  730. {
  731. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  732. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  733. {
  734. FRefreshLocalDirectory = (QueueItem == NULL) ||
  735. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  736. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  737. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  738. }
  739. if (QueueItem != NULL)
  740. {
  741. QueueItem->UserData = (void*)true;
  742. FQueueItemInvalidated = true;
  743. }
  744. }
  745. }
  746. }
  747. //---------------------------------------------------------------------------
  748. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  749. {
  750. // during standalone editing, we have no way to see/control queue,
  751. // so we have to always popup prompts automatically
  752. return StandaloneOperation || GUIConfiguration->QueueAutoPopup;
  753. }
  754. //---------------------------------------------------------------------------
  755. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  756. {
  757. if (FQueueStatus != NULL)
  758. {
  759. bool QueueAutoPopup = IsQueueAutoPopup();
  760. bool NeedRefresh = FQueueController->NeedRefresh();
  761. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  762. FQueueItemInvalidated = false;
  763. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  764. bool Updated = false;
  765. TQueueItemProxy * QueueItem;
  766. bool WasUserAction;
  767. for (int Index = 0; Index < Limit; Index++)
  768. {
  769. bool Update = false;
  770. QueueItem = FQueueStatus->Items[Index];
  771. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  772. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  773. (FPendingQueueActionItem == NULL))
  774. {
  775. FPendingQueueActionItem = QueueItem;
  776. FUserActionTimer->Enabled = true;
  777. }
  778. if ((bool)QueueItem->UserData)
  779. {
  780. QueueItem->UserData = (void*)false;
  781. QueueItem->Update();
  782. Updated = true;
  783. Update = true;
  784. }
  785. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  786. {
  787. Update = true;
  788. }
  789. if (Update)
  790. {
  791. FQueueController->RefreshQueueItem(QueueItem);
  792. }
  793. }
  794. if (Updated)
  795. {
  796. NonVisualDataModule->UpdateNonVisibleActions();
  797. SetQueueProgress();
  798. UpdateQueueFileList();
  799. }
  800. }
  801. }
  802. //---------------------------------------------------------------------------
  803. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  804. {
  805. if (FTaskbarList != NULL)
  806. {
  807. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  808. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  809. }
  810. }
  811. //---------------------------------------------------------------------------
  812. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  813. {
  814. if (Progress >= 0)
  815. {
  816. if (FTaskbarList != NULL)
  817. {
  818. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  819. }
  820. }
  821. else
  822. {
  823. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  824. }
  825. }
  826. //---------------------------------------------------------------------------
  827. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  828. {
  829. int OverallProgress;
  830. // FProgressForm is null when this is called from SetQueueProgress
  831. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  832. {
  833. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  834. }
  835. else if (!ProgressData->IsIndeterminate())
  836. {
  837. OverallProgress = ProgressData->OverallProgress();
  838. }
  839. else
  840. {
  841. OverallProgress = -1;
  842. }
  843. SetTaskbarListProgressValue(OverallProgress);
  844. }
  845. //---------------------------------------------------------------------------
  846. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  847. {
  848. TTerminalManager::Instance()->QueueStatusUpdated();
  849. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  850. {
  851. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  852. {
  853. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  854. {
  855. TFileOperationProgressType * ProgressData = NULL;
  856. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  857. {
  858. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  859. }
  860. if ((ProgressData != NULL) &&
  861. ProgressData->InProgress)
  862. {
  863. SetTaskbarListProgressValue(ProgressData);
  864. }
  865. else
  866. {
  867. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  868. }
  869. }
  870. else
  871. {
  872. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  873. }
  874. }
  875. else
  876. {
  877. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  878. }
  879. }
  880. UpdateQueueLabel();
  881. }
  882. //---------------------------------------------------------------------------
  883. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  884. {
  885. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  886. if (FQueueStatus != NULL)
  887. {
  888. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  889. if (ActiveAndPendingPrimaryCount > 0)
  890. {
  891. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  892. }
  893. }
  894. QueueLabel->Caption = Caption;
  895. }
  896. //---------------------------------------------------------------------------
  897. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  898. {
  899. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  900. static_cast<TComponent*>(GetComponent(fcTransferList)));
  901. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  902. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  903. TransferList->Strings->BeginUpdate();
  904. try
  905. {
  906. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  907. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  908. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  909. if (FTransferDropDownHint.IsEmpty())
  910. {
  911. FTransferDropDownHint = TransferDropDown->Hint;
  912. }
  913. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  914. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  915. TransferDropDown->Text = StripHotkey(Name);
  916. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  917. (FTransferDropDownHint, StripHotkey(Name),
  918. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  919. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  920. // update the label, otherwise when it is updated only on the first draw
  921. // of the list, it is drawn "bold" for some reason
  922. FTransferListHoverIndex = TransferList->ItemIndex;
  923. UpdateTransferLabel();
  924. }
  925. __finally
  926. {
  927. TransferList->Strings->EndUpdate();
  928. }
  929. }
  930. //---------------------------------------------------------------------------
  931. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  932. {
  933. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  934. DebugAssert(Toolbar != NULL);
  935. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  936. }
  937. //---------------------------------------------------------------------------
  938. void __fastcall TCustomScpExplorerForm::UpdateActions()
  939. {
  940. TForm::UpdateActions();
  941. if (ComponentVisible[fcCustomCommandsBand])
  942. {
  943. UpdateCustomCommandsToolbar();
  944. }
  945. }
  946. //---------------------------------------------------------------------------
  947. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  948. {
  949. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  950. }
  951. //---------------------------------------------------------------------------
  952. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  953. {
  954. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  955. {
  956. DirView->RowSelect = WinConfiguration->FullRowSelect;
  957. // Without this, the panel turns gray and unused part of header turns black
  958. DirView->Perform(CM_COLORCHANGED, 0, 0);
  959. }
  960. }
  961. //---------------------------------------------------------------------------
  962. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  963. {
  964. Color = GetBtnFaceColor();
  965. DebugAssert(Configuration && RemoteDirView);
  966. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  967. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  968. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  969. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  970. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  971. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  972. UpdateRowSelect(RemoteDirView);
  973. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  974. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  975. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  976. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  977. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  978. UpdateSessionsPageControlHeight();
  979. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  980. UpdateToolbarDisplayMode();
  981. UpdateTransferList();
  982. if (Terminal != NULL)
  983. {
  984. TransferPresetAutoSelect();
  985. }
  986. UpdateQueueView();
  987. UpdateControls();
  988. // this can be called even before constuctor finishes.
  989. if (FEditorManager != NULL)
  990. {
  991. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  992. }
  993. // this can be called even before constuctor finishes.
  994. if (FLocalEditors != NULL)
  995. {
  996. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  997. {
  998. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  999. }
  1000. }
  1001. if (ComponentVisible[fcCustomCommandsBand])
  1002. {
  1003. UpdateCustomCommandsToolbar();
  1004. }
  1005. // show only when keeping queue items forever,
  1006. // otherwise, it's enough to have it in the context menu
  1007. QueueDeleteAllDoneQueueToolbarItem->Visible =
  1008. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  1009. if (FFileColorsCurrent != WinConfiguration->FileColors)
  1010. {
  1011. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  1012. FFileColorsCurrent = WinConfiguration->FileColors;
  1013. FileColorsChanged();
  1014. }
  1015. }
  1016. //---------------------------------------------------------------------------
  1017. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  1018. {
  1019. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  1020. DirView->Invalidate();
  1021. }
  1022. //---------------------------------------------------------------------------
  1023. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  1024. {
  1025. DoFileColorsChanged(RemoteDirView);
  1026. }
  1027. //---------------------------------------------------------------------------
  1028. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  1029. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  1030. void * /*Arg*/)
  1031. {
  1032. if (Token != NULL)
  1033. {
  1034. TForm * Editor = dynamic_cast<TForm*>(Token);
  1035. DebugAssert(Editor != NULL);
  1036. ReconfigureEditorForm(Editor);
  1037. }
  1038. }
  1039. //---------------------------------------------------------------------------
  1040. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1041. {
  1042. WinConfiguration->DDTransferConfirmation = asOn;
  1043. }
  1044. //---------------------------------------------------------------------------
  1045. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1046. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1047. {
  1048. // noop
  1049. }
  1050. //---------------------------------------------------------------------------
  1051. bool TCustomScpExplorerForm::GetDoNotShowCopyDialogDefault(bool DragDrop)
  1052. {
  1053. return DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto);
  1054. }
  1055. //---------------------------------------------------------------------------
  1056. void TCustomScpExplorerForm::HandleDoNotShowCopyDialogAgain(bool DragDrop, bool DoNotShowAgain)
  1057. {
  1058. if (DoNotShowAgain)
  1059. {
  1060. if (DragDrop)
  1061. {
  1062. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1063. {
  1064. PopupTrayBalloon(
  1065. NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation, NULL, 0, EnableDDTransferConfirmation, NULL);
  1066. }
  1067. WinConfiguration->DDTransferConfirmation = asOff;
  1068. }
  1069. else
  1070. {
  1071. WinConfiguration->ConfirmTransferring = false;
  1072. }
  1073. }
  1074. else
  1075. {
  1076. // User explicitly unchecked "do not show again",
  1077. // so show him the dialog the next time
  1078. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1079. {
  1080. WinConfiguration->DDTransferConfirmation = asOn;
  1081. }
  1082. }
  1083. }
  1084. //---------------------------------------------------------------------------
  1085. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1086. TTransferDirection Direction, TTransferType Type, bool Temp,
  1087. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1088. bool Confirm, bool DragDrop, int Options)
  1089. {
  1090. bool Result = true;
  1091. DebugAssert(HasActiveTerminal());
  1092. // these parameters are known in advance
  1093. int Params =
  1094. FLAGMASK(Type == ttMove, cpDelete);
  1095. bool ToTemp = (Temp && (Direction == tdToLocal));
  1096. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1097. {
  1098. bool DisableNewerOnly =
  1099. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1100. ToTemp;
  1101. Options |=
  1102. FLAGMASK(ToTemp, coTemp) |
  1103. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1104. coDoNotShowAgain;
  1105. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1106. int CopyParamAttrs = (Direction == tdToRemote ?
  1107. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1108. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1109. int OutputOptions = FLAGMASK(GetDoNotShowCopyDialogDefault(DragDrop), cooDoNotShowAgain);
  1110. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1111. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1112. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1113. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1114. if (Result)
  1115. {
  1116. HandleDoNotShowCopyDialogAgain(DragDrop, FLAGSET(OutputOptions, cooDoNotShowAgain));
  1117. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1118. }
  1119. }
  1120. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1121. {
  1122. Configuration->Usage->Inc(L"TransfersOnBackground");
  1123. // these parameter are known only after transfer dialog
  1124. Params |=
  1125. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1126. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1127. Result = false;
  1128. ClearTransferSourceSelection(Direction);
  1129. }
  1130. return Result;
  1131. }
  1132. //---------------------------------------------------------------------------
  1133. void TCustomScpExplorerForm::ClearOperationSelection(TOperationSide Side)
  1134. {
  1135. if (FOnFileOperationFinished != NULL)
  1136. {
  1137. FOnFileOperationFinished(Side, UnicodeString(), true);
  1138. }
  1139. else
  1140. {
  1141. if (HasDirView[Side])
  1142. {
  1143. DirView(Side)->SelectAll(smNone);
  1144. }
  1145. }
  1146. }
  1147. //---------------------------------------------------------------------------
  1148. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1149. {
  1150. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1151. ClearOperationSelection(Side);
  1152. }
  1153. //---------------------------------------------------------------------------
  1154. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1155. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1156. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1157. int Params)
  1158. {
  1159. DebugAssert(Queue != NULL);
  1160. bool SingleFile = false;
  1161. if (FileList->Count == 1)
  1162. {
  1163. if (Direction == tdToRemote)
  1164. {
  1165. UnicodeString FileName = FileList->Strings[0];
  1166. SingleFile = FileExists(ApiPath(FileName));
  1167. }
  1168. else
  1169. {
  1170. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1171. SingleFile = !File->IsDirectory;
  1172. }
  1173. }
  1174. TQueueItem * QueueItem;
  1175. if (Direction == tdToRemote)
  1176. {
  1177. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1178. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1179. }
  1180. else
  1181. {
  1182. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1183. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1184. }
  1185. AddQueueItem(Queue, QueueItem, Terminal);
  1186. }
  1187. //---------------------------------------------------------------------------
  1188. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1189. {
  1190. if (Queue->IsEmpty)
  1191. {
  1192. Terminal->QueueOperationStart = Now();
  1193. }
  1194. Queue->AddItem(QueueItem);
  1195. }
  1196. //---------------------------------------------------------------------------
  1197. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1198. {
  1199. }
  1200. //---------------------------------------------------------------------------
  1201. void __fastcall TCustomScpExplorerForm::InitControls()
  1202. {
  1203. DebugAssert(FDocks != NULL);
  1204. for (int Index = 0; Index < ComponentCount; Index++)
  1205. {
  1206. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1207. if ((Dock != NULL) && (Dock->Tag == 0))
  1208. {
  1209. FDocks->Add(Dock);
  1210. }
  1211. }
  1212. CollectItemsWithTextDisplayMode(this);
  1213. }
  1214. //---------------------------------------------------------------------------
  1215. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1216. {
  1217. ConfigurationChanged();
  1218. QueuePanel->Height =
  1219. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1220. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1221. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1222. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1223. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1224. QueueFileList->Height =
  1225. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1226. if (QueueFileList->Visible)
  1227. {
  1228. AdjustQueueLayout();
  1229. }
  1230. UpdateCustomCommandsToolbar();
  1231. }
  1232. //---------------------------------------------------------------------------
  1233. void __fastcall TCustomScpExplorerForm::StoreParams()
  1234. {
  1235. int APixelsPerInch = GetControlPixelsPerInch(this);
  1236. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1237. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1238. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1239. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1240. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1241. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1242. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1243. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1244. }
  1245. //---------------------------------------------------------------------------
  1246. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1247. {
  1248. if (!FFormRestored)
  1249. {
  1250. FFormRestored = true;
  1251. RestoreFormParams();
  1252. }
  1253. TForm::CreateParams(Params);
  1254. }
  1255. //---------------------------------------------------------------------------
  1256. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1257. {
  1258. DebugAssert(FDocks != NULL);
  1259. for (int Index = 0; Index < FDocks->Count; Index++)
  1260. {
  1261. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1262. }
  1263. }
  1264. //---------------------------------------------------------------------------
  1265. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1266. {
  1267. SetDockAllowDrag(true);
  1268. while (!ButtonsStr.IsEmpty())
  1269. {
  1270. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1271. UnicodeString Name = CutToChar(S, L'=', true);
  1272. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1273. {
  1274. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1275. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1276. {
  1277. while (!S.IsEmpty())
  1278. {
  1279. UnicodeString S2 = CutToChar(S, L',', true);
  1280. UnicodeString Name = CutToChar(S2, L':', true);
  1281. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1282. {
  1283. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1284. if (SameText(GetToolbarItemName(Item), Name))
  1285. {
  1286. // forward compatibility
  1287. UnicodeString S3 = CutToChar(S2, L':', true);
  1288. bool Visible = StrToIntDef(S3, 0);
  1289. Item->Visible = Visible;
  1290. }
  1291. }
  1292. }
  1293. }
  1294. }
  1295. }
  1296. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1297. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1298. }
  1299. //---------------------------------------------------------------------------
  1300. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1301. {
  1302. UnicodeString Result;
  1303. SetDockAllowDrag(true);
  1304. Result = ::GetToolbarsLayoutStr(this);
  1305. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1306. return Result;
  1307. }
  1308. //---------------------------------------------------------------------------
  1309. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1310. {
  1311. UnicodeString Result;
  1312. if (Item->Action != NULL)
  1313. {
  1314. Result = Item->Action->Name;
  1315. Result = RemoveSuffix(Result, L"Action", true);
  1316. }
  1317. else
  1318. {
  1319. Result = Item->Name;
  1320. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1321. Result = RemoveSuffix(Result, L"Item", true);
  1322. }
  1323. return Result;
  1324. }
  1325. //---------------------------------------------------------------------------
  1326. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1327. {
  1328. UnicodeString Result;
  1329. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1330. {
  1331. UnicodeString ToolbarStr;
  1332. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1333. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1334. {
  1335. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1336. {
  1337. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1338. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1339. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1340. // and save the changes here only.
  1341. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1342. {
  1343. UnicodeString Name = GetToolbarItemName(Item);
  1344. DebugAssert(Name.Pos(L"TBX") == 0);
  1345. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1346. }
  1347. }
  1348. }
  1349. if (!ToolbarStr.IsEmpty())
  1350. {
  1351. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1352. }
  1353. }
  1354. return Result;
  1355. }
  1356. //---------------------------------------------------------------------------
  1357. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1358. {
  1359. DebugAssert(FProgressForm == NULL);
  1360. bool AllowSkip = HasActiveTerminal() ? Terminal->IsCapable[fcSkipTransfer] : false;
  1361. bool AllowMoveToQueue = (FTransferResumeList != NULL) || (FDeletedFiles != NULL);
  1362. FProgressForm = new TProgressForm(Application, AllowMoveToQueue, AllowSkip, SynchronizeProgress);
  1363. FProgressForm->DeleteLocalToRecycleBin =
  1364. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1365. FProgressForm->DeleteRemoteToRecycleBin =
  1366. HasActiveTerminal() &&
  1367. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1368. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1369. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1370. LockWindow();
  1371. // Actually, do not know what hides the progress once the operation finishes
  1372. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1373. SetTaskbarListProgressState(TBPF_NORMAL);
  1374. }
  1375. //---------------------------------------------------------------------------
  1376. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1377. {
  1378. UnlockWindow();
  1379. SAFE_DESTROY(FProgressForm);
  1380. SetQueueProgress();
  1381. }
  1382. //---------------------------------------------------------------------------
  1383. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1384. TFileOperationProgressType & ProgressData)
  1385. {
  1386. // Download to temporary local directory
  1387. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1388. {
  1389. bool Continue = true;
  1390. FPendingTempSpaceWarn = false;
  1391. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1392. if (!Continue)
  1393. {
  1394. Abort();
  1395. }
  1396. }
  1397. // operation is being executed and we still didn't show up progress form
  1398. if (ProgressData.InProgress && !FProgressForm)
  1399. {
  1400. CreateProgressForm(NULL);
  1401. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1402. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1403. }
  1404. // operation is finished (or terminated), so we hide progress form
  1405. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1406. {
  1407. DestroyProgressForm();
  1408. if (ProgressData.Operation == foCalculateSize)
  1409. {
  1410. // When calculating size before transfer, the abort caused by
  1411. // cancel flag set due to "MoveToQueue" below,
  1412. // is not propagated back to us in ExecuteFileOperation,
  1413. // as it is silently swallowed.
  1414. // So we explicitly (re)throw it here.
  1415. if (FMoveToQueue)
  1416. {
  1417. Abort();
  1418. }
  1419. }
  1420. else
  1421. {
  1422. if ((ProgressData.Cancel == csContinue) &&
  1423. !FAutoOperation)
  1424. {
  1425. OperationComplete(ProgressData.StartTime);
  1426. }
  1427. }
  1428. }
  1429. if (FProgressForm &&
  1430. // Can happen only during synchronization, when ending one of the operations
  1431. ProgressData.InProgress)
  1432. {
  1433. FProgressForm->SetProgressData(ProgressData);
  1434. DebugAssert(ProgressData.InProgress);
  1435. SetTaskbarListProgressValue(&ProgressData);
  1436. if (FProgressForm->Cancel > csContinue)
  1437. {
  1438. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1439. if (FProgressForm->Cancel == csCancelFile)
  1440. {
  1441. FProgressForm->ClearCancel();
  1442. }
  1443. // cancel cancels even the move
  1444. FMoveToQueue = false;
  1445. }
  1446. else if (FProgressForm->MoveToQueue)
  1447. {
  1448. FMoveToQueue = true;
  1449. ProgressData.SetCancelAtLeast(csCancel);
  1450. }
  1451. if ((FTransferResumeList != NULL) &&
  1452. ProgressData.InProgress &&
  1453. ProgressData.IsTransfer() &&
  1454. !ProgressData.FullFileName.IsEmpty())
  1455. {
  1456. if ((FTransferResumeList->Count == 0) ||
  1457. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1458. {
  1459. // note that we do not recognize directories from files here
  1460. FTransferResumeList->Add(ProgressData.FullFileName);
  1461. }
  1462. }
  1463. }
  1464. }
  1465. //---------------------------------------------------------------------------
  1466. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1467. const TDateTime & StartTime)
  1468. {
  1469. if (GUIConfiguration->BeepOnFinish &&
  1470. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1471. {
  1472. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1473. DWORD Sound;
  1474. if (!ExtractFileExt(BeepSound).IsEmpty())
  1475. {
  1476. Sound = SND_FILENAME;
  1477. }
  1478. else
  1479. {
  1480. Sound = SND_ALIAS;
  1481. }
  1482. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1483. }
  1484. }
  1485. //---------------------------------------------------------------------------
  1486. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1487. TFileOperationProgressType & ProgressData)
  1488. {
  1489. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1490. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1491. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1492. FileOperationProgress(ProgressData);
  1493. }
  1494. //---------------------------------------------------------------------------
  1495. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1496. {
  1497. UnicodeString Result;
  1498. if (FProgressForm != NULL)
  1499. {
  1500. Result = FProgressForm->ProgressStr();
  1501. }
  1502. return Result;
  1503. }
  1504. //---------------------------------------------------------------------------
  1505. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1506. bool DragDrop)
  1507. {
  1508. return (!DragDrop && (DropSourceControl == NULL)) ||
  1509. (DropSourceControl == DirView(osOther));
  1510. }
  1511. //---------------------------------------------------------------------------
  1512. TListItem * TCustomScpExplorerForm::VisualiseOperationFinished(TOperationSide Side, const UnicodeString & FileName, bool Unselect)
  1513. {
  1514. TCustomDirView * ADirView = DirView(Side);
  1515. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(Side));
  1516. TListItem * Item = ADirView->FindFileItem(FileNameOnly);
  1517. // this can happen when local drive is unplugged in the middle of the operation
  1518. if (Item != NULL)
  1519. {
  1520. if (Unselect)
  1521. {
  1522. Item->Selected = false;
  1523. }
  1524. ADirView->MakeProgressVisible(Item);
  1525. }
  1526. return Item;
  1527. }
  1528. //---------------------------------------------------------------------------
  1529. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1530. TFileOperation Operation, TOperationSide Side,
  1531. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1532. TOnceDoneOperation & OnceDoneOperation)
  1533. {
  1534. if (!FAutoOperation)
  1535. {
  1536. // no selection on "/upload", form serves only as event handler
  1537. // (it is not displayed)
  1538. if (PanelOperation(Side, FDragDropOperation) && Visible &&
  1539. ((Operation == FPrimaryOperation) ||
  1540. ((Operation != foCalculateSize) && (Operation != foGetProperties) && (Operation != foCalculateChecksum))))
  1541. {
  1542. TOperationSide DViewSide;
  1543. if ((FProgressSide != osCurrent) &&
  1544. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1545. {
  1546. // assume the operation is over the focused panel
  1547. DViewSide = FProgressSide;
  1548. }
  1549. else
  1550. {
  1551. DViewSide = Side;
  1552. }
  1553. if (FOnFileOperationFinished != NULL)
  1554. {
  1555. FOnFileOperationFinished(DViewSide, FileName, Success);
  1556. }
  1557. else
  1558. {
  1559. VisualiseOperationFinished(DViewSide, FileName, Success);
  1560. }
  1561. }
  1562. if (TFileOperationProgressType::IsTransferOperation(Operation))
  1563. {
  1564. if (DebugAlwaysTrue(!IsLocalBrowserMode()))
  1565. {
  1566. if (Side == osLocal)
  1567. {
  1568. Configuration->Usage->Inc(L"UploadedFiles");
  1569. }
  1570. else
  1571. {
  1572. Configuration->Usage->Inc(L"DownloadedFiles");
  1573. }
  1574. }
  1575. }
  1576. }
  1577. if (Success && (FSynchronizeController != NULL))
  1578. {
  1579. DebugAssert(!IsSideLocalBrowser(osRemote));
  1580. if (Operation == foCopy)
  1581. {
  1582. DebugAssert(Side == osLocal);
  1583. FSynchronizeController->LogOperation(soUpload, FileName);
  1584. }
  1585. else if (Operation == foDelete)
  1586. {
  1587. DebugAssert(Side == osRemote);
  1588. FSynchronizeController->LogOperation(soDelete, FileName);
  1589. }
  1590. }
  1591. if (FProgressForm)
  1592. {
  1593. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1594. }
  1595. }
  1596. //---------------------------------------------------------------------------
  1597. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1598. TFileOperation Operation, TOperationSide Side,
  1599. bool Temp, const UnicodeString & FileName, Boolean Success,
  1600. TOnceDoneOperation & OnceDoneOperation)
  1601. {
  1602. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1603. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1604. OnceDoneOperation);
  1605. }
  1606. //---------------------------------------------------------------------------
  1607. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1608. {
  1609. return false;
  1610. }
  1611. //---------------------------------------------------------------------------
  1612. bool TCustomScpExplorerForm::SupportsLocalBrowser()
  1613. {
  1614. return false;
  1615. }
  1616. //---------------------------------------------------------------------------
  1617. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1618. {
  1619. return false;
  1620. }
  1621. //---------------------------------------------------------------------------
  1622. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1623. {
  1624. return NULL;
  1625. }
  1626. //---------------------------------------------------------------------------
  1627. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1628. {
  1629. DebugAssert(GetSide(Side) == osRemote);
  1630. DebugUsedParam(Side);
  1631. return RemoteDirView;
  1632. }
  1633. //---------------------------------------------------------------------------
  1634. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1635. {
  1636. DebugAssert(GetSide(Side) == osRemote);
  1637. DebugUsedParam(Side);
  1638. return RemoteDriveView;
  1639. }
  1640. //---------------------------------------------------------------------------
  1641. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1642. {
  1643. DebugAssert(GetSide(Side) == osRemote);
  1644. DebugUsedParam(Side);
  1645. return HasActiveTerminal();
  1646. }
  1647. //---------------------------------------------------------------------------
  1648. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1649. TOperationSide Side, int FilesOnly)
  1650. {
  1651. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1652. }
  1653. //---------------------------------------------------------------------------
  1654. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1655. TOperationSide Side, int FilesOnly)
  1656. {
  1657. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1658. }
  1659. //---------------------------------------------------------------------------
  1660. struct THistoryItemData
  1661. {
  1662. short int Side;
  1663. short int Index;
  1664. };
  1665. //---------------------------------------------------------------------------
  1666. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1667. {
  1668. DirView(Side)->HistoryGo(Index);
  1669. }
  1670. //---------------------------------------------------------------------------
  1671. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1672. {
  1673. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1674. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1675. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1676. }
  1677. //---------------------------------------------------------------------------
  1678. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1679. bool Back)
  1680. {
  1681. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1682. {
  1683. TCustomDirView * DView = DirView(Side);
  1684. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1685. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1686. if (ICount > 10)
  1687. {
  1688. ICount = 10;
  1689. }
  1690. Menu->Items->Clear();
  1691. THistoryItemData Data;
  1692. Data.Side = Side;
  1693. for (short int i = 1; i <= ICount; i++)
  1694. {
  1695. TTBCustomItem * Item = new TTBXItem(Menu);
  1696. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1697. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1698. Item->Hint = DView->HistoryPath[Data.Index];
  1699. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1700. Item->Tag = *reinterpret_cast<int*>(&Data);
  1701. Item->OnClick = HistoryItemClick;
  1702. Menu->Items->Add(Item);
  1703. }
  1704. }
  1705. }
  1706. //---------------------------------------------------------------------------
  1707. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1708. TOperationSide Side, bool Back)
  1709. {
  1710. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1711. {
  1712. // workaround
  1713. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1714. // operator new allocates memory in Pascal code, but calls inline
  1715. // contructor in C++, leading in problems, the function does
  1716. // both in Pascal code
  1717. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1718. UpdateHistoryMenu(Side, Back);
  1719. }
  1720. return FHistoryMenu[Side == osLocal][Back];
  1721. }
  1722. //---------------------------------------------------------------------------
  1723. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1724. TCustomDirView *Sender)
  1725. {
  1726. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1727. UpdateHistoryMenu(Side, true);
  1728. UpdateHistoryMenu(Side, false);
  1729. }
  1730. //---------------------------------------------------------------------------
  1731. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1732. {
  1733. // remote custom commands can be executed only if the server supports shell commands
  1734. // or have secondary shell
  1735. return HasActiveTerminal() && (Terminal->IsCapable[fcSecondaryShell] || Terminal->IsCapable[fcShellAnyCommand]);
  1736. }
  1737. //---------------------------------------------------------------------------
  1738. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1739. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1740. {
  1741. // -1 = hidden, 0 = disabled, 1 = enabled
  1742. int Result;
  1743. TFileCustomCommand RemoteCustomCommand;
  1744. TLocalCustomCommand LocalCustomCommand;
  1745. TFileCustomCommand * NonInteractiveCustomCommand =
  1746. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1747. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1748. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1749. if (FLAGCLEAR(Command.Params, ccLocal))
  1750. {
  1751. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1752. // custom command that does not operate with files can be executed anytime ...
  1753. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1754. {
  1755. // ... but do not show such command in remote file menu
  1756. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1757. {
  1758. Result = AllowedState;
  1759. }
  1760. else
  1761. {
  1762. Result = -1;
  1763. }
  1764. }
  1765. else
  1766. {
  1767. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1768. {
  1769. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1770. }
  1771. else
  1772. {
  1773. Result = -1;
  1774. }
  1775. }
  1776. }
  1777. else
  1778. {
  1779. // custom command that does not operate with files can be executed anytime
  1780. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1781. {
  1782. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1783. }
  1784. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1785. {
  1786. if ((ListType == ccltAll) || (ListType == ccltFile))
  1787. {
  1788. // special case is "diff"-style command that can be executed over any side,
  1789. // if we have both sides
  1790. Result =
  1791. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1792. // directly (instead of EnableSelectedOperation) to pass
  1793. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1794. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1795. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1796. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1797. }
  1798. else if (ListType == ccltBoth)
  1799. {
  1800. DebugAssert(!IsLocalBrowserMode());
  1801. Result = 1;
  1802. }
  1803. else
  1804. {
  1805. Result = -1;
  1806. }
  1807. }
  1808. else
  1809. {
  1810. if ((ListType == ccltAll) ||
  1811. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1812. {
  1813. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1814. }
  1815. else
  1816. {
  1817. Result = -1;
  1818. }
  1819. }
  1820. if ((Result > 0) &&
  1821. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1822. !HasActiveTerminal())
  1823. {
  1824. Result = 0;
  1825. }
  1826. }
  1827. return Result;
  1828. }
  1829. //---------------------------------------------------------------------------
  1830. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1831. TStrings * FileList, const TCustomCommandType & ACommand,
  1832. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1833. {
  1834. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1835. {
  1836. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1837. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1838. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1839. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1840. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1841. bool Capture =
  1842. FLAGSET(ACommand.Params, ccShowResults) ||
  1843. FLAGSET(ACommand.Params, ccCopyResults) ||
  1844. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1845. TCaptureOutputEvent OutputEvent = NULL;
  1846. DebugAssert(FCapturedLog == NULL);
  1847. if (Capture)
  1848. {
  1849. FCapturedLog = new TStringList();
  1850. OutputEvent = TerminalCaptureLog;
  1851. }
  1852. try
  1853. {
  1854. if (!RemoteCustomCommand.IsFileCommand(Command))
  1855. {
  1856. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1857. OutputEvent);
  1858. }
  1859. else
  1860. {
  1861. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1862. }
  1863. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1864. {
  1865. if (FLAGSET(ACommand.Params, ccCopyResults))
  1866. {
  1867. CopyToClipboard(FCapturedLog);
  1868. }
  1869. if (FLAGSET(ACommand.Params, ccShowResults))
  1870. {
  1871. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1872. }
  1873. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1874. {
  1875. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1876. }
  1877. }
  1878. }
  1879. __finally
  1880. {
  1881. SAFE_DESTROY(FCapturedLog);
  1882. }
  1883. }
  1884. }
  1885. //---------------------------------------------------------------------------
  1886. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1887. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1888. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1889. {
  1890. DebugAssert(!IsLocalBrowserMode());
  1891. TStrings * LocalFileList = NULL;
  1892. TStrings * RemoteFileList = NULL;
  1893. TStrings * RemoteFileListFull = NULL;
  1894. try
  1895. {
  1896. if (LocalFileCommand)
  1897. {
  1898. if (ALocalFileList == NULL)
  1899. {
  1900. DebugAssert(HasDirView[osLocal]);
  1901. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1902. // directly (instead of EnableSelectedOperation) to pass
  1903. // false to FocusedFileOnlyWhenFocused
  1904. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1905. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1906. }
  1907. else
  1908. {
  1909. LocalFileList = ALocalFileList;
  1910. }
  1911. if (FileListCommand)
  1912. {
  1913. if (LocalFileList->Count != 1)
  1914. {
  1915. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1916. }
  1917. }
  1918. else
  1919. {
  1920. if ((LocalFileList->Count != 1) &&
  1921. (FileList->Count != 1) &&
  1922. (LocalFileList->Count != FileList->Count))
  1923. {
  1924. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1925. }
  1926. }
  1927. }
  1928. UnicodeString RootTempDir;
  1929. UnicodeString TempDir;
  1930. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1931. if (!RemoteFiles)
  1932. {
  1933. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1934. }
  1935. try
  1936. {
  1937. TDateTimes RemoteFileTimes;
  1938. if (RemoteFiles)
  1939. {
  1940. RemoteFileList = FileList;
  1941. }
  1942. else
  1943. {
  1944. RemoteFileList = new TStringList();
  1945. TMakeLocalFileListParams MakeFileListParam;
  1946. MakeFileListParam.FileList = RemoteFileList;
  1947. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1948. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1949. MakeFileListParam.Recursive =
  1950. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1951. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1952. if (!MakeFileListParam.Recursive)
  1953. {
  1954. RemoteFileTimes.clear();
  1955. RemoteFileListFull = new TStringList();
  1956. MakeFileListParam.FileList = RemoteFileListFull;
  1957. MakeFileListParam.Recursive = true;
  1958. MakeFileListParam.IncludeDirs = false;
  1959. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1960. }
  1961. else
  1962. {
  1963. RemoteFileListFull = RemoteFileList;
  1964. }
  1965. }
  1966. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1967. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1968. if (!NonBlocking)
  1969. {
  1970. int Count;
  1971. if (FileListCommand)
  1972. {
  1973. Count = 1;
  1974. }
  1975. else if (LocalFileCommand)
  1976. {
  1977. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1978. }
  1979. else
  1980. {
  1981. Count = RemoteFileList->Count;
  1982. }
  1983. Progress.Start(foCustomCommand, osRemote, Count);
  1984. DebugAssert(FProgressForm != NULL);
  1985. FProgressForm->ReadOnly = true;
  1986. }
  1987. try
  1988. {
  1989. if (FileListCommand)
  1990. {
  1991. UnicodeString LocalFile;
  1992. // MakeFileList does not delimit filenames
  1993. UnicodeString FileList = MakeFileList(RemoteFileList);
  1994. if (LocalFileCommand)
  1995. {
  1996. DebugAssert(LocalFileList->Count == 1);
  1997. LocalFile = LocalFileList->Strings[0];
  1998. }
  1999. TLocalCustomCommand CustomCommand(Data,
  2000. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  2001. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  2002. if (NonBlocking)
  2003. {
  2004. DebugAssert(!POutput);
  2005. ExecuteShellChecked(ShellCommand);
  2006. }
  2007. else
  2008. {
  2009. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  2010. }
  2011. }
  2012. else if (LocalFileCommand)
  2013. {
  2014. if (LocalFileList->Count == 1)
  2015. {
  2016. UnicodeString LocalFile = LocalFileList->Strings[0];
  2017. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2018. {
  2019. UnicodeString FileName = RemoteFileList->Strings[Index];
  2020. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2021. Progress.SetFile(FileNameForProgress);
  2022. TLocalCustomCommand CustomCommand(Data,
  2023. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  2024. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2025. TOnceDoneOperation OnceDoneOperation;
  2026. // Do not unselect anything, as it won't work with two panels anyway
  2027. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2028. }
  2029. }
  2030. else if (RemoteFileList->Count == 1)
  2031. {
  2032. UnicodeString FileName = RemoteFileList->Strings[0];
  2033. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2034. {
  2035. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2036. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2037. Progress.SetFile(LocalFileNameOnly);
  2038. TLocalCustomCommand CustomCommand(
  2039. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2040. FileName, LocalFileName, L"");
  2041. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2042. TOnceDoneOperation OnceDoneOperation;
  2043. // Do not unselect anything, as it won't work with two panels anyway
  2044. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2045. }
  2046. }
  2047. else
  2048. {
  2049. if (LocalFileList->Count != RemoteFileList->Count)
  2050. {
  2051. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  2052. }
  2053. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2054. {
  2055. UnicodeString FileName = RemoteFileList->Strings[Index];
  2056. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2057. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2058. Progress.SetFile(LocalFileNameOnly); // sic
  2059. TLocalCustomCommand CustomCommand(
  2060. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2061. FileName, LocalFileName, L"");
  2062. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2063. TOnceDoneOperation OnceDoneOperation;
  2064. // Do not unselect anything, as it won't work with two panels anyway
  2065. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2066. }
  2067. }
  2068. }
  2069. else
  2070. {
  2071. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2072. {
  2073. UnicodeString FileName = RemoteFileList->Strings[Index];
  2074. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2075. Progress.SetFile(FileNameForProgress);
  2076. TLocalCustomCommand CustomCommand(Data,
  2077. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2078. FileName, L"", L"");
  2079. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2080. TOnceDoneOperation OnceDoneOperation;
  2081. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2082. }
  2083. }
  2084. }
  2085. __finally
  2086. {
  2087. if (!NonBlocking)
  2088. {
  2089. Progress.Stop();
  2090. }
  2091. }
  2092. DebugAssert(!FAutoOperation);
  2093. if (!RemoteFiles)
  2094. {
  2095. TempDir = IncludeTrailingBackslash(TempDir);
  2096. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2097. {
  2098. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2099. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2100. // Skip directories, process only nested files.
  2101. // The check is redundant as FileAge fails for directories anyway.
  2102. !DirectoryExists(FileName))
  2103. {
  2104. UnicodeString RemoteDir =
  2105. UnixExtractFileDir(
  2106. UnixIncludeTrailingBackslash(Terminal->CurrentDirectory) +
  2107. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2108. TDateTime NewTime;
  2109. if (FileAge(FileName, NewTime) &&
  2110. (NewTime != RemoteFileTimes[Index]))
  2111. {
  2112. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2113. TemporaryFileCopyParam(CopyParam);
  2114. CopyParam.FileMask = L"";
  2115. FAutoOperation = true;
  2116. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2117. TemporaryFilesList->Add(FileName);
  2118. Terminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2119. }
  2120. }
  2121. }
  2122. }
  2123. }
  2124. __finally
  2125. {
  2126. FAutoOperation = false;
  2127. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2128. {
  2129. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2130. }
  2131. }
  2132. }
  2133. __finally
  2134. {
  2135. if (RemoteFileList != FileList)
  2136. {
  2137. delete RemoteFileList;
  2138. }
  2139. if (LocalFileList != ALocalFileList)
  2140. {
  2141. delete LocalFileList;
  2142. }
  2143. if (RemoteFileListFull != RemoteFileList)
  2144. {
  2145. delete RemoteFileListFull;
  2146. }
  2147. }
  2148. }
  2149. //---------------------------------------------------------------------------
  2150. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2151. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2152. bool FileListCommand, UnicodeString * POutput)
  2153. {
  2154. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2155. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2156. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2157. {
  2158. UnicodeString FileName = SelectedFileList->Strings[Index];
  2159. if (DirectoryExists(FileName))
  2160. {
  2161. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2162. {
  2163. LocalFileList->Add(FileName);
  2164. }
  2165. if (FLAGSET(ACommand.Params, ccRecursive))
  2166. {
  2167. TMakeLocalFileListParams MakeFileListParam;
  2168. MakeFileListParam.FileList = LocalFileList.get();
  2169. MakeFileListParam.FileTimes = NULL;
  2170. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2171. MakeFileListParam.Recursive = true;
  2172. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2173. }
  2174. }
  2175. else
  2176. {
  2177. LocalFileList->Add(FileName);
  2178. }
  2179. }
  2180. UnicodeString RemotePath;
  2181. if (Terminal != NULL)
  2182. {
  2183. RemotePath = Terminal->CurrentDirectory;
  2184. }
  2185. if (FileListCommand)
  2186. {
  2187. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2188. TLocalCustomCommand CustomCommand(
  2189. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2190. L"", L"", FileList);
  2191. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2192. }
  2193. else
  2194. {
  2195. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2196. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2197. DebugAssert(FProgressForm != NULL);
  2198. FProgressForm->ReadOnly = true;
  2199. try
  2200. {
  2201. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2202. {
  2203. UnicodeString FileName = LocalFileList->Strings[Index];
  2204. Progress.SetFile(FileName);
  2205. TLocalCustomCommand CustomCommand(
  2206. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2207. FileName, L"", L"");
  2208. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2209. TOnceDoneOperation OnceDoneOperation;
  2210. Progress.Finish(FileName, true, OnceDoneOperation);
  2211. }
  2212. }
  2213. __finally
  2214. {
  2215. Progress.Stop();
  2216. }
  2217. }
  2218. }
  2219. //---------------------------------------------------------------------------
  2220. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2221. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2222. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2223. {
  2224. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2225. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2226. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2227. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2228. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2229. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2230. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2231. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2232. std::unique_ptr<UnicodeString> POutput;
  2233. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2234. FLAGSET(ACommand.Params, ccCopyResults))
  2235. {
  2236. POutput.reset(new UnicodeString());
  2237. }
  2238. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  2239. FProgressSide = FCurrentSide;
  2240. if (!LocalCustomCommand.IsFileCommand(Command))
  2241. {
  2242. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2243. }
  2244. // remote files?
  2245. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2246. {
  2247. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2248. }
  2249. // local files
  2250. else
  2251. {
  2252. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2253. }
  2254. if (POutput.get() != NULL)
  2255. {
  2256. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2257. int P = POutput->Pos(sLineBreak);
  2258. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2259. {
  2260. POutput->SetLength(P - 1);
  2261. }
  2262. // Copy even empty output to clipboard
  2263. if (FLAGSET(ACommand.Params, ccCopyResults))
  2264. {
  2265. CopyToClipboard(*POutput);
  2266. }
  2267. // But do not show an empty message box.
  2268. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2269. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2270. !POutput->IsEmpty())
  2271. {
  2272. TClipboardHandler ClipboardHandler;
  2273. ClipboardHandler.Text = *POutput;
  2274. TMessageParams Params;
  2275. TQueryButtonAlias Aliases[1];
  2276. Aliases[0].Button = qaRetry;
  2277. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2278. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2279. Params.Aliases = Aliases;
  2280. Params.AliasesCount = LENOF(Aliases);
  2281. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2282. }
  2283. }
  2284. }
  2285. //---------------------------------------------------------------------------
  2286. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2287. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2288. {
  2289. TCustomCommandData Data;
  2290. UnicodeString Site;
  2291. UnicodeString RemotePath;
  2292. if (HasActiveTerminal())
  2293. {
  2294. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2295. Data = TCustomCommandData(SessionData.get());
  2296. Site = Terminal->SessionData->SessionKey;
  2297. RemotePath = Terminal->CurrentDirectory;
  2298. }
  2299. UnicodeString HelpKeyword = ACommand.HomePage;
  2300. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2301. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2302. {
  2303. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2304. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2305. {
  2306. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2307. }
  2308. else
  2309. {
  2310. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2311. }
  2312. if (!DoCustomCommandOptionsDialog(
  2313. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2314. {
  2315. Abort();
  2316. }
  2317. }
  2318. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2319. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2320. {
  2321. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2322. }
  2323. else
  2324. {
  2325. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2326. }
  2327. }
  2328. //---------------------------------------------------------------------------
  2329. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2330. const TCustomCommandType & Command)
  2331. {
  2332. DebugAssert(FCustomCommandLocalFileList != NULL);
  2333. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2334. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2335. TStrings * LocalFileList = new TStringList();
  2336. TStrings * RemoteFileList = new TStringList();
  2337. try
  2338. {
  2339. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2340. {
  2341. LocalFileList->Clear();
  2342. LocalFileList->AddObject(
  2343. FCustomCommandLocalFileList->Strings[Index],
  2344. FCustomCommandLocalFileList->Objects[Index]);
  2345. RemoteFileList->Clear();
  2346. RemoteFileList->AddObject(
  2347. FCustomCommandRemoteFileList->Strings[Index],
  2348. FCustomCommandRemoteFileList->Objects[Index]);
  2349. CustomCommand(RemoteFileList, Command, LocalFileList);
  2350. }
  2351. }
  2352. __finally
  2353. {
  2354. delete LocalFileList;
  2355. delete RemoteFileList;
  2356. }
  2357. }
  2358. //---------------------------------------------------------------------------
  2359. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2360. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2361. {
  2362. delete FCustomCommandLocalFileList;
  2363. delete FCustomCommandRemoteFileList;
  2364. // takeover ownership,
  2365. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2366. FCustomCommandLocalFileList = LocalFileList;
  2367. FCustomCommandRemoteFileList = RemoteFileList;
  2368. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2369. if (Button != NULL)
  2370. {
  2371. FCustomCommandMenu->Items->Clear();
  2372. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2373. MenuPopup(FCustomCommandMenu, Button);
  2374. }
  2375. else
  2376. {
  2377. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2378. }
  2379. }
  2380. //---------------------------------------------------------------------------
  2381. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2382. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2383. {
  2384. DebugAssert(FCapturedLog != NULL);
  2385. if ((OutputType == cotOutput) || (OutputType == cotError))
  2386. {
  2387. FCapturedLog->Add(AddedLine);
  2388. }
  2389. }
  2390. //---------------------------------------------------------------------------
  2391. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2392. TOperationSide Side)
  2393. {
  2394. return
  2395. (Side == osOther) &&
  2396. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2397. }
  2398. //---------------------------------------------------------------------------
  2399. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2400. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2401. {
  2402. TTBItemOptions O;
  2403. O = Item->Options;
  2404. TCustomDirView * DView = DirView(Side);
  2405. if ((DView->ItemFocused != NULL) &&
  2406. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2407. // when resolving links is disabled, default action is to enter the directory,
  2408. // no matter what DoubleClickAction is configured to
  2409. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2410. // Can only Edit files, but can Open/Copy even directories
  2411. ((DoubleClickAction != dcaEdit) ||
  2412. !DView->ItemIsDirectory(DView->ItemFocused)))
  2413. {
  2414. Item->Options = O << tboDefault;
  2415. }
  2416. else
  2417. {
  2418. Item->Options = O >> tboDefault;
  2419. }
  2420. }
  2421. //---------------------------------------------------------------------------
  2422. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2423. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2424. {
  2425. TCustomDirView * DView = DirView(Side);
  2426. TListItem * Item = DView->ItemFocused;
  2427. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2428. EnableFocusedOperation[Side])
  2429. {
  2430. TPoint ClientPoint;
  2431. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2432. TPoint(0, 0) : MousePos;
  2433. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2434. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2435. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2436. }
  2437. }
  2438. //---------------------------------------------------------------------------
  2439. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2440. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2441. {
  2442. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2443. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2444. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2445. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2446. Handled = true;
  2447. }
  2448. //---------------------------------------------------------------------------
  2449. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2450. {
  2451. }
  2452. //---------------------------------------------------------------------------
  2453. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2454. {
  2455. DebugAssert(FErrorList == NULL);
  2456. if (WinConfiguration->ContinueOnError)
  2457. {
  2458. FErrorList = new TStringList();
  2459. Configuration->Usage->Inc(L"ContinuationsOnError");
  2460. }
  2461. NonVisualDataModule->StartBusy();
  2462. }
  2463. //---------------------------------------------------------------------------
  2464. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2465. {
  2466. NonVisualDataModule->EndBusy();
  2467. if (FErrorList)
  2468. {
  2469. HandleErrorList(FErrorList);
  2470. }
  2471. }
  2472. //---------------------------------------------------------------------------
  2473. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2474. const TCopyParamType & CopyParam)
  2475. {
  2476. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2477. {
  2478. Configuration->Usage->Inc(L"FileMaskUses");
  2479. }
  2480. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2481. {
  2482. Configuration->Usage->Inc(L"OperationMaskUses");
  2483. }
  2484. }
  2485. //---------------------------------------------------------------------------
  2486. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2487. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2488. {
  2489. DebugAssert(!IsLocalBrowserMode());
  2490. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2491. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2492. TTransferOperationParam DefaultParam;
  2493. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2494. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2495. switch (Param.Queue)
  2496. {
  2497. case asOn:
  2498. CopyParam.Queue = true;
  2499. break;
  2500. case asOff:
  2501. CopyParam.Queue = false;
  2502. break;
  2503. case asAuto:
  2504. default:
  2505. // keep default
  2506. break;
  2507. }
  2508. bool Result =
  2509. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2510. if (Result)
  2511. {
  2512. DebugAssert(Terminal);
  2513. bool SelectionRestored = false;
  2514. TCustomDirView * DView = NULL;
  2515. if (HasDirView[Side])
  2516. {
  2517. DView = DirView(Side);
  2518. DView->SaveSelection();
  2519. DView->SaveSelectedNames();
  2520. }
  2521. UpdateCopyParamCounters(CopyParam);
  2522. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2523. DebugAssert(FTransferResumeList == NULL);
  2524. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2525. FMoveToQueue = false;
  2526. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2527. try
  2528. {
  2529. TStrings * PermanentFileList;
  2530. std::unique_ptr<TStrings> PermanentFileListOwner;
  2531. try
  2532. {
  2533. if (Side == osLocal)
  2534. {
  2535. PermanentFileList = FileList;
  2536. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2537. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2538. if (Operation == foMove)
  2539. {
  2540. ReloadLocalDirectory();
  2541. if (DView != NULL)
  2542. {
  2543. DView->RestoreSelection();
  2544. }
  2545. SelectionRestored = true;
  2546. }
  2547. }
  2548. else
  2549. {
  2550. // Clone the file list as it may refer to current directory files,
  2551. // which get destroyed, when the source directory is reloaded after foMove operation.
  2552. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2553. // But for a hotfix, we are not going to do such a big change.
  2554. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2555. PermanentFileList = PermanentFileListOwner.get();
  2556. try
  2557. {
  2558. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2559. }
  2560. __finally
  2561. {
  2562. if (Operation == foMove)
  2563. {
  2564. if (DView != NULL)
  2565. {
  2566. DView->RestoreSelection();
  2567. }
  2568. SelectionRestored = true;
  2569. }
  2570. ReloadLocalDirectory(Param.TargetDirectory);
  2571. }
  2572. }
  2573. // When the transfer batch is aborted between individual file transfers, the Abort is not called.
  2574. if (FMoveToQueue)
  2575. {
  2576. Abort();
  2577. }
  2578. }
  2579. catch (EAbort &)
  2580. {
  2581. if (FMoveToQueue)
  2582. {
  2583. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2584. DebugAssert(CopyParam.TransferSkipList == NULL);
  2585. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2586. if (TransferResumeList->Count > 0)
  2587. {
  2588. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2589. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2590. }
  2591. CopyParam.TransferSkipList = TransferResumeList.release();
  2592. // not really needed, just to keep it consistent with TransferResumeList
  2593. FTransferResumeList = NULL;
  2594. FMoveToQueue = false;
  2595. Configuration->Usage->Inc("MovesToBackground");
  2596. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2597. ClearTransferSourceSelection(Direction);
  2598. }
  2599. throw;
  2600. }
  2601. }
  2602. __finally
  2603. {
  2604. if (!SelectionRestored && (DView != NULL))
  2605. {
  2606. DView->DiscardSavedSelection();
  2607. }
  2608. FTransferResumeList = NULL;
  2609. }
  2610. }
  2611. return Result;
  2612. }
  2613. //---------------------------------------------------------------------------
  2614. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2615. TOperationSide Side, TStrings * FileList, void * Param)
  2616. {
  2617. DebugAssert(FileList->Count);
  2618. // We deliberately do not toggle alternative flag (Param), but use OR,
  2619. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2620. // shortcut of CurrentDeleteAlternativeAction
  2621. bool Alternative =
  2622. bool(Param) || UseAlternativeFunction();
  2623. bool Recycle;
  2624. if (IsSideLocalBrowser(Side))
  2625. {
  2626. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2627. }
  2628. else
  2629. {
  2630. Recycle =
  2631. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2632. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2633. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2634. }
  2635. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2636. if (!Result)
  2637. {
  2638. UnicodeString Query;
  2639. if (FileList->Count == 1)
  2640. {
  2641. if (IsSideLocalBrowser(Side))
  2642. {
  2643. Query = ExtractFileName(FileList->Strings[0]);
  2644. }
  2645. else
  2646. {
  2647. Query = UnixExtractFileName(FileList->Strings[0]);
  2648. }
  2649. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2650. }
  2651. else
  2652. {
  2653. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2654. }
  2655. TMessageParams Params(mpNeverAskAgainCheck);
  2656. Params.ImageName = L"Delete file";
  2657. unsigned int Answer =
  2658. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2659. if (Answer == qaNeverAskAgain)
  2660. {
  2661. Result = true;
  2662. if (Recycle)
  2663. {
  2664. WinConfiguration->ConfirmRecycling = false;
  2665. }
  2666. else
  2667. {
  2668. WinConfiguration->ConfirmDeleting = false;
  2669. }
  2670. }
  2671. else
  2672. {
  2673. Result = (Answer == qaOK);
  2674. }
  2675. }
  2676. if (Result)
  2677. {
  2678. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2679. }
  2680. return Result;
  2681. }
  2682. //---------------------------------------------------------------------------
  2683. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2684. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2685. {
  2686. TAutoBatch AutoBatch(this);
  2687. bool Result;
  2688. if (TFileOperationProgressType::IsTransferOperation(Operation))
  2689. {
  2690. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2691. }
  2692. else if (Operation == foRename)
  2693. {
  2694. DebugAssert(DirView(Side)->ItemFocused);
  2695. DirView(Side)->ItemFocused->EditCaption();
  2696. Result = true;
  2697. }
  2698. else if (Operation == foDelete)
  2699. {
  2700. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2701. }
  2702. else if (Operation == foSetProperties)
  2703. {
  2704. DirView(osRemote)->SaveSelectedNames();
  2705. Result = SetProperties(Side, FileList);
  2706. }
  2707. else if (Operation == foCustomCommand)
  2708. {
  2709. DebugAssert(Param);
  2710. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2711. DirView(osRemote)->SaveSelectedNames();
  2712. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2713. CustomCommand(FileList, *Command, NULL);
  2714. Result = true;
  2715. }
  2716. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2717. {
  2718. DebugAssert(!IsSideLocalBrowser(Side));
  2719. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2720. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2721. }
  2722. else if (Operation == foLock)
  2723. {
  2724. DebugAssert(!IsSideLocalBrowser(Side));
  2725. LockFiles(FileList, true);
  2726. Result = true;
  2727. }
  2728. else if (Operation == foUnlock)
  2729. {
  2730. DebugAssert(!IsSideLocalBrowser(Side));
  2731. LockFiles(FileList, false);
  2732. Result = true;
  2733. }
  2734. else
  2735. {
  2736. DebugFail();
  2737. }
  2738. return Result;
  2739. }
  2740. //---------------------------------------------------------------------------
  2741. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2742. {
  2743. if (Side == osCurrent)
  2744. {
  2745. Side = FCurrentSide;
  2746. }
  2747. return Side;
  2748. }
  2749. //---------------------------------------------------------------------------
  2750. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2751. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2752. {
  2753. Side = GetSide(Side);
  2754. bool FullPath = IsSideLocalBrowser(Side);
  2755. TCustomDirView * ADirView = DirView(Side);
  2756. std::unique_ptr<TStringList> FileList(new TStringList());
  2757. ADirView->CreateFileList(OnFocused, FullPath, FileList.get());
  2758. bool ReloadProperties =
  2759. (Side == osRemote) && (Operation == foSetProperties) &&
  2760. DebugAlwaysTrue(HasActiveTerminal()) && Terminal->IsCapable[fcLoadingAdditionalProperties];
  2761. bool Result = ExecuteFileOperation(Operation, Side, FileList.get(), NoConfirmation, Param);
  2762. if (Result && ReloadProperties)
  2763. {
  2764. std::unique_ptr<TStringList> FileList2(new TStringList());
  2765. FileList->CaseSensitive = true;
  2766. FileList->Sort();
  2767. for (int Index = 0; Index < ADirView->Items->Count; Index++)
  2768. {
  2769. TListItem * Item = ADirView->Items->Item[Index];
  2770. UnicodeString FileName = ADirView->ItemFileName(Item);
  2771. int Index2;
  2772. if (FileList->Find(FileName, Index2))
  2773. {
  2774. FileList2->AddObject(FileName, ADirView->ItemData(Item));
  2775. }
  2776. }
  2777. LoadFilesProperties(FileList2.get());
  2778. }
  2779. return Result;
  2780. }
  2781. //---------------------------------------------------------------------------
  2782. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2783. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2784. bool NoConfirmation, void * Param)
  2785. {
  2786. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2787. {
  2788. if (TFileOperationProgressType::IsTransferOperation(Operation))
  2789. {
  2790. DebugAssert(!IsLocalBrowserMode());
  2791. if (GetSide(Side) == osLocal)
  2792. {
  2793. Configuration->Usage->Inc(L"UploadsCommand");
  2794. }
  2795. else
  2796. {
  2797. Configuration->Usage->Inc(L"DownloadsCommand");
  2798. }
  2799. }
  2800. }
  2801. }
  2802. //---------------------------------------------------------------------------
  2803. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2804. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2805. {
  2806. TTransferOperationParam Param;
  2807. if ((WinConfiguration->Interface != ifCommander) ||
  2808. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2809. {
  2810. Flags &= ~cocShortCutHint;
  2811. }
  2812. TCustomDirView * DView = DirView(Side);
  2813. Param.Options =
  2814. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2815. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2816. if (FLAGSET(Flags, cocQueue))
  2817. {
  2818. Param.Queue = asOn;
  2819. }
  2820. else if (FLAGSET(Flags, cocNonQueue))
  2821. {
  2822. Param.Queue = asOff;
  2823. }
  2824. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2825. }
  2826. //---------------------------------------------------------------------------
  2827. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2828. {
  2829. int Count = ErrorList->Count;
  2830. try
  2831. {
  2832. if (ErrorList->Count)
  2833. {
  2834. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2835. if (MessageDialog(Message, qtError,
  2836. qaOK | qaCancel, HELP_NONE) == qaOK)
  2837. {
  2838. unsigned int Answer;
  2839. int Index = 0;
  2840. do
  2841. {
  2842. DebugAssert(Index >= 0 && Index < Count);
  2843. TQueryButtonAlias Aliases[2];
  2844. Aliases[0].Button = qaYes;
  2845. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2846. Aliases[1].Button = qaNo;
  2847. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2848. TMessageParams Params;
  2849. Params.Aliases = Aliases;
  2850. Params.AliasesCount = LENOF(Aliases);
  2851. int No = Index + 1;
  2852. UnicodeString Message = ErrorList->Strings[Index];
  2853. UnicodeString AMainInstructions;
  2854. UnicodeString Details;
  2855. if (ExtractMainInstructions(Message, AMainInstructions))
  2856. {
  2857. Details = Message;
  2858. Message = AMainInstructions;
  2859. }
  2860. Message = MainInstructions(FMTLOAD(ERROR_LIST_NUMBER, (No, Count, Message))) + Details;
  2861. Answer = MoreMessageDialog(
  2862. Message,
  2863. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2864. (Index ? qaYes : 0) | (Index < Count - 1 ? qaNo : 0) |
  2865. qaOK, HELP_NONE, &Params);
  2866. if (Answer == qaNo)
  2867. {
  2868. Index++;
  2869. }
  2870. if (Answer == qaYes)
  2871. {
  2872. Index--;
  2873. }
  2874. }
  2875. while (Answer != qaOK);
  2876. }
  2877. }
  2878. }
  2879. __finally
  2880. {
  2881. TStrings * List = ErrorList;
  2882. ErrorList = NULL;
  2883. for (int i = 0; i < Count; i++)
  2884. {
  2885. delete List->Objects[i];
  2886. }
  2887. delete List;
  2888. }
  2889. }
  2890. //---------------------------------------------------------------------------
  2891. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2892. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2893. {
  2894. // needed for checking filemasks, as there's no directory object
  2895. // associated with the file object
  2896. File->FullFileName = FullFileName;
  2897. TFileMasks::TParams MaskParams;
  2898. MaskParams.Size = File->Size;
  2899. MaskParams.Modification = File->Modification;
  2900. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2901. }
  2902. //---------------------------------------------------------------------------
  2903. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2904. {
  2905. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2906. Side = GetSide(Side);
  2907. TCustomDirView * DView = DirView(Side);
  2908. TListItem * FocusedItem = DView->ItemFocused;
  2909. UnicodeString Name;
  2910. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2911. {
  2912. Name = DView->ItemFileName(FocusedItem);
  2913. }
  2914. else
  2915. {
  2916. Name = LoadStr(NEW_FILE);
  2917. }
  2918. UnicodeString Names = Name;
  2919. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2920. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2921. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  2922. {
  2923. while (!Names.IsEmpty())
  2924. {
  2925. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2926. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2927. UnicodeString TargetFileName;
  2928. UnicodeString LocalFileName;
  2929. UnicodeString RootTempDir;
  2930. UnicodeString TempDir;
  2931. UnicodeString RemoteDirectory;
  2932. bool ExistingFile = false;
  2933. if (!IsSideLocalBrowser(Side))
  2934. {
  2935. Name = AbsolutePath(Terminal->CurrentDirectory, Name);
  2936. TRemoteFile * File = NULL;
  2937. if (Terminal->FileExists(Name, &File) &&
  2938. !File->IsDirectory)
  2939. {
  2940. try
  2941. {
  2942. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2943. ExistingFile = true;
  2944. }
  2945. __finally
  2946. {
  2947. delete File;
  2948. }
  2949. }
  2950. if (!ExistingFile)
  2951. {
  2952. RemoteDirectory = UnixExtractFilePath(Name);
  2953. TemporaryDirectoryForRemoteFiles(
  2954. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2955. TargetFileName = UnixExtractFileName(Name);
  2956. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2957. LocalFileName = TempDir +
  2958. // We probably do not want to trim the VMS version here
  2959. Terminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2960. }
  2961. }
  2962. else
  2963. {
  2964. if (ExtractFilePath(Name).IsEmpty())
  2965. {
  2966. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2967. }
  2968. else
  2969. {
  2970. LocalFileName = ExpandFileName(Name);
  2971. }
  2972. TargetFileName = ExtractFileName(Name);
  2973. }
  2974. if (!ExistingFile)
  2975. {
  2976. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2977. if (NewFile)
  2978. {
  2979. int File = FileCreate(ApiPath(LocalFileName));
  2980. if (File < 0)
  2981. {
  2982. if (!RootTempDir.IsEmpty())
  2983. {
  2984. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2985. }
  2986. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2987. }
  2988. else
  2989. {
  2990. FileClose(File);
  2991. }
  2992. }
  2993. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2994. const TEditorData * ExternalEditor = NULL;
  2995. TFileMasks::TParams MaskParams; // size not known
  2996. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2997. false, MaskParams);
  2998. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2999. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  3000. }
  3001. }
  3002. }
  3003. }
  3004. //---------------------------------------------------------------------------
  3005. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  3006. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  3007. {
  3008. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3009. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3010. DebugAssert(ExecuteFileBy != efDefaultEditor);
  3011. return
  3012. ((ExecuteFileBy == efInternalEditor)) ||
  3013. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  3014. }
  3015. //---------------------------------------------------------------------------
  3016. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  3017. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  3018. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  3019. UnicodeString RemoteDirectory, bool NewFile)
  3020. {
  3021. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3022. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3023. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3024. DebugAssert(ExecuteFileBy != efDefaultEditor);
  3025. Side = GetSide(Side);
  3026. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  3027. if (!IsSideLocalBrowser(Side))
  3028. {
  3029. Data->Terminal = Terminal;
  3030. Data->Queue = Queue;
  3031. Data->SessionData = CloneCurrentSessionData();
  3032. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  3033. Data->RemoteDirectory = RemoteDirectory;
  3034. Data->SessionName = Terminal->SessionData->SessionName;
  3035. Data->LocalRootDirectory = LocalRootDirectory;
  3036. Data->OriginalFileName = OriginalFileName;
  3037. Data->Command = L""; // will be changed later for external editor
  3038. }
  3039. if (ExecuteFileBy == efInternalEditor)
  3040. {
  3041. if (!IsSideLocalBrowser(Side))
  3042. {
  3043. UnicodeString RemotePath = UnixCombinePaths(RemoteDirectory, OriginalFileName);
  3044. UnicodeString Caption = RemotePath + TitleSeparator + Terminal->SessionData->SessionName;
  3045. TForm * Editor;
  3046. try
  3047. {
  3048. TNotifyEvent OnFileChanged = NULL;
  3049. TNotifyEvent OnSaveAll = NULL;
  3050. TAnyModifiedEvent OnAnyModified = NULL;
  3051. // Edited files are uploaded in background queue, what we do not support with encrypted files
  3052. if (Terminal->IsCapable[fcBackgroundTransfers])
  3053. {
  3054. OnFileChanged = FEditorManager->FileChanged;
  3055. OnSaveAll = SaveAllInternalEditors;
  3056. OnAnyModified = AnyInternalEditorModified;
  3057. }
  3058. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  3059. FEditorManager->FileReload, FEditorManager->FileClosed,
  3060. OnSaveAll, OnAnyModified,
  3061. Caption, StandaloneOperation, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  3062. }
  3063. catch(...)
  3064. {
  3065. if (!LocalRootDirectory.IsEmpty())
  3066. {
  3067. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  3068. }
  3069. throw;
  3070. }
  3071. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  3072. }
  3073. else
  3074. {
  3075. DebugAssert(!StandaloneOperation);
  3076. TForm * Editor =
  3077. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  3078. SaveAllInternalEditors, AnyInternalEditorModified,
  3079. L"", false, SessionColor, -1, NewFile);
  3080. FLocalEditors->Add(Editor);
  3081. }
  3082. }
  3083. else
  3084. {
  3085. HANDLE Process;
  3086. if (ExecuteFileBy == efExternalEditor)
  3087. {
  3088. UnicodeString Program, Params, Dir;
  3089. Data->Command = ExternalEditor->ExternalEditor;
  3090. ReformatFileNameCommand(Data->Command);
  3091. SplitCommand(Data->Command, Program, Params, Dir);
  3092. Params = ExpandFileNameCommand(Params, FileName);
  3093. Program = ExpandEnvironmentVariables(Program);
  3094. if (!ExecuteShell(Program, Params, Process))
  3095. {
  3096. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3097. }
  3098. }
  3099. else
  3100. {
  3101. DebugAssert(!IsSideLocalBrowser(Side));
  3102. if (!ExecuteShell(FileName, L"", Process))
  3103. {
  3104. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3105. }
  3106. }
  3107. if (IsSideLocalBrowser(Side) ||
  3108. ((ExecuteFileBy == efShell) &&
  3109. !WinConfiguration->Editor.SDIShellEditor) ||
  3110. ((ExecuteFileBy == efExternalEditor) &&
  3111. !ExternalEditor->SDIExternalEditor))
  3112. {
  3113. // no need for handle
  3114. if (Process != NULL)
  3115. {
  3116. DebugCheck(CloseHandle(Process));
  3117. }
  3118. Process = INVALID_HANDLE_VALUE;
  3119. }
  3120. else
  3121. {
  3122. if (Process == NULL)
  3123. {
  3124. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3125. }
  3126. }
  3127. if (!IsSideLocalBrowser(Side))
  3128. {
  3129. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3130. }
  3131. }
  3132. }
  3133. //---------------------------------------------------------------------------
  3134. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3135. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3136. void * /*Arg*/)
  3137. {
  3138. if (Token != NULL)
  3139. {
  3140. EditorFormFileSave(static_cast<TForm *>(Token));
  3141. }
  3142. }
  3143. //---------------------------------------------------------------------------
  3144. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3145. {
  3146. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3147. {
  3148. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3149. }
  3150. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3151. }
  3152. //---------------------------------------------------------------------------
  3153. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3154. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3155. void * Arg)
  3156. {
  3157. if ((Token != NULL) &&
  3158. IsEditorFormModified(static_cast<TForm *>(Token)))
  3159. {
  3160. *static_cast<bool *>(Arg) = true;
  3161. }
  3162. }
  3163. //---------------------------------------------------------------------------
  3164. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3165. TObject * /*Sender*/, bool & Modified)
  3166. {
  3167. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3168. {
  3169. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3170. {
  3171. Modified = true;
  3172. }
  3173. }
  3174. if (!Modified)
  3175. {
  3176. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3177. }
  3178. }
  3179. //---------------------------------------------------------------------------
  3180. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3181. {
  3182. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3183. }
  3184. //---------------------------------------------------------------------------
  3185. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3186. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3187. UnicodeString & Result, UnicodeString & RootDirectory)
  3188. {
  3189. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3190. {
  3191. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3192. Result = RootDirectory;
  3193. }
  3194. else
  3195. {
  3196. RootDirectory = L"";
  3197. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3198. Result = IncludeTrailingBackslash(Result);
  3199. }
  3200. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3201. {
  3202. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3203. }
  3204. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3205. {
  3206. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3207. {
  3208. RemoteDirectory.Delete(1, 1);
  3209. }
  3210. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3211. }
  3212. if (!ForceDirectories(ApiPath(Result)))
  3213. {
  3214. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3215. }
  3216. }
  3217. //---------------------------------------------------------------------------
  3218. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3219. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3220. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3221. {
  3222. DebugAssert(!IsLocalBrowserMode());
  3223. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3224. if (ForceText)
  3225. {
  3226. CopyParam.TransferMode = tmAscii;
  3227. }
  3228. TemporaryFileCopyParam(CopyParam);
  3229. if (AllFiles)
  3230. {
  3231. CopyParam.IncludeFileMask = TFileMasks();
  3232. }
  3233. if (TempDir.IsEmpty())
  3234. {
  3235. TemporaryDirectoryForRemoteFiles(Terminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3236. }
  3237. DebugAssert(!FAutoOperation);
  3238. FAutoOperation = AutoOperation;
  3239. Terminal->ExceptionOnFail = true;
  3240. try
  3241. {
  3242. try
  3243. {
  3244. // turn off confirmations, as for MDI editors we may possibly download
  3245. // the same file over
  3246. Terminal->CopyToLocal(
  3247. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3248. if (GetTargetNames)
  3249. {
  3250. for (int i = 0; i < FileList->Count; i++)
  3251. {
  3252. FileList->Strings[i] =
  3253. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3254. }
  3255. }
  3256. }
  3257. catch(...)
  3258. {
  3259. if (!RootTempDir.IsEmpty())
  3260. {
  3261. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3262. }
  3263. throw;
  3264. }
  3265. }
  3266. __finally
  3267. {
  3268. FAutoOperation = false;
  3269. Terminal->ExceptionOnFail = false;
  3270. }
  3271. }
  3272. //---------------------------------------------------------------------------
  3273. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3274. {
  3275. // Do not waste time checking for default editor list the next time,
  3276. // or testing if default editor is not notepad.
  3277. bool TryNextTime = false;
  3278. UnicodeString UsageState;
  3279. if (!WinConfiguration->EditorList->IsDefaultList())
  3280. {
  3281. UsageState = "H";
  3282. }
  3283. else
  3284. {
  3285. UnicodeString Executable;
  3286. UnicodeString ExecutableDescription;
  3287. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3288. {
  3289. UnicodeString Message =
  3290. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3291. unsigned int Answer =
  3292. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3293. if (Answer != qaOK)
  3294. {
  3295. UsageState = "R";
  3296. }
  3297. else
  3298. {
  3299. UsageState = "A";
  3300. TEditorData EditorData;
  3301. EditorData.Editor = edExternal;
  3302. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3303. EditorData.ExternalEditorOptionsAutodetect();
  3304. TEditorList EditorList;
  3305. EditorList = *WinConfiguration->EditorList;
  3306. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3307. WinConfiguration->EditorList = &EditorList;
  3308. }
  3309. }
  3310. }
  3311. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3312. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3313. }
  3314. //---------------------------------------------------------------------------
  3315. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3316. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3317. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3318. {
  3319. if (ExecuteFileBy == efDefaultEditor)
  3320. {
  3321. if (!WinConfiguration->OfferedEditorAutoConfig)
  3322. {
  3323. EditorAutoConfig();
  3324. }
  3325. const TEditorPreferences * Editor =
  3326. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3327. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3328. {
  3329. ExecuteFileBy = efInternalEditor;
  3330. ExternalEditor = NULL;
  3331. }
  3332. else if (Editor->Data->Editor == edOpen)
  3333. {
  3334. ExecuteFileBy = efShell;
  3335. ExternalEditor = NULL;
  3336. }
  3337. else
  3338. {
  3339. ExecuteFileBy = efExternalEditor;
  3340. ExternalEditor = Editor->Data;
  3341. }
  3342. }
  3343. }
  3344. //---------------------------------------------------------------------------
  3345. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3346. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3347. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3348. {
  3349. UnicodeString OriginalFileName;
  3350. UnicodeString LocalRootDirectory;
  3351. UnicodeString RemoteDirectory;
  3352. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3353. IsSideLocalBrowser(Side), MaskParams);
  3354. UnicodeString Counter;
  3355. UnicodeString LocalFileName;
  3356. bool Handled = false;
  3357. if (!IsSideLocalBrowser(Side))
  3358. {
  3359. // We need to trim VMS version here, so that we use name without version
  3360. // when uploading back to create a new version of the file
  3361. OriginalFileName = Terminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3362. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3363. TObject * Token = NULL;
  3364. UnicodeString LocalDirectory;
  3365. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3366. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3367. LocalDirectory))
  3368. {
  3369. if (Token != NULL)
  3370. {
  3371. TForm * Form = dynamic_cast<TForm *>(Token);
  3372. if (Form->WindowState == wsMinimized)
  3373. {
  3374. ShowWindow(Form->Handle, SW_RESTORE);
  3375. }
  3376. else
  3377. {
  3378. Form->SetFocus();
  3379. }
  3380. Handled = true;
  3381. }
  3382. else
  3383. {
  3384. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3385. }
  3386. }
  3387. if (!Handled)
  3388. {
  3389. TStringList * FileList1 = new TStringList();
  3390. try
  3391. {
  3392. FileList1->AddObject(FullFileName, Object);
  3393. TemporarilyDownloadFiles(FileList1,
  3394. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3395. LocalRootDirectory, LocalDirectory, true, true, true);
  3396. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3397. }
  3398. __finally
  3399. {
  3400. delete FileList1;
  3401. }
  3402. switch (ExecuteFileBy)
  3403. {
  3404. case efShell:
  3405. Counter = "RemoteFilesExecuted";
  3406. break;
  3407. case efInternalEditor:
  3408. Counter = "RemoteFilesOpenedInInternalEditor";
  3409. break;
  3410. case efExternalEditor:
  3411. Counter = "RemoteFilesOpenedInExternalEditor";
  3412. break;
  3413. default:
  3414. DebugFail();
  3415. }
  3416. }
  3417. }
  3418. else
  3419. {
  3420. LocalFileName = FullFileName;
  3421. OriginalFileName = ExtractFileName(FullFileName);
  3422. switch (ExecuteFileBy)
  3423. {
  3424. case efShell:
  3425. Counter = "LocalFilesExecuted";
  3426. break;
  3427. case efInternalEditor:
  3428. Counter = "LocalFilesOpenedInInternalEditor";
  3429. break;
  3430. case efExternalEditor:
  3431. Counter = "LocalFilesOpenedInExternalEditor";
  3432. break;
  3433. default:
  3434. DebugFail();
  3435. }
  3436. }
  3437. if (!Handled)
  3438. {
  3439. Configuration->Usage->Inc(Counter);
  3440. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3441. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3442. }
  3443. }
  3444. //---------------------------------------------------------------------------
  3445. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3446. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3447. bool AllSelected, bool OnFocused)
  3448. {
  3449. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3450. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3451. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3452. Side = GetSide(Side);
  3453. TCustomDirView * DView = DirView(Side);
  3454. TStrings * FileList =
  3455. AllSelected ?
  3456. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3457. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3458. try
  3459. {
  3460. DebugAssert(AllSelected || (FileList->Count == 1));
  3461. for (int i = 0; i < FileList->Count; i++)
  3462. {
  3463. UnicodeString ListFileName = FileList->Strings[i];
  3464. UnicodeString FileNameOnly =
  3465. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3466. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3467. if (!DView->ItemIsDirectory(Item))
  3468. {
  3469. UnicodeString FullFileName;
  3470. if (!IsSideLocalBrowser(Side))
  3471. {
  3472. FullFileName = DirView(Side)->Path + ListFileName;
  3473. }
  3474. else
  3475. {
  3476. FullFileName = ListFileName;
  3477. }
  3478. TFileMasks::TParams MaskParams;
  3479. MaskParams.Size = DView->ItemFileSize(Item);
  3480. TDateTimePrecision Precision;
  3481. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3482. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3483. FileList->Objects[i], MaskParams);
  3484. }
  3485. }
  3486. }
  3487. __finally
  3488. {
  3489. delete FileList;
  3490. }
  3491. }
  3492. //---------------------------------------------------------------------------
  3493. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3494. {
  3495. CopyParam.FileNameCase = ncNoChange;
  3496. CopyParam.PreserveRights = false;
  3497. CopyParam.PreserveReadOnly = false;
  3498. CopyParam.ReplaceInvalidChars = true;
  3499. CopyParam.IncludeFileMask = TFileMasks();
  3500. CopyParam.NewerOnly = false;
  3501. CopyParam.FileMask = L"";
  3502. }
  3503. //---------------------------------------------------------------------------
  3504. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3505. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3506. {
  3507. TTerminalManager * Manager = TTerminalManager::Instance();
  3508. if (!IsActiveTerminal(Data->Terminal))
  3509. {
  3510. if (!NonVisualDataModule->Busy)
  3511. {
  3512. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3513. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3514. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3515. if (Data->Terminal == NULL)
  3516. {
  3517. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3518. if (SameSiteTerminal != NULL)
  3519. {
  3520. UnicodeString Message =
  3521. FMTLOAD(EDIT_SESSION_REATTACH,
  3522. (FileNameOnly, Data->SessionName, FileNameOnly));
  3523. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3524. {
  3525. Data->Terminal = Terminal;
  3526. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3527. Data->SessionName = Terminal->SessionData->SessionName;
  3528. // We might also overwrite session data
  3529. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3530. }
  3531. else
  3532. {
  3533. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3534. Abort();
  3535. }
  3536. }
  3537. }
  3538. // foreground session should reconnect itself
  3539. else if (Terminal != Data->Terminal)
  3540. {
  3541. UnicodeString Message =
  3542. MainInstructions(
  3543. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3544. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3545. {
  3546. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3547. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3548. }
  3549. else
  3550. {
  3551. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3552. Abort();
  3553. }
  3554. }
  3555. }
  3556. if (!IsActiveTerminal(Data->Terminal))
  3557. {
  3558. Configuration->Usage->Inc(L"EditInactiveSession");
  3559. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3560. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3561. (ExtractFileName(FileName), Data->SessionName)));
  3562. }
  3563. }
  3564. TStrings * FileList = new TStringList();
  3565. try
  3566. {
  3567. FileList->Add(FileName);
  3568. // consider using the same settings (preset) as when the file was downloaded
  3569. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3570. TemporaryFileCopyParam(CopyParam);
  3571. if (Data->ForceText)
  3572. {
  3573. CopyParam.TransferMode = tmAscii;
  3574. }
  3575. // so i do not need to worry if masking algorithm works in all cases
  3576. // ("" means "copy file name", no masking is actually done)
  3577. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3578. {
  3579. CopyParam.FileMask = L"";
  3580. }
  3581. else
  3582. {
  3583. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3584. }
  3585. DebugAssert(Data->Queue != NULL);
  3586. int Params = cpNoConfirmation | cpTemporary;
  3587. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3588. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3589. QueueItem->CompleteEvent = UploadCompleteEvent;
  3590. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3591. }
  3592. __finally
  3593. {
  3594. delete FileList;
  3595. }
  3596. }
  3597. //---------------------------------------------------------------------------
  3598. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3599. const UnicodeString FileName, const TEditedFileData * Data)
  3600. {
  3601. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3602. DebugAssert(!NonVisualDataModule->Busy);
  3603. if (!IsActiveTerminal(Data->Terminal))
  3604. {
  3605. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3606. (ExtractFileName(FileName), Data->SessionName)));
  3607. }
  3608. TManagedTerminal * PrevSession = TTerminalManager::Instance()->ActiveSession;
  3609. TTerminalManager::Instance()->ActiveSession = Data->Terminal;
  3610. NonVisualDataModule->StartBusy();
  3611. try
  3612. {
  3613. std::unique_ptr<TRemoteFile> File;
  3614. UnicodeString RemoteFileName =
  3615. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3616. Terminal->ExceptionOnFail = true;
  3617. try
  3618. {
  3619. TRemoteFile * AFile = NULL;
  3620. Terminal->ReadFile(RemoteFileName, AFile);
  3621. File.reset(AFile);
  3622. if (!File->HaveFullFileName)
  3623. {
  3624. File->FullFileName = RemoteFileName;
  3625. }
  3626. }
  3627. __finally
  3628. {
  3629. Terminal->ExceptionOnFail = false;
  3630. }
  3631. std::unique_ptr<TStrings> FileList(new TStringList());
  3632. FileList->AddObject(RemoteFileName, File.get());
  3633. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3634. UnicodeString TempDir = ExtractFilePath(FileName);
  3635. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3636. TempDir, true, true, true);
  3637. // sanity check, the target file name should be still the same
  3638. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3639. }
  3640. __finally
  3641. {
  3642. NonVisualDataModule->EndBusy();
  3643. // it actually may not exist anymore...
  3644. TTerminalManager::Instance()->ActiveSession = PrevSession;
  3645. }
  3646. }
  3647. //---------------------------------------------------------------------------
  3648. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3649. const TEditedFileData * Data, bool & KeepOpen)
  3650. {
  3651. // Command is set for external editors only (not for "shell" open).
  3652. if (!Data->Command.IsEmpty())
  3653. {
  3654. bool AnyFound = false;
  3655. bool AnyMDI = false;
  3656. bool AnyNonMDI = false;
  3657. bool AnyDetect = false;
  3658. TEditorList * EditorList = new TEditorList();
  3659. try
  3660. {
  3661. *EditorList = *WinConfiguration->EditorList;
  3662. for (int i = 0; i < EditorList->Count; i++)
  3663. {
  3664. const TEditorPreferences * Editor = EditorList->Editors[i];
  3665. if ((Editor->Data->Editor == edExternal) &&
  3666. (Editor->Data->ExternalEditor == Data->Command))
  3667. {
  3668. AnyFound = true;
  3669. if (Editor->Data->SDIExternalEditor)
  3670. {
  3671. AnyNonMDI = true;
  3672. if (Editor->Data->DetectMDIExternalEditor)
  3673. {
  3674. AnyDetect = true;
  3675. }
  3676. }
  3677. else
  3678. {
  3679. AnyMDI = true;
  3680. }
  3681. }
  3682. }
  3683. bool EnableMDI = false;
  3684. bool DisableDetect = false;
  3685. if (AnyMDI)
  3686. {
  3687. KeepOpen = true;
  3688. if (AnyNonMDI)
  3689. {
  3690. // there is at least one instance of the editor with MDI support enabled,
  3691. // and one with disabled, enable it for all instances
  3692. EnableMDI = true;
  3693. }
  3694. }
  3695. else if (AnyFound && !AnyDetect)
  3696. {
  3697. // at least once instance found but all have MDI autodetection disabled
  3698. // => close the file (default action)
  3699. }
  3700. else
  3701. {
  3702. // no instance of the editor has MDI support enabled
  3703. TMessageParams Params;
  3704. if (AnyFound)
  3705. {
  3706. // there is at least one instance of the editor
  3707. Params.Params |= mpNeverAskAgainCheck;
  3708. }
  3709. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3710. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3711. switch (Answer)
  3712. {
  3713. case qaNeverAskAgain:
  3714. DisableDetect = true;
  3715. break;
  3716. case qaNo:
  3717. EnableMDI = true;
  3718. KeepOpen = true;
  3719. break;
  3720. }
  3721. }
  3722. if (AnyFound && (EnableMDI || DisableDetect))
  3723. {
  3724. bool Changed = false;
  3725. for (int i = 0; i < EditorList->Count; i++)
  3726. {
  3727. const TEditorPreferences * Editor = EditorList->Editors[i];
  3728. if ((Editor->Data->Editor == edExternal) &&
  3729. (Editor->Data->ExternalEditor == Data->Command) &&
  3730. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3731. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3732. {
  3733. Changed = true;
  3734. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3735. if (EnableMDI)
  3736. {
  3737. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3738. }
  3739. if (DisableDetect)
  3740. {
  3741. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3742. }
  3743. EditorList->Change(i, UpdatedEditor);
  3744. }
  3745. }
  3746. if (Changed)
  3747. {
  3748. WinConfiguration->EditorList = EditorList;
  3749. }
  3750. }
  3751. }
  3752. __finally
  3753. {
  3754. delete EditorList;
  3755. }
  3756. }
  3757. else
  3758. {
  3759. // "open" case
  3760. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3761. qaOK, HELP_APP_EARLY_CLOSED);
  3762. }
  3763. }
  3764. //---------------------------------------------------------------------------
  3765. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3766. {
  3767. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3768. }
  3769. //---------------------------------------------------------------------------
  3770. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3771. {
  3772. SideEnter(osRemote);
  3773. }
  3774. //---------------------------------------------------------------------------
  3775. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3776. {
  3777. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3778. SideEnter(osRemote);
  3779. }
  3780. //---------------------------------------------------------------------------
  3781. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3782. {
  3783. FCurrentSide = Side;
  3784. if (Visible)
  3785. {
  3786. UpdateControls();
  3787. }
  3788. }
  3789. //---------------------------------------------------------------------------
  3790. void __fastcall TCustomScpExplorerForm::FileDeleted(TOperationSide Side, const UnicodeString & FileName, bool Success)
  3791. {
  3792. VisualiseOperationFinished(Side, FileName, Success);
  3793. if (DebugAlwaysTrue(FDeletedFiles != NULL) && Success)
  3794. {
  3795. FDeletedFiles->Add(FileName);
  3796. }
  3797. }
  3798. //---------------------------------------------------------------------------
  3799. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3800. TStrings * FileList, bool Alternative)
  3801. {
  3802. TCustomDirView * DView = DirView(Side);
  3803. DView->SaveSelection();
  3804. DView->SaveSelectedNames();
  3805. DebugAssert(!FAlternativeDelete);
  3806. FAlternativeDelete = Alternative;
  3807. try
  3808. {
  3809. if (!IsSideLocalBrowser(Side))
  3810. {
  3811. DebugAssert(Terminal != NULL);
  3812. // Clone the file list as it may refer to current directory files, which get destroyed, when the directory is reloaded after the operation
  3813. std::unique_ptr<TStrings> PermanentFileList(TRemoteFileList::CloneStrings(FileList));
  3814. std::unique_ptr<TStringList> DeletedFiles(new TStringList());
  3815. DeletedFiles->CaseSensitive = DebugAlwaysTrue(!IsSideLocalBrowser(Side));
  3816. int Params = FLAGMASK(Alternative, dfAlternative);
  3817. try
  3818. {
  3819. TValueRestorer<TStrings *> DeletedFilesRestorer(FDeletedFiles);
  3820. DebugAssert(FDeletedFiles == NULL);
  3821. FDeletedFiles = DeletedFiles.get();
  3822. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  3823. FOnFileOperationFinished = FileDeleted;
  3824. FMoveToQueue = false;
  3825. Terminal->DeleteFiles(FileList, Params);
  3826. // Probably not needed for deleting, just for consistency with transfer code
  3827. if (FMoveToQueue)
  3828. {
  3829. Abort();
  3830. }
  3831. }
  3832. catch (EAbort &)
  3833. {
  3834. if (FMoveToQueue)
  3835. {
  3836. DeletedFiles->Sorted = true;
  3837. for (int Index = 0; Index < PermanentFileList->Count; Index++)
  3838. {
  3839. if (DeletedFiles->IndexOf(PermanentFileList->Strings[Index]) >= 0)
  3840. {
  3841. // We should always be deleting the first item => what can be used to optimize this code, if needed
  3842. DebugAssert(Index == 0);
  3843. PermanentFileList->Delete(Index);
  3844. Index--;
  3845. }
  3846. }
  3847. Configuration->Usage->Inc("MovesToBackgroundDelete");
  3848. TQueueItem * QueueItem = new TDeleteQueueItem(Terminal, PermanentFileList.get(), Params);
  3849. AddQueueItem(Queue, QueueItem, Terminal);
  3850. ClearOperationSelection(osRemote);
  3851. }
  3852. }
  3853. }
  3854. else
  3855. {
  3856. if (IsLocalBrowserMode())
  3857. {
  3858. Configuration->Usage->Inc(L"LocalLocalDeletes");
  3859. }
  3860. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  3861. FProgressSide = FCurrentSide;
  3862. try
  3863. {
  3864. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3865. }
  3866. __finally
  3867. {
  3868. ReloadLocalDirectory();
  3869. }
  3870. }
  3871. FAlternativeDelete = false;
  3872. }
  3873. catch(...)
  3874. {
  3875. FAlternativeDelete = false;
  3876. DView->DiscardSavedSelection();
  3877. throw;
  3878. }
  3879. DView->RestoreSelection();
  3880. }
  3881. //---------------------------------------------------------------------------
  3882. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3883. {
  3884. DebugAssert(Terminal);
  3885. DebugAssert(!IsLocalBrowserMode());
  3886. RemoteDirView->SaveSelection();
  3887. RemoteDirView->SaveSelectedNames();
  3888. try
  3889. {
  3890. if (Lock)
  3891. {
  3892. Terminal->LockFiles(FileList);
  3893. }
  3894. else
  3895. {
  3896. Terminal->UnlockFiles(FileList);
  3897. }
  3898. }
  3899. catch(...)
  3900. {
  3901. RemoteDirView->DiscardSavedSelection();
  3902. throw;
  3903. }
  3904. RemoteDirView->RestoreSelection();
  3905. }
  3906. //---------------------------------------------------------------------------
  3907. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3908. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3909. bool NoConfirmation, bool Move)
  3910. {
  3911. DebugAssert(Terminal != NULL);
  3912. DebugAssert(Terminal == TTerminalManager::Instance()->ActiveTerminal);
  3913. DebugAssert(!IsLocalBrowserMode());
  3914. if (Session == NULL)
  3915. {
  3916. Session = Terminal;
  3917. }
  3918. if (Session == Terminal)
  3919. {
  3920. if (RemoteDriveView->DropTarget != NULL)
  3921. {
  3922. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3923. }
  3924. else if (RemoteDirView->DropTarget != NULL)
  3925. {
  3926. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3927. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3928. }
  3929. else
  3930. {
  3931. Target = RemoteDirView->Path;
  3932. }
  3933. }
  3934. else
  3935. {
  3936. Target = GetSessionPath(Session, osRemote);
  3937. }
  3938. Target = UnixIncludeTrailingBackslash(Target);
  3939. if (FileList->Count == 1)
  3940. {
  3941. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3942. }
  3943. else
  3944. {
  3945. FileMask = AnyMask;
  3946. }
  3947. DirectCopy = Terminal->IsCapable[fcRemoteCopy] || Terminal->IsCapable[fcSecondaryShell];
  3948. bool Result = true;
  3949. if (!NoConfirmation)
  3950. {
  3951. bool Multi = (FileList->Count > 1);
  3952. if (Move)
  3953. {
  3954. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3955. }
  3956. else
  3957. {
  3958. std::unique_ptr<TStrings> Sessions(new TStringList);
  3959. std::unique_ptr<TStrings> Directories(new TStringList);
  3960. TStrings * SessionList = TTerminalManager::Instance()->SessionList;
  3961. for (int Index = 0; Index < SessionList->Count; Index++)
  3962. {
  3963. TManagedTerminal * ASession = DebugNotNull(dynamic_cast<TManagedTerminal *>(SessionList->Objects[Index]));
  3964. if (IsActiveTerminal(ASession) && DebugAlwaysTrue(!ASession->LocalBrowser))
  3965. {
  3966. Sessions->AddObject(SessionList->Strings[Index], ASession);
  3967. Directories->Add(GetSessionPath(ASession, osRemote));
  3968. }
  3969. }
  3970. TDirectRemoteCopy AllowDirectCopy;
  3971. if (Terminal->IsCapable[fcRemoteCopy] || Terminal->CommandSessionOpened)
  3972. {
  3973. DebugAssert(DirectCopy);
  3974. AllowDirectCopy = drcAllow;
  3975. }
  3976. else if (Terminal->IsCapable[fcSecondaryShell])
  3977. {
  3978. DebugAssert(DirectCopy);
  3979. AllowDirectCopy = drcConfirmCommandSession;
  3980. }
  3981. else
  3982. {
  3983. DebugAssert(!DirectCopy);
  3984. AllowDirectCopy = drcDisallow;
  3985. }
  3986. void * ASession = Session;
  3987. Result = DoRemoteCopyDialog(
  3988. Sessions.get(), Directories.get(), AllowDirectCopy, Multi, ASession, Target, FileMask, DirectCopy, Terminal);
  3989. Session = static_cast<TManagedTerminal *>(ASession);
  3990. }
  3991. }
  3992. return Result;
  3993. }
  3994. //---------------------------------------------------------------------------
  3995. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3996. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3997. {
  3998. DebugAssert(!IsLocalBrowserMode());
  3999. bool DirectCopy;
  4000. UnicodeString Target, FileMask;
  4001. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  4002. if (Result)
  4003. {
  4004. if (!Move && !DirectCopy)
  4005. {
  4006. Configuration->Usage->Inc("RemoteCopyTemp");
  4007. UnicodeString RootTempDir;
  4008. UnicodeString TempDir;
  4009. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  4010. TStrings * TemporaryFilesList = new TStringList();
  4011. try
  4012. {
  4013. TMakeLocalFileListParams MakeFileListParam;
  4014. MakeFileListParam.FileList = TemporaryFilesList;
  4015. MakeFileListParam.FileTimes = NULL;
  4016. MakeFileListParam.IncludeDirs = true;
  4017. MakeFileListParam.Recursive = false;
  4018. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  4019. TTerminalManager::Instance()->ActiveSession = Session;
  4020. if (TemporaryFilesList->Count > 0)
  4021. {
  4022. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4023. CopyParam.FileMask = FileMask;
  4024. DebugAssert(!FAutoOperation);
  4025. FAutoOperation = true;
  4026. Terminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  4027. }
  4028. }
  4029. __finally
  4030. {
  4031. delete TemporaryFilesList;
  4032. FAutoOperation = false;
  4033. if (!RootTempDir.IsEmpty())
  4034. {
  4035. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  4036. }
  4037. }
  4038. }
  4039. else
  4040. {
  4041. RemoteDirView->SaveSelection();
  4042. RemoteDirView->SaveSelectedNames();
  4043. try
  4044. {
  4045. if (Move)
  4046. {
  4047. Configuration->Usage->Inc("RemoteMove");
  4048. Terminal->MoveFiles(FileList, Target, FileMask);
  4049. }
  4050. else
  4051. {
  4052. Configuration->Usage->Inc("RemoteCopyDirect");
  4053. DebugAssert(DirectCopy);
  4054. DebugAssert(Session == Terminal);
  4055. if (Terminal->IsCapable[fcRemoteCopy] ||
  4056. Terminal->CommandSessionOpened ||
  4057. CommandSessionFallback())
  4058. {
  4059. Terminal->CopyFiles(FileList, Target, FileMask);
  4060. }
  4061. }
  4062. }
  4063. catch(...)
  4064. {
  4065. RemoteDirView->DiscardSavedSelection();
  4066. throw;
  4067. }
  4068. RemoteDirView->RestoreSelection();
  4069. }
  4070. }
  4071. return Result;
  4072. }
  4073. //---------------------------------------------------------------------------
  4074. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  4075. const UnicodeString & Path, TRemoteProperties & Properties)
  4076. {
  4077. DebugAssert(!IsLocalBrowserMode());
  4078. Properties.Valid = Properties.Valid << vpEncrypt;
  4079. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  4080. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  4081. }
  4082. //---------------------------------------------------------------------------
  4083. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  4084. {
  4085. Side = GetSide(Side);
  4086. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  4087. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  4088. UnicodeString Name = LoadStr(NEW_FOLDER);
  4089. int AllowedChanges =
  4090. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  4091. bool SaveSettings = false;
  4092. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  4093. {
  4094. TWindowLock Lock(this);
  4095. if (!IsSideLocalBrowser(Side))
  4096. {
  4097. if (SaveSettings)
  4098. {
  4099. GUIConfiguration->NewDirectoryProperties = Properties;
  4100. }
  4101. CreateRemoteDirectory(Name, Properties);
  4102. }
  4103. else
  4104. {
  4105. DirView(Side)->CreateDirectory(Name);
  4106. }
  4107. }
  4108. }
  4109. //---------------------------------------------------------------------------
  4110. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  4111. {
  4112. TWindowLock Lock(this);
  4113. DirView(Side)->ExecuteHomeDirectory();
  4114. }
  4115. //---------------------------------------------------------------------------
  4116. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  4117. {
  4118. DoOpenDirectoryDialog(odBrowse, Side);
  4119. }
  4120. //---------------------------------------------------------------------------
  4121. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  4122. {
  4123. TOperationSide BookmarkSide = IsLocalBrowserMode() ? osLocal : Side;
  4124. UnicodeString Path = Bookmark->GetSideDirectory(BookmarkSide);
  4125. bool Result = !Path.IsEmpty();
  4126. if (Result)
  4127. {
  4128. // While we might get here when the session is closed (from location profiles),
  4129. // it's not a problem as the Path setter is noop then
  4130. DirView(Side)->Path = Path;
  4131. }
  4132. return Result;
  4133. }
  4134. //---------------------------------------------------------------------------
  4135. void __fastcall TCustomScpExplorerForm::CalculateSize(
  4136. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  4137. bool & Close)
  4138. {
  4139. // terminal can be already closed (e.g. dropped connection)
  4140. if (Terminal != NULL)
  4141. {
  4142. try
  4143. {
  4144. TCalculateSizeParams Params;
  4145. Params.Stats = &Stats;
  4146. Terminal->CalculateFilesSize(FileList, Size, Params);
  4147. }
  4148. catch(...)
  4149. {
  4150. if (!Terminal->Active)
  4151. {
  4152. Close = true;
  4153. }
  4154. throw;
  4155. }
  4156. }
  4157. }
  4158. //---------------------------------------------------------------------------
  4159. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4160. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4161. bool & Close)
  4162. {
  4163. // terminal can be already closed (e.g. dropped connection)
  4164. if (Terminal != NULL)
  4165. {
  4166. Configuration->Usage->Inc(L"ChecksumCalculated");
  4167. try
  4168. {
  4169. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4170. }
  4171. catch(...)
  4172. {
  4173. if (!Terminal->Active)
  4174. {
  4175. Close = true;
  4176. }
  4177. throw;
  4178. }
  4179. }
  4180. }
  4181. //---------------------------------------------------------------------------
  4182. void TCustomScpExplorerForm::LoadFilesProperties(TStrings * FileList)
  4183. {
  4184. if (Terminal->LoadFilesProperties(FileList))
  4185. {
  4186. RemoteDirView->Invalidate();
  4187. }
  4188. }
  4189. //---------------------------------------------------------------------------
  4190. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4191. {
  4192. bool Result;
  4193. if (!IsSideLocalBrowser(Side))
  4194. {
  4195. TRemoteTokenList * GroupList = NULL;
  4196. TRemoteTokenList * UserList = NULL;
  4197. try
  4198. {
  4199. TRemoteProperties CurrentProperties;
  4200. LoadFilesProperties(FileList);
  4201. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4202. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4203. if (CapableGroupChanging || CapableOwnerChanging)
  4204. {
  4205. if (CapableGroupChanging)
  4206. {
  4207. GroupList = Terminal->Groups->Duplicate();
  4208. }
  4209. if (CapableOwnerChanging)
  4210. {
  4211. UserList = Terminal->Users->Duplicate();
  4212. }
  4213. TRemoteDirectory * Files = Terminal->Files;
  4214. int Count = Files->Count;
  4215. if (Count > 100)
  4216. {
  4217. Count = 100;
  4218. }
  4219. for (int Index = 0; Index < Count; Index++)
  4220. {
  4221. TRemoteFile * File = Files->Files[Index];
  4222. if (CapableGroupChanging)
  4223. {
  4224. GroupList->AddUnique(File->Group);
  4225. }
  4226. if (CapableOwnerChanging)
  4227. {
  4228. UserList->AddUnique(File->Owner);
  4229. }
  4230. }
  4231. // if we haven't collected tokens for all files in current directory,
  4232. // make sure we collect them at least for all selected files.
  4233. // (note that so far the files in FileList has to be from current direcotry)
  4234. if (Count < Files->Count)
  4235. {
  4236. for (int Index = 0; Index < FileList->Count; Index++)
  4237. {
  4238. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4239. if (CapableGroupChanging)
  4240. {
  4241. GroupList->AddUnique(File->Group);
  4242. }
  4243. if (CapableOwnerChanging)
  4244. {
  4245. UserList->AddUnique(File->Owner);
  4246. }
  4247. }
  4248. }
  4249. }
  4250. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4251. bool CapableAclChanging = Terminal->IsCapable[fcAclChangingFiles];
  4252. for (int Index = 0; (Index < FileList->Count) && CapableAclChanging; Index++)
  4253. {
  4254. if (dynamic_cast<TRemoteFile *>(FileList->Objects[Index])->IsDirectory)
  4255. {
  4256. CapableAclChanging = false;
  4257. CurrentProperties.Valid = CurrentProperties.Valid >> vpRights;
  4258. }
  4259. }
  4260. int Flags = 0;
  4261. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4262. if (CapableAclChanging) Flags |= cpAcl;
  4263. if (CapableOwnerChanging) Flags |= cpOwner;
  4264. if (CapableGroupChanging) Flags |= cpGroup;
  4265. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4266. if (Terminal->IsCapable[fcCalculatingChecksum])
  4267. {
  4268. CalculateChecksumEvent = CalculateChecksum;
  4269. }
  4270. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4271. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4272. TRemoteProperties NewProperties = CurrentProperties;
  4273. Result =
  4274. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4275. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4276. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4277. CalculateSize, CalculateChecksumEvent);
  4278. if (Result)
  4279. {
  4280. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4281. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4282. }
  4283. }
  4284. __finally
  4285. {
  4286. delete GroupList;
  4287. delete UserList;
  4288. }
  4289. }
  4290. else
  4291. {
  4292. DirView(Side)->DisplayPropertiesMenu();
  4293. Result = true;
  4294. }
  4295. return Result;
  4296. }
  4297. //---------------------------------------------------------------------------
  4298. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4299. {
  4300. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4301. {
  4302. FIgnoreNextDialogChar = Key;
  4303. }
  4304. Key = 0;
  4305. }
  4306. //---------------------------------------------------------------------------
  4307. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4308. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4309. {
  4310. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4311. if (Command != NULL)
  4312. {
  4313. KeyProcessed(Key, Shift);
  4314. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4315. {
  4316. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4317. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4318. false, false, const_cast<TCustomCommandType *>(Command));
  4319. }
  4320. }
  4321. }
  4322. //---------------------------------------------------------------------------
  4323. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4324. {
  4325. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4326. {
  4327. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4328. }
  4329. if ((Key != 0) && !DirView(osCurrent)->IsEditing())
  4330. {
  4331. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4332. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4333. {
  4334. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4335. // But so far it's not a problem, as it does what we want.
  4336. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4337. if (((Action->ShortCut == KeyShortCut) ||
  4338. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4339. AllowedAction(Action, aaShortCut))
  4340. {
  4341. // Has to be called before the action as the dialog char is already in queue.
  4342. // So when the action consumes message queue, we already need to have the
  4343. // FIgnoreNextDialogChar set
  4344. KeyProcessed(Key, Shift);
  4345. // Reset reference to previous component (when menu/toolbar was clicked).
  4346. // Needed to detect that action was invoked by keyboard shortcut
  4347. // in TNonVisualDataModule::ExplorerActionsExecute
  4348. Action->ActionComponent = NULL;
  4349. Action->Execute();
  4350. return;
  4351. }
  4352. }
  4353. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4354. {
  4355. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4356. {
  4357. KeyProcessed(Key, Shift);
  4358. TTerminalManager::Instance()->ActiveSessionIndex = i;
  4359. return;
  4360. }
  4361. }
  4362. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4363. {
  4364. KeyProcessed(Key, Shift);
  4365. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4366. }
  4367. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4368. if (IsCustomShortCut(CustomShortCut))
  4369. {
  4370. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4371. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4372. if (WinConfiguration->SharedBookmarks != NULL)
  4373. {
  4374. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4375. if ((Bookmark != NULL) &&
  4376. OpenBookmark(FCurrentSide, Bookmark))
  4377. {
  4378. KeyProcessed(Key, Shift);
  4379. }
  4380. }
  4381. }
  4382. }
  4383. TForm::KeyDown(Key, Shift);
  4384. }
  4385. //---------------------------------------------------------------------------
  4386. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4387. {
  4388. bool OpenedTerminal = false;
  4389. UnicodeString ProtocolName;
  4390. UnicodeString ProtocolNameHint;
  4391. UnicodeString SecurityProtocolName;
  4392. UnicodeString DurationHint;
  4393. // See the comment in TScpCommanderForm::UpdateControls()
  4394. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4395. if (ActiveTerminal != NULL)
  4396. {
  4397. // Active is not enough here
  4398. if (ActiveTerminal->Status == ssOpened)
  4399. {
  4400. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4401. const TFileSystemInfo & FileSystemInfo = ActiveTerminal->GetFileSystemInfo();
  4402. if (FileSystemInfo.ProtocolName.IsEmpty())
  4403. {
  4404. ProtocolName = SessionInfo.ProtocolName;
  4405. }
  4406. else
  4407. {
  4408. ProtocolName = FileSystemInfo.ProtocolName;
  4409. }
  4410. ProtocolNameHint = LoadStr(STATUS_PROTOCOL_HINT);
  4411. SecurityProtocolName = SessionInfo.SecurityProtocolName;
  4412. DurationHint = LoadStr(STATUS_DURATION_HINT);
  4413. OpenedTerminal = true;
  4414. }
  4415. else if (ActiveTerminal->Status > ssClosed)
  4416. {
  4417. ProtocolName = LoadStr(STATUS_CONNECTING);
  4418. }
  4419. else
  4420. {
  4421. ProtocolName = LoadStr(STATUS_NOT_CONNECTED2);
  4422. }
  4423. }
  4424. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4425. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4426. TTBXStatusPanel * ProtocolStatusPanel = SessionStatusBar->Panels->Items[Offset + 0];
  4427. ProtocolStatusPanel->ViewPriority = (ActiveTerminal != NULL) ? 100 : 0;
  4428. if (ProtocolStatusPanel->Caption != ProtocolName)
  4429. {
  4430. ProtocolStatusPanel->Caption = ProtocolName;
  4431. std::unique_ptr<TCanvas> Canvas(CreateControlCanvas(SessionStatusBar));
  4432. ProtocolStatusPanel->Size = Canvas->TextWidth(ProtocolName) + ScaleByTextHeight(SessionStatusBar, 32);
  4433. }
  4434. ProtocolStatusPanel->Hint = ProtocolNameHint;
  4435. TTBXStatusPanel * SecurityStatusPanel = SessionStatusBar->Panels->Items[Offset + 1];
  4436. SecurityStatusPanel->ViewPriority = OpenedTerminal ? 98 : 0;
  4437. bool SecurityEnabled = !SecurityProtocolName.IsEmpty();
  4438. SecurityStatusPanel->Enabled = SecurityEnabled;
  4439. UnicodeString SecurityProtocolHint;
  4440. if (SecurityEnabled)
  4441. {
  4442. SecurityProtocolHint = FMTLOAD(STATUS_SECURE, (SecurityProtocolName));
  4443. }
  4444. else
  4445. {
  4446. SecurityProtocolHint = LoadStr(STATUS_INSECURE);
  4447. }
  4448. SecurityStatusPanel->Hint = SecurityProtocolHint;
  4449. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[Offset + 2];
  4450. DurationStatusPanel->ViewPriority = OpenedTerminal ? 99 : 0;
  4451. DurationStatusPanel->Hint = DurationHint;
  4452. UpdateStatusBar();
  4453. }
  4454. //---------------------------------------------------------------------------
  4455. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4456. {
  4457. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4458. DebugAssert(SessionStatusBar != NULL);
  4459. TTBXStatusPanel * NoteStatusPanel = SessionStatusBar->Panels->Items[0];
  4460. if (!FNote.IsEmpty())
  4461. {
  4462. NoteStatusPanel->Caption = FNote;
  4463. }
  4464. else
  4465. {
  4466. UpdateStatusPanelText(NoteStatusPanel);
  4467. }
  4468. NoteStatusPanel->Hint = FNoteHints;
  4469. UnicodeString LoginTime;
  4470. // See the comment in TScpCommanderForm::UpdateControls()
  4471. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4472. // Active is not enough here
  4473. if ((ActiveTerminal != NULL) && (ActiveTerminal->Status == ssOpened))
  4474. {
  4475. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4476. LoginTime = FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4477. }
  4478. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1];
  4479. DurationStatusPanel->Caption = LoginTime;
  4480. }
  4481. //---------------------------------------------------------------------------
  4482. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4483. {
  4484. Panel->Caption = L"";
  4485. }
  4486. //---------------------------------------------------------------------------
  4487. void __fastcall TCustomScpExplorerForm::Idle()
  4488. {
  4489. if (FShowing ||
  4490. // Particularly for
  4491. // - Standalone editing
  4492. // - Detecting closed connection and automatically reconnect it while waiting for changes
  4493. // while "keeping remote directory up to date".
  4494. StandaloneOperation)
  4495. {
  4496. FEditorManager->Check();
  4497. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4498. // that needs to know if queue view is visible (and it may be closed after queue update)
  4499. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4500. }
  4501. if (FShowing)
  4502. {
  4503. if (!NonVisualDataModule->Busy &&
  4504. // Menu is opened or drag&drop is going on
  4505. (Mouse->Capture == NULL))
  4506. {
  4507. if (FRefreshRemoteDirectory)
  4508. {
  4509. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4510. {
  4511. Terminal->RefreshDirectory();
  4512. }
  4513. FRefreshRemoteDirectory = false;
  4514. }
  4515. if (FRefreshLocalDirectory)
  4516. {
  4517. ReloadLocalDirectory();
  4518. FRefreshLocalDirectory = false;
  4519. }
  4520. if (WinConfiguration->RefreshRemotePanel)
  4521. {
  4522. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4523. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4524. {
  4525. RemoteDirView->ReloadDirectory();
  4526. }
  4527. }
  4528. }
  4529. }
  4530. if (FShowing || StandaloneOperation)
  4531. {
  4532. if (FQueueStatusInvalidated)
  4533. {
  4534. UpdateQueueStatus(false);
  4535. }
  4536. RefreshQueueItems();
  4537. }
  4538. if (FShowing)
  4539. {
  4540. UpdateStatusBar();
  4541. }
  4542. if (FClipboardFakeMonitorsPendingReset && !FDownloadingFromClipboard)
  4543. {
  4544. FClipboardFakeMonitorsPendingReset = false;
  4545. FClipboardFakeMonitors.reset(NULL);
  4546. }
  4547. FIgnoreNextDialogChar = 0;
  4548. }
  4549. //---------------------------------------------------------------------------
  4550. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4551. {
  4552. try
  4553. {
  4554. FUserActionTimer->Enabled = false;
  4555. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4556. {
  4557. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4558. {
  4559. FPendingQueueActionItem->ProcessUserAction();
  4560. }
  4561. }
  4562. }
  4563. __finally
  4564. {
  4565. FPendingQueueActionItem = NULL;
  4566. }
  4567. }
  4568. //---------------------------------------------------------------------------
  4569. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4570. {
  4571. if (WinConfiguration->MinimizeToTray)
  4572. {
  4573. UpdateTrayIcon();
  4574. FTrayIcon->Visible = true;
  4575. if (Visible)
  4576. {
  4577. ShowWindow(Handle, SW_HIDE);
  4578. }
  4579. }
  4580. }
  4581. //---------------------------------------------------------------------------
  4582. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4583. {
  4584. // WORKAROUND
  4585. // When restoring maximized window from minimization,
  4586. // rarely some controls do not align properly.
  4587. // Two instances seen (both for Commander):
  4588. // - When restoring, window is temporarily narrower (not maximized),
  4589. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4590. // Once maximized already, top dock shinks back, but the session PageControl,
  4591. // do not align up, leaving space between TopDock and PageControl.
  4592. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4593. for (int Index = 0; Index < ControlCount; Index++)
  4594. {
  4595. RealignControl(Controls[Index]);
  4596. }
  4597. if (FTrayIcon->Visible)
  4598. {
  4599. FTrayIcon->Visible = false;
  4600. if (Visible)
  4601. {
  4602. ShowWindow(Handle, SW_SHOW);
  4603. }
  4604. }
  4605. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4606. {
  4607. FNeedSession = false;
  4608. NonVisualDataModule->StartBusy();
  4609. try
  4610. {
  4611. NeedSession(true);
  4612. }
  4613. __finally
  4614. {
  4615. NonVisualDataModule->EndBusy();
  4616. }
  4617. }
  4618. }
  4619. //---------------------------------------------------------------------------
  4620. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4621. {
  4622. FTrayIcon->Hint = GetMainForm()->Caption;
  4623. }
  4624. //---------------------------------------------------------------------------
  4625. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4626. {
  4627. UpdateTrayIcon();
  4628. }
  4629. //---------------------------------------------------------------------------
  4630. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4631. {
  4632. // workaround
  4633. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4634. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4635. // But WM_ACTIVATEAPP message can be received even when
  4636. // the main window is minimized to the tray and internal editor window is focused
  4637. // (after another application was previously active)
  4638. if (::IsIconic(Handle))
  4639. {
  4640. if (!IsAppIconic())
  4641. {
  4642. SetAppIconic(true);
  4643. }
  4644. }
  4645. ::ApplicationRestore();
  4646. Application->BringToFront();
  4647. }
  4648. //---------------------------------------------------------------------------
  4649. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4650. {
  4651. RestoreApp();
  4652. }
  4653. //---------------------------------------------------------------------------
  4654. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4655. {
  4656. if (OpenInNewWindow())
  4657. {
  4658. ExecuteNewInstance(SessionUrl);
  4659. }
  4660. else
  4661. {
  4662. TTerminalManager::Instance()->NewSession(SessionUrl);
  4663. }
  4664. }
  4665. //---------------------------------------------------------------------------
  4666. void TCustomScpExplorerForm::NewTab(TOperationSide)
  4667. {
  4668. NewSession();
  4669. }
  4670. //---------------------------------------------------------------------------
  4671. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4672. {
  4673. UnicodeString SessionName = StoredSessions->HiddenPrefix + ManagedSession->SessionData->SessionName;
  4674. StoredSessions->NewSession(SessionName, SessionData);
  4675. // modified only, explicit
  4676. StoredSessions->Save(false, true);
  4677. // encode session name because of slashes in hierarchical sessions
  4678. return EncodeUrlString(SessionName);
  4679. }
  4680. //---------------------------------------------------------------------------
  4681. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4682. {
  4683. // current working directories become defaults here, what is not right
  4684. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4685. return SaveHiddenDuplicateSession(SessionData.get());
  4686. }
  4687. //---------------------------------------------------------------------------
  4688. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4689. {
  4690. if (OpenInNewWindow())
  4691. {
  4692. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4693. }
  4694. else
  4695. {
  4696. // current working directories become defaults here, what is not right
  4697. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4698. TTerminalManager * Manager = TTerminalManager::Instance();
  4699. TManagedTerminal * ASession = Manager->NewManagedTerminal(SessionData.get());
  4700. DebugAssert(ASession->LocalBrowser == ManagedSession->LocalBrowser);
  4701. // We definitelly want these
  4702. ASession->Disconnected = ManagedSession->Disconnected;
  4703. // Not sure about these two
  4704. ASession->Permanent = ManagedSession->Permanent;
  4705. ASession->DisconnectedTemporarily = ManagedSession->DisconnectedTemporarily;
  4706. Manager->ActiveSession = ASession;
  4707. }
  4708. }
  4709. //---------------------------------------------------------------------------
  4710. void __fastcall TCustomScpExplorerForm::RenameSession()
  4711. {
  4712. UnicodeString Name = ManagedSession->SessionData->SessionName;
  4713. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME) &&
  4714. // When submitting the default name, do not fix it
  4715. (Name != ManagedSession->SessionData->SessionName))
  4716. {
  4717. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4718. TSessionData::ValidateName(Name);
  4719. // This is inconsistent with how color (for example) is handled.
  4720. ManagedSession->SessionData->Name = Name;
  4721. UpdateControls();
  4722. // Add/Remove distinguishing paths from sessions of the same name.
  4723. SessionListChanged();
  4724. }
  4725. }
  4726. //---------------------------------------------------------------------------
  4727. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4728. {
  4729. DebugAssert(Queue != NULL);
  4730. bool Result = Queue->IsEmpty;
  4731. if (!Result)
  4732. {
  4733. SetFocus();
  4734. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4735. }
  4736. return Result;
  4737. }
  4738. //---------------------------------------------------------------------------
  4739. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4740. {
  4741. return CanCloseQueue(FQueue);
  4742. }
  4743. //---------------------------------------------------------------------------
  4744. void __fastcall TCustomScpExplorerForm::CloseSession()
  4745. {
  4746. if (CanCloseQueue())
  4747. {
  4748. TTerminalManager::Instance()->FreeActiveTerminal();
  4749. }
  4750. }
  4751. //---------------------------------------------------------------------------
  4752. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4753. {
  4754. if (CanCloseQueue())
  4755. {
  4756. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4757. }
  4758. }
  4759. //---------------------------------------------------------------------------
  4760. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4761. {
  4762. DetachTerminal(Terminal);
  4763. RemoteDirView->Terminal = Terminal;
  4764. UpdateRemotePathComboBox(false);
  4765. InitStatusBar();
  4766. UpdateControls();
  4767. }
  4768. //---------------------------------------------------------------------------
  4769. void __fastcall TCustomScpExplorerForm::TerminalConnecting()
  4770. {
  4771. InitStatusBar();
  4772. }
  4773. //---------------------------------------------------------------------------
  4774. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4775. {
  4776. if (DebugAlwaysTrue(!Terminal->Active))
  4777. {
  4778. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4779. }
  4780. }
  4781. //---------------------------------------------------------------------------
  4782. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4783. {
  4784. if (OpenInNewWindow())
  4785. {
  4786. // encode session name because of slashes in hierarchical sessions
  4787. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4788. }
  4789. else
  4790. {
  4791. TTerminalManager * Manager = TTerminalManager::Instance();
  4792. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4793. Manager->ActiveSession = Terminal;
  4794. }
  4795. }
  4796. //---------------------------------------------------------------------------
  4797. void TCustomScpExplorerForm::DoOpenFolderOrWorkspace(
  4798. const UnicodeString & Name, bool ConnectFirstTerminal, bool CheckMaxSessions)
  4799. {
  4800. TTerminalManager * Manager = TTerminalManager::Instance();
  4801. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4802. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4803. if (!CheckMaxSessions || (DataList->Count <= WinConfiguration->MaxSessions))
  4804. {
  4805. TManagedTerminal * FirstSession = Manager->NewSessions(DataList.get());
  4806. // FirstSession can be null, if some of the
  4807. if (!ConnectFirstTerminal && (FirstSession != NULL))
  4808. {
  4809. FirstSession->Disconnected = true;
  4810. FirstSession->DisconnectedTemporarily = true;
  4811. }
  4812. Manager->ActiveSession = FirstSession;
  4813. }
  4814. }
  4815. //---------------------------------------------------------------------------
  4816. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4817. {
  4818. if (OpenInNewWindow())
  4819. {
  4820. ExecuteNewInstance(Name);
  4821. }
  4822. else
  4823. {
  4824. DoOpenFolderOrWorkspace(Name, true, false);
  4825. }
  4826. }
  4827. //---------------------------------------------------------------------------
  4828. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4829. bool &CanClose)
  4830. {
  4831. // See the comment in CloseApp()
  4832. if (NonVisualDataModule->Busy)
  4833. {
  4834. CanClose = false;
  4835. }
  4836. else
  4837. {
  4838. TTerminalManager * Manager = TTerminalManager::Instance();
  4839. int ActiveSessions = 0;
  4840. for (int Index = 0; Index < Manager->Count; Index++)
  4841. {
  4842. if (Manager->Sessions[Index]->Active)
  4843. {
  4844. ActiveSessions++;
  4845. }
  4846. }
  4847. // Confirm, when there's at least one active remote session or
  4848. // when there are multiple (inactive or local) sessions and auto workspace saving is not enabled.
  4849. if (((ActiveSessions > 0) || ((Manager->Count > 1) && !WinConfiguration->AutoSaveWorkspace)) &&
  4850. WinConfiguration->ConfirmClosingSession)
  4851. {
  4852. unsigned int Result;
  4853. TMessageParams Params(mpNeverAskAgainCheck);
  4854. UnicodeString Message;
  4855. int Answers = qaOK | qaCancel;
  4856. // The current session is the only active session
  4857. if ((ActiveSessions == 1) && (Terminal != NULL) && Terminal->Active)
  4858. {
  4859. if (!WinConfiguration->AutoSaveWorkspace)
  4860. {
  4861. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4862. }
  4863. else
  4864. {
  4865. Message = LoadStr(CLOSE_SESSION);
  4866. }
  4867. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4868. }
  4869. // Multiple active sessions or one active session, but it's not the current one
  4870. else if (ActiveSessions > 0)
  4871. {
  4872. if (!WinConfiguration->AutoSaveWorkspace)
  4873. {
  4874. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4875. }
  4876. else
  4877. {
  4878. Message = LoadStr(CLOSE_SESSIONS);
  4879. }
  4880. }
  4881. // Multiple tabs, but all are intactive or local, and saving of worspace is not enabled
  4882. else
  4883. {
  4884. DebugAlwaysTrue(Manager->Count > 1);
  4885. DebugAlwaysTrue(!WinConfiguration->AutoSaveWorkspace);
  4886. Message = LoadStr(CLOSE_WORKSPACE);
  4887. }
  4888. UnicodeString Note;
  4889. if (WinConfiguration->AutoSaveWorkspace)
  4890. {
  4891. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4892. }
  4893. else
  4894. {
  4895. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4896. Answers = qaYes | qaNo | qaCancel;
  4897. }
  4898. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4899. SetFocus();
  4900. Result = MessageDialog(Message, qtConfirmation,
  4901. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4902. if (Result == qaNeverAskAgain)
  4903. {
  4904. WinConfiguration->ConfirmClosingSession = false;
  4905. }
  4906. if (Result == qaNo)
  4907. {
  4908. CanClose = SaveWorkspace(true);
  4909. // note that the workspace will be saved redundatly again from FormClose
  4910. }
  4911. else
  4912. {
  4913. CanClose =
  4914. (Result == qaOK) ||
  4915. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4916. (Result == qaNeverAskAgain);
  4917. }
  4918. }
  4919. if (CanClose && HasActiveTerminal())
  4920. {
  4921. CanClose = CanCloseQueue();
  4922. }
  4923. }
  4924. if (CanClose)
  4925. {
  4926. CanClose =
  4927. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4928. FEditorManager->CloseExternalFilesWithoutProcess();
  4929. if (CanClose)
  4930. {
  4931. while (CanClose && (FLocalEditors->Count > 0))
  4932. {
  4933. int PrevCount = FLocalEditors->Count;
  4934. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4935. CanClose = (FLocalEditors->Count < PrevCount);
  4936. }
  4937. if (CanClose)
  4938. {
  4939. CanClose = FEditorManager->Empty(true);
  4940. if (!CanClose)
  4941. {
  4942. SetFocus();
  4943. CanClose =
  4944. (MessageDialog(
  4945. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4946. }
  4947. }
  4948. }
  4949. }
  4950. }
  4951. //---------------------------------------------------------------------------
  4952. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4953. {
  4954. TForm * Form = dynamic_cast<TForm *>(Sender);
  4955. DebugAssert(Form != NULL);
  4956. Form->Close();
  4957. }
  4958. //---------------------------------------------------------------------------
  4959. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4960. {
  4961. TForm * Form = dynamic_cast<TForm *>(Sender);
  4962. delete Form;
  4963. }
  4964. //---------------------------------------------------------------------------
  4965. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4966. {
  4967. while (FLocalEditors->Count > 0)
  4968. {
  4969. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4970. }
  4971. }
  4972. //---------------------------------------------------------------------------
  4973. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4974. TObject *Sender)
  4975. {
  4976. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4977. try
  4978. {
  4979. SetProperties(osRemote, FileList);
  4980. }
  4981. __finally
  4982. {
  4983. delete FileList;
  4984. }
  4985. }
  4986. //---------------------------------------------------------------------------
  4987. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4988. {
  4989. if (value)
  4990. {
  4991. if (Component == fcCustomCommandsBand)
  4992. {
  4993. UpdateCustomCommandsToolbar();
  4994. }
  4995. if (Component == fcQueueFileList)
  4996. {
  4997. DebugAssert(!QueueFileListSplitter->Visible);
  4998. AdjustQueueLayout();
  4999. UpdateQueueFileList();
  5000. }
  5001. }
  5002. }
  5003. //---------------------------------------------------------------------------
  5004. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  5005. {
  5006. int MinHeightLimit =
  5007. GetStaticQueuePanelComponentsHeight() +
  5008. QueueFileListSplitter->Height +
  5009. QueueFileList->Height +
  5010. GetMinQueueViewHeight();
  5011. if (QueuePanel->ClientHeight < MinHeightLimit)
  5012. {
  5013. QueuePanel->ClientHeight = MinHeightLimit;
  5014. }
  5015. }
  5016. //---------------------------------------------------------------------------
  5017. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  5018. {
  5019. TControl * Control = GetComponent(Component);
  5020. DebugAssert(Control);
  5021. bool Changed = (Control->Visible != value);
  5022. if (Changed)
  5023. {
  5024. ComponentShowing(Component, value);
  5025. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  5026. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  5027. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  5028. if (value)
  5029. {
  5030. int RemainingHeight = Control->Parent->ClientHeight;
  5031. int RemainingWidth = Control->Parent->ClientWidth;
  5032. for (int i = 0; i < Control->Parent->ControlCount; i++)
  5033. {
  5034. TControl * ChildControl = Control->Parent->Controls[i];
  5035. if (ChildControl->Visible)
  5036. {
  5037. switch (ChildControl->Align)
  5038. {
  5039. case alTop:
  5040. case alBottom:
  5041. RemainingHeight -= ChildControl->Height;
  5042. break;
  5043. case alLeft:
  5044. case alRight:
  5045. RemainingWidth -= ChildControl->Width;
  5046. break;
  5047. }
  5048. }
  5049. }
  5050. int Reserve = ScaleByTextHeight(this, 32);
  5051. // queue in explorer, trees in commander
  5052. if (Control->Height > RemainingHeight - Reserve)
  5053. {
  5054. Control->Height = RemainingHeight / 2;
  5055. }
  5056. if (Control->Width > RemainingWidth - Reserve)
  5057. {
  5058. Control->Width = RemainingWidth / 2;
  5059. }
  5060. }
  5061. Control->Visible = value;
  5062. if (WasFocused && Visible)
  5063. {
  5064. DirView(osCurrent)->SetFocus();
  5065. }
  5066. FixControlsPlacement();
  5067. }
  5068. }
  5069. //---------------------------------------------------------------------------
  5070. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  5071. {
  5072. TControl * Control = GetComponent(Component);
  5073. if (Control == NULL)
  5074. {
  5075. return false;
  5076. }
  5077. else
  5078. {
  5079. return Control->Visible;
  5080. }
  5081. }
  5082. //---------------------------------------------------------------------------
  5083. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  5084. {
  5085. bool Result;
  5086. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  5087. {
  5088. Result = !IsUWP();
  5089. }
  5090. else
  5091. {
  5092. Result = true;
  5093. }
  5094. return Result;
  5095. }
  5096. //---------------------------------------------------------------------------
  5097. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  5098. {
  5099. if (DirView->ItemFocused != NULL)
  5100. {
  5101. DirView->ItemFocused->MakeVisible(false);
  5102. }
  5103. }
  5104. //---------------------------------------------------------------------------
  5105. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  5106. {
  5107. MakeFocusedItemVisible(RemoteDirView);
  5108. QueueSplitter->Visible = QueuePanel->Visible;
  5109. QueueFileListSplitter->Visible = QueueFileList->Visible;
  5110. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  5111. TControl * QueueControlsOrder[] =
  5112. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  5113. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  5114. }
  5115. //---------------------------------------------------------------------------
  5116. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  5117. {
  5118. switch (Component) {
  5119. case fcStatusBar: return RemoteStatusBar;
  5120. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  5121. case fcQueueView: return QueuePanel;
  5122. case fcQueueToolbar: return QueueDock;
  5123. case fcRemoteTree: return RemoteDrivePanel;
  5124. case fcSessionsTabs: return SessionsPageControl;
  5125. case fcQueueFileList: return QueueFileList;
  5126. default: return NULL;
  5127. }
  5128. }
  5129. //---------------------------------------------------------------------------
  5130. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  5131. TObject *Sender, TListColumn *Column, TPoint &Point)
  5132. {
  5133. DebugAssert(NonVisualDataModule && Column && Sender);
  5134. NonVisualDataModule->ListColumn = Column;
  5135. TPopupMenu * DirViewColumnMenu;
  5136. if (Sender == DirView(osOther))
  5137. {
  5138. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  5139. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  5140. (Column->Index == uvName);
  5141. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  5142. (Column->Index == uvSize);
  5143. }
  5144. else
  5145. {
  5146. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  5147. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  5148. (Column->Index == dvName);
  5149. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  5150. (Column->Index == dvSize);
  5151. }
  5152. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  5153. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  5154. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  5155. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  5156. }
  5157. //---------------------------------------------------------------------------
  5158. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  5159. TObject *Sender, TListItem *Item, bool &AllowExec)
  5160. {
  5161. DoDirViewExecFile(Sender, Item, AllowExec);
  5162. }
  5163. //---------------------------------------------------------------------------
  5164. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  5165. TListItem * Item, bool & AllowExec)
  5166. {
  5167. DebugAssert(Sender && Item && Configuration);
  5168. DebugAssert(AllowExec);
  5169. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  5170. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  5171. bool Remote = !IsSideLocalBrowser(Side);
  5172. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  5173. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  5174. // on files only (not directories)
  5175. // and only when symlinks are resolved (apply to remote panel only)
  5176. if (!ADirView->ItemIsDirectory(Item) &&
  5177. (ResolvedSymlinks || FForceExecution))
  5178. {
  5179. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  5180. !FForceExecution && ResolvedSymlinks)
  5181. {
  5182. if (WinConfiguration->DoubleClickAction == dcaCopy)
  5183. {
  5184. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  5185. UnlockWindow();
  5186. try
  5187. {
  5188. if (IsLocalBrowserMode())
  5189. {
  5190. LocalLocalCopy(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation, false, 0);
  5191. }
  5192. else
  5193. {
  5194. ExecuteFileOperation(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  5195. }
  5196. }
  5197. __finally
  5198. {
  5199. LockWindow();
  5200. }
  5201. AllowExec = false;
  5202. }
  5203. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  5204. {
  5205. if (!Remote || !WinConfiguration->DisableOpenEdit)
  5206. {
  5207. ExecuteFile(Side, efDefaultEditor);
  5208. AllowExec = false;
  5209. }
  5210. }
  5211. else
  5212. {
  5213. DebugFail();
  5214. }
  5215. }
  5216. // if we have not done anything special, fall back to default behavior
  5217. if (AllowExec)
  5218. {
  5219. if (Remote && !WinConfiguration->DisableOpenEdit)
  5220. {
  5221. ExecuteFile(osRemote, efShell);
  5222. AllowExec = false;
  5223. }
  5224. }
  5225. }
  5226. }
  5227. //---------------------------------------------------------------------------
  5228. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  5229. {
  5230. return ((Side == osRemote) || (Side == osCurrent));
  5231. }
  5232. //---------------------------------------------------------------------------
  5233. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5234. {
  5235. DebugFail();
  5236. }
  5237. //---------------------------------------------------------------------------
  5238. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5239. {
  5240. DebugFail();
  5241. }
  5242. //---------------------------------------------------------------------------
  5243. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5244. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5245. {
  5246. TSynchronizeParamType Params;
  5247. Params.LocalDirectory = LocalDirectory;
  5248. Params.RemoteDirectory = RemoteDirectory;
  5249. int UnusedParams =
  5250. (GUIConfiguration->SynchronizeParams &
  5251. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5252. TTerminal::spCaseSensitive));
  5253. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5254. Params.Options = GUIConfiguration->SynchronizeOptions;
  5255. bool SaveSettings = false;
  5256. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5257. &DoSynchronizeTooManyDirectories);
  5258. DebugAssert(FSynchronizeController == NULL);
  5259. FSynchronizeController = &Controller;
  5260. bool Result;
  5261. try
  5262. {
  5263. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5264. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5265. int Options =
  5266. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5267. DebugAssert(FOnFeedSynchronizeError == NULL);
  5268. DebugAssert(FOnSynchronizeAbort == NULL);
  5269. DebugAssert(FSynchronizeTerminal == NULL);
  5270. FSynchronizeTerminal = Terminal;
  5271. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5272. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5273. FOnFeedSynchronizeError, FOnSynchronizeAbort, SynchronizeInNewWindow, UseDefaults);
  5274. if (Result)
  5275. {
  5276. if (SaveSettings)
  5277. {
  5278. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5279. GUIConfiguration->SynchronizeOptions = Params.Options;
  5280. }
  5281. else
  5282. {
  5283. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5284. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5285. FLAGSET(Params.Options, soSynchronize))
  5286. {
  5287. GUIConfiguration->SynchronizeOptions =
  5288. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5289. soSynchronize;
  5290. }
  5291. }
  5292. LocalDirectory = Params.LocalDirectory;
  5293. RemoteDirectory = Params.RemoteDirectory;
  5294. }
  5295. }
  5296. __finally
  5297. {
  5298. FSynchronizeController = NULL;
  5299. DebugAssert(FOnFeedSynchronizeError == NULL);
  5300. FOnFeedSynchronizeError = NULL;
  5301. DebugAssert(FOnSynchronizeAbort == NULL);
  5302. FOnSynchronizeAbort = NULL;
  5303. FSynchronizeTerminal = NULL;
  5304. }
  5305. return Result;
  5306. }
  5307. //---------------------------------------------------------------------------
  5308. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5309. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5310. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5311. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5312. TSynchronizeOptions * Options, bool Full)
  5313. {
  5314. // Keep-up-to-date mode
  5315. if (Terminal->Status == ssOpened)
  5316. {
  5317. try
  5318. {
  5319. int PParams = Params.Params;
  5320. if (!Full)
  5321. {
  5322. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5323. if (FLAGSET(Params.Options, soRecurse))
  5324. {
  5325. PParams |= TTerminal::spSubDirs;
  5326. }
  5327. }
  5328. else
  5329. {
  5330. // if keepuptodate is non-recursive,
  5331. // full sync before has to be non-recursive as well
  5332. if (FLAGCLEAR(Params.Options, soRecurse))
  5333. {
  5334. PParams |= TTerminal::spNoRecurse;
  5335. }
  5336. }
  5337. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5338. PParams, Checklist, Options);
  5339. }
  5340. catch (Exception & E)
  5341. {
  5342. if (!Terminal->Active)
  5343. {
  5344. ShowExtendedExceptionEx(Terminal, &E);
  5345. // Do not abort the "keep up to date" when the session was succesfully reconnected.
  5346. if (!Terminal->Active)
  5347. {
  5348. throw;
  5349. }
  5350. }
  5351. else
  5352. {
  5353. if (FLAGSET(Params.Options, soContinueOnError) &&
  5354. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5355. {
  5356. // noop, already logged in MoreMessageDialog
  5357. }
  5358. else
  5359. {
  5360. // We get mostly EAbort here, so this is noop.
  5361. // Exception is an error when listing directories while looking for differences.
  5362. ShowExtendedExceptionEx(Terminal, &E);
  5363. throw;
  5364. }
  5365. }
  5366. }
  5367. }
  5368. }
  5369. //---------------------------------------------------------------------------
  5370. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5371. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5372. const UnicodeString ErrorStr)
  5373. {
  5374. if (!Directory.IsEmpty())
  5375. {
  5376. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5377. }
  5378. else
  5379. {
  5380. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5381. }
  5382. }
  5383. //---------------------------------------------------------------------------
  5384. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5385. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5386. {
  5387. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5388. {
  5389. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5390. }
  5391. else
  5392. {
  5393. TMessageParams Params(mpNeverAskAgainCheck);
  5394. unsigned int Result = MessageDialog(
  5395. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5396. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5397. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5398. {
  5399. MaxDirectories *= 2;
  5400. if (Result == qaNeverAskAgain)
  5401. {
  5402. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5403. }
  5404. }
  5405. else
  5406. {
  5407. Abort();
  5408. }
  5409. }
  5410. }
  5411. //---------------------------------------------------------------------------
  5412. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5413. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5414. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5415. TSynchronizeOptions * Options)
  5416. {
  5417. // Keep-up-to-date mode
  5418. DebugAssert(!FAutoOperation);
  5419. void * BatchStorage;
  5420. BatchStart(BatchStorage);
  5421. FAutoOperation = true;
  5422. bool AnyOperation = false;
  5423. TDateTime StartTime = Now();
  5424. TSynchronizeChecklist * AChecklist = NULL;
  5425. try
  5426. {
  5427. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5428. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5429. {
  5430. FSynchronizeProgressForm->Start();
  5431. }
  5432. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5433. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5434. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5435. Options);
  5436. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5437. SAFE_DESTROY(FSynchronizeProgressForm);
  5438. AnyOperation = (AChecklist->CheckedCount > 0);
  5439. if (AnyOperation)
  5440. {
  5441. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5442. CreateProgressForm(&SynchronizeProgress);
  5443. try
  5444. {
  5445. Terminal->SynchronizeApply(
  5446. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5447. SynchronizeProcessedItem, NULL, NULL, NULL);
  5448. }
  5449. __finally
  5450. {
  5451. DestroyProgressForm();
  5452. }
  5453. }
  5454. }
  5455. __finally
  5456. {
  5457. if (Checklist == NULL)
  5458. {
  5459. delete AChecklist;
  5460. }
  5461. else
  5462. {
  5463. *Checklist = AChecklist;
  5464. }
  5465. FAutoOperation = false;
  5466. SAFE_DESTROY(FSynchronizeProgressForm);
  5467. BatchEnd(BatchStorage);
  5468. ReloadLocalDirectory();
  5469. if (AnyOperation)
  5470. {
  5471. OperationComplete(StartTime);
  5472. }
  5473. }
  5474. }
  5475. //---------------------------------------------------------------------------
  5476. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5477. {
  5478. // can be called from command line
  5479. return Visible &&
  5480. ((DirView(osRemote)->SelCount > 0) ||
  5481. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5482. }
  5483. //---------------------------------------------------------------------------
  5484. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5485. {
  5486. LogSynchronizeEvent(Terminal, Message);
  5487. }
  5488. //---------------------------------------------------------------------------
  5489. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5490. int Params, TSynchronizeOptions & Options)
  5491. {
  5492. DebugAssert(!IsLocalBrowserMode());
  5493. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5494. {
  5495. Options.Filter = new TStringList();
  5496. Options.Filter->CaseSensitive = false;
  5497. Options.Filter->Duplicates = Types::dupAccept;
  5498. if (DirView(osRemote)->SelCount > 0)
  5499. {
  5500. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5501. }
  5502. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5503. {
  5504. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5505. }
  5506. Options.Filter->Sort();
  5507. }
  5508. }
  5509. //---------------------------------------------------------------------------
  5510. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5511. {
  5512. TCopyParamType Defaults;
  5513. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5514. ConfigStorage->AccessMode = smRead;
  5515. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5516. {
  5517. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5518. }
  5519. ConfigStorage.reset(NULL);
  5520. std::unique_ptr<TStringList> Options(new TStringList());
  5521. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5522. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5523. UnicodeString Result;
  5524. if (Options->Count > 0)
  5525. {
  5526. Result =
  5527. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5528. }
  5529. return Result;
  5530. }
  5531. //---------------------------------------------------------------------------
  5532. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5533. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5534. {
  5535. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5536. UnicodeString AdditionalParams =
  5537. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5538. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5539. SerializeCopyParamForCommandLine(CopyParams),
  5540. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5541. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5542. ExecuteNewInstance(SessionName, AdditionalParams);
  5543. }
  5544. //---------------------------------------------------------------------------
  5545. struct TSynchronizeParams
  5546. {
  5547. UnicodeString LocalDirectory;
  5548. UnicodeString RemoteDirectory;
  5549. TSynchronizeMode Mode;
  5550. TSynchronizeChecklist * Checklist;
  5551. int Params;
  5552. TCopyParamType * CopyParam;
  5553. TDateTime CollectElapsed;
  5554. TDateTime * StartTime;
  5555. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5556. };
  5557. //---------------------------------------------------------------------------
  5558. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5559. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5560. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5561. {
  5562. DebugAssert(!FAutoOperation);
  5563. void * BatchStorage;
  5564. BatchStart(BatchStorage);
  5565. FAutoOperation = true;
  5566. TFileOperationStatistics Statistics;
  5567. TDateTime Start = Now();
  5568. try
  5569. {
  5570. Params.OnProcessedItem = OnProcessedItem;
  5571. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5572. CreateProgressForm(&SynchronizeProgress);
  5573. Terminal->SynchronizeApply(
  5574. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5575. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5576. &Statistics);
  5577. }
  5578. __finally
  5579. {
  5580. Params.OnProcessedItem = NULL;
  5581. FAutoOperation = false;
  5582. DestroyProgressForm();
  5583. BatchEnd(BatchStorage);
  5584. ReloadLocalDirectory();
  5585. }
  5586. if (WinConfiguration->SynchronizeSummary)
  5587. {
  5588. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5589. // The statistics should be 0 anyway in this case
  5590. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5591. {
  5592. Message += L"\n";
  5593. if (Statistics.FilesUploaded > 0)
  5594. {
  5595. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5596. }
  5597. if (Statistics.FilesDownloaded > 0)
  5598. {
  5599. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5600. }
  5601. if (Statistics.FilesDeletedLocal > 0)
  5602. {
  5603. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5604. }
  5605. if (Statistics.FilesDeletedRemote > 0)
  5606. {
  5607. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5608. }
  5609. }
  5610. TDateTime Elapsed = (Now() - Start);
  5611. Message +=
  5612. L"\n" +
  5613. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5614. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5615. TMessageParams Params(mpNeverAskAgainCheck);
  5616. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5617. if (Result == qaNeverAskAgain)
  5618. {
  5619. WinConfiguration->SynchronizeSummary = false;
  5620. }
  5621. }
  5622. }
  5623. //---------------------------------------------------------------------------
  5624. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5625. {
  5626. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5627. {
  5628. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5629. }
  5630. // Not set in keep-up-to-date mode - Synchronize() method
  5631. if (Token != NULL)
  5632. {
  5633. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5634. if (Params.OnProcessedItem != NULL)
  5635. {
  5636. Params.OnProcessedItem(NULL, ChecklistItem);
  5637. }
  5638. }
  5639. }
  5640. //---------------------------------------------------------------------------
  5641. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5642. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5643. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5644. {
  5645. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5646. *Params.StartTime = Now();
  5647. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5648. }
  5649. //---------------------------------------------------------------------------
  5650. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5651. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5652. {
  5653. // terminal can be already closed (e.g. dropped connection)
  5654. if (Terminal != NULL)
  5655. {
  5656. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5657. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5658. }
  5659. }
  5660. //---------------------------------------------------------------------------
  5661. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5662. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5663. {
  5664. DebugAssert(!IsLocalBrowserMode());
  5665. TAutoBatch AutoBatch(this);
  5666. TAutoFlag AutoOperationFlag(FAutoOperation);
  5667. if (Side == osRemote)
  5668. {
  5669. std::unique_ptr<TStrings> FileList(new TStringList());
  5670. FileList->AddObject(FileName, RemoteFile);
  5671. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5672. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5673. RemoteDirView->SaveSelection();
  5674. RemoteDirView->SaveSelectedNames();
  5675. try
  5676. {
  5677. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5678. }
  5679. catch(...)
  5680. {
  5681. RemoteDirView->DiscardSavedSelection();
  5682. throw;
  5683. }
  5684. RemoteDirView->RestoreSelection();
  5685. }
  5686. else if (DebugAlwaysTrue(Side == osLocal))
  5687. {
  5688. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5689. {
  5690. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5691. }
  5692. UnicodeString Directory = ExtractFileDir(FileName);
  5693. ReloadLocalDirectory(Directory);
  5694. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5695. if (!SamePaths(Directory, NewDirectory))
  5696. {
  5697. ReloadLocalDirectory(NewDirectory);
  5698. }
  5699. }
  5700. }
  5701. //---------------------------------------------------------------------------
  5702. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5703. {
  5704. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5705. if (Side == osLocal)
  5706. {
  5707. if (Action == TSynchronizeChecklist::saDownloadNew)
  5708. {
  5709. OpenFolderInExplorer(LocalPath);
  5710. }
  5711. else
  5712. {
  5713. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5714. }
  5715. }
  5716. else if (DebugAlwaysTrue(Side == osRemote))
  5717. {
  5718. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5719. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5720. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5721. if (!LocalPath.IsEmpty())
  5722. {
  5723. SessionData->LocalDirectory = LocalPath;
  5724. }
  5725. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5726. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5727. }
  5728. }
  5729. //---------------------------------------------------------------------------
  5730. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5731. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5732. const TCopyParamType * CopyParams)
  5733. {
  5734. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5735. UnicodeString AdditionalParams =
  5736. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5737. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5738. SerializeCopyParamForCommandLine(CopyParams),
  5739. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5740. LocalDirectory, RemoteDirectory, Mode, Params));
  5741. ExecuteNewInstance(SessionName, AdditionalParams);
  5742. }
  5743. //---------------------------------------------------------------------------
  5744. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5745. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5746. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5747. {
  5748. int Result;
  5749. bool SaveSettings = false;
  5750. int Options =
  5751. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5752. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5753. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5754. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5755. bool Continue =
  5756. (UseDefaults == 0) ||
  5757. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5758. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5759. if (Continue)
  5760. {
  5761. Configuration->Usage->Inc(L"Synchronizations");
  5762. UpdateCopyParamCounters(CopyParam);
  5763. TSynchronizeOptions SynchronizeOptions;
  5764. GetSynchronizeOptions(Params, SynchronizeOptions);
  5765. if (SaveSettings)
  5766. {
  5767. GUIConfiguration->SynchronizeParams = Params;
  5768. }
  5769. else
  5770. {
  5771. SaveMode = false;
  5772. }
  5773. TDateTime StartTime = Now();
  5774. TSynchronizeChecklist * Checklist = NULL;
  5775. try
  5776. {
  5777. DebugAssert(!FAutoOperation);
  5778. FAutoOperation = true;
  5779. try
  5780. {
  5781. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5782. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5783. int Files = -1;
  5784. if (DataList->Count >= 1)
  5785. {
  5786. Files = StrToIntDef(DataList->Strings[0], Files);
  5787. }
  5788. else
  5789. {
  5790. DataList->Add(UnicodeString());
  5791. }
  5792. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5793. FSynchronizeProgressForm->Start();
  5794. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5795. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5796. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5797. &SynchronizeOptions);
  5798. if (Terminal->SessionData->CacheDirectories)
  5799. {
  5800. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5801. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5802. }
  5803. }
  5804. __finally
  5805. {
  5806. FAutoOperation = false;
  5807. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5808. SAFE_DESTROY(FSynchronizeProgressForm);
  5809. }
  5810. TSynchronizeParams SynchronizeParams;
  5811. SynchronizeParams.LocalDirectory = LocalDirectory;
  5812. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5813. SynchronizeParams.Mode = Mode;
  5814. SynchronizeParams.CopyParam = &CopyParam;
  5815. SynchronizeParams.Params = Params;
  5816. SynchronizeParams.Checklist = Checklist;
  5817. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5818. SynchronizeParams.StartTime = &StartTime;
  5819. SynchronizeParams.OnProcessedItem = NULL;
  5820. Result = Checklist->Count;
  5821. if (Checklist->Count > 0)
  5822. {
  5823. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5824. {
  5825. if (!DoSynchronizeChecklistDialog(
  5826. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5827. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5828. {
  5829. Result = -1;
  5830. }
  5831. }
  5832. else
  5833. {
  5834. FullSynchronize(SynchronizeParams, NULL, NULL);
  5835. }
  5836. }
  5837. else
  5838. {
  5839. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5840. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5841. }
  5842. }
  5843. __finally
  5844. {
  5845. delete Checklist;
  5846. }
  5847. OperationComplete(StartTime);
  5848. }
  5849. else
  5850. {
  5851. Result = -1;
  5852. }
  5853. return Result;
  5854. }
  5855. //---------------------------------------------------------------------------
  5856. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5857. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5858. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5859. {
  5860. if (Collect)
  5861. {
  5862. DebugAssert(FSynchronizeProgressForm != NULL);
  5863. if (!FSynchronizeProgressForm->Started)
  5864. {
  5865. FSynchronizeProgressForm->Start();
  5866. }
  5867. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5868. SetTaskbarListProgressValue(CompareProgress);
  5869. }
  5870. else
  5871. {
  5872. DebugAssert(FSynchronizeProgressForm == NULL);
  5873. DebugAssert(FProgressForm != NULL);
  5874. }
  5875. }
  5876. //---------------------------------------------------------------------------
  5877. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5878. {
  5879. UnicodeString FullFileName = AbsolutePath(Terminal->CurrentDirectory, FileName);
  5880. TRemoteFile * File = NULL;
  5881. Terminal->ReadFile(FullFileName, File);
  5882. if (File != NULL)
  5883. {
  5884. std::unique_ptr<TRemoteFile> FileOwner(File);
  5885. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5886. Application->ShowMainForm = false;
  5887. Application->Run();
  5888. }
  5889. }
  5890. //---------------------------------------------------------------------------
  5891. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  5892. {
  5893. DebugFail();
  5894. }
  5895. //---------------------------------------------------------------------------
  5896. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5897. {
  5898. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5899. SessionData->Assign(ManagedSession->SessionData);
  5900. UpdateSessionData(SessionData.get());
  5901. DebugAssert(SessionData->IsLocalBrowser == IsLocalBrowserMode());
  5902. if (IsActiveTerminal(ManagedSession))
  5903. {
  5904. ManagedSession->UpdateSessionCredentials(SessionData.get());
  5905. }
  5906. if (!ManagedSession->SessionData->HasSessionName())
  5907. {
  5908. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5909. // once IsWorkspace is cleared
  5910. SessionData->Name = UnicodeString();
  5911. }
  5912. // Most uses of this method ends with saving the session, and we do not want to store the IsWorkspace flag.
  5913. // Particularly, with SaveHiddenDuplicateSession, it won't work as TSessionData::ParseUrl explicitly ignored workspace sessions.
  5914. SessionData->IsWorkspace = false;
  5915. return SessionData.release();
  5916. }
  5917. //---------------------------------------------------------------------------
  5918. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5919. {
  5920. TSessionData * SessionData = CloneCurrentSessionData();
  5921. try
  5922. {
  5923. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5924. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5925. }
  5926. __finally
  5927. {
  5928. delete SessionData;
  5929. }
  5930. }
  5931. //---------------------------------------------------------------------------
  5932. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5933. {
  5934. TTerminalManager * Manager = TTerminalManager::Instance();
  5935. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5936. if (DebugAlwaysTrue(ManagedSession != NULL))
  5937. {
  5938. // Update ManagedSession->StateData
  5939. UpdateSession(ManagedSession);
  5940. }
  5941. Manager->SaveWorkspace(DataList.get());
  5942. return DataList.release();
  5943. }
  5944. //---------------------------------------------------------------------------
  5945. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5946. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5947. {
  5948. WinConfiguration->LastWorkspace = Name;
  5949. if (!SavePasswords)
  5950. {
  5951. for (int Index = 0; Index < DataList->Count; Index++)
  5952. {
  5953. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5954. if (SessionData->Link.IsEmpty())
  5955. {
  5956. SessionData->ClearSessionPasswords();
  5957. }
  5958. }
  5959. }
  5960. StoredSessions->NewWorkspace(Name, DataList);
  5961. // modified only
  5962. StoredSessions->Save(false, Explicit);
  5963. }
  5964. //---------------------------------------------------------------------------
  5965. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5966. {
  5967. return
  5968. DefaultStr(WinConfiguration->LastWorkspace,
  5969. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5970. }
  5971. //---------------------------------------------------------------------------
  5972. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5973. {
  5974. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5975. bool AnyNonStoredSessionWithPassword = false;
  5976. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5977. bool AllNonStoredSessionsAnonymous = true;
  5978. TTerminalManager * Manager = TTerminalManager::Instance();
  5979. for (int Index = 0; Index < DataList->Count; Index++)
  5980. {
  5981. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5982. if (SessionData->Link.IsEmpty())
  5983. {
  5984. if (SessionData->HasAnySessionPassword())
  5985. {
  5986. AnyNonStoredSessionWithPassword = true;
  5987. if (!Manager->Sessions[Index]->SessionData->IsWorkspace)
  5988. {
  5989. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5990. }
  5991. }
  5992. if (!SameText(SessionData->UserName, AnonymousUserName))
  5993. {
  5994. AllNonStoredSessionsAnonymous = false;
  5995. }
  5996. }
  5997. }
  5998. bool SavePasswords;
  5999. bool * PSavePasswords;
  6000. bool NotRecommendedSavingPasswords =
  6001. !CustomWinConfiguration->UseMasterPassword &&
  6002. !AllNonStoredSessionsAnonymous;
  6003. if (Configuration->DisablePasswordStoring ||
  6004. !AnyNonStoredSessionWithPassword)
  6005. {
  6006. PSavePasswords = NULL;
  6007. SavePasswords = false;
  6008. }
  6009. else
  6010. {
  6011. PSavePasswords = &SavePasswords;
  6012. SavePasswords =
  6013. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  6014. !NotRecommendedSavingPasswords;
  6015. }
  6016. UnicodeString Name = WorkspaceName();
  6017. bool CreateShortcut = false;
  6018. bool Result =
  6019. DoSaveWorkspaceDialog(
  6020. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  6021. EnableAutoSave);
  6022. if (Result)
  6023. {
  6024. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  6025. if (CreateShortcut)
  6026. {
  6027. TOperationVisualizer Visualizer;
  6028. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  6029. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  6030. }
  6031. if (EnableAutoSave)
  6032. {
  6033. WinConfiguration->AutoSaveWorkspace = true;
  6034. WinConfiguration->AutoWorkspace = Name;
  6035. if (PSavePasswords != NULL)
  6036. {
  6037. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  6038. }
  6039. }
  6040. }
  6041. return Result;
  6042. }
  6043. //---------------------------------------------------------------------------
  6044. void __fastcall TCustomScpExplorerForm::UpdateSession(TManagedTerminal * Session)
  6045. {
  6046. DebugAssert(IsLocalBrowserMode() == Session->LocalBrowser);
  6047. DebugAssert(Session == ManagedSession);
  6048. if (!IsLocalBrowserMode())
  6049. {
  6050. SAFE_DESTROY(Session->RemoteExplorerState);
  6051. if (WinConfiguration->PreservePanelState)
  6052. {
  6053. Session->RemoteExplorerState = RemoteDirView->SaveState();
  6054. }
  6055. }
  6056. UpdateSessionData(Session->StateData);
  6057. }
  6058. //---------------------------------------------------------------------------
  6059. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  6060. {
  6061. // Keep in sync with TSessionData::CopyStateData
  6062. DebugAssert(Data != NULL);
  6063. // This is inconsistent with how color (for example) is handled.
  6064. Data->Name = ManagedSession->SessionData->Name;
  6065. if (!IsLocalBrowserMode())
  6066. {
  6067. // cannot use RemoteDirView->Path, because it is empty if connection
  6068. // was already closed
  6069. // also only peek, we may not be connected at all atm
  6070. // so make sure we do not try retrieving current directory from the server
  6071. // (particularly with FTP)
  6072. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  6073. if (!ACurrentDirectory.IsEmpty())
  6074. {
  6075. Data->RemoteDirectory = ACurrentDirectory;
  6076. }
  6077. }
  6078. Data->Color = SessionColor;
  6079. }
  6080. //---------------------------------------------------------------------------
  6081. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  6082. {
  6083. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  6084. DebugAssert(Toolbar != NULL);
  6085. for (int i = 0; i < Toolbar->Items->Count; i++)
  6086. {
  6087. TTBXCustomDropDownItem * DropDownItem;
  6088. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  6089. if (DropDownItem != NULL)
  6090. {
  6091. ToolbarItemResize(DropDownItem,
  6092. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  6093. Toolbar->NonClientWidth);
  6094. break;
  6095. }
  6096. }
  6097. }
  6098. //---------------------------------------------------------------------------
  6099. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  6100. {
  6101. Item->EditWidth = Width;
  6102. }
  6103. //---------------------------------------------------------------------------
  6104. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  6105. TTBCustomToolbar * Toolbar, TPoint & ASize)
  6106. {
  6107. for (int i = 0; i < Toolbar->Items->Count; i++)
  6108. {
  6109. TTBXCustomDropDownItem * DropDownItem;
  6110. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  6111. if (DropDownItem != NULL)
  6112. {
  6113. ASize.x -= DropDownItem->EditWidth;
  6114. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  6115. }
  6116. }
  6117. }
  6118. //---------------------------------------------------------------------------
  6119. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  6120. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  6121. {
  6122. if (WinConfiguration->DDWarnLackOfTempSpace)
  6123. {
  6124. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  6125. if (!ADrive.IsEmpty())
  6126. {
  6127. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  6128. DebugAssert(RequiredSpace >= 0);
  6129. __int64 RequiredWithReserve;
  6130. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  6131. if (FreeSpace < RequiredWithReserve)
  6132. {
  6133. unsigned int Result;
  6134. TMessageParams Params(mpNeverAskAgainCheck);
  6135. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  6136. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  6137. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  6138. if (Result == qaNeverAskAgain)
  6139. {
  6140. WinConfiguration->DDWarnLackOfTempSpace = false;
  6141. }
  6142. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  6143. }
  6144. }
  6145. }
  6146. }
  6147. //---------------------------------------------------------------------------
  6148. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  6149. {
  6150. DoOpenDirectoryDialog(odAddBookmark, Side);
  6151. }
  6152. //---------------------------------------------------------------------------
  6153. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  6154. {
  6155. // we should better use TCustomDirView::FCaseSensitive, but it is private
  6156. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  6157. try
  6158. {
  6159. TCustomDirView * DView = DirView(Side);
  6160. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  6161. {
  6162. VisitedDirectories->Add(DView->HistoryPath[Index]);
  6163. }
  6164. }
  6165. catch (...)
  6166. {
  6167. delete VisitedDirectories;
  6168. throw;
  6169. }
  6170. return VisitedDirectories;
  6171. }
  6172. //---------------------------------------------------------------------------
  6173. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  6174. TOpenDirectoryMode Mode, TOperationSide Side)
  6175. {
  6176. bool Continue = true;
  6177. if (Mode == odAddBookmark)
  6178. {
  6179. TMessageParams Params(mpNeverAskAgainCheck);
  6180. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  6181. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  6182. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  6183. unsigned int Answer =
  6184. MessageDialog(Message,
  6185. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  6186. if (Answer == qaNeverAskAgain)
  6187. {
  6188. Continue = true;
  6189. WinConfiguration->UseSharedBookmarks = true;
  6190. }
  6191. else if (Answer == qaOK)
  6192. {
  6193. Continue = true;
  6194. WinConfiguration->UseSharedBookmarks = false;
  6195. }
  6196. else
  6197. {
  6198. Continue = false;
  6199. }
  6200. }
  6201. if (Continue)
  6202. {
  6203. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  6204. try
  6205. {
  6206. UnicodeString Name = DirView(Side)->PathName;
  6207. bool Repeat;
  6208. do
  6209. {
  6210. Repeat = false;
  6211. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  6212. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  6213. // do not allow switching to location profiles,
  6214. // if we are not connected
  6215. HasDirView[osLocal] && (Terminal != NULL)))
  6216. {
  6217. TWindowLock Lock(this);
  6218. if (!TryOpenDirectory(Side, Name))
  6219. {
  6220. Repeat = true;
  6221. Mode = odBrowse;
  6222. }
  6223. }
  6224. }
  6225. while (Repeat);
  6226. }
  6227. __finally
  6228. {
  6229. delete VisitedDirectories;
  6230. }
  6231. }
  6232. }
  6233. //---------------------------------------------------------------------------
  6234. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  6235. {
  6236. DebugAssert(!Terminal->CommandSessionOpened);
  6237. return TTerminalManager::Instance()->ConnectTerminal(Terminal->CommandSession);
  6238. }
  6239. //---------------------------------------------------------------------------
  6240. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  6241. {
  6242. bool Result = Terminal->IsCapable[Capability] ||
  6243. Terminal->CommandSessionOpened;
  6244. if (!Result)
  6245. {
  6246. DebugAssert(Terminal->IsCapable[fcSecondaryShell]);
  6247. if (!GUIConfiguration->ConfirmCommandSession)
  6248. {
  6249. Result = true;
  6250. }
  6251. else
  6252. {
  6253. TMessageParams Params(mpNeverAskAgainCheck);
  6254. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6255. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6256. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6257. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6258. if (Answer == qaNeverAskAgain)
  6259. {
  6260. GUIConfiguration->ConfirmCommandSession = false;
  6261. Result = true;
  6262. }
  6263. else if (Answer == qaOK)
  6264. {
  6265. Result = true;
  6266. }
  6267. }
  6268. if (Result)
  6269. {
  6270. Result = CommandSessionFallback();
  6271. }
  6272. }
  6273. return Result;
  6274. }
  6275. //---------------------------------------------------------------------------
  6276. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6277. {
  6278. if (EnsureCommandSessionFallback(fcAnyCommand))
  6279. {
  6280. DoConsoleDialog(Terminal, Command);
  6281. }
  6282. }
  6283. //---------------------------------------------------------------------------
  6284. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6285. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6286. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6287. {
  6288. if (!IsSideLocalBrowser(osRemote) &&
  6289. IsFileControl(DropSourceControl, osRemote) &&
  6290. (FDDExtMapFile != NULL))
  6291. {
  6292. Accept = true;
  6293. }
  6294. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6295. DebugAssert(FDDTargetControl != NULL);
  6296. }
  6297. //---------------------------------------------------------------------------
  6298. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6299. _di_IDataObject DataObj, int KeyState,
  6300. const TPoint & Point, int & Effect, bool & Accept)
  6301. {
  6302. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6303. }
  6304. //---------------------------------------------------------------------------
  6305. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6306. _di_IDataObject DataObj, int KeyState,
  6307. const TPoint & Point, int & Effect, bool & Accept)
  6308. {
  6309. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6310. }
  6311. //---------------------------------------------------------------------------
  6312. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6313. TObject * Sender)
  6314. {
  6315. DebugUsedParam(Sender);
  6316. DebugAssert(FDDTargetControl == Sender);
  6317. FDDTargetControl = NULL;
  6318. }
  6319. //---------------------------------------------------------------------------
  6320. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6321. {
  6322. FileControlDDDragLeave(SessionsPageControl);
  6323. }
  6324. //---------------------------------------------------------------------------
  6325. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6326. {
  6327. FileControlDDDragLeave(QueueView3);
  6328. }
  6329. //---------------------------------------------------------------------------
  6330. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6331. {
  6332. DebugAssert(!IsSideLocalBrowser(Side));
  6333. DebugUsedParam(Side);
  6334. bool Edit = false;
  6335. TRemoteFile * File = NULL;
  6336. UnicodeString FileName;
  6337. UnicodeString PointTo;
  6338. bool SymbolicLink = true;
  6339. if (RemoteDirView->ItemFocused)
  6340. {
  6341. DebugAssert(RemoteDirView->ItemFocused->Data);
  6342. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6343. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6344. if (Edit)
  6345. {
  6346. FileName = File->FileName;
  6347. PointTo = File->LinkTo;
  6348. }
  6349. else
  6350. {
  6351. PointTo = File->FileName;
  6352. }
  6353. }
  6354. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6355. Terminal->IsCapable[fcHardLink]))
  6356. {
  6357. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6358. if (Edit)
  6359. {
  6360. DebugAssert(File->FileName == FileName);
  6361. int Params = dfNoRecursive;
  6362. Terminal->ExceptionOnFail = true;
  6363. try
  6364. {
  6365. Terminal->DeleteFile(L"", File, &Params);
  6366. }
  6367. __finally
  6368. {
  6369. Terminal->ExceptionOnFail = false;
  6370. }
  6371. }
  6372. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6373. }
  6374. }
  6375. //---------------------------------------------------------------------------
  6376. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6377. {
  6378. return
  6379. (IsSideLocalBrowser(Side) ||
  6380. (HasActiveTerminal() &&
  6381. Terminal->ResolvingSymlinks &&
  6382. Terminal->IsCapable[fcSymbolicLink]));
  6383. }
  6384. //---------------------------------------------------------------------------
  6385. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6386. {
  6387. return
  6388. !IsSideLocalBrowser(FCurrentSide) &&
  6389. (RemoteDirView->ItemFocused != NULL) &&
  6390. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6391. Terminal->SessionData->ResolveSymlinks;
  6392. }
  6393. //---------------------------------------------------------------------------
  6394. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6395. {
  6396. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6397. FForceExecution = true;
  6398. try
  6399. {
  6400. DirView(osCurrent)->ExecuteCurrentFile();
  6401. }
  6402. __finally
  6403. {
  6404. FForceExecution = false;
  6405. }
  6406. }
  6407. //---------------------------------------------------------------------------
  6408. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6409. {
  6410. TEditorData ExternalEditor;
  6411. ExternalEditor.Editor = edExternal;
  6412. bool Remember = false;
  6413. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6414. {
  6415. if (Remember)
  6416. {
  6417. TEditorList * EditorList = new TEditorList;
  6418. try
  6419. {
  6420. *EditorList = *WinConfiguration->EditorList;
  6421. bool Found = false;
  6422. int i = 0;
  6423. while (!Found && (i < EditorList->Count))
  6424. {
  6425. const TEditorPreferences * Editor = EditorList->Editors[i];
  6426. if ((Editor->Data->Editor == edExternal) &&
  6427. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6428. {
  6429. Found = true;
  6430. }
  6431. i++;
  6432. }
  6433. if (!Found)
  6434. {
  6435. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6436. WinConfiguration->EditorList = EditorList;
  6437. }
  6438. }
  6439. __finally
  6440. {
  6441. delete EditorList;
  6442. }
  6443. }
  6444. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6445. }
  6446. }
  6447. //---------------------------------------------------------------------------
  6448. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6449. {
  6450. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6451. if (FFileFindTerminal == ATerminal)
  6452. {
  6453. FFileFindTerminal = NULL;
  6454. HideFileFindDialog();
  6455. }
  6456. if (FClipboardTerminal == ATerminal)
  6457. {
  6458. ClipboardClear(); // implies ClipboardStop
  6459. }
  6460. if ((FOnSynchronizeAbort != NULL) &&
  6461. (ATerminal == FManagedSession))
  6462. {
  6463. FOnSynchronizeAbort(NULL);
  6464. }
  6465. }
  6466. //---------------------------------------------------------------------------
  6467. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6468. {
  6469. DetachTerminal(Sender);
  6470. }
  6471. //---------------------------------------------------------------------------
  6472. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6473. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6474. {
  6475. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6476. DebugAssert(Terminal != NULL);
  6477. if (Data->Terminal == Terminal)
  6478. {
  6479. Data->Terminal = NULL;
  6480. }
  6481. }
  6482. //---------------------------------------------------------------------------
  6483. TManagedTerminal * TCustomScpExplorerForm::GetReplacementForLastSession()
  6484. {
  6485. return NULL;
  6486. }
  6487. //---------------------------------------------------------------------------
  6488. void __fastcall TCustomScpExplorerForm::LastTerminalClosed()
  6489. {
  6490. UpdateControls();
  6491. SessionColor = TColor(0);
  6492. UpdateRemotePathComboBox(false);
  6493. NeedSession(false);
  6494. }
  6495. //---------------------------------------------------------------------------
  6496. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6497. {
  6498. try
  6499. {
  6500. // Cache, as the login dialog can change its value.
  6501. // See also DoShow. Also see TTerminalManager::NewSession.
  6502. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6503. try
  6504. {
  6505. if (ShowLogin)
  6506. {
  6507. bool ReloadSessions = !Startup;
  6508. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this, true);
  6509. }
  6510. }
  6511. __finally
  6512. {
  6513. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6514. // (so there was no chance for the user to open any session yet)
  6515. if ((ShowLogin || !Startup) &&
  6516. !WinConfiguration->KeepOpenWhenNoSession &&
  6517. // this rules out the implicit Commander's local-local browser
  6518. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6519. {
  6520. TerminateApplication();
  6521. }
  6522. }
  6523. }
  6524. catch (EAbort &)
  6525. {
  6526. // swallow
  6527. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6528. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6529. }
  6530. }
  6531. //---------------------------------------------------------------------------
  6532. void __fastcall TCustomScpExplorerForm::SessionListChanged(bool ForceTruncationUpdate)
  6533. {
  6534. TTerminalManager * Manager = TTerminalManager::Instance();
  6535. DebugAssert(!Manager->Updating);
  6536. TAutoFlag UpdatingSessionTabsFlag(FUpdatingSessionTabs);
  6537. int ActiveSessionIndex = Manager->ActiveSessionIndex;
  6538. Configuration->Usage->SetMax(L"MaxOpenedSessions", Manager->Count);
  6539. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6540. try
  6541. {
  6542. int PrevTabsWidth = SessionsPageControl->TotalTabsWidth();
  6543. while (SessionsPageControl->PageCount > Manager->Count + 1)
  6544. {
  6545. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6546. }
  6547. for (int Index = 0; Index <= Manager->Count; Index++)
  6548. {
  6549. TThemeTabSheet * TabSheet;
  6550. if (Index >= SessionsPageControl->PageCount)
  6551. {
  6552. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6553. TabSheet->PageControl = SessionsPageControl;
  6554. }
  6555. else
  6556. {
  6557. TabSheet = SessionsPageControl->Pages[Index];
  6558. }
  6559. bool IsSessionTab = (Index < Manager->Count);
  6560. if (IsSessionTab)
  6561. {
  6562. TTerminal * Terminal = Manager->Sessions[Index];
  6563. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6564. TabSheet->CaptionTruncation = tttEllipsis;
  6565. UpdateSessionTab(TabSheet);
  6566. }
  6567. else
  6568. {
  6569. TabSheet->Tag = 0; // not really needed
  6570. TabSheet->Shadowed = false;
  6571. TabSheet->Button = SupportsLocalBrowser() ? ttbDropDown : ttbNone;
  6572. TabSheet->CaptionTruncation = tttNoText;
  6573. // We know that we are at the last page, otherwise we could not call this (it assumes that new session tab is the last one)
  6574. UpdateNewTabTab();
  6575. }
  6576. }
  6577. // Prevent flicker on the right side where scrolling buttons would be, unless really needed
  6578. if (ForceTruncationUpdate || (SessionsPageControl->TotalTabsWidth() != PrevTabsWidth))
  6579. {
  6580. SessionsPageControl->UpdateTabsCaptionTruncation();
  6581. }
  6582. }
  6583. __finally
  6584. {
  6585. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6586. }
  6587. SessionsPageControl->ActivePageIndex = ActiveSessionIndex;
  6588. }
  6589. //---------------------------------------------------------------------------
  6590. UnicodeString TCustomScpExplorerForm::GetNewTabTabCaption()
  6591. {
  6592. return StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewTabAction->Caption));
  6593. }
  6594. //---------------------------------------------------------------------------
  6595. void __fastcall TCustomScpExplorerForm::UpdateNewTabTab()
  6596. {
  6597. TThemeTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6598. UnicodeString TabCaption;
  6599. if (WinConfiguration->SelectiveToolbarText)
  6600. {
  6601. TabCaption = GetNewTabTabCaption();
  6602. }
  6603. TabSheet->BaseCaption = TabCaption;
  6604. TabSheet->ImageIndex = GetNewTabTabImageIndex(osCurrent);
  6605. }
  6606. //---------------------------------------------------------------------------
  6607. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabSession(TTabSheet * TabSheet)
  6608. {
  6609. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6610. }
  6611. //---------------------------------------------------------------------------
  6612. UnicodeString TCustomScpExplorerForm::GetLocalBrowserSessionTitle(TManagedTerminal *)
  6613. {
  6614. DebugFail();
  6615. return UnicodeString();
  6616. }
  6617. //---------------------------------------------------------------------------
  6618. void TCustomScpExplorerForm::UpdateSessionTab(TThemeTabSheet * TabSheet)
  6619. {
  6620. if (DebugAlwaysTrue(TabSheet != NULL))
  6621. {
  6622. TManagedTerminal * ASession = GetSessionTabSession(TabSheet);
  6623. if (DebugAlwaysTrue(ASession != NULL))
  6624. {
  6625. TColor Color = (ASession == Terminal) ? FSessionColor : ASession->StateData->Color;
  6626. if (ASession->LocalBrowser)
  6627. {
  6628. TabSheet->ImageIndex = FLocalBrowserTabImageIndex;
  6629. }
  6630. else
  6631. {
  6632. TabSheet->ImageIndex = AddSessionColor(Color);
  6633. }
  6634. TTerminalManager * Manager = TTerminalManager::Instance();
  6635. TabSheet->Shadowed = !ASession->Active && !ASession->LocalBrowser;
  6636. TabSheet->Button = CanCloseSession(ASession) ? ttbClose : ttbNone;
  6637. TabSheet->BaseCaption = Manager->GetSessionTitle(ASession, true);
  6638. }
  6639. }
  6640. }
  6641. //---------------------------------------------------------------------------
  6642. bool TCustomScpExplorerForm::CanCloseSession(TManagedTerminal * Session)
  6643. {
  6644. return !Session->LocalBrowser || (TTerminalManager::Instance()->Count > 1);
  6645. }
  6646. //---------------------------------------------------------------------------
  6647. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6648. {
  6649. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6650. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->ActivePage);
  6651. bool Result = (Session != NULL);
  6652. if (Result)
  6653. {
  6654. TTerminalManager::Instance()->ActiveSession = Session;
  6655. }
  6656. else
  6657. {
  6658. try
  6659. {
  6660. NewTab();
  6661. }
  6662. __finally
  6663. {
  6664. SessionListChanged();
  6665. }
  6666. FSessionsPageControlNewTabTime = Now();
  6667. }
  6668. return Result;
  6669. }
  6670. //---------------------------------------------------------------------------
  6671. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6672. {
  6673. SessionTabSwitched();
  6674. }
  6675. //---------------------------------------------------------------------------
  6676. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6677. {
  6678. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6679. DebugAssert(TransferList != NULL);
  6680. UnicodeString Name;
  6681. if (TransferList->ItemIndex <= 0)
  6682. {
  6683. Name = L"";
  6684. }
  6685. else
  6686. {
  6687. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6688. }
  6689. if (FCopyParamAutoSelected.IsEmpty())
  6690. {
  6691. // if previous preset was not autoselected, make new preset the "default"
  6692. FCopyParamDefault = Name;
  6693. }
  6694. GUIConfiguration->CopyParamCurrent = Name;
  6695. }
  6696. //---------------------------------------------------------------------------
  6697. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6698. {
  6699. // sanity check
  6700. bool ExistingPreset =
  6701. (FTransferListHoverIndex >= 0) &&
  6702. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6703. DebugAssert(ExistingPreset);
  6704. if (ExistingPreset)
  6705. {
  6706. HDC DC = GetDC(0);
  6707. TCanvas * Canvas = new TCanvas();
  6708. try
  6709. {
  6710. Canvas->Handle = DC;
  6711. Canvas->Font = GetToolbarFont(this);
  6712. UnicodeString Name;
  6713. if (FTransferListHoverIndex == 0)
  6714. {
  6715. Name = L"";
  6716. }
  6717. else
  6718. {
  6719. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6720. }
  6721. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6722. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6723. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6724. static_cast<TObject*>(GetComponent(fcTransferList)));
  6725. UnicodeString InfoStr =
  6726. GUIConfiguration->CopyParamPreset[Name].
  6727. GetInfoStr(L"; ",
  6728. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6729. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6730. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6731. {
  6732. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6733. {
  6734. InfoStr.SetLength(InfoStr.Length() - 1);
  6735. }
  6736. InfoStr += Ellipsis;
  6737. }
  6738. // UpdateCaption does not cause invalidation of whole submenu, while
  6739. // setting Caption property does.
  6740. // also it probably does not resize the label, even if necessary
  6741. // (we do not want that anyway)
  6742. TransferLabel->UpdateCaption(InfoStr);
  6743. }
  6744. __finally
  6745. {
  6746. Canvas->Handle = NULL;
  6747. ReleaseDC(0, DC);
  6748. delete Canvas;
  6749. }
  6750. }
  6751. }
  6752. //---------------------------------------------------------------------------
  6753. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6754. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6755. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6756. {
  6757. if (FTransferListHoverIndex != AHoverIndex)
  6758. {
  6759. FTransferListHoverIndex = AHoverIndex;
  6760. UpdateTransferLabel();
  6761. }
  6762. }
  6763. //---------------------------------------------------------------------------
  6764. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6765. {
  6766. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6767. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6768. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6769. {
  6770. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6771. {
  6772. if (!NonVisualDataModule->Busy)
  6773. {
  6774. OpenDirectory(GetSide(osCurrent));
  6775. }
  6776. Message.Result = 1;
  6777. }
  6778. else
  6779. {
  6780. TForm::Dispatch(&Message);
  6781. }
  6782. }
  6783. else
  6784. {
  6785. TForm::Dispatch(&Message);
  6786. }
  6787. }
  6788. //---------------------------------------------------------------------------
  6789. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6790. {
  6791. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6792. if ((FIgnoreNextDialogChar != 0) &&
  6793. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6794. {
  6795. Message.Result = 1;
  6796. }
  6797. else
  6798. {
  6799. TForm::Dispatch(&Message);
  6800. }
  6801. FIgnoreNextDialogChar = 0;
  6802. }
  6803. //---------------------------------------------------------------------------
  6804. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6805. {
  6806. // The four low-order bits are used internally by Windows
  6807. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6808. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6809. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6810. // 61730 - restore thru double click - undocumented
  6811. // 61490 - maximize thru double click - undocumented
  6812. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6813. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6814. {
  6815. SysResizing(Cmd);
  6816. }
  6817. TForm::Dispatch(&Message);
  6818. }
  6819. //---------------------------------------------------------------------------
  6820. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6821. {
  6822. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6823. // Also there no point returning TRUE as we are not able to
  6824. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6825. // Hence the process termination might be safer :)
  6826. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6827. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6828. {
  6829. Message.Result = FALSE;
  6830. }
  6831. else
  6832. {
  6833. Message.Result = TRUE;
  6834. }
  6835. // Do not call default handling as that triggers OnCloseQuery,
  6836. // where our implementation will popup confirmation dialogs, what we do not want,
  6837. // as per Vista guidelines:
  6838. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6839. }
  6840. //---------------------------------------------------------------------------
  6841. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6842. {
  6843. if (Message.EndSession && IsApplicationMinimized())
  6844. {
  6845. // WORKAROUND
  6846. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6847. // when it receives WM_ENDSESSION,
  6848. // but that sometimes (particularly when application is minimized) cause crashes.
  6849. // Crash popups message that blocks log off.
  6850. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6851. // so we call ExitProcess() immediately, not even trying to cleanup.
  6852. // It still causes beep, so there's likely some popup, but it does not block
  6853. // log off.
  6854. ExitProcess(0);
  6855. }
  6856. TForm::Dispatch(&Message);
  6857. }
  6858. #ifdef _DEBUG
  6859. //---------------------------------------------------------------------------
  6860. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6861. {
  6862. TForm::Dispatch(&Message);
  6863. }
  6864. #endif
  6865. //---------------------------------------------------------------------------
  6866. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6867. {
  6868. }
  6869. //---------------------------------------------------------------------------
  6870. void __fastcall TCustomScpExplorerForm::DoShow()
  6871. {
  6872. // Called from TCustomScpExplorerForm::CMShowingChanged
  6873. // only now are the controls resized finally, so the size constraints
  6874. // will not conflict with possibly very small window size
  6875. RestoreFormParams();
  6876. // This indicates that the form was rescaled after parameters were loaded and
  6877. // as most probably the parameters were actually saved with the current form scaling
  6878. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6879. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6880. // and no rounding problems will occur.
  6881. // See also RestoreForm.
  6882. // (we should be safe to call RestoreParams unconditionally)
  6883. if (PixelsPerInch != Screen->PixelsPerInch)
  6884. {
  6885. RestoreParams();
  6886. }
  6887. FixControlsPlacement();
  6888. if (Position == poDefaultPosOnly)
  6889. {
  6890. CutFormToDesktop(this);
  6891. }
  6892. TForm::DoShow();
  6893. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6894. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6895. // This was previously in NeedSession, where other related code is.
  6896. // But that is called from CMShowingChanged, when the window is already visible and the local-local window state
  6897. // unpleasantly shows briefly.
  6898. if ((ManagedSession == NULL) &&
  6899. !WinConfiguration->ShowLoginWhenNoSession &&
  6900. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6901. // This detects if workspace was saved the last time the main widow was closed
  6902. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6903. {
  6904. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false, true);
  6905. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6906. }
  6907. // Before main window displays
  6908. if (ManagedSession == NULL)
  6909. {
  6910. StartingWithoutSession();
  6911. }
  6912. UpdatePixelsPerInchMainWindowCounter();
  6913. FShowing = true;
  6914. }
  6915. //---------------------------------------------------------------------------
  6916. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6917. {
  6918. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6919. }
  6920. //---------------------------------------------------------------------------
  6921. void __fastcall TCustomScpExplorerForm::StartingWithoutSession()
  6922. {
  6923. SessionListChanged();
  6924. InitStatusBar();
  6925. UpdateControls();
  6926. }
  6927. //---------------------------------------------------------------------------
  6928. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6929. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6930. TNotifyEvent OnBalloonClick, TObject * UserData)
  6931. {
  6932. bool Do;
  6933. UnicodeString Message;
  6934. if (E == NULL)
  6935. {
  6936. Message = Str;
  6937. Do = true;
  6938. }
  6939. else
  6940. {
  6941. Do = ExceptionMessage(E, Message);
  6942. }
  6943. if (Do && WinConfiguration->BalloonNotifications)
  6944. {
  6945. UnicodeString Title;
  6946. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6947. {
  6948. Message = TrimLeft(Message);
  6949. }
  6950. else
  6951. {
  6952. Message = UnformatMessage(Message);
  6953. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6954. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6955. Title = LoadResourceString(Captions[Type]);
  6956. if (Terminal != NULL)
  6957. {
  6958. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  6959. Title = TTerminalManager::Instance()->GetSessionTitle(Session, true) + TitleSeparator + Title;
  6960. }
  6961. }
  6962. if (Seconds == 0)
  6963. {
  6964. Seconds = WinConfiguration->NotificationsTimeout;
  6965. }
  6966. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6967. }
  6968. }
  6969. //---------------------------------------------------------------------------
  6970. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6971. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6972. UnicodeString HelpKeyword, const TMessageParams * Params,
  6973. TTerminal * Terminal)
  6974. {
  6975. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6976. (FOnFeedSynchronizeError != NULL)) &&
  6977. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6978. {
  6979. if (FOnFeedSynchronizeError != NULL)
  6980. {
  6981. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6982. }
  6983. else
  6984. {
  6985. DebugAssert(FErrorList != NULL);
  6986. TStringList * MoreMessagesCopy = NULL;
  6987. if (MoreMessages)
  6988. {
  6989. MoreMessagesCopy = new TStringList();
  6990. MoreMessagesCopy->Assign(MoreMessages);
  6991. }
  6992. FErrorList->AddObject(Message, MoreMessagesCopy);
  6993. }
  6994. PopupTrayBalloon(Terminal, Message, Type);
  6995. return ContinueAnswer(Answers);
  6996. }
  6997. else
  6998. {
  6999. bool UseBalloon = FTrayIcon->Visible;
  7000. if (UseBalloon)
  7001. {
  7002. PopupTrayBalloon(Terminal, Message, Type);
  7003. }
  7004. unsigned int Result;
  7005. try
  7006. {
  7007. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  7008. }
  7009. __finally
  7010. {
  7011. // cancel only balloon we popped up, otherwise we may cancel notification
  7012. // balloon that was there before the message dialog
  7013. // (such as "dd confirmation opt in balloon)
  7014. if (UseBalloon)
  7015. {
  7016. FTrayIcon->CancelBalloon();
  7017. }
  7018. }
  7019. return Result;
  7020. }
  7021. }
  7022. //---------------------------------------------------------------------------
  7023. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  7024. TTerminal * Terminal, Exception * E)
  7025. {
  7026. if (FTrayIcon->Visible)
  7027. {
  7028. PopupTrayBalloon(Terminal, L"", qtError, E);
  7029. }
  7030. // particularly prevent opening new session from jump list,
  7031. // while exception is shown
  7032. NonVisualDataModule->StartBusy();
  7033. try
  7034. {
  7035. ShowExtendedExceptionEx(Terminal, E);
  7036. }
  7037. __finally
  7038. {
  7039. NonVisualDataModule->EndBusy();
  7040. FTrayIcon->CancelBalloon();
  7041. }
  7042. }
  7043. //---------------------------------------------------------------------------
  7044. void __fastcall TCustomScpExplorerForm::SessionReady()
  7045. {
  7046. InitStatusBar();
  7047. // cannot rely on active page being page for active terminal,
  7048. // as it can happen that active page is the "new session" page
  7049. // (e.g. when reconnecting active terminal, while login dialog
  7050. // invoked from "new session" page is modal)
  7051. int ActiveSessionIndex = TTerminalManager::Instance()->ActiveSessionIndex;
  7052. UpdateSessionTab(SessionsPageControl->Pages[ActiveSessionIndex]);
  7053. }
  7054. //---------------------------------------------------------------------------
  7055. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  7056. TTerminal * Terminal, Exception * E)
  7057. {
  7058. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  7059. if (!Terminal->Active)
  7060. {
  7061. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  7062. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  7063. {
  7064. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  7065. }
  7066. }
  7067. }
  7068. //---------------------------------------------------------------------------
  7069. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  7070. UnicodeString Message, TQueryType Type,
  7071. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  7072. {
  7073. if ((E == NULL) ||
  7074. ExceptionMessage(E, Message))
  7075. {
  7076. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  7077. if (Important)
  7078. {
  7079. Seconds *= 5;
  7080. }
  7081. UnicodeString NoteMessage(UnformatMessage(Message));
  7082. if (Terminal != NULL)
  7083. {
  7084. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  7085. NoteMessage = FORMAT(L"%s: %s",
  7086. (TTerminalManager::Instance()->GetSessionTitle(Session, true), NoteMessage));
  7087. }
  7088. if (WinConfiguration->BalloonNotifications)
  7089. {
  7090. AddNote(NoteMessage);
  7091. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  7092. }
  7093. else
  7094. {
  7095. FlashOnBackground();
  7096. PostNote(NoteMessage, Seconds, OnClick, UserData);
  7097. }
  7098. }
  7099. }
  7100. //---------------------------------------------------------------------------
  7101. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  7102. {
  7103. RestoreApp();
  7104. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  7105. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  7106. !NonVisualDataModule->Busy)
  7107. {
  7108. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  7109. TTerminalManager::Instance()->ActiveSession = Terminal;
  7110. if (!ComponentVisible[fcQueueView])
  7111. {
  7112. ToggleQueueVisibility();
  7113. GoToQueue();
  7114. }
  7115. }
  7116. }
  7117. //---------------------------------------------------------------------------
  7118. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  7119. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  7120. {
  7121. UnicodeString Message;
  7122. TNotifyEvent OnClick = NULL;
  7123. TObject * UserData = NULL;
  7124. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  7125. switch (Event)
  7126. {
  7127. case qeEmptyButMonitored:
  7128. if ((ATerminal != Terminal) || QueueInvisible)
  7129. {
  7130. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  7131. OnClick = QueueEmptyNoteClicked;
  7132. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  7133. TerminalNoteData->Terminal = ATerminal;
  7134. UserData = TerminalNoteData;
  7135. }
  7136. break;
  7137. case qeEmpty:
  7138. OperationComplete(ATerminal->QueueOperationStart);
  7139. break;
  7140. case qePendingUserAction:
  7141. if ((ATerminal != Terminal) ||
  7142. (QueueInvisible && !IsQueueAutoPopup()))
  7143. {
  7144. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  7145. }
  7146. break;
  7147. default:
  7148. DebugFail();
  7149. }
  7150. if (!Message.IsEmpty())
  7151. {
  7152. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  7153. }
  7154. }
  7155. //---------------------------------------------------------------------------
  7156. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  7157. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  7158. {
  7159. if (FDDExtMapFile != NULL)
  7160. {
  7161. CloseHandle(FDDExtMapFile);
  7162. FDDExtMapFile = NULL;
  7163. }
  7164. if (WinConfiguration->DDFakeFile)
  7165. {
  7166. DDFakeFileInitDrag(FileList, Created);
  7167. }
  7168. }
  7169. //---------------------------------------------------------------------------
  7170. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  7171. {
  7172. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  7173. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  7174. {
  7175. FFakeFileDropTarget = FileName;
  7176. }
  7177. }
  7178. //---------------------------------------------------------------------------
  7179. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  7180. {
  7181. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  7182. if (!ForceDirectories(ApiPath(Result)))
  7183. {
  7184. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  7185. }
  7186. FileSetAttr(ApiPath(Result), faHidden);
  7187. return Result;
  7188. }
  7189. //---------------------------------------------------------------------------
  7190. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  7191. bool & Created)
  7192. {
  7193. FFakeFileDropTarget = UnicodeString();
  7194. FDragFakeDirectory = CreateFakeTransferDirectory();
  7195. FileList->AddItem(NULL, FDragFakeDirectory);
  7196. Created = true;
  7197. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  7198. {
  7199. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  7200. }
  7201. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  7202. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  7203. {
  7204. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7205. TDragExtCommStruct* CommStruct;
  7206. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7207. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7208. DebugAssert(CommStruct != NULL);
  7209. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  7210. CommStruct->Dragging = true;
  7211. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  7212. LENOF(CommStruct->DropDest));
  7213. NULL_TERMINATE(CommStruct->DropDest);
  7214. UnmapViewOfFile(CommStruct);
  7215. }
  7216. }
  7217. //---------------------------------------------------------------------------
  7218. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  7219. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  7220. {
  7221. bool Result;
  7222. DebugAssert(!IsLocalBrowserMode());
  7223. if (Sender == RemoteDirView)
  7224. {
  7225. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  7226. }
  7227. else
  7228. {
  7229. DebugAssert(Sender == RemoteDriveView);
  7230. TStrings * FileList = RemoteDriveView->DragFileList();
  7231. try
  7232. {
  7233. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  7234. }
  7235. __finally
  7236. {
  7237. delete FileList;
  7238. }
  7239. }
  7240. if (FDDTargetControl == RemoteDriveView)
  7241. {
  7242. RemoteDriveView->UpdateDropTarget();
  7243. }
  7244. // foRemoteMove happens when file/dir is dragged within the remote tree view
  7245. // or from tree view to dir view.
  7246. // foMove happens when file/dir is dragged from remote tree view outside of
  7247. // application via dragex
  7248. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  7249. (DropSourceControl == RemoteDriveView))
  7250. {
  7251. RemoteDriveView->UpdateDropSource();
  7252. }
  7253. return Result;
  7254. }
  7255. //---------------------------------------------------------------------------
  7256. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  7257. {
  7258. DebugAssert(!IsLocalBrowserMode());
  7259. // This also handles drops of remote files to queue.
  7260. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  7261. SAFE_DESTROY(FDDFileList);
  7262. if (!FFakeFileDropTarget.IsEmpty())
  7263. {
  7264. RemoveDir(ApiPath(FFakeFileDropTarget));
  7265. }
  7266. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  7267. {
  7268. try
  7269. {
  7270. TDragResult DDResult = (Sender == RemoteDirView) ?
  7271. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  7272. // Focus is moved to the target application,
  7273. // but as we are going to present the UI, we need to steal the focus back.
  7274. // This most likely won't work though (windows does not allow application
  7275. // to steal focus most of the time)
  7276. Application->BringToFront();
  7277. // On older version of Windows we never got drMove here, see also comment below.
  7278. // On Windows 10, we get the "move".
  7279. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  7280. {
  7281. UnicodeString TargetDirectory;
  7282. TFileOperation Operation;
  7283. // drInvalid may mean drMove, see comment below
  7284. switch (DDResult)
  7285. {
  7286. case drCopy:
  7287. Operation = foCopy;
  7288. break;
  7289. case drMove:
  7290. Operation = foMove;
  7291. break;
  7292. default:
  7293. DebugFail();
  7294. case drInvalid:
  7295. // prefer "copy" for safety
  7296. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7297. break;
  7298. }
  7299. TTransferOperationParam Param;
  7300. UnicodeString CounterName;
  7301. bool ForceQueue;
  7302. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7303. {
  7304. // we get drInvalid both if d&d was intercepted by ddext,
  7305. // and when users drops on no-drop location.
  7306. // we tell the difference by existence of response from ddext,
  7307. // so we ignore absence of response in this case
  7308. if (DDResult != drInvalid)
  7309. {
  7310. // here we know that the extension is installed,
  7311. // as it is checked as soon as drag&drop starts from
  7312. // RemoteFileControlDDCreateDragFileList
  7313. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7314. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7315. {
  7316. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7317. }
  7318. else
  7319. {
  7320. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7321. }
  7322. }
  7323. }
  7324. else
  7325. {
  7326. // download using fake file
  7327. Param.Temp = false;
  7328. Param.DragDrop = true;
  7329. if (ForceQueue)
  7330. {
  7331. Param.Queue = asOn;
  7332. }
  7333. if (Sender == RemoteDirView)
  7334. {
  7335. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7336. }
  7337. if (RemoteFileControlFileOperation(Sender, Operation,
  7338. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7339. {
  7340. Configuration->Usage->Inc(CounterName);
  7341. }
  7342. }
  7343. }
  7344. }
  7345. __finally
  7346. {
  7347. CloseHandle(FDDExtMapFile);
  7348. FDDExtMapFile = NULL;
  7349. delete FDragFakeMonitors;
  7350. FDragFakeMonitors = NULL;
  7351. RemoveDir(ApiPath(FDragFakeDirectory));
  7352. FDragFakeDirectory = L"";
  7353. FFakeFileDropTarget = UnicodeString();
  7354. }
  7355. }
  7356. if (FDragDropSshTerminate.get() != NULL)
  7357. {
  7358. FDragDropSshTerminate->Rethrow();
  7359. }
  7360. }
  7361. //---------------------------------------------------------------------------
  7362. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7363. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7364. {
  7365. // Remember drop effect so we know (when user drops files), if we copy or move
  7366. FLastDropEffect = dwEffect;
  7367. }
  7368. //---------------------------------------------------------------------------
  7369. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7370. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7371. {
  7372. bool Result;
  7373. if (FDDTargetControl == QueueView3)
  7374. {
  7375. Directory = DefaultDownloadTargetDirectory();
  7376. Result = true;
  7377. CounterName = L"DownloadsDragDropQueue";
  7378. ForceQueue = true;
  7379. }
  7380. else if (!FFakeFileDropTarget.IsEmpty())
  7381. {
  7382. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7383. Result = true;
  7384. ForceQueue = false;
  7385. CounterName = L"DownloadsDragDropFakeFile";
  7386. }
  7387. else
  7388. {
  7389. ForceQueue = false;
  7390. Enabled = false;
  7391. try
  7392. {
  7393. int Timer = 0;
  7394. Result = false;
  7395. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7396. {
  7397. {
  7398. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7399. TDragExtCommStruct* CommStruct;
  7400. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7401. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7402. DebugAssert(CommStruct != NULL);
  7403. Result = !CommStruct->Dragging;
  7404. if (Result)
  7405. {
  7406. Directory = ExtractFilePath(CommStruct->DropDest);
  7407. CounterName = L"DownloadsDragDropExternalExt";
  7408. }
  7409. UnmapViewOfFile(CommStruct);
  7410. }
  7411. if (!Result)
  7412. {
  7413. Sleep(50);
  7414. Timer += 50;
  7415. Application->ProcessMessages();
  7416. }
  7417. }
  7418. }
  7419. __finally
  7420. {
  7421. Enabled = true;
  7422. }
  7423. }
  7424. return Result;
  7425. }
  7426. //---------------------------------------------------------------------------
  7427. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7428. const UnicodeString TempDir, int SecDelay)
  7429. {
  7430. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7431. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7432. if (FDelayedDeletionTimer == NULL)
  7433. {
  7434. DebugAssert(HandleAllocated());
  7435. FDelayedDeletionTimer = new TTimer(this);
  7436. FDelayedDeletionTimer->Interval = 10000;
  7437. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7438. }
  7439. else
  7440. {
  7441. FDelayedDeletionTimer->Enabled = true;
  7442. }
  7443. }
  7444. //---------------------------------------------------------------------------
  7445. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7446. {
  7447. DebugAssert(FDelayedDeletionList != NULL);
  7448. TDateTime N = Now();
  7449. TDateTime Alert;
  7450. UnicodeString Directory;
  7451. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7452. {
  7453. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7454. if ((N >= Alert) || (Sender == NULL))
  7455. {
  7456. Directory = FDelayedDeletionList->Strings[Index];
  7457. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7458. {
  7459. FDelayedDeletionList->Delete(Index);
  7460. }
  7461. }
  7462. }
  7463. if (FDelayedDeletionList->Count == 0)
  7464. {
  7465. FDelayedDeletionTimer->Enabled = false;
  7466. }
  7467. }
  7468. //---------------------------------------------------------------------------
  7469. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7470. {
  7471. DebugAssert(!IsLocalBrowserMode());
  7472. if (IsFileControl(FDDTargetControl, osRemote) ||
  7473. (FDDTargetControl == SessionsPageControl))
  7474. {
  7475. TManagedTerminal * TargetTerminal = NULL;
  7476. TFileOperation Operation = foNone;
  7477. if (FDDTargetControl == SessionsPageControl)
  7478. {
  7479. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7480. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7481. // do not allow dropping on local-local, disconnected and the "+" tab (see also SessionsDDProcessDropped)
  7482. TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  7483. if (IsActiveTerminal(TargetTerminal) && DebugAlwaysTrue(!TargetTerminal->LocalBrowser))
  7484. {
  7485. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7486. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7487. {
  7488. Operation = foRemoteMove;
  7489. }
  7490. else
  7491. {
  7492. Operation = foRemoteCopy;
  7493. }
  7494. }
  7495. }
  7496. else
  7497. {
  7498. if (FLastDropEffect == DROPEFFECT_MOVE)
  7499. {
  7500. Operation = foRemoteMove;
  7501. }
  7502. else if (FLastDropEffect == DROPEFFECT_COPY)
  7503. {
  7504. Operation = foRemoteCopy;
  7505. }
  7506. }
  7507. if (Operation != foNone)
  7508. {
  7509. RemoteFileControlFileOperation(DropSourceControl,
  7510. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7511. }
  7512. // abort drag&drop
  7513. Abort();
  7514. }
  7515. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7516. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7517. (FDDTargetControl != QueueView3))
  7518. {
  7519. DebugAssert(!FDragTempDir.IsEmpty());
  7520. TTransferType Type;
  7521. UnicodeString TempDir = FDragTempDir;
  7522. // We clear FDragTempDir before calling
  7523. // just in case it fail (raises exception)
  7524. FDragTempDir = L"";
  7525. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7526. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7527. // empty directory parameter means temp directory -> don't display it!
  7528. UnicodeString TargetDir = L"";
  7529. int Options = 0;
  7530. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7531. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7532. {
  7533. Abort();
  7534. }
  7535. // TargetDir is set when dropped on local file control
  7536. // (this was workaround for legacy dirview event handling, now it should be
  7537. // made prettier)
  7538. if (TargetDir.IsEmpty())
  7539. {
  7540. TargetDir = TempDir;
  7541. if (ForceDirectories(ApiPath(TargetDir)))
  7542. {
  7543. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7544. FPendingTempSpaceWarn = true;
  7545. try
  7546. {
  7547. FDragDropOperation = true;
  7548. int Params = cpTemporary |
  7549. (Type == ttMove ? cpDelete : 0);
  7550. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7551. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7552. }
  7553. __finally
  7554. {
  7555. FDragDropOperation = false;
  7556. FPendingTempSpaceWarn = false;
  7557. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7558. }
  7559. }
  7560. else
  7561. {
  7562. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7563. }
  7564. }
  7565. }
  7566. }
  7567. //---------------------------------------------------------------------------
  7568. void __fastcall TCustomScpExplorerForm::DDDownload(
  7569. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7570. {
  7571. DebugAssert(!IsLocalBrowserMode());
  7572. TAutoBatch AutoBatch(this);
  7573. UpdateCopyParamCounters(*CopyParam);
  7574. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7575. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7576. {
  7577. RemoteDriveView->UpdateDropSource();
  7578. }
  7579. }
  7580. //---------------------------------------------------------------------------
  7581. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7582. {
  7583. public:
  7584. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7585. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7586. {
  7587. }
  7588. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7589. {
  7590. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7591. TDataObjectFilesEx::AllowData(FormatEtc);
  7592. }
  7593. };
  7594. //---------------------------------------------------------------------------
  7595. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7596. TObject * Sender, TDataObject *& DataObject)
  7597. {
  7598. if (FDDExtMapFile != NULL)
  7599. {
  7600. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7601. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7602. {
  7603. Abort();
  7604. }
  7605. if (FileList->Count > 0)
  7606. {
  7607. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7608. if (!FilesObject->IsValid(true, true))
  7609. {
  7610. FilesObject->_Release();
  7611. }
  7612. else
  7613. {
  7614. DataObject = FilesObject;
  7615. }
  7616. }
  7617. }
  7618. }
  7619. //---------------------------------------------------------------------------
  7620. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7621. {
  7622. DebugFail();
  7623. }
  7624. //---------------------------------------------------------------------------
  7625. void __fastcall TCustomScpExplorerForm::GoToTree()
  7626. {
  7627. ComponentVisible[fcRemoteTree] = true;
  7628. DriveView(osRemote)->SetFocus();
  7629. }
  7630. //---------------------------------------------------------------------------
  7631. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7632. TPanelExport Export)
  7633. {
  7634. TCustomDirView * DirView = this->DirView(Side);
  7635. std::unique_ptr<TStrings> ExportData(new TStringList());
  7636. switch (Export)
  7637. {
  7638. case pePath:
  7639. ExportData->Add(DirView->PathName);
  7640. break;
  7641. case peFileList:
  7642. case peFullFileList:
  7643. {
  7644. bool FullPath = (Export == peFullFileList);
  7645. DirView->CreateFileList(false, FullPath, ExportData.get());
  7646. for (int Index = 0; Index < ExportData->Count; Index++)
  7647. {
  7648. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7649. {
  7650. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7651. }
  7652. }
  7653. }
  7654. break;
  7655. default:
  7656. DebugFail();
  7657. }
  7658. return ExportData.release();
  7659. }
  7660. //---------------------------------------------------------------------------
  7661. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7662. TPanelExport Export, TPanelExportDestination Destination)
  7663. {
  7664. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7665. PanelExportStore(Side, Export, Destination, ExportData.get());
  7666. }
  7667. //---------------------------------------------------------------------------
  7668. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7669. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7670. TStrings * ExportData)
  7671. {
  7672. if (Destination == pedClipboard)
  7673. {
  7674. TInstantOperationVisualizer Visualizer;
  7675. CopyToClipboard(ExportData);
  7676. }
  7677. else
  7678. {
  7679. DebugFail();
  7680. }
  7681. }
  7682. //---------------------------------------------------------------------------
  7683. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7684. {
  7685. TCustomDirView * DirView = this->DirView(Side);
  7686. UnicodeString Mask = DirView->Mask;
  7687. if (DoFilterMaskDialog(DirView, Mask))
  7688. {
  7689. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7690. Configuration->Usage->Inc(L"Filters");
  7691. }
  7692. }
  7693. //---------------------------------------------------------------------------
  7694. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7695. {
  7696. return FQueueController->DefaultOperation();
  7697. }
  7698. //---------------------------------------------------------------------------
  7699. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7700. TQueueOperation Operation, void ** Param)
  7701. {
  7702. switch (Operation)
  7703. {
  7704. case qoPreferences:
  7705. return true;
  7706. case qoGoTo:
  7707. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7708. case qoOnceEmpty:
  7709. return IsAnythingQueued();
  7710. default:
  7711. return FQueueController->AllowOperation(Operation, Param);
  7712. }
  7713. }
  7714. //---------------------------------------------------------------------------
  7715. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7716. {
  7717. if (DebugAlwaysTrue(QueueView3->Visible))
  7718. {
  7719. QueueView3->SetFocus();
  7720. }
  7721. }
  7722. //---------------------------------------------------------------------------
  7723. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7724. TQueueOperation Operation, void * Param)
  7725. {
  7726. if (Operation == qoGoTo)
  7727. {
  7728. GoToQueue();
  7729. }
  7730. else if (Operation == qoPreferences)
  7731. {
  7732. PreferencesDialog(pmQueue);
  7733. }
  7734. else
  7735. {
  7736. FQueueController->ExecuteOperation(Operation, Param);
  7737. }
  7738. }
  7739. //---------------------------------------------------------------------------
  7740. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7741. {
  7742. return (Queue != NULL) && Queue->Enabled;
  7743. }
  7744. //---------------------------------------------------------------------------
  7745. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7746. {
  7747. DebugAssert(Queue != NULL);
  7748. if (Queue != NULL)
  7749. {
  7750. Queue->Enabled = !Queue->Enabled;
  7751. }
  7752. }
  7753. //---------------------------------------------------------------------------
  7754. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7755. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7756. {
  7757. FQueueActedItem = QueueView3->ItemFocused;
  7758. }
  7759. //---------------------------------------------------------------------------
  7760. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7761. {
  7762. return TopDock->Height + QueueSplitter->Height;
  7763. }
  7764. //---------------------------------------------------------------------------
  7765. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7766. {
  7767. return
  7768. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7769. (QueueDock->Visible ? QueueDock->Height : 0) +
  7770. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7771. }
  7772. //---------------------------------------------------------------------------
  7773. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7774. {
  7775. return ScaleByTextHeight(this, 48);
  7776. }
  7777. //---------------------------------------------------------------------------
  7778. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7779. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7780. {
  7781. // when queue is hidden by double-clicking splitter, stray attempt to
  7782. // resize the panel with strange value arrives, make sure it is ignored
  7783. if (ComponentVisible[fcQueueView])
  7784. {
  7785. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7786. if (NewSize > MaxHeightLimit)
  7787. {
  7788. NewSize = MaxHeightLimit;
  7789. }
  7790. int MinHeightLimit =
  7791. GetStaticQueuePanelComponentsHeight() +
  7792. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7793. GetMinQueueViewHeight();
  7794. if (NewSize < MinHeightLimit)
  7795. {
  7796. NewSize = MinHeightLimit;
  7797. }
  7798. }
  7799. else
  7800. {
  7801. Accept = false;
  7802. }
  7803. }
  7804. //---------------------------------------------------------------------------
  7805. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7806. {
  7807. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7808. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7809. if (QueueViewHeight < GetMinQueueViewHeight())
  7810. {
  7811. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7812. }
  7813. }
  7814. //---------------------------------------------------------------------------
  7815. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7816. TDragObject *& /*DragObject*/)
  7817. {
  7818. FQueueActedItem = QueueView3->ItemFocused;
  7819. }
  7820. //---------------------------------------------------------------------------
  7821. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7822. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7823. {
  7824. Accept = true;
  7825. if (Source == QueueView3)
  7826. {
  7827. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7828. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7829. if (Accept)
  7830. {
  7831. TQueueItemProxy * QueueItem;
  7832. TQueueItemProxy * DestQueueItem;
  7833. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7834. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7835. Accept = (QueueItem != DestQueueItem) &&
  7836. (QueueItem->Status == TQueueItem::qsPending) &&
  7837. (DestQueueItem->Status == TQueueItem::qsPending);
  7838. }
  7839. }
  7840. }
  7841. //---------------------------------------------------------------------------
  7842. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7843. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7844. {
  7845. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7846. {
  7847. TQueueItemProxy * QueueItem;
  7848. TQueueItemProxy * DestQueueItem;
  7849. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7850. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7851. QueueItem->Move(DestQueueItem);
  7852. }
  7853. }
  7854. //---------------------------------------------------------------------------
  7855. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7856. {
  7857. if ((QueueView3->ItemFocused == NULL) &&
  7858. (QueueView3->Items->Count > 0))
  7859. {
  7860. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7861. }
  7862. QueueLabelUpdateStatus();
  7863. }
  7864. //---------------------------------------------------------------------------
  7865. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7866. {
  7867. QueueLabelUpdateStatus();
  7868. }
  7869. //---------------------------------------------------------------------------
  7870. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7871. {
  7872. QueueLabel->UpdateStatus();
  7873. }
  7874. //---------------------------------------------------------------------------
  7875. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7876. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7877. {
  7878. if (Selected)
  7879. {
  7880. NonVisualDataModule->UpdateNonVisibleActions();
  7881. }
  7882. }
  7883. //---------------------------------------------------------------------------
  7884. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7885. {
  7886. TDragDropFilesEx * Result = NULL;
  7887. if (Sender == SessionsPageControl)
  7888. {
  7889. Result = FSessionsDragDropFilesEx;
  7890. }
  7891. else if (Sender == QueueView3)
  7892. {
  7893. Result = FQueueDragDropFilesEx;
  7894. }
  7895. else
  7896. {
  7897. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7898. if (DirView != NULL)
  7899. {
  7900. Result = DirView->DragDropFilesEx;
  7901. }
  7902. else
  7903. {
  7904. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7905. if (DriveView != NULL)
  7906. {
  7907. Result = DriveView->DragDropFilesEx;
  7908. }
  7909. }
  7910. }
  7911. DebugAssert(Result != NULL);
  7912. return Result;
  7913. }
  7914. //---------------------------------------------------------------------------
  7915. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7916. {
  7917. return (DView->SelCount == DView->FilesCount);
  7918. }
  7919. //---------------------------------------------------------------------------
  7920. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7921. {
  7922. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7923. }
  7924. //---------------------------------------------------------------------------
  7925. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7926. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7927. {
  7928. DebugAssert(!IsLocalBrowserMode());
  7929. TFileOperation Operation;
  7930. switch (Effect)
  7931. {
  7932. case DROPEFFECT_MOVE:
  7933. Operation = foMove;
  7934. break;
  7935. case DROPEFFECT_COPY:
  7936. // occures on WinXP (reported by user)
  7937. default:
  7938. Operation = foCopy;
  7939. break;
  7940. };
  7941. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7942. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7943. if (DragDropFilesEx->FileList->Count > 0)
  7944. {
  7945. TStrings * FileList = new TStringList();
  7946. try
  7947. {
  7948. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7949. {
  7950. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7951. }
  7952. FDragDropOperation = true;
  7953. TTransferOperationParam Param;
  7954. Param.TargetDirectory = TargetPath;
  7955. // upload, no temp dirs
  7956. Param.Temp = false;
  7957. Param.DragDrop = DragDrop;
  7958. Param.Options =
  7959. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7960. if (ForceQueue)
  7961. {
  7962. Param.Queue = asOn;
  7963. }
  7964. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7965. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7966. {
  7967. if (IsFileControl(DropSourceControl, osLocal))
  7968. {
  7969. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7970. }
  7971. else
  7972. {
  7973. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7974. }
  7975. }
  7976. }
  7977. __finally
  7978. {
  7979. FDragDropOperation = false;
  7980. delete FileList;
  7981. }
  7982. }
  7983. }
  7984. //---------------------------------------------------------------------------
  7985. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7986. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7987. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7988. {
  7989. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7990. }
  7991. //---------------------------------------------------------------------------
  7992. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7993. TObject * Sender, int grfKeyState, int & dwEffect)
  7994. {
  7995. DebugAssert(!IsLocalBrowserMode());
  7996. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7997. if ((dwEffect != DROPEFFECT_NONE) &&
  7998. IsFileControl(DropSourceControl, osRemote))
  7999. {
  8000. // do not allow drop on remote panel (on free space, still allow drop on directories)
  8001. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  8002. (RemoteDirView->DropTarget == NULL))
  8003. {
  8004. dwEffect = DROPEFFECT_NONE;
  8005. }
  8006. else
  8007. {
  8008. if (dwEffect == DROPEFFECT_COPY)
  8009. {
  8010. bool MoveCapable = Terminal->IsCapable[fcRemoteMove];
  8011. // currently we support copying always (at least via temporary directory);
  8012. // remove associated checks once this all proves stable and working
  8013. bool CopyCapable = true;
  8014. // if we do not support neither of operations, there's no discussion
  8015. if (!MoveCapable && !CopyCapable)
  8016. {
  8017. dwEffect = DROPEFFECT_NONE;
  8018. }
  8019. else
  8020. {
  8021. // The default effect inside remote panel is move,
  8022. // unless we do not support it, but support copy
  8023. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  8024. {
  8025. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  8026. }
  8027. else
  8028. {
  8029. // with ctrl-down, we want copy unless it is not supported
  8030. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  8031. }
  8032. }
  8033. }
  8034. }
  8035. }
  8036. }
  8037. //---------------------------------------------------------------------------
  8038. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  8039. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  8040. {
  8041. DebugAssert(!IsLocalBrowserMode());
  8042. if (FDDTotalSize >= 0)
  8043. {
  8044. if (File->IsDirectory)
  8045. {
  8046. FDDTotalSize = -1;
  8047. }
  8048. else
  8049. {
  8050. FDDTotalSize += File->Size;
  8051. }
  8052. }
  8053. DebugAssert(!FDragTempDir.IsEmpty());
  8054. // TODO: this is quite ineffective
  8055. // TODO: what if invalid character replacement is disabled?
  8056. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  8057. UnicodeString TransferFileName;
  8058. if (Sender == RemoteDriveView)
  8059. {
  8060. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  8061. }
  8062. else
  8063. {
  8064. TransferFileName = File->FileName;
  8065. }
  8066. FDDFileList->AddObject(TransferFileName, File);
  8067. }
  8068. //---------------------------------------------------------------------------
  8069. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  8070. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  8071. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  8072. {
  8073. // sometimes we do not get DDEnd so the list is not released
  8074. SAFE_DESTROY(FDDFileList);
  8075. FDDFileList = new TStringList();
  8076. FDragTempDir = WinConfiguration->TemporaryDir();
  8077. FDDTotalSize = 0;
  8078. FDragDropSshTerminate.reset(NULL);
  8079. }
  8080. //---------------------------------------------------------------------------
  8081. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  8082. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  8083. HRESULT & Result)
  8084. {
  8085. if (Result == DRAGDROP_S_DROP)
  8086. {
  8087. try
  8088. {
  8089. GlobalDragImageList->HideDragImage();
  8090. try
  8091. {
  8092. RemoteFileControlDDTargetDrop();
  8093. }
  8094. catch(ESshTerminate & E)
  8095. {
  8096. FDragDropSshTerminate.reset(E.Clone());
  8097. }
  8098. }
  8099. catch (Exception &E)
  8100. {
  8101. // If downloading fails we need to cancel drag&drop, otherwise
  8102. // Explorer shows error
  8103. // But by the way exception probably never reach this point as
  8104. // it's catched on way.
  8105. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  8106. Result = DRAGDROP_S_CANCEL;
  8107. ShowExtendedException(Terminal, &E);
  8108. }
  8109. }
  8110. }
  8111. //---------------------------------------------------------------------------
  8112. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  8113. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  8114. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  8115. {
  8116. TFileMasks::TParams MaskParams;
  8117. MaskParams.Size = Size;
  8118. MaskParams.Modification = Modification;
  8119. // this does not re-parse the mask if it is the same as the last time
  8120. FDirViewMatchMask = Masks;
  8121. bool ImplicitMatch;
  8122. Matches =
  8123. // RecurseInclude parameter has no effect as the Path is empty
  8124. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  8125. (AllowImplicitMatches || !ImplicitMatch);
  8126. }
  8127. //---------------------------------------------------------------------------
  8128. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  8129. TObject * Sender, TListItem * Item, WORD & Indexes)
  8130. {
  8131. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  8132. UnicodeString Ext;
  8133. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  8134. {
  8135. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  8136. }
  8137. else
  8138. {
  8139. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  8140. }
  8141. if (SameText(Ext, Configuration->PartialExt))
  8142. {
  8143. Indexes |= oiPartial;
  8144. }
  8145. }
  8146. //---------------------------------------------------------------------------
  8147. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  8148. {
  8149. return
  8150. DirViewEnabled(osCurrent) &&
  8151. DirView(osCurrent)->CanPasteFromClipBoard();
  8152. }
  8153. //---------------------------------------------------------------------------
  8154. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  8155. {
  8156. bool Result = false;
  8157. if (CanPasteToDirViewFromClipBoard())
  8158. {
  8159. Result = true;
  8160. }
  8161. else
  8162. {
  8163. UnicodeString ClipboardText;
  8164. if (NonEmptyTextFromClipboard(ClipboardText) &&
  8165. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  8166. {
  8167. if (StoredSessions->IsUrl(ClipboardText))
  8168. {
  8169. Result = true;
  8170. }
  8171. else
  8172. {
  8173. Result = DirViewEnabled(osCurrent);
  8174. }
  8175. }
  8176. }
  8177. return Result;
  8178. }
  8179. //---------------------------------------------------------------------------
  8180. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  8181. {
  8182. // Pasting to any local panel is handled in TScpCommanderForm::PasteFromClipBoard()
  8183. if (DoesClipboardContainOurFiles())
  8184. {
  8185. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  8186. {
  8187. DebugAssert(!IsLocalBrowserMode());
  8188. TTerminalManager * Manager = TTerminalManager::Instance();
  8189. TTerminal * TargetTerminal = Manager->ActiveTerminal;
  8190. Manager->ActiveSession = FClipboardTerminal;
  8191. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TargetTerminal);
  8192. }
  8193. }
  8194. else if (CanPasteToDirViewFromClipBoard())
  8195. {
  8196. DirView(osCurrent)->PasteFromClipBoard();
  8197. }
  8198. else
  8199. {
  8200. UnicodeString ClipboardText;
  8201. if (NonEmptyTextFromClipboard(ClipboardText))
  8202. {
  8203. if (StoredSessions->IsUrl(ClipboardText))
  8204. {
  8205. NewSession(ClipboardText);
  8206. }
  8207. else
  8208. {
  8209. DirView(osCurrent)->Path = ClipboardText;
  8210. }
  8211. }
  8212. }
  8213. }
  8214. //---------------------------------------------------------------------------
  8215. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  8216. {
  8217. // TBD
  8218. }
  8219. //---------------------------------------------------------------------------
  8220. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  8221. {
  8222. TCustomDirView * ADirView = DirView(Side);
  8223. ADirView->SelectAll(Mode);
  8224. ADirView->SetFocus();
  8225. }
  8226. //---------------------------------------------------------------------------
  8227. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  8228. {
  8229. TCustomDirView * ADirView = DirView(Side);
  8230. TFileFilter Filter;
  8231. DefaultFileFilter(Filter);
  8232. if (DoSelectMaskDialog(ADirView, Select, Filter))
  8233. {
  8234. Configuration->Usage->Inc(L"MaskSelections");
  8235. ADirView->SelectFiles(Filter, Select);
  8236. ADirView->SetFocus();
  8237. }
  8238. }
  8239. //---------------------------------------------------------------------------
  8240. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  8241. {
  8242. TCustomDirView * ADirView = DirView(Side);
  8243. ADirView->RestoreSelectedNames();
  8244. ADirView->SetFocus();
  8245. }
  8246. //---------------------------------------------------------------------------
  8247. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  8248. {
  8249. TCustomDirView * CurrentDirView = DirView(osCurrent);
  8250. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  8251. {
  8252. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  8253. UnicodeString Ext;
  8254. if (!IsSideLocalBrowser(osCurrent))
  8255. {
  8256. Ext = UnixExtractFileExt(FileName);
  8257. }
  8258. else
  8259. {
  8260. Ext = ExtractFileExt(FileName);
  8261. }
  8262. if (Ext.IsEmpty())
  8263. {
  8264. Ext = L".";
  8265. }
  8266. TFileFilter Filter;
  8267. Filter.Masks = FORMAT(L"*%s", (Ext));
  8268. Filter.Directories = false;
  8269. CurrentDirView->SelectFiles(Filter, Select);
  8270. }
  8271. }
  8272. //---------------------------------------------------------------------------
  8273. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  8274. const TStatusFileInfo & FileInfo, TOperationSide Side)
  8275. {
  8276. UnicodeString Result;
  8277. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  8278. {
  8279. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  8280. }
  8281. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  8282. {
  8283. // noop
  8284. }
  8285. else
  8286. {
  8287. Result =
  8288. FMTLOAD(FILE_INFO_FORMAT,
  8289. (FormatBytes(FileInfo.SelectedSize),
  8290. FormatBytes(FileInfo.FilesSize),
  8291. FormatNumber(FileInfo.SelectedCount),
  8292. FormatNumber(FileInfo.FilesCount)));
  8293. }
  8294. return Result;
  8295. }
  8296. //---------------------------------------------------------------------------
  8297. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8298. TTBXStatusPanel * Panel, TOperationSide Side)
  8299. {
  8300. if (Panel->Index == 1)
  8301. {
  8302. ToggleShowHiddenFiles();
  8303. }
  8304. else if (Panel->Index == 2)
  8305. {
  8306. Filter(Side);
  8307. }
  8308. }
  8309. //---------------------------------------------------------------------------
  8310. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8311. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8312. {
  8313. DebugAssert(!StatusBar->SimplePanel);
  8314. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8315. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8316. }
  8317. //---------------------------------------------------------------------------
  8318. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8319. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8320. {
  8321. DebugAssert(StatusBar->Panels->Count >= 3);
  8322. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8323. if (FileInfo.HiddenCount > 0)
  8324. {
  8325. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8326. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8327. }
  8328. else
  8329. {
  8330. HiddenFilesPanel->ViewPriority = 0;
  8331. // not really necessary, just to cleanup no-longer-valid data
  8332. HiddenFilesPanel->Caption = L"";
  8333. }
  8334. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8335. if (FileInfo.FilteredCount > 0)
  8336. {
  8337. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8338. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8339. }
  8340. else
  8341. {
  8342. FilteredFilesPanel->ViewPriority = 0;
  8343. // not really necessary, just to cleanup no-longer-valid data
  8344. FilteredFilesPanel->Caption = L"";
  8345. }
  8346. }
  8347. //---------------------------------------------------------------------------
  8348. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8349. TObject * /*Sender*/)
  8350. {
  8351. if (DirView(osOther)->Enabled)
  8352. {
  8353. DirView(osOther)->SetFocus();
  8354. }
  8355. }
  8356. //---------------------------------------------------------------------------
  8357. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8358. {
  8359. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8360. switch (Config.Show)
  8361. {
  8362. case qvShow:
  8363. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8364. {
  8365. Config.Show = qvHide;
  8366. }
  8367. else
  8368. {
  8369. Config.Show = Config.LastHideShow;
  8370. }
  8371. break;
  8372. case qvHideWhenEmpty:
  8373. if (ComponentVisible[fcQueueView])
  8374. {
  8375. Config.Show = qvHide;
  8376. }
  8377. else
  8378. {
  8379. Config.LastHideShow = Config.Show;
  8380. Config.Show = qvShow;
  8381. }
  8382. break;
  8383. case qvHide:
  8384. Config.LastHideShow = Config.Show;
  8385. Config.Show = qvShow;
  8386. break;
  8387. }
  8388. WinConfiguration->QueueView = Config;
  8389. }
  8390. //---------------------------------------------------------------------------
  8391. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8392. {
  8393. UnicodeString Result;
  8394. if (Terminal != NULL)
  8395. {
  8396. switch (WinConfiguration->PathInCaption)
  8397. {
  8398. case picShort:
  8399. Result = ExtractShortName(Terminal->CurrentDirectory, true);
  8400. break;
  8401. case picFull:
  8402. Result = Terminal->CurrentDirectory;
  8403. break;
  8404. }
  8405. }
  8406. return Result;
  8407. }
  8408. //---------------------------------------------------------------------------
  8409. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8410. {
  8411. TColor Result = GetWindowColor(FSessionColor);
  8412. return Result;
  8413. }
  8414. //---------------------------------------------------------------------------
  8415. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8416. {
  8417. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8418. return Result;
  8419. }
  8420. //---------------------------------------------------------------------------
  8421. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8422. {
  8423. if (!FSessionChanging)
  8424. {
  8425. TTerminalManager::Instance()->UpdateAppTitle();
  8426. }
  8427. // WORKAROUND: Disabling list view when it is not showing yet does not set its
  8428. // background to gray on Windows 7 (works on Windows 10).
  8429. // See also EnableControl
  8430. if (Showing)
  8431. {
  8432. if (ManagedSession != NULL)
  8433. {
  8434. // Update path when it changes
  8435. if ((SessionsPageControl->ActivePage != NULL) &&
  8436. (GetSessionTabSession(SessionsPageControl->ActivePage) == ManagedSession))
  8437. {
  8438. UpdateSessionTab(SessionsPageControl->ActivePage);
  8439. }
  8440. }
  8441. NonVisualDataModule->ReconnectSessionAction->Update();
  8442. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8443. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8444. CenterReconnectToolbar();
  8445. bool HasTerminal = HasActiveTerminal();
  8446. RemoteDirView->Enabled = HasTerminal;
  8447. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8448. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8449. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8450. RemoteDriveView->Color = RemoteDirView->Color;
  8451. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8452. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8453. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8454. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8455. QueueFileList->Enabled = QueueView3->Enabled;
  8456. QueueFileList->Color = QueueView3->Color;
  8457. QueueFileList->Font->Color = QueueView3->Font->Color;
  8458. QueueLabelUpdateStatus();
  8459. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8460. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8461. if (FImmersiveDarkMode != WinConfiguration->UseDarkTheme())
  8462. {
  8463. UpdateDarkMode();
  8464. }
  8465. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8466. }
  8467. }
  8468. //---------------------------------------------------------------------------
  8469. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8470. {
  8471. UpdateControls();
  8472. }
  8473. //---------------------------------------------------------------------------
  8474. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8475. TObject * Sender)
  8476. {
  8477. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8478. DebugAssert(DirView != NULL);
  8479. DoDirViewLoaded(DirView);
  8480. TransferPresetAutoSelect();
  8481. }
  8482. //---------------------------------------------------------------------------
  8483. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8484. {
  8485. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8486. // first run after installation
  8487. if (double(Updates.LastCheck) == 0)
  8488. {
  8489. // make sure next time there will be an update (if enabled)
  8490. Updates.LastCheck = TDateTime(1);
  8491. WinConfiguration->Updates = Updates;
  8492. }
  8493. else if ((double(Updates.Period) > 0) &&
  8494. (Now() - Updates.LastCheck >= Updates.Period))
  8495. {
  8496. TThreadMethod OnUpdatesChecked = NULL;
  8497. if (!IsUWP())
  8498. {
  8499. OnUpdatesChecked = UpdatesChecked;
  8500. }
  8501. StartUpdateThread(OnUpdatesChecked);
  8502. }
  8503. }
  8504. //---------------------------------------------------------------------------
  8505. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8506. {
  8507. UnicodeString Message;
  8508. bool New;
  8509. TQueryType Type;
  8510. GetUpdatesMessage(Message, New, Type, false);
  8511. if (!Message.IsEmpty())
  8512. {
  8513. if (New)
  8514. {
  8515. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8516. }
  8517. if (!New && (Type != qtWarning))
  8518. {
  8519. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8520. }
  8521. else
  8522. {
  8523. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8524. }
  8525. if (New)
  8526. {
  8527. Configuration->Usage->Inc(L"UpdateNotifications");
  8528. }
  8529. }
  8530. }
  8531. //---------------------------------------------------------------------------
  8532. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8533. {
  8534. RestoreApp();
  8535. bool CanDisplay = !NonVisualDataModule->Busy;
  8536. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8537. {
  8538. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8539. }
  8540. if (CanDisplay)
  8541. {
  8542. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8543. CheckForUpdates(true);
  8544. }
  8545. else
  8546. {
  8547. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8548. }
  8549. }
  8550. //---------------------------------------------------------------------------
  8551. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8552. TCopyParamRuleData & Data)
  8553. {
  8554. DebugAssert(Terminal != NULL);
  8555. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8556. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8557. Data.RemoteDirectory = RemoteDirView->PathName;
  8558. }
  8559. //---------------------------------------------------------------------------
  8560. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8561. {
  8562. // Terminal can be null when we are changing local directory implicitly,
  8563. // because it has been deleted, while no session is connected
  8564. // (Login dialog is open)
  8565. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8566. {
  8567. DebugAssert(!IsLocalBrowserMode());
  8568. TCopyParamRuleData Data;
  8569. GetTransferPresetAutoSelectData(Data);
  8570. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8571. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8572. if (CopyParamIndex < 0)
  8573. {
  8574. // there is no preset that matches autoselection
  8575. // set preset that we consider "default"
  8576. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8577. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8578. }
  8579. else
  8580. {
  8581. // there is preset matching autoselection
  8582. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8583. if (CopyParamName == FCopyParamAutoSelected)
  8584. {
  8585. // autoselected the same preset as the last time
  8586. // make no change (i.e. preserve custom user preset, if any)
  8587. }
  8588. else
  8589. {
  8590. // autoselected the different preset then the last time (or there
  8591. // was default preset set)
  8592. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8593. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8594. }
  8595. }
  8596. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8597. {
  8598. if (CopyParamIndex >= 0)
  8599. {
  8600. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8601. }
  8602. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8603. try
  8604. {
  8605. int Fmt =
  8606. (CopyParamIndex < 0) ?
  8607. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8608. COPY_PARAM_AUTOSELECTED;
  8609. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8610. Data->Message = MainInstructions(Message);
  8611. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8612. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8613. CopyParamAttrs);
  8614. if (CopyParamIndex >= 0)
  8615. {
  8616. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8617. Info = FORMAT(L"%s\n \n%s", (Info,
  8618. FMTLOAD(COPY_PARAM_RULE,
  8619. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8620. }
  8621. Data->Message += L"\n\n" + Info;
  8622. if (WinConfiguration->CopyParamAutoSelectNotice)
  8623. {
  8624. TransferPresetNoteMessage(Data, true);
  8625. }
  8626. else
  8627. {
  8628. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8629. Data = NULL; // ownership passed
  8630. }
  8631. }
  8632. __finally
  8633. {
  8634. delete Data;
  8635. }
  8636. }
  8637. }
  8638. }
  8639. //---------------------------------------------------------------------------
  8640. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8641. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8642. {
  8643. DebugAssert(NoteData != NULL);
  8644. DebugAssert(!IsLocalBrowserMode());
  8645. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8646. TQueryButtonAlias Aliases[1];
  8647. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8648. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8649. Params.Aliases = Aliases;
  8650. Params.AliasesCount = LENOF(Aliases);
  8651. unsigned int Result =
  8652. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8653. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8654. switch (Result)
  8655. {
  8656. case qaNeverAskAgain:
  8657. DebugAssert(AllowNeverAskAgain);
  8658. WinConfiguration->CopyParamAutoSelectNotice = false;
  8659. break;
  8660. case qaIgnore:
  8661. PreferencesDialog(pmPresets);
  8662. break;
  8663. }
  8664. }
  8665. //---------------------------------------------------------------------------
  8666. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8667. {
  8668. // as of now useless, as this is used for notes only, never for balloons, ...
  8669. RestoreApp();
  8670. // .. and we should never be busy here
  8671. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8672. {
  8673. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8674. }
  8675. }
  8676. //---------------------------------------------------------------------------
  8677. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8678. TPreferencesMode APreferencesMode)
  8679. {
  8680. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8681. TCopyParamRuleData Data;
  8682. if (Terminal != NULL)
  8683. {
  8684. PreferencesData.reset(new TPreferencesDialogData());
  8685. GetTransferPresetAutoSelectData(Data);
  8686. PreferencesData->CopyParamRuleData = &Data;
  8687. }
  8688. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8689. }
  8690. //---------------------------------------------------------------------------
  8691. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8692. const TCustomCommandType & Command)
  8693. {
  8694. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8695. {
  8696. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8697. }
  8698. }
  8699. //---------------------------------------------------------------------------
  8700. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8701. {
  8702. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8703. TCustomCommandType Command;
  8704. // make sure we use local custom command when remote are not supported
  8705. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8706. {
  8707. Command = FLastCustomCommand;
  8708. }
  8709. else
  8710. {
  8711. Command.Params = Command.Params | ccLocal;
  8712. }
  8713. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8714. FEditingFocusedAdHocCommand = OnFocused;
  8715. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8716. int Options =
  8717. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8718. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8719. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8720. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8721. {
  8722. FLastCustomCommand = Command;
  8723. UpdateCustomCommandsToolbar();
  8724. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8725. }
  8726. }
  8727. //---------------------------------------------------------------------------
  8728. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8729. {
  8730. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8731. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8732. DebugAssert(State > 0);
  8733. if (State <= 0)
  8734. {
  8735. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8736. }
  8737. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8738. }
  8739. //---------------------------------------------------------------------------
  8740. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8741. TCustomCommandType & Command, int & State)
  8742. {
  8743. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8744. if (Result)
  8745. {
  8746. Command = FLastCustomCommand;
  8747. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8748. }
  8749. return Result;
  8750. }
  8751. //---------------------------------------------------------------------------
  8752. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8753. {
  8754. ResetIncrementalSearch();
  8755. }
  8756. //---------------------------------------------------------------------------
  8757. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8758. {
  8759. DebugAssert(ComponentVisible[Component]);
  8760. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8761. }
  8762. //---------------------------------------------------------------------------
  8763. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8764. {
  8765. // when queue panel is resized here directly, the status bar is stretched
  8766. // over whole space the panel occupied
  8767. PostComponentHide(fcQueueView);
  8768. }
  8769. //---------------------------------------------------------------------------
  8770. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8771. {
  8772. ComponentVisible[fcQueueFileList] = false;
  8773. }
  8774. //---------------------------------------------------------------------------
  8775. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8776. {
  8777. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8778. RefreshColorMode();
  8779. ResetSysDarkTheme();
  8780. ConfigurationChanged();
  8781. ConfigureInterface();
  8782. // Should be called for all controls
  8783. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8784. }
  8785. //---------------------------------------------------------------------------
  8786. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8787. {
  8788. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8789. if (!FInvalid &&
  8790. (Message.LParam != 0) &&
  8791. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8792. {
  8793. ThemeChanged();
  8794. }
  8795. TForm::Dispatch(&Message);
  8796. }
  8797. //---------------------------------------------------------------------------
  8798. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8799. {
  8800. TMessage * M = static_cast<TMessage*>(Message);
  8801. switch (M->Msg)
  8802. {
  8803. case CM_DIALOGCHAR:
  8804. CMDialogChar(*M);
  8805. break;
  8806. case WM_APPCOMMAND:
  8807. WMAppCommand(*M);
  8808. break;
  8809. case WM_SYSCOMMAND:
  8810. WMSysCommand(*M);
  8811. break;
  8812. case WM_QUERYENDSESSION:
  8813. WMQueryEndSession(*M);
  8814. break;
  8815. case WM_ENDSESSION:
  8816. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8817. break;
  8818. #ifdef _DEBUG
  8819. case WM_WINDOWPOSCHANGED:
  8820. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8821. break;
  8822. case CM_CUSTOMSTYLECHANGED:
  8823. TForm::Dispatch(Message);
  8824. break;
  8825. #endif
  8826. case WM_COMPONENT_HIDE:
  8827. {
  8828. Byte Component = static_cast<Byte>(M->WParam);
  8829. // sanity check
  8830. if (ComponentVisible[Component])
  8831. {
  8832. // special treatment
  8833. if (Component == fcQueueView)
  8834. {
  8835. ToggleQueueVisibility();
  8836. DebugAssert(!ComponentVisible[fcQueueView]);
  8837. }
  8838. else
  8839. {
  8840. ComponentVisible[Component] = false;
  8841. }
  8842. }
  8843. }
  8844. break;
  8845. case WM_COPYDATA:
  8846. WMCopyData(*M);
  8847. break;
  8848. case WM_MANAGES_CAPTION:
  8849. // caption managed in TTerminalManager::UpdateAppTitle()
  8850. M->Result = 1;
  8851. break;
  8852. case WM_WANTS_MOUSEWHEEL:
  8853. M->Result = 1;
  8854. break;
  8855. case CM_SHOWINGCHANGED:
  8856. CMShowingChanged(*M);
  8857. break;
  8858. case WM_CLOSE:
  8859. WMClose(*M);
  8860. break;
  8861. case WM_DPICHANGED:
  8862. WMDpiChanged(*M);
  8863. break;
  8864. case CM_DPICHANGED:
  8865. CMDpiChanged(*M);
  8866. break;
  8867. case WM_SETTINGCHANGE:
  8868. WMSettingChange(*M);
  8869. break;
  8870. case CM_DIALOGKEY:
  8871. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8872. break;
  8873. default:
  8874. TForm::Dispatch(Message);
  8875. break;
  8876. }
  8877. }
  8878. //---------------------------------------------------------------------------
  8879. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8880. {
  8881. // noop
  8882. }
  8883. //---------------------------------------------------------------------------
  8884. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8885. {
  8886. TForm::Dispatch(&Message);
  8887. FSessionColors->Clear();
  8888. AddFixedSessionImages();
  8889. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8890. UpdateImages();
  8891. }
  8892. //---------------------------------------------------------------------------
  8893. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8894. {
  8895. TForm::Dispatch(&Message);
  8896. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8897. UpdatePixelsPerInchMainWindowCounter();
  8898. }
  8899. //---------------------------------------------------------------------------
  8900. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8901. {
  8902. // Cannot close window while we are busy.
  8903. // We cannot test this in FormCloseQuery as that is called also from
  8904. // Close(), which is called by CloseApplicationAction. So we can be busy
  8905. // there already even, when it is legitimate to close the application.
  8906. // Possibly a better place to handle this would be WMSysCommand.
  8907. if (NonVisualDataModule->Busy)
  8908. {
  8909. Message.Result = 1;
  8910. }
  8911. else
  8912. {
  8913. TForm::Dispatch(&Message);
  8914. }
  8915. }
  8916. //---------------------------------------------------------------------------
  8917. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8918. {
  8919. // Ignoring implicit local-local browser of Commander, opened from DoShow
  8920. bool NoSession = (ManagedSession == NULL);
  8921. // This calls TCustomScpExplorerForm::DoShow
  8922. TForm::Dispatch(&Message);
  8923. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  8924. if (Showing && !FStarted)
  8925. {
  8926. FStarted = true;
  8927. InterfaceStarted();
  8928. }
  8929. if (Showing && NoSession)
  8930. {
  8931. // When we are starting minimized (i.e. from an installer),
  8932. // postpone showing Login dialog until we get restored.
  8933. // Otherwise the Login dialog (and Authentication window) show restored
  8934. // over invisible (minimized) main window.
  8935. if (WindowState == wsMinimized)
  8936. {
  8937. FNeedSession = true;
  8938. }
  8939. else
  8940. {
  8941. // This happens before application ever goes idle, so the toolbars would
  8942. // stay enabled (initial state) until the Login dialog is dismissed.
  8943. UpdateActions();
  8944. NonVisualDataModule->StartBusy();
  8945. try
  8946. {
  8947. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8948. // otherwise the dialog does not receive focus.
  8949. // With Commander interface the ProcessMessages is called already
  8950. // by TDriveView, but with Explorer interface, we need to call it explicily
  8951. Application->ProcessMessages();
  8952. // do not reload sessions, they have been loaded just now (optimization)
  8953. NeedSession(true);
  8954. }
  8955. __finally
  8956. {
  8957. NonVisualDataModule->EndBusy();
  8958. }
  8959. }
  8960. }
  8961. }
  8962. //---------------------------------------------------------------------------
  8963. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8964. {
  8965. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8966. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8967. }
  8968. //---------------------------------------------------------------------------
  8969. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8970. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8971. int & MaxHeight)
  8972. {
  8973. // workaround for bug in TWinControl.CalcConstraints
  8974. // Check for empty rect (restore from iconic state) is done there only after
  8975. // call to AdjustClientRect, which enlarges the rect (for forms).
  8976. TRect R = GetClientRect();
  8977. // when restoring from iconic state, place no restrictions
  8978. if (IsRectEmpty(R))
  8979. {
  8980. MinWidth = 0;
  8981. MinHeight = 0;
  8982. MaxWidth = 32000;
  8983. MaxHeight = 32000;
  8984. }
  8985. }
  8986. //---------------------------------------------------------------------------
  8987. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8988. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8989. {
  8990. // terminal can be already closed (e.g. dropped connection)
  8991. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8992. {
  8993. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8994. try
  8995. {
  8996. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8997. }
  8998. catch(...)
  8999. {
  9000. if (!Terminal->Active)
  9001. {
  9002. Close = true;
  9003. }
  9004. throw;
  9005. }
  9006. }
  9007. }
  9008. //---------------------------------------------------------------------------
  9009. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  9010. {
  9011. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  9012. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  9013. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  9014. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  9015. {
  9016. OnGetSpaceAvailable = GetSpaceAvailable;
  9017. }
  9018. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  9019. OnGetSpaceAvailable);
  9020. }
  9021. //---------------------------------------------------------------------------
  9022. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  9023. {
  9024. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  9025. Terminal->FillSessionDataForCode(Data.get());
  9026. return Data.release();
  9027. }
  9028. //---------------------------------------------------------------------------
  9029. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  9030. {
  9031. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  9032. DoGenerateUrlDialog(Data.get(), Paths);
  9033. }
  9034. //---------------------------------------------------------------------------
  9035. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  9036. {
  9037. GenerateUrl(NULL);
  9038. }
  9039. //---------------------------------------------------------------------------
  9040. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  9041. {
  9042. std::unique_ptr<TStrings> Paths(new TStringList());
  9043. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  9044. GenerateUrl(Paths.get());
  9045. }
  9046. //---------------------------------------------------------------------------
  9047. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  9048. {
  9049. FSessionColor = value;
  9050. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  9051. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  9052. static_cast<TObject *>(GetComponent(fcColorMenu)));
  9053. DebugAssert(ColorItem != NULL);
  9054. ColorItem->Color = C;
  9055. NonVisualDataModule->ColorMenuItem->Color = C;
  9056. UpdateControls();
  9057. }
  9058. //---------------------------------------------------------------------------
  9059. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  9060. {
  9061. if (value != FSessionColor)
  9062. {
  9063. UpdateSessionColor(value);
  9064. // Is null when called from LastTerminalClosed
  9065. if (Terminal != NULL)
  9066. {
  9067. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  9068. }
  9069. }
  9070. }
  9071. //---------------------------------------------------------------------------
  9072. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  9073. {
  9074. bool Result = FNoteTimer->Enabled;
  9075. if (Result)
  9076. {
  9077. // cannot cancel note too early
  9078. bool NotEarly =
  9079. (Now() - FNoteShown >
  9080. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  9081. if (Force || NotEarly)
  9082. {
  9083. FNoteTimer->Enabled = false;
  9084. FNote = L"";
  9085. SAFE_DESTROY(FNoteData);
  9086. FOnNoteClick = NULL;
  9087. FNoteHints = FNotes->Text;
  9088. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  9089. UpdateStatusBar();
  9090. }
  9091. }
  9092. return Result;
  9093. }
  9094. //---------------------------------------------------------------------------
  9095. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  9096. {
  9097. DebugAssert(FNoteTimer->Enabled);
  9098. CancelNote(true);
  9099. }
  9100. //---------------------------------------------------------------------------
  9101. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  9102. {
  9103. FNoteHints = FNotes->Text.TrimRight();
  9104. }
  9105. //---------------------------------------------------------------------------
  9106. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  9107. {
  9108. int P = Note.Pos(L"\n");
  9109. if (P > 0)
  9110. {
  9111. Note.SetLength(P - 1);
  9112. }
  9113. FNotes->Add(FORMAT(L"[%s] %s",
  9114. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  9115. while (FNotes->Count > 10)
  9116. {
  9117. FNotes->Delete(0);
  9118. }
  9119. if (UpdateNow)
  9120. {
  9121. UpdateNoteHints();
  9122. UpdateStatusBar();
  9123. }
  9124. }
  9125. //---------------------------------------------------------------------------
  9126. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  9127. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  9128. {
  9129. int P = Note.Pos(L"\n");
  9130. if (P > 0)
  9131. {
  9132. Note.SetLength(P - 1);
  9133. }
  9134. UpdateNoteHints();
  9135. FNote = Note;
  9136. SAFE_DESTROY(FNoteData);
  9137. FNoteData = NoteData;
  9138. FOnNoteClick = OnNoteClick;
  9139. AddNote(Note, false);
  9140. UpdateStatusBar();
  9141. FNoteShown = Now();
  9142. FNoteTimer->Enabled = false;
  9143. if (Seconds == 0)
  9144. {
  9145. Seconds = WinConfiguration->NotificationsTimeout;
  9146. }
  9147. FNoteTimer->Interval = Seconds * MSecsPerSec;
  9148. FNoteTimer->Enabled = true;
  9149. }
  9150. //---------------------------------------------------------------------------
  9151. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  9152. {
  9153. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  9154. }
  9155. //---------------------------------------------------------------------------
  9156. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  9157. {
  9158. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  9159. {
  9160. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  9161. }
  9162. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  9163. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  9164. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  9165. 0, NULL, NULL);
  9166. }
  9167. //---------------------------------------------------------------------------
  9168. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  9169. {
  9170. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  9171. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  9172. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  9173. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  9174. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  9175. }
  9176. //---------------------------------------------------------------------------
  9177. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  9178. {
  9179. WinConfiguration->FormatSizeBytes = Style;
  9180. }
  9181. //---------------------------------------------------------------------------
  9182. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  9183. {
  9184. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  9185. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  9186. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  9187. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  9188. }
  9189. //---------------------------------------------------------------------------
  9190. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  9191. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  9192. {
  9193. if (Panel->Index == 0)
  9194. {
  9195. if (FOnNoteClick != NULL)
  9196. {
  9197. // prevent the user data from being freed by possible call
  9198. // to CancelNote or PostNote during call to OnNoteClick
  9199. std::unique_ptr<TObject> NoteData(FNoteData);
  9200. TNotifyEvent OnNoteClick = FOnNoteClick;
  9201. FNoteData = NULL;
  9202. // need to cancel the note as we are going to delete its user data
  9203. CancelNote(true);
  9204. OnNoteClick(NoteData.get());
  9205. }
  9206. }
  9207. if (HasActiveTerminal() &&
  9208. (Panel->Index >= Sender->Panels->Count - SessionPanelCount))
  9209. {
  9210. FileSystemInfo();
  9211. }
  9212. }
  9213. //---------------------------------------------------------------------------
  9214. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  9215. {
  9216. // workaround:
  9217. // 1) for unknown reason, disabling window, while minimized,
  9218. // prevents it from restoring, even if it was enabled again meanwhile
  9219. // 2) when disabling the main window, while another has focus
  9220. // minimize is no longer possible
  9221. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  9222. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  9223. // Shouldn't we use IsApplicationMinimized() here?
  9224. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  9225. {
  9226. Enabled = false;
  9227. }
  9228. FLockLevel++;
  9229. }
  9230. //---------------------------------------------------------------------------
  9231. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  9232. {
  9233. DebugAssert(FLockLevel > 0);
  9234. FLockLevel--;
  9235. if (FLockLevel == 0)
  9236. {
  9237. DebugAssert(FLockSuspendLevel == 0);
  9238. Enabled = true;
  9239. }
  9240. }
  9241. //---------------------------------------------------------------------------
  9242. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  9243. {
  9244. // We need to make sure that window is enabled when the last modal window closes
  9245. // otherwise focus is not restored correctly.
  9246. // So we re-enable the window when modal window opens and
  9247. // disable it back after is closes
  9248. if (FLockLevel > 0)
  9249. {
  9250. // while we have nesting counter, we know that we never be called
  9251. // recursivelly as Application->OnModalBegin is called only
  9252. // for the top-level modal window
  9253. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9254. {
  9255. // won't be disabled when conditions in LockWindow() were not satisfied
  9256. FDisabledOnLockSuspend = !Enabled;
  9257. // When minimized to tray (or actually when set to SW_HIDE),
  9258. // setting Enabled makes the window focusable even when there's
  9259. // modal window over it
  9260. if (!FTrayIcon->Visible)
  9261. {
  9262. Enabled = true;
  9263. }
  9264. }
  9265. FLockSuspendLevel++;
  9266. }
  9267. }
  9268. //---------------------------------------------------------------------------
  9269. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  9270. {
  9271. if (FLockSuspendLevel > 0)
  9272. {
  9273. DebugAssert(FLockLevel > 0);
  9274. FLockSuspendLevel--;
  9275. // see comment in SuspendWindowLock
  9276. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9277. {
  9278. // Note that window can be enabled here, when we were minized to tray when
  9279. // was SuspendWindowLock() called.
  9280. // We should possibly do the same check as in LockWindow(),
  9281. // if it is ever possible that the consitions change between
  9282. // SuspendWindowLock() and ResumeWindowLock()
  9283. Enabled = !FDisabledOnLockSuspend;
  9284. }
  9285. }
  9286. }
  9287. //---------------------------------------------------------------------------
  9288. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9289. {
  9290. TTBXComboBoxItem * RemotePathComboBox =
  9291. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9292. if (!TextOnly)
  9293. {
  9294. TStrings * Items = RemotePathComboBox->Strings;
  9295. Items->BeginUpdate();
  9296. try
  9297. {
  9298. Items->Clear();
  9299. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9300. {
  9301. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9302. while (!IsUnixRootPath(APath))
  9303. {
  9304. int P = APath.LastDelimiter(L'/');
  9305. DebugAssert(P >= 0);
  9306. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9307. APath.SetLength(P - 1);
  9308. }
  9309. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9310. }
  9311. }
  9312. __finally
  9313. {
  9314. Items->EndUpdate();
  9315. }
  9316. }
  9317. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9318. // Setting ItemIndex to -1 does not reset its text
  9319. if (RemotePathComboBox->Strings->Count == 0)
  9320. {
  9321. RemotePathComboBox->Text = L"";
  9322. }
  9323. }
  9324. //---------------------------------------------------------------------------
  9325. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9326. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9327. {
  9328. if (AIndex < 0)
  9329. {
  9330. AIndex = Sender->ItemIndex;
  9331. }
  9332. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9333. }
  9334. //---------------------------------------------------------------------------
  9335. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9336. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9337. int & ImageIndex)
  9338. {
  9339. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9340. }
  9341. //---------------------------------------------------------------------------
  9342. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9343. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9344. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9345. {
  9346. if (!IsLocalBrowserMode())
  9347. {
  9348. ARect.Left += (10 * AIndex);
  9349. }
  9350. }
  9351. //---------------------------------------------------------------------------
  9352. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9353. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9354. {
  9355. AWidth += (10 * AIndex);
  9356. }
  9357. //---------------------------------------------------------------------------
  9358. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9359. {
  9360. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9361. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9362. int Index = RemotePathComboBox->ItemIndex;
  9363. while (Index < RemotePathComboBox->Strings->Count - 1)
  9364. {
  9365. APath = UnixExtractFileDir(APath);
  9366. Index++;
  9367. }
  9368. // VanDyke style paths
  9369. if (APath.IsEmpty())
  9370. {
  9371. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9372. APath = ROOTDIRECTORY;
  9373. }
  9374. if (RemoteDirView->Path != APath)
  9375. {
  9376. RemoteDirView->Path = APath;
  9377. }
  9378. }
  9379. //---------------------------------------------------------------------------
  9380. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9381. {
  9382. DoRemotePathComboBoxItemClick(Sender);
  9383. }
  9384. //---------------------------------------------------------------------------
  9385. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9386. {
  9387. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9388. DebugUsedParam(Sender);
  9389. UpdateRemotePathComboBox(true);
  9390. }
  9391. //---------------------------------------------------------------------------
  9392. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9393. {
  9394. DoRemotePathComboBoxCancel(Sender);
  9395. }
  9396. //---------------------------------------------------------------------------
  9397. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9398. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9399. {
  9400. ResetIncrementalSearch();
  9401. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9402. DebugAssert(DirView != NULL);
  9403. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9404. {
  9405. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9406. // OnEditing is called also from TCustomListView::CanEdit
  9407. if (Edit != NULL)
  9408. {
  9409. EditSelectBaseName(Edit);
  9410. }
  9411. }
  9412. }
  9413. //---------------------------------------------------------------------------
  9414. //---------------------------------------------------------------------------
  9415. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9416. {
  9417. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9418. Result->AutoDetectDnD = false;
  9419. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9420. Result->RenderDataOn = rdoEnterAndDropSync;
  9421. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9422. return Result;
  9423. }
  9424. //---------------------------------------------------------------------------
  9425. void __fastcall TCustomScpExplorerForm::UpdateDarkMode()
  9426. {
  9427. if (IsWin10Build(2004))
  9428. {
  9429. FImmersiveDarkMode = WinConfiguration->UseDarkTheme();
  9430. BOOL DarkMode = FImmersiveDarkMode ? TRUE : FALSE;
  9431. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9432. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9433. }
  9434. }
  9435. //---------------------------------------------------------------------------
  9436. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9437. {
  9438. TForm::CreateWnd();
  9439. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9440. UpdateDarkMode();
  9441. if (FSessionsDragDropFilesEx == NULL)
  9442. {
  9443. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9444. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9445. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9446. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9447. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9448. }
  9449. if (FQueueDragDropFilesEx == NULL)
  9450. {
  9451. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9452. // No need to set OnDragOver as we do not have any restrictions
  9453. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9454. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9455. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9456. }
  9457. }
  9458. //---------------------------------------------------------------------------
  9459. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9460. {
  9461. TForm::DestroyWnd();
  9462. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9463. FQueueDragDropFilesEx->DragDropControl = NULL;
  9464. }
  9465. //---------------------------------------------------------------------------
  9466. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9467. {
  9468. SideEnter(FCurrentSide);
  9469. FEverShown = true;
  9470. }
  9471. //---------------------------------------------------------------------------
  9472. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9473. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9474. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9475. {
  9476. if (!NonVisualDataModule->Busy)
  9477. {
  9478. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9479. Configuration->Usage->Inc(L"FileFinds");
  9480. LockWindow(true);
  9481. NonVisualDataModule->StartBusy();
  9482. WinConfiguration->LockedInterface = true;
  9483. try
  9484. {
  9485. Terminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9486. }
  9487. __finally
  9488. {
  9489. WinConfiguration->LockedInterface = false;
  9490. NonVisualDataModule->EndBusy();
  9491. UnlockWindow();
  9492. }
  9493. }
  9494. }
  9495. //---------------------------------------------------------------------------
  9496. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9497. {
  9498. if (!NonVisualDataModule->Busy)
  9499. {
  9500. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9501. SetFocus();
  9502. RemoteDirView->Path = UnixExtractFilePath(Path);
  9503. UnicodeString FileName = UnixExtractFileName(Path);
  9504. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9505. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9506. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9507. if (Item == NULL)
  9508. {
  9509. ReloadDirectory(osRemote);
  9510. Item = RemoteDirView->FindFileItem(FileName);
  9511. }
  9512. if (Item != NULL)
  9513. {
  9514. RemoteDirView->ItemFocused = Item;
  9515. RemoteDirView->ItemFocused->MakeVisible(false);
  9516. RemoteDirView->SetFocus();
  9517. }
  9518. }
  9519. }
  9520. //---------------------------------------------------------------------------
  9521. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9522. {
  9523. bool Result = !NonVisualDataModule->Busy;
  9524. if (Result)
  9525. {
  9526. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9527. }
  9528. return Result;
  9529. }
  9530. //---------------------------------------------------------------------------
  9531. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9532. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9533. {
  9534. if (CanOperateOnFoundFiles(ATerminal))
  9535. {
  9536. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9537. FOnFileOperationFinished = OnFileOperationFinished;
  9538. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9539. }
  9540. }
  9541. //---------------------------------------------------------------------------
  9542. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9543. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9544. {
  9545. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9546. }
  9547. //---------------------------------------------------------------------------
  9548. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9549. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9550. {
  9551. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9552. }
  9553. //---------------------------------------------------------------------------
  9554. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9555. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9556. {
  9557. if (CanOperateOnFoundFiles(ATerminal))
  9558. {
  9559. for (int Index = 0; Index < FileList->Count; Index++)
  9560. {
  9561. UnicodeString FileName = FileList->Strings[Index];
  9562. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9563. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9564. OnFileOperationFinished(osRemote, FileName, true);
  9565. }
  9566. }
  9567. }
  9568. //---------------------------------------------------------------------------
  9569. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9570. {
  9571. FFileFindTerminal = Terminal;
  9572. ShowFileFindDialog(
  9573. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9574. DoDownloadFoundFiles, DoEditFoundFiles);
  9575. }
  9576. //---------------------------------------------------------------------------
  9577. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9578. {
  9579. FTaskbarList = TaskbarList;
  9580. }
  9581. //---------------------------------------------------------------------------
  9582. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9583. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9584. {
  9585. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9586. if (Index >= 0)
  9587. {
  9588. if (Button == mbLeft)
  9589. {
  9590. // WORKAROUND: "Mouse down" is raised only after tab is switched.
  9591. // If switching tab (switching session) takes long enough for user
  9592. // to actually release the button, "mouse down" is still raised,
  9593. // but we do not get "mouse up" event, so dragging is not cancelled,
  9594. // prevent that by not beginning dragging in the first place.
  9595. if (IsKeyPressed(VK_LBUTTON))
  9596. {
  9597. // when user clicks the "+", we get mouse down only after the session
  9598. // is closed, when new session tab is already on X:Y, so dragging
  9599. // starts, prevent that
  9600. if (MilliSecondsBetween(Now(), FSessionsPageControlNewTabTime) > 500)
  9601. {
  9602. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9603. if (Terminal != NULL)
  9604. {
  9605. SessionsPageControl->BeginDrag(false);
  9606. }
  9607. }
  9608. }
  9609. }
  9610. else if (Button == mbMiddle)
  9611. {
  9612. // ignore middle-click for "New session tab" and the last local-local tab
  9613. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9614. if ((Session != NULL) && CanCloseSession(Session))
  9615. {
  9616. CloseSessionTab(Index);
  9617. }
  9618. }
  9619. }
  9620. }
  9621. //---------------------------------------------------------------------------
  9622. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9623. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9624. {
  9625. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9626. // do not allow dropping on the "+" tab
  9627. TTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9628. if ((TargetTerminal != NULL) &&
  9629. (SessionsPageControl->ActivePage->PageIndex != Index))
  9630. {
  9631. Configuration->Usage->Inc(L"SessionTabMoves");
  9632. // this is almost redundant as we would recreate tabs in SessionListChanged,
  9633. // but we want to actually prevent that to avoid flicker
  9634. SessionsPageControl->ActivePage->PageIndex = Index;
  9635. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->ActivePage);
  9636. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9637. }
  9638. }
  9639. //---------------------------------------------------------------------------
  9640. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9641. TObject * Sender, TObject * Source, int X, int Y,
  9642. TDragState /*State*/, bool & Accept)
  9643. {
  9644. Accept = (Sender == Source);
  9645. if (Accept)
  9646. {
  9647. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9648. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9649. // do not allow dragging to the "+" tab
  9650. Accept = (Terminal != NULL);
  9651. }
  9652. }
  9653. //---------------------------------------------------------------------------
  9654. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9655. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9656. {
  9657. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9658. if (Index < 0)
  9659. {
  9660. Effect = DROPEFFECT_NONE;
  9661. }
  9662. else
  9663. {
  9664. TManagedTerminal * TargetSession = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9665. // do not allow dropping on the "+" tab or on disconnected or local-local tabs
  9666. if (!IsActiveTerminal(TargetSession) || DebugAlwaysFalse(TargetSession->LocalBrowser))
  9667. {
  9668. Effect = DROPEFFECT_NONE;
  9669. }
  9670. else if ((TargetSession != Terminal) && (Effect == DROPEFFECT_MOVE))
  9671. {
  9672. Effect = DROPEFFECT_COPY;
  9673. }
  9674. }
  9675. }
  9676. //---------------------------------------------------------------------------
  9677. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9678. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9679. {
  9680. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9681. // do not allow dropping on local-local, disconnected and the "+" tab
  9682. // (though we do not seem to get here in that case anyway, contrary to RemoteFileControlDDTargetDrop)
  9683. TManagedTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9684. if (DebugAlwaysTrue(IsActiveTerminal(TargetTerminal) && !TargetTerminal->LocalBrowser))
  9685. {
  9686. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9687. if (!IsFileControl(DropSourceControl, osRemote))
  9688. {
  9689. TTerminalManager::Instance()->ActiveSession = TargetTerminal;
  9690. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9691. // Why don't we use Terminal->CurrentDirectory directly?
  9692. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9693. // do not force queue, drag drop
  9694. false, true);
  9695. }
  9696. }
  9697. }
  9698. //---------------------------------------------------------------------------
  9699. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9700. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9701. {
  9702. // Downloads are handled in RemoteFileControlDDEnd
  9703. if (!IsFileControl(DropSourceControl, osRemote))
  9704. {
  9705. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9706. Terminal->CurrentDirectory,
  9707. // force queue, drag drop
  9708. true, true);
  9709. }
  9710. }
  9711. //---------------------------------------------------------------------------
  9712. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9713. {
  9714. FShowing = false;
  9715. // Do not save empty workspace
  9716. if (WinConfiguration->AutoSaveWorkspace && (ManagedSession != NULL))
  9717. {
  9718. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9719. UnicodeString Name = WorkspaceName();
  9720. DoSaveWorkspace(
  9721. Name, DataList.get(),
  9722. !Configuration->DisablePasswordStoring &&
  9723. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9724. WinConfiguration->LastStoredSession = Name;
  9725. }
  9726. }
  9727. //---------------------------------------------------------------------------
  9728. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9729. {
  9730. TManagedTerminal * ManagedTerminal =
  9731. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9732. if (ManagedTerminal != NULL)
  9733. {
  9734. ManagedTerminal->DirectoryLoaded = Now();
  9735. }
  9736. }
  9737. //---------------------------------------------------------------------------
  9738. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9739. TListItem * /*Item*/, bool /*Selected*/)
  9740. {
  9741. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9742. switch (DirView->LastSelectMethod)
  9743. {
  9744. case smKeyboard:
  9745. Configuration->Usage->Inc(L"KeyboardSelections");
  9746. break;
  9747. case smMouse:
  9748. Configuration->Usage->Inc(L"MouseSelections");
  9749. break;
  9750. }
  9751. }
  9752. //---------------------------------------------------------------------------
  9753. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9754. {
  9755. if (Color != 0)
  9756. {
  9757. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9758. }
  9759. else
  9760. {
  9761. return FSessionTabImageIndex;
  9762. }
  9763. }
  9764. //---------------------------------------------------------------------------
  9765. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9766. {
  9767. TPngImageCollectionItem * Item =
  9768. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9769. FSessionColors->AddPng(Item->PngImage);
  9770. return FSessionColors->Count - 1;
  9771. }
  9772. //---------------------------------------------------------------------------
  9773. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9774. {
  9775. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9776. FNewRemoteTabTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewRemoteTabAction->ImageIndex);
  9777. FNewLocalTabTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewLocalTabAction->ImageIndex);
  9778. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9779. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9780. FLocalBrowserTabImageIndex = AddFixedSessionImage(LocalBrowserImageIndex);
  9781. }
  9782. //---------------------------------------------------------------------------
  9783. int TCustomScpExplorerForm::GetNewTabActionImageIndex()
  9784. {
  9785. return NonVisualDataModule->NewRemoteTabAction->ImageIndex;
  9786. }
  9787. //---------------------------------------------------------------------------
  9788. int TCustomScpExplorerForm::GetNewTabTabImageIndex(TOperationSide Side)
  9789. {
  9790. switch (Side)
  9791. {
  9792. case osLocal:
  9793. return FNewLocalTabTabImageIndex;
  9794. case osRemote:
  9795. case osCurrent:
  9796. return FNewRemoteTabTabImageIndex;
  9797. default:
  9798. DebugFail();
  9799. return -1;
  9800. }
  9801. }
  9802. //---------------------------------------------------------------------------
  9803. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9804. {
  9805. for (int Index = 0; Index < Control->ControlCount; Index++)
  9806. {
  9807. TControl * AControl = Control->Controls[Index];
  9808. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9809. if (WinControl != NULL)
  9810. {
  9811. CollectItemsWithTextDisplayMode(WinControl);
  9812. }
  9813. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9814. if (Toolbar != NULL)
  9815. {
  9816. // we care for top-level items only
  9817. TTBCustomItem * Items = Toolbar->Items;
  9818. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9819. {
  9820. TTBCustomItem * Item = Items->Items[ItemIndex];
  9821. if (((Item->DisplayMode == nbdmImageAndText) ||
  9822. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9823. EligibleForImageDisplayMode(Item))
  9824. {
  9825. FItemsWithTextDisplayMode.insert(Item);
  9826. }
  9827. }
  9828. }
  9829. }
  9830. }
  9831. //---------------------------------------------------------------------------
  9832. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9833. {
  9834. return true;
  9835. }
  9836. //---------------------------------------------------------------------------
  9837. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9838. {
  9839. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9840. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9841. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9842. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9843. bool Result = true;
  9844. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9845. {
  9846. TTBCustomItem * Item = *i;
  9847. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9848. if (Label != NULL)
  9849. {
  9850. // optimization
  9851. if (Label->Visible == SelectiveToolbarText)
  9852. {
  9853. Result = false;
  9854. }
  9855. else
  9856. {
  9857. Label->Visible = SelectiveToolbarText;
  9858. }
  9859. }
  9860. else
  9861. {
  9862. // optimization
  9863. if (Item->DisplayMode == DisplayMode)
  9864. {
  9865. Result = false;
  9866. }
  9867. else
  9868. {
  9869. Item->DisplayMode = DisplayMode;
  9870. }
  9871. }
  9872. ++i;
  9873. }
  9874. UpdateNewTabTab();
  9875. return Result;
  9876. }
  9877. //---------------------------------------------------------------------------
  9878. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9879. {
  9880. DebugFail();
  9881. }
  9882. //---------------------------------------------------------------------------
  9883. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9884. {
  9885. // Among other, a lock level is non zero, while directory is being loaded,
  9886. // even when it happens as a result of dirview navigation,
  9887. // i.e. when TNonVisualDataModule is NOT FBusy.
  9888. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9889. // Among other this prevents a panel auto update to occur while
  9890. // directory is changing.
  9891. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9892. }
  9893. //---------------------------------------------------------------------------
  9894. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  9895. {
  9896. // While the window is disabled, we still seem to process menu shortcuts at least,
  9897. // so stop it at least here.
  9898. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9899. bool Result;
  9900. if (Allowed == aaUpdate)
  9901. {
  9902. Result = true;
  9903. }
  9904. else
  9905. {
  9906. Result = !NonVisualDataModule->Busy;
  9907. if (Result && (Allowed == aaShortCut))
  9908. {
  9909. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  9910. Action->Update();
  9911. Result = Action->Enabled;
  9912. }
  9913. }
  9914. return Result;
  9915. }
  9916. //---------------------------------------------------------------------------
  9917. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9918. {
  9919. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9920. }
  9921. //---------------------------------------------------------------------------
  9922. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9923. {
  9924. // This is somewhat redundant to LockWindow() call from
  9925. // TTerminalManager::TerminalReadDirectoryProgress.
  9926. // But disabling window is known not to block keyboard shorcuts
  9927. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9928. if (Busy > 0)
  9929. {
  9930. if (NonVisualDataModule->Busy)
  9931. {
  9932. State = false;
  9933. }
  9934. else
  9935. {
  9936. NonVisualDataModule->StartBusy();
  9937. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9938. LockWindow();
  9939. }
  9940. }
  9941. else if (Busy < 0)
  9942. {
  9943. UnlockWindow();
  9944. NonVisualDataModule->EndBusy();
  9945. }
  9946. else
  9947. {
  9948. State = NonVisualDataModule->Busy;
  9949. }
  9950. }
  9951. //---------------------------------------------------------------------------
  9952. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9953. {
  9954. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9955. if (Index >= 0)
  9956. {
  9957. TPopupMenu * PopupMenu = NULL;
  9958. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9959. if (Session != NULL)
  9960. {
  9961. SessionsPageControl->ActivePageIndex = Index;
  9962. if (DebugAlwaysTrue(SessionTabSwitched()))
  9963. {
  9964. // copied from TControl.WMContextMenu
  9965. SendCancelMode(SessionsPageControl);
  9966. // explicit popup instead of using PopupMenu property
  9967. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9968. // while connecting yet not-connected session and hence
  9969. // allowing an access to commands over not-completelly connected session
  9970. PopupMenu = Session->LocalBrowser ? NonVisualDataModule->LocalBrowserPopup : NonVisualDataModule->SessionsPopup;
  9971. }
  9972. }
  9973. else
  9974. {
  9975. if (SupportsLocalBrowser())
  9976. {
  9977. PopupMenu = NonVisualDataModule->NewTabPopup;
  9978. }
  9979. }
  9980. if (PopupMenu != NULL)
  9981. {
  9982. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9983. PopupMenu->PopupComponent = SessionsPageControl;
  9984. PopupMenu->Popup(Point.x, Point.y);
  9985. }
  9986. }
  9987. Handled = true;
  9988. }
  9989. //---------------------------------------------------------------------------
  9990. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9991. {
  9992. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9993. }
  9994. //---------------------------------------------------------------------------
  9995. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9996. {
  9997. Configuration->Usage->Inc(L"PasswordChanges");
  9998. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9999. ChangePasswordData->DisableAuthentationsExceptPassword();
  10000. ChangePasswordData->ChangePassword = true;
  10001. std::unique_ptr<TTerminal> ChangePasswordSession(
  10002. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  10003. ChangePasswordSession->AutoReadDirectory = false;
  10004. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  10005. {
  10006. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  10007. }
  10008. else
  10009. {
  10010. Configuration->Usage->Inc(L"PasswordChangesFailed");
  10011. }
  10012. }
  10013. //---------------------------------------------------------------------------
  10014. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  10015. {
  10016. // No nice way to assert SSH2
  10017. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  10018. }
  10019. //---------------------------------------------------------------------------
  10020. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  10021. {
  10022. TOperationVisualizer OperationVisualizer;
  10023. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  10024. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  10025. }
  10026. //---------------------------------------------------------------------------
  10027. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  10028. {
  10029. TForm::ChangeScale(M, D);
  10030. int APixelsPerInch = GetControlPixelsPerInch(this);
  10031. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  10032. try
  10033. {
  10034. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  10035. }
  10036. __finally
  10037. {
  10038. GUIConfiguration->ChangeResourceModule(ResourceModule);
  10039. }
  10040. }
  10041. //---------------------------------------------------------------------------
  10042. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  10043. {
  10044. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  10045. }
  10046. //---------------------------------------------------------------------
  10047. class TPublicControl : public TControl
  10048. {
  10049. friend class TCustomScpExplorerForm;
  10050. };
  10051. //---------------------------------------------------------------------------
  10052. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  10053. {
  10054. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  10055. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  10056. }
  10057. //---------------------------------------------------------------------------
  10058. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  10059. {
  10060. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  10061. OpenBookmark(Side, Bookmark);
  10062. }
  10063. //---------------------------------------------------------------------------
  10064. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  10065. {
  10066. DoBookmarkClick(osLocal, Sender);
  10067. }
  10068. //---------------------------------------------------------------------------
  10069. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  10070. {
  10071. DoBookmarkClick(osRemote, Sender);
  10072. }
  10073. //---------------------------------------------------------------------------
  10074. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  10075. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  10076. {
  10077. if (BookmarkList != NULL)
  10078. {
  10079. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  10080. if (IsLocalBrowserMode())
  10081. {
  10082. Side = osLocal;
  10083. }
  10084. if (!WinConfiguration->UseLocationProfiles)
  10085. {
  10086. std::unique_ptr<TStringList> Directories(new TStringList());
  10087. Directories->CaseSensitive = (Side == osRemote);
  10088. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10089. {
  10090. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10091. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  10092. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  10093. {
  10094. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  10095. Item->Caption = EscapeHotkey(Directory);
  10096. Item->ShortCut = Bookmark->ShortCut;
  10097. Item->OnClick = OnBookmarkClick;
  10098. Item->Tag = reinterpret_cast<int>(Bookmark);
  10099. Directories->Add(Directory);
  10100. Menu->Add(Item.release());
  10101. }
  10102. }
  10103. }
  10104. else
  10105. {
  10106. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  10107. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10108. {
  10109. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10110. if (!Bookmark->Node.IsEmpty())
  10111. {
  10112. Folders->Add(Bookmark->Node);
  10113. }
  10114. }
  10115. for (int Index = 0; Index < Folders->Count; Index++)
  10116. {
  10117. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  10118. Item->Caption = Folders->Strings[Index];
  10119. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  10120. Folders->Objects[Index] = Item.get();
  10121. Menu->Add(Item.release());
  10122. }
  10123. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10124. {
  10125. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10126. TTBCustomItem * Parent;
  10127. if (!Bookmark->Node.IsEmpty())
  10128. {
  10129. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  10130. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  10131. }
  10132. else
  10133. {
  10134. Parent = Menu;
  10135. }
  10136. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  10137. Item->Caption = Bookmark->Name;
  10138. Item->ShortCut = Bookmark->ShortCut;
  10139. Item->OnClick = OnBookmarkClick;
  10140. Item->Tag = reinterpret_cast<int>(Bookmark);
  10141. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  10142. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  10143. {
  10144. // No hint for location profiles that are actually mere "bookmarks"
  10145. }
  10146. else
  10147. {
  10148. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  10149. UnicodeString LongHint;
  10150. if (!Bookmark->Local.IsEmpty())
  10151. {
  10152. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  10153. }
  10154. if (!Bookmark->Remote.IsEmpty())
  10155. {
  10156. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  10157. }
  10158. AddToList(Hint, LongHint, L"|");
  10159. Item->Hint = Hint;
  10160. }
  10161. Parent->Add(Item.release());
  10162. }
  10163. }
  10164. AddMenuSeparator(Menu);
  10165. }
  10166. }
  10167. //---------------------------------------------------------------------------
  10168. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  10169. {
  10170. Menu->Clear();
  10171. std::unique_ptr<TTBCustomItem> Item;
  10172. Item.reset(new TTBXItem(Owner));
  10173. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  10174. Item->Options = Item->Options << tboDefault;
  10175. Menu->Add(Item.release());
  10176. AddMenuSeparator(Menu);
  10177. if (Terminal != NULL)
  10178. {
  10179. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  10180. }
  10181. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  10182. Item.reset(new TTBXItem(Owner));
  10183. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  10184. Menu->Add(Item.release());
  10185. }
  10186. //---------------------------------------------------------------------------
  10187. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  10188. {
  10189. bool Result = true;
  10190. bool Remote = !IsSideLocalBrowser(Side);
  10191. try
  10192. {
  10193. if (Remote)
  10194. {
  10195. Terminal->ExceptionOnFail = true;
  10196. }
  10197. try
  10198. {
  10199. DirView(Side)->Path = Path;
  10200. }
  10201. __finally
  10202. {
  10203. if (Remote)
  10204. {
  10205. Terminal->ExceptionOnFail = false;
  10206. }
  10207. }
  10208. }
  10209. catch (Exception & E)
  10210. {
  10211. if (!Remote || Terminal->Active)
  10212. {
  10213. ShowExtendedExceptionEx(Terminal, &E);
  10214. Result = false;
  10215. }
  10216. else
  10217. {
  10218. throw;
  10219. }
  10220. }
  10221. return Result;
  10222. }
  10223. //---------------------------------------------------------------------------
  10224. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  10225. {
  10226. // Make sure there some feedback even when loading tiny local folders
  10227. TInstantOperationVisualizer Visualizer;
  10228. DirView(Side)->ReloadDirectory();
  10229. }
  10230. //---------------------------------------------------------------------------
  10231. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  10232. {
  10233. if (Index == SessionsPageControl->TabIndex)
  10234. {
  10235. CloseSession();
  10236. }
  10237. else
  10238. {
  10239. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  10240. TTerminal * Terminal = GetSessionTabSession(TabSheet);
  10241. TTerminalManager * Manager = TTerminalManager::Instance();
  10242. if (!Terminal->Active)
  10243. {
  10244. Manager->FreeTerminal(Terminal);
  10245. }
  10246. else
  10247. {
  10248. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  10249. if (CanCloseQueue(Queue))
  10250. {
  10251. Manager->FreeTerminal(Terminal);
  10252. }
  10253. }
  10254. }
  10255. }
  10256. //---------------------------------------------------------------------------
  10257. void __fastcall TCustomScpExplorerForm::SessionsPageControlTabButtonClick(TPageControl *, int Index)
  10258. {
  10259. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10260. if (Session == NULL)
  10261. {
  10262. TRect ButtonRect = SessionsPageControl->TabButtonRect(Index);
  10263. ButtonRect = TRect(SessionsPageControl->ClientToScreen(ButtonRect.TopLeft()), SessionsPageControl->ClientToScreen(ButtonRect.BottomRight()));
  10264. //TPoint P = TPoint(ButtonRect.Left, ButtonRect.Bottom);
  10265. //P = SessionsPageControl->ClientToScreen(P);
  10266. MenuPopup(NonVisualDataModule->NewTabPopup, ButtonRect, SessionsPageControl);
  10267. }
  10268. else
  10269. {
  10270. CloseSessionTab(Index);
  10271. }
  10272. }
  10273. //---------------------------------------------------------------------------
  10274. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  10275. {
  10276. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  10277. {
  10278. TInstantOperationVisualizer Visualizer;
  10279. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  10280. // before we create a new data object
  10281. ClipboardClear();
  10282. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  10283. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  10284. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  10285. // Intermediate variable to WORKAROUND a crash in compiler
  10286. TObjectList * ClipboardFakeMonitors =
  10287. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  10288. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  10289. if (FClipboardDragDropFilesEx.get() == NULL)
  10290. {
  10291. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  10292. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  10293. }
  10294. FClipboardDragDropFilesEx->FileList->Clear();
  10295. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  10296. FClipboardDragDropFilesEx->CopyToClipboard();
  10297. FClipboardTerminal = Terminal;
  10298. // Need full paths, as cwd can be different once files are pasted
  10299. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  10300. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  10301. {
  10302. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  10303. }
  10304. }
  10305. }
  10306. //---------------------------------------------------------------------------
  10307. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  10308. {
  10309. if (OpenClipboard(0))
  10310. {
  10311. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  10312. CloseClipboard();
  10313. }
  10314. }
  10315. //---------------------------------------------------------------------------
  10316. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  10317. {
  10318. return !FClipboardFakeDirectory.IsEmpty();
  10319. }
  10320. //---------------------------------------------------------------------------
  10321. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  10322. {
  10323. RemoveDir(ApiPath(FClipboardFakeDirectory));
  10324. FClipboardFakeDirectory = UnicodeString();
  10325. FClipboardTerminal = NULL;
  10326. if (FDownloadingFromClipboard)
  10327. {
  10328. // We are called by the monitor, so attempt to release it would deadlonk
  10329. FClipboardFakeMonitorsPendingReset = true;
  10330. }
  10331. else
  10332. {
  10333. FClipboardFakeMonitors.reset(NULL);
  10334. }
  10335. }
  10336. //---------------------------------------------------------------------------
  10337. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  10338. {
  10339. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  10340. {
  10341. ClipboardStop();
  10342. }
  10343. }
  10344. //---------------------------------------------------------------------------
  10345. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  10346. {
  10347. TTerminalManager * Manager = TTerminalManager::Instance();
  10348. Manager->ActiveSession = FClipboardTerminal;
  10349. TTransferOperationParam Params;
  10350. Params.TargetDirectory = TargetDirectory;
  10351. Params.DragDrop = DragDrop;
  10352. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  10353. }
  10354. //---------------------------------------------------------------------------
  10355. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  10356. {
  10357. // It can actually rarelly happen that some random file is created, while we are shutting down the monitor
  10358. // (as it pumps a Windows message queue while being shutted down)
  10359. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10360. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10361. {
  10362. // Can fail as it can be e.g. locked by AV, so we retry that later
  10363. bool Removed = RemoveDir(ApiPath(FileName));
  10364. try
  10365. {
  10366. if (!NonVisualDataModule->Busy)
  10367. {
  10368. DebugAssert(!FClipboardFakeMonitorsPendingReset);
  10369. FClipboardFakeMonitorsPendingReset = false;
  10370. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10371. TAutoFlag Flag(FDownloadingFromClipboard);
  10372. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  10373. }
  10374. }
  10375. __finally
  10376. {
  10377. if (!Removed)
  10378. {
  10379. RemoveDir(ApiPath(FileName));
  10380. }
  10381. }
  10382. }
  10383. }
  10384. //---------------------------------------------------------------------------
  10385. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10386. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10387. {
  10388. TFileMasks::TParams MaskParams;
  10389. MaskParams.Size = Size;
  10390. MaskParams.Modification = Modification;
  10391. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10392. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10393. {
  10394. bool ImplicitMatch;
  10395. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  10396. !ImplicitMatch)
  10397. {
  10398. Color = Iter->Color;
  10399. break;
  10400. }
  10401. }
  10402. }
  10403. //---------------------------------------------------------------------------
  10404. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10405. {
  10406. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10407. if (!DirView->IsEditing())
  10408. {
  10409. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10410. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10411. // while searching
  10412. if (Key == VK_BACK)
  10413. {
  10414. if (!FIncrementalSearch.IsEmpty())
  10415. {
  10416. if (FIncrementalSearch.Length() == 1)
  10417. {
  10418. ResetIncrementalSearch();
  10419. }
  10420. else
  10421. {
  10422. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10423. IncrementalSearch(NewText, false, false);
  10424. }
  10425. Key = 0;
  10426. }
  10427. }
  10428. }
  10429. }
  10430. //---------------------------------------------------------------------------
  10431. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10432. {
  10433. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10434. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10435. {
  10436. // Filter control sequences.
  10437. // When not searching yet, prefer use of the space for toggling file selection
  10438. // (so we cannot incrementally search for a string starting with a space).
  10439. if ((Key > VK_SPACE) ||
  10440. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10441. {
  10442. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10443. Key = 0;
  10444. }
  10445. }
  10446. }
  10447. //---------------------------------------------------------------------------
  10448. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10449. {
  10450. if (!FIncrementalSearch.IsEmpty())
  10451. {
  10452. FIncrementalSearch = L"";
  10453. DirView(osCurrent)->UpdateStatusBar();
  10454. }
  10455. }
  10456. //---------------------------------------------------------------------------
  10457. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10458. {
  10459. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10460. if (Item == NULL)
  10461. {
  10462. MessageBeep(MB_ICONHAND);
  10463. }
  10464. else
  10465. {
  10466. TCustomDirView * ADirView = DirView(osCurrent);
  10467. {
  10468. TAutoNestingCounter Guard(FIncrementalSearching);
  10469. ADirView->FocusItem(Item);
  10470. if (ADirView->NortonLike == nlOff)
  10471. {
  10472. if ((ADirView->Selected != Item) ||
  10473. (ADirView->SelCount > 1))
  10474. {
  10475. ADirView->ClearSelection();
  10476. ADirView->Selected = Item;
  10477. }
  10478. }
  10479. }
  10480. FIncrementalSearch = Text;
  10481. Item->MakeVisible(false);
  10482. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10483. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10484. ADirView->UpdateStatusBar();
  10485. }
  10486. }
  10487. //---------------------------------------------------------------------------
  10488. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10489. {
  10490. int Index = Item->Index;
  10491. if (!Reverse)
  10492. {
  10493. Index++;
  10494. if (Index >= Item->Owner->Count)
  10495. {
  10496. Index = 0;
  10497. }
  10498. }
  10499. else
  10500. {
  10501. Index--;
  10502. if (Index < 0)
  10503. {
  10504. Index = Item->Owner->Count - 1;
  10505. }
  10506. }
  10507. return Item->Owner->Item[Index];
  10508. }
  10509. //---------------------------------------------------------------------------
  10510. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10511. {
  10512. TCustomDirView * ADirView = DirView(osCurrent);
  10513. if (ADirView->Items->Count == 0)
  10514. {
  10515. return NULL;
  10516. }
  10517. else
  10518. {
  10519. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10520. TListItem * Item = CurrentItem;
  10521. if (SkipCurrent)
  10522. {
  10523. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10524. }
  10525. while (true)
  10526. {
  10527. bool Matches = false;
  10528. switch (WinConfiguration->PanelSearch)
  10529. {
  10530. case isNameStartOnly:
  10531. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10532. break;
  10533. case isName:
  10534. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10535. break;
  10536. case isAll:
  10537. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10538. int Index = 0;
  10539. while ((Index < ColCount) && !Matches)
  10540. {
  10541. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10542. if (Visible)
  10543. {
  10544. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10545. }
  10546. Index++;
  10547. }
  10548. break;
  10549. }
  10550. if (Matches)
  10551. {
  10552. return Item;
  10553. }
  10554. Item = GetNextFile(Item, Reverse);
  10555. if (Item == CurrentItem)
  10556. {
  10557. return NULL;
  10558. }
  10559. }
  10560. }
  10561. }
  10562. //---------------------------------------------------------------------------
  10563. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10564. {
  10565. ResetIncrementalSearch();
  10566. }
  10567. //---------------------------------------------------------------------------
  10568. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10569. {
  10570. if (Message.CharCode == VK_TAB)
  10571. {
  10572. if (!FIncrementalSearch.IsEmpty())
  10573. {
  10574. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10575. bool Reverse = Shift.Contains(ssShift);
  10576. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10577. Message.Result = 1;
  10578. return;
  10579. }
  10580. }
  10581. else if (Message.CharCode == VK_ESCAPE)
  10582. {
  10583. if (!FIncrementalSearch.IsEmpty())
  10584. {
  10585. ResetIncrementalSearch();
  10586. Message.Result = 1;
  10587. return;
  10588. }
  10589. }
  10590. TForm::Dispatch(&Message);
  10591. }
  10592. //---------------------------------------------------------------------------
  10593. void __fastcall TCustomScpExplorerForm::Deactivate()
  10594. {
  10595. TForm::Deactivate();
  10596. // E.g. when switching to an internal editor window
  10597. ResetIncrementalSearch();
  10598. }
  10599. //---------------------------------------------------------------------------
  10600. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10601. {
  10602. // When switching to another application
  10603. ResetIncrementalSearch();
  10604. }
  10605. //---------------------------------------------------------------------------
  10606. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10607. {
  10608. ResetIncrementalSearch();
  10609. }
  10610. //---------------------------------------------------------------------------
  10611. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10612. {
  10613. if (FIncrementalSearching <= 0)
  10614. {
  10615. ResetIncrementalSearch();
  10616. }
  10617. }
  10618. //---------------------------------------------------------------------------
  10619. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10620. {
  10621. CountClicksForWindowPrint(this);
  10622. }
  10623. //---------------------------------------------------------------------------
  10624. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10625. {
  10626. CenterReconnectToolbar();
  10627. }
  10628. //---------------------------------------------------------------------------
  10629. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10630. {
  10631. if (RemoteDirView->ItemFocused != NULL)
  10632. {
  10633. RemoteDirView->ItemFocused->Selected = true;
  10634. }
  10635. }
  10636. //---------------------------------------------------------------------------
  10637. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10638. {
  10639. if (!FQueueStatusUpdating)
  10640. {
  10641. bool Refresh;
  10642. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10643. {
  10644. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10645. }
  10646. else
  10647. {
  10648. if (FQueueFileList->GetCount() > 0)
  10649. {
  10650. FQueueFileList->Clear();
  10651. Refresh = true;
  10652. }
  10653. }
  10654. int Count = FQueueFileList->GetCount();
  10655. if (QueueFileList->Items->Count != Count)
  10656. {
  10657. DebugAssert(Refresh);
  10658. QueueFileList->Items->Count = Count;
  10659. }
  10660. if (Refresh)
  10661. {
  10662. QueueFileList->Invalidate();
  10663. }
  10664. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10665. }
  10666. }
  10667. //---------------------------------------------------------------------------
  10668. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10669. {
  10670. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10671. }
  10672. //---------------------------------------------------------------------------
  10673. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10674. {
  10675. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10676. // See TSynchronizeChecklistDialog::UpdateTimer
  10677. if (QueueFileList->Items->Count > 0)
  10678. {
  10679. QueueFileList->Items->Item[0]->MakeVisible(false);
  10680. }
  10681. UpdateQueueFileList();
  10682. }
  10683. //---------------------------------------------------------------------------
  10684. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10685. {
  10686. Active = QueueView3->Focused() || QueueFileList->Focused();
  10687. }
  10688. //---------------------------------------------------------------------------
  10689. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10690. {
  10691. QueueLabelUpdateStatus();
  10692. }
  10693. //---------------------------------------------------------------------------
  10694. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10695. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10696. {
  10697. int State = FQueueFileList->GetState(Item->Index);
  10698. if (State == qfsProcessed)
  10699. {
  10700. Sender->Canvas->Font->Color = clGrayText;
  10701. }
  10702. }
  10703. //---------------------------------------------------------------------------
  10704. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10705. {
  10706. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10707. QueueFileList->Column[0]->Width =
  10708. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10709. }
  10710. //---------------------------------------------------------------------------
  10711. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10712. {
  10713. QueueFileListColumnAutoSize();
  10714. }
  10715. //---------------------------------------------------------------------------
  10716. void __fastcall TCustomScpExplorerForm::CloseApp()
  10717. {
  10718. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10719. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10720. // So we clear the flag here.
  10721. DebugAssert(NonVisualDataModule->Busy);
  10722. NonVisualDataModule->EndBusy();
  10723. try
  10724. {
  10725. Close();
  10726. }
  10727. __finally
  10728. {
  10729. NonVisualDataModule->StartBusy();
  10730. }
  10731. }
  10732. //---------------------------------------------------------------------------
  10733. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10734. {
  10735. return (Terminal != NULL) && Terminal->Active;
  10736. }
  10737. //---------------------------------------------------------------------------
  10738. bool __fastcall TCustomScpExplorerForm::HasManagedSession()
  10739. {
  10740. return (ManagedSession != NULL);
  10741. }
  10742. //---------------------------------------------------------------------------
  10743. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10744. {
  10745. return IsActiveTerminal(Terminal);
  10746. }
  10747. //---------------------------------------------------------------------------
  10748. void TCustomScpExplorerForm::LocalLocalCopy(
  10749. TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused), bool DebugUsedArg(NoConfirmation),
  10750. bool DebugUsedArg(DragDrop), unsigned int DebugUsedArg(Flags))
  10751. {
  10752. DebugFail();
  10753. }
  10754. //---------------------------------------------------------------------------
  10755. void TCustomScpExplorerForm::LocalLocalCopyCommand(TFileOperation Operation, TOperationSide Side, bool OnFocused, unsigned int Flags)
  10756. {
  10757. LocalLocalCopy(Operation, Side, OnFocused, !WinConfiguration->ConfirmTransferring, false, Flags);
  10758. }
  10759. //---------------------------------------------------------------------------
  10760. void __fastcall TCustomScpExplorerForm::SessionsPageControlResize(TObject *)
  10761. {
  10762. // Changing tab list triggers the OnResize.
  10763. if (!FUpdatingSessionTabs)
  10764. {
  10765. // UpdateTabsCaptionTruncation should be enough
  10766. SessionListChanged(true);
  10767. }
  10768. }
  10769. //---------------------------------------------------------------------------
  10770. UnicodeString TCustomScpExplorerForm::GetSessionPath(TManagedTerminal * ASession, TOperationSide Side)
  10771. {
  10772. if (ASession == ManagedSession)
  10773. {
  10774. UpdateSession(ASession);
  10775. }
  10776. TSessionData * Data = ASession->StateData;
  10777. UnicodeString Result;
  10778. if (Side == osLocal)
  10779. {
  10780. Result = Data->LocalDirectory;
  10781. }
  10782. else if (DebugAlwaysTrue(Side == osOther))
  10783. {
  10784. Result = ASession->LocalBrowser ? Data->OtherLocalDirectory : Data->RemoteDirectory;
  10785. }
  10786. return Result;
  10787. }
  10788. //---------------------------------------------------------------------------
  10789. UnicodeString TCustomScpExplorerForm::GetTabHintDetails(TManagedTerminal * ASession)
  10790. {
  10791. UnicodeString Result;
  10792. if (!ASession->Active)
  10793. {
  10794. Result = LoadStr(STATUS_NOT_CONNECTED2);
  10795. }
  10796. else
  10797. {
  10798. Result = GetSessionPath(ASession, osRemote);
  10799. }
  10800. return Result;
  10801. }
  10802. //---------------------------------------------------------------------------
  10803. UnicodeString TCustomScpExplorerForm::GetNewTabHintDetails()
  10804. {
  10805. return LoadStr(NEW_REMOTE_TAB_HINT);
  10806. }
  10807. //---------------------------------------------------------------------------
  10808. void __fastcall TCustomScpExplorerForm::SessionsPageControlTabHint(TPageControl *, int Index, UnicodeString & Hint)
  10809. {
  10810. if (Index >= 0)
  10811. {
  10812. TThemeTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  10813. TManagedTerminal * TabSession = GetSessionTabSession(TabSheet);
  10814. if (TabSession == NULL)
  10815. {
  10816. UnicodeString NewTabTabCaption = GetNewTabTabCaption();
  10817. if (NewTabTabCaption != TabSheet->Caption)
  10818. {
  10819. Hint = NewTabTabCaption + L"|" + GetNewTabHintDetails();
  10820. }
  10821. }
  10822. else
  10823. {
  10824. TTerminalManager * Manager = TTerminalManager::Instance();
  10825. UnicodeString TabCaption = Manager->GetSessionTitle(TabSession, true);
  10826. Hint = TabCaption + L"|" + GetTabHintDetails(TabSession);
  10827. }
  10828. }
  10829. }
  10830. //---------------------------------------------------------------------------
  10831. typedef std::vector<TListItem *> TListItemsVector;
  10832. struct TCalculateSizeOperation
  10833. {
  10834. TCalculateSizeStats Stats;
  10835. TListItemsVector ListItems;
  10836. size_t Index;
  10837. };
  10838. //---------------------------------------------------------------------------
  10839. void TCustomScpExplorerForm::CalculateDirectorySizes()
  10840. {
  10841. TCalculateSizeOperation CalculateSizeOperation;
  10842. TOperationSide Side = GetSide(osCurrent);
  10843. TCustomDirView * ADirView = DirView(Side);
  10844. bool FullPath = IsSideLocalBrowser(Side);
  10845. std::unique_ptr<TStrings> AllFileList(ADirView->CreateFileList(false, FullPath, NULL, true));
  10846. std::unique_ptr<TStrings> FileList(new TStringList());
  10847. for (int Index = 0; Index < AllFileList->Count; Index++)
  10848. {
  10849. TListItem * Item = DebugNotNull(dynamic_cast<TListItem *>(AllFileList->Objects[Index]));
  10850. if (ADirView->ItemIsDirectory(Item))
  10851. {
  10852. FileList->AddObject(AllFileList->Strings[Index], ADirView->ItemData(Item));
  10853. CalculateSizeOperation.ListItems.push_back(Item);
  10854. }
  10855. }
  10856. CalculateSizeOperation.Index = 0;
  10857. __int64 Size = 0;
  10858. TValueRestorer<TCalculateSizeOperation *> DirectorySizeOperationRestorer(FCalculateSizeOperation);
  10859. FCalculateSizeOperation = &CalculateSizeOperation;
  10860. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  10861. FOnFileOperationFinished = DirectorySizeCalculated;
  10862. TValueRestorer<TFileOperation> PrimaryOperationRestorer(FPrimaryOperation);
  10863. FPrimaryOperation = foCalculateSize;
  10864. TCalculatedSizes CalculatedSizes;
  10865. CalculateSizeOperation.Stats.CalculatedSizes = &CalculatedSizes;
  10866. if (Side == osLocal)
  10867. {
  10868. Terminal->CalculateLocalFilesSize(FileList.get(), Size, NULL, true, NULL, &CalculatedSizes);
  10869. }
  10870. else
  10871. {
  10872. TCalculateSizeParams Params;
  10873. Params.Stats = &CalculateSizeOperation.Stats;
  10874. Params.UseCache = true;
  10875. Terminal->CalculateFilesSize(FileList.get(), Size, Params);
  10876. }
  10877. }
  10878. //---------------------------------------------------------------------------
  10879. void __fastcall TCustomScpExplorerForm::DirectorySizeCalculated(TOperationSide Side, const UnicodeString & FileName, bool)
  10880. {
  10881. DebugAlwaysTrue(FCalculateSizeOperation != NULL);
  10882. TListItem * Item = VisualiseOperationFinished(Side, FileName, false);
  10883. TCustomDirView * ADirView = dynamic_cast<TCustomDirView *>(Item->Owner->Owner);
  10884. // optimization
  10885. bool GotExpectedItem =
  10886. (FCalculateSizeOperation->Index < FCalculateSizeOperation->ListItems.size()) &&
  10887. (FCalculateSizeOperation->ListItems[FCalculateSizeOperation->Index] == Item);
  10888. int Index = -1;
  10889. if (DebugAlwaysTrue(GotExpectedItem))
  10890. {
  10891. Index = FCalculateSizeOperation->Index;
  10892. FCalculateSizeOperation->Index++;
  10893. }
  10894. else
  10895. {
  10896. TListItemsVector::iterator I =
  10897. std::find(FCalculateSizeOperation->ListItems.begin(), FCalculateSizeOperation->ListItems.end(), Item);
  10898. if (DebugAlwaysTrue(I != FCalculateSizeOperation->ListItems.end()))
  10899. {
  10900. Index = I - FCalculateSizeOperation->ListItems.begin();
  10901. }
  10902. }
  10903. if (DebugAlwaysTrue(Index >= 0))
  10904. {
  10905. __int64 Size = (*FCalculateSizeOperation->Stats.CalculatedSizes)[Index];
  10906. ADirView->SetItemCalculatedSize(Item, Size);
  10907. }
  10908. }