CustomScpExplorer.cpp 364 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063
  1. //---------------------------------------------------------------------------
  2. #define NO_WIN32_LEAN_AND_MEAN
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <Common.h>
  6. #include "CustomScpExplorer.h"
  7. #include <Bookmarks.h>
  8. #include <Interface.h>
  9. #include <Exceptions.h>
  10. #include <CoreMain.h>
  11. #include <FileSystems.h>
  12. #include <TextsCore.h>
  13. #include <TextsWin.h>
  14. #include <HelpWin.h>
  15. #include <VCLCommon.h>
  16. #include <Progress.h>
  17. #include <SynchronizeProgress.h>
  18. #include <DragExt.h>
  19. #include <WinApi.h>
  20. #include "GUITools.h"
  21. #include "NonVisual.h"
  22. #include "Glyphs.h"
  23. #include "Tools.h"
  24. #include "WinConfiguration.h"
  25. #include "TerminalManager.h"
  26. #include "EditorManager.h"
  27. #include "ProgParams.h"
  28. #include "Setup.h"
  29. #include <Consts.hpp>
  30. #include <DateUtils.hpp>
  31. #include <TB2Common.hpp>
  32. #include <DirectoryMonitor.hpp>
  33. #include <System.IOUtils.hpp>
  34. //---------------------------------------------------------------------------
  35. #pragma package(smart_init)
  36. #pragma link "CustomDirView"
  37. #pragma link "CustomUnixDirView"
  38. #pragma link "IEListView"
  39. #pragma link "NortonLikeListView"
  40. #pragma link "UnixDirView"
  41. #pragma link "CustomDriveView"
  42. #pragma link "UnixDriveView"
  43. #pragma link "CustomDriveView"
  44. #pragma link "TB2Dock"
  45. #pragma link "TBXStatusBars"
  46. #pragma link "TB2Item"
  47. #pragma link "TB2Toolbar"
  48. #pragma link "ThemePageControl"
  49. #pragma link "PathLabel"
  50. #pragma resource "*.dfm"
  51. //---------------------------------------------------------------------------
  52. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  53. static const int SessionPanelCount = 3;
  54. //---------------------------------------------------------------------------
  55. class TMutexGuard
  56. {
  57. public:
  58. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  59. int Timeout = 5000)
  60. {
  61. FMutex = NULL;
  62. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  63. if (WaitResult == WAIT_TIMEOUT)
  64. {
  65. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  66. }
  67. else
  68. {
  69. FMutex = AMutex;
  70. }
  71. }
  72. ~TMutexGuard()
  73. {
  74. if (FMutex != NULL)
  75. {
  76. ReleaseMutex(FMutex);
  77. }
  78. }
  79. private:
  80. HANDLE FMutex;
  81. };
  82. //---------------------------------------------------------------------------
  83. class TWindowLock
  84. {
  85. public:
  86. TWindowLock(TCustomScpExplorerForm * Form) :
  87. FForm(Form)
  88. {
  89. FForm->LockWindow();
  90. }
  91. ~TWindowLock()
  92. {
  93. FForm->UnlockWindow();
  94. }
  95. private:
  96. TCustomScpExplorerForm * FForm;
  97. };
  98. //---------------------------------------------------------------------------
  99. TAutoBatch::TAutoBatch(TCustomScpExplorerForm * Form) :
  100. FForm(Form)
  101. {
  102. FForm->BatchStart(FBatchStorage);
  103. }
  104. //---------------------------------------------------------------------------
  105. TAutoBatch::~TAutoBatch()
  106. {
  107. FForm->BatchEnd(FBatchStorage);
  108. }
  109. //---------------------------------------------------------------------------
  110. struct TTransferOperationParam
  111. {
  112. TTransferOperationParam();
  113. UnicodeString TargetDirectory;
  114. bool Temp;
  115. bool DragDrop;
  116. int Options;
  117. TAutoSwitch Queue;
  118. };
  119. //---------------------------------------------------------------------------
  120. TTransferOperationParam::TTransferOperationParam()
  121. {
  122. Temp = false;
  123. DragDrop = false;
  124. Options = 0;
  125. Queue = asAuto;
  126. }
  127. //---------------------------------------------------------------------------
  128. class TTransferPresetNoteData : public TObject
  129. {
  130. public:
  131. UnicodeString Message;
  132. };
  133. //---------------------------------------------------------------------------
  134. class TTerminalNoteData : public TObject
  135. {
  136. public:
  137. TManagedTerminal * Terminal;
  138. };
  139. //---------------------------------------------------------------------------
  140. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  141. FFormRestored(false),
  142. TForm(Owner)
  143. {
  144. FInvalid = false;
  145. FCurrentSide = osRemote;
  146. FEverShown = false;
  147. FDocks = new TList();
  148. InitControls();
  149. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  150. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  151. NonVisualDataModule->ScpExplorer = this;
  152. RestoreParams();
  153. ConfigurationChanged();
  154. RemoteDirView->Invalidate();
  155. FAutoOperation = false;
  156. FOnFileOperationFinished = NULL;
  157. FForceExecution = false;
  158. FIgnoreNextDialogChar = 0;
  159. FErrorList = NULL;
  160. FSynchronizeProgressForm = NULL;
  161. FProgressForm = NULL;
  162. FRefreshLocalDirectory = false;
  163. FRefreshRemoteDirectory = false;
  164. FDDExtMapFile = NULL;
  165. // CreateMutexW keeps failing with ERROR_NOACCESS
  166. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  167. DebugAssert(FDDExtMutex != NULL);
  168. FDDTargetControl = NULL;
  169. FDelayedDeletionTimer = NULL;
  170. FDelayedDeletionList = new TStringList();
  171. FDDFileList = NULL;
  172. FPendingTempSpaceWarn = false;
  173. FCapturedLog = NULL;
  174. FDragDropOperation = false;
  175. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  176. FAllowTransferPresetAutoSelect = true;
  177. FCopyParamDefault = L"";
  178. FSynchronizeController = NULL;
  179. FPendingQueueActionItem = NULL;
  180. FLockLevel = 0;
  181. FLockSuspendLevel = 0;
  182. FDisabledOnLockSuspend = false;
  183. FAlternativeDelete = false;
  184. FTrayIcon = new ::TTrayIcon(0);
  185. FTrayIcon->OnClick = TrayIconClick;
  186. FMaxQueueLength = 0;
  187. FLastContextPopupScreenPoint = TPoint(-1, -1);
  188. FTransferResumeList = NULL;
  189. FMoveToQueue = false;
  190. FStandaloneEditing = false;
  191. FOnFeedSynchronizeError = NULL;
  192. FNeedSession = false;
  193. FDoNotIdleCurrentTerminal = 0;
  194. FIncrementalSearching = 0;
  195. FIncrementalSearchHaveNext = false;
  196. FQueueFileList.reset(new TQueueFileList());
  197. FProgressSide = osCurrent;
  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. FQueueStatusUpdating = false;
  209. FQueueActedItem = NULL;
  210. FQueueController = new TQueueController(QueueView3);
  211. FUserActionTimer = new TTimer(this);
  212. FUserActionTimer->Enabled = false;
  213. FUserActionTimer->Interval = 10;
  214. FUserActionTimer->OnTimer = UserActionTimer;
  215. FNotes = new TStringList();
  216. FNoteTimer = new TTimer(this);
  217. FNoteTimer->Enabled = false;
  218. FNoteTimer->OnTimer = NoteTimer;
  219. FOnNoteClick = NULL;
  220. FOle32Library = LoadLibrary(L"Ole32.dll");
  221. FDragMoveCursor = FOle32Library != NULL ?
  222. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  223. UseSystemSettings(this);
  224. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  225. static_cast<TObject*>(GetComponent(fcTransferList)));
  226. DebugAssert(TransferList != NULL);
  227. FTransferListHoverIndex = -1;
  228. TransferList->OnChange = TransferListChange;
  229. TransferList->OnDrawItem = TransferListDrawItem;
  230. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  231. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  232. UseDesktopFont(SessionsPageControl);
  233. UpdateSessionsPageControlHeight();
  234. UseDesktopFont(RemoteDirView);
  235. UseDesktopFont(RemoteDriveView);
  236. UseDesktopFont(QueueView3);
  237. UseDesktopFont(QueueFileList);
  238. UseDesktopFont(QueueLabel);
  239. UseDesktopFont(RemoteStatusBar);
  240. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  241. QueueSplitter->ShowHint = true;
  242. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  243. QueueFileListSplitter->ShowHint = true;
  244. RemotePanelSplitter->ShowHint = true;
  245. UpdateImages();
  246. FCustomCommandMenu = CreateTBXPopupMenu(this);
  247. FCustomCommandLocalFileList = NULL;
  248. FCustomCommandRemoteFileList = NULL;
  249. FSessionColors = new TPngImageList(this);
  250. FSessionColors->ColorDepth = cd32Bit;
  251. AddFixedSessionImages();
  252. SessionsPageControl->Images = FSessionColors;
  253. UpdateQueueLabel();
  254. CreateHiddenWindow();
  255. StartUpdates();
  256. }
  257. //---------------------------------------------------------------------------
  258. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  259. {
  260. FInvalid = true;
  261. // this has to be one of the very first things to do
  262. StopUpdateThread();
  263. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  264. TTerminalManager::Instance()->ScpExplorer = NULL;
  265. delete FCustomCommandLocalFileList;
  266. delete FCustomCommandRemoteFileList;
  267. delete FCustomCommandMenu;
  268. delete FTrayIcon;
  269. FTrayIcon = NULL;
  270. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  271. delete FEditorManager;
  272. ForceCloseLocalEditors();
  273. delete FLocalEditors;
  274. HideFileFindDialog();
  275. if (FDelayedDeletionTimer)
  276. {
  277. DoDelayedDeletion(NULL);
  278. SAFE_DESTROY(FDelayedDeletionTimer);
  279. }
  280. SAFE_DESTROY(FDelayedDeletionList);
  281. // sometimes we do not get DDEnd so the list is not released
  282. SAFE_DESTROY(FDDFileList);
  283. DebugAssert(FSynchronizeController == NULL);
  284. CloseHandle(FDDExtMutex);
  285. FDDExtMutex = NULL;
  286. FreeLibrary(FOle32Library);
  287. FOle32Library = NULL;
  288. FDragMoveCursor = NULL;
  289. DebugAssert(!FErrorList);
  290. if (FEverShown)
  291. {
  292. // when window is never shown (like when running command-line operation),
  293. // particularly window site is not restored correctly (BoundsRect value set
  294. // in RestoreForm gets lost during handle allocation), so we do not want
  295. // it to be stored
  296. StoreParams();
  297. }
  298. Terminal = NULL;
  299. Queue = NULL;
  300. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  301. NonVisualDataModule->ScpExplorer = NULL;
  302. delete FQueueController;
  303. FQueueController = NULL;
  304. delete FQueueStatusSection;
  305. FQueueStatusSection = NULL;
  306. delete FQueueStatus;
  307. FQueueStatus = NULL;
  308. delete FUserActionTimer;
  309. FUserActionTimer = NULL;
  310. delete FNoteTimer;
  311. delete FNotes;
  312. delete FNoteData;
  313. SAFE_DESTROY(FDocks);
  314. SessionsPageControl->Images = NULL;
  315. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  316. SAFE_DESTROY(FSessionColors);
  317. SAFE_DESTROY(FSessionsDragDropFilesEx);
  318. SAFE_DESTROY(FHistoryMenu[0][0]);
  319. SAFE_DESTROY(FHistoryMenu[0][1]);
  320. SAFE_DESTROY(FHistoryMenu[1][0]);
  321. SAFE_DESTROY(FHistoryMenu[1][1]);
  322. if (FHiddenWindow != NULL)
  323. {
  324. DestroyWindow(FHiddenWindow);
  325. FHiddenWindow = NULL;
  326. }
  327. }
  328. //---------------------------------------------------------------------------
  329. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  330. {
  331. std::unique_ptr<TSessionData> Data;
  332. if (!Session.IsEmpty())
  333. {
  334. bool DefaultsOnly;
  335. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  336. }
  337. TTerminalManager * Manager = TTerminalManager::Instance();
  338. for (int Index = 0; Index < Manager->Count; Index++)
  339. {
  340. TTerminal * Terminal = Manager->Terminals[Index];
  341. if (Session.IsEmpty() ||
  342. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  343. {
  344. if (Path.IsEmpty())
  345. {
  346. Terminal->ClearCaches();
  347. }
  348. else
  349. {
  350. Terminal->DirectoryModified(Path, true);
  351. }
  352. }
  353. }
  354. // We should flag a pending refresh for the background terminals or busy foreground terminals
  355. if (HasActiveTerminal() &&
  356. CanCommandLineFromAnotherInstance() &&
  357. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  358. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  359. {
  360. Terminal->ReloadDirectory();
  361. }
  362. }
  363. //---------------------------------------------------------------------------
  364. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  365. {
  366. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  367. size_t MessageSize = sizeof(TCopyDataMessage);
  368. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  369. if (Result)
  370. {
  371. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  372. Result = (Message.Version == TCopyDataMessage::Version1);
  373. if (Result)
  374. {
  375. switch (Message.Command)
  376. {
  377. case TCopyDataMessage::CommandCanCommandLine:
  378. Result = CanCommandLineFromAnotherInstance();
  379. break;
  380. case TCopyDataMessage::CommandCommandLine:
  381. {
  382. UnicodeString CommandLine(Message.CommandLine);
  383. Result = CommandLineFromAnotherInstance(CommandLine);
  384. }
  385. break;
  386. case TCopyDataMessage::RefreshPanel:
  387. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  388. break;
  389. case TCopyDataMessage::MainWindowCheck:
  390. Result = true;
  391. break;
  392. default:
  393. Result = false;
  394. break;
  395. }
  396. }
  397. }
  398. Message.Result = Result ? 1 : 0;
  399. }
  400. //---------------------------------------------------------------------------
  401. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  402. {
  403. WNDCLASS WindowClass = {0};
  404. WindowClass.lpfnWndProc = DefWindowProc;
  405. WindowClass.hInstance = HInstance;
  406. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  407. FHiddenWindow = NULL;
  408. if (RegisterClass(&WindowClass))
  409. {
  410. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  411. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  412. }
  413. }
  414. //---------------------------------------------------------------------------
  415. bool __fastcall TCustomScpExplorerForm::CanConsole()
  416. {
  417. return
  418. HasActiveTerminal() &&
  419. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  420. }
  421. //---------------------------------------------------------------------------
  422. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  423. {
  424. bool Result = Visible && !NonVisualDataModule->Busy;
  425. return Result;
  426. }
  427. //---------------------------------------------------------------------------
  428. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  429. const UnicodeString & CommandLine)
  430. {
  431. TProgramParams Params(CommandLine);
  432. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  433. if (Result)
  434. {
  435. NonVisualDataModule->StartBusy();
  436. try
  437. {
  438. // this action is initiated from another process,
  439. // so it's likely that our window is not visible,
  440. // and user won't see what is going on
  441. Application->BringToFront();
  442. // reload sessions as we may be asked to open a session
  443. // just stored by another instance
  444. StoredSessions->Reload();
  445. UnicodeString SessionName = Params.Param[1];
  446. std::unique_ptr<TObjectList> DataList(new TObjectList());
  447. UnicodeString DownloadFile; // unused
  448. try
  449. {
  450. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  451. }
  452. catch (EAbort &)
  453. {
  454. // Happens when opening session in PuTTY and in other situations,
  455. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  456. // to process the command-line on its own (or to pass it to yet another instance)
  457. }
  458. if (DataList->Count > 0)
  459. {
  460. TTerminalManager * Manager = TTerminalManager::Instance();
  461. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  462. }
  463. }
  464. __finally
  465. {
  466. NonVisualDataModule->EndBusy();
  467. }
  468. }
  469. return Result;
  470. }
  471. //---------------------------------------------------------------------------
  472. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  473. {
  474. if (FTerminal != value)
  475. {
  476. TerminalChanging();
  477. DoSetTerminal(value, false);
  478. }
  479. }
  480. //---------------------------------------------------------------------------
  481. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  482. {
  483. FTerminal = value;
  484. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  485. FAllowTransferPresetAutoSelect = false;
  486. try
  487. {
  488. TerminalChanged(Replace);
  489. }
  490. __finally
  491. {
  492. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  493. }
  494. if (Terminal != NULL)
  495. {
  496. TransferPresetAutoSelect();
  497. }
  498. }
  499. //---------------------------------------------------------------------------
  500. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  501. {
  502. DoSetTerminal(value, true);
  503. }
  504. //---------------------------------------------------------------------------
  505. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  506. {
  507. if (FTerminal != NULL)
  508. {
  509. UpdateTerminal(Terminal);
  510. }
  511. }
  512. //---------------------------------------------------------------------------
  513. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  514. {
  515. if (Terminal != NULL)
  516. {
  517. UpdateSessionColor((TColor)Terminal->StateData->Color);
  518. }
  519. DoTerminalListChanged();
  520. DebugAssert(!IsLocalBrowserMode());
  521. if (Replaced)
  522. {
  523. RemoteDirView->ReplaceTerminal(Terminal);
  524. }
  525. else
  526. {
  527. RemoteDirView->Terminal = Terminal;
  528. }
  529. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  530. if (Terminal != NULL)
  531. {
  532. if (Terminal->Active)
  533. {
  534. Terminal->RefreshDirectory();
  535. }
  536. if (WinConfiguration->PreservePanelState)
  537. {
  538. if (Terminal->RemoteExplorerState != NULL)
  539. {
  540. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  541. }
  542. else
  543. {
  544. DirView(osRemote)->ClearState();
  545. }
  546. }
  547. }
  548. InitStatusBar();
  549. UpdateTransferList();
  550. // Update panels Enable state before refreshing the labels
  551. UpdateControls();
  552. }
  553. //---------------------------------------------------------------------------
  554. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  555. {
  556. if (Queue != value)
  557. {
  558. if (FQueue != NULL)
  559. {
  560. FQueue->OnListUpdate = NULL;
  561. FQueue->OnQueueItemUpdate = NULL;
  562. }
  563. FQueue = value;
  564. if (FQueue != NULL)
  565. {
  566. DebugAssert(FQueue->OnListUpdate == NULL);
  567. FQueue->OnListUpdate = QueueListUpdate;
  568. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  569. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  570. }
  571. QueueChanged();
  572. }
  573. }
  574. //---------------------------------------------------------------------------
  575. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  576. TListItem * Item)
  577. {
  578. if (FQueueActedItem == Item)
  579. {
  580. FQueueActedItem = NULL;
  581. if ((QueueView3->PopupMenu != NULL) &&
  582. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  583. {
  584. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  585. ReleaseCapture();
  586. }
  587. }
  588. if (Item->Data == FPendingQueueActionItem)
  589. {
  590. FPendingQueueActionItem = NULL;
  591. }
  592. }
  593. //---------------------------------------------------------------------------
  594. bool TCustomScpExplorerForm::IsAnythingQueued()
  595. {
  596. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  597. }
  598. //---------------------------------------------------------------------------
  599. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  600. {
  601. {
  602. TGuard Guard(FQueueStatusSection);
  603. FQueueStatusInvalidated = false;
  604. if (FQueue != NULL)
  605. {
  606. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  607. }
  608. }
  609. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  610. {
  611. FMaxQueueLength = FQueueStatus->Count;
  612. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  613. }
  614. {
  615. TAutoFlag Flag(FQueueStatusUpdating);
  616. FQueueController->UpdateQueueStatus(FQueueStatus);
  617. }
  618. UpdateQueueFileList();
  619. SetQueueProgress();
  620. UpdateQueueView();
  621. bool IsEmpty = !IsAnythingQueued();
  622. if (IsEmpty && (Terminal != NULL))
  623. {
  624. TOnceDoneOperation OnceDoneOperation =
  625. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  626. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  627. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  628. {
  629. FQueue->Enabled = false;
  630. }
  631. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  632. {
  633. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  634. }
  635. }
  636. }
  637. //---------------------------------------------------------------------------
  638. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  639. {
  640. UnicodeString Result;
  641. if (FQueueStatus != NULL)
  642. {
  643. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  644. {
  645. TFileOperationProgressType * ProgressData =
  646. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  647. if ((ProgressData != NULL) && ProgressData->InProgress)
  648. {
  649. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  650. }
  651. }
  652. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  653. {
  654. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  655. }
  656. }
  657. return Result;
  658. }
  659. //---------------------------------------------------------------------------
  660. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  661. {
  662. ComponentVisible[fcQueueView] =
  663. (WinConfiguration->QueueView.Show == qvShow) ||
  664. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  665. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  666. }
  667. //---------------------------------------------------------------------------
  668. void __fastcall TCustomScpExplorerForm::QueueChanged()
  669. {
  670. if (FQueueStatus != NULL)
  671. {
  672. // UpdateFileList implementation relies on the status being recreated when session changes
  673. delete FQueueStatus;
  674. FQueueStatus = NULL;
  675. }
  676. UpdateQueueStatus(true);
  677. }
  678. //---------------------------------------------------------------------------
  679. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  680. {
  681. if (FQueue == Queue)
  682. {
  683. FQueueStatusInvalidated = true;
  684. }
  685. }
  686. //---------------------------------------------------------------------------
  687. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  688. TQueueItem * Item)
  689. {
  690. if (FQueue == Queue)
  691. {
  692. TGuard Guard(FQueueStatusSection);
  693. // this may be running in parallel with QueueChanged
  694. if (FQueueStatus != NULL)
  695. {
  696. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  697. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  698. {
  699. FRefreshLocalDirectory = (QueueItem == NULL) ||
  700. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  701. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  702. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  703. }
  704. if (QueueItem != NULL)
  705. {
  706. QueueItem->UserData = (void*)true;
  707. FQueueItemInvalidated = true;
  708. }
  709. }
  710. }
  711. }
  712. //---------------------------------------------------------------------------
  713. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  714. {
  715. // during standalone editing, we have no way to see/control queue,
  716. // so we have to always popup prompts automatically
  717. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  718. }
  719. //---------------------------------------------------------------------------
  720. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  721. {
  722. if (FQueueStatus != NULL)
  723. {
  724. bool QueueAutoPopup = IsQueueAutoPopup();
  725. bool NeedRefresh = FQueueController->NeedRefresh();
  726. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  727. FQueueItemInvalidated = false;
  728. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  729. bool Updated = false;
  730. TQueueItemProxy * QueueItem;
  731. bool WasUserAction;
  732. for (int Index = 0; Index < Limit; Index++)
  733. {
  734. bool Update = false;
  735. QueueItem = FQueueStatus->Items[Index];
  736. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  737. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  738. (FPendingQueueActionItem == NULL))
  739. {
  740. FPendingQueueActionItem = QueueItem;
  741. FUserActionTimer->Enabled = true;
  742. }
  743. if ((bool)QueueItem->UserData)
  744. {
  745. QueueItem->UserData = (void*)false;
  746. QueueItem->Update();
  747. Updated = true;
  748. Update = true;
  749. }
  750. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  751. {
  752. Update = true;
  753. }
  754. if (Update)
  755. {
  756. FQueueController->RefreshQueueItem(QueueItem);
  757. }
  758. }
  759. if (Updated)
  760. {
  761. NonVisualDataModule->UpdateNonVisibleActions();
  762. SetQueueProgress();
  763. UpdateQueueFileList();
  764. }
  765. }
  766. }
  767. //---------------------------------------------------------------------------
  768. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  769. {
  770. if (FTaskbarList != NULL)
  771. {
  772. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  773. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  774. }
  775. }
  776. //---------------------------------------------------------------------------
  777. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  778. {
  779. if (Progress >= 0)
  780. {
  781. if (FTaskbarList != NULL)
  782. {
  783. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  784. }
  785. }
  786. else
  787. {
  788. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  789. }
  790. }
  791. //---------------------------------------------------------------------------
  792. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  793. {
  794. int OverallProgress;
  795. // FProgressForm is null when this is called from SetQueueProgress
  796. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  797. {
  798. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  799. }
  800. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  801. {
  802. OverallProgress = ProgressData->OverallProgress();
  803. }
  804. else
  805. {
  806. OverallProgress = -1;
  807. }
  808. SetTaskbarListProgressValue(OverallProgress);
  809. }
  810. //---------------------------------------------------------------------------
  811. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  812. {
  813. TTerminalManager::Instance()->QueueStatusUpdated();
  814. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  815. {
  816. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  817. {
  818. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  819. {
  820. TFileOperationProgressType * ProgressData = NULL;
  821. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  822. {
  823. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  824. }
  825. if ((ProgressData != NULL) &&
  826. ProgressData->InProgress)
  827. {
  828. SetTaskbarListProgressValue(ProgressData);
  829. }
  830. else
  831. {
  832. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  833. }
  834. }
  835. else
  836. {
  837. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  838. }
  839. }
  840. else
  841. {
  842. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  843. }
  844. }
  845. UpdateQueueLabel();
  846. }
  847. //---------------------------------------------------------------------------
  848. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  849. {
  850. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  851. if (FQueueStatus != NULL)
  852. {
  853. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  854. if (ActiveAndPendingPrimaryCount > 0)
  855. {
  856. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  857. }
  858. }
  859. QueueLabel->Caption = Caption;
  860. }
  861. //---------------------------------------------------------------------------
  862. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  863. {
  864. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  865. static_cast<TComponent*>(GetComponent(fcTransferList)));
  866. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  867. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  868. TransferList->Strings->BeginUpdate();
  869. try
  870. {
  871. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  872. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  873. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  874. if (FTransferDropDownHint.IsEmpty())
  875. {
  876. FTransferDropDownHint = TransferDropDown->Hint;
  877. }
  878. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  879. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  880. TransferDropDown->Text = StripHotkey(Name);
  881. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  882. (FTransferDropDownHint, StripHotkey(Name),
  883. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  884. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  885. // update the label, otherwise when it is updated only on the first draw
  886. // of the list, it is drawn "bold" for some reason
  887. FTransferListHoverIndex = TransferList->ItemIndex;
  888. UpdateTransferLabel();
  889. }
  890. __finally
  891. {
  892. TransferList->Strings->EndUpdate();
  893. }
  894. }
  895. //---------------------------------------------------------------------------
  896. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  897. {
  898. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  899. DebugAssert(Toolbar != NULL);
  900. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  901. }
  902. //---------------------------------------------------------------------------
  903. void __fastcall TCustomScpExplorerForm::UpdateActions()
  904. {
  905. TForm::UpdateActions();
  906. if (ComponentVisible[fcCustomCommandsBand])
  907. {
  908. UpdateCustomCommandsToolbar();
  909. }
  910. }
  911. //---------------------------------------------------------------------------
  912. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  913. {
  914. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  915. }
  916. //---------------------------------------------------------------------------
  917. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  918. {
  919. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  920. {
  921. DirView->RowSelect = WinConfiguration->FullRowSelect;
  922. // selection is not redrawn automatically when RowSelect changes
  923. DirView->Invalidate();
  924. }
  925. }
  926. //---------------------------------------------------------------------------
  927. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  928. {
  929. Color = GetBtnFaceColor();
  930. DebugAssert(Configuration && RemoteDirView);
  931. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  932. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  933. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  934. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  935. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  936. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  937. UpdateRowSelect(RemoteDirView);
  938. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  939. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  940. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  941. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  942. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  943. UpdateSessionsPageControlHeight();
  944. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  945. UpdateToolbarDisplayMode();
  946. UpdateTransferList();
  947. if (Terminal != NULL)
  948. {
  949. TransferPresetAutoSelect();
  950. }
  951. UpdateQueueView();
  952. UpdateControls();
  953. // this can be called even before constuctor finishes.
  954. if (FEditorManager != NULL)
  955. {
  956. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  957. }
  958. // this can be called even before constuctor finishes.
  959. if (FLocalEditors != NULL)
  960. {
  961. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  962. {
  963. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  964. }
  965. }
  966. if (ComponentVisible[fcCustomCommandsBand])
  967. {
  968. UpdateCustomCommandsToolbar();
  969. }
  970. // show only when keeping queue items forever,
  971. // otherwise, its enough to have in in the context menu
  972. QueueDeleteAllDoneQueueToolbarItem->Visible =
  973. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  974. if (FFileColorsCurrent != WinConfiguration->FileColors)
  975. {
  976. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  977. FFileColorsCurrent = WinConfiguration->FileColors;
  978. FileColorsChanged();
  979. }
  980. }
  981. //---------------------------------------------------------------------------
  982. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  983. {
  984. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  985. DirView->Invalidate();
  986. }
  987. //---------------------------------------------------------------------------
  988. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  989. {
  990. DoFileColorsChanged(RemoteDirView);
  991. }
  992. //---------------------------------------------------------------------------
  993. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  994. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  995. void * /*Arg*/)
  996. {
  997. if (Token != NULL)
  998. {
  999. TForm * Editor = dynamic_cast<TForm*>(Token);
  1000. DebugAssert(Editor != NULL);
  1001. ReconfigureEditorForm(Editor);
  1002. }
  1003. }
  1004. //---------------------------------------------------------------------------
  1005. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1006. {
  1007. WinConfiguration->DDTransferConfirmation = asOn;
  1008. }
  1009. //---------------------------------------------------------------------------
  1010. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1011. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1012. {
  1013. // noop
  1014. }
  1015. //---------------------------------------------------------------------------
  1016. bool TCustomScpExplorerForm::GetDoNotShowCopyDialogDefault(bool DragDrop)
  1017. {
  1018. return DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto);
  1019. }
  1020. //---------------------------------------------------------------------------
  1021. void TCustomScpExplorerForm::HandleDoNotShowCopyDialogAgain(bool DragDrop, bool DoNotShowAgain)
  1022. {
  1023. if (DoNotShowAgain)
  1024. {
  1025. if (DragDrop)
  1026. {
  1027. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1028. {
  1029. PopupTrayBalloon(
  1030. NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation, NULL, 0, EnableDDTransferConfirmation, NULL);
  1031. }
  1032. WinConfiguration->DDTransferConfirmation = asOff;
  1033. }
  1034. else
  1035. {
  1036. WinConfiguration->ConfirmTransferring = false;
  1037. }
  1038. }
  1039. else
  1040. {
  1041. // User explicitly unchecked "do not show again",
  1042. // so show him the dialog the next time
  1043. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1044. {
  1045. WinConfiguration->DDTransferConfirmation = asOn;
  1046. }
  1047. }
  1048. }
  1049. //---------------------------------------------------------------------------
  1050. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1051. TTransferDirection Direction, TTransferType Type, bool Temp,
  1052. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1053. bool Confirm, bool DragDrop, int Options)
  1054. {
  1055. bool Result = true;
  1056. DebugAssert(HasActiveTerminal());
  1057. // these parameters are known in advance
  1058. int Params =
  1059. FLAGMASK(Type == ttMove, cpDelete);
  1060. bool ToTemp = (Temp && (Direction == tdToLocal));
  1061. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1062. {
  1063. bool DisableNewerOnly =
  1064. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1065. ToTemp;
  1066. Options |=
  1067. FLAGMASK(ToTemp, coTemp) |
  1068. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1069. coDoNotShowAgain;
  1070. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1071. int CopyParamAttrs = (Direction == tdToRemote ?
  1072. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1073. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1074. int OutputOptions = FLAGMASK(GetDoNotShowCopyDialogDefault(DragDrop), cooDoNotShowAgain);
  1075. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1076. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1077. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1078. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1079. if (Result)
  1080. {
  1081. HandleDoNotShowCopyDialogAgain(DragDrop, FLAGSET(OutputOptions, cooDoNotShowAgain));
  1082. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1083. }
  1084. }
  1085. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1086. {
  1087. Configuration->Usage->Inc(L"TransfersOnBackground");
  1088. // these parameter are known only after transfer dialog
  1089. Params |=
  1090. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1091. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1092. Result = false;
  1093. ClearTransferSourceSelection(Direction);
  1094. }
  1095. return Result;
  1096. }
  1097. //---------------------------------------------------------------------------
  1098. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1099. {
  1100. if (FOnFileOperationFinished != NULL)
  1101. {
  1102. FOnFileOperationFinished(UnicodeString(), true);
  1103. }
  1104. else
  1105. {
  1106. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1107. if (HasDirView[Side])
  1108. {
  1109. DirView(Side)->SelectAll(smNone);
  1110. }
  1111. }
  1112. }
  1113. //---------------------------------------------------------------------------
  1114. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1115. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1116. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1117. int Params)
  1118. {
  1119. DebugAssert(Queue != NULL);
  1120. bool SingleFile = false;
  1121. if (FileList->Count == 1)
  1122. {
  1123. if (Direction == tdToRemote)
  1124. {
  1125. UnicodeString FileName = FileList->Strings[0];
  1126. SingleFile = FileExists(ApiPath(FileName));
  1127. }
  1128. else
  1129. {
  1130. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1131. SingleFile = !File->IsDirectory;
  1132. }
  1133. }
  1134. TQueueItem * QueueItem;
  1135. if (Direction == tdToRemote)
  1136. {
  1137. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1138. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1139. }
  1140. else
  1141. {
  1142. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1143. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1144. }
  1145. AddQueueItem(Queue, QueueItem, Terminal);
  1146. }
  1147. //---------------------------------------------------------------------------
  1148. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1149. {
  1150. if (Queue->IsEmpty)
  1151. {
  1152. Terminal->QueueOperationStart = Now();
  1153. }
  1154. Queue->AddItem(QueueItem);
  1155. }
  1156. //---------------------------------------------------------------------------
  1157. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1158. {
  1159. }
  1160. //---------------------------------------------------------------------------
  1161. void __fastcall TCustomScpExplorerForm::InitControls()
  1162. {
  1163. DebugAssert(FDocks != NULL);
  1164. for (int Index = 0; Index < ComponentCount; Index++)
  1165. {
  1166. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1167. if ((Dock != NULL) && (Dock->Tag == 0))
  1168. {
  1169. FDocks->Add(Dock);
  1170. }
  1171. }
  1172. CollectItemsWithTextDisplayMode(this);
  1173. }
  1174. //---------------------------------------------------------------------------
  1175. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1176. {
  1177. ConfigurationChanged();
  1178. QueuePanel->Height =
  1179. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1180. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1181. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1182. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1183. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1184. QueueFileList->Height =
  1185. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1186. if (QueueFileList->Visible)
  1187. {
  1188. AdjustQueueLayout();
  1189. }
  1190. UpdateCustomCommandsToolbar();
  1191. }
  1192. //---------------------------------------------------------------------------
  1193. void __fastcall TCustomScpExplorerForm::StoreParams()
  1194. {
  1195. int APixelsPerInch = GetControlPixelsPerInch(this);
  1196. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1197. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1198. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1199. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1200. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1201. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1202. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1203. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1204. }
  1205. //---------------------------------------------------------------------------
  1206. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1207. {
  1208. if (!FFormRestored)
  1209. {
  1210. FFormRestored = true;
  1211. RestoreFormParams();
  1212. }
  1213. TForm::CreateParams(Params);
  1214. }
  1215. //---------------------------------------------------------------------------
  1216. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1217. {
  1218. DebugAssert(FDocks != NULL);
  1219. for (int Index = 0; Index < FDocks->Count; Index++)
  1220. {
  1221. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1222. }
  1223. }
  1224. //---------------------------------------------------------------------------
  1225. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1226. {
  1227. SetDockAllowDrag(true);
  1228. while (!ButtonsStr.IsEmpty())
  1229. {
  1230. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1231. UnicodeString Name = CutToChar(S, L'=', true);
  1232. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1233. {
  1234. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1235. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1236. {
  1237. while (!S.IsEmpty())
  1238. {
  1239. UnicodeString S2 = CutToChar(S, L',', true);
  1240. UnicodeString Name = CutToChar(S2, L':', true);
  1241. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1242. {
  1243. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1244. if (SameText(GetToolbarItemName(Item), Name))
  1245. {
  1246. // forward compatibility
  1247. UnicodeString S3 = CutToChar(S2, L':', true);
  1248. bool Visible = StrToIntDef(S3, 0);
  1249. Item->Visible = Visible;
  1250. }
  1251. }
  1252. }
  1253. }
  1254. }
  1255. }
  1256. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1257. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1258. }
  1259. //---------------------------------------------------------------------------
  1260. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1261. {
  1262. UnicodeString Result;
  1263. SetDockAllowDrag(true);
  1264. Result = ::GetToolbarsLayoutStr(this);
  1265. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1266. return Result;
  1267. }
  1268. //---------------------------------------------------------------------------
  1269. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1270. {
  1271. UnicodeString Result;
  1272. if (Item->Action != NULL)
  1273. {
  1274. Result = Item->Action->Name;
  1275. Result = RemoveSuffix(Result, L"Action", true);
  1276. }
  1277. else
  1278. {
  1279. Result = Item->Name;
  1280. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1281. Result = RemoveSuffix(Result, L"Item", true);
  1282. }
  1283. return Result;
  1284. }
  1285. //---------------------------------------------------------------------------
  1286. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1287. {
  1288. UnicodeString Result;
  1289. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1290. {
  1291. UnicodeString ToolbarStr;
  1292. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1293. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1294. {
  1295. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1296. {
  1297. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1298. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1299. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1300. // and save the changes here only.
  1301. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1302. {
  1303. UnicodeString Name = GetToolbarItemName(Item);
  1304. DebugAssert(Name.Pos(L"TBX") == 0);
  1305. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1306. }
  1307. }
  1308. }
  1309. if (!ToolbarStr.IsEmpty())
  1310. {
  1311. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1312. }
  1313. }
  1314. return Result;
  1315. }
  1316. //---------------------------------------------------------------------------
  1317. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1318. {
  1319. DebugAssert(FProgressForm == NULL);
  1320. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1321. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1322. FProgressForm->DeleteLocalToRecycleBin =
  1323. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1324. FProgressForm->DeleteRemoteToRecycleBin =
  1325. (Terminal != NULL) &&
  1326. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1327. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1328. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1329. LockWindow();
  1330. // Actually, do not know what hides the progress once the operation finishes
  1331. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1332. SetTaskbarListProgressState(TBPF_NORMAL);
  1333. }
  1334. //---------------------------------------------------------------------------
  1335. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1336. {
  1337. UnlockWindow();
  1338. SAFE_DESTROY(FProgressForm);
  1339. SetQueueProgress();
  1340. }
  1341. //---------------------------------------------------------------------------
  1342. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1343. TFileOperationProgressType & ProgressData)
  1344. {
  1345. // Download to temporary local directory
  1346. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1347. {
  1348. bool Continue = true;
  1349. FPendingTempSpaceWarn = false;
  1350. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1351. if (!Continue)
  1352. {
  1353. Abort();
  1354. }
  1355. }
  1356. // operation is being executed and we still didn't show up progress form
  1357. if (ProgressData.InProgress && !FProgressForm)
  1358. {
  1359. CreateProgressForm(NULL);
  1360. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1361. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1362. }
  1363. // operation is finished (or terminated), so we hide progress form
  1364. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1365. {
  1366. DestroyProgressForm();
  1367. if (ProgressData.Operation == foCalculateSize)
  1368. {
  1369. // When calculating size before transfer, the abort caused by
  1370. // cancel flag set due to "MoveToQueue" below,
  1371. // is not propagated back to us in ExecuteFileOperation,
  1372. // as it is silently swallowed.
  1373. // So we explicitly (re)throw it here.
  1374. if (FMoveToQueue)
  1375. {
  1376. Abort();
  1377. }
  1378. }
  1379. else
  1380. {
  1381. if ((ProgressData.Cancel == csContinue) &&
  1382. !FAutoOperation)
  1383. {
  1384. OperationComplete(ProgressData.StartTime);
  1385. }
  1386. }
  1387. }
  1388. if (FProgressForm &&
  1389. // Can happen only during synchronization, when ending one of the operations
  1390. ProgressData.InProgress)
  1391. {
  1392. FProgressForm->SetProgressData(ProgressData);
  1393. DebugAssert(ProgressData.InProgress);
  1394. SetTaskbarListProgressValue(&ProgressData);
  1395. if (FProgressForm->Cancel > csContinue)
  1396. {
  1397. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1398. if (FProgressForm->Cancel == csCancelFile)
  1399. {
  1400. FProgressForm->ClearCancel();
  1401. }
  1402. // cancel cancels even the move
  1403. FMoveToQueue = false;
  1404. }
  1405. else if (FProgressForm->MoveToQueue)
  1406. {
  1407. FMoveToQueue = true;
  1408. ProgressData.SetCancelAtLeast(csCancel);
  1409. }
  1410. if ((FTransferResumeList != NULL) &&
  1411. ProgressData.InProgress &&
  1412. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1413. !ProgressData.FullFileName.IsEmpty())
  1414. {
  1415. if ((FTransferResumeList->Count == 0) ||
  1416. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1417. {
  1418. // note that we do not recognize directories from files here
  1419. FTransferResumeList->Add(ProgressData.FullFileName);
  1420. }
  1421. }
  1422. }
  1423. }
  1424. //---------------------------------------------------------------------------
  1425. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1426. const TDateTime & StartTime)
  1427. {
  1428. if (GUIConfiguration->BeepOnFinish &&
  1429. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1430. {
  1431. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1432. DWORD Sound;
  1433. if (!ExtractFileExt(BeepSound).IsEmpty())
  1434. {
  1435. Sound = SND_FILENAME;
  1436. }
  1437. else
  1438. {
  1439. Sound = SND_ALIAS;
  1440. }
  1441. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1442. }
  1443. }
  1444. //---------------------------------------------------------------------------
  1445. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1446. TFileOperationProgressType & ProgressData)
  1447. {
  1448. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1449. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1450. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1451. FileOperationProgress(ProgressData);
  1452. }
  1453. //---------------------------------------------------------------------------
  1454. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1455. {
  1456. UnicodeString Result;
  1457. if (FProgressForm != NULL)
  1458. {
  1459. Result = FProgressForm->ProgressStr();
  1460. }
  1461. return Result;
  1462. }
  1463. //---------------------------------------------------------------------------
  1464. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1465. bool DragDrop)
  1466. {
  1467. return (!DragDrop && (DropSourceControl == NULL)) ||
  1468. (DropSourceControl == DirView(osOther));
  1469. }
  1470. //---------------------------------------------------------------------------
  1471. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1472. TFileOperation Operation, TOperationSide Side,
  1473. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1474. TOnceDoneOperation & OnceDoneOperation)
  1475. {
  1476. if (!FAutoOperation)
  1477. {
  1478. // no selection on "/upload", form serves only as event handler
  1479. // (it is not displayed)
  1480. if (PanelOperation(Side, FDragDropOperation) &&
  1481. Visible && (Operation != foCalculateSize) &&
  1482. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1483. {
  1484. if (FOnFileOperationFinished != NULL)
  1485. {
  1486. FOnFileOperationFinished(FileName, Success);
  1487. }
  1488. else
  1489. {
  1490. TOperationSide DViewSide;
  1491. if ((FProgressSide != osCurrent) &&
  1492. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1493. {
  1494. // assume the operation is over the focused panel
  1495. DViewSide = FProgressSide;
  1496. }
  1497. else
  1498. {
  1499. DViewSide = Side;
  1500. }
  1501. TCustomDirView * DView = DirView(DViewSide);
  1502. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(DViewSide));
  1503. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1504. // this can happen when local drive is unplugged in the middle of the operation
  1505. if (Item != NULL)
  1506. {
  1507. if (Success) Item->Selected = false;
  1508. DView->MakeProgressVisible(Item);
  1509. }
  1510. }
  1511. }
  1512. if ((Operation == foCopy) || (Operation == foMove))
  1513. {
  1514. if (DebugAlwaysTrue(!IsLocalBrowserMode()))
  1515. {
  1516. if (Side == osLocal)
  1517. {
  1518. Configuration->Usage->Inc(L"UploadedFiles");
  1519. }
  1520. else
  1521. {
  1522. Configuration->Usage->Inc(L"DownloadedFiles");
  1523. }
  1524. }
  1525. }
  1526. }
  1527. if (Success && (FSynchronizeController != NULL))
  1528. {
  1529. DebugAssert(!IsSideLocalBrowser(osRemote));
  1530. if (Operation == foCopy)
  1531. {
  1532. DebugAssert(Side == osLocal);
  1533. FSynchronizeController->LogOperation(soUpload, FileName);
  1534. }
  1535. else if (Operation == foDelete)
  1536. {
  1537. DebugAssert(Side == osRemote);
  1538. FSynchronizeController->LogOperation(soDelete, FileName);
  1539. }
  1540. }
  1541. if (FProgressForm)
  1542. {
  1543. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1544. }
  1545. }
  1546. //---------------------------------------------------------------------------
  1547. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1548. TFileOperation Operation, TOperationSide Side,
  1549. bool Temp, const UnicodeString & FileName, Boolean Success,
  1550. TOnceDoneOperation & OnceDoneOperation)
  1551. {
  1552. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1553. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1554. OnceDoneOperation);
  1555. }
  1556. //---------------------------------------------------------------------------
  1557. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1558. {
  1559. return false;
  1560. }
  1561. //---------------------------------------------------------------------------
  1562. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1563. {
  1564. return false;
  1565. }
  1566. //---------------------------------------------------------------------------
  1567. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1568. {
  1569. return NULL;
  1570. }
  1571. //---------------------------------------------------------------------------
  1572. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1573. {
  1574. DebugAssert(GetSide(Side) == osRemote);
  1575. DebugUsedParam(Side);
  1576. return RemoteDirView;
  1577. }
  1578. //---------------------------------------------------------------------------
  1579. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1580. {
  1581. DebugAssert(GetSide(Side) == osRemote);
  1582. DebugUsedParam(Side);
  1583. return RemoteDriveView;
  1584. }
  1585. //---------------------------------------------------------------------------
  1586. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1587. {
  1588. DebugAssert(GetSide(Side) == osRemote);
  1589. DebugUsedParam(Side);
  1590. return HasActiveTerminal();
  1591. }
  1592. //---------------------------------------------------------------------------
  1593. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1594. TOperationSide Side, int FilesOnly)
  1595. {
  1596. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1597. }
  1598. //---------------------------------------------------------------------------
  1599. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1600. TOperationSide Side, int FilesOnly)
  1601. {
  1602. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1603. }
  1604. //---------------------------------------------------------------------------
  1605. struct THistoryItemData
  1606. {
  1607. short int Side;
  1608. short int Index;
  1609. };
  1610. //---------------------------------------------------------------------------
  1611. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1612. {
  1613. DirView(Side)->HistoryGo(Index);
  1614. }
  1615. //---------------------------------------------------------------------------
  1616. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1617. {
  1618. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1619. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1620. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1621. }
  1622. //---------------------------------------------------------------------------
  1623. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1624. bool Back)
  1625. {
  1626. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1627. {
  1628. TCustomDirView * DView = DirView(Side);
  1629. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1630. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1631. if (ICount > 10)
  1632. {
  1633. ICount = 10;
  1634. }
  1635. Menu->Items->Clear();
  1636. THistoryItemData Data;
  1637. Data.Side = Side;
  1638. for (short int i = 1; i <= ICount; i++)
  1639. {
  1640. TTBCustomItem * Item = new TTBXItem(Menu);
  1641. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1642. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1643. Item->Hint = DView->HistoryPath[Data.Index];
  1644. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1645. Item->Tag = *reinterpret_cast<int*>(&Data);
  1646. Item->OnClick = HistoryItemClick;
  1647. Menu->Items->Add(Item);
  1648. }
  1649. }
  1650. }
  1651. //---------------------------------------------------------------------------
  1652. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1653. TOperationSide Side, bool Back)
  1654. {
  1655. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1656. {
  1657. // workaround
  1658. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1659. // operator new allocates memory in Pascal code, but calls inline
  1660. // contructor in C++, leading in problems, the function does
  1661. // both in Pascal code
  1662. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1663. UpdateHistoryMenu(Side, Back);
  1664. }
  1665. return FHistoryMenu[Side == osLocal][Back];
  1666. }
  1667. //---------------------------------------------------------------------------
  1668. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1669. TCustomDirView *Sender)
  1670. {
  1671. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1672. UpdateHistoryMenu(Side, true);
  1673. UpdateHistoryMenu(Side, false);
  1674. }
  1675. //---------------------------------------------------------------------------
  1676. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1677. {
  1678. // remote custom commands can be executed only if the server supports shell commands
  1679. // or have secondary shell
  1680. return HasActiveTerminal() && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1681. }
  1682. //---------------------------------------------------------------------------
  1683. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1684. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1685. {
  1686. // -1 = hidden, 0 = disabled, 1 = enabled
  1687. int Result;
  1688. TFileCustomCommand RemoteCustomCommand;
  1689. TLocalCustomCommand LocalCustomCommand;
  1690. TFileCustomCommand * NonInteractiveCustomCommand =
  1691. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1692. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1693. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1694. if (FLAGCLEAR(Command.Params, ccLocal))
  1695. {
  1696. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1697. // custom command that does not operate with files can be executed anytime ...
  1698. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1699. {
  1700. // ... but do not show such command in remote file menu
  1701. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1702. {
  1703. Result = AllowedState;
  1704. }
  1705. else
  1706. {
  1707. Result = -1;
  1708. }
  1709. }
  1710. else
  1711. {
  1712. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1713. {
  1714. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1715. }
  1716. else
  1717. {
  1718. Result = -1;
  1719. }
  1720. }
  1721. }
  1722. else
  1723. {
  1724. // custom command that does not operate with files can be executed anytime
  1725. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1726. {
  1727. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1728. }
  1729. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1730. {
  1731. if ((ListType == ccltAll) || (ListType == ccltFile))
  1732. {
  1733. // special case is "diff"-style command that can be executed over any side,
  1734. // if we have both sides
  1735. Result =
  1736. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1737. // directly (instead of EnableSelectedOperation) to pass
  1738. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1739. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1740. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1741. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1742. }
  1743. else if (ListType == ccltBoth)
  1744. {
  1745. DebugAssert(!IsLocalBrowserMode());
  1746. Result = 1;
  1747. }
  1748. else
  1749. {
  1750. Result = -1;
  1751. }
  1752. }
  1753. else
  1754. {
  1755. if ((ListType == ccltAll) ||
  1756. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1757. {
  1758. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1759. }
  1760. else
  1761. {
  1762. Result = -1;
  1763. }
  1764. }
  1765. if ((Result > 0) &&
  1766. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1767. !HasActiveTerminal())
  1768. {
  1769. Result = 0;
  1770. }
  1771. }
  1772. return Result;
  1773. }
  1774. //---------------------------------------------------------------------------
  1775. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1776. TStrings * FileList, const TCustomCommandType & ACommand,
  1777. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1778. {
  1779. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1780. {
  1781. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1782. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1783. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1784. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1785. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1786. bool Capture =
  1787. FLAGSET(ACommand.Params, ccShowResults) ||
  1788. FLAGSET(ACommand.Params, ccCopyResults) ||
  1789. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1790. TCaptureOutputEvent OutputEvent = NULL;
  1791. DebugAssert(FCapturedLog == NULL);
  1792. if (Capture)
  1793. {
  1794. FCapturedLog = new TStringList();
  1795. OutputEvent = TerminalCaptureLog;
  1796. }
  1797. try
  1798. {
  1799. if (!RemoteCustomCommand.IsFileCommand(Command))
  1800. {
  1801. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1802. OutputEvent);
  1803. }
  1804. else
  1805. {
  1806. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1807. }
  1808. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1809. {
  1810. if (FLAGSET(ACommand.Params, ccCopyResults))
  1811. {
  1812. CopyToClipboard(FCapturedLog);
  1813. }
  1814. if (FLAGSET(ACommand.Params, ccShowResults))
  1815. {
  1816. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1817. }
  1818. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1819. {
  1820. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1821. }
  1822. }
  1823. }
  1824. __finally
  1825. {
  1826. SAFE_DESTROY(FCapturedLog);
  1827. }
  1828. }
  1829. }
  1830. //---------------------------------------------------------------------------
  1831. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1832. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1833. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1834. {
  1835. DebugAssert(!IsLocalBrowserMode());
  1836. TStrings * LocalFileList = NULL;
  1837. TStrings * RemoteFileList = NULL;
  1838. TStrings * RemoteFileListFull = NULL;
  1839. try
  1840. {
  1841. if (LocalFileCommand)
  1842. {
  1843. if (ALocalFileList == NULL)
  1844. {
  1845. DebugAssert(HasDirView[osLocal]);
  1846. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1847. // directly (instead of EnableSelectedOperation) to pass
  1848. // false to FocusedFileOnlyWhenFocused
  1849. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1850. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1851. }
  1852. else
  1853. {
  1854. LocalFileList = ALocalFileList;
  1855. }
  1856. if (FileListCommand)
  1857. {
  1858. if (LocalFileList->Count != 1)
  1859. {
  1860. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1861. }
  1862. }
  1863. else
  1864. {
  1865. if ((LocalFileList->Count != 1) &&
  1866. (FileList->Count != 1) &&
  1867. (LocalFileList->Count != FileList->Count))
  1868. {
  1869. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1870. }
  1871. }
  1872. }
  1873. UnicodeString RootTempDir;
  1874. UnicodeString TempDir;
  1875. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1876. if (!RemoteFiles)
  1877. {
  1878. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1879. }
  1880. try
  1881. {
  1882. TDateTimes RemoteFileTimes;
  1883. if (RemoteFiles)
  1884. {
  1885. RemoteFileList = FileList;
  1886. }
  1887. else
  1888. {
  1889. RemoteFileList = new TStringList();
  1890. TMakeLocalFileListParams MakeFileListParam;
  1891. MakeFileListParam.FileList = RemoteFileList;
  1892. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1893. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1894. MakeFileListParam.Recursive =
  1895. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1896. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1897. if (!MakeFileListParam.Recursive)
  1898. {
  1899. RemoteFileTimes.clear();
  1900. RemoteFileListFull = new TStringList();
  1901. MakeFileListParam.FileList = RemoteFileListFull;
  1902. MakeFileListParam.Recursive = true;
  1903. MakeFileListParam.IncludeDirs = false;
  1904. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1905. }
  1906. else
  1907. {
  1908. RemoteFileListFull = RemoteFileList;
  1909. }
  1910. }
  1911. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1912. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1913. if (!NonBlocking)
  1914. {
  1915. int Count;
  1916. if (FileListCommand)
  1917. {
  1918. Count = 1;
  1919. }
  1920. else if (LocalFileCommand)
  1921. {
  1922. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1923. }
  1924. else
  1925. {
  1926. Count = RemoteFileList->Count;
  1927. }
  1928. Progress.Start(foCustomCommand, osRemote, Count);
  1929. DebugAssert(FProgressForm != NULL);
  1930. FProgressForm->ReadOnly = true;
  1931. }
  1932. try
  1933. {
  1934. if (FileListCommand)
  1935. {
  1936. UnicodeString LocalFile;
  1937. // MakeFileList does not delimit filenames
  1938. UnicodeString FileList = MakeFileList(RemoteFileList);
  1939. if (LocalFileCommand)
  1940. {
  1941. DebugAssert(LocalFileList->Count == 1);
  1942. LocalFile = LocalFileList->Strings[0];
  1943. }
  1944. TLocalCustomCommand CustomCommand(Data,
  1945. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1946. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1947. if (NonBlocking)
  1948. {
  1949. DebugAssert(!POutput);
  1950. ExecuteShellChecked(ShellCommand);
  1951. }
  1952. else
  1953. {
  1954. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1955. }
  1956. }
  1957. else if (LocalFileCommand)
  1958. {
  1959. if (LocalFileList->Count == 1)
  1960. {
  1961. UnicodeString LocalFile = LocalFileList->Strings[0];
  1962. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1963. {
  1964. UnicodeString FileName = RemoteFileList->Strings[Index];
  1965. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1966. Progress.SetFile(FileNameForProgress);
  1967. TLocalCustomCommand CustomCommand(Data,
  1968. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1969. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1970. TOnceDoneOperation OnceDoneOperation;
  1971. // Do not unselect anything, as it won't work with two panels anyway
  1972. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1973. }
  1974. }
  1975. else if (RemoteFileList->Count == 1)
  1976. {
  1977. UnicodeString FileName = RemoteFileList->Strings[0];
  1978. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1979. {
  1980. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1981. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1982. Progress.SetFile(LocalFileNameOnly);
  1983. TLocalCustomCommand CustomCommand(
  1984. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1985. FileName, LocalFileName, L"");
  1986. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1987. TOnceDoneOperation OnceDoneOperation;
  1988. // Do not unselect anything, as it won't work with two panels anyway
  1989. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1990. }
  1991. }
  1992. else
  1993. {
  1994. if (LocalFileList->Count != RemoteFileList->Count)
  1995. {
  1996. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1997. }
  1998. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1999. {
  2000. UnicodeString FileName = RemoteFileList->Strings[Index];
  2001. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2002. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2003. Progress.SetFile(LocalFileNameOnly); // sic
  2004. TLocalCustomCommand CustomCommand(
  2005. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2006. FileName, LocalFileName, L"");
  2007. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2008. TOnceDoneOperation OnceDoneOperation;
  2009. // Do not unselect anything, as it won't work with two panels anyway
  2010. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2011. }
  2012. }
  2013. }
  2014. else
  2015. {
  2016. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2017. {
  2018. UnicodeString FileName = RemoteFileList->Strings[Index];
  2019. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2020. Progress.SetFile(FileNameForProgress);
  2021. TLocalCustomCommand CustomCommand(Data,
  2022. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2023. FileName, L"", L"");
  2024. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2025. TOnceDoneOperation OnceDoneOperation;
  2026. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2027. }
  2028. }
  2029. }
  2030. __finally
  2031. {
  2032. if (!NonBlocking)
  2033. {
  2034. Progress.Stop();
  2035. }
  2036. }
  2037. DebugAssert(!FAutoOperation);
  2038. if (!RemoteFiles)
  2039. {
  2040. TempDir = IncludeTrailingBackslash(TempDir);
  2041. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2042. {
  2043. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2044. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2045. // Skip directories, process only nested files.
  2046. // The check is redundant as FileAge fails for directories anyway.
  2047. !DirectoryExists(FileName))
  2048. {
  2049. UnicodeString RemoteDir =
  2050. UnixExtractFileDir(
  2051. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2052. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2053. TDateTime NewTime;
  2054. if (FileAge(FileName, NewTime) &&
  2055. (NewTime != RemoteFileTimes[Index]))
  2056. {
  2057. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2058. TemporaryFileCopyParam(CopyParam);
  2059. CopyParam.FileMask = L"";
  2060. FAutoOperation = true;
  2061. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2062. TemporaryFilesList->Add(FileName);
  2063. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2064. }
  2065. }
  2066. }
  2067. }
  2068. }
  2069. __finally
  2070. {
  2071. FAutoOperation = false;
  2072. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2073. {
  2074. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2075. }
  2076. }
  2077. }
  2078. __finally
  2079. {
  2080. if (RemoteFileList != FileList)
  2081. {
  2082. delete RemoteFileList;
  2083. }
  2084. if (LocalFileList != ALocalFileList)
  2085. {
  2086. delete LocalFileList;
  2087. }
  2088. if (RemoteFileListFull != RemoteFileList)
  2089. {
  2090. delete RemoteFileListFull;
  2091. }
  2092. }
  2093. }
  2094. //---------------------------------------------------------------------------
  2095. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2096. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2097. bool FileListCommand, UnicodeString * POutput)
  2098. {
  2099. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2100. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2101. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2102. {
  2103. UnicodeString FileName = SelectedFileList->Strings[Index];
  2104. if (DirectoryExists(FileName))
  2105. {
  2106. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2107. {
  2108. LocalFileList->Add(FileName);
  2109. }
  2110. if (FLAGSET(ACommand.Params, ccRecursive))
  2111. {
  2112. TMakeLocalFileListParams MakeFileListParam;
  2113. MakeFileListParam.FileList = LocalFileList.get();
  2114. MakeFileListParam.FileTimes = NULL;
  2115. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2116. MakeFileListParam.Recursive = true;
  2117. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2118. }
  2119. }
  2120. else
  2121. {
  2122. LocalFileList->Add(FileName);
  2123. }
  2124. }
  2125. UnicodeString RemotePath;
  2126. if (Terminal != NULL)
  2127. {
  2128. RemotePath = Terminal->CurrentDirectory;
  2129. }
  2130. if (FileListCommand)
  2131. {
  2132. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2133. TLocalCustomCommand CustomCommand(
  2134. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2135. L"", L"", FileList);
  2136. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2137. }
  2138. else
  2139. {
  2140. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2141. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2142. DebugAssert(FProgressForm != NULL);
  2143. FProgressForm->ReadOnly = true;
  2144. try
  2145. {
  2146. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2147. {
  2148. UnicodeString FileName = LocalFileList->Strings[Index];
  2149. Progress.SetFile(FileName);
  2150. TLocalCustomCommand CustomCommand(
  2151. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2152. FileName, L"", L"");
  2153. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2154. TOnceDoneOperation OnceDoneOperation;
  2155. Progress.Finish(FileName, true, OnceDoneOperation);
  2156. }
  2157. }
  2158. __finally
  2159. {
  2160. Progress.Stop();
  2161. }
  2162. }
  2163. }
  2164. //---------------------------------------------------------------------------
  2165. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2166. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2167. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2168. {
  2169. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2170. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2171. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2172. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2173. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2174. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2175. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2176. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2177. std::unique_ptr<UnicodeString> POutput;
  2178. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2179. FLAGSET(ACommand.Params, ccCopyResults))
  2180. {
  2181. POutput.reset(new UnicodeString());
  2182. }
  2183. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  2184. FProgressSide = FCurrentSide;
  2185. if (!LocalCustomCommand.IsFileCommand(Command))
  2186. {
  2187. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2188. }
  2189. // remote files?
  2190. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2191. {
  2192. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2193. }
  2194. // local files
  2195. else
  2196. {
  2197. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2198. }
  2199. if (POutput.get() != NULL)
  2200. {
  2201. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2202. int P = POutput->Pos(sLineBreak);
  2203. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2204. {
  2205. POutput->SetLength(P - 1);
  2206. }
  2207. // Copy even empty output to clipboard
  2208. if (FLAGSET(ACommand.Params, ccCopyResults))
  2209. {
  2210. CopyToClipboard(*POutput);
  2211. }
  2212. // But do not show an empty message box.
  2213. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2214. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2215. !POutput->IsEmpty())
  2216. {
  2217. TClipboardHandler ClipboardHandler;
  2218. ClipboardHandler.Text = *POutput;
  2219. TMessageParams Params;
  2220. TQueryButtonAlias Aliases[1];
  2221. Aliases[0].Button = qaRetry;
  2222. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2223. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2224. Params.Aliases = Aliases;
  2225. Params.AliasesCount = LENOF(Aliases);
  2226. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2227. }
  2228. }
  2229. }
  2230. //---------------------------------------------------------------------------
  2231. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2232. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2233. {
  2234. TCustomCommandData Data;
  2235. UnicodeString Site;
  2236. UnicodeString RemotePath;
  2237. if (HasActiveTerminal())
  2238. {
  2239. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2240. Data = TCustomCommandData(SessionData.get());
  2241. Site = Terminal->SessionData->SessionKey;
  2242. RemotePath = Terminal->CurrentDirectory;
  2243. }
  2244. UnicodeString HelpKeyword = ACommand.HomePage;
  2245. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2246. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2247. {
  2248. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2249. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2250. {
  2251. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2252. }
  2253. else
  2254. {
  2255. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2256. }
  2257. if (!DoCustomCommandOptionsDialog(
  2258. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2259. {
  2260. Abort();
  2261. }
  2262. }
  2263. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2264. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2265. {
  2266. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2267. }
  2268. else
  2269. {
  2270. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2271. }
  2272. }
  2273. //---------------------------------------------------------------------------
  2274. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2275. const TCustomCommandType & Command)
  2276. {
  2277. DebugAssert(FCustomCommandLocalFileList != NULL);
  2278. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2279. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2280. TStrings * LocalFileList = new TStringList();
  2281. TStrings * RemoteFileList = new TStringList();
  2282. try
  2283. {
  2284. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2285. {
  2286. LocalFileList->Clear();
  2287. LocalFileList->AddObject(
  2288. FCustomCommandLocalFileList->Strings[Index],
  2289. FCustomCommandLocalFileList->Objects[Index]);
  2290. RemoteFileList->Clear();
  2291. RemoteFileList->AddObject(
  2292. FCustomCommandRemoteFileList->Strings[Index],
  2293. FCustomCommandRemoteFileList->Objects[Index]);
  2294. CustomCommand(RemoteFileList, Command, LocalFileList);
  2295. }
  2296. }
  2297. __finally
  2298. {
  2299. delete LocalFileList;
  2300. delete RemoteFileList;
  2301. }
  2302. }
  2303. //---------------------------------------------------------------------------
  2304. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2305. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2306. {
  2307. delete FCustomCommandLocalFileList;
  2308. delete FCustomCommandRemoteFileList;
  2309. // takeover ownership,
  2310. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2311. FCustomCommandLocalFileList = LocalFileList;
  2312. FCustomCommandRemoteFileList = RemoteFileList;
  2313. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2314. if (Button != NULL)
  2315. {
  2316. FCustomCommandMenu->Items->Clear();
  2317. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2318. MenuPopup(FCustomCommandMenu, Button);
  2319. }
  2320. else
  2321. {
  2322. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2323. }
  2324. }
  2325. //---------------------------------------------------------------------------
  2326. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2327. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2328. {
  2329. DebugAssert(FCapturedLog != NULL);
  2330. if ((OutputType == cotOutput) || (OutputType == cotError))
  2331. {
  2332. FCapturedLog->Add(AddedLine);
  2333. }
  2334. }
  2335. //---------------------------------------------------------------------------
  2336. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2337. TOperationSide Side)
  2338. {
  2339. return
  2340. (Side == osOther) &&
  2341. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2342. }
  2343. //---------------------------------------------------------------------------
  2344. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2345. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2346. {
  2347. TTBItemOptions O;
  2348. O = Item->Options;
  2349. TCustomDirView * DView = DirView(Side);
  2350. if ((DView->ItemFocused != NULL) &&
  2351. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2352. // when resolving links is disabled, default action is to enter the directory,
  2353. // no matter what DoubleClickAction is configured to
  2354. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2355. // Can only Edit files, but can Open/Copy even directories
  2356. ((DoubleClickAction != dcaEdit) ||
  2357. !DView->ItemIsDirectory(DView->ItemFocused)))
  2358. {
  2359. Item->Options = O << tboDefault;
  2360. }
  2361. else
  2362. {
  2363. Item->Options = O >> tboDefault;
  2364. }
  2365. }
  2366. //---------------------------------------------------------------------------
  2367. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2368. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2369. {
  2370. TCustomDirView * DView = DirView(Side);
  2371. TListItem * Item = DView->ItemFocused;
  2372. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2373. EnableFocusedOperation[Side])
  2374. {
  2375. TPoint ClientPoint;
  2376. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2377. TPoint(0, 0) : MousePos;
  2378. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2379. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2380. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2381. }
  2382. }
  2383. //---------------------------------------------------------------------------
  2384. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2385. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2386. {
  2387. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2388. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2389. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2390. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2391. Handled = true;
  2392. }
  2393. //---------------------------------------------------------------------------
  2394. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2395. {
  2396. }
  2397. //---------------------------------------------------------------------------
  2398. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2399. {
  2400. DebugAssert(FErrorList == NULL);
  2401. if (WinConfiguration->ContinueOnError)
  2402. {
  2403. FErrorList = new TStringList();
  2404. Configuration->Usage->Inc(L"ContinuationsOnError");
  2405. }
  2406. NonVisualDataModule->StartBusy();
  2407. }
  2408. //---------------------------------------------------------------------------
  2409. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2410. {
  2411. NonVisualDataModule->EndBusy();
  2412. if (FErrorList)
  2413. {
  2414. HandleErrorList(FErrorList);
  2415. }
  2416. }
  2417. //---------------------------------------------------------------------------
  2418. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2419. const TCopyParamType & CopyParam)
  2420. {
  2421. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2422. {
  2423. Configuration->Usage->Inc(L"FileMaskUses");
  2424. }
  2425. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2426. {
  2427. Configuration->Usage->Inc(L"OperationMaskUses");
  2428. }
  2429. }
  2430. //---------------------------------------------------------------------------
  2431. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2432. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2433. {
  2434. DebugAssert(!IsLocalBrowserMode());
  2435. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2436. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2437. TTransferOperationParam DefaultParam;
  2438. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2439. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2440. switch (Param.Queue)
  2441. {
  2442. case asOn:
  2443. CopyParam.Queue = true;
  2444. break;
  2445. case asOff:
  2446. CopyParam.Queue = false;
  2447. break;
  2448. case asAuto:
  2449. default:
  2450. // keep default
  2451. break;
  2452. }
  2453. bool Result =
  2454. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2455. if (Result)
  2456. {
  2457. DebugAssert(Terminal);
  2458. bool SelectionRestored = false;
  2459. TCustomDirView * DView = NULL;
  2460. if (HasDirView[Side])
  2461. {
  2462. DView = DirView(Side);
  2463. DView->SaveSelection();
  2464. DView->SaveSelectedNames();
  2465. }
  2466. UpdateCopyParamCounters(CopyParam);
  2467. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2468. DebugAssert(FTransferResumeList == NULL);
  2469. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2470. FMoveToQueue = false;
  2471. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2472. try
  2473. {
  2474. TStrings * PermanentFileList;
  2475. std::unique_ptr<TStrings> PermanentFileListOwner;
  2476. try
  2477. {
  2478. if (Side == osLocal)
  2479. {
  2480. PermanentFileList = FileList;
  2481. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2482. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2483. if (Operation == foMove)
  2484. {
  2485. ReloadLocalDirectory();
  2486. if (DView != NULL)
  2487. {
  2488. DView->RestoreSelection();
  2489. }
  2490. SelectionRestored = true;
  2491. }
  2492. }
  2493. else
  2494. {
  2495. // Clone the file list as it may refer to current directory files,
  2496. // which get destroyed, when the source directory is reloaded after foMove operation.
  2497. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2498. // But for a hotfix, we are not going to do such a big change.
  2499. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2500. PermanentFileList = PermanentFileListOwner.get();
  2501. try
  2502. {
  2503. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2504. }
  2505. __finally
  2506. {
  2507. if (Operation == foMove)
  2508. {
  2509. if (DView != NULL)
  2510. {
  2511. DView->RestoreSelection();
  2512. }
  2513. SelectionRestored = true;
  2514. }
  2515. ReloadLocalDirectory(Param.TargetDirectory);
  2516. }
  2517. }
  2518. }
  2519. catch (EAbort &)
  2520. {
  2521. if (FMoveToQueue)
  2522. {
  2523. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2524. DebugAssert(CopyParam.TransferSkipList == NULL);
  2525. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2526. if (TransferResumeList->Count > 0)
  2527. {
  2528. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2529. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2530. }
  2531. CopyParam.TransferSkipList = TransferResumeList.release();
  2532. // not really needed, just to keep it consistent with TransferResumeList
  2533. FTransferResumeList = NULL;
  2534. FMoveToQueue = false;
  2535. Configuration->Usage->Inc("MovesToBackground");
  2536. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2537. ClearTransferSourceSelection(Direction);
  2538. }
  2539. throw;
  2540. }
  2541. }
  2542. __finally
  2543. {
  2544. if (!SelectionRestored && (DView != NULL))
  2545. {
  2546. DView->DiscardSavedSelection();
  2547. }
  2548. FTransferResumeList = NULL;
  2549. }
  2550. }
  2551. return Result;
  2552. }
  2553. //---------------------------------------------------------------------------
  2554. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2555. TOperationSide Side, TStrings * FileList, void * Param)
  2556. {
  2557. DebugAssert(FileList->Count);
  2558. // We deliberately do not toggle alternative flag (Param), but use OR,
  2559. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2560. // shortcut of CurrentDeleteAlternativeAction
  2561. bool Alternative =
  2562. bool(Param) || UseAlternativeFunction();
  2563. bool Recycle;
  2564. if (IsSideLocalBrowser(Side))
  2565. {
  2566. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2567. }
  2568. else
  2569. {
  2570. Recycle =
  2571. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2572. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2573. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2574. }
  2575. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2576. if (!Result)
  2577. {
  2578. UnicodeString Query;
  2579. if (FileList->Count == 1)
  2580. {
  2581. if (IsSideLocalBrowser(Side))
  2582. {
  2583. Query = ExtractFileName(FileList->Strings[0]);
  2584. }
  2585. else
  2586. {
  2587. Query = UnixExtractFileName(FileList->Strings[0]);
  2588. }
  2589. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2590. }
  2591. else
  2592. {
  2593. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2594. }
  2595. TMessageParams Params(mpNeverAskAgainCheck);
  2596. Params.ImageName = L"Delete file";
  2597. unsigned int Answer =
  2598. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2599. if (Answer == qaNeverAskAgain)
  2600. {
  2601. Result = true;
  2602. if (Recycle)
  2603. {
  2604. WinConfiguration->ConfirmRecycling = false;
  2605. }
  2606. else
  2607. {
  2608. WinConfiguration->ConfirmDeleting = false;
  2609. }
  2610. }
  2611. else
  2612. {
  2613. Result = (Answer == qaOK);
  2614. }
  2615. }
  2616. if (Result)
  2617. {
  2618. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2619. }
  2620. return Result;
  2621. }
  2622. //---------------------------------------------------------------------------
  2623. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2624. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2625. {
  2626. TAutoBatch AutoBatch(this);
  2627. bool Result;
  2628. if ((Operation == foCopy) || (Operation == foMove))
  2629. {
  2630. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2631. }
  2632. else if (Operation == foRename)
  2633. {
  2634. DebugAssert(DirView(Side)->ItemFocused);
  2635. DirView(Side)->ItemFocused->EditCaption();
  2636. Result = true;
  2637. }
  2638. else if (Operation == foDelete)
  2639. {
  2640. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2641. }
  2642. else if (Operation == foSetProperties)
  2643. {
  2644. DirView(osRemote)->SaveSelectedNames();
  2645. Result = SetProperties(Side, FileList);
  2646. }
  2647. else if (Operation == foCustomCommand)
  2648. {
  2649. DebugAssert(Param);
  2650. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2651. DirView(osRemote)->SaveSelectedNames();
  2652. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2653. CustomCommand(FileList, *Command, NULL);
  2654. Result = true;
  2655. }
  2656. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2657. {
  2658. DebugAssert(!IsSideLocalBrowser(Side));
  2659. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2660. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2661. }
  2662. else if (Operation == foLock)
  2663. {
  2664. DebugAssert(!IsSideLocalBrowser(Side));
  2665. LockFiles(FileList, true);
  2666. Result = true;
  2667. }
  2668. else if (Operation == foUnlock)
  2669. {
  2670. DebugAssert(!IsSideLocalBrowser(Side));
  2671. LockFiles(FileList, false);
  2672. Result = true;
  2673. }
  2674. else
  2675. {
  2676. DebugFail();
  2677. }
  2678. return Result;
  2679. }
  2680. //---------------------------------------------------------------------------
  2681. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2682. {
  2683. if (Side == osCurrent)
  2684. {
  2685. Side = FCurrentSide;
  2686. }
  2687. return Side;
  2688. }
  2689. //---------------------------------------------------------------------------
  2690. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2691. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2692. {
  2693. Side = GetSide(Side);
  2694. bool Result;
  2695. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2696. try
  2697. {
  2698. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2699. }
  2700. __finally
  2701. {
  2702. delete FileList;
  2703. }
  2704. return Result;
  2705. }
  2706. //---------------------------------------------------------------------------
  2707. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2708. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2709. bool NoConfirmation, void * Param)
  2710. {
  2711. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2712. {
  2713. if ((Operation == foCopy) || (Operation == foMove))
  2714. {
  2715. DebugAssert(!IsLocalBrowserMode());
  2716. if (GetSide(Side) == osLocal)
  2717. {
  2718. Configuration->Usage->Inc(L"UploadsCommand");
  2719. }
  2720. else
  2721. {
  2722. Configuration->Usage->Inc(L"DownloadsCommand");
  2723. }
  2724. }
  2725. }
  2726. }
  2727. //---------------------------------------------------------------------------
  2728. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2729. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2730. {
  2731. TTransferOperationParam Param;
  2732. if ((WinConfiguration->Interface != ifCommander) ||
  2733. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2734. {
  2735. Flags &= ~cocShortCutHint;
  2736. }
  2737. TCustomDirView * DView = DirView(Side);
  2738. Param.Options =
  2739. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2740. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2741. if (FLAGSET(Flags, cocQueue))
  2742. {
  2743. Param.Queue = asOn;
  2744. }
  2745. else if (FLAGSET(Flags, cocNonQueue))
  2746. {
  2747. Param.Queue = asOff;
  2748. }
  2749. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2750. }
  2751. //---------------------------------------------------------------------------
  2752. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2753. {
  2754. try
  2755. {
  2756. if (ErrorList->Count)
  2757. {
  2758. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2759. if (MessageDialog(Message, qtError,
  2760. qaOK | qaCancel, HELP_NONE) == qaOK)
  2761. {
  2762. unsigned int Answer;
  2763. int Index = 0;
  2764. do
  2765. {
  2766. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2767. TQueryButtonAlias Aliases[2];
  2768. Aliases[0].Button = qaYes;
  2769. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2770. Aliases[1].Button = qaNo;
  2771. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2772. TMessageParams Params;
  2773. Params.Aliases = Aliases;
  2774. Params.AliasesCount = LENOF(Aliases);
  2775. Answer = MoreMessageDialog(
  2776. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2777. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2778. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2779. qaOK, HELP_NONE, &Params);
  2780. if (Answer == qaNo)
  2781. {
  2782. Index++;
  2783. }
  2784. if (Answer == qaYes)
  2785. {
  2786. Index--;
  2787. }
  2788. }
  2789. while (Answer != qaOK);
  2790. }
  2791. }
  2792. }
  2793. __finally
  2794. {
  2795. TStrings * List = ErrorList;
  2796. ErrorList = NULL;
  2797. for (int i = 0; i < List->Count; i++)
  2798. {
  2799. delete List->Objects[i];
  2800. }
  2801. delete List;
  2802. }
  2803. }
  2804. //---------------------------------------------------------------------------
  2805. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2806. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2807. {
  2808. // needed for checking filemasks, as there's no directory object
  2809. // associated with the file object
  2810. File->FullFileName = FullFileName;
  2811. TFileMasks::TParams MaskParams;
  2812. MaskParams.Size = File->Size;
  2813. MaskParams.Modification = File->Modification;
  2814. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2815. }
  2816. //---------------------------------------------------------------------------
  2817. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2818. {
  2819. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2820. Side = GetSide(Side);
  2821. TCustomDirView * DView = DirView(Side);
  2822. TListItem * FocusedItem = DView->ItemFocused;
  2823. UnicodeString Name;
  2824. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2825. {
  2826. Name = DView->ItemFileName(FocusedItem);
  2827. }
  2828. else
  2829. {
  2830. Name = LoadStr(NEW_FILE);
  2831. }
  2832. UnicodeString Names = Name;
  2833. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2834. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2835. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  2836. {
  2837. while (!Names.IsEmpty())
  2838. {
  2839. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2840. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2841. UnicodeString TargetFileName;
  2842. UnicodeString LocalFileName;
  2843. UnicodeString RootTempDir;
  2844. UnicodeString TempDir;
  2845. UnicodeString RemoteDirectory;
  2846. bool ExistingFile = false;
  2847. if (!IsSideLocalBrowser(Side))
  2848. {
  2849. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2850. TRemoteFile * File = NULL;
  2851. if (FTerminal->FileExists(Name, &File) &&
  2852. !File->IsDirectory)
  2853. {
  2854. try
  2855. {
  2856. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2857. ExistingFile = true;
  2858. }
  2859. __finally
  2860. {
  2861. delete File;
  2862. }
  2863. }
  2864. if (!ExistingFile)
  2865. {
  2866. RemoteDirectory = UnixExtractFilePath(Name);
  2867. TemporaryDirectoryForRemoteFiles(
  2868. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2869. TargetFileName = UnixExtractFileName(Name);
  2870. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2871. LocalFileName = TempDir +
  2872. // We probably do not want to trim the VMS version here
  2873. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2874. }
  2875. }
  2876. else
  2877. {
  2878. if (ExtractFilePath(Name).IsEmpty())
  2879. {
  2880. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2881. }
  2882. else
  2883. {
  2884. LocalFileName = ExpandFileName(Name);
  2885. }
  2886. TargetFileName = ExtractFileName(Name);
  2887. }
  2888. if (!ExistingFile)
  2889. {
  2890. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2891. if (NewFile)
  2892. {
  2893. int File = FileCreate(ApiPath(LocalFileName));
  2894. if (File < 0)
  2895. {
  2896. if (!RootTempDir.IsEmpty())
  2897. {
  2898. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2899. }
  2900. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2901. }
  2902. else
  2903. {
  2904. FileClose(File);
  2905. }
  2906. }
  2907. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2908. const TEditorData * ExternalEditor = NULL;
  2909. TFileMasks::TParams MaskParams; // size not known
  2910. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2911. false, MaskParams);
  2912. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2913. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2914. }
  2915. }
  2916. }
  2917. }
  2918. //---------------------------------------------------------------------------
  2919. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2920. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2921. {
  2922. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2923. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2924. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2925. return
  2926. ((ExecuteFileBy == efInternalEditor)) ||
  2927. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2928. }
  2929. //---------------------------------------------------------------------------
  2930. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2931. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2932. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2933. UnicodeString RemoteDirectory, bool NewFile)
  2934. {
  2935. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2936. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2937. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2938. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2939. Side = GetSide(Side);
  2940. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2941. if (!IsSideLocalBrowser(Side))
  2942. {
  2943. Data->Terminal = Terminal;
  2944. Data->Queue = Queue;
  2945. Data->SessionData = CloneCurrentSessionData();
  2946. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2947. Data->RemoteDirectory = RemoteDirectory;
  2948. Data->SessionName = Terminal->SessionData->SessionName;
  2949. Data->LocalRootDirectory = LocalRootDirectory;
  2950. Data->OriginalFileName = OriginalFileName;
  2951. Data->Command = L""; // will be changed later for external editor
  2952. }
  2953. if (ExecuteFileBy == efInternalEditor)
  2954. {
  2955. if (!IsSideLocalBrowser(Side))
  2956. {
  2957. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2958. L" - " + Terminal->SessionData->SessionName;
  2959. TForm * Editor;
  2960. try
  2961. {
  2962. TNotifyEvent OnFileChanged = NULL;
  2963. TNotifyEvent OnSaveAll = NULL;
  2964. TAnyModifiedEvent OnAnyModified = NULL;
  2965. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2966. if (Terminal->IsCapable[fcBackgroundTransfers])
  2967. {
  2968. OnFileChanged = FEditorManager->FileChanged;
  2969. OnSaveAll = SaveAllInternalEditors;
  2970. OnAnyModified = AnyInternalEditorModified;
  2971. }
  2972. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2973. FEditorManager->FileReload, FEditorManager->FileClosed,
  2974. OnSaveAll, OnAnyModified,
  2975. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2976. }
  2977. catch(...)
  2978. {
  2979. if (!LocalRootDirectory.IsEmpty())
  2980. {
  2981. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2982. }
  2983. throw;
  2984. }
  2985. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2986. }
  2987. else
  2988. {
  2989. DebugAssert(!FStandaloneEditing);
  2990. TForm * Editor =
  2991. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2992. SaveAllInternalEditors, AnyInternalEditorModified,
  2993. L"", false, SessionColor, -1, NewFile);
  2994. FLocalEditors->Add(Editor);
  2995. }
  2996. }
  2997. else
  2998. {
  2999. HANDLE Process;
  3000. if (ExecuteFileBy == efExternalEditor)
  3001. {
  3002. UnicodeString Program, Params, Dir;
  3003. Data->Command = ExternalEditor->ExternalEditor;
  3004. ReformatFileNameCommand(Data->Command);
  3005. SplitCommand(Data->Command, Program, Params, Dir);
  3006. Params = ExpandFileNameCommand(Params, FileName);
  3007. Program = ExpandEnvironmentVariables(Program);
  3008. if (!ExecuteShell(Program, Params, Process))
  3009. {
  3010. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3011. }
  3012. }
  3013. else
  3014. {
  3015. DebugAssert(!IsSideLocalBrowser(Side));
  3016. if (!ExecuteShell(FileName, L"", Process))
  3017. {
  3018. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3019. }
  3020. }
  3021. if (IsSideLocalBrowser(Side) ||
  3022. ((ExecuteFileBy == efShell) &&
  3023. !WinConfiguration->Editor.SDIShellEditor) ||
  3024. ((ExecuteFileBy == efExternalEditor) &&
  3025. !ExternalEditor->SDIExternalEditor))
  3026. {
  3027. // no need for handle
  3028. if (Process != NULL)
  3029. {
  3030. DebugCheck(CloseHandle(Process));
  3031. }
  3032. Process = INVALID_HANDLE_VALUE;
  3033. }
  3034. else
  3035. {
  3036. if (Process == NULL)
  3037. {
  3038. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3039. }
  3040. }
  3041. if (!IsSideLocalBrowser(Side))
  3042. {
  3043. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3044. }
  3045. }
  3046. }
  3047. //---------------------------------------------------------------------------
  3048. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3049. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3050. void * /*Arg*/)
  3051. {
  3052. if (Token != NULL)
  3053. {
  3054. EditorFormFileSave(static_cast<TForm *>(Token));
  3055. }
  3056. }
  3057. //---------------------------------------------------------------------------
  3058. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3059. {
  3060. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3061. {
  3062. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3063. }
  3064. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3065. }
  3066. //---------------------------------------------------------------------------
  3067. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3068. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3069. void * Arg)
  3070. {
  3071. if ((Token != NULL) &&
  3072. IsEditorFormModified(static_cast<TForm *>(Token)))
  3073. {
  3074. *static_cast<bool *>(Arg) = true;
  3075. }
  3076. }
  3077. //---------------------------------------------------------------------------
  3078. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3079. TObject * /*Sender*/, bool & Modified)
  3080. {
  3081. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3082. {
  3083. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3084. {
  3085. Modified = true;
  3086. }
  3087. }
  3088. if (!Modified)
  3089. {
  3090. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3091. }
  3092. }
  3093. //---------------------------------------------------------------------------
  3094. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3095. {
  3096. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3097. }
  3098. //---------------------------------------------------------------------------
  3099. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3100. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3101. UnicodeString & Result, UnicodeString & RootDirectory)
  3102. {
  3103. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3104. {
  3105. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3106. Result = RootDirectory;
  3107. }
  3108. else
  3109. {
  3110. RootDirectory = L"";
  3111. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3112. Result = IncludeTrailingBackslash(Result);
  3113. }
  3114. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3115. {
  3116. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3117. }
  3118. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3119. {
  3120. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3121. {
  3122. RemoteDirectory.Delete(1, 1);
  3123. }
  3124. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3125. }
  3126. if (!ForceDirectories(ApiPath(Result)))
  3127. {
  3128. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3129. }
  3130. }
  3131. //---------------------------------------------------------------------------
  3132. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3133. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3134. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3135. {
  3136. DebugAssert(!IsLocalBrowserMode());
  3137. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3138. if (ForceText)
  3139. {
  3140. CopyParam.TransferMode = tmAscii;
  3141. }
  3142. TemporaryFileCopyParam(CopyParam);
  3143. if (AllFiles)
  3144. {
  3145. CopyParam.IncludeFileMask = TFileMasks();
  3146. }
  3147. if (TempDir.IsEmpty())
  3148. {
  3149. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3150. }
  3151. DebugAssert(!FAutoOperation);
  3152. FAutoOperation = AutoOperation;
  3153. Terminal->ExceptionOnFail = true;
  3154. try
  3155. {
  3156. try
  3157. {
  3158. // turn off confirmations, as for MDI editors we may possibly download
  3159. // the same file over
  3160. Terminal->CopyToLocal(
  3161. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3162. if (GetTargetNames)
  3163. {
  3164. for (int i = 0; i < FileList->Count; i++)
  3165. {
  3166. FileList->Strings[i] =
  3167. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3168. }
  3169. }
  3170. }
  3171. catch(...)
  3172. {
  3173. if (!RootTempDir.IsEmpty())
  3174. {
  3175. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3176. }
  3177. throw;
  3178. }
  3179. }
  3180. __finally
  3181. {
  3182. FAutoOperation = false;
  3183. Terminal->ExceptionOnFail = false;
  3184. }
  3185. }
  3186. //---------------------------------------------------------------------------
  3187. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3188. {
  3189. // Do not waste time checking for default editor list the next time,
  3190. // or testing if default editor is not notepad.
  3191. bool TryNextTime = false;
  3192. UnicodeString UsageState;
  3193. if (!WinConfiguration->EditorList->IsDefaultList())
  3194. {
  3195. UsageState = "H";
  3196. }
  3197. else
  3198. {
  3199. UnicodeString Executable;
  3200. UnicodeString ExecutableDescription;
  3201. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3202. {
  3203. UnicodeString Message =
  3204. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3205. unsigned int Answer =
  3206. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3207. if (Answer != qaOK)
  3208. {
  3209. UsageState = "R";
  3210. }
  3211. else
  3212. {
  3213. UsageState = "A";
  3214. TEditorData EditorData;
  3215. EditorData.Editor = edExternal;
  3216. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3217. EditorData.ExternalEditorOptionsAutodetect();
  3218. TEditorList EditorList;
  3219. EditorList = *WinConfiguration->EditorList;
  3220. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3221. WinConfiguration->EditorList = &EditorList;
  3222. }
  3223. }
  3224. }
  3225. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3226. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3227. }
  3228. //---------------------------------------------------------------------------
  3229. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3230. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3231. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3232. {
  3233. if (ExecuteFileBy == efDefaultEditor)
  3234. {
  3235. if (!WinConfiguration->OfferedEditorAutoConfig)
  3236. {
  3237. EditorAutoConfig();
  3238. }
  3239. const TEditorPreferences * Editor =
  3240. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3241. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3242. {
  3243. ExecuteFileBy = efInternalEditor;
  3244. ExternalEditor = NULL;
  3245. }
  3246. else if (Editor->Data->Editor == edOpen)
  3247. {
  3248. ExecuteFileBy = efShell;
  3249. ExternalEditor = NULL;
  3250. }
  3251. else
  3252. {
  3253. ExecuteFileBy = efExternalEditor;
  3254. ExternalEditor = Editor->Data;
  3255. }
  3256. }
  3257. }
  3258. //---------------------------------------------------------------------------
  3259. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3260. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3261. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3262. {
  3263. UnicodeString OriginalFileName;
  3264. UnicodeString LocalRootDirectory;
  3265. UnicodeString RemoteDirectory;
  3266. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3267. IsSideLocalBrowser(Side), MaskParams);
  3268. UnicodeString Counter;
  3269. UnicodeString LocalFileName;
  3270. bool Handled = false;
  3271. if (!IsSideLocalBrowser(Side))
  3272. {
  3273. // We need to trim VMS version here, so that we use name without version
  3274. // when uploading back to create a new version of the file
  3275. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3276. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3277. TObject * Token = NULL;
  3278. UnicodeString LocalDirectory;
  3279. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3280. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3281. LocalDirectory))
  3282. {
  3283. if (Token != NULL)
  3284. {
  3285. TForm * Form = dynamic_cast<TForm *>(Token);
  3286. if (Form->WindowState == wsMinimized)
  3287. {
  3288. ShowWindow(Form->Handle, SW_RESTORE);
  3289. }
  3290. else
  3291. {
  3292. Form->SetFocus();
  3293. }
  3294. Handled = true;
  3295. }
  3296. else
  3297. {
  3298. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3299. }
  3300. }
  3301. if (!Handled)
  3302. {
  3303. TStringList * FileList1 = new TStringList();
  3304. try
  3305. {
  3306. FileList1->AddObject(FullFileName, Object);
  3307. TemporarilyDownloadFiles(FileList1,
  3308. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3309. LocalRootDirectory, LocalDirectory, true, true, true);
  3310. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3311. }
  3312. __finally
  3313. {
  3314. delete FileList1;
  3315. }
  3316. switch (ExecuteFileBy)
  3317. {
  3318. case efShell:
  3319. Counter = "RemoteFilesExecuted";
  3320. break;
  3321. case efInternalEditor:
  3322. Counter = "RemoteFilesOpenedInInternalEditor";
  3323. break;
  3324. case efExternalEditor:
  3325. Counter = "RemoteFilesOpenedInExternalEditor";
  3326. break;
  3327. default:
  3328. DebugFail();
  3329. }
  3330. }
  3331. }
  3332. else
  3333. {
  3334. LocalFileName = FullFileName;
  3335. OriginalFileName = ExtractFileName(FullFileName);
  3336. switch (ExecuteFileBy)
  3337. {
  3338. case efShell:
  3339. Counter = "LocalFilesExecuted";
  3340. break;
  3341. case efInternalEditor:
  3342. Counter = "LocalFilesOpenedInInternalEditor";
  3343. break;
  3344. case efExternalEditor:
  3345. Counter = "LocalFilesOpenedInExternalEditor";
  3346. break;
  3347. default:
  3348. DebugFail();
  3349. }
  3350. }
  3351. if (!Handled)
  3352. {
  3353. Configuration->Usage->Inc(Counter);
  3354. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3355. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3356. }
  3357. }
  3358. //---------------------------------------------------------------------------
  3359. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3360. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3361. bool AllSelected, bool OnFocused)
  3362. {
  3363. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3364. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3365. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3366. Side = GetSide(Side);
  3367. TCustomDirView * DView = DirView(Side);
  3368. TStrings * FileList =
  3369. AllSelected ?
  3370. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3371. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3372. try
  3373. {
  3374. DebugAssert(AllSelected || (FileList->Count == 1));
  3375. for (int i = 0; i < FileList->Count; i++)
  3376. {
  3377. UnicodeString ListFileName = FileList->Strings[i];
  3378. UnicodeString FileNameOnly =
  3379. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3380. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3381. if (!DView->ItemIsDirectory(Item))
  3382. {
  3383. UnicodeString FullFileName;
  3384. if (!IsSideLocalBrowser(Side))
  3385. {
  3386. FullFileName = DirView(Side)->Path + ListFileName;
  3387. }
  3388. else
  3389. {
  3390. FullFileName = ListFileName;
  3391. }
  3392. TFileMasks::TParams MaskParams;
  3393. MaskParams.Size = DView->ItemFileSize(Item);
  3394. TDateTimePrecision Precision;
  3395. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3396. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3397. FileList->Objects[i], MaskParams);
  3398. }
  3399. }
  3400. }
  3401. __finally
  3402. {
  3403. delete FileList;
  3404. }
  3405. }
  3406. //---------------------------------------------------------------------------
  3407. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3408. {
  3409. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3410. CopyParam.FileNameCase = ncNoChange;
  3411. CopyParam.PreserveRights = false;
  3412. CopyParam.PreserveReadOnly = false;
  3413. CopyParam.ReplaceInvalidChars = true;
  3414. CopyParam.IncludeFileMask = TFileMasks();
  3415. CopyParam.NewerOnly = false;
  3416. CopyParam.FileMask = L"";
  3417. }
  3418. //---------------------------------------------------------------------------
  3419. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3420. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3421. {
  3422. TTerminalManager * Manager = TTerminalManager::Instance();
  3423. if (!IsActiveTerminal(Data->Terminal))
  3424. {
  3425. if (!NonVisualDataModule->Busy)
  3426. {
  3427. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3428. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3429. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3430. if (Data->Terminal == NULL)
  3431. {
  3432. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3433. if (SameSiteTerminal != NULL)
  3434. {
  3435. UnicodeString Message =
  3436. FMTLOAD(EDIT_SESSION_REATTACH,
  3437. (FileNameOnly, Data->SessionName, FileNameOnly));
  3438. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3439. {
  3440. Data->Terminal = Terminal;
  3441. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3442. Data->SessionName = Terminal->SessionData->SessionName;
  3443. // We might also overwrite session data
  3444. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3445. }
  3446. else
  3447. {
  3448. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3449. Abort();
  3450. }
  3451. }
  3452. }
  3453. // foreground session should reconnect itself
  3454. else if (Terminal != Data->Terminal)
  3455. {
  3456. UnicodeString Message =
  3457. MainInstructions(
  3458. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3459. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3460. {
  3461. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3462. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3463. }
  3464. else
  3465. {
  3466. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3467. Abort();
  3468. }
  3469. }
  3470. }
  3471. if (!IsActiveTerminal(Data->Terminal))
  3472. {
  3473. Configuration->Usage->Inc(L"EditInactiveSession");
  3474. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3475. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3476. (ExtractFileName(FileName), Data->SessionName)));
  3477. }
  3478. }
  3479. TStrings * FileList = new TStringList();
  3480. try
  3481. {
  3482. FileList->Add(FileName);
  3483. // consider using the same settings (preset) as when the file was downloaded
  3484. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3485. TemporaryFileCopyParam(CopyParam);
  3486. if (Data->ForceText)
  3487. {
  3488. CopyParam.TransferMode = tmAscii;
  3489. }
  3490. // so i do not need to worry if masking algorithm works in all cases
  3491. // ("" means "copy file name", no masking is actually done)
  3492. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3493. {
  3494. CopyParam.FileMask = L"";
  3495. }
  3496. else
  3497. {
  3498. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3499. }
  3500. DebugAssert(Data->Queue != NULL);
  3501. int Params = cpNoConfirmation | cpTemporary;
  3502. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3503. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3504. QueueItem->CompleteEvent = UploadCompleteEvent;
  3505. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3506. }
  3507. __finally
  3508. {
  3509. delete FileList;
  3510. }
  3511. }
  3512. //---------------------------------------------------------------------------
  3513. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3514. const UnicodeString FileName, const TEditedFileData * Data)
  3515. {
  3516. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3517. DebugAssert(!NonVisualDataModule->Busy);
  3518. if (!IsActiveTerminal(Data->Terminal))
  3519. {
  3520. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3521. (ExtractFileName(FileName), Data->SessionName)));
  3522. }
  3523. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3524. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3525. NonVisualDataModule->StartBusy();
  3526. try
  3527. {
  3528. std::unique_ptr<TRemoteFile> File;
  3529. UnicodeString RemoteFileName =
  3530. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3531. FTerminal->ExceptionOnFail = true;
  3532. try
  3533. {
  3534. TRemoteFile * AFile = NULL;
  3535. FTerminal->ReadFile(RemoteFileName, AFile);
  3536. File.reset(AFile);
  3537. if (!File->HaveFullFileName)
  3538. {
  3539. File->FullFileName = RemoteFileName;
  3540. }
  3541. }
  3542. __finally
  3543. {
  3544. FTerminal->ExceptionOnFail = false;
  3545. }
  3546. std::unique_ptr<TStrings> FileList(new TStringList());
  3547. FileList->AddObject(RemoteFileName, File.get());
  3548. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3549. UnicodeString TempDir = ExtractFilePath(FileName);
  3550. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3551. TempDir, true, true, true);
  3552. // sanity check, the target file name should be still the same
  3553. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3554. }
  3555. __finally
  3556. {
  3557. NonVisualDataModule->EndBusy();
  3558. // it actually may not exist anymore...
  3559. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3560. }
  3561. }
  3562. //---------------------------------------------------------------------------
  3563. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3564. const TEditedFileData * Data, bool & KeepOpen)
  3565. {
  3566. // Command is set for external editors only (not for "shell" open).
  3567. if (!Data->Command.IsEmpty())
  3568. {
  3569. bool AnyFound = false;
  3570. bool AnyMDI = false;
  3571. bool AnyNonMDI = false;
  3572. bool AnyDetect = false;
  3573. TEditorList * EditorList = new TEditorList();
  3574. try
  3575. {
  3576. *EditorList = *WinConfiguration->EditorList;
  3577. for (int i = 0; i < EditorList->Count; i++)
  3578. {
  3579. const TEditorPreferences * Editor = EditorList->Editors[i];
  3580. if ((Editor->Data->Editor == edExternal) &&
  3581. (Editor->Data->ExternalEditor == Data->Command))
  3582. {
  3583. AnyFound = true;
  3584. if (Editor->Data->SDIExternalEditor)
  3585. {
  3586. AnyNonMDI = true;
  3587. if (Editor->Data->DetectMDIExternalEditor)
  3588. {
  3589. AnyDetect = true;
  3590. }
  3591. }
  3592. else
  3593. {
  3594. AnyMDI = true;
  3595. }
  3596. }
  3597. }
  3598. bool EnableMDI = false;
  3599. bool DisableDetect = false;
  3600. if (AnyMDI)
  3601. {
  3602. KeepOpen = true;
  3603. if (AnyNonMDI)
  3604. {
  3605. // there is at least one instance of the editor with MDI support enabled,
  3606. // and one with disabled, enable it for all instances
  3607. EnableMDI = true;
  3608. }
  3609. }
  3610. else if (AnyFound && !AnyDetect)
  3611. {
  3612. // at least once instance found but all have MDI autodetection disabled
  3613. // => close the file (default action)
  3614. }
  3615. else
  3616. {
  3617. // no instance of the editor has MDI support enabled
  3618. TMessageParams Params;
  3619. if (AnyFound)
  3620. {
  3621. // there is at least one instance of the editor
  3622. Params.Params |= mpNeverAskAgainCheck;
  3623. }
  3624. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3625. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3626. switch (Answer)
  3627. {
  3628. case qaNeverAskAgain:
  3629. DisableDetect = true;
  3630. break;
  3631. case qaNo:
  3632. EnableMDI = true;
  3633. KeepOpen = true;
  3634. break;
  3635. }
  3636. }
  3637. if (AnyFound && (EnableMDI || DisableDetect))
  3638. {
  3639. bool Changed = false;
  3640. for (int i = 0; i < EditorList->Count; i++)
  3641. {
  3642. const TEditorPreferences * Editor = EditorList->Editors[i];
  3643. if ((Editor->Data->Editor == edExternal) &&
  3644. (Editor->Data->ExternalEditor == Data->Command) &&
  3645. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3646. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3647. {
  3648. Changed = true;
  3649. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3650. if (EnableMDI)
  3651. {
  3652. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3653. }
  3654. if (DisableDetect)
  3655. {
  3656. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3657. }
  3658. EditorList->Change(i, UpdatedEditor);
  3659. }
  3660. }
  3661. if (Changed)
  3662. {
  3663. WinConfiguration->EditorList = EditorList;
  3664. }
  3665. }
  3666. }
  3667. __finally
  3668. {
  3669. delete EditorList;
  3670. }
  3671. }
  3672. else
  3673. {
  3674. // "open" case
  3675. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3676. qaOK, HELP_APP_EARLY_CLOSED);
  3677. }
  3678. }
  3679. //---------------------------------------------------------------------------
  3680. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3681. {
  3682. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3683. }
  3684. //---------------------------------------------------------------------------
  3685. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3686. {
  3687. SideEnter(osRemote);
  3688. }
  3689. //---------------------------------------------------------------------------
  3690. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3691. {
  3692. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3693. SideEnter(osRemote);
  3694. }
  3695. //---------------------------------------------------------------------------
  3696. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3697. {
  3698. FCurrentSide = Side;
  3699. if (Visible)
  3700. {
  3701. UpdateControls();
  3702. }
  3703. }
  3704. //---------------------------------------------------------------------------
  3705. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3706. TStrings * FileList, bool Alternative)
  3707. {
  3708. TCustomDirView * DView = DirView(Side);
  3709. DView->SaveSelection();
  3710. DView->SaveSelectedNames();
  3711. DebugAssert(!FAlternativeDelete);
  3712. FAlternativeDelete = Alternative;
  3713. try
  3714. {
  3715. if (!IsSideLocalBrowser(Side))
  3716. {
  3717. DebugAssert(Terminal != NULL);
  3718. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3719. }
  3720. else
  3721. {
  3722. if (IsLocalBrowserMode())
  3723. {
  3724. Configuration->Usage->Inc(L"LocalLocalDeletes");
  3725. }
  3726. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  3727. FProgressSide = FCurrentSide;
  3728. try
  3729. {
  3730. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3731. }
  3732. __finally
  3733. {
  3734. ReloadLocalDirectory();
  3735. }
  3736. }
  3737. FAlternativeDelete = false;
  3738. }
  3739. catch(...)
  3740. {
  3741. FAlternativeDelete = false;
  3742. DView->DiscardSavedSelection();
  3743. throw;
  3744. }
  3745. DView->RestoreSelection();
  3746. }
  3747. //---------------------------------------------------------------------------
  3748. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3749. {
  3750. DebugAssert(Terminal);
  3751. DebugAssert(!IsLocalBrowserMode());
  3752. RemoteDirView->SaveSelection();
  3753. RemoteDirView->SaveSelectedNames();
  3754. try
  3755. {
  3756. if (Lock)
  3757. {
  3758. Terminal->LockFiles(FileList);
  3759. }
  3760. else
  3761. {
  3762. Terminal->UnlockFiles(FileList);
  3763. }
  3764. }
  3765. catch(...)
  3766. {
  3767. RemoteDirView->DiscardSavedSelection();
  3768. throw;
  3769. }
  3770. RemoteDirView->RestoreSelection();
  3771. }
  3772. //---------------------------------------------------------------------------
  3773. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3774. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3775. bool NoConfirmation, bool Move)
  3776. {
  3777. DebugAssert(Terminal != NULL);
  3778. DebugAssert(!IsLocalBrowserMode());
  3779. // update Terminal->StateData->RemoteDirectory
  3780. UpdateTerminal(Terminal);
  3781. if (Session == NULL)
  3782. {
  3783. Session = TTerminalManager::Instance()->ActiveTerminal;
  3784. }
  3785. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3786. {
  3787. if (RemoteDriveView->DropTarget != NULL)
  3788. {
  3789. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3790. }
  3791. else if (RemoteDirView->DropTarget != NULL)
  3792. {
  3793. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3794. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3795. }
  3796. else
  3797. {
  3798. Target = RemoteDirView->Path;
  3799. }
  3800. }
  3801. else
  3802. {
  3803. Target = Session->StateData->RemoteDirectory;
  3804. }
  3805. Target = UnixIncludeTrailingBackslash(Target);
  3806. if (FileList->Count == 1)
  3807. {
  3808. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3809. }
  3810. else
  3811. {
  3812. FileMask = AnyMask;
  3813. }
  3814. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3815. bool Result = true;
  3816. if (!NoConfirmation)
  3817. {
  3818. bool Multi = (FileList->Count > 1);
  3819. if (Move)
  3820. {
  3821. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3822. }
  3823. else
  3824. {
  3825. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3826. TStrings * Directories = new TStringList;
  3827. try
  3828. {
  3829. for (int Index = 0; Index < Sessions->Count; Index++)
  3830. {
  3831. TManagedTerminal * Terminal =
  3832. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3833. Directories->Add(Terminal->StateData->RemoteDirectory);
  3834. }
  3835. TDirectRemoteCopy AllowDirectCopy;
  3836. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3837. {
  3838. DebugAssert(DirectCopy);
  3839. AllowDirectCopy = drcAllow;
  3840. }
  3841. else if (FTerminal->IsCapable[fcSecondaryShell])
  3842. {
  3843. DebugAssert(DirectCopy);
  3844. AllowDirectCopy = drcConfirmCommandSession;
  3845. }
  3846. else
  3847. {
  3848. DebugAssert(!DirectCopy);
  3849. AllowDirectCopy = drcDisallow;
  3850. }
  3851. void * ASession = Session;
  3852. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3853. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3854. Session = static_cast<TManagedTerminal *>(ASession);
  3855. }
  3856. __finally
  3857. {
  3858. delete Directories;
  3859. }
  3860. }
  3861. }
  3862. return Result;
  3863. }
  3864. //---------------------------------------------------------------------------
  3865. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3866. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3867. {
  3868. DebugAssert(!IsLocalBrowserMode());
  3869. bool DirectCopy;
  3870. UnicodeString Target, FileMask;
  3871. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3872. if (Result)
  3873. {
  3874. if (!Move && !DirectCopy)
  3875. {
  3876. Configuration->Usage->Inc("RemoteCopyTemp");
  3877. UnicodeString RootTempDir;
  3878. UnicodeString TempDir;
  3879. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3880. TStrings * TemporaryFilesList = new TStringList();
  3881. try
  3882. {
  3883. TMakeLocalFileListParams MakeFileListParam;
  3884. MakeFileListParam.FileList = TemporaryFilesList;
  3885. MakeFileListParam.FileTimes = NULL;
  3886. MakeFileListParam.IncludeDirs = true;
  3887. MakeFileListParam.Recursive = false;
  3888. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3889. TTerminalManager::Instance()->ActiveTerminal = Session;
  3890. if (TemporaryFilesList->Count > 0)
  3891. {
  3892. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3893. CopyParam.FileMask = FileMask;
  3894. DebugAssert(!FAutoOperation);
  3895. FAutoOperation = true;
  3896. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3897. }
  3898. }
  3899. __finally
  3900. {
  3901. delete TemporaryFilesList;
  3902. FAutoOperation = false;
  3903. if (!RootTempDir.IsEmpty())
  3904. {
  3905. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3906. }
  3907. }
  3908. }
  3909. else
  3910. {
  3911. RemoteDirView->SaveSelection();
  3912. RemoteDirView->SaveSelectedNames();
  3913. try
  3914. {
  3915. if (Move)
  3916. {
  3917. Configuration->Usage->Inc("RemoteMove");
  3918. Terminal->MoveFiles(FileList, Target, FileMask);
  3919. }
  3920. else
  3921. {
  3922. Configuration->Usage->Inc("RemoteCopyDirect");
  3923. DebugAssert(DirectCopy);
  3924. DebugAssert(Session == FTerminal);
  3925. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3926. FTerminal->CommandSessionOpened ||
  3927. CommandSessionFallback())
  3928. {
  3929. Terminal->CopyFiles(FileList, Target, FileMask);
  3930. }
  3931. }
  3932. }
  3933. catch(...)
  3934. {
  3935. RemoteDirView->DiscardSavedSelection();
  3936. throw;
  3937. }
  3938. RemoteDirView->RestoreSelection();
  3939. }
  3940. }
  3941. return Result;
  3942. }
  3943. //---------------------------------------------------------------------------
  3944. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3945. const UnicodeString & Path, TRemoteProperties & Properties)
  3946. {
  3947. DebugAssert(!IsLocalBrowserMode());
  3948. Properties.Valid = Properties.Valid << vpEncrypt;
  3949. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3950. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3951. }
  3952. //---------------------------------------------------------------------------
  3953. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3954. {
  3955. Side = GetSide(Side);
  3956. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3957. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3958. UnicodeString Name = LoadStr(NEW_FOLDER);
  3959. int AllowedChanges =
  3960. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3961. bool SaveSettings = false;
  3962. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3963. {
  3964. TWindowLock Lock(this);
  3965. if (!IsSideLocalBrowser(Side))
  3966. {
  3967. if (SaveSettings)
  3968. {
  3969. GUIConfiguration->NewDirectoryProperties = Properties;
  3970. }
  3971. CreateRemoteDirectory(Name, Properties);
  3972. }
  3973. else
  3974. {
  3975. DirView(Side)->CreateDirectory(Name);
  3976. }
  3977. }
  3978. }
  3979. //---------------------------------------------------------------------------
  3980. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3981. {
  3982. TWindowLock Lock(this);
  3983. DirView(Side)->ExecuteHomeDirectory();
  3984. }
  3985. //---------------------------------------------------------------------------
  3986. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3987. {
  3988. DoOpenDirectoryDialog(odBrowse, Side);
  3989. }
  3990. //---------------------------------------------------------------------------
  3991. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3992. {
  3993. TOperationSide BookmarkSide = IsLocalBrowserMode() ? osLocal : Side;
  3994. UnicodeString Path = Bookmark->GetSideDirectory(BookmarkSide);
  3995. bool Result = !Path.IsEmpty();
  3996. if (Result)
  3997. {
  3998. // While we might get here when the session is closed (from location profiles),
  3999. // it's not a problem as the Path setter is noop then
  4000. DirView(Side)->Path = Path;
  4001. }
  4002. return Result;
  4003. }
  4004. //---------------------------------------------------------------------------
  4005. void __fastcall TCustomScpExplorerForm::CalculateSize(
  4006. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  4007. bool & Close)
  4008. {
  4009. // terminal can be already closed (e.g. dropped connection)
  4010. if (Terminal != NULL)
  4011. {
  4012. try
  4013. {
  4014. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  4015. }
  4016. catch(...)
  4017. {
  4018. if (!Terminal->Active)
  4019. {
  4020. Close = true;
  4021. }
  4022. throw;
  4023. }
  4024. }
  4025. }
  4026. //---------------------------------------------------------------------------
  4027. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4028. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4029. bool & Close)
  4030. {
  4031. // terminal can be already closed (e.g. dropped connection)
  4032. if (Terminal != NULL)
  4033. {
  4034. Configuration->Usage->Inc(L"ChecksumCalculated");
  4035. try
  4036. {
  4037. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4038. }
  4039. catch(...)
  4040. {
  4041. if (!Terminal->Active)
  4042. {
  4043. Close = true;
  4044. }
  4045. throw;
  4046. }
  4047. }
  4048. }
  4049. //---------------------------------------------------------------------------
  4050. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4051. {
  4052. bool Result;
  4053. if (!IsSideLocalBrowser(Side))
  4054. {
  4055. TRemoteTokenList * GroupList = NULL;
  4056. TRemoteTokenList * UserList = NULL;
  4057. try
  4058. {
  4059. TRemoteProperties CurrentProperties;
  4060. if (Terminal->LoadFilesProperties(FileList))
  4061. {
  4062. RemoteDirView->Invalidate();
  4063. }
  4064. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4065. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4066. if (CapableGroupChanging || CapableOwnerChanging)
  4067. {
  4068. if (CapableGroupChanging)
  4069. {
  4070. GroupList = Terminal->Groups->Duplicate();
  4071. }
  4072. if (CapableOwnerChanging)
  4073. {
  4074. UserList = Terminal->Users->Duplicate();
  4075. }
  4076. TRemoteDirectory * Files = Terminal->Files;
  4077. int Count = Files->Count;
  4078. if (Count > 100)
  4079. {
  4080. Count = 100;
  4081. }
  4082. for (int Index = 0; Index < Count; Index++)
  4083. {
  4084. TRemoteFile * File = Files->Files[Index];
  4085. if (CapableGroupChanging)
  4086. {
  4087. GroupList->AddUnique(File->Group);
  4088. }
  4089. if (CapableOwnerChanging)
  4090. {
  4091. UserList->AddUnique(File->Owner);
  4092. }
  4093. }
  4094. // if we haven't collected tokens for all files in current directory,
  4095. // make sure we collect them at least for all selected files.
  4096. // (note that so far the files in FileList has to be from current direcotry)
  4097. if (Count < Files->Count)
  4098. {
  4099. for (int Index = 0; Index < FileList->Count; Index++)
  4100. {
  4101. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4102. if (CapableGroupChanging)
  4103. {
  4104. GroupList->AddUnique(File->Group);
  4105. }
  4106. if (CapableOwnerChanging)
  4107. {
  4108. UserList->AddUnique(File->Owner);
  4109. }
  4110. }
  4111. }
  4112. }
  4113. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4114. int Flags = 0;
  4115. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4116. if (CapableOwnerChanging) Flags |= cpOwner;
  4117. if (CapableGroupChanging) Flags |= cpGroup;
  4118. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4119. if (Terminal->IsCapable[fcCalculatingChecksum])
  4120. {
  4121. CalculateChecksumEvent = CalculateChecksum;
  4122. }
  4123. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4124. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4125. TRemoteProperties NewProperties = CurrentProperties;
  4126. Result =
  4127. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4128. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4129. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4130. CalculateSize, CalculateChecksumEvent);
  4131. if (Result)
  4132. {
  4133. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4134. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4135. }
  4136. }
  4137. __finally
  4138. {
  4139. delete GroupList;
  4140. delete UserList;
  4141. }
  4142. }
  4143. else
  4144. {
  4145. DirView(Side)->DisplayPropertiesMenu();
  4146. Result = true;
  4147. }
  4148. return Result;
  4149. }
  4150. //---------------------------------------------------------------------------
  4151. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4152. {
  4153. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4154. {
  4155. FIgnoreNextDialogChar = Key;
  4156. }
  4157. Key = 0;
  4158. }
  4159. //---------------------------------------------------------------------------
  4160. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4161. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4162. {
  4163. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4164. if (Command != NULL)
  4165. {
  4166. KeyProcessed(Key, Shift);
  4167. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4168. {
  4169. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4170. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4171. false, false, const_cast<TCustomCommandType *>(Command));
  4172. }
  4173. }
  4174. }
  4175. //---------------------------------------------------------------------------
  4176. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4177. {
  4178. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4179. {
  4180. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4181. }
  4182. if (!DirView(osCurrent)->IsEditing())
  4183. {
  4184. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4185. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4186. {
  4187. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4188. // But so far it's not a problem, as it does what we want.
  4189. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4190. if (((Action->ShortCut == KeyShortCut) ||
  4191. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4192. AllowedAction(Action, aaShortCut))
  4193. {
  4194. // Has to be called before the action as the dialog char is already in queue.
  4195. // So when the action consumes message queue, we already need to have the
  4196. // FIgnoreNextDialogChar set
  4197. KeyProcessed(Key, Shift);
  4198. // Reset reference to previous component (when menu/toolbar was clicked).
  4199. // Needed to detect that action was invoked by keyboard shortcut
  4200. // in TNonVisualDataModule::ExplorerActionsExecute
  4201. Action->ActionComponent = NULL;
  4202. Action->Execute();
  4203. return;
  4204. }
  4205. }
  4206. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4207. {
  4208. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4209. {
  4210. KeyProcessed(Key, Shift);
  4211. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4212. return;
  4213. }
  4214. }
  4215. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4216. {
  4217. KeyProcessed(Key, Shift);
  4218. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4219. }
  4220. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4221. if (IsCustomShortCut(CustomShortCut))
  4222. {
  4223. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4224. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4225. if (WinConfiguration->SharedBookmarks != NULL)
  4226. {
  4227. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4228. if ((Bookmark != NULL) &&
  4229. OpenBookmark(FCurrentSide, Bookmark))
  4230. {
  4231. KeyProcessed(Key, Shift);
  4232. }
  4233. }
  4234. }
  4235. }
  4236. TForm::KeyDown(Key, Shift);
  4237. }
  4238. //---------------------------------------------------------------------------
  4239. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4240. {
  4241. bool OpenedTerminal = false;
  4242. UnicodeString ProtocolName;
  4243. UnicodeString ProtocolNameHint;
  4244. UnicodeString SecurityProtocolName;
  4245. UnicodeString DurationHint;
  4246. // See the comment in TScpCommanderForm::UpdateControls()
  4247. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4248. if (ActiveTerminal != NULL)
  4249. {
  4250. // Active is not enough here
  4251. if (ActiveTerminal->Status == ssOpened)
  4252. {
  4253. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4254. const TFileSystemInfo & FileSystemInfo = ActiveTerminal->GetFileSystemInfo();
  4255. if (FileSystemInfo.ProtocolName.IsEmpty())
  4256. {
  4257. ProtocolName = SessionInfo.ProtocolName;
  4258. }
  4259. else
  4260. {
  4261. ProtocolName = FileSystemInfo.ProtocolName;
  4262. }
  4263. ProtocolNameHint = LoadStr(STATUS_PROTOCOL_HINT);
  4264. SecurityProtocolName = SessionInfo.SecurityProtocolName;
  4265. DurationHint = LoadStr(STATUS_DURATION_HINT);
  4266. OpenedTerminal = true;
  4267. }
  4268. else if (ActiveTerminal->Status > ssClosed)
  4269. {
  4270. ProtocolName = LoadStr(STATUS_CONNECTING);
  4271. }
  4272. else
  4273. {
  4274. ProtocolName = LoadStr(STATUS_NOT_CONNECTED2);
  4275. }
  4276. }
  4277. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4278. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4279. TTBXStatusPanel * ProtocolStatusPanel = SessionStatusBar->Panels->Items[Offset + 0];
  4280. ProtocolStatusPanel->ViewPriority = (ActiveTerminal != NULL) ? 100 : 0;
  4281. if (ProtocolStatusPanel->Caption != ProtocolName)
  4282. {
  4283. ProtocolStatusPanel->Caption = ProtocolName;
  4284. std::unique_ptr<TCanvas> Canvas(CreateControlCanvas(SessionStatusBar));
  4285. ProtocolStatusPanel->Size = Canvas->TextWidth(ProtocolName) + ScaleByTextHeight(SessionStatusBar, 32);
  4286. }
  4287. ProtocolStatusPanel->Hint = ProtocolNameHint;
  4288. TTBXStatusPanel * SecurityStatusPanel = SessionStatusBar->Panels->Items[Offset + 1];
  4289. SecurityStatusPanel->ViewPriority = OpenedTerminal ? 98 : 0;
  4290. bool SecurityEnabled = !SecurityProtocolName.IsEmpty();
  4291. SecurityStatusPanel->Enabled = SecurityEnabled;
  4292. UnicodeString SecurityProtocolHint;
  4293. if (SecurityEnabled)
  4294. {
  4295. SecurityProtocolHint = FMTLOAD(STATUS_SECURE, (SecurityProtocolName));
  4296. }
  4297. else
  4298. {
  4299. SecurityProtocolHint = LoadStr(STATUS_INSECURE);
  4300. }
  4301. SecurityStatusPanel->Hint = SecurityProtocolHint;
  4302. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[Offset + 2];
  4303. DurationStatusPanel->ViewPriority = OpenedTerminal ? 99 : 0;
  4304. DurationStatusPanel->Hint = DurationHint;
  4305. UpdateStatusBar();
  4306. }
  4307. //---------------------------------------------------------------------------
  4308. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4309. {
  4310. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4311. DebugAssert(SessionStatusBar != NULL);
  4312. TTBXStatusPanel * NoteStatusPanel = SessionStatusBar->Panels->Items[0];
  4313. if (!FNote.IsEmpty())
  4314. {
  4315. NoteStatusPanel->Caption = FNote;
  4316. }
  4317. else
  4318. {
  4319. UpdateStatusPanelText(NoteStatusPanel);
  4320. }
  4321. NoteStatusPanel->Hint = FNoteHints;
  4322. UnicodeString LoginTime;
  4323. // See the comment in TScpCommanderForm::UpdateControls()
  4324. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4325. // Active is not enough here
  4326. if ((ActiveTerminal != NULL) && (ActiveTerminal->Status == ssOpened))
  4327. {
  4328. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4329. LoginTime = FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4330. }
  4331. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1];
  4332. DurationStatusPanel->Caption = LoginTime;
  4333. }
  4334. //---------------------------------------------------------------------------
  4335. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4336. {
  4337. Panel->Caption = L"";
  4338. }
  4339. //---------------------------------------------------------------------------
  4340. void __fastcall TCustomScpExplorerForm::Idle()
  4341. {
  4342. if (FShowing || FStandaloneEditing)
  4343. {
  4344. FEditorManager->Check();
  4345. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4346. // that needs to know if queue view is visible (and it may be closed after queue update)
  4347. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4348. }
  4349. if (FShowing)
  4350. {
  4351. if (!NonVisualDataModule->Busy &&
  4352. // Menu is opened or drag&drop is going on
  4353. (Mouse->Capture == NULL))
  4354. {
  4355. if (FRefreshRemoteDirectory)
  4356. {
  4357. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4358. {
  4359. Terminal->RefreshDirectory();
  4360. }
  4361. FRefreshRemoteDirectory = false;
  4362. }
  4363. if (FRefreshLocalDirectory)
  4364. {
  4365. ReloadLocalDirectory();
  4366. FRefreshLocalDirectory = false;
  4367. }
  4368. if (WinConfiguration->RefreshRemotePanel)
  4369. {
  4370. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4371. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4372. {
  4373. RemoteDirView->ReloadDirectory();
  4374. }
  4375. }
  4376. if (!FStarted)
  4377. {
  4378. FStarted = true;
  4379. InterfaceStarted();
  4380. }
  4381. }
  4382. }
  4383. if (FShowing || FStandaloneEditing)
  4384. {
  4385. if (FQueueStatusInvalidated)
  4386. {
  4387. UpdateQueueStatus(false);
  4388. }
  4389. RefreshQueueItems();
  4390. }
  4391. if (FShowing)
  4392. {
  4393. UpdateStatusBar();
  4394. }
  4395. FIgnoreNextDialogChar = 0;
  4396. }
  4397. //---------------------------------------------------------------------------
  4398. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4399. {
  4400. try
  4401. {
  4402. FUserActionTimer->Enabled = false;
  4403. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4404. {
  4405. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4406. {
  4407. FPendingQueueActionItem->ProcessUserAction();
  4408. }
  4409. }
  4410. }
  4411. __finally
  4412. {
  4413. FPendingQueueActionItem = NULL;
  4414. }
  4415. }
  4416. //---------------------------------------------------------------------------
  4417. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4418. {
  4419. if (WinConfiguration->MinimizeToTray)
  4420. {
  4421. UpdateTrayIcon();
  4422. FTrayIcon->Visible = true;
  4423. if (Visible)
  4424. {
  4425. ShowWindow(Handle, SW_HIDE);
  4426. }
  4427. }
  4428. }
  4429. //---------------------------------------------------------------------------
  4430. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4431. {
  4432. // WORKAROUND
  4433. // When restoring maximized window from minimization,
  4434. // rarely some controls do not align properly.
  4435. // Two instances seen (both for Commander):
  4436. // - When restoring, window is temporarily narrower (not maximized),
  4437. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4438. // Once maximized already, top dock shinks back, but the session PageControl,
  4439. // do not align up, leaving space between TopDock and PageControl.
  4440. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4441. for (int Index = 0; Index < ControlCount; Index++)
  4442. {
  4443. RealignControl(Controls[Index]);
  4444. }
  4445. if (FTrayIcon->Visible)
  4446. {
  4447. FTrayIcon->Visible = false;
  4448. if (Visible)
  4449. {
  4450. ShowWindow(Handle, SW_SHOW);
  4451. }
  4452. }
  4453. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4454. {
  4455. FNeedSession = false;
  4456. NonVisualDataModule->StartBusy();
  4457. try
  4458. {
  4459. NeedSession(true);
  4460. }
  4461. __finally
  4462. {
  4463. NonVisualDataModule->EndBusy();
  4464. }
  4465. }
  4466. }
  4467. //---------------------------------------------------------------------------
  4468. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4469. {
  4470. FTrayIcon->Hint = GetMainForm()->Caption;
  4471. }
  4472. //---------------------------------------------------------------------------
  4473. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4474. {
  4475. UpdateTrayIcon();
  4476. }
  4477. //---------------------------------------------------------------------------
  4478. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4479. {
  4480. // workaround
  4481. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4482. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4483. // But WM_ACTIVATEAPP message can be received even when
  4484. // the main window is minimized to the tray and internal editor window is focused
  4485. // (after another application was previously active)
  4486. if (::IsIconic(Handle))
  4487. {
  4488. if (!IsAppIconic())
  4489. {
  4490. SetAppIconic(true);
  4491. }
  4492. }
  4493. ::ApplicationRestore();
  4494. Application->BringToFront();
  4495. }
  4496. //---------------------------------------------------------------------------
  4497. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4498. {
  4499. RestoreApp();
  4500. }
  4501. //---------------------------------------------------------------------------
  4502. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4503. {
  4504. if (OpenInNewWindow())
  4505. {
  4506. // todo: Pass FromSite
  4507. ExecuteNewInstance(SessionUrl);
  4508. }
  4509. else
  4510. {
  4511. TTerminalManager::Instance()->NewSession(SessionUrl);
  4512. }
  4513. }
  4514. //---------------------------------------------------------------------------
  4515. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4516. {
  4517. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4518. StoredSessions->NewSession(SessionName, SessionData);
  4519. // modified only, explicit
  4520. StoredSessions->Save(false, true);
  4521. // encode session name because of slashes in hierarchical sessions
  4522. return EncodeUrlString(SessionName);
  4523. }
  4524. //---------------------------------------------------------------------------
  4525. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4526. {
  4527. // current working directories become defaults here, what is not right
  4528. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4529. return SaveHiddenDuplicateSession(SessionData.get());
  4530. }
  4531. //---------------------------------------------------------------------------
  4532. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4533. {
  4534. if (OpenInNewWindow())
  4535. {
  4536. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4537. }
  4538. else
  4539. {
  4540. // current working directories become defaults here, what is not right
  4541. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4542. TTerminalManager * Manager = TTerminalManager::Instance();
  4543. TManagedTerminal * Terminal = Manager->NewManagedTerminal(SessionData.get());
  4544. Manager->ActiveTerminal = Terminal;
  4545. }
  4546. }
  4547. //---------------------------------------------------------------------------
  4548. void __fastcall TCustomScpExplorerForm::RenameSession()
  4549. {
  4550. UnicodeString Name = Terminal->SessionData->SessionName;
  4551. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4552. {
  4553. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4554. TSessionData::ValidateName(Name);
  4555. // This is inconsistent with how color (for example) is handled.
  4556. Terminal->SessionData->Name = Name;
  4557. UpdateControls();
  4558. // Add/Remove distinguishing paths from sessions of the same name.
  4559. DoTerminalListChanged();
  4560. }
  4561. }
  4562. //---------------------------------------------------------------------------
  4563. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4564. {
  4565. DebugAssert(Queue != NULL);
  4566. bool Result = Queue->IsEmpty;
  4567. if (!Result)
  4568. {
  4569. SetFocus();
  4570. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4571. }
  4572. return Result;
  4573. }
  4574. //---------------------------------------------------------------------------
  4575. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4576. {
  4577. return CanCloseQueue(FQueue);
  4578. }
  4579. //---------------------------------------------------------------------------
  4580. void __fastcall TCustomScpExplorerForm::CloseSession()
  4581. {
  4582. if (CanCloseQueue())
  4583. {
  4584. TTerminalManager::Instance()->FreeActiveTerminal();
  4585. }
  4586. }
  4587. //---------------------------------------------------------------------------
  4588. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4589. {
  4590. if (CanCloseQueue())
  4591. {
  4592. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4593. }
  4594. }
  4595. //---------------------------------------------------------------------------
  4596. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4597. {
  4598. DetachTerminal(Terminal);
  4599. RemoteDirView->Terminal = Terminal;
  4600. UpdateRemotePathComboBox(false);
  4601. InitStatusBar();
  4602. UpdateControls();
  4603. }
  4604. //---------------------------------------------------------------------------
  4605. void __fastcall TCustomScpExplorerForm::TerminalConnecting()
  4606. {
  4607. InitStatusBar();
  4608. }
  4609. //---------------------------------------------------------------------------
  4610. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4611. {
  4612. if (DebugAlwaysTrue(!Terminal->Active))
  4613. {
  4614. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4615. }
  4616. }
  4617. //---------------------------------------------------------------------------
  4618. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4619. {
  4620. if (OpenInNewWindow())
  4621. {
  4622. // encode session name because of slashes in hierarchical sessions
  4623. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4624. }
  4625. else
  4626. {
  4627. TTerminalManager * Manager = TTerminalManager::Instance();
  4628. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4629. Manager->ActiveTerminal = Terminal;
  4630. }
  4631. }
  4632. //---------------------------------------------------------------------------
  4633. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4634. {
  4635. TTerminalManager * Manager = TTerminalManager::Instance();
  4636. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4637. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4638. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4639. // FirstTerminal can be null, if some of the
  4640. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4641. {
  4642. FirstTerminal->Disconnected = true;
  4643. FirstTerminal->DisconnectedTemporarily = true;
  4644. }
  4645. Manager->ActiveTerminal = FirstTerminal;
  4646. }
  4647. //---------------------------------------------------------------------------
  4648. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4649. {
  4650. if (OpenInNewWindow())
  4651. {
  4652. ExecuteNewInstance(Name);
  4653. }
  4654. else
  4655. {
  4656. DoOpenFolderOrWorkspace(Name, true);
  4657. }
  4658. }
  4659. //---------------------------------------------------------------------------
  4660. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4661. bool &CanClose)
  4662. {
  4663. // See the comment in CloseApp()
  4664. if (NonVisualDataModule->Busy)
  4665. {
  4666. CanClose = false;
  4667. }
  4668. else if (Terminal != NULL)
  4669. {
  4670. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4671. {
  4672. unsigned int Result;
  4673. TMessageParams Params(mpNeverAskAgainCheck);
  4674. UnicodeString Message;
  4675. int Answers = qaOK | qaCancel;
  4676. if (TTerminalManager::Instance()->Count > 1)
  4677. {
  4678. if (!WinConfiguration->AutoSaveWorkspace)
  4679. {
  4680. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4681. }
  4682. else
  4683. {
  4684. Message = LoadStr(CLOSE_SESSIONS);
  4685. }
  4686. }
  4687. else
  4688. {
  4689. if (!WinConfiguration->AutoSaveWorkspace)
  4690. {
  4691. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4692. }
  4693. else
  4694. {
  4695. Message = LoadStr(CLOSE_SESSION);
  4696. }
  4697. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4698. }
  4699. UnicodeString Note;
  4700. if (WinConfiguration->AutoSaveWorkspace)
  4701. {
  4702. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4703. }
  4704. else
  4705. {
  4706. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4707. Answers = qaYes | qaNo | qaCancel;
  4708. }
  4709. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4710. SetFocus();
  4711. Result = MessageDialog(Message, qtConfirmation,
  4712. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4713. if (Result == qaNeverAskAgain)
  4714. {
  4715. WinConfiguration->ConfirmClosingSession = false;
  4716. }
  4717. if (Result == qaNo)
  4718. {
  4719. CanClose = SaveWorkspace(true);
  4720. // note that the workspace will be saved redundatly again from FormClose
  4721. }
  4722. else
  4723. {
  4724. CanClose =
  4725. (Result == qaOK) ||
  4726. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4727. (Result == qaNeverAskAgain);
  4728. }
  4729. }
  4730. if (CanClose)
  4731. {
  4732. CanClose = CanCloseQueue();
  4733. }
  4734. }
  4735. if (CanClose)
  4736. {
  4737. CanClose =
  4738. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4739. FEditorManager->CloseExternalFilesWithoutProcess();
  4740. if (CanClose)
  4741. {
  4742. while (CanClose && (FLocalEditors->Count > 0))
  4743. {
  4744. int PrevCount = FLocalEditors->Count;
  4745. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4746. CanClose = (FLocalEditors->Count < PrevCount);
  4747. }
  4748. if (CanClose)
  4749. {
  4750. CanClose = FEditorManager->Empty(true);
  4751. if (!CanClose)
  4752. {
  4753. SetFocus();
  4754. CanClose =
  4755. (MessageDialog(
  4756. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4757. }
  4758. }
  4759. }
  4760. }
  4761. }
  4762. //---------------------------------------------------------------------------
  4763. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4764. {
  4765. TForm * Form = dynamic_cast<TForm *>(Sender);
  4766. DebugAssert(Form != NULL);
  4767. Form->Close();
  4768. }
  4769. //---------------------------------------------------------------------------
  4770. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4771. {
  4772. TForm * Form = dynamic_cast<TForm *>(Sender);
  4773. delete Form;
  4774. }
  4775. //---------------------------------------------------------------------------
  4776. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4777. {
  4778. while (FLocalEditors->Count > 0)
  4779. {
  4780. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4781. }
  4782. }
  4783. //---------------------------------------------------------------------------
  4784. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4785. TObject *Sender)
  4786. {
  4787. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4788. try
  4789. {
  4790. SetProperties(osRemote, FileList);
  4791. }
  4792. __finally
  4793. {
  4794. delete FileList;
  4795. }
  4796. }
  4797. //---------------------------------------------------------------------------
  4798. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4799. {
  4800. if (value)
  4801. {
  4802. if (Component == fcCustomCommandsBand)
  4803. {
  4804. UpdateCustomCommandsToolbar();
  4805. }
  4806. if (Component == fcQueueFileList)
  4807. {
  4808. DebugAssert(!QueueFileListSplitter->Visible);
  4809. AdjustQueueLayout();
  4810. UpdateQueueFileList();
  4811. }
  4812. }
  4813. }
  4814. //---------------------------------------------------------------------------
  4815. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4816. {
  4817. int MinHeightLimit =
  4818. GetStaticQueuePanelComponentsHeight() +
  4819. QueueFileListSplitter->Height +
  4820. QueueFileList->Height +
  4821. GetMinQueueViewHeight();
  4822. if (QueuePanel->ClientHeight < MinHeightLimit)
  4823. {
  4824. QueuePanel->ClientHeight = MinHeightLimit;
  4825. }
  4826. }
  4827. //---------------------------------------------------------------------------
  4828. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4829. {
  4830. TControl * Control = GetComponent(Component);
  4831. DebugAssert(Control);
  4832. bool Changed = (Control->Visible != value);
  4833. if (Changed)
  4834. {
  4835. ComponentShowing(Component, value);
  4836. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4837. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4838. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4839. if (value)
  4840. {
  4841. int RemainingHeight = Control->Parent->ClientHeight;
  4842. int RemainingWidth = Control->Parent->ClientWidth;
  4843. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4844. {
  4845. TControl * ChildControl = Control->Parent->Controls[i];
  4846. if (ChildControl->Visible)
  4847. {
  4848. switch (ChildControl->Align)
  4849. {
  4850. case alTop:
  4851. case alBottom:
  4852. RemainingHeight -= ChildControl->Height;
  4853. break;
  4854. case alLeft:
  4855. case alRight:
  4856. RemainingWidth -= ChildControl->Width;
  4857. break;
  4858. }
  4859. }
  4860. }
  4861. int Reserve = ScaleByTextHeight(this, 32);
  4862. // queue in explorer, trees in commander
  4863. if (Control->Height > RemainingHeight - Reserve)
  4864. {
  4865. Control->Height = RemainingHeight / 2;
  4866. }
  4867. if (Control->Width > RemainingWidth - Reserve)
  4868. {
  4869. Control->Width = RemainingWidth / 2;
  4870. }
  4871. }
  4872. Control->Visible = value;
  4873. if (WasFocused && Visible)
  4874. {
  4875. DirView(osCurrent)->SetFocus();
  4876. }
  4877. FixControlsPlacement();
  4878. }
  4879. }
  4880. //---------------------------------------------------------------------------
  4881. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4882. {
  4883. TControl * Control = GetComponent(Component);
  4884. if (Control == NULL)
  4885. {
  4886. return false;
  4887. }
  4888. else
  4889. {
  4890. return Control->Visible;
  4891. }
  4892. }
  4893. //---------------------------------------------------------------------------
  4894. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4895. {
  4896. bool Result;
  4897. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4898. {
  4899. Result = !IsUWP();
  4900. }
  4901. else
  4902. {
  4903. Result = true;
  4904. }
  4905. return Result;
  4906. }
  4907. //---------------------------------------------------------------------------
  4908. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  4909. {
  4910. if (DirView->ItemFocused != NULL)
  4911. {
  4912. DirView->ItemFocused->MakeVisible(false);
  4913. }
  4914. }
  4915. //---------------------------------------------------------------------------
  4916. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4917. {
  4918. MakeFocusedItemVisible(RemoteDirView);
  4919. QueueSplitter->Visible = QueuePanel->Visible;
  4920. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4921. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4922. TControl * QueueControlsOrder[] =
  4923. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4924. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4925. }
  4926. //---------------------------------------------------------------------------
  4927. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4928. {
  4929. switch (Component) {
  4930. case fcStatusBar: return RemoteStatusBar;
  4931. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4932. case fcQueueView: return QueuePanel;
  4933. case fcQueueToolbar: return QueueDock;
  4934. case fcRemoteTree: return RemoteDrivePanel;
  4935. case fcSessionsTabs: return SessionsPageControl;
  4936. case fcQueueFileList: return QueueFileList;
  4937. default: return NULL;
  4938. }
  4939. }
  4940. //---------------------------------------------------------------------------
  4941. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4942. TObject *Sender, TListColumn *Column, TPoint &Point)
  4943. {
  4944. DebugAssert(NonVisualDataModule && Column && Sender);
  4945. NonVisualDataModule->ListColumn = Column;
  4946. TPopupMenu * DirViewColumnMenu;
  4947. if (Sender == DirView(osOther))
  4948. {
  4949. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4950. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4951. (Column->Index == uvName);
  4952. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4953. (Column->Index == uvSize);
  4954. }
  4955. else
  4956. {
  4957. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4958. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4959. (Column->Index == dvName);
  4960. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4961. (Column->Index == dvSize);
  4962. }
  4963. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4964. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4965. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4966. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4967. }
  4968. //---------------------------------------------------------------------------
  4969. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4970. TObject *Sender, TListItem *Item, bool &AllowExec)
  4971. {
  4972. DoDirViewExecFile(Sender, Item, AllowExec);
  4973. }
  4974. //---------------------------------------------------------------------------
  4975. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4976. TListItem * Item, bool & AllowExec)
  4977. {
  4978. DebugAssert(Sender && Item && Configuration);
  4979. DebugAssert(AllowExec);
  4980. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4981. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  4982. bool Remote = !IsSideLocalBrowser(Side);
  4983. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  4984. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4985. // on files only (not directories)
  4986. // and only when symlinks are resolved (apply to remote panel only)
  4987. if (!ADirView->ItemIsDirectory(Item) &&
  4988. (ResolvedSymlinks || FForceExecution))
  4989. {
  4990. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4991. !FForceExecution && ResolvedSymlinks)
  4992. {
  4993. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4994. {
  4995. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4996. UnlockWindow();
  4997. try
  4998. {
  4999. if (IsLocalBrowserMode())
  5000. {
  5001. LocalLocalCopy(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation, false, 0);
  5002. }
  5003. else
  5004. {
  5005. ExecuteFileOperation(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  5006. }
  5007. }
  5008. __finally
  5009. {
  5010. LockWindow();
  5011. }
  5012. AllowExec = false;
  5013. }
  5014. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  5015. {
  5016. if (!Remote || !WinConfiguration->DisableOpenEdit)
  5017. {
  5018. ExecuteFile(Side, efDefaultEditor);
  5019. AllowExec = false;
  5020. }
  5021. }
  5022. else
  5023. {
  5024. DebugFail();
  5025. }
  5026. }
  5027. // if we have not done anything special, fall back to default behavior
  5028. if (AllowExec)
  5029. {
  5030. if (Remote && !WinConfiguration->DisableOpenEdit)
  5031. {
  5032. ExecuteFile(osRemote, efShell);
  5033. AllowExec = false;
  5034. }
  5035. }
  5036. }
  5037. }
  5038. //---------------------------------------------------------------------------
  5039. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  5040. {
  5041. return ((Side == osRemote) || (Side == osCurrent));
  5042. }
  5043. //---------------------------------------------------------------------------
  5044. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5045. {
  5046. DebugFail();
  5047. }
  5048. //---------------------------------------------------------------------------
  5049. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5050. {
  5051. DebugFail();
  5052. }
  5053. //---------------------------------------------------------------------------
  5054. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5055. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5056. {
  5057. TSynchronizeParamType Params;
  5058. Params.LocalDirectory = LocalDirectory;
  5059. Params.RemoteDirectory = RemoteDirectory;
  5060. int UnusedParams =
  5061. (GUIConfiguration->SynchronizeParams &
  5062. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5063. TTerminal::spCaseSensitive));
  5064. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5065. Params.Options = GUIConfiguration->SynchronizeOptions;
  5066. bool SaveSettings = false;
  5067. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5068. &DoSynchronizeTooManyDirectories);
  5069. DebugAssert(FSynchronizeController == NULL);
  5070. FSynchronizeController = &Controller;
  5071. bool Result;
  5072. try
  5073. {
  5074. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5075. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5076. int Options =
  5077. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5078. DebugAssert(FOnFeedSynchronizeError == NULL);
  5079. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5080. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5081. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5082. if (Result)
  5083. {
  5084. if (SaveSettings)
  5085. {
  5086. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5087. GUIConfiguration->SynchronizeOptions = Params.Options;
  5088. }
  5089. else
  5090. {
  5091. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5092. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5093. FLAGSET(Params.Options, soSynchronize))
  5094. {
  5095. GUIConfiguration->SynchronizeOptions =
  5096. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5097. soSynchronize;
  5098. }
  5099. }
  5100. LocalDirectory = Params.LocalDirectory;
  5101. RemoteDirectory = Params.RemoteDirectory;
  5102. }
  5103. }
  5104. __finally
  5105. {
  5106. FSynchronizeController = NULL;
  5107. DebugAssert(FOnFeedSynchronizeError == NULL);
  5108. FOnFeedSynchronizeError = NULL;
  5109. }
  5110. return Result;
  5111. }
  5112. //---------------------------------------------------------------------------
  5113. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5114. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5115. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5116. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5117. TSynchronizeOptions * Options, bool Full)
  5118. {
  5119. // Keep-up-to-date mode
  5120. if (Terminal->Status == ssOpened)
  5121. {
  5122. try
  5123. {
  5124. int PParams = Params.Params;
  5125. if (!Full)
  5126. {
  5127. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5128. if (FLAGSET(Params.Options, soRecurse))
  5129. {
  5130. PParams |= TTerminal::spSubDirs;
  5131. }
  5132. }
  5133. else
  5134. {
  5135. // if keepuptodate is non-recursive,
  5136. // full sync before has to be non-recursive as well
  5137. if (FLAGCLEAR(Params.Options, soRecurse))
  5138. {
  5139. PParams |= TTerminal::spNoRecurse;
  5140. }
  5141. }
  5142. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5143. PParams, Checklist, Options);
  5144. }
  5145. catch (Exception & E)
  5146. {
  5147. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5148. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5149. {
  5150. // noop, already logged in MoreMessageDialog
  5151. }
  5152. else
  5153. {
  5154. ShowExtendedExceptionEx(Terminal, &E);
  5155. throw;
  5156. }
  5157. }
  5158. }
  5159. }
  5160. //---------------------------------------------------------------------------
  5161. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5162. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5163. const UnicodeString ErrorStr)
  5164. {
  5165. if (!Directory.IsEmpty())
  5166. {
  5167. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5168. }
  5169. else
  5170. {
  5171. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5172. }
  5173. }
  5174. //---------------------------------------------------------------------------
  5175. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5176. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5177. {
  5178. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5179. {
  5180. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5181. }
  5182. else
  5183. {
  5184. TMessageParams Params(mpNeverAskAgainCheck);
  5185. unsigned int Result = MessageDialog(
  5186. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5187. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5188. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5189. {
  5190. MaxDirectories *= 2;
  5191. if (Result == qaNeverAskAgain)
  5192. {
  5193. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5194. }
  5195. }
  5196. else
  5197. {
  5198. Abort();
  5199. }
  5200. }
  5201. }
  5202. //---------------------------------------------------------------------------
  5203. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5204. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5205. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5206. TSynchronizeOptions * Options)
  5207. {
  5208. // Keep-up-to-date mode
  5209. DebugAssert(!FAutoOperation);
  5210. void * BatchStorage;
  5211. BatchStart(BatchStorage);
  5212. FAutoOperation = true;
  5213. bool AnyOperation = false;
  5214. TDateTime StartTime = Now();
  5215. TSynchronizeChecklist * AChecklist = NULL;
  5216. try
  5217. {
  5218. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5219. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5220. {
  5221. FSynchronizeProgressForm->Start();
  5222. }
  5223. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5224. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5225. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5226. Options);
  5227. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5228. SAFE_DESTROY(FSynchronizeProgressForm);
  5229. AnyOperation = (AChecklist->CheckedCount > 0);
  5230. if (AnyOperation)
  5231. {
  5232. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5233. CreateProgressForm(&SynchronizeProgress);
  5234. try
  5235. {
  5236. Terminal->SynchronizeApply(
  5237. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5238. SynchronizeProcessedItem, NULL, NULL, NULL);
  5239. }
  5240. __finally
  5241. {
  5242. DestroyProgressForm();
  5243. }
  5244. }
  5245. }
  5246. __finally
  5247. {
  5248. if (Checklist == NULL)
  5249. {
  5250. delete AChecklist;
  5251. }
  5252. else
  5253. {
  5254. *Checklist = AChecklist;
  5255. }
  5256. FAutoOperation = false;
  5257. SAFE_DESTROY(FSynchronizeProgressForm);
  5258. BatchEnd(BatchStorage);
  5259. ReloadLocalDirectory();
  5260. if (AnyOperation)
  5261. {
  5262. OperationComplete(StartTime);
  5263. }
  5264. }
  5265. }
  5266. //---------------------------------------------------------------------------
  5267. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5268. {
  5269. // can be called from command line
  5270. return Visible &&
  5271. ((DirView(osRemote)->SelCount > 0) ||
  5272. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5273. }
  5274. //---------------------------------------------------------------------------
  5275. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5276. {
  5277. LogSynchronizeEvent(Terminal, Message);
  5278. }
  5279. //---------------------------------------------------------------------------
  5280. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5281. int Params, TSynchronizeOptions & Options)
  5282. {
  5283. DebugAssert(!IsLocalBrowserMode());
  5284. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5285. {
  5286. Options.Filter = new TStringList();
  5287. Options.Filter->CaseSensitive = false;
  5288. Options.Filter->Duplicates = Types::dupAccept;
  5289. if (DirView(osRemote)->SelCount > 0)
  5290. {
  5291. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5292. }
  5293. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5294. {
  5295. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5296. }
  5297. Options.Filter->Sort();
  5298. }
  5299. }
  5300. //---------------------------------------------------------------------------
  5301. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5302. {
  5303. TCopyParamType Defaults;
  5304. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5305. ConfigStorage->AccessMode = smRead;
  5306. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5307. {
  5308. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5309. }
  5310. ConfigStorage.reset(NULL);
  5311. std::unique_ptr<TStringList> Options(new TStringList());
  5312. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5313. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5314. UnicodeString Result;
  5315. if (Options->Count > 0)
  5316. {
  5317. Result =
  5318. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5319. }
  5320. return Result;
  5321. }
  5322. //---------------------------------------------------------------------------
  5323. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5324. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5325. {
  5326. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5327. UnicodeString AdditionalParams =
  5328. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5329. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5330. SerializeCopyParamForCommandLine(CopyParams),
  5331. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5332. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5333. ExecuteNewInstance(SessionName, AdditionalParams);
  5334. }
  5335. //---------------------------------------------------------------------------
  5336. struct TSynchronizeParams
  5337. {
  5338. UnicodeString LocalDirectory;
  5339. UnicodeString RemoteDirectory;
  5340. TSynchronizeMode Mode;
  5341. TSynchronizeChecklist * Checklist;
  5342. int Params;
  5343. TCopyParamType * CopyParam;
  5344. TDateTime CollectElapsed;
  5345. TDateTime * StartTime;
  5346. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5347. };
  5348. //---------------------------------------------------------------------------
  5349. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5350. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5351. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5352. {
  5353. DebugAssert(!FAutoOperation);
  5354. void * BatchStorage;
  5355. BatchStart(BatchStorage);
  5356. FAutoOperation = true;
  5357. TFileOperationStatistics Statistics;
  5358. TDateTime Start = Now();
  5359. try
  5360. {
  5361. Params.OnProcessedItem = OnProcessedItem;
  5362. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5363. CreateProgressForm(&SynchronizeProgress);
  5364. Terminal->SynchronizeApply(
  5365. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5366. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5367. &Statistics);
  5368. }
  5369. __finally
  5370. {
  5371. Params.OnProcessedItem = NULL;
  5372. FAutoOperation = false;
  5373. DestroyProgressForm();
  5374. BatchEnd(BatchStorage);
  5375. ReloadLocalDirectory();
  5376. }
  5377. if (WinConfiguration->SynchronizeSummary)
  5378. {
  5379. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5380. // The statistics should be 0 anyway in this case
  5381. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5382. {
  5383. Message += L"\n";
  5384. if (Statistics.FilesUploaded > 0)
  5385. {
  5386. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5387. }
  5388. if (Statistics.FilesDownloaded > 0)
  5389. {
  5390. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5391. }
  5392. if (Statistics.FilesDeletedLocal > 0)
  5393. {
  5394. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5395. }
  5396. if (Statistics.FilesDeletedRemote > 0)
  5397. {
  5398. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5399. }
  5400. }
  5401. TDateTime Elapsed = (Now() - Start);
  5402. Message +=
  5403. L"\n" +
  5404. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5405. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5406. TMessageParams Params(mpNeverAskAgainCheck);
  5407. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5408. if (Result == qaNeverAskAgain)
  5409. {
  5410. WinConfiguration->SynchronizeSummary = false;
  5411. }
  5412. }
  5413. }
  5414. //---------------------------------------------------------------------------
  5415. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5416. {
  5417. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5418. {
  5419. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5420. }
  5421. // Not set in keep-up-to-date mode - Synchronize() method
  5422. if (Token != NULL)
  5423. {
  5424. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5425. if (Params.OnProcessedItem != NULL)
  5426. {
  5427. Params.OnProcessedItem(NULL, ChecklistItem);
  5428. }
  5429. }
  5430. }
  5431. //---------------------------------------------------------------------------
  5432. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5433. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5434. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5435. {
  5436. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5437. *Params.StartTime = Now();
  5438. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5439. }
  5440. //---------------------------------------------------------------------------
  5441. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5442. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5443. {
  5444. // terminal can be already closed (e.g. dropped connection)
  5445. if (Terminal != NULL)
  5446. {
  5447. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5448. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5449. }
  5450. }
  5451. //---------------------------------------------------------------------------
  5452. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5453. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5454. {
  5455. DebugAssert(!IsLocalBrowserMode());
  5456. TAutoBatch AutoBatch(this);
  5457. TAutoFlag AutoOperationFlag(FAutoOperation);
  5458. if (Side == osRemote)
  5459. {
  5460. std::unique_ptr<TStrings> FileList(new TStringList());
  5461. FileList->AddObject(FileName, RemoteFile);
  5462. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5463. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5464. RemoteDirView->SaveSelection();
  5465. RemoteDirView->SaveSelectedNames();
  5466. try
  5467. {
  5468. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5469. }
  5470. catch(...)
  5471. {
  5472. RemoteDirView->DiscardSavedSelection();
  5473. throw;
  5474. }
  5475. RemoteDirView->RestoreSelection();
  5476. }
  5477. else if (DebugAlwaysTrue(Side == osLocal))
  5478. {
  5479. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5480. {
  5481. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5482. }
  5483. UnicodeString Directory = ExtractFileDir(FileName);
  5484. ReloadLocalDirectory(Directory);
  5485. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5486. if (!SamePaths(Directory, NewDirectory))
  5487. {
  5488. ReloadLocalDirectory(NewDirectory);
  5489. }
  5490. }
  5491. }
  5492. //---------------------------------------------------------------------------
  5493. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5494. {
  5495. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5496. if (Side == osLocal)
  5497. {
  5498. if (Action == TSynchronizeChecklist::saDownloadNew)
  5499. {
  5500. OpenFolderInExplorer(LocalPath);
  5501. }
  5502. else
  5503. {
  5504. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5505. }
  5506. }
  5507. else if (DebugAlwaysTrue(Side == osRemote))
  5508. {
  5509. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5510. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5511. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5512. if (!LocalPath.IsEmpty())
  5513. {
  5514. SessionData->LocalDirectory = LocalPath;
  5515. }
  5516. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5517. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5518. }
  5519. }
  5520. //---------------------------------------------------------------------------
  5521. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5522. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5523. const TCopyParamType * CopyParams)
  5524. {
  5525. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5526. UnicodeString AdditionalParams =
  5527. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5528. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5529. SerializeCopyParamForCommandLine(CopyParams),
  5530. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5531. LocalDirectory, RemoteDirectory, Mode, Params));
  5532. ExecuteNewInstance(SessionName, AdditionalParams);
  5533. }
  5534. //---------------------------------------------------------------------------
  5535. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5536. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5537. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5538. {
  5539. int Result;
  5540. bool SaveSettings = false;
  5541. int Options =
  5542. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5543. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5544. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5545. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5546. bool Continue =
  5547. (UseDefaults == 0) ||
  5548. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5549. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5550. if (Continue)
  5551. {
  5552. Configuration->Usage->Inc(L"Synchronizations");
  5553. UpdateCopyParamCounters(CopyParam);
  5554. TSynchronizeOptions SynchronizeOptions;
  5555. GetSynchronizeOptions(Params, SynchronizeOptions);
  5556. if (SaveSettings)
  5557. {
  5558. GUIConfiguration->SynchronizeParams = Params;
  5559. }
  5560. else
  5561. {
  5562. SaveMode = false;
  5563. }
  5564. TDateTime StartTime = Now();
  5565. TSynchronizeChecklist * Checklist = NULL;
  5566. try
  5567. {
  5568. DebugAssert(!FAutoOperation);
  5569. FAutoOperation = true;
  5570. try
  5571. {
  5572. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5573. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5574. int Files = -1;
  5575. if (DataList->Count >= 1)
  5576. {
  5577. Files = StrToIntDef(DataList->Strings[0], Files);
  5578. }
  5579. else
  5580. {
  5581. DataList->Add(UnicodeString());
  5582. }
  5583. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5584. FSynchronizeProgressForm->Start();
  5585. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5586. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5587. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5588. &SynchronizeOptions);
  5589. if (Terminal->SessionData->CacheDirectories)
  5590. {
  5591. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5592. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5593. }
  5594. }
  5595. __finally
  5596. {
  5597. FAutoOperation = false;
  5598. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5599. SAFE_DESTROY(FSynchronizeProgressForm);
  5600. }
  5601. TSynchronizeParams SynchronizeParams;
  5602. SynchronizeParams.LocalDirectory = LocalDirectory;
  5603. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5604. SynchronizeParams.Mode = Mode;
  5605. SynchronizeParams.CopyParam = &CopyParam;
  5606. SynchronizeParams.Params = Params;
  5607. SynchronizeParams.Checklist = Checklist;
  5608. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5609. SynchronizeParams.StartTime = &StartTime;
  5610. SynchronizeParams.OnProcessedItem = NULL;
  5611. Result = Checklist->Count;
  5612. if (Checklist->Count > 0)
  5613. {
  5614. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5615. {
  5616. if (!DoSynchronizeChecklistDialog(
  5617. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5618. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5619. {
  5620. Result = -1;
  5621. }
  5622. }
  5623. else
  5624. {
  5625. FullSynchronize(SynchronizeParams, NULL, NULL);
  5626. }
  5627. }
  5628. else
  5629. {
  5630. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5631. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5632. }
  5633. }
  5634. __finally
  5635. {
  5636. delete Checklist;
  5637. }
  5638. OperationComplete(StartTime);
  5639. }
  5640. else
  5641. {
  5642. Result = -1;
  5643. }
  5644. return Result;
  5645. }
  5646. //---------------------------------------------------------------------------
  5647. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5648. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5649. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5650. {
  5651. if (Collect)
  5652. {
  5653. DebugAssert(FSynchronizeProgressForm != NULL);
  5654. if (!FSynchronizeProgressForm->Started)
  5655. {
  5656. FSynchronizeProgressForm->Start();
  5657. }
  5658. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5659. SetTaskbarListProgressValue(CompareProgress);
  5660. }
  5661. else
  5662. {
  5663. DebugAssert(FSynchronizeProgressForm == NULL);
  5664. DebugAssert(FProgressForm != NULL);
  5665. }
  5666. }
  5667. //---------------------------------------------------------------------------
  5668. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5669. {
  5670. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5671. TRemoteFile * File = NULL;
  5672. Terminal->ReadFile(FullFileName, File);
  5673. if (File != NULL)
  5674. {
  5675. std::unique_ptr<TRemoteFile> FileOwner(File);
  5676. TAutoFlag Flag(FStandaloneEditing);
  5677. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5678. Application->ShowMainForm = false;
  5679. Application->Run();
  5680. }
  5681. }
  5682. //---------------------------------------------------------------------------
  5683. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  5684. {
  5685. DebugFail();
  5686. }
  5687. //---------------------------------------------------------------------------
  5688. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5689. {
  5690. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5691. SessionData->Assign(Terminal->SessionData);
  5692. UpdateSessionData(SessionData.get());
  5693. Terminal->UpdateSessionCredentials(SessionData.get());
  5694. if (!Terminal->SessionData->HasSessionName())
  5695. {
  5696. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5697. // once IsWorkspace is cleared
  5698. SessionData->Name = UnicodeString();
  5699. SessionData->IsWorkspace = false;
  5700. }
  5701. return SessionData.release();
  5702. }
  5703. //---------------------------------------------------------------------------
  5704. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5705. {
  5706. TSessionData * SessionData = CloneCurrentSessionData();
  5707. try
  5708. {
  5709. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5710. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5711. }
  5712. __finally
  5713. {
  5714. delete SessionData;
  5715. }
  5716. }
  5717. //---------------------------------------------------------------------------
  5718. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5719. {
  5720. TTerminalManager * Manager = TTerminalManager::Instance();
  5721. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5722. if (DebugAlwaysTrue(Terminal != NULL))
  5723. {
  5724. // Update (Managed)Terminal->StateData
  5725. UpdateTerminal(Terminal);
  5726. }
  5727. Manager->SaveWorkspace(DataList.get());
  5728. return DataList.release();
  5729. }
  5730. //---------------------------------------------------------------------------
  5731. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5732. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5733. {
  5734. WinConfiguration->LastWorkspace = Name;
  5735. if (!SavePasswords)
  5736. {
  5737. for (int Index = 0; Index < DataList->Count; Index++)
  5738. {
  5739. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5740. if (SessionData->Link.IsEmpty())
  5741. {
  5742. SessionData->ClearSessionPasswords();
  5743. }
  5744. }
  5745. }
  5746. StoredSessions->NewWorkspace(Name, DataList);
  5747. // modified only
  5748. StoredSessions->Save(false, Explicit);
  5749. }
  5750. //---------------------------------------------------------------------------
  5751. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5752. {
  5753. return
  5754. DefaultStr(WinConfiguration->LastWorkspace,
  5755. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5756. }
  5757. //---------------------------------------------------------------------------
  5758. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5759. {
  5760. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5761. bool AnyNonStoredSessionWithPassword = false;
  5762. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5763. bool AllNonStoredSessionsAnonymous = true;
  5764. TTerminalManager * Manager = TTerminalManager::Instance();
  5765. for (int Index = 0; Index < DataList->Count; Index++)
  5766. {
  5767. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5768. if (SessionData->Link.IsEmpty())
  5769. {
  5770. if (SessionData->HasAnySessionPassword())
  5771. {
  5772. AnyNonStoredSessionWithPassword = true;
  5773. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5774. {
  5775. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5776. }
  5777. }
  5778. if (!SameText(SessionData->UserName, AnonymousUserName))
  5779. {
  5780. AllNonStoredSessionsAnonymous = false;
  5781. }
  5782. }
  5783. }
  5784. bool SavePasswords;
  5785. bool * PSavePasswords;
  5786. bool NotRecommendedSavingPasswords =
  5787. !CustomWinConfiguration->UseMasterPassword &&
  5788. !AllNonStoredSessionsAnonymous;
  5789. if (Configuration->DisablePasswordStoring ||
  5790. !AnyNonStoredSessionWithPassword)
  5791. {
  5792. PSavePasswords = NULL;
  5793. SavePasswords = false;
  5794. }
  5795. else
  5796. {
  5797. PSavePasswords = &SavePasswords;
  5798. SavePasswords =
  5799. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5800. !NotRecommendedSavingPasswords;
  5801. }
  5802. UnicodeString Name = WorkspaceName();
  5803. bool CreateShortcut = false;
  5804. bool Result =
  5805. DoSaveWorkspaceDialog(
  5806. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5807. EnableAutoSave);
  5808. if (Result)
  5809. {
  5810. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5811. if (CreateShortcut)
  5812. {
  5813. TOperationVisualizer Visualizer;
  5814. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5815. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5816. }
  5817. if (EnableAutoSave)
  5818. {
  5819. WinConfiguration->AutoSaveWorkspace = true;
  5820. WinConfiguration->AutoWorkspace = Name;
  5821. if (PSavePasswords != NULL)
  5822. {
  5823. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5824. }
  5825. }
  5826. }
  5827. return Result;
  5828. }
  5829. //---------------------------------------------------------------------------
  5830. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5831. {
  5832. DebugAssert(!IsLocalBrowserMode());
  5833. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5834. if (WinConfiguration->PreservePanelState)
  5835. {
  5836. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5837. }
  5838. UpdateSessionData(Terminal->StateData);
  5839. }
  5840. //---------------------------------------------------------------------------
  5841. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5842. {
  5843. // Keep in sync with TSessionData::CopyStateData
  5844. DebugAssert(!IsLocalBrowserMode());
  5845. DebugAssert(Data != NULL);
  5846. // This is inconsistent with how color (for example) is handled.
  5847. Data->Name = Terminal->SessionData->Name;
  5848. // cannot use RemoteDirView->Path, because it is empty if connection
  5849. // was already closed
  5850. // also only peek, we may not be connected at all atm
  5851. // so make sure we do not try retrieving current directory from the server
  5852. // (particularly with FTP)
  5853. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5854. if (!ACurrentDirectory.IsEmpty())
  5855. {
  5856. Data->RemoteDirectory = ACurrentDirectory;
  5857. }
  5858. Data->Color = SessionColor;
  5859. }
  5860. //---------------------------------------------------------------------------
  5861. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5862. {
  5863. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5864. DebugAssert(Toolbar != NULL);
  5865. for (int i = 0; i < Toolbar->Items->Count; i++)
  5866. {
  5867. TTBXCustomDropDownItem * DropDownItem;
  5868. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5869. if (DropDownItem != NULL)
  5870. {
  5871. ToolbarItemResize(DropDownItem,
  5872. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5873. Toolbar->NonClientWidth);
  5874. break;
  5875. }
  5876. }
  5877. }
  5878. //---------------------------------------------------------------------------
  5879. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5880. {
  5881. Item->EditWidth = Width;
  5882. }
  5883. //---------------------------------------------------------------------------
  5884. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5885. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5886. {
  5887. for (int i = 0; i < Toolbar->Items->Count; i++)
  5888. {
  5889. TTBXCustomDropDownItem * DropDownItem;
  5890. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5891. if (DropDownItem != NULL)
  5892. {
  5893. ASize.x -= DropDownItem->EditWidth;
  5894. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5895. }
  5896. }
  5897. }
  5898. //---------------------------------------------------------------------------
  5899. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5900. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5901. {
  5902. if (WinConfiguration->DDWarnLackOfTempSpace)
  5903. {
  5904. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5905. if (!ADrive.IsEmpty())
  5906. {
  5907. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5908. DebugAssert(RequiredSpace >= 0);
  5909. __int64 RequiredWithReserve;
  5910. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5911. if (FreeSpace < RequiredWithReserve)
  5912. {
  5913. unsigned int Result;
  5914. TMessageParams Params(mpNeverAskAgainCheck);
  5915. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5916. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5917. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5918. if (Result == qaNeverAskAgain)
  5919. {
  5920. WinConfiguration->DDWarnLackOfTempSpace = false;
  5921. }
  5922. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5923. }
  5924. }
  5925. }
  5926. }
  5927. //---------------------------------------------------------------------------
  5928. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5929. {
  5930. DoOpenDirectoryDialog(odAddBookmark, Side);
  5931. }
  5932. //---------------------------------------------------------------------------
  5933. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5934. {
  5935. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5936. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5937. try
  5938. {
  5939. TCustomDirView * DView = DirView(Side);
  5940. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5941. {
  5942. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5943. }
  5944. }
  5945. catch (...)
  5946. {
  5947. delete VisitedDirectories;
  5948. throw;
  5949. }
  5950. return VisitedDirectories;
  5951. }
  5952. //---------------------------------------------------------------------------
  5953. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5954. TOpenDirectoryMode Mode, TOperationSide Side)
  5955. {
  5956. bool Continue = true;
  5957. if (Mode == odAddBookmark)
  5958. {
  5959. TMessageParams Params(mpNeverAskAgainCheck);
  5960. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5961. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5962. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5963. unsigned int Answer =
  5964. MessageDialog(Message,
  5965. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5966. if (Answer == qaNeverAskAgain)
  5967. {
  5968. Continue = true;
  5969. WinConfiguration->UseSharedBookmarks = true;
  5970. }
  5971. else if (Answer == qaOK)
  5972. {
  5973. Continue = true;
  5974. WinConfiguration->UseSharedBookmarks = false;
  5975. }
  5976. else
  5977. {
  5978. Continue = false;
  5979. }
  5980. }
  5981. if (Continue)
  5982. {
  5983. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5984. try
  5985. {
  5986. UnicodeString Name = DirView(Side)->PathName;
  5987. bool Repeat;
  5988. do
  5989. {
  5990. Repeat = false;
  5991. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  5992. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  5993. // do not allow switching to location profiles,
  5994. // if we are not connected
  5995. HasDirView[osLocal] && (Terminal != NULL)))
  5996. {
  5997. TWindowLock Lock(this);
  5998. if (!TryOpenDirectory(Side, Name))
  5999. {
  6000. Repeat = true;
  6001. Mode = odBrowse;
  6002. }
  6003. }
  6004. }
  6005. while (Repeat);
  6006. }
  6007. __finally
  6008. {
  6009. delete VisitedDirectories;
  6010. }
  6011. }
  6012. }
  6013. //---------------------------------------------------------------------------
  6014. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  6015. {
  6016. DebugAssert(!FTerminal->CommandSessionOpened);
  6017. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  6018. }
  6019. //---------------------------------------------------------------------------
  6020. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  6021. {
  6022. bool Result = FTerminal->IsCapable[Capability] ||
  6023. FTerminal->CommandSessionOpened;
  6024. if (!Result)
  6025. {
  6026. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  6027. if (!GUIConfiguration->ConfirmCommandSession)
  6028. {
  6029. Result = true;
  6030. }
  6031. else
  6032. {
  6033. TMessageParams Params(mpNeverAskAgainCheck);
  6034. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6035. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6036. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6037. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6038. if (Answer == qaNeverAskAgain)
  6039. {
  6040. GUIConfiguration->ConfirmCommandSession = false;
  6041. Result = true;
  6042. }
  6043. else if (Answer == qaOK)
  6044. {
  6045. Result = true;
  6046. }
  6047. }
  6048. if (Result)
  6049. {
  6050. Result = CommandSessionFallback();
  6051. }
  6052. }
  6053. return Result;
  6054. }
  6055. //---------------------------------------------------------------------------
  6056. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6057. {
  6058. if (EnsureCommandSessionFallback(fcAnyCommand))
  6059. {
  6060. DoConsoleDialog(Terminal, Command);
  6061. }
  6062. }
  6063. //---------------------------------------------------------------------------
  6064. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6065. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6066. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6067. {
  6068. if (!IsSideLocalBrowser(osRemote) &&
  6069. IsFileControl(DropSourceControl, osRemote) &&
  6070. (FDDExtMapFile != NULL))
  6071. {
  6072. Accept = true;
  6073. }
  6074. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6075. DebugAssert(FDDTargetControl != NULL);
  6076. }
  6077. //---------------------------------------------------------------------------
  6078. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6079. _di_IDataObject DataObj, int KeyState,
  6080. const TPoint & Point, int & Effect, bool & Accept)
  6081. {
  6082. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6083. }
  6084. //---------------------------------------------------------------------------
  6085. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6086. _di_IDataObject DataObj, int KeyState,
  6087. const TPoint & Point, int & Effect, bool & Accept)
  6088. {
  6089. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6090. }
  6091. //---------------------------------------------------------------------------
  6092. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6093. TObject * Sender)
  6094. {
  6095. DebugUsedParam(Sender);
  6096. DebugAssert(FDDTargetControl == Sender);
  6097. FDDTargetControl = NULL;
  6098. }
  6099. //---------------------------------------------------------------------------
  6100. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6101. {
  6102. FileControlDDDragLeave(SessionsPageControl);
  6103. }
  6104. //---------------------------------------------------------------------------
  6105. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6106. {
  6107. FileControlDDDragLeave(QueueView3);
  6108. }
  6109. //---------------------------------------------------------------------------
  6110. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6111. {
  6112. DebugAssert(!IsSideLocalBrowser(Side));
  6113. DebugUsedParam(Side);
  6114. bool Edit = false;
  6115. TRemoteFile * File = NULL;
  6116. UnicodeString FileName;
  6117. UnicodeString PointTo;
  6118. bool SymbolicLink = true;
  6119. if (RemoteDirView->ItemFocused)
  6120. {
  6121. DebugAssert(RemoteDirView->ItemFocused->Data);
  6122. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6123. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6124. if (Edit)
  6125. {
  6126. FileName = File->FileName;
  6127. PointTo = File->LinkTo;
  6128. }
  6129. else
  6130. {
  6131. PointTo = File->FileName;
  6132. }
  6133. }
  6134. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6135. Terminal->IsCapable[fcHardLink]))
  6136. {
  6137. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6138. if (Edit)
  6139. {
  6140. DebugAssert(File->FileName == FileName);
  6141. int Params = dfNoRecursive;
  6142. Terminal->ExceptionOnFail = true;
  6143. try
  6144. {
  6145. Terminal->DeleteFile(L"", File, &Params);
  6146. }
  6147. __finally
  6148. {
  6149. Terminal->ExceptionOnFail = false;
  6150. }
  6151. }
  6152. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6153. }
  6154. }
  6155. //---------------------------------------------------------------------------
  6156. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6157. {
  6158. return
  6159. (IsSideLocalBrowser(Side) ||
  6160. (HasActiveTerminal() &&
  6161. Terminal->ResolvingSymlinks &&
  6162. Terminal->IsCapable[fcSymbolicLink]));
  6163. }
  6164. //---------------------------------------------------------------------------
  6165. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6166. {
  6167. return
  6168. !IsSideLocalBrowser(FCurrentSide) &&
  6169. (RemoteDirView->ItemFocused != NULL) &&
  6170. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6171. Terminal->SessionData->ResolveSymlinks;
  6172. }
  6173. //---------------------------------------------------------------------------
  6174. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6175. {
  6176. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6177. FForceExecution = true;
  6178. try
  6179. {
  6180. DirView(osCurrent)->ExecuteCurrentFile();
  6181. }
  6182. __finally
  6183. {
  6184. FForceExecution = false;
  6185. }
  6186. }
  6187. //---------------------------------------------------------------------------
  6188. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6189. {
  6190. TEditorData ExternalEditor;
  6191. ExternalEditor.Editor = edExternal;
  6192. bool Remember = false;
  6193. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6194. {
  6195. if (Remember)
  6196. {
  6197. TEditorList * EditorList = new TEditorList;
  6198. try
  6199. {
  6200. *EditorList = *WinConfiguration->EditorList;
  6201. bool Found = false;
  6202. int i = 0;
  6203. while (!Found && (i < EditorList->Count))
  6204. {
  6205. const TEditorPreferences * Editor = EditorList->Editors[i];
  6206. if ((Editor->Data->Editor == edExternal) &&
  6207. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6208. {
  6209. Found = true;
  6210. }
  6211. i++;
  6212. }
  6213. if (!Found)
  6214. {
  6215. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6216. WinConfiguration->EditorList = EditorList;
  6217. }
  6218. }
  6219. __finally
  6220. {
  6221. delete EditorList;
  6222. }
  6223. }
  6224. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6225. }
  6226. }
  6227. //---------------------------------------------------------------------------
  6228. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6229. {
  6230. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6231. if (FFileFindTerminal == ATerminal)
  6232. {
  6233. FFileFindTerminal = NULL;
  6234. HideFileFindDialog();
  6235. }
  6236. if (FClipboardTerminal == ATerminal)
  6237. {
  6238. ClipboardClear(); // implies ClipboardStop
  6239. }
  6240. }
  6241. //---------------------------------------------------------------------------
  6242. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6243. {
  6244. DetachTerminal(Sender);
  6245. }
  6246. //---------------------------------------------------------------------------
  6247. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6248. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6249. {
  6250. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6251. DebugAssert(Terminal != NULL);
  6252. if (Data->Terminal == Terminal)
  6253. {
  6254. Data->Terminal = NULL;
  6255. }
  6256. }
  6257. //---------------------------------------------------------------------------
  6258. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6259. {
  6260. UpdateControls();
  6261. SessionColor = TColor(0);
  6262. UpdateRemotePathComboBox(false);
  6263. NeedSession(false);
  6264. }
  6265. //---------------------------------------------------------------------------
  6266. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6267. {
  6268. try
  6269. {
  6270. // Cache, as the login dialog can change its value.
  6271. // See also DoShow.
  6272. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6273. try
  6274. {
  6275. if (ShowLogin)
  6276. {
  6277. bool ReloadSessions = !Startup;
  6278. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this);
  6279. }
  6280. }
  6281. __finally
  6282. {
  6283. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6284. // (so there was no chance for the user to open any session yet)
  6285. if ((ShowLogin || !Startup) &&
  6286. !WinConfiguration->KeepOpenWhenNoSession &&
  6287. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6288. {
  6289. TerminateApplication();
  6290. }
  6291. }
  6292. }
  6293. catch (EAbort &)
  6294. {
  6295. // swallow
  6296. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6297. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6298. }
  6299. }
  6300. //---------------------------------------------------------------------------
  6301. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6302. {
  6303. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6304. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6305. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6306. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6307. try
  6308. {
  6309. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6310. // Clear the design time unthemed tab
  6311. ((SessionsPageControl->PageCount > 0) &&
  6312. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6313. {
  6314. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6315. }
  6316. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6317. {
  6318. TThemeTabSheet * TabSheet;
  6319. if (Index >= SessionsPageControl->PageCount)
  6320. {
  6321. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6322. TabSheet->PageControl = SessionsPageControl;
  6323. }
  6324. else
  6325. {
  6326. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6327. }
  6328. bool IsSessionTab = (Index < TerminalList->Count);
  6329. if (IsSessionTab)
  6330. {
  6331. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6332. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6333. UpdateSessionTab(TabSheet);
  6334. }
  6335. else
  6336. {
  6337. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6338. TabSheet->Tag = 0; // not really needed
  6339. TabSheet->Shadowed = false;
  6340. // We know that we are at the last page, otherwise we could not call this (it assumes that new session tab is the last one)
  6341. UpdateNewSessionTab();
  6342. }
  6343. TabSheet->ShowCloseButton = IsSessionTab;
  6344. }
  6345. }
  6346. __finally
  6347. {
  6348. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6349. }
  6350. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6351. }
  6352. //---------------------------------------------------------------------------
  6353. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6354. {
  6355. DoTerminalListChanged();
  6356. }
  6357. //---------------------------------------------------------------------------
  6358. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6359. {
  6360. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6361. DebugAssert(TabSheet->ImageIndex == 0);
  6362. TabSheet->Caption =
  6363. WinConfiguration->SelectiveToolbarText ?
  6364. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6365. UnicodeString();
  6366. }
  6367. //---------------------------------------------------------------------------
  6368. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6369. {
  6370. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6371. }
  6372. //---------------------------------------------------------------------------
  6373. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6374. {
  6375. if (DebugAlwaysTrue(TabSheet != NULL))
  6376. {
  6377. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6378. if (DebugAlwaysTrue(ATerminal != NULL))
  6379. {
  6380. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6381. TabSheet->ImageIndex = AddSessionColor(Color);
  6382. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6383. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6384. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6385. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6386. {
  6387. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6388. }
  6389. }
  6390. }
  6391. }
  6392. //---------------------------------------------------------------------------
  6393. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6394. {
  6395. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6396. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6397. bool Result = (Terminal != NULL);
  6398. if (Result)
  6399. {
  6400. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6401. }
  6402. else
  6403. {
  6404. try
  6405. {
  6406. NewSession();
  6407. }
  6408. __finally
  6409. {
  6410. DoTerminalListChanged();
  6411. }
  6412. FSessionsPageControlNewSessionTime = Now();
  6413. }
  6414. return Result;
  6415. }
  6416. //---------------------------------------------------------------------------
  6417. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6418. {
  6419. SessionTabSwitched();
  6420. }
  6421. //---------------------------------------------------------------------------
  6422. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6423. {
  6424. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6425. DebugAssert(TransferList != NULL);
  6426. UnicodeString Name;
  6427. if (TransferList->ItemIndex <= 0)
  6428. {
  6429. Name = L"";
  6430. }
  6431. else
  6432. {
  6433. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6434. }
  6435. if (FCopyParamAutoSelected.IsEmpty())
  6436. {
  6437. // if previous preset was not autoselected, make new preset the "default"
  6438. FCopyParamDefault = Name;
  6439. }
  6440. GUIConfiguration->CopyParamCurrent = Name;
  6441. }
  6442. //---------------------------------------------------------------------------
  6443. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6444. {
  6445. // sanity check
  6446. bool ExistingPreset =
  6447. (FTransferListHoverIndex >= 0) &&
  6448. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6449. DebugAssert(ExistingPreset);
  6450. if (ExistingPreset)
  6451. {
  6452. HDC DC = GetDC(0);
  6453. TCanvas * Canvas = new TCanvas();
  6454. try
  6455. {
  6456. Canvas->Handle = DC;
  6457. Canvas->Font = GetToolbarFont(this);
  6458. UnicodeString Name;
  6459. if (FTransferListHoverIndex == 0)
  6460. {
  6461. Name = L"";
  6462. }
  6463. else
  6464. {
  6465. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6466. }
  6467. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6468. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6469. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6470. static_cast<TObject*>(GetComponent(fcTransferList)));
  6471. UnicodeString InfoStr =
  6472. GUIConfiguration->CopyParamPreset[Name].
  6473. GetInfoStr(L"; ",
  6474. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6475. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6476. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6477. {
  6478. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6479. {
  6480. InfoStr.SetLength(InfoStr.Length() - 1);
  6481. }
  6482. InfoStr += Ellipsis;
  6483. }
  6484. // UpdateCaption does not cause invalidation of whole submenu, while
  6485. // setting Caption property does.
  6486. // also it probably does not resize the label, even if necessary
  6487. // (we do not want that anyway)
  6488. TransferLabel->UpdateCaption(InfoStr);
  6489. }
  6490. __finally
  6491. {
  6492. Canvas->Handle = NULL;
  6493. ReleaseDC(0, DC);
  6494. delete Canvas;
  6495. }
  6496. }
  6497. }
  6498. //---------------------------------------------------------------------------
  6499. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6500. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6501. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6502. {
  6503. if (FTransferListHoverIndex != AHoverIndex)
  6504. {
  6505. FTransferListHoverIndex = AHoverIndex;
  6506. UpdateTransferLabel();
  6507. }
  6508. }
  6509. //---------------------------------------------------------------------------
  6510. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6511. {
  6512. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6513. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6514. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6515. {
  6516. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6517. {
  6518. if (!NonVisualDataModule->Busy)
  6519. {
  6520. OpenDirectory(GetSide(osCurrent));
  6521. }
  6522. Message.Result = 1;
  6523. }
  6524. else
  6525. {
  6526. TForm::Dispatch(&Message);
  6527. }
  6528. }
  6529. else
  6530. {
  6531. TForm::Dispatch(&Message);
  6532. }
  6533. }
  6534. //---------------------------------------------------------------------------
  6535. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6536. {
  6537. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6538. if ((FIgnoreNextDialogChar != 0) &&
  6539. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6540. {
  6541. Message.Result = 1;
  6542. }
  6543. else
  6544. {
  6545. TForm::Dispatch(&Message);
  6546. }
  6547. FIgnoreNextDialogChar = 0;
  6548. }
  6549. //---------------------------------------------------------------------------
  6550. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6551. {
  6552. // The four low-order bits are used internally by Windows
  6553. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6554. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6555. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6556. // 61730 - restore thru double click - undocumented
  6557. // 61490 - maximize thru double click - undocumented
  6558. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6559. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6560. {
  6561. SysResizing(Cmd);
  6562. }
  6563. TForm::Dispatch(&Message);
  6564. }
  6565. //---------------------------------------------------------------------------
  6566. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6567. {
  6568. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6569. // Also there no point returning TRUE as we are not able to
  6570. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6571. // Hence the process termination might be safer :)
  6572. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6573. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6574. {
  6575. Message.Result = FALSE;
  6576. }
  6577. else
  6578. {
  6579. Message.Result = TRUE;
  6580. }
  6581. // Do not call default handling as that triggers OnCloseQuery,
  6582. // where our implementation will popup confirmation dialogs, what we do not want,
  6583. // as per Vista guidelines:
  6584. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6585. }
  6586. //---------------------------------------------------------------------------
  6587. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6588. {
  6589. if (Message.EndSession && IsApplicationMinimized())
  6590. {
  6591. // WORKAROUND
  6592. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6593. // when it receives WM_ENDSESSION,
  6594. // but that sometimes (particularly when application is minimized) cause crashes.
  6595. // Crash popups message that blocks log off.
  6596. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6597. // so we call ExitProcess() immediately, not even trying to cleanup.
  6598. // It still causes beep, so there's likely some popup, but it does not block
  6599. // log off.
  6600. ExitProcess(0);
  6601. }
  6602. TForm::Dispatch(&Message);
  6603. }
  6604. #ifdef _DEBUG
  6605. //---------------------------------------------------------------------------
  6606. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6607. {
  6608. TForm::Dispatch(&Message);
  6609. }
  6610. #endif
  6611. //---------------------------------------------------------------------------
  6612. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6613. {
  6614. }
  6615. //---------------------------------------------------------------------------
  6616. void __fastcall TCustomScpExplorerForm::DoShow()
  6617. {
  6618. // only now are the controls resized finally, so the size constraints
  6619. // will not conflict with possibly very small window size
  6620. RestoreFormParams();
  6621. // This indicates that the form was rescaled after parameters were loaded and
  6622. // as most probably the parameters were actually saved with the current form scaling
  6623. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6624. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6625. // and no rounding problems will occur.
  6626. // See also RestoreForm.
  6627. // (we should be safe to call RestoreParams unconditionally)
  6628. if (PixelsPerInch != Screen->PixelsPerInch)
  6629. {
  6630. RestoreParams();
  6631. }
  6632. FixControlsPlacement();
  6633. if (Position == poDefaultPosOnly)
  6634. {
  6635. CutFormToDesktop(this);
  6636. }
  6637. TForm::DoShow();
  6638. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6639. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6640. // This was previously in NeedSession, where other related code is.
  6641. // But that is called form CMShowingChanged, when the window is already visible and the local-local window state
  6642. // unpleasanly shows briefly.
  6643. if (!WinConfiguration->ShowLoginWhenNoSession &&
  6644. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6645. // This detects if workspace was saved the last time the main widow was closed
  6646. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6647. {
  6648. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6649. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6650. }
  6651. if (Terminal == NULL)
  6652. {
  6653. StartingDisconnected();
  6654. }
  6655. UpdatePixelsPerInchMainWindowCounter();
  6656. FShowing = true;
  6657. }
  6658. //---------------------------------------------------------------------------
  6659. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6660. {
  6661. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6662. }
  6663. //---------------------------------------------------------------------------
  6664. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6665. {
  6666. DoTerminalListChanged();
  6667. InitStatusBar();
  6668. UpdateControls();
  6669. }
  6670. //---------------------------------------------------------------------------
  6671. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6672. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6673. TNotifyEvent OnBalloonClick, TObject * UserData)
  6674. {
  6675. bool Do;
  6676. UnicodeString Message;
  6677. if (E == NULL)
  6678. {
  6679. Message = Str;
  6680. Do = true;
  6681. }
  6682. else
  6683. {
  6684. Do = ExceptionMessage(E, Message);
  6685. }
  6686. if (Do && WinConfiguration->BalloonNotifications)
  6687. {
  6688. UnicodeString Title;
  6689. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6690. {
  6691. Message = TrimLeft(Message);
  6692. }
  6693. else
  6694. {
  6695. Message = UnformatMessage(Message);
  6696. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6697. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6698. Title = LoadResourceString(Captions[Type]);
  6699. if (Terminal != NULL)
  6700. {
  6701. Title = FORMAT(L"%s - %s",
  6702. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6703. }
  6704. }
  6705. if (Seconds == 0)
  6706. {
  6707. Seconds = WinConfiguration->NotificationsTimeout;
  6708. }
  6709. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6710. }
  6711. }
  6712. //---------------------------------------------------------------------------
  6713. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6714. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6715. UnicodeString HelpKeyword, const TMessageParams * Params,
  6716. TTerminal * Terminal)
  6717. {
  6718. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6719. (FOnFeedSynchronizeError != NULL)) &&
  6720. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6721. {
  6722. if (FOnFeedSynchronizeError != NULL)
  6723. {
  6724. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6725. }
  6726. else
  6727. {
  6728. DebugAssert(FErrorList != NULL);
  6729. TStringList * MoreMessagesCopy = NULL;
  6730. if (MoreMessages)
  6731. {
  6732. MoreMessagesCopy = new TStringList();
  6733. MoreMessagesCopy->Assign(MoreMessages);
  6734. }
  6735. FErrorList->AddObject(Message, MoreMessagesCopy);
  6736. }
  6737. PopupTrayBalloon(Terminal, Message, Type);
  6738. return ContinueAnswer(Answers);
  6739. }
  6740. else
  6741. {
  6742. bool UseBalloon = FTrayIcon->Visible;
  6743. if (UseBalloon)
  6744. {
  6745. PopupTrayBalloon(Terminal, Message, Type);
  6746. }
  6747. unsigned int Result;
  6748. try
  6749. {
  6750. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6751. }
  6752. __finally
  6753. {
  6754. // cancel only balloon we popped up, otherwise we may cancel notification
  6755. // balloon that was there before the message dialog
  6756. // (such as "dd confirmation opt in balloon)
  6757. if (UseBalloon)
  6758. {
  6759. FTrayIcon->CancelBalloon();
  6760. }
  6761. }
  6762. return Result;
  6763. }
  6764. }
  6765. //---------------------------------------------------------------------------
  6766. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6767. TTerminal * Terminal, Exception * E)
  6768. {
  6769. if (FTrayIcon->Visible)
  6770. {
  6771. PopupTrayBalloon(Terminal, L"", qtError, E);
  6772. }
  6773. // particularly prevent opening new session from jump list,
  6774. // while exception is shown
  6775. NonVisualDataModule->StartBusy();
  6776. try
  6777. {
  6778. ShowExtendedExceptionEx(Terminal, E);
  6779. }
  6780. __finally
  6781. {
  6782. NonVisualDataModule->EndBusy();
  6783. FTrayIcon->CancelBalloon();
  6784. }
  6785. }
  6786. //---------------------------------------------------------------------------
  6787. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6788. {
  6789. if (Terminal->Active)
  6790. {
  6791. InitStatusBar();
  6792. }
  6793. // cannot rely on active page being page for active terminal,
  6794. // as it can happen that active page is the "new session" page
  6795. // (e.g. when reconnecting active terminal, while login dialog
  6796. // invoked from "new session" page is modal)
  6797. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6798. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6799. }
  6800. //---------------------------------------------------------------------------
  6801. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6802. TTerminal * Terminal, Exception * E)
  6803. {
  6804. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6805. if (!Terminal->Active)
  6806. {
  6807. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6808. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6809. {
  6810. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6811. }
  6812. }
  6813. }
  6814. //---------------------------------------------------------------------------
  6815. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6816. UnicodeString Message, TQueryType Type,
  6817. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6818. {
  6819. if ((E == NULL) ||
  6820. ExceptionMessage(E, Message))
  6821. {
  6822. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6823. if (Important)
  6824. {
  6825. Seconds *= 5;
  6826. }
  6827. UnicodeString NoteMessage(UnformatMessage(Message));
  6828. if (Terminal != NULL)
  6829. {
  6830. NoteMessage = FORMAT(L"%s: %s",
  6831. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6832. }
  6833. if (WinConfiguration->BalloonNotifications)
  6834. {
  6835. AddNote(NoteMessage);
  6836. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6837. }
  6838. else
  6839. {
  6840. FlashOnBackground();
  6841. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6842. }
  6843. }
  6844. }
  6845. //---------------------------------------------------------------------------
  6846. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6847. {
  6848. RestoreApp();
  6849. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6850. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6851. !NonVisualDataModule->Busy)
  6852. {
  6853. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6854. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6855. if (!ComponentVisible[fcQueueView])
  6856. {
  6857. ToggleQueueVisibility();
  6858. GoToQueue();
  6859. }
  6860. }
  6861. }
  6862. //---------------------------------------------------------------------------
  6863. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6864. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6865. {
  6866. UnicodeString Message;
  6867. TNotifyEvent OnClick = NULL;
  6868. TObject * UserData = NULL;
  6869. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6870. switch (Event)
  6871. {
  6872. case qeEmptyButMonitored:
  6873. if ((ATerminal != Terminal) || QueueInvisible)
  6874. {
  6875. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6876. OnClick = QueueEmptyNoteClicked;
  6877. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6878. TerminalNoteData->Terminal = ATerminal;
  6879. UserData = TerminalNoteData;
  6880. }
  6881. break;
  6882. case qeEmpty:
  6883. OperationComplete(ATerminal->QueueOperationStart);
  6884. break;
  6885. case qePendingUserAction:
  6886. if ((ATerminal != Terminal) ||
  6887. (QueueInvisible && !IsQueueAutoPopup()))
  6888. {
  6889. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6890. }
  6891. break;
  6892. default:
  6893. DebugFail();
  6894. }
  6895. if (!Message.IsEmpty())
  6896. {
  6897. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6898. }
  6899. }
  6900. //---------------------------------------------------------------------------
  6901. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6902. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6903. {
  6904. if (FDDExtMapFile != NULL)
  6905. {
  6906. CloseHandle(FDDExtMapFile);
  6907. FDDExtMapFile = NULL;
  6908. }
  6909. if (WinConfiguration->DDFakeFile)
  6910. {
  6911. DDFakeFileInitDrag(FileList, Created);
  6912. }
  6913. }
  6914. //---------------------------------------------------------------------------
  6915. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6916. {
  6917. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6918. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6919. {
  6920. FFakeFileDropTarget = FileName;
  6921. }
  6922. }
  6923. //---------------------------------------------------------------------------
  6924. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6925. {
  6926. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6927. if (!ForceDirectories(ApiPath(Result)))
  6928. {
  6929. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6930. }
  6931. FileSetAttr(ApiPath(Result), faHidden);
  6932. return Result;
  6933. }
  6934. //---------------------------------------------------------------------------
  6935. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6936. bool & Created)
  6937. {
  6938. FFakeFileDropTarget = UnicodeString();
  6939. FDragFakeDirectory = CreateFakeTransferDirectory();
  6940. FileList->AddItem(NULL, FDragFakeDirectory);
  6941. Created = true;
  6942. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6943. {
  6944. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6945. }
  6946. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6947. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6948. {
  6949. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6950. TDragExtCommStruct* CommStruct;
  6951. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6952. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6953. DebugAssert(CommStruct != NULL);
  6954. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6955. CommStruct->Dragging = true;
  6956. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6957. LENOF(CommStruct->DropDest));
  6958. NULL_TERMINATE(CommStruct->DropDest);
  6959. UnmapViewOfFile(CommStruct);
  6960. }
  6961. }
  6962. //---------------------------------------------------------------------------
  6963. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6964. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6965. {
  6966. bool Result;
  6967. DebugAssert(!IsLocalBrowserMode());
  6968. if (Sender == RemoteDirView)
  6969. {
  6970. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6971. }
  6972. else
  6973. {
  6974. DebugAssert(Sender == RemoteDriveView);
  6975. TStrings * FileList = RemoteDriveView->DragFileList();
  6976. try
  6977. {
  6978. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6979. }
  6980. __finally
  6981. {
  6982. delete FileList;
  6983. }
  6984. }
  6985. if (FDDTargetControl == RemoteDriveView)
  6986. {
  6987. RemoteDriveView->UpdateDropTarget();
  6988. }
  6989. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6990. // or from tree view to dir view.
  6991. // foMove happens when file/dir is dragged from remote tree view outside of
  6992. // application via dragex
  6993. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6994. (DropSourceControl == RemoteDriveView))
  6995. {
  6996. RemoteDriveView->UpdateDropSource();
  6997. }
  6998. return Result;
  6999. }
  7000. //---------------------------------------------------------------------------
  7001. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  7002. {
  7003. DebugAssert(!IsLocalBrowserMode());
  7004. // This also handles drops of remote files to queue.
  7005. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  7006. SAFE_DESTROY(FDDFileList);
  7007. if (!FFakeFileDropTarget.IsEmpty())
  7008. {
  7009. RemoveDir(ApiPath(FFakeFileDropTarget));
  7010. }
  7011. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  7012. {
  7013. try
  7014. {
  7015. TDragResult DDResult = (Sender == RemoteDirView) ?
  7016. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  7017. // Focus is moved to the target application,
  7018. // but as we are going to present the UI, we need to steal the focus back.
  7019. // This most likely won't work though (windows does not allow application
  7020. // to steal focus most of the time)
  7021. Application->BringToFront();
  7022. // On older version of Windows we never got drMove here, see also comment below.
  7023. // On Windows 10, we get the "move".
  7024. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  7025. {
  7026. UnicodeString TargetDirectory;
  7027. TFileOperation Operation;
  7028. // drInvalid may mean drMove, see comment below
  7029. switch (DDResult)
  7030. {
  7031. case drCopy:
  7032. Operation = foCopy;
  7033. break;
  7034. case drMove:
  7035. Operation = foMove;
  7036. break;
  7037. default:
  7038. DebugFail();
  7039. case drInvalid:
  7040. // prefer "copy" for safety
  7041. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7042. break;
  7043. }
  7044. TTransferOperationParam Param;
  7045. UnicodeString CounterName;
  7046. bool ForceQueue;
  7047. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7048. {
  7049. // we get drInvalid both if d&d was intercepted by ddext,
  7050. // and when users drops on no-drop location.
  7051. // we tell the difference by existence of response from ddext,
  7052. // so we ignore absence of response in this case
  7053. if (DDResult != drInvalid)
  7054. {
  7055. // here we know that the extension is installed,
  7056. // as it is checked as soon as drag&drop starts from
  7057. // RemoteFileControlDDCreateDragFileList
  7058. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7059. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7060. {
  7061. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7062. }
  7063. else
  7064. {
  7065. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7066. }
  7067. }
  7068. }
  7069. else
  7070. {
  7071. // download using fake file
  7072. Param.Temp = false;
  7073. Param.DragDrop = true;
  7074. if (ForceQueue)
  7075. {
  7076. Param.Queue = asOn;
  7077. }
  7078. if (Sender == RemoteDirView)
  7079. {
  7080. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7081. }
  7082. if (RemoteFileControlFileOperation(Sender, Operation,
  7083. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7084. {
  7085. Configuration->Usage->Inc(CounterName);
  7086. }
  7087. }
  7088. }
  7089. }
  7090. __finally
  7091. {
  7092. CloseHandle(FDDExtMapFile);
  7093. FDDExtMapFile = NULL;
  7094. delete FDragFakeMonitors;
  7095. FDragFakeMonitors = NULL;
  7096. RemoveDir(ApiPath(FDragFakeDirectory));
  7097. FDragFakeDirectory = L"";
  7098. FFakeFileDropTarget = UnicodeString();
  7099. }
  7100. }
  7101. if (FDragDropSshTerminate.get() != NULL)
  7102. {
  7103. FDragDropSshTerminate->Rethrow();
  7104. }
  7105. }
  7106. //---------------------------------------------------------------------------
  7107. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7108. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7109. {
  7110. // Remember drop effect so we know (when user drops files), if we copy or move
  7111. FLastDropEffect = dwEffect;
  7112. }
  7113. //---------------------------------------------------------------------------
  7114. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7115. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7116. {
  7117. bool Result;
  7118. if (FDDTargetControl == QueueView3)
  7119. {
  7120. Directory = DefaultDownloadTargetDirectory();
  7121. Result = true;
  7122. CounterName = L"DownloadsDragDropQueue";
  7123. ForceQueue = true;
  7124. }
  7125. else if (!FFakeFileDropTarget.IsEmpty())
  7126. {
  7127. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7128. Result = true;
  7129. ForceQueue = false;
  7130. CounterName = L"DownloadsDragDropFakeFile";
  7131. }
  7132. else
  7133. {
  7134. ForceQueue = false;
  7135. Enabled = false;
  7136. try
  7137. {
  7138. int Timer = 0;
  7139. Result = false;
  7140. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7141. {
  7142. {
  7143. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7144. TDragExtCommStruct* CommStruct;
  7145. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7146. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7147. DebugAssert(CommStruct != NULL);
  7148. Result = !CommStruct->Dragging;
  7149. if (Result)
  7150. {
  7151. Directory = ExtractFilePath(CommStruct->DropDest);
  7152. CounterName = L"DownloadsDragDropExternalExt";
  7153. }
  7154. UnmapViewOfFile(CommStruct);
  7155. }
  7156. if (!Result)
  7157. {
  7158. Sleep(50);
  7159. Timer += 50;
  7160. Application->ProcessMessages();
  7161. }
  7162. }
  7163. }
  7164. __finally
  7165. {
  7166. Enabled = true;
  7167. }
  7168. }
  7169. return Result;
  7170. }
  7171. //---------------------------------------------------------------------------
  7172. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7173. const UnicodeString TempDir, int SecDelay)
  7174. {
  7175. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7176. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7177. if (FDelayedDeletionTimer == NULL)
  7178. {
  7179. DebugAssert(HandleAllocated());
  7180. FDelayedDeletionTimer = new TTimer(this);
  7181. FDelayedDeletionTimer->Interval = 10000;
  7182. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7183. }
  7184. else
  7185. {
  7186. FDelayedDeletionTimer->Enabled = true;
  7187. }
  7188. }
  7189. //---------------------------------------------------------------------------
  7190. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7191. {
  7192. DebugAssert(FDelayedDeletionList != NULL);
  7193. TDateTime N = Now();
  7194. TDateTime Alert;
  7195. UnicodeString Directory;
  7196. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7197. {
  7198. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7199. if ((N >= Alert) || (Sender == NULL))
  7200. {
  7201. Directory = FDelayedDeletionList->Strings[Index];
  7202. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7203. {
  7204. FDelayedDeletionList->Delete(Index);
  7205. }
  7206. }
  7207. }
  7208. if (FDelayedDeletionList->Count == 0)
  7209. {
  7210. FDelayedDeletionTimer->Enabled = false;
  7211. }
  7212. }
  7213. //---------------------------------------------------------------------------
  7214. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7215. {
  7216. DebugAssert(!IsLocalBrowserMode());
  7217. if (IsFileControl(FDDTargetControl, osRemote) ||
  7218. (FDDTargetControl == SessionsPageControl))
  7219. {
  7220. TTerminal * TargetTerminal = NULL;
  7221. TFileOperation Operation = foNone;
  7222. if (FDDTargetControl == SessionsPageControl)
  7223. {
  7224. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7225. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7226. // do not allow dropping on the "+" tab
  7227. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7228. if (TargetTerminal != NULL)
  7229. {
  7230. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7231. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7232. {
  7233. Operation = foRemoteMove;
  7234. }
  7235. else
  7236. {
  7237. Operation = foRemoteCopy;
  7238. }
  7239. }
  7240. }
  7241. else
  7242. {
  7243. if (FLastDropEffect == DROPEFFECT_MOVE)
  7244. {
  7245. Operation = foRemoteMove;
  7246. }
  7247. else if (FLastDropEffect == DROPEFFECT_COPY)
  7248. {
  7249. Operation = foRemoteCopy;
  7250. }
  7251. }
  7252. if (Operation != foNone)
  7253. {
  7254. RemoteFileControlFileOperation(DropSourceControl,
  7255. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7256. }
  7257. // abort drag&drop
  7258. Abort();
  7259. }
  7260. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7261. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7262. (FDDTargetControl != QueueView3))
  7263. {
  7264. DebugAssert(!FDragTempDir.IsEmpty());
  7265. TTransferType Type;
  7266. UnicodeString TempDir = FDragTempDir;
  7267. // We clear FDragTempDir before calling
  7268. // just in case it fail (raises exception)
  7269. FDragTempDir = L"";
  7270. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7271. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7272. // empty directory parameter means temp directory -> don't display it!
  7273. UnicodeString TargetDir = L"";
  7274. int Options = 0;
  7275. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7276. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7277. {
  7278. Abort();
  7279. }
  7280. // TargetDir is set when dropped on local file control
  7281. // (this was workaround for legacy dirview event handling, now it should be
  7282. // made prettier)
  7283. if (TargetDir.IsEmpty())
  7284. {
  7285. TargetDir = TempDir;
  7286. if (ForceDirectories(ApiPath(TargetDir)))
  7287. {
  7288. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7289. FPendingTempSpaceWarn = true;
  7290. try
  7291. {
  7292. FDragDropOperation = true;
  7293. int Params = cpTemporary |
  7294. (Type == ttMove ? cpDelete : 0);
  7295. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7296. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7297. }
  7298. __finally
  7299. {
  7300. FDragDropOperation = false;
  7301. FPendingTempSpaceWarn = false;
  7302. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7303. }
  7304. }
  7305. else
  7306. {
  7307. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7308. }
  7309. }
  7310. }
  7311. }
  7312. //---------------------------------------------------------------------------
  7313. void __fastcall TCustomScpExplorerForm::DDDownload(
  7314. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7315. {
  7316. DebugAssert(!IsLocalBrowserMode());
  7317. TAutoBatch AutoBatch(this);
  7318. UpdateCopyParamCounters(*CopyParam);
  7319. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7320. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7321. {
  7322. RemoteDriveView->UpdateDropSource();
  7323. }
  7324. }
  7325. //---------------------------------------------------------------------------
  7326. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7327. {
  7328. public:
  7329. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7330. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7331. {
  7332. }
  7333. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7334. {
  7335. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7336. TDataObjectFilesEx::AllowData(FormatEtc);
  7337. }
  7338. };
  7339. //---------------------------------------------------------------------------
  7340. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7341. TObject * Sender, TDataObject *& DataObject)
  7342. {
  7343. if (FDDExtMapFile != NULL)
  7344. {
  7345. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7346. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7347. {
  7348. Abort();
  7349. }
  7350. if (FileList->Count > 0)
  7351. {
  7352. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7353. if (!FilesObject->IsValid(true, true))
  7354. {
  7355. FilesObject->_Release();
  7356. }
  7357. else
  7358. {
  7359. DataObject = FilesObject;
  7360. }
  7361. }
  7362. }
  7363. }
  7364. //---------------------------------------------------------------------------
  7365. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7366. {
  7367. DebugFail();
  7368. }
  7369. //---------------------------------------------------------------------------
  7370. void __fastcall TCustomScpExplorerForm::GoToTree()
  7371. {
  7372. ComponentVisible[fcRemoteTree] = true;
  7373. DriveView(osRemote)->SetFocus();
  7374. }
  7375. //---------------------------------------------------------------------------
  7376. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7377. TPanelExport Export)
  7378. {
  7379. TCustomDirView * DirView = this->DirView(Side);
  7380. std::unique_ptr<TStrings> ExportData(new TStringList());
  7381. switch (Export)
  7382. {
  7383. case pePath:
  7384. ExportData->Add(DirView->PathName);
  7385. break;
  7386. case peFileList:
  7387. case peFullFileList:
  7388. {
  7389. bool FullPath = (Export == peFullFileList);
  7390. DirView->CreateFileList(false, FullPath, ExportData.get());
  7391. for (int Index = 0; Index < ExportData->Count; Index++)
  7392. {
  7393. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7394. {
  7395. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7396. }
  7397. }
  7398. }
  7399. break;
  7400. default:
  7401. DebugFail();
  7402. }
  7403. return ExportData.release();
  7404. }
  7405. //---------------------------------------------------------------------------
  7406. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7407. TPanelExport Export, TPanelExportDestination Destination)
  7408. {
  7409. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7410. PanelExportStore(Side, Export, Destination, ExportData.get());
  7411. }
  7412. //---------------------------------------------------------------------------
  7413. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7414. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7415. TStrings * ExportData)
  7416. {
  7417. if (Destination == pedClipboard)
  7418. {
  7419. TInstantOperationVisualizer Visualizer;
  7420. CopyToClipboard(ExportData);
  7421. }
  7422. else
  7423. {
  7424. DebugFail();
  7425. }
  7426. }
  7427. //---------------------------------------------------------------------------
  7428. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7429. {
  7430. TCustomDirView * DirView = this->DirView(Side);
  7431. UnicodeString Mask = DirView->Mask;
  7432. if (DoFilterMaskDialog(DirView, Mask))
  7433. {
  7434. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7435. Configuration->Usage->Inc(L"Filters");
  7436. }
  7437. }
  7438. //---------------------------------------------------------------------------
  7439. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7440. {
  7441. return FQueueController->DefaultOperation();
  7442. }
  7443. //---------------------------------------------------------------------------
  7444. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7445. TQueueOperation Operation, void ** Param)
  7446. {
  7447. switch (Operation)
  7448. {
  7449. case qoPreferences:
  7450. return true;
  7451. case qoGoTo:
  7452. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7453. case qoOnceEmpty:
  7454. return IsAnythingQueued();
  7455. default:
  7456. return FQueueController->AllowOperation(Operation, Param);
  7457. }
  7458. }
  7459. //---------------------------------------------------------------------------
  7460. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7461. {
  7462. if (DebugAlwaysTrue(QueueView3->Visible))
  7463. {
  7464. QueueView3->SetFocus();
  7465. }
  7466. }
  7467. //---------------------------------------------------------------------------
  7468. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7469. TQueueOperation Operation, void * Param)
  7470. {
  7471. if (Operation == qoGoTo)
  7472. {
  7473. GoToQueue();
  7474. }
  7475. else if (Operation == qoPreferences)
  7476. {
  7477. PreferencesDialog(pmQueue);
  7478. }
  7479. else
  7480. {
  7481. FQueueController->ExecuteOperation(Operation, Param);
  7482. }
  7483. }
  7484. //---------------------------------------------------------------------------
  7485. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7486. {
  7487. return (Queue != NULL) && Queue->Enabled;
  7488. }
  7489. //---------------------------------------------------------------------------
  7490. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7491. {
  7492. DebugAssert(Queue != NULL);
  7493. if (Queue != NULL)
  7494. {
  7495. Queue->Enabled = !Queue->Enabled;
  7496. }
  7497. }
  7498. //---------------------------------------------------------------------------
  7499. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7500. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7501. {
  7502. FQueueActedItem = QueueView3->ItemFocused;
  7503. }
  7504. //---------------------------------------------------------------------------
  7505. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7506. {
  7507. return TopDock->Height + QueueSplitter->Height;
  7508. }
  7509. //---------------------------------------------------------------------------
  7510. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7511. {
  7512. return
  7513. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7514. (QueueDock->Visible ? QueueDock->Height : 0) +
  7515. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7516. }
  7517. //---------------------------------------------------------------------------
  7518. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7519. {
  7520. return ScaleByTextHeight(this, 48);
  7521. }
  7522. //---------------------------------------------------------------------------
  7523. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7524. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7525. {
  7526. // when queue is hidden by double-clicking splitter, stray attempt to
  7527. // resize the panel with strange value arrives, make sure it is ignored
  7528. if (ComponentVisible[fcQueueView])
  7529. {
  7530. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7531. if (NewSize > MaxHeightLimit)
  7532. {
  7533. NewSize = MaxHeightLimit;
  7534. }
  7535. int MinHeightLimit =
  7536. GetStaticQueuePanelComponentsHeight() +
  7537. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7538. GetMinQueueViewHeight();
  7539. if (NewSize < MinHeightLimit)
  7540. {
  7541. NewSize = MinHeightLimit;
  7542. }
  7543. }
  7544. else
  7545. {
  7546. Accept = false;
  7547. }
  7548. }
  7549. //---------------------------------------------------------------------------
  7550. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7551. {
  7552. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7553. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7554. if (QueueViewHeight < GetMinQueueViewHeight())
  7555. {
  7556. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7557. }
  7558. }
  7559. //---------------------------------------------------------------------------
  7560. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7561. TDragObject *& /*DragObject*/)
  7562. {
  7563. FQueueActedItem = QueueView3->ItemFocused;
  7564. }
  7565. //---------------------------------------------------------------------------
  7566. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7567. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7568. {
  7569. Accept = true;
  7570. if (Source == QueueView3)
  7571. {
  7572. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7573. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7574. if (Accept)
  7575. {
  7576. TQueueItemProxy * QueueItem;
  7577. TQueueItemProxy * DestQueueItem;
  7578. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7579. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7580. Accept = (QueueItem != DestQueueItem) &&
  7581. (QueueItem->Status == TQueueItem::qsPending) &&
  7582. (DestQueueItem->Status == TQueueItem::qsPending);
  7583. }
  7584. }
  7585. }
  7586. //---------------------------------------------------------------------------
  7587. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7588. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7589. {
  7590. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7591. {
  7592. TQueueItemProxy * QueueItem;
  7593. TQueueItemProxy * DestQueueItem;
  7594. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7595. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7596. QueueItem->Move(DestQueueItem);
  7597. }
  7598. }
  7599. //---------------------------------------------------------------------------
  7600. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7601. {
  7602. if ((QueueView3->ItemFocused == NULL) &&
  7603. (QueueView3->Items->Count > 0))
  7604. {
  7605. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7606. }
  7607. QueueLabelUpdateStatus();
  7608. }
  7609. //---------------------------------------------------------------------------
  7610. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7611. {
  7612. QueueLabelUpdateStatus();
  7613. }
  7614. //---------------------------------------------------------------------------
  7615. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7616. {
  7617. QueueLabel->UpdateStatus();
  7618. }
  7619. //---------------------------------------------------------------------------
  7620. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7621. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7622. {
  7623. if (Selected)
  7624. {
  7625. NonVisualDataModule->UpdateNonVisibleActions();
  7626. }
  7627. }
  7628. //---------------------------------------------------------------------------
  7629. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7630. {
  7631. TDragDropFilesEx * Result = NULL;
  7632. if (Sender == SessionsPageControl)
  7633. {
  7634. Result = FSessionsDragDropFilesEx;
  7635. }
  7636. else if (Sender == QueueView3)
  7637. {
  7638. Result = FQueueDragDropFilesEx;
  7639. }
  7640. else
  7641. {
  7642. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7643. if (DirView != NULL)
  7644. {
  7645. Result = DirView->DragDropFilesEx;
  7646. }
  7647. else
  7648. {
  7649. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7650. if (DriveView != NULL)
  7651. {
  7652. Result = DriveView->DragDropFilesEx;
  7653. }
  7654. }
  7655. }
  7656. DebugAssert(Result != NULL);
  7657. return Result;
  7658. }
  7659. //---------------------------------------------------------------------------
  7660. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7661. {
  7662. return (DView->SelCount == DView->FilesCount);
  7663. }
  7664. //---------------------------------------------------------------------------
  7665. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7666. {
  7667. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7668. }
  7669. //---------------------------------------------------------------------------
  7670. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7671. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7672. {
  7673. DebugAssert(!IsLocalBrowserMode());
  7674. TFileOperation Operation;
  7675. switch (Effect)
  7676. {
  7677. case DROPEFFECT_MOVE:
  7678. Operation = foMove;
  7679. break;
  7680. case DROPEFFECT_COPY:
  7681. // occures on WinXP (reported by user)
  7682. default:
  7683. Operation = foCopy;
  7684. break;
  7685. };
  7686. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7687. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7688. if (DragDropFilesEx->FileList->Count > 0)
  7689. {
  7690. TStrings * FileList = new TStringList();
  7691. try
  7692. {
  7693. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7694. {
  7695. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7696. }
  7697. FDragDropOperation = true;
  7698. TTransferOperationParam Param;
  7699. Param.TargetDirectory = TargetPath;
  7700. // upload, no temp dirs
  7701. Param.Temp = false;
  7702. Param.DragDrop = DragDrop;
  7703. Param.Options =
  7704. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7705. if (ForceQueue)
  7706. {
  7707. Param.Queue = asOn;
  7708. }
  7709. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7710. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7711. {
  7712. if (IsFileControl(DropSourceControl, osLocal))
  7713. {
  7714. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7715. }
  7716. else
  7717. {
  7718. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7719. }
  7720. }
  7721. }
  7722. __finally
  7723. {
  7724. FDragDropOperation = false;
  7725. delete FileList;
  7726. }
  7727. }
  7728. }
  7729. //---------------------------------------------------------------------------
  7730. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7731. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7732. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7733. {
  7734. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7735. }
  7736. //---------------------------------------------------------------------------
  7737. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7738. TObject * Sender, int grfKeyState, int & dwEffect)
  7739. {
  7740. DebugAssert(!IsLocalBrowserMode());
  7741. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7742. if ((dwEffect != DROPEFFECT_NONE) &&
  7743. IsFileControl(DropSourceControl, osRemote))
  7744. {
  7745. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7746. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7747. (RemoteDirView->DropTarget == NULL))
  7748. {
  7749. dwEffect = DROPEFFECT_NONE;
  7750. }
  7751. else
  7752. {
  7753. if (dwEffect == DROPEFFECT_COPY)
  7754. {
  7755. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7756. // currently we support copying always (at least via temporary directory);
  7757. // remove associated checks once this all proves stable and working
  7758. bool CopyCapable = true;
  7759. // if we do not support neither of operations, there's no discussion
  7760. if (!MoveCapable && !CopyCapable)
  7761. {
  7762. dwEffect = DROPEFFECT_NONE;
  7763. }
  7764. else
  7765. {
  7766. // The default effect inside remote panel is move,
  7767. // unless we do not support it, but support copy
  7768. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7769. {
  7770. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7771. }
  7772. else
  7773. {
  7774. // with ctrl-down, we want copy unless it is not supported
  7775. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7776. }
  7777. }
  7778. }
  7779. }
  7780. }
  7781. }
  7782. //---------------------------------------------------------------------------
  7783. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7784. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7785. {
  7786. DebugAssert(!IsLocalBrowserMode());
  7787. if (FDDTotalSize >= 0)
  7788. {
  7789. if (File->IsDirectory)
  7790. {
  7791. FDDTotalSize = -1;
  7792. }
  7793. else
  7794. {
  7795. FDDTotalSize += File->Size;
  7796. }
  7797. }
  7798. DebugAssert(!FDragTempDir.IsEmpty());
  7799. // TODO: this is quite ineffective
  7800. // TODO: what if invalid character replacement is disabled?
  7801. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7802. UnicodeString TransferFileName;
  7803. if (Sender == RemoteDriveView)
  7804. {
  7805. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7806. }
  7807. else
  7808. {
  7809. TransferFileName = File->FileName;
  7810. }
  7811. FDDFileList->AddObject(TransferFileName, File);
  7812. }
  7813. //---------------------------------------------------------------------------
  7814. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7815. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7816. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7817. {
  7818. // sometimes we do not get DDEnd so the list is not released
  7819. SAFE_DESTROY(FDDFileList);
  7820. FDDFileList = new TStringList();
  7821. FDragTempDir = WinConfiguration->TemporaryDir();
  7822. FDDTotalSize = 0;
  7823. FDragDropSshTerminate.reset(NULL);
  7824. }
  7825. //---------------------------------------------------------------------------
  7826. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7827. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7828. HRESULT & Result)
  7829. {
  7830. if (Result == DRAGDROP_S_DROP)
  7831. {
  7832. try
  7833. {
  7834. GlobalDragImageList->HideDragImage();
  7835. try
  7836. {
  7837. RemoteFileControlDDTargetDrop();
  7838. }
  7839. catch(ESshTerminate & E)
  7840. {
  7841. FDragDropSshTerminate.reset(E.Clone());
  7842. }
  7843. }
  7844. catch (Exception &E)
  7845. {
  7846. // If downloading fails we need to cancel drag&drop, otherwise
  7847. // Explorer shows error
  7848. // But by the way exception probably never reach this point as
  7849. // it's catched on way.
  7850. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7851. Result = DRAGDROP_S_CANCEL;
  7852. ShowExtendedException(Terminal, &E);
  7853. }
  7854. }
  7855. }
  7856. //---------------------------------------------------------------------------
  7857. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7858. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7859. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7860. {
  7861. TFileMasks::TParams MaskParams;
  7862. MaskParams.Size = Size;
  7863. MaskParams.Modification = Modification;
  7864. // this does not re-parse the mask if it is the same as the last time
  7865. FDirViewMatchMask = Masks;
  7866. bool ImplicitMatch;
  7867. Matches =
  7868. // RecurseInclude parameter has no effect as the Path is empty
  7869. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7870. (AllowImplicitMatches || !ImplicitMatch);
  7871. }
  7872. //---------------------------------------------------------------------------
  7873. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7874. TObject * Sender, TListItem * Item, WORD & Indexes)
  7875. {
  7876. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7877. UnicodeString Ext;
  7878. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7879. {
  7880. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7881. }
  7882. else
  7883. {
  7884. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7885. }
  7886. if (SameText(Ext, Configuration->PartialExt))
  7887. {
  7888. Indexes |= oiPartial;
  7889. }
  7890. }
  7891. //---------------------------------------------------------------------------
  7892. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7893. {
  7894. return
  7895. DirViewEnabled(osCurrent) &&
  7896. DirView(osCurrent)->CanPasteFromClipBoard();
  7897. }
  7898. //---------------------------------------------------------------------------
  7899. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7900. {
  7901. bool Result = false;
  7902. if (CanPasteToDirViewFromClipBoard())
  7903. {
  7904. Result = true;
  7905. }
  7906. else
  7907. {
  7908. UnicodeString ClipboardText;
  7909. if (NonEmptyTextFromClipboard(ClipboardText) &&
  7910. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  7911. {
  7912. if (StoredSessions->IsUrl(ClipboardText))
  7913. {
  7914. Result = true;
  7915. }
  7916. else
  7917. {
  7918. Result = DirViewEnabled(osCurrent);
  7919. }
  7920. }
  7921. }
  7922. return Result;
  7923. }
  7924. //---------------------------------------------------------------------------
  7925. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7926. {
  7927. if (DoesClipboardContainOurFiles())
  7928. {
  7929. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7930. {
  7931. DebugAssert(!IsLocalBrowserMode());
  7932. TTerminalManager * Manager = TTerminalManager::Instance();
  7933. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7934. Manager->ActiveTerminal = FClipboardTerminal;
  7935. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7936. }
  7937. }
  7938. else if (CanPasteToDirViewFromClipBoard())
  7939. {
  7940. DirView(osCurrent)->PasteFromClipBoard();
  7941. }
  7942. else
  7943. {
  7944. UnicodeString ClipboardText;
  7945. if (NonEmptyTextFromClipboard(ClipboardText))
  7946. {
  7947. if (StoredSessions->IsUrl(ClipboardText))
  7948. {
  7949. NewSession(ClipboardText);
  7950. }
  7951. else
  7952. {
  7953. DirView(osCurrent)->Path = ClipboardText;
  7954. }
  7955. }
  7956. }
  7957. }
  7958. //---------------------------------------------------------------------------
  7959. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7960. {
  7961. // TBD
  7962. }
  7963. //---------------------------------------------------------------------------
  7964. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7965. {
  7966. TCustomDirView * ADirView = DirView(Side);
  7967. ADirView->SelectAll(Mode);
  7968. ADirView->SetFocus();
  7969. }
  7970. //---------------------------------------------------------------------------
  7971. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7972. {
  7973. TCustomDirView * ADirView = DirView(Side);
  7974. TFileFilter Filter;
  7975. DefaultFileFilter(Filter);
  7976. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7977. {
  7978. Configuration->Usage->Inc(L"MaskSelections");
  7979. ADirView->SelectFiles(Filter, Select);
  7980. ADirView->SetFocus();
  7981. }
  7982. }
  7983. //---------------------------------------------------------------------------
  7984. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7985. {
  7986. TCustomDirView * ADirView = DirView(Side);
  7987. ADirView->RestoreSelectedNames();
  7988. ADirView->SetFocus();
  7989. }
  7990. //---------------------------------------------------------------------------
  7991. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7992. {
  7993. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7994. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7995. {
  7996. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7997. UnicodeString Ext;
  7998. if (!IsSideLocalBrowser(osCurrent))
  7999. {
  8000. Ext = UnixExtractFileExt(FileName);
  8001. }
  8002. else
  8003. {
  8004. Ext = ExtractFileExt(FileName);
  8005. }
  8006. if (Ext.IsEmpty())
  8007. {
  8008. Ext = L".";
  8009. }
  8010. TFileFilter Filter;
  8011. Filter.Masks = FORMAT(L"*%s", (Ext));
  8012. Filter.Directories = false;
  8013. CurrentDirView->SelectFiles(Filter, Select);
  8014. }
  8015. }
  8016. //---------------------------------------------------------------------------
  8017. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  8018. const TStatusFileInfo & FileInfo, TOperationSide Side)
  8019. {
  8020. UnicodeString Result;
  8021. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  8022. {
  8023. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  8024. }
  8025. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  8026. {
  8027. // noop
  8028. }
  8029. else
  8030. {
  8031. Result =
  8032. FMTLOAD(FILE_INFO_FORMAT,
  8033. (FormatBytes(FileInfo.SelectedSize),
  8034. FormatBytes(FileInfo.FilesSize),
  8035. FormatNumber(FileInfo.SelectedCount),
  8036. FormatNumber(FileInfo.FilesCount)));
  8037. }
  8038. return Result;
  8039. }
  8040. //---------------------------------------------------------------------------
  8041. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8042. TTBXStatusPanel * Panel, TOperationSide Side)
  8043. {
  8044. if (Panel->Index == 1)
  8045. {
  8046. ToggleShowHiddenFiles();
  8047. }
  8048. else if (Panel->Index == 2)
  8049. {
  8050. Filter(Side);
  8051. }
  8052. }
  8053. //---------------------------------------------------------------------------
  8054. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8055. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8056. {
  8057. DebugAssert(!StatusBar->SimplePanel);
  8058. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8059. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8060. }
  8061. //---------------------------------------------------------------------------
  8062. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8063. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8064. {
  8065. DebugAssert(StatusBar->Panels->Count >= 3);
  8066. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8067. if (FileInfo.HiddenCount > 0)
  8068. {
  8069. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8070. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8071. }
  8072. else
  8073. {
  8074. HiddenFilesPanel->ViewPriority = 0;
  8075. // not really necessary, just to cleanup no-longer-valid data
  8076. HiddenFilesPanel->Caption = L"";
  8077. }
  8078. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8079. if (FileInfo.FilteredCount > 0)
  8080. {
  8081. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8082. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8083. }
  8084. else
  8085. {
  8086. FilteredFilesPanel->ViewPriority = 0;
  8087. // not really necessary, just to cleanup no-longer-valid data
  8088. FilteredFilesPanel->Caption = L"";
  8089. }
  8090. }
  8091. //---------------------------------------------------------------------------
  8092. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8093. TObject * /*Sender*/)
  8094. {
  8095. if (DirView(osOther)->Enabled)
  8096. {
  8097. DirView(osOther)->SetFocus();
  8098. }
  8099. }
  8100. //---------------------------------------------------------------------------
  8101. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8102. {
  8103. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8104. switch (Config.Show)
  8105. {
  8106. case qvShow:
  8107. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8108. {
  8109. Config.Show = qvHide;
  8110. }
  8111. else
  8112. {
  8113. Config.Show = Config.LastHideShow;
  8114. }
  8115. break;
  8116. case qvHideWhenEmpty:
  8117. if (ComponentVisible[fcQueueView])
  8118. {
  8119. Config.Show = qvHide;
  8120. }
  8121. else
  8122. {
  8123. Config.LastHideShow = Config.Show;
  8124. Config.Show = qvShow;
  8125. }
  8126. break;
  8127. case qvHide:
  8128. Config.LastHideShow = Config.Show;
  8129. Config.Show = qvShow;
  8130. break;
  8131. }
  8132. WinConfiguration->QueueView = Config;
  8133. }
  8134. //---------------------------------------------------------------------------
  8135. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8136. {
  8137. UnicodeString Result;
  8138. if (FTerminal != NULL)
  8139. {
  8140. switch (WinConfiguration->PathInCaption)
  8141. {
  8142. case picShort:
  8143. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8144. break;
  8145. case picFull:
  8146. Result = FTerminal->CurrentDirectory;
  8147. break;
  8148. }
  8149. }
  8150. return Result;
  8151. }
  8152. //---------------------------------------------------------------------------
  8153. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8154. {
  8155. TColor Result = GetWindowColor(FSessionColor);
  8156. return Result;
  8157. }
  8158. //---------------------------------------------------------------------------
  8159. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8160. {
  8161. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8162. return Result;
  8163. }
  8164. //---------------------------------------------------------------------------
  8165. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8166. {
  8167. TTerminalManager::Instance()->UpdateAppTitle();
  8168. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8169. // background to gray on Windows 7 (works on Windows 10).
  8170. // See also EnableControl
  8171. if (Showing)
  8172. {
  8173. if (Terminal != NULL)
  8174. {
  8175. // Update path when it changes
  8176. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8177. {
  8178. UpdateSessionTab(SessionsPageControl->ActivePage);
  8179. }
  8180. }
  8181. NonVisualDataModule->ReconnectSessionAction->Update();
  8182. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8183. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8184. CenterReconnectToolbar();
  8185. bool HasTerminal = HasActiveTerminal();
  8186. RemoteDirView->Enabled = HasTerminal;
  8187. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8188. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8189. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8190. RemoteDriveView->Color = RemoteDirView->Color;
  8191. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8192. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8193. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8194. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8195. QueueFileList->Enabled = QueueView3->Enabled;
  8196. QueueFileList->Color = QueueView3->Color;
  8197. QueueFileList->Font->Color = QueueView3->Font->Color;
  8198. QueueLabelUpdateStatus();
  8199. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8200. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8201. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8202. }
  8203. }
  8204. //---------------------------------------------------------------------------
  8205. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8206. {
  8207. UpdateControls();
  8208. }
  8209. //---------------------------------------------------------------------------
  8210. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8211. TObject * Sender)
  8212. {
  8213. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8214. DebugAssert(DirView != NULL);
  8215. DoDirViewLoaded(DirView);
  8216. TransferPresetAutoSelect();
  8217. }
  8218. //---------------------------------------------------------------------------
  8219. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8220. {
  8221. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8222. // first run after installation
  8223. if (double(Updates.LastCheck) == 0)
  8224. {
  8225. // make sure next time there will be an update (if enabled)
  8226. Updates.LastCheck = TDateTime(1);
  8227. WinConfiguration->Updates = Updates;
  8228. }
  8229. else if ((double(Updates.Period) > 0) &&
  8230. (Now() - Updates.LastCheck >= Updates.Period))
  8231. {
  8232. TThreadMethod OnUpdatesChecked = NULL;
  8233. if (!IsUWP())
  8234. {
  8235. OnUpdatesChecked = UpdatesChecked;
  8236. }
  8237. StartUpdateThread(OnUpdatesChecked);
  8238. }
  8239. }
  8240. //---------------------------------------------------------------------------
  8241. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8242. {
  8243. UnicodeString Message;
  8244. bool New;
  8245. TQueryType Type;
  8246. GetUpdatesMessage(Message, New, Type, false);
  8247. if (!Message.IsEmpty())
  8248. {
  8249. if (New)
  8250. {
  8251. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8252. }
  8253. if (!New && (Type != qtWarning))
  8254. {
  8255. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8256. }
  8257. else
  8258. {
  8259. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8260. }
  8261. if (New)
  8262. {
  8263. Configuration->Usage->Inc(L"UpdateNotifications");
  8264. }
  8265. }
  8266. }
  8267. //---------------------------------------------------------------------------
  8268. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8269. {
  8270. RestoreApp();
  8271. bool CanDisplay = !NonVisualDataModule->Busy;
  8272. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8273. {
  8274. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8275. }
  8276. if (CanDisplay)
  8277. {
  8278. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8279. CheckForUpdates(true);
  8280. }
  8281. else
  8282. {
  8283. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8284. }
  8285. }
  8286. //---------------------------------------------------------------------------
  8287. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8288. TCopyParamRuleData & Data)
  8289. {
  8290. DebugAssert(Terminal != NULL);
  8291. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8292. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8293. Data.RemoteDirectory = RemoteDirView->PathName;
  8294. }
  8295. //---------------------------------------------------------------------------
  8296. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8297. {
  8298. // Terminal can be null when we are changing local directory implicitly,
  8299. // because it has been deleted, while no session is connected
  8300. // (Login dialog is open)
  8301. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8302. {
  8303. DebugAssert(!IsLocalBrowserMode());
  8304. TCopyParamRuleData Data;
  8305. GetTransferPresetAutoSelectData(Data);
  8306. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8307. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8308. if (CopyParamIndex < 0)
  8309. {
  8310. // there is no preset that matches autoselection
  8311. // set preset that we consider "default"
  8312. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8313. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8314. }
  8315. else
  8316. {
  8317. // there is preset matching autoselection
  8318. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8319. if (CopyParamName == FCopyParamAutoSelected)
  8320. {
  8321. // autoselected the same preset as the last time
  8322. // make no change (i.e. preserve custom user preset, if any)
  8323. }
  8324. else
  8325. {
  8326. // autoselected the different preset then the last time (or there
  8327. // was default preset set)
  8328. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8329. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8330. }
  8331. }
  8332. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8333. {
  8334. if (CopyParamIndex >= 0)
  8335. {
  8336. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8337. }
  8338. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8339. try
  8340. {
  8341. int Fmt =
  8342. (CopyParamIndex < 0) ?
  8343. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8344. COPY_PARAM_AUTOSELECTED;
  8345. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8346. Data->Message = MainInstructions(Message);
  8347. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8348. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8349. CopyParamAttrs);
  8350. if (CopyParamIndex >= 0)
  8351. {
  8352. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8353. Info = FORMAT(L"%s\n \n%s", (Info,
  8354. FMTLOAD(COPY_PARAM_RULE,
  8355. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8356. }
  8357. Data->Message += L"\n\n" + Info;
  8358. if (WinConfiguration->CopyParamAutoSelectNotice)
  8359. {
  8360. TransferPresetNoteMessage(Data, true);
  8361. }
  8362. else
  8363. {
  8364. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8365. Data = NULL; // ownership passed
  8366. }
  8367. }
  8368. __finally
  8369. {
  8370. delete Data;
  8371. }
  8372. }
  8373. }
  8374. }
  8375. //---------------------------------------------------------------------------
  8376. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8377. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8378. {
  8379. DebugAssert(NoteData != NULL);
  8380. DebugAssert(!IsLocalBrowserMode());
  8381. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8382. TQueryButtonAlias Aliases[1];
  8383. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8384. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8385. Params.Aliases = Aliases;
  8386. Params.AliasesCount = LENOF(Aliases);
  8387. unsigned int Result =
  8388. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8389. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8390. switch (Result)
  8391. {
  8392. case qaNeverAskAgain:
  8393. DebugAssert(AllowNeverAskAgain);
  8394. WinConfiguration->CopyParamAutoSelectNotice = false;
  8395. break;
  8396. case qaIgnore:
  8397. PreferencesDialog(pmPresets);
  8398. break;
  8399. }
  8400. }
  8401. //---------------------------------------------------------------------------
  8402. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8403. {
  8404. // as of now useless, as this is used for notes only, never for balloons, ...
  8405. RestoreApp();
  8406. // .. and we should never be busy here
  8407. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8408. {
  8409. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8410. }
  8411. }
  8412. //---------------------------------------------------------------------------
  8413. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8414. TPreferencesMode APreferencesMode)
  8415. {
  8416. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8417. TCopyParamRuleData Data;
  8418. if (Terminal != NULL)
  8419. {
  8420. PreferencesData.reset(new TPreferencesDialogData());
  8421. GetTransferPresetAutoSelectData(Data);
  8422. PreferencesData->CopyParamRuleData = &Data;
  8423. }
  8424. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8425. }
  8426. //---------------------------------------------------------------------------
  8427. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8428. const TCustomCommandType & Command)
  8429. {
  8430. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8431. {
  8432. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8433. }
  8434. }
  8435. //---------------------------------------------------------------------------
  8436. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8437. {
  8438. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8439. TCustomCommandType Command;
  8440. // make sure we use local custom command when remote are not supported
  8441. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8442. {
  8443. Command = FLastCustomCommand;
  8444. }
  8445. else
  8446. {
  8447. Command.Params = Command.Params | ccLocal;
  8448. }
  8449. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8450. FEditingFocusedAdHocCommand = OnFocused;
  8451. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8452. int Options =
  8453. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8454. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8455. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8456. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8457. {
  8458. FLastCustomCommand = Command;
  8459. UpdateCustomCommandsToolbar();
  8460. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8461. }
  8462. }
  8463. //---------------------------------------------------------------------------
  8464. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8465. {
  8466. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8467. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8468. DebugAssert(State > 0);
  8469. if (State <= 0)
  8470. {
  8471. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8472. }
  8473. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8474. }
  8475. //---------------------------------------------------------------------------
  8476. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8477. TCustomCommandType & Command, int & State)
  8478. {
  8479. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8480. if (Result)
  8481. {
  8482. Command = FLastCustomCommand;
  8483. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8484. }
  8485. return Result;
  8486. }
  8487. //---------------------------------------------------------------------------
  8488. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8489. {
  8490. ResetIncrementalSearch();
  8491. }
  8492. //---------------------------------------------------------------------------
  8493. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8494. {
  8495. DebugAssert(ComponentVisible[Component]);
  8496. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8497. }
  8498. //---------------------------------------------------------------------------
  8499. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8500. {
  8501. // when queue panel is resized here directly, the status bar is stretched
  8502. // over whole space the panel occupied
  8503. PostComponentHide(fcQueueView);
  8504. }
  8505. //---------------------------------------------------------------------------
  8506. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8507. {
  8508. ComponentVisible[fcQueueFileList] = false;
  8509. }
  8510. //---------------------------------------------------------------------------
  8511. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8512. {
  8513. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8514. RefreshColorMode();
  8515. ResetSysDarkTheme();
  8516. ConfigurationChanged();
  8517. ConfigureInterface();
  8518. // Should be called for all controls
  8519. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8520. }
  8521. //---------------------------------------------------------------------------
  8522. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8523. {
  8524. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8525. if (!FInvalid &&
  8526. (Message.LParam != 0) &&
  8527. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8528. {
  8529. ThemeChanged();
  8530. }
  8531. TForm::Dispatch(&Message);
  8532. }
  8533. //---------------------------------------------------------------------------
  8534. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8535. {
  8536. TMessage * M = static_cast<TMessage*>(Message);
  8537. switch (M->Msg)
  8538. {
  8539. case CM_DIALOGCHAR:
  8540. CMDialogChar(*M);
  8541. break;
  8542. case WM_APPCOMMAND:
  8543. WMAppCommand(*M);
  8544. break;
  8545. case WM_SYSCOMMAND:
  8546. WMSysCommand(*M);
  8547. break;
  8548. case WM_QUERYENDSESSION:
  8549. WMQueryEndSession(*M);
  8550. break;
  8551. case WM_ENDSESSION:
  8552. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8553. break;
  8554. #ifdef _DEBUG
  8555. case WM_WINDOWPOSCHANGED:
  8556. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8557. break;
  8558. case CM_CUSTOMSTYLECHANGED:
  8559. TForm::Dispatch(Message);
  8560. break;
  8561. #endif
  8562. case WM_COMPONENT_HIDE:
  8563. {
  8564. Byte Component = static_cast<Byte>(M->WParam);
  8565. // sanity check
  8566. if (ComponentVisible[Component])
  8567. {
  8568. // special treatment
  8569. if (Component == fcQueueView)
  8570. {
  8571. ToggleQueueVisibility();
  8572. DebugAssert(!ComponentVisible[fcQueueView]);
  8573. }
  8574. else
  8575. {
  8576. ComponentVisible[Component] = false;
  8577. }
  8578. }
  8579. }
  8580. break;
  8581. case WM_COPYDATA:
  8582. WMCopyData(*M);
  8583. break;
  8584. case WM_MANAGES_CAPTION:
  8585. // caption managed in TTerminalManager::UpdateAppTitle()
  8586. M->Result = 1;
  8587. break;
  8588. case WM_WANTS_MOUSEWHEEL:
  8589. M->Result = 1;
  8590. break;
  8591. case CM_SHOWINGCHANGED:
  8592. CMShowingChanged(*M);
  8593. break;
  8594. case WM_CLOSE:
  8595. WMClose(*M);
  8596. break;
  8597. case WM_DPICHANGED:
  8598. WMDpiChanged(*M);
  8599. break;
  8600. case CM_DPICHANGED:
  8601. CMDpiChanged(*M);
  8602. break;
  8603. case WM_SETTINGCHANGE:
  8604. WMSettingChange(*M);
  8605. break;
  8606. case CM_DIALOGKEY:
  8607. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8608. break;
  8609. default:
  8610. TForm::Dispatch(Message);
  8611. break;
  8612. }
  8613. }
  8614. //---------------------------------------------------------------------------
  8615. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8616. {
  8617. // noop
  8618. }
  8619. //---------------------------------------------------------------------------
  8620. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8621. {
  8622. TForm::Dispatch(&Message);
  8623. FSessionColors->Clear();
  8624. AddFixedSessionImages();
  8625. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8626. UpdateImages();
  8627. }
  8628. //---------------------------------------------------------------------------
  8629. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8630. {
  8631. TForm::Dispatch(&Message);
  8632. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8633. UpdatePixelsPerInchMainWindowCounter();
  8634. }
  8635. //---------------------------------------------------------------------------
  8636. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8637. {
  8638. // Cannot close window while we are busy.
  8639. // We cannot test this in FormCloseQuery as that is called also from
  8640. // Close(), which is called by CloseApplicationAction. So we can be busy
  8641. // there already even, when it is legitimate to close the application.
  8642. // Possibly a better place to handle this would be WMSysCommand.
  8643. if (NonVisualDataModule->Busy)
  8644. {
  8645. Message.Result = 1;
  8646. }
  8647. else
  8648. {
  8649. TForm::Dispatch(&Message);
  8650. }
  8651. }
  8652. //---------------------------------------------------------------------------
  8653. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8654. {
  8655. TForm::Dispatch(&Message);
  8656. if (Showing && (Terminal == NULL))
  8657. {
  8658. // When we are starting minimized (i.e. from an installer),
  8659. // postpone showing Login dialog until we get restored.
  8660. // Otherwise the Login dialog (and Authentication window) show restored
  8661. // over invisible (minimized) main window.
  8662. if (WindowState == wsMinimized)
  8663. {
  8664. FNeedSession = true;
  8665. }
  8666. else
  8667. {
  8668. // This happens before application ever goes idle, so the toolbars would
  8669. // stay enabled (initial state) until the Login dialog is dismissed.
  8670. UpdateActions();
  8671. NonVisualDataModule->StartBusy();
  8672. try
  8673. {
  8674. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8675. // otherwise the dialog does not receive focus.
  8676. // With Commander interface the ProcessMessages is called already
  8677. // by TDriveView, but with Explorer interface, we need to call it explicily
  8678. Application->ProcessMessages();
  8679. // do not reload sessions, they have been loaded just now (optimization)
  8680. NeedSession(true);
  8681. }
  8682. __finally
  8683. {
  8684. NonVisualDataModule->EndBusy();
  8685. }
  8686. }
  8687. }
  8688. }
  8689. //---------------------------------------------------------------------------
  8690. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8691. {
  8692. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8693. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8694. }
  8695. //---------------------------------------------------------------------------
  8696. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8697. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8698. int & MaxHeight)
  8699. {
  8700. // workaround for bug in TWinControl.CalcConstraints
  8701. // Check for empty rect (restore from iconic state) is done there only after
  8702. // call to AdjustClientRect, which enlarges the rect (for forms).
  8703. TRect R = GetClientRect();
  8704. // when restoring from iconic state, place no restrictions
  8705. if (IsRectEmpty(R))
  8706. {
  8707. MinWidth = 0;
  8708. MinHeight = 0;
  8709. MaxWidth = 32000;
  8710. MaxHeight = 32000;
  8711. }
  8712. }
  8713. //---------------------------------------------------------------------------
  8714. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8715. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8716. {
  8717. // terminal can be already closed (e.g. dropped connection)
  8718. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8719. {
  8720. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8721. try
  8722. {
  8723. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8724. }
  8725. catch(...)
  8726. {
  8727. if (!Terminal->Active)
  8728. {
  8729. Close = true;
  8730. }
  8731. throw;
  8732. }
  8733. }
  8734. }
  8735. //---------------------------------------------------------------------------
  8736. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8737. {
  8738. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8739. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8740. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8741. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8742. {
  8743. OnGetSpaceAvailable = GetSpaceAvailable;
  8744. }
  8745. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8746. OnGetSpaceAvailable);
  8747. }
  8748. //---------------------------------------------------------------------------
  8749. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8750. {
  8751. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8752. Terminal->FillSessionDataForCode(Data.get());
  8753. return Data.release();
  8754. }
  8755. //---------------------------------------------------------------------------
  8756. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8757. {
  8758. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8759. DoGenerateUrlDialog(Data.get(), Paths);
  8760. }
  8761. //---------------------------------------------------------------------------
  8762. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8763. {
  8764. GenerateUrl(NULL);
  8765. }
  8766. //---------------------------------------------------------------------------
  8767. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8768. {
  8769. std::unique_ptr<TStrings> Paths(new TStringList());
  8770. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8771. GenerateUrl(Paths.get());
  8772. }
  8773. //---------------------------------------------------------------------------
  8774. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8775. {
  8776. FSessionColor = value;
  8777. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8778. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8779. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8780. DebugAssert(ColorItem != NULL);
  8781. ColorItem->Color = C;
  8782. NonVisualDataModule->ColorMenuItem->Color = C;
  8783. UpdateControls();
  8784. }
  8785. //---------------------------------------------------------------------------
  8786. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8787. {
  8788. if (value != FSessionColor)
  8789. {
  8790. UpdateSessionColor(value);
  8791. // Is null when called from LastTerminalClosed
  8792. if (Terminal != NULL)
  8793. {
  8794. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8795. }
  8796. }
  8797. }
  8798. //---------------------------------------------------------------------------
  8799. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8800. {
  8801. bool Result = FNoteTimer->Enabled;
  8802. if (Result)
  8803. {
  8804. // cannot cancel note too early
  8805. bool NotEarly =
  8806. (Now() - FNoteShown >
  8807. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8808. if (Force || NotEarly)
  8809. {
  8810. FNoteTimer->Enabled = false;
  8811. FNote = L"";
  8812. SAFE_DESTROY(FNoteData);
  8813. FOnNoteClick = NULL;
  8814. FNoteHints = FNotes->Text;
  8815. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8816. UpdateStatusBar();
  8817. }
  8818. }
  8819. return Result;
  8820. }
  8821. //---------------------------------------------------------------------------
  8822. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8823. {
  8824. DebugAssert(FNoteTimer->Enabled);
  8825. CancelNote(true);
  8826. }
  8827. //---------------------------------------------------------------------------
  8828. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  8829. {
  8830. FNoteHints = FNotes->Text.TrimRight();
  8831. }
  8832. //---------------------------------------------------------------------------
  8833. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8834. {
  8835. int P = Note.Pos(L"\n");
  8836. if (P > 0)
  8837. {
  8838. Note.SetLength(P - 1);
  8839. }
  8840. FNotes->Add(FORMAT(L"[%s] %s",
  8841. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8842. while (FNotes->Count > 10)
  8843. {
  8844. FNotes->Delete(0);
  8845. }
  8846. if (UpdateNow)
  8847. {
  8848. UpdateNoteHints();
  8849. UpdateStatusBar();
  8850. }
  8851. }
  8852. //---------------------------------------------------------------------------
  8853. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8854. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8855. {
  8856. int P = Note.Pos(L"\n");
  8857. if (P > 0)
  8858. {
  8859. Note.SetLength(P - 1);
  8860. }
  8861. UpdateNoteHints();
  8862. FNote = Note;
  8863. SAFE_DESTROY(FNoteData);
  8864. FNoteData = NoteData;
  8865. FOnNoteClick = OnNoteClick;
  8866. AddNote(Note, false);
  8867. UpdateStatusBar();
  8868. FNoteShown = Now();
  8869. FNoteTimer->Enabled = false;
  8870. if (Seconds == 0)
  8871. {
  8872. Seconds = WinConfiguration->NotificationsTimeout;
  8873. }
  8874. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8875. FNoteTimer->Enabled = true;
  8876. }
  8877. //---------------------------------------------------------------------------
  8878. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8879. {
  8880. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8881. }
  8882. //---------------------------------------------------------------------------
  8883. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8884. {
  8885. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  8886. {
  8887. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8888. }
  8889. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8890. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8891. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  8892. 0, NULL, NULL);
  8893. }
  8894. //---------------------------------------------------------------------------
  8895. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8896. {
  8897. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8898. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8899. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8900. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  8901. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8902. }
  8903. //---------------------------------------------------------------------------
  8904. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8905. {
  8906. WinConfiguration->FormatSizeBytes = Style;
  8907. }
  8908. //---------------------------------------------------------------------------
  8909. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8910. {
  8911. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8912. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8913. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8914. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8915. }
  8916. //---------------------------------------------------------------------------
  8917. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8918. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8919. {
  8920. if (Panel->Index == 0)
  8921. {
  8922. if (FOnNoteClick != NULL)
  8923. {
  8924. // prevent the user data from being freed by possible call
  8925. // to CancelNote or PostNote during call to OnNoteClick
  8926. std::unique_ptr<TObject> NoteData(FNoteData);
  8927. TNotifyEvent OnNoteClick = FOnNoteClick;
  8928. FNoteData = NULL;
  8929. // need to cancel the note as we are going to delete its user data
  8930. CancelNote(true);
  8931. OnNoteClick(NoteData.get());
  8932. }
  8933. }
  8934. if (HasActiveTerminal() &&
  8935. (Panel->Index >= Sender->Panels->Count - SessionPanelCount))
  8936. {
  8937. FileSystemInfo();
  8938. }
  8939. }
  8940. //---------------------------------------------------------------------------
  8941. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8942. {
  8943. // workaround:
  8944. // 1) for unknown reason, disabling window, while minimized,
  8945. // prevents it from restoring, even if it was enabled again meanwhile
  8946. // 2) when disabling the main window, while another has focus
  8947. // minimize is no longer possible
  8948. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8949. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8950. // Shouldn't we use IsApplicationMinimized() here?
  8951. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8952. {
  8953. Enabled = false;
  8954. }
  8955. FLockLevel++;
  8956. }
  8957. //---------------------------------------------------------------------------
  8958. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8959. {
  8960. DebugAssert(FLockLevel > 0);
  8961. FLockLevel--;
  8962. if (FLockLevel == 0)
  8963. {
  8964. DebugAssert(FLockSuspendLevel == 0);
  8965. Enabled = true;
  8966. }
  8967. }
  8968. //---------------------------------------------------------------------------
  8969. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8970. {
  8971. // We need to make sure that window is enabled when the last modal window closes
  8972. // otherwise focus is not restored correctly.
  8973. // So we re-enable the window when modal window opens and
  8974. // disable it back after is closes
  8975. if (FLockLevel > 0)
  8976. {
  8977. // while we have nesting counter, we know that we never be called
  8978. // recursivelly as Application->OnModalBegin is called only
  8979. // for the top-level modal window
  8980. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8981. {
  8982. // won't be disabled when conditions in LockWindow() were not satisfied
  8983. FDisabledOnLockSuspend = !Enabled;
  8984. // When minimized to tray (or actually when set to SW_HIDE),
  8985. // setting Enabled makes the window focusable even when there's
  8986. // modal window over it
  8987. if (!FTrayIcon->Visible)
  8988. {
  8989. Enabled = true;
  8990. }
  8991. }
  8992. FLockSuspendLevel++;
  8993. }
  8994. }
  8995. //---------------------------------------------------------------------------
  8996. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8997. {
  8998. if (FLockSuspendLevel > 0)
  8999. {
  9000. DebugAssert(FLockLevel > 0);
  9001. FLockSuspendLevel--;
  9002. // see comment in SuspendWindowLock
  9003. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9004. {
  9005. // Note that window can be enabled here, when we were minized to tray when
  9006. // was SuspendWindowLock() called.
  9007. // We should possibly do the same check as in LockWindow(),
  9008. // if it is ever possible that the consitions change between
  9009. // SuspendWindowLock() and ResumeWindowLock()
  9010. Enabled = !FDisabledOnLockSuspend;
  9011. }
  9012. }
  9013. }
  9014. //---------------------------------------------------------------------------
  9015. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9016. {
  9017. TTBXComboBoxItem * RemotePathComboBox =
  9018. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9019. if (!TextOnly)
  9020. {
  9021. TStrings * Items = RemotePathComboBox->Strings;
  9022. Items->BeginUpdate();
  9023. try
  9024. {
  9025. Items->Clear();
  9026. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9027. {
  9028. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9029. while (!IsUnixRootPath(APath))
  9030. {
  9031. int P = APath.LastDelimiter(L'/');
  9032. DebugAssert(P >= 0);
  9033. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9034. APath.SetLength(P - 1);
  9035. }
  9036. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9037. }
  9038. }
  9039. __finally
  9040. {
  9041. Items->EndUpdate();
  9042. }
  9043. }
  9044. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9045. // Setting ItemIndex to -1 does not reset its text
  9046. if (RemotePathComboBox->Strings->Count == 0)
  9047. {
  9048. RemotePathComboBox->Text = L"";
  9049. }
  9050. }
  9051. //---------------------------------------------------------------------------
  9052. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9053. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9054. {
  9055. if (AIndex < 0)
  9056. {
  9057. AIndex = Sender->ItemIndex;
  9058. }
  9059. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9060. }
  9061. //---------------------------------------------------------------------------
  9062. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9063. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9064. int & ImageIndex)
  9065. {
  9066. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9067. }
  9068. //---------------------------------------------------------------------------
  9069. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9070. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9071. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9072. {
  9073. if (!IsLocalBrowserMode())
  9074. {
  9075. ARect.Left += (10 * AIndex);
  9076. }
  9077. }
  9078. //---------------------------------------------------------------------------
  9079. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9080. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9081. {
  9082. AWidth += (10 * AIndex);
  9083. }
  9084. //---------------------------------------------------------------------------
  9085. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9086. {
  9087. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9088. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9089. int Index = RemotePathComboBox->ItemIndex;
  9090. while (Index < RemotePathComboBox->Strings->Count - 1)
  9091. {
  9092. APath = UnixExtractFileDir(APath);
  9093. Index++;
  9094. }
  9095. // VanDyke style paths
  9096. if (APath.IsEmpty())
  9097. {
  9098. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9099. APath = ROOTDIRECTORY;
  9100. }
  9101. if (RemoteDirView->Path != APath)
  9102. {
  9103. RemoteDirView->Path = APath;
  9104. }
  9105. }
  9106. //---------------------------------------------------------------------------
  9107. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9108. {
  9109. DoRemotePathComboBoxItemClick(Sender);
  9110. }
  9111. //---------------------------------------------------------------------------
  9112. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9113. {
  9114. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9115. DebugUsedParam(Sender);
  9116. UpdateRemotePathComboBox(true);
  9117. }
  9118. //---------------------------------------------------------------------------
  9119. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9120. {
  9121. DoRemotePathComboBoxCancel(Sender);
  9122. }
  9123. //---------------------------------------------------------------------------
  9124. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9125. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9126. {
  9127. ResetIncrementalSearch();
  9128. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9129. DebugAssert(DirView != NULL);
  9130. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9131. {
  9132. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9133. // OnEditing is called also from TCustomListView::CanEdit
  9134. if (Edit != NULL)
  9135. {
  9136. EditSelectBaseName(Edit);
  9137. }
  9138. }
  9139. }
  9140. //---------------------------------------------------------------------------
  9141. //---------------------------------------------------------------------------
  9142. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9143. {
  9144. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9145. Result->AutoDetectDnD = false;
  9146. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9147. Result->RenderDataOn = rdoEnterAndDropSync;
  9148. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9149. return Result;
  9150. }
  9151. //---------------------------------------------------------------------------
  9152. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9153. {
  9154. TForm::CreateWnd();
  9155. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9156. if (FSessionsDragDropFilesEx == NULL)
  9157. {
  9158. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9159. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9160. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9161. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9162. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9163. }
  9164. if (FQueueDragDropFilesEx == NULL)
  9165. {
  9166. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9167. // No need to set OnDragOver as we do not have any restrictions
  9168. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9169. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9170. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9171. }
  9172. }
  9173. //---------------------------------------------------------------------------
  9174. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9175. {
  9176. TForm::DestroyWnd();
  9177. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9178. FQueueDragDropFilesEx->DragDropControl = NULL;
  9179. }
  9180. //---------------------------------------------------------------------------
  9181. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9182. {
  9183. SideEnter(FCurrentSide);
  9184. FEverShown = true;
  9185. }
  9186. //---------------------------------------------------------------------------
  9187. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9188. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9189. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9190. {
  9191. if (!NonVisualDataModule->Busy)
  9192. {
  9193. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9194. Configuration->Usage->Inc(L"FileFinds");
  9195. LockWindow(true);
  9196. NonVisualDataModule->StartBusy();
  9197. WinConfiguration->LockedInterface = true;
  9198. try
  9199. {
  9200. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9201. }
  9202. __finally
  9203. {
  9204. WinConfiguration->LockedInterface = false;
  9205. NonVisualDataModule->EndBusy();
  9206. UnlockWindow();
  9207. }
  9208. }
  9209. }
  9210. //---------------------------------------------------------------------------
  9211. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9212. {
  9213. if (!NonVisualDataModule->Busy)
  9214. {
  9215. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9216. SetFocus();
  9217. RemoteDirView->Path = UnixExtractFilePath(Path);
  9218. UnicodeString FileName = UnixExtractFileName(Path);
  9219. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9220. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9221. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9222. if (Item == NULL)
  9223. {
  9224. ReloadDirectory(osRemote);
  9225. Item = RemoteDirView->FindFileItem(FileName);
  9226. }
  9227. if (Item != NULL)
  9228. {
  9229. RemoteDirView->ItemFocused = Item;
  9230. RemoteDirView->ItemFocused->MakeVisible(false);
  9231. RemoteDirView->SetFocus();
  9232. }
  9233. }
  9234. }
  9235. //---------------------------------------------------------------------------
  9236. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9237. {
  9238. bool Result = !NonVisualDataModule->Busy;
  9239. if (Result)
  9240. {
  9241. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9242. }
  9243. return Result;
  9244. }
  9245. //---------------------------------------------------------------------------
  9246. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9247. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9248. {
  9249. if (CanOperateOnFoundFiles(ATerminal))
  9250. {
  9251. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9252. FOnFileOperationFinished = OnFileOperationFinished;
  9253. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9254. }
  9255. }
  9256. //---------------------------------------------------------------------------
  9257. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9258. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9259. {
  9260. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9261. }
  9262. //---------------------------------------------------------------------------
  9263. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9264. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9265. {
  9266. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9267. }
  9268. //---------------------------------------------------------------------------
  9269. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9270. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9271. {
  9272. if (CanOperateOnFoundFiles(ATerminal))
  9273. {
  9274. for (int Index = 0; Index < FileList->Count; Index++)
  9275. {
  9276. UnicodeString FileName = FileList->Strings[Index];
  9277. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9278. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9279. OnFileOperationFinished(FileName, true);
  9280. }
  9281. }
  9282. }
  9283. //---------------------------------------------------------------------------
  9284. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9285. {
  9286. FFileFindTerminal = Terminal;
  9287. ShowFileFindDialog(
  9288. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9289. DoDownloadFoundFiles, DoEditFoundFiles);
  9290. }
  9291. //---------------------------------------------------------------------------
  9292. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9293. {
  9294. FTaskbarList = TaskbarList;
  9295. }
  9296. //---------------------------------------------------------------------------
  9297. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9298. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9299. {
  9300. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9301. if (Index >= 0)
  9302. {
  9303. if (Button == mbLeft)
  9304. {
  9305. // "Mouse down" is raised only after tab is switched.
  9306. // If switching tab (switching session) takes long enough for user
  9307. // to actually release the button, "mouse down" is still raised,
  9308. // but we do not get "mouse up" event, so dragging is not cancelled,
  9309. // prevent that by not beginning dragging in the first place.
  9310. if (IsKeyPressed(VK_LBUTTON))
  9311. {
  9312. // when user clicks the "+", we get mouse down only after the session
  9313. // is closed, when new session tab is already on X:Y, so dragging
  9314. // starts, prevent that
  9315. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9316. {
  9317. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9318. if (Terminal != NULL)
  9319. {
  9320. SessionsPageControl->BeginDrag(false);
  9321. }
  9322. }
  9323. }
  9324. }
  9325. else if (Button == mbMiddle)
  9326. {
  9327. // ignore middle-click for "New session tab"
  9328. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9329. if (Terminal != NULL)
  9330. {
  9331. CloseSessionTab(Index);
  9332. }
  9333. }
  9334. }
  9335. }
  9336. //---------------------------------------------------------------------------
  9337. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9338. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9339. {
  9340. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9341. // do not allow dropping on the "+" tab
  9342. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9343. if ((TargetTerminal != NULL) &&
  9344. (SessionsPageControl->ActivePage->PageIndex != Index))
  9345. {
  9346. Configuration->Usage->Inc(L"SessionTabMoves");
  9347. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9348. // but we want to actually prevent that to avoid flicker
  9349. SessionsPageControl->ActivePage->PageIndex = Index;
  9350. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9351. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9352. }
  9353. }
  9354. //---------------------------------------------------------------------------
  9355. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9356. TObject * Sender, TObject * Source, int X, int Y,
  9357. TDragState /*State*/, bool & Accept)
  9358. {
  9359. Accept = (Sender == Source);
  9360. if (Accept)
  9361. {
  9362. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9363. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9364. // do not allow dragging to the "+" tab
  9365. Accept = (Terminal != NULL);
  9366. }
  9367. }
  9368. //---------------------------------------------------------------------------
  9369. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9370. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9371. {
  9372. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9373. if (Index < 0)
  9374. {
  9375. Effect = DROPEFFECT_NONE;
  9376. }
  9377. else
  9378. {
  9379. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9380. // do not allow dropping on the "+" tab
  9381. if (TargetTerminal == NULL)
  9382. {
  9383. Effect = DROPEFFECT_NONE;
  9384. }
  9385. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9386. {
  9387. Effect = DROPEFFECT_COPY;
  9388. }
  9389. }
  9390. }
  9391. //---------------------------------------------------------------------------
  9392. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9393. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9394. {
  9395. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9396. // do not allow dropping on the "+" tab
  9397. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9398. if (TargetTerminal != NULL)
  9399. {
  9400. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9401. if (!IsFileControl(DropSourceControl, osRemote))
  9402. {
  9403. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9404. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9405. // Why don't we use Terminal->CurrentDirectory directly?
  9406. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9407. // do not force queue, drag drop
  9408. false, true);
  9409. }
  9410. }
  9411. }
  9412. //---------------------------------------------------------------------------
  9413. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9414. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9415. {
  9416. // Downloads are handled in RemoteFileControlDDEnd
  9417. if (!IsFileControl(DropSourceControl, osRemote))
  9418. {
  9419. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9420. Terminal->CurrentDirectory,
  9421. // force queue, drag drop
  9422. true, true);
  9423. }
  9424. }
  9425. //---------------------------------------------------------------------------
  9426. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9427. {
  9428. FShowing = false;
  9429. // Do not save empty workspace
  9430. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9431. {
  9432. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9433. UnicodeString Name = WorkspaceName();
  9434. DoSaveWorkspace(
  9435. Name, DataList.get(),
  9436. !Configuration->DisablePasswordStoring &&
  9437. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9438. WinConfiguration->LastStoredSession = Name;
  9439. }
  9440. }
  9441. //---------------------------------------------------------------------------
  9442. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9443. {
  9444. TManagedTerminal * ManagedTerminal =
  9445. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9446. if (ManagedTerminal != NULL)
  9447. {
  9448. ManagedTerminal->DirectoryLoaded = Now();
  9449. }
  9450. }
  9451. //---------------------------------------------------------------------------
  9452. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9453. TListItem * /*Item*/, bool /*Selected*/)
  9454. {
  9455. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9456. switch (DirView->LastSelectMethod)
  9457. {
  9458. case smKeyboard:
  9459. Configuration->Usage->Inc(L"KeyboardSelections");
  9460. break;
  9461. case smMouse:
  9462. Configuration->Usage->Inc(L"MouseSelections");
  9463. break;
  9464. }
  9465. }
  9466. //---------------------------------------------------------------------------
  9467. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9468. {
  9469. if (Color != 0)
  9470. {
  9471. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9472. }
  9473. else
  9474. {
  9475. return FSessionTabImageIndex;
  9476. }
  9477. }
  9478. //---------------------------------------------------------------------------
  9479. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9480. {
  9481. TPngImageCollectionItem * Item =
  9482. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9483. FSessionColors->AddPng(Item->PngImage);
  9484. return FSessionColors->Count - 1;
  9485. }
  9486. //---------------------------------------------------------------------------
  9487. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9488. {
  9489. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9490. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9491. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9492. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9493. }
  9494. //---------------------------------------------------------------------------
  9495. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9496. {
  9497. for (int Index = 0; Index < Control->ControlCount; Index++)
  9498. {
  9499. TControl * AControl = Control->Controls[Index];
  9500. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9501. if (WinControl != NULL)
  9502. {
  9503. CollectItemsWithTextDisplayMode(WinControl);
  9504. }
  9505. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9506. if (Toolbar != NULL)
  9507. {
  9508. // we care for top-level items only
  9509. TTBCustomItem * Items = Toolbar->Items;
  9510. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9511. {
  9512. TTBCustomItem * Item = Items->Items[ItemIndex];
  9513. if (((Item->DisplayMode == nbdmImageAndText) ||
  9514. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9515. EligibleForImageDisplayMode(Item))
  9516. {
  9517. FItemsWithTextDisplayMode.insert(Item);
  9518. }
  9519. }
  9520. }
  9521. }
  9522. }
  9523. //---------------------------------------------------------------------------
  9524. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9525. {
  9526. return true;
  9527. }
  9528. //---------------------------------------------------------------------------
  9529. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9530. {
  9531. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9532. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9533. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9534. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9535. bool Result = true;
  9536. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9537. {
  9538. TTBCustomItem * Item = *i;
  9539. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9540. if (Label != NULL)
  9541. {
  9542. // optimization
  9543. if (Label->Visible == SelectiveToolbarText)
  9544. {
  9545. Result = false;
  9546. }
  9547. else
  9548. {
  9549. Label->Visible = SelectiveToolbarText;
  9550. }
  9551. }
  9552. else
  9553. {
  9554. // optimization
  9555. if (Item->DisplayMode == DisplayMode)
  9556. {
  9557. Result = false;
  9558. }
  9559. else
  9560. {
  9561. Item->DisplayMode = DisplayMode;
  9562. }
  9563. }
  9564. ++i;
  9565. }
  9566. if (Result)
  9567. {
  9568. UpdateNewSessionTab();
  9569. }
  9570. return Result;
  9571. }
  9572. //---------------------------------------------------------------------------
  9573. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9574. {
  9575. DebugFail();
  9576. }
  9577. //---------------------------------------------------------------------------
  9578. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9579. {
  9580. // Among other, a lock level is non zero, while directory is being loaded,
  9581. // even when it happens as a result of dirview navigation,
  9582. // i.e. when TNonVisualDataModule is NOT FBusy.
  9583. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9584. // Among other this prevents a panel auto update to occur while
  9585. // directory is changing.
  9586. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9587. }
  9588. //---------------------------------------------------------------------------
  9589. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  9590. {
  9591. // While the window is disabled, we still seem to process menu shortcuts at least,
  9592. // so stop it at least here.
  9593. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9594. bool Result;
  9595. if (Allowed == aaUpdate)
  9596. {
  9597. Result = true;
  9598. }
  9599. else
  9600. {
  9601. Result = !NonVisualDataModule->Busy;
  9602. if (Result && (Allowed == aaShortCut))
  9603. {
  9604. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  9605. Action->Update();
  9606. Result = Action->Enabled;
  9607. }
  9608. }
  9609. return Result;
  9610. }
  9611. //---------------------------------------------------------------------------
  9612. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9613. {
  9614. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9615. }
  9616. //---------------------------------------------------------------------------
  9617. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9618. {
  9619. // This is somewhat redundant to LockWindow() call from
  9620. // TTerminalManager::TerminalReadDirectoryProgress.
  9621. // But disabling window is known not to block keyboard shorcuts
  9622. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9623. if (Busy > 0)
  9624. {
  9625. if (NonVisualDataModule->Busy)
  9626. {
  9627. State = false;
  9628. }
  9629. else
  9630. {
  9631. NonVisualDataModule->StartBusy();
  9632. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9633. LockWindow();
  9634. }
  9635. }
  9636. else if (Busy < 0)
  9637. {
  9638. UnlockWindow();
  9639. NonVisualDataModule->EndBusy();
  9640. }
  9641. else
  9642. {
  9643. State = NonVisualDataModule->Busy;
  9644. }
  9645. }
  9646. //---------------------------------------------------------------------------
  9647. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9648. {
  9649. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9650. // no context menu for "New session tab"
  9651. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9652. {
  9653. SessionsPageControl->ActivePageIndex = Index;
  9654. if (DebugAlwaysTrue(SessionTabSwitched()))
  9655. {
  9656. // copied from TControl.WMContextMenu
  9657. SendCancelMode(SessionsPageControl);
  9658. // explicit popup instead of using PopupMenu property
  9659. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9660. // while connecting yet not-connected session and hence
  9661. // allowing an access to commands over not-completelly connected session
  9662. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9663. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9664. PopupMenu->PopupComponent = SessionsPageControl;
  9665. PopupMenu->Popup(Point.x, Point.y);
  9666. }
  9667. }
  9668. Handled = true;
  9669. }
  9670. //---------------------------------------------------------------------------
  9671. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9672. {
  9673. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9674. }
  9675. //---------------------------------------------------------------------------
  9676. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9677. {
  9678. Configuration->Usage->Inc(L"PasswordChanges");
  9679. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9680. ChangePasswordData->DisableAuthentationsExceptPassword();
  9681. ChangePasswordData->ChangePassword = true;
  9682. std::unique_ptr<TTerminal> ChangePasswordSession(
  9683. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9684. ChangePasswordSession->AutoReadDirectory = false;
  9685. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9686. {
  9687. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9688. }
  9689. else
  9690. {
  9691. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9692. }
  9693. }
  9694. //---------------------------------------------------------------------------
  9695. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9696. {
  9697. // No nice way to assert SSH2
  9698. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9699. }
  9700. //---------------------------------------------------------------------------
  9701. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9702. {
  9703. TOperationVisualizer OperationVisualizer;
  9704. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9705. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9706. }
  9707. //---------------------------------------------------------------------------
  9708. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9709. {
  9710. TForm::ChangeScale(M, D);
  9711. int APixelsPerInch = GetControlPixelsPerInch(this);
  9712. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9713. try
  9714. {
  9715. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9716. }
  9717. __finally
  9718. {
  9719. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9720. }
  9721. }
  9722. //---------------------------------------------------------------------------
  9723. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9724. {
  9725. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9726. }
  9727. //---------------------------------------------------------------------
  9728. class TPublicControl : public TControl
  9729. {
  9730. friend class TCustomScpExplorerForm;
  9731. };
  9732. //---------------------------------------------------------------------------
  9733. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9734. {
  9735. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9736. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9737. }
  9738. //---------------------------------------------------------------------------
  9739. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9740. {
  9741. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9742. OpenBookmark(Side, Bookmark);
  9743. }
  9744. //---------------------------------------------------------------------------
  9745. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9746. {
  9747. DoBookmarkClick(osLocal, Sender);
  9748. }
  9749. //---------------------------------------------------------------------------
  9750. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9751. {
  9752. DoBookmarkClick(osRemote, Sender);
  9753. }
  9754. //---------------------------------------------------------------------------
  9755. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9756. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9757. {
  9758. if (BookmarkList != NULL)
  9759. {
  9760. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9761. if (IsLocalBrowserMode())
  9762. {
  9763. Side = osLocal;
  9764. }
  9765. if (!WinConfiguration->UseLocationProfiles)
  9766. {
  9767. std::unique_ptr<TStringList> Directories(new TStringList());
  9768. Directories->CaseSensitive = (Side == osRemote);
  9769. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9770. {
  9771. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9772. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9773. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9774. {
  9775. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9776. Item->Caption = EscapeHotkey(Directory);
  9777. Item->ShortCut = Bookmark->ShortCut;
  9778. Item->OnClick = OnBookmarkClick;
  9779. Item->Tag = reinterpret_cast<int>(Bookmark);
  9780. Directories->Add(Directory);
  9781. Menu->Add(Item.release());
  9782. }
  9783. }
  9784. }
  9785. else
  9786. {
  9787. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9788. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9789. {
  9790. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9791. if (!Bookmark->Node.IsEmpty())
  9792. {
  9793. Folders->Add(Bookmark->Node);
  9794. }
  9795. }
  9796. for (int Index = 0; Index < Folders->Count; Index++)
  9797. {
  9798. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9799. Item->Caption = Folders->Strings[Index];
  9800. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  9801. Folders->Objects[Index] = Item.get();
  9802. Menu->Add(Item.release());
  9803. }
  9804. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9805. {
  9806. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9807. TTBCustomItem * Parent;
  9808. if (!Bookmark->Node.IsEmpty())
  9809. {
  9810. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9811. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9812. }
  9813. else
  9814. {
  9815. Parent = Menu;
  9816. }
  9817. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9818. Item->Caption = Bookmark->Name;
  9819. Item->ShortCut = Bookmark->ShortCut;
  9820. Item->OnClick = OnBookmarkClick;
  9821. Item->Tag = reinterpret_cast<int>(Bookmark);
  9822. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9823. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9824. {
  9825. // No hint for location profiles that are actually mere "bookmarks"
  9826. }
  9827. else
  9828. {
  9829. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9830. UnicodeString LongHint;
  9831. if (!Bookmark->Local.IsEmpty())
  9832. {
  9833. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9834. }
  9835. if (!Bookmark->Remote.IsEmpty())
  9836. {
  9837. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9838. }
  9839. AddToList(Hint, LongHint, L"|");
  9840. Item->Hint = Hint;
  9841. }
  9842. Parent->Add(Item.release());
  9843. }
  9844. }
  9845. AddMenuSeparator(Menu);
  9846. }
  9847. }
  9848. //---------------------------------------------------------------------------
  9849. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9850. {
  9851. Menu->Clear();
  9852. std::unique_ptr<TTBCustomItem> Item;
  9853. Item.reset(new TTBXItem(Owner));
  9854. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9855. Item->Options = Item->Options << tboDefault;
  9856. Menu->Add(Item.release());
  9857. AddMenuSeparator(Menu);
  9858. if (Terminal != NULL)
  9859. {
  9860. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9861. }
  9862. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9863. Item.reset(new TTBXItem(Owner));
  9864. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  9865. Menu->Add(Item.release());
  9866. }
  9867. //---------------------------------------------------------------------------
  9868. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9869. {
  9870. bool Result = true;
  9871. bool Remote = !IsSideLocalBrowser(Side);
  9872. try
  9873. {
  9874. if (Remote)
  9875. {
  9876. Terminal->ExceptionOnFail = true;
  9877. }
  9878. try
  9879. {
  9880. DirView(Side)->Path = Path;
  9881. }
  9882. __finally
  9883. {
  9884. if (Remote)
  9885. {
  9886. Terminal->ExceptionOnFail = false;
  9887. }
  9888. }
  9889. }
  9890. catch (Exception & E)
  9891. {
  9892. if (!Remote || Terminal->Active)
  9893. {
  9894. ShowExtendedExceptionEx(Terminal, &E);
  9895. Result = false;
  9896. }
  9897. else
  9898. {
  9899. throw;
  9900. }
  9901. }
  9902. return Result;
  9903. }
  9904. //---------------------------------------------------------------------------
  9905. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9906. {
  9907. // Make sure there some feedback even when loading tiny local folders
  9908. TInstantOperationVisualizer Visualizer;
  9909. DirView(Side)->ReloadDirectory();
  9910. }
  9911. //---------------------------------------------------------------------------
  9912. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9913. {
  9914. if (Index == SessionsPageControl->TabIndex)
  9915. {
  9916. CloseSession();
  9917. }
  9918. else
  9919. {
  9920. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9921. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9922. TTerminalManager * Manager = TTerminalManager::Instance();
  9923. if (!Terminal->Active)
  9924. {
  9925. Manager->FreeTerminal(Terminal);
  9926. }
  9927. else
  9928. {
  9929. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9930. if (CanCloseQueue(Queue))
  9931. {
  9932. Manager->FreeTerminal(Terminal);
  9933. }
  9934. }
  9935. }
  9936. }
  9937. //---------------------------------------------------------------------------
  9938. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9939. {
  9940. CloseSessionTab(Index);
  9941. }
  9942. //---------------------------------------------------------------------------
  9943. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9944. {
  9945. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9946. {
  9947. TInstantOperationVisualizer Visualizer;
  9948. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9949. // before we create a new data object
  9950. ClipboardClear();
  9951. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9952. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9953. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9954. // Intermediate variable to WORKAROUND a crash in compiler
  9955. TObjectList * ClipboardFakeMonitors =
  9956. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9957. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9958. if (FClipboardDragDropFilesEx.get() == NULL)
  9959. {
  9960. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9961. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9962. }
  9963. FClipboardDragDropFilesEx->FileList->Clear();
  9964. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9965. FClipboardDragDropFilesEx->CopyToClipboard();
  9966. FClipboardTerminal = FTerminal;
  9967. // Need full paths, as cwd can be different once files are pasted
  9968. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9969. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9970. {
  9971. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9972. }
  9973. }
  9974. }
  9975. //---------------------------------------------------------------------------
  9976. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9977. {
  9978. if (OpenClipboard(0))
  9979. {
  9980. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9981. CloseClipboard();
  9982. }
  9983. }
  9984. //---------------------------------------------------------------------------
  9985. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9986. {
  9987. return !FClipboardFakeDirectory.IsEmpty();
  9988. }
  9989. //---------------------------------------------------------------------------
  9990. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9991. {
  9992. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9993. FClipboardFakeDirectory = UnicodeString();
  9994. FClipboardTerminal = NULL;
  9995. // Also called in Idle()
  9996. FClipboardFakeMonitors.reset(NULL);
  9997. }
  9998. //---------------------------------------------------------------------------
  9999. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  10000. {
  10001. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  10002. {
  10003. ClipboardStop();
  10004. }
  10005. }
  10006. //---------------------------------------------------------------------------
  10007. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  10008. {
  10009. TTerminalManager * Manager = TTerminalManager::Instance();
  10010. Manager->ActiveTerminal = FClipboardTerminal;
  10011. TTransferOperationParam Params;
  10012. Params.TargetDirectory = TargetDirectory;
  10013. Params.DragDrop = DragDrop;
  10014. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  10015. }
  10016. //---------------------------------------------------------------------------
  10017. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  10018. {
  10019. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  10020. // (as it pumps a Windows message queue while being shutted down)
  10021. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10022. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10023. {
  10024. // Can fail as it can be e.g. locked by AV, so we retry that later
  10025. bool Removed = RemoveDir(ApiPath(FileName));
  10026. try
  10027. {
  10028. if (!NonVisualDataModule->Busy)
  10029. {
  10030. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10031. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  10032. }
  10033. }
  10034. __finally
  10035. {
  10036. if (!Removed)
  10037. {
  10038. RemoveDir(ApiPath(FileName));
  10039. }
  10040. }
  10041. }
  10042. }
  10043. //---------------------------------------------------------------------------
  10044. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10045. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10046. {
  10047. TFileMasks::TParams MaskParams;
  10048. MaskParams.Size = Size;
  10049. MaskParams.Modification = Modification;
  10050. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10051. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10052. {
  10053. bool ImplicitMatch;
  10054. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  10055. !ImplicitMatch)
  10056. {
  10057. Color = Iter->Color;
  10058. break;
  10059. }
  10060. }
  10061. }
  10062. //---------------------------------------------------------------------------
  10063. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10064. {
  10065. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10066. if (!DirView->IsEditing())
  10067. {
  10068. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10069. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10070. // while searching
  10071. if (Key == VK_BACK)
  10072. {
  10073. if (!FIncrementalSearch.IsEmpty())
  10074. {
  10075. if (FIncrementalSearch.Length() == 1)
  10076. {
  10077. ResetIncrementalSearch();
  10078. }
  10079. else
  10080. {
  10081. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10082. IncrementalSearch(NewText, false, false);
  10083. }
  10084. Key = 0;
  10085. }
  10086. }
  10087. }
  10088. }
  10089. //---------------------------------------------------------------------------
  10090. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10091. {
  10092. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10093. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10094. {
  10095. // Filter control sequences.
  10096. // When not searching yet, prefer use of the space for toggling file selection
  10097. // (so we cannot incrementally search for a string starting with a space).
  10098. if ((Key > VK_SPACE) ||
  10099. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10100. {
  10101. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10102. Key = 0;
  10103. }
  10104. }
  10105. }
  10106. //---------------------------------------------------------------------------
  10107. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10108. {
  10109. if (!FIncrementalSearch.IsEmpty())
  10110. {
  10111. FIncrementalSearch = L"";
  10112. DirView(osCurrent)->UpdateStatusBar();
  10113. }
  10114. }
  10115. //---------------------------------------------------------------------------
  10116. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10117. {
  10118. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10119. if (Item == NULL)
  10120. {
  10121. MessageBeep(MB_ICONHAND);
  10122. }
  10123. else
  10124. {
  10125. TCustomDirView * ADirView = DirView(osCurrent);
  10126. {
  10127. TAutoNestingCounter Guard(FIncrementalSearching);
  10128. ADirView->FocusItem(Item);
  10129. if (ADirView->NortonLike == nlOff)
  10130. {
  10131. if ((ADirView->Selected != Item) ||
  10132. (ADirView->SelCount > 1))
  10133. {
  10134. ADirView->ClearSelection();
  10135. ADirView->Selected = Item;
  10136. }
  10137. }
  10138. }
  10139. FIncrementalSearch = Text;
  10140. Item->MakeVisible(false);
  10141. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10142. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10143. ADirView->UpdateStatusBar();
  10144. }
  10145. }
  10146. //---------------------------------------------------------------------------
  10147. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10148. {
  10149. int Index = Item->Index;
  10150. if (!Reverse)
  10151. {
  10152. Index++;
  10153. if (Index >= Item->Owner->Count)
  10154. {
  10155. Index = 0;
  10156. }
  10157. }
  10158. else
  10159. {
  10160. Index--;
  10161. if (Index < 0)
  10162. {
  10163. Index = Item->Owner->Count - 1;
  10164. }
  10165. }
  10166. return Item->Owner->Item[Index];
  10167. }
  10168. //---------------------------------------------------------------------------
  10169. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10170. {
  10171. TCustomDirView * ADirView = DirView(osCurrent);
  10172. if (ADirView->Items->Count == 0)
  10173. {
  10174. return NULL;
  10175. }
  10176. else
  10177. {
  10178. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10179. TListItem * Item = CurrentItem;
  10180. if (SkipCurrent)
  10181. {
  10182. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10183. }
  10184. while (true)
  10185. {
  10186. bool Matches = false;
  10187. switch (WinConfiguration->PanelSearch)
  10188. {
  10189. case isNameStartOnly:
  10190. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10191. break;
  10192. case isName:
  10193. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10194. break;
  10195. case isAll:
  10196. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10197. int Index = 0;
  10198. while ((Index < ColCount) && !Matches)
  10199. {
  10200. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10201. if (Visible)
  10202. {
  10203. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10204. }
  10205. Index++;
  10206. }
  10207. break;
  10208. }
  10209. if (Matches)
  10210. {
  10211. return Item;
  10212. }
  10213. Item = GetNextFile(Item, Reverse);
  10214. if (Item == CurrentItem)
  10215. {
  10216. return NULL;
  10217. }
  10218. }
  10219. }
  10220. }
  10221. //---------------------------------------------------------------------------
  10222. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10223. {
  10224. ResetIncrementalSearch();
  10225. }
  10226. //---------------------------------------------------------------------------
  10227. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10228. {
  10229. if (Message.CharCode == VK_TAB)
  10230. {
  10231. if (!FIncrementalSearch.IsEmpty())
  10232. {
  10233. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10234. bool Reverse = Shift.Contains(ssShift);
  10235. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10236. Message.Result = 1;
  10237. return;
  10238. }
  10239. }
  10240. else if (Message.CharCode == VK_ESCAPE)
  10241. {
  10242. if (!FIncrementalSearch.IsEmpty())
  10243. {
  10244. ResetIncrementalSearch();
  10245. Message.Result = 1;
  10246. return;
  10247. }
  10248. }
  10249. TForm::Dispatch(&Message);
  10250. }
  10251. //---------------------------------------------------------------------------
  10252. void __fastcall TCustomScpExplorerForm::Deactivate()
  10253. {
  10254. TForm::Deactivate();
  10255. // E.g. when switching to an internal editor window
  10256. ResetIncrementalSearch();
  10257. }
  10258. //---------------------------------------------------------------------------
  10259. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10260. {
  10261. // When switching to another application
  10262. ResetIncrementalSearch();
  10263. }
  10264. //---------------------------------------------------------------------------
  10265. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10266. {
  10267. ResetIncrementalSearch();
  10268. }
  10269. //---------------------------------------------------------------------------
  10270. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10271. {
  10272. if (FIncrementalSearching <= 0)
  10273. {
  10274. ResetIncrementalSearch();
  10275. }
  10276. }
  10277. //---------------------------------------------------------------------------
  10278. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10279. {
  10280. CountClicksForWindowPrint(this);
  10281. }
  10282. //---------------------------------------------------------------------------
  10283. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10284. {
  10285. CenterReconnectToolbar();
  10286. }
  10287. //---------------------------------------------------------------------------
  10288. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10289. {
  10290. if (RemoteDirView->ItemFocused != NULL)
  10291. {
  10292. RemoteDirView->ItemFocused->Selected = true;
  10293. }
  10294. }
  10295. //---------------------------------------------------------------------------
  10296. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10297. {
  10298. if (!FQueueStatusUpdating)
  10299. {
  10300. bool Refresh;
  10301. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10302. {
  10303. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10304. }
  10305. else
  10306. {
  10307. if (FQueueFileList->GetCount() > 0)
  10308. {
  10309. FQueueFileList->Clear();
  10310. Refresh = true;
  10311. }
  10312. }
  10313. int Count = FQueueFileList->GetCount();
  10314. if (QueueFileList->Items->Count != Count)
  10315. {
  10316. DebugAssert(Refresh);
  10317. QueueFileList->Items->Count = Count;
  10318. }
  10319. if (Refresh)
  10320. {
  10321. QueueFileList->Invalidate();
  10322. }
  10323. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10324. }
  10325. }
  10326. //---------------------------------------------------------------------------
  10327. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10328. {
  10329. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10330. }
  10331. //---------------------------------------------------------------------------
  10332. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10333. {
  10334. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10335. // See TSynchronizeChecklistDialog::UpdateTimer
  10336. if (QueueFileList->Items->Count > 0)
  10337. {
  10338. QueueFileList->Items->Item[0]->MakeVisible(false);
  10339. }
  10340. UpdateQueueFileList();
  10341. }
  10342. //---------------------------------------------------------------------------
  10343. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10344. {
  10345. Active = QueueView3->Focused() || QueueFileList->Focused();
  10346. }
  10347. //---------------------------------------------------------------------------
  10348. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10349. {
  10350. QueueLabelUpdateStatus();
  10351. }
  10352. //---------------------------------------------------------------------------
  10353. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10354. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10355. {
  10356. int State = FQueueFileList->GetState(Item->Index);
  10357. if (State == qfsProcessed)
  10358. {
  10359. Sender->Canvas->Font->Color = clGrayText;
  10360. }
  10361. }
  10362. //---------------------------------------------------------------------------
  10363. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10364. {
  10365. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10366. QueueFileList->Column[0]->Width =
  10367. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10368. }
  10369. //---------------------------------------------------------------------------
  10370. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10371. {
  10372. QueueFileListColumnAutoSize();
  10373. }
  10374. //---------------------------------------------------------------------------
  10375. void __fastcall TCustomScpExplorerForm::CloseApp()
  10376. {
  10377. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10378. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10379. // So we clear the flag here.
  10380. DebugAssert(NonVisualDataModule->Busy);
  10381. NonVisualDataModule->EndBusy();
  10382. try
  10383. {
  10384. Close();
  10385. }
  10386. __finally
  10387. {
  10388. NonVisualDataModule->StartBusy();
  10389. }
  10390. }
  10391. //---------------------------------------------------------------------------
  10392. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10393. {
  10394. return (Terminal != NULL) && Terminal->Active;
  10395. }
  10396. //---------------------------------------------------------------------------
  10397. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10398. {
  10399. return IsActiveTerminal(Terminal);
  10400. }
  10401. //---------------------------------------------------------------------------
  10402. void TCustomScpExplorerForm::LocalLocalCopy(
  10403. TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused), bool DebugUsedArg(NoConfirmation),
  10404. bool DebugUsedArg(DragDrop), unsigned int DebugUsedArg(Flags))
  10405. {
  10406. DebugFail();
  10407. }
  10408. //---------------------------------------------------------------------------
  10409. void TCustomScpExplorerForm::LocalLocalCopyCommand(TFileOperation Operation, TOperationSide Side, bool OnFocused, unsigned int Flags)
  10410. {
  10411. LocalLocalCopy(Operation, Side, OnFocused, !WinConfiguration->ConfirmTransferring, false, Flags);
  10412. }