CustomScpExplorer.cpp 287 KB

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