CustomScpExplorer.cpp 289 KB

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