CustomScpExplorer.cpp 295 KB

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