CustomScpExplorer.cpp 305 KB

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