CustomScpExplorer.cpp 305 KB

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