CustomScpExplorer.cpp 365 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102
  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. ManagedSession = 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 SessionListChanged => ... => 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->Sessions[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->ActiveSession = Manager->NewTerminals(DataList.get());
  462. }
  463. }
  464. __finally
  465. {
  466. NonVisualDataModule->EndBusy();
  467. }
  468. }
  469. return Result;
  470. }
  471. //---------------------------------------------------------------------------
  472. TManagedTerminal * TCustomScpExplorerForm::GetTerminal()
  473. {
  474. TManagedTerminal * Result;
  475. if ((FManagedSession != NULL) && !FManagedSession->LocalBrowser)
  476. {
  477. Result = FManagedSession;
  478. }
  479. else
  480. {
  481. Result = NULL;
  482. }
  483. return Result;
  484. }
  485. //---------------------------------------------------------------------------
  486. void __fastcall TCustomScpExplorerForm::SetManagedSession(TManagedTerminal * value)
  487. {
  488. if (FManagedSession != value)
  489. {
  490. TerminalChanging();
  491. DoSetManagedSession(value, false);
  492. }
  493. }
  494. //---------------------------------------------------------------------------
  495. void __fastcall TCustomScpExplorerForm::DoSetManagedSession(TManagedTerminal * value, bool Replace)
  496. {
  497. DebugAssert(!Replace || ((value != NULL) && !value->LocalBrowser));
  498. FManagedSession = value;
  499. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  500. FAllowTransferPresetAutoSelect = false;
  501. try
  502. {
  503. TerminalChanged(Replace);
  504. }
  505. __finally
  506. {
  507. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  508. }
  509. if (Terminal != NULL)
  510. {
  511. TransferPresetAutoSelect();
  512. }
  513. }
  514. //---------------------------------------------------------------------------
  515. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  516. {
  517. DoSetManagedSession(value, true);
  518. }
  519. //---------------------------------------------------------------------------
  520. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  521. {
  522. if (ManagedSession != NULL)
  523. {
  524. UpdateTerminal(ManagedSession);
  525. }
  526. }
  527. //---------------------------------------------------------------------------
  528. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  529. {
  530. if (Terminal != NULL)
  531. {
  532. UpdateSessionColor((TColor)Terminal->StateData->Color);
  533. }
  534. SessionListChanged();
  535. if (Terminal != NULL)
  536. {
  537. if (Replaced)
  538. {
  539. RemoteDirView->ReplaceTerminal(Terminal);
  540. }
  541. else
  542. {
  543. RemoteDirView->Terminal = Terminal;
  544. }
  545. if (Terminal->Active)
  546. {
  547. Terminal->RefreshDirectory();
  548. }
  549. if (WinConfiguration->PreservePanelState)
  550. {
  551. if (Terminal->RemoteExplorerState != NULL)
  552. {
  553. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  554. }
  555. else
  556. {
  557. DirView(osRemote)->ClearState();
  558. }
  559. }
  560. }
  561. else
  562. {
  563. RemoteDirView->Terminal = NULL;
  564. }
  565. InitStatusBar();
  566. UpdateTransferList();
  567. // Update panels Enable state before refreshing the labels
  568. UpdateControls();
  569. }
  570. //---------------------------------------------------------------------------
  571. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  572. {
  573. if (Queue != value)
  574. {
  575. if (FQueue != NULL)
  576. {
  577. FQueue->OnListUpdate = NULL;
  578. FQueue->OnQueueItemUpdate = NULL;
  579. }
  580. FQueue = value;
  581. if (FQueue != NULL)
  582. {
  583. DebugAssert(FQueue->OnListUpdate == NULL);
  584. FQueue->OnListUpdate = QueueListUpdate;
  585. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  586. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  587. }
  588. QueueChanged();
  589. }
  590. }
  591. //---------------------------------------------------------------------------
  592. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  593. TListItem * Item)
  594. {
  595. if (FQueueActedItem == Item)
  596. {
  597. FQueueActedItem = NULL;
  598. if ((QueueView3->PopupMenu != NULL) &&
  599. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  600. {
  601. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  602. ReleaseCapture();
  603. }
  604. }
  605. if (Item->Data == FPendingQueueActionItem)
  606. {
  607. FPendingQueueActionItem = NULL;
  608. }
  609. }
  610. //---------------------------------------------------------------------------
  611. bool TCustomScpExplorerForm::IsAnythingQueued()
  612. {
  613. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  614. }
  615. //---------------------------------------------------------------------------
  616. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  617. {
  618. {
  619. TGuard Guard(FQueueStatusSection);
  620. FQueueStatusInvalidated = false;
  621. if (FQueue != NULL)
  622. {
  623. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  624. }
  625. }
  626. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  627. {
  628. FMaxQueueLength = FQueueStatus->Count;
  629. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  630. }
  631. {
  632. TAutoFlag Flag(FQueueStatusUpdating);
  633. FQueueController->UpdateQueueStatus(FQueueStatus);
  634. }
  635. UpdateQueueFileList();
  636. SetQueueProgress();
  637. UpdateQueueView();
  638. bool IsEmpty = !IsAnythingQueued();
  639. if (IsEmpty && (Terminal != NULL))
  640. {
  641. TOnceDoneOperation OnceDoneOperation =
  642. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  643. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  644. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  645. {
  646. FQueue->Enabled = false;
  647. }
  648. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  649. {
  650. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  651. }
  652. }
  653. }
  654. //---------------------------------------------------------------------------
  655. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  656. {
  657. UnicodeString Result;
  658. if (FQueueStatus != NULL)
  659. {
  660. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  661. {
  662. TFileOperationProgressType * ProgressData =
  663. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  664. if ((ProgressData != NULL) && ProgressData->InProgress)
  665. {
  666. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  667. }
  668. }
  669. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  670. {
  671. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  672. }
  673. }
  674. return Result;
  675. }
  676. //---------------------------------------------------------------------------
  677. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  678. {
  679. ComponentVisible[fcQueueView] =
  680. (WinConfiguration->QueueView.Show == qvShow) ||
  681. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  682. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  683. }
  684. //---------------------------------------------------------------------------
  685. void __fastcall TCustomScpExplorerForm::QueueChanged()
  686. {
  687. if (FQueueStatus != NULL)
  688. {
  689. // UpdateFileList implementation relies on the status being recreated when session changes
  690. delete FQueueStatus;
  691. FQueueStatus = NULL;
  692. }
  693. UpdateQueueStatus(true);
  694. }
  695. //---------------------------------------------------------------------------
  696. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  697. {
  698. if (FQueue == Queue)
  699. {
  700. FQueueStatusInvalidated = true;
  701. }
  702. }
  703. //---------------------------------------------------------------------------
  704. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  705. TQueueItem * Item)
  706. {
  707. if (FQueue == Queue)
  708. {
  709. TGuard Guard(FQueueStatusSection);
  710. // this may be running in parallel with QueueChanged
  711. if (FQueueStatus != NULL)
  712. {
  713. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  714. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  715. {
  716. FRefreshLocalDirectory = (QueueItem == NULL) ||
  717. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  718. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  719. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  720. }
  721. if (QueueItem != NULL)
  722. {
  723. QueueItem->UserData = (void*)true;
  724. FQueueItemInvalidated = true;
  725. }
  726. }
  727. }
  728. }
  729. //---------------------------------------------------------------------------
  730. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  731. {
  732. // during standalone editing, we have no way to see/control queue,
  733. // so we have to always popup prompts automatically
  734. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  735. }
  736. //---------------------------------------------------------------------------
  737. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  738. {
  739. if (FQueueStatus != NULL)
  740. {
  741. bool QueueAutoPopup = IsQueueAutoPopup();
  742. bool NeedRefresh = FQueueController->NeedRefresh();
  743. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  744. FQueueItemInvalidated = false;
  745. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  746. bool Updated = false;
  747. TQueueItemProxy * QueueItem;
  748. bool WasUserAction;
  749. for (int Index = 0; Index < Limit; Index++)
  750. {
  751. bool Update = false;
  752. QueueItem = FQueueStatus->Items[Index];
  753. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  754. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  755. (FPendingQueueActionItem == NULL))
  756. {
  757. FPendingQueueActionItem = QueueItem;
  758. FUserActionTimer->Enabled = true;
  759. }
  760. if ((bool)QueueItem->UserData)
  761. {
  762. QueueItem->UserData = (void*)false;
  763. QueueItem->Update();
  764. Updated = true;
  765. Update = true;
  766. }
  767. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  768. {
  769. Update = true;
  770. }
  771. if (Update)
  772. {
  773. FQueueController->RefreshQueueItem(QueueItem);
  774. }
  775. }
  776. if (Updated)
  777. {
  778. NonVisualDataModule->UpdateNonVisibleActions();
  779. SetQueueProgress();
  780. UpdateQueueFileList();
  781. }
  782. }
  783. }
  784. //---------------------------------------------------------------------------
  785. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  786. {
  787. if (FTaskbarList != NULL)
  788. {
  789. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  790. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  791. }
  792. }
  793. //---------------------------------------------------------------------------
  794. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  795. {
  796. if (Progress >= 0)
  797. {
  798. if (FTaskbarList != NULL)
  799. {
  800. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  801. }
  802. }
  803. else
  804. {
  805. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  806. }
  807. }
  808. //---------------------------------------------------------------------------
  809. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  810. {
  811. int OverallProgress;
  812. // FProgressForm is null when this is called from SetQueueProgress
  813. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  814. {
  815. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  816. }
  817. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  818. {
  819. OverallProgress = ProgressData->OverallProgress();
  820. }
  821. else
  822. {
  823. OverallProgress = -1;
  824. }
  825. SetTaskbarListProgressValue(OverallProgress);
  826. }
  827. //---------------------------------------------------------------------------
  828. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  829. {
  830. TTerminalManager::Instance()->QueueStatusUpdated();
  831. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  832. {
  833. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  834. {
  835. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  836. {
  837. TFileOperationProgressType * ProgressData = NULL;
  838. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  839. {
  840. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  841. }
  842. if ((ProgressData != NULL) &&
  843. ProgressData->InProgress)
  844. {
  845. SetTaskbarListProgressValue(ProgressData);
  846. }
  847. else
  848. {
  849. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  850. }
  851. }
  852. else
  853. {
  854. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  855. }
  856. }
  857. else
  858. {
  859. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  860. }
  861. }
  862. UpdateQueueLabel();
  863. }
  864. //---------------------------------------------------------------------------
  865. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  866. {
  867. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  868. if (FQueueStatus != NULL)
  869. {
  870. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  871. if (ActiveAndPendingPrimaryCount > 0)
  872. {
  873. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  874. }
  875. }
  876. QueueLabel->Caption = Caption;
  877. }
  878. //---------------------------------------------------------------------------
  879. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  880. {
  881. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  882. static_cast<TComponent*>(GetComponent(fcTransferList)));
  883. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  884. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  885. TransferList->Strings->BeginUpdate();
  886. try
  887. {
  888. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  889. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  890. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  891. if (FTransferDropDownHint.IsEmpty())
  892. {
  893. FTransferDropDownHint = TransferDropDown->Hint;
  894. }
  895. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  896. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  897. TransferDropDown->Text = StripHotkey(Name);
  898. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  899. (FTransferDropDownHint, StripHotkey(Name),
  900. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  901. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  902. // update the label, otherwise when it is updated only on the first draw
  903. // of the list, it is drawn "bold" for some reason
  904. FTransferListHoverIndex = TransferList->ItemIndex;
  905. UpdateTransferLabel();
  906. }
  907. __finally
  908. {
  909. TransferList->Strings->EndUpdate();
  910. }
  911. }
  912. //---------------------------------------------------------------------------
  913. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  914. {
  915. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  916. DebugAssert(Toolbar != NULL);
  917. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  918. }
  919. //---------------------------------------------------------------------------
  920. void __fastcall TCustomScpExplorerForm::UpdateActions()
  921. {
  922. TForm::UpdateActions();
  923. if (ComponentVisible[fcCustomCommandsBand])
  924. {
  925. UpdateCustomCommandsToolbar();
  926. }
  927. }
  928. //---------------------------------------------------------------------------
  929. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  930. {
  931. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  932. }
  933. //---------------------------------------------------------------------------
  934. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  935. {
  936. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  937. {
  938. DirView->RowSelect = WinConfiguration->FullRowSelect;
  939. // selection is not redrawn automatically when RowSelect changes
  940. DirView->Invalidate();
  941. }
  942. }
  943. //---------------------------------------------------------------------------
  944. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  945. {
  946. Color = GetBtnFaceColor();
  947. DebugAssert(Configuration && RemoteDirView);
  948. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  949. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  950. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  951. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  952. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  953. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  954. UpdateRowSelect(RemoteDirView);
  955. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  956. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  957. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  958. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  959. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  960. UpdateSessionsPageControlHeight();
  961. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  962. UpdateToolbarDisplayMode();
  963. UpdateTransferList();
  964. if (Terminal != NULL)
  965. {
  966. TransferPresetAutoSelect();
  967. }
  968. UpdateQueueView();
  969. UpdateControls();
  970. // this can be called even before constuctor finishes.
  971. if (FEditorManager != NULL)
  972. {
  973. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  974. }
  975. // this can be called even before constuctor finishes.
  976. if (FLocalEditors != NULL)
  977. {
  978. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  979. {
  980. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  981. }
  982. }
  983. if (ComponentVisible[fcCustomCommandsBand])
  984. {
  985. UpdateCustomCommandsToolbar();
  986. }
  987. // show only when keeping queue items forever,
  988. // otherwise, its enough to have in in the context menu
  989. QueueDeleteAllDoneQueueToolbarItem->Visible =
  990. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  991. if (FFileColorsCurrent != WinConfiguration->FileColors)
  992. {
  993. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  994. FFileColorsCurrent = WinConfiguration->FileColors;
  995. FileColorsChanged();
  996. }
  997. }
  998. //---------------------------------------------------------------------------
  999. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  1000. {
  1001. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  1002. DirView->Invalidate();
  1003. }
  1004. //---------------------------------------------------------------------------
  1005. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  1006. {
  1007. DoFileColorsChanged(RemoteDirView);
  1008. }
  1009. //---------------------------------------------------------------------------
  1010. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  1011. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  1012. void * /*Arg*/)
  1013. {
  1014. if (Token != NULL)
  1015. {
  1016. TForm * Editor = dynamic_cast<TForm*>(Token);
  1017. DebugAssert(Editor != NULL);
  1018. ReconfigureEditorForm(Editor);
  1019. }
  1020. }
  1021. //---------------------------------------------------------------------------
  1022. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1023. {
  1024. WinConfiguration->DDTransferConfirmation = asOn;
  1025. }
  1026. //---------------------------------------------------------------------------
  1027. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1028. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1029. {
  1030. // noop
  1031. }
  1032. //---------------------------------------------------------------------------
  1033. bool TCustomScpExplorerForm::GetDoNotShowCopyDialogDefault(bool DragDrop)
  1034. {
  1035. return DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto);
  1036. }
  1037. //---------------------------------------------------------------------------
  1038. void TCustomScpExplorerForm::HandleDoNotShowCopyDialogAgain(bool DragDrop, bool DoNotShowAgain)
  1039. {
  1040. if (DoNotShowAgain)
  1041. {
  1042. if (DragDrop)
  1043. {
  1044. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1045. {
  1046. PopupTrayBalloon(
  1047. NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation, NULL, 0, EnableDDTransferConfirmation, NULL);
  1048. }
  1049. WinConfiguration->DDTransferConfirmation = asOff;
  1050. }
  1051. else
  1052. {
  1053. WinConfiguration->ConfirmTransferring = false;
  1054. }
  1055. }
  1056. else
  1057. {
  1058. // User explicitly unchecked "do not show again",
  1059. // so show him the dialog the next time
  1060. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1061. {
  1062. WinConfiguration->DDTransferConfirmation = asOn;
  1063. }
  1064. }
  1065. }
  1066. //---------------------------------------------------------------------------
  1067. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1068. TTransferDirection Direction, TTransferType Type, bool Temp,
  1069. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1070. bool Confirm, bool DragDrop, int Options)
  1071. {
  1072. bool Result = true;
  1073. DebugAssert(HasActiveTerminal());
  1074. // these parameters are known in advance
  1075. int Params =
  1076. FLAGMASK(Type == ttMove, cpDelete);
  1077. bool ToTemp = (Temp && (Direction == tdToLocal));
  1078. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1079. {
  1080. bool DisableNewerOnly =
  1081. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1082. ToTemp;
  1083. Options |=
  1084. FLAGMASK(ToTemp, coTemp) |
  1085. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1086. coDoNotShowAgain;
  1087. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1088. int CopyParamAttrs = (Direction == tdToRemote ?
  1089. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1090. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1091. int OutputOptions = FLAGMASK(GetDoNotShowCopyDialogDefault(DragDrop), cooDoNotShowAgain);
  1092. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1093. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1094. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1095. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1096. if (Result)
  1097. {
  1098. HandleDoNotShowCopyDialogAgain(DragDrop, FLAGSET(OutputOptions, cooDoNotShowAgain));
  1099. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1100. }
  1101. }
  1102. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1103. {
  1104. Configuration->Usage->Inc(L"TransfersOnBackground");
  1105. // these parameter are known only after transfer dialog
  1106. Params |=
  1107. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1108. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1109. Result = false;
  1110. ClearTransferSourceSelection(Direction);
  1111. }
  1112. return Result;
  1113. }
  1114. //---------------------------------------------------------------------------
  1115. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1116. {
  1117. if (FOnFileOperationFinished != NULL)
  1118. {
  1119. FOnFileOperationFinished(UnicodeString(), true);
  1120. }
  1121. else
  1122. {
  1123. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1124. if (HasDirView[Side])
  1125. {
  1126. DirView(Side)->SelectAll(smNone);
  1127. }
  1128. }
  1129. }
  1130. //---------------------------------------------------------------------------
  1131. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1132. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1133. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1134. int Params)
  1135. {
  1136. DebugAssert(Queue != NULL);
  1137. bool SingleFile = false;
  1138. if (FileList->Count == 1)
  1139. {
  1140. if (Direction == tdToRemote)
  1141. {
  1142. UnicodeString FileName = FileList->Strings[0];
  1143. SingleFile = FileExists(ApiPath(FileName));
  1144. }
  1145. else
  1146. {
  1147. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1148. SingleFile = !File->IsDirectory;
  1149. }
  1150. }
  1151. TQueueItem * QueueItem;
  1152. if (Direction == tdToRemote)
  1153. {
  1154. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1155. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1156. }
  1157. else
  1158. {
  1159. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1160. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1161. }
  1162. AddQueueItem(Queue, QueueItem, Terminal);
  1163. }
  1164. //---------------------------------------------------------------------------
  1165. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1166. {
  1167. if (Queue->IsEmpty)
  1168. {
  1169. Terminal->QueueOperationStart = Now();
  1170. }
  1171. Queue->AddItem(QueueItem);
  1172. }
  1173. //---------------------------------------------------------------------------
  1174. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1175. {
  1176. }
  1177. //---------------------------------------------------------------------------
  1178. void __fastcall TCustomScpExplorerForm::InitControls()
  1179. {
  1180. DebugAssert(FDocks != NULL);
  1181. for (int Index = 0; Index < ComponentCount; Index++)
  1182. {
  1183. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1184. if ((Dock != NULL) && (Dock->Tag == 0))
  1185. {
  1186. FDocks->Add(Dock);
  1187. }
  1188. }
  1189. CollectItemsWithTextDisplayMode(this);
  1190. }
  1191. //---------------------------------------------------------------------------
  1192. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1193. {
  1194. ConfigurationChanged();
  1195. QueuePanel->Height =
  1196. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1197. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1198. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1199. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1200. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1201. QueueFileList->Height =
  1202. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1203. if (QueueFileList->Visible)
  1204. {
  1205. AdjustQueueLayout();
  1206. }
  1207. UpdateCustomCommandsToolbar();
  1208. }
  1209. //---------------------------------------------------------------------------
  1210. void __fastcall TCustomScpExplorerForm::StoreParams()
  1211. {
  1212. int APixelsPerInch = GetControlPixelsPerInch(this);
  1213. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1214. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1215. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1216. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1217. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1218. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1219. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1220. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1221. }
  1222. //---------------------------------------------------------------------------
  1223. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1224. {
  1225. if (!FFormRestored)
  1226. {
  1227. FFormRestored = true;
  1228. RestoreFormParams();
  1229. }
  1230. TForm::CreateParams(Params);
  1231. }
  1232. //---------------------------------------------------------------------------
  1233. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1234. {
  1235. DebugAssert(FDocks != NULL);
  1236. for (int Index = 0; Index < FDocks->Count; Index++)
  1237. {
  1238. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1239. }
  1240. }
  1241. //---------------------------------------------------------------------------
  1242. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1243. {
  1244. SetDockAllowDrag(true);
  1245. while (!ButtonsStr.IsEmpty())
  1246. {
  1247. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1248. UnicodeString Name = CutToChar(S, L'=', true);
  1249. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1250. {
  1251. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1252. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1253. {
  1254. while (!S.IsEmpty())
  1255. {
  1256. UnicodeString S2 = CutToChar(S, L',', true);
  1257. UnicodeString Name = CutToChar(S2, L':', true);
  1258. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1259. {
  1260. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1261. if (SameText(GetToolbarItemName(Item), Name))
  1262. {
  1263. // forward compatibility
  1264. UnicodeString S3 = CutToChar(S2, L':', true);
  1265. bool Visible = StrToIntDef(S3, 0);
  1266. Item->Visible = Visible;
  1267. }
  1268. }
  1269. }
  1270. }
  1271. }
  1272. }
  1273. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1274. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1275. }
  1276. //---------------------------------------------------------------------------
  1277. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1278. {
  1279. UnicodeString Result;
  1280. SetDockAllowDrag(true);
  1281. Result = ::GetToolbarsLayoutStr(this);
  1282. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1283. return Result;
  1284. }
  1285. //---------------------------------------------------------------------------
  1286. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1287. {
  1288. UnicodeString Result;
  1289. if (Item->Action != NULL)
  1290. {
  1291. Result = Item->Action->Name;
  1292. Result = RemoveSuffix(Result, L"Action", true);
  1293. }
  1294. else
  1295. {
  1296. Result = Item->Name;
  1297. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1298. Result = RemoveSuffix(Result, L"Item", true);
  1299. }
  1300. return Result;
  1301. }
  1302. //---------------------------------------------------------------------------
  1303. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1304. {
  1305. UnicodeString Result;
  1306. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1307. {
  1308. UnicodeString ToolbarStr;
  1309. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1310. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1311. {
  1312. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1313. {
  1314. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1315. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1316. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1317. // and save the changes here only.
  1318. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1319. {
  1320. UnicodeString Name = GetToolbarItemName(Item);
  1321. DebugAssert(Name.Pos(L"TBX") == 0);
  1322. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1323. }
  1324. }
  1325. }
  1326. if (!ToolbarStr.IsEmpty())
  1327. {
  1328. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1329. }
  1330. }
  1331. return Result;
  1332. }
  1333. //---------------------------------------------------------------------------
  1334. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1335. {
  1336. DebugAssert(FProgressForm == NULL);
  1337. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1338. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1339. FProgressForm->DeleteLocalToRecycleBin =
  1340. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1341. FProgressForm->DeleteRemoteToRecycleBin =
  1342. (Terminal != NULL) &&
  1343. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1344. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1345. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1346. LockWindow();
  1347. // Actually, do not know what hides the progress once the operation finishes
  1348. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1349. SetTaskbarListProgressState(TBPF_NORMAL);
  1350. }
  1351. //---------------------------------------------------------------------------
  1352. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1353. {
  1354. UnlockWindow();
  1355. SAFE_DESTROY(FProgressForm);
  1356. SetQueueProgress();
  1357. }
  1358. //---------------------------------------------------------------------------
  1359. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1360. TFileOperationProgressType & ProgressData)
  1361. {
  1362. // Download to temporary local directory
  1363. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1364. {
  1365. bool Continue = true;
  1366. FPendingTempSpaceWarn = false;
  1367. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1368. if (!Continue)
  1369. {
  1370. Abort();
  1371. }
  1372. }
  1373. // operation is being executed and we still didn't show up progress form
  1374. if (ProgressData.InProgress && !FProgressForm)
  1375. {
  1376. CreateProgressForm(NULL);
  1377. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1378. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1379. }
  1380. // operation is finished (or terminated), so we hide progress form
  1381. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1382. {
  1383. DestroyProgressForm();
  1384. if (ProgressData.Operation == foCalculateSize)
  1385. {
  1386. // When calculating size before transfer, the abort caused by
  1387. // cancel flag set due to "MoveToQueue" below,
  1388. // is not propagated back to us in ExecuteFileOperation,
  1389. // as it is silently swallowed.
  1390. // So we explicitly (re)throw it here.
  1391. if (FMoveToQueue)
  1392. {
  1393. Abort();
  1394. }
  1395. }
  1396. else
  1397. {
  1398. if ((ProgressData.Cancel == csContinue) &&
  1399. !FAutoOperation)
  1400. {
  1401. OperationComplete(ProgressData.StartTime);
  1402. }
  1403. }
  1404. }
  1405. if (FProgressForm &&
  1406. // Can happen only during synchronization, when ending one of the operations
  1407. ProgressData.InProgress)
  1408. {
  1409. FProgressForm->SetProgressData(ProgressData);
  1410. DebugAssert(ProgressData.InProgress);
  1411. SetTaskbarListProgressValue(&ProgressData);
  1412. if (FProgressForm->Cancel > csContinue)
  1413. {
  1414. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1415. if (FProgressForm->Cancel == csCancelFile)
  1416. {
  1417. FProgressForm->ClearCancel();
  1418. }
  1419. // cancel cancels even the move
  1420. FMoveToQueue = false;
  1421. }
  1422. else if (FProgressForm->MoveToQueue)
  1423. {
  1424. FMoveToQueue = true;
  1425. ProgressData.SetCancelAtLeast(csCancel);
  1426. }
  1427. if ((FTransferResumeList != NULL) &&
  1428. ProgressData.InProgress &&
  1429. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1430. !ProgressData.FullFileName.IsEmpty())
  1431. {
  1432. if ((FTransferResumeList->Count == 0) ||
  1433. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1434. {
  1435. // note that we do not recognize directories from files here
  1436. FTransferResumeList->Add(ProgressData.FullFileName);
  1437. }
  1438. }
  1439. }
  1440. }
  1441. //---------------------------------------------------------------------------
  1442. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1443. const TDateTime & StartTime)
  1444. {
  1445. if (GUIConfiguration->BeepOnFinish &&
  1446. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1447. {
  1448. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1449. DWORD Sound;
  1450. if (!ExtractFileExt(BeepSound).IsEmpty())
  1451. {
  1452. Sound = SND_FILENAME;
  1453. }
  1454. else
  1455. {
  1456. Sound = SND_ALIAS;
  1457. }
  1458. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1459. }
  1460. }
  1461. //---------------------------------------------------------------------------
  1462. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1463. TFileOperationProgressType & ProgressData)
  1464. {
  1465. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1466. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1467. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1468. FileOperationProgress(ProgressData);
  1469. }
  1470. //---------------------------------------------------------------------------
  1471. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1472. {
  1473. UnicodeString Result;
  1474. if (FProgressForm != NULL)
  1475. {
  1476. Result = FProgressForm->ProgressStr();
  1477. }
  1478. return Result;
  1479. }
  1480. //---------------------------------------------------------------------------
  1481. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1482. bool DragDrop)
  1483. {
  1484. return (!DragDrop && (DropSourceControl == NULL)) ||
  1485. (DropSourceControl == DirView(osOther));
  1486. }
  1487. //---------------------------------------------------------------------------
  1488. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1489. TFileOperation Operation, TOperationSide Side,
  1490. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1491. TOnceDoneOperation & OnceDoneOperation)
  1492. {
  1493. if (!FAutoOperation)
  1494. {
  1495. // no selection on "/upload", form serves only as event handler
  1496. // (it is not displayed)
  1497. if (PanelOperation(Side, FDragDropOperation) &&
  1498. Visible && (Operation != foCalculateSize) &&
  1499. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1500. {
  1501. if (FOnFileOperationFinished != NULL)
  1502. {
  1503. FOnFileOperationFinished(FileName, Success);
  1504. }
  1505. else
  1506. {
  1507. TOperationSide DViewSide;
  1508. if ((FProgressSide != osCurrent) &&
  1509. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1510. {
  1511. // assume the operation is over the focused panel
  1512. DViewSide = FProgressSide;
  1513. }
  1514. else
  1515. {
  1516. DViewSide = Side;
  1517. }
  1518. TCustomDirView * DView = DirView(DViewSide);
  1519. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(DViewSide));
  1520. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1521. // this can happen when local drive is unplugged in the middle of the operation
  1522. if (Item != NULL)
  1523. {
  1524. if (Success) Item->Selected = false;
  1525. DView->MakeProgressVisible(Item);
  1526. }
  1527. }
  1528. }
  1529. if ((Operation == foCopy) || (Operation == foMove))
  1530. {
  1531. if (DebugAlwaysTrue(!IsLocalBrowserMode()))
  1532. {
  1533. if (Side == osLocal)
  1534. {
  1535. Configuration->Usage->Inc(L"UploadedFiles");
  1536. }
  1537. else
  1538. {
  1539. Configuration->Usage->Inc(L"DownloadedFiles");
  1540. }
  1541. }
  1542. }
  1543. }
  1544. if (Success && (FSynchronizeController != NULL))
  1545. {
  1546. DebugAssert(!IsSideLocalBrowser(osRemote));
  1547. if (Operation == foCopy)
  1548. {
  1549. DebugAssert(Side == osLocal);
  1550. FSynchronizeController->LogOperation(soUpload, FileName);
  1551. }
  1552. else if (Operation == foDelete)
  1553. {
  1554. DebugAssert(Side == osRemote);
  1555. FSynchronizeController->LogOperation(soDelete, FileName);
  1556. }
  1557. }
  1558. if (FProgressForm)
  1559. {
  1560. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1561. }
  1562. }
  1563. //---------------------------------------------------------------------------
  1564. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1565. TFileOperation Operation, TOperationSide Side,
  1566. bool Temp, const UnicodeString & FileName, Boolean Success,
  1567. TOnceDoneOperation & OnceDoneOperation)
  1568. {
  1569. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1570. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1571. OnceDoneOperation);
  1572. }
  1573. //---------------------------------------------------------------------------
  1574. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1575. {
  1576. return false;
  1577. }
  1578. //---------------------------------------------------------------------------
  1579. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1580. {
  1581. return false;
  1582. }
  1583. //---------------------------------------------------------------------------
  1584. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1585. {
  1586. return NULL;
  1587. }
  1588. //---------------------------------------------------------------------------
  1589. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1590. {
  1591. DebugAssert(GetSide(Side) == osRemote);
  1592. DebugUsedParam(Side);
  1593. return RemoteDirView;
  1594. }
  1595. //---------------------------------------------------------------------------
  1596. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1597. {
  1598. DebugAssert(GetSide(Side) == osRemote);
  1599. DebugUsedParam(Side);
  1600. return RemoteDriveView;
  1601. }
  1602. //---------------------------------------------------------------------------
  1603. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1604. {
  1605. DebugAssert(GetSide(Side) == osRemote);
  1606. DebugUsedParam(Side);
  1607. return HasActiveTerminal();
  1608. }
  1609. //---------------------------------------------------------------------------
  1610. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1611. TOperationSide Side, int FilesOnly)
  1612. {
  1613. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1614. }
  1615. //---------------------------------------------------------------------------
  1616. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1617. TOperationSide Side, int FilesOnly)
  1618. {
  1619. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1620. }
  1621. //---------------------------------------------------------------------------
  1622. struct THistoryItemData
  1623. {
  1624. short int Side;
  1625. short int Index;
  1626. };
  1627. //---------------------------------------------------------------------------
  1628. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1629. {
  1630. DirView(Side)->HistoryGo(Index);
  1631. }
  1632. //---------------------------------------------------------------------------
  1633. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1634. {
  1635. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1636. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1637. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1638. }
  1639. //---------------------------------------------------------------------------
  1640. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1641. bool Back)
  1642. {
  1643. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1644. {
  1645. TCustomDirView * DView = DirView(Side);
  1646. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1647. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1648. if (ICount > 10)
  1649. {
  1650. ICount = 10;
  1651. }
  1652. Menu->Items->Clear();
  1653. THistoryItemData Data;
  1654. Data.Side = Side;
  1655. for (short int i = 1; i <= ICount; i++)
  1656. {
  1657. TTBCustomItem * Item = new TTBXItem(Menu);
  1658. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1659. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1660. Item->Hint = DView->HistoryPath[Data.Index];
  1661. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1662. Item->Tag = *reinterpret_cast<int*>(&Data);
  1663. Item->OnClick = HistoryItemClick;
  1664. Menu->Items->Add(Item);
  1665. }
  1666. }
  1667. }
  1668. //---------------------------------------------------------------------------
  1669. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1670. TOperationSide Side, bool Back)
  1671. {
  1672. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1673. {
  1674. // workaround
  1675. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1676. // operator new allocates memory in Pascal code, but calls inline
  1677. // contructor in C++, leading in problems, the function does
  1678. // both in Pascal code
  1679. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1680. UpdateHistoryMenu(Side, Back);
  1681. }
  1682. return FHistoryMenu[Side == osLocal][Back];
  1683. }
  1684. //---------------------------------------------------------------------------
  1685. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1686. TCustomDirView *Sender)
  1687. {
  1688. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1689. UpdateHistoryMenu(Side, true);
  1690. UpdateHistoryMenu(Side, false);
  1691. }
  1692. //---------------------------------------------------------------------------
  1693. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1694. {
  1695. // remote custom commands can be executed only if the server supports shell commands
  1696. // or have secondary shell
  1697. return HasActiveTerminal() && (Terminal->IsCapable[fcSecondaryShell] || Terminal->IsCapable[fcShellAnyCommand]);
  1698. }
  1699. //---------------------------------------------------------------------------
  1700. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1701. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1702. {
  1703. // -1 = hidden, 0 = disabled, 1 = enabled
  1704. int Result;
  1705. TFileCustomCommand RemoteCustomCommand;
  1706. TLocalCustomCommand LocalCustomCommand;
  1707. TFileCustomCommand * NonInteractiveCustomCommand =
  1708. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1709. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1710. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1711. if (FLAGCLEAR(Command.Params, ccLocal))
  1712. {
  1713. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1714. // custom command that does not operate with files can be executed anytime ...
  1715. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1716. {
  1717. // ... but do not show such command in remote file menu
  1718. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1719. {
  1720. Result = AllowedState;
  1721. }
  1722. else
  1723. {
  1724. Result = -1;
  1725. }
  1726. }
  1727. else
  1728. {
  1729. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1730. {
  1731. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1732. }
  1733. else
  1734. {
  1735. Result = -1;
  1736. }
  1737. }
  1738. }
  1739. else
  1740. {
  1741. // custom command that does not operate with files can be executed anytime
  1742. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1743. {
  1744. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1745. }
  1746. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1747. {
  1748. if ((ListType == ccltAll) || (ListType == ccltFile))
  1749. {
  1750. // special case is "diff"-style command that can be executed over any side,
  1751. // if we have both sides
  1752. Result =
  1753. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1754. // directly (instead of EnableSelectedOperation) to pass
  1755. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1756. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1757. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1758. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1759. }
  1760. else if (ListType == ccltBoth)
  1761. {
  1762. DebugAssert(!IsLocalBrowserMode());
  1763. Result = 1;
  1764. }
  1765. else
  1766. {
  1767. Result = -1;
  1768. }
  1769. }
  1770. else
  1771. {
  1772. if ((ListType == ccltAll) ||
  1773. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1774. {
  1775. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1776. }
  1777. else
  1778. {
  1779. Result = -1;
  1780. }
  1781. }
  1782. if ((Result > 0) &&
  1783. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1784. !HasActiveTerminal())
  1785. {
  1786. Result = 0;
  1787. }
  1788. }
  1789. return Result;
  1790. }
  1791. //---------------------------------------------------------------------------
  1792. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1793. TStrings * FileList, const TCustomCommandType & ACommand,
  1794. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1795. {
  1796. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1797. {
  1798. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1799. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1800. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1801. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1802. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1803. bool Capture =
  1804. FLAGSET(ACommand.Params, ccShowResults) ||
  1805. FLAGSET(ACommand.Params, ccCopyResults) ||
  1806. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1807. TCaptureOutputEvent OutputEvent = NULL;
  1808. DebugAssert(FCapturedLog == NULL);
  1809. if (Capture)
  1810. {
  1811. FCapturedLog = new TStringList();
  1812. OutputEvent = TerminalCaptureLog;
  1813. }
  1814. try
  1815. {
  1816. if (!RemoteCustomCommand.IsFileCommand(Command))
  1817. {
  1818. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1819. OutputEvent);
  1820. }
  1821. else
  1822. {
  1823. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1824. }
  1825. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1826. {
  1827. if (FLAGSET(ACommand.Params, ccCopyResults))
  1828. {
  1829. CopyToClipboard(FCapturedLog);
  1830. }
  1831. if (FLAGSET(ACommand.Params, ccShowResults))
  1832. {
  1833. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1834. }
  1835. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1836. {
  1837. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1838. }
  1839. }
  1840. }
  1841. __finally
  1842. {
  1843. SAFE_DESTROY(FCapturedLog);
  1844. }
  1845. }
  1846. }
  1847. //---------------------------------------------------------------------------
  1848. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1849. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1850. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1851. {
  1852. DebugAssert(!IsLocalBrowserMode());
  1853. TStrings * LocalFileList = NULL;
  1854. TStrings * RemoteFileList = NULL;
  1855. TStrings * RemoteFileListFull = NULL;
  1856. try
  1857. {
  1858. if (LocalFileCommand)
  1859. {
  1860. if (ALocalFileList == NULL)
  1861. {
  1862. DebugAssert(HasDirView[osLocal]);
  1863. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1864. // directly (instead of EnableSelectedOperation) to pass
  1865. // false to FocusedFileOnlyWhenFocused
  1866. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1867. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1868. }
  1869. else
  1870. {
  1871. LocalFileList = ALocalFileList;
  1872. }
  1873. if (FileListCommand)
  1874. {
  1875. if (LocalFileList->Count != 1)
  1876. {
  1877. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1878. }
  1879. }
  1880. else
  1881. {
  1882. if ((LocalFileList->Count != 1) &&
  1883. (FileList->Count != 1) &&
  1884. (LocalFileList->Count != FileList->Count))
  1885. {
  1886. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1887. }
  1888. }
  1889. }
  1890. UnicodeString RootTempDir;
  1891. UnicodeString TempDir;
  1892. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1893. if (!RemoteFiles)
  1894. {
  1895. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1896. }
  1897. try
  1898. {
  1899. TDateTimes RemoteFileTimes;
  1900. if (RemoteFiles)
  1901. {
  1902. RemoteFileList = FileList;
  1903. }
  1904. else
  1905. {
  1906. RemoteFileList = new TStringList();
  1907. TMakeLocalFileListParams MakeFileListParam;
  1908. MakeFileListParam.FileList = RemoteFileList;
  1909. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1910. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1911. MakeFileListParam.Recursive =
  1912. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1913. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1914. if (!MakeFileListParam.Recursive)
  1915. {
  1916. RemoteFileTimes.clear();
  1917. RemoteFileListFull = new TStringList();
  1918. MakeFileListParam.FileList = RemoteFileListFull;
  1919. MakeFileListParam.Recursive = true;
  1920. MakeFileListParam.IncludeDirs = false;
  1921. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1922. }
  1923. else
  1924. {
  1925. RemoteFileListFull = RemoteFileList;
  1926. }
  1927. }
  1928. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1929. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1930. if (!NonBlocking)
  1931. {
  1932. int Count;
  1933. if (FileListCommand)
  1934. {
  1935. Count = 1;
  1936. }
  1937. else if (LocalFileCommand)
  1938. {
  1939. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1940. }
  1941. else
  1942. {
  1943. Count = RemoteFileList->Count;
  1944. }
  1945. Progress.Start(foCustomCommand, osRemote, Count);
  1946. DebugAssert(FProgressForm != NULL);
  1947. FProgressForm->ReadOnly = true;
  1948. }
  1949. try
  1950. {
  1951. if (FileListCommand)
  1952. {
  1953. UnicodeString LocalFile;
  1954. // MakeFileList does not delimit filenames
  1955. UnicodeString FileList = MakeFileList(RemoteFileList);
  1956. if (LocalFileCommand)
  1957. {
  1958. DebugAssert(LocalFileList->Count == 1);
  1959. LocalFile = LocalFileList->Strings[0];
  1960. }
  1961. TLocalCustomCommand CustomCommand(Data,
  1962. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1963. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1964. if (NonBlocking)
  1965. {
  1966. DebugAssert(!POutput);
  1967. ExecuteShellChecked(ShellCommand);
  1968. }
  1969. else
  1970. {
  1971. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1972. }
  1973. }
  1974. else if (LocalFileCommand)
  1975. {
  1976. if (LocalFileList->Count == 1)
  1977. {
  1978. UnicodeString LocalFile = LocalFileList->Strings[0];
  1979. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1980. {
  1981. UnicodeString FileName = RemoteFileList->Strings[Index];
  1982. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1983. Progress.SetFile(FileNameForProgress);
  1984. TLocalCustomCommand CustomCommand(Data,
  1985. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, 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 if (RemoteFileList->Count == 1)
  1993. {
  1994. UnicodeString FileName = RemoteFileList->Strings[0];
  1995. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1996. {
  1997. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1998. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1999. Progress.SetFile(LocalFileNameOnly);
  2000. TLocalCustomCommand CustomCommand(
  2001. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2002. FileName, LocalFileName, L"");
  2003. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2004. TOnceDoneOperation OnceDoneOperation;
  2005. // Do not unselect anything, as it won't work with two panels anyway
  2006. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2007. }
  2008. }
  2009. else
  2010. {
  2011. if (LocalFileList->Count != RemoteFileList->Count)
  2012. {
  2013. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  2014. }
  2015. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2016. {
  2017. UnicodeString FileName = RemoteFileList->Strings[Index];
  2018. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2019. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2020. Progress.SetFile(LocalFileNameOnly); // sic
  2021. TLocalCustomCommand CustomCommand(
  2022. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2023. FileName, LocalFileName, L"");
  2024. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2025. TOnceDoneOperation OnceDoneOperation;
  2026. // Do not unselect anything, as it won't work with two panels anyway
  2027. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2028. }
  2029. }
  2030. }
  2031. else
  2032. {
  2033. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2034. {
  2035. UnicodeString FileName = RemoteFileList->Strings[Index];
  2036. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2037. Progress.SetFile(FileNameForProgress);
  2038. TLocalCustomCommand CustomCommand(Data,
  2039. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2040. FileName, L"", L"");
  2041. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2042. TOnceDoneOperation OnceDoneOperation;
  2043. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2044. }
  2045. }
  2046. }
  2047. __finally
  2048. {
  2049. if (!NonBlocking)
  2050. {
  2051. Progress.Stop();
  2052. }
  2053. }
  2054. DebugAssert(!FAutoOperation);
  2055. if (!RemoteFiles)
  2056. {
  2057. TempDir = IncludeTrailingBackslash(TempDir);
  2058. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2059. {
  2060. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2061. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2062. // Skip directories, process only nested files.
  2063. // The check is redundant as FileAge fails for directories anyway.
  2064. !DirectoryExists(FileName))
  2065. {
  2066. UnicodeString RemoteDir =
  2067. UnixExtractFileDir(
  2068. UnixIncludeTrailingBackslash(Terminal->CurrentDirectory) +
  2069. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2070. TDateTime NewTime;
  2071. if (FileAge(FileName, NewTime) &&
  2072. (NewTime != RemoteFileTimes[Index]))
  2073. {
  2074. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2075. TemporaryFileCopyParam(CopyParam);
  2076. CopyParam.FileMask = L"";
  2077. FAutoOperation = true;
  2078. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2079. TemporaryFilesList->Add(FileName);
  2080. Terminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2081. }
  2082. }
  2083. }
  2084. }
  2085. }
  2086. __finally
  2087. {
  2088. FAutoOperation = false;
  2089. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2090. {
  2091. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2092. }
  2093. }
  2094. }
  2095. __finally
  2096. {
  2097. if (RemoteFileList != FileList)
  2098. {
  2099. delete RemoteFileList;
  2100. }
  2101. if (LocalFileList != ALocalFileList)
  2102. {
  2103. delete LocalFileList;
  2104. }
  2105. if (RemoteFileListFull != RemoteFileList)
  2106. {
  2107. delete RemoteFileListFull;
  2108. }
  2109. }
  2110. }
  2111. //---------------------------------------------------------------------------
  2112. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2113. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2114. bool FileListCommand, UnicodeString * POutput)
  2115. {
  2116. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2117. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2118. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2119. {
  2120. UnicodeString FileName = SelectedFileList->Strings[Index];
  2121. if (DirectoryExists(FileName))
  2122. {
  2123. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2124. {
  2125. LocalFileList->Add(FileName);
  2126. }
  2127. if (FLAGSET(ACommand.Params, ccRecursive))
  2128. {
  2129. TMakeLocalFileListParams MakeFileListParam;
  2130. MakeFileListParam.FileList = LocalFileList.get();
  2131. MakeFileListParam.FileTimes = NULL;
  2132. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2133. MakeFileListParam.Recursive = true;
  2134. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2135. }
  2136. }
  2137. else
  2138. {
  2139. LocalFileList->Add(FileName);
  2140. }
  2141. }
  2142. UnicodeString RemotePath;
  2143. if (Terminal != NULL)
  2144. {
  2145. RemotePath = Terminal->CurrentDirectory;
  2146. }
  2147. if (FileListCommand)
  2148. {
  2149. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2150. TLocalCustomCommand CustomCommand(
  2151. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2152. L"", L"", FileList);
  2153. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2154. }
  2155. else
  2156. {
  2157. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2158. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2159. DebugAssert(FProgressForm != NULL);
  2160. FProgressForm->ReadOnly = true;
  2161. try
  2162. {
  2163. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2164. {
  2165. UnicodeString FileName = LocalFileList->Strings[Index];
  2166. Progress.SetFile(FileName);
  2167. TLocalCustomCommand CustomCommand(
  2168. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2169. FileName, L"", L"");
  2170. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2171. TOnceDoneOperation OnceDoneOperation;
  2172. Progress.Finish(FileName, true, OnceDoneOperation);
  2173. }
  2174. }
  2175. __finally
  2176. {
  2177. Progress.Stop();
  2178. }
  2179. }
  2180. }
  2181. //---------------------------------------------------------------------------
  2182. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2183. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2184. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2185. {
  2186. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2187. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2188. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2189. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2190. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2191. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2192. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2193. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2194. std::unique_ptr<UnicodeString> POutput;
  2195. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2196. FLAGSET(ACommand.Params, ccCopyResults))
  2197. {
  2198. POutput.reset(new UnicodeString());
  2199. }
  2200. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  2201. FProgressSide = FCurrentSide;
  2202. if (!LocalCustomCommand.IsFileCommand(Command))
  2203. {
  2204. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2205. }
  2206. // remote files?
  2207. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2208. {
  2209. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2210. }
  2211. // local files
  2212. else
  2213. {
  2214. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2215. }
  2216. if (POutput.get() != NULL)
  2217. {
  2218. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2219. int P = POutput->Pos(sLineBreak);
  2220. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2221. {
  2222. POutput->SetLength(P - 1);
  2223. }
  2224. // Copy even empty output to clipboard
  2225. if (FLAGSET(ACommand.Params, ccCopyResults))
  2226. {
  2227. CopyToClipboard(*POutput);
  2228. }
  2229. // But do not show an empty message box.
  2230. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2231. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2232. !POutput->IsEmpty())
  2233. {
  2234. TClipboardHandler ClipboardHandler;
  2235. ClipboardHandler.Text = *POutput;
  2236. TMessageParams Params;
  2237. TQueryButtonAlias Aliases[1];
  2238. Aliases[0].Button = qaRetry;
  2239. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2240. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2241. Params.Aliases = Aliases;
  2242. Params.AliasesCount = LENOF(Aliases);
  2243. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2244. }
  2245. }
  2246. }
  2247. //---------------------------------------------------------------------------
  2248. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2249. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2250. {
  2251. TCustomCommandData Data;
  2252. UnicodeString Site;
  2253. UnicodeString RemotePath;
  2254. if (HasActiveTerminal())
  2255. {
  2256. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2257. Data = TCustomCommandData(SessionData.get());
  2258. Site = Terminal->SessionData->SessionKey;
  2259. RemotePath = Terminal->CurrentDirectory;
  2260. }
  2261. UnicodeString HelpKeyword = ACommand.HomePage;
  2262. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2263. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2264. {
  2265. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2266. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2267. {
  2268. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2269. }
  2270. else
  2271. {
  2272. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2273. }
  2274. if (!DoCustomCommandOptionsDialog(
  2275. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2276. {
  2277. Abort();
  2278. }
  2279. }
  2280. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2281. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2282. {
  2283. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2284. }
  2285. else
  2286. {
  2287. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2288. }
  2289. }
  2290. //---------------------------------------------------------------------------
  2291. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2292. const TCustomCommandType & Command)
  2293. {
  2294. DebugAssert(FCustomCommandLocalFileList != NULL);
  2295. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2296. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2297. TStrings * LocalFileList = new TStringList();
  2298. TStrings * RemoteFileList = new TStringList();
  2299. try
  2300. {
  2301. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2302. {
  2303. LocalFileList->Clear();
  2304. LocalFileList->AddObject(
  2305. FCustomCommandLocalFileList->Strings[Index],
  2306. FCustomCommandLocalFileList->Objects[Index]);
  2307. RemoteFileList->Clear();
  2308. RemoteFileList->AddObject(
  2309. FCustomCommandRemoteFileList->Strings[Index],
  2310. FCustomCommandRemoteFileList->Objects[Index]);
  2311. CustomCommand(RemoteFileList, Command, LocalFileList);
  2312. }
  2313. }
  2314. __finally
  2315. {
  2316. delete LocalFileList;
  2317. delete RemoteFileList;
  2318. }
  2319. }
  2320. //---------------------------------------------------------------------------
  2321. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2322. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2323. {
  2324. delete FCustomCommandLocalFileList;
  2325. delete FCustomCommandRemoteFileList;
  2326. // takeover ownership,
  2327. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2328. FCustomCommandLocalFileList = LocalFileList;
  2329. FCustomCommandRemoteFileList = RemoteFileList;
  2330. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2331. if (Button != NULL)
  2332. {
  2333. FCustomCommandMenu->Items->Clear();
  2334. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2335. MenuPopup(FCustomCommandMenu, Button);
  2336. }
  2337. else
  2338. {
  2339. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2340. }
  2341. }
  2342. //---------------------------------------------------------------------------
  2343. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2344. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2345. {
  2346. DebugAssert(FCapturedLog != NULL);
  2347. if ((OutputType == cotOutput) || (OutputType == cotError))
  2348. {
  2349. FCapturedLog->Add(AddedLine);
  2350. }
  2351. }
  2352. //---------------------------------------------------------------------------
  2353. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2354. TOperationSide Side)
  2355. {
  2356. return
  2357. (Side == osOther) &&
  2358. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2359. }
  2360. //---------------------------------------------------------------------------
  2361. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2362. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2363. {
  2364. TTBItemOptions O;
  2365. O = Item->Options;
  2366. TCustomDirView * DView = DirView(Side);
  2367. if ((DView->ItemFocused != NULL) &&
  2368. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2369. // when resolving links is disabled, default action is to enter the directory,
  2370. // no matter what DoubleClickAction is configured to
  2371. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2372. // Can only Edit files, but can Open/Copy even directories
  2373. ((DoubleClickAction != dcaEdit) ||
  2374. !DView->ItemIsDirectory(DView->ItemFocused)))
  2375. {
  2376. Item->Options = O << tboDefault;
  2377. }
  2378. else
  2379. {
  2380. Item->Options = O >> tboDefault;
  2381. }
  2382. }
  2383. //---------------------------------------------------------------------------
  2384. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2385. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2386. {
  2387. TCustomDirView * DView = DirView(Side);
  2388. TListItem * Item = DView->ItemFocused;
  2389. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2390. EnableFocusedOperation[Side])
  2391. {
  2392. TPoint ClientPoint;
  2393. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2394. TPoint(0, 0) : MousePos;
  2395. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2396. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2397. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2398. }
  2399. }
  2400. //---------------------------------------------------------------------------
  2401. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2402. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2403. {
  2404. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2405. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2406. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2407. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2408. Handled = true;
  2409. }
  2410. //---------------------------------------------------------------------------
  2411. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2412. {
  2413. }
  2414. //---------------------------------------------------------------------------
  2415. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2416. {
  2417. DebugAssert(FErrorList == NULL);
  2418. if (WinConfiguration->ContinueOnError)
  2419. {
  2420. FErrorList = new TStringList();
  2421. Configuration->Usage->Inc(L"ContinuationsOnError");
  2422. }
  2423. NonVisualDataModule->StartBusy();
  2424. }
  2425. //---------------------------------------------------------------------------
  2426. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2427. {
  2428. NonVisualDataModule->EndBusy();
  2429. if (FErrorList)
  2430. {
  2431. HandleErrorList(FErrorList);
  2432. }
  2433. }
  2434. //---------------------------------------------------------------------------
  2435. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2436. const TCopyParamType & CopyParam)
  2437. {
  2438. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2439. {
  2440. Configuration->Usage->Inc(L"FileMaskUses");
  2441. }
  2442. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2443. {
  2444. Configuration->Usage->Inc(L"OperationMaskUses");
  2445. }
  2446. }
  2447. //---------------------------------------------------------------------------
  2448. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2449. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2450. {
  2451. DebugAssert(!IsLocalBrowserMode());
  2452. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2453. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2454. TTransferOperationParam DefaultParam;
  2455. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2456. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2457. switch (Param.Queue)
  2458. {
  2459. case asOn:
  2460. CopyParam.Queue = true;
  2461. break;
  2462. case asOff:
  2463. CopyParam.Queue = false;
  2464. break;
  2465. case asAuto:
  2466. default:
  2467. // keep default
  2468. break;
  2469. }
  2470. bool Result =
  2471. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2472. if (Result)
  2473. {
  2474. DebugAssert(Terminal);
  2475. bool SelectionRestored = false;
  2476. TCustomDirView * DView = NULL;
  2477. if (HasDirView[Side])
  2478. {
  2479. DView = DirView(Side);
  2480. DView->SaveSelection();
  2481. DView->SaveSelectedNames();
  2482. }
  2483. UpdateCopyParamCounters(CopyParam);
  2484. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2485. DebugAssert(FTransferResumeList == NULL);
  2486. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2487. FMoveToQueue = false;
  2488. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2489. try
  2490. {
  2491. TStrings * PermanentFileList;
  2492. std::unique_ptr<TStrings> PermanentFileListOwner;
  2493. try
  2494. {
  2495. if (Side == osLocal)
  2496. {
  2497. PermanentFileList = FileList;
  2498. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2499. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2500. if (Operation == foMove)
  2501. {
  2502. ReloadLocalDirectory();
  2503. if (DView != NULL)
  2504. {
  2505. DView->RestoreSelection();
  2506. }
  2507. SelectionRestored = true;
  2508. }
  2509. }
  2510. else
  2511. {
  2512. // Clone the file list as it may refer to current directory files,
  2513. // which get destroyed, when the source directory is reloaded after foMove operation.
  2514. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2515. // But for a hotfix, we are not going to do such a big change.
  2516. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2517. PermanentFileList = PermanentFileListOwner.get();
  2518. try
  2519. {
  2520. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2521. }
  2522. __finally
  2523. {
  2524. if (Operation == foMove)
  2525. {
  2526. if (DView != NULL)
  2527. {
  2528. DView->RestoreSelection();
  2529. }
  2530. SelectionRestored = true;
  2531. }
  2532. ReloadLocalDirectory(Param.TargetDirectory);
  2533. }
  2534. }
  2535. }
  2536. catch (EAbort &)
  2537. {
  2538. if (FMoveToQueue)
  2539. {
  2540. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2541. DebugAssert(CopyParam.TransferSkipList == NULL);
  2542. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2543. if (TransferResumeList->Count > 0)
  2544. {
  2545. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2546. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2547. }
  2548. CopyParam.TransferSkipList = TransferResumeList.release();
  2549. // not really needed, just to keep it consistent with TransferResumeList
  2550. FTransferResumeList = NULL;
  2551. FMoveToQueue = false;
  2552. Configuration->Usage->Inc("MovesToBackground");
  2553. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2554. ClearTransferSourceSelection(Direction);
  2555. }
  2556. throw;
  2557. }
  2558. }
  2559. __finally
  2560. {
  2561. if (!SelectionRestored && (DView != NULL))
  2562. {
  2563. DView->DiscardSavedSelection();
  2564. }
  2565. FTransferResumeList = NULL;
  2566. }
  2567. }
  2568. return Result;
  2569. }
  2570. //---------------------------------------------------------------------------
  2571. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2572. TOperationSide Side, TStrings * FileList, void * Param)
  2573. {
  2574. DebugAssert(FileList->Count);
  2575. // We deliberately do not toggle alternative flag (Param), but use OR,
  2576. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2577. // shortcut of CurrentDeleteAlternativeAction
  2578. bool Alternative =
  2579. bool(Param) || UseAlternativeFunction();
  2580. bool Recycle;
  2581. if (IsSideLocalBrowser(Side))
  2582. {
  2583. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2584. }
  2585. else
  2586. {
  2587. Recycle =
  2588. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2589. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2590. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2591. }
  2592. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2593. if (!Result)
  2594. {
  2595. UnicodeString Query;
  2596. if (FileList->Count == 1)
  2597. {
  2598. if (IsSideLocalBrowser(Side))
  2599. {
  2600. Query = ExtractFileName(FileList->Strings[0]);
  2601. }
  2602. else
  2603. {
  2604. Query = UnixExtractFileName(FileList->Strings[0]);
  2605. }
  2606. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2607. }
  2608. else
  2609. {
  2610. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2611. }
  2612. TMessageParams Params(mpNeverAskAgainCheck);
  2613. Params.ImageName = L"Delete file";
  2614. unsigned int Answer =
  2615. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2616. if (Answer == qaNeverAskAgain)
  2617. {
  2618. Result = true;
  2619. if (Recycle)
  2620. {
  2621. WinConfiguration->ConfirmRecycling = false;
  2622. }
  2623. else
  2624. {
  2625. WinConfiguration->ConfirmDeleting = false;
  2626. }
  2627. }
  2628. else
  2629. {
  2630. Result = (Answer == qaOK);
  2631. }
  2632. }
  2633. if (Result)
  2634. {
  2635. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2636. }
  2637. return Result;
  2638. }
  2639. //---------------------------------------------------------------------------
  2640. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2641. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2642. {
  2643. TAutoBatch AutoBatch(this);
  2644. bool Result;
  2645. if ((Operation == foCopy) || (Operation == foMove))
  2646. {
  2647. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2648. }
  2649. else if (Operation == foRename)
  2650. {
  2651. DebugAssert(DirView(Side)->ItemFocused);
  2652. DirView(Side)->ItemFocused->EditCaption();
  2653. Result = true;
  2654. }
  2655. else if (Operation == foDelete)
  2656. {
  2657. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2658. }
  2659. else if (Operation == foSetProperties)
  2660. {
  2661. DirView(osRemote)->SaveSelectedNames();
  2662. Result = SetProperties(Side, FileList);
  2663. }
  2664. else if (Operation == foCustomCommand)
  2665. {
  2666. DebugAssert(Param);
  2667. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2668. DirView(osRemote)->SaveSelectedNames();
  2669. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2670. CustomCommand(FileList, *Command, NULL);
  2671. Result = true;
  2672. }
  2673. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2674. {
  2675. DebugAssert(!IsSideLocalBrowser(Side));
  2676. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2677. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2678. }
  2679. else if (Operation == foLock)
  2680. {
  2681. DebugAssert(!IsSideLocalBrowser(Side));
  2682. LockFiles(FileList, true);
  2683. Result = true;
  2684. }
  2685. else if (Operation == foUnlock)
  2686. {
  2687. DebugAssert(!IsSideLocalBrowser(Side));
  2688. LockFiles(FileList, false);
  2689. Result = true;
  2690. }
  2691. else
  2692. {
  2693. DebugFail();
  2694. }
  2695. return Result;
  2696. }
  2697. //---------------------------------------------------------------------------
  2698. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2699. {
  2700. if (Side == osCurrent)
  2701. {
  2702. Side = FCurrentSide;
  2703. }
  2704. return Side;
  2705. }
  2706. //---------------------------------------------------------------------------
  2707. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2708. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2709. {
  2710. Side = GetSide(Side);
  2711. bool Result;
  2712. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2713. try
  2714. {
  2715. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2716. }
  2717. __finally
  2718. {
  2719. delete FileList;
  2720. }
  2721. return Result;
  2722. }
  2723. //---------------------------------------------------------------------------
  2724. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2725. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2726. bool NoConfirmation, void * Param)
  2727. {
  2728. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2729. {
  2730. if ((Operation == foCopy) || (Operation == foMove))
  2731. {
  2732. DebugAssert(!IsLocalBrowserMode());
  2733. if (GetSide(Side) == osLocal)
  2734. {
  2735. Configuration->Usage->Inc(L"UploadsCommand");
  2736. }
  2737. else
  2738. {
  2739. Configuration->Usage->Inc(L"DownloadsCommand");
  2740. }
  2741. }
  2742. }
  2743. }
  2744. //---------------------------------------------------------------------------
  2745. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2746. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2747. {
  2748. TTransferOperationParam Param;
  2749. if ((WinConfiguration->Interface != ifCommander) ||
  2750. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2751. {
  2752. Flags &= ~cocShortCutHint;
  2753. }
  2754. TCustomDirView * DView = DirView(Side);
  2755. Param.Options =
  2756. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2757. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2758. if (FLAGSET(Flags, cocQueue))
  2759. {
  2760. Param.Queue = asOn;
  2761. }
  2762. else if (FLAGSET(Flags, cocNonQueue))
  2763. {
  2764. Param.Queue = asOff;
  2765. }
  2766. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2767. }
  2768. //---------------------------------------------------------------------------
  2769. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2770. {
  2771. try
  2772. {
  2773. if (ErrorList->Count)
  2774. {
  2775. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2776. if (MessageDialog(Message, qtError,
  2777. qaOK | qaCancel, HELP_NONE) == qaOK)
  2778. {
  2779. unsigned int Answer;
  2780. int Index = 0;
  2781. do
  2782. {
  2783. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2784. TQueryButtonAlias Aliases[2];
  2785. Aliases[0].Button = qaYes;
  2786. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2787. Aliases[1].Button = qaNo;
  2788. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2789. TMessageParams Params;
  2790. Params.Aliases = Aliases;
  2791. Params.AliasesCount = LENOF(Aliases);
  2792. Answer = MoreMessageDialog(
  2793. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2794. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2795. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2796. qaOK, HELP_NONE, &Params);
  2797. if (Answer == qaNo)
  2798. {
  2799. Index++;
  2800. }
  2801. if (Answer == qaYes)
  2802. {
  2803. Index--;
  2804. }
  2805. }
  2806. while (Answer != qaOK);
  2807. }
  2808. }
  2809. }
  2810. __finally
  2811. {
  2812. TStrings * List = ErrorList;
  2813. ErrorList = NULL;
  2814. for (int i = 0; i < List->Count; i++)
  2815. {
  2816. delete List->Objects[i];
  2817. }
  2818. delete List;
  2819. }
  2820. }
  2821. //---------------------------------------------------------------------------
  2822. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2823. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2824. {
  2825. // needed for checking filemasks, as there's no directory object
  2826. // associated with the file object
  2827. File->FullFileName = FullFileName;
  2828. TFileMasks::TParams MaskParams;
  2829. MaskParams.Size = File->Size;
  2830. MaskParams.Modification = File->Modification;
  2831. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2832. }
  2833. //---------------------------------------------------------------------------
  2834. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2835. {
  2836. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2837. Side = GetSide(Side);
  2838. TCustomDirView * DView = DirView(Side);
  2839. TListItem * FocusedItem = DView->ItemFocused;
  2840. UnicodeString Name;
  2841. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2842. {
  2843. Name = DView->ItemFileName(FocusedItem);
  2844. }
  2845. else
  2846. {
  2847. Name = LoadStr(NEW_FILE);
  2848. }
  2849. UnicodeString Names = Name;
  2850. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2851. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2852. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  2853. {
  2854. while (!Names.IsEmpty())
  2855. {
  2856. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2857. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2858. UnicodeString TargetFileName;
  2859. UnicodeString LocalFileName;
  2860. UnicodeString RootTempDir;
  2861. UnicodeString TempDir;
  2862. UnicodeString RemoteDirectory;
  2863. bool ExistingFile = false;
  2864. if (!IsSideLocalBrowser(Side))
  2865. {
  2866. Name = AbsolutePath(Terminal->CurrentDirectory, Name);
  2867. TRemoteFile * File = NULL;
  2868. if (Terminal->FileExists(Name, &File) &&
  2869. !File->IsDirectory)
  2870. {
  2871. try
  2872. {
  2873. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2874. ExistingFile = true;
  2875. }
  2876. __finally
  2877. {
  2878. delete File;
  2879. }
  2880. }
  2881. if (!ExistingFile)
  2882. {
  2883. RemoteDirectory = UnixExtractFilePath(Name);
  2884. TemporaryDirectoryForRemoteFiles(
  2885. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2886. TargetFileName = UnixExtractFileName(Name);
  2887. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2888. LocalFileName = TempDir +
  2889. // We probably do not want to trim the VMS version here
  2890. Terminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2891. }
  2892. }
  2893. else
  2894. {
  2895. if (ExtractFilePath(Name).IsEmpty())
  2896. {
  2897. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2898. }
  2899. else
  2900. {
  2901. LocalFileName = ExpandFileName(Name);
  2902. }
  2903. TargetFileName = ExtractFileName(Name);
  2904. }
  2905. if (!ExistingFile)
  2906. {
  2907. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2908. if (NewFile)
  2909. {
  2910. int File = FileCreate(ApiPath(LocalFileName));
  2911. if (File < 0)
  2912. {
  2913. if (!RootTempDir.IsEmpty())
  2914. {
  2915. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2916. }
  2917. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2918. }
  2919. else
  2920. {
  2921. FileClose(File);
  2922. }
  2923. }
  2924. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2925. const TEditorData * ExternalEditor = NULL;
  2926. TFileMasks::TParams MaskParams; // size not known
  2927. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2928. false, MaskParams);
  2929. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2930. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2931. }
  2932. }
  2933. }
  2934. }
  2935. //---------------------------------------------------------------------------
  2936. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2937. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2938. {
  2939. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2940. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2941. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2942. return
  2943. ((ExecuteFileBy == efInternalEditor)) ||
  2944. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2945. }
  2946. //---------------------------------------------------------------------------
  2947. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2948. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2949. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2950. UnicodeString RemoteDirectory, bool NewFile)
  2951. {
  2952. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2953. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2954. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2955. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2956. Side = GetSide(Side);
  2957. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2958. if (!IsSideLocalBrowser(Side))
  2959. {
  2960. Data->Terminal = Terminal;
  2961. Data->Queue = Queue;
  2962. Data->SessionData = CloneCurrentSessionData();
  2963. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2964. Data->RemoteDirectory = RemoteDirectory;
  2965. Data->SessionName = Terminal->SessionData->SessionName;
  2966. Data->LocalRootDirectory = LocalRootDirectory;
  2967. Data->OriginalFileName = OriginalFileName;
  2968. Data->Command = L""; // will be changed later for external editor
  2969. }
  2970. if (ExecuteFileBy == efInternalEditor)
  2971. {
  2972. if (!IsSideLocalBrowser(Side))
  2973. {
  2974. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2975. L" - " + Terminal->SessionData->SessionName;
  2976. TForm * Editor;
  2977. try
  2978. {
  2979. TNotifyEvent OnFileChanged = NULL;
  2980. TNotifyEvent OnSaveAll = NULL;
  2981. TAnyModifiedEvent OnAnyModified = NULL;
  2982. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2983. if (Terminal->IsCapable[fcBackgroundTransfers])
  2984. {
  2985. OnFileChanged = FEditorManager->FileChanged;
  2986. OnSaveAll = SaveAllInternalEditors;
  2987. OnAnyModified = AnyInternalEditorModified;
  2988. }
  2989. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2990. FEditorManager->FileReload, FEditorManager->FileClosed,
  2991. OnSaveAll, OnAnyModified,
  2992. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2993. }
  2994. catch(...)
  2995. {
  2996. if (!LocalRootDirectory.IsEmpty())
  2997. {
  2998. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2999. }
  3000. throw;
  3001. }
  3002. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  3003. }
  3004. else
  3005. {
  3006. DebugAssert(!FStandaloneEditing);
  3007. TForm * Editor =
  3008. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  3009. SaveAllInternalEditors, AnyInternalEditorModified,
  3010. L"", false, SessionColor, -1, NewFile);
  3011. FLocalEditors->Add(Editor);
  3012. }
  3013. }
  3014. else
  3015. {
  3016. HANDLE Process;
  3017. if (ExecuteFileBy == efExternalEditor)
  3018. {
  3019. UnicodeString Program, Params, Dir;
  3020. Data->Command = ExternalEditor->ExternalEditor;
  3021. ReformatFileNameCommand(Data->Command);
  3022. SplitCommand(Data->Command, Program, Params, Dir);
  3023. Params = ExpandFileNameCommand(Params, FileName);
  3024. Program = ExpandEnvironmentVariables(Program);
  3025. if (!ExecuteShell(Program, Params, Process))
  3026. {
  3027. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3028. }
  3029. }
  3030. else
  3031. {
  3032. DebugAssert(!IsSideLocalBrowser(Side));
  3033. if (!ExecuteShell(FileName, L"", Process))
  3034. {
  3035. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3036. }
  3037. }
  3038. if (IsSideLocalBrowser(Side) ||
  3039. ((ExecuteFileBy == efShell) &&
  3040. !WinConfiguration->Editor.SDIShellEditor) ||
  3041. ((ExecuteFileBy == efExternalEditor) &&
  3042. !ExternalEditor->SDIExternalEditor))
  3043. {
  3044. // no need for handle
  3045. if (Process != NULL)
  3046. {
  3047. DebugCheck(CloseHandle(Process));
  3048. }
  3049. Process = INVALID_HANDLE_VALUE;
  3050. }
  3051. else
  3052. {
  3053. if (Process == NULL)
  3054. {
  3055. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3056. }
  3057. }
  3058. if (!IsSideLocalBrowser(Side))
  3059. {
  3060. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3061. }
  3062. }
  3063. }
  3064. //---------------------------------------------------------------------------
  3065. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3066. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3067. void * /*Arg*/)
  3068. {
  3069. if (Token != NULL)
  3070. {
  3071. EditorFormFileSave(static_cast<TForm *>(Token));
  3072. }
  3073. }
  3074. //---------------------------------------------------------------------------
  3075. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3076. {
  3077. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3078. {
  3079. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3080. }
  3081. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3082. }
  3083. //---------------------------------------------------------------------------
  3084. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3085. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3086. void * Arg)
  3087. {
  3088. if ((Token != NULL) &&
  3089. IsEditorFormModified(static_cast<TForm *>(Token)))
  3090. {
  3091. *static_cast<bool *>(Arg) = true;
  3092. }
  3093. }
  3094. //---------------------------------------------------------------------------
  3095. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3096. TObject * /*Sender*/, bool & Modified)
  3097. {
  3098. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3099. {
  3100. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3101. {
  3102. Modified = true;
  3103. }
  3104. }
  3105. if (!Modified)
  3106. {
  3107. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3108. }
  3109. }
  3110. //---------------------------------------------------------------------------
  3111. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3112. {
  3113. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3114. }
  3115. //---------------------------------------------------------------------------
  3116. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3117. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3118. UnicodeString & Result, UnicodeString & RootDirectory)
  3119. {
  3120. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3121. {
  3122. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3123. Result = RootDirectory;
  3124. }
  3125. else
  3126. {
  3127. RootDirectory = L"";
  3128. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3129. Result = IncludeTrailingBackslash(Result);
  3130. }
  3131. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3132. {
  3133. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3134. }
  3135. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3136. {
  3137. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3138. {
  3139. RemoteDirectory.Delete(1, 1);
  3140. }
  3141. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3142. }
  3143. if (!ForceDirectories(ApiPath(Result)))
  3144. {
  3145. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3146. }
  3147. }
  3148. //---------------------------------------------------------------------------
  3149. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3150. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3151. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3152. {
  3153. DebugAssert(!IsLocalBrowserMode());
  3154. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3155. if (ForceText)
  3156. {
  3157. CopyParam.TransferMode = tmAscii;
  3158. }
  3159. TemporaryFileCopyParam(CopyParam);
  3160. if (AllFiles)
  3161. {
  3162. CopyParam.IncludeFileMask = TFileMasks();
  3163. }
  3164. if (TempDir.IsEmpty())
  3165. {
  3166. TemporaryDirectoryForRemoteFiles(Terminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3167. }
  3168. DebugAssert(!FAutoOperation);
  3169. FAutoOperation = AutoOperation;
  3170. Terminal->ExceptionOnFail = true;
  3171. try
  3172. {
  3173. try
  3174. {
  3175. // turn off confirmations, as for MDI editors we may possibly download
  3176. // the same file over
  3177. Terminal->CopyToLocal(
  3178. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3179. if (GetTargetNames)
  3180. {
  3181. for (int i = 0; i < FileList->Count; i++)
  3182. {
  3183. FileList->Strings[i] =
  3184. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3185. }
  3186. }
  3187. }
  3188. catch(...)
  3189. {
  3190. if (!RootTempDir.IsEmpty())
  3191. {
  3192. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3193. }
  3194. throw;
  3195. }
  3196. }
  3197. __finally
  3198. {
  3199. FAutoOperation = false;
  3200. Terminal->ExceptionOnFail = false;
  3201. }
  3202. }
  3203. //---------------------------------------------------------------------------
  3204. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3205. {
  3206. // Do not waste time checking for default editor list the next time,
  3207. // or testing if default editor is not notepad.
  3208. bool TryNextTime = false;
  3209. UnicodeString UsageState;
  3210. if (!WinConfiguration->EditorList->IsDefaultList())
  3211. {
  3212. UsageState = "H";
  3213. }
  3214. else
  3215. {
  3216. UnicodeString Executable;
  3217. UnicodeString ExecutableDescription;
  3218. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3219. {
  3220. UnicodeString Message =
  3221. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3222. unsigned int Answer =
  3223. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3224. if (Answer != qaOK)
  3225. {
  3226. UsageState = "R";
  3227. }
  3228. else
  3229. {
  3230. UsageState = "A";
  3231. TEditorData EditorData;
  3232. EditorData.Editor = edExternal;
  3233. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3234. EditorData.ExternalEditorOptionsAutodetect();
  3235. TEditorList EditorList;
  3236. EditorList = *WinConfiguration->EditorList;
  3237. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3238. WinConfiguration->EditorList = &EditorList;
  3239. }
  3240. }
  3241. }
  3242. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3243. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3244. }
  3245. //---------------------------------------------------------------------------
  3246. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3247. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3248. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3249. {
  3250. if (ExecuteFileBy == efDefaultEditor)
  3251. {
  3252. if (!WinConfiguration->OfferedEditorAutoConfig)
  3253. {
  3254. EditorAutoConfig();
  3255. }
  3256. const TEditorPreferences * Editor =
  3257. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3258. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3259. {
  3260. ExecuteFileBy = efInternalEditor;
  3261. ExternalEditor = NULL;
  3262. }
  3263. else if (Editor->Data->Editor == edOpen)
  3264. {
  3265. ExecuteFileBy = efShell;
  3266. ExternalEditor = NULL;
  3267. }
  3268. else
  3269. {
  3270. ExecuteFileBy = efExternalEditor;
  3271. ExternalEditor = Editor->Data;
  3272. }
  3273. }
  3274. }
  3275. //---------------------------------------------------------------------------
  3276. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3277. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3278. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3279. {
  3280. UnicodeString OriginalFileName;
  3281. UnicodeString LocalRootDirectory;
  3282. UnicodeString RemoteDirectory;
  3283. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3284. IsSideLocalBrowser(Side), MaskParams);
  3285. UnicodeString Counter;
  3286. UnicodeString LocalFileName;
  3287. bool Handled = false;
  3288. if (!IsSideLocalBrowser(Side))
  3289. {
  3290. // We need to trim VMS version here, so that we use name without version
  3291. // when uploading back to create a new version of the file
  3292. OriginalFileName = Terminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3293. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3294. TObject * Token = NULL;
  3295. UnicodeString LocalDirectory;
  3296. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3297. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3298. LocalDirectory))
  3299. {
  3300. if (Token != NULL)
  3301. {
  3302. TForm * Form = dynamic_cast<TForm *>(Token);
  3303. if (Form->WindowState == wsMinimized)
  3304. {
  3305. ShowWindow(Form->Handle, SW_RESTORE);
  3306. }
  3307. else
  3308. {
  3309. Form->SetFocus();
  3310. }
  3311. Handled = true;
  3312. }
  3313. else
  3314. {
  3315. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3316. }
  3317. }
  3318. if (!Handled)
  3319. {
  3320. TStringList * FileList1 = new TStringList();
  3321. try
  3322. {
  3323. FileList1->AddObject(FullFileName, Object);
  3324. TemporarilyDownloadFiles(FileList1,
  3325. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3326. LocalRootDirectory, LocalDirectory, true, true, true);
  3327. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3328. }
  3329. __finally
  3330. {
  3331. delete FileList1;
  3332. }
  3333. switch (ExecuteFileBy)
  3334. {
  3335. case efShell:
  3336. Counter = "RemoteFilesExecuted";
  3337. break;
  3338. case efInternalEditor:
  3339. Counter = "RemoteFilesOpenedInInternalEditor";
  3340. break;
  3341. case efExternalEditor:
  3342. Counter = "RemoteFilesOpenedInExternalEditor";
  3343. break;
  3344. default:
  3345. DebugFail();
  3346. }
  3347. }
  3348. }
  3349. else
  3350. {
  3351. LocalFileName = FullFileName;
  3352. OriginalFileName = ExtractFileName(FullFileName);
  3353. switch (ExecuteFileBy)
  3354. {
  3355. case efShell:
  3356. Counter = "LocalFilesExecuted";
  3357. break;
  3358. case efInternalEditor:
  3359. Counter = "LocalFilesOpenedInInternalEditor";
  3360. break;
  3361. case efExternalEditor:
  3362. Counter = "LocalFilesOpenedInExternalEditor";
  3363. break;
  3364. default:
  3365. DebugFail();
  3366. }
  3367. }
  3368. if (!Handled)
  3369. {
  3370. Configuration->Usage->Inc(Counter);
  3371. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3372. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3373. }
  3374. }
  3375. //---------------------------------------------------------------------------
  3376. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3377. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3378. bool AllSelected, bool OnFocused)
  3379. {
  3380. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3381. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3382. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3383. Side = GetSide(Side);
  3384. TCustomDirView * DView = DirView(Side);
  3385. TStrings * FileList =
  3386. AllSelected ?
  3387. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3388. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3389. try
  3390. {
  3391. DebugAssert(AllSelected || (FileList->Count == 1));
  3392. for (int i = 0; i < FileList->Count; i++)
  3393. {
  3394. UnicodeString ListFileName = FileList->Strings[i];
  3395. UnicodeString FileNameOnly =
  3396. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3397. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3398. if (!DView->ItemIsDirectory(Item))
  3399. {
  3400. UnicodeString FullFileName;
  3401. if (!IsSideLocalBrowser(Side))
  3402. {
  3403. FullFileName = DirView(Side)->Path + ListFileName;
  3404. }
  3405. else
  3406. {
  3407. FullFileName = ListFileName;
  3408. }
  3409. TFileMasks::TParams MaskParams;
  3410. MaskParams.Size = DView->ItemFileSize(Item);
  3411. TDateTimePrecision Precision;
  3412. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3413. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3414. FileList->Objects[i], MaskParams);
  3415. }
  3416. }
  3417. }
  3418. __finally
  3419. {
  3420. delete FileList;
  3421. }
  3422. }
  3423. //---------------------------------------------------------------------------
  3424. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3425. {
  3426. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3427. CopyParam.FileNameCase = ncNoChange;
  3428. CopyParam.PreserveRights = false;
  3429. CopyParam.PreserveReadOnly = false;
  3430. CopyParam.ReplaceInvalidChars = true;
  3431. CopyParam.IncludeFileMask = TFileMasks();
  3432. CopyParam.NewerOnly = false;
  3433. CopyParam.FileMask = L"";
  3434. }
  3435. //---------------------------------------------------------------------------
  3436. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3437. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3438. {
  3439. TTerminalManager * Manager = TTerminalManager::Instance();
  3440. if (!IsActiveTerminal(Data->Terminal))
  3441. {
  3442. if (!NonVisualDataModule->Busy)
  3443. {
  3444. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3445. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3446. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3447. if (Data->Terminal == NULL)
  3448. {
  3449. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3450. if (SameSiteTerminal != NULL)
  3451. {
  3452. UnicodeString Message =
  3453. FMTLOAD(EDIT_SESSION_REATTACH,
  3454. (FileNameOnly, Data->SessionName, FileNameOnly));
  3455. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3456. {
  3457. Data->Terminal = Terminal;
  3458. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3459. Data->SessionName = Terminal->SessionData->SessionName;
  3460. // We might also overwrite session data
  3461. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3462. }
  3463. else
  3464. {
  3465. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3466. Abort();
  3467. }
  3468. }
  3469. }
  3470. // foreground session should reconnect itself
  3471. else if (Terminal != Data->Terminal)
  3472. {
  3473. UnicodeString Message =
  3474. MainInstructions(
  3475. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3476. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3477. {
  3478. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3479. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3480. }
  3481. else
  3482. {
  3483. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3484. Abort();
  3485. }
  3486. }
  3487. }
  3488. if (!IsActiveTerminal(Data->Terminal))
  3489. {
  3490. Configuration->Usage->Inc(L"EditInactiveSession");
  3491. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3492. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3493. (ExtractFileName(FileName), Data->SessionName)));
  3494. }
  3495. }
  3496. TStrings * FileList = new TStringList();
  3497. try
  3498. {
  3499. FileList->Add(FileName);
  3500. // consider using the same settings (preset) as when the file was downloaded
  3501. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3502. TemporaryFileCopyParam(CopyParam);
  3503. if (Data->ForceText)
  3504. {
  3505. CopyParam.TransferMode = tmAscii;
  3506. }
  3507. // so i do not need to worry if masking algorithm works in all cases
  3508. // ("" means "copy file name", no masking is actually done)
  3509. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3510. {
  3511. CopyParam.FileMask = L"";
  3512. }
  3513. else
  3514. {
  3515. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3516. }
  3517. DebugAssert(Data->Queue != NULL);
  3518. int Params = cpNoConfirmation | cpTemporary;
  3519. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3520. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3521. QueueItem->CompleteEvent = UploadCompleteEvent;
  3522. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3523. }
  3524. __finally
  3525. {
  3526. delete FileList;
  3527. }
  3528. }
  3529. //---------------------------------------------------------------------------
  3530. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3531. const UnicodeString FileName, const TEditedFileData * Data)
  3532. {
  3533. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3534. DebugAssert(!NonVisualDataModule->Busy);
  3535. if (!IsActiveTerminal(Data->Terminal))
  3536. {
  3537. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3538. (ExtractFileName(FileName), Data->SessionName)));
  3539. }
  3540. TManagedTerminal * PrevSession = TTerminalManager::Instance()->ActiveSession;
  3541. TTerminalManager::Instance()->ActiveSession = Data->Terminal;
  3542. NonVisualDataModule->StartBusy();
  3543. try
  3544. {
  3545. std::unique_ptr<TRemoteFile> File;
  3546. UnicodeString RemoteFileName =
  3547. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3548. Terminal->ExceptionOnFail = true;
  3549. try
  3550. {
  3551. TRemoteFile * AFile = NULL;
  3552. Terminal->ReadFile(RemoteFileName, AFile);
  3553. File.reset(AFile);
  3554. if (!File->HaveFullFileName)
  3555. {
  3556. File->FullFileName = RemoteFileName;
  3557. }
  3558. }
  3559. __finally
  3560. {
  3561. Terminal->ExceptionOnFail = false;
  3562. }
  3563. std::unique_ptr<TStrings> FileList(new TStringList());
  3564. FileList->AddObject(RemoteFileName, File.get());
  3565. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3566. UnicodeString TempDir = ExtractFilePath(FileName);
  3567. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3568. TempDir, true, true, true);
  3569. // sanity check, the target file name should be still the same
  3570. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3571. }
  3572. __finally
  3573. {
  3574. NonVisualDataModule->EndBusy();
  3575. // it actually may not exist anymore...
  3576. TTerminalManager::Instance()->ActiveSession = PrevSession;
  3577. }
  3578. }
  3579. //---------------------------------------------------------------------------
  3580. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3581. const TEditedFileData * Data, bool & KeepOpen)
  3582. {
  3583. // Command is set for external editors only (not for "shell" open).
  3584. if (!Data->Command.IsEmpty())
  3585. {
  3586. bool AnyFound = false;
  3587. bool AnyMDI = false;
  3588. bool AnyNonMDI = false;
  3589. bool AnyDetect = false;
  3590. TEditorList * EditorList = new TEditorList();
  3591. try
  3592. {
  3593. *EditorList = *WinConfiguration->EditorList;
  3594. for (int i = 0; i < EditorList->Count; i++)
  3595. {
  3596. const TEditorPreferences * Editor = EditorList->Editors[i];
  3597. if ((Editor->Data->Editor == edExternal) &&
  3598. (Editor->Data->ExternalEditor == Data->Command))
  3599. {
  3600. AnyFound = true;
  3601. if (Editor->Data->SDIExternalEditor)
  3602. {
  3603. AnyNonMDI = true;
  3604. if (Editor->Data->DetectMDIExternalEditor)
  3605. {
  3606. AnyDetect = true;
  3607. }
  3608. }
  3609. else
  3610. {
  3611. AnyMDI = true;
  3612. }
  3613. }
  3614. }
  3615. bool EnableMDI = false;
  3616. bool DisableDetect = false;
  3617. if (AnyMDI)
  3618. {
  3619. KeepOpen = true;
  3620. if (AnyNonMDI)
  3621. {
  3622. // there is at least one instance of the editor with MDI support enabled,
  3623. // and one with disabled, enable it for all instances
  3624. EnableMDI = true;
  3625. }
  3626. }
  3627. else if (AnyFound && !AnyDetect)
  3628. {
  3629. // at least once instance found but all have MDI autodetection disabled
  3630. // => close the file (default action)
  3631. }
  3632. else
  3633. {
  3634. // no instance of the editor has MDI support enabled
  3635. TMessageParams Params;
  3636. if (AnyFound)
  3637. {
  3638. // there is at least one instance of the editor
  3639. Params.Params |= mpNeverAskAgainCheck;
  3640. }
  3641. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3642. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3643. switch (Answer)
  3644. {
  3645. case qaNeverAskAgain:
  3646. DisableDetect = true;
  3647. break;
  3648. case qaNo:
  3649. EnableMDI = true;
  3650. KeepOpen = true;
  3651. break;
  3652. }
  3653. }
  3654. if (AnyFound && (EnableMDI || DisableDetect))
  3655. {
  3656. bool Changed = false;
  3657. for (int i = 0; i < EditorList->Count; i++)
  3658. {
  3659. const TEditorPreferences * Editor = EditorList->Editors[i];
  3660. if ((Editor->Data->Editor == edExternal) &&
  3661. (Editor->Data->ExternalEditor == Data->Command) &&
  3662. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3663. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3664. {
  3665. Changed = true;
  3666. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3667. if (EnableMDI)
  3668. {
  3669. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3670. }
  3671. if (DisableDetect)
  3672. {
  3673. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3674. }
  3675. EditorList->Change(i, UpdatedEditor);
  3676. }
  3677. }
  3678. if (Changed)
  3679. {
  3680. WinConfiguration->EditorList = EditorList;
  3681. }
  3682. }
  3683. }
  3684. __finally
  3685. {
  3686. delete EditorList;
  3687. }
  3688. }
  3689. else
  3690. {
  3691. // "open" case
  3692. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3693. qaOK, HELP_APP_EARLY_CLOSED);
  3694. }
  3695. }
  3696. //---------------------------------------------------------------------------
  3697. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3698. {
  3699. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3700. }
  3701. //---------------------------------------------------------------------------
  3702. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3703. {
  3704. SideEnter(osRemote);
  3705. }
  3706. //---------------------------------------------------------------------------
  3707. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3708. {
  3709. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3710. SideEnter(osRemote);
  3711. }
  3712. //---------------------------------------------------------------------------
  3713. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3714. {
  3715. FCurrentSide = Side;
  3716. if (Visible)
  3717. {
  3718. UpdateControls();
  3719. }
  3720. }
  3721. //---------------------------------------------------------------------------
  3722. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3723. TStrings * FileList, bool Alternative)
  3724. {
  3725. TCustomDirView * DView = DirView(Side);
  3726. DView->SaveSelection();
  3727. DView->SaveSelectedNames();
  3728. DebugAssert(!FAlternativeDelete);
  3729. FAlternativeDelete = Alternative;
  3730. try
  3731. {
  3732. if (!IsSideLocalBrowser(Side))
  3733. {
  3734. DebugAssert(Terminal != NULL);
  3735. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3736. }
  3737. else
  3738. {
  3739. if (IsLocalBrowserMode())
  3740. {
  3741. Configuration->Usage->Inc(L"LocalLocalDeletes");
  3742. }
  3743. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  3744. FProgressSide = FCurrentSide;
  3745. try
  3746. {
  3747. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3748. }
  3749. __finally
  3750. {
  3751. ReloadLocalDirectory();
  3752. }
  3753. }
  3754. FAlternativeDelete = false;
  3755. }
  3756. catch(...)
  3757. {
  3758. FAlternativeDelete = false;
  3759. DView->DiscardSavedSelection();
  3760. throw;
  3761. }
  3762. DView->RestoreSelection();
  3763. }
  3764. //---------------------------------------------------------------------------
  3765. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3766. {
  3767. DebugAssert(Terminal);
  3768. DebugAssert(!IsLocalBrowserMode());
  3769. RemoteDirView->SaveSelection();
  3770. RemoteDirView->SaveSelectedNames();
  3771. try
  3772. {
  3773. if (Lock)
  3774. {
  3775. Terminal->LockFiles(FileList);
  3776. }
  3777. else
  3778. {
  3779. Terminal->UnlockFiles(FileList);
  3780. }
  3781. }
  3782. catch(...)
  3783. {
  3784. RemoteDirView->DiscardSavedSelection();
  3785. throw;
  3786. }
  3787. RemoteDirView->RestoreSelection();
  3788. }
  3789. //---------------------------------------------------------------------------
  3790. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3791. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3792. bool NoConfirmation, bool Move)
  3793. {
  3794. DebugAssert(Terminal != NULL);
  3795. DebugAssert(!IsLocalBrowserMode());
  3796. // update Terminal->StateData->RemoteDirectory
  3797. UpdateTerminal(Terminal);
  3798. if (Session == NULL)
  3799. {
  3800. Session = TTerminalManager::Instance()->ActiveTerminal;
  3801. }
  3802. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3803. {
  3804. if (RemoteDriveView->DropTarget != NULL)
  3805. {
  3806. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3807. }
  3808. else if (RemoteDirView->DropTarget != NULL)
  3809. {
  3810. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3811. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3812. }
  3813. else
  3814. {
  3815. Target = RemoteDirView->Path;
  3816. }
  3817. }
  3818. else
  3819. {
  3820. Target = Session->StateData->RemoteDirectory;
  3821. }
  3822. Target = UnixIncludeTrailingBackslash(Target);
  3823. if (FileList->Count == 1)
  3824. {
  3825. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3826. }
  3827. else
  3828. {
  3829. FileMask = AnyMask;
  3830. }
  3831. DirectCopy = Terminal->IsCapable[fcRemoteCopy] || Terminal->IsCapable[fcSecondaryShell];
  3832. bool Result = true;
  3833. if (!NoConfirmation)
  3834. {
  3835. bool Multi = (FileList->Count > 1);
  3836. if (Move)
  3837. {
  3838. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3839. }
  3840. else
  3841. {
  3842. TStrings * Sessions = TTerminalManager::Instance()->SessionList;
  3843. TStrings * Directories = new TStringList;
  3844. try
  3845. {
  3846. for (int Index = 0; Index < Sessions->Count; Index++)
  3847. {
  3848. TManagedTerminal * Terminal =
  3849. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3850. Directories->Add(Terminal->StateData->RemoteDirectory);
  3851. }
  3852. TDirectRemoteCopy AllowDirectCopy;
  3853. if (Terminal->IsCapable[fcRemoteCopy] || Terminal->CommandSessionOpened)
  3854. {
  3855. DebugAssert(DirectCopy);
  3856. AllowDirectCopy = drcAllow;
  3857. }
  3858. else if (Terminal->IsCapable[fcSecondaryShell])
  3859. {
  3860. DebugAssert(DirectCopy);
  3861. AllowDirectCopy = drcConfirmCommandSession;
  3862. }
  3863. else
  3864. {
  3865. DebugAssert(!DirectCopy);
  3866. AllowDirectCopy = drcDisallow;
  3867. }
  3868. void * ASession = Session;
  3869. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3870. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3871. Session = static_cast<TManagedTerminal *>(ASession);
  3872. }
  3873. __finally
  3874. {
  3875. delete Directories;
  3876. }
  3877. }
  3878. }
  3879. return Result;
  3880. }
  3881. //---------------------------------------------------------------------------
  3882. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3883. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3884. {
  3885. DebugAssert(!IsLocalBrowserMode());
  3886. bool DirectCopy;
  3887. UnicodeString Target, FileMask;
  3888. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3889. if (Result)
  3890. {
  3891. if (!Move && !DirectCopy)
  3892. {
  3893. Configuration->Usage->Inc("RemoteCopyTemp");
  3894. UnicodeString RootTempDir;
  3895. UnicodeString TempDir;
  3896. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3897. TStrings * TemporaryFilesList = new TStringList();
  3898. try
  3899. {
  3900. TMakeLocalFileListParams MakeFileListParam;
  3901. MakeFileListParam.FileList = TemporaryFilesList;
  3902. MakeFileListParam.FileTimes = NULL;
  3903. MakeFileListParam.IncludeDirs = true;
  3904. MakeFileListParam.Recursive = false;
  3905. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  3906. TTerminalManager::Instance()->ActiveSession = Session;
  3907. if (TemporaryFilesList->Count > 0)
  3908. {
  3909. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3910. CopyParam.FileMask = FileMask;
  3911. DebugAssert(!FAutoOperation);
  3912. FAutoOperation = true;
  3913. Terminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3914. }
  3915. }
  3916. __finally
  3917. {
  3918. delete TemporaryFilesList;
  3919. FAutoOperation = false;
  3920. if (!RootTempDir.IsEmpty())
  3921. {
  3922. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3923. }
  3924. }
  3925. }
  3926. else
  3927. {
  3928. RemoteDirView->SaveSelection();
  3929. RemoteDirView->SaveSelectedNames();
  3930. try
  3931. {
  3932. if (Move)
  3933. {
  3934. Configuration->Usage->Inc("RemoteMove");
  3935. Terminal->MoveFiles(FileList, Target, FileMask);
  3936. }
  3937. else
  3938. {
  3939. Configuration->Usage->Inc("RemoteCopyDirect");
  3940. DebugAssert(DirectCopy);
  3941. DebugAssert(Session == Terminal);
  3942. if (Terminal->IsCapable[fcRemoteCopy] ||
  3943. Terminal->CommandSessionOpened ||
  3944. CommandSessionFallback())
  3945. {
  3946. Terminal->CopyFiles(FileList, Target, FileMask);
  3947. }
  3948. }
  3949. }
  3950. catch(...)
  3951. {
  3952. RemoteDirView->DiscardSavedSelection();
  3953. throw;
  3954. }
  3955. RemoteDirView->RestoreSelection();
  3956. }
  3957. }
  3958. return Result;
  3959. }
  3960. //---------------------------------------------------------------------------
  3961. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3962. const UnicodeString & Path, TRemoteProperties & Properties)
  3963. {
  3964. DebugAssert(!IsLocalBrowserMode());
  3965. Properties.Valid = Properties.Valid << vpEncrypt;
  3966. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3967. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3968. }
  3969. //---------------------------------------------------------------------------
  3970. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3971. {
  3972. Side = GetSide(Side);
  3973. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3974. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3975. UnicodeString Name = LoadStr(NEW_FOLDER);
  3976. int AllowedChanges =
  3977. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3978. bool SaveSettings = false;
  3979. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3980. {
  3981. TWindowLock Lock(this);
  3982. if (!IsSideLocalBrowser(Side))
  3983. {
  3984. if (SaveSettings)
  3985. {
  3986. GUIConfiguration->NewDirectoryProperties = Properties;
  3987. }
  3988. CreateRemoteDirectory(Name, Properties);
  3989. }
  3990. else
  3991. {
  3992. DirView(Side)->CreateDirectory(Name);
  3993. }
  3994. }
  3995. }
  3996. //---------------------------------------------------------------------------
  3997. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3998. {
  3999. TWindowLock Lock(this);
  4000. DirView(Side)->ExecuteHomeDirectory();
  4001. }
  4002. //---------------------------------------------------------------------------
  4003. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  4004. {
  4005. DoOpenDirectoryDialog(odBrowse, Side);
  4006. }
  4007. //---------------------------------------------------------------------------
  4008. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  4009. {
  4010. TOperationSide BookmarkSide = IsLocalBrowserMode() ? osLocal : Side;
  4011. UnicodeString Path = Bookmark->GetSideDirectory(BookmarkSide);
  4012. bool Result = !Path.IsEmpty();
  4013. if (Result)
  4014. {
  4015. // While we might get here when the session is closed (from location profiles),
  4016. // it's not a problem as the Path setter is noop then
  4017. DirView(Side)->Path = Path;
  4018. }
  4019. return Result;
  4020. }
  4021. //---------------------------------------------------------------------------
  4022. void __fastcall TCustomScpExplorerForm::CalculateSize(
  4023. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  4024. bool & Close)
  4025. {
  4026. // terminal can be already closed (e.g. dropped connection)
  4027. if (Terminal != NULL)
  4028. {
  4029. try
  4030. {
  4031. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  4032. }
  4033. catch(...)
  4034. {
  4035. if (!Terminal->Active)
  4036. {
  4037. Close = true;
  4038. }
  4039. throw;
  4040. }
  4041. }
  4042. }
  4043. //---------------------------------------------------------------------------
  4044. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4045. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4046. bool & Close)
  4047. {
  4048. // terminal can be already closed (e.g. dropped connection)
  4049. if (Terminal != NULL)
  4050. {
  4051. Configuration->Usage->Inc(L"ChecksumCalculated");
  4052. try
  4053. {
  4054. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4055. }
  4056. catch(...)
  4057. {
  4058. if (!Terminal->Active)
  4059. {
  4060. Close = true;
  4061. }
  4062. throw;
  4063. }
  4064. }
  4065. }
  4066. //---------------------------------------------------------------------------
  4067. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4068. {
  4069. bool Result;
  4070. if (!IsSideLocalBrowser(Side))
  4071. {
  4072. TRemoteTokenList * GroupList = NULL;
  4073. TRemoteTokenList * UserList = NULL;
  4074. try
  4075. {
  4076. TRemoteProperties CurrentProperties;
  4077. if (Terminal->LoadFilesProperties(FileList))
  4078. {
  4079. RemoteDirView->Invalidate();
  4080. }
  4081. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4082. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4083. if (CapableGroupChanging || CapableOwnerChanging)
  4084. {
  4085. if (CapableGroupChanging)
  4086. {
  4087. GroupList = Terminal->Groups->Duplicate();
  4088. }
  4089. if (CapableOwnerChanging)
  4090. {
  4091. UserList = Terminal->Users->Duplicate();
  4092. }
  4093. TRemoteDirectory * Files = Terminal->Files;
  4094. int Count = Files->Count;
  4095. if (Count > 100)
  4096. {
  4097. Count = 100;
  4098. }
  4099. for (int Index = 0; Index < Count; Index++)
  4100. {
  4101. TRemoteFile * File = Files->Files[Index];
  4102. if (CapableGroupChanging)
  4103. {
  4104. GroupList->AddUnique(File->Group);
  4105. }
  4106. if (CapableOwnerChanging)
  4107. {
  4108. UserList->AddUnique(File->Owner);
  4109. }
  4110. }
  4111. // if we haven't collected tokens for all files in current directory,
  4112. // make sure we collect them at least for all selected files.
  4113. // (note that so far the files in FileList has to be from current direcotry)
  4114. if (Count < Files->Count)
  4115. {
  4116. for (int Index = 0; Index < FileList->Count; Index++)
  4117. {
  4118. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4119. if (CapableGroupChanging)
  4120. {
  4121. GroupList->AddUnique(File->Group);
  4122. }
  4123. if (CapableOwnerChanging)
  4124. {
  4125. UserList->AddUnique(File->Owner);
  4126. }
  4127. }
  4128. }
  4129. }
  4130. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4131. int Flags = 0;
  4132. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4133. if (CapableOwnerChanging) Flags |= cpOwner;
  4134. if (CapableGroupChanging) Flags |= cpGroup;
  4135. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4136. if (Terminal->IsCapable[fcCalculatingChecksum])
  4137. {
  4138. CalculateChecksumEvent = CalculateChecksum;
  4139. }
  4140. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4141. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4142. TRemoteProperties NewProperties = CurrentProperties;
  4143. Result =
  4144. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4145. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4146. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4147. CalculateSize, CalculateChecksumEvent);
  4148. if (Result)
  4149. {
  4150. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4151. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4152. }
  4153. }
  4154. __finally
  4155. {
  4156. delete GroupList;
  4157. delete UserList;
  4158. }
  4159. }
  4160. else
  4161. {
  4162. DirView(Side)->DisplayPropertiesMenu();
  4163. Result = true;
  4164. }
  4165. return Result;
  4166. }
  4167. //---------------------------------------------------------------------------
  4168. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4169. {
  4170. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4171. {
  4172. FIgnoreNextDialogChar = Key;
  4173. }
  4174. Key = 0;
  4175. }
  4176. //---------------------------------------------------------------------------
  4177. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4178. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4179. {
  4180. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4181. if (Command != NULL)
  4182. {
  4183. KeyProcessed(Key, Shift);
  4184. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4185. {
  4186. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4187. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4188. false, false, const_cast<TCustomCommandType *>(Command));
  4189. }
  4190. }
  4191. }
  4192. //---------------------------------------------------------------------------
  4193. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4194. {
  4195. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4196. {
  4197. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4198. }
  4199. if (!DirView(osCurrent)->IsEditing())
  4200. {
  4201. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4202. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4203. {
  4204. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4205. // But so far it's not a problem, as it does what we want.
  4206. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4207. if (((Action->ShortCut == KeyShortCut) ||
  4208. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4209. AllowedAction(Action, aaShortCut))
  4210. {
  4211. // Has to be called before the action as the dialog char is already in queue.
  4212. // So when the action consumes message queue, we already need to have the
  4213. // FIgnoreNextDialogChar set
  4214. KeyProcessed(Key, Shift);
  4215. // Reset reference to previous component (when menu/toolbar was clicked).
  4216. // Needed to detect that action was invoked by keyboard shortcut
  4217. // in TNonVisualDataModule::ExplorerActionsExecute
  4218. Action->ActionComponent = NULL;
  4219. Action->Execute();
  4220. return;
  4221. }
  4222. }
  4223. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4224. {
  4225. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4226. {
  4227. KeyProcessed(Key, Shift);
  4228. TTerminalManager::Instance()->ActiveSessionIndex = i;
  4229. return;
  4230. }
  4231. }
  4232. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4233. {
  4234. KeyProcessed(Key, Shift);
  4235. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4236. }
  4237. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4238. if (IsCustomShortCut(CustomShortCut))
  4239. {
  4240. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4241. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4242. if (WinConfiguration->SharedBookmarks != NULL)
  4243. {
  4244. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4245. if ((Bookmark != NULL) &&
  4246. OpenBookmark(FCurrentSide, Bookmark))
  4247. {
  4248. KeyProcessed(Key, Shift);
  4249. }
  4250. }
  4251. }
  4252. }
  4253. TForm::KeyDown(Key, Shift);
  4254. }
  4255. //---------------------------------------------------------------------------
  4256. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4257. {
  4258. bool OpenedTerminal = false;
  4259. UnicodeString ProtocolName;
  4260. UnicodeString ProtocolNameHint;
  4261. UnicodeString SecurityProtocolName;
  4262. UnicodeString DurationHint;
  4263. // See the comment in TScpCommanderForm::UpdateControls()
  4264. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4265. if (ActiveTerminal != NULL)
  4266. {
  4267. // Active is not enough here
  4268. if (ActiveTerminal->Status == ssOpened)
  4269. {
  4270. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4271. const TFileSystemInfo & FileSystemInfo = ActiveTerminal->GetFileSystemInfo();
  4272. if (FileSystemInfo.ProtocolName.IsEmpty())
  4273. {
  4274. ProtocolName = SessionInfo.ProtocolName;
  4275. }
  4276. else
  4277. {
  4278. ProtocolName = FileSystemInfo.ProtocolName;
  4279. }
  4280. ProtocolNameHint = LoadStr(STATUS_PROTOCOL_HINT);
  4281. SecurityProtocolName = SessionInfo.SecurityProtocolName;
  4282. DurationHint = LoadStr(STATUS_DURATION_HINT);
  4283. OpenedTerminal = true;
  4284. }
  4285. else if (ActiveTerminal->Status > ssClosed)
  4286. {
  4287. ProtocolName = LoadStr(STATUS_CONNECTING);
  4288. }
  4289. else
  4290. {
  4291. ProtocolName = LoadStr(STATUS_NOT_CONNECTED2);
  4292. }
  4293. }
  4294. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4295. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4296. TTBXStatusPanel * ProtocolStatusPanel = SessionStatusBar->Panels->Items[Offset + 0];
  4297. ProtocolStatusPanel->ViewPriority = (ActiveTerminal != NULL) ? 100 : 0;
  4298. if (ProtocolStatusPanel->Caption != ProtocolName)
  4299. {
  4300. ProtocolStatusPanel->Caption = ProtocolName;
  4301. std::unique_ptr<TCanvas> Canvas(CreateControlCanvas(SessionStatusBar));
  4302. ProtocolStatusPanel->Size = Canvas->TextWidth(ProtocolName) + ScaleByTextHeight(SessionStatusBar, 32);
  4303. }
  4304. ProtocolStatusPanel->Hint = ProtocolNameHint;
  4305. TTBXStatusPanel * SecurityStatusPanel = SessionStatusBar->Panels->Items[Offset + 1];
  4306. SecurityStatusPanel->ViewPriority = OpenedTerminal ? 98 : 0;
  4307. bool SecurityEnabled = !SecurityProtocolName.IsEmpty();
  4308. SecurityStatusPanel->Enabled = SecurityEnabled;
  4309. UnicodeString SecurityProtocolHint;
  4310. if (SecurityEnabled)
  4311. {
  4312. SecurityProtocolHint = FMTLOAD(STATUS_SECURE, (SecurityProtocolName));
  4313. }
  4314. else
  4315. {
  4316. SecurityProtocolHint = LoadStr(STATUS_INSECURE);
  4317. }
  4318. SecurityStatusPanel->Hint = SecurityProtocolHint;
  4319. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[Offset + 2];
  4320. DurationStatusPanel->ViewPriority = OpenedTerminal ? 99 : 0;
  4321. DurationStatusPanel->Hint = DurationHint;
  4322. UpdateStatusBar();
  4323. }
  4324. //---------------------------------------------------------------------------
  4325. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4326. {
  4327. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4328. DebugAssert(SessionStatusBar != NULL);
  4329. TTBXStatusPanel * NoteStatusPanel = SessionStatusBar->Panels->Items[0];
  4330. if (!FNote.IsEmpty())
  4331. {
  4332. NoteStatusPanel->Caption = FNote;
  4333. }
  4334. else
  4335. {
  4336. UpdateStatusPanelText(NoteStatusPanel);
  4337. }
  4338. NoteStatusPanel->Hint = FNoteHints;
  4339. UnicodeString LoginTime;
  4340. // See the comment in TScpCommanderForm::UpdateControls()
  4341. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4342. // Active is not enough here
  4343. if ((ActiveTerminal != NULL) && (ActiveTerminal->Status == ssOpened))
  4344. {
  4345. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4346. LoginTime = FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4347. }
  4348. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1];
  4349. DurationStatusPanel->Caption = LoginTime;
  4350. }
  4351. //---------------------------------------------------------------------------
  4352. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4353. {
  4354. Panel->Caption = L"";
  4355. }
  4356. //---------------------------------------------------------------------------
  4357. void __fastcall TCustomScpExplorerForm::Idle()
  4358. {
  4359. if (FShowing || FStandaloneEditing)
  4360. {
  4361. FEditorManager->Check();
  4362. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4363. // that needs to know if queue view is visible (and it may be closed after queue update)
  4364. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4365. }
  4366. if (FShowing)
  4367. {
  4368. if (!NonVisualDataModule->Busy &&
  4369. // Menu is opened or drag&drop is going on
  4370. (Mouse->Capture == NULL))
  4371. {
  4372. if (FRefreshRemoteDirectory)
  4373. {
  4374. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4375. {
  4376. Terminal->RefreshDirectory();
  4377. }
  4378. FRefreshRemoteDirectory = false;
  4379. }
  4380. if (FRefreshLocalDirectory)
  4381. {
  4382. ReloadLocalDirectory();
  4383. FRefreshLocalDirectory = false;
  4384. }
  4385. if (WinConfiguration->RefreshRemotePanel)
  4386. {
  4387. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4388. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4389. {
  4390. RemoteDirView->ReloadDirectory();
  4391. }
  4392. }
  4393. }
  4394. }
  4395. if (FShowing || FStandaloneEditing)
  4396. {
  4397. if (FQueueStatusInvalidated)
  4398. {
  4399. UpdateQueueStatus(false);
  4400. }
  4401. RefreshQueueItems();
  4402. }
  4403. if (FShowing)
  4404. {
  4405. UpdateStatusBar();
  4406. }
  4407. FIgnoreNextDialogChar = 0;
  4408. }
  4409. //---------------------------------------------------------------------------
  4410. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4411. {
  4412. try
  4413. {
  4414. FUserActionTimer->Enabled = false;
  4415. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4416. {
  4417. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4418. {
  4419. FPendingQueueActionItem->ProcessUserAction();
  4420. }
  4421. }
  4422. }
  4423. __finally
  4424. {
  4425. FPendingQueueActionItem = NULL;
  4426. }
  4427. }
  4428. //---------------------------------------------------------------------------
  4429. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4430. {
  4431. if (WinConfiguration->MinimizeToTray)
  4432. {
  4433. UpdateTrayIcon();
  4434. FTrayIcon->Visible = true;
  4435. if (Visible)
  4436. {
  4437. ShowWindow(Handle, SW_HIDE);
  4438. }
  4439. }
  4440. }
  4441. //---------------------------------------------------------------------------
  4442. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4443. {
  4444. // WORKAROUND
  4445. // When restoring maximized window from minimization,
  4446. // rarely some controls do not align properly.
  4447. // Two instances seen (both for Commander):
  4448. // - When restoring, window is temporarily narrower (not maximized),
  4449. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4450. // Once maximized already, top dock shinks back, but the session PageControl,
  4451. // do not align up, leaving space between TopDock and PageControl.
  4452. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4453. for (int Index = 0; Index < ControlCount; Index++)
  4454. {
  4455. RealignControl(Controls[Index]);
  4456. }
  4457. if (FTrayIcon->Visible)
  4458. {
  4459. FTrayIcon->Visible = false;
  4460. if (Visible)
  4461. {
  4462. ShowWindow(Handle, SW_SHOW);
  4463. }
  4464. }
  4465. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4466. {
  4467. FNeedSession = false;
  4468. NonVisualDataModule->StartBusy();
  4469. try
  4470. {
  4471. NeedSession(true);
  4472. }
  4473. __finally
  4474. {
  4475. NonVisualDataModule->EndBusy();
  4476. }
  4477. }
  4478. }
  4479. //---------------------------------------------------------------------------
  4480. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4481. {
  4482. FTrayIcon->Hint = GetMainForm()->Caption;
  4483. }
  4484. //---------------------------------------------------------------------------
  4485. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4486. {
  4487. UpdateTrayIcon();
  4488. }
  4489. //---------------------------------------------------------------------------
  4490. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4491. {
  4492. // workaround
  4493. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4494. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4495. // But WM_ACTIVATEAPP message can be received even when
  4496. // the main window is minimized to the tray and internal editor window is focused
  4497. // (after another application was previously active)
  4498. if (::IsIconic(Handle))
  4499. {
  4500. if (!IsAppIconic())
  4501. {
  4502. SetAppIconic(true);
  4503. }
  4504. }
  4505. ::ApplicationRestore();
  4506. Application->BringToFront();
  4507. }
  4508. //---------------------------------------------------------------------------
  4509. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4510. {
  4511. RestoreApp();
  4512. }
  4513. //---------------------------------------------------------------------------
  4514. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4515. {
  4516. if (OpenInNewWindow())
  4517. {
  4518. // todo: Pass FromSite
  4519. ExecuteNewInstance(SessionUrl);
  4520. }
  4521. else
  4522. {
  4523. TTerminalManager::Instance()->NewSession(SessionUrl);
  4524. }
  4525. }
  4526. //---------------------------------------------------------------------------
  4527. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4528. {
  4529. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4530. StoredSessions->NewSession(SessionName, SessionData);
  4531. // modified only, explicit
  4532. StoredSessions->Save(false, true);
  4533. // encode session name because of slashes in hierarchical sessions
  4534. return EncodeUrlString(SessionName);
  4535. }
  4536. //---------------------------------------------------------------------------
  4537. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4538. {
  4539. // current working directories become defaults here, what is not right
  4540. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4541. return SaveHiddenDuplicateSession(SessionData.get());
  4542. }
  4543. //---------------------------------------------------------------------------
  4544. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4545. {
  4546. if (OpenInNewWindow())
  4547. {
  4548. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4549. }
  4550. else
  4551. {
  4552. // current working directories become defaults here, what is not right
  4553. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4554. TTerminalManager * Manager = TTerminalManager::Instance();
  4555. TManagedTerminal * ATerminal = Manager->NewManagedTerminal(SessionData.get());
  4556. // We definitelly want this
  4557. ATerminal->Disconnected = Terminal->Disconnected;
  4558. // Not sure about these two
  4559. ATerminal->Permanent = Terminal->Permanent;
  4560. ATerminal->DisconnectedTemporarily = Terminal->DisconnectedTemporarily; // maybe
  4561. Manager->ActiveSession = ATerminal;
  4562. }
  4563. }
  4564. //---------------------------------------------------------------------------
  4565. void __fastcall TCustomScpExplorerForm::RenameSession()
  4566. {
  4567. UnicodeString Name = Terminal->SessionData->SessionName;
  4568. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4569. {
  4570. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4571. TSessionData::ValidateName(Name);
  4572. // This is inconsistent with how color (for example) is handled.
  4573. Terminal->SessionData->Name = Name;
  4574. UpdateControls();
  4575. // Add/Remove distinguishing paths from sessions of the same name.
  4576. SessionListChanged();
  4577. }
  4578. }
  4579. //---------------------------------------------------------------------------
  4580. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4581. {
  4582. DebugAssert(Queue != NULL);
  4583. bool Result = Queue->IsEmpty;
  4584. if (!Result)
  4585. {
  4586. SetFocus();
  4587. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4588. }
  4589. return Result;
  4590. }
  4591. //---------------------------------------------------------------------------
  4592. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4593. {
  4594. return CanCloseQueue(FQueue);
  4595. }
  4596. //---------------------------------------------------------------------------
  4597. void __fastcall TCustomScpExplorerForm::CloseSession()
  4598. {
  4599. if (CanCloseQueue())
  4600. {
  4601. TTerminalManager::Instance()->FreeActiveTerminal();
  4602. }
  4603. }
  4604. //---------------------------------------------------------------------------
  4605. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4606. {
  4607. if (CanCloseQueue())
  4608. {
  4609. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4610. }
  4611. }
  4612. //---------------------------------------------------------------------------
  4613. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4614. {
  4615. DetachTerminal(Terminal);
  4616. RemoteDirView->Terminal = Terminal;
  4617. UpdateRemotePathComboBox(false);
  4618. InitStatusBar();
  4619. UpdateControls();
  4620. }
  4621. //---------------------------------------------------------------------------
  4622. void __fastcall TCustomScpExplorerForm::TerminalConnecting()
  4623. {
  4624. InitStatusBar();
  4625. }
  4626. //---------------------------------------------------------------------------
  4627. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4628. {
  4629. if (DebugAlwaysTrue(!Terminal->Active))
  4630. {
  4631. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4632. }
  4633. }
  4634. //---------------------------------------------------------------------------
  4635. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4636. {
  4637. if (OpenInNewWindow())
  4638. {
  4639. // encode session name because of slashes in hierarchical sessions
  4640. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4641. }
  4642. else
  4643. {
  4644. TTerminalManager * Manager = TTerminalManager::Instance();
  4645. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4646. Manager->ActiveSession = Terminal;
  4647. }
  4648. }
  4649. //---------------------------------------------------------------------------
  4650. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4651. {
  4652. TTerminalManager * Manager = TTerminalManager::Instance();
  4653. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4654. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4655. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4656. // FirstTerminal can be null, if some of the
  4657. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4658. {
  4659. FirstTerminal->Disconnected = true;
  4660. FirstTerminal->DisconnectedTemporarily = true;
  4661. }
  4662. Manager->ActiveSession = FirstTerminal;
  4663. }
  4664. //---------------------------------------------------------------------------
  4665. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4666. {
  4667. if (OpenInNewWindow())
  4668. {
  4669. ExecuteNewInstance(Name);
  4670. }
  4671. else
  4672. {
  4673. DoOpenFolderOrWorkspace(Name, true);
  4674. }
  4675. }
  4676. //---------------------------------------------------------------------------
  4677. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4678. bool &CanClose)
  4679. {
  4680. // See the comment in CloseApp()
  4681. if (NonVisualDataModule->Busy)
  4682. {
  4683. CanClose = false;
  4684. }
  4685. else if (Terminal != NULL)
  4686. {
  4687. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4688. {
  4689. unsigned int Result;
  4690. TMessageParams Params(mpNeverAskAgainCheck);
  4691. UnicodeString Message;
  4692. int Answers = qaOK | qaCancel;
  4693. if (TTerminalManager::Instance()->Count > 1)
  4694. {
  4695. if (!WinConfiguration->AutoSaveWorkspace)
  4696. {
  4697. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4698. }
  4699. else
  4700. {
  4701. Message = LoadStr(CLOSE_SESSIONS);
  4702. }
  4703. }
  4704. else
  4705. {
  4706. if (!WinConfiguration->AutoSaveWorkspace)
  4707. {
  4708. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4709. }
  4710. else
  4711. {
  4712. Message = LoadStr(CLOSE_SESSION);
  4713. }
  4714. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4715. }
  4716. UnicodeString Note;
  4717. if (WinConfiguration->AutoSaveWorkspace)
  4718. {
  4719. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4720. }
  4721. else
  4722. {
  4723. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4724. Answers = qaYes | qaNo | qaCancel;
  4725. }
  4726. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4727. SetFocus();
  4728. Result = MessageDialog(Message, qtConfirmation,
  4729. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4730. if (Result == qaNeverAskAgain)
  4731. {
  4732. WinConfiguration->ConfirmClosingSession = false;
  4733. }
  4734. if (Result == qaNo)
  4735. {
  4736. CanClose = SaveWorkspace(true);
  4737. // note that the workspace will be saved redundatly again from FormClose
  4738. }
  4739. else
  4740. {
  4741. CanClose =
  4742. (Result == qaOK) ||
  4743. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4744. (Result == qaNeverAskAgain);
  4745. }
  4746. }
  4747. if (CanClose)
  4748. {
  4749. CanClose = CanCloseQueue();
  4750. }
  4751. }
  4752. if (CanClose)
  4753. {
  4754. CanClose =
  4755. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4756. FEditorManager->CloseExternalFilesWithoutProcess();
  4757. if (CanClose)
  4758. {
  4759. while (CanClose && (FLocalEditors->Count > 0))
  4760. {
  4761. int PrevCount = FLocalEditors->Count;
  4762. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4763. CanClose = (FLocalEditors->Count < PrevCount);
  4764. }
  4765. if (CanClose)
  4766. {
  4767. CanClose = FEditorManager->Empty(true);
  4768. if (!CanClose)
  4769. {
  4770. SetFocus();
  4771. CanClose =
  4772. (MessageDialog(
  4773. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4774. }
  4775. }
  4776. }
  4777. }
  4778. }
  4779. //---------------------------------------------------------------------------
  4780. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4781. {
  4782. TForm * Form = dynamic_cast<TForm *>(Sender);
  4783. DebugAssert(Form != NULL);
  4784. Form->Close();
  4785. }
  4786. //---------------------------------------------------------------------------
  4787. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4788. {
  4789. TForm * Form = dynamic_cast<TForm *>(Sender);
  4790. delete Form;
  4791. }
  4792. //---------------------------------------------------------------------------
  4793. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4794. {
  4795. while (FLocalEditors->Count > 0)
  4796. {
  4797. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4798. }
  4799. }
  4800. //---------------------------------------------------------------------------
  4801. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4802. TObject *Sender)
  4803. {
  4804. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4805. try
  4806. {
  4807. SetProperties(osRemote, FileList);
  4808. }
  4809. __finally
  4810. {
  4811. delete FileList;
  4812. }
  4813. }
  4814. //---------------------------------------------------------------------------
  4815. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4816. {
  4817. if (value)
  4818. {
  4819. if (Component == fcCustomCommandsBand)
  4820. {
  4821. UpdateCustomCommandsToolbar();
  4822. }
  4823. if (Component == fcQueueFileList)
  4824. {
  4825. DebugAssert(!QueueFileListSplitter->Visible);
  4826. AdjustQueueLayout();
  4827. UpdateQueueFileList();
  4828. }
  4829. }
  4830. }
  4831. //---------------------------------------------------------------------------
  4832. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4833. {
  4834. int MinHeightLimit =
  4835. GetStaticQueuePanelComponentsHeight() +
  4836. QueueFileListSplitter->Height +
  4837. QueueFileList->Height +
  4838. GetMinQueueViewHeight();
  4839. if (QueuePanel->ClientHeight < MinHeightLimit)
  4840. {
  4841. QueuePanel->ClientHeight = MinHeightLimit;
  4842. }
  4843. }
  4844. //---------------------------------------------------------------------------
  4845. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4846. {
  4847. TControl * Control = GetComponent(Component);
  4848. DebugAssert(Control);
  4849. bool Changed = (Control->Visible != value);
  4850. if (Changed)
  4851. {
  4852. ComponentShowing(Component, value);
  4853. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4854. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4855. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4856. if (value)
  4857. {
  4858. int RemainingHeight = Control->Parent->ClientHeight;
  4859. int RemainingWidth = Control->Parent->ClientWidth;
  4860. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4861. {
  4862. TControl * ChildControl = Control->Parent->Controls[i];
  4863. if (ChildControl->Visible)
  4864. {
  4865. switch (ChildControl->Align)
  4866. {
  4867. case alTop:
  4868. case alBottom:
  4869. RemainingHeight -= ChildControl->Height;
  4870. break;
  4871. case alLeft:
  4872. case alRight:
  4873. RemainingWidth -= ChildControl->Width;
  4874. break;
  4875. }
  4876. }
  4877. }
  4878. int Reserve = ScaleByTextHeight(this, 32);
  4879. // queue in explorer, trees in commander
  4880. if (Control->Height > RemainingHeight - Reserve)
  4881. {
  4882. Control->Height = RemainingHeight / 2;
  4883. }
  4884. if (Control->Width > RemainingWidth - Reserve)
  4885. {
  4886. Control->Width = RemainingWidth / 2;
  4887. }
  4888. }
  4889. Control->Visible = value;
  4890. if (WasFocused && Visible)
  4891. {
  4892. DirView(osCurrent)->SetFocus();
  4893. }
  4894. FixControlsPlacement();
  4895. }
  4896. }
  4897. //---------------------------------------------------------------------------
  4898. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4899. {
  4900. TControl * Control = GetComponent(Component);
  4901. if (Control == NULL)
  4902. {
  4903. return false;
  4904. }
  4905. else
  4906. {
  4907. return Control->Visible;
  4908. }
  4909. }
  4910. //---------------------------------------------------------------------------
  4911. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4912. {
  4913. bool Result;
  4914. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4915. {
  4916. Result = !IsUWP();
  4917. }
  4918. else
  4919. {
  4920. Result = true;
  4921. }
  4922. return Result;
  4923. }
  4924. //---------------------------------------------------------------------------
  4925. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  4926. {
  4927. if (DirView->ItemFocused != NULL)
  4928. {
  4929. DirView->ItemFocused->MakeVisible(false);
  4930. }
  4931. }
  4932. //---------------------------------------------------------------------------
  4933. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4934. {
  4935. MakeFocusedItemVisible(RemoteDirView);
  4936. QueueSplitter->Visible = QueuePanel->Visible;
  4937. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4938. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4939. TControl * QueueControlsOrder[] =
  4940. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4941. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4942. }
  4943. //---------------------------------------------------------------------------
  4944. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4945. {
  4946. switch (Component) {
  4947. case fcStatusBar: return RemoteStatusBar;
  4948. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4949. case fcQueueView: return QueuePanel;
  4950. case fcQueueToolbar: return QueueDock;
  4951. case fcRemoteTree: return RemoteDrivePanel;
  4952. case fcSessionsTabs: return SessionsPageControl;
  4953. case fcQueueFileList: return QueueFileList;
  4954. default: return NULL;
  4955. }
  4956. }
  4957. //---------------------------------------------------------------------------
  4958. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4959. TObject *Sender, TListColumn *Column, TPoint &Point)
  4960. {
  4961. DebugAssert(NonVisualDataModule && Column && Sender);
  4962. NonVisualDataModule->ListColumn = Column;
  4963. TPopupMenu * DirViewColumnMenu;
  4964. if (Sender == DirView(osOther))
  4965. {
  4966. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4967. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4968. (Column->Index == uvName);
  4969. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4970. (Column->Index == uvSize);
  4971. }
  4972. else
  4973. {
  4974. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4975. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4976. (Column->Index == dvName);
  4977. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4978. (Column->Index == dvSize);
  4979. }
  4980. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4981. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4982. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4983. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4984. }
  4985. //---------------------------------------------------------------------------
  4986. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4987. TObject *Sender, TListItem *Item, bool &AllowExec)
  4988. {
  4989. DoDirViewExecFile(Sender, Item, AllowExec);
  4990. }
  4991. //---------------------------------------------------------------------------
  4992. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4993. TListItem * Item, bool & AllowExec)
  4994. {
  4995. DebugAssert(Sender && Item && Configuration);
  4996. DebugAssert(AllowExec);
  4997. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4998. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  4999. bool Remote = !IsSideLocalBrowser(Side);
  5000. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  5001. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  5002. // on files only (not directories)
  5003. // and only when symlinks are resolved (apply to remote panel only)
  5004. if (!ADirView->ItemIsDirectory(Item) &&
  5005. (ResolvedSymlinks || FForceExecution))
  5006. {
  5007. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  5008. !FForceExecution && ResolvedSymlinks)
  5009. {
  5010. if (WinConfiguration->DoubleClickAction == dcaCopy)
  5011. {
  5012. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  5013. UnlockWindow();
  5014. try
  5015. {
  5016. if (IsLocalBrowserMode())
  5017. {
  5018. LocalLocalCopy(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation, false, 0);
  5019. }
  5020. else
  5021. {
  5022. ExecuteFileOperation(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  5023. }
  5024. }
  5025. __finally
  5026. {
  5027. LockWindow();
  5028. }
  5029. AllowExec = false;
  5030. }
  5031. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  5032. {
  5033. if (!Remote || !WinConfiguration->DisableOpenEdit)
  5034. {
  5035. ExecuteFile(Side, efDefaultEditor);
  5036. AllowExec = false;
  5037. }
  5038. }
  5039. else
  5040. {
  5041. DebugFail();
  5042. }
  5043. }
  5044. // if we have not done anything special, fall back to default behavior
  5045. if (AllowExec)
  5046. {
  5047. if (Remote && !WinConfiguration->DisableOpenEdit)
  5048. {
  5049. ExecuteFile(osRemote, efShell);
  5050. AllowExec = false;
  5051. }
  5052. }
  5053. }
  5054. }
  5055. //---------------------------------------------------------------------------
  5056. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  5057. {
  5058. return ((Side == osRemote) || (Side == osCurrent));
  5059. }
  5060. //---------------------------------------------------------------------------
  5061. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5062. {
  5063. DebugFail();
  5064. }
  5065. //---------------------------------------------------------------------------
  5066. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5067. {
  5068. DebugFail();
  5069. }
  5070. //---------------------------------------------------------------------------
  5071. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5072. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5073. {
  5074. TSynchronizeParamType Params;
  5075. Params.LocalDirectory = LocalDirectory;
  5076. Params.RemoteDirectory = RemoteDirectory;
  5077. int UnusedParams =
  5078. (GUIConfiguration->SynchronizeParams &
  5079. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5080. TTerminal::spCaseSensitive));
  5081. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5082. Params.Options = GUIConfiguration->SynchronizeOptions;
  5083. bool SaveSettings = false;
  5084. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5085. &DoSynchronizeTooManyDirectories);
  5086. DebugAssert(FSynchronizeController == NULL);
  5087. FSynchronizeController = &Controller;
  5088. bool Result;
  5089. try
  5090. {
  5091. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5092. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5093. int Options =
  5094. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5095. DebugAssert(FOnFeedSynchronizeError == NULL);
  5096. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5097. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5098. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5099. if (Result)
  5100. {
  5101. if (SaveSettings)
  5102. {
  5103. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5104. GUIConfiguration->SynchronizeOptions = Params.Options;
  5105. }
  5106. else
  5107. {
  5108. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5109. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5110. FLAGSET(Params.Options, soSynchronize))
  5111. {
  5112. GUIConfiguration->SynchronizeOptions =
  5113. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5114. soSynchronize;
  5115. }
  5116. }
  5117. LocalDirectory = Params.LocalDirectory;
  5118. RemoteDirectory = Params.RemoteDirectory;
  5119. }
  5120. }
  5121. __finally
  5122. {
  5123. FSynchronizeController = NULL;
  5124. DebugAssert(FOnFeedSynchronizeError == NULL);
  5125. FOnFeedSynchronizeError = NULL;
  5126. }
  5127. return Result;
  5128. }
  5129. //---------------------------------------------------------------------------
  5130. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5131. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5132. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5133. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5134. TSynchronizeOptions * Options, bool Full)
  5135. {
  5136. // Keep-up-to-date mode
  5137. if (Terminal->Status == ssOpened)
  5138. {
  5139. try
  5140. {
  5141. int PParams = Params.Params;
  5142. if (!Full)
  5143. {
  5144. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5145. if (FLAGSET(Params.Options, soRecurse))
  5146. {
  5147. PParams |= TTerminal::spSubDirs;
  5148. }
  5149. }
  5150. else
  5151. {
  5152. // if keepuptodate is non-recursive,
  5153. // full sync before has to be non-recursive as well
  5154. if (FLAGCLEAR(Params.Options, soRecurse))
  5155. {
  5156. PParams |= TTerminal::spNoRecurse;
  5157. }
  5158. }
  5159. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5160. PParams, Checklist, Options);
  5161. }
  5162. catch (Exception & E)
  5163. {
  5164. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5165. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5166. {
  5167. // noop, already logged in MoreMessageDialog
  5168. }
  5169. else
  5170. {
  5171. ShowExtendedExceptionEx(Terminal, &E);
  5172. throw;
  5173. }
  5174. }
  5175. }
  5176. }
  5177. //---------------------------------------------------------------------------
  5178. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5179. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5180. const UnicodeString ErrorStr)
  5181. {
  5182. if (!Directory.IsEmpty())
  5183. {
  5184. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5185. }
  5186. else
  5187. {
  5188. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5189. }
  5190. }
  5191. //---------------------------------------------------------------------------
  5192. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5193. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5194. {
  5195. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5196. {
  5197. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5198. }
  5199. else
  5200. {
  5201. TMessageParams Params(mpNeverAskAgainCheck);
  5202. unsigned int Result = MessageDialog(
  5203. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5204. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5205. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5206. {
  5207. MaxDirectories *= 2;
  5208. if (Result == qaNeverAskAgain)
  5209. {
  5210. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5211. }
  5212. }
  5213. else
  5214. {
  5215. Abort();
  5216. }
  5217. }
  5218. }
  5219. //---------------------------------------------------------------------------
  5220. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5221. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5222. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5223. TSynchronizeOptions * Options)
  5224. {
  5225. // Keep-up-to-date mode
  5226. DebugAssert(!FAutoOperation);
  5227. void * BatchStorage;
  5228. BatchStart(BatchStorage);
  5229. FAutoOperation = true;
  5230. bool AnyOperation = false;
  5231. TDateTime StartTime = Now();
  5232. TSynchronizeChecklist * AChecklist = NULL;
  5233. try
  5234. {
  5235. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5236. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5237. {
  5238. FSynchronizeProgressForm->Start();
  5239. }
  5240. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5241. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5242. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5243. Options);
  5244. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5245. SAFE_DESTROY(FSynchronizeProgressForm);
  5246. AnyOperation = (AChecklist->CheckedCount > 0);
  5247. if (AnyOperation)
  5248. {
  5249. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5250. CreateProgressForm(&SynchronizeProgress);
  5251. try
  5252. {
  5253. Terminal->SynchronizeApply(
  5254. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5255. SynchronizeProcessedItem, NULL, NULL, NULL);
  5256. }
  5257. __finally
  5258. {
  5259. DestroyProgressForm();
  5260. }
  5261. }
  5262. }
  5263. __finally
  5264. {
  5265. if (Checklist == NULL)
  5266. {
  5267. delete AChecklist;
  5268. }
  5269. else
  5270. {
  5271. *Checklist = AChecklist;
  5272. }
  5273. FAutoOperation = false;
  5274. SAFE_DESTROY(FSynchronizeProgressForm);
  5275. BatchEnd(BatchStorage);
  5276. ReloadLocalDirectory();
  5277. if (AnyOperation)
  5278. {
  5279. OperationComplete(StartTime);
  5280. }
  5281. }
  5282. }
  5283. //---------------------------------------------------------------------------
  5284. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5285. {
  5286. // can be called from command line
  5287. return Visible &&
  5288. ((DirView(osRemote)->SelCount > 0) ||
  5289. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5290. }
  5291. //---------------------------------------------------------------------------
  5292. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5293. {
  5294. LogSynchronizeEvent(Terminal, Message);
  5295. }
  5296. //---------------------------------------------------------------------------
  5297. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5298. int Params, TSynchronizeOptions & Options)
  5299. {
  5300. DebugAssert(!IsLocalBrowserMode());
  5301. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5302. {
  5303. Options.Filter = new TStringList();
  5304. Options.Filter->CaseSensitive = false;
  5305. Options.Filter->Duplicates = Types::dupAccept;
  5306. if (DirView(osRemote)->SelCount > 0)
  5307. {
  5308. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5309. }
  5310. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5311. {
  5312. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5313. }
  5314. Options.Filter->Sort();
  5315. }
  5316. }
  5317. //---------------------------------------------------------------------------
  5318. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5319. {
  5320. TCopyParamType Defaults;
  5321. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5322. ConfigStorage->AccessMode = smRead;
  5323. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5324. {
  5325. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5326. }
  5327. ConfigStorage.reset(NULL);
  5328. std::unique_ptr<TStringList> Options(new TStringList());
  5329. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5330. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5331. UnicodeString Result;
  5332. if (Options->Count > 0)
  5333. {
  5334. Result =
  5335. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5336. }
  5337. return Result;
  5338. }
  5339. //---------------------------------------------------------------------------
  5340. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5341. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5342. {
  5343. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5344. UnicodeString AdditionalParams =
  5345. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5346. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5347. SerializeCopyParamForCommandLine(CopyParams),
  5348. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5349. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5350. ExecuteNewInstance(SessionName, AdditionalParams);
  5351. }
  5352. //---------------------------------------------------------------------------
  5353. struct TSynchronizeParams
  5354. {
  5355. UnicodeString LocalDirectory;
  5356. UnicodeString RemoteDirectory;
  5357. TSynchronizeMode Mode;
  5358. TSynchronizeChecklist * Checklist;
  5359. int Params;
  5360. TCopyParamType * CopyParam;
  5361. TDateTime CollectElapsed;
  5362. TDateTime * StartTime;
  5363. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5364. };
  5365. //---------------------------------------------------------------------------
  5366. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5367. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5368. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5369. {
  5370. DebugAssert(!FAutoOperation);
  5371. void * BatchStorage;
  5372. BatchStart(BatchStorage);
  5373. FAutoOperation = true;
  5374. TFileOperationStatistics Statistics;
  5375. TDateTime Start = Now();
  5376. try
  5377. {
  5378. Params.OnProcessedItem = OnProcessedItem;
  5379. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5380. CreateProgressForm(&SynchronizeProgress);
  5381. Terminal->SynchronizeApply(
  5382. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5383. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5384. &Statistics);
  5385. }
  5386. __finally
  5387. {
  5388. Params.OnProcessedItem = NULL;
  5389. FAutoOperation = false;
  5390. DestroyProgressForm();
  5391. BatchEnd(BatchStorage);
  5392. ReloadLocalDirectory();
  5393. }
  5394. if (WinConfiguration->SynchronizeSummary)
  5395. {
  5396. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5397. // The statistics should be 0 anyway in this case
  5398. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5399. {
  5400. Message += L"\n";
  5401. if (Statistics.FilesUploaded > 0)
  5402. {
  5403. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5404. }
  5405. if (Statistics.FilesDownloaded > 0)
  5406. {
  5407. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5408. }
  5409. if (Statistics.FilesDeletedLocal > 0)
  5410. {
  5411. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5412. }
  5413. if (Statistics.FilesDeletedRemote > 0)
  5414. {
  5415. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5416. }
  5417. }
  5418. TDateTime Elapsed = (Now() - Start);
  5419. Message +=
  5420. L"\n" +
  5421. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5422. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5423. TMessageParams Params(mpNeverAskAgainCheck);
  5424. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5425. if (Result == qaNeverAskAgain)
  5426. {
  5427. WinConfiguration->SynchronizeSummary = false;
  5428. }
  5429. }
  5430. }
  5431. //---------------------------------------------------------------------------
  5432. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5433. {
  5434. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5435. {
  5436. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5437. }
  5438. // Not set in keep-up-to-date mode - Synchronize() method
  5439. if (Token != NULL)
  5440. {
  5441. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5442. if (Params.OnProcessedItem != NULL)
  5443. {
  5444. Params.OnProcessedItem(NULL, ChecklistItem);
  5445. }
  5446. }
  5447. }
  5448. //---------------------------------------------------------------------------
  5449. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5450. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5451. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5452. {
  5453. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5454. *Params.StartTime = Now();
  5455. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5456. }
  5457. //---------------------------------------------------------------------------
  5458. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5459. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5460. {
  5461. // terminal can be already closed (e.g. dropped connection)
  5462. if (Terminal != NULL)
  5463. {
  5464. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5465. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5466. }
  5467. }
  5468. //---------------------------------------------------------------------------
  5469. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5470. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5471. {
  5472. DebugAssert(!IsLocalBrowserMode());
  5473. TAutoBatch AutoBatch(this);
  5474. TAutoFlag AutoOperationFlag(FAutoOperation);
  5475. if (Side == osRemote)
  5476. {
  5477. std::unique_ptr<TStrings> FileList(new TStringList());
  5478. FileList->AddObject(FileName, RemoteFile);
  5479. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5480. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5481. RemoteDirView->SaveSelection();
  5482. RemoteDirView->SaveSelectedNames();
  5483. try
  5484. {
  5485. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5486. }
  5487. catch(...)
  5488. {
  5489. RemoteDirView->DiscardSavedSelection();
  5490. throw;
  5491. }
  5492. RemoteDirView->RestoreSelection();
  5493. }
  5494. else if (DebugAlwaysTrue(Side == osLocal))
  5495. {
  5496. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5497. {
  5498. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5499. }
  5500. UnicodeString Directory = ExtractFileDir(FileName);
  5501. ReloadLocalDirectory(Directory);
  5502. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5503. if (!SamePaths(Directory, NewDirectory))
  5504. {
  5505. ReloadLocalDirectory(NewDirectory);
  5506. }
  5507. }
  5508. }
  5509. //---------------------------------------------------------------------------
  5510. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5511. {
  5512. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5513. if (Side == osLocal)
  5514. {
  5515. if (Action == TSynchronizeChecklist::saDownloadNew)
  5516. {
  5517. OpenFolderInExplorer(LocalPath);
  5518. }
  5519. else
  5520. {
  5521. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5522. }
  5523. }
  5524. else if (DebugAlwaysTrue(Side == osRemote))
  5525. {
  5526. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5527. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5528. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5529. if (!LocalPath.IsEmpty())
  5530. {
  5531. SessionData->LocalDirectory = LocalPath;
  5532. }
  5533. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5534. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5535. }
  5536. }
  5537. //---------------------------------------------------------------------------
  5538. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5539. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5540. const TCopyParamType * CopyParams)
  5541. {
  5542. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5543. UnicodeString AdditionalParams =
  5544. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5545. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5546. SerializeCopyParamForCommandLine(CopyParams),
  5547. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5548. LocalDirectory, RemoteDirectory, Mode, Params));
  5549. ExecuteNewInstance(SessionName, AdditionalParams);
  5550. }
  5551. //---------------------------------------------------------------------------
  5552. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5553. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5554. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5555. {
  5556. int Result;
  5557. bool SaveSettings = false;
  5558. int Options =
  5559. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5560. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5561. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5562. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5563. bool Continue =
  5564. (UseDefaults == 0) ||
  5565. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5566. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5567. if (Continue)
  5568. {
  5569. Configuration->Usage->Inc(L"Synchronizations");
  5570. UpdateCopyParamCounters(CopyParam);
  5571. TSynchronizeOptions SynchronizeOptions;
  5572. GetSynchronizeOptions(Params, SynchronizeOptions);
  5573. if (SaveSettings)
  5574. {
  5575. GUIConfiguration->SynchronizeParams = Params;
  5576. }
  5577. else
  5578. {
  5579. SaveMode = false;
  5580. }
  5581. TDateTime StartTime = Now();
  5582. TSynchronizeChecklist * Checklist = NULL;
  5583. try
  5584. {
  5585. DebugAssert(!FAutoOperation);
  5586. FAutoOperation = true;
  5587. try
  5588. {
  5589. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5590. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5591. int Files = -1;
  5592. if (DataList->Count >= 1)
  5593. {
  5594. Files = StrToIntDef(DataList->Strings[0], Files);
  5595. }
  5596. else
  5597. {
  5598. DataList->Add(UnicodeString());
  5599. }
  5600. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5601. FSynchronizeProgressForm->Start();
  5602. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5603. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5604. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5605. &SynchronizeOptions);
  5606. if (Terminal->SessionData->CacheDirectories)
  5607. {
  5608. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5609. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5610. }
  5611. }
  5612. __finally
  5613. {
  5614. FAutoOperation = false;
  5615. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5616. SAFE_DESTROY(FSynchronizeProgressForm);
  5617. }
  5618. TSynchronizeParams SynchronizeParams;
  5619. SynchronizeParams.LocalDirectory = LocalDirectory;
  5620. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5621. SynchronizeParams.Mode = Mode;
  5622. SynchronizeParams.CopyParam = &CopyParam;
  5623. SynchronizeParams.Params = Params;
  5624. SynchronizeParams.Checklist = Checklist;
  5625. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5626. SynchronizeParams.StartTime = &StartTime;
  5627. SynchronizeParams.OnProcessedItem = NULL;
  5628. Result = Checklist->Count;
  5629. if (Checklist->Count > 0)
  5630. {
  5631. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5632. {
  5633. if (!DoSynchronizeChecklistDialog(
  5634. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5635. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5636. {
  5637. Result = -1;
  5638. }
  5639. }
  5640. else
  5641. {
  5642. FullSynchronize(SynchronizeParams, NULL, NULL);
  5643. }
  5644. }
  5645. else
  5646. {
  5647. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5648. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5649. }
  5650. }
  5651. __finally
  5652. {
  5653. delete Checklist;
  5654. }
  5655. OperationComplete(StartTime);
  5656. }
  5657. else
  5658. {
  5659. Result = -1;
  5660. }
  5661. return Result;
  5662. }
  5663. //---------------------------------------------------------------------------
  5664. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5665. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5666. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5667. {
  5668. if (Collect)
  5669. {
  5670. DebugAssert(FSynchronizeProgressForm != NULL);
  5671. if (!FSynchronizeProgressForm->Started)
  5672. {
  5673. FSynchronizeProgressForm->Start();
  5674. }
  5675. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5676. SetTaskbarListProgressValue(CompareProgress);
  5677. }
  5678. else
  5679. {
  5680. DebugAssert(FSynchronizeProgressForm == NULL);
  5681. DebugAssert(FProgressForm != NULL);
  5682. }
  5683. }
  5684. //---------------------------------------------------------------------------
  5685. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5686. {
  5687. UnicodeString FullFileName = AbsolutePath(Terminal->CurrentDirectory, FileName);
  5688. TRemoteFile * File = NULL;
  5689. Terminal->ReadFile(FullFileName, File);
  5690. if (File != NULL)
  5691. {
  5692. std::unique_ptr<TRemoteFile> FileOwner(File);
  5693. TAutoFlag Flag(FStandaloneEditing);
  5694. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5695. Application->ShowMainForm = false;
  5696. Application->Run();
  5697. }
  5698. }
  5699. //---------------------------------------------------------------------------
  5700. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  5701. {
  5702. DebugFail();
  5703. }
  5704. //---------------------------------------------------------------------------
  5705. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5706. {
  5707. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5708. SessionData->Assign(Terminal->SessionData);
  5709. UpdateSessionData(SessionData.get());
  5710. Terminal->UpdateSessionCredentials(SessionData.get());
  5711. if (!Terminal->SessionData->HasSessionName())
  5712. {
  5713. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5714. // once IsWorkspace is cleared
  5715. SessionData->Name = UnicodeString();
  5716. SessionData->IsWorkspace = false;
  5717. }
  5718. return SessionData.release();
  5719. }
  5720. //---------------------------------------------------------------------------
  5721. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5722. {
  5723. TSessionData * SessionData = CloneCurrentSessionData();
  5724. try
  5725. {
  5726. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5727. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5728. }
  5729. __finally
  5730. {
  5731. delete SessionData;
  5732. }
  5733. }
  5734. //---------------------------------------------------------------------------
  5735. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5736. {
  5737. TTerminalManager * Manager = TTerminalManager::Instance();
  5738. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5739. if (DebugAlwaysTrue(Terminal != NULL))
  5740. {
  5741. // Update (Managed)Terminal->StateData
  5742. UpdateTerminal(Terminal);
  5743. }
  5744. Manager->SaveWorkspace(DataList.get());
  5745. return DataList.release();
  5746. }
  5747. //---------------------------------------------------------------------------
  5748. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5749. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5750. {
  5751. WinConfiguration->LastWorkspace = Name;
  5752. if (!SavePasswords)
  5753. {
  5754. for (int Index = 0; Index < DataList->Count; Index++)
  5755. {
  5756. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5757. if (SessionData->Link.IsEmpty())
  5758. {
  5759. SessionData->ClearSessionPasswords();
  5760. }
  5761. }
  5762. }
  5763. StoredSessions->NewWorkspace(Name, DataList);
  5764. // modified only
  5765. StoredSessions->Save(false, Explicit);
  5766. }
  5767. //---------------------------------------------------------------------------
  5768. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5769. {
  5770. return
  5771. DefaultStr(WinConfiguration->LastWorkspace,
  5772. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5773. }
  5774. //---------------------------------------------------------------------------
  5775. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5776. {
  5777. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5778. bool AnyNonStoredSessionWithPassword = false;
  5779. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5780. bool AllNonStoredSessionsAnonymous = true;
  5781. TTerminalManager * Manager = TTerminalManager::Instance();
  5782. for (int Index = 0; Index < DataList->Count; Index++)
  5783. {
  5784. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5785. if (SessionData->Link.IsEmpty())
  5786. {
  5787. if (SessionData->HasAnySessionPassword())
  5788. {
  5789. AnyNonStoredSessionWithPassword = true;
  5790. if (!Manager->Sessions[Index]->SessionData->IsWorkspace)
  5791. {
  5792. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5793. }
  5794. }
  5795. if (!SameText(SessionData->UserName, AnonymousUserName))
  5796. {
  5797. AllNonStoredSessionsAnonymous = false;
  5798. }
  5799. }
  5800. }
  5801. bool SavePasswords;
  5802. bool * PSavePasswords;
  5803. bool NotRecommendedSavingPasswords =
  5804. !CustomWinConfiguration->UseMasterPassword &&
  5805. !AllNonStoredSessionsAnonymous;
  5806. if (Configuration->DisablePasswordStoring ||
  5807. !AnyNonStoredSessionWithPassword)
  5808. {
  5809. PSavePasswords = NULL;
  5810. SavePasswords = false;
  5811. }
  5812. else
  5813. {
  5814. PSavePasswords = &SavePasswords;
  5815. SavePasswords =
  5816. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5817. !NotRecommendedSavingPasswords;
  5818. }
  5819. UnicodeString Name = WorkspaceName();
  5820. bool CreateShortcut = false;
  5821. bool Result =
  5822. DoSaveWorkspaceDialog(
  5823. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5824. EnableAutoSave);
  5825. if (Result)
  5826. {
  5827. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5828. if (CreateShortcut)
  5829. {
  5830. TOperationVisualizer Visualizer;
  5831. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5832. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5833. }
  5834. if (EnableAutoSave)
  5835. {
  5836. WinConfiguration->AutoSaveWorkspace = true;
  5837. WinConfiguration->AutoWorkspace = Name;
  5838. if (PSavePasswords != NULL)
  5839. {
  5840. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5841. }
  5842. }
  5843. }
  5844. return Result;
  5845. }
  5846. //---------------------------------------------------------------------------
  5847. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5848. {
  5849. DebugAssert(!IsLocalBrowserMode());
  5850. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5851. if (WinConfiguration->PreservePanelState)
  5852. {
  5853. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5854. }
  5855. UpdateSessionData(Terminal->StateData);
  5856. }
  5857. //---------------------------------------------------------------------------
  5858. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5859. {
  5860. // Keep in sync with TSessionData::CopyStateData
  5861. DebugAssert(!IsLocalBrowserMode());
  5862. DebugAssert(Data != NULL);
  5863. // This is inconsistent with how color (for example) is handled.
  5864. Data->Name = Terminal->SessionData->Name;
  5865. // cannot use RemoteDirView->Path, because it is empty if connection
  5866. // was already closed
  5867. // also only peek, we may not be connected at all atm
  5868. // so make sure we do not try retrieving current directory from the server
  5869. // (particularly with FTP)
  5870. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5871. if (!ACurrentDirectory.IsEmpty())
  5872. {
  5873. Data->RemoteDirectory = ACurrentDirectory;
  5874. }
  5875. Data->Color = SessionColor;
  5876. }
  5877. //---------------------------------------------------------------------------
  5878. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5879. {
  5880. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5881. DebugAssert(Toolbar != NULL);
  5882. for (int i = 0; i < Toolbar->Items->Count; i++)
  5883. {
  5884. TTBXCustomDropDownItem * DropDownItem;
  5885. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5886. if (DropDownItem != NULL)
  5887. {
  5888. ToolbarItemResize(DropDownItem,
  5889. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5890. Toolbar->NonClientWidth);
  5891. break;
  5892. }
  5893. }
  5894. }
  5895. //---------------------------------------------------------------------------
  5896. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5897. {
  5898. Item->EditWidth = Width;
  5899. }
  5900. //---------------------------------------------------------------------------
  5901. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5902. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5903. {
  5904. for (int i = 0; i < Toolbar->Items->Count; i++)
  5905. {
  5906. TTBXCustomDropDownItem * DropDownItem;
  5907. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5908. if (DropDownItem != NULL)
  5909. {
  5910. ASize.x -= DropDownItem->EditWidth;
  5911. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5912. }
  5913. }
  5914. }
  5915. //---------------------------------------------------------------------------
  5916. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5917. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5918. {
  5919. if (WinConfiguration->DDWarnLackOfTempSpace)
  5920. {
  5921. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5922. if (!ADrive.IsEmpty())
  5923. {
  5924. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5925. DebugAssert(RequiredSpace >= 0);
  5926. __int64 RequiredWithReserve;
  5927. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5928. if (FreeSpace < RequiredWithReserve)
  5929. {
  5930. unsigned int Result;
  5931. TMessageParams Params(mpNeverAskAgainCheck);
  5932. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5933. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5934. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5935. if (Result == qaNeverAskAgain)
  5936. {
  5937. WinConfiguration->DDWarnLackOfTempSpace = false;
  5938. }
  5939. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5940. }
  5941. }
  5942. }
  5943. }
  5944. //---------------------------------------------------------------------------
  5945. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5946. {
  5947. DoOpenDirectoryDialog(odAddBookmark, Side);
  5948. }
  5949. //---------------------------------------------------------------------------
  5950. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5951. {
  5952. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5953. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5954. try
  5955. {
  5956. TCustomDirView * DView = DirView(Side);
  5957. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5958. {
  5959. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5960. }
  5961. }
  5962. catch (...)
  5963. {
  5964. delete VisitedDirectories;
  5965. throw;
  5966. }
  5967. return VisitedDirectories;
  5968. }
  5969. //---------------------------------------------------------------------------
  5970. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5971. TOpenDirectoryMode Mode, TOperationSide Side)
  5972. {
  5973. bool Continue = true;
  5974. if (Mode == odAddBookmark)
  5975. {
  5976. TMessageParams Params(mpNeverAskAgainCheck);
  5977. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5978. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5979. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5980. unsigned int Answer =
  5981. MessageDialog(Message,
  5982. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5983. if (Answer == qaNeverAskAgain)
  5984. {
  5985. Continue = true;
  5986. WinConfiguration->UseSharedBookmarks = true;
  5987. }
  5988. else if (Answer == qaOK)
  5989. {
  5990. Continue = true;
  5991. WinConfiguration->UseSharedBookmarks = false;
  5992. }
  5993. else
  5994. {
  5995. Continue = false;
  5996. }
  5997. }
  5998. if (Continue)
  5999. {
  6000. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  6001. try
  6002. {
  6003. UnicodeString Name = DirView(Side)->PathName;
  6004. bool Repeat;
  6005. do
  6006. {
  6007. Repeat = false;
  6008. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  6009. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  6010. // do not allow switching to location profiles,
  6011. // if we are not connected
  6012. HasDirView[osLocal] && (Terminal != NULL)))
  6013. {
  6014. TWindowLock Lock(this);
  6015. if (!TryOpenDirectory(Side, Name))
  6016. {
  6017. Repeat = true;
  6018. Mode = odBrowse;
  6019. }
  6020. }
  6021. }
  6022. while (Repeat);
  6023. }
  6024. __finally
  6025. {
  6026. delete VisitedDirectories;
  6027. }
  6028. }
  6029. }
  6030. //---------------------------------------------------------------------------
  6031. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  6032. {
  6033. DebugAssert(!Terminal->CommandSessionOpened);
  6034. return TTerminalManager::Instance()->ConnectTerminal(Terminal->CommandSession);
  6035. }
  6036. //---------------------------------------------------------------------------
  6037. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  6038. {
  6039. bool Result = Terminal->IsCapable[Capability] ||
  6040. Terminal->CommandSessionOpened;
  6041. if (!Result)
  6042. {
  6043. DebugAssert(Terminal->IsCapable[fcSecondaryShell]);
  6044. if (!GUIConfiguration->ConfirmCommandSession)
  6045. {
  6046. Result = true;
  6047. }
  6048. else
  6049. {
  6050. TMessageParams Params(mpNeverAskAgainCheck);
  6051. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6052. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6053. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6054. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6055. if (Answer == qaNeverAskAgain)
  6056. {
  6057. GUIConfiguration->ConfirmCommandSession = false;
  6058. Result = true;
  6059. }
  6060. else if (Answer == qaOK)
  6061. {
  6062. Result = true;
  6063. }
  6064. }
  6065. if (Result)
  6066. {
  6067. Result = CommandSessionFallback();
  6068. }
  6069. }
  6070. return Result;
  6071. }
  6072. //---------------------------------------------------------------------------
  6073. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6074. {
  6075. if (EnsureCommandSessionFallback(fcAnyCommand))
  6076. {
  6077. DoConsoleDialog(Terminal, Command);
  6078. }
  6079. }
  6080. //---------------------------------------------------------------------------
  6081. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6082. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6083. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6084. {
  6085. if (!IsSideLocalBrowser(osRemote) &&
  6086. IsFileControl(DropSourceControl, osRemote) &&
  6087. (FDDExtMapFile != NULL))
  6088. {
  6089. Accept = true;
  6090. }
  6091. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6092. DebugAssert(FDDTargetControl != NULL);
  6093. }
  6094. //---------------------------------------------------------------------------
  6095. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6096. _di_IDataObject DataObj, int KeyState,
  6097. const TPoint & Point, int & Effect, bool & Accept)
  6098. {
  6099. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6100. }
  6101. //---------------------------------------------------------------------------
  6102. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6103. _di_IDataObject DataObj, int KeyState,
  6104. const TPoint & Point, int & Effect, bool & Accept)
  6105. {
  6106. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6107. }
  6108. //---------------------------------------------------------------------------
  6109. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6110. TObject * Sender)
  6111. {
  6112. DebugUsedParam(Sender);
  6113. DebugAssert(FDDTargetControl == Sender);
  6114. FDDTargetControl = NULL;
  6115. }
  6116. //---------------------------------------------------------------------------
  6117. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6118. {
  6119. FileControlDDDragLeave(SessionsPageControl);
  6120. }
  6121. //---------------------------------------------------------------------------
  6122. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6123. {
  6124. FileControlDDDragLeave(QueueView3);
  6125. }
  6126. //---------------------------------------------------------------------------
  6127. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6128. {
  6129. DebugAssert(!IsSideLocalBrowser(Side));
  6130. DebugUsedParam(Side);
  6131. bool Edit = false;
  6132. TRemoteFile * File = NULL;
  6133. UnicodeString FileName;
  6134. UnicodeString PointTo;
  6135. bool SymbolicLink = true;
  6136. if (RemoteDirView->ItemFocused)
  6137. {
  6138. DebugAssert(RemoteDirView->ItemFocused->Data);
  6139. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6140. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6141. if (Edit)
  6142. {
  6143. FileName = File->FileName;
  6144. PointTo = File->LinkTo;
  6145. }
  6146. else
  6147. {
  6148. PointTo = File->FileName;
  6149. }
  6150. }
  6151. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6152. Terminal->IsCapable[fcHardLink]))
  6153. {
  6154. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6155. if (Edit)
  6156. {
  6157. DebugAssert(File->FileName == FileName);
  6158. int Params = dfNoRecursive;
  6159. Terminal->ExceptionOnFail = true;
  6160. try
  6161. {
  6162. Terminal->DeleteFile(L"", File, &Params);
  6163. }
  6164. __finally
  6165. {
  6166. Terminal->ExceptionOnFail = false;
  6167. }
  6168. }
  6169. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6170. }
  6171. }
  6172. //---------------------------------------------------------------------------
  6173. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6174. {
  6175. return
  6176. (IsSideLocalBrowser(Side) ||
  6177. (HasActiveTerminal() &&
  6178. Terminal->ResolvingSymlinks &&
  6179. Terminal->IsCapable[fcSymbolicLink]));
  6180. }
  6181. //---------------------------------------------------------------------------
  6182. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6183. {
  6184. return
  6185. !IsSideLocalBrowser(FCurrentSide) &&
  6186. (RemoteDirView->ItemFocused != NULL) &&
  6187. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6188. Terminal->SessionData->ResolveSymlinks;
  6189. }
  6190. //---------------------------------------------------------------------------
  6191. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6192. {
  6193. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6194. FForceExecution = true;
  6195. try
  6196. {
  6197. DirView(osCurrent)->ExecuteCurrentFile();
  6198. }
  6199. __finally
  6200. {
  6201. FForceExecution = false;
  6202. }
  6203. }
  6204. //---------------------------------------------------------------------------
  6205. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6206. {
  6207. TEditorData ExternalEditor;
  6208. ExternalEditor.Editor = edExternal;
  6209. bool Remember = false;
  6210. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6211. {
  6212. if (Remember)
  6213. {
  6214. TEditorList * EditorList = new TEditorList;
  6215. try
  6216. {
  6217. *EditorList = *WinConfiguration->EditorList;
  6218. bool Found = false;
  6219. int i = 0;
  6220. while (!Found && (i < EditorList->Count))
  6221. {
  6222. const TEditorPreferences * Editor = EditorList->Editors[i];
  6223. if ((Editor->Data->Editor == edExternal) &&
  6224. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6225. {
  6226. Found = true;
  6227. }
  6228. i++;
  6229. }
  6230. if (!Found)
  6231. {
  6232. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6233. WinConfiguration->EditorList = EditorList;
  6234. }
  6235. }
  6236. __finally
  6237. {
  6238. delete EditorList;
  6239. }
  6240. }
  6241. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6242. }
  6243. }
  6244. //---------------------------------------------------------------------------
  6245. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6246. {
  6247. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6248. if (FFileFindTerminal == ATerminal)
  6249. {
  6250. FFileFindTerminal = NULL;
  6251. HideFileFindDialog();
  6252. }
  6253. if (FClipboardTerminal == ATerminal)
  6254. {
  6255. ClipboardClear(); // implies ClipboardStop
  6256. }
  6257. }
  6258. //---------------------------------------------------------------------------
  6259. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6260. {
  6261. DetachTerminal(Sender);
  6262. }
  6263. //---------------------------------------------------------------------------
  6264. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6265. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6266. {
  6267. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6268. DebugAssert(Terminal != NULL);
  6269. if (Data->Terminal == Terminal)
  6270. {
  6271. Data->Terminal = NULL;
  6272. }
  6273. }
  6274. //---------------------------------------------------------------------------
  6275. void __fastcall TCustomScpExplorerForm::LastTerminalClosed()
  6276. {
  6277. UpdateControls();
  6278. SessionColor = TColor(0);
  6279. UpdateRemotePathComboBox(false);
  6280. NeedSession(false);
  6281. }
  6282. //---------------------------------------------------------------------------
  6283. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6284. {
  6285. try
  6286. {
  6287. // Cache, as the login dialog can change its value.
  6288. // See also DoShow. Also see TTerminalManager::NewSession.
  6289. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6290. try
  6291. {
  6292. if (ShowLogin)
  6293. {
  6294. bool ReloadSessions = !Startup;
  6295. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this);
  6296. }
  6297. }
  6298. __finally
  6299. {
  6300. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6301. // (so there was no chance for the user to open any session yet)
  6302. if ((ShowLogin || !Startup) &&
  6303. !WinConfiguration->KeepOpenWhenNoSession &&
  6304. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6305. {
  6306. TerminateApplication();
  6307. }
  6308. }
  6309. }
  6310. catch (EAbort &)
  6311. {
  6312. // swallow
  6313. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6314. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6315. }
  6316. }
  6317. //---------------------------------------------------------------------------
  6318. void __fastcall TCustomScpExplorerForm::SessionListChanged()
  6319. {
  6320. TStrings * SessionList = TTerminalManager::Instance()->SessionList;
  6321. int ActiveSessionIndex = TTerminalManager::Instance()->ActiveSessionIndex;
  6322. Configuration->Usage->SetMax(L"MaxOpenedSessions", SessionList->Count);
  6323. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6324. try
  6325. {
  6326. while ((SessionsPageControl->PageCount > SessionList->Count + 1) ||
  6327. // Clear the design time unthemed tab
  6328. ((SessionsPageControl->PageCount > 0) &&
  6329. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6330. {
  6331. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6332. }
  6333. for (int Index = 0; Index <= SessionList->Count; Index++)
  6334. {
  6335. TThemeTabSheet * TabSheet;
  6336. if (Index >= SessionsPageControl->PageCount)
  6337. {
  6338. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6339. TabSheet->PageControl = SessionsPageControl;
  6340. }
  6341. else
  6342. {
  6343. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6344. }
  6345. bool IsSessionTab = (Index < SessionList->Count);
  6346. if (IsSessionTab)
  6347. {
  6348. TTerminal * Terminal = dynamic_cast<TTerminal *>(SessionList->Objects[Index]);
  6349. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6350. UpdateSessionTab(TabSheet);
  6351. }
  6352. else
  6353. {
  6354. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6355. TabSheet->Tag = 0; // not really needed
  6356. TabSheet->Shadowed = false;
  6357. // 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)
  6358. UpdateNewSessionTab();
  6359. }
  6360. TabSheet->ShowCloseButton = IsSessionTab;
  6361. }
  6362. }
  6363. __finally
  6364. {
  6365. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6366. }
  6367. SessionsPageControl->ActivePageIndex = ActiveSessionIndex;
  6368. }
  6369. //---------------------------------------------------------------------------
  6370. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6371. {
  6372. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6373. DebugAssert(TabSheet->ImageIndex == 0);
  6374. TabSheet->Caption =
  6375. WinConfiguration->SelectiveToolbarText ?
  6376. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6377. UnicodeString();
  6378. }
  6379. //---------------------------------------------------------------------------
  6380. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabSession(TTabSheet * TabSheet)
  6381. {
  6382. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6383. }
  6384. //---------------------------------------------------------------------------
  6385. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6386. {
  6387. if (DebugAlwaysTrue(TabSheet != NULL))
  6388. {
  6389. TManagedTerminal * ATerminal = GetSessionTabSession(TabSheet);
  6390. if (DebugAlwaysTrue(ATerminal != NULL))
  6391. {
  6392. TColor Color = (ATerminal == Terminal) ? FSessionColor : ATerminal->StateData->Color;
  6393. TabSheet->ImageIndex = AddSessionColor(Color);
  6394. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6395. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6396. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6397. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6398. {
  6399. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6400. }
  6401. }
  6402. }
  6403. }
  6404. //---------------------------------------------------------------------------
  6405. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6406. {
  6407. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6408. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->ActivePage);
  6409. bool Result = (Session != NULL);
  6410. if (Result)
  6411. {
  6412. TTerminalManager::Instance()->ActiveSession = Session;
  6413. }
  6414. else
  6415. {
  6416. try
  6417. {
  6418. NewSession();
  6419. }
  6420. __finally
  6421. {
  6422. SessionListChanged();
  6423. }
  6424. FSessionsPageControlNewSessionTime = Now();
  6425. }
  6426. return Result;
  6427. }
  6428. //---------------------------------------------------------------------------
  6429. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6430. {
  6431. SessionTabSwitched();
  6432. }
  6433. //---------------------------------------------------------------------------
  6434. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6435. {
  6436. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6437. DebugAssert(TransferList != NULL);
  6438. UnicodeString Name;
  6439. if (TransferList->ItemIndex <= 0)
  6440. {
  6441. Name = L"";
  6442. }
  6443. else
  6444. {
  6445. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6446. }
  6447. if (FCopyParamAutoSelected.IsEmpty())
  6448. {
  6449. // if previous preset was not autoselected, make new preset the "default"
  6450. FCopyParamDefault = Name;
  6451. }
  6452. GUIConfiguration->CopyParamCurrent = Name;
  6453. }
  6454. //---------------------------------------------------------------------------
  6455. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6456. {
  6457. // sanity check
  6458. bool ExistingPreset =
  6459. (FTransferListHoverIndex >= 0) &&
  6460. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6461. DebugAssert(ExistingPreset);
  6462. if (ExistingPreset)
  6463. {
  6464. HDC DC = GetDC(0);
  6465. TCanvas * Canvas = new TCanvas();
  6466. try
  6467. {
  6468. Canvas->Handle = DC;
  6469. Canvas->Font = GetToolbarFont(this);
  6470. UnicodeString Name;
  6471. if (FTransferListHoverIndex == 0)
  6472. {
  6473. Name = L"";
  6474. }
  6475. else
  6476. {
  6477. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6478. }
  6479. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6480. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6481. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6482. static_cast<TObject*>(GetComponent(fcTransferList)));
  6483. UnicodeString InfoStr =
  6484. GUIConfiguration->CopyParamPreset[Name].
  6485. GetInfoStr(L"; ",
  6486. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6487. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6488. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6489. {
  6490. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6491. {
  6492. InfoStr.SetLength(InfoStr.Length() - 1);
  6493. }
  6494. InfoStr += Ellipsis;
  6495. }
  6496. // UpdateCaption does not cause invalidation of whole submenu, while
  6497. // setting Caption property does.
  6498. // also it probably does not resize the label, even if necessary
  6499. // (we do not want that anyway)
  6500. TransferLabel->UpdateCaption(InfoStr);
  6501. }
  6502. __finally
  6503. {
  6504. Canvas->Handle = NULL;
  6505. ReleaseDC(0, DC);
  6506. delete Canvas;
  6507. }
  6508. }
  6509. }
  6510. //---------------------------------------------------------------------------
  6511. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6512. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6513. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6514. {
  6515. if (FTransferListHoverIndex != AHoverIndex)
  6516. {
  6517. FTransferListHoverIndex = AHoverIndex;
  6518. UpdateTransferLabel();
  6519. }
  6520. }
  6521. //---------------------------------------------------------------------------
  6522. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6523. {
  6524. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6525. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6526. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6527. {
  6528. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6529. {
  6530. if (!NonVisualDataModule->Busy)
  6531. {
  6532. OpenDirectory(GetSide(osCurrent));
  6533. }
  6534. Message.Result = 1;
  6535. }
  6536. else
  6537. {
  6538. TForm::Dispatch(&Message);
  6539. }
  6540. }
  6541. else
  6542. {
  6543. TForm::Dispatch(&Message);
  6544. }
  6545. }
  6546. //---------------------------------------------------------------------------
  6547. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6548. {
  6549. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6550. if ((FIgnoreNextDialogChar != 0) &&
  6551. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6552. {
  6553. Message.Result = 1;
  6554. }
  6555. else
  6556. {
  6557. TForm::Dispatch(&Message);
  6558. }
  6559. FIgnoreNextDialogChar = 0;
  6560. }
  6561. //---------------------------------------------------------------------------
  6562. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6563. {
  6564. // The four low-order bits are used internally by Windows
  6565. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6566. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6567. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6568. // 61730 - restore thru double click - undocumented
  6569. // 61490 - maximize thru double click - undocumented
  6570. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6571. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6572. {
  6573. SysResizing(Cmd);
  6574. }
  6575. TForm::Dispatch(&Message);
  6576. }
  6577. //---------------------------------------------------------------------------
  6578. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6579. {
  6580. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6581. // Also there no point returning TRUE as we are not able to
  6582. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6583. // Hence the process termination might be safer :)
  6584. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6585. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6586. {
  6587. Message.Result = FALSE;
  6588. }
  6589. else
  6590. {
  6591. Message.Result = TRUE;
  6592. }
  6593. // Do not call default handling as that triggers OnCloseQuery,
  6594. // where our implementation will popup confirmation dialogs, what we do not want,
  6595. // as per Vista guidelines:
  6596. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6597. }
  6598. //---------------------------------------------------------------------------
  6599. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6600. {
  6601. if (Message.EndSession && IsApplicationMinimized())
  6602. {
  6603. // WORKAROUND
  6604. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6605. // when it receives WM_ENDSESSION,
  6606. // but that sometimes (particularly when application is minimized) cause crashes.
  6607. // Crash popups message that blocks log off.
  6608. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6609. // so we call ExitProcess() immediately, not even trying to cleanup.
  6610. // It still causes beep, so there's likely some popup, but it does not block
  6611. // log off.
  6612. ExitProcess(0);
  6613. }
  6614. TForm::Dispatch(&Message);
  6615. }
  6616. #ifdef _DEBUG
  6617. //---------------------------------------------------------------------------
  6618. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6619. {
  6620. TForm::Dispatch(&Message);
  6621. }
  6622. #endif
  6623. //---------------------------------------------------------------------------
  6624. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6625. {
  6626. }
  6627. //---------------------------------------------------------------------------
  6628. void __fastcall TCustomScpExplorerForm::DoShow()
  6629. {
  6630. // only now are the controls resized finally, so the size constraints
  6631. // will not conflict with possibly very small window size
  6632. RestoreFormParams();
  6633. // This indicates that the form was rescaled after parameters were loaded and
  6634. // as most probably the parameters were actually saved with the current form scaling
  6635. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6636. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6637. // and no rounding problems will occur.
  6638. // See also RestoreForm.
  6639. // (we should be safe to call RestoreParams unconditionally)
  6640. if (PixelsPerInch != Screen->PixelsPerInch)
  6641. {
  6642. RestoreParams();
  6643. }
  6644. FixControlsPlacement();
  6645. if (Position == poDefaultPosOnly)
  6646. {
  6647. CutFormToDesktop(this);
  6648. }
  6649. TForm::DoShow();
  6650. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6651. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6652. // This was previously in NeedSession, where other related code is.
  6653. // But that is called from CMShowingChanged, when the window is already visible and the local-local window state
  6654. // unpleasanly shows briefly.
  6655. if (!WinConfiguration->ShowLoginWhenNoSession &&
  6656. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6657. // This detects if workspace was saved the last time the main widow was closed
  6658. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6659. {
  6660. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6661. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6662. }
  6663. if (Terminal == NULL)
  6664. {
  6665. StartingDisconnected();
  6666. }
  6667. UpdatePixelsPerInchMainWindowCounter();
  6668. FShowing = true;
  6669. }
  6670. //---------------------------------------------------------------------------
  6671. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6672. {
  6673. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6674. }
  6675. //---------------------------------------------------------------------------
  6676. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6677. {
  6678. SessionListChanged();
  6679. InitStatusBar();
  6680. UpdateControls();
  6681. }
  6682. //---------------------------------------------------------------------------
  6683. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6684. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6685. TNotifyEvent OnBalloonClick, TObject * UserData)
  6686. {
  6687. bool Do;
  6688. UnicodeString Message;
  6689. if (E == NULL)
  6690. {
  6691. Message = Str;
  6692. Do = true;
  6693. }
  6694. else
  6695. {
  6696. Do = ExceptionMessage(E, Message);
  6697. }
  6698. if (Do && WinConfiguration->BalloonNotifications)
  6699. {
  6700. UnicodeString Title;
  6701. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6702. {
  6703. Message = TrimLeft(Message);
  6704. }
  6705. else
  6706. {
  6707. Message = UnformatMessage(Message);
  6708. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6709. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6710. Title = LoadResourceString(Captions[Type]);
  6711. if (Terminal != NULL)
  6712. {
  6713. Title = FORMAT(L"%s - %s",
  6714. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6715. }
  6716. }
  6717. if (Seconds == 0)
  6718. {
  6719. Seconds = WinConfiguration->NotificationsTimeout;
  6720. }
  6721. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6722. }
  6723. }
  6724. //---------------------------------------------------------------------------
  6725. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6726. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6727. UnicodeString HelpKeyword, const TMessageParams * Params,
  6728. TTerminal * Terminal)
  6729. {
  6730. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6731. (FOnFeedSynchronizeError != NULL)) &&
  6732. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6733. {
  6734. if (FOnFeedSynchronizeError != NULL)
  6735. {
  6736. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6737. }
  6738. else
  6739. {
  6740. DebugAssert(FErrorList != NULL);
  6741. TStringList * MoreMessagesCopy = NULL;
  6742. if (MoreMessages)
  6743. {
  6744. MoreMessagesCopy = new TStringList();
  6745. MoreMessagesCopy->Assign(MoreMessages);
  6746. }
  6747. FErrorList->AddObject(Message, MoreMessagesCopy);
  6748. }
  6749. PopupTrayBalloon(Terminal, Message, Type);
  6750. return ContinueAnswer(Answers);
  6751. }
  6752. else
  6753. {
  6754. bool UseBalloon = FTrayIcon->Visible;
  6755. if (UseBalloon)
  6756. {
  6757. PopupTrayBalloon(Terminal, Message, Type);
  6758. }
  6759. unsigned int Result;
  6760. try
  6761. {
  6762. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6763. }
  6764. __finally
  6765. {
  6766. // cancel only balloon we popped up, otherwise we may cancel notification
  6767. // balloon that was there before the message dialog
  6768. // (such as "dd confirmation opt in balloon)
  6769. if (UseBalloon)
  6770. {
  6771. FTrayIcon->CancelBalloon();
  6772. }
  6773. }
  6774. return Result;
  6775. }
  6776. }
  6777. //---------------------------------------------------------------------------
  6778. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6779. TTerminal * Terminal, Exception * E)
  6780. {
  6781. if (FTrayIcon->Visible)
  6782. {
  6783. PopupTrayBalloon(Terminal, L"", qtError, E);
  6784. }
  6785. // particularly prevent opening new session from jump list,
  6786. // while exception is shown
  6787. NonVisualDataModule->StartBusy();
  6788. try
  6789. {
  6790. ShowExtendedExceptionEx(Terminal, E);
  6791. }
  6792. __finally
  6793. {
  6794. NonVisualDataModule->EndBusy();
  6795. FTrayIcon->CancelBalloon();
  6796. }
  6797. }
  6798. //---------------------------------------------------------------------------
  6799. void __fastcall TCustomScpExplorerForm::SessionReady()
  6800. {
  6801. if (Terminal->Active)
  6802. {
  6803. InitStatusBar();
  6804. }
  6805. // cannot rely on active page being page for active terminal,
  6806. // as it can happen that active page is the "new session" page
  6807. // (e.g. when reconnecting active terminal, while login dialog
  6808. // invoked from "new session" page is modal)
  6809. int ActiveSessionIndex = TTerminalManager::Instance()->ActiveSessionIndex;
  6810. UpdateSessionTab(SessionsPageControl->Pages[ActiveSessionIndex]);
  6811. }
  6812. //---------------------------------------------------------------------------
  6813. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6814. TTerminal * Terminal, Exception * E)
  6815. {
  6816. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6817. if (!Terminal->Active)
  6818. {
  6819. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6820. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6821. {
  6822. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6823. }
  6824. }
  6825. }
  6826. //---------------------------------------------------------------------------
  6827. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6828. UnicodeString Message, TQueryType Type,
  6829. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6830. {
  6831. if ((E == NULL) ||
  6832. ExceptionMessage(E, Message))
  6833. {
  6834. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6835. if (Important)
  6836. {
  6837. Seconds *= 5;
  6838. }
  6839. UnicodeString NoteMessage(UnformatMessage(Message));
  6840. if (Terminal != NULL)
  6841. {
  6842. NoteMessage = FORMAT(L"%s: %s",
  6843. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6844. }
  6845. if (WinConfiguration->BalloonNotifications)
  6846. {
  6847. AddNote(NoteMessage);
  6848. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6849. }
  6850. else
  6851. {
  6852. FlashOnBackground();
  6853. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6854. }
  6855. }
  6856. }
  6857. //---------------------------------------------------------------------------
  6858. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6859. {
  6860. RestoreApp();
  6861. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6862. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6863. !NonVisualDataModule->Busy)
  6864. {
  6865. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6866. TTerminalManager::Instance()->ActiveSession = Terminal;
  6867. if (!ComponentVisible[fcQueueView])
  6868. {
  6869. ToggleQueueVisibility();
  6870. GoToQueue();
  6871. }
  6872. }
  6873. }
  6874. //---------------------------------------------------------------------------
  6875. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6876. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6877. {
  6878. UnicodeString Message;
  6879. TNotifyEvent OnClick = NULL;
  6880. TObject * UserData = NULL;
  6881. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6882. switch (Event)
  6883. {
  6884. case qeEmptyButMonitored:
  6885. if ((ATerminal != Terminal) || QueueInvisible)
  6886. {
  6887. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6888. OnClick = QueueEmptyNoteClicked;
  6889. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6890. TerminalNoteData->Terminal = ATerminal;
  6891. UserData = TerminalNoteData;
  6892. }
  6893. break;
  6894. case qeEmpty:
  6895. OperationComplete(ATerminal->QueueOperationStart);
  6896. break;
  6897. case qePendingUserAction:
  6898. if ((ATerminal != Terminal) ||
  6899. (QueueInvisible && !IsQueueAutoPopup()))
  6900. {
  6901. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6902. }
  6903. break;
  6904. default:
  6905. DebugFail();
  6906. }
  6907. if (!Message.IsEmpty())
  6908. {
  6909. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6910. }
  6911. }
  6912. //---------------------------------------------------------------------------
  6913. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6914. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6915. {
  6916. if (FDDExtMapFile != NULL)
  6917. {
  6918. CloseHandle(FDDExtMapFile);
  6919. FDDExtMapFile = NULL;
  6920. }
  6921. if (WinConfiguration->DDFakeFile)
  6922. {
  6923. DDFakeFileInitDrag(FileList, Created);
  6924. }
  6925. }
  6926. //---------------------------------------------------------------------------
  6927. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6928. {
  6929. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6930. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6931. {
  6932. FFakeFileDropTarget = FileName;
  6933. }
  6934. }
  6935. //---------------------------------------------------------------------------
  6936. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6937. {
  6938. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6939. if (!ForceDirectories(ApiPath(Result)))
  6940. {
  6941. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6942. }
  6943. FileSetAttr(ApiPath(Result), faHidden);
  6944. return Result;
  6945. }
  6946. //---------------------------------------------------------------------------
  6947. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6948. bool & Created)
  6949. {
  6950. FFakeFileDropTarget = UnicodeString();
  6951. FDragFakeDirectory = CreateFakeTransferDirectory();
  6952. FileList->AddItem(NULL, FDragFakeDirectory);
  6953. Created = true;
  6954. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6955. {
  6956. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6957. }
  6958. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6959. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6960. {
  6961. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6962. TDragExtCommStruct* CommStruct;
  6963. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6964. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6965. DebugAssert(CommStruct != NULL);
  6966. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6967. CommStruct->Dragging = true;
  6968. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6969. LENOF(CommStruct->DropDest));
  6970. NULL_TERMINATE(CommStruct->DropDest);
  6971. UnmapViewOfFile(CommStruct);
  6972. }
  6973. }
  6974. //---------------------------------------------------------------------------
  6975. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6976. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6977. {
  6978. bool Result;
  6979. DebugAssert(!IsLocalBrowserMode());
  6980. if (Sender == RemoteDirView)
  6981. {
  6982. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6983. }
  6984. else
  6985. {
  6986. DebugAssert(Sender == RemoteDriveView);
  6987. TStrings * FileList = RemoteDriveView->DragFileList();
  6988. try
  6989. {
  6990. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6991. }
  6992. __finally
  6993. {
  6994. delete FileList;
  6995. }
  6996. }
  6997. if (FDDTargetControl == RemoteDriveView)
  6998. {
  6999. RemoteDriveView->UpdateDropTarget();
  7000. }
  7001. // foRemoteMove happens when file/dir is dragged within the remote tree view
  7002. // or from tree view to dir view.
  7003. // foMove happens when file/dir is dragged from remote tree view outside of
  7004. // application via dragex
  7005. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  7006. (DropSourceControl == RemoteDriveView))
  7007. {
  7008. RemoteDriveView->UpdateDropSource();
  7009. }
  7010. return Result;
  7011. }
  7012. //---------------------------------------------------------------------------
  7013. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  7014. {
  7015. DebugAssert(!IsLocalBrowserMode());
  7016. // This also handles drops of remote files to queue.
  7017. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  7018. SAFE_DESTROY(FDDFileList);
  7019. if (!FFakeFileDropTarget.IsEmpty())
  7020. {
  7021. RemoveDir(ApiPath(FFakeFileDropTarget));
  7022. }
  7023. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  7024. {
  7025. try
  7026. {
  7027. TDragResult DDResult = (Sender == RemoteDirView) ?
  7028. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  7029. // Focus is moved to the target application,
  7030. // but as we are going to present the UI, we need to steal the focus back.
  7031. // This most likely won't work though (windows does not allow application
  7032. // to steal focus most of the time)
  7033. Application->BringToFront();
  7034. // On older version of Windows we never got drMove here, see also comment below.
  7035. // On Windows 10, we get the "move".
  7036. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  7037. {
  7038. UnicodeString TargetDirectory;
  7039. TFileOperation Operation;
  7040. // drInvalid may mean drMove, see comment below
  7041. switch (DDResult)
  7042. {
  7043. case drCopy:
  7044. Operation = foCopy;
  7045. break;
  7046. case drMove:
  7047. Operation = foMove;
  7048. break;
  7049. default:
  7050. DebugFail();
  7051. case drInvalid:
  7052. // prefer "copy" for safety
  7053. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7054. break;
  7055. }
  7056. TTransferOperationParam Param;
  7057. UnicodeString CounterName;
  7058. bool ForceQueue;
  7059. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7060. {
  7061. // we get drInvalid both if d&d was intercepted by ddext,
  7062. // and when users drops on no-drop location.
  7063. // we tell the difference by existence of response from ddext,
  7064. // so we ignore absence of response in this case
  7065. if (DDResult != drInvalid)
  7066. {
  7067. // here we know that the extension is installed,
  7068. // as it is checked as soon as drag&drop starts from
  7069. // RemoteFileControlDDCreateDragFileList
  7070. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7071. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7072. {
  7073. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7074. }
  7075. else
  7076. {
  7077. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7078. }
  7079. }
  7080. }
  7081. else
  7082. {
  7083. // download using fake file
  7084. Param.Temp = false;
  7085. Param.DragDrop = true;
  7086. if (ForceQueue)
  7087. {
  7088. Param.Queue = asOn;
  7089. }
  7090. if (Sender == RemoteDirView)
  7091. {
  7092. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7093. }
  7094. if (RemoteFileControlFileOperation(Sender, Operation,
  7095. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7096. {
  7097. Configuration->Usage->Inc(CounterName);
  7098. }
  7099. }
  7100. }
  7101. }
  7102. __finally
  7103. {
  7104. CloseHandle(FDDExtMapFile);
  7105. FDDExtMapFile = NULL;
  7106. delete FDragFakeMonitors;
  7107. FDragFakeMonitors = NULL;
  7108. RemoveDir(ApiPath(FDragFakeDirectory));
  7109. FDragFakeDirectory = L"";
  7110. FFakeFileDropTarget = UnicodeString();
  7111. }
  7112. }
  7113. if (FDragDropSshTerminate.get() != NULL)
  7114. {
  7115. FDragDropSshTerminate->Rethrow();
  7116. }
  7117. }
  7118. //---------------------------------------------------------------------------
  7119. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7120. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7121. {
  7122. // Remember drop effect so we know (when user drops files), if we copy or move
  7123. FLastDropEffect = dwEffect;
  7124. }
  7125. //---------------------------------------------------------------------------
  7126. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7127. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7128. {
  7129. bool Result;
  7130. if (FDDTargetControl == QueueView3)
  7131. {
  7132. Directory = DefaultDownloadTargetDirectory();
  7133. Result = true;
  7134. CounterName = L"DownloadsDragDropQueue";
  7135. ForceQueue = true;
  7136. }
  7137. else if (!FFakeFileDropTarget.IsEmpty())
  7138. {
  7139. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7140. Result = true;
  7141. ForceQueue = false;
  7142. CounterName = L"DownloadsDragDropFakeFile";
  7143. }
  7144. else
  7145. {
  7146. ForceQueue = false;
  7147. Enabled = false;
  7148. try
  7149. {
  7150. int Timer = 0;
  7151. Result = false;
  7152. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7153. {
  7154. {
  7155. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7156. TDragExtCommStruct* CommStruct;
  7157. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7158. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7159. DebugAssert(CommStruct != NULL);
  7160. Result = !CommStruct->Dragging;
  7161. if (Result)
  7162. {
  7163. Directory = ExtractFilePath(CommStruct->DropDest);
  7164. CounterName = L"DownloadsDragDropExternalExt";
  7165. }
  7166. UnmapViewOfFile(CommStruct);
  7167. }
  7168. if (!Result)
  7169. {
  7170. Sleep(50);
  7171. Timer += 50;
  7172. Application->ProcessMessages();
  7173. }
  7174. }
  7175. }
  7176. __finally
  7177. {
  7178. Enabled = true;
  7179. }
  7180. }
  7181. return Result;
  7182. }
  7183. //---------------------------------------------------------------------------
  7184. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7185. const UnicodeString TempDir, int SecDelay)
  7186. {
  7187. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7188. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7189. if (FDelayedDeletionTimer == NULL)
  7190. {
  7191. DebugAssert(HandleAllocated());
  7192. FDelayedDeletionTimer = new TTimer(this);
  7193. FDelayedDeletionTimer->Interval = 10000;
  7194. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7195. }
  7196. else
  7197. {
  7198. FDelayedDeletionTimer->Enabled = true;
  7199. }
  7200. }
  7201. //---------------------------------------------------------------------------
  7202. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7203. {
  7204. DebugAssert(FDelayedDeletionList != NULL);
  7205. TDateTime N = Now();
  7206. TDateTime Alert;
  7207. UnicodeString Directory;
  7208. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7209. {
  7210. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7211. if ((N >= Alert) || (Sender == NULL))
  7212. {
  7213. Directory = FDelayedDeletionList->Strings[Index];
  7214. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7215. {
  7216. FDelayedDeletionList->Delete(Index);
  7217. }
  7218. }
  7219. }
  7220. if (FDelayedDeletionList->Count == 0)
  7221. {
  7222. FDelayedDeletionTimer->Enabled = false;
  7223. }
  7224. }
  7225. //---------------------------------------------------------------------------
  7226. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7227. {
  7228. DebugAssert(!IsLocalBrowserMode());
  7229. if (IsFileControl(FDDTargetControl, osRemote) ||
  7230. (FDDTargetControl == SessionsPageControl))
  7231. {
  7232. TTerminal * TargetTerminal = NULL;
  7233. TFileOperation Operation = foNone;
  7234. if (FDDTargetControl == SessionsPageControl)
  7235. {
  7236. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7237. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7238. // do not allow dropping on the "+" tab
  7239. TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  7240. if (TargetTerminal != NULL)
  7241. {
  7242. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7243. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7244. {
  7245. Operation = foRemoteMove;
  7246. }
  7247. else
  7248. {
  7249. Operation = foRemoteCopy;
  7250. }
  7251. }
  7252. }
  7253. else
  7254. {
  7255. if (FLastDropEffect == DROPEFFECT_MOVE)
  7256. {
  7257. Operation = foRemoteMove;
  7258. }
  7259. else if (FLastDropEffect == DROPEFFECT_COPY)
  7260. {
  7261. Operation = foRemoteCopy;
  7262. }
  7263. }
  7264. if (Operation != foNone)
  7265. {
  7266. RemoteFileControlFileOperation(DropSourceControl,
  7267. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7268. }
  7269. // abort drag&drop
  7270. Abort();
  7271. }
  7272. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7273. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7274. (FDDTargetControl != QueueView3))
  7275. {
  7276. DebugAssert(!FDragTempDir.IsEmpty());
  7277. TTransferType Type;
  7278. UnicodeString TempDir = FDragTempDir;
  7279. // We clear FDragTempDir before calling
  7280. // just in case it fail (raises exception)
  7281. FDragTempDir = L"";
  7282. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7283. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7284. // empty directory parameter means temp directory -> don't display it!
  7285. UnicodeString TargetDir = L"";
  7286. int Options = 0;
  7287. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7288. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7289. {
  7290. Abort();
  7291. }
  7292. // TargetDir is set when dropped on local file control
  7293. // (this was workaround for legacy dirview event handling, now it should be
  7294. // made prettier)
  7295. if (TargetDir.IsEmpty())
  7296. {
  7297. TargetDir = TempDir;
  7298. if (ForceDirectories(ApiPath(TargetDir)))
  7299. {
  7300. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7301. FPendingTempSpaceWarn = true;
  7302. try
  7303. {
  7304. FDragDropOperation = true;
  7305. int Params = cpTemporary |
  7306. (Type == ttMove ? cpDelete : 0);
  7307. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7308. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7309. }
  7310. __finally
  7311. {
  7312. FDragDropOperation = false;
  7313. FPendingTempSpaceWarn = false;
  7314. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7315. }
  7316. }
  7317. else
  7318. {
  7319. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7320. }
  7321. }
  7322. }
  7323. }
  7324. //---------------------------------------------------------------------------
  7325. void __fastcall TCustomScpExplorerForm::DDDownload(
  7326. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7327. {
  7328. DebugAssert(!IsLocalBrowserMode());
  7329. TAutoBatch AutoBatch(this);
  7330. UpdateCopyParamCounters(*CopyParam);
  7331. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7332. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7333. {
  7334. RemoteDriveView->UpdateDropSource();
  7335. }
  7336. }
  7337. //---------------------------------------------------------------------------
  7338. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7339. {
  7340. public:
  7341. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7342. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7343. {
  7344. }
  7345. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7346. {
  7347. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7348. TDataObjectFilesEx::AllowData(FormatEtc);
  7349. }
  7350. };
  7351. //---------------------------------------------------------------------------
  7352. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7353. TObject * Sender, TDataObject *& DataObject)
  7354. {
  7355. if (FDDExtMapFile != NULL)
  7356. {
  7357. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7358. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7359. {
  7360. Abort();
  7361. }
  7362. if (FileList->Count > 0)
  7363. {
  7364. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7365. if (!FilesObject->IsValid(true, true))
  7366. {
  7367. FilesObject->_Release();
  7368. }
  7369. else
  7370. {
  7371. DataObject = FilesObject;
  7372. }
  7373. }
  7374. }
  7375. }
  7376. //---------------------------------------------------------------------------
  7377. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7378. {
  7379. DebugFail();
  7380. }
  7381. //---------------------------------------------------------------------------
  7382. void __fastcall TCustomScpExplorerForm::GoToTree()
  7383. {
  7384. ComponentVisible[fcRemoteTree] = true;
  7385. DriveView(osRemote)->SetFocus();
  7386. }
  7387. //---------------------------------------------------------------------------
  7388. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7389. TPanelExport Export)
  7390. {
  7391. TCustomDirView * DirView = this->DirView(Side);
  7392. std::unique_ptr<TStrings> ExportData(new TStringList());
  7393. switch (Export)
  7394. {
  7395. case pePath:
  7396. ExportData->Add(DirView->PathName);
  7397. break;
  7398. case peFileList:
  7399. case peFullFileList:
  7400. {
  7401. bool FullPath = (Export == peFullFileList);
  7402. DirView->CreateFileList(false, FullPath, ExportData.get());
  7403. for (int Index = 0; Index < ExportData->Count; Index++)
  7404. {
  7405. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7406. {
  7407. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7408. }
  7409. }
  7410. }
  7411. break;
  7412. default:
  7413. DebugFail();
  7414. }
  7415. return ExportData.release();
  7416. }
  7417. //---------------------------------------------------------------------------
  7418. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7419. TPanelExport Export, TPanelExportDestination Destination)
  7420. {
  7421. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7422. PanelExportStore(Side, Export, Destination, ExportData.get());
  7423. }
  7424. //---------------------------------------------------------------------------
  7425. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7426. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7427. TStrings * ExportData)
  7428. {
  7429. if (Destination == pedClipboard)
  7430. {
  7431. TInstantOperationVisualizer Visualizer;
  7432. CopyToClipboard(ExportData);
  7433. }
  7434. else
  7435. {
  7436. DebugFail();
  7437. }
  7438. }
  7439. //---------------------------------------------------------------------------
  7440. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7441. {
  7442. TCustomDirView * DirView = this->DirView(Side);
  7443. UnicodeString Mask = DirView->Mask;
  7444. if (DoFilterMaskDialog(DirView, Mask))
  7445. {
  7446. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7447. Configuration->Usage->Inc(L"Filters");
  7448. }
  7449. }
  7450. //---------------------------------------------------------------------------
  7451. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7452. {
  7453. return FQueueController->DefaultOperation();
  7454. }
  7455. //---------------------------------------------------------------------------
  7456. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7457. TQueueOperation Operation, void ** Param)
  7458. {
  7459. switch (Operation)
  7460. {
  7461. case qoPreferences:
  7462. return true;
  7463. case qoGoTo:
  7464. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7465. case qoOnceEmpty:
  7466. return IsAnythingQueued();
  7467. default:
  7468. return FQueueController->AllowOperation(Operation, Param);
  7469. }
  7470. }
  7471. //---------------------------------------------------------------------------
  7472. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7473. {
  7474. if (DebugAlwaysTrue(QueueView3->Visible))
  7475. {
  7476. QueueView3->SetFocus();
  7477. }
  7478. }
  7479. //---------------------------------------------------------------------------
  7480. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7481. TQueueOperation Operation, void * Param)
  7482. {
  7483. if (Operation == qoGoTo)
  7484. {
  7485. GoToQueue();
  7486. }
  7487. else if (Operation == qoPreferences)
  7488. {
  7489. PreferencesDialog(pmQueue);
  7490. }
  7491. else
  7492. {
  7493. FQueueController->ExecuteOperation(Operation, Param);
  7494. }
  7495. }
  7496. //---------------------------------------------------------------------------
  7497. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7498. {
  7499. return (Queue != NULL) && Queue->Enabled;
  7500. }
  7501. //---------------------------------------------------------------------------
  7502. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7503. {
  7504. DebugAssert(Queue != NULL);
  7505. if (Queue != NULL)
  7506. {
  7507. Queue->Enabled = !Queue->Enabled;
  7508. }
  7509. }
  7510. //---------------------------------------------------------------------------
  7511. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7512. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7513. {
  7514. FQueueActedItem = QueueView3->ItemFocused;
  7515. }
  7516. //---------------------------------------------------------------------------
  7517. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7518. {
  7519. return TopDock->Height + QueueSplitter->Height;
  7520. }
  7521. //---------------------------------------------------------------------------
  7522. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7523. {
  7524. return
  7525. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7526. (QueueDock->Visible ? QueueDock->Height : 0) +
  7527. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7528. }
  7529. //---------------------------------------------------------------------------
  7530. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7531. {
  7532. return ScaleByTextHeight(this, 48);
  7533. }
  7534. //---------------------------------------------------------------------------
  7535. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7536. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7537. {
  7538. // when queue is hidden by double-clicking splitter, stray attempt to
  7539. // resize the panel with strange value arrives, make sure it is ignored
  7540. if (ComponentVisible[fcQueueView])
  7541. {
  7542. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7543. if (NewSize > MaxHeightLimit)
  7544. {
  7545. NewSize = MaxHeightLimit;
  7546. }
  7547. int MinHeightLimit =
  7548. GetStaticQueuePanelComponentsHeight() +
  7549. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7550. GetMinQueueViewHeight();
  7551. if (NewSize < MinHeightLimit)
  7552. {
  7553. NewSize = MinHeightLimit;
  7554. }
  7555. }
  7556. else
  7557. {
  7558. Accept = false;
  7559. }
  7560. }
  7561. //---------------------------------------------------------------------------
  7562. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7563. {
  7564. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7565. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7566. if (QueueViewHeight < GetMinQueueViewHeight())
  7567. {
  7568. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7569. }
  7570. }
  7571. //---------------------------------------------------------------------------
  7572. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7573. TDragObject *& /*DragObject*/)
  7574. {
  7575. FQueueActedItem = QueueView3->ItemFocused;
  7576. }
  7577. //---------------------------------------------------------------------------
  7578. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7579. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7580. {
  7581. Accept = true;
  7582. if (Source == QueueView3)
  7583. {
  7584. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7585. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7586. if (Accept)
  7587. {
  7588. TQueueItemProxy * QueueItem;
  7589. TQueueItemProxy * DestQueueItem;
  7590. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7591. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7592. Accept = (QueueItem != DestQueueItem) &&
  7593. (QueueItem->Status == TQueueItem::qsPending) &&
  7594. (DestQueueItem->Status == TQueueItem::qsPending);
  7595. }
  7596. }
  7597. }
  7598. //---------------------------------------------------------------------------
  7599. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7600. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7601. {
  7602. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7603. {
  7604. TQueueItemProxy * QueueItem;
  7605. TQueueItemProxy * DestQueueItem;
  7606. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7607. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7608. QueueItem->Move(DestQueueItem);
  7609. }
  7610. }
  7611. //---------------------------------------------------------------------------
  7612. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7613. {
  7614. if ((QueueView3->ItemFocused == NULL) &&
  7615. (QueueView3->Items->Count > 0))
  7616. {
  7617. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7618. }
  7619. QueueLabelUpdateStatus();
  7620. }
  7621. //---------------------------------------------------------------------------
  7622. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7623. {
  7624. QueueLabelUpdateStatus();
  7625. }
  7626. //---------------------------------------------------------------------------
  7627. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7628. {
  7629. QueueLabel->UpdateStatus();
  7630. }
  7631. //---------------------------------------------------------------------------
  7632. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7633. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7634. {
  7635. if (Selected)
  7636. {
  7637. NonVisualDataModule->UpdateNonVisibleActions();
  7638. }
  7639. }
  7640. //---------------------------------------------------------------------------
  7641. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7642. {
  7643. TDragDropFilesEx * Result = NULL;
  7644. if (Sender == SessionsPageControl)
  7645. {
  7646. Result = FSessionsDragDropFilesEx;
  7647. }
  7648. else if (Sender == QueueView3)
  7649. {
  7650. Result = FQueueDragDropFilesEx;
  7651. }
  7652. else
  7653. {
  7654. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7655. if (DirView != NULL)
  7656. {
  7657. Result = DirView->DragDropFilesEx;
  7658. }
  7659. else
  7660. {
  7661. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7662. if (DriveView != NULL)
  7663. {
  7664. Result = DriveView->DragDropFilesEx;
  7665. }
  7666. }
  7667. }
  7668. DebugAssert(Result != NULL);
  7669. return Result;
  7670. }
  7671. //---------------------------------------------------------------------------
  7672. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7673. {
  7674. return (DView->SelCount == DView->FilesCount);
  7675. }
  7676. //---------------------------------------------------------------------------
  7677. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7678. {
  7679. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7680. }
  7681. //---------------------------------------------------------------------------
  7682. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7683. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7684. {
  7685. DebugAssert(!IsLocalBrowserMode());
  7686. TFileOperation Operation;
  7687. switch (Effect)
  7688. {
  7689. case DROPEFFECT_MOVE:
  7690. Operation = foMove;
  7691. break;
  7692. case DROPEFFECT_COPY:
  7693. // occures on WinXP (reported by user)
  7694. default:
  7695. Operation = foCopy;
  7696. break;
  7697. };
  7698. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7699. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7700. if (DragDropFilesEx->FileList->Count > 0)
  7701. {
  7702. TStrings * FileList = new TStringList();
  7703. try
  7704. {
  7705. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7706. {
  7707. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7708. }
  7709. FDragDropOperation = true;
  7710. TTransferOperationParam Param;
  7711. Param.TargetDirectory = TargetPath;
  7712. // upload, no temp dirs
  7713. Param.Temp = false;
  7714. Param.DragDrop = DragDrop;
  7715. Param.Options =
  7716. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7717. if (ForceQueue)
  7718. {
  7719. Param.Queue = asOn;
  7720. }
  7721. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7722. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7723. {
  7724. if (IsFileControl(DropSourceControl, osLocal))
  7725. {
  7726. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7727. }
  7728. else
  7729. {
  7730. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7731. }
  7732. }
  7733. }
  7734. __finally
  7735. {
  7736. FDragDropOperation = false;
  7737. delete FileList;
  7738. }
  7739. }
  7740. }
  7741. //---------------------------------------------------------------------------
  7742. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7743. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7744. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7745. {
  7746. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7747. }
  7748. //---------------------------------------------------------------------------
  7749. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7750. TObject * Sender, int grfKeyState, int & dwEffect)
  7751. {
  7752. DebugAssert(!IsLocalBrowserMode());
  7753. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7754. if ((dwEffect != DROPEFFECT_NONE) &&
  7755. IsFileControl(DropSourceControl, osRemote))
  7756. {
  7757. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7758. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7759. (RemoteDirView->DropTarget == NULL))
  7760. {
  7761. dwEffect = DROPEFFECT_NONE;
  7762. }
  7763. else
  7764. {
  7765. if (dwEffect == DROPEFFECT_COPY)
  7766. {
  7767. bool MoveCapable = Terminal->IsCapable[fcRemoteMove];
  7768. // currently we support copying always (at least via temporary directory);
  7769. // remove associated checks once this all proves stable and working
  7770. bool CopyCapable = true;
  7771. // if we do not support neither of operations, there's no discussion
  7772. if (!MoveCapable && !CopyCapable)
  7773. {
  7774. dwEffect = DROPEFFECT_NONE;
  7775. }
  7776. else
  7777. {
  7778. // The default effect inside remote panel is move,
  7779. // unless we do not support it, but support copy
  7780. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7781. {
  7782. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7783. }
  7784. else
  7785. {
  7786. // with ctrl-down, we want copy unless it is not supported
  7787. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7788. }
  7789. }
  7790. }
  7791. }
  7792. }
  7793. }
  7794. //---------------------------------------------------------------------------
  7795. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7796. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7797. {
  7798. DebugAssert(!IsLocalBrowserMode());
  7799. if (FDDTotalSize >= 0)
  7800. {
  7801. if (File->IsDirectory)
  7802. {
  7803. FDDTotalSize = -1;
  7804. }
  7805. else
  7806. {
  7807. FDDTotalSize += File->Size;
  7808. }
  7809. }
  7810. DebugAssert(!FDragTempDir.IsEmpty());
  7811. // TODO: this is quite ineffective
  7812. // TODO: what if invalid character replacement is disabled?
  7813. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7814. UnicodeString TransferFileName;
  7815. if (Sender == RemoteDriveView)
  7816. {
  7817. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7818. }
  7819. else
  7820. {
  7821. TransferFileName = File->FileName;
  7822. }
  7823. FDDFileList->AddObject(TransferFileName, File);
  7824. }
  7825. //---------------------------------------------------------------------------
  7826. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7827. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7828. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7829. {
  7830. // sometimes we do not get DDEnd so the list is not released
  7831. SAFE_DESTROY(FDDFileList);
  7832. FDDFileList = new TStringList();
  7833. FDragTempDir = WinConfiguration->TemporaryDir();
  7834. FDDTotalSize = 0;
  7835. FDragDropSshTerminate.reset(NULL);
  7836. }
  7837. //---------------------------------------------------------------------------
  7838. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7839. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7840. HRESULT & Result)
  7841. {
  7842. if (Result == DRAGDROP_S_DROP)
  7843. {
  7844. try
  7845. {
  7846. GlobalDragImageList->HideDragImage();
  7847. try
  7848. {
  7849. RemoteFileControlDDTargetDrop();
  7850. }
  7851. catch(ESshTerminate & E)
  7852. {
  7853. FDragDropSshTerminate.reset(E.Clone());
  7854. }
  7855. }
  7856. catch (Exception &E)
  7857. {
  7858. // If downloading fails we need to cancel drag&drop, otherwise
  7859. // Explorer shows error
  7860. // But by the way exception probably never reach this point as
  7861. // it's catched on way.
  7862. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7863. Result = DRAGDROP_S_CANCEL;
  7864. ShowExtendedException(Terminal, &E);
  7865. }
  7866. }
  7867. }
  7868. //---------------------------------------------------------------------------
  7869. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7870. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7871. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7872. {
  7873. TFileMasks::TParams MaskParams;
  7874. MaskParams.Size = Size;
  7875. MaskParams.Modification = Modification;
  7876. // this does not re-parse the mask if it is the same as the last time
  7877. FDirViewMatchMask = Masks;
  7878. bool ImplicitMatch;
  7879. Matches =
  7880. // RecurseInclude parameter has no effect as the Path is empty
  7881. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7882. (AllowImplicitMatches || !ImplicitMatch);
  7883. }
  7884. //---------------------------------------------------------------------------
  7885. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7886. TObject * Sender, TListItem * Item, WORD & Indexes)
  7887. {
  7888. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7889. UnicodeString Ext;
  7890. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7891. {
  7892. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7893. }
  7894. else
  7895. {
  7896. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7897. }
  7898. if (SameText(Ext, Configuration->PartialExt))
  7899. {
  7900. Indexes |= oiPartial;
  7901. }
  7902. }
  7903. //---------------------------------------------------------------------------
  7904. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7905. {
  7906. return
  7907. DirViewEnabled(osCurrent) &&
  7908. DirView(osCurrent)->CanPasteFromClipBoard();
  7909. }
  7910. //---------------------------------------------------------------------------
  7911. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7912. {
  7913. bool Result = false;
  7914. if (CanPasteToDirViewFromClipBoard())
  7915. {
  7916. Result = true;
  7917. }
  7918. else
  7919. {
  7920. UnicodeString ClipboardText;
  7921. if (NonEmptyTextFromClipboard(ClipboardText) &&
  7922. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  7923. {
  7924. if (StoredSessions->IsUrl(ClipboardText))
  7925. {
  7926. Result = true;
  7927. }
  7928. else
  7929. {
  7930. Result = DirViewEnabled(osCurrent);
  7931. }
  7932. }
  7933. }
  7934. return Result;
  7935. }
  7936. //---------------------------------------------------------------------------
  7937. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7938. {
  7939. if (DoesClipboardContainOurFiles())
  7940. {
  7941. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7942. {
  7943. DebugAssert(!IsLocalBrowserMode());
  7944. TTerminalManager * Manager = TTerminalManager::Instance();
  7945. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7946. Manager->ActiveSession = FClipboardTerminal;
  7947. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7948. }
  7949. }
  7950. else if (CanPasteToDirViewFromClipBoard())
  7951. {
  7952. DirView(osCurrent)->PasteFromClipBoard();
  7953. }
  7954. else
  7955. {
  7956. UnicodeString ClipboardText;
  7957. if (NonEmptyTextFromClipboard(ClipboardText))
  7958. {
  7959. if (StoredSessions->IsUrl(ClipboardText))
  7960. {
  7961. NewSession(ClipboardText);
  7962. }
  7963. else
  7964. {
  7965. DirView(osCurrent)->Path = ClipboardText;
  7966. }
  7967. }
  7968. }
  7969. }
  7970. //---------------------------------------------------------------------------
  7971. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7972. {
  7973. // TBD
  7974. }
  7975. //---------------------------------------------------------------------------
  7976. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7977. {
  7978. TCustomDirView * ADirView = DirView(Side);
  7979. ADirView->SelectAll(Mode);
  7980. ADirView->SetFocus();
  7981. }
  7982. //---------------------------------------------------------------------------
  7983. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7984. {
  7985. TCustomDirView * ADirView = DirView(Side);
  7986. TFileFilter Filter;
  7987. DefaultFileFilter(Filter);
  7988. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7989. {
  7990. Configuration->Usage->Inc(L"MaskSelections");
  7991. ADirView->SelectFiles(Filter, Select);
  7992. ADirView->SetFocus();
  7993. }
  7994. }
  7995. //---------------------------------------------------------------------------
  7996. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7997. {
  7998. TCustomDirView * ADirView = DirView(Side);
  7999. ADirView->RestoreSelectedNames();
  8000. ADirView->SetFocus();
  8001. }
  8002. //---------------------------------------------------------------------------
  8003. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  8004. {
  8005. TCustomDirView * CurrentDirView = DirView(osCurrent);
  8006. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  8007. {
  8008. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  8009. UnicodeString Ext;
  8010. if (!IsSideLocalBrowser(osCurrent))
  8011. {
  8012. Ext = UnixExtractFileExt(FileName);
  8013. }
  8014. else
  8015. {
  8016. Ext = ExtractFileExt(FileName);
  8017. }
  8018. if (Ext.IsEmpty())
  8019. {
  8020. Ext = L".";
  8021. }
  8022. TFileFilter Filter;
  8023. Filter.Masks = FORMAT(L"*%s", (Ext));
  8024. Filter.Directories = false;
  8025. CurrentDirView->SelectFiles(Filter, Select);
  8026. }
  8027. }
  8028. //---------------------------------------------------------------------------
  8029. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  8030. const TStatusFileInfo & FileInfo, TOperationSide Side)
  8031. {
  8032. UnicodeString Result;
  8033. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  8034. {
  8035. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  8036. }
  8037. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  8038. {
  8039. // noop
  8040. }
  8041. else
  8042. {
  8043. Result =
  8044. FMTLOAD(FILE_INFO_FORMAT,
  8045. (FormatBytes(FileInfo.SelectedSize),
  8046. FormatBytes(FileInfo.FilesSize),
  8047. FormatNumber(FileInfo.SelectedCount),
  8048. FormatNumber(FileInfo.FilesCount)));
  8049. }
  8050. return Result;
  8051. }
  8052. //---------------------------------------------------------------------------
  8053. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8054. TTBXStatusPanel * Panel, TOperationSide Side)
  8055. {
  8056. if (Panel->Index == 1)
  8057. {
  8058. ToggleShowHiddenFiles();
  8059. }
  8060. else if (Panel->Index == 2)
  8061. {
  8062. Filter(Side);
  8063. }
  8064. }
  8065. //---------------------------------------------------------------------------
  8066. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8067. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8068. {
  8069. DebugAssert(!StatusBar->SimplePanel);
  8070. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8071. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8072. }
  8073. //---------------------------------------------------------------------------
  8074. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8075. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8076. {
  8077. DebugAssert(StatusBar->Panels->Count >= 3);
  8078. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8079. if (FileInfo.HiddenCount > 0)
  8080. {
  8081. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8082. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8083. }
  8084. else
  8085. {
  8086. HiddenFilesPanel->ViewPriority = 0;
  8087. // not really necessary, just to cleanup no-longer-valid data
  8088. HiddenFilesPanel->Caption = L"";
  8089. }
  8090. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8091. if (FileInfo.FilteredCount > 0)
  8092. {
  8093. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8094. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8095. }
  8096. else
  8097. {
  8098. FilteredFilesPanel->ViewPriority = 0;
  8099. // not really necessary, just to cleanup no-longer-valid data
  8100. FilteredFilesPanel->Caption = L"";
  8101. }
  8102. }
  8103. //---------------------------------------------------------------------------
  8104. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8105. TObject * /*Sender*/)
  8106. {
  8107. if (DirView(osOther)->Enabled)
  8108. {
  8109. DirView(osOther)->SetFocus();
  8110. }
  8111. }
  8112. //---------------------------------------------------------------------------
  8113. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8114. {
  8115. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8116. switch (Config.Show)
  8117. {
  8118. case qvShow:
  8119. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8120. {
  8121. Config.Show = qvHide;
  8122. }
  8123. else
  8124. {
  8125. Config.Show = Config.LastHideShow;
  8126. }
  8127. break;
  8128. case qvHideWhenEmpty:
  8129. if (ComponentVisible[fcQueueView])
  8130. {
  8131. Config.Show = qvHide;
  8132. }
  8133. else
  8134. {
  8135. Config.LastHideShow = Config.Show;
  8136. Config.Show = qvShow;
  8137. }
  8138. break;
  8139. case qvHide:
  8140. Config.LastHideShow = Config.Show;
  8141. Config.Show = qvShow;
  8142. break;
  8143. }
  8144. WinConfiguration->QueueView = Config;
  8145. }
  8146. //---------------------------------------------------------------------------
  8147. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8148. {
  8149. UnicodeString Result;
  8150. if (Terminal != NULL)
  8151. {
  8152. switch (WinConfiguration->PathInCaption)
  8153. {
  8154. case picShort:
  8155. Result = TTerminalManager::Instance()->GetTerminalShortPath(Terminal);
  8156. break;
  8157. case picFull:
  8158. Result = Terminal->CurrentDirectory;
  8159. break;
  8160. }
  8161. }
  8162. return Result;
  8163. }
  8164. //---------------------------------------------------------------------------
  8165. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8166. {
  8167. TColor Result = GetWindowColor(FSessionColor);
  8168. return Result;
  8169. }
  8170. //---------------------------------------------------------------------------
  8171. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8172. {
  8173. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8174. return Result;
  8175. }
  8176. //---------------------------------------------------------------------------
  8177. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8178. {
  8179. TTerminalManager::Instance()->UpdateAppTitle();
  8180. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8181. // background to gray on Windows 7 (works on Windows 10).
  8182. // See also EnableControl
  8183. if (Showing)
  8184. {
  8185. if (Terminal != NULL)
  8186. {
  8187. // Update path when it changes
  8188. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabSession(SessionsPageControl->ActivePage) == Terminal))
  8189. {
  8190. UpdateSessionTab(SessionsPageControl->ActivePage);
  8191. }
  8192. }
  8193. NonVisualDataModule->ReconnectSessionAction->Update();
  8194. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8195. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8196. CenterReconnectToolbar();
  8197. bool HasTerminal = HasActiveTerminal();
  8198. RemoteDirView->Enabled = HasTerminal;
  8199. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8200. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8201. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8202. RemoteDriveView->Color = RemoteDirView->Color;
  8203. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8204. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8205. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8206. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8207. QueueFileList->Enabled = QueueView3->Enabled;
  8208. QueueFileList->Color = QueueView3->Color;
  8209. QueueFileList->Font->Color = QueueView3->Font->Color;
  8210. QueueLabelUpdateStatus();
  8211. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8212. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8213. if (FImmersiveDarkMode != WinConfiguration->UseDarkTheme())
  8214. {
  8215. UpdateDarkMode();
  8216. }
  8217. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8218. }
  8219. }
  8220. //---------------------------------------------------------------------------
  8221. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8222. {
  8223. UpdateControls();
  8224. }
  8225. //---------------------------------------------------------------------------
  8226. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8227. TObject * Sender)
  8228. {
  8229. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8230. DebugAssert(DirView != NULL);
  8231. DoDirViewLoaded(DirView);
  8232. TransferPresetAutoSelect();
  8233. }
  8234. //---------------------------------------------------------------------------
  8235. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8236. {
  8237. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8238. // first run after installation
  8239. if (double(Updates.LastCheck) == 0)
  8240. {
  8241. // make sure next time there will be an update (if enabled)
  8242. Updates.LastCheck = TDateTime(1);
  8243. WinConfiguration->Updates = Updates;
  8244. }
  8245. else if ((double(Updates.Period) > 0) &&
  8246. (Now() - Updates.LastCheck >= Updates.Period))
  8247. {
  8248. TThreadMethod OnUpdatesChecked = NULL;
  8249. if (!IsUWP())
  8250. {
  8251. OnUpdatesChecked = UpdatesChecked;
  8252. }
  8253. StartUpdateThread(OnUpdatesChecked);
  8254. }
  8255. }
  8256. //---------------------------------------------------------------------------
  8257. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8258. {
  8259. UnicodeString Message;
  8260. bool New;
  8261. TQueryType Type;
  8262. GetUpdatesMessage(Message, New, Type, false);
  8263. if (!Message.IsEmpty())
  8264. {
  8265. if (New)
  8266. {
  8267. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8268. }
  8269. if (!New && (Type != qtWarning))
  8270. {
  8271. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8272. }
  8273. else
  8274. {
  8275. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8276. }
  8277. if (New)
  8278. {
  8279. Configuration->Usage->Inc(L"UpdateNotifications");
  8280. }
  8281. }
  8282. }
  8283. //---------------------------------------------------------------------------
  8284. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8285. {
  8286. RestoreApp();
  8287. bool CanDisplay = !NonVisualDataModule->Busy;
  8288. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8289. {
  8290. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8291. }
  8292. if (CanDisplay)
  8293. {
  8294. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8295. CheckForUpdates(true);
  8296. }
  8297. else
  8298. {
  8299. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8300. }
  8301. }
  8302. //---------------------------------------------------------------------------
  8303. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8304. TCopyParamRuleData & Data)
  8305. {
  8306. DebugAssert(Terminal != NULL);
  8307. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8308. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8309. Data.RemoteDirectory = RemoteDirView->PathName;
  8310. }
  8311. //---------------------------------------------------------------------------
  8312. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8313. {
  8314. // Terminal can be null when we are changing local directory implicitly,
  8315. // because it has been deleted, while no session is connected
  8316. // (Login dialog is open)
  8317. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8318. {
  8319. DebugAssert(!IsLocalBrowserMode());
  8320. TCopyParamRuleData Data;
  8321. GetTransferPresetAutoSelectData(Data);
  8322. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8323. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8324. if (CopyParamIndex < 0)
  8325. {
  8326. // there is no preset that matches autoselection
  8327. // set preset that we consider "default"
  8328. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8329. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8330. }
  8331. else
  8332. {
  8333. // there is preset matching autoselection
  8334. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8335. if (CopyParamName == FCopyParamAutoSelected)
  8336. {
  8337. // autoselected the same preset as the last time
  8338. // make no change (i.e. preserve custom user preset, if any)
  8339. }
  8340. else
  8341. {
  8342. // autoselected the different preset then the last time (or there
  8343. // was default preset set)
  8344. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8345. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8346. }
  8347. }
  8348. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8349. {
  8350. if (CopyParamIndex >= 0)
  8351. {
  8352. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8353. }
  8354. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8355. try
  8356. {
  8357. int Fmt =
  8358. (CopyParamIndex < 0) ?
  8359. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8360. COPY_PARAM_AUTOSELECTED;
  8361. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8362. Data->Message = MainInstructions(Message);
  8363. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8364. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8365. CopyParamAttrs);
  8366. if (CopyParamIndex >= 0)
  8367. {
  8368. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8369. Info = FORMAT(L"%s\n \n%s", (Info,
  8370. FMTLOAD(COPY_PARAM_RULE,
  8371. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8372. }
  8373. Data->Message += L"\n\n" + Info;
  8374. if (WinConfiguration->CopyParamAutoSelectNotice)
  8375. {
  8376. TransferPresetNoteMessage(Data, true);
  8377. }
  8378. else
  8379. {
  8380. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8381. Data = NULL; // ownership passed
  8382. }
  8383. }
  8384. __finally
  8385. {
  8386. delete Data;
  8387. }
  8388. }
  8389. }
  8390. }
  8391. //---------------------------------------------------------------------------
  8392. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8393. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8394. {
  8395. DebugAssert(NoteData != NULL);
  8396. DebugAssert(!IsLocalBrowserMode());
  8397. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8398. TQueryButtonAlias Aliases[1];
  8399. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8400. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8401. Params.Aliases = Aliases;
  8402. Params.AliasesCount = LENOF(Aliases);
  8403. unsigned int Result =
  8404. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8405. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8406. switch (Result)
  8407. {
  8408. case qaNeverAskAgain:
  8409. DebugAssert(AllowNeverAskAgain);
  8410. WinConfiguration->CopyParamAutoSelectNotice = false;
  8411. break;
  8412. case qaIgnore:
  8413. PreferencesDialog(pmPresets);
  8414. break;
  8415. }
  8416. }
  8417. //---------------------------------------------------------------------------
  8418. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8419. {
  8420. // as of now useless, as this is used for notes only, never for balloons, ...
  8421. RestoreApp();
  8422. // .. and we should never be busy here
  8423. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8424. {
  8425. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8426. }
  8427. }
  8428. //---------------------------------------------------------------------------
  8429. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8430. TPreferencesMode APreferencesMode)
  8431. {
  8432. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8433. TCopyParamRuleData Data;
  8434. if (Terminal != NULL)
  8435. {
  8436. PreferencesData.reset(new TPreferencesDialogData());
  8437. GetTransferPresetAutoSelectData(Data);
  8438. PreferencesData->CopyParamRuleData = &Data;
  8439. }
  8440. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8441. }
  8442. //---------------------------------------------------------------------------
  8443. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8444. const TCustomCommandType & Command)
  8445. {
  8446. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8447. {
  8448. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8449. }
  8450. }
  8451. //---------------------------------------------------------------------------
  8452. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8453. {
  8454. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8455. TCustomCommandType Command;
  8456. // make sure we use local custom command when remote are not supported
  8457. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8458. {
  8459. Command = FLastCustomCommand;
  8460. }
  8461. else
  8462. {
  8463. Command.Params = Command.Params | ccLocal;
  8464. }
  8465. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8466. FEditingFocusedAdHocCommand = OnFocused;
  8467. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8468. int Options =
  8469. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8470. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8471. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8472. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8473. {
  8474. FLastCustomCommand = Command;
  8475. UpdateCustomCommandsToolbar();
  8476. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8477. }
  8478. }
  8479. //---------------------------------------------------------------------------
  8480. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8481. {
  8482. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8483. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8484. DebugAssert(State > 0);
  8485. if (State <= 0)
  8486. {
  8487. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8488. }
  8489. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8490. }
  8491. //---------------------------------------------------------------------------
  8492. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8493. TCustomCommandType & Command, int & State)
  8494. {
  8495. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8496. if (Result)
  8497. {
  8498. Command = FLastCustomCommand;
  8499. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8500. }
  8501. return Result;
  8502. }
  8503. //---------------------------------------------------------------------------
  8504. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8505. {
  8506. ResetIncrementalSearch();
  8507. }
  8508. //---------------------------------------------------------------------------
  8509. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8510. {
  8511. DebugAssert(ComponentVisible[Component]);
  8512. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8513. }
  8514. //---------------------------------------------------------------------------
  8515. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8516. {
  8517. // when queue panel is resized here directly, the status bar is stretched
  8518. // over whole space the panel occupied
  8519. PostComponentHide(fcQueueView);
  8520. }
  8521. //---------------------------------------------------------------------------
  8522. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8523. {
  8524. ComponentVisible[fcQueueFileList] = false;
  8525. }
  8526. //---------------------------------------------------------------------------
  8527. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8528. {
  8529. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8530. RefreshColorMode();
  8531. ResetSysDarkTheme();
  8532. ConfigurationChanged();
  8533. ConfigureInterface();
  8534. // Should be called for all controls
  8535. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8536. }
  8537. //---------------------------------------------------------------------------
  8538. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8539. {
  8540. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8541. if (!FInvalid &&
  8542. (Message.LParam != 0) &&
  8543. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8544. {
  8545. ThemeChanged();
  8546. }
  8547. TForm::Dispatch(&Message);
  8548. }
  8549. //---------------------------------------------------------------------------
  8550. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8551. {
  8552. TMessage * M = static_cast<TMessage*>(Message);
  8553. switch (M->Msg)
  8554. {
  8555. case CM_DIALOGCHAR:
  8556. CMDialogChar(*M);
  8557. break;
  8558. case WM_APPCOMMAND:
  8559. WMAppCommand(*M);
  8560. break;
  8561. case WM_SYSCOMMAND:
  8562. WMSysCommand(*M);
  8563. break;
  8564. case WM_QUERYENDSESSION:
  8565. WMQueryEndSession(*M);
  8566. break;
  8567. case WM_ENDSESSION:
  8568. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8569. break;
  8570. #ifdef _DEBUG
  8571. case WM_WINDOWPOSCHANGED:
  8572. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8573. break;
  8574. case CM_CUSTOMSTYLECHANGED:
  8575. TForm::Dispatch(Message);
  8576. break;
  8577. #endif
  8578. case WM_COMPONENT_HIDE:
  8579. {
  8580. Byte Component = static_cast<Byte>(M->WParam);
  8581. // sanity check
  8582. if (ComponentVisible[Component])
  8583. {
  8584. // special treatment
  8585. if (Component == fcQueueView)
  8586. {
  8587. ToggleQueueVisibility();
  8588. DebugAssert(!ComponentVisible[fcQueueView]);
  8589. }
  8590. else
  8591. {
  8592. ComponentVisible[Component] = false;
  8593. }
  8594. }
  8595. }
  8596. break;
  8597. case WM_COPYDATA:
  8598. WMCopyData(*M);
  8599. break;
  8600. case WM_MANAGES_CAPTION:
  8601. // caption managed in TTerminalManager::UpdateAppTitle()
  8602. M->Result = 1;
  8603. break;
  8604. case WM_WANTS_MOUSEWHEEL:
  8605. M->Result = 1;
  8606. break;
  8607. case CM_SHOWINGCHANGED:
  8608. CMShowingChanged(*M);
  8609. break;
  8610. case WM_CLOSE:
  8611. WMClose(*M);
  8612. break;
  8613. case WM_DPICHANGED:
  8614. WMDpiChanged(*M);
  8615. break;
  8616. case CM_DPICHANGED:
  8617. CMDpiChanged(*M);
  8618. break;
  8619. case WM_SETTINGCHANGE:
  8620. WMSettingChange(*M);
  8621. break;
  8622. case CM_DIALOGKEY:
  8623. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8624. break;
  8625. default:
  8626. TForm::Dispatch(Message);
  8627. break;
  8628. }
  8629. }
  8630. //---------------------------------------------------------------------------
  8631. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8632. {
  8633. // noop
  8634. }
  8635. //---------------------------------------------------------------------------
  8636. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8637. {
  8638. TForm::Dispatch(&Message);
  8639. FSessionColors->Clear();
  8640. AddFixedSessionImages();
  8641. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8642. UpdateImages();
  8643. }
  8644. //---------------------------------------------------------------------------
  8645. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8646. {
  8647. TForm::Dispatch(&Message);
  8648. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8649. UpdatePixelsPerInchMainWindowCounter();
  8650. }
  8651. //---------------------------------------------------------------------------
  8652. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8653. {
  8654. // Cannot close window while we are busy.
  8655. // We cannot test this in FormCloseQuery as that is called also from
  8656. // Close(), which is called by CloseApplicationAction. So we can be busy
  8657. // there already even, when it is legitimate to close the application.
  8658. // Possibly a better place to handle this would be WMSysCommand.
  8659. if (NonVisualDataModule->Busy)
  8660. {
  8661. Message.Result = 1;
  8662. }
  8663. else
  8664. {
  8665. TForm::Dispatch(&Message);
  8666. }
  8667. }
  8668. //---------------------------------------------------------------------------
  8669. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8670. {
  8671. TForm::Dispatch(&Message);
  8672. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  8673. if (Showing && !FStarted)
  8674. {
  8675. FStarted = true;
  8676. InterfaceStarted();
  8677. }
  8678. if (Showing && (Terminal == NULL))
  8679. {
  8680. // When we are starting minimized (i.e. from an installer),
  8681. // postpone showing Login dialog until we get restored.
  8682. // Otherwise the Login dialog (and Authentication window) show restored
  8683. // over invisible (minimized) main window.
  8684. if (WindowState == wsMinimized)
  8685. {
  8686. FNeedSession = true;
  8687. }
  8688. else
  8689. {
  8690. // This happens before application ever goes idle, so the toolbars would
  8691. // stay enabled (initial state) until the Login dialog is dismissed.
  8692. UpdateActions();
  8693. NonVisualDataModule->StartBusy();
  8694. try
  8695. {
  8696. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8697. // otherwise the dialog does not receive focus.
  8698. // With Commander interface the ProcessMessages is called already
  8699. // by TDriveView, but with Explorer interface, we need to call it explicily
  8700. Application->ProcessMessages();
  8701. // do not reload sessions, they have been loaded just now (optimization)
  8702. NeedSession(true);
  8703. }
  8704. __finally
  8705. {
  8706. NonVisualDataModule->EndBusy();
  8707. }
  8708. }
  8709. }
  8710. }
  8711. //---------------------------------------------------------------------------
  8712. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8713. {
  8714. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8715. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8716. }
  8717. //---------------------------------------------------------------------------
  8718. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8719. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8720. int & MaxHeight)
  8721. {
  8722. // workaround for bug in TWinControl.CalcConstraints
  8723. // Check for empty rect (restore from iconic state) is done there only after
  8724. // call to AdjustClientRect, which enlarges the rect (for forms).
  8725. TRect R = GetClientRect();
  8726. // when restoring from iconic state, place no restrictions
  8727. if (IsRectEmpty(R))
  8728. {
  8729. MinWidth = 0;
  8730. MinHeight = 0;
  8731. MaxWidth = 32000;
  8732. MaxHeight = 32000;
  8733. }
  8734. }
  8735. //---------------------------------------------------------------------------
  8736. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8737. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8738. {
  8739. // terminal can be already closed (e.g. dropped connection)
  8740. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8741. {
  8742. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8743. try
  8744. {
  8745. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8746. }
  8747. catch(...)
  8748. {
  8749. if (!Terminal->Active)
  8750. {
  8751. Close = true;
  8752. }
  8753. throw;
  8754. }
  8755. }
  8756. }
  8757. //---------------------------------------------------------------------------
  8758. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8759. {
  8760. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8761. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8762. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8763. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8764. {
  8765. OnGetSpaceAvailable = GetSpaceAvailable;
  8766. }
  8767. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8768. OnGetSpaceAvailable);
  8769. }
  8770. //---------------------------------------------------------------------------
  8771. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8772. {
  8773. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8774. Terminal->FillSessionDataForCode(Data.get());
  8775. return Data.release();
  8776. }
  8777. //---------------------------------------------------------------------------
  8778. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8779. {
  8780. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8781. DoGenerateUrlDialog(Data.get(), Paths);
  8782. }
  8783. //---------------------------------------------------------------------------
  8784. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8785. {
  8786. GenerateUrl(NULL);
  8787. }
  8788. //---------------------------------------------------------------------------
  8789. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8790. {
  8791. std::unique_ptr<TStrings> Paths(new TStringList());
  8792. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8793. GenerateUrl(Paths.get());
  8794. }
  8795. //---------------------------------------------------------------------------
  8796. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8797. {
  8798. FSessionColor = value;
  8799. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8800. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8801. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8802. DebugAssert(ColorItem != NULL);
  8803. ColorItem->Color = C;
  8804. NonVisualDataModule->ColorMenuItem->Color = C;
  8805. UpdateControls();
  8806. }
  8807. //---------------------------------------------------------------------------
  8808. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8809. {
  8810. if (value != FSessionColor)
  8811. {
  8812. UpdateSessionColor(value);
  8813. // Is null when called from LastTerminalClosed
  8814. if (Terminal != NULL)
  8815. {
  8816. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8817. }
  8818. }
  8819. }
  8820. //---------------------------------------------------------------------------
  8821. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8822. {
  8823. bool Result = FNoteTimer->Enabled;
  8824. if (Result)
  8825. {
  8826. // cannot cancel note too early
  8827. bool NotEarly =
  8828. (Now() - FNoteShown >
  8829. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8830. if (Force || NotEarly)
  8831. {
  8832. FNoteTimer->Enabled = false;
  8833. FNote = L"";
  8834. SAFE_DESTROY(FNoteData);
  8835. FOnNoteClick = NULL;
  8836. FNoteHints = FNotes->Text;
  8837. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8838. UpdateStatusBar();
  8839. }
  8840. }
  8841. return Result;
  8842. }
  8843. //---------------------------------------------------------------------------
  8844. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8845. {
  8846. DebugAssert(FNoteTimer->Enabled);
  8847. CancelNote(true);
  8848. }
  8849. //---------------------------------------------------------------------------
  8850. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  8851. {
  8852. FNoteHints = FNotes->Text.TrimRight();
  8853. }
  8854. //---------------------------------------------------------------------------
  8855. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8856. {
  8857. int P = Note.Pos(L"\n");
  8858. if (P > 0)
  8859. {
  8860. Note.SetLength(P - 1);
  8861. }
  8862. FNotes->Add(FORMAT(L"[%s] %s",
  8863. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8864. while (FNotes->Count > 10)
  8865. {
  8866. FNotes->Delete(0);
  8867. }
  8868. if (UpdateNow)
  8869. {
  8870. UpdateNoteHints();
  8871. UpdateStatusBar();
  8872. }
  8873. }
  8874. //---------------------------------------------------------------------------
  8875. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8876. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8877. {
  8878. int P = Note.Pos(L"\n");
  8879. if (P > 0)
  8880. {
  8881. Note.SetLength(P - 1);
  8882. }
  8883. UpdateNoteHints();
  8884. FNote = Note;
  8885. SAFE_DESTROY(FNoteData);
  8886. FNoteData = NoteData;
  8887. FOnNoteClick = OnNoteClick;
  8888. AddNote(Note, false);
  8889. UpdateStatusBar();
  8890. FNoteShown = Now();
  8891. FNoteTimer->Enabled = false;
  8892. if (Seconds == 0)
  8893. {
  8894. Seconds = WinConfiguration->NotificationsTimeout;
  8895. }
  8896. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8897. FNoteTimer->Enabled = true;
  8898. }
  8899. //---------------------------------------------------------------------------
  8900. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8901. {
  8902. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8903. }
  8904. //---------------------------------------------------------------------------
  8905. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8906. {
  8907. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  8908. {
  8909. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8910. }
  8911. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8912. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8913. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  8914. 0, NULL, NULL);
  8915. }
  8916. //---------------------------------------------------------------------------
  8917. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8918. {
  8919. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8920. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8921. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8922. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  8923. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8924. }
  8925. //---------------------------------------------------------------------------
  8926. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8927. {
  8928. WinConfiguration->FormatSizeBytes = Style;
  8929. }
  8930. //---------------------------------------------------------------------------
  8931. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8932. {
  8933. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8934. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8935. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8936. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8937. }
  8938. //---------------------------------------------------------------------------
  8939. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8940. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8941. {
  8942. if (Panel->Index == 0)
  8943. {
  8944. if (FOnNoteClick != NULL)
  8945. {
  8946. // prevent the user data from being freed by possible call
  8947. // to CancelNote or PostNote during call to OnNoteClick
  8948. std::unique_ptr<TObject> NoteData(FNoteData);
  8949. TNotifyEvent OnNoteClick = FOnNoteClick;
  8950. FNoteData = NULL;
  8951. // need to cancel the note as we are going to delete its user data
  8952. CancelNote(true);
  8953. OnNoteClick(NoteData.get());
  8954. }
  8955. }
  8956. if (HasActiveTerminal() &&
  8957. (Panel->Index >= Sender->Panels->Count - SessionPanelCount))
  8958. {
  8959. FileSystemInfo();
  8960. }
  8961. }
  8962. //---------------------------------------------------------------------------
  8963. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8964. {
  8965. // workaround:
  8966. // 1) for unknown reason, disabling window, while minimized,
  8967. // prevents it from restoring, even if it was enabled again meanwhile
  8968. // 2) when disabling the main window, while another has focus
  8969. // minimize is no longer possible
  8970. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8971. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8972. // Shouldn't we use IsApplicationMinimized() here?
  8973. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8974. {
  8975. Enabled = false;
  8976. }
  8977. FLockLevel++;
  8978. }
  8979. //---------------------------------------------------------------------------
  8980. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8981. {
  8982. DebugAssert(FLockLevel > 0);
  8983. FLockLevel--;
  8984. if (FLockLevel == 0)
  8985. {
  8986. DebugAssert(FLockSuspendLevel == 0);
  8987. Enabled = true;
  8988. }
  8989. }
  8990. //---------------------------------------------------------------------------
  8991. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8992. {
  8993. // We need to make sure that window is enabled when the last modal window closes
  8994. // otherwise focus is not restored correctly.
  8995. // So we re-enable the window when modal window opens and
  8996. // disable it back after is closes
  8997. if (FLockLevel > 0)
  8998. {
  8999. // while we have nesting counter, we know that we never be called
  9000. // recursivelly as Application->OnModalBegin is called only
  9001. // for the top-level modal window
  9002. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9003. {
  9004. // won't be disabled when conditions in LockWindow() were not satisfied
  9005. FDisabledOnLockSuspend = !Enabled;
  9006. // When minimized to tray (or actually when set to SW_HIDE),
  9007. // setting Enabled makes the window focusable even when there's
  9008. // modal window over it
  9009. if (!FTrayIcon->Visible)
  9010. {
  9011. Enabled = true;
  9012. }
  9013. }
  9014. FLockSuspendLevel++;
  9015. }
  9016. }
  9017. //---------------------------------------------------------------------------
  9018. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  9019. {
  9020. if (FLockSuspendLevel > 0)
  9021. {
  9022. DebugAssert(FLockLevel > 0);
  9023. FLockSuspendLevel--;
  9024. // see comment in SuspendWindowLock
  9025. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9026. {
  9027. // Note that window can be enabled here, when we were minized to tray when
  9028. // was SuspendWindowLock() called.
  9029. // We should possibly do the same check as in LockWindow(),
  9030. // if it is ever possible that the consitions change between
  9031. // SuspendWindowLock() and ResumeWindowLock()
  9032. Enabled = !FDisabledOnLockSuspend;
  9033. }
  9034. }
  9035. }
  9036. //---------------------------------------------------------------------------
  9037. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9038. {
  9039. TTBXComboBoxItem * RemotePathComboBox =
  9040. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9041. if (!TextOnly)
  9042. {
  9043. TStrings * Items = RemotePathComboBox->Strings;
  9044. Items->BeginUpdate();
  9045. try
  9046. {
  9047. Items->Clear();
  9048. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9049. {
  9050. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9051. while (!IsUnixRootPath(APath))
  9052. {
  9053. int P = APath.LastDelimiter(L'/');
  9054. DebugAssert(P >= 0);
  9055. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9056. APath.SetLength(P - 1);
  9057. }
  9058. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9059. }
  9060. }
  9061. __finally
  9062. {
  9063. Items->EndUpdate();
  9064. }
  9065. }
  9066. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9067. // Setting ItemIndex to -1 does not reset its text
  9068. if (RemotePathComboBox->Strings->Count == 0)
  9069. {
  9070. RemotePathComboBox->Text = L"";
  9071. }
  9072. }
  9073. //---------------------------------------------------------------------------
  9074. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9075. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9076. {
  9077. if (AIndex < 0)
  9078. {
  9079. AIndex = Sender->ItemIndex;
  9080. }
  9081. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9082. }
  9083. //---------------------------------------------------------------------------
  9084. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9085. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9086. int & ImageIndex)
  9087. {
  9088. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9089. }
  9090. //---------------------------------------------------------------------------
  9091. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9092. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9093. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9094. {
  9095. if (!IsLocalBrowserMode())
  9096. {
  9097. ARect.Left += (10 * AIndex);
  9098. }
  9099. }
  9100. //---------------------------------------------------------------------------
  9101. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9102. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9103. {
  9104. AWidth += (10 * AIndex);
  9105. }
  9106. //---------------------------------------------------------------------------
  9107. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9108. {
  9109. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9110. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9111. int Index = RemotePathComboBox->ItemIndex;
  9112. while (Index < RemotePathComboBox->Strings->Count - 1)
  9113. {
  9114. APath = UnixExtractFileDir(APath);
  9115. Index++;
  9116. }
  9117. // VanDyke style paths
  9118. if (APath.IsEmpty())
  9119. {
  9120. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9121. APath = ROOTDIRECTORY;
  9122. }
  9123. if (RemoteDirView->Path != APath)
  9124. {
  9125. RemoteDirView->Path = APath;
  9126. }
  9127. }
  9128. //---------------------------------------------------------------------------
  9129. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9130. {
  9131. DoRemotePathComboBoxItemClick(Sender);
  9132. }
  9133. //---------------------------------------------------------------------------
  9134. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9135. {
  9136. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9137. DebugUsedParam(Sender);
  9138. UpdateRemotePathComboBox(true);
  9139. }
  9140. //---------------------------------------------------------------------------
  9141. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9142. {
  9143. DoRemotePathComboBoxCancel(Sender);
  9144. }
  9145. //---------------------------------------------------------------------------
  9146. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9147. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9148. {
  9149. ResetIncrementalSearch();
  9150. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9151. DebugAssert(DirView != NULL);
  9152. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9153. {
  9154. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9155. // OnEditing is called also from TCustomListView::CanEdit
  9156. if (Edit != NULL)
  9157. {
  9158. EditSelectBaseName(Edit);
  9159. }
  9160. }
  9161. }
  9162. //---------------------------------------------------------------------------
  9163. //---------------------------------------------------------------------------
  9164. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9165. {
  9166. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9167. Result->AutoDetectDnD = false;
  9168. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9169. Result->RenderDataOn = rdoEnterAndDropSync;
  9170. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9171. return Result;
  9172. }
  9173. //---------------------------------------------------------------------------
  9174. void __fastcall TCustomScpExplorerForm::UpdateDarkMode()
  9175. {
  9176. if (IsWin10Build(2004))
  9177. {
  9178. FImmersiveDarkMode = WinConfiguration->UseDarkTheme();
  9179. BOOL DarkMode = FImmersiveDarkMode ? TRUE : FALSE;
  9180. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9181. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9182. }
  9183. }
  9184. //---------------------------------------------------------------------------
  9185. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9186. {
  9187. TForm::CreateWnd();
  9188. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9189. UpdateDarkMode();
  9190. if (FSessionsDragDropFilesEx == NULL)
  9191. {
  9192. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9193. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9194. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9195. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9196. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9197. }
  9198. if (FQueueDragDropFilesEx == NULL)
  9199. {
  9200. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9201. // No need to set OnDragOver as we do not have any restrictions
  9202. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9203. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9204. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9205. }
  9206. }
  9207. //---------------------------------------------------------------------------
  9208. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9209. {
  9210. TForm::DestroyWnd();
  9211. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9212. FQueueDragDropFilesEx->DragDropControl = NULL;
  9213. }
  9214. //---------------------------------------------------------------------------
  9215. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9216. {
  9217. SideEnter(FCurrentSide);
  9218. FEverShown = true;
  9219. }
  9220. //---------------------------------------------------------------------------
  9221. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9222. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9223. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9224. {
  9225. if (!NonVisualDataModule->Busy)
  9226. {
  9227. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9228. Configuration->Usage->Inc(L"FileFinds");
  9229. LockWindow(true);
  9230. NonVisualDataModule->StartBusy();
  9231. WinConfiguration->LockedInterface = true;
  9232. try
  9233. {
  9234. Terminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9235. }
  9236. __finally
  9237. {
  9238. WinConfiguration->LockedInterface = false;
  9239. NonVisualDataModule->EndBusy();
  9240. UnlockWindow();
  9241. }
  9242. }
  9243. }
  9244. //---------------------------------------------------------------------------
  9245. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9246. {
  9247. if (!NonVisualDataModule->Busy)
  9248. {
  9249. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9250. SetFocus();
  9251. RemoteDirView->Path = UnixExtractFilePath(Path);
  9252. UnicodeString FileName = UnixExtractFileName(Path);
  9253. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9254. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9255. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9256. if (Item == NULL)
  9257. {
  9258. ReloadDirectory(osRemote);
  9259. Item = RemoteDirView->FindFileItem(FileName);
  9260. }
  9261. if (Item != NULL)
  9262. {
  9263. RemoteDirView->ItemFocused = Item;
  9264. RemoteDirView->ItemFocused->MakeVisible(false);
  9265. RemoteDirView->SetFocus();
  9266. }
  9267. }
  9268. }
  9269. //---------------------------------------------------------------------------
  9270. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9271. {
  9272. bool Result = !NonVisualDataModule->Busy;
  9273. if (Result)
  9274. {
  9275. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9276. }
  9277. return Result;
  9278. }
  9279. //---------------------------------------------------------------------------
  9280. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9281. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9282. {
  9283. if (CanOperateOnFoundFiles(ATerminal))
  9284. {
  9285. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9286. FOnFileOperationFinished = OnFileOperationFinished;
  9287. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9288. }
  9289. }
  9290. //---------------------------------------------------------------------------
  9291. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9292. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9293. {
  9294. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9295. }
  9296. //---------------------------------------------------------------------------
  9297. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9298. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9299. {
  9300. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9301. }
  9302. //---------------------------------------------------------------------------
  9303. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9304. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9305. {
  9306. if (CanOperateOnFoundFiles(ATerminal))
  9307. {
  9308. for (int Index = 0; Index < FileList->Count; Index++)
  9309. {
  9310. UnicodeString FileName = FileList->Strings[Index];
  9311. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9312. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9313. OnFileOperationFinished(FileName, true);
  9314. }
  9315. }
  9316. }
  9317. //---------------------------------------------------------------------------
  9318. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9319. {
  9320. FFileFindTerminal = Terminal;
  9321. ShowFileFindDialog(
  9322. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9323. DoDownloadFoundFiles, DoEditFoundFiles);
  9324. }
  9325. //---------------------------------------------------------------------------
  9326. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9327. {
  9328. FTaskbarList = TaskbarList;
  9329. }
  9330. //---------------------------------------------------------------------------
  9331. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9332. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9333. {
  9334. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9335. if (Index >= 0)
  9336. {
  9337. if (Button == mbLeft)
  9338. {
  9339. // "Mouse down" is raised only after tab is switched.
  9340. // If switching tab (switching session) takes long enough for user
  9341. // to actually release the button, "mouse down" is still raised,
  9342. // but we do not get "mouse up" event, so dragging is not cancelled,
  9343. // prevent that by not beginning dragging in the first place.
  9344. if (IsKeyPressed(VK_LBUTTON))
  9345. {
  9346. // when user clicks the "+", we get mouse down only after the session
  9347. // is closed, when new session tab is already on X:Y, so dragging
  9348. // starts, prevent that
  9349. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9350. {
  9351. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9352. if (Terminal != NULL)
  9353. {
  9354. SessionsPageControl->BeginDrag(false);
  9355. }
  9356. }
  9357. }
  9358. }
  9359. else if (Button == mbMiddle)
  9360. {
  9361. // ignore middle-click for "New session tab"
  9362. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9363. if (Terminal != NULL)
  9364. {
  9365. CloseSessionTab(Index);
  9366. }
  9367. }
  9368. }
  9369. }
  9370. //---------------------------------------------------------------------------
  9371. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9372. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9373. {
  9374. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9375. // do not allow dropping on the "+" tab
  9376. TTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9377. if ((TargetTerminal != NULL) &&
  9378. (SessionsPageControl->ActivePage->PageIndex != Index))
  9379. {
  9380. Configuration->Usage->Inc(L"SessionTabMoves");
  9381. // this is almost redundant as we would recreate tabs in SessionListChanged,
  9382. // but we want to actually prevent that to avoid flicker
  9383. SessionsPageControl->ActivePage->PageIndex = Index;
  9384. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->ActivePage);
  9385. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9386. }
  9387. }
  9388. //---------------------------------------------------------------------------
  9389. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9390. TObject * Sender, TObject * Source, int X, int Y,
  9391. TDragState /*State*/, bool & Accept)
  9392. {
  9393. Accept = (Sender == Source);
  9394. if (Accept)
  9395. {
  9396. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9397. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9398. // do not allow dragging to the "+" tab
  9399. Accept = (Terminal != NULL);
  9400. }
  9401. }
  9402. //---------------------------------------------------------------------------
  9403. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9404. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9405. {
  9406. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9407. if (Index < 0)
  9408. {
  9409. Effect = DROPEFFECT_NONE;
  9410. }
  9411. else
  9412. {
  9413. TTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9414. // do not allow dropping on the "+" tab
  9415. if (TargetTerminal == NULL)
  9416. {
  9417. Effect = DROPEFFECT_NONE;
  9418. }
  9419. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9420. {
  9421. Effect = DROPEFFECT_COPY;
  9422. }
  9423. }
  9424. }
  9425. //---------------------------------------------------------------------------
  9426. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9427. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9428. {
  9429. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9430. // do not allow dropping on the "+" tab
  9431. TManagedTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9432. if (TargetTerminal != NULL)
  9433. {
  9434. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9435. if (!IsFileControl(DropSourceControl, osRemote))
  9436. {
  9437. TTerminalManager::Instance()->ActiveSession = TargetTerminal;
  9438. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9439. // Why don't we use Terminal->CurrentDirectory directly?
  9440. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9441. // do not force queue, drag drop
  9442. false, true);
  9443. }
  9444. }
  9445. }
  9446. //---------------------------------------------------------------------------
  9447. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9448. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9449. {
  9450. // Downloads are handled in RemoteFileControlDDEnd
  9451. if (!IsFileControl(DropSourceControl, osRemote))
  9452. {
  9453. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9454. Terminal->CurrentDirectory,
  9455. // force queue, drag drop
  9456. true, true);
  9457. }
  9458. }
  9459. //---------------------------------------------------------------------------
  9460. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9461. {
  9462. FShowing = false;
  9463. // Do not save empty workspace
  9464. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9465. {
  9466. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9467. UnicodeString Name = WorkspaceName();
  9468. DoSaveWorkspace(
  9469. Name, DataList.get(),
  9470. !Configuration->DisablePasswordStoring &&
  9471. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9472. WinConfiguration->LastStoredSession = Name;
  9473. }
  9474. }
  9475. //---------------------------------------------------------------------------
  9476. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9477. {
  9478. TManagedTerminal * ManagedTerminal =
  9479. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9480. if (ManagedTerminal != NULL)
  9481. {
  9482. ManagedTerminal->DirectoryLoaded = Now();
  9483. }
  9484. }
  9485. //---------------------------------------------------------------------------
  9486. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9487. TListItem * /*Item*/, bool /*Selected*/)
  9488. {
  9489. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9490. switch (DirView->LastSelectMethod)
  9491. {
  9492. case smKeyboard:
  9493. Configuration->Usage->Inc(L"KeyboardSelections");
  9494. break;
  9495. case smMouse:
  9496. Configuration->Usage->Inc(L"MouseSelections");
  9497. break;
  9498. }
  9499. }
  9500. //---------------------------------------------------------------------------
  9501. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9502. {
  9503. if (Color != 0)
  9504. {
  9505. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9506. }
  9507. else
  9508. {
  9509. return FSessionTabImageIndex;
  9510. }
  9511. }
  9512. //---------------------------------------------------------------------------
  9513. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9514. {
  9515. TPngImageCollectionItem * Item =
  9516. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9517. FSessionColors->AddPng(Item->PngImage);
  9518. return FSessionColors->Count - 1;
  9519. }
  9520. //---------------------------------------------------------------------------
  9521. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9522. {
  9523. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9524. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9525. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9526. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9527. }
  9528. //---------------------------------------------------------------------------
  9529. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9530. {
  9531. for (int Index = 0; Index < Control->ControlCount; Index++)
  9532. {
  9533. TControl * AControl = Control->Controls[Index];
  9534. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9535. if (WinControl != NULL)
  9536. {
  9537. CollectItemsWithTextDisplayMode(WinControl);
  9538. }
  9539. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9540. if (Toolbar != NULL)
  9541. {
  9542. // we care for top-level items only
  9543. TTBCustomItem * Items = Toolbar->Items;
  9544. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9545. {
  9546. TTBCustomItem * Item = Items->Items[ItemIndex];
  9547. if (((Item->DisplayMode == nbdmImageAndText) ||
  9548. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9549. EligibleForImageDisplayMode(Item))
  9550. {
  9551. FItemsWithTextDisplayMode.insert(Item);
  9552. }
  9553. }
  9554. }
  9555. }
  9556. }
  9557. //---------------------------------------------------------------------------
  9558. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9559. {
  9560. return true;
  9561. }
  9562. //---------------------------------------------------------------------------
  9563. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9564. {
  9565. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9566. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9567. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9568. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9569. bool Result = true;
  9570. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9571. {
  9572. TTBCustomItem * Item = *i;
  9573. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9574. if (Label != NULL)
  9575. {
  9576. // optimization
  9577. if (Label->Visible == SelectiveToolbarText)
  9578. {
  9579. Result = false;
  9580. }
  9581. else
  9582. {
  9583. Label->Visible = SelectiveToolbarText;
  9584. }
  9585. }
  9586. else
  9587. {
  9588. // optimization
  9589. if (Item->DisplayMode == DisplayMode)
  9590. {
  9591. Result = false;
  9592. }
  9593. else
  9594. {
  9595. Item->DisplayMode = DisplayMode;
  9596. }
  9597. }
  9598. ++i;
  9599. }
  9600. if (Result)
  9601. {
  9602. UpdateNewSessionTab();
  9603. }
  9604. return Result;
  9605. }
  9606. //---------------------------------------------------------------------------
  9607. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9608. {
  9609. DebugFail();
  9610. }
  9611. //---------------------------------------------------------------------------
  9612. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9613. {
  9614. // Among other, a lock level is non zero, while directory is being loaded,
  9615. // even when it happens as a result of dirview navigation,
  9616. // i.e. when TNonVisualDataModule is NOT FBusy.
  9617. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9618. // Among other this prevents a panel auto update to occur while
  9619. // directory is changing.
  9620. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9621. }
  9622. //---------------------------------------------------------------------------
  9623. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  9624. {
  9625. // While the window is disabled, we still seem to process menu shortcuts at least,
  9626. // so stop it at least here.
  9627. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9628. bool Result;
  9629. if (Allowed == aaUpdate)
  9630. {
  9631. Result = true;
  9632. }
  9633. else
  9634. {
  9635. Result = !NonVisualDataModule->Busy;
  9636. if (Result && (Allowed == aaShortCut))
  9637. {
  9638. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  9639. Action->Update();
  9640. Result = Action->Enabled;
  9641. }
  9642. }
  9643. return Result;
  9644. }
  9645. //---------------------------------------------------------------------------
  9646. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9647. {
  9648. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9649. }
  9650. //---------------------------------------------------------------------------
  9651. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9652. {
  9653. // This is somewhat redundant to LockWindow() call from
  9654. // TTerminalManager::TerminalReadDirectoryProgress.
  9655. // But disabling window is known not to block keyboard shorcuts
  9656. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9657. if (Busy > 0)
  9658. {
  9659. if (NonVisualDataModule->Busy)
  9660. {
  9661. State = false;
  9662. }
  9663. else
  9664. {
  9665. NonVisualDataModule->StartBusy();
  9666. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9667. LockWindow();
  9668. }
  9669. }
  9670. else if (Busy < 0)
  9671. {
  9672. UnlockWindow();
  9673. NonVisualDataModule->EndBusy();
  9674. }
  9675. else
  9676. {
  9677. State = NonVisualDataModule->Busy;
  9678. }
  9679. }
  9680. //---------------------------------------------------------------------------
  9681. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9682. {
  9683. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9684. // no context menu for "New session tab"
  9685. if ((Index >= 0) && (GetSessionTabSession(SessionsPageControl->Pages[Index]) != NULL))
  9686. {
  9687. SessionsPageControl->ActivePageIndex = Index;
  9688. if (DebugAlwaysTrue(SessionTabSwitched()))
  9689. {
  9690. // copied from TControl.WMContextMenu
  9691. SendCancelMode(SessionsPageControl);
  9692. // explicit popup instead of using PopupMenu property
  9693. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9694. // while connecting yet not-connected session and hence
  9695. // allowing an access to commands over not-completelly connected session
  9696. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9697. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9698. PopupMenu->PopupComponent = SessionsPageControl;
  9699. PopupMenu->Popup(Point.x, Point.y);
  9700. }
  9701. }
  9702. Handled = true;
  9703. }
  9704. //---------------------------------------------------------------------------
  9705. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9706. {
  9707. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9708. }
  9709. //---------------------------------------------------------------------------
  9710. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9711. {
  9712. Configuration->Usage->Inc(L"PasswordChanges");
  9713. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9714. ChangePasswordData->DisableAuthentationsExceptPassword();
  9715. ChangePasswordData->ChangePassword = true;
  9716. std::unique_ptr<TTerminal> ChangePasswordSession(
  9717. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9718. ChangePasswordSession->AutoReadDirectory = false;
  9719. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9720. {
  9721. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9722. }
  9723. else
  9724. {
  9725. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9726. }
  9727. }
  9728. //---------------------------------------------------------------------------
  9729. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9730. {
  9731. // No nice way to assert SSH2
  9732. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9733. }
  9734. //---------------------------------------------------------------------------
  9735. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9736. {
  9737. TOperationVisualizer OperationVisualizer;
  9738. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9739. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9740. }
  9741. //---------------------------------------------------------------------------
  9742. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9743. {
  9744. TForm::ChangeScale(M, D);
  9745. int APixelsPerInch = GetControlPixelsPerInch(this);
  9746. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9747. try
  9748. {
  9749. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9750. }
  9751. __finally
  9752. {
  9753. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9754. }
  9755. }
  9756. //---------------------------------------------------------------------------
  9757. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9758. {
  9759. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9760. }
  9761. //---------------------------------------------------------------------
  9762. class TPublicControl : public TControl
  9763. {
  9764. friend class TCustomScpExplorerForm;
  9765. };
  9766. //---------------------------------------------------------------------------
  9767. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9768. {
  9769. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9770. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9771. }
  9772. //---------------------------------------------------------------------------
  9773. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9774. {
  9775. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9776. OpenBookmark(Side, Bookmark);
  9777. }
  9778. //---------------------------------------------------------------------------
  9779. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9780. {
  9781. DoBookmarkClick(osLocal, Sender);
  9782. }
  9783. //---------------------------------------------------------------------------
  9784. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9785. {
  9786. DoBookmarkClick(osRemote, Sender);
  9787. }
  9788. //---------------------------------------------------------------------------
  9789. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9790. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9791. {
  9792. if (BookmarkList != NULL)
  9793. {
  9794. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9795. if (IsLocalBrowserMode())
  9796. {
  9797. Side = osLocal;
  9798. }
  9799. if (!WinConfiguration->UseLocationProfiles)
  9800. {
  9801. std::unique_ptr<TStringList> Directories(new TStringList());
  9802. Directories->CaseSensitive = (Side == osRemote);
  9803. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9804. {
  9805. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9806. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9807. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9808. {
  9809. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9810. Item->Caption = EscapeHotkey(Directory);
  9811. Item->ShortCut = Bookmark->ShortCut;
  9812. Item->OnClick = OnBookmarkClick;
  9813. Item->Tag = reinterpret_cast<int>(Bookmark);
  9814. Directories->Add(Directory);
  9815. Menu->Add(Item.release());
  9816. }
  9817. }
  9818. }
  9819. else
  9820. {
  9821. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9822. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9823. {
  9824. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9825. if (!Bookmark->Node.IsEmpty())
  9826. {
  9827. Folders->Add(Bookmark->Node);
  9828. }
  9829. }
  9830. for (int Index = 0; Index < Folders->Count; Index++)
  9831. {
  9832. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9833. Item->Caption = Folders->Strings[Index];
  9834. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  9835. Folders->Objects[Index] = Item.get();
  9836. Menu->Add(Item.release());
  9837. }
  9838. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9839. {
  9840. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9841. TTBCustomItem * Parent;
  9842. if (!Bookmark->Node.IsEmpty())
  9843. {
  9844. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9845. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9846. }
  9847. else
  9848. {
  9849. Parent = Menu;
  9850. }
  9851. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9852. Item->Caption = Bookmark->Name;
  9853. Item->ShortCut = Bookmark->ShortCut;
  9854. Item->OnClick = OnBookmarkClick;
  9855. Item->Tag = reinterpret_cast<int>(Bookmark);
  9856. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9857. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9858. {
  9859. // No hint for location profiles that are actually mere "bookmarks"
  9860. }
  9861. else
  9862. {
  9863. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9864. UnicodeString LongHint;
  9865. if (!Bookmark->Local.IsEmpty())
  9866. {
  9867. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9868. }
  9869. if (!Bookmark->Remote.IsEmpty())
  9870. {
  9871. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9872. }
  9873. AddToList(Hint, LongHint, L"|");
  9874. Item->Hint = Hint;
  9875. }
  9876. Parent->Add(Item.release());
  9877. }
  9878. }
  9879. AddMenuSeparator(Menu);
  9880. }
  9881. }
  9882. //---------------------------------------------------------------------------
  9883. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9884. {
  9885. Menu->Clear();
  9886. std::unique_ptr<TTBCustomItem> Item;
  9887. Item.reset(new TTBXItem(Owner));
  9888. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9889. Item->Options = Item->Options << tboDefault;
  9890. Menu->Add(Item.release());
  9891. AddMenuSeparator(Menu);
  9892. if (Terminal != NULL)
  9893. {
  9894. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9895. }
  9896. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9897. Item.reset(new TTBXItem(Owner));
  9898. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  9899. Menu->Add(Item.release());
  9900. }
  9901. //---------------------------------------------------------------------------
  9902. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9903. {
  9904. bool Result = true;
  9905. bool Remote = !IsSideLocalBrowser(Side);
  9906. try
  9907. {
  9908. if (Remote)
  9909. {
  9910. Terminal->ExceptionOnFail = true;
  9911. }
  9912. try
  9913. {
  9914. DirView(Side)->Path = Path;
  9915. }
  9916. __finally
  9917. {
  9918. if (Remote)
  9919. {
  9920. Terminal->ExceptionOnFail = false;
  9921. }
  9922. }
  9923. }
  9924. catch (Exception & E)
  9925. {
  9926. if (!Remote || Terminal->Active)
  9927. {
  9928. ShowExtendedExceptionEx(Terminal, &E);
  9929. Result = false;
  9930. }
  9931. else
  9932. {
  9933. throw;
  9934. }
  9935. }
  9936. return Result;
  9937. }
  9938. //---------------------------------------------------------------------------
  9939. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9940. {
  9941. // Make sure there some feedback even when loading tiny local folders
  9942. TInstantOperationVisualizer Visualizer;
  9943. DirView(Side)->ReloadDirectory();
  9944. }
  9945. //---------------------------------------------------------------------------
  9946. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9947. {
  9948. if (Index == SessionsPageControl->TabIndex)
  9949. {
  9950. CloseSession();
  9951. }
  9952. else
  9953. {
  9954. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9955. TTerminal * Terminal = GetSessionTabSession(TabSheet);
  9956. TTerminalManager * Manager = TTerminalManager::Instance();
  9957. if (!Terminal->Active)
  9958. {
  9959. Manager->FreeTerminal(Terminal);
  9960. }
  9961. else
  9962. {
  9963. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9964. if (CanCloseQueue(Queue))
  9965. {
  9966. Manager->FreeTerminal(Terminal);
  9967. }
  9968. }
  9969. }
  9970. }
  9971. //---------------------------------------------------------------------------
  9972. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9973. {
  9974. CloseSessionTab(Index);
  9975. }
  9976. //---------------------------------------------------------------------------
  9977. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9978. {
  9979. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9980. {
  9981. TInstantOperationVisualizer Visualizer;
  9982. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9983. // before we create a new data object
  9984. ClipboardClear();
  9985. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9986. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9987. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9988. // Intermediate variable to WORKAROUND a crash in compiler
  9989. TObjectList * ClipboardFakeMonitors =
  9990. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9991. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9992. if (FClipboardDragDropFilesEx.get() == NULL)
  9993. {
  9994. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9995. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9996. }
  9997. FClipboardDragDropFilesEx->FileList->Clear();
  9998. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9999. FClipboardDragDropFilesEx->CopyToClipboard();
  10000. FClipboardTerminal = Terminal;
  10001. // Need full paths, as cwd can be different once files are pasted
  10002. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  10003. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  10004. {
  10005. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  10006. }
  10007. }
  10008. }
  10009. //---------------------------------------------------------------------------
  10010. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  10011. {
  10012. if (OpenClipboard(0))
  10013. {
  10014. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  10015. CloseClipboard();
  10016. }
  10017. }
  10018. //---------------------------------------------------------------------------
  10019. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  10020. {
  10021. return !FClipboardFakeDirectory.IsEmpty();
  10022. }
  10023. //---------------------------------------------------------------------------
  10024. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  10025. {
  10026. RemoveDir(ApiPath(FClipboardFakeDirectory));
  10027. FClipboardFakeDirectory = UnicodeString();
  10028. FClipboardTerminal = NULL;
  10029. // Also called in Idle()
  10030. FClipboardFakeMonitors.reset(NULL);
  10031. }
  10032. //---------------------------------------------------------------------------
  10033. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  10034. {
  10035. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  10036. {
  10037. ClipboardStop();
  10038. }
  10039. }
  10040. //---------------------------------------------------------------------------
  10041. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  10042. {
  10043. TTerminalManager * Manager = TTerminalManager::Instance();
  10044. Manager->ActiveSession = FClipboardTerminal;
  10045. TTransferOperationParam Params;
  10046. Params.TargetDirectory = TargetDirectory;
  10047. Params.DragDrop = DragDrop;
  10048. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  10049. }
  10050. //---------------------------------------------------------------------------
  10051. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  10052. {
  10053. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  10054. // (as it pumps a Windows message queue while being shutted down)
  10055. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10056. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10057. {
  10058. // Can fail as it can be e.g. locked by AV, so we retry that later
  10059. bool Removed = RemoveDir(ApiPath(FileName));
  10060. try
  10061. {
  10062. if (!NonVisualDataModule->Busy)
  10063. {
  10064. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10065. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  10066. }
  10067. }
  10068. __finally
  10069. {
  10070. if (!Removed)
  10071. {
  10072. RemoveDir(ApiPath(FileName));
  10073. }
  10074. }
  10075. }
  10076. }
  10077. //---------------------------------------------------------------------------
  10078. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10079. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10080. {
  10081. TFileMasks::TParams MaskParams;
  10082. MaskParams.Size = Size;
  10083. MaskParams.Modification = Modification;
  10084. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10085. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10086. {
  10087. bool ImplicitMatch;
  10088. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  10089. !ImplicitMatch)
  10090. {
  10091. Color = Iter->Color;
  10092. break;
  10093. }
  10094. }
  10095. }
  10096. //---------------------------------------------------------------------------
  10097. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10098. {
  10099. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10100. if (!DirView->IsEditing())
  10101. {
  10102. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10103. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10104. // while searching
  10105. if (Key == VK_BACK)
  10106. {
  10107. if (!FIncrementalSearch.IsEmpty())
  10108. {
  10109. if (FIncrementalSearch.Length() == 1)
  10110. {
  10111. ResetIncrementalSearch();
  10112. }
  10113. else
  10114. {
  10115. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10116. IncrementalSearch(NewText, false, false);
  10117. }
  10118. Key = 0;
  10119. }
  10120. }
  10121. }
  10122. }
  10123. //---------------------------------------------------------------------------
  10124. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10125. {
  10126. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10127. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10128. {
  10129. // Filter control sequences.
  10130. // When not searching yet, prefer use of the space for toggling file selection
  10131. // (so we cannot incrementally search for a string starting with a space).
  10132. if ((Key > VK_SPACE) ||
  10133. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10134. {
  10135. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10136. Key = 0;
  10137. }
  10138. }
  10139. }
  10140. //---------------------------------------------------------------------------
  10141. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10142. {
  10143. if (!FIncrementalSearch.IsEmpty())
  10144. {
  10145. FIncrementalSearch = L"";
  10146. DirView(osCurrent)->UpdateStatusBar();
  10147. }
  10148. }
  10149. //---------------------------------------------------------------------------
  10150. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10151. {
  10152. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10153. if (Item == NULL)
  10154. {
  10155. MessageBeep(MB_ICONHAND);
  10156. }
  10157. else
  10158. {
  10159. TCustomDirView * ADirView = DirView(osCurrent);
  10160. {
  10161. TAutoNestingCounter Guard(FIncrementalSearching);
  10162. ADirView->FocusItem(Item);
  10163. if (ADirView->NortonLike == nlOff)
  10164. {
  10165. if ((ADirView->Selected != Item) ||
  10166. (ADirView->SelCount > 1))
  10167. {
  10168. ADirView->ClearSelection();
  10169. ADirView->Selected = Item;
  10170. }
  10171. }
  10172. }
  10173. FIncrementalSearch = Text;
  10174. Item->MakeVisible(false);
  10175. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10176. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10177. ADirView->UpdateStatusBar();
  10178. }
  10179. }
  10180. //---------------------------------------------------------------------------
  10181. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10182. {
  10183. int Index = Item->Index;
  10184. if (!Reverse)
  10185. {
  10186. Index++;
  10187. if (Index >= Item->Owner->Count)
  10188. {
  10189. Index = 0;
  10190. }
  10191. }
  10192. else
  10193. {
  10194. Index--;
  10195. if (Index < 0)
  10196. {
  10197. Index = Item->Owner->Count - 1;
  10198. }
  10199. }
  10200. return Item->Owner->Item[Index];
  10201. }
  10202. //---------------------------------------------------------------------------
  10203. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10204. {
  10205. TCustomDirView * ADirView = DirView(osCurrent);
  10206. if (ADirView->Items->Count == 0)
  10207. {
  10208. return NULL;
  10209. }
  10210. else
  10211. {
  10212. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10213. TListItem * Item = CurrentItem;
  10214. if (SkipCurrent)
  10215. {
  10216. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10217. }
  10218. while (true)
  10219. {
  10220. bool Matches = false;
  10221. switch (WinConfiguration->PanelSearch)
  10222. {
  10223. case isNameStartOnly:
  10224. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10225. break;
  10226. case isName:
  10227. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10228. break;
  10229. case isAll:
  10230. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10231. int Index = 0;
  10232. while ((Index < ColCount) && !Matches)
  10233. {
  10234. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10235. if (Visible)
  10236. {
  10237. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10238. }
  10239. Index++;
  10240. }
  10241. break;
  10242. }
  10243. if (Matches)
  10244. {
  10245. return Item;
  10246. }
  10247. Item = GetNextFile(Item, Reverse);
  10248. if (Item == CurrentItem)
  10249. {
  10250. return NULL;
  10251. }
  10252. }
  10253. }
  10254. }
  10255. //---------------------------------------------------------------------------
  10256. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10257. {
  10258. ResetIncrementalSearch();
  10259. }
  10260. //---------------------------------------------------------------------------
  10261. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10262. {
  10263. if (Message.CharCode == VK_TAB)
  10264. {
  10265. if (!FIncrementalSearch.IsEmpty())
  10266. {
  10267. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10268. bool Reverse = Shift.Contains(ssShift);
  10269. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10270. Message.Result = 1;
  10271. return;
  10272. }
  10273. }
  10274. else if (Message.CharCode == VK_ESCAPE)
  10275. {
  10276. if (!FIncrementalSearch.IsEmpty())
  10277. {
  10278. ResetIncrementalSearch();
  10279. Message.Result = 1;
  10280. return;
  10281. }
  10282. }
  10283. TForm::Dispatch(&Message);
  10284. }
  10285. //---------------------------------------------------------------------------
  10286. void __fastcall TCustomScpExplorerForm::Deactivate()
  10287. {
  10288. TForm::Deactivate();
  10289. // E.g. when switching to an internal editor window
  10290. ResetIncrementalSearch();
  10291. }
  10292. //---------------------------------------------------------------------------
  10293. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10294. {
  10295. // When switching to another application
  10296. ResetIncrementalSearch();
  10297. }
  10298. //---------------------------------------------------------------------------
  10299. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10300. {
  10301. ResetIncrementalSearch();
  10302. }
  10303. //---------------------------------------------------------------------------
  10304. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10305. {
  10306. if (FIncrementalSearching <= 0)
  10307. {
  10308. ResetIncrementalSearch();
  10309. }
  10310. }
  10311. //---------------------------------------------------------------------------
  10312. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10313. {
  10314. CountClicksForWindowPrint(this);
  10315. }
  10316. //---------------------------------------------------------------------------
  10317. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10318. {
  10319. CenterReconnectToolbar();
  10320. }
  10321. //---------------------------------------------------------------------------
  10322. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10323. {
  10324. if (RemoteDirView->ItemFocused != NULL)
  10325. {
  10326. RemoteDirView->ItemFocused->Selected = true;
  10327. }
  10328. }
  10329. //---------------------------------------------------------------------------
  10330. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10331. {
  10332. if (!FQueueStatusUpdating)
  10333. {
  10334. bool Refresh;
  10335. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10336. {
  10337. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10338. }
  10339. else
  10340. {
  10341. if (FQueueFileList->GetCount() > 0)
  10342. {
  10343. FQueueFileList->Clear();
  10344. Refresh = true;
  10345. }
  10346. }
  10347. int Count = FQueueFileList->GetCount();
  10348. if (QueueFileList->Items->Count != Count)
  10349. {
  10350. DebugAssert(Refresh);
  10351. QueueFileList->Items->Count = Count;
  10352. }
  10353. if (Refresh)
  10354. {
  10355. QueueFileList->Invalidate();
  10356. }
  10357. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10358. }
  10359. }
  10360. //---------------------------------------------------------------------------
  10361. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10362. {
  10363. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10364. }
  10365. //---------------------------------------------------------------------------
  10366. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10367. {
  10368. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10369. // See TSynchronizeChecklistDialog::UpdateTimer
  10370. if (QueueFileList->Items->Count > 0)
  10371. {
  10372. QueueFileList->Items->Item[0]->MakeVisible(false);
  10373. }
  10374. UpdateQueueFileList();
  10375. }
  10376. //---------------------------------------------------------------------------
  10377. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10378. {
  10379. Active = QueueView3->Focused() || QueueFileList->Focused();
  10380. }
  10381. //---------------------------------------------------------------------------
  10382. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10383. {
  10384. QueueLabelUpdateStatus();
  10385. }
  10386. //---------------------------------------------------------------------------
  10387. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10388. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10389. {
  10390. int State = FQueueFileList->GetState(Item->Index);
  10391. if (State == qfsProcessed)
  10392. {
  10393. Sender->Canvas->Font->Color = clGrayText;
  10394. }
  10395. }
  10396. //---------------------------------------------------------------------------
  10397. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10398. {
  10399. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10400. QueueFileList->Column[0]->Width =
  10401. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10402. }
  10403. //---------------------------------------------------------------------------
  10404. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10405. {
  10406. QueueFileListColumnAutoSize();
  10407. }
  10408. //---------------------------------------------------------------------------
  10409. void __fastcall TCustomScpExplorerForm::CloseApp()
  10410. {
  10411. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10412. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10413. // So we clear the flag here.
  10414. DebugAssert(NonVisualDataModule->Busy);
  10415. NonVisualDataModule->EndBusy();
  10416. try
  10417. {
  10418. Close();
  10419. }
  10420. __finally
  10421. {
  10422. NonVisualDataModule->StartBusy();
  10423. }
  10424. }
  10425. //---------------------------------------------------------------------------
  10426. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10427. {
  10428. return (Terminal != NULL) && Terminal->Active;
  10429. }
  10430. //---------------------------------------------------------------------------
  10431. bool __fastcall TCustomScpExplorerForm::HasManagedSession()
  10432. {
  10433. return (ManagedSession != NULL);
  10434. }
  10435. //---------------------------------------------------------------------------
  10436. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10437. {
  10438. return IsActiveTerminal(Terminal);
  10439. }
  10440. //---------------------------------------------------------------------------
  10441. void TCustomScpExplorerForm::LocalLocalCopy(
  10442. TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused), bool DebugUsedArg(NoConfirmation),
  10443. bool DebugUsedArg(DragDrop), unsigned int DebugUsedArg(Flags))
  10444. {
  10445. DebugFail();
  10446. }
  10447. //---------------------------------------------------------------------------
  10448. void TCustomScpExplorerForm::LocalLocalCopyCommand(TFileOperation Operation, TOperationSide Side, bool OnFocused, unsigned int Flags)
  10449. {
  10450. LocalLocalCopy(Operation, Side, OnFocused, !WinConfiguration->ConfirmTransferring, false, Flags);
  10451. }