CustomScpExplorer.cpp 281 KB

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