CustomScpExplorer.cpp 296 KB

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