CustomScpExplorer.cpp 253 KB

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