CustomScpExplorer.cpp 264 KB

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