CustomScpExplorer.cpp 367 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144
  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. FSessionChanging = false;
  178. FCopyParamDefault = L"";
  179. FSynchronizeController = NULL;
  180. FPendingQueueActionItem = NULL;
  181. FLockLevel = 0;
  182. FLockSuspendLevel = 0;
  183. FDisabledOnLockSuspend = false;
  184. FAlternativeDelete = false;
  185. FTrayIcon = new ::TTrayIcon(0);
  186. FTrayIcon->OnClick = TrayIconClick;
  187. FMaxQueueLength = 0;
  188. FLastContextPopupScreenPoint = TPoint(-1, -1);
  189. FTransferResumeList = NULL;
  190. FMoveToQueue = false;
  191. FStandaloneEditing = false;
  192. FOnFeedSynchronizeError = NULL;
  193. FNeedSession = false;
  194. FDoNotIdleCurrentTerminal = 0;
  195. FIncrementalSearching = 0;
  196. FIncrementalSearchHaveNext = false;
  197. FQueueFileList.reset(new TQueueFileList());
  198. FProgressSide = osCurrent;
  199. FEditorManager = new TEditorManager();
  200. FEditorManager->OnFileChange = ExecutedFileChanged;
  201. FEditorManager->OnFileReload = ExecutedFileReload;
  202. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  203. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  204. FLocalEditors = new TList();
  205. FQueueStatus = NULL;
  206. FQueueStatusSection = new TCriticalSection();
  207. FQueueStatusInvalidated = false;
  208. FQueueItemInvalidated = false;
  209. FQueueStatusUpdating = false;
  210. FQueueActedItem = NULL;
  211. FQueueController = new TQueueController(QueueView3);
  212. FUserActionTimer = new TTimer(this);
  213. FUserActionTimer->Enabled = false;
  214. FUserActionTimer->Interval = 10;
  215. FUserActionTimer->OnTimer = UserActionTimer;
  216. FNotes = new TStringList();
  217. FNoteTimer = new TTimer(this);
  218. FNoteTimer->Enabled = false;
  219. FNoteTimer->OnTimer = NoteTimer;
  220. FOnNoteClick = NULL;
  221. FOle32Library = LoadLibrary(L"Ole32.dll");
  222. FDragMoveCursor = FOle32Library != NULL ?
  223. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  224. UseSystemSettings(this);
  225. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  226. static_cast<TObject*>(GetComponent(fcTransferList)));
  227. DebugAssert(TransferList != NULL);
  228. FTransferListHoverIndex = -1;
  229. TransferList->OnChange = TransferListChange;
  230. TransferList->OnDrawItem = TransferListDrawItem;
  231. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  232. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  233. UseDesktopFont(SessionsPageControl);
  234. UpdateSessionsPageControlHeight();
  235. UseDesktopFont(RemoteDirView);
  236. UseDesktopFont(RemoteDriveView);
  237. UseDesktopFont(QueueView3);
  238. UseDesktopFont(QueueFileList);
  239. UseDesktopFont(QueueLabel);
  240. UseDesktopFont(RemoteStatusBar);
  241. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  242. QueueSplitter->ShowHint = true;
  243. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  244. QueueFileListSplitter->ShowHint = true;
  245. RemotePanelSplitter->ShowHint = true;
  246. UpdateImages();
  247. FCustomCommandMenu = CreateTBXPopupMenu(this);
  248. FCustomCommandLocalFileList = NULL;
  249. FCustomCommandRemoteFileList = NULL;
  250. FSessionColors = new TPngImageList(this);
  251. FSessionColors->ColorDepth = cd32Bit;
  252. AddFixedSessionImages();
  253. SessionsPageControl->Images = FSessionColors;
  254. UpdateQueueLabel();
  255. CreateHiddenWindow();
  256. StartUpdates();
  257. }
  258. //---------------------------------------------------------------------------
  259. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  260. {
  261. FInvalid = true;
  262. // this has to be one of the very first things to do
  263. StopUpdateThread();
  264. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  265. TTerminalManager::Instance()->ScpExplorer = NULL;
  266. delete FCustomCommandLocalFileList;
  267. delete FCustomCommandRemoteFileList;
  268. delete FCustomCommandMenu;
  269. delete FTrayIcon;
  270. FTrayIcon = NULL;
  271. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  272. delete FEditorManager;
  273. ForceCloseLocalEditors();
  274. delete FLocalEditors;
  275. HideFileFindDialog();
  276. if (FDelayedDeletionTimer)
  277. {
  278. DoDelayedDeletion(NULL);
  279. SAFE_DESTROY(FDelayedDeletionTimer);
  280. }
  281. SAFE_DESTROY(FDelayedDeletionList);
  282. // sometimes we do not get DDEnd so the list is not released
  283. SAFE_DESTROY(FDDFileList);
  284. DebugAssert(FSynchronizeController == NULL);
  285. CloseHandle(FDDExtMutex);
  286. FDDExtMutex = NULL;
  287. FreeLibrary(FOle32Library);
  288. FOle32Library = NULL;
  289. FDragMoveCursor = NULL;
  290. DebugAssert(!FErrorList);
  291. if (FEverShown)
  292. {
  293. // when window is never shown (like when running command-line operation),
  294. // particularly window site is not restored correctly (BoundsRect value set
  295. // in RestoreForm gets lost during handle allocation), so we do not want
  296. // it to be stored
  297. StoreParams();
  298. }
  299. ManagedSession = NULL;
  300. Queue = NULL;
  301. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  302. NonVisualDataModule->ScpExplorer = NULL;
  303. delete FQueueController;
  304. FQueueController = NULL;
  305. delete FQueueStatusSection;
  306. FQueueStatusSection = NULL;
  307. delete FQueueStatus;
  308. FQueueStatus = NULL;
  309. delete FUserActionTimer;
  310. FUserActionTimer = NULL;
  311. delete FNoteTimer;
  312. delete FNotes;
  313. delete FNoteData;
  314. SAFE_DESTROY(FDocks);
  315. SessionsPageControl->Images = NULL;
  316. // only after clearing Terminal (after SessionListChanged => ... => AddSessionColor is called)
  317. SAFE_DESTROY(FSessionColors);
  318. SAFE_DESTROY(FSessionsDragDropFilesEx);
  319. SAFE_DESTROY(FHistoryMenu[0][0]);
  320. SAFE_DESTROY(FHistoryMenu[0][1]);
  321. SAFE_DESTROY(FHistoryMenu[1][0]);
  322. SAFE_DESTROY(FHistoryMenu[1][1]);
  323. if (FHiddenWindow != NULL)
  324. {
  325. DestroyWindow(FHiddenWindow);
  326. FHiddenWindow = NULL;
  327. }
  328. }
  329. //---------------------------------------------------------------------------
  330. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  331. {
  332. std::unique_ptr<TSessionData> Data;
  333. if (!Session.IsEmpty())
  334. {
  335. bool DefaultsOnly;
  336. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  337. }
  338. TTerminalManager * Manager = TTerminalManager::Instance();
  339. for (int Index = 0; Index < Manager->Count; Index++)
  340. {
  341. TTerminal * Terminal = Manager->Sessions[Index];
  342. if (Session.IsEmpty() ||
  343. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  344. {
  345. if (Path.IsEmpty())
  346. {
  347. Terminal->ClearCaches();
  348. }
  349. else
  350. {
  351. Terminal->DirectoryModified(Path, true);
  352. }
  353. }
  354. }
  355. // We should flag a pending refresh for the background terminals or busy foreground terminals
  356. if (HasActiveTerminal() &&
  357. CanCommandLineFromAnotherInstance() &&
  358. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  359. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  360. {
  361. Terminal->ReloadDirectory();
  362. }
  363. }
  364. //---------------------------------------------------------------------------
  365. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  366. {
  367. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  368. size_t MessageSize = sizeof(TCopyDataMessage);
  369. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  370. if (Result)
  371. {
  372. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  373. Result = (Message.Version == TCopyDataMessage::Version1);
  374. if (Result)
  375. {
  376. switch (Message.Command)
  377. {
  378. case TCopyDataMessage::CommandCanCommandLine:
  379. Result = CanCommandLineFromAnotherInstance();
  380. break;
  381. case TCopyDataMessage::CommandCommandLine:
  382. {
  383. UnicodeString CommandLine(Message.CommandLine);
  384. Result = CommandLineFromAnotherInstance(CommandLine);
  385. }
  386. break;
  387. case TCopyDataMessage::RefreshPanel:
  388. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  389. break;
  390. case TCopyDataMessage::MainWindowCheck:
  391. Result = true;
  392. break;
  393. default:
  394. Result = false;
  395. break;
  396. }
  397. }
  398. }
  399. Message.Result = Result ? 1 : 0;
  400. }
  401. //---------------------------------------------------------------------------
  402. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  403. {
  404. WNDCLASS WindowClass = {0};
  405. WindowClass.lpfnWndProc = DefWindowProc;
  406. WindowClass.hInstance = HInstance;
  407. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  408. FHiddenWindow = NULL;
  409. if (RegisterClass(&WindowClass))
  410. {
  411. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  412. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  413. }
  414. }
  415. //---------------------------------------------------------------------------
  416. bool __fastcall TCustomScpExplorerForm::CanConsole()
  417. {
  418. return
  419. HasActiveTerminal() &&
  420. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  421. }
  422. //---------------------------------------------------------------------------
  423. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  424. {
  425. bool Result = Visible && !NonVisualDataModule->Busy;
  426. return Result;
  427. }
  428. //---------------------------------------------------------------------------
  429. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  430. const UnicodeString & CommandLine)
  431. {
  432. TProgramParams Params(CommandLine);
  433. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  434. if (Result)
  435. {
  436. NonVisualDataModule->StartBusy();
  437. try
  438. {
  439. // this action is initiated from another process,
  440. // so it's likely that our window is not visible,
  441. // and user won't see what is going on
  442. Application->BringToFront();
  443. // reload sessions as we may be asked to open a session
  444. // just stored by another instance
  445. StoredSessions->Reload();
  446. UnicodeString SessionName = Params.Param[1];
  447. std::unique_ptr<TObjectList> DataList(new TObjectList());
  448. UnicodeString DownloadFile; // unused
  449. try
  450. {
  451. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  452. }
  453. catch (EAbort &)
  454. {
  455. // Happens when opening session in PuTTY and in other situations,
  456. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  457. // to process the command-line on its own (or to pass it to yet another instance)
  458. }
  459. if (DataList->Count > 0)
  460. {
  461. TTerminalManager * Manager = TTerminalManager::Instance();
  462. Manager->ActiveSession = Manager->NewTerminals(DataList.get());
  463. }
  464. }
  465. __finally
  466. {
  467. NonVisualDataModule->EndBusy();
  468. }
  469. }
  470. return Result;
  471. }
  472. //---------------------------------------------------------------------------
  473. TManagedTerminal * TCustomScpExplorerForm::GetTerminal()
  474. {
  475. TManagedTerminal * Result;
  476. if ((FManagedSession != NULL) && !FManagedSession->LocalBrowser)
  477. {
  478. Result = FManagedSession;
  479. }
  480. else
  481. {
  482. Result = NULL;
  483. }
  484. return Result;
  485. }
  486. //---------------------------------------------------------------------------
  487. void __fastcall TCustomScpExplorerForm::SetManagedSession(TManagedTerminal * value)
  488. {
  489. if (FManagedSession != value)
  490. {
  491. SessionChanging();
  492. DoSetManagedSession(value, false);
  493. }
  494. }
  495. //---------------------------------------------------------------------------
  496. void __fastcall TCustomScpExplorerForm::DoSetManagedSession(TManagedTerminal * value, bool Replace)
  497. {
  498. DebugAssert(!Replace || ((value != NULL) && !value->LocalBrowser));
  499. FManagedSession = value;
  500. {
  501. TValueRestorer<bool> AllowTransferPresetAutoSelectRestorer(FAllowTransferPresetAutoSelect);
  502. FAllowTransferPresetAutoSelect = false;
  503. TAutoFlag SessionChangingFlag(FSessionChanging);
  504. SessionChanged(Replace);
  505. }
  506. if (Terminal != NULL)
  507. {
  508. TransferPresetAutoSelect();
  509. }
  510. // Update app and tab titles, prevented above by FSessionChanging.
  511. UpdateControls();
  512. }
  513. //---------------------------------------------------------------------------
  514. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  515. {
  516. DoSetManagedSession(value, true);
  517. }
  518. //---------------------------------------------------------------------------
  519. void __fastcall TCustomScpExplorerForm::SessionChanging()
  520. {
  521. if (ManagedSession != NULL)
  522. {
  523. UpdateSession(ManagedSession);
  524. }
  525. }
  526. //---------------------------------------------------------------------------
  527. void __fastcall TCustomScpExplorerForm::SessionChanged(bool Replaced)
  528. {
  529. if (Terminal != NULL)
  530. {
  531. UpdateSessionColor((TColor)Terminal->StateData->Color);
  532. }
  533. if (!TTerminalManager::Instance()->Updating)
  534. {
  535. SessionListChanged();
  536. }
  537. if (Terminal != NULL)
  538. {
  539. if (Replaced)
  540. {
  541. RemoteDirView->ReplaceTerminal(Terminal);
  542. }
  543. else
  544. {
  545. RemoteDirView->Terminal = Terminal;
  546. }
  547. if (Terminal->Active)
  548. {
  549. Terminal->RefreshDirectory();
  550. }
  551. if (WinConfiguration->PreservePanelState)
  552. {
  553. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  554. }
  555. }
  556. else
  557. {
  558. RemoteDirView->Terminal = NULL;
  559. }
  560. InitStatusBar();
  561. UpdateTransferList();
  562. // Update panels Enable state before refreshing the labels
  563. UpdateControls();
  564. }
  565. //---------------------------------------------------------------------------
  566. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  567. {
  568. if (Queue != value)
  569. {
  570. if (FQueue != NULL)
  571. {
  572. FQueue->OnListUpdate = NULL;
  573. FQueue->OnQueueItemUpdate = NULL;
  574. }
  575. FQueue = value;
  576. if (FQueue != NULL)
  577. {
  578. DebugAssert(FQueue->OnListUpdate == NULL);
  579. FQueue->OnListUpdate = QueueListUpdate;
  580. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  581. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  582. }
  583. QueueChanged();
  584. }
  585. }
  586. //---------------------------------------------------------------------------
  587. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  588. TListItem * Item)
  589. {
  590. if (FQueueActedItem == Item)
  591. {
  592. FQueueActedItem = NULL;
  593. if ((QueueView3->PopupMenu != NULL) &&
  594. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  595. {
  596. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  597. ReleaseCapture();
  598. }
  599. }
  600. if (Item->Data == FPendingQueueActionItem)
  601. {
  602. FPendingQueueActionItem = NULL;
  603. }
  604. }
  605. //---------------------------------------------------------------------------
  606. bool TCustomScpExplorerForm::IsAnythingQueued()
  607. {
  608. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  609. }
  610. //---------------------------------------------------------------------------
  611. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  612. {
  613. {
  614. TGuard Guard(FQueueStatusSection);
  615. FQueueStatusInvalidated = false;
  616. if (FQueue != NULL)
  617. {
  618. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  619. }
  620. }
  621. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  622. {
  623. FMaxQueueLength = FQueueStatus->Count;
  624. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  625. }
  626. {
  627. TAutoFlag Flag(FQueueStatusUpdating);
  628. FQueueController->UpdateQueueStatus(FQueueStatus);
  629. }
  630. UpdateQueueFileList();
  631. SetQueueProgress();
  632. UpdateQueueView();
  633. bool IsEmpty = !IsAnythingQueued();
  634. if (IsEmpty && (Terminal != NULL))
  635. {
  636. TOnceDoneOperation OnceDoneOperation =
  637. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  638. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  639. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  640. {
  641. FQueue->Enabled = false;
  642. }
  643. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  644. {
  645. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  646. }
  647. }
  648. }
  649. //---------------------------------------------------------------------------
  650. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  651. {
  652. UnicodeString Result;
  653. if (FQueueStatus != NULL)
  654. {
  655. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  656. {
  657. TFileOperationProgressType * ProgressData =
  658. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  659. if ((ProgressData != NULL) && ProgressData->InProgress)
  660. {
  661. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  662. }
  663. }
  664. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  665. {
  666. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  667. }
  668. }
  669. return Result;
  670. }
  671. //---------------------------------------------------------------------------
  672. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  673. {
  674. ComponentVisible[fcQueueView] =
  675. (WinConfiguration->QueueView.Show == qvShow) ||
  676. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  677. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  678. }
  679. //---------------------------------------------------------------------------
  680. void __fastcall TCustomScpExplorerForm::QueueChanged()
  681. {
  682. if (FQueueStatus != NULL)
  683. {
  684. // UpdateFileList implementation relies on the status being recreated when session changes
  685. delete FQueueStatus;
  686. FQueueStatus = NULL;
  687. }
  688. UpdateQueueStatus(true);
  689. }
  690. //---------------------------------------------------------------------------
  691. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  692. {
  693. if (FQueue == Queue)
  694. {
  695. FQueueStatusInvalidated = true;
  696. }
  697. }
  698. //---------------------------------------------------------------------------
  699. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  700. TQueueItem * Item)
  701. {
  702. if (FQueue == Queue)
  703. {
  704. TGuard Guard(FQueueStatusSection);
  705. // this may be running in parallel with QueueChanged
  706. if (FQueueStatus != NULL)
  707. {
  708. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  709. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  710. {
  711. FRefreshLocalDirectory = (QueueItem == NULL) ||
  712. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  713. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  714. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  715. }
  716. if (QueueItem != NULL)
  717. {
  718. QueueItem->UserData = (void*)true;
  719. FQueueItemInvalidated = true;
  720. }
  721. }
  722. }
  723. }
  724. //---------------------------------------------------------------------------
  725. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  726. {
  727. // during standalone editing, we have no way to see/control queue,
  728. // so we have to always popup prompts automatically
  729. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  730. }
  731. //---------------------------------------------------------------------------
  732. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  733. {
  734. if (FQueueStatus != NULL)
  735. {
  736. bool QueueAutoPopup = IsQueueAutoPopup();
  737. bool NeedRefresh = FQueueController->NeedRefresh();
  738. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  739. FQueueItemInvalidated = false;
  740. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  741. bool Updated = false;
  742. TQueueItemProxy * QueueItem;
  743. bool WasUserAction;
  744. for (int Index = 0; Index < Limit; Index++)
  745. {
  746. bool Update = false;
  747. QueueItem = FQueueStatus->Items[Index];
  748. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  749. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  750. (FPendingQueueActionItem == NULL))
  751. {
  752. FPendingQueueActionItem = QueueItem;
  753. FUserActionTimer->Enabled = true;
  754. }
  755. if ((bool)QueueItem->UserData)
  756. {
  757. QueueItem->UserData = (void*)false;
  758. QueueItem->Update();
  759. Updated = true;
  760. Update = true;
  761. }
  762. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  763. {
  764. Update = true;
  765. }
  766. if (Update)
  767. {
  768. FQueueController->RefreshQueueItem(QueueItem);
  769. }
  770. }
  771. if (Updated)
  772. {
  773. NonVisualDataModule->UpdateNonVisibleActions();
  774. SetQueueProgress();
  775. UpdateQueueFileList();
  776. }
  777. }
  778. }
  779. //---------------------------------------------------------------------------
  780. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  781. {
  782. if (FTaskbarList != NULL)
  783. {
  784. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  785. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  786. }
  787. }
  788. //---------------------------------------------------------------------------
  789. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  790. {
  791. if (Progress >= 0)
  792. {
  793. if (FTaskbarList != NULL)
  794. {
  795. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  796. }
  797. }
  798. else
  799. {
  800. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  801. }
  802. }
  803. //---------------------------------------------------------------------------
  804. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  805. {
  806. int OverallProgress;
  807. // FProgressForm is null when this is called from SetQueueProgress
  808. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  809. {
  810. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  811. }
  812. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  813. {
  814. OverallProgress = ProgressData->OverallProgress();
  815. }
  816. else
  817. {
  818. OverallProgress = -1;
  819. }
  820. SetTaskbarListProgressValue(OverallProgress);
  821. }
  822. //---------------------------------------------------------------------------
  823. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  824. {
  825. TTerminalManager::Instance()->QueueStatusUpdated();
  826. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  827. {
  828. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  829. {
  830. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  831. {
  832. TFileOperationProgressType * ProgressData = NULL;
  833. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  834. {
  835. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  836. }
  837. if ((ProgressData != NULL) &&
  838. ProgressData->InProgress)
  839. {
  840. SetTaskbarListProgressValue(ProgressData);
  841. }
  842. else
  843. {
  844. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  845. }
  846. }
  847. else
  848. {
  849. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  850. }
  851. }
  852. else
  853. {
  854. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  855. }
  856. }
  857. UpdateQueueLabel();
  858. }
  859. //---------------------------------------------------------------------------
  860. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  861. {
  862. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  863. if (FQueueStatus != NULL)
  864. {
  865. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  866. if (ActiveAndPendingPrimaryCount > 0)
  867. {
  868. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  869. }
  870. }
  871. QueueLabel->Caption = Caption;
  872. }
  873. //---------------------------------------------------------------------------
  874. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  875. {
  876. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  877. static_cast<TComponent*>(GetComponent(fcTransferList)));
  878. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  879. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  880. TransferList->Strings->BeginUpdate();
  881. try
  882. {
  883. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  884. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  885. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  886. if (FTransferDropDownHint.IsEmpty())
  887. {
  888. FTransferDropDownHint = TransferDropDown->Hint;
  889. }
  890. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  891. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  892. TransferDropDown->Text = StripHotkey(Name);
  893. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  894. (FTransferDropDownHint, StripHotkey(Name),
  895. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  896. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  897. // update the label, otherwise when it is updated only on the first draw
  898. // of the list, it is drawn "bold" for some reason
  899. FTransferListHoverIndex = TransferList->ItemIndex;
  900. UpdateTransferLabel();
  901. }
  902. __finally
  903. {
  904. TransferList->Strings->EndUpdate();
  905. }
  906. }
  907. //---------------------------------------------------------------------------
  908. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  909. {
  910. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  911. DebugAssert(Toolbar != NULL);
  912. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  913. }
  914. //---------------------------------------------------------------------------
  915. void __fastcall TCustomScpExplorerForm::UpdateActions()
  916. {
  917. TForm::UpdateActions();
  918. if (ComponentVisible[fcCustomCommandsBand])
  919. {
  920. UpdateCustomCommandsToolbar();
  921. }
  922. }
  923. //---------------------------------------------------------------------------
  924. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  925. {
  926. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  927. }
  928. //---------------------------------------------------------------------------
  929. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  930. {
  931. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  932. {
  933. DirView->RowSelect = WinConfiguration->FullRowSelect;
  934. // selection is not redrawn automatically when RowSelect changes
  935. DirView->Invalidate();
  936. }
  937. }
  938. //---------------------------------------------------------------------------
  939. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  940. {
  941. Color = GetBtnFaceColor();
  942. DebugAssert(Configuration && RemoteDirView);
  943. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  944. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  945. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  946. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  947. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  948. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  949. UpdateRowSelect(RemoteDirView);
  950. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  951. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  952. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  953. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  954. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  955. UpdateSessionsPageControlHeight();
  956. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  957. UpdateToolbarDisplayMode();
  958. UpdateTransferList();
  959. if (Terminal != NULL)
  960. {
  961. TransferPresetAutoSelect();
  962. }
  963. UpdateQueueView();
  964. UpdateControls();
  965. // this can be called even before constuctor finishes.
  966. if (FEditorManager != NULL)
  967. {
  968. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  969. }
  970. // this can be called even before constuctor finishes.
  971. if (FLocalEditors != NULL)
  972. {
  973. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  974. {
  975. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  976. }
  977. }
  978. if (ComponentVisible[fcCustomCommandsBand])
  979. {
  980. UpdateCustomCommandsToolbar();
  981. }
  982. // show only when keeping queue items forever,
  983. // otherwise, its enough to have in in the context menu
  984. QueueDeleteAllDoneQueueToolbarItem->Visible =
  985. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  986. if (FFileColorsCurrent != WinConfiguration->FileColors)
  987. {
  988. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  989. FFileColorsCurrent = WinConfiguration->FileColors;
  990. FileColorsChanged();
  991. }
  992. }
  993. //---------------------------------------------------------------------------
  994. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  995. {
  996. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  997. DirView->Invalidate();
  998. }
  999. //---------------------------------------------------------------------------
  1000. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  1001. {
  1002. DoFileColorsChanged(RemoteDirView);
  1003. }
  1004. //---------------------------------------------------------------------------
  1005. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  1006. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  1007. void * /*Arg*/)
  1008. {
  1009. if (Token != NULL)
  1010. {
  1011. TForm * Editor = dynamic_cast<TForm*>(Token);
  1012. DebugAssert(Editor != NULL);
  1013. ReconfigureEditorForm(Editor);
  1014. }
  1015. }
  1016. //---------------------------------------------------------------------------
  1017. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1018. {
  1019. WinConfiguration->DDTransferConfirmation = asOn;
  1020. }
  1021. //---------------------------------------------------------------------------
  1022. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1023. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1024. {
  1025. // noop
  1026. }
  1027. //---------------------------------------------------------------------------
  1028. bool TCustomScpExplorerForm::GetDoNotShowCopyDialogDefault(bool DragDrop)
  1029. {
  1030. return DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto);
  1031. }
  1032. //---------------------------------------------------------------------------
  1033. void TCustomScpExplorerForm::HandleDoNotShowCopyDialogAgain(bool DragDrop, bool DoNotShowAgain)
  1034. {
  1035. if (DoNotShowAgain)
  1036. {
  1037. if (DragDrop)
  1038. {
  1039. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1040. {
  1041. PopupTrayBalloon(
  1042. NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation, NULL, 0, EnableDDTransferConfirmation, NULL);
  1043. }
  1044. WinConfiguration->DDTransferConfirmation = asOff;
  1045. }
  1046. else
  1047. {
  1048. WinConfiguration->ConfirmTransferring = false;
  1049. }
  1050. }
  1051. else
  1052. {
  1053. // User explicitly unchecked "do not show again",
  1054. // so show him the dialog the next time
  1055. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1056. {
  1057. WinConfiguration->DDTransferConfirmation = asOn;
  1058. }
  1059. }
  1060. }
  1061. //---------------------------------------------------------------------------
  1062. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1063. TTransferDirection Direction, TTransferType Type, bool Temp,
  1064. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1065. bool Confirm, bool DragDrop, int Options)
  1066. {
  1067. bool Result = true;
  1068. DebugAssert(HasActiveTerminal());
  1069. // these parameters are known in advance
  1070. int Params =
  1071. FLAGMASK(Type == ttMove, cpDelete);
  1072. bool ToTemp = (Temp && (Direction == tdToLocal));
  1073. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1074. {
  1075. bool DisableNewerOnly =
  1076. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1077. ToTemp;
  1078. Options |=
  1079. FLAGMASK(ToTemp, coTemp) |
  1080. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1081. coDoNotShowAgain;
  1082. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1083. int CopyParamAttrs = (Direction == tdToRemote ?
  1084. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1085. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1086. int OutputOptions = FLAGMASK(GetDoNotShowCopyDialogDefault(DragDrop), cooDoNotShowAgain);
  1087. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1088. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1089. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1090. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1091. if (Result)
  1092. {
  1093. HandleDoNotShowCopyDialogAgain(DragDrop, FLAGSET(OutputOptions, cooDoNotShowAgain));
  1094. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1095. }
  1096. }
  1097. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1098. {
  1099. Configuration->Usage->Inc(L"TransfersOnBackground");
  1100. // these parameter are known only after transfer dialog
  1101. Params |=
  1102. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1103. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1104. Result = false;
  1105. ClearTransferSourceSelection(Direction);
  1106. }
  1107. return Result;
  1108. }
  1109. //---------------------------------------------------------------------------
  1110. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1111. {
  1112. if (FOnFileOperationFinished != NULL)
  1113. {
  1114. FOnFileOperationFinished(UnicodeString(), true);
  1115. }
  1116. else
  1117. {
  1118. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1119. if (HasDirView[Side])
  1120. {
  1121. DirView(Side)->SelectAll(smNone);
  1122. }
  1123. }
  1124. }
  1125. //---------------------------------------------------------------------------
  1126. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1127. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1128. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1129. int Params)
  1130. {
  1131. DebugAssert(Queue != NULL);
  1132. bool SingleFile = false;
  1133. if (FileList->Count == 1)
  1134. {
  1135. if (Direction == tdToRemote)
  1136. {
  1137. UnicodeString FileName = FileList->Strings[0];
  1138. SingleFile = FileExists(ApiPath(FileName));
  1139. }
  1140. else
  1141. {
  1142. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1143. SingleFile = !File->IsDirectory;
  1144. }
  1145. }
  1146. TQueueItem * QueueItem;
  1147. if (Direction == tdToRemote)
  1148. {
  1149. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1150. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1151. }
  1152. else
  1153. {
  1154. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1155. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1156. }
  1157. AddQueueItem(Queue, QueueItem, Terminal);
  1158. }
  1159. //---------------------------------------------------------------------------
  1160. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1161. {
  1162. if (Queue->IsEmpty)
  1163. {
  1164. Terminal->QueueOperationStart = Now();
  1165. }
  1166. Queue->AddItem(QueueItem);
  1167. }
  1168. //---------------------------------------------------------------------------
  1169. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1170. {
  1171. }
  1172. //---------------------------------------------------------------------------
  1173. void __fastcall TCustomScpExplorerForm::InitControls()
  1174. {
  1175. DebugAssert(FDocks != NULL);
  1176. for (int Index = 0; Index < ComponentCount; Index++)
  1177. {
  1178. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1179. if ((Dock != NULL) && (Dock->Tag == 0))
  1180. {
  1181. FDocks->Add(Dock);
  1182. }
  1183. }
  1184. CollectItemsWithTextDisplayMode(this);
  1185. }
  1186. //---------------------------------------------------------------------------
  1187. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1188. {
  1189. ConfigurationChanged();
  1190. QueuePanel->Height =
  1191. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1192. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1193. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1194. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1195. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1196. QueueFileList->Height =
  1197. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1198. if (QueueFileList->Visible)
  1199. {
  1200. AdjustQueueLayout();
  1201. }
  1202. UpdateCustomCommandsToolbar();
  1203. }
  1204. //---------------------------------------------------------------------------
  1205. void __fastcall TCustomScpExplorerForm::StoreParams()
  1206. {
  1207. int APixelsPerInch = GetControlPixelsPerInch(this);
  1208. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1209. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1210. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1211. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1212. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1213. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1214. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1215. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1216. }
  1217. //---------------------------------------------------------------------------
  1218. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1219. {
  1220. if (!FFormRestored)
  1221. {
  1222. FFormRestored = true;
  1223. RestoreFormParams();
  1224. }
  1225. TForm::CreateParams(Params);
  1226. }
  1227. //---------------------------------------------------------------------------
  1228. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1229. {
  1230. DebugAssert(FDocks != NULL);
  1231. for (int Index = 0; Index < FDocks->Count; Index++)
  1232. {
  1233. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1234. }
  1235. }
  1236. //---------------------------------------------------------------------------
  1237. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1238. {
  1239. SetDockAllowDrag(true);
  1240. while (!ButtonsStr.IsEmpty())
  1241. {
  1242. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1243. UnicodeString Name = CutToChar(S, L'=', true);
  1244. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1245. {
  1246. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1247. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1248. {
  1249. while (!S.IsEmpty())
  1250. {
  1251. UnicodeString S2 = CutToChar(S, L',', true);
  1252. UnicodeString Name = CutToChar(S2, L':', true);
  1253. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1254. {
  1255. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1256. if (SameText(GetToolbarItemName(Item), Name))
  1257. {
  1258. // forward compatibility
  1259. UnicodeString S3 = CutToChar(S2, L':', true);
  1260. bool Visible = StrToIntDef(S3, 0);
  1261. Item->Visible = Visible;
  1262. }
  1263. }
  1264. }
  1265. }
  1266. }
  1267. }
  1268. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1269. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1270. }
  1271. //---------------------------------------------------------------------------
  1272. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1273. {
  1274. UnicodeString Result;
  1275. SetDockAllowDrag(true);
  1276. Result = ::GetToolbarsLayoutStr(this);
  1277. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1278. return Result;
  1279. }
  1280. //---------------------------------------------------------------------------
  1281. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1282. {
  1283. UnicodeString Result;
  1284. if (Item->Action != NULL)
  1285. {
  1286. Result = Item->Action->Name;
  1287. Result = RemoveSuffix(Result, L"Action", true);
  1288. }
  1289. else
  1290. {
  1291. Result = Item->Name;
  1292. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1293. Result = RemoveSuffix(Result, L"Item", true);
  1294. }
  1295. return Result;
  1296. }
  1297. //---------------------------------------------------------------------------
  1298. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1299. {
  1300. UnicodeString Result;
  1301. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1302. {
  1303. UnicodeString ToolbarStr;
  1304. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1305. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1306. {
  1307. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1308. {
  1309. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1310. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1311. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1312. // and save the changes here only.
  1313. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1314. {
  1315. UnicodeString Name = GetToolbarItemName(Item);
  1316. DebugAssert(Name.Pos(L"TBX") == 0);
  1317. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1318. }
  1319. }
  1320. }
  1321. if (!ToolbarStr.IsEmpty())
  1322. {
  1323. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1324. }
  1325. }
  1326. return Result;
  1327. }
  1328. //---------------------------------------------------------------------------
  1329. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1330. {
  1331. DebugAssert(FProgressForm == NULL);
  1332. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1333. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1334. FProgressForm->DeleteLocalToRecycleBin =
  1335. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1336. FProgressForm->DeleteRemoteToRecycleBin =
  1337. (Terminal != NULL) &&
  1338. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1339. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1340. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1341. LockWindow();
  1342. // Actually, do not know what hides the progress once the operation finishes
  1343. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1344. SetTaskbarListProgressState(TBPF_NORMAL);
  1345. }
  1346. //---------------------------------------------------------------------------
  1347. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1348. {
  1349. UnlockWindow();
  1350. SAFE_DESTROY(FProgressForm);
  1351. SetQueueProgress();
  1352. }
  1353. //---------------------------------------------------------------------------
  1354. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1355. TFileOperationProgressType & ProgressData)
  1356. {
  1357. // Download to temporary local directory
  1358. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1359. {
  1360. bool Continue = true;
  1361. FPendingTempSpaceWarn = false;
  1362. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1363. if (!Continue)
  1364. {
  1365. Abort();
  1366. }
  1367. }
  1368. // operation is being executed and we still didn't show up progress form
  1369. if (ProgressData.InProgress && !FProgressForm)
  1370. {
  1371. CreateProgressForm(NULL);
  1372. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1373. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1374. }
  1375. // operation is finished (or terminated), so we hide progress form
  1376. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1377. {
  1378. DestroyProgressForm();
  1379. if (ProgressData.Operation == foCalculateSize)
  1380. {
  1381. // When calculating size before transfer, the abort caused by
  1382. // cancel flag set due to "MoveToQueue" below,
  1383. // is not propagated back to us in ExecuteFileOperation,
  1384. // as it is silently swallowed.
  1385. // So we explicitly (re)throw it here.
  1386. if (FMoveToQueue)
  1387. {
  1388. Abort();
  1389. }
  1390. }
  1391. else
  1392. {
  1393. if ((ProgressData.Cancel == csContinue) &&
  1394. !FAutoOperation)
  1395. {
  1396. OperationComplete(ProgressData.StartTime);
  1397. }
  1398. }
  1399. }
  1400. if (FProgressForm &&
  1401. // Can happen only during synchronization, when ending one of the operations
  1402. ProgressData.InProgress)
  1403. {
  1404. FProgressForm->SetProgressData(ProgressData);
  1405. DebugAssert(ProgressData.InProgress);
  1406. SetTaskbarListProgressValue(&ProgressData);
  1407. if (FProgressForm->Cancel > csContinue)
  1408. {
  1409. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1410. if (FProgressForm->Cancel == csCancelFile)
  1411. {
  1412. FProgressForm->ClearCancel();
  1413. }
  1414. // cancel cancels even the move
  1415. FMoveToQueue = false;
  1416. }
  1417. else if (FProgressForm->MoveToQueue)
  1418. {
  1419. FMoveToQueue = true;
  1420. ProgressData.SetCancelAtLeast(csCancel);
  1421. }
  1422. if ((FTransferResumeList != NULL) &&
  1423. ProgressData.InProgress &&
  1424. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1425. !ProgressData.FullFileName.IsEmpty())
  1426. {
  1427. if ((FTransferResumeList->Count == 0) ||
  1428. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1429. {
  1430. // note that we do not recognize directories from files here
  1431. FTransferResumeList->Add(ProgressData.FullFileName);
  1432. }
  1433. }
  1434. }
  1435. }
  1436. //---------------------------------------------------------------------------
  1437. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1438. const TDateTime & StartTime)
  1439. {
  1440. if (GUIConfiguration->BeepOnFinish &&
  1441. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1442. {
  1443. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1444. DWORD Sound;
  1445. if (!ExtractFileExt(BeepSound).IsEmpty())
  1446. {
  1447. Sound = SND_FILENAME;
  1448. }
  1449. else
  1450. {
  1451. Sound = SND_ALIAS;
  1452. }
  1453. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1454. }
  1455. }
  1456. //---------------------------------------------------------------------------
  1457. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1458. TFileOperationProgressType & ProgressData)
  1459. {
  1460. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1461. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1462. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1463. FileOperationProgress(ProgressData);
  1464. }
  1465. //---------------------------------------------------------------------------
  1466. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1467. {
  1468. UnicodeString Result;
  1469. if (FProgressForm != NULL)
  1470. {
  1471. Result = FProgressForm->ProgressStr();
  1472. }
  1473. return Result;
  1474. }
  1475. //---------------------------------------------------------------------------
  1476. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1477. bool DragDrop)
  1478. {
  1479. return (!DragDrop && (DropSourceControl == NULL)) ||
  1480. (DropSourceControl == DirView(osOther));
  1481. }
  1482. //---------------------------------------------------------------------------
  1483. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1484. TFileOperation Operation, TOperationSide Side,
  1485. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1486. TOnceDoneOperation & OnceDoneOperation)
  1487. {
  1488. if (!FAutoOperation)
  1489. {
  1490. // no selection on "/upload", form serves only as event handler
  1491. // (it is not displayed)
  1492. if (PanelOperation(Side, FDragDropOperation) &&
  1493. Visible && (Operation != foCalculateSize) &&
  1494. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1495. {
  1496. if (FOnFileOperationFinished != NULL)
  1497. {
  1498. FOnFileOperationFinished(FileName, Success);
  1499. }
  1500. else
  1501. {
  1502. TOperationSide DViewSide;
  1503. if ((FProgressSide != osCurrent) &&
  1504. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1505. {
  1506. // assume the operation is over the focused panel
  1507. DViewSide = FProgressSide;
  1508. }
  1509. else
  1510. {
  1511. DViewSide = Side;
  1512. }
  1513. TCustomDirView * DView = DirView(DViewSide);
  1514. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(DViewSide));
  1515. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1516. // this can happen when local drive is unplugged in the middle of the operation
  1517. if (Item != NULL)
  1518. {
  1519. if (Success) Item->Selected = false;
  1520. DView->MakeProgressVisible(Item);
  1521. }
  1522. }
  1523. }
  1524. if ((Operation == foCopy) || (Operation == foMove))
  1525. {
  1526. if (DebugAlwaysTrue(!IsLocalBrowserMode()))
  1527. {
  1528. if (Side == osLocal)
  1529. {
  1530. Configuration->Usage->Inc(L"UploadedFiles");
  1531. }
  1532. else
  1533. {
  1534. Configuration->Usage->Inc(L"DownloadedFiles");
  1535. }
  1536. }
  1537. }
  1538. }
  1539. if (Success && (FSynchronizeController != NULL))
  1540. {
  1541. DebugAssert(!IsSideLocalBrowser(osRemote));
  1542. if (Operation == foCopy)
  1543. {
  1544. DebugAssert(Side == osLocal);
  1545. FSynchronizeController->LogOperation(soUpload, FileName);
  1546. }
  1547. else if (Operation == foDelete)
  1548. {
  1549. DebugAssert(Side == osRemote);
  1550. FSynchronizeController->LogOperation(soDelete, FileName);
  1551. }
  1552. }
  1553. if (FProgressForm)
  1554. {
  1555. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1556. }
  1557. }
  1558. //---------------------------------------------------------------------------
  1559. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1560. TFileOperation Operation, TOperationSide Side,
  1561. bool Temp, const UnicodeString & FileName, Boolean Success,
  1562. TOnceDoneOperation & OnceDoneOperation)
  1563. {
  1564. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1565. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1566. OnceDoneOperation);
  1567. }
  1568. //---------------------------------------------------------------------------
  1569. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1570. {
  1571. return false;
  1572. }
  1573. //---------------------------------------------------------------------------
  1574. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1575. {
  1576. return false;
  1577. }
  1578. //---------------------------------------------------------------------------
  1579. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1580. {
  1581. return NULL;
  1582. }
  1583. //---------------------------------------------------------------------------
  1584. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1585. {
  1586. DebugAssert(GetSide(Side) == osRemote);
  1587. DebugUsedParam(Side);
  1588. return RemoteDirView;
  1589. }
  1590. //---------------------------------------------------------------------------
  1591. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1592. {
  1593. DebugAssert(GetSide(Side) == osRemote);
  1594. DebugUsedParam(Side);
  1595. return RemoteDriveView;
  1596. }
  1597. //---------------------------------------------------------------------------
  1598. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1599. {
  1600. DebugAssert(GetSide(Side) == osRemote);
  1601. DebugUsedParam(Side);
  1602. return HasActiveTerminal();
  1603. }
  1604. //---------------------------------------------------------------------------
  1605. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1606. TOperationSide Side, int FilesOnly)
  1607. {
  1608. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1609. }
  1610. //---------------------------------------------------------------------------
  1611. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1612. TOperationSide Side, int FilesOnly)
  1613. {
  1614. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1615. }
  1616. //---------------------------------------------------------------------------
  1617. struct THistoryItemData
  1618. {
  1619. short int Side;
  1620. short int Index;
  1621. };
  1622. //---------------------------------------------------------------------------
  1623. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1624. {
  1625. DirView(Side)->HistoryGo(Index);
  1626. }
  1627. //---------------------------------------------------------------------------
  1628. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1629. {
  1630. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1631. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1632. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1633. }
  1634. //---------------------------------------------------------------------------
  1635. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1636. bool Back)
  1637. {
  1638. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1639. {
  1640. TCustomDirView * DView = DirView(Side);
  1641. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1642. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1643. if (ICount > 10)
  1644. {
  1645. ICount = 10;
  1646. }
  1647. Menu->Items->Clear();
  1648. THistoryItemData Data;
  1649. Data.Side = Side;
  1650. for (short int i = 1; i <= ICount; i++)
  1651. {
  1652. TTBCustomItem * Item = new TTBXItem(Menu);
  1653. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1654. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1655. Item->Hint = DView->HistoryPath[Data.Index];
  1656. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1657. Item->Tag = *reinterpret_cast<int*>(&Data);
  1658. Item->OnClick = HistoryItemClick;
  1659. Menu->Items->Add(Item);
  1660. }
  1661. }
  1662. }
  1663. //---------------------------------------------------------------------------
  1664. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1665. TOperationSide Side, bool Back)
  1666. {
  1667. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1668. {
  1669. // workaround
  1670. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1671. // operator new allocates memory in Pascal code, but calls inline
  1672. // contructor in C++, leading in problems, the function does
  1673. // both in Pascal code
  1674. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1675. UpdateHistoryMenu(Side, Back);
  1676. }
  1677. return FHistoryMenu[Side == osLocal][Back];
  1678. }
  1679. //---------------------------------------------------------------------------
  1680. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1681. TCustomDirView *Sender)
  1682. {
  1683. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1684. UpdateHistoryMenu(Side, true);
  1685. UpdateHistoryMenu(Side, false);
  1686. }
  1687. //---------------------------------------------------------------------------
  1688. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1689. {
  1690. // remote custom commands can be executed only if the server supports shell commands
  1691. // or have secondary shell
  1692. return HasActiveTerminal() && (Terminal->IsCapable[fcSecondaryShell] || Terminal->IsCapable[fcShellAnyCommand]);
  1693. }
  1694. //---------------------------------------------------------------------------
  1695. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1696. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1697. {
  1698. // -1 = hidden, 0 = disabled, 1 = enabled
  1699. int Result;
  1700. TFileCustomCommand RemoteCustomCommand;
  1701. TLocalCustomCommand LocalCustomCommand;
  1702. TFileCustomCommand * NonInteractiveCustomCommand =
  1703. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1704. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1705. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1706. if (FLAGCLEAR(Command.Params, ccLocal))
  1707. {
  1708. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1709. // custom command that does not operate with files can be executed anytime ...
  1710. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1711. {
  1712. // ... but do not show such command in remote file menu
  1713. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1714. {
  1715. Result = AllowedState;
  1716. }
  1717. else
  1718. {
  1719. Result = -1;
  1720. }
  1721. }
  1722. else
  1723. {
  1724. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1725. {
  1726. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1727. }
  1728. else
  1729. {
  1730. Result = -1;
  1731. }
  1732. }
  1733. }
  1734. else
  1735. {
  1736. // custom command that does not operate with files can be executed anytime
  1737. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1738. {
  1739. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1740. }
  1741. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1742. {
  1743. if ((ListType == ccltAll) || (ListType == ccltFile))
  1744. {
  1745. // special case is "diff"-style command that can be executed over any side,
  1746. // if we have both sides
  1747. Result =
  1748. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1749. // directly (instead of EnableSelectedOperation) to pass
  1750. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1751. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1752. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1753. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1754. }
  1755. else if (ListType == ccltBoth)
  1756. {
  1757. DebugAssert(!IsLocalBrowserMode());
  1758. Result = 1;
  1759. }
  1760. else
  1761. {
  1762. Result = -1;
  1763. }
  1764. }
  1765. else
  1766. {
  1767. if ((ListType == ccltAll) ||
  1768. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1769. {
  1770. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1771. }
  1772. else
  1773. {
  1774. Result = -1;
  1775. }
  1776. }
  1777. if ((Result > 0) &&
  1778. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1779. !HasActiveTerminal())
  1780. {
  1781. Result = 0;
  1782. }
  1783. }
  1784. return Result;
  1785. }
  1786. //---------------------------------------------------------------------------
  1787. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1788. TStrings * FileList, const TCustomCommandType & ACommand,
  1789. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1790. {
  1791. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1792. {
  1793. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1794. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1795. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1796. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1797. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1798. bool Capture =
  1799. FLAGSET(ACommand.Params, ccShowResults) ||
  1800. FLAGSET(ACommand.Params, ccCopyResults) ||
  1801. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1802. TCaptureOutputEvent OutputEvent = NULL;
  1803. DebugAssert(FCapturedLog == NULL);
  1804. if (Capture)
  1805. {
  1806. FCapturedLog = new TStringList();
  1807. OutputEvent = TerminalCaptureLog;
  1808. }
  1809. try
  1810. {
  1811. if (!RemoteCustomCommand.IsFileCommand(Command))
  1812. {
  1813. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1814. OutputEvent);
  1815. }
  1816. else
  1817. {
  1818. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1819. }
  1820. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1821. {
  1822. if (FLAGSET(ACommand.Params, ccCopyResults))
  1823. {
  1824. CopyToClipboard(FCapturedLog);
  1825. }
  1826. if (FLAGSET(ACommand.Params, ccShowResults))
  1827. {
  1828. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1829. }
  1830. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1831. {
  1832. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1833. }
  1834. }
  1835. }
  1836. __finally
  1837. {
  1838. SAFE_DESTROY(FCapturedLog);
  1839. }
  1840. }
  1841. }
  1842. //---------------------------------------------------------------------------
  1843. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1844. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1845. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1846. {
  1847. DebugAssert(!IsLocalBrowserMode());
  1848. TStrings * LocalFileList = NULL;
  1849. TStrings * RemoteFileList = NULL;
  1850. TStrings * RemoteFileListFull = NULL;
  1851. try
  1852. {
  1853. if (LocalFileCommand)
  1854. {
  1855. if (ALocalFileList == NULL)
  1856. {
  1857. DebugAssert(HasDirView[osLocal]);
  1858. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1859. // directly (instead of EnableSelectedOperation) to pass
  1860. // false to FocusedFileOnlyWhenFocused
  1861. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1862. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1863. }
  1864. else
  1865. {
  1866. LocalFileList = ALocalFileList;
  1867. }
  1868. if (FileListCommand)
  1869. {
  1870. if (LocalFileList->Count != 1)
  1871. {
  1872. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1873. }
  1874. }
  1875. else
  1876. {
  1877. if ((LocalFileList->Count != 1) &&
  1878. (FileList->Count != 1) &&
  1879. (LocalFileList->Count != FileList->Count))
  1880. {
  1881. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1882. }
  1883. }
  1884. }
  1885. UnicodeString RootTempDir;
  1886. UnicodeString TempDir;
  1887. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1888. if (!RemoteFiles)
  1889. {
  1890. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1891. }
  1892. try
  1893. {
  1894. TDateTimes RemoteFileTimes;
  1895. if (RemoteFiles)
  1896. {
  1897. RemoteFileList = FileList;
  1898. }
  1899. else
  1900. {
  1901. RemoteFileList = new TStringList();
  1902. TMakeLocalFileListParams MakeFileListParam;
  1903. MakeFileListParam.FileList = RemoteFileList;
  1904. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1905. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1906. MakeFileListParam.Recursive =
  1907. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1908. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1909. if (!MakeFileListParam.Recursive)
  1910. {
  1911. RemoteFileTimes.clear();
  1912. RemoteFileListFull = new TStringList();
  1913. MakeFileListParam.FileList = RemoteFileListFull;
  1914. MakeFileListParam.Recursive = true;
  1915. MakeFileListParam.IncludeDirs = false;
  1916. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1917. }
  1918. else
  1919. {
  1920. RemoteFileListFull = RemoteFileList;
  1921. }
  1922. }
  1923. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1924. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1925. if (!NonBlocking)
  1926. {
  1927. int Count;
  1928. if (FileListCommand)
  1929. {
  1930. Count = 1;
  1931. }
  1932. else if (LocalFileCommand)
  1933. {
  1934. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1935. }
  1936. else
  1937. {
  1938. Count = RemoteFileList->Count;
  1939. }
  1940. Progress.Start(foCustomCommand, osRemote, Count);
  1941. DebugAssert(FProgressForm != NULL);
  1942. FProgressForm->ReadOnly = true;
  1943. }
  1944. try
  1945. {
  1946. if (FileListCommand)
  1947. {
  1948. UnicodeString LocalFile;
  1949. // MakeFileList does not delimit filenames
  1950. UnicodeString FileList = MakeFileList(RemoteFileList);
  1951. if (LocalFileCommand)
  1952. {
  1953. DebugAssert(LocalFileList->Count == 1);
  1954. LocalFile = LocalFileList->Strings[0];
  1955. }
  1956. TLocalCustomCommand CustomCommand(Data,
  1957. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1958. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1959. if (NonBlocking)
  1960. {
  1961. DebugAssert(!POutput);
  1962. ExecuteShellChecked(ShellCommand);
  1963. }
  1964. else
  1965. {
  1966. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1967. }
  1968. }
  1969. else if (LocalFileCommand)
  1970. {
  1971. if (LocalFileList->Count == 1)
  1972. {
  1973. UnicodeString LocalFile = LocalFileList->Strings[0];
  1974. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1975. {
  1976. UnicodeString FileName = RemoteFileList->Strings[Index];
  1977. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1978. Progress.SetFile(FileNameForProgress);
  1979. TLocalCustomCommand CustomCommand(Data,
  1980. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1981. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1982. TOnceDoneOperation OnceDoneOperation;
  1983. // Do not unselect anything, as it won't work with two panels anyway
  1984. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1985. }
  1986. }
  1987. else if (RemoteFileList->Count == 1)
  1988. {
  1989. UnicodeString FileName = RemoteFileList->Strings[0];
  1990. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1991. {
  1992. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1993. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1994. Progress.SetFile(LocalFileNameOnly);
  1995. TLocalCustomCommand CustomCommand(
  1996. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1997. FileName, LocalFileName, L"");
  1998. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1999. TOnceDoneOperation OnceDoneOperation;
  2000. // Do not unselect anything, as it won't work with two panels anyway
  2001. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2002. }
  2003. }
  2004. else
  2005. {
  2006. if (LocalFileList->Count != RemoteFileList->Count)
  2007. {
  2008. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  2009. }
  2010. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2011. {
  2012. UnicodeString FileName = RemoteFileList->Strings[Index];
  2013. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2014. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2015. Progress.SetFile(LocalFileNameOnly); // sic
  2016. TLocalCustomCommand CustomCommand(
  2017. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2018. FileName, LocalFileName, L"");
  2019. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2020. TOnceDoneOperation OnceDoneOperation;
  2021. // Do not unselect anything, as it won't work with two panels anyway
  2022. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2023. }
  2024. }
  2025. }
  2026. else
  2027. {
  2028. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2029. {
  2030. UnicodeString FileName = RemoteFileList->Strings[Index];
  2031. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2032. Progress.SetFile(FileNameForProgress);
  2033. TLocalCustomCommand CustomCommand(Data,
  2034. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2035. FileName, L"", L"");
  2036. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2037. TOnceDoneOperation OnceDoneOperation;
  2038. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2039. }
  2040. }
  2041. }
  2042. __finally
  2043. {
  2044. if (!NonBlocking)
  2045. {
  2046. Progress.Stop();
  2047. }
  2048. }
  2049. DebugAssert(!FAutoOperation);
  2050. if (!RemoteFiles)
  2051. {
  2052. TempDir = IncludeTrailingBackslash(TempDir);
  2053. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2054. {
  2055. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2056. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2057. // Skip directories, process only nested files.
  2058. // The check is redundant as FileAge fails for directories anyway.
  2059. !DirectoryExists(FileName))
  2060. {
  2061. UnicodeString RemoteDir =
  2062. UnixExtractFileDir(
  2063. UnixIncludeTrailingBackslash(Terminal->CurrentDirectory) +
  2064. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2065. TDateTime NewTime;
  2066. if (FileAge(FileName, NewTime) &&
  2067. (NewTime != RemoteFileTimes[Index]))
  2068. {
  2069. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2070. TemporaryFileCopyParam(CopyParam);
  2071. CopyParam.FileMask = L"";
  2072. FAutoOperation = true;
  2073. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2074. TemporaryFilesList->Add(FileName);
  2075. Terminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2076. }
  2077. }
  2078. }
  2079. }
  2080. }
  2081. __finally
  2082. {
  2083. FAutoOperation = false;
  2084. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2085. {
  2086. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2087. }
  2088. }
  2089. }
  2090. __finally
  2091. {
  2092. if (RemoteFileList != FileList)
  2093. {
  2094. delete RemoteFileList;
  2095. }
  2096. if (LocalFileList != ALocalFileList)
  2097. {
  2098. delete LocalFileList;
  2099. }
  2100. if (RemoteFileListFull != RemoteFileList)
  2101. {
  2102. delete RemoteFileListFull;
  2103. }
  2104. }
  2105. }
  2106. //---------------------------------------------------------------------------
  2107. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2108. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2109. bool FileListCommand, UnicodeString * POutput)
  2110. {
  2111. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2112. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2113. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2114. {
  2115. UnicodeString FileName = SelectedFileList->Strings[Index];
  2116. if (DirectoryExists(FileName))
  2117. {
  2118. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2119. {
  2120. LocalFileList->Add(FileName);
  2121. }
  2122. if (FLAGSET(ACommand.Params, ccRecursive))
  2123. {
  2124. TMakeLocalFileListParams MakeFileListParam;
  2125. MakeFileListParam.FileList = LocalFileList.get();
  2126. MakeFileListParam.FileTimes = NULL;
  2127. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2128. MakeFileListParam.Recursive = true;
  2129. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2130. }
  2131. }
  2132. else
  2133. {
  2134. LocalFileList->Add(FileName);
  2135. }
  2136. }
  2137. UnicodeString RemotePath;
  2138. if (Terminal != NULL)
  2139. {
  2140. RemotePath = Terminal->CurrentDirectory;
  2141. }
  2142. if (FileListCommand)
  2143. {
  2144. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2145. TLocalCustomCommand CustomCommand(
  2146. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2147. L"", L"", FileList);
  2148. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2149. }
  2150. else
  2151. {
  2152. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2153. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2154. DebugAssert(FProgressForm != NULL);
  2155. FProgressForm->ReadOnly = true;
  2156. try
  2157. {
  2158. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2159. {
  2160. UnicodeString FileName = LocalFileList->Strings[Index];
  2161. Progress.SetFile(FileName);
  2162. TLocalCustomCommand CustomCommand(
  2163. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2164. FileName, L"", L"");
  2165. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2166. TOnceDoneOperation OnceDoneOperation;
  2167. Progress.Finish(FileName, true, OnceDoneOperation);
  2168. }
  2169. }
  2170. __finally
  2171. {
  2172. Progress.Stop();
  2173. }
  2174. }
  2175. }
  2176. //---------------------------------------------------------------------------
  2177. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2178. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2179. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2180. {
  2181. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2182. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2183. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2184. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2185. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2186. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2187. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2188. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2189. std::unique_ptr<UnicodeString> POutput;
  2190. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2191. FLAGSET(ACommand.Params, ccCopyResults))
  2192. {
  2193. POutput.reset(new UnicodeString());
  2194. }
  2195. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  2196. FProgressSide = FCurrentSide;
  2197. if (!LocalCustomCommand.IsFileCommand(Command))
  2198. {
  2199. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2200. }
  2201. // remote files?
  2202. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2203. {
  2204. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2205. }
  2206. // local files
  2207. else
  2208. {
  2209. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2210. }
  2211. if (POutput.get() != NULL)
  2212. {
  2213. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2214. int P = POutput->Pos(sLineBreak);
  2215. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2216. {
  2217. POutput->SetLength(P - 1);
  2218. }
  2219. // Copy even empty output to clipboard
  2220. if (FLAGSET(ACommand.Params, ccCopyResults))
  2221. {
  2222. CopyToClipboard(*POutput);
  2223. }
  2224. // But do not show an empty message box.
  2225. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2226. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2227. !POutput->IsEmpty())
  2228. {
  2229. TClipboardHandler ClipboardHandler;
  2230. ClipboardHandler.Text = *POutput;
  2231. TMessageParams Params;
  2232. TQueryButtonAlias Aliases[1];
  2233. Aliases[0].Button = qaRetry;
  2234. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2235. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2236. Params.Aliases = Aliases;
  2237. Params.AliasesCount = LENOF(Aliases);
  2238. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2239. }
  2240. }
  2241. }
  2242. //---------------------------------------------------------------------------
  2243. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2244. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2245. {
  2246. TCustomCommandData Data;
  2247. UnicodeString Site;
  2248. UnicodeString RemotePath;
  2249. if (HasActiveTerminal())
  2250. {
  2251. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2252. Data = TCustomCommandData(SessionData.get());
  2253. Site = Terminal->SessionData->SessionKey;
  2254. RemotePath = Terminal->CurrentDirectory;
  2255. }
  2256. UnicodeString HelpKeyword = ACommand.HomePage;
  2257. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2258. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2259. {
  2260. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2261. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2262. {
  2263. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2264. }
  2265. else
  2266. {
  2267. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2268. }
  2269. if (!DoCustomCommandOptionsDialog(
  2270. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2271. {
  2272. Abort();
  2273. }
  2274. }
  2275. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2276. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2277. {
  2278. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2279. }
  2280. else
  2281. {
  2282. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2283. }
  2284. }
  2285. //---------------------------------------------------------------------------
  2286. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2287. const TCustomCommandType & Command)
  2288. {
  2289. DebugAssert(FCustomCommandLocalFileList != NULL);
  2290. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2291. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2292. TStrings * LocalFileList = new TStringList();
  2293. TStrings * RemoteFileList = new TStringList();
  2294. try
  2295. {
  2296. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2297. {
  2298. LocalFileList->Clear();
  2299. LocalFileList->AddObject(
  2300. FCustomCommandLocalFileList->Strings[Index],
  2301. FCustomCommandLocalFileList->Objects[Index]);
  2302. RemoteFileList->Clear();
  2303. RemoteFileList->AddObject(
  2304. FCustomCommandRemoteFileList->Strings[Index],
  2305. FCustomCommandRemoteFileList->Objects[Index]);
  2306. CustomCommand(RemoteFileList, Command, LocalFileList);
  2307. }
  2308. }
  2309. __finally
  2310. {
  2311. delete LocalFileList;
  2312. delete RemoteFileList;
  2313. }
  2314. }
  2315. //---------------------------------------------------------------------------
  2316. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2317. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2318. {
  2319. delete FCustomCommandLocalFileList;
  2320. delete FCustomCommandRemoteFileList;
  2321. // takeover ownership,
  2322. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2323. FCustomCommandLocalFileList = LocalFileList;
  2324. FCustomCommandRemoteFileList = RemoteFileList;
  2325. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2326. if (Button != NULL)
  2327. {
  2328. FCustomCommandMenu->Items->Clear();
  2329. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2330. MenuPopup(FCustomCommandMenu, Button);
  2331. }
  2332. else
  2333. {
  2334. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2335. }
  2336. }
  2337. //---------------------------------------------------------------------------
  2338. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2339. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2340. {
  2341. DebugAssert(FCapturedLog != NULL);
  2342. if ((OutputType == cotOutput) || (OutputType == cotError))
  2343. {
  2344. FCapturedLog->Add(AddedLine);
  2345. }
  2346. }
  2347. //---------------------------------------------------------------------------
  2348. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2349. TOperationSide Side)
  2350. {
  2351. return
  2352. (Side == osOther) &&
  2353. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2354. }
  2355. //---------------------------------------------------------------------------
  2356. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2357. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2358. {
  2359. TTBItemOptions O;
  2360. O = Item->Options;
  2361. TCustomDirView * DView = DirView(Side);
  2362. if ((DView->ItemFocused != NULL) &&
  2363. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2364. // when resolving links is disabled, default action is to enter the directory,
  2365. // no matter what DoubleClickAction is configured to
  2366. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2367. // Can only Edit files, but can Open/Copy even directories
  2368. ((DoubleClickAction != dcaEdit) ||
  2369. !DView->ItemIsDirectory(DView->ItemFocused)))
  2370. {
  2371. Item->Options = O << tboDefault;
  2372. }
  2373. else
  2374. {
  2375. Item->Options = O >> tboDefault;
  2376. }
  2377. }
  2378. //---------------------------------------------------------------------------
  2379. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2380. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2381. {
  2382. TCustomDirView * DView = DirView(Side);
  2383. TListItem * Item = DView->ItemFocused;
  2384. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2385. EnableFocusedOperation[Side])
  2386. {
  2387. TPoint ClientPoint;
  2388. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2389. TPoint(0, 0) : MousePos;
  2390. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2391. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2392. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2393. }
  2394. }
  2395. //---------------------------------------------------------------------------
  2396. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2397. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2398. {
  2399. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2400. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2401. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2402. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2403. Handled = true;
  2404. }
  2405. //---------------------------------------------------------------------------
  2406. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2407. {
  2408. }
  2409. //---------------------------------------------------------------------------
  2410. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2411. {
  2412. DebugAssert(FErrorList == NULL);
  2413. if (WinConfiguration->ContinueOnError)
  2414. {
  2415. FErrorList = new TStringList();
  2416. Configuration->Usage->Inc(L"ContinuationsOnError");
  2417. }
  2418. NonVisualDataModule->StartBusy();
  2419. }
  2420. //---------------------------------------------------------------------------
  2421. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2422. {
  2423. NonVisualDataModule->EndBusy();
  2424. if (FErrorList)
  2425. {
  2426. HandleErrorList(FErrorList);
  2427. }
  2428. }
  2429. //---------------------------------------------------------------------------
  2430. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2431. const TCopyParamType & CopyParam)
  2432. {
  2433. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2434. {
  2435. Configuration->Usage->Inc(L"FileMaskUses");
  2436. }
  2437. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2438. {
  2439. Configuration->Usage->Inc(L"OperationMaskUses");
  2440. }
  2441. }
  2442. //---------------------------------------------------------------------------
  2443. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2444. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2445. {
  2446. DebugAssert(!IsLocalBrowserMode());
  2447. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2448. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2449. TTransferOperationParam DefaultParam;
  2450. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2451. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2452. switch (Param.Queue)
  2453. {
  2454. case asOn:
  2455. CopyParam.Queue = true;
  2456. break;
  2457. case asOff:
  2458. CopyParam.Queue = false;
  2459. break;
  2460. case asAuto:
  2461. default:
  2462. // keep default
  2463. break;
  2464. }
  2465. bool Result =
  2466. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2467. if (Result)
  2468. {
  2469. DebugAssert(Terminal);
  2470. bool SelectionRestored = false;
  2471. TCustomDirView * DView = NULL;
  2472. if (HasDirView[Side])
  2473. {
  2474. DView = DirView(Side);
  2475. DView->SaveSelection();
  2476. DView->SaveSelectedNames();
  2477. }
  2478. UpdateCopyParamCounters(CopyParam);
  2479. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2480. DebugAssert(FTransferResumeList == NULL);
  2481. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2482. FMoveToQueue = false;
  2483. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2484. try
  2485. {
  2486. TStrings * PermanentFileList;
  2487. std::unique_ptr<TStrings> PermanentFileListOwner;
  2488. try
  2489. {
  2490. if (Side == osLocal)
  2491. {
  2492. PermanentFileList = FileList;
  2493. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2494. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2495. if (Operation == foMove)
  2496. {
  2497. ReloadLocalDirectory();
  2498. if (DView != NULL)
  2499. {
  2500. DView->RestoreSelection();
  2501. }
  2502. SelectionRestored = true;
  2503. }
  2504. }
  2505. else
  2506. {
  2507. // Clone the file list as it may refer to current directory files,
  2508. // which get destroyed, when the source directory is reloaded after foMove operation.
  2509. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2510. // But for a hotfix, we are not going to do such a big change.
  2511. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2512. PermanentFileList = PermanentFileListOwner.get();
  2513. try
  2514. {
  2515. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2516. }
  2517. __finally
  2518. {
  2519. if (Operation == foMove)
  2520. {
  2521. if (DView != NULL)
  2522. {
  2523. DView->RestoreSelection();
  2524. }
  2525. SelectionRestored = true;
  2526. }
  2527. ReloadLocalDirectory(Param.TargetDirectory);
  2528. }
  2529. }
  2530. }
  2531. catch (EAbort &)
  2532. {
  2533. if (FMoveToQueue)
  2534. {
  2535. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2536. DebugAssert(CopyParam.TransferSkipList == NULL);
  2537. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2538. if (TransferResumeList->Count > 0)
  2539. {
  2540. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2541. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2542. }
  2543. CopyParam.TransferSkipList = TransferResumeList.release();
  2544. // not really needed, just to keep it consistent with TransferResumeList
  2545. FTransferResumeList = NULL;
  2546. FMoveToQueue = false;
  2547. Configuration->Usage->Inc("MovesToBackground");
  2548. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2549. ClearTransferSourceSelection(Direction);
  2550. }
  2551. throw;
  2552. }
  2553. }
  2554. __finally
  2555. {
  2556. if (!SelectionRestored && (DView != NULL))
  2557. {
  2558. DView->DiscardSavedSelection();
  2559. }
  2560. FTransferResumeList = NULL;
  2561. }
  2562. }
  2563. return Result;
  2564. }
  2565. //---------------------------------------------------------------------------
  2566. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2567. TOperationSide Side, TStrings * FileList, void * Param)
  2568. {
  2569. DebugAssert(FileList->Count);
  2570. // We deliberately do not toggle alternative flag (Param), but use OR,
  2571. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2572. // shortcut of CurrentDeleteAlternativeAction
  2573. bool Alternative =
  2574. bool(Param) || UseAlternativeFunction();
  2575. bool Recycle;
  2576. if (IsSideLocalBrowser(Side))
  2577. {
  2578. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2579. }
  2580. else
  2581. {
  2582. Recycle =
  2583. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2584. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2585. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2586. }
  2587. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2588. if (!Result)
  2589. {
  2590. UnicodeString Query;
  2591. if (FileList->Count == 1)
  2592. {
  2593. if (IsSideLocalBrowser(Side))
  2594. {
  2595. Query = ExtractFileName(FileList->Strings[0]);
  2596. }
  2597. else
  2598. {
  2599. Query = UnixExtractFileName(FileList->Strings[0]);
  2600. }
  2601. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2602. }
  2603. else
  2604. {
  2605. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2606. }
  2607. TMessageParams Params(mpNeverAskAgainCheck);
  2608. Params.ImageName = L"Delete file";
  2609. unsigned int Answer =
  2610. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2611. if (Answer == qaNeverAskAgain)
  2612. {
  2613. Result = true;
  2614. if (Recycle)
  2615. {
  2616. WinConfiguration->ConfirmRecycling = false;
  2617. }
  2618. else
  2619. {
  2620. WinConfiguration->ConfirmDeleting = false;
  2621. }
  2622. }
  2623. else
  2624. {
  2625. Result = (Answer == qaOK);
  2626. }
  2627. }
  2628. if (Result)
  2629. {
  2630. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2631. }
  2632. return Result;
  2633. }
  2634. //---------------------------------------------------------------------------
  2635. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2636. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2637. {
  2638. TAutoBatch AutoBatch(this);
  2639. bool Result;
  2640. if ((Operation == foCopy) || (Operation == foMove))
  2641. {
  2642. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2643. }
  2644. else if (Operation == foRename)
  2645. {
  2646. DebugAssert(DirView(Side)->ItemFocused);
  2647. DirView(Side)->ItemFocused->EditCaption();
  2648. Result = true;
  2649. }
  2650. else if (Operation == foDelete)
  2651. {
  2652. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2653. }
  2654. else if (Operation == foSetProperties)
  2655. {
  2656. DirView(osRemote)->SaveSelectedNames();
  2657. Result = SetProperties(Side, FileList);
  2658. }
  2659. else if (Operation == foCustomCommand)
  2660. {
  2661. DebugAssert(Param);
  2662. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2663. DirView(osRemote)->SaveSelectedNames();
  2664. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2665. CustomCommand(FileList, *Command, NULL);
  2666. Result = true;
  2667. }
  2668. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2669. {
  2670. DebugAssert(!IsSideLocalBrowser(Side));
  2671. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2672. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2673. }
  2674. else if (Operation == foLock)
  2675. {
  2676. DebugAssert(!IsSideLocalBrowser(Side));
  2677. LockFiles(FileList, true);
  2678. Result = true;
  2679. }
  2680. else if (Operation == foUnlock)
  2681. {
  2682. DebugAssert(!IsSideLocalBrowser(Side));
  2683. LockFiles(FileList, false);
  2684. Result = true;
  2685. }
  2686. else
  2687. {
  2688. DebugFail();
  2689. }
  2690. return Result;
  2691. }
  2692. //---------------------------------------------------------------------------
  2693. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2694. {
  2695. if (Side == osCurrent)
  2696. {
  2697. Side = FCurrentSide;
  2698. }
  2699. return Side;
  2700. }
  2701. //---------------------------------------------------------------------------
  2702. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2703. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2704. {
  2705. Side = GetSide(Side);
  2706. bool Result;
  2707. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2708. try
  2709. {
  2710. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2711. }
  2712. __finally
  2713. {
  2714. delete FileList;
  2715. }
  2716. return Result;
  2717. }
  2718. //---------------------------------------------------------------------------
  2719. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2720. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2721. bool NoConfirmation, void * Param)
  2722. {
  2723. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2724. {
  2725. if ((Operation == foCopy) || (Operation == foMove))
  2726. {
  2727. DebugAssert(!IsLocalBrowserMode());
  2728. if (GetSide(Side) == osLocal)
  2729. {
  2730. Configuration->Usage->Inc(L"UploadsCommand");
  2731. }
  2732. else
  2733. {
  2734. Configuration->Usage->Inc(L"DownloadsCommand");
  2735. }
  2736. }
  2737. }
  2738. }
  2739. //---------------------------------------------------------------------------
  2740. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2741. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2742. {
  2743. TTransferOperationParam Param;
  2744. if ((WinConfiguration->Interface != ifCommander) ||
  2745. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2746. {
  2747. Flags &= ~cocShortCutHint;
  2748. }
  2749. TCustomDirView * DView = DirView(Side);
  2750. Param.Options =
  2751. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2752. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2753. if (FLAGSET(Flags, cocQueue))
  2754. {
  2755. Param.Queue = asOn;
  2756. }
  2757. else if (FLAGSET(Flags, cocNonQueue))
  2758. {
  2759. Param.Queue = asOff;
  2760. }
  2761. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2762. }
  2763. //---------------------------------------------------------------------------
  2764. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2765. {
  2766. try
  2767. {
  2768. if (ErrorList->Count)
  2769. {
  2770. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2771. if (MessageDialog(Message, qtError,
  2772. qaOK | qaCancel, HELP_NONE) == qaOK)
  2773. {
  2774. unsigned int Answer;
  2775. int Index = 0;
  2776. do
  2777. {
  2778. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2779. TQueryButtonAlias Aliases[2];
  2780. Aliases[0].Button = qaYes;
  2781. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2782. Aliases[1].Button = qaNo;
  2783. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2784. TMessageParams Params;
  2785. Params.Aliases = Aliases;
  2786. Params.AliasesCount = LENOF(Aliases);
  2787. Answer = MoreMessageDialog(
  2788. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2789. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2790. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2791. qaOK, HELP_NONE, &Params);
  2792. if (Answer == qaNo)
  2793. {
  2794. Index++;
  2795. }
  2796. if (Answer == qaYes)
  2797. {
  2798. Index--;
  2799. }
  2800. }
  2801. while (Answer != qaOK);
  2802. }
  2803. }
  2804. }
  2805. __finally
  2806. {
  2807. TStrings * List = ErrorList;
  2808. ErrorList = NULL;
  2809. for (int i = 0; i < List->Count; i++)
  2810. {
  2811. delete List->Objects[i];
  2812. }
  2813. delete List;
  2814. }
  2815. }
  2816. //---------------------------------------------------------------------------
  2817. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2818. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2819. {
  2820. // needed for checking filemasks, as there's no directory object
  2821. // associated with the file object
  2822. File->FullFileName = FullFileName;
  2823. TFileMasks::TParams MaskParams;
  2824. MaskParams.Size = File->Size;
  2825. MaskParams.Modification = File->Modification;
  2826. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2827. }
  2828. //---------------------------------------------------------------------------
  2829. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2830. {
  2831. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2832. Side = GetSide(Side);
  2833. TCustomDirView * DView = DirView(Side);
  2834. TListItem * FocusedItem = DView->ItemFocused;
  2835. UnicodeString Name;
  2836. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2837. {
  2838. Name = DView->ItemFileName(FocusedItem);
  2839. }
  2840. else
  2841. {
  2842. Name = LoadStr(NEW_FILE);
  2843. }
  2844. UnicodeString Names = Name;
  2845. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2846. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2847. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  2848. {
  2849. while (!Names.IsEmpty())
  2850. {
  2851. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2852. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2853. UnicodeString TargetFileName;
  2854. UnicodeString LocalFileName;
  2855. UnicodeString RootTempDir;
  2856. UnicodeString TempDir;
  2857. UnicodeString RemoteDirectory;
  2858. bool ExistingFile = false;
  2859. if (!IsSideLocalBrowser(Side))
  2860. {
  2861. Name = AbsolutePath(Terminal->CurrentDirectory, Name);
  2862. TRemoteFile * File = NULL;
  2863. if (Terminal->FileExists(Name, &File) &&
  2864. !File->IsDirectory)
  2865. {
  2866. try
  2867. {
  2868. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2869. ExistingFile = true;
  2870. }
  2871. __finally
  2872. {
  2873. delete File;
  2874. }
  2875. }
  2876. if (!ExistingFile)
  2877. {
  2878. RemoteDirectory = UnixExtractFilePath(Name);
  2879. TemporaryDirectoryForRemoteFiles(
  2880. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2881. TargetFileName = UnixExtractFileName(Name);
  2882. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2883. LocalFileName = TempDir +
  2884. // We probably do not want to trim the VMS version here
  2885. Terminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2886. }
  2887. }
  2888. else
  2889. {
  2890. if (ExtractFilePath(Name).IsEmpty())
  2891. {
  2892. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2893. }
  2894. else
  2895. {
  2896. LocalFileName = ExpandFileName(Name);
  2897. }
  2898. TargetFileName = ExtractFileName(Name);
  2899. }
  2900. if (!ExistingFile)
  2901. {
  2902. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2903. if (NewFile)
  2904. {
  2905. int File = FileCreate(ApiPath(LocalFileName));
  2906. if (File < 0)
  2907. {
  2908. if (!RootTempDir.IsEmpty())
  2909. {
  2910. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2911. }
  2912. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2913. }
  2914. else
  2915. {
  2916. FileClose(File);
  2917. }
  2918. }
  2919. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2920. const TEditorData * ExternalEditor = NULL;
  2921. TFileMasks::TParams MaskParams; // size not known
  2922. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2923. false, MaskParams);
  2924. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2925. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2926. }
  2927. }
  2928. }
  2929. }
  2930. //---------------------------------------------------------------------------
  2931. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2932. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2933. {
  2934. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2935. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2936. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2937. return
  2938. ((ExecuteFileBy == efInternalEditor)) ||
  2939. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2940. }
  2941. //---------------------------------------------------------------------------
  2942. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2943. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2944. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2945. UnicodeString RemoteDirectory, bool NewFile)
  2946. {
  2947. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2948. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2949. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2950. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2951. Side = GetSide(Side);
  2952. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2953. if (!IsSideLocalBrowser(Side))
  2954. {
  2955. Data->Terminal = Terminal;
  2956. Data->Queue = Queue;
  2957. Data->SessionData = CloneCurrentSessionData();
  2958. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2959. Data->RemoteDirectory = RemoteDirectory;
  2960. Data->SessionName = Terminal->SessionData->SessionName;
  2961. Data->LocalRootDirectory = LocalRootDirectory;
  2962. Data->OriginalFileName = OriginalFileName;
  2963. Data->Command = L""; // will be changed later for external editor
  2964. }
  2965. if (ExecuteFileBy == efInternalEditor)
  2966. {
  2967. if (!IsSideLocalBrowser(Side))
  2968. {
  2969. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2970. L" - " + Terminal->SessionData->SessionName;
  2971. TForm * Editor;
  2972. try
  2973. {
  2974. TNotifyEvent OnFileChanged = NULL;
  2975. TNotifyEvent OnSaveAll = NULL;
  2976. TAnyModifiedEvent OnAnyModified = NULL;
  2977. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2978. if (Terminal->IsCapable[fcBackgroundTransfers])
  2979. {
  2980. OnFileChanged = FEditorManager->FileChanged;
  2981. OnSaveAll = SaveAllInternalEditors;
  2982. OnAnyModified = AnyInternalEditorModified;
  2983. }
  2984. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2985. FEditorManager->FileReload, FEditorManager->FileClosed,
  2986. OnSaveAll, OnAnyModified,
  2987. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2988. }
  2989. catch(...)
  2990. {
  2991. if (!LocalRootDirectory.IsEmpty())
  2992. {
  2993. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2994. }
  2995. throw;
  2996. }
  2997. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2998. }
  2999. else
  3000. {
  3001. DebugAssert(!FStandaloneEditing);
  3002. TForm * Editor =
  3003. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  3004. SaveAllInternalEditors, AnyInternalEditorModified,
  3005. L"", false, SessionColor, -1, NewFile);
  3006. FLocalEditors->Add(Editor);
  3007. }
  3008. }
  3009. else
  3010. {
  3011. HANDLE Process;
  3012. if (ExecuteFileBy == efExternalEditor)
  3013. {
  3014. UnicodeString Program, Params, Dir;
  3015. Data->Command = ExternalEditor->ExternalEditor;
  3016. ReformatFileNameCommand(Data->Command);
  3017. SplitCommand(Data->Command, Program, Params, Dir);
  3018. Params = ExpandFileNameCommand(Params, FileName);
  3019. Program = ExpandEnvironmentVariables(Program);
  3020. if (!ExecuteShell(Program, Params, Process))
  3021. {
  3022. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3023. }
  3024. }
  3025. else
  3026. {
  3027. DebugAssert(!IsSideLocalBrowser(Side));
  3028. if (!ExecuteShell(FileName, L"", Process))
  3029. {
  3030. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3031. }
  3032. }
  3033. if (IsSideLocalBrowser(Side) ||
  3034. ((ExecuteFileBy == efShell) &&
  3035. !WinConfiguration->Editor.SDIShellEditor) ||
  3036. ((ExecuteFileBy == efExternalEditor) &&
  3037. !ExternalEditor->SDIExternalEditor))
  3038. {
  3039. // no need for handle
  3040. if (Process != NULL)
  3041. {
  3042. DebugCheck(CloseHandle(Process));
  3043. }
  3044. Process = INVALID_HANDLE_VALUE;
  3045. }
  3046. else
  3047. {
  3048. if (Process == NULL)
  3049. {
  3050. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3051. }
  3052. }
  3053. if (!IsSideLocalBrowser(Side))
  3054. {
  3055. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3056. }
  3057. }
  3058. }
  3059. //---------------------------------------------------------------------------
  3060. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3061. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3062. void * /*Arg*/)
  3063. {
  3064. if (Token != NULL)
  3065. {
  3066. EditorFormFileSave(static_cast<TForm *>(Token));
  3067. }
  3068. }
  3069. //---------------------------------------------------------------------------
  3070. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3071. {
  3072. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3073. {
  3074. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3075. }
  3076. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3077. }
  3078. //---------------------------------------------------------------------------
  3079. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3080. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3081. void * Arg)
  3082. {
  3083. if ((Token != NULL) &&
  3084. IsEditorFormModified(static_cast<TForm *>(Token)))
  3085. {
  3086. *static_cast<bool *>(Arg) = true;
  3087. }
  3088. }
  3089. //---------------------------------------------------------------------------
  3090. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3091. TObject * /*Sender*/, bool & Modified)
  3092. {
  3093. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3094. {
  3095. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3096. {
  3097. Modified = true;
  3098. }
  3099. }
  3100. if (!Modified)
  3101. {
  3102. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3103. }
  3104. }
  3105. //---------------------------------------------------------------------------
  3106. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3107. {
  3108. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3109. }
  3110. //---------------------------------------------------------------------------
  3111. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3112. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3113. UnicodeString & Result, UnicodeString & RootDirectory)
  3114. {
  3115. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3116. {
  3117. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3118. Result = RootDirectory;
  3119. }
  3120. else
  3121. {
  3122. RootDirectory = L"";
  3123. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3124. Result = IncludeTrailingBackslash(Result);
  3125. }
  3126. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3127. {
  3128. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3129. }
  3130. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3131. {
  3132. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3133. {
  3134. RemoteDirectory.Delete(1, 1);
  3135. }
  3136. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3137. }
  3138. if (!ForceDirectories(ApiPath(Result)))
  3139. {
  3140. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3141. }
  3142. }
  3143. //---------------------------------------------------------------------------
  3144. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3145. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3146. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3147. {
  3148. DebugAssert(!IsLocalBrowserMode());
  3149. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3150. if (ForceText)
  3151. {
  3152. CopyParam.TransferMode = tmAscii;
  3153. }
  3154. TemporaryFileCopyParam(CopyParam);
  3155. if (AllFiles)
  3156. {
  3157. CopyParam.IncludeFileMask = TFileMasks();
  3158. }
  3159. if (TempDir.IsEmpty())
  3160. {
  3161. TemporaryDirectoryForRemoteFiles(Terminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3162. }
  3163. DebugAssert(!FAutoOperation);
  3164. FAutoOperation = AutoOperation;
  3165. Terminal->ExceptionOnFail = true;
  3166. try
  3167. {
  3168. try
  3169. {
  3170. // turn off confirmations, as for MDI editors we may possibly download
  3171. // the same file over
  3172. Terminal->CopyToLocal(
  3173. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3174. if (GetTargetNames)
  3175. {
  3176. for (int i = 0; i < FileList->Count; i++)
  3177. {
  3178. FileList->Strings[i] =
  3179. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3180. }
  3181. }
  3182. }
  3183. catch(...)
  3184. {
  3185. if (!RootTempDir.IsEmpty())
  3186. {
  3187. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3188. }
  3189. throw;
  3190. }
  3191. }
  3192. __finally
  3193. {
  3194. FAutoOperation = false;
  3195. Terminal->ExceptionOnFail = false;
  3196. }
  3197. }
  3198. //---------------------------------------------------------------------------
  3199. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3200. {
  3201. // Do not waste time checking for default editor list the next time,
  3202. // or testing if default editor is not notepad.
  3203. bool TryNextTime = false;
  3204. UnicodeString UsageState;
  3205. if (!WinConfiguration->EditorList->IsDefaultList())
  3206. {
  3207. UsageState = "H";
  3208. }
  3209. else
  3210. {
  3211. UnicodeString Executable;
  3212. UnicodeString ExecutableDescription;
  3213. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3214. {
  3215. UnicodeString Message =
  3216. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3217. unsigned int Answer =
  3218. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3219. if (Answer != qaOK)
  3220. {
  3221. UsageState = "R";
  3222. }
  3223. else
  3224. {
  3225. UsageState = "A";
  3226. TEditorData EditorData;
  3227. EditorData.Editor = edExternal;
  3228. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3229. EditorData.ExternalEditorOptionsAutodetect();
  3230. TEditorList EditorList;
  3231. EditorList = *WinConfiguration->EditorList;
  3232. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3233. WinConfiguration->EditorList = &EditorList;
  3234. }
  3235. }
  3236. }
  3237. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3238. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3239. }
  3240. //---------------------------------------------------------------------------
  3241. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3242. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3243. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3244. {
  3245. if (ExecuteFileBy == efDefaultEditor)
  3246. {
  3247. if (!WinConfiguration->OfferedEditorAutoConfig)
  3248. {
  3249. EditorAutoConfig();
  3250. }
  3251. const TEditorPreferences * Editor =
  3252. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3253. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3254. {
  3255. ExecuteFileBy = efInternalEditor;
  3256. ExternalEditor = NULL;
  3257. }
  3258. else if (Editor->Data->Editor == edOpen)
  3259. {
  3260. ExecuteFileBy = efShell;
  3261. ExternalEditor = NULL;
  3262. }
  3263. else
  3264. {
  3265. ExecuteFileBy = efExternalEditor;
  3266. ExternalEditor = Editor->Data;
  3267. }
  3268. }
  3269. }
  3270. //---------------------------------------------------------------------------
  3271. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3272. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3273. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3274. {
  3275. UnicodeString OriginalFileName;
  3276. UnicodeString LocalRootDirectory;
  3277. UnicodeString RemoteDirectory;
  3278. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3279. IsSideLocalBrowser(Side), MaskParams);
  3280. UnicodeString Counter;
  3281. UnicodeString LocalFileName;
  3282. bool Handled = false;
  3283. if (!IsSideLocalBrowser(Side))
  3284. {
  3285. // We need to trim VMS version here, so that we use name without version
  3286. // when uploading back to create a new version of the file
  3287. OriginalFileName = Terminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3288. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3289. TObject * Token = NULL;
  3290. UnicodeString LocalDirectory;
  3291. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3292. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3293. LocalDirectory))
  3294. {
  3295. if (Token != NULL)
  3296. {
  3297. TForm * Form = dynamic_cast<TForm *>(Token);
  3298. if (Form->WindowState == wsMinimized)
  3299. {
  3300. ShowWindow(Form->Handle, SW_RESTORE);
  3301. }
  3302. else
  3303. {
  3304. Form->SetFocus();
  3305. }
  3306. Handled = true;
  3307. }
  3308. else
  3309. {
  3310. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3311. }
  3312. }
  3313. if (!Handled)
  3314. {
  3315. TStringList * FileList1 = new TStringList();
  3316. try
  3317. {
  3318. FileList1->AddObject(FullFileName, Object);
  3319. TemporarilyDownloadFiles(FileList1,
  3320. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3321. LocalRootDirectory, LocalDirectory, true, true, true);
  3322. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3323. }
  3324. __finally
  3325. {
  3326. delete FileList1;
  3327. }
  3328. switch (ExecuteFileBy)
  3329. {
  3330. case efShell:
  3331. Counter = "RemoteFilesExecuted";
  3332. break;
  3333. case efInternalEditor:
  3334. Counter = "RemoteFilesOpenedInInternalEditor";
  3335. break;
  3336. case efExternalEditor:
  3337. Counter = "RemoteFilesOpenedInExternalEditor";
  3338. break;
  3339. default:
  3340. DebugFail();
  3341. }
  3342. }
  3343. }
  3344. else
  3345. {
  3346. LocalFileName = FullFileName;
  3347. OriginalFileName = ExtractFileName(FullFileName);
  3348. switch (ExecuteFileBy)
  3349. {
  3350. case efShell:
  3351. Counter = "LocalFilesExecuted";
  3352. break;
  3353. case efInternalEditor:
  3354. Counter = "LocalFilesOpenedInInternalEditor";
  3355. break;
  3356. case efExternalEditor:
  3357. Counter = "LocalFilesOpenedInExternalEditor";
  3358. break;
  3359. default:
  3360. DebugFail();
  3361. }
  3362. }
  3363. if (!Handled)
  3364. {
  3365. Configuration->Usage->Inc(Counter);
  3366. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3367. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3368. }
  3369. }
  3370. //---------------------------------------------------------------------------
  3371. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3372. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3373. bool AllSelected, bool OnFocused)
  3374. {
  3375. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3376. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3377. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3378. Side = GetSide(Side);
  3379. TCustomDirView * DView = DirView(Side);
  3380. TStrings * FileList =
  3381. AllSelected ?
  3382. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3383. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3384. try
  3385. {
  3386. DebugAssert(AllSelected || (FileList->Count == 1));
  3387. for (int i = 0; i < FileList->Count; i++)
  3388. {
  3389. UnicodeString ListFileName = FileList->Strings[i];
  3390. UnicodeString FileNameOnly =
  3391. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3392. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3393. if (!DView->ItemIsDirectory(Item))
  3394. {
  3395. UnicodeString FullFileName;
  3396. if (!IsSideLocalBrowser(Side))
  3397. {
  3398. FullFileName = DirView(Side)->Path + ListFileName;
  3399. }
  3400. else
  3401. {
  3402. FullFileName = ListFileName;
  3403. }
  3404. TFileMasks::TParams MaskParams;
  3405. MaskParams.Size = DView->ItemFileSize(Item);
  3406. TDateTimePrecision Precision;
  3407. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3408. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3409. FileList->Objects[i], MaskParams);
  3410. }
  3411. }
  3412. }
  3413. __finally
  3414. {
  3415. delete FileList;
  3416. }
  3417. }
  3418. //---------------------------------------------------------------------------
  3419. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3420. {
  3421. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3422. CopyParam.FileNameCase = ncNoChange;
  3423. CopyParam.PreserveRights = false;
  3424. CopyParam.PreserveReadOnly = false;
  3425. CopyParam.ReplaceInvalidChars = true;
  3426. CopyParam.IncludeFileMask = TFileMasks();
  3427. CopyParam.NewerOnly = false;
  3428. CopyParam.FileMask = L"";
  3429. }
  3430. //---------------------------------------------------------------------------
  3431. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3432. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3433. {
  3434. TTerminalManager * Manager = TTerminalManager::Instance();
  3435. if (!IsActiveTerminal(Data->Terminal))
  3436. {
  3437. if (!NonVisualDataModule->Busy)
  3438. {
  3439. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3440. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3441. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3442. if (Data->Terminal == NULL)
  3443. {
  3444. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3445. if (SameSiteTerminal != NULL)
  3446. {
  3447. UnicodeString Message =
  3448. FMTLOAD(EDIT_SESSION_REATTACH,
  3449. (FileNameOnly, Data->SessionName, FileNameOnly));
  3450. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3451. {
  3452. Data->Terminal = Terminal;
  3453. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3454. Data->SessionName = Terminal->SessionData->SessionName;
  3455. // We might also overwrite session data
  3456. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3457. }
  3458. else
  3459. {
  3460. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3461. Abort();
  3462. }
  3463. }
  3464. }
  3465. // foreground session should reconnect itself
  3466. else if (Terminal != Data->Terminal)
  3467. {
  3468. UnicodeString Message =
  3469. MainInstructions(
  3470. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3471. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3472. {
  3473. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3474. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3475. }
  3476. else
  3477. {
  3478. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3479. Abort();
  3480. }
  3481. }
  3482. }
  3483. if (!IsActiveTerminal(Data->Terminal))
  3484. {
  3485. Configuration->Usage->Inc(L"EditInactiveSession");
  3486. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3487. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3488. (ExtractFileName(FileName), Data->SessionName)));
  3489. }
  3490. }
  3491. TStrings * FileList = new TStringList();
  3492. try
  3493. {
  3494. FileList->Add(FileName);
  3495. // consider using the same settings (preset) as when the file was downloaded
  3496. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3497. TemporaryFileCopyParam(CopyParam);
  3498. if (Data->ForceText)
  3499. {
  3500. CopyParam.TransferMode = tmAscii;
  3501. }
  3502. // so i do not need to worry if masking algorithm works in all cases
  3503. // ("" means "copy file name", no masking is actually done)
  3504. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3505. {
  3506. CopyParam.FileMask = L"";
  3507. }
  3508. else
  3509. {
  3510. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3511. }
  3512. DebugAssert(Data->Queue != NULL);
  3513. int Params = cpNoConfirmation | cpTemporary;
  3514. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3515. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3516. QueueItem->CompleteEvent = UploadCompleteEvent;
  3517. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3518. }
  3519. __finally
  3520. {
  3521. delete FileList;
  3522. }
  3523. }
  3524. //---------------------------------------------------------------------------
  3525. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3526. const UnicodeString FileName, const TEditedFileData * Data)
  3527. {
  3528. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3529. DebugAssert(!NonVisualDataModule->Busy);
  3530. if (!IsActiveTerminal(Data->Terminal))
  3531. {
  3532. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3533. (ExtractFileName(FileName), Data->SessionName)));
  3534. }
  3535. TManagedTerminal * PrevSession = TTerminalManager::Instance()->ActiveSession;
  3536. TTerminalManager::Instance()->ActiveSession = Data->Terminal;
  3537. NonVisualDataModule->StartBusy();
  3538. try
  3539. {
  3540. std::unique_ptr<TRemoteFile> File;
  3541. UnicodeString RemoteFileName =
  3542. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3543. Terminal->ExceptionOnFail = true;
  3544. try
  3545. {
  3546. TRemoteFile * AFile = NULL;
  3547. Terminal->ReadFile(RemoteFileName, AFile);
  3548. File.reset(AFile);
  3549. if (!File->HaveFullFileName)
  3550. {
  3551. File->FullFileName = RemoteFileName;
  3552. }
  3553. }
  3554. __finally
  3555. {
  3556. Terminal->ExceptionOnFail = false;
  3557. }
  3558. std::unique_ptr<TStrings> FileList(new TStringList());
  3559. FileList->AddObject(RemoteFileName, File.get());
  3560. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3561. UnicodeString TempDir = ExtractFilePath(FileName);
  3562. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3563. TempDir, true, true, true);
  3564. // sanity check, the target file name should be still the same
  3565. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3566. }
  3567. __finally
  3568. {
  3569. NonVisualDataModule->EndBusy();
  3570. // it actually may not exist anymore...
  3571. TTerminalManager::Instance()->ActiveSession = PrevSession;
  3572. }
  3573. }
  3574. //---------------------------------------------------------------------------
  3575. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3576. const TEditedFileData * Data, bool & KeepOpen)
  3577. {
  3578. // Command is set for external editors only (not for "shell" open).
  3579. if (!Data->Command.IsEmpty())
  3580. {
  3581. bool AnyFound = false;
  3582. bool AnyMDI = false;
  3583. bool AnyNonMDI = false;
  3584. bool AnyDetect = false;
  3585. TEditorList * EditorList = new TEditorList();
  3586. try
  3587. {
  3588. *EditorList = *WinConfiguration->EditorList;
  3589. for (int i = 0; i < EditorList->Count; i++)
  3590. {
  3591. const TEditorPreferences * Editor = EditorList->Editors[i];
  3592. if ((Editor->Data->Editor == edExternal) &&
  3593. (Editor->Data->ExternalEditor == Data->Command))
  3594. {
  3595. AnyFound = true;
  3596. if (Editor->Data->SDIExternalEditor)
  3597. {
  3598. AnyNonMDI = true;
  3599. if (Editor->Data->DetectMDIExternalEditor)
  3600. {
  3601. AnyDetect = true;
  3602. }
  3603. }
  3604. else
  3605. {
  3606. AnyMDI = true;
  3607. }
  3608. }
  3609. }
  3610. bool EnableMDI = false;
  3611. bool DisableDetect = false;
  3612. if (AnyMDI)
  3613. {
  3614. KeepOpen = true;
  3615. if (AnyNonMDI)
  3616. {
  3617. // there is at least one instance of the editor with MDI support enabled,
  3618. // and one with disabled, enable it for all instances
  3619. EnableMDI = true;
  3620. }
  3621. }
  3622. else if (AnyFound && !AnyDetect)
  3623. {
  3624. // at least once instance found but all have MDI autodetection disabled
  3625. // => close the file (default action)
  3626. }
  3627. else
  3628. {
  3629. // no instance of the editor has MDI support enabled
  3630. TMessageParams Params;
  3631. if (AnyFound)
  3632. {
  3633. // there is at least one instance of the editor
  3634. Params.Params |= mpNeverAskAgainCheck;
  3635. }
  3636. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3637. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3638. switch (Answer)
  3639. {
  3640. case qaNeverAskAgain:
  3641. DisableDetect = true;
  3642. break;
  3643. case qaNo:
  3644. EnableMDI = true;
  3645. KeepOpen = true;
  3646. break;
  3647. }
  3648. }
  3649. if (AnyFound && (EnableMDI || DisableDetect))
  3650. {
  3651. bool Changed = false;
  3652. for (int i = 0; i < EditorList->Count; i++)
  3653. {
  3654. const TEditorPreferences * Editor = EditorList->Editors[i];
  3655. if ((Editor->Data->Editor == edExternal) &&
  3656. (Editor->Data->ExternalEditor == Data->Command) &&
  3657. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3658. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3659. {
  3660. Changed = true;
  3661. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3662. if (EnableMDI)
  3663. {
  3664. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3665. }
  3666. if (DisableDetect)
  3667. {
  3668. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3669. }
  3670. EditorList->Change(i, UpdatedEditor);
  3671. }
  3672. }
  3673. if (Changed)
  3674. {
  3675. WinConfiguration->EditorList = EditorList;
  3676. }
  3677. }
  3678. }
  3679. __finally
  3680. {
  3681. delete EditorList;
  3682. }
  3683. }
  3684. else
  3685. {
  3686. // "open" case
  3687. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3688. qaOK, HELP_APP_EARLY_CLOSED);
  3689. }
  3690. }
  3691. //---------------------------------------------------------------------------
  3692. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3693. {
  3694. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3695. }
  3696. //---------------------------------------------------------------------------
  3697. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3698. {
  3699. SideEnter(osRemote);
  3700. }
  3701. //---------------------------------------------------------------------------
  3702. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3703. {
  3704. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3705. SideEnter(osRemote);
  3706. }
  3707. //---------------------------------------------------------------------------
  3708. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3709. {
  3710. FCurrentSide = Side;
  3711. if (Visible)
  3712. {
  3713. UpdateControls();
  3714. }
  3715. }
  3716. //---------------------------------------------------------------------------
  3717. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3718. TStrings * FileList, bool Alternative)
  3719. {
  3720. TCustomDirView * DView = DirView(Side);
  3721. DView->SaveSelection();
  3722. DView->SaveSelectedNames();
  3723. DebugAssert(!FAlternativeDelete);
  3724. FAlternativeDelete = Alternative;
  3725. try
  3726. {
  3727. if (!IsSideLocalBrowser(Side))
  3728. {
  3729. DebugAssert(Terminal != NULL);
  3730. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3731. }
  3732. else
  3733. {
  3734. if (IsLocalBrowserMode())
  3735. {
  3736. Configuration->Usage->Inc(L"LocalLocalDeletes");
  3737. }
  3738. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  3739. FProgressSide = FCurrentSide;
  3740. try
  3741. {
  3742. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3743. }
  3744. __finally
  3745. {
  3746. ReloadLocalDirectory();
  3747. }
  3748. }
  3749. FAlternativeDelete = false;
  3750. }
  3751. catch(...)
  3752. {
  3753. FAlternativeDelete = false;
  3754. DView->DiscardSavedSelection();
  3755. throw;
  3756. }
  3757. DView->RestoreSelection();
  3758. }
  3759. //---------------------------------------------------------------------------
  3760. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3761. {
  3762. DebugAssert(Terminal);
  3763. DebugAssert(!IsLocalBrowserMode());
  3764. RemoteDirView->SaveSelection();
  3765. RemoteDirView->SaveSelectedNames();
  3766. try
  3767. {
  3768. if (Lock)
  3769. {
  3770. Terminal->LockFiles(FileList);
  3771. }
  3772. else
  3773. {
  3774. Terminal->UnlockFiles(FileList);
  3775. }
  3776. }
  3777. catch(...)
  3778. {
  3779. RemoteDirView->DiscardSavedSelection();
  3780. throw;
  3781. }
  3782. RemoteDirView->RestoreSelection();
  3783. }
  3784. //---------------------------------------------------------------------------
  3785. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3786. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3787. bool NoConfirmation, bool Move)
  3788. {
  3789. DebugAssert(Terminal != NULL);
  3790. DebugAssert(!IsLocalBrowserMode());
  3791. // update Terminal->StateData->RemoteDirectory
  3792. UpdateSession(Terminal);
  3793. if (Session == NULL)
  3794. {
  3795. Session = TTerminalManager::Instance()->ActiveTerminal;
  3796. }
  3797. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3798. {
  3799. if (RemoteDriveView->DropTarget != NULL)
  3800. {
  3801. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3802. }
  3803. else if (RemoteDirView->DropTarget != NULL)
  3804. {
  3805. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3806. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3807. }
  3808. else
  3809. {
  3810. Target = RemoteDirView->Path;
  3811. }
  3812. }
  3813. else
  3814. {
  3815. Target = Session->StateData->RemoteDirectory;
  3816. }
  3817. Target = UnixIncludeTrailingBackslash(Target);
  3818. if (FileList->Count == 1)
  3819. {
  3820. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3821. }
  3822. else
  3823. {
  3824. FileMask = AnyMask;
  3825. }
  3826. DirectCopy = Terminal->IsCapable[fcRemoteCopy] || Terminal->IsCapable[fcSecondaryShell];
  3827. bool Result = true;
  3828. if (!NoConfirmation)
  3829. {
  3830. bool Multi = (FileList->Count > 1);
  3831. if (Move)
  3832. {
  3833. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3834. }
  3835. else
  3836. {
  3837. TStrings * Sessions = TTerminalManager::Instance()->SessionList;
  3838. TStrings * Directories = new TStringList;
  3839. try
  3840. {
  3841. for (int Index = 0; Index < Sessions->Count; Index++)
  3842. {
  3843. TManagedTerminal * Terminal =
  3844. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3845. Directories->Add(Terminal->StateData->RemoteDirectory);
  3846. }
  3847. TDirectRemoteCopy AllowDirectCopy;
  3848. if (Terminal->IsCapable[fcRemoteCopy] || Terminal->CommandSessionOpened)
  3849. {
  3850. DebugAssert(DirectCopy);
  3851. AllowDirectCopy = drcAllow;
  3852. }
  3853. else if (Terminal->IsCapable[fcSecondaryShell])
  3854. {
  3855. DebugAssert(DirectCopy);
  3856. AllowDirectCopy = drcConfirmCommandSession;
  3857. }
  3858. else
  3859. {
  3860. DebugAssert(!DirectCopy);
  3861. AllowDirectCopy = drcDisallow;
  3862. }
  3863. void * ASession = Session;
  3864. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3865. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3866. Session = static_cast<TManagedTerminal *>(ASession);
  3867. }
  3868. __finally
  3869. {
  3870. delete Directories;
  3871. }
  3872. }
  3873. }
  3874. return Result;
  3875. }
  3876. //---------------------------------------------------------------------------
  3877. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3878. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3879. {
  3880. DebugAssert(!IsLocalBrowserMode());
  3881. bool DirectCopy;
  3882. UnicodeString Target, FileMask;
  3883. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3884. if (Result)
  3885. {
  3886. if (!Move && !DirectCopy)
  3887. {
  3888. Configuration->Usage->Inc("RemoteCopyTemp");
  3889. UnicodeString RootTempDir;
  3890. UnicodeString TempDir;
  3891. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3892. TStrings * TemporaryFilesList = new TStringList();
  3893. try
  3894. {
  3895. TMakeLocalFileListParams MakeFileListParam;
  3896. MakeFileListParam.FileList = TemporaryFilesList;
  3897. MakeFileListParam.FileTimes = NULL;
  3898. MakeFileListParam.IncludeDirs = true;
  3899. MakeFileListParam.Recursive = false;
  3900. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  3901. TTerminalManager::Instance()->ActiveSession = Session;
  3902. if (TemporaryFilesList->Count > 0)
  3903. {
  3904. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3905. CopyParam.FileMask = FileMask;
  3906. DebugAssert(!FAutoOperation);
  3907. FAutoOperation = true;
  3908. Terminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3909. }
  3910. }
  3911. __finally
  3912. {
  3913. delete TemporaryFilesList;
  3914. FAutoOperation = false;
  3915. if (!RootTempDir.IsEmpty())
  3916. {
  3917. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3918. }
  3919. }
  3920. }
  3921. else
  3922. {
  3923. RemoteDirView->SaveSelection();
  3924. RemoteDirView->SaveSelectedNames();
  3925. try
  3926. {
  3927. if (Move)
  3928. {
  3929. Configuration->Usage->Inc("RemoteMove");
  3930. Terminal->MoveFiles(FileList, Target, FileMask);
  3931. }
  3932. else
  3933. {
  3934. Configuration->Usage->Inc("RemoteCopyDirect");
  3935. DebugAssert(DirectCopy);
  3936. DebugAssert(Session == Terminal);
  3937. if (Terminal->IsCapable[fcRemoteCopy] ||
  3938. Terminal->CommandSessionOpened ||
  3939. CommandSessionFallback())
  3940. {
  3941. Terminal->CopyFiles(FileList, Target, FileMask);
  3942. }
  3943. }
  3944. }
  3945. catch(...)
  3946. {
  3947. RemoteDirView->DiscardSavedSelection();
  3948. throw;
  3949. }
  3950. RemoteDirView->RestoreSelection();
  3951. }
  3952. }
  3953. return Result;
  3954. }
  3955. //---------------------------------------------------------------------------
  3956. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3957. const UnicodeString & Path, TRemoteProperties & Properties)
  3958. {
  3959. DebugAssert(!IsLocalBrowserMode());
  3960. Properties.Valid = Properties.Valid << vpEncrypt;
  3961. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3962. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3963. }
  3964. //---------------------------------------------------------------------------
  3965. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3966. {
  3967. Side = GetSide(Side);
  3968. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3969. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3970. UnicodeString Name = LoadStr(NEW_FOLDER);
  3971. int AllowedChanges =
  3972. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3973. bool SaveSettings = false;
  3974. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3975. {
  3976. TWindowLock Lock(this);
  3977. if (!IsSideLocalBrowser(Side))
  3978. {
  3979. if (SaveSettings)
  3980. {
  3981. GUIConfiguration->NewDirectoryProperties = Properties;
  3982. }
  3983. CreateRemoteDirectory(Name, Properties);
  3984. }
  3985. else
  3986. {
  3987. DirView(Side)->CreateDirectory(Name);
  3988. }
  3989. }
  3990. }
  3991. //---------------------------------------------------------------------------
  3992. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3993. {
  3994. TWindowLock Lock(this);
  3995. DirView(Side)->ExecuteHomeDirectory();
  3996. }
  3997. //---------------------------------------------------------------------------
  3998. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3999. {
  4000. DoOpenDirectoryDialog(odBrowse, Side);
  4001. }
  4002. //---------------------------------------------------------------------------
  4003. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  4004. {
  4005. TOperationSide BookmarkSide = IsLocalBrowserMode() ? osLocal : Side;
  4006. UnicodeString Path = Bookmark->GetSideDirectory(BookmarkSide);
  4007. bool Result = !Path.IsEmpty();
  4008. if (Result)
  4009. {
  4010. // While we might get here when the session is closed (from location profiles),
  4011. // it's not a problem as the Path setter is noop then
  4012. DirView(Side)->Path = Path;
  4013. }
  4014. return Result;
  4015. }
  4016. //---------------------------------------------------------------------------
  4017. void __fastcall TCustomScpExplorerForm::CalculateSize(
  4018. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  4019. bool & Close)
  4020. {
  4021. // terminal can be already closed (e.g. dropped connection)
  4022. if (Terminal != NULL)
  4023. {
  4024. try
  4025. {
  4026. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  4027. }
  4028. catch(...)
  4029. {
  4030. if (!Terminal->Active)
  4031. {
  4032. Close = true;
  4033. }
  4034. throw;
  4035. }
  4036. }
  4037. }
  4038. //---------------------------------------------------------------------------
  4039. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4040. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4041. bool & Close)
  4042. {
  4043. // terminal can be already closed (e.g. dropped connection)
  4044. if (Terminal != NULL)
  4045. {
  4046. Configuration->Usage->Inc(L"ChecksumCalculated");
  4047. try
  4048. {
  4049. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4050. }
  4051. catch(...)
  4052. {
  4053. if (!Terminal->Active)
  4054. {
  4055. Close = true;
  4056. }
  4057. throw;
  4058. }
  4059. }
  4060. }
  4061. //---------------------------------------------------------------------------
  4062. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4063. {
  4064. bool Result;
  4065. if (!IsSideLocalBrowser(Side))
  4066. {
  4067. TRemoteTokenList * GroupList = NULL;
  4068. TRemoteTokenList * UserList = NULL;
  4069. try
  4070. {
  4071. TRemoteProperties CurrentProperties;
  4072. if (Terminal->LoadFilesProperties(FileList))
  4073. {
  4074. RemoteDirView->Invalidate();
  4075. }
  4076. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4077. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4078. if (CapableGroupChanging || CapableOwnerChanging)
  4079. {
  4080. if (CapableGroupChanging)
  4081. {
  4082. GroupList = Terminal->Groups->Duplicate();
  4083. }
  4084. if (CapableOwnerChanging)
  4085. {
  4086. UserList = Terminal->Users->Duplicate();
  4087. }
  4088. TRemoteDirectory * Files = Terminal->Files;
  4089. int Count = Files->Count;
  4090. if (Count > 100)
  4091. {
  4092. Count = 100;
  4093. }
  4094. for (int Index = 0; Index < Count; Index++)
  4095. {
  4096. TRemoteFile * File = Files->Files[Index];
  4097. if (CapableGroupChanging)
  4098. {
  4099. GroupList->AddUnique(File->Group);
  4100. }
  4101. if (CapableOwnerChanging)
  4102. {
  4103. UserList->AddUnique(File->Owner);
  4104. }
  4105. }
  4106. // if we haven't collected tokens for all files in current directory,
  4107. // make sure we collect them at least for all selected files.
  4108. // (note that so far the files in FileList has to be from current direcotry)
  4109. if (Count < Files->Count)
  4110. {
  4111. for (int Index = 0; Index < FileList->Count; Index++)
  4112. {
  4113. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4114. if (CapableGroupChanging)
  4115. {
  4116. GroupList->AddUnique(File->Group);
  4117. }
  4118. if (CapableOwnerChanging)
  4119. {
  4120. UserList->AddUnique(File->Owner);
  4121. }
  4122. }
  4123. }
  4124. }
  4125. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4126. int Flags = 0;
  4127. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4128. if (CapableOwnerChanging) Flags |= cpOwner;
  4129. if (CapableGroupChanging) Flags |= cpGroup;
  4130. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4131. if (Terminal->IsCapable[fcCalculatingChecksum])
  4132. {
  4133. CalculateChecksumEvent = CalculateChecksum;
  4134. }
  4135. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4136. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4137. TRemoteProperties NewProperties = CurrentProperties;
  4138. Result =
  4139. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4140. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4141. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4142. CalculateSize, CalculateChecksumEvent);
  4143. if (Result)
  4144. {
  4145. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4146. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4147. }
  4148. }
  4149. __finally
  4150. {
  4151. delete GroupList;
  4152. delete UserList;
  4153. }
  4154. }
  4155. else
  4156. {
  4157. DirView(Side)->DisplayPropertiesMenu();
  4158. Result = true;
  4159. }
  4160. return Result;
  4161. }
  4162. //---------------------------------------------------------------------------
  4163. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4164. {
  4165. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4166. {
  4167. FIgnoreNextDialogChar = Key;
  4168. }
  4169. Key = 0;
  4170. }
  4171. //---------------------------------------------------------------------------
  4172. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4173. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4174. {
  4175. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4176. if (Command != NULL)
  4177. {
  4178. KeyProcessed(Key, Shift);
  4179. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4180. {
  4181. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4182. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4183. false, false, const_cast<TCustomCommandType *>(Command));
  4184. }
  4185. }
  4186. }
  4187. //---------------------------------------------------------------------------
  4188. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4189. {
  4190. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4191. {
  4192. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4193. }
  4194. if (!DirView(osCurrent)->IsEditing())
  4195. {
  4196. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4197. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4198. {
  4199. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4200. // But so far it's not a problem, as it does what we want.
  4201. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4202. if (((Action->ShortCut == KeyShortCut) ||
  4203. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4204. AllowedAction(Action, aaShortCut))
  4205. {
  4206. // Has to be called before the action as the dialog char is already in queue.
  4207. // So when the action consumes message queue, we already need to have the
  4208. // FIgnoreNextDialogChar set
  4209. KeyProcessed(Key, Shift);
  4210. // Reset reference to previous component (when menu/toolbar was clicked).
  4211. // Needed to detect that action was invoked by keyboard shortcut
  4212. // in TNonVisualDataModule::ExplorerActionsExecute
  4213. Action->ActionComponent = NULL;
  4214. Action->Execute();
  4215. return;
  4216. }
  4217. }
  4218. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4219. {
  4220. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4221. {
  4222. KeyProcessed(Key, Shift);
  4223. TTerminalManager::Instance()->ActiveSessionIndex = i;
  4224. return;
  4225. }
  4226. }
  4227. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4228. {
  4229. KeyProcessed(Key, Shift);
  4230. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4231. }
  4232. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4233. if (IsCustomShortCut(CustomShortCut))
  4234. {
  4235. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4236. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4237. if (WinConfiguration->SharedBookmarks != NULL)
  4238. {
  4239. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4240. if ((Bookmark != NULL) &&
  4241. OpenBookmark(FCurrentSide, Bookmark))
  4242. {
  4243. KeyProcessed(Key, Shift);
  4244. }
  4245. }
  4246. }
  4247. }
  4248. TForm::KeyDown(Key, Shift);
  4249. }
  4250. //---------------------------------------------------------------------------
  4251. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4252. {
  4253. bool OpenedTerminal = false;
  4254. UnicodeString ProtocolName;
  4255. UnicodeString ProtocolNameHint;
  4256. UnicodeString SecurityProtocolName;
  4257. UnicodeString DurationHint;
  4258. // See the comment in TScpCommanderForm::UpdateControls()
  4259. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4260. if (ActiveTerminal != NULL)
  4261. {
  4262. // Active is not enough here
  4263. if (ActiveTerminal->Status == ssOpened)
  4264. {
  4265. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4266. const TFileSystemInfo & FileSystemInfo = ActiveTerminal->GetFileSystemInfo();
  4267. if (FileSystemInfo.ProtocolName.IsEmpty())
  4268. {
  4269. ProtocolName = SessionInfo.ProtocolName;
  4270. }
  4271. else
  4272. {
  4273. ProtocolName = FileSystemInfo.ProtocolName;
  4274. }
  4275. ProtocolNameHint = LoadStr(STATUS_PROTOCOL_HINT);
  4276. SecurityProtocolName = SessionInfo.SecurityProtocolName;
  4277. DurationHint = LoadStr(STATUS_DURATION_HINT);
  4278. OpenedTerminal = true;
  4279. }
  4280. else if (ActiveTerminal->Status > ssClosed)
  4281. {
  4282. ProtocolName = LoadStr(STATUS_CONNECTING);
  4283. }
  4284. else
  4285. {
  4286. ProtocolName = LoadStr(STATUS_NOT_CONNECTED2);
  4287. }
  4288. }
  4289. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4290. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4291. TTBXStatusPanel * ProtocolStatusPanel = SessionStatusBar->Panels->Items[Offset + 0];
  4292. ProtocolStatusPanel->ViewPriority = (ActiveTerminal != NULL) ? 100 : 0;
  4293. if (ProtocolStatusPanel->Caption != ProtocolName)
  4294. {
  4295. ProtocolStatusPanel->Caption = ProtocolName;
  4296. std::unique_ptr<TCanvas> Canvas(CreateControlCanvas(SessionStatusBar));
  4297. ProtocolStatusPanel->Size = Canvas->TextWidth(ProtocolName) + ScaleByTextHeight(SessionStatusBar, 32);
  4298. }
  4299. ProtocolStatusPanel->Hint = ProtocolNameHint;
  4300. TTBXStatusPanel * SecurityStatusPanel = SessionStatusBar->Panels->Items[Offset + 1];
  4301. SecurityStatusPanel->ViewPriority = OpenedTerminal ? 98 : 0;
  4302. bool SecurityEnabled = !SecurityProtocolName.IsEmpty();
  4303. SecurityStatusPanel->Enabled = SecurityEnabled;
  4304. UnicodeString SecurityProtocolHint;
  4305. if (SecurityEnabled)
  4306. {
  4307. SecurityProtocolHint = FMTLOAD(STATUS_SECURE, (SecurityProtocolName));
  4308. }
  4309. else
  4310. {
  4311. SecurityProtocolHint = LoadStr(STATUS_INSECURE);
  4312. }
  4313. SecurityStatusPanel->Hint = SecurityProtocolHint;
  4314. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[Offset + 2];
  4315. DurationStatusPanel->ViewPriority = OpenedTerminal ? 99 : 0;
  4316. DurationStatusPanel->Hint = DurationHint;
  4317. UpdateStatusBar();
  4318. }
  4319. //---------------------------------------------------------------------------
  4320. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4321. {
  4322. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4323. DebugAssert(SessionStatusBar != NULL);
  4324. TTBXStatusPanel * NoteStatusPanel = SessionStatusBar->Panels->Items[0];
  4325. if (!FNote.IsEmpty())
  4326. {
  4327. NoteStatusPanel->Caption = FNote;
  4328. }
  4329. else
  4330. {
  4331. UpdateStatusPanelText(NoteStatusPanel);
  4332. }
  4333. NoteStatusPanel->Hint = FNoteHints;
  4334. UnicodeString LoginTime;
  4335. // See the comment in TScpCommanderForm::UpdateControls()
  4336. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4337. // Active is not enough here
  4338. if ((ActiveTerminal != NULL) && (ActiveTerminal->Status == ssOpened))
  4339. {
  4340. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4341. LoginTime = FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4342. }
  4343. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1];
  4344. DurationStatusPanel->Caption = LoginTime;
  4345. }
  4346. //---------------------------------------------------------------------------
  4347. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4348. {
  4349. Panel->Caption = L"";
  4350. }
  4351. //---------------------------------------------------------------------------
  4352. void __fastcall TCustomScpExplorerForm::Idle()
  4353. {
  4354. if (FShowing || FStandaloneEditing)
  4355. {
  4356. FEditorManager->Check();
  4357. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4358. // that needs to know if queue view is visible (and it may be closed after queue update)
  4359. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4360. }
  4361. if (FShowing)
  4362. {
  4363. if (!NonVisualDataModule->Busy &&
  4364. // Menu is opened or drag&drop is going on
  4365. (Mouse->Capture == NULL))
  4366. {
  4367. if (FRefreshRemoteDirectory)
  4368. {
  4369. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4370. {
  4371. Terminal->RefreshDirectory();
  4372. }
  4373. FRefreshRemoteDirectory = false;
  4374. }
  4375. if (FRefreshLocalDirectory)
  4376. {
  4377. ReloadLocalDirectory();
  4378. FRefreshLocalDirectory = false;
  4379. }
  4380. if (WinConfiguration->RefreshRemotePanel)
  4381. {
  4382. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4383. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4384. {
  4385. RemoteDirView->ReloadDirectory();
  4386. }
  4387. }
  4388. }
  4389. }
  4390. if (FShowing || FStandaloneEditing)
  4391. {
  4392. if (FQueueStatusInvalidated)
  4393. {
  4394. UpdateQueueStatus(false);
  4395. }
  4396. RefreshQueueItems();
  4397. }
  4398. if (FShowing)
  4399. {
  4400. UpdateStatusBar();
  4401. }
  4402. FIgnoreNextDialogChar = 0;
  4403. }
  4404. //---------------------------------------------------------------------------
  4405. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4406. {
  4407. try
  4408. {
  4409. FUserActionTimer->Enabled = false;
  4410. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4411. {
  4412. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4413. {
  4414. FPendingQueueActionItem->ProcessUserAction();
  4415. }
  4416. }
  4417. }
  4418. __finally
  4419. {
  4420. FPendingQueueActionItem = NULL;
  4421. }
  4422. }
  4423. //---------------------------------------------------------------------------
  4424. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4425. {
  4426. if (WinConfiguration->MinimizeToTray)
  4427. {
  4428. UpdateTrayIcon();
  4429. FTrayIcon->Visible = true;
  4430. if (Visible)
  4431. {
  4432. ShowWindow(Handle, SW_HIDE);
  4433. }
  4434. }
  4435. }
  4436. //---------------------------------------------------------------------------
  4437. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4438. {
  4439. // WORKAROUND
  4440. // When restoring maximized window from minimization,
  4441. // rarely some controls do not align properly.
  4442. // Two instances seen (both for Commander):
  4443. // - When restoring, window is temporarily narrower (not maximized),
  4444. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4445. // Once maximized already, top dock shinks back, but the session PageControl,
  4446. // do not align up, leaving space between TopDock and PageControl.
  4447. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4448. for (int Index = 0; Index < ControlCount; Index++)
  4449. {
  4450. RealignControl(Controls[Index]);
  4451. }
  4452. if (FTrayIcon->Visible)
  4453. {
  4454. FTrayIcon->Visible = false;
  4455. if (Visible)
  4456. {
  4457. ShowWindow(Handle, SW_SHOW);
  4458. }
  4459. }
  4460. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4461. {
  4462. FNeedSession = false;
  4463. NonVisualDataModule->StartBusy();
  4464. try
  4465. {
  4466. NeedSession(true);
  4467. }
  4468. __finally
  4469. {
  4470. NonVisualDataModule->EndBusy();
  4471. }
  4472. }
  4473. }
  4474. //---------------------------------------------------------------------------
  4475. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4476. {
  4477. FTrayIcon->Hint = GetMainForm()->Caption;
  4478. }
  4479. //---------------------------------------------------------------------------
  4480. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4481. {
  4482. UpdateTrayIcon();
  4483. }
  4484. //---------------------------------------------------------------------------
  4485. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4486. {
  4487. // workaround
  4488. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4489. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4490. // But WM_ACTIVATEAPP message can be received even when
  4491. // the main window is minimized to the tray and internal editor window is focused
  4492. // (after another application was previously active)
  4493. if (::IsIconic(Handle))
  4494. {
  4495. if (!IsAppIconic())
  4496. {
  4497. SetAppIconic(true);
  4498. }
  4499. }
  4500. ::ApplicationRestore();
  4501. Application->BringToFront();
  4502. }
  4503. //---------------------------------------------------------------------------
  4504. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4505. {
  4506. RestoreApp();
  4507. }
  4508. //---------------------------------------------------------------------------
  4509. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4510. {
  4511. if (OpenInNewWindow())
  4512. {
  4513. // todo: Pass FromSite
  4514. ExecuteNewInstance(SessionUrl);
  4515. }
  4516. else
  4517. {
  4518. TTerminalManager::Instance()->NewSession(SessionUrl);
  4519. }
  4520. }
  4521. //---------------------------------------------------------------------------
  4522. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4523. {
  4524. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4525. StoredSessions->NewSession(SessionName, SessionData);
  4526. // modified only, explicit
  4527. StoredSessions->Save(false, true);
  4528. // encode session name because of slashes in hierarchical sessions
  4529. return EncodeUrlString(SessionName);
  4530. }
  4531. //---------------------------------------------------------------------------
  4532. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4533. {
  4534. // current working directories become defaults here, what is not right
  4535. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4536. return SaveHiddenDuplicateSession(SessionData.get());
  4537. }
  4538. //---------------------------------------------------------------------------
  4539. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4540. {
  4541. if (OpenInNewWindow())
  4542. {
  4543. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4544. }
  4545. else
  4546. {
  4547. // current working directories become defaults here, what is not right
  4548. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4549. TTerminalManager * Manager = TTerminalManager::Instance();
  4550. TManagedTerminal * ATerminal = Manager->NewManagedTerminal(SessionData.get());
  4551. // We definitelly want this
  4552. ATerminal->Disconnected = Terminal->Disconnected;
  4553. // Not sure about these two
  4554. ATerminal->Permanent = Terminal->Permanent;
  4555. ATerminal->DisconnectedTemporarily = Terminal->DisconnectedTemporarily; // maybe
  4556. Manager->ActiveSession = ATerminal;
  4557. }
  4558. }
  4559. //---------------------------------------------------------------------------
  4560. void __fastcall TCustomScpExplorerForm::RenameSession()
  4561. {
  4562. UnicodeString Name = Terminal->SessionData->SessionName;
  4563. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4564. {
  4565. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4566. TSessionData::ValidateName(Name);
  4567. // This is inconsistent with how color (for example) is handled.
  4568. Terminal->SessionData->Name = Name;
  4569. UpdateControls();
  4570. // Add/Remove distinguishing paths from sessions of the same name.
  4571. SessionListChanged();
  4572. }
  4573. }
  4574. //---------------------------------------------------------------------------
  4575. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4576. {
  4577. DebugAssert(Queue != NULL);
  4578. bool Result = Queue->IsEmpty;
  4579. if (!Result)
  4580. {
  4581. SetFocus();
  4582. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4583. }
  4584. return Result;
  4585. }
  4586. //---------------------------------------------------------------------------
  4587. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4588. {
  4589. return CanCloseQueue(FQueue);
  4590. }
  4591. //---------------------------------------------------------------------------
  4592. void __fastcall TCustomScpExplorerForm::CloseSession()
  4593. {
  4594. if (CanCloseQueue())
  4595. {
  4596. TTerminalManager::Instance()->FreeActiveTerminal();
  4597. }
  4598. }
  4599. //---------------------------------------------------------------------------
  4600. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4601. {
  4602. if (CanCloseQueue())
  4603. {
  4604. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4605. }
  4606. }
  4607. //---------------------------------------------------------------------------
  4608. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4609. {
  4610. DetachTerminal(Terminal);
  4611. RemoteDirView->Terminal = Terminal;
  4612. UpdateRemotePathComboBox(false);
  4613. InitStatusBar();
  4614. UpdateControls();
  4615. }
  4616. //---------------------------------------------------------------------------
  4617. void __fastcall TCustomScpExplorerForm::TerminalConnecting()
  4618. {
  4619. InitStatusBar();
  4620. }
  4621. //---------------------------------------------------------------------------
  4622. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4623. {
  4624. if (DebugAlwaysTrue(!Terminal->Active))
  4625. {
  4626. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4627. }
  4628. }
  4629. //---------------------------------------------------------------------------
  4630. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4631. {
  4632. if (OpenInNewWindow())
  4633. {
  4634. // encode session name because of slashes in hierarchical sessions
  4635. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4636. }
  4637. else
  4638. {
  4639. TTerminalManager * Manager = TTerminalManager::Instance();
  4640. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4641. Manager->ActiveSession = Terminal;
  4642. }
  4643. }
  4644. //---------------------------------------------------------------------------
  4645. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4646. {
  4647. TTerminalManager * Manager = TTerminalManager::Instance();
  4648. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4649. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4650. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4651. // FirstTerminal can be null, if some of the
  4652. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4653. {
  4654. FirstTerminal->Disconnected = true;
  4655. FirstTerminal->DisconnectedTemporarily = true;
  4656. }
  4657. Manager->ActiveSession = FirstTerminal;
  4658. }
  4659. //---------------------------------------------------------------------------
  4660. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4661. {
  4662. if (OpenInNewWindow())
  4663. {
  4664. ExecuteNewInstance(Name);
  4665. }
  4666. else
  4667. {
  4668. DoOpenFolderOrWorkspace(Name, true);
  4669. }
  4670. }
  4671. //---------------------------------------------------------------------------
  4672. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4673. bool &CanClose)
  4674. {
  4675. // See the comment in CloseApp()
  4676. if (NonVisualDataModule->Busy)
  4677. {
  4678. CanClose = false;
  4679. }
  4680. else if (Terminal != NULL)
  4681. {
  4682. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4683. {
  4684. unsigned int Result;
  4685. TMessageParams Params(mpNeverAskAgainCheck);
  4686. UnicodeString Message;
  4687. int Answers = qaOK | qaCancel;
  4688. if (TTerminalManager::Instance()->Count > 1)
  4689. {
  4690. if (!WinConfiguration->AutoSaveWorkspace)
  4691. {
  4692. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4693. }
  4694. else
  4695. {
  4696. Message = LoadStr(CLOSE_SESSIONS);
  4697. }
  4698. }
  4699. else
  4700. {
  4701. if (!WinConfiguration->AutoSaveWorkspace)
  4702. {
  4703. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4704. }
  4705. else
  4706. {
  4707. Message = LoadStr(CLOSE_SESSION);
  4708. }
  4709. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4710. }
  4711. UnicodeString Note;
  4712. if (WinConfiguration->AutoSaveWorkspace)
  4713. {
  4714. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4715. }
  4716. else
  4717. {
  4718. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4719. Answers = qaYes | qaNo | qaCancel;
  4720. }
  4721. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4722. SetFocus();
  4723. Result = MessageDialog(Message, qtConfirmation,
  4724. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4725. if (Result == qaNeverAskAgain)
  4726. {
  4727. WinConfiguration->ConfirmClosingSession = false;
  4728. }
  4729. if (Result == qaNo)
  4730. {
  4731. CanClose = SaveWorkspace(true);
  4732. // note that the workspace will be saved redundatly again from FormClose
  4733. }
  4734. else
  4735. {
  4736. CanClose =
  4737. (Result == qaOK) ||
  4738. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4739. (Result == qaNeverAskAgain);
  4740. }
  4741. }
  4742. if (CanClose)
  4743. {
  4744. CanClose = CanCloseQueue();
  4745. }
  4746. }
  4747. if (CanClose)
  4748. {
  4749. CanClose =
  4750. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4751. FEditorManager->CloseExternalFilesWithoutProcess();
  4752. if (CanClose)
  4753. {
  4754. while (CanClose && (FLocalEditors->Count > 0))
  4755. {
  4756. int PrevCount = FLocalEditors->Count;
  4757. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4758. CanClose = (FLocalEditors->Count < PrevCount);
  4759. }
  4760. if (CanClose)
  4761. {
  4762. CanClose = FEditorManager->Empty(true);
  4763. if (!CanClose)
  4764. {
  4765. SetFocus();
  4766. CanClose =
  4767. (MessageDialog(
  4768. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4769. }
  4770. }
  4771. }
  4772. }
  4773. }
  4774. //---------------------------------------------------------------------------
  4775. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4776. {
  4777. TForm * Form = dynamic_cast<TForm *>(Sender);
  4778. DebugAssert(Form != NULL);
  4779. Form->Close();
  4780. }
  4781. //---------------------------------------------------------------------------
  4782. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4783. {
  4784. TForm * Form = dynamic_cast<TForm *>(Sender);
  4785. delete Form;
  4786. }
  4787. //---------------------------------------------------------------------------
  4788. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4789. {
  4790. while (FLocalEditors->Count > 0)
  4791. {
  4792. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4793. }
  4794. }
  4795. //---------------------------------------------------------------------------
  4796. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4797. TObject *Sender)
  4798. {
  4799. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4800. try
  4801. {
  4802. SetProperties(osRemote, FileList);
  4803. }
  4804. __finally
  4805. {
  4806. delete FileList;
  4807. }
  4808. }
  4809. //---------------------------------------------------------------------------
  4810. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4811. {
  4812. if (value)
  4813. {
  4814. if (Component == fcCustomCommandsBand)
  4815. {
  4816. UpdateCustomCommandsToolbar();
  4817. }
  4818. if (Component == fcQueueFileList)
  4819. {
  4820. DebugAssert(!QueueFileListSplitter->Visible);
  4821. AdjustQueueLayout();
  4822. UpdateQueueFileList();
  4823. }
  4824. }
  4825. }
  4826. //---------------------------------------------------------------------------
  4827. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4828. {
  4829. int MinHeightLimit =
  4830. GetStaticQueuePanelComponentsHeight() +
  4831. QueueFileListSplitter->Height +
  4832. QueueFileList->Height +
  4833. GetMinQueueViewHeight();
  4834. if (QueuePanel->ClientHeight < MinHeightLimit)
  4835. {
  4836. QueuePanel->ClientHeight = MinHeightLimit;
  4837. }
  4838. }
  4839. //---------------------------------------------------------------------------
  4840. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4841. {
  4842. TControl * Control = GetComponent(Component);
  4843. DebugAssert(Control);
  4844. bool Changed = (Control->Visible != value);
  4845. if (Changed)
  4846. {
  4847. ComponentShowing(Component, value);
  4848. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4849. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4850. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4851. if (value)
  4852. {
  4853. int RemainingHeight = Control->Parent->ClientHeight;
  4854. int RemainingWidth = Control->Parent->ClientWidth;
  4855. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4856. {
  4857. TControl * ChildControl = Control->Parent->Controls[i];
  4858. if (ChildControl->Visible)
  4859. {
  4860. switch (ChildControl->Align)
  4861. {
  4862. case alTop:
  4863. case alBottom:
  4864. RemainingHeight -= ChildControl->Height;
  4865. break;
  4866. case alLeft:
  4867. case alRight:
  4868. RemainingWidth -= ChildControl->Width;
  4869. break;
  4870. }
  4871. }
  4872. }
  4873. int Reserve = ScaleByTextHeight(this, 32);
  4874. // queue in explorer, trees in commander
  4875. if (Control->Height > RemainingHeight - Reserve)
  4876. {
  4877. Control->Height = RemainingHeight / 2;
  4878. }
  4879. if (Control->Width > RemainingWidth - Reserve)
  4880. {
  4881. Control->Width = RemainingWidth / 2;
  4882. }
  4883. }
  4884. Control->Visible = value;
  4885. if (WasFocused && Visible)
  4886. {
  4887. DirView(osCurrent)->SetFocus();
  4888. }
  4889. FixControlsPlacement();
  4890. }
  4891. }
  4892. //---------------------------------------------------------------------------
  4893. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4894. {
  4895. TControl * Control = GetComponent(Component);
  4896. if (Control == NULL)
  4897. {
  4898. return false;
  4899. }
  4900. else
  4901. {
  4902. return Control->Visible;
  4903. }
  4904. }
  4905. //---------------------------------------------------------------------------
  4906. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4907. {
  4908. bool Result;
  4909. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4910. {
  4911. Result = !IsUWP();
  4912. }
  4913. else
  4914. {
  4915. Result = true;
  4916. }
  4917. return Result;
  4918. }
  4919. //---------------------------------------------------------------------------
  4920. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  4921. {
  4922. if (DirView->ItemFocused != NULL)
  4923. {
  4924. DirView->ItemFocused->MakeVisible(false);
  4925. }
  4926. }
  4927. //---------------------------------------------------------------------------
  4928. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4929. {
  4930. MakeFocusedItemVisible(RemoteDirView);
  4931. QueueSplitter->Visible = QueuePanel->Visible;
  4932. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4933. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4934. TControl * QueueControlsOrder[] =
  4935. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4936. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4937. }
  4938. //---------------------------------------------------------------------------
  4939. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4940. {
  4941. switch (Component) {
  4942. case fcStatusBar: return RemoteStatusBar;
  4943. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4944. case fcQueueView: return QueuePanel;
  4945. case fcQueueToolbar: return QueueDock;
  4946. case fcRemoteTree: return RemoteDrivePanel;
  4947. case fcSessionsTabs: return SessionsPageControl;
  4948. case fcQueueFileList: return QueueFileList;
  4949. default: return NULL;
  4950. }
  4951. }
  4952. //---------------------------------------------------------------------------
  4953. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4954. TObject *Sender, TListColumn *Column, TPoint &Point)
  4955. {
  4956. DebugAssert(NonVisualDataModule && Column && Sender);
  4957. NonVisualDataModule->ListColumn = Column;
  4958. TPopupMenu * DirViewColumnMenu;
  4959. if (Sender == DirView(osOther))
  4960. {
  4961. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4962. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4963. (Column->Index == uvName);
  4964. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4965. (Column->Index == uvSize);
  4966. }
  4967. else
  4968. {
  4969. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4970. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4971. (Column->Index == dvName);
  4972. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4973. (Column->Index == dvSize);
  4974. }
  4975. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4976. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4977. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4978. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4979. }
  4980. //---------------------------------------------------------------------------
  4981. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4982. TObject *Sender, TListItem *Item, bool &AllowExec)
  4983. {
  4984. DoDirViewExecFile(Sender, Item, AllowExec);
  4985. }
  4986. //---------------------------------------------------------------------------
  4987. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4988. TListItem * Item, bool & AllowExec)
  4989. {
  4990. DebugAssert(Sender && Item && Configuration);
  4991. DebugAssert(AllowExec);
  4992. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4993. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  4994. bool Remote = !IsSideLocalBrowser(Side);
  4995. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  4996. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4997. // on files only (not directories)
  4998. // and only when symlinks are resolved (apply to remote panel only)
  4999. if (!ADirView->ItemIsDirectory(Item) &&
  5000. (ResolvedSymlinks || FForceExecution))
  5001. {
  5002. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  5003. !FForceExecution && ResolvedSymlinks)
  5004. {
  5005. if (WinConfiguration->DoubleClickAction == dcaCopy)
  5006. {
  5007. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  5008. UnlockWindow();
  5009. try
  5010. {
  5011. if (IsLocalBrowserMode())
  5012. {
  5013. LocalLocalCopy(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation, false, 0);
  5014. }
  5015. else
  5016. {
  5017. ExecuteFileOperation(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  5018. }
  5019. }
  5020. __finally
  5021. {
  5022. LockWindow();
  5023. }
  5024. AllowExec = false;
  5025. }
  5026. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  5027. {
  5028. if (!Remote || !WinConfiguration->DisableOpenEdit)
  5029. {
  5030. ExecuteFile(Side, efDefaultEditor);
  5031. AllowExec = false;
  5032. }
  5033. }
  5034. else
  5035. {
  5036. DebugFail();
  5037. }
  5038. }
  5039. // if we have not done anything special, fall back to default behavior
  5040. if (AllowExec)
  5041. {
  5042. if (Remote && !WinConfiguration->DisableOpenEdit)
  5043. {
  5044. ExecuteFile(osRemote, efShell);
  5045. AllowExec = false;
  5046. }
  5047. }
  5048. }
  5049. }
  5050. //---------------------------------------------------------------------------
  5051. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  5052. {
  5053. return ((Side == osRemote) || (Side == osCurrent));
  5054. }
  5055. //---------------------------------------------------------------------------
  5056. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5057. {
  5058. DebugFail();
  5059. }
  5060. //---------------------------------------------------------------------------
  5061. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5062. {
  5063. DebugFail();
  5064. }
  5065. //---------------------------------------------------------------------------
  5066. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5067. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5068. {
  5069. TSynchronizeParamType Params;
  5070. Params.LocalDirectory = LocalDirectory;
  5071. Params.RemoteDirectory = RemoteDirectory;
  5072. int UnusedParams =
  5073. (GUIConfiguration->SynchronizeParams &
  5074. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5075. TTerminal::spCaseSensitive));
  5076. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5077. Params.Options = GUIConfiguration->SynchronizeOptions;
  5078. bool SaveSettings = false;
  5079. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5080. &DoSynchronizeTooManyDirectories);
  5081. DebugAssert(FSynchronizeController == NULL);
  5082. FSynchronizeController = &Controller;
  5083. bool Result;
  5084. try
  5085. {
  5086. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5087. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5088. int Options =
  5089. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5090. DebugAssert(FOnFeedSynchronizeError == NULL);
  5091. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5092. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5093. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5094. if (Result)
  5095. {
  5096. if (SaveSettings)
  5097. {
  5098. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5099. GUIConfiguration->SynchronizeOptions = Params.Options;
  5100. }
  5101. else
  5102. {
  5103. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5104. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5105. FLAGSET(Params.Options, soSynchronize))
  5106. {
  5107. GUIConfiguration->SynchronizeOptions =
  5108. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5109. soSynchronize;
  5110. }
  5111. }
  5112. LocalDirectory = Params.LocalDirectory;
  5113. RemoteDirectory = Params.RemoteDirectory;
  5114. }
  5115. }
  5116. __finally
  5117. {
  5118. FSynchronizeController = NULL;
  5119. DebugAssert(FOnFeedSynchronizeError == NULL);
  5120. FOnFeedSynchronizeError = NULL;
  5121. }
  5122. return Result;
  5123. }
  5124. //---------------------------------------------------------------------------
  5125. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5126. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5127. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5128. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5129. TSynchronizeOptions * Options, bool Full)
  5130. {
  5131. // Keep-up-to-date mode
  5132. if (Terminal->Status == ssOpened)
  5133. {
  5134. try
  5135. {
  5136. int PParams = Params.Params;
  5137. if (!Full)
  5138. {
  5139. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5140. if (FLAGSET(Params.Options, soRecurse))
  5141. {
  5142. PParams |= TTerminal::spSubDirs;
  5143. }
  5144. }
  5145. else
  5146. {
  5147. // if keepuptodate is non-recursive,
  5148. // full sync before has to be non-recursive as well
  5149. if (FLAGCLEAR(Params.Options, soRecurse))
  5150. {
  5151. PParams |= TTerminal::spNoRecurse;
  5152. }
  5153. }
  5154. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5155. PParams, Checklist, Options);
  5156. }
  5157. catch (Exception & E)
  5158. {
  5159. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5160. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5161. {
  5162. // noop, already logged in MoreMessageDialog
  5163. }
  5164. else
  5165. {
  5166. ShowExtendedExceptionEx(Terminal, &E);
  5167. throw;
  5168. }
  5169. }
  5170. }
  5171. }
  5172. //---------------------------------------------------------------------------
  5173. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5174. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5175. const UnicodeString ErrorStr)
  5176. {
  5177. if (!Directory.IsEmpty())
  5178. {
  5179. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5180. }
  5181. else
  5182. {
  5183. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5184. }
  5185. }
  5186. //---------------------------------------------------------------------------
  5187. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5188. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5189. {
  5190. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5191. {
  5192. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5193. }
  5194. else
  5195. {
  5196. TMessageParams Params(mpNeverAskAgainCheck);
  5197. unsigned int Result = MessageDialog(
  5198. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5199. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5200. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5201. {
  5202. MaxDirectories *= 2;
  5203. if (Result == qaNeverAskAgain)
  5204. {
  5205. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5206. }
  5207. }
  5208. else
  5209. {
  5210. Abort();
  5211. }
  5212. }
  5213. }
  5214. //---------------------------------------------------------------------------
  5215. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5216. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5217. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5218. TSynchronizeOptions * Options)
  5219. {
  5220. // Keep-up-to-date mode
  5221. DebugAssert(!FAutoOperation);
  5222. void * BatchStorage;
  5223. BatchStart(BatchStorage);
  5224. FAutoOperation = true;
  5225. bool AnyOperation = false;
  5226. TDateTime StartTime = Now();
  5227. TSynchronizeChecklist * AChecklist = NULL;
  5228. try
  5229. {
  5230. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5231. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5232. {
  5233. FSynchronizeProgressForm->Start();
  5234. }
  5235. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5236. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5237. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5238. Options);
  5239. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5240. SAFE_DESTROY(FSynchronizeProgressForm);
  5241. AnyOperation = (AChecklist->CheckedCount > 0);
  5242. if (AnyOperation)
  5243. {
  5244. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5245. CreateProgressForm(&SynchronizeProgress);
  5246. try
  5247. {
  5248. Terminal->SynchronizeApply(
  5249. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5250. SynchronizeProcessedItem, NULL, NULL, NULL);
  5251. }
  5252. __finally
  5253. {
  5254. DestroyProgressForm();
  5255. }
  5256. }
  5257. }
  5258. __finally
  5259. {
  5260. if (Checklist == NULL)
  5261. {
  5262. delete AChecklist;
  5263. }
  5264. else
  5265. {
  5266. *Checklist = AChecklist;
  5267. }
  5268. FAutoOperation = false;
  5269. SAFE_DESTROY(FSynchronizeProgressForm);
  5270. BatchEnd(BatchStorage);
  5271. ReloadLocalDirectory();
  5272. if (AnyOperation)
  5273. {
  5274. OperationComplete(StartTime);
  5275. }
  5276. }
  5277. }
  5278. //---------------------------------------------------------------------------
  5279. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5280. {
  5281. // can be called from command line
  5282. return Visible &&
  5283. ((DirView(osRemote)->SelCount > 0) ||
  5284. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5285. }
  5286. //---------------------------------------------------------------------------
  5287. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5288. {
  5289. LogSynchronizeEvent(Terminal, Message);
  5290. }
  5291. //---------------------------------------------------------------------------
  5292. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5293. int Params, TSynchronizeOptions & Options)
  5294. {
  5295. DebugAssert(!IsLocalBrowserMode());
  5296. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5297. {
  5298. Options.Filter = new TStringList();
  5299. Options.Filter->CaseSensitive = false;
  5300. Options.Filter->Duplicates = Types::dupAccept;
  5301. if (DirView(osRemote)->SelCount > 0)
  5302. {
  5303. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5304. }
  5305. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5306. {
  5307. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5308. }
  5309. Options.Filter->Sort();
  5310. }
  5311. }
  5312. //---------------------------------------------------------------------------
  5313. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5314. {
  5315. TCopyParamType Defaults;
  5316. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5317. ConfigStorage->AccessMode = smRead;
  5318. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5319. {
  5320. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5321. }
  5322. ConfigStorage.reset(NULL);
  5323. std::unique_ptr<TStringList> Options(new TStringList());
  5324. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5325. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5326. UnicodeString Result;
  5327. if (Options->Count > 0)
  5328. {
  5329. Result =
  5330. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5331. }
  5332. return Result;
  5333. }
  5334. //---------------------------------------------------------------------------
  5335. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5336. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5337. {
  5338. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5339. UnicodeString AdditionalParams =
  5340. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5341. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5342. SerializeCopyParamForCommandLine(CopyParams),
  5343. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5344. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5345. ExecuteNewInstance(SessionName, AdditionalParams);
  5346. }
  5347. //---------------------------------------------------------------------------
  5348. struct TSynchronizeParams
  5349. {
  5350. UnicodeString LocalDirectory;
  5351. UnicodeString RemoteDirectory;
  5352. TSynchronizeMode Mode;
  5353. TSynchronizeChecklist * Checklist;
  5354. int Params;
  5355. TCopyParamType * CopyParam;
  5356. TDateTime CollectElapsed;
  5357. TDateTime * StartTime;
  5358. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5359. };
  5360. //---------------------------------------------------------------------------
  5361. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5362. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5363. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5364. {
  5365. DebugAssert(!FAutoOperation);
  5366. void * BatchStorage;
  5367. BatchStart(BatchStorage);
  5368. FAutoOperation = true;
  5369. TFileOperationStatistics Statistics;
  5370. TDateTime Start = Now();
  5371. try
  5372. {
  5373. Params.OnProcessedItem = OnProcessedItem;
  5374. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5375. CreateProgressForm(&SynchronizeProgress);
  5376. Terminal->SynchronizeApply(
  5377. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5378. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5379. &Statistics);
  5380. }
  5381. __finally
  5382. {
  5383. Params.OnProcessedItem = NULL;
  5384. FAutoOperation = false;
  5385. DestroyProgressForm();
  5386. BatchEnd(BatchStorage);
  5387. ReloadLocalDirectory();
  5388. }
  5389. if (WinConfiguration->SynchronizeSummary)
  5390. {
  5391. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5392. // The statistics should be 0 anyway in this case
  5393. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5394. {
  5395. Message += L"\n";
  5396. if (Statistics.FilesUploaded > 0)
  5397. {
  5398. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5399. }
  5400. if (Statistics.FilesDownloaded > 0)
  5401. {
  5402. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5403. }
  5404. if (Statistics.FilesDeletedLocal > 0)
  5405. {
  5406. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5407. }
  5408. if (Statistics.FilesDeletedRemote > 0)
  5409. {
  5410. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5411. }
  5412. }
  5413. TDateTime Elapsed = (Now() - Start);
  5414. Message +=
  5415. L"\n" +
  5416. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5417. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5418. TMessageParams Params(mpNeverAskAgainCheck);
  5419. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5420. if (Result == qaNeverAskAgain)
  5421. {
  5422. WinConfiguration->SynchronizeSummary = false;
  5423. }
  5424. }
  5425. }
  5426. //---------------------------------------------------------------------------
  5427. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5428. {
  5429. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5430. {
  5431. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5432. }
  5433. // Not set in keep-up-to-date mode - Synchronize() method
  5434. if (Token != NULL)
  5435. {
  5436. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5437. if (Params.OnProcessedItem != NULL)
  5438. {
  5439. Params.OnProcessedItem(NULL, ChecklistItem);
  5440. }
  5441. }
  5442. }
  5443. //---------------------------------------------------------------------------
  5444. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5445. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5446. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5447. {
  5448. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5449. *Params.StartTime = Now();
  5450. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5451. }
  5452. //---------------------------------------------------------------------------
  5453. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5454. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5455. {
  5456. // terminal can be already closed (e.g. dropped connection)
  5457. if (Terminal != NULL)
  5458. {
  5459. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5460. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5461. }
  5462. }
  5463. //---------------------------------------------------------------------------
  5464. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5465. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5466. {
  5467. DebugAssert(!IsLocalBrowserMode());
  5468. TAutoBatch AutoBatch(this);
  5469. TAutoFlag AutoOperationFlag(FAutoOperation);
  5470. if (Side == osRemote)
  5471. {
  5472. std::unique_ptr<TStrings> FileList(new TStringList());
  5473. FileList->AddObject(FileName, RemoteFile);
  5474. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5475. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5476. RemoteDirView->SaveSelection();
  5477. RemoteDirView->SaveSelectedNames();
  5478. try
  5479. {
  5480. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5481. }
  5482. catch(...)
  5483. {
  5484. RemoteDirView->DiscardSavedSelection();
  5485. throw;
  5486. }
  5487. RemoteDirView->RestoreSelection();
  5488. }
  5489. else if (DebugAlwaysTrue(Side == osLocal))
  5490. {
  5491. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5492. {
  5493. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5494. }
  5495. UnicodeString Directory = ExtractFileDir(FileName);
  5496. ReloadLocalDirectory(Directory);
  5497. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5498. if (!SamePaths(Directory, NewDirectory))
  5499. {
  5500. ReloadLocalDirectory(NewDirectory);
  5501. }
  5502. }
  5503. }
  5504. //---------------------------------------------------------------------------
  5505. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5506. {
  5507. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5508. if (Side == osLocal)
  5509. {
  5510. if (Action == TSynchronizeChecklist::saDownloadNew)
  5511. {
  5512. OpenFolderInExplorer(LocalPath);
  5513. }
  5514. else
  5515. {
  5516. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5517. }
  5518. }
  5519. else if (DebugAlwaysTrue(Side == osRemote))
  5520. {
  5521. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5522. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5523. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5524. if (!LocalPath.IsEmpty())
  5525. {
  5526. SessionData->LocalDirectory = LocalPath;
  5527. }
  5528. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5529. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5530. }
  5531. }
  5532. //---------------------------------------------------------------------------
  5533. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5534. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5535. const TCopyParamType * CopyParams)
  5536. {
  5537. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5538. UnicodeString AdditionalParams =
  5539. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5540. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5541. SerializeCopyParamForCommandLine(CopyParams),
  5542. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5543. LocalDirectory, RemoteDirectory, Mode, Params));
  5544. ExecuteNewInstance(SessionName, AdditionalParams);
  5545. }
  5546. //---------------------------------------------------------------------------
  5547. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5548. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5549. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5550. {
  5551. int Result;
  5552. bool SaveSettings = false;
  5553. int Options =
  5554. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5555. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5556. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5557. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5558. bool Continue =
  5559. (UseDefaults == 0) ||
  5560. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5561. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5562. if (Continue)
  5563. {
  5564. Configuration->Usage->Inc(L"Synchronizations");
  5565. UpdateCopyParamCounters(CopyParam);
  5566. TSynchronizeOptions SynchronizeOptions;
  5567. GetSynchronizeOptions(Params, SynchronizeOptions);
  5568. if (SaveSettings)
  5569. {
  5570. GUIConfiguration->SynchronizeParams = Params;
  5571. }
  5572. else
  5573. {
  5574. SaveMode = false;
  5575. }
  5576. TDateTime StartTime = Now();
  5577. TSynchronizeChecklist * Checklist = NULL;
  5578. try
  5579. {
  5580. DebugAssert(!FAutoOperation);
  5581. FAutoOperation = true;
  5582. try
  5583. {
  5584. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5585. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5586. int Files = -1;
  5587. if (DataList->Count >= 1)
  5588. {
  5589. Files = StrToIntDef(DataList->Strings[0], Files);
  5590. }
  5591. else
  5592. {
  5593. DataList->Add(UnicodeString());
  5594. }
  5595. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5596. FSynchronizeProgressForm->Start();
  5597. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5598. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5599. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5600. &SynchronizeOptions);
  5601. if (Terminal->SessionData->CacheDirectories)
  5602. {
  5603. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5604. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5605. }
  5606. }
  5607. __finally
  5608. {
  5609. FAutoOperation = false;
  5610. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5611. SAFE_DESTROY(FSynchronizeProgressForm);
  5612. }
  5613. TSynchronizeParams SynchronizeParams;
  5614. SynchronizeParams.LocalDirectory = LocalDirectory;
  5615. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5616. SynchronizeParams.Mode = Mode;
  5617. SynchronizeParams.CopyParam = &CopyParam;
  5618. SynchronizeParams.Params = Params;
  5619. SynchronizeParams.Checklist = Checklist;
  5620. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5621. SynchronizeParams.StartTime = &StartTime;
  5622. SynchronizeParams.OnProcessedItem = NULL;
  5623. Result = Checklist->Count;
  5624. if (Checklist->Count > 0)
  5625. {
  5626. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5627. {
  5628. if (!DoSynchronizeChecklistDialog(
  5629. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5630. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5631. {
  5632. Result = -1;
  5633. }
  5634. }
  5635. else
  5636. {
  5637. FullSynchronize(SynchronizeParams, NULL, NULL);
  5638. }
  5639. }
  5640. else
  5641. {
  5642. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5643. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5644. }
  5645. }
  5646. __finally
  5647. {
  5648. delete Checklist;
  5649. }
  5650. OperationComplete(StartTime);
  5651. }
  5652. else
  5653. {
  5654. Result = -1;
  5655. }
  5656. return Result;
  5657. }
  5658. //---------------------------------------------------------------------------
  5659. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5660. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5661. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5662. {
  5663. if (Collect)
  5664. {
  5665. DebugAssert(FSynchronizeProgressForm != NULL);
  5666. if (!FSynchronizeProgressForm->Started)
  5667. {
  5668. FSynchronizeProgressForm->Start();
  5669. }
  5670. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5671. SetTaskbarListProgressValue(CompareProgress);
  5672. }
  5673. else
  5674. {
  5675. DebugAssert(FSynchronizeProgressForm == NULL);
  5676. DebugAssert(FProgressForm != NULL);
  5677. }
  5678. }
  5679. //---------------------------------------------------------------------------
  5680. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5681. {
  5682. UnicodeString FullFileName = AbsolutePath(Terminal->CurrentDirectory, FileName);
  5683. TRemoteFile * File = NULL;
  5684. Terminal->ReadFile(FullFileName, File);
  5685. if (File != NULL)
  5686. {
  5687. std::unique_ptr<TRemoteFile> FileOwner(File);
  5688. TAutoFlag Flag(FStandaloneEditing);
  5689. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5690. Application->ShowMainForm = false;
  5691. Application->Run();
  5692. }
  5693. }
  5694. //---------------------------------------------------------------------------
  5695. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  5696. {
  5697. DebugFail();
  5698. }
  5699. //---------------------------------------------------------------------------
  5700. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5701. {
  5702. DebugAssert(!IsLocalBrowserMode()); // untested
  5703. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5704. SessionData->Assign(Terminal->SessionData);
  5705. UpdateSessionData(SessionData.get());
  5706. Terminal->UpdateSessionCredentials(SessionData.get());
  5707. if (!Terminal->SessionData->HasSessionName())
  5708. {
  5709. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5710. // once IsWorkspace is cleared
  5711. SessionData->Name = UnicodeString();
  5712. SessionData->IsWorkspace = false;
  5713. }
  5714. return SessionData.release();
  5715. }
  5716. //---------------------------------------------------------------------------
  5717. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5718. {
  5719. TSessionData * SessionData = CloneCurrentSessionData();
  5720. try
  5721. {
  5722. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5723. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5724. }
  5725. __finally
  5726. {
  5727. delete SessionData;
  5728. }
  5729. }
  5730. //---------------------------------------------------------------------------
  5731. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5732. {
  5733. TTerminalManager * Manager = TTerminalManager::Instance();
  5734. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5735. if (DebugAlwaysTrue(ManagedSession != NULL))
  5736. {
  5737. // Update ManagedSession->StateData
  5738. UpdateSession(ManagedSession);
  5739. }
  5740. Manager->SaveWorkspace(DataList.get());
  5741. return DataList.release();
  5742. }
  5743. //---------------------------------------------------------------------------
  5744. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5745. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5746. {
  5747. WinConfiguration->LastWorkspace = Name;
  5748. if (!SavePasswords)
  5749. {
  5750. for (int Index = 0; Index < DataList->Count; Index++)
  5751. {
  5752. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5753. if (SessionData->Link.IsEmpty())
  5754. {
  5755. SessionData->ClearSessionPasswords();
  5756. }
  5757. }
  5758. }
  5759. StoredSessions->NewWorkspace(Name, DataList);
  5760. // modified only
  5761. StoredSessions->Save(false, Explicit);
  5762. }
  5763. //---------------------------------------------------------------------------
  5764. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5765. {
  5766. return
  5767. DefaultStr(WinConfiguration->LastWorkspace,
  5768. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5769. }
  5770. //---------------------------------------------------------------------------
  5771. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5772. {
  5773. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5774. bool AnyNonStoredSessionWithPassword = false;
  5775. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5776. bool AllNonStoredSessionsAnonymous = true;
  5777. TTerminalManager * Manager = TTerminalManager::Instance();
  5778. for (int Index = 0; Index < DataList->Count; Index++)
  5779. {
  5780. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5781. if (SessionData->Link.IsEmpty())
  5782. {
  5783. if (SessionData->HasAnySessionPassword())
  5784. {
  5785. AnyNonStoredSessionWithPassword = true;
  5786. if (!Manager->Sessions[Index]->SessionData->IsWorkspace)
  5787. {
  5788. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5789. }
  5790. }
  5791. if (!SameText(SessionData->UserName, AnonymousUserName))
  5792. {
  5793. AllNonStoredSessionsAnonymous = false;
  5794. }
  5795. }
  5796. }
  5797. bool SavePasswords;
  5798. bool * PSavePasswords;
  5799. bool NotRecommendedSavingPasswords =
  5800. !CustomWinConfiguration->UseMasterPassword &&
  5801. !AllNonStoredSessionsAnonymous;
  5802. if (Configuration->DisablePasswordStoring ||
  5803. !AnyNonStoredSessionWithPassword)
  5804. {
  5805. PSavePasswords = NULL;
  5806. SavePasswords = false;
  5807. }
  5808. else
  5809. {
  5810. PSavePasswords = &SavePasswords;
  5811. SavePasswords =
  5812. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5813. !NotRecommendedSavingPasswords;
  5814. }
  5815. UnicodeString Name = WorkspaceName();
  5816. bool CreateShortcut = false;
  5817. bool Result =
  5818. DoSaveWorkspaceDialog(
  5819. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5820. EnableAutoSave);
  5821. if (Result)
  5822. {
  5823. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5824. if (CreateShortcut)
  5825. {
  5826. TOperationVisualizer Visualizer;
  5827. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5828. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5829. }
  5830. if (EnableAutoSave)
  5831. {
  5832. WinConfiguration->AutoSaveWorkspace = true;
  5833. WinConfiguration->AutoWorkspace = Name;
  5834. if (PSavePasswords != NULL)
  5835. {
  5836. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5837. }
  5838. }
  5839. }
  5840. return Result;
  5841. }
  5842. //---------------------------------------------------------------------------
  5843. void __fastcall TCustomScpExplorerForm::UpdateSession(TManagedTerminal * Session)
  5844. {
  5845. DebugAssert(IsLocalBrowserMode() == Session->LocalBrowser);
  5846. DebugAssert(Session == ManagedSession);
  5847. if (!IsLocalBrowserMode())
  5848. {
  5849. SAFE_DESTROY(Session->RemoteExplorerState);
  5850. if (WinConfiguration->PreservePanelState)
  5851. {
  5852. Session->RemoteExplorerState = RemoteDirView->SaveState();
  5853. }
  5854. }
  5855. UpdateSessionData(Session->StateData);
  5856. }
  5857. //---------------------------------------------------------------------------
  5858. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5859. {
  5860. // Keep in sync with TSessionData::CopyStateData
  5861. DebugAssert(Data != NULL);
  5862. // This is inconsistent with how color (for example) is handled.
  5863. Data->Name = ManagedSession->SessionData->Name;
  5864. if (!IsLocalBrowserMode())
  5865. {
  5866. // cannot use RemoteDirView->Path, because it is empty if connection
  5867. // was already closed
  5868. // also only peek, we may not be connected at all atm
  5869. // so make sure we do not try retrieving current directory from the server
  5870. // (particularly with FTP)
  5871. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5872. if (!ACurrentDirectory.IsEmpty())
  5873. {
  5874. Data->RemoteDirectory = ACurrentDirectory;
  5875. }
  5876. }
  5877. Data->Color = SessionColor;
  5878. }
  5879. //---------------------------------------------------------------------------
  5880. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5881. {
  5882. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5883. DebugAssert(Toolbar != NULL);
  5884. for (int i = 0; i < Toolbar->Items->Count; i++)
  5885. {
  5886. TTBXCustomDropDownItem * DropDownItem;
  5887. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5888. if (DropDownItem != NULL)
  5889. {
  5890. ToolbarItemResize(DropDownItem,
  5891. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5892. Toolbar->NonClientWidth);
  5893. break;
  5894. }
  5895. }
  5896. }
  5897. //---------------------------------------------------------------------------
  5898. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5899. {
  5900. Item->EditWidth = Width;
  5901. }
  5902. //---------------------------------------------------------------------------
  5903. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5904. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5905. {
  5906. for (int i = 0; i < Toolbar->Items->Count; i++)
  5907. {
  5908. TTBXCustomDropDownItem * DropDownItem;
  5909. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5910. if (DropDownItem != NULL)
  5911. {
  5912. ASize.x -= DropDownItem->EditWidth;
  5913. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5914. }
  5915. }
  5916. }
  5917. //---------------------------------------------------------------------------
  5918. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5919. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5920. {
  5921. if (WinConfiguration->DDWarnLackOfTempSpace)
  5922. {
  5923. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5924. if (!ADrive.IsEmpty())
  5925. {
  5926. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5927. DebugAssert(RequiredSpace >= 0);
  5928. __int64 RequiredWithReserve;
  5929. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5930. if (FreeSpace < RequiredWithReserve)
  5931. {
  5932. unsigned int Result;
  5933. TMessageParams Params(mpNeverAskAgainCheck);
  5934. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5935. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5936. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5937. if (Result == qaNeverAskAgain)
  5938. {
  5939. WinConfiguration->DDWarnLackOfTempSpace = false;
  5940. }
  5941. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5942. }
  5943. }
  5944. }
  5945. }
  5946. //---------------------------------------------------------------------------
  5947. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5948. {
  5949. DoOpenDirectoryDialog(odAddBookmark, Side);
  5950. }
  5951. //---------------------------------------------------------------------------
  5952. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5953. {
  5954. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5955. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5956. try
  5957. {
  5958. TCustomDirView * DView = DirView(Side);
  5959. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5960. {
  5961. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5962. }
  5963. }
  5964. catch (...)
  5965. {
  5966. delete VisitedDirectories;
  5967. throw;
  5968. }
  5969. return VisitedDirectories;
  5970. }
  5971. //---------------------------------------------------------------------------
  5972. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5973. TOpenDirectoryMode Mode, TOperationSide Side)
  5974. {
  5975. bool Continue = true;
  5976. if (Mode == odAddBookmark)
  5977. {
  5978. TMessageParams Params(mpNeverAskAgainCheck);
  5979. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5980. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5981. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5982. unsigned int Answer =
  5983. MessageDialog(Message,
  5984. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5985. if (Answer == qaNeverAskAgain)
  5986. {
  5987. Continue = true;
  5988. WinConfiguration->UseSharedBookmarks = true;
  5989. }
  5990. else if (Answer == qaOK)
  5991. {
  5992. Continue = true;
  5993. WinConfiguration->UseSharedBookmarks = false;
  5994. }
  5995. else
  5996. {
  5997. Continue = false;
  5998. }
  5999. }
  6000. if (Continue)
  6001. {
  6002. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  6003. try
  6004. {
  6005. UnicodeString Name = DirView(Side)->PathName;
  6006. bool Repeat;
  6007. do
  6008. {
  6009. Repeat = false;
  6010. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  6011. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  6012. // do not allow switching to location profiles,
  6013. // if we are not connected
  6014. HasDirView[osLocal] && (Terminal != NULL)))
  6015. {
  6016. TWindowLock Lock(this);
  6017. if (!TryOpenDirectory(Side, Name))
  6018. {
  6019. Repeat = true;
  6020. Mode = odBrowse;
  6021. }
  6022. }
  6023. }
  6024. while (Repeat);
  6025. }
  6026. __finally
  6027. {
  6028. delete VisitedDirectories;
  6029. }
  6030. }
  6031. }
  6032. //---------------------------------------------------------------------------
  6033. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  6034. {
  6035. DebugAssert(!Terminal->CommandSessionOpened);
  6036. return TTerminalManager::Instance()->ConnectTerminal(Terminal->CommandSession);
  6037. }
  6038. //---------------------------------------------------------------------------
  6039. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  6040. {
  6041. bool Result = Terminal->IsCapable[Capability] ||
  6042. Terminal->CommandSessionOpened;
  6043. if (!Result)
  6044. {
  6045. DebugAssert(Terminal->IsCapable[fcSecondaryShell]);
  6046. if (!GUIConfiguration->ConfirmCommandSession)
  6047. {
  6048. Result = true;
  6049. }
  6050. else
  6051. {
  6052. TMessageParams Params(mpNeverAskAgainCheck);
  6053. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6054. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6055. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6056. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6057. if (Answer == qaNeverAskAgain)
  6058. {
  6059. GUIConfiguration->ConfirmCommandSession = false;
  6060. Result = true;
  6061. }
  6062. else if (Answer == qaOK)
  6063. {
  6064. Result = true;
  6065. }
  6066. }
  6067. if (Result)
  6068. {
  6069. Result = CommandSessionFallback();
  6070. }
  6071. }
  6072. return Result;
  6073. }
  6074. //---------------------------------------------------------------------------
  6075. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6076. {
  6077. if (EnsureCommandSessionFallback(fcAnyCommand))
  6078. {
  6079. DoConsoleDialog(Terminal, Command);
  6080. }
  6081. }
  6082. //---------------------------------------------------------------------------
  6083. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6084. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6085. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6086. {
  6087. if (!IsSideLocalBrowser(osRemote) &&
  6088. IsFileControl(DropSourceControl, osRemote) &&
  6089. (FDDExtMapFile != NULL))
  6090. {
  6091. Accept = true;
  6092. }
  6093. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6094. DebugAssert(FDDTargetControl != NULL);
  6095. }
  6096. //---------------------------------------------------------------------------
  6097. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6098. _di_IDataObject DataObj, int KeyState,
  6099. const TPoint & Point, int & Effect, bool & Accept)
  6100. {
  6101. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6102. }
  6103. //---------------------------------------------------------------------------
  6104. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6105. _di_IDataObject DataObj, int KeyState,
  6106. const TPoint & Point, int & Effect, bool & Accept)
  6107. {
  6108. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6109. }
  6110. //---------------------------------------------------------------------------
  6111. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6112. TObject * Sender)
  6113. {
  6114. DebugUsedParam(Sender);
  6115. DebugAssert(FDDTargetControl == Sender);
  6116. FDDTargetControl = NULL;
  6117. }
  6118. //---------------------------------------------------------------------------
  6119. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6120. {
  6121. FileControlDDDragLeave(SessionsPageControl);
  6122. }
  6123. //---------------------------------------------------------------------------
  6124. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6125. {
  6126. FileControlDDDragLeave(QueueView3);
  6127. }
  6128. //---------------------------------------------------------------------------
  6129. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6130. {
  6131. DebugAssert(!IsSideLocalBrowser(Side));
  6132. DebugUsedParam(Side);
  6133. bool Edit = false;
  6134. TRemoteFile * File = NULL;
  6135. UnicodeString FileName;
  6136. UnicodeString PointTo;
  6137. bool SymbolicLink = true;
  6138. if (RemoteDirView->ItemFocused)
  6139. {
  6140. DebugAssert(RemoteDirView->ItemFocused->Data);
  6141. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6142. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6143. if (Edit)
  6144. {
  6145. FileName = File->FileName;
  6146. PointTo = File->LinkTo;
  6147. }
  6148. else
  6149. {
  6150. PointTo = File->FileName;
  6151. }
  6152. }
  6153. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6154. Terminal->IsCapable[fcHardLink]))
  6155. {
  6156. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6157. if (Edit)
  6158. {
  6159. DebugAssert(File->FileName == FileName);
  6160. int Params = dfNoRecursive;
  6161. Terminal->ExceptionOnFail = true;
  6162. try
  6163. {
  6164. Terminal->DeleteFile(L"", File, &Params);
  6165. }
  6166. __finally
  6167. {
  6168. Terminal->ExceptionOnFail = false;
  6169. }
  6170. }
  6171. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6172. }
  6173. }
  6174. //---------------------------------------------------------------------------
  6175. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6176. {
  6177. return
  6178. (IsSideLocalBrowser(Side) ||
  6179. (HasActiveTerminal() &&
  6180. Terminal->ResolvingSymlinks &&
  6181. Terminal->IsCapable[fcSymbolicLink]));
  6182. }
  6183. //---------------------------------------------------------------------------
  6184. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6185. {
  6186. return
  6187. !IsSideLocalBrowser(FCurrentSide) &&
  6188. (RemoteDirView->ItemFocused != NULL) &&
  6189. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6190. Terminal->SessionData->ResolveSymlinks;
  6191. }
  6192. //---------------------------------------------------------------------------
  6193. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6194. {
  6195. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6196. FForceExecution = true;
  6197. try
  6198. {
  6199. DirView(osCurrent)->ExecuteCurrentFile();
  6200. }
  6201. __finally
  6202. {
  6203. FForceExecution = false;
  6204. }
  6205. }
  6206. //---------------------------------------------------------------------------
  6207. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6208. {
  6209. TEditorData ExternalEditor;
  6210. ExternalEditor.Editor = edExternal;
  6211. bool Remember = false;
  6212. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6213. {
  6214. if (Remember)
  6215. {
  6216. TEditorList * EditorList = new TEditorList;
  6217. try
  6218. {
  6219. *EditorList = *WinConfiguration->EditorList;
  6220. bool Found = false;
  6221. int i = 0;
  6222. while (!Found && (i < EditorList->Count))
  6223. {
  6224. const TEditorPreferences * Editor = EditorList->Editors[i];
  6225. if ((Editor->Data->Editor == edExternal) &&
  6226. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6227. {
  6228. Found = true;
  6229. }
  6230. i++;
  6231. }
  6232. if (!Found)
  6233. {
  6234. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6235. WinConfiguration->EditorList = EditorList;
  6236. }
  6237. }
  6238. __finally
  6239. {
  6240. delete EditorList;
  6241. }
  6242. }
  6243. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6244. }
  6245. }
  6246. //---------------------------------------------------------------------------
  6247. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6248. {
  6249. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6250. if (FFileFindTerminal == ATerminal)
  6251. {
  6252. FFileFindTerminal = NULL;
  6253. HideFileFindDialog();
  6254. }
  6255. if (FClipboardTerminal == ATerminal)
  6256. {
  6257. ClipboardClear(); // implies ClipboardStop
  6258. }
  6259. }
  6260. //---------------------------------------------------------------------------
  6261. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6262. {
  6263. DetachTerminal(Sender);
  6264. }
  6265. //---------------------------------------------------------------------------
  6266. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6267. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6268. {
  6269. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6270. DebugAssert(Terminal != NULL);
  6271. if (Data->Terminal == Terminal)
  6272. {
  6273. Data->Terminal = NULL;
  6274. }
  6275. }
  6276. //---------------------------------------------------------------------------
  6277. TManagedTerminal * TCustomScpExplorerForm::GetReplacementForLastSession()
  6278. {
  6279. return NULL;
  6280. }
  6281. //---------------------------------------------------------------------------
  6282. void __fastcall TCustomScpExplorerForm::LastTerminalClosed()
  6283. {
  6284. UpdateControls();
  6285. SessionColor = TColor(0);
  6286. UpdateRemotePathComboBox(false);
  6287. NeedSession(false);
  6288. }
  6289. //---------------------------------------------------------------------------
  6290. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6291. {
  6292. try
  6293. {
  6294. // Cache, as the login dialog can change its value.
  6295. // See also DoShow. Also see TTerminalManager::NewSession.
  6296. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6297. try
  6298. {
  6299. if (ShowLogin)
  6300. {
  6301. bool ReloadSessions = !Startup;
  6302. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this, true);
  6303. }
  6304. }
  6305. __finally
  6306. {
  6307. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6308. // (so there was no chance for the user to open any session yet)
  6309. if ((ShowLogin || !Startup) &&
  6310. !WinConfiguration->KeepOpenWhenNoSession &&
  6311. // this rules out the implicit Commander's local-local browser
  6312. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6313. {
  6314. TerminateApplication();
  6315. }
  6316. }
  6317. }
  6318. catch (EAbort &)
  6319. {
  6320. // swallow
  6321. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6322. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6323. }
  6324. }
  6325. //---------------------------------------------------------------------------
  6326. void __fastcall TCustomScpExplorerForm::SessionListChanged()
  6327. {
  6328. TTerminalManager * Manager = TTerminalManager::Instance();
  6329. DebugAssert(!Manager->Updating);
  6330. TStrings * SessionList = Manager->SessionList;
  6331. int ActiveSessionIndex = Manager->ActiveSessionIndex;
  6332. Configuration->Usage->SetMax(L"MaxOpenedSessions", SessionList->Count);
  6333. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6334. try
  6335. {
  6336. while ((SessionsPageControl->PageCount > SessionList->Count + 1) ||
  6337. // Clear the design time unthemed tab
  6338. ((SessionsPageControl->PageCount > 0) &&
  6339. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6340. {
  6341. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6342. }
  6343. for (int Index = 0; Index <= SessionList->Count; Index++)
  6344. {
  6345. TThemeTabSheet * TabSheet;
  6346. if (Index >= SessionsPageControl->PageCount)
  6347. {
  6348. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6349. TabSheet->PageControl = SessionsPageControl;
  6350. }
  6351. else
  6352. {
  6353. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6354. }
  6355. bool IsSessionTab = (Index < SessionList->Count);
  6356. if (IsSessionTab)
  6357. {
  6358. TTerminal * Terminal = dynamic_cast<TTerminal *>(SessionList->Objects[Index]);
  6359. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6360. UpdateSessionTab(TabSheet);
  6361. }
  6362. else
  6363. {
  6364. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6365. TabSheet->Tag = 0; // not really needed
  6366. TabSheet->Shadowed = false;
  6367. TabSheet->ShowCloseButton = false;
  6368. // 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)
  6369. UpdateNewSessionTab();
  6370. }
  6371. }
  6372. }
  6373. __finally
  6374. {
  6375. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6376. }
  6377. SessionsPageControl->ActivePageIndex = ActiveSessionIndex;
  6378. }
  6379. //---------------------------------------------------------------------------
  6380. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6381. {
  6382. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6383. DebugAssert(TabSheet->ImageIndex == 0);
  6384. TabSheet->Caption =
  6385. WinConfiguration->SelectiveToolbarText ?
  6386. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6387. UnicodeString();
  6388. }
  6389. //---------------------------------------------------------------------------
  6390. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabSession(TTabSheet * TabSheet)
  6391. {
  6392. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6393. }
  6394. //---------------------------------------------------------------------------
  6395. UnicodeString TCustomScpExplorerForm::GetLocalBrowserSessionTitle(TManagedTerminal *)
  6396. {
  6397. DebugFail();
  6398. return UnicodeString();
  6399. }
  6400. //---------------------------------------------------------------------------
  6401. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6402. {
  6403. if (DebugAlwaysTrue(TabSheet != NULL))
  6404. {
  6405. TManagedTerminal * ASession = GetSessionTabSession(TabSheet);
  6406. if (DebugAlwaysTrue(ASession != NULL))
  6407. {
  6408. TColor Color = (ASession == Terminal) ? FSessionColor : ASession->StateData->Color;
  6409. if (ASession->LocalBrowser)
  6410. {
  6411. TabSheet->ImageIndex = FLocalBrowserTabImageIndex;
  6412. }
  6413. else
  6414. {
  6415. TabSheet->ImageIndex = AddSessionColor(Color);
  6416. }
  6417. TTerminalManager * Manager = TTerminalManager::Instance();
  6418. UnicodeString TabCaption = Manager->GetSessionTitle(ASession, true);
  6419. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6420. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6421. {
  6422. ThemeTabSheet->Shadowed = !ASession->Active && !ASession->LocalBrowser;
  6423. ThemeTabSheet->ShowCloseButton = CanCloseSession(ASession);
  6424. if (ThemeTabSheet->ShowCloseButton)
  6425. {
  6426. TabCaption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6427. }
  6428. }
  6429. TabSheet->Caption = TabCaption;
  6430. }
  6431. }
  6432. }
  6433. //---------------------------------------------------------------------------
  6434. bool TCustomScpExplorerForm::CanCloseSession(TManagedTerminal * Session)
  6435. {
  6436. return !Session->LocalBrowser || (TTerminalManager::Instance()->Count > 1);
  6437. }
  6438. //---------------------------------------------------------------------------
  6439. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6440. {
  6441. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6442. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->ActivePage);
  6443. bool Result = (Session != NULL);
  6444. if (Result)
  6445. {
  6446. TTerminalManager::Instance()->ActiveSession = Session;
  6447. }
  6448. else
  6449. {
  6450. try
  6451. {
  6452. NewSession();
  6453. }
  6454. __finally
  6455. {
  6456. SessionListChanged();
  6457. }
  6458. FSessionsPageControlNewSessionTime = Now();
  6459. }
  6460. return Result;
  6461. }
  6462. //---------------------------------------------------------------------------
  6463. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6464. {
  6465. SessionTabSwitched();
  6466. }
  6467. //---------------------------------------------------------------------------
  6468. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6469. {
  6470. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6471. DebugAssert(TransferList != NULL);
  6472. UnicodeString Name;
  6473. if (TransferList->ItemIndex <= 0)
  6474. {
  6475. Name = L"";
  6476. }
  6477. else
  6478. {
  6479. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6480. }
  6481. if (FCopyParamAutoSelected.IsEmpty())
  6482. {
  6483. // if previous preset was not autoselected, make new preset the "default"
  6484. FCopyParamDefault = Name;
  6485. }
  6486. GUIConfiguration->CopyParamCurrent = Name;
  6487. }
  6488. //---------------------------------------------------------------------------
  6489. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6490. {
  6491. // sanity check
  6492. bool ExistingPreset =
  6493. (FTransferListHoverIndex >= 0) &&
  6494. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6495. DebugAssert(ExistingPreset);
  6496. if (ExistingPreset)
  6497. {
  6498. HDC DC = GetDC(0);
  6499. TCanvas * Canvas = new TCanvas();
  6500. try
  6501. {
  6502. Canvas->Handle = DC;
  6503. Canvas->Font = GetToolbarFont(this);
  6504. UnicodeString Name;
  6505. if (FTransferListHoverIndex == 0)
  6506. {
  6507. Name = L"";
  6508. }
  6509. else
  6510. {
  6511. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6512. }
  6513. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6514. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6515. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6516. static_cast<TObject*>(GetComponent(fcTransferList)));
  6517. UnicodeString InfoStr =
  6518. GUIConfiguration->CopyParamPreset[Name].
  6519. GetInfoStr(L"; ",
  6520. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6521. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6522. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6523. {
  6524. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6525. {
  6526. InfoStr.SetLength(InfoStr.Length() - 1);
  6527. }
  6528. InfoStr += Ellipsis;
  6529. }
  6530. // UpdateCaption does not cause invalidation of whole submenu, while
  6531. // setting Caption property does.
  6532. // also it probably does not resize the label, even if necessary
  6533. // (we do not want that anyway)
  6534. TransferLabel->UpdateCaption(InfoStr);
  6535. }
  6536. __finally
  6537. {
  6538. Canvas->Handle = NULL;
  6539. ReleaseDC(0, DC);
  6540. delete Canvas;
  6541. }
  6542. }
  6543. }
  6544. //---------------------------------------------------------------------------
  6545. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6546. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6547. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6548. {
  6549. if (FTransferListHoverIndex != AHoverIndex)
  6550. {
  6551. FTransferListHoverIndex = AHoverIndex;
  6552. UpdateTransferLabel();
  6553. }
  6554. }
  6555. //---------------------------------------------------------------------------
  6556. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6557. {
  6558. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6559. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6560. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6561. {
  6562. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6563. {
  6564. if (!NonVisualDataModule->Busy)
  6565. {
  6566. OpenDirectory(GetSide(osCurrent));
  6567. }
  6568. Message.Result = 1;
  6569. }
  6570. else
  6571. {
  6572. TForm::Dispatch(&Message);
  6573. }
  6574. }
  6575. else
  6576. {
  6577. TForm::Dispatch(&Message);
  6578. }
  6579. }
  6580. //---------------------------------------------------------------------------
  6581. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6582. {
  6583. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6584. if ((FIgnoreNextDialogChar != 0) &&
  6585. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6586. {
  6587. Message.Result = 1;
  6588. }
  6589. else
  6590. {
  6591. TForm::Dispatch(&Message);
  6592. }
  6593. FIgnoreNextDialogChar = 0;
  6594. }
  6595. //---------------------------------------------------------------------------
  6596. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6597. {
  6598. // The four low-order bits are used internally by Windows
  6599. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6600. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6601. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6602. // 61730 - restore thru double click - undocumented
  6603. // 61490 - maximize thru double click - undocumented
  6604. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6605. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6606. {
  6607. SysResizing(Cmd);
  6608. }
  6609. TForm::Dispatch(&Message);
  6610. }
  6611. //---------------------------------------------------------------------------
  6612. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6613. {
  6614. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6615. // Also there no point returning TRUE as we are not able to
  6616. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6617. // Hence the process termination might be safer :)
  6618. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6619. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6620. {
  6621. Message.Result = FALSE;
  6622. }
  6623. else
  6624. {
  6625. Message.Result = TRUE;
  6626. }
  6627. // Do not call default handling as that triggers OnCloseQuery,
  6628. // where our implementation will popup confirmation dialogs, what we do not want,
  6629. // as per Vista guidelines:
  6630. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6631. }
  6632. //---------------------------------------------------------------------------
  6633. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6634. {
  6635. if (Message.EndSession && IsApplicationMinimized())
  6636. {
  6637. // WORKAROUND
  6638. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6639. // when it receives WM_ENDSESSION,
  6640. // but that sometimes (particularly when application is minimized) cause crashes.
  6641. // Crash popups message that blocks log off.
  6642. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6643. // so we call ExitProcess() immediately, not even trying to cleanup.
  6644. // It still causes beep, so there's likely some popup, but it does not block
  6645. // log off.
  6646. ExitProcess(0);
  6647. }
  6648. TForm::Dispatch(&Message);
  6649. }
  6650. #ifdef _DEBUG
  6651. //---------------------------------------------------------------------------
  6652. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6653. {
  6654. TForm::Dispatch(&Message);
  6655. }
  6656. #endif
  6657. //---------------------------------------------------------------------------
  6658. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6659. {
  6660. }
  6661. //---------------------------------------------------------------------------
  6662. void __fastcall TCustomScpExplorerForm::DoShow()
  6663. {
  6664. // Called from TCustomScpExplorerForm::CMShowingChanged
  6665. // only now are the controls resized finally, so the size constraints
  6666. // will not conflict with possibly very small window size
  6667. RestoreFormParams();
  6668. // This indicates that the form was rescaled after parameters were loaded and
  6669. // as most probably the parameters were actually saved with the current form scaling
  6670. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6671. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6672. // and no rounding problems will occur.
  6673. // See also RestoreForm.
  6674. // (we should be safe to call RestoreParams unconditionally)
  6675. if (PixelsPerInch != Screen->PixelsPerInch)
  6676. {
  6677. RestoreParams();
  6678. }
  6679. FixControlsPlacement();
  6680. if (Position == poDefaultPosOnly)
  6681. {
  6682. CutFormToDesktop(this);
  6683. }
  6684. TForm::DoShow();
  6685. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6686. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6687. // This was previously in NeedSession, where other related code is.
  6688. // But that is called from CMShowingChanged, when the window is already visible and the local-local window state
  6689. // unpleasanly shows briefly.
  6690. if (!WinConfiguration->ShowLoginWhenNoSession &&
  6691. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6692. // This detects if workspace was saved the last time the main widow was closed
  6693. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6694. {
  6695. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6696. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6697. }
  6698. // Before main window displays
  6699. if (ManagedSession == NULL)
  6700. {
  6701. StartingWithoutSession();
  6702. }
  6703. UpdatePixelsPerInchMainWindowCounter();
  6704. FShowing = true;
  6705. }
  6706. //---------------------------------------------------------------------------
  6707. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6708. {
  6709. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6710. }
  6711. //---------------------------------------------------------------------------
  6712. void __fastcall TCustomScpExplorerForm::StartingWithoutSession()
  6713. {
  6714. SessionListChanged();
  6715. InitStatusBar();
  6716. UpdateControls();
  6717. }
  6718. //---------------------------------------------------------------------------
  6719. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6720. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6721. TNotifyEvent OnBalloonClick, TObject * UserData)
  6722. {
  6723. bool Do;
  6724. UnicodeString Message;
  6725. if (E == NULL)
  6726. {
  6727. Message = Str;
  6728. Do = true;
  6729. }
  6730. else
  6731. {
  6732. Do = ExceptionMessage(E, Message);
  6733. }
  6734. if (Do && WinConfiguration->BalloonNotifications)
  6735. {
  6736. UnicodeString Title;
  6737. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6738. {
  6739. Message = TrimLeft(Message);
  6740. }
  6741. else
  6742. {
  6743. Message = UnformatMessage(Message);
  6744. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6745. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6746. Title = LoadResourceString(Captions[Type]);
  6747. if (Terminal != NULL)
  6748. {
  6749. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  6750. Title = FORMAT(L"%s - %s",
  6751. (TTerminalManager::Instance()->GetSessionTitle(Session, true), Title));
  6752. }
  6753. }
  6754. if (Seconds == 0)
  6755. {
  6756. Seconds = WinConfiguration->NotificationsTimeout;
  6757. }
  6758. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6759. }
  6760. }
  6761. //---------------------------------------------------------------------------
  6762. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6763. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6764. UnicodeString HelpKeyword, const TMessageParams * Params,
  6765. TTerminal * Terminal)
  6766. {
  6767. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6768. (FOnFeedSynchronizeError != NULL)) &&
  6769. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6770. {
  6771. if (FOnFeedSynchronizeError != NULL)
  6772. {
  6773. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6774. }
  6775. else
  6776. {
  6777. DebugAssert(FErrorList != NULL);
  6778. TStringList * MoreMessagesCopy = NULL;
  6779. if (MoreMessages)
  6780. {
  6781. MoreMessagesCopy = new TStringList();
  6782. MoreMessagesCopy->Assign(MoreMessages);
  6783. }
  6784. FErrorList->AddObject(Message, MoreMessagesCopy);
  6785. }
  6786. PopupTrayBalloon(Terminal, Message, Type);
  6787. return ContinueAnswer(Answers);
  6788. }
  6789. else
  6790. {
  6791. bool UseBalloon = FTrayIcon->Visible;
  6792. if (UseBalloon)
  6793. {
  6794. PopupTrayBalloon(Terminal, Message, Type);
  6795. }
  6796. unsigned int Result;
  6797. try
  6798. {
  6799. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6800. }
  6801. __finally
  6802. {
  6803. // cancel only balloon we popped up, otherwise we may cancel notification
  6804. // balloon that was there before the message dialog
  6805. // (such as "dd confirmation opt in balloon)
  6806. if (UseBalloon)
  6807. {
  6808. FTrayIcon->CancelBalloon();
  6809. }
  6810. }
  6811. return Result;
  6812. }
  6813. }
  6814. //---------------------------------------------------------------------------
  6815. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6816. TTerminal * Terminal, Exception * E)
  6817. {
  6818. if (FTrayIcon->Visible)
  6819. {
  6820. PopupTrayBalloon(Terminal, L"", qtError, E);
  6821. }
  6822. // particularly prevent opening new session from jump list,
  6823. // while exception is shown
  6824. NonVisualDataModule->StartBusy();
  6825. try
  6826. {
  6827. ShowExtendedExceptionEx(Terminal, E);
  6828. }
  6829. __finally
  6830. {
  6831. NonVisualDataModule->EndBusy();
  6832. FTrayIcon->CancelBalloon();
  6833. }
  6834. }
  6835. //---------------------------------------------------------------------------
  6836. void __fastcall TCustomScpExplorerForm::SessionReady()
  6837. {
  6838. InitStatusBar();
  6839. // cannot rely on active page being page for active terminal,
  6840. // as it can happen that active page is the "new session" page
  6841. // (e.g. when reconnecting active terminal, while login dialog
  6842. // invoked from "new session" page is modal)
  6843. int ActiveSessionIndex = TTerminalManager::Instance()->ActiveSessionIndex;
  6844. UpdateSessionTab(SessionsPageControl->Pages[ActiveSessionIndex]);
  6845. }
  6846. //---------------------------------------------------------------------------
  6847. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6848. TTerminal * Terminal, Exception * E)
  6849. {
  6850. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6851. if (!Terminal->Active)
  6852. {
  6853. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6854. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6855. {
  6856. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6857. }
  6858. }
  6859. }
  6860. //---------------------------------------------------------------------------
  6861. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6862. UnicodeString Message, TQueryType Type,
  6863. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6864. {
  6865. if ((E == NULL) ||
  6866. ExceptionMessage(E, Message))
  6867. {
  6868. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6869. if (Important)
  6870. {
  6871. Seconds *= 5;
  6872. }
  6873. UnicodeString NoteMessage(UnformatMessage(Message));
  6874. if (Terminal != NULL)
  6875. {
  6876. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  6877. NoteMessage = FORMAT(L"%s: %s",
  6878. (TTerminalManager::Instance()->GetSessionTitle(Session, true), NoteMessage));
  6879. }
  6880. if (WinConfiguration->BalloonNotifications)
  6881. {
  6882. AddNote(NoteMessage);
  6883. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6884. }
  6885. else
  6886. {
  6887. FlashOnBackground();
  6888. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6889. }
  6890. }
  6891. }
  6892. //---------------------------------------------------------------------------
  6893. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6894. {
  6895. RestoreApp();
  6896. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6897. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6898. !NonVisualDataModule->Busy)
  6899. {
  6900. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6901. TTerminalManager::Instance()->ActiveSession = Terminal;
  6902. if (!ComponentVisible[fcQueueView])
  6903. {
  6904. ToggleQueueVisibility();
  6905. GoToQueue();
  6906. }
  6907. }
  6908. }
  6909. //---------------------------------------------------------------------------
  6910. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6911. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6912. {
  6913. UnicodeString Message;
  6914. TNotifyEvent OnClick = NULL;
  6915. TObject * UserData = NULL;
  6916. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6917. switch (Event)
  6918. {
  6919. case qeEmptyButMonitored:
  6920. if ((ATerminal != Terminal) || QueueInvisible)
  6921. {
  6922. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6923. OnClick = QueueEmptyNoteClicked;
  6924. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6925. TerminalNoteData->Terminal = ATerminal;
  6926. UserData = TerminalNoteData;
  6927. }
  6928. break;
  6929. case qeEmpty:
  6930. OperationComplete(ATerminal->QueueOperationStart);
  6931. break;
  6932. case qePendingUserAction:
  6933. if ((ATerminal != Terminal) ||
  6934. (QueueInvisible && !IsQueueAutoPopup()))
  6935. {
  6936. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6937. }
  6938. break;
  6939. default:
  6940. DebugFail();
  6941. }
  6942. if (!Message.IsEmpty())
  6943. {
  6944. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6945. }
  6946. }
  6947. //---------------------------------------------------------------------------
  6948. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6949. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6950. {
  6951. if (FDDExtMapFile != NULL)
  6952. {
  6953. CloseHandle(FDDExtMapFile);
  6954. FDDExtMapFile = NULL;
  6955. }
  6956. if (WinConfiguration->DDFakeFile)
  6957. {
  6958. DDFakeFileInitDrag(FileList, Created);
  6959. }
  6960. }
  6961. //---------------------------------------------------------------------------
  6962. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6963. {
  6964. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6965. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6966. {
  6967. FFakeFileDropTarget = FileName;
  6968. }
  6969. }
  6970. //---------------------------------------------------------------------------
  6971. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6972. {
  6973. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6974. if (!ForceDirectories(ApiPath(Result)))
  6975. {
  6976. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6977. }
  6978. FileSetAttr(ApiPath(Result), faHidden);
  6979. return Result;
  6980. }
  6981. //---------------------------------------------------------------------------
  6982. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6983. bool & Created)
  6984. {
  6985. FFakeFileDropTarget = UnicodeString();
  6986. FDragFakeDirectory = CreateFakeTransferDirectory();
  6987. FileList->AddItem(NULL, FDragFakeDirectory);
  6988. Created = true;
  6989. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6990. {
  6991. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6992. }
  6993. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6994. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6995. {
  6996. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6997. TDragExtCommStruct* CommStruct;
  6998. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6999. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7000. DebugAssert(CommStruct != NULL);
  7001. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  7002. CommStruct->Dragging = true;
  7003. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  7004. LENOF(CommStruct->DropDest));
  7005. NULL_TERMINATE(CommStruct->DropDest);
  7006. UnmapViewOfFile(CommStruct);
  7007. }
  7008. }
  7009. //---------------------------------------------------------------------------
  7010. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  7011. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  7012. {
  7013. bool Result;
  7014. DebugAssert(!IsLocalBrowserMode());
  7015. if (Sender == RemoteDirView)
  7016. {
  7017. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  7018. }
  7019. else
  7020. {
  7021. DebugAssert(Sender == RemoteDriveView);
  7022. TStrings * FileList = RemoteDriveView->DragFileList();
  7023. try
  7024. {
  7025. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  7026. }
  7027. __finally
  7028. {
  7029. delete FileList;
  7030. }
  7031. }
  7032. if (FDDTargetControl == RemoteDriveView)
  7033. {
  7034. RemoteDriveView->UpdateDropTarget();
  7035. }
  7036. // foRemoteMove happens when file/dir is dragged within the remote tree view
  7037. // or from tree view to dir view.
  7038. // foMove happens when file/dir is dragged from remote tree view outside of
  7039. // application via dragex
  7040. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  7041. (DropSourceControl == RemoteDriveView))
  7042. {
  7043. RemoteDriveView->UpdateDropSource();
  7044. }
  7045. return Result;
  7046. }
  7047. //---------------------------------------------------------------------------
  7048. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  7049. {
  7050. DebugAssert(!IsLocalBrowserMode());
  7051. // This also handles drops of remote files to queue.
  7052. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  7053. SAFE_DESTROY(FDDFileList);
  7054. if (!FFakeFileDropTarget.IsEmpty())
  7055. {
  7056. RemoveDir(ApiPath(FFakeFileDropTarget));
  7057. }
  7058. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  7059. {
  7060. try
  7061. {
  7062. TDragResult DDResult = (Sender == RemoteDirView) ?
  7063. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  7064. // Focus is moved to the target application,
  7065. // but as we are going to present the UI, we need to steal the focus back.
  7066. // This most likely won't work though (windows does not allow application
  7067. // to steal focus most of the time)
  7068. Application->BringToFront();
  7069. // On older version of Windows we never got drMove here, see also comment below.
  7070. // On Windows 10, we get the "move".
  7071. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  7072. {
  7073. UnicodeString TargetDirectory;
  7074. TFileOperation Operation;
  7075. // drInvalid may mean drMove, see comment below
  7076. switch (DDResult)
  7077. {
  7078. case drCopy:
  7079. Operation = foCopy;
  7080. break;
  7081. case drMove:
  7082. Operation = foMove;
  7083. break;
  7084. default:
  7085. DebugFail();
  7086. case drInvalid:
  7087. // prefer "copy" for safety
  7088. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7089. break;
  7090. }
  7091. TTransferOperationParam Param;
  7092. UnicodeString CounterName;
  7093. bool ForceQueue;
  7094. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7095. {
  7096. // we get drInvalid both if d&d was intercepted by ddext,
  7097. // and when users drops on no-drop location.
  7098. // we tell the difference by existence of response from ddext,
  7099. // so we ignore absence of response in this case
  7100. if (DDResult != drInvalid)
  7101. {
  7102. // here we know that the extension is installed,
  7103. // as it is checked as soon as drag&drop starts from
  7104. // RemoteFileControlDDCreateDragFileList
  7105. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7106. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7107. {
  7108. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7109. }
  7110. else
  7111. {
  7112. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7113. }
  7114. }
  7115. }
  7116. else
  7117. {
  7118. // download using fake file
  7119. Param.Temp = false;
  7120. Param.DragDrop = true;
  7121. if (ForceQueue)
  7122. {
  7123. Param.Queue = asOn;
  7124. }
  7125. if (Sender == RemoteDirView)
  7126. {
  7127. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7128. }
  7129. if (RemoteFileControlFileOperation(Sender, Operation,
  7130. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7131. {
  7132. Configuration->Usage->Inc(CounterName);
  7133. }
  7134. }
  7135. }
  7136. }
  7137. __finally
  7138. {
  7139. CloseHandle(FDDExtMapFile);
  7140. FDDExtMapFile = NULL;
  7141. delete FDragFakeMonitors;
  7142. FDragFakeMonitors = NULL;
  7143. RemoveDir(ApiPath(FDragFakeDirectory));
  7144. FDragFakeDirectory = L"";
  7145. FFakeFileDropTarget = UnicodeString();
  7146. }
  7147. }
  7148. if (FDragDropSshTerminate.get() != NULL)
  7149. {
  7150. FDragDropSshTerminate->Rethrow();
  7151. }
  7152. }
  7153. //---------------------------------------------------------------------------
  7154. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7155. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7156. {
  7157. // Remember drop effect so we know (when user drops files), if we copy or move
  7158. FLastDropEffect = dwEffect;
  7159. }
  7160. //---------------------------------------------------------------------------
  7161. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7162. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7163. {
  7164. bool Result;
  7165. if (FDDTargetControl == QueueView3)
  7166. {
  7167. Directory = DefaultDownloadTargetDirectory();
  7168. Result = true;
  7169. CounterName = L"DownloadsDragDropQueue";
  7170. ForceQueue = true;
  7171. }
  7172. else if (!FFakeFileDropTarget.IsEmpty())
  7173. {
  7174. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7175. Result = true;
  7176. ForceQueue = false;
  7177. CounterName = L"DownloadsDragDropFakeFile";
  7178. }
  7179. else
  7180. {
  7181. ForceQueue = false;
  7182. Enabled = false;
  7183. try
  7184. {
  7185. int Timer = 0;
  7186. Result = false;
  7187. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7188. {
  7189. {
  7190. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7191. TDragExtCommStruct* CommStruct;
  7192. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7193. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7194. DebugAssert(CommStruct != NULL);
  7195. Result = !CommStruct->Dragging;
  7196. if (Result)
  7197. {
  7198. Directory = ExtractFilePath(CommStruct->DropDest);
  7199. CounterName = L"DownloadsDragDropExternalExt";
  7200. }
  7201. UnmapViewOfFile(CommStruct);
  7202. }
  7203. if (!Result)
  7204. {
  7205. Sleep(50);
  7206. Timer += 50;
  7207. Application->ProcessMessages();
  7208. }
  7209. }
  7210. }
  7211. __finally
  7212. {
  7213. Enabled = true;
  7214. }
  7215. }
  7216. return Result;
  7217. }
  7218. //---------------------------------------------------------------------------
  7219. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7220. const UnicodeString TempDir, int SecDelay)
  7221. {
  7222. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7223. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7224. if (FDelayedDeletionTimer == NULL)
  7225. {
  7226. DebugAssert(HandleAllocated());
  7227. FDelayedDeletionTimer = new TTimer(this);
  7228. FDelayedDeletionTimer->Interval = 10000;
  7229. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7230. }
  7231. else
  7232. {
  7233. FDelayedDeletionTimer->Enabled = true;
  7234. }
  7235. }
  7236. //---------------------------------------------------------------------------
  7237. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7238. {
  7239. DebugAssert(FDelayedDeletionList != NULL);
  7240. TDateTime N = Now();
  7241. TDateTime Alert;
  7242. UnicodeString Directory;
  7243. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7244. {
  7245. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7246. if ((N >= Alert) || (Sender == NULL))
  7247. {
  7248. Directory = FDelayedDeletionList->Strings[Index];
  7249. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7250. {
  7251. FDelayedDeletionList->Delete(Index);
  7252. }
  7253. }
  7254. }
  7255. if (FDelayedDeletionList->Count == 0)
  7256. {
  7257. FDelayedDeletionTimer->Enabled = false;
  7258. }
  7259. }
  7260. //---------------------------------------------------------------------------
  7261. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7262. {
  7263. DebugAssert(!IsLocalBrowserMode());
  7264. if (IsFileControl(FDDTargetControl, osRemote) ||
  7265. (FDDTargetControl == SessionsPageControl))
  7266. {
  7267. TTerminal * TargetTerminal = NULL;
  7268. TFileOperation Operation = foNone;
  7269. if (FDDTargetControl == SessionsPageControl)
  7270. {
  7271. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7272. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7273. // do not allow dropping on the "+" tab
  7274. TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  7275. if (TargetTerminal != NULL)
  7276. {
  7277. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7278. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7279. {
  7280. Operation = foRemoteMove;
  7281. }
  7282. else
  7283. {
  7284. Operation = foRemoteCopy;
  7285. }
  7286. }
  7287. }
  7288. else
  7289. {
  7290. if (FLastDropEffect == DROPEFFECT_MOVE)
  7291. {
  7292. Operation = foRemoteMove;
  7293. }
  7294. else if (FLastDropEffect == DROPEFFECT_COPY)
  7295. {
  7296. Operation = foRemoteCopy;
  7297. }
  7298. }
  7299. if (Operation != foNone)
  7300. {
  7301. RemoteFileControlFileOperation(DropSourceControl,
  7302. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7303. }
  7304. // abort drag&drop
  7305. Abort();
  7306. }
  7307. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7308. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7309. (FDDTargetControl != QueueView3))
  7310. {
  7311. DebugAssert(!FDragTempDir.IsEmpty());
  7312. TTransferType Type;
  7313. UnicodeString TempDir = FDragTempDir;
  7314. // We clear FDragTempDir before calling
  7315. // just in case it fail (raises exception)
  7316. FDragTempDir = L"";
  7317. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7318. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7319. // empty directory parameter means temp directory -> don't display it!
  7320. UnicodeString TargetDir = L"";
  7321. int Options = 0;
  7322. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7323. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7324. {
  7325. Abort();
  7326. }
  7327. // TargetDir is set when dropped on local file control
  7328. // (this was workaround for legacy dirview event handling, now it should be
  7329. // made prettier)
  7330. if (TargetDir.IsEmpty())
  7331. {
  7332. TargetDir = TempDir;
  7333. if (ForceDirectories(ApiPath(TargetDir)))
  7334. {
  7335. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7336. FPendingTempSpaceWarn = true;
  7337. try
  7338. {
  7339. FDragDropOperation = true;
  7340. int Params = cpTemporary |
  7341. (Type == ttMove ? cpDelete : 0);
  7342. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7343. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7344. }
  7345. __finally
  7346. {
  7347. FDragDropOperation = false;
  7348. FPendingTempSpaceWarn = false;
  7349. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7350. }
  7351. }
  7352. else
  7353. {
  7354. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7355. }
  7356. }
  7357. }
  7358. }
  7359. //---------------------------------------------------------------------------
  7360. void __fastcall TCustomScpExplorerForm::DDDownload(
  7361. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7362. {
  7363. DebugAssert(!IsLocalBrowserMode());
  7364. TAutoBatch AutoBatch(this);
  7365. UpdateCopyParamCounters(*CopyParam);
  7366. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7367. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7368. {
  7369. RemoteDriveView->UpdateDropSource();
  7370. }
  7371. }
  7372. //---------------------------------------------------------------------------
  7373. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7374. {
  7375. public:
  7376. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7377. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7378. {
  7379. }
  7380. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7381. {
  7382. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7383. TDataObjectFilesEx::AllowData(FormatEtc);
  7384. }
  7385. };
  7386. //---------------------------------------------------------------------------
  7387. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7388. TObject * Sender, TDataObject *& DataObject)
  7389. {
  7390. if (FDDExtMapFile != NULL)
  7391. {
  7392. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7393. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7394. {
  7395. Abort();
  7396. }
  7397. if (FileList->Count > 0)
  7398. {
  7399. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7400. if (!FilesObject->IsValid(true, true))
  7401. {
  7402. FilesObject->_Release();
  7403. }
  7404. else
  7405. {
  7406. DataObject = FilesObject;
  7407. }
  7408. }
  7409. }
  7410. }
  7411. //---------------------------------------------------------------------------
  7412. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7413. {
  7414. DebugFail();
  7415. }
  7416. //---------------------------------------------------------------------------
  7417. void __fastcall TCustomScpExplorerForm::GoToTree()
  7418. {
  7419. ComponentVisible[fcRemoteTree] = true;
  7420. DriveView(osRemote)->SetFocus();
  7421. }
  7422. //---------------------------------------------------------------------------
  7423. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7424. TPanelExport Export)
  7425. {
  7426. TCustomDirView * DirView = this->DirView(Side);
  7427. std::unique_ptr<TStrings> ExportData(new TStringList());
  7428. switch (Export)
  7429. {
  7430. case pePath:
  7431. ExportData->Add(DirView->PathName);
  7432. break;
  7433. case peFileList:
  7434. case peFullFileList:
  7435. {
  7436. bool FullPath = (Export == peFullFileList);
  7437. DirView->CreateFileList(false, FullPath, ExportData.get());
  7438. for (int Index = 0; Index < ExportData->Count; Index++)
  7439. {
  7440. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7441. {
  7442. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7443. }
  7444. }
  7445. }
  7446. break;
  7447. default:
  7448. DebugFail();
  7449. }
  7450. return ExportData.release();
  7451. }
  7452. //---------------------------------------------------------------------------
  7453. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7454. TPanelExport Export, TPanelExportDestination Destination)
  7455. {
  7456. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7457. PanelExportStore(Side, Export, Destination, ExportData.get());
  7458. }
  7459. //---------------------------------------------------------------------------
  7460. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7461. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7462. TStrings * ExportData)
  7463. {
  7464. if (Destination == pedClipboard)
  7465. {
  7466. TInstantOperationVisualizer Visualizer;
  7467. CopyToClipboard(ExportData);
  7468. }
  7469. else
  7470. {
  7471. DebugFail();
  7472. }
  7473. }
  7474. //---------------------------------------------------------------------------
  7475. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7476. {
  7477. TCustomDirView * DirView = this->DirView(Side);
  7478. UnicodeString Mask = DirView->Mask;
  7479. if (DoFilterMaskDialog(DirView, Mask))
  7480. {
  7481. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7482. Configuration->Usage->Inc(L"Filters");
  7483. }
  7484. }
  7485. //---------------------------------------------------------------------------
  7486. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7487. {
  7488. return FQueueController->DefaultOperation();
  7489. }
  7490. //---------------------------------------------------------------------------
  7491. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7492. TQueueOperation Operation, void ** Param)
  7493. {
  7494. switch (Operation)
  7495. {
  7496. case qoPreferences:
  7497. return true;
  7498. case qoGoTo:
  7499. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7500. case qoOnceEmpty:
  7501. return IsAnythingQueued();
  7502. default:
  7503. return FQueueController->AllowOperation(Operation, Param);
  7504. }
  7505. }
  7506. //---------------------------------------------------------------------------
  7507. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7508. {
  7509. if (DebugAlwaysTrue(QueueView3->Visible))
  7510. {
  7511. QueueView3->SetFocus();
  7512. }
  7513. }
  7514. //---------------------------------------------------------------------------
  7515. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7516. TQueueOperation Operation, void * Param)
  7517. {
  7518. if (Operation == qoGoTo)
  7519. {
  7520. GoToQueue();
  7521. }
  7522. else if (Operation == qoPreferences)
  7523. {
  7524. PreferencesDialog(pmQueue);
  7525. }
  7526. else
  7527. {
  7528. FQueueController->ExecuteOperation(Operation, Param);
  7529. }
  7530. }
  7531. //---------------------------------------------------------------------------
  7532. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7533. {
  7534. return (Queue != NULL) && Queue->Enabled;
  7535. }
  7536. //---------------------------------------------------------------------------
  7537. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7538. {
  7539. DebugAssert(Queue != NULL);
  7540. if (Queue != NULL)
  7541. {
  7542. Queue->Enabled = !Queue->Enabled;
  7543. }
  7544. }
  7545. //---------------------------------------------------------------------------
  7546. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7547. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7548. {
  7549. FQueueActedItem = QueueView3->ItemFocused;
  7550. }
  7551. //---------------------------------------------------------------------------
  7552. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7553. {
  7554. return TopDock->Height + QueueSplitter->Height;
  7555. }
  7556. //---------------------------------------------------------------------------
  7557. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7558. {
  7559. return
  7560. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7561. (QueueDock->Visible ? QueueDock->Height : 0) +
  7562. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7563. }
  7564. //---------------------------------------------------------------------------
  7565. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7566. {
  7567. return ScaleByTextHeight(this, 48);
  7568. }
  7569. //---------------------------------------------------------------------------
  7570. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7571. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7572. {
  7573. // when queue is hidden by double-clicking splitter, stray attempt to
  7574. // resize the panel with strange value arrives, make sure it is ignored
  7575. if (ComponentVisible[fcQueueView])
  7576. {
  7577. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7578. if (NewSize > MaxHeightLimit)
  7579. {
  7580. NewSize = MaxHeightLimit;
  7581. }
  7582. int MinHeightLimit =
  7583. GetStaticQueuePanelComponentsHeight() +
  7584. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7585. GetMinQueueViewHeight();
  7586. if (NewSize < MinHeightLimit)
  7587. {
  7588. NewSize = MinHeightLimit;
  7589. }
  7590. }
  7591. else
  7592. {
  7593. Accept = false;
  7594. }
  7595. }
  7596. //---------------------------------------------------------------------------
  7597. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7598. {
  7599. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7600. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7601. if (QueueViewHeight < GetMinQueueViewHeight())
  7602. {
  7603. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7604. }
  7605. }
  7606. //---------------------------------------------------------------------------
  7607. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7608. TDragObject *& /*DragObject*/)
  7609. {
  7610. FQueueActedItem = QueueView3->ItemFocused;
  7611. }
  7612. //---------------------------------------------------------------------------
  7613. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7614. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7615. {
  7616. Accept = true;
  7617. if (Source == QueueView3)
  7618. {
  7619. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7620. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7621. if (Accept)
  7622. {
  7623. TQueueItemProxy * QueueItem;
  7624. TQueueItemProxy * DestQueueItem;
  7625. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7626. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7627. Accept = (QueueItem != DestQueueItem) &&
  7628. (QueueItem->Status == TQueueItem::qsPending) &&
  7629. (DestQueueItem->Status == TQueueItem::qsPending);
  7630. }
  7631. }
  7632. }
  7633. //---------------------------------------------------------------------------
  7634. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7635. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7636. {
  7637. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7638. {
  7639. TQueueItemProxy * QueueItem;
  7640. TQueueItemProxy * DestQueueItem;
  7641. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7642. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7643. QueueItem->Move(DestQueueItem);
  7644. }
  7645. }
  7646. //---------------------------------------------------------------------------
  7647. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7648. {
  7649. if ((QueueView3->ItemFocused == NULL) &&
  7650. (QueueView3->Items->Count > 0))
  7651. {
  7652. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7653. }
  7654. QueueLabelUpdateStatus();
  7655. }
  7656. //---------------------------------------------------------------------------
  7657. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7658. {
  7659. QueueLabelUpdateStatus();
  7660. }
  7661. //---------------------------------------------------------------------------
  7662. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7663. {
  7664. QueueLabel->UpdateStatus();
  7665. }
  7666. //---------------------------------------------------------------------------
  7667. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7668. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7669. {
  7670. if (Selected)
  7671. {
  7672. NonVisualDataModule->UpdateNonVisibleActions();
  7673. }
  7674. }
  7675. //---------------------------------------------------------------------------
  7676. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7677. {
  7678. TDragDropFilesEx * Result = NULL;
  7679. if (Sender == SessionsPageControl)
  7680. {
  7681. Result = FSessionsDragDropFilesEx;
  7682. }
  7683. else if (Sender == QueueView3)
  7684. {
  7685. Result = FQueueDragDropFilesEx;
  7686. }
  7687. else
  7688. {
  7689. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7690. if (DirView != NULL)
  7691. {
  7692. Result = DirView->DragDropFilesEx;
  7693. }
  7694. else
  7695. {
  7696. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7697. if (DriveView != NULL)
  7698. {
  7699. Result = DriveView->DragDropFilesEx;
  7700. }
  7701. }
  7702. }
  7703. DebugAssert(Result != NULL);
  7704. return Result;
  7705. }
  7706. //---------------------------------------------------------------------------
  7707. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7708. {
  7709. return (DView->SelCount == DView->FilesCount);
  7710. }
  7711. //---------------------------------------------------------------------------
  7712. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7713. {
  7714. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7715. }
  7716. //---------------------------------------------------------------------------
  7717. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7718. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7719. {
  7720. DebugAssert(!IsLocalBrowserMode());
  7721. TFileOperation Operation;
  7722. switch (Effect)
  7723. {
  7724. case DROPEFFECT_MOVE:
  7725. Operation = foMove;
  7726. break;
  7727. case DROPEFFECT_COPY:
  7728. // occures on WinXP (reported by user)
  7729. default:
  7730. Operation = foCopy;
  7731. break;
  7732. };
  7733. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7734. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7735. if (DragDropFilesEx->FileList->Count > 0)
  7736. {
  7737. TStrings * FileList = new TStringList();
  7738. try
  7739. {
  7740. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7741. {
  7742. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7743. }
  7744. FDragDropOperation = true;
  7745. TTransferOperationParam Param;
  7746. Param.TargetDirectory = TargetPath;
  7747. // upload, no temp dirs
  7748. Param.Temp = false;
  7749. Param.DragDrop = DragDrop;
  7750. Param.Options =
  7751. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7752. if (ForceQueue)
  7753. {
  7754. Param.Queue = asOn;
  7755. }
  7756. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7757. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7758. {
  7759. if (IsFileControl(DropSourceControl, osLocal))
  7760. {
  7761. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7762. }
  7763. else
  7764. {
  7765. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7766. }
  7767. }
  7768. }
  7769. __finally
  7770. {
  7771. FDragDropOperation = false;
  7772. delete FileList;
  7773. }
  7774. }
  7775. }
  7776. //---------------------------------------------------------------------------
  7777. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7778. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7779. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7780. {
  7781. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7782. }
  7783. //---------------------------------------------------------------------------
  7784. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7785. TObject * Sender, int grfKeyState, int & dwEffect)
  7786. {
  7787. DebugAssert(!IsLocalBrowserMode());
  7788. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7789. if ((dwEffect != DROPEFFECT_NONE) &&
  7790. IsFileControl(DropSourceControl, osRemote))
  7791. {
  7792. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7793. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7794. (RemoteDirView->DropTarget == NULL))
  7795. {
  7796. dwEffect = DROPEFFECT_NONE;
  7797. }
  7798. else
  7799. {
  7800. if (dwEffect == DROPEFFECT_COPY)
  7801. {
  7802. bool MoveCapable = Terminal->IsCapable[fcRemoteMove];
  7803. // currently we support copying always (at least via temporary directory);
  7804. // remove associated checks once this all proves stable and working
  7805. bool CopyCapable = true;
  7806. // if we do not support neither of operations, there's no discussion
  7807. if (!MoveCapable && !CopyCapable)
  7808. {
  7809. dwEffect = DROPEFFECT_NONE;
  7810. }
  7811. else
  7812. {
  7813. // The default effect inside remote panel is move,
  7814. // unless we do not support it, but support copy
  7815. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7816. {
  7817. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7818. }
  7819. else
  7820. {
  7821. // with ctrl-down, we want copy unless it is not supported
  7822. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7823. }
  7824. }
  7825. }
  7826. }
  7827. }
  7828. }
  7829. //---------------------------------------------------------------------------
  7830. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7831. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7832. {
  7833. DebugAssert(!IsLocalBrowserMode());
  7834. if (FDDTotalSize >= 0)
  7835. {
  7836. if (File->IsDirectory)
  7837. {
  7838. FDDTotalSize = -1;
  7839. }
  7840. else
  7841. {
  7842. FDDTotalSize += File->Size;
  7843. }
  7844. }
  7845. DebugAssert(!FDragTempDir.IsEmpty());
  7846. // TODO: this is quite ineffective
  7847. // TODO: what if invalid character replacement is disabled?
  7848. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7849. UnicodeString TransferFileName;
  7850. if (Sender == RemoteDriveView)
  7851. {
  7852. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7853. }
  7854. else
  7855. {
  7856. TransferFileName = File->FileName;
  7857. }
  7858. FDDFileList->AddObject(TransferFileName, File);
  7859. }
  7860. //---------------------------------------------------------------------------
  7861. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7862. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7863. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7864. {
  7865. // sometimes we do not get DDEnd so the list is not released
  7866. SAFE_DESTROY(FDDFileList);
  7867. FDDFileList = new TStringList();
  7868. FDragTempDir = WinConfiguration->TemporaryDir();
  7869. FDDTotalSize = 0;
  7870. FDragDropSshTerminate.reset(NULL);
  7871. }
  7872. //---------------------------------------------------------------------------
  7873. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7874. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7875. HRESULT & Result)
  7876. {
  7877. if (Result == DRAGDROP_S_DROP)
  7878. {
  7879. try
  7880. {
  7881. GlobalDragImageList->HideDragImage();
  7882. try
  7883. {
  7884. RemoteFileControlDDTargetDrop();
  7885. }
  7886. catch(ESshTerminate & E)
  7887. {
  7888. FDragDropSshTerminate.reset(E.Clone());
  7889. }
  7890. }
  7891. catch (Exception &E)
  7892. {
  7893. // If downloading fails we need to cancel drag&drop, otherwise
  7894. // Explorer shows error
  7895. // But by the way exception probably never reach this point as
  7896. // it's catched on way.
  7897. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7898. Result = DRAGDROP_S_CANCEL;
  7899. ShowExtendedException(Terminal, &E);
  7900. }
  7901. }
  7902. }
  7903. //---------------------------------------------------------------------------
  7904. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7905. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7906. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7907. {
  7908. TFileMasks::TParams MaskParams;
  7909. MaskParams.Size = Size;
  7910. MaskParams.Modification = Modification;
  7911. // this does not re-parse the mask if it is the same as the last time
  7912. FDirViewMatchMask = Masks;
  7913. bool ImplicitMatch;
  7914. Matches =
  7915. // RecurseInclude parameter has no effect as the Path is empty
  7916. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7917. (AllowImplicitMatches || !ImplicitMatch);
  7918. }
  7919. //---------------------------------------------------------------------------
  7920. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7921. TObject * Sender, TListItem * Item, WORD & Indexes)
  7922. {
  7923. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7924. UnicodeString Ext;
  7925. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7926. {
  7927. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7928. }
  7929. else
  7930. {
  7931. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7932. }
  7933. if (SameText(Ext, Configuration->PartialExt))
  7934. {
  7935. Indexes |= oiPartial;
  7936. }
  7937. }
  7938. //---------------------------------------------------------------------------
  7939. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7940. {
  7941. return
  7942. DirViewEnabled(osCurrent) &&
  7943. DirView(osCurrent)->CanPasteFromClipBoard();
  7944. }
  7945. //---------------------------------------------------------------------------
  7946. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7947. {
  7948. bool Result = false;
  7949. if (CanPasteToDirViewFromClipBoard())
  7950. {
  7951. Result = true;
  7952. }
  7953. else
  7954. {
  7955. UnicodeString ClipboardText;
  7956. if (NonEmptyTextFromClipboard(ClipboardText) &&
  7957. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  7958. {
  7959. if (StoredSessions->IsUrl(ClipboardText))
  7960. {
  7961. Result = true;
  7962. }
  7963. else
  7964. {
  7965. Result = DirViewEnabled(osCurrent);
  7966. }
  7967. }
  7968. }
  7969. return Result;
  7970. }
  7971. //---------------------------------------------------------------------------
  7972. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7973. {
  7974. if (DoesClipboardContainOurFiles())
  7975. {
  7976. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7977. {
  7978. DebugAssert(!IsLocalBrowserMode());
  7979. TTerminalManager * Manager = TTerminalManager::Instance();
  7980. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7981. Manager->ActiveSession = FClipboardTerminal;
  7982. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7983. }
  7984. }
  7985. else if (CanPasteToDirViewFromClipBoard())
  7986. {
  7987. DirView(osCurrent)->PasteFromClipBoard();
  7988. }
  7989. else
  7990. {
  7991. UnicodeString ClipboardText;
  7992. if (NonEmptyTextFromClipboard(ClipboardText))
  7993. {
  7994. if (StoredSessions->IsUrl(ClipboardText))
  7995. {
  7996. NewSession(ClipboardText);
  7997. }
  7998. else
  7999. {
  8000. DirView(osCurrent)->Path = ClipboardText;
  8001. }
  8002. }
  8003. }
  8004. }
  8005. //---------------------------------------------------------------------------
  8006. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  8007. {
  8008. // TBD
  8009. }
  8010. //---------------------------------------------------------------------------
  8011. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  8012. {
  8013. TCustomDirView * ADirView = DirView(Side);
  8014. ADirView->SelectAll(Mode);
  8015. ADirView->SetFocus();
  8016. }
  8017. //---------------------------------------------------------------------------
  8018. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  8019. {
  8020. TCustomDirView * ADirView = DirView(Side);
  8021. TFileFilter Filter;
  8022. DefaultFileFilter(Filter);
  8023. if (DoSelectMaskDialog(ADirView, Select, Filter))
  8024. {
  8025. Configuration->Usage->Inc(L"MaskSelections");
  8026. ADirView->SelectFiles(Filter, Select);
  8027. ADirView->SetFocus();
  8028. }
  8029. }
  8030. //---------------------------------------------------------------------------
  8031. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  8032. {
  8033. TCustomDirView * ADirView = DirView(Side);
  8034. ADirView->RestoreSelectedNames();
  8035. ADirView->SetFocus();
  8036. }
  8037. //---------------------------------------------------------------------------
  8038. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  8039. {
  8040. TCustomDirView * CurrentDirView = DirView(osCurrent);
  8041. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  8042. {
  8043. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  8044. UnicodeString Ext;
  8045. if (!IsSideLocalBrowser(osCurrent))
  8046. {
  8047. Ext = UnixExtractFileExt(FileName);
  8048. }
  8049. else
  8050. {
  8051. Ext = ExtractFileExt(FileName);
  8052. }
  8053. if (Ext.IsEmpty())
  8054. {
  8055. Ext = L".";
  8056. }
  8057. TFileFilter Filter;
  8058. Filter.Masks = FORMAT(L"*%s", (Ext));
  8059. Filter.Directories = false;
  8060. CurrentDirView->SelectFiles(Filter, Select);
  8061. }
  8062. }
  8063. //---------------------------------------------------------------------------
  8064. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  8065. const TStatusFileInfo & FileInfo, TOperationSide Side)
  8066. {
  8067. UnicodeString Result;
  8068. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  8069. {
  8070. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  8071. }
  8072. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  8073. {
  8074. // noop
  8075. }
  8076. else
  8077. {
  8078. Result =
  8079. FMTLOAD(FILE_INFO_FORMAT,
  8080. (FormatBytes(FileInfo.SelectedSize),
  8081. FormatBytes(FileInfo.FilesSize),
  8082. FormatNumber(FileInfo.SelectedCount),
  8083. FormatNumber(FileInfo.FilesCount)));
  8084. }
  8085. return Result;
  8086. }
  8087. //---------------------------------------------------------------------------
  8088. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8089. TTBXStatusPanel * Panel, TOperationSide Side)
  8090. {
  8091. if (Panel->Index == 1)
  8092. {
  8093. ToggleShowHiddenFiles();
  8094. }
  8095. else if (Panel->Index == 2)
  8096. {
  8097. Filter(Side);
  8098. }
  8099. }
  8100. //---------------------------------------------------------------------------
  8101. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8102. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8103. {
  8104. DebugAssert(!StatusBar->SimplePanel);
  8105. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8106. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8107. }
  8108. //---------------------------------------------------------------------------
  8109. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8110. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8111. {
  8112. DebugAssert(StatusBar->Panels->Count >= 3);
  8113. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8114. if (FileInfo.HiddenCount > 0)
  8115. {
  8116. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8117. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8118. }
  8119. else
  8120. {
  8121. HiddenFilesPanel->ViewPriority = 0;
  8122. // not really necessary, just to cleanup no-longer-valid data
  8123. HiddenFilesPanel->Caption = L"";
  8124. }
  8125. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8126. if (FileInfo.FilteredCount > 0)
  8127. {
  8128. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8129. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8130. }
  8131. else
  8132. {
  8133. FilteredFilesPanel->ViewPriority = 0;
  8134. // not really necessary, just to cleanup no-longer-valid data
  8135. FilteredFilesPanel->Caption = L"";
  8136. }
  8137. }
  8138. //---------------------------------------------------------------------------
  8139. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8140. TObject * /*Sender*/)
  8141. {
  8142. if (DirView(osOther)->Enabled)
  8143. {
  8144. DirView(osOther)->SetFocus();
  8145. }
  8146. }
  8147. //---------------------------------------------------------------------------
  8148. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8149. {
  8150. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8151. switch (Config.Show)
  8152. {
  8153. case qvShow:
  8154. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8155. {
  8156. Config.Show = qvHide;
  8157. }
  8158. else
  8159. {
  8160. Config.Show = Config.LastHideShow;
  8161. }
  8162. break;
  8163. case qvHideWhenEmpty:
  8164. if (ComponentVisible[fcQueueView])
  8165. {
  8166. Config.Show = qvHide;
  8167. }
  8168. else
  8169. {
  8170. Config.LastHideShow = Config.Show;
  8171. Config.Show = qvShow;
  8172. }
  8173. break;
  8174. case qvHide:
  8175. Config.LastHideShow = Config.Show;
  8176. Config.Show = qvShow;
  8177. break;
  8178. }
  8179. WinConfiguration->QueueView = Config;
  8180. }
  8181. //---------------------------------------------------------------------------
  8182. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8183. {
  8184. UnicodeString Result;
  8185. if (Terminal != NULL)
  8186. {
  8187. switch (WinConfiguration->PathInCaption)
  8188. {
  8189. case picShort:
  8190. Result = ExtractShortName(Terminal->CurrentDirectory, true);
  8191. break;
  8192. case picFull:
  8193. Result = Terminal->CurrentDirectory;
  8194. break;
  8195. }
  8196. }
  8197. return Result;
  8198. }
  8199. //---------------------------------------------------------------------------
  8200. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8201. {
  8202. TColor Result = GetWindowColor(FSessionColor);
  8203. return Result;
  8204. }
  8205. //---------------------------------------------------------------------------
  8206. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8207. {
  8208. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8209. return Result;
  8210. }
  8211. //---------------------------------------------------------------------------
  8212. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8213. {
  8214. if (!FSessionChanging)
  8215. {
  8216. TTerminalManager::Instance()->UpdateAppTitle();
  8217. }
  8218. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8219. // background to gray on Windows 7 (works on Windows 10).
  8220. // See also EnableControl
  8221. if (Showing)
  8222. {
  8223. if (ManagedSession != NULL)
  8224. {
  8225. // Update path when it changes
  8226. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabSession(SessionsPageControl->ActivePage) == ManagedSession))
  8227. {
  8228. UpdateSessionTab(SessionsPageControl->ActivePage);
  8229. }
  8230. }
  8231. NonVisualDataModule->ReconnectSessionAction->Update();
  8232. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8233. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8234. CenterReconnectToolbar();
  8235. bool HasTerminal = HasActiveTerminal();
  8236. RemoteDirView->Enabled = HasTerminal;
  8237. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8238. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8239. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8240. RemoteDriveView->Color = RemoteDirView->Color;
  8241. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8242. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8243. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8244. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8245. QueueFileList->Enabled = QueueView3->Enabled;
  8246. QueueFileList->Color = QueueView3->Color;
  8247. QueueFileList->Font->Color = QueueView3->Font->Color;
  8248. QueueLabelUpdateStatus();
  8249. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8250. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8251. if (FImmersiveDarkMode != WinConfiguration->UseDarkTheme())
  8252. {
  8253. UpdateDarkMode();
  8254. }
  8255. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8256. }
  8257. }
  8258. //---------------------------------------------------------------------------
  8259. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8260. {
  8261. UpdateControls();
  8262. }
  8263. //---------------------------------------------------------------------------
  8264. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8265. TObject * Sender)
  8266. {
  8267. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8268. DebugAssert(DirView != NULL);
  8269. DoDirViewLoaded(DirView);
  8270. TransferPresetAutoSelect();
  8271. }
  8272. //---------------------------------------------------------------------------
  8273. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8274. {
  8275. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8276. // first run after installation
  8277. if (double(Updates.LastCheck) == 0)
  8278. {
  8279. // make sure next time there will be an update (if enabled)
  8280. Updates.LastCheck = TDateTime(1);
  8281. WinConfiguration->Updates = Updates;
  8282. }
  8283. else if ((double(Updates.Period) > 0) &&
  8284. (Now() - Updates.LastCheck >= Updates.Period))
  8285. {
  8286. TThreadMethod OnUpdatesChecked = NULL;
  8287. if (!IsUWP())
  8288. {
  8289. OnUpdatesChecked = UpdatesChecked;
  8290. }
  8291. StartUpdateThread(OnUpdatesChecked);
  8292. }
  8293. }
  8294. //---------------------------------------------------------------------------
  8295. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8296. {
  8297. UnicodeString Message;
  8298. bool New;
  8299. TQueryType Type;
  8300. GetUpdatesMessage(Message, New, Type, false);
  8301. if (!Message.IsEmpty())
  8302. {
  8303. if (New)
  8304. {
  8305. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8306. }
  8307. if (!New && (Type != qtWarning))
  8308. {
  8309. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8310. }
  8311. else
  8312. {
  8313. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8314. }
  8315. if (New)
  8316. {
  8317. Configuration->Usage->Inc(L"UpdateNotifications");
  8318. }
  8319. }
  8320. }
  8321. //---------------------------------------------------------------------------
  8322. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8323. {
  8324. RestoreApp();
  8325. bool CanDisplay = !NonVisualDataModule->Busy;
  8326. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8327. {
  8328. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8329. }
  8330. if (CanDisplay)
  8331. {
  8332. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8333. CheckForUpdates(true);
  8334. }
  8335. else
  8336. {
  8337. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8338. }
  8339. }
  8340. //---------------------------------------------------------------------------
  8341. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8342. TCopyParamRuleData & Data)
  8343. {
  8344. DebugAssert(Terminal != NULL);
  8345. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8346. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8347. Data.RemoteDirectory = RemoteDirView->PathName;
  8348. }
  8349. //---------------------------------------------------------------------------
  8350. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8351. {
  8352. // Terminal can be null when we are changing local directory implicitly,
  8353. // because it has been deleted, while no session is connected
  8354. // (Login dialog is open)
  8355. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8356. {
  8357. DebugAssert(!IsLocalBrowserMode());
  8358. TCopyParamRuleData Data;
  8359. GetTransferPresetAutoSelectData(Data);
  8360. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8361. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8362. if (CopyParamIndex < 0)
  8363. {
  8364. // there is no preset that matches autoselection
  8365. // set preset that we consider "default"
  8366. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8367. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8368. }
  8369. else
  8370. {
  8371. // there is preset matching autoselection
  8372. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8373. if (CopyParamName == FCopyParamAutoSelected)
  8374. {
  8375. // autoselected the same preset as the last time
  8376. // make no change (i.e. preserve custom user preset, if any)
  8377. }
  8378. else
  8379. {
  8380. // autoselected the different preset then the last time (or there
  8381. // was default preset set)
  8382. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8383. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8384. }
  8385. }
  8386. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8387. {
  8388. if (CopyParamIndex >= 0)
  8389. {
  8390. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8391. }
  8392. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8393. try
  8394. {
  8395. int Fmt =
  8396. (CopyParamIndex < 0) ?
  8397. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8398. COPY_PARAM_AUTOSELECTED;
  8399. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8400. Data->Message = MainInstructions(Message);
  8401. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8402. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8403. CopyParamAttrs);
  8404. if (CopyParamIndex >= 0)
  8405. {
  8406. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8407. Info = FORMAT(L"%s\n \n%s", (Info,
  8408. FMTLOAD(COPY_PARAM_RULE,
  8409. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8410. }
  8411. Data->Message += L"\n\n" + Info;
  8412. if (WinConfiguration->CopyParamAutoSelectNotice)
  8413. {
  8414. TransferPresetNoteMessage(Data, true);
  8415. }
  8416. else
  8417. {
  8418. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8419. Data = NULL; // ownership passed
  8420. }
  8421. }
  8422. __finally
  8423. {
  8424. delete Data;
  8425. }
  8426. }
  8427. }
  8428. }
  8429. //---------------------------------------------------------------------------
  8430. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8431. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8432. {
  8433. DebugAssert(NoteData != NULL);
  8434. DebugAssert(!IsLocalBrowserMode());
  8435. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8436. TQueryButtonAlias Aliases[1];
  8437. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8438. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8439. Params.Aliases = Aliases;
  8440. Params.AliasesCount = LENOF(Aliases);
  8441. unsigned int Result =
  8442. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8443. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8444. switch (Result)
  8445. {
  8446. case qaNeverAskAgain:
  8447. DebugAssert(AllowNeverAskAgain);
  8448. WinConfiguration->CopyParamAutoSelectNotice = false;
  8449. break;
  8450. case qaIgnore:
  8451. PreferencesDialog(pmPresets);
  8452. break;
  8453. }
  8454. }
  8455. //---------------------------------------------------------------------------
  8456. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8457. {
  8458. // as of now useless, as this is used for notes only, never for balloons, ...
  8459. RestoreApp();
  8460. // .. and we should never be busy here
  8461. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8462. {
  8463. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8464. }
  8465. }
  8466. //---------------------------------------------------------------------------
  8467. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8468. TPreferencesMode APreferencesMode)
  8469. {
  8470. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8471. TCopyParamRuleData Data;
  8472. if (Terminal != NULL)
  8473. {
  8474. PreferencesData.reset(new TPreferencesDialogData());
  8475. GetTransferPresetAutoSelectData(Data);
  8476. PreferencesData->CopyParamRuleData = &Data;
  8477. }
  8478. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8479. }
  8480. //---------------------------------------------------------------------------
  8481. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8482. const TCustomCommandType & Command)
  8483. {
  8484. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8485. {
  8486. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8487. }
  8488. }
  8489. //---------------------------------------------------------------------------
  8490. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8491. {
  8492. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8493. TCustomCommandType Command;
  8494. // make sure we use local custom command when remote are not supported
  8495. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8496. {
  8497. Command = FLastCustomCommand;
  8498. }
  8499. else
  8500. {
  8501. Command.Params = Command.Params | ccLocal;
  8502. }
  8503. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8504. FEditingFocusedAdHocCommand = OnFocused;
  8505. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8506. int Options =
  8507. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8508. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8509. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8510. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8511. {
  8512. FLastCustomCommand = Command;
  8513. UpdateCustomCommandsToolbar();
  8514. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8515. }
  8516. }
  8517. //---------------------------------------------------------------------------
  8518. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8519. {
  8520. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8521. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8522. DebugAssert(State > 0);
  8523. if (State <= 0)
  8524. {
  8525. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8526. }
  8527. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8528. }
  8529. //---------------------------------------------------------------------------
  8530. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8531. TCustomCommandType & Command, int & State)
  8532. {
  8533. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8534. if (Result)
  8535. {
  8536. Command = FLastCustomCommand;
  8537. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8538. }
  8539. return Result;
  8540. }
  8541. //---------------------------------------------------------------------------
  8542. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8543. {
  8544. ResetIncrementalSearch();
  8545. }
  8546. //---------------------------------------------------------------------------
  8547. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8548. {
  8549. DebugAssert(ComponentVisible[Component]);
  8550. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8551. }
  8552. //---------------------------------------------------------------------------
  8553. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8554. {
  8555. // when queue panel is resized here directly, the status bar is stretched
  8556. // over whole space the panel occupied
  8557. PostComponentHide(fcQueueView);
  8558. }
  8559. //---------------------------------------------------------------------------
  8560. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8561. {
  8562. ComponentVisible[fcQueueFileList] = false;
  8563. }
  8564. //---------------------------------------------------------------------------
  8565. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8566. {
  8567. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8568. RefreshColorMode();
  8569. ResetSysDarkTheme();
  8570. ConfigurationChanged();
  8571. ConfigureInterface();
  8572. // Should be called for all controls
  8573. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8574. }
  8575. //---------------------------------------------------------------------------
  8576. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8577. {
  8578. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8579. if (!FInvalid &&
  8580. (Message.LParam != 0) &&
  8581. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8582. {
  8583. ThemeChanged();
  8584. }
  8585. TForm::Dispatch(&Message);
  8586. }
  8587. //---------------------------------------------------------------------------
  8588. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8589. {
  8590. TMessage * M = static_cast<TMessage*>(Message);
  8591. switch (M->Msg)
  8592. {
  8593. case CM_DIALOGCHAR:
  8594. CMDialogChar(*M);
  8595. break;
  8596. case WM_APPCOMMAND:
  8597. WMAppCommand(*M);
  8598. break;
  8599. case WM_SYSCOMMAND:
  8600. WMSysCommand(*M);
  8601. break;
  8602. case WM_QUERYENDSESSION:
  8603. WMQueryEndSession(*M);
  8604. break;
  8605. case WM_ENDSESSION:
  8606. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8607. break;
  8608. #ifdef _DEBUG
  8609. case WM_WINDOWPOSCHANGED:
  8610. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8611. break;
  8612. case CM_CUSTOMSTYLECHANGED:
  8613. TForm::Dispatch(Message);
  8614. break;
  8615. #endif
  8616. case WM_COMPONENT_HIDE:
  8617. {
  8618. Byte Component = static_cast<Byte>(M->WParam);
  8619. // sanity check
  8620. if (ComponentVisible[Component])
  8621. {
  8622. // special treatment
  8623. if (Component == fcQueueView)
  8624. {
  8625. ToggleQueueVisibility();
  8626. DebugAssert(!ComponentVisible[fcQueueView]);
  8627. }
  8628. else
  8629. {
  8630. ComponentVisible[Component] = false;
  8631. }
  8632. }
  8633. }
  8634. break;
  8635. case WM_COPYDATA:
  8636. WMCopyData(*M);
  8637. break;
  8638. case WM_MANAGES_CAPTION:
  8639. // caption managed in TTerminalManager::UpdateAppTitle()
  8640. M->Result = 1;
  8641. break;
  8642. case WM_WANTS_MOUSEWHEEL:
  8643. M->Result = 1;
  8644. break;
  8645. case CM_SHOWINGCHANGED:
  8646. CMShowingChanged(*M);
  8647. break;
  8648. case WM_CLOSE:
  8649. WMClose(*M);
  8650. break;
  8651. case WM_DPICHANGED:
  8652. WMDpiChanged(*M);
  8653. break;
  8654. case CM_DPICHANGED:
  8655. CMDpiChanged(*M);
  8656. break;
  8657. case WM_SETTINGCHANGE:
  8658. WMSettingChange(*M);
  8659. break;
  8660. case CM_DIALOGKEY:
  8661. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8662. break;
  8663. default:
  8664. TForm::Dispatch(Message);
  8665. break;
  8666. }
  8667. }
  8668. //---------------------------------------------------------------------------
  8669. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8670. {
  8671. // noop
  8672. }
  8673. //---------------------------------------------------------------------------
  8674. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8675. {
  8676. TForm::Dispatch(&Message);
  8677. FSessionColors->Clear();
  8678. AddFixedSessionImages();
  8679. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8680. UpdateImages();
  8681. }
  8682. //---------------------------------------------------------------------------
  8683. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8684. {
  8685. TForm::Dispatch(&Message);
  8686. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8687. UpdatePixelsPerInchMainWindowCounter();
  8688. }
  8689. //---------------------------------------------------------------------------
  8690. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8691. {
  8692. // Cannot close window while we are busy.
  8693. // We cannot test this in FormCloseQuery as that is called also from
  8694. // Close(), which is called by CloseApplicationAction. So we can be busy
  8695. // there already even, when it is legitimate to close the application.
  8696. // Possibly a better place to handle this would be WMSysCommand.
  8697. if (NonVisualDataModule->Busy)
  8698. {
  8699. Message.Result = 1;
  8700. }
  8701. else
  8702. {
  8703. TForm::Dispatch(&Message);
  8704. }
  8705. }
  8706. //---------------------------------------------------------------------------
  8707. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8708. {
  8709. // Ignoring implicit local-local browser of Commander, opened from DoShow
  8710. bool NoSession = (ManagedSession == NULL);
  8711. // This calls TCustomScpExplorerForm::DoShow
  8712. TForm::Dispatch(&Message);
  8713. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  8714. if (Showing && !FStarted)
  8715. {
  8716. FStarted = true;
  8717. InterfaceStarted();
  8718. }
  8719. if (Showing && NoSession)
  8720. {
  8721. // When we are starting minimized (i.e. from an installer),
  8722. // postpone showing Login dialog until we get restored.
  8723. // Otherwise the Login dialog (and Authentication window) show restored
  8724. // over invisible (minimized) main window.
  8725. if (WindowState == wsMinimized)
  8726. {
  8727. FNeedSession = true;
  8728. }
  8729. else
  8730. {
  8731. // This happens before application ever goes idle, so the toolbars would
  8732. // stay enabled (initial state) until the Login dialog is dismissed.
  8733. UpdateActions();
  8734. NonVisualDataModule->StartBusy();
  8735. try
  8736. {
  8737. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8738. // otherwise the dialog does not receive focus.
  8739. // With Commander interface the ProcessMessages is called already
  8740. // by TDriveView, but with Explorer interface, we need to call it explicily
  8741. Application->ProcessMessages();
  8742. // do not reload sessions, they have been loaded just now (optimization)
  8743. NeedSession(true);
  8744. }
  8745. __finally
  8746. {
  8747. NonVisualDataModule->EndBusy();
  8748. }
  8749. }
  8750. }
  8751. }
  8752. //---------------------------------------------------------------------------
  8753. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8754. {
  8755. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8756. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8757. }
  8758. //---------------------------------------------------------------------------
  8759. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8760. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8761. int & MaxHeight)
  8762. {
  8763. // workaround for bug in TWinControl.CalcConstraints
  8764. // Check for empty rect (restore from iconic state) is done there only after
  8765. // call to AdjustClientRect, which enlarges the rect (for forms).
  8766. TRect R = GetClientRect();
  8767. // when restoring from iconic state, place no restrictions
  8768. if (IsRectEmpty(R))
  8769. {
  8770. MinWidth = 0;
  8771. MinHeight = 0;
  8772. MaxWidth = 32000;
  8773. MaxHeight = 32000;
  8774. }
  8775. }
  8776. //---------------------------------------------------------------------------
  8777. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8778. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8779. {
  8780. // terminal can be already closed (e.g. dropped connection)
  8781. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8782. {
  8783. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8784. try
  8785. {
  8786. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8787. }
  8788. catch(...)
  8789. {
  8790. if (!Terminal->Active)
  8791. {
  8792. Close = true;
  8793. }
  8794. throw;
  8795. }
  8796. }
  8797. }
  8798. //---------------------------------------------------------------------------
  8799. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8800. {
  8801. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8802. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8803. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8804. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8805. {
  8806. OnGetSpaceAvailable = GetSpaceAvailable;
  8807. }
  8808. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8809. OnGetSpaceAvailable);
  8810. }
  8811. //---------------------------------------------------------------------------
  8812. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8813. {
  8814. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8815. Terminal->FillSessionDataForCode(Data.get());
  8816. return Data.release();
  8817. }
  8818. //---------------------------------------------------------------------------
  8819. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8820. {
  8821. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8822. DoGenerateUrlDialog(Data.get(), Paths);
  8823. }
  8824. //---------------------------------------------------------------------------
  8825. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8826. {
  8827. GenerateUrl(NULL);
  8828. }
  8829. //---------------------------------------------------------------------------
  8830. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8831. {
  8832. std::unique_ptr<TStrings> Paths(new TStringList());
  8833. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8834. GenerateUrl(Paths.get());
  8835. }
  8836. //---------------------------------------------------------------------------
  8837. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8838. {
  8839. FSessionColor = value;
  8840. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8841. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8842. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8843. DebugAssert(ColorItem != NULL);
  8844. ColorItem->Color = C;
  8845. NonVisualDataModule->ColorMenuItem->Color = C;
  8846. UpdateControls();
  8847. }
  8848. //---------------------------------------------------------------------------
  8849. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8850. {
  8851. if (value != FSessionColor)
  8852. {
  8853. UpdateSessionColor(value);
  8854. // Is null when called from LastTerminalClosed
  8855. if (Terminal != NULL)
  8856. {
  8857. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8858. }
  8859. }
  8860. }
  8861. //---------------------------------------------------------------------------
  8862. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8863. {
  8864. bool Result = FNoteTimer->Enabled;
  8865. if (Result)
  8866. {
  8867. // cannot cancel note too early
  8868. bool NotEarly =
  8869. (Now() - FNoteShown >
  8870. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8871. if (Force || NotEarly)
  8872. {
  8873. FNoteTimer->Enabled = false;
  8874. FNote = L"";
  8875. SAFE_DESTROY(FNoteData);
  8876. FOnNoteClick = NULL;
  8877. FNoteHints = FNotes->Text;
  8878. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8879. UpdateStatusBar();
  8880. }
  8881. }
  8882. return Result;
  8883. }
  8884. //---------------------------------------------------------------------------
  8885. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8886. {
  8887. DebugAssert(FNoteTimer->Enabled);
  8888. CancelNote(true);
  8889. }
  8890. //---------------------------------------------------------------------------
  8891. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  8892. {
  8893. FNoteHints = FNotes->Text.TrimRight();
  8894. }
  8895. //---------------------------------------------------------------------------
  8896. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8897. {
  8898. int P = Note.Pos(L"\n");
  8899. if (P > 0)
  8900. {
  8901. Note.SetLength(P - 1);
  8902. }
  8903. FNotes->Add(FORMAT(L"[%s] %s",
  8904. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8905. while (FNotes->Count > 10)
  8906. {
  8907. FNotes->Delete(0);
  8908. }
  8909. if (UpdateNow)
  8910. {
  8911. UpdateNoteHints();
  8912. UpdateStatusBar();
  8913. }
  8914. }
  8915. //---------------------------------------------------------------------------
  8916. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8917. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8918. {
  8919. int P = Note.Pos(L"\n");
  8920. if (P > 0)
  8921. {
  8922. Note.SetLength(P - 1);
  8923. }
  8924. UpdateNoteHints();
  8925. FNote = Note;
  8926. SAFE_DESTROY(FNoteData);
  8927. FNoteData = NoteData;
  8928. FOnNoteClick = OnNoteClick;
  8929. AddNote(Note, false);
  8930. UpdateStatusBar();
  8931. FNoteShown = Now();
  8932. FNoteTimer->Enabled = false;
  8933. if (Seconds == 0)
  8934. {
  8935. Seconds = WinConfiguration->NotificationsTimeout;
  8936. }
  8937. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8938. FNoteTimer->Enabled = true;
  8939. }
  8940. //---------------------------------------------------------------------------
  8941. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8942. {
  8943. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8944. }
  8945. //---------------------------------------------------------------------------
  8946. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8947. {
  8948. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  8949. {
  8950. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8951. }
  8952. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8953. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8954. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  8955. 0, NULL, NULL);
  8956. }
  8957. //---------------------------------------------------------------------------
  8958. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8959. {
  8960. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8961. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8962. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8963. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  8964. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8965. }
  8966. //---------------------------------------------------------------------------
  8967. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8968. {
  8969. WinConfiguration->FormatSizeBytes = Style;
  8970. }
  8971. //---------------------------------------------------------------------------
  8972. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8973. {
  8974. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8975. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8976. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8977. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8978. }
  8979. //---------------------------------------------------------------------------
  8980. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8981. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8982. {
  8983. if (Panel->Index == 0)
  8984. {
  8985. if (FOnNoteClick != NULL)
  8986. {
  8987. // prevent the user data from being freed by possible call
  8988. // to CancelNote or PostNote during call to OnNoteClick
  8989. std::unique_ptr<TObject> NoteData(FNoteData);
  8990. TNotifyEvent OnNoteClick = FOnNoteClick;
  8991. FNoteData = NULL;
  8992. // need to cancel the note as we are going to delete its user data
  8993. CancelNote(true);
  8994. OnNoteClick(NoteData.get());
  8995. }
  8996. }
  8997. if (HasActiveTerminal() &&
  8998. (Panel->Index >= Sender->Panels->Count - SessionPanelCount))
  8999. {
  9000. FileSystemInfo();
  9001. }
  9002. }
  9003. //---------------------------------------------------------------------------
  9004. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  9005. {
  9006. // workaround:
  9007. // 1) for unknown reason, disabling window, while minimized,
  9008. // prevents it from restoring, even if it was enabled again meanwhile
  9009. // 2) when disabling the main window, while another has focus
  9010. // minimize is no longer possible
  9011. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  9012. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  9013. // Shouldn't we use IsApplicationMinimized() here?
  9014. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  9015. {
  9016. Enabled = false;
  9017. }
  9018. FLockLevel++;
  9019. }
  9020. //---------------------------------------------------------------------------
  9021. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  9022. {
  9023. DebugAssert(FLockLevel > 0);
  9024. FLockLevel--;
  9025. if (FLockLevel == 0)
  9026. {
  9027. DebugAssert(FLockSuspendLevel == 0);
  9028. Enabled = true;
  9029. }
  9030. }
  9031. //---------------------------------------------------------------------------
  9032. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  9033. {
  9034. // We need to make sure that window is enabled when the last modal window closes
  9035. // otherwise focus is not restored correctly.
  9036. // So we re-enable the window when modal window opens and
  9037. // disable it back after is closes
  9038. if (FLockLevel > 0)
  9039. {
  9040. // while we have nesting counter, we know that we never be called
  9041. // recursivelly as Application->OnModalBegin is called only
  9042. // for the top-level modal window
  9043. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9044. {
  9045. // won't be disabled when conditions in LockWindow() were not satisfied
  9046. FDisabledOnLockSuspend = !Enabled;
  9047. // When minimized to tray (or actually when set to SW_HIDE),
  9048. // setting Enabled makes the window focusable even when there's
  9049. // modal window over it
  9050. if (!FTrayIcon->Visible)
  9051. {
  9052. Enabled = true;
  9053. }
  9054. }
  9055. FLockSuspendLevel++;
  9056. }
  9057. }
  9058. //---------------------------------------------------------------------------
  9059. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  9060. {
  9061. if (FLockSuspendLevel > 0)
  9062. {
  9063. DebugAssert(FLockLevel > 0);
  9064. FLockSuspendLevel--;
  9065. // see comment in SuspendWindowLock
  9066. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9067. {
  9068. // Note that window can be enabled here, when we were minized to tray when
  9069. // was SuspendWindowLock() called.
  9070. // We should possibly do the same check as in LockWindow(),
  9071. // if it is ever possible that the consitions change between
  9072. // SuspendWindowLock() and ResumeWindowLock()
  9073. Enabled = !FDisabledOnLockSuspend;
  9074. }
  9075. }
  9076. }
  9077. //---------------------------------------------------------------------------
  9078. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9079. {
  9080. TTBXComboBoxItem * RemotePathComboBox =
  9081. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9082. if (!TextOnly)
  9083. {
  9084. TStrings * Items = RemotePathComboBox->Strings;
  9085. Items->BeginUpdate();
  9086. try
  9087. {
  9088. Items->Clear();
  9089. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9090. {
  9091. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9092. while (!IsUnixRootPath(APath))
  9093. {
  9094. int P = APath.LastDelimiter(L'/');
  9095. DebugAssert(P >= 0);
  9096. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9097. APath.SetLength(P - 1);
  9098. }
  9099. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9100. }
  9101. }
  9102. __finally
  9103. {
  9104. Items->EndUpdate();
  9105. }
  9106. }
  9107. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9108. // Setting ItemIndex to -1 does not reset its text
  9109. if (RemotePathComboBox->Strings->Count == 0)
  9110. {
  9111. RemotePathComboBox->Text = L"";
  9112. }
  9113. }
  9114. //---------------------------------------------------------------------------
  9115. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9116. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9117. {
  9118. if (AIndex < 0)
  9119. {
  9120. AIndex = Sender->ItemIndex;
  9121. }
  9122. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9123. }
  9124. //---------------------------------------------------------------------------
  9125. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9126. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9127. int & ImageIndex)
  9128. {
  9129. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9130. }
  9131. //---------------------------------------------------------------------------
  9132. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9133. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9134. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9135. {
  9136. if (!IsLocalBrowserMode())
  9137. {
  9138. ARect.Left += (10 * AIndex);
  9139. }
  9140. }
  9141. //---------------------------------------------------------------------------
  9142. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9143. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9144. {
  9145. AWidth += (10 * AIndex);
  9146. }
  9147. //---------------------------------------------------------------------------
  9148. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9149. {
  9150. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9151. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9152. int Index = RemotePathComboBox->ItemIndex;
  9153. while (Index < RemotePathComboBox->Strings->Count - 1)
  9154. {
  9155. APath = UnixExtractFileDir(APath);
  9156. Index++;
  9157. }
  9158. // VanDyke style paths
  9159. if (APath.IsEmpty())
  9160. {
  9161. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9162. APath = ROOTDIRECTORY;
  9163. }
  9164. if (RemoteDirView->Path != APath)
  9165. {
  9166. RemoteDirView->Path = APath;
  9167. }
  9168. }
  9169. //---------------------------------------------------------------------------
  9170. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9171. {
  9172. DoRemotePathComboBoxItemClick(Sender);
  9173. }
  9174. //---------------------------------------------------------------------------
  9175. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9176. {
  9177. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9178. DebugUsedParam(Sender);
  9179. UpdateRemotePathComboBox(true);
  9180. }
  9181. //---------------------------------------------------------------------------
  9182. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9183. {
  9184. DoRemotePathComboBoxCancel(Sender);
  9185. }
  9186. //---------------------------------------------------------------------------
  9187. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9188. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9189. {
  9190. ResetIncrementalSearch();
  9191. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9192. DebugAssert(DirView != NULL);
  9193. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9194. {
  9195. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9196. // OnEditing is called also from TCustomListView::CanEdit
  9197. if (Edit != NULL)
  9198. {
  9199. EditSelectBaseName(Edit);
  9200. }
  9201. }
  9202. }
  9203. //---------------------------------------------------------------------------
  9204. //---------------------------------------------------------------------------
  9205. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9206. {
  9207. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9208. Result->AutoDetectDnD = false;
  9209. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9210. Result->RenderDataOn = rdoEnterAndDropSync;
  9211. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9212. return Result;
  9213. }
  9214. //---------------------------------------------------------------------------
  9215. void __fastcall TCustomScpExplorerForm::UpdateDarkMode()
  9216. {
  9217. if (IsWin10Build(2004))
  9218. {
  9219. FImmersiveDarkMode = WinConfiguration->UseDarkTheme();
  9220. BOOL DarkMode = FImmersiveDarkMode ? TRUE : FALSE;
  9221. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9222. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9223. }
  9224. }
  9225. //---------------------------------------------------------------------------
  9226. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9227. {
  9228. TForm::CreateWnd();
  9229. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9230. UpdateDarkMode();
  9231. if (FSessionsDragDropFilesEx == NULL)
  9232. {
  9233. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9234. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9235. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9236. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9237. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9238. }
  9239. if (FQueueDragDropFilesEx == NULL)
  9240. {
  9241. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9242. // No need to set OnDragOver as we do not have any restrictions
  9243. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9244. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9245. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9246. }
  9247. }
  9248. //---------------------------------------------------------------------------
  9249. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9250. {
  9251. TForm::DestroyWnd();
  9252. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9253. FQueueDragDropFilesEx->DragDropControl = NULL;
  9254. }
  9255. //---------------------------------------------------------------------------
  9256. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9257. {
  9258. SideEnter(FCurrentSide);
  9259. FEverShown = true;
  9260. }
  9261. //---------------------------------------------------------------------------
  9262. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9263. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9264. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9265. {
  9266. if (!NonVisualDataModule->Busy)
  9267. {
  9268. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9269. Configuration->Usage->Inc(L"FileFinds");
  9270. LockWindow(true);
  9271. NonVisualDataModule->StartBusy();
  9272. WinConfiguration->LockedInterface = true;
  9273. try
  9274. {
  9275. Terminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9276. }
  9277. __finally
  9278. {
  9279. WinConfiguration->LockedInterface = false;
  9280. NonVisualDataModule->EndBusy();
  9281. UnlockWindow();
  9282. }
  9283. }
  9284. }
  9285. //---------------------------------------------------------------------------
  9286. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9287. {
  9288. if (!NonVisualDataModule->Busy)
  9289. {
  9290. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9291. SetFocus();
  9292. RemoteDirView->Path = UnixExtractFilePath(Path);
  9293. UnicodeString FileName = UnixExtractFileName(Path);
  9294. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9295. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9296. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9297. if (Item == NULL)
  9298. {
  9299. ReloadDirectory(osRemote);
  9300. Item = RemoteDirView->FindFileItem(FileName);
  9301. }
  9302. if (Item != NULL)
  9303. {
  9304. RemoteDirView->ItemFocused = Item;
  9305. RemoteDirView->ItemFocused->MakeVisible(false);
  9306. RemoteDirView->SetFocus();
  9307. }
  9308. }
  9309. }
  9310. //---------------------------------------------------------------------------
  9311. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9312. {
  9313. bool Result = !NonVisualDataModule->Busy;
  9314. if (Result)
  9315. {
  9316. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9317. }
  9318. return Result;
  9319. }
  9320. //---------------------------------------------------------------------------
  9321. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9322. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9323. {
  9324. if (CanOperateOnFoundFiles(ATerminal))
  9325. {
  9326. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9327. FOnFileOperationFinished = OnFileOperationFinished;
  9328. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9329. }
  9330. }
  9331. //---------------------------------------------------------------------------
  9332. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9333. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9334. {
  9335. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9336. }
  9337. //---------------------------------------------------------------------------
  9338. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9339. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9340. {
  9341. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9342. }
  9343. //---------------------------------------------------------------------------
  9344. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9345. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9346. {
  9347. if (CanOperateOnFoundFiles(ATerminal))
  9348. {
  9349. for (int Index = 0; Index < FileList->Count; Index++)
  9350. {
  9351. UnicodeString FileName = FileList->Strings[Index];
  9352. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9353. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9354. OnFileOperationFinished(FileName, true);
  9355. }
  9356. }
  9357. }
  9358. //---------------------------------------------------------------------------
  9359. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9360. {
  9361. FFileFindTerminal = Terminal;
  9362. ShowFileFindDialog(
  9363. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9364. DoDownloadFoundFiles, DoEditFoundFiles);
  9365. }
  9366. //---------------------------------------------------------------------------
  9367. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9368. {
  9369. FTaskbarList = TaskbarList;
  9370. }
  9371. //---------------------------------------------------------------------------
  9372. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9373. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9374. {
  9375. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9376. if (Index >= 0)
  9377. {
  9378. if (Button == mbLeft)
  9379. {
  9380. // "Mouse down" is raised only after tab is switched.
  9381. // If switching tab (switching session) takes long enough for user
  9382. // to actually release the button, "mouse down" is still raised,
  9383. // but we do not get "mouse up" event, so dragging is not cancelled,
  9384. // prevent that by not beginning dragging in the first place.
  9385. if (IsKeyPressed(VK_LBUTTON))
  9386. {
  9387. // when user clicks the "+", we get mouse down only after the session
  9388. // is closed, when new session tab is already on X:Y, so dragging
  9389. // starts, prevent that
  9390. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9391. {
  9392. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9393. if (Terminal != NULL)
  9394. {
  9395. SessionsPageControl->BeginDrag(false);
  9396. }
  9397. }
  9398. }
  9399. }
  9400. else if (Button == mbMiddle)
  9401. {
  9402. // ignore middle-click for "New session tab"
  9403. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9404. if (Terminal != NULL)
  9405. {
  9406. CloseSessionTab(Index);
  9407. }
  9408. }
  9409. }
  9410. }
  9411. //---------------------------------------------------------------------------
  9412. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9413. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9414. {
  9415. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9416. // do not allow dropping on the "+" tab
  9417. TTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9418. if ((TargetTerminal != NULL) &&
  9419. (SessionsPageControl->ActivePage->PageIndex != Index))
  9420. {
  9421. Configuration->Usage->Inc(L"SessionTabMoves");
  9422. // this is almost redundant as we would recreate tabs in SessionListChanged,
  9423. // but we want to actually prevent that to avoid flicker
  9424. SessionsPageControl->ActivePage->PageIndex = Index;
  9425. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->ActivePage);
  9426. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9427. }
  9428. }
  9429. //---------------------------------------------------------------------------
  9430. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9431. TObject * Sender, TObject * Source, int X, int Y,
  9432. TDragState /*State*/, bool & Accept)
  9433. {
  9434. Accept = (Sender == Source);
  9435. if (Accept)
  9436. {
  9437. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9438. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9439. // do not allow dragging to the "+" tab
  9440. Accept = (Terminal != NULL);
  9441. }
  9442. }
  9443. //---------------------------------------------------------------------------
  9444. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9445. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9446. {
  9447. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9448. if (Index < 0)
  9449. {
  9450. Effect = DROPEFFECT_NONE;
  9451. }
  9452. else
  9453. {
  9454. TManagedTerminal * TargetSession = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9455. // do not allow dropping on the "+" tab or on local-local tabs
  9456. if ((TargetSession == NULL) || TargetSession->LocalBrowser)
  9457. {
  9458. Effect = DROPEFFECT_NONE;
  9459. }
  9460. else if ((TargetSession != Terminal) && (Effect == DROPEFFECT_MOVE))
  9461. {
  9462. Effect = DROPEFFECT_COPY;
  9463. }
  9464. }
  9465. }
  9466. //---------------------------------------------------------------------------
  9467. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9468. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9469. {
  9470. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9471. // do not allow dropping on the "+" tab
  9472. TManagedTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9473. if (TargetTerminal != NULL)
  9474. {
  9475. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9476. if (!IsFileControl(DropSourceControl, osRemote))
  9477. {
  9478. TTerminalManager::Instance()->ActiveSession = TargetTerminal;
  9479. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9480. // Why don't we use Terminal->CurrentDirectory directly?
  9481. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9482. // do not force queue, drag drop
  9483. false, true);
  9484. }
  9485. }
  9486. }
  9487. //---------------------------------------------------------------------------
  9488. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9489. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9490. {
  9491. // Downloads are handled in RemoteFileControlDDEnd
  9492. if (!IsFileControl(DropSourceControl, osRemote))
  9493. {
  9494. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9495. Terminal->CurrentDirectory,
  9496. // force queue, drag drop
  9497. true, true);
  9498. }
  9499. }
  9500. //---------------------------------------------------------------------------
  9501. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9502. {
  9503. FShowing = false;
  9504. // Do not save empty workspace
  9505. if (WinConfiguration->AutoSaveWorkspace && (ManagedSession != NULL))
  9506. {
  9507. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9508. UnicodeString Name = WorkspaceName();
  9509. DoSaveWorkspace(
  9510. Name, DataList.get(),
  9511. !Configuration->DisablePasswordStoring &&
  9512. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9513. WinConfiguration->LastStoredSession = Name;
  9514. }
  9515. }
  9516. //---------------------------------------------------------------------------
  9517. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9518. {
  9519. TManagedTerminal * ManagedTerminal =
  9520. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9521. if (ManagedTerminal != NULL)
  9522. {
  9523. ManagedTerminal->DirectoryLoaded = Now();
  9524. }
  9525. }
  9526. //---------------------------------------------------------------------------
  9527. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9528. TListItem * /*Item*/, bool /*Selected*/)
  9529. {
  9530. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9531. switch (DirView->LastSelectMethod)
  9532. {
  9533. case smKeyboard:
  9534. Configuration->Usage->Inc(L"KeyboardSelections");
  9535. break;
  9536. case smMouse:
  9537. Configuration->Usage->Inc(L"MouseSelections");
  9538. break;
  9539. }
  9540. }
  9541. //---------------------------------------------------------------------------
  9542. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9543. {
  9544. if (Color != 0)
  9545. {
  9546. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9547. }
  9548. else
  9549. {
  9550. return FSessionTabImageIndex;
  9551. }
  9552. }
  9553. //---------------------------------------------------------------------------
  9554. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9555. {
  9556. TPngImageCollectionItem * Item =
  9557. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9558. FSessionColors->AddPng(Item->PngImage);
  9559. return FSessionColors->Count - 1;
  9560. }
  9561. //---------------------------------------------------------------------------
  9562. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9563. {
  9564. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9565. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9566. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9567. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9568. FLocalBrowserTabImageIndex = AddFixedSessionImage(LocalBrowserImageIndex);
  9569. }
  9570. //---------------------------------------------------------------------------
  9571. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9572. {
  9573. for (int Index = 0; Index < Control->ControlCount; Index++)
  9574. {
  9575. TControl * AControl = Control->Controls[Index];
  9576. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9577. if (WinControl != NULL)
  9578. {
  9579. CollectItemsWithTextDisplayMode(WinControl);
  9580. }
  9581. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9582. if (Toolbar != NULL)
  9583. {
  9584. // we care for top-level items only
  9585. TTBCustomItem * Items = Toolbar->Items;
  9586. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9587. {
  9588. TTBCustomItem * Item = Items->Items[ItemIndex];
  9589. if (((Item->DisplayMode == nbdmImageAndText) ||
  9590. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9591. EligibleForImageDisplayMode(Item))
  9592. {
  9593. FItemsWithTextDisplayMode.insert(Item);
  9594. }
  9595. }
  9596. }
  9597. }
  9598. }
  9599. //---------------------------------------------------------------------------
  9600. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9601. {
  9602. return true;
  9603. }
  9604. //---------------------------------------------------------------------------
  9605. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9606. {
  9607. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9608. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9609. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9610. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9611. bool Result = true;
  9612. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9613. {
  9614. TTBCustomItem * Item = *i;
  9615. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9616. if (Label != NULL)
  9617. {
  9618. // optimization
  9619. if (Label->Visible == SelectiveToolbarText)
  9620. {
  9621. Result = false;
  9622. }
  9623. else
  9624. {
  9625. Label->Visible = SelectiveToolbarText;
  9626. }
  9627. }
  9628. else
  9629. {
  9630. // optimization
  9631. if (Item->DisplayMode == DisplayMode)
  9632. {
  9633. Result = false;
  9634. }
  9635. else
  9636. {
  9637. Item->DisplayMode = DisplayMode;
  9638. }
  9639. }
  9640. ++i;
  9641. }
  9642. if (Result)
  9643. {
  9644. UpdateNewSessionTab();
  9645. }
  9646. return Result;
  9647. }
  9648. //---------------------------------------------------------------------------
  9649. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9650. {
  9651. DebugFail();
  9652. }
  9653. //---------------------------------------------------------------------------
  9654. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9655. {
  9656. // Among other, a lock level is non zero, while directory is being loaded,
  9657. // even when it happens as a result of dirview navigation,
  9658. // i.e. when TNonVisualDataModule is NOT FBusy.
  9659. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9660. // Among other this prevents a panel auto update to occur while
  9661. // directory is changing.
  9662. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9663. }
  9664. //---------------------------------------------------------------------------
  9665. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  9666. {
  9667. // While the window is disabled, we still seem to process menu shortcuts at least,
  9668. // so stop it at least here.
  9669. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9670. bool Result;
  9671. if (Allowed == aaUpdate)
  9672. {
  9673. Result = true;
  9674. }
  9675. else
  9676. {
  9677. Result = !NonVisualDataModule->Busy;
  9678. if (Result && (Allowed == aaShortCut))
  9679. {
  9680. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  9681. Action->Update();
  9682. Result = Action->Enabled;
  9683. }
  9684. }
  9685. return Result;
  9686. }
  9687. //---------------------------------------------------------------------------
  9688. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9689. {
  9690. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9691. }
  9692. //---------------------------------------------------------------------------
  9693. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9694. {
  9695. // This is somewhat redundant to LockWindow() call from
  9696. // TTerminalManager::TerminalReadDirectoryProgress.
  9697. // But disabling window is known not to block keyboard shorcuts
  9698. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9699. if (Busy > 0)
  9700. {
  9701. if (NonVisualDataModule->Busy)
  9702. {
  9703. State = false;
  9704. }
  9705. else
  9706. {
  9707. NonVisualDataModule->StartBusy();
  9708. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9709. LockWindow();
  9710. }
  9711. }
  9712. else if (Busy < 0)
  9713. {
  9714. UnlockWindow();
  9715. NonVisualDataModule->EndBusy();
  9716. }
  9717. else
  9718. {
  9719. State = NonVisualDataModule->Busy;
  9720. }
  9721. }
  9722. //---------------------------------------------------------------------------
  9723. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9724. {
  9725. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9726. // no context menu for "New session tab"
  9727. if ((Index >= 0) && (GetSessionTabSession(SessionsPageControl->Pages[Index]) != NULL))
  9728. {
  9729. SessionsPageControl->ActivePageIndex = Index;
  9730. if (DebugAlwaysTrue(SessionTabSwitched()))
  9731. {
  9732. // copied from TControl.WMContextMenu
  9733. SendCancelMode(SessionsPageControl);
  9734. // explicit popup instead of using PopupMenu property
  9735. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9736. // while connecting yet not-connected session and hence
  9737. // allowing an access to commands over not-completelly connected session
  9738. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9739. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9740. PopupMenu->PopupComponent = SessionsPageControl;
  9741. PopupMenu->Popup(Point.x, Point.y);
  9742. }
  9743. }
  9744. Handled = true;
  9745. }
  9746. //---------------------------------------------------------------------------
  9747. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9748. {
  9749. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9750. }
  9751. //---------------------------------------------------------------------------
  9752. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9753. {
  9754. Configuration->Usage->Inc(L"PasswordChanges");
  9755. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9756. ChangePasswordData->DisableAuthentationsExceptPassword();
  9757. ChangePasswordData->ChangePassword = true;
  9758. std::unique_ptr<TTerminal> ChangePasswordSession(
  9759. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9760. ChangePasswordSession->AutoReadDirectory = false;
  9761. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9762. {
  9763. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9764. }
  9765. else
  9766. {
  9767. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9768. }
  9769. }
  9770. //---------------------------------------------------------------------------
  9771. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9772. {
  9773. // No nice way to assert SSH2
  9774. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9775. }
  9776. //---------------------------------------------------------------------------
  9777. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9778. {
  9779. TOperationVisualizer OperationVisualizer;
  9780. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9781. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9782. }
  9783. //---------------------------------------------------------------------------
  9784. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9785. {
  9786. TForm::ChangeScale(M, D);
  9787. int APixelsPerInch = GetControlPixelsPerInch(this);
  9788. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9789. try
  9790. {
  9791. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9792. }
  9793. __finally
  9794. {
  9795. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9796. }
  9797. }
  9798. //---------------------------------------------------------------------------
  9799. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9800. {
  9801. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9802. }
  9803. //---------------------------------------------------------------------
  9804. class TPublicControl : public TControl
  9805. {
  9806. friend class TCustomScpExplorerForm;
  9807. };
  9808. //---------------------------------------------------------------------------
  9809. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9810. {
  9811. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9812. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9813. }
  9814. //---------------------------------------------------------------------------
  9815. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9816. {
  9817. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9818. OpenBookmark(Side, Bookmark);
  9819. }
  9820. //---------------------------------------------------------------------------
  9821. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9822. {
  9823. DoBookmarkClick(osLocal, Sender);
  9824. }
  9825. //---------------------------------------------------------------------------
  9826. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9827. {
  9828. DoBookmarkClick(osRemote, Sender);
  9829. }
  9830. //---------------------------------------------------------------------------
  9831. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9832. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9833. {
  9834. if (BookmarkList != NULL)
  9835. {
  9836. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9837. if (IsLocalBrowserMode())
  9838. {
  9839. Side = osLocal;
  9840. }
  9841. if (!WinConfiguration->UseLocationProfiles)
  9842. {
  9843. std::unique_ptr<TStringList> Directories(new TStringList());
  9844. Directories->CaseSensitive = (Side == osRemote);
  9845. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9846. {
  9847. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9848. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9849. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9850. {
  9851. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9852. Item->Caption = EscapeHotkey(Directory);
  9853. Item->ShortCut = Bookmark->ShortCut;
  9854. Item->OnClick = OnBookmarkClick;
  9855. Item->Tag = reinterpret_cast<int>(Bookmark);
  9856. Directories->Add(Directory);
  9857. Menu->Add(Item.release());
  9858. }
  9859. }
  9860. }
  9861. else
  9862. {
  9863. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9864. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9865. {
  9866. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9867. if (!Bookmark->Node.IsEmpty())
  9868. {
  9869. Folders->Add(Bookmark->Node);
  9870. }
  9871. }
  9872. for (int Index = 0; Index < Folders->Count; Index++)
  9873. {
  9874. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9875. Item->Caption = Folders->Strings[Index];
  9876. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  9877. Folders->Objects[Index] = Item.get();
  9878. Menu->Add(Item.release());
  9879. }
  9880. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9881. {
  9882. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9883. TTBCustomItem * Parent;
  9884. if (!Bookmark->Node.IsEmpty())
  9885. {
  9886. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9887. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9888. }
  9889. else
  9890. {
  9891. Parent = Menu;
  9892. }
  9893. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9894. Item->Caption = Bookmark->Name;
  9895. Item->ShortCut = Bookmark->ShortCut;
  9896. Item->OnClick = OnBookmarkClick;
  9897. Item->Tag = reinterpret_cast<int>(Bookmark);
  9898. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9899. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9900. {
  9901. // No hint for location profiles that are actually mere "bookmarks"
  9902. }
  9903. else
  9904. {
  9905. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9906. UnicodeString LongHint;
  9907. if (!Bookmark->Local.IsEmpty())
  9908. {
  9909. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9910. }
  9911. if (!Bookmark->Remote.IsEmpty())
  9912. {
  9913. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9914. }
  9915. AddToList(Hint, LongHint, L"|");
  9916. Item->Hint = Hint;
  9917. }
  9918. Parent->Add(Item.release());
  9919. }
  9920. }
  9921. AddMenuSeparator(Menu);
  9922. }
  9923. }
  9924. //---------------------------------------------------------------------------
  9925. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9926. {
  9927. Menu->Clear();
  9928. std::unique_ptr<TTBCustomItem> Item;
  9929. Item.reset(new TTBXItem(Owner));
  9930. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9931. Item->Options = Item->Options << tboDefault;
  9932. Menu->Add(Item.release());
  9933. AddMenuSeparator(Menu);
  9934. if (Terminal != NULL)
  9935. {
  9936. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9937. }
  9938. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9939. Item.reset(new TTBXItem(Owner));
  9940. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  9941. Menu->Add(Item.release());
  9942. }
  9943. //---------------------------------------------------------------------------
  9944. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9945. {
  9946. bool Result = true;
  9947. bool Remote = !IsSideLocalBrowser(Side);
  9948. try
  9949. {
  9950. if (Remote)
  9951. {
  9952. Terminal->ExceptionOnFail = true;
  9953. }
  9954. try
  9955. {
  9956. DirView(Side)->Path = Path;
  9957. }
  9958. __finally
  9959. {
  9960. if (Remote)
  9961. {
  9962. Terminal->ExceptionOnFail = false;
  9963. }
  9964. }
  9965. }
  9966. catch (Exception & E)
  9967. {
  9968. if (!Remote || Terminal->Active)
  9969. {
  9970. ShowExtendedExceptionEx(Terminal, &E);
  9971. Result = false;
  9972. }
  9973. else
  9974. {
  9975. throw;
  9976. }
  9977. }
  9978. return Result;
  9979. }
  9980. //---------------------------------------------------------------------------
  9981. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9982. {
  9983. // Make sure there some feedback even when loading tiny local folders
  9984. TInstantOperationVisualizer Visualizer;
  9985. DirView(Side)->ReloadDirectory();
  9986. }
  9987. //---------------------------------------------------------------------------
  9988. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9989. {
  9990. if (Index == SessionsPageControl->TabIndex)
  9991. {
  9992. CloseSession();
  9993. }
  9994. else
  9995. {
  9996. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9997. TTerminal * Terminal = GetSessionTabSession(TabSheet);
  9998. TTerminalManager * Manager = TTerminalManager::Instance();
  9999. if (!Terminal->Active)
  10000. {
  10001. Manager->FreeTerminal(Terminal);
  10002. }
  10003. else
  10004. {
  10005. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  10006. if (CanCloseQueue(Queue))
  10007. {
  10008. Manager->FreeTerminal(Terminal);
  10009. }
  10010. }
  10011. }
  10012. }
  10013. //---------------------------------------------------------------------------
  10014. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  10015. {
  10016. CloseSessionTab(Index);
  10017. }
  10018. //---------------------------------------------------------------------------
  10019. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  10020. {
  10021. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  10022. {
  10023. TInstantOperationVisualizer Visualizer;
  10024. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  10025. // before we create a new data object
  10026. ClipboardClear();
  10027. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  10028. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  10029. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  10030. // Intermediate variable to WORKAROUND a crash in compiler
  10031. TObjectList * ClipboardFakeMonitors =
  10032. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  10033. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  10034. if (FClipboardDragDropFilesEx.get() == NULL)
  10035. {
  10036. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  10037. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  10038. }
  10039. FClipboardDragDropFilesEx->FileList->Clear();
  10040. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  10041. FClipboardDragDropFilesEx->CopyToClipboard();
  10042. FClipboardTerminal = Terminal;
  10043. // Need full paths, as cwd can be different once files are pasted
  10044. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  10045. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  10046. {
  10047. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  10048. }
  10049. }
  10050. }
  10051. //---------------------------------------------------------------------------
  10052. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  10053. {
  10054. if (OpenClipboard(0))
  10055. {
  10056. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  10057. CloseClipboard();
  10058. }
  10059. }
  10060. //---------------------------------------------------------------------------
  10061. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  10062. {
  10063. return !FClipboardFakeDirectory.IsEmpty();
  10064. }
  10065. //---------------------------------------------------------------------------
  10066. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  10067. {
  10068. RemoveDir(ApiPath(FClipboardFakeDirectory));
  10069. FClipboardFakeDirectory = UnicodeString();
  10070. FClipboardTerminal = NULL;
  10071. // Also called in Idle()
  10072. FClipboardFakeMonitors.reset(NULL);
  10073. }
  10074. //---------------------------------------------------------------------------
  10075. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  10076. {
  10077. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  10078. {
  10079. ClipboardStop();
  10080. }
  10081. }
  10082. //---------------------------------------------------------------------------
  10083. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  10084. {
  10085. TTerminalManager * Manager = TTerminalManager::Instance();
  10086. Manager->ActiveSession = FClipboardTerminal;
  10087. TTransferOperationParam Params;
  10088. Params.TargetDirectory = TargetDirectory;
  10089. Params.DragDrop = DragDrop;
  10090. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  10091. }
  10092. //---------------------------------------------------------------------------
  10093. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  10094. {
  10095. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  10096. // (as it pumps a Windows message queue while being shutted down)
  10097. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10098. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10099. {
  10100. // Can fail as it can be e.g. locked by AV, so we retry that later
  10101. bool Removed = RemoveDir(ApiPath(FileName));
  10102. try
  10103. {
  10104. if (!NonVisualDataModule->Busy)
  10105. {
  10106. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10107. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  10108. }
  10109. }
  10110. __finally
  10111. {
  10112. if (!Removed)
  10113. {
  10114. RemoveDir(ApiPath(FileName));
  10115. }
  10116. }
  10117. }
  10118. }
  10119. //---------------------------------------------------------------------------
  10120. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10121. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10122. {
  10123. TFileMasks::TParams MaskParams;
  10124. MaskParams.Size = Size;
  10125. MaskParams.Modification = Modification;
  10126. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10127. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10128. {
  10129. bool ImplicitMatch;
  10130. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  10131. !ImplicitMatch)
  10132. {
  10133. Color = Iter->Color;
  10134. break;
  10135. }
  10136. }
  10137. }
  10138. //---------------------------------------------------------------------------
  10139. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10140. {
  10141. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10142. if (!DirView->IsEditing())
  10143. {
  10144. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10145. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10146. // while searching
  10147. if (Key == VK_BACK)
  10148. {
  10149. if (!FIncrementalSearch.IsEmpty())
  10150. {
  10151. if (FIncrementalSearch.Length() == 1)
  10152. {
  10153. ResetIncrementalSearch();
  10154. }
  10155. else
  10156. {
  10157. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10158. IncrementalSearch(NewText, false, false);
  10159. }
  10160. Key = 0;
  10161. }
  10162. }
  10163. }
  10164. }
  10165. //---------------------------------------------------------------------------
  10166. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10167. {
  10168. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10169. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10170. {
  10171. // Filter control sequences.
  10172. // When not searching yet, prefer use of the space for toggling file selection
  10173. // (so we cannot incrementally search for a string starting with a space).
  10174. if ((Key > VK_SPACE) ||
  10175. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10176. {
  10177. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10178. Key = 0;
  10179. }
  10180. }
  10181. }
  10182. //---------------------------------------------------------------------------
  10183. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10184. {
  10185. if (!FIncrementalSearch.IsEmpty())
  10186. {
  10187. FIncrementalSearch = L"";
  10188. DirView(osCurrent)->UpdateStatusBar();
  10189. }
  10190. }
  10191. //---------------------------------------------------------------------------
  10192. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10193. {
  10194. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10195. if (Item == NULL)
  10196. {
  10197. MessageBeep(MB_ICONHAND);
  10198. }
  10199. else
  10200. {
  10201. TCustomDirView * ADirView = DirView(osCurrent);
  10202. {
  10203. TAutoNestingCounter Guard(FIncrementalSearching);
  10204. ADirView->FocusItem(Item);
  10205. if (ADirView->NortonLike == nlOff)
  10206. {
  10207. if ((ADirView->Selected != Item) ||
  10208. (ADirView->SelCount > 1))
  10209. {
  10210. ADirView->ClearSelection();
  10211. ADirView->Selected = Item;
  10212. }
  10213. }
  10214. }
  10215. FIncrementalSearch = Text;
  10216. Item->MakeVisible(false);
  10217. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10218. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10219. ADirView->UpdateStatusBar();
  10220. }
  10221. }
  10222. //---------------------------------------------------------------------------
  10223. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10224. {
  10225. int Index = Item->Index;
  10226. if (!Reverse)
  10227. {
  10228. Index++;
  10229. if (Index >= Item->Owner->Count)
  10230. {
  10231. Index = 0;
  10232. }
  10233. }
  10234. else
  10235. {
  10236. Index--;
  10237. if (Index < 0)
  10238. {
  10239. Index = Item->Owner->Count - 1;
  10240. }
  10241. }
  10242. return Item->Owner->Item[Index];
  10243. }
  10244. //---------------------------------------------------------------------------
  10245. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10246. {
  10247. TCustomDirView * ADirView = DirView(osCurrent);
  10248. if (ADirView->Items->Count == 0)
  10249. {
  10250. return NULL;
  10251. }
  10252. else
  10253. {
  10254. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10255. TListItem * Item = CurrentItem;
  10256. if (SkipCurrent)
  10257. {
  10258. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10259. }
  10260. while (true)
  10261. {
  10262. bool Matches = false;
  10263. switch (WinConfiguration->PanelSearch)
  10264. {
  10265. case isNameStartOnly:
  10266. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10267. break;
  10268. case isName:
  10269. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10270. break;
  10271. case isAll:
  10272. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10273. int Index = 0;
  10274. while ((Index < ColCount) && !Matches)
  10275. {
  10276. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10277. if (Visible)
  10278. {
  10279. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10280. }
  10281. Index++;
  10282. }
  10283. break;
  10284. }
  10285. if (Matches)
  10286. {
  10287. return Item;
  10288. }
  10289. Item = GetNextFile(Item, Reverse);
  10290. if (Item == CurrentItem)
  10291. {
  10292. return NULL;
  10293. }
  10294. }
  10295. }
  10296. }
  10297. //---------------------------------------------------------------------------
  10298. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10299. {
  10300. ResetIncrementalSearch();
  10301. }
  10302. //---------------------------------------------------------------------------
  10303. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10304. {
  10305. if (Message.CharCode == VK_TAB)
  10306. {
  10307. if (!FIncrementalSearch.IsEmpty())
  10308. {
  10309. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10310. bool Reverse = Shift.Contains(ssShift);
  10311. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10312. Message.Result = 1;
  10313. return;
  10314. }
  10315. }
  10316. else if (Message.CharCode == VK_ESCAPE)
  10317. {
  10318. if (!FIncrementalSearch.IsEmpty())
  10319. {
  10320. ResetIncrementalSearch();
  10321. Message.Result = 1;
  10322. return;
  10323. }
  10324. }
  10325. TForm::Dispatch(&Message);
  10326. }
  10327. //---------------------------------------------------------------------------
  10328. void __fastcall TCustomScpExplorerForm::Deactivate()
  10329. {
  10330. TForm::Deactivate();
  10331. // E.g. when switching to an internal editor window
  10332. ResetIncrementalSearch();
  10333. }
  10334. //---------------------------------------------------------------------------
  10335. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10336. {
  10337. // When switching to another application
  10338. ResetIncrementalSearch();
  10339. }
  10340. //---------------------------------------------------------------------------
  10341. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10342. {
  10343. ResetIncrementalSearch();
  10344. }
  10345. //---------------------------------------------------------------------------
  10346. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10347. {
  10348. if (FIncrementalSearching <= 0)
  10349. {
  10350. ResetIncrementalSearch();
  10351. }
  10352. }
  10353. //---------------------------------------------------------------------------
  10354. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10355. {
  10356. CountClicksForWindowPrint(this);
  10357. }
  10358. //---------------------------------------------------------------------------
  10359. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10360. {
  10361. CenterReconnectToolbar();
  10362. }
  10363. //---------------------------------------------------------------------------
  10364. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10365. {
  10366. if (RemoteDirView->ItemFocused != NULL)
  10367. {
  10368. RemoteDirView->ItemFocused->Selected = true;
  10369. }
  10370. }
  10371. //---------------------------------------------------------------------------
  10372. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10373. {
  10374. if (!FQueueStatusUpdating)
  10375. {
  10376. bool Refresh;
  10377. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10378. {
  10379. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10380. }
  10381. else
  10382. {
  10383. if (FQueueFileList->GetCount() > 0)
  10384. {
  10385. FQueueFileList->Clear();
  10386. Refresh = true;
  10387. }
  10388. }
  10389. int Count = FQueueFileList->GetCount();
  10390. if (QueueFileList->Items->Count != Count)
  10391. {
  10392. DebugAssert(Refresh);
  10393. QueueFileList->Items->Count = Count;
  10394. }
  10395. if (Refresh)
  10396. {
  10397. QueueFileList->Invalidate();
  10398. }
  10399. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10400. }
  10401. }
  10402. //---------------------------------------------------------------------------
  10403. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10404. {
  10405. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10406. }
  10407. //---------------------------------------------------------------------------
  10408. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10409. {
  10410. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10411. // See TSynchronizeChecklistDialog::UpdateTimer
  10412. if (QueueFileList->Items->Count > 0)
  10413. {
  10414. QueueFileList->Items->Item[0]->MakeVisible(false);
  10415. }
  10416. UpdateQueueFileList();
  10417. }
  10418. //---------------------------------------------------------------------------
  10419. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10420. {
  10421. Active = QueueView3->Focused() || QueueFileList->Focused();
  10422. }
  10423. //---------------------------------------------------------------------------
  10424. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10425. {
  10426. QueueLabelUpdateStatus();
  10427. }
  10428. //---------------------------------------------------------------------------
  10429. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10430. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10431. {
  10432. int State = FQueueFileList->GetState(Item->Index);
  10433. if (State == qfsProcessed)
  10434. {
  10435. Sender->Canvas->Font->Color = clGrayText;
  10436. }
  10437. }
  10438. //---------------------------------------------------------------------------
  10439. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10440. {
  10441. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10442. QueueFileList->Column[0]->Width =
  10443. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10444. }
  10445. //---------------------------------------------------------------------------
  10446. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10447. {
  10448. QueueFileListColumnAutoSize();
  10449. }
  10450. //---------------------------------------------------------------------------
  10451. void __fastcall TCustomScpExplorerForm::CloseApp()
  10452. {
  10453. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10454. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10455. // So we clear the flag here.
  10456. DebugAssert(NonVisualDataModule->Busy);
  10457. NonVisualDataModule->EndBusy();
  10458. try
  10459. {
  10460. Close();
  10461. }
  10462. __finally
  10463. {
  10464. NonVisualDataModule->StartBusy();
  10465. }
  10466. }
  10467. //---------------------------------------------------------------------------
  10468. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10469. {
  10470. return (Terminal != NULL) && Terminal->Active;
  10471. }
  10472. //---------------------------------------------------------------------------
  10473. bool __fastcall TCustomScpExplorerForm::HasManagedSession()
  10474. {
  10475. return (ManagedSession != NULL);
  10476. }
  10477. //---------------------------------------------------------------------------
  10478. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10479. {
  10480. return IsActiveTerminal(Terminal);
  10481. }
  10482. //---------------------------------------------------------------------------
  10483. void TCustomScpExplorerForm::LocalLocalCopy(
  10484. TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused), bool DebugUsedArg(NoConfirmation),
  10485. bool DebugUsedArg(DragDrop), unsigned int DebugUsedArg(Flags))
  10486. {
  10487. DebugFail();
  10488. }
  10489. //---------------------------------------------------------------------------
  10490. void TCustomScpExplorerForm::LocalLocalCopyCommand(TFileOperation Operation, TOperationSide Side, bool OnFocused, unsigned int Flags)
  10491. {
  10492. LocalLocalCopy(Operation, Side, OnFocused, !WinConfiguration->ConfirmTransferring, false, Flags);
  10493. }