CustomScpExplorer.cpp 359 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943
  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 = 4;
  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. class TAutoBatch
  100. {
  101. public:
  102. TAutoBatch(TCustomScpExplorerForm * Form) :
  103. FForm(Form)
  104. {
  105. FForm->BatchStart(FBatchStorage);
  106. }
  107. ~TAutoBatch()
  108. {
  109. FForm->BatchEnd(FBatchStorage);
  110. }
  111. private:
  112. TCustomScpExplorerForm * FForm;
  113. void * FBatchStorage;
  114. };
  115. //---------------------------------------------------------------------------
  116. struct TTransferOperationParam
  117. {
  118. TTransferOperationParam();
  119. UnicodeString TargetDirectory;
  120. bool Temp;
  121. bool DragDrop;
  122. int Options;
  123. TAutoSwitch Queue;
  124. };
  125. //---------------------------------------------------------------------------
  126. TTransferOperationParam::TTransferOperationParam()
  127. {
  128. Temp = false;
  129. DragDrop = false;
  130. Options = 0;
  131. Queue = asAuto;
  132. }
  133. //---------------------------------------------------------------------------
  134. class TTransferPresetNoteData : public TObject
  135. {
  136. public:
  137. UnicodeString Message;
  138. };
  139. //---------------------------------------------------------------------------
  140. class TTerminalNoteData : public TObject
  141. {
  142. public:
  143. TManagedTerminal * Terminal;
  144. };
  145. //---------------------------------------------------------------------------
  146. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  147. FFormRestored(false),
  148. TForm(Owner)
  149. {
  150. FInvalid = false;
  151. FCurrentSide = osRemote;
  152. FEverShown = false;
  153. FDocks = new TList();
  154. InitControls();
  155. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  156. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  157. NonVisualDataModule->ScpExplorer = this;
  158. RestoreParams();
  159. ConfigurationChanged();
  160. RemoteDirView->Invalidate();
  161. FAutoOperation = false;
  162. FOnFileOperationFinished = NULL;
  163. FForceExecution = false;
  164. FIgnoreNextDialogChar = 0;
  165. FErrorList = NULL;
  166. FSynchronizeProgressForm = NULL;
  167. FProgressForm = NULL;
  168. FRefreshLocalDirectory = false;
  169. FRefreshRemoteDirectory = false;
  170. FDDExtMapFile = NULL;
  171. // CreateMutexW keeps failing with ERROR_NOACCESS
  172. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  173. DebugAssert(FDDExtMutex != NULL);
  174. FDDTargetControl = NULL;
  175. FDelayedDeletionTimer = NULL;
  176. FDelayedDeletionList = new TStringList();
  177. FDDFileList = NULL;
  178. FPendingTempSpaceWarn = false;
  179. FCapturedLog = NULL;
  180. FDragDropOperation = false;
  181. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  182. FAllowTransferPresetAutoSelect = true;
  183. FCopyParamDefault = L"";
  184. FSynchronizeController = NULL;
  185. FPendingQueueActionItem = NULL;
  186. FLockLevel = 0;
  187. FLockSuspendLevel = 0;
  188. FDisabledOnLockSuspend = false;
  189. FAlternativeDelete = false;
  190. FTrayIcon = new ::TTrayIcon(0);
  191. FTrayIcon->OnClick = TrayIconClick;
  192. FMaxQueueLength = 0;
  193. FLastContextPopupScreenPoint = TPoint(-1, -1);
  194. FTransferResumeList = NULL;
  195. FMoveToQueue = false;
  196. FStandaloneEditing = false;
  197. FOnFeedSynchronizeError = NULL;
  198. FNeedSession = false;
  199. FDoNotIdleCurrentTerminal = 0;
  200. FIncrementalSearching = 0;
  201. FIncrementalSearchHaveNext = false;
  202. FQueueFileList.reset(new TQueueFileList());
  203. FEditorManager = new TEditorManager();
  204. FEditorManager->OnFileChange = ExecutedFileChanged;
  205. FEditorManager->OnFileReload = ExecutedFileReload;
  206. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  207. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  208. FLocalEditors = new TList();
  209. FQueueStatus = NULL;
  210. FQueueStatusSection = new TCriticalSection();
  211. FQueueStatusInvalidated = false;
  212. FQueueItemInvalidated = false;
  213. FQueueStatusUpdating = false;
  214. FQueueActedItem = NULL;
  215. FQueueController = new TQueueController(QueueView3);
  216. FUserActionTimer = new TTimer(this);
  217. FUserActionTimer->Enabled = false;
  218. FUserActionTimer->Interval = 10;
  219. FUserActionTimer->OnTimer = UserActionTimer;
  220. FNotes = new TStringList();
  221. FNoteTimer = new TTimer(this);
  222. FNoteTimer->Enabled = false;
  223. FNoteTimer->OnTimer = NoteTimer;
  224. FOnNoteClick = NULL;
  225. FOle32Library = LoadLibrary(L"Ole32.dll");
  226. FDragMoveCursor = FOle32Library != NULL ?
  227. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  228. UseSystemSettings(this);
  229. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  230. static_cast<TObject*>(GetComponent(fcTransferList)));
  231. DebugAssert(TransferList != NULL);
  232. FTransferListHoverIndex = -1;
  233. TransferList->OnChange = TransferListChange;
  234. TransferList->OnDrawItem = TransferListDrawItem;
  235. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  236. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  237. UseDesktopFont(SessionsPageControl);
  238. UpdateSessionsPageControlHeight();
  239. UseDesktopFont(RemoteDirView);
  240. UseDesktopFont(RemoteDriveView);
  241. UseDesktopFont(QueueView3);
  242. UseDesktopFont(QueueFileList);
  243. UseDesktopFont(QueueLabel);
  244. UseDesktopFont(RemoteStatusBar);
  245. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  246. QueueSplitter->ShowHint = true;
  247. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  248. QueueFileListSplitter->ShowHint = true;
  249. RemotePanelSplitter->ShowHint = true;
  250. UpdateImages();
  251. FCustomCommandMenu = CreateTBXPopupMenu(this);
  252. FCustomCommandLocalFileList = NULL;
  253. FCustomCommandRemoteFileList = NULL;
  254. FSessionColors = new TPngImageList(this);
  255. FSessionColors->ColorDepth = cd32Bit;
  256. AddFixedSessionImages();
  257. SessionsPageControl->Images = FSessionColors;
  258. UpdateQueueLabel();
  259. FRemoteDirViewWasFocused = true;
  260. CreateHiddenWindow();
  261. StartUpdates();
  262. }
  263. //---------------------------------------------------------------------------
  264. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  265. {
  266. FInvalid = true;
  267. // this has to be one of the very first things to do
  268. StopUpdateThread();
  269. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  270. TTerminalManager::Instance()->ScpExplorer = NULL;
  271. delete FCustomCommandLocalFileList;
  272. delete FCustomCommandRemoteFileList;
  273. delete FCustomCommandMenu;
  274. delete FTrayIcon;
  275. FTrayIcon = NULL;
  276. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  277. delete FEditorManager;
  278. ForceCloseLocalEditors();
  279. delete FLocalEditors;
  280. HideFileFindDialog();
  281. if (FDelayedDeletionTimer)
  282. {
  283. DoDelayedDeletion(NULL);
  284. SAFE_DESTROY(FDelayedDeletionTimer);
  285. }
  286. SAFE_DESTROY(FDelayedDeletionList);
  287. // sometimes we do not get DDEnd so the list is not released
  288. SAFE_DESTROY(FDDFileList);
  289. DebugAssert(FSynchronizeController == NULL);
  290. CloseHandle(FDDExtMutex);
  291. FDDExtMutex = NULL;
  292. FreeLibrary(FOle32Library);
  293. FOle32Library = NULL;
  294. FDragMoveCursor = NULL;
  295. DebugAssert(!FErrorList);
  296. if (FEverShown)
  297. {
  298. // when window is never shown (like when running command-line operation),
  299. // particularly window site is not restored correctly (BoundsRect value set
  300. // in RestoreForm gets lost during handle allocation), so we do not want
  301. // it to be stored
  302. StoreParams();
  303. }
  304. Terminal = NULL;
  305. Queue = NULL;
  306. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  307. NonVisualDataModule->ScpExplorer = NULL;
  308. delete FQueueController;
  309. FQueueController = NULL;
  310. delete FQueueStatusSection;
  311. FQueueStatusSection = NULL;
  312. delete FQueueStatus;
  313. FQueueStatus = NULL;
  314. delete FUserActionTimer;
  315. FUserActionTimer = NULL;
  316. delete FNoteTimer;
  317. delete FNotes;
  318. delete FNoteData;
  319. SAFE_DESTROY(FDocks);
  320. SessionsPageControl->Images = NULL;
  321. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  322. SAFE_DESTROY(FSessionColors);
  323. SAFE_DESTROY(FSessionsDragDropFilesEx);
  324. SAFE_DESTROY(FHistoryMenu[0][0]);
  325. SAFE_DESTROY(FHistoryMenu[0][1]);
  326. SAFE_DESTROY(FHistoryMenu[1][0]);
  327. SAFE_DESTROY(FHistoryMenu[1][1]);
  328. if (FHiddenWindow != NULL)
  329. {
  330. DestroyWindow(FHiddenWindow);
  331. FHiddenWindow = NULL;
  332. }
  333. }
  334. //---------------------------------------------------------------------------
  335. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  336. {
  337. std::unique_ptr<TSessionData> Data;
  338. if (!Session.IsEmpty())
  339. {
  340. bool DefaultsOnly;
  341. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  342. }
  343. TTerminalManager * Manager = TTerminalManager::Instance();
  344. for (int Index = 0; Index < Manager->Count; Index++)
  345. {
  346. TTerminal * Terminal = Manager->Terminals[Index];
  347. if (Session.IsEmpty() ||
  348. Terminal->SessionData->IsSameSite(Data.get()))
  349. {
  350. if (Path.IsEmpty())
  351. {
  352. Terminal->ClearCaches();
  353. }
  354. else
  355. {
  356. Terminal->DirectoryModified(Path, true);
  357. }
  358. }
  359. }
  360. // We should flag a pending refresh for the background terminals or busy foreground terminals
  361. if (HasActiveTerminal() &&
  362. CanCommandLineFromAnotherInstance() &&
  363. (Session.IsEmpty() || Terminal->SessionData->IsSameSite(Data.get())) &&
  364. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  365. {
  366. Terminal->ReloadDirectory();
  367. }
  368. }
  369. //---------------------------------------------------------------------------
  370. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  371. {
  372. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  373. size_t MessageSize = sizeof(TCopyDataMessage);
  374. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  375. if (Result)
  376. {
  377. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  378. Result = (Message.Version == TCopyDataMessage::Version1);
  379. if (Result)
  380. {
  381. switch (Message.Command)
  382. {
  383. case TCopyDataMessage::CommandCanCommandLine:
  384. Result = CanCommandLineFromAnotherInstance();
  385. break;
  386. case TCopyDataMessage::CommandCommandLine:
  387. {
  388. UnicodeString CommandLine(Message.CommandLine);
  389. Result = CommandLineFromAnotherInstance(CommandLine);
  390. }
  391. break;
  392. case TCopyDataMessage::RefreshPanel:
  393. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  394. break;
  395. case TCopyDataMessage::MainWindowCheck:
  396. Result = true;
  397. break;
  398. default:
  399. Result = false;
  400. break;
  401. }
  402. }
  403. }
  404. Message.Result = Result ? 1 : 0;
  405. }
  406. //---------------------------------------------------------------------------
  407. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  408. {
  409. WNDCLASS WindowClass = {0};
  410. WindowClass.lpfnWndProc = DefWindowProc;
  411. WindowClass.hInstance = HInstance;
  412. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  413. FHiddenWindow = NULL;
  414. if (RegisterClass(&WindowClass))
  415. {
  416. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  417. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  418. }
  419. }
  420. //---------------------------------------------------------------------------
  421. bool __fastcall TCustomScpExplorerForm::CanConsole()
  422. {
  423. return
  424. HasActiveTerminal() &&
  425. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  426. }
  427. //---------------------------------------------------------------------------
  428. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  429. {
  430. bool Result = Visible && !NonVisualDataModule->Busy;
  431. return Result;
  432. }
  433. //---------------------------------------------------------------------------
  434. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  435. const UnicodeString & CommandLine)
  436. {
  437. TProgramParams Params(CommandLine);
  438. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  439. if (Result)
  440. {
  441. NonVisualDataModule->StartBusy();
  442. try
  443. {
  444. // this action is initiated from another process,
  445. // so it's likely that our window is not visible,
  446. // and user won't see what is going on
  447. Application->BringToFront();
  448. // reload sessions as we may be asked to open a session
  449. // just stored by another instance
  450. StoredSessions->Reload();
  451. UnicodeString SessionName = Params.Param[1];
  452. std::unique_ptr<TObjectList> DataList(new TObjectList());
  453. UnicodeString DownloadFile; // unused
  454. try
  455. {
  456. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  457. }
  458. catch (EAbort &)
  459. {
  460. // Happens when opening session in PuTTY and in other situations,
  461. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  462. // to process the command-line on its own (or to pass it to yet another instance)
  463. }
  464. if (DataList->Count > 0)
  465. {
  466. TTerminalManager * Manager = TTerminalManager::Instance();
  467. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  468. }
  469. }
  470. __finally
  471. {
  472. NonVisualDataModule->EndBusy();
  473. }
  474. }
  475. return Result;
  476. }
  477. //---------------------------------------------------------------------------
  478. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  479. {
  480. if (FTerminal != value)
  481. {
  482. TerminalChanging();
  483. DoSetTerminal(value, false);
  484. }
  485. }
  486. //---------------------------------------------------------------------------
  487. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  488. {
  489. FTerminal = value;
  490. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  491. FAllowTransferPresetAutoSelect = false;
  492. try
  493. {
  494. TerminalChanged(Replace);
  495. }
  496. __finally
  497. {
  498. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  499. }
  500. if (Terminal != NULL)
  501. {
  502. TransferPresetAutoSelect();
  503. }
  504. }
  505. //---------------------------------------------------------------------------
  506. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  507. {
  508. DoSetTerminal(value, true);
  509. }
  510. //---------------------------------------------------------------------------
  511. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  512. {
  513. if (FTerminal != NULL)
  514. {
  515. UpdateTerminal(Terminal);
  516. }
  517. }
  518. //---------------------------------------------------------------------------
  519. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  520. {
  521. if (Terminal != NULL)
  522. {
  523. UpdateSessionColor((TColor)Terminal->StateData->Color);
  524. }
  525. DoTerminalListChanged();
  526. DebugAssert(!IsLocalBrowserMode()); // TODO
  527. if (Replaced)
  528. {
  529. RemoteDirView->ReplaceTerminal(Terminal);
  530. }
  531. else
  532. {
  533. RemoteDirView->Terminal = Terminal;
  534. }
  535. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  536. if (Terminal != NULL)
  537. {
  538. if (Terminal->Active)
  539. {
  540. Terminal->RefreshDirectory();
  541. }
  542. if (WinConfiguration->PreservePanelState)
  543. {
  544. if (Terminal->RemoteExplorerState != NULL)
  545. {
  546. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  547. }
  548. else
  549. {
  550. DirView(osRemote)->ClearState();
  551. }
  552. }
  553. if (!Replaced && Terminal->Active)
  554. {
  555. InitStatusBar();
  556. }
  557. }
  558. UpdateTransferList();
  559. // Update panels Enable state before refreshing the labels
  560. UpdateControls();
  561. }
  562. //---------------------------------------------------------------------------
  563. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  564. {
  565. if (Queue != value)
  566. {
  567. if (FQueue != NULL)
  568. {
  569. FQueue->OnListUpdate = NULL;
  570. FQueue->OnQueueItemUpdate = NULL;
  571. }
  572. FQueue = value;
  573. if (FQueue != NULL)
  574. {
  575. DebugAssert(FQueue->OnListUpdate == NULL);
  576. FQueue->OnListUpdate = QueueListUpdate;
  577. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  578. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  579. }
  580. QueueChanged();
  581. }
  582. }
  583. //---------------------------------------------------------------------------
  584. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  585. TListItem * Item)
  586. {
  587. if (FQueueActedItem == Item)
  588. {
  589. FQueueActedItem = NULL;
  590. if ((QueueView3->PopupMenu != NULL) &&
  591. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  592. {
  593. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  594. ReleaseCapture();
  595. }
  596. }
  597. if (Item->Data == FPendingQueueActionItem)
  598. {
  599. FPendingQueueActionItem = NULL;
  600. }
  601. }
  602. //---------------------------------------------------------------------------
  603. bool TCustomScpExplorerForm::IsAnythingQueued()
  604. {
  605. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  606. }
  607. //---------------------------------------------------------------------------
  608. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  609. {
  610. {
  611. TGuard Guard(FQueueStatusSection);
  612. FQueueStatusInvalidated = false;
  613. if (FQueue != NULL)
  614. {
  615. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  616. }
  617. }
  618. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  619. {
  620. FMaxQueueLength = FQueueStatus->Count;
  621. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  622. }
  623. {
  624. TAutoFlag Flag(FQueueStatusUpdating);
  625. FQueueController->UpdateQueueStatus(FQueueStatus);
  626. }
  627. UpdateQueueFileList();
  628. SetQueueProgress();
  629. UpdateQueueView();
  630. bool IsEmpty = !IsAnythingQueued();
  631. if (IsEmpty && (Terminal != NULL))
  632. {
  633. TOnceDoneOperation OnceDoneOperation =
  634. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  635. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  636. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  637. {
  638. FQueue->Enabled = false;
  639. }
  640. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  641. {
  642. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  643. }
  644. }
  645. }
  646. //---------------------------------------------------------------------------
  647. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  648. {
  649. UnicodeString Result;
  650. if (FQueueStatus != NULL)
  651. {
  652. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  653. {
  654. TFileOperationProgressType * ProgressData =
  655. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  656. if ((ProgressData != NULL) && ProgressData->InProgress)
  657. {
  658. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  659. }
  660. }
  661. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  662. {
  663. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  664. }
  665. }
  666. return Result;
  667. }
  668. //---------------------------------------------------------------------------
  669. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  670. {
  671. ComponentVisible[fcQueueView] =
  672. (WinConfiguration->QueueView.Show == qvShow) ||
  673. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  674. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  675. }
  676. //---------------------------------------------------------------------------
  677. void __fastcall TCustomScpExplorerForm::QueueChanged()
  678. {
  679. if (FQueueStatus != NULL)
  680. {
  681. // UpdateFileList implementation relies on the status being recreated when session changes
  682. delete FQueueStatus;
  683. FQueueStatus = NULL;
  684. }
  685. UpdateQueueStatus(true);
  686. }
  687. //---------------------------------------------------------------------------
  688. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  689. {
  690. if (FQueue == Queue)
  691. {
  692. FQueueStatusInvalidated = true;
  693. }
  694. }
  695. //---------------------------------------------------------------------------
  696. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  697. TQueueItem * Item)
  698. {
  699. if (FQueue == Queue)
  700. {
  701. TGuard Guard(FQueueStatusSection);
  702. // this may be running in parallel with QueueChanged
  703. if (FQueueStatus != NULL)
  704. {
  705. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  706. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  707. {
  708. FRefreshLocalDirectory = (QueueItem == NULL) ||
  709. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  710. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  711. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  712. }
  713. if (QueueItem != NULL)
  714. {
  715. QueueItem->UserData = (void*)true;
  716. FQueueItemInvalidated = true;
  717. }
  718. }
  719. }
  720. }
  721. //---------------------------------------------------------------------------
  722. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  723. {
  724. // during standalone editing, we have no way to see/control queue,
  725. // so we have to always popup prompts automatically
  726. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  727. }
  728. //---------------------------------------------------------------------------
  729. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  730. {
  731. if (FQueueStatus != NULL)
  732. {
  733. bool QueueAutoPopup = IsQueueAutoPopup();
  734. bool NeedRefresh = FQueueController->NeedRefresh();
  735. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  736. FQueueItemInvalidated = false;
  737. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  738. bool Updated = false;
  739. TQueueItemProxy * QueueItem;
  740. bool WasUserAction;
  741. for (int Index = 0; Index < Limit; Index++)
  742. {
  743. bool Update = false;
  744. QueueItem = FQueueStatus->Items[Index];
  745. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  746. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  747. (FPendingQueueActionItem == NULL))
  748. {
  749. FPendingQueueActionItem = QueueItem;
  750. FUserActionTimer->Enabled = true;
  751. }
  752. if ((bool)QueueItem->UserData)
  753. {
  754. QueueItem->UserData = (void*)false;
  755. QueueItem->Update();
  756. Updated = true;
  757. Update = true;
  758. }
  759. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  760. {
  761. Update = true;
  762. }
  763. if (Update)
  764. {
  765. FQueueController->RefreshQueueItem(QueueItem);
  766. }
  767. }
  768. if (Updated)
  769. {
  770. NonVisualDataModule->UpdateNonVisibleActions();
  771. SetQueueProgress();
  772. UpdateQueueFileList();
  773. }
  774. }
  775. }
  776. //---------------------------------------------------------------------------
  777. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  778. {
  779. if (FTaskbarList != NULL)
  780. {
  781. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  782. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  783. }
  784. }
  785. //---------------------------------------------------------------------------
  786. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  787. {
  788. if (Progress >= 0)
  789. {
  790. if (FTaskbarList != NULL)
  791. {
  792. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  793. }
  794. }
  795. else
  796. {
  797. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  798. }
  799. }
  800. //---------------------------------------------------------------------------
  801. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  802. {
  803. int OverallProgress;
  804. // FProgressForm is null when this is called from SetQueueProgress
  805. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  806. {
  807. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  808. }
  809. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  810. {
  811. OverallProgress = ProgressData->OverallProgress();
  812. }
  813. else
  814. {
  815. OverallProgress = -1;
  816. }
  817. SetTaskbarListProgressValue(OverallProgress);
  818. }
  819. //---------------------------------------------------------------------------
  820. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  821. {
  822. TTerminalManager::Instance()->QueueStatusUpdated();
  823. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  824. {
  825. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  826. {
  827. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  828. {
  829. TFileOperationProgressType * ProgressData = NULL;
  830. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  831. {
  832. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  833. }
  834. if ((ProgressData != NULL) &&
  835. ProgressData->InProgress)
  836. {
  837. SetTaskbarListProgressValue(ProgressData);
  838. }
  839. else
  840. {
  841. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  842. }
  843. }
  844. else
  845. {
  846. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  847. }
  848. }
  849. else
  850. {
  851. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  852. }
  853. }
  854. UpdateQueueLabel();
  855. }
  856. //---------------------------------------------------------------------------
  857. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  858. {
  859. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  860. if (FQueueStatus != NULL)
  861. {
  862. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  863. if (ActiveAndPendingPrimaryCount > 0)
  864. {
  865. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  866. }
  867. }
  868. QueueLabel->Caption = Caption;
  869. }
  870. //---------------------------------------------------------------------------
  871. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  872. {
  873. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  874. static_cast<TComponent*>(GetComponent(fcTransferList)));
  875. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  876. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  877. TransferList->Strings->BeginUpdate();
  878. try
  879. {
  880. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  881. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  882. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  883. if (FTransferDropDownHint.IsEmpty())
  884. {
  885. FTransferDropDownHint = TransferDropDown->Hint;
  886. }
  887. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  888. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  889. TransferDropDown->Text = StripHotkey(Name);
  890. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  891. (FTransferDropDownHint, StripHotkey(Name),
  892. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  893. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  894. // update the label, otherwise when it is updated only on the first draw
  895. // of the list, it is drawn "bold" for some reason
  896. FTransferListHoverIndex = TransferList->ItemIndex;
  897. UpdateTransferLabel();
  898. }
  899. __finally
  900. {
  901. TransferList->Strings->EndUpdate();
  902. }
  903. }
  904. //---------------------------------------------------------------------------
  905. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  906. {
  907. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  908. DebugAssert(Toolbar != NULL);
  909. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  910. }
  911. //---------------------------------------------------------------------------
  912. void __fastcall TCustomScpExplorerForm::UpdateActions()
  913. {
  914. TForm::UpdateActions();
  915. if (ComponentVisible[fcCustomCommandsBand])
  916. {
  917. UpdateCustomCommandsToolbar();
  918. }
  919. }
  920. //---------------------------------------------------------------------------
  921. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  922. {
  923. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  924. }
  925. //---------------------------------------------------------------------------
  926. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  927. {
  928. Color = GetBtnFaceColor();
  929. DebugAssert(Configuration && RemoteDirView);
  930. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  931. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  932. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  933. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  934. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  935. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  936. if (RemoteDirView->RowSelect != WinConfiguration->FullRowSelect)
  937. {
  938. RemoteDirView->RowSelect = WinConfiguration->FullRowSelect;
  939. // selection is not redrawn automatically when RowSelect changes
  940. RemoteDirView->Invalidate();
  941. }
  942. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  943. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  944. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  945. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  946. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  947. UpdateSessionsPageControlHeight();
  948. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  949. UpdateToolbarDisplayMode();
  950. UpdateTransferList();
  951. if (Terminal != NULL)
  952. {
  953. TransferPresetAutoSelect();
  954. }
  955. UpdateQueueView();
  956. UpdateControls();
  957. // this can be called even before constuctor finishes.
  958. if (FEditorManager != NULL)
  959. {
  960. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  961. }
  962. // this can be called even before constuctor finishes.
  963. if (FLocalEditors != NULL)
  964. {
  965. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  966. {
  967. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  968. }
  969. }
  970. if (ComponentVisible[fcCustomCommandsBand])
  971. {
  972. UpdateCustomCommandsToolbar();
  973. }
  974. // show only when keeping queue items forever,
  975. // otherwise, its enough to have in in the context menu
  976. QueueDeleteAllDoneQueueToolbarItem->Visible =
  977. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  978. if (FFileColorsCurrent != WinConfiguration->FileColors)
  979. {
  980. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  981. FFileColorsCurrent = WinConfiguration->FileColors;
  982. FileColorsChanged();
  983. }
  984. }
  985. //---------------------------------------------------------------------------
  986. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  987. {
  988. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  989. DirView->Invalidate();
  990. }
  991. //---------------------------------------------------------------------------
  992. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  993. {
  994. DoFileColorsChanged(RemoteDirView);
  995. }
  996. //---------------------------------------------------------------------------
  997. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  998. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  999. void * /*Arg*/)
  1000. {
  1001. if (Token != NULL)
  1002. {
  1003. TForm * Editor = dynamic_cast<TForm*>(Token);
  1004. DebugAssert(Editor != NULL);
  1005. ReconfigureEditorForm(Editor);
  1006. }
  1007. }
  1008. //---------------------------------------------------------------------------
  1009. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1010. {
  1011. WinConfiguration->DDTransferConfirmation = asOn;
  1012. }
  1013. //---------------------------------------------------------------------------
  1014. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1015. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1016. {
  1017. // noop
  1018. }
  1019. //---------------------------------------------------------------------------
  1020. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1021. TTransferDirection Direction, TTransferType Type, bool Temp,
  1022. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1023. bool Confirm, bool DragDrop, int Options)
  1024. {
  1025. bool Result = true;
  1026. DebugAssert(HasActiveTerminal());
  1027. // these parameters are known in advance
  1028. int Params =
  1029. FLAGMASK(Type == ttMove, cpDelete);
  1030. bool ToTemp = (Temp && (Direction == tdToLocal));
  1031. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1032. {
  1033. bool DisableNewerOnly =
  1034. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1035. ToTemp;
  1036. Options |=
  1037. FLAGMASK(ToTemp, coTemp) |
  1038. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1039. coDoNotShowAgain;
  1040. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1041. int CopyParamAttrs = (Direction == tdToRemote ?
  1042. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1043. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1044. int OutputOptions =
  1045. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1046. cooDoNotShowAgain);
  1047. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1048. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1049. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1050. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1051. if (Result)
  1052. {
  1053. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1054. {
  1055. if (DragDrop)
  1056. {
  1057. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1058. {
  1059. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1060. NULL, 0, EnableDDTransferConfirmation, NULL);
  1061. }
  1062. WinConfiguration->DDTransferConfirmation = asOff;
  1063. }
  1064. else
  1065. {
  1066. WinConfiguration->ConfirmTransferring = false;
  1067. }
  1068. }
  1069. else
  1070. {
  1071. // User explicitly unchecked "do not show again",
  1072. // so show him the dialog the next time
  1073. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1074. {
  1075. WinConfiguration->DDTransferConfirmation = asOn;
  1076. }
  1077. }
  1078. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1079. }
  1080. }
  1081. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1082. {
  1083. Configuration->Usage->Inc(L"TransfersOnBackground");
  1084. // these parameter are known only after transfer dialog
  1085. Params |=
  1086. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1087. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1088. Result = false;
  1089. ClearTransferSourceSelection(Direction);
  1090. }
  1091. return Result;
  1092. }
  1093. //---------------------------------------------------------------------------
  1094. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1095. {
  1096. if (FOnFileOperationFinished != NULL)
  1097. {
  1098. FOnFileOperationFinished(UnicodeString(), true);
  1099. }
  1100. else
  1101. {
  1102. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1103. if (HasDirView[Side])
  1104. {
  1105. DirView(Side)->SelectAll(smNone);
  1106. }
  1107. }
  1108. }
  1109. //---------------------------------------------------------------------------
  1110. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1111. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1112. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1113. int Params)
  1114. {
  1115. DebugAssert(Queue != NULL);
  1116. bool SingleFile = false;
  1117. if (FileList->Count == 1)
  1118. {
  1119. if (Direction == tdToRemote)
  1120. {
  1121. UnicodeString FileName = FileList->Strings[0];
  1122. SingleFile = FileExists(ApiPath(FileName));
  1123. }
  1124. else
  1125. {
  1126. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1127. SingleFile = !File->IsDirectory;
  1128. }
  1129. }
  1130. TQueueItem * QueueItem;
  1131. if (Direction == tdToRemote)
  1132. {
  1133. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1134. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1135. }
  1136. else
  1137. {
  1138. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1139. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1140. }
  1141. AddQueueItem(Queue, QueueItem, Terminal);
  1142. }
  1143. //---------------------------------------------------------------------------
  1144. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1145. {
  1146. if (Queue->IsEmpty)
  1147. {
  1148. Terminal->QueueOperationStart = Now();
  1149. }
  1150. Queue->AddItem(QueueItem);
  1151. }
  1152. //---------------------------------------------------------------------------
  1153. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1154. {
  1155. }
  1156. //---------------------------------------------------------------------------
  1157. void __fastcall TCustomScpExplorerForm::InitControls()
  1158. {
  1159. DebugAssert(FDocks != NULL);
  1160. for (int Index = 0; Index < ComponentCount; Index++)
  1161. {
  1162. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1163. if ((Dock != NULL) && (Dock->Tag == 0))
  1164. {
  1165. FDocks->Add(Dock);
  1166. }
  1167. }
  1168. CollectItemsWithTextDisplayMode(this);
  1169. }
  1170. //---------------------------------------------------------------------------
  1171. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1172. {
  1173. ConfigurationChanged();
  1174. QueuePanel->Height =
  1175. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1176. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1177. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1178. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1179. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1180. QueueFileList->Height =
  1181. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1182. if (QueueFileList->Visible)
  1183. {
  1184. AdjustQueueLayout();
  1185. }
  1186. UpdateCustomCommandsToolbar();
  1187. }
  1188. //---------------------------------------------------------------------------
  1189. void __fastcall TCustomScpExplorerForm::StoreParams()
  1190. {
  1191. int APixelsPerInch = GetControlPixelsPerInch(this);
  1192. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1193. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1194. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1195. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1196. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1197. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1198. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1199. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1200. }
  1201. //---------------------------------------------------------------------------
  1202. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1203. {
  1204. if (!FFormRestored)
  1205. {
  1206. FFormRestored = true;
  1207. RestoreFormParams();
  1208. }
  1209. TForm::CreateParams(Params);
  1210. }
  1211. //---------------------------------------------------------------------------
  1212. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1213. {
  1214. DebugAssert(FDocks != NULL);
  1215. for (int Index = 0; Index < FDocks->Count; Index++)
  1216. {
  1217. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1218. }
  1219. }
  1220. //---------------------------------------------------------------------------
  1221. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1222. {
  1223. SetDockAllowDrag(true);
  1224. while (!ButtonsStr.IsEmpty())
  1225. {
  1226. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1227. UnicodeString Name = CutToChar(S, L'=', true);
  1228. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1229. {
  1230. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1231. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1232. {
  1233. while (!S.IsEmpty())
  1234. {
  1235. UnicodeString S2 = CutToChar(S, L',', true);
  1236. UnicodeString Name = CutToChar(S2, L':', true);
  1237. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1238. {
  1239. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1240. if (SameText(GetToolbarItemName(Item), Name))
  1241. {
  1242. // forward compatibility
  1243. UnicodeString S3 = CutToChar(S2, L':', true);
  1244. bool Visible = StrToIntDef(S3, 0);
  1245. Item->Visible = Visible;
  1246. }
  1247. }
  1248. }
  1249. }
  1250. }
  1251. }
  1252. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1253. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1254. }
  1255. //---------------------------------------------------------------------------
  1256. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1257. {
  1258. UnicodeString Result;
  1259. SetDockAllowDrag(true);
  1260. Result = ::GetToolbarsLayoutStr(this);
  1261. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1262. return Result;
  1263. }
  1264. //---------------------------------------------------------------------------
  1265. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1266. {
  1267. UnicodeString Result;
  1268. if (Item->Action != NULL)
  1269. {
  1270. Result = Item->Action->Name;
  1271. Result = RemoveSuffix(Result, L"Action", true);
  1272. }
  1273. else
  1274. {
  1275. Result = Item->Name;
  1276. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1277. Result = RemoveSuffix(Result, L"Item", true);
  1278. }
  1279. return Result;
  1280. }
  1281. //---------------------------------------------------------------------------
  1282. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1283. {
  1284. UnicodeString Result;
  1285. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1286. {
  1287. UnicodeString ToolbarStr;
  1288. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1289. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1290. {
  1291. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1292. {
  1293. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1294. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1295. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1296. // and save the changes here only.
  1297. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1298. {
  1299. UnicodeString Name = GetToolbarItemName(Item);
  1300. DebugAssert(Name.Pos(L"TBX") == 0);
  1301. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1302. }
  1303. }
  1304. }
  1305. if (!ToolbarStr.IsEmpty())
  1306. {
  1307. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1308. }
  1309. }
  1310. return Result;
  1311. }
  1312. //---------------------------------------------------------------------------
  1313. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1314. {
  1315. DebugAssert(FProgressForm == NULL);
  1316. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1317. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1318. FProgressForm->DeleteLocalToRecycleBin =
  1319. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1320. FProgressForm->DeleteRemoteToRecycleBin =
  1321. (Terminal != NULL) &&
  1322. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1323. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1324. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1325. LockWindow();
  1326. // Actually, do not know what hides the progress once the operation finishes
  1327. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1328. SetTaskbarListProgressState(TBPF_NORMAL);
  1329. }
  1330. //---------------------------------------------------------------------------
  1331. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1332. {
  1333. UnlockWindow();
  1334. SAFE_DESTROY(FProgressForm);
  1335. SetQueueProgress();
  1336. }
  1337. //---------------------------------------------------------------------------
  1338. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1339. TFileOperationProgressType & ProgressData)
  1340. {
  1341. // Download to temporary local directory
  1342. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1343. {
  1344. bool Continue = true;
  1345. FPendingTempSpaceWarn = false;
  1346. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1347. if (!Continue)
  1348. {
  1349. Abort();
  1350. }
  1351. }
  1352. // operation is being executed and we still didn't show up progress form
  1353. if (ProgressData.InProgress && !FProgressForm)
  1354. {
  1355. CreateProgressForm(NULL);
  1356. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1357. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1358. }
  1359. // operation is finished (or terminated), so we hide progress form
  1360. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1361. {
  1362. DestroyProgressForm();
  1363. if (ProgressData.Operation == foCalculateSize)
  1364. {
  1365. // When calculating size before transfer, the abort caused by
  1366. // cancel flag set due to "MoveToQueue" below,
  1367. // is not propagated back to us in ExecuteFileOperation,
  1368. // as it is silently swallowed.
  1369. // So we explicitly (re)throw it here.
  1370. if (FMoveToQueue)
  1371. {
  1372. Abort();
  1373. }
  1374. }
  1375. else
  1376. {
  1377. if ((ProgressData.Cancel == csContinue) &&
  1378. !FAutoOperation)
  1379. {
  1380. OperationComplete(ProgressData.StartTime);
  1381. }
  1382. }
  1383. }
  1384. if (FProgressForm &&
  1385. // Can happen only during synchronization, when ending one of the operations
  1386. ProgressData.InProgress)
  1387. {
  1388. FProgressForm->SetProgressData(ProgressData);
  1389. DebugAssert(ProgressData.InProgress);
  1390. SetTaskbarListProgressValue(&ProgressData);
  1391. if (FProgressForm->Cancel > csContinue)
  1392. {
  1393. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1394. if (FProgressForm->Cancel == csCancelFile)
  1395. {
  1396. FProgressForm->ClearCancel();
  1397. }
  1398. // cancel cancels even the move
  1399. FMoveToQueue = false;
  1400. }
  1401. else if (FProgressForm->MoveToQueue)
  1402. {
  1403. FMoveToQueue = true;
  1404. ProgressData.SetCancelAtLeast(csCancel);
  1405. }
  1406. if ((FTransferResumeList != NULL) &&
  1407. ProgressData.InProgress &&
  1408. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1409. !ProgressData.FullFileName.IsEmpty())
  1410. {
  1411. if ((FTransferResumeList->Count == 0) ||
  1412. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1413. {
  1414. // note that we do not recognize directories from files here
  1415. FTransferResumeList->Add(ProgressData.FullFileName);
  1416. }
  1417. }
  1418. }
  1419. }
  1420. //---------------------------------------------------------------------------
  1421. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1422. const TDateTime & StartTime)
  1423. {
  1424. if (GUIConfiguration->BeepOnFinish &&
  1425. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1426. {
  1427. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1428. DWORD Sound;
  1429. if (!ExtractFileExt(BeepSound).IsEmpty())
  1430. {
  1431. Sound = SND_FILENAME;
  1432. }
  1433. else
  1434. {
  1435. Sound = SND_ALIAS;
  1436. }
  1437. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1438. }
  1439. }
  1440. //---------------------------------------------------------------------------
  1441. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1442. TFileOperationProgressType & ProgressData)
  1443. {
  1444. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1445. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1446. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1447. FileOperationProgress(ProgressData);
  1448. }
  1449. //---------------------------------------------------------------------------
  1450. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1451. {
  1452. UnicodeString Result;
  1453. if (FProgressForm != NULL)
  1454. {
  1455. Result = FProgressForm->ProgressStr();
  1456. }
  1457. return Result;
  1458. }
  1459. //---------------------------------------------------------------------------
  1460. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1461. bool DragDrop)
  1462. {
  1463. return (!DragDrop && (DropSourceControl == NULL)) ||
  1464. (DropSourceControl == DirView(osOther));
  1465. }
  1466. //---------------------------------------------------------------------------
  1467. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1468. TFileOperation Operation, TOperationSide Side,
  1469. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1470. TOnceDoneOperation & OnceDoneOperation)
  1471. {
  1472. if (!FAutoOperation)
  1473. {
  1474. // no selection on "/upload", form servers only as event handler
  1475. // (it is not displayed)
  1476. if (PanelOperation(Side, FDragDropOperation) &&
  1477. Visible && (Operation != foCalculateSize) &&
  1478. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1479. {
  1480. if (FOnFileOperationFinished != NULL)
  1481. {
  1482. FOnFileOperationFinished(FileName, Success);
  1483. }
  1484. else
  1485. {
  1486. TCustomDirView * DView = DirView(Side);
  1487. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(Side));
  1488. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1489. // this can happen when local drive is unplugged in the middle of the operation
  1490. if (Item != NULL)
  1491. {
  1492. if (Success) Item->Selected = false;
  1493. DView->MakeProgressVisible(Item);
  1494. }
  1495. }
  1496. }
  1497. if ((Operation == foCopy) || (Operation == foMove))
  1498. {
  1499. DebugAssert(!IsLocalBrowserMode()); // TODO
  1500. if (Side == osLocal)
  1501. {
  1502. Configuration->Usage->Inc(L"UploadedFiles");
  1503. }
  1504. else
  1505. {
  1506. Configuration->Usage->Inc(L"DownloadedFiles");
  1507. }
  1508. }
  1509. }
  1510. if (Success && (FSynchronizeController != NULL))
  1511. {
  1512. DebugAssert(!IsSideLocalBrowser(osRemote));
  1513. if (Operation == foCopy)
  1514. {
  1515. DebugAssert(Side == osLocal);
  1516. FSynchronizeController->LogOperation(soUpload, FileName);
  1517. }
  1518. else if (Operation == foDelete)
  1519. {
  1520. DebugAssert(Side == osRemote);
  1521. FSynchronizeController->LogOperation(soDelete, FileName);
  1522. }
  1523. }
  1524. if (FProgressForm)
  1525. {
  1526. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1527. }
  1528. }
  1529. //---------------------------------------------------------------------------
  1530. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1531. TFileOperation Operation, TOperationSide Side,
  1532. bool Temp, const UnicodeString & FileName, Boolean Success,
  1533. TOnceDoneOperation & OnceDoneOperation)
  1534. {
  1535. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1536. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1537. OnceDoneOperation);
  1538. }
  1539. //---------------------------------------------------------------------------
  1540. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1541. {
  1542. return false;
  1543. }
  1544. //---------------------------------------------------------------------------
  1545. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1546. {
  1547. return false;
  1548. }
  1549. //---------------------------------------------------------------------------
  1550. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1551. {
  1552. return NULL;
  1553. }
  1554. //---------------------------------------------------------------------------
  1555. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1556. {
  1557. DebugAssert(GetSide(Side) == osRemote);
  1558. DebugUsedParam(Side);
  1559. return RemoteDirView;
  1560. }
  1561. //---------------------------------------------------------------------------
  1562. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1563. {
  1564. DebugAssert(GetSide(Side) == osRemote);
  1565. DebugUsedParam(Side);
  1566. return RemoteDriveView;
  1567. }
  1568. //---------------------------------------------------------------------------
  1569. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1570. {
  1571. DebugAssert(GetSide(Side) == osRemote);
  1572. DebugUsedParam(Side);
  1573. return HasActiveTerminal();
  1574. }
  1575. //---------------------------------------------------------------------------
  1576. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1577. TOperationSide Side, int FilesOnly)
  1578. {
  1579. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1580. }
  1581. //---------------------------------------------------------------------------
  1582. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1583. TOperationSide Side, int FilesOnly)
  1584. {
  1585. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1586. }
  1587. //---------------------------------------------------------------------------
  1588. struct THistoryItemData
  1589. {
  1590. short int Side;
  1591. short int Index;
  1592. };
  1593. //---------------------------------------------------------------------------
  1594. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1595. {
  1596. DirView(Side)->HistoryGo(Index);
  1597. }
  1598. //---------------------------------------------------------------------------
  1599. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1600. {
  1601. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1602. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1603. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1604. }
  1605. //---------------------------------------------------------------------------
  1606. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1607. bool Back)
  1608. {
  1609. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1610. {
  1611. TCustomDirView * DView = DirView(Side);
  1612. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1613. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1614. if (ICount > 10)
  1615. {
  1616. ICount = 10;
  1617. }
  1618. Menu->Items->Clear();
  1619. THistoryItemData Data;
  1620. Data.Side = Side;
  1621. for (short int i = 1; i <= ICount; i++)
  1622. {
  1623. TTBCustomItem * Item = new TTBXItem(Menu);
  1624. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1625. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1626. Item->Hint = DView->HistoryPath[Data.Index];
  1627. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1628. Item->Tag = *reinterpret_cast<int*>(&Data);
  1629. Item->OnClick = HistoryItemClick;
  1630. Menu->Items->Add(Item);
  1631. }
  1632. }
  1633. }
  1634. //---------------------------------------------------------------------------
  1635. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1636. TOperationSide Side, bool Back)
  1637. {
  1638. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1639. {
  1640. // workaround
  1641. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1642. // operator new allocates memory in Pascal code, but calls inline
  1643. // contructor in C++, leading in problems, the function does
  1644. // both in Pascal code
  1645. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1646. UpdateHistoryMenu(Side, Back);
  1647. }
  1648. return FHistoryMenu[Side == osLocal][Back];
  1649. }
  1650. //---------------------------------------------------------------------------
  1651. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1652. TCustomDirView *Sender)
  1653. {
  1654. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1655. UpdateHistoryMenu(Side, true);
  1656. UpdateHistoryMenu(Side, false);
  1657. }
  1658. //---------------------------------------------------------------------------
  1659. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1660. {
  1661. // remote custom commands can be executed only if the server supports shell commands
  1662. // or have secondary shell
  1663. return HasActiveTerminal() && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1664. }
  1665. //---------------------------------------------------------------------------
  1666. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1667. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1668. {
  1669. int Result;
  1670. TFileCustomCommand RemoteCustomCommand;
  1671. TLocalCustomCommand LocalCustomCommand;
  1672. TFileCustomCommand * NonInteractiveCustomCommand =
  1673. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1674. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1675. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1676. if (FLAGCLEAR(Command.Params, ccLocal))
  1677. {
  1678. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1679. // custom command that does not operate with files can be executed anytime ...
  1680. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1681. {
  1682. // ... but do not show such command in remote file menu
  1683. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1684. {
  1685. Result = AllowedState;
  1686. }
  1687. else
  1688. {
  1689. Result = -1;
  1690. }
  1691. }
  1692. else
  1693. {
  1694. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1695. {
  1696. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1697. }
  1698. else
  1699. {
  1700. Result = -1;
  1701. }
  1702. }
  1703. }
  1704. else
  1705. {
  1706. // custom command that does not operate with files can be executed anytime
  1707. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1708. {
  1709. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1710. }
  1711. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1712. {
  1713. if ((ListType == ccltAll) || (ListType == ccltFile))
  1714. {
  1715. // special case is "diff"-style command that can be executed over any side,
  1716. // if we have both sides
  1717. Result =
  1718. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1719. // directly (instead of EnableSelectedOperation) to pass
  1720. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1721. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1722. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1723. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1724. }
  1725. else if (ListType == ccltBoth)
  1726. {
  1727. DebugAssert(!IsLocalBrowserMode());
  1728. Result = 1;
  1729. }
  1730. else
  1731. {
  1732. Result = -1;
  1733. }
  1734. }
  1735. else
  1736. {
  1737. if ((ListType == ccltAll) ||
  1738. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1739. {
  1740. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1741. }
  1742. else
  1743. {
  1744. Result = -1;
  1745. }
  1746. }
  1747. }
  1748. return Result;
  1749. }
  1750. //---------------------------------------------------------------------------
  1751. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1752. TStrings * FileList, const TCustomCommandType & ACommand,
  1753. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1754. {
  1755. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1756. {
  1757. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1758. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1759. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1760. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1761. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1762. bool Capture =
  1763. FLAGSET(ACommand.Params, ccShowResults) ||
  1764. FLAGSET(ACommand.Params, ccCopyResults) ||
  1765. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1766. TCaptureOutputEvent OutputEvent = NULL;
  1767. DebugAssert(FCapturedLog == NULL);
  1768. if (Capture)
  1769. {
  1770. FCapturedLog = new TStringList();
  1771. OutputEvent = TerminalCaptureLog;
  1772. }
  1773. try
  1774. {
  1775. if (!RemoteCustomCommand.IsFileCommand(Command))
  1776. {
  1777. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1778. OutputEvent);
  1779. }
  1780. else
  1781. {
  1782. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1783. }
  1784. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1785. {
  1786. if (FLAGSET(ACommand.Params, ccCopyResults))
  1787. {
  1788. CopyToClipboard(FCapturedLog);
  1789. }
  1790. if (FLAGSET(ACommand.Params, ccShowResults))
  1791. {
  1792. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1793. }
  1794. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1795. {
  1796. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1797. }
  1798. }
  1799. }
  1800. __finally
  1801. {
  1802. SAFE_DESTROY(FCapturedLog);
  1803. }
  1804. }
  1805. }
  1806. //---------------------------------------------------------------------------
  1807. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1808. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1809. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1810. {
  1811. DebugAssert(!IsLocalBrowserMode());
  1812. TStrings * LocalFileList = NULL;
  1813. TStrings * RemoteFileList = NULL;
  1814. TStrings * RemoteFileListFull = NULL;
  1815. try
  1816. {
  1817. if (LocalFileCommand)
  1818. {
  1819. if (ALocalFileList == NULL)
  1820. {
  1821. DebugAssert(HasDirView[osLocal]);
  1822. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1823. // directly (instead of EnableSelectedOperation) to pass
  1824. // false to FocusedFileOnlyWhenFocused
  1825. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1826. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1827. }
  1828. else
  1829. {
  1830. LocalFileList = ALocalFileList;
  1831. }
  1832. if (FileListCommand)
  1833. {
  1834. if (LocalFileList->Count != 1)
  1835. {
  1836. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1837. }
  1838. }
  1839. else
  1840. {
  1841. if ((LocalFileList->Count != 1) &&
  1842. (FileList->Count != 1) &&
  1843. (LocalFileList->Count != FileList->Count))
  1844. {
  1845. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1846. }
  1847. }
  1848. }
  1849. UnicodeString RootTempDir;
  1850. UnicodeString TempDir;
  1851. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1852. if (!RemoteFiles)
  1853. {
  1854. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1855. }
  1856. try
  1857. {
  1858. TDateTimes RemoteFileTimes;
  1859. if (RemoteFiles)
  1860. {
  1861. RemoteFileList = FileList;
  1862. }
  1863. else
  1864. {
  1865. RemoteFileList = new TStringList();
  1866. TMakeLocalFileListParams MakeFileListParam;
  1867. MakeFileListParam.FileList = RemoteFileList;
  1868. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1869. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1870. MakeFileListParam.Recursive =
  1871. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1872. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1873. if (!MakeFileListParam.Recursive)
  1874. {
  1875. RemoteFileTimes.clear();
  1876. RemoteFileListFull = new TStringList();
  1877. MakeFileListParam.FileList = RemoteFileListFull;
  1878. MakeFileListParam.Recursive = true;
  1879. MakeFileListParam.IncludeDirs = false;
  1880. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1881. }
  1882. else
  1883. {
  1884. RemoteFileListFull = RemoteFileList;
  1885. }
  1886. }
  1887. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1888. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1889. if (!NonBlocking)
  1890. {
  1891. int Count;
  1892. if (FileListCommand)
  1893. {
  1894. Count = 1;
  1895. }
  1896. else if (LocalFileCommand)
  1897. {
  1898. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1899. }
  1900. else
  1901. {
  1902. Count = RemoteFileList->Count;
  1903. }
  1904. Progress.Start(foCustomCommand, osRemote, Count);
  1905. DebugAssert(FProgressForm != NULL);
  1906. FProgressForm->ReadOnly = true;
  1907. }
  1908. try
  1909. {
  1910. if (FileListCommand)
  1911. {
  1912. UnicodeString LocalFile;
  1913. // MakeFileList does not delimit filenames
  1914. UnicodeString FileList = MakeFileList(RemoteFileList);
  1915. if (LocalFileCommand)
  1916. {
  1917. DebugAssert(LocalFileList->Count == 1);
  1918. LocalFile = LocalFileList->Strings[0];
  1919. }
  1920. TLocalCustomCommand CustomCommand(Data,
  1921. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1922. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1923. if (NonBlocking)
  1924. {
  1925. DebugAssert(!POutput);
  1926. ExecuteShellChecked(ShellCommand);
  1927. }
  1928. else
  1929. {
  1930. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1931. }
  1932. }
  1933. else if (LocalFileCommand)
  1934. {
  1935. if (LocalFileList->Count == 1)
  1936. {
  1937. UnicodeString LocalFile = LocalFileList->Strings[0];
  1938. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1939. {
  1940. UnicodeString FileName = RemoteFileList->Strings[Index];
  1941. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1942. Progress.SetFile(FileNameForProgress);
  1943. TLocalCustomCommand CustomCommand(Data,
  1944. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1945. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1946. TOnceDoneOperation OnceDoneOperation;
  1947. // Do not unselect anything, as it won't work with two panels anyway
  1948. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1949. }
  1950. }
  1951. else if (RemoteFileList->Count == 1)
  1952. {
  1953. UnicodeString FileName = RemoteFileList->Strings[0];
  1954. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1955. {
  1956. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1957. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1958. Progress.SetFile(LocalFileNameOnly);
  1959. TLocalCustomCommand CustomCommand(
  1960. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1961. FileName, LocalFileName, L"");
  1962. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1963. TOnceDoneOperation OnceDoneOperation;
  1964. // Do not unselect anything, as it won't work with two panels anyway
  1965. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1966. }
  1967. }
  1968. else
  1969. {
  1970. if (LocalFileList->Count != RemoteFileList->Count)
  1971. {
  1972. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1973. }
  1974. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1975. {
  1976. UnicodeString FileName = RemoteFileList->Strings[Index];
  1977. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1978. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1979. Progress.SetFile(LocalFileNameOnly); // sic
  1980. TLocalCustomCommand CustomCommand(
  1981. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1982. FileName, LocalFileName, L"");
  1983. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1984. TOnceDoneOperation OnceDoneOperation;
  1985. // Do not unselect anything, as it won't work with two panels anyway
  1986. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1987. }
  1988. }
  1989. }
  1990. else
  1991. {
  1992. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1993. {
  1994. UnicodeString FileName = RemoteFileList->Strings[Index];
  1995. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1996. Progress.SetFile(FileNameForProgress);
  1997. TLocalCustomCommand CustomCommand(Data,
  1998. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1999. FileName, L"", L"");
  2000. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2001. TOnceDoneOperation OnceDoneOperation;
  2002. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2003. }
  2004. }
  2005. }
  2006. __finally
  2007. {
  2008. if (!NonBlocking)
  2009. {
  2010. Progress.Stop();
  2011. }
  2012. }
  2013. DebugAssert(!FAutoOperation);
  2014. if (!RemoteFiles)
  2015. {
  2016. TempDir = IncludeTrailingBackslash(TempDir);
  2017. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2018. {
  2019. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2020. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2021. // Skip directories, process only nested files.
  2022. // The check is redundant as FileAge fails for directories anyway.
  2023. !DirectoryExists(FileName))
  2024. {
  2025. UnicodeString RemoteDir =
  2026. UnixExtractFileDir(
  2027. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2028. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2029. TDateTime NewTime;
  2030. if (FileAge(FileName, NewTime) &&
  2031. (NewTime != RemoteFileTimes[Index]))
  2032. {
  2033. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2034. TemporaryFileCopyParam(CopyParam);
  2035. CopyParam.FileMask = L"";
  2036. FAutoOperation = true;
  2037. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2038. TemporaryFilesList->Add(FileName);
  2039. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2040. }
  2041. }
  2042. }
  2043. }
  2044. }
  2045. __finally
  2046. {
  2047. FAutoOperation = false;
  2048. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2049. {
  2050. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2051. }
  2052. }
  2053. }
  2054. __finally
  2055. {
  2056. if (RemoteFileList != FileList)
  2057. {
  2058. delete RemoteFileList;
  2059. }
  2060. if (LocalFileList != ALocalFileList)
  2061. {
  2062. delete LocalFileList;
  2063. }
  2064. if (RemoteFileListFull != RemoteFileList)
  2065. {
  2066. delete RemoteFileListFull;
  2067. }
  2068. }
  2069. }
  2070. //---------------------------------------------------------------------------
  2071. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2072. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2073. bool FileListCommand, UnicodeString * POutput)
  2074. {
  2075. std::unique_ptr<TStrings> SelectedFileList(DirView(osLocal)->CreateFileList(false, true, NULL));
  2076. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2077. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2078. {
  2079. UnicodeString FileName = SelectedFileList->Strings[Index];
  2080. if (DirectoryExists(FileName))
  2081. {
  2082. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2083. {
  2084. LocalFileList->Add(FileName);
  2085. }
  2086. if (FLAGSET(ACommand.Params, ccRecursive))
  2087. {
  2088. TMakeLocalFileListParams MakeFileListParam;
  2089. MakeFileListParam.FileList = LocalFileList.get();
  2090. MakeFileListParam.FileTimes = NULL;
  2091. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2092. MakeFileListParam.Recursive = true;
  2093. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2094. }
  2095. }
  2096. else
  2097. {
  2098. LocalFileList->Add(FileName);
  2099. }
  2100. }
  2101. UnicodeString RemotePath;
  2102. if (Terminal != NULL)
  2103. {
  2104. RemotePath = Terminal->CurrentDirectory;
  2105. }
  2106. if (FileListCommand)
  2107. {
  2108. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2109. TLocalCustomCommand CustomCommand(
  2110. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2111. L"", L"", FileList);
  2112. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2113. }
  2114. else
  2115. {
  2116. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2117. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2118. DebugAssert(FProgressForm != NULL);
  2119. FProgressForm->ReadOnly = true;
  2120. try
  2121. {
  2122. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2123. {
  2124. UnicodeString FileName = LocalFileList->Strings[Index];
  2125. Progress.SetFile(FileName);
  2126. TLocalCustomCommand CustomCommand(
  2127. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2128. FileName, L"", L"");
  2129. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2130. TOnceDoneOperation OnceDoneOperation;
  2131. Progress.Finish(FileName, true, OnceDoneOperation);
  2132. }
  2133. }
  2134. __finally
  2135. {
  2136. Progress.Stop();
  2137. }
  2138. }
  2139. }
  2140. //---------------------------------------------------------------------------
  2141. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2142. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2143. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2144. {
  2145. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2146. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2147. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2148. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2149. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2150. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2151. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2152. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2153. std::unique_ptr<UnicodeString> POutput;
  2154. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2155. FLAGSET(ACommand.Params, ccCopyResults))
  2156. {
  2157. POutput.reset(new UnicodeString());
  2158. }
  2159. if (!LocalCustomCommand.IsFileCommand(Command))
  2160. {
  2161. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2162. }
  2163. // remote files?
  2164. else if ((FCurrentSide == osRemote) || LocalFileCommand)
  2165. {
  2166. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2167. }
  2168. // local files
  2169. else
  2170. {
  2171. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2172. }
  2173. if (POutput.get() != NULL)
  2174. {
  2175. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2176. int P = POutput->Pos(sLineBreak);
  2177. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2178. {
  2179. POutput->SetLength(P - 1);
  2180. }
  2181. // Copy even empty output to clipboard
  2182. if (FLAGSET(ACommand.Params, ccCopyResults))
  2183. {
  2184. CopyToClipboard(*POutput);
  2185. }
  2186. // But do not show an empty message box.
  2187. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2188. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2189. !POutput->IsEmpty())
  2190. {
  2191. TClipboardHandler ClipboardHandler;
  2192. ClipboardHandler.Text = *POutput;
  2193. TMessageParams Params;
  2194. TQueryButtonAlias Aliases[1];
  2195. Aliases[0].Button = qaRetry;
  2196. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2197. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2198. Params.Aliases = Aliases;
  2199. Params.AliasesCount = LENOF(Aliases);
  2200. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2201. }
  2202. }
  2203. }
  2204. //---------------------------------------------------------------------------
  2205. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2206. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2207. {
  2208. TCustomCommandData Data;
  2209. UnicodeString Site;
  2210. UnicodeString RemotePath;
  2211. if (Terminal != NULL)
  2212. {
  2213. Data = TCustomCommandData(Terminal);
  2214. Site = Terminal->SessionData->SessionKey;
  2215. RemotePath = Terminal->CurrentDirectory;
  2216. }
  2217. UnicodeString HelpKeyword = ACommand.HomePage;
  2218. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2219. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2220. {
  2221. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2222. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2223. {
  2224. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2225. }
  2226. else
  2227. {
  2228. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2229. }
  2230. if (!DoCustomCommandOptionsDialog(
  2231. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2232. {
  2233. Abort();
  2234. }
  2235. }
  2236. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2237. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2238. {
  2239. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2240. }
  2241. else
  2242. {
  2243. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2244. }
  2245. }
  2246. //---------------------------------------------------------------------------
  2247. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2248. const TCustomCommandType & Command)
  2249. {
  2250. DebugAssert(FCustomCommandLocalFileList != NULL);
  2251. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2252. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2253. TStrings * LocalFileList = new TStringList();
  2254. TStrings * RemoteFileList = new TStringList();
  2255. try
  2256. {
  2257. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2258. {
  2259. LocalFileList->Clear();
  2260. LocalFileList->AddObject(
  2261. FCustomCommandLocalFileList->Strings[Index],
  2262. FCustomCommandLocalFileList->Objects[Index]);
  2263. RemoteFileList->Clear();
  2264. RemoteFileList->AddObject(
  2265. FCustomCommandRemoteFileList->Strings[Index],
  2266. FCustomCommandRemoteFileList->Objects[Index]);
  2267. CustomCommand(RemoteFileList, Command, LocalFileList);
  2268. }
  2269. }
  2270. __finally
  2271. {
  2272. delete LocalFileList;
  2273. delete RemoteFileList;
  2274. }
  2275. }
  2276. //---------------------------------------------------------------------------
  2277. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2278. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2279. {
  2280. delete FCustomCommandLocalFileList;
  2281. delete FCustomCommandRemoteFileList;
  2282. // takeover ownership,
  2283. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2284. FCustomCommandLocalFileList = LocalFileList;
  2285. FCustomCommandRemoteFileList = RemoteFileList;
  2286. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2287. if (Button != NULL)
  2288. {
  2289. FCustomCommandMenu->Items->Clear();
  2290. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2291. MenuPopup(FCustomCommandMenu, Button);
  2292. }
  2293. else
  2294. {
  2295. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2296. }
  2297. }
  2298. //---------------------------------------------------------------------------
  2299. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2300. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2301. {
  2302. DebugAssert(FCapturedLog != NULL);
  2303. if ((OutputType == cotOutput) || (OutputType == cotError))
  2304. {
  2305. FCapturedLog->Add(AddedLine);
  2306. }
  2307. }
  2308. //---------------------------------------------------------------------------
  2309. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2310. TOperationSide Side)
  2311. {
  2312. return
  2313. (Side == osOther) &&
  2314. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2315. }
  2316. //---------------------------------------------------------------------------
  2317. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2318. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2319. {
  2320. TTBItemOptions O;
  2321. O = Item->Options;
  2322. TCustomDirView * DView = DirView(Side);
  2323. if ((DView->ItemFocused != NULL) &&
  2324. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2325. // when resolving links is disabled, default action is to enter the directory,
  2326. // no matter what DoubleClickAction is configured to
  2327. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2328. // Can only Edit files, but can Open/Copy even directories
  2329. ((DoubleClickAction != dcaEdit) ||
  2330. !DView->ItemIsDirectory(DView->ItemFocused)))
  2331. {
  2332. Item->Options = O << tboDefault;
  2333. }
  2334. else
  2335. {
  2336. Item->Options = O >> tboDefault;
  2337. }
  2338. }
  2339. //---------------------------------------------------------------------------
  2340. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2341. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2342. {
  2343. TCustomDirView * DView = DirView(Side);
  2344. TListItem * Item = DView->ItemFocused;
  2345. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2346. EnableFocusedOperation[Side])
  2347. {
  2348. TPoint ClientPoint;
  2349. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2350. TPoint(0, 0) : MousePos;
  2351. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2352. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2353. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2354. }
  2355. }
  2356. //---------------------------------------------------------------------------
  2357. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2358. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2359. {
  2360. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2361. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2362. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2363. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2364. Handled = true;
  2365. }
  2366. //---------------------------------------------------------------------------
  2367. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2368. {
  2369. }
  2370. //---------------------------------------------------------------------------
  2371. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2372. {
  2373. DebugAssert(FErrorList == NULL);
  2374. if (WinConfiguration->ContinueOnError)
  2375. {
  2376. FErrorList = new TStringList();
  2377. Configuration->Usage->Inc(L"ContinuationsOnError");
  2378. }
  2379. NonVisualDataModule->StartBusy();
  2380. }
  2381. //---------------------------------------------------------------------------
  2382. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2383. {
  2384. NonVisualDataModule->EndBusy();
  2385. if (FErrorList)
  2386. {
  2387. HandleErrorList(FErrorList);
  2388. }
  2389. }
  2390. //---------------------------------------------------------------------------
  2391. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2392. const TCopyParamType & CopyParam)
  2393. {
  2394. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2395. {
  2396. Configuration->Usage->Inc(L"FileMaskUses");
  2397. }
  2398. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2399. {
  2400. Configuration->Usage->Inc(L"OperationMaskUses");
  2401. }
  2402. }
  2403. //---------------------------------------------------------------------------
  2404. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2405. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2406. {
  2407. DebugAssert(!IsLocalBrowserMode());
  2408. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2409. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2410. TTransferOperationParam DefaultParam;
  2411. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2412. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2413. switch (Param.Queue)
  2414. {
  2415. case asOn:
  2416. CopyParam.Queue = true;
  2417. break;
  2418. case asOff:
  2419. CopyParam.Queue = false;
  2420. break;
  2421. case asAuto:
  2422. default:
  2423. // keep default
  2424. break;
  2425. }
  2426. bool Result =
  2427. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2428. if (Result)
  2429. {
  2430. DebugAssert(Terminal);
  2431. bool SelectionRestored = false;
  2432. TCustomDirView * DView = NULL;
  2433. if (HasDirView[Side])
  2434. {
  2435. DView = DirView(Side);
  2436. DView->SaveSelection();
  2437. DView->SaveSelectedNames();
  2438. }
  2439. UpdateCopyParamCounters(CopyParam);
  2440. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2441. DebugAssert(FTransferResumeList == NULL);
  2442. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2443. FMoveToQueue = false;
  2444. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2445. try
  2446. {
  2447. TStrings * PermanentFileList;
  2448. std::unique_ptr<TStrings> PermanentFileListOwner;
  2449. try
  2450. {
  2451. if (Side == osLocal)
  2452. {
  2453. PermanentFileList = FileList;
  2454. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2455. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2456. if (Operation == foMove)
  2457. {
  2458. ReloadLocalDirectory();
  2459. if (DView != NULL)
  2460. {
  2461. DView->RestoreSelection();
  2462. }
  2463. SelectionRestored = true;
  2464. }
  2465. }
  2466. else
  2467. {
  2468. // Clone the file list as it may refer to current directory files,
  2469. // which get destroyed, when the source directory is reloaded after foMove operation.
  2470. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2471. // But for a hotfix, we are not going to do such a big change.
  2472. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2473. PermanentFileList = PermanentFileListOwner.get();
  2474. try
  2475. {
  2476. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2477. }
  2478. __finally
  2479. {
  2480. if (Operation == foMove)
  2481. {
  2482. if (DView != NULL)
  2483. {
  2484. DView->RestoreSelection();
  2485. }
  2486. SelectionRestored = true;
  2487. }
  2488. ReloadLocalDirectory(Param.TargetDirectory);
  2489. }
  2490. }
  2491. }
  2492. catch (EAbort &)
  2493. {
  2494. if (FMoveToQueue)
  2495. {
  2496. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2497. DebugAssert(CopyParam.TransferSkipList == NULL);
  2498. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2499. if (TransferResumeList->Count > 0)
  2500. {
  2501. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2502. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2503. }
  2504. CopyParam.TransferSkipList = TransferResumeList.release();
  2505. // not really needed, just to keep it consistent with TransferResumeList
  2506. FTransferResumeList = NULL;
  2507. FMoveToQueue = false;
  2508. Configuration->Usage->Inc("MovesToBackground");
  2509. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2510. ClearTransferSourceSelection(Direction);
  2511. }
  2512. throw;
  2513. }
  2514. }
  2515. __finally
  2516. {
  2517. if (!SelectionRestored && (DView != NULL))
  2518. {
  2519. DView->DiscardSavedSelection();
  2520. }
  2521. FTransferResumeList = NULL;
  2522. }
  2523. }
  2524. return Result;
  2525. }
  2526. //---------------------------------------------------------------------------
  2527. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2528. TOperationSide Side, TStrings * FileList, void * Param)
  2529. {
  2530. DebugAssert(FileList->Count);
  2531. // We deliberately do not toggle alternative flag (Param), but use OR,
  2532. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2533. // shortcut of CurrentDeleteAlternativeAction
  2534. bool Alternative =
  2535. bool(Param) || UseAlternativeFunction();
  2536. bool Recycle;
  2537. if (IsSideLocalBrowser(Side))
  2538. {
  2539. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2540. }
  2541. else
  2542. {
  2543. Recycle =
  2544. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2545. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2546. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2547. }
  2548. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2549. if (!Result)
  2550. {
  2551. UnicodeString Query;
  2552. if (FileList->Count == 1)
  2553. {
  2554. if (IsSideLocalBrowser(Side))
  2555. {
  2556. Query = ExtractFileName(FileList->Strings[0]);
  2557. }
  2558. else
  2559. {
  2560. Query = UnixExtractFileName(FileList->Strings[0]);
  2561. }
  2562. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2563. }
  2564. else
  2565. {
  2566. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2567. }
  2568. TMessageParams Params(mpNeverAskAgainCheck);
  2569. Params.ImageName = L"Delete file";
  2570. unsigned int Answer =
  2571. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2572. if (Answer == qaNeverAskAgain)
  2573. {
  2574. Result = true;
  2575. if (Recycle)
  2576. {
  2577. WinConfiguration->ConfirmRecycling = false;
  2578. }
  2579. else
  2580. {
  2581. WinConfiguration->ConfirmDeleting = false;
  2582. }
  2583. }
  2584. else
  2585. {
  2586. Result = (Answer == qaOK);
  2587. }
  2588. }
  2589. if (Result)
  2590. {
  2591. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2592. }
  2593. return Result;
  2594. }
  2595. //---------------------------------------------------------------------------
  2596. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2597. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2598. {
  2599. TAutoBatch AutoBatch(this);
  2600. bool Result;
  2601. if ((Operation == foCopy) || (Operation == foMove))
  2602. {
  2603. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2604. }
  2605. else if (Operation == foRename)
  2606. {
  2607. DebugAssert(DirView(Side)->ItemFocused);
  2608. DirView(Side)->ItemFocused->EditCaption();
  2609. Result = true;
  2610. }
  2611. else if (Operation == foDelete)
  2612. {
  2613. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2614. }
  2615. else if (Operation == foSetProperties)
  2616. {
  2617. DirView(osRemote)->SaveSelectedNames();
  2618. Result = SetProperties(Side, FileList);
  2619. }
  2620. else if (Operation == foCustomCommand)
  2621. {
  2622. DebugAssert(Param);
  2623. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2624. DirView(osRemote)->SaveSelectedNames();
  2625. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2626. CustomCommand(FileList, *Command, NULL);
  2627. Result = true;
  2628. }
  2629. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2630. {
  2631. DebugAssert(!IsSideLocalBrowser(Side));
  2632. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2633. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2634. }
  2635. else if (Operation == foLock)
  2636. {
  2637. DebugAssert(!IsSideLocalBrowser(Side));
  2638. LockFiles(FileList, true);
  2639. Result = true;
  2640. }
  2641. else if (Operation == foUnlock)
  2642. {
  2643. DebugAssert(!IsSideLocalBrowser(Side));
  2644. LockFiles(FileList, false);
  2645. Result = true;
  2646. }
  2647. else
  2648. {
  2649. DebugFail();
  2650. }
  2651. return Result;
  2652. }
  2653. //---------------------------------------------------------------------------
  2654. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2655. {
  2656. if (Side == osCurrent)
  2657. {
  2658. Side = FCurrentSide;
  2659. }
  2660. return Side;
  2661. }
  2662. //---------------------------------------------------------------------------
  2663. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2664. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2665. {
  2666. Side = GetSide(Side);
  2667. bool Result;
  2668. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2669. try
  2670. {
  2671. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2672. }
  2673. __finally
  2674. {
  2675. delete FileList;
  2676. }
  2677. return Result;
  2678. }
  2679. //---------------------------------------------------------------------------
  2680. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2681. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2682. bool NoConfirmation, void * Param)
  2683. {
  2684. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2685. {
  2686. if ((Operation == foCopy) || (Operation == foMove))
  2687. {
  2688. DebugAssert(!IsLocalBrowserMode());
  2689. if (GetSide(Side) == osLocal)
  2690. {
  2691. Configuration->Usage->Inc(L"UploadsCommand");
  2692. }
  2693. else
  2694. {
  2695. Configuration->Usage->Inc(L"DownloadsCommand");
  2696. }
  2697. }
  2698. }
  2699. }
  2700. //---------------------------------------------------------------------------
  2701. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2702. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2703. {
  2704. TTransferOperationParam Param;
  2705. if ((WinConfiguration->Interface != ifCommander) ||
  2706. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2707. {
  2708. Flags &= ~cocShortCutHint;
  2709. }
  2710. TCustomDirView * DView = DirView(Side);
  2711. Param.Options =
  2712. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2713. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2714. if (FLAGSET(Flags, cocQueue))
  2715. {
  2716. Param.Queue = asOn;
  2717. }
  2718. else if (FLAGSET(Flags, cocNonQueue))
  2719. {
  2720. Param.Queue = asOff;
  2721. }
  2722. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2723. }
  2724. //---------------------------------------------------------------------------
  2725. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2726. {
  2727. try
  2728. {
  2729. if (ErrorList->Count)
  2730. {
  2731. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2732. if (MessageDialog(Message, qtError,
  2733. qaOK | qaCancel, HELP_NONE) == qaOK)
  2734. {
  2735. unsigned int Answer;
  2736. int Index = 0;
  2737. do
  2738. {
  2739. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2740. TQueryButtonAlias Aliases[2];
  2741. Aliases[0].Button = qaYes;
  2742. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2743. Aliases[1].Button = qaNo;
  2744. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2745. TMessageParams Params;
  2746. Params.Aliases = Aliases;
  2747. Params.AliasesCount = LENOF(Aliases);
  2748. Answer = MoreMessageDialog(
  2749. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2750. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2751. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2752. qaOK, HELP_NONE, &Params);
  2753. if (Answer == qaNo)
  2754. {
  2755. Index++;
  2756. }
  2757. if (Answer == qaYes)
  2758. {
  2759. Index--;
  2760. }
  2761. }
  2762. while (Answer != qaOK);
  2763. }
  2764. }
  2765. }
  2766. __finally
  2767. {
  2768. TStrings * List = ErrorList;
  2769. ErrorList = NULL;
  2770. for (int i = 0; i < List->Count; i++)
  2771. {
  2772. delete List->Objects[i];
  2773. }
  2774. delete List;
  2775. }
  2776. }
  2777. //---------------------------------------------------------------------------
  2778. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2779. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2780. {
  2781. // needed for checking filemasks, as there's no directory object
  2782. // associated with the file object
  2783. File->FullFileName = FullFileName;
  2784. TFileMasks::TParams MaskParams;
  2785. MaskParams.Size = File->Size;
  2786. MaskParams.Modification = File->Modification;
  2787. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2788. }
  2789. //---------------------------------------------------------------------------
  2790. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2791. {
  2792. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2793. Side = GetSide(Side);
  2794. TCustomDirView * DView = DirView(Side);
  2795. TListItem * FocusedItem = DView->ItemFocused;
  2796. UnicodeString Name;
  2797. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2798. {
  2799. Name = DView->ItemFileName(FocusedItem);
  2800. }
  2801. else
  2802. {
  2803. Name = LoadStr(NEW_FILE);
  2804. }
  2805. UnicodeString Names = Name;
  2806. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2807. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2808. HELP_EDIT_NEW, History.get(), true))
  2809. {
  2810. while (!Names.IsEmpty())
  2811. {
  2812. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2813. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2814. UnicodeString TargetFileName;
  2815. UnicodeString LocalFileName;
  2816. UnicodeString RootTempDir;
  2817. UnicodeString TempDir;
  2818. UnicodeString RemoteDirectory;
  2819. bool ExistingFile = false;
  2820. if (!IsSideLocalBrowser(Side))
  2821. {
  2822. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2823. TRemoteFile * File = NULL;
  2824. if (FTerminal->FileExists(Name, &File) &&
  2825. !File->IsDirectory)
  2826. {
  2827. try
  2828. {
  2829. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2830. ExistingFile = true;
  2831. }
  2832. __finally
  2833. {
  2834. delete File;
  2835. }
  2836. }
  2837. if (!ExistingFile)
  2838. {
  2839. RemoteDirectory = UnixExtractFilePath(Name);
  2840. TemporaryDirectoryForRemoteFiles(
  2841. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2842. TargetFileName = UnixExtractFileName(Name);
  2843. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2844. LocalFileName = TempDir +
  2845. // We probably do not want to trim the VMS version here
  2846. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2847. }
  2848. }
  2849. else
  2850. {
  2851. if (ExtractFilePath(Name).IsEmpty())
  2852. {
  2853. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2854. }
  2855. else
  2856. {
  2857. LocalFileName = ExpandFileName(Name);
  2858. }
  2859. TargetFileName = ExtractFileName(Name);
  2860. }
  2861. if (!ExistingFile)
  2862. {
  2863. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2864. if (NewFile)
  2865. {
  2866. int File = FileCreate(ApiPath(LocalFileName));
  2867. if (File < 0)
  2868. {
  2869. if (!RootTempDir.IsEmpty())
  2870. {
  2871. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2872. }
  2873. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2874. }
  2875. else
  2876. {
  2877. FileClose(File);
  2878. }
  2879. }
  2880. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2881. const TEditorData * ExternalEditor = NULL;
  2882. TFileMasks::TParams MaskParams; // size not known
  2883. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2884. false, MaskParams);
  2885. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2886. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2887. }
  2888. }
  2889. }
  2890. }
  2891. //---------------------------------------------------------------------------
  2892. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2893. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2894. {
  2895. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2896. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2897. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2898. return
  2899. ((ExecuteFileBy == efInternalEditor)) ||
  2900. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2901. }
  2902. //---------------------------------------------------------------------------
  2903. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2904. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2905. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2906. UnicodeString RemoteDirectory, bool NewFile)
  2907. {
  2908. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2909. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2910. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2911. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2912. Side = GetSide(Side);
  2913. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2914. if (!IsSideLocalBrowser(Side))
  2915. {
  2916. Data->Terminal = Terminal;
  2917. Data->Queue = Queue;
  2918. Data->SessionData = CloneCurrentSessionData();
  2919. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2920. Data->RemoteDirectory = RemoteDirectory;
  2921. Data->SessionName = Terminal->SessionData->SessionName;
  2922. Data->LocalRootDirectory = LocalRootDirectory;
  2923. Data->OriginalFileName = OriginalFileName;
  2924. Data->Command = L""; // will be changed later for external editor
  2925. }
  2926. if (ExecuteFileBy == efInternalEditor)
  2927. {
  2928. if (!IsSideLocalBrowser(Side))
  2929. {
  2930. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2931. L" - " + Terminal->SessionData->SessionName;
  2932. TForm * Editor;
  2933. try
  2934. {
  2935. TNotifyEvent OnFileChanged = NULL;
  2936. TNotifyEvent OnSaveAll = NULL;
  2937. TAnyModifiedEvent OnAnyModified = NULL;
  2938. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2939. if (Terminal->IsCapable[fcBackgroundTransfers])
  2940. {
  2941. OnFileChanged = FEditorManager->FileChanged;
  2942. OnSaveAll = SaveAllInternalEditors;
  2943. OnAnyModified = AnyInternalEditorModified;
  2944. }
  2945. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2946. FEditorManager->FileReload, FEditorManager->FileClosed,
  2947. OnSaveAll, OnAnyModified,
  2948. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2949. }
  2950. catch(...)
  2951. {
  2952. if (!LocalRootDirectory.IsEmpty())
  2953. {
  2954. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2955. }
  2956. throw;
  2957. }
  2958. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2959. }
  2960. else
  2961. {
  2962. DebugAssert(!FStandaloneEditing);
  2963. TForm * Editor =
  2964. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2965. SaveAllInternalEditors, AnyInternalEditorModified,
  2966. L"", false, SessionColor, -1, NewFile);
  2967. FLocalEditors->Add(Editor);
  2968. }
  2969. }
  2970. else
  2971. {
  2972. HANDLE Process;
  2973. if (ExecuteFileBy == efExternalEditor)
  2974. {
  2975. UnicodeString Program, Params, Dir;
  2976. Data->Command = ExternalEditor->ExternalEditor;
  2977. ReformatFileNameCommand(Data->Command);
  2978. SplitCommand(Data->Command, Program, Params, Dir);
  2979. Params = ExpandFileNameCommand(Params, FileName);
  2980. Program = ExpandEnvironmentVariables(Program);
  2981. if (!ExecuteShell(Program, Params, Process))
  2982. {
  2983. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  2984. }
  2985. }
  2986. else
  2987. {
  2988. DebugAssert(!IsSideLocalBrowser(Side));
  2989. if (!ExecuteShell(FileName, L"", Process))
  2990. {
  2991. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  2992. }
  2993. }
  2994. if (IsSideLocalBrowser(Side) ||
  2995. ((ExecuteFileBy == efShell) &&
  2996. !WinConfiguration->Editor.SDIShellEditor) ||
  2997. ((ExecuteFileBy == efExternalEditor) &&
  2998. !ExternalEditor->SDIExternalEditor))
  2999. {
  3000. // no need for handle
  3001. if (Process != NULL)
  3002. {
  3003. DebugCheck(CloseHandle(Process));
  3004. }
  3005. Process = INVALID_HANDLE_VALUE;
  3006. }
  3007. else
  3008. {
  3009. if (Process == NULL)
  3010. {
  3011. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3012. }
  3013. }
  3014. if (!IsSideLocalBrowser(Side))
  3015. {
  3016. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3017. }
  3018. }
  3019. }
  3020. //---------------------------------------------------------------------------
  3021. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3022. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3023. void * /*Arg*/)
  3024. {
  3025. if (Token != NULL)
  3026. {
  3027. EditorFormFileSave(static_cast<TForm *>(Token));
  3028. }
  3029. }
  3030. //---------------------------------------------------------------------------
  3031. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3032. {
  3033. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3034. {
  3035. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3036. }
  3037. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3038. }
  3039. //---------------------------------------------------------------------------
  3040. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3041. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3042. void * Arg)
  3043. {
  3044. if ((Token != NULL) &&
  3045. IsEditorFormModified(static_cast<TForm *>(Token)))
  3046. {
  3047. *static_cast<bool *>(Arg) = true;
  3048. }
  3049. }
  3050. //---------------------------------------------------------------------------
  3051. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3052. TObject * /*Sender*/, bool & Modified)
  3053. {
  3054. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3055. {
  3056. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3057. {
  3058. Modified = true;
  3059. }
  3060. }
  3061. if (!Modified)
  3062. {
  3063. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3064. }
  3065. }
  3066. //---------------------------------------------------------------------------
  3067. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3068. {
  3069. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3070. }
  3071. //---------------------------------------------------------------------------
  3072. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3073. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3074. UnicodeString & Result, UnicodeString & RootDirectory)
  3075. {
  3076. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3077. {
  3078. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3079. Result = RootDirectory;
  3080. }
  3081. else
  3082. {
  3083. RootDirectory = L"";
  3084. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3085. Result = IncludeTrailingBackslash(Result);
  3086. }
  3087. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3088. {
  3089. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3090. }
  3091. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3092. {
  3093. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3094. {
  3095. RemoteDirectory.Delete(1, 1);
  3096. }
  3097. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3098. }
  3099. if (!ForceDirectories(ApiPath(Result)))
  3100. {
  3101. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3102. }
  3103. }
  3104. //---------------------------------------------------------------------------
  3105. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3106. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3107. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3108. {
  3109. DebugAssert(!IsLocalBrowserMode());
  3110. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3111. if (ForceText)
  3112. {
  3113. CopyParam.TransferMode = tmAscii;
  3114. }
  3115. TemporaryFileCopyParam(CopyParam);
  3116. if (AllFiles)
  3117. {
  3118. CopyParam.IncludeFileMask = TFileMasks();
  3119. }
  3120. if (TempDir.IsEmpty())
  3121. {
  3122. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3123. }
  3124. DebugAssert(!FAutoOperation);
  3125. FAutoOperation = AutoOperation;
  3126. Terminal->ExceptionOnFail = true;
  3127. try
  3128. {
  3129. try
  3130. {
  3131. // turn off confirmations, as for MDI editors we may possibly download
  3132. // the same file over
  3133. Terminal->CopyToLocal(
  3134. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3135. if (GetTargetNames)
  3136. {
  3137. for (int i = 0; i < FileList->Count; i++)
  3138. {
  3139. FileList->Strings[i] =
  3140. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3141. }
  3142. }
  3143. }
  3144. catch(...)
  3145. {
  3146. if (!RootTempDir.IsEmpty())
  3147. {
  3148. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3149. }
  3150. throw;
  3151. }
  3152. }
  3153. __finally
  3154. {
  3155. FAutoOperation = false;
  3156. Terminal->ExceptionOnFail = false;
  3157. }
  3158. }
  3159. //---------------------------------------------------------------------------
  3160. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3161. {
  3162. // Do not waste time checking for default editor list the next time,
  3163. // or testing if default editor is not notepad.
  3164. bool TryNextTime = false;
  3165. UnicodeString UsageState;
  3166. if (!WinConfiguration->EditorList->IsDefaultList())
  3167. {
  3168. UsageState = "H";
  3169. }
  3170. else
  3171. {
  3172. UnicodeString Executable;
  3173. UnicodeString ExecutableDescription;
  3174. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3175. {
  3176. UnicodeString Message =
  3177. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3178. unsigned int Answer =
  3179. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3180. if (Answer != qaOK)
  3181. {
  3182. UsageState = "R";
  3183. }
  3184. else
  3185. {
  3186. UsageState = "A";
  3187. TEditorData EditorData;
  3188. EditorData.Editor = edExternal;
  3189. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3190. EditorData.ExternalEditorOptionsAutodetect();
  3191. TEditorList EditorList;
  3192. EditorList = *WinConfiguration->EditorList;
  3193. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3194. WinConfiguration->EditorList = &EditorList;
  3195. }
  3196. }
  3197. }
  3198. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3199. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3200. }
  3201. //---------------------------------------------------------------------------
  3202. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3203. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3204. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3205. {
  3206. if (ExecuteFileBy == efDefaultEditor)
  3207. {
  3208. if (!WinConfiguration->OfferedEditorAutoConfig)
  3209. {
  3210. EditorAutoConfig();
  3211. }
  3212. const TEditorPreferences * Editor =
  3213. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3214. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3215. {
  3216. ExecuteFileBy = efInternalEditor;
  3217. ExternalEditor = NULL;
  3218. }
  3219. else if (Editor->Data->Editor == edOpen)
  3220. {
  3221. ExecuteFileBy = efShell;
  3222. ExternalEditor = NULL;
  3223. }
  3224. else
  3225. {
  3226. ExecuteFileBy = efExternalEditor;
  3227. ExternalEditor = Editor->Data;
  3228. }
  3229. }
  3230. }
  3231. //---------------------------------------------------------------------------
  3232. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3233. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3234. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3235. {
  3236. UnicodeString OriginalFileName;
  3237. UnicodeString LocalRootDirectory;
  3238. UnicodeString RemoteDirectory;
  3239. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3240. IsSideLocalBrowser(Side), MaskParams);
  3241. UnicodeString Counter;
  3242. UnicodeString LocalFileName;
  3243. bool Handled = false;
  3244. if (!IsSideLocalBrowser(Side))
  3245. {
  3246. // We need to trim VMS version here, so that we use name without version
  3247. // when uploading back to create a new version of the file
  3248. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3249. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3250. TObject * Token = NULL;
  3251. UnicodeString LocalDirectory;
  3252. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3253. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3254. LocalDirectory))
  3255. {
  3256. if (Token != NULL)
  3257. {
  3258. TForm * Form = dynamic_cast<TForm *>(Token);
  3259. if (Form->WindowState == wsMinimized)
  3260. {
  3261. ShowWindow(Form->Handle, SW_RESTORE);
  3262. }
  3263. else
  3264. {
  3265. Form->SetFocus();
  3266. }
  3267. Handled = true;
  3268. }
  3269. else
  3270. {
  3271. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3272. }
  3273. }
  3274. if (!Handled)
  3275. {
  3276. TStringList * FileList1 = new TStringList();
  3277. try
  3278. {
  3279. FileList1->AddObject(FullFileName, Object);
  3280. TemporarilyDownloadFiles(FileList1,
  3281. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3282. LocalRootDirectory, LocalDirectory, true, true, true);
  3283. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3284. }
  3285. __finally
  3286. {
  3287. delete FileList1;
  3288. }
  3289. switch (ExecuteFileBy)
  3290. {
  3291. case efShell:
  3292. Counter = "RemoteFilesExecuted";
  3293. break;
  3294. case efInternalEditor:
  3295. Counter = "RemoteFilesOpenedInInternalEditor";
  3296. break;
  3297. case efExternalEditor:
  3298. Counter = "RemoteFilesOpenedInExternalEditor";
  3299. break;
  3300. default:
  3301. DebugFail();
  3302. }
  3303. }
  3304. }
  3305. else
  3306. {
  3307. LocalFileName = FullFileName;
  3308. OriginalFileName = ExtractFileName(FullFileName);
  3309. switch (ExecuteFileBy)
  3310. {
  3311. case efShell:
  3312. Counter = "LocalFilesExecuted";
  3313. break;
  3314. case efInternalEditor:
  3315. Counter = "LocalFilesOpenedInInternalEditor";
  3316. break;
  3317. case efExternalEditor:
  3318. Counter = "LocalFilesOpenedInExternalEditor";
  3319. break;
  3320. default:
  3321. DebugFail();
  3322. }
  3323. }
  3324. if (!Handled)
  3325. {
  3326. Configuration->Usage->Inc(Counter);
  3327. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3328. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3329. }
  3330. }
  3331. //---------------------------------------------------------------------------
  3332. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3333. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3334. bool AllSelected, bool OnFocused)
  3335. {
  3336. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3337. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3338. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3339. Side = GetSide(Side);
  3340. TCustomDirView * DView = DirView(Side);
  3341. TStrings * FileList =
  3342. AllSelected ?
  3343. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3344. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3345. try
  3346. {
  3347. DebugAssert(AllSelected || (FileList->Count == 1));
  3348. for (int i = 0; i < FileList->Count; i++)
  3349. {
  3350. UnicodeString ListFileName = FileList->Strings[i];
  3351. UnicodeString FileNameOnly =
  3352. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3353. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3354. if (!DView->ItemIsDirectory(Item))
  3355. {
  3356. UnicodeString FullFileName;
  3357. if (!IsSideLocalBrowser(Side))
  3358. {
  3359. FullFileName = DirView(Side)->Path + ListFileName;
  3360. }
  3361. else
  3362. {
  3363. FullFileName = ListFileName;
  3364. }
  3365. TFileMasks::TParams MaskParams;
  3366. MaskParams.Size = DView->ItemFileSize(Item);
  3367. TDateTimePrecision Precision;
  3368. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3369. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3370. FileList->Objects[i], MaskParams);
  3371. }
  3372. }
  3373. }
  3374. __finally
  3375. {
  3376. delete FileList;
  3377. }
  3378. }
  3379. //---------------------------------------------------------------------------
  3380. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3381. {
  3382. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3383. CopyParam.FileNameCase = ncNoChange;
  3384. CopyParam.PreserveRights = false;
  3385. CopyParam.PreserveReadOnly = false;
  3386. CopyParam.ReplaceInvalidChars = true;
  3387. CopyParam.IncludeFileMask = TFileMasks();
  3388. CopyParam.NewerOnly = false;
  3389. CopyParam.FileMask = L"";
  3390. }
  3391. //---------------------------------------------------------------------------
  3392. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3393. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3394. {
  3395. TTerminalManager * Manager = TTerminalManager::Instance();
  3396. if (!IsActiveTerminal(Data->Terminal))
  3397. {
  3398. if (!NonVisualDataModule->Busy)
  3399. {
  3400. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3401. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3402. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3403. if (Data->Terminal == NULL)
  3404. {
  3405. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3406. if (SameSiteTerminal != NULL)
  3407. {
  3408. UnicodeString Message =
  3409. FMTLOAD(EDIT_SESSION_REATTACH,
  3410. (FileNameOnly, Data->SessionName, FileNameOnly));
  3411. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3412. {
  3413. Data->Terminal = Terminal;
  3414. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3415. Data->SessionName = Terminal->SessionData->SessionName;
  3416. // We might also overwrite session data
  3417. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3418. }
  3419. else
  3420. {
  3421. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3422. Abort();
  3423. }
  3424. }
  3425. }
  3426. // foreground session should reconnect itself
  3427. else if (Terminal != Data->Terminal)
  3428. {
  3429. UnicodeString Message =
  3430. MainInstructions(
  3431. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3432. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3433. {
  3434. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3435. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3436. }
  3437. else
  3438. {
  3439. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3440. Abort();
  3441. }
  3442. }
  3443. }
  3444. if (!IsActiveTerminal(Data->Terminal))
  3445. {
  3446. Configuration->Usage->Inc(L"EditInactiveSession");
  3447. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3448. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3449. (ExtractFileName(FileName), Data->SessionName)));
  3450. }
  3451. }
  3452. TStrings * FileList = new TStringList();
  3453. try
  3454. {
  3455. FileList->Add(FileName);
  3456. // consider using the same settings (preset) as when the file was downloaded
  3457. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3458. TemporaryFileCopyParam(CopyParam);
  3459. if (Data->ForceText)
  3460. {
  3461. CopyParam.TransferMode = tmAscii;
  3462. }
  3463. // so i do not need to worry if masking algorithm works in all cases
  3464. // ("" means "copy file name", no masking is actually done)
  3465. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3466. {
  3467. CopyParam.FileMask = L"";
  3468. }
  3469. else
  3470. {
  3471. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3472. }
  3473. DebugAssert(Data->Queue != NULL);
  3474. int Params = cpNoConfirmation | cpTemporary;
  3475. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3476. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3477. QueueItem->CompleteEvent = UploadCompleteEvent;
  3478. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3479. }
  3480. __finally
  3481. {
  3482. delete FileList;
  3483. }
  3484. }
  3485. //---------------------------------------------------------------------------
  3486. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3487. const UnicodeString FileName, const TEditedFileData * Data)
  3488. {
  3489. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3490. DebugAssert(!NonVisualDataModule->Busy);
  3491. if (!IsActiveTerminal(Data->Terminal))
  3492. {
  3493. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3494. (ExtractFileName(FileName), Data->SessionName)));
  3495. }
  3496. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3497. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3498. NonVisualDataModule->StartBusy();
  3499. try
  3500. {
  3501. std::unique_ptr<TRemoteFile> File;
  3502. UnicodeString RemoteFileName =
  3503. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3504. FTerminal->ExceptionOnFail = true;
  3505. try
  3506. {
  3507. TRemoteFile * AFile = NULL;
  3508. FTerminal->ReadFile(RemoteFileName, AFile);
  3509. File.reset(AFile);
  3510. if (!File->HaveFullFileName)
  3511. {
  3512. File->FullFileName = RemoteFileName;
  3513. }
  3514. }
  3515. __finally
  3516. {
  3517. FTerminal->ExceptionOnFail = false;
  3518. }
  3519. std::unique_ptr<TStrings> FileList(new TStringList());
  3520. FileList->AddObject(RemoteFileName, File.get());
  3521. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3522. UnicodeString TempDir = ExtractFilePath(FileName);
  3523. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3524. TempDir, true, true, true);
  3525. // sanity check, the target file name should be still the same
  3526. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3527. }
  3528. __finally
  3529. {
  3530. NonVisualDataModule->EndBusy();
  3531. // it actually may not exist anymore...
  3532. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3533. }
  3534. }
  3535. //---------------------------------------------------------------------------
  3536. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3537. const TEditedFileData * Data, bool & KeepOpen)
  3538. {
  3539. // Command is set for external editors only (not for "shell" open).
  3540. if (!Data->Command.IsEmpty())
  3541. {
  3542. bool AnyFound = false;
  3543. bool AnyMDI = false;
  3544. bool AnyNonMDI = false;
  3545. bool AnyDetect = false;
  3546. TEditorList * EditorList = new TEditorList();
  3547. try
  3548. {
  3549. *EditorList = *WinConfiguration->EditorList;
  3550. for (int i = 0; i < EditorList->Count; i++)
  3551. {
  3552. const TEditorPreferences * Editor = EditorList->Editors[i];
  3553. if ((Editor->Data->Editor == edExternal) &&
  3554. (Editor->Data->ExternalEditor == Data->Command))
  3555. {
  3556. AnyFound = true;
  3557. if (Editor->Data->SDIExternalEditor)
  3558. {
  3559. AnyNonMDI = true;
  3560. if (Editor->Data->DetectMDIExternalEditor)
  3561. {
  3562. AnyDetect = true;
  3563. }
  3564. }
  3565. else
  3566. {
  3567. AnyMDI = true;
  3568. }
  3569. }
  3570. }
  3571. bool EnableMDI = false;
  3572. bool DisableDetect = false;
  3573. if (AnyMDI)
  3574. {
  3575. KeepOpen = true;
  3576. if (AnyNonMDI)
  3577. {
  3578. // there is at least one instance of the editor with MDI support enabled,
  3579. // and one with disabled, enable it for all instances
  3580. EnableMDI = true;
  3581. }
  3582. }
  3583. else if (AnyFound && !AnyDetect)
  3584. {
  3585. // at least once instance found but all have MDI autodetection disabled
  3586. // => close the file (default action)
  3587. }
  3588. else
  3589. {
  3590. // no instance of the editor has MDI support enabled
  3591. TMessageParams Params;
  3592. if (AnyFound)
  3593. {
  3594. // there is at least one instance of the editor
  3595. Params.Params |= mpNeverAskAgainCheck;
  3596. }
  3597. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3598. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3599. switch (Answer)
  3600. {
  3601. case qaNeverAskAgain:
  3602. DisableDetect = true;
  3603. break;
  3604. case qaNo:
  3605. EnableMDI = true;
  3606. KeepOpen = true;
  3607. break;
  3608. }
  3609. }
  3610. if (AnyFound && (EnableMDI || DisableDetect))
  3611. {
  3612. bool Changed = false;
  3613. for (int i = 0; i < EditorList->Count; i++)
  3614. {
  3615. const TEditorPreferences * Editor = EditorList->Editors[i];
  3616. if ((Editor->Data->Editor == edExternal) &&
  3617. (Editor->Data->ExternalEditor == Data->Command) &&
  3618. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3619. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3620. {
  3621. Changed = true;
  3622. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3623. if (EnableMDI)
  3624. {
  3625. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3626. }
  3627. if (DisableDetect)
  3628. {
  3629. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3630. }
  3631. EditorList->Change(i, UpdatedEditor);
  3632. }
  3633. }
  3634. if (Changed)
  3635. {
  3636. WinConfiguration->EditorList = EditorList;
  3637. }
  3638. }
  3639. }
  3640. __finally
  3641. {
  3642. delete EditorList;
  3643. }
  3644. }
  3645. else
  3646. {
  3647. // "open" case
  3648. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3649. qaOK, HELP_APP_EARLY_CLOSED);
  3650. }
  3651. }
  3652. //---------------------------------------------------------------------------
  3653. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3654. {
  3655. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3656. }
  3657. //---------------------------------------------------------------------------
  3658. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3659. {
  3660. SideEnter(osRemote);
  3661. }
  3662. //---------------------------------------------------------------------------
  3663. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3664. {
  3665. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3666. SideEnter(osRemote);
  3667. }
  3668. //---------------------------------------------------------------------------
  3669. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3670. {
  3671. FCurrentSide = Side;
  3672. if (Visible)
  3673. {
  3674. UpdateControls();
  3675. }
  3676. }
  3677. //---------------------------------------------------------------------------
  3678. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3679. TStrings * FileList, bool Alternative)
  3680. {
  3681. TCustomDirView * DView = DirView(Side);
  3682. DView->SaveSelection();
  3683. DView->SaveSelectedNames();
  3684. DebugAssert(!FAlternativeDelete);
  3685. FAlternativeDelete = Alternative;
  3686. try
  3687. {
  3688. if (!IsSideLocalBrowser(Side))
  3689. {
  3690. DebugAssert(Terminal != NULL);
  3691. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3692. }
  3693. else
  3694. {
  3695. try
  3696. {
  3697. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3698. }
  3699. __finally
  3700. {
  3701. ReloadLocalDirectory();
  3702. }
  3703. }
  3704. FAlternativeDelete = false;
  3705. }
  3706. catch(...)
  3707. {
  3708. FAlternativeDelete = false;
  3709. DView->DiscardSavedSelection();
  3710. throw;
  3711. }
  3712. DView->RestoreSelection();
  3713. }
  3714. //---------------------------------------------------------------------------
  3715. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3716. {
  3717. DebugAssert(Terminal);
  3718. DebugAssert(!IsLocalBrowserMode());
  3719. RemoteDirView->SaveSelection();
  3720. RemoteDirView->SaveSelectedNames();
  3721. try
  3722. {
  3723. if (Lock)
  3724. {
  3725. Terminal->LockFiles(FileList);
  3726. }
  3727. else
  3728. {
  3729. Terminal->UnlockFiles(FileList);
  3730. }
  3731. }
  3732. catch(...)
  3733. {
  3734. RemoteDirView->DiscardSavedSelection();
  3735. throw;
  3736. }
  3737. RemoteDirView->RestoreSelection();
  3738. }
  3739. //---------------------------------------------------------------------------
  3740. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3741. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3742. bool NoConfirmation, bool Move)
  3743. {
  3744. DebugAssert(Terminal != NULL);
  3745. DebugAssert(!IsLocalBrowserMode());
  3746. // update Terminal->StateData->RemoteDirectory
  3747. UpdateTerminal(Terminal);
  3748. if (Session == NULL)
  3749. {
  3750. Session = TTerminalManager::Instance()->ActiveTerminal;
  3751. }
  3752. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3753. {
  3754. if (RemoteDriveView->DropTarget != NULL)
  3755. {
  3756. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3757. }
  3758. else if (RemoteDirView->DropTarget != NULL)
  3759. {
  3760. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3761. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3762. }
  3763. else
  3764. {
  3765. Target = RemoteDirView->Path;
  3766. }
  3767. }
  3768. else
  3769. {
  3770. Target = Session->StateData->RemoteDirectory;
  3771. }
  3772. Target = UnixIncludeTrailingBackslash(Target);
  3773. if (FileList->Count == 1)
  3774. {
  3775. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3776. }
  3777. else
  3778. {
  3779. FileMask = AnyMask;
  3780. }
  3781. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3782. bool Result = true;
  3783. if (!NoConfirmation)
  3784. {
  3785. bool Multi = (FileList->Count > 1);
  3786. if (Move)
  3787. {
  3788. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3789. }
  3790. else
  3791. {
  3792. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3793. TStrings * Directories = new TStringList;
  3794. try
  3795. {
  3796. for (int Index = 0; Index < Sessions->Count; Index++)
  3797. {
  3798. TManagedTerminal * Terminal =
  3799. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3800. Directories->Add(Terminal->StateData->RemoteDirectory);
  3801. }
  3802. TDirectRemoteCopy AllowDirectCopy;
  3803. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3804. {
  3805. DebugAssert(DirectCopy);
  3806. AllowDirectCopy = drcAllow;
  3807. }
  3808. else if (FTerminal->IsCapable[fcSecondaryShell])
  3809. {
  3810. DebugAssert(DirectCopy);
  3811. AllowDirectCopy = drcConfirmCommandSession;
  3812. }
  3813. else
  3814. {
  3815. DebugAssert(!DirectCopy);
  3816. AllowDirectCopy = drcDisallow;
  3817. }
  3818. void * ASession = Session;
  3819. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3820. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3821. Session = static_cast<TManagedTerminal *>(ASession);
  3822. }
  3823. __finally
  3824. {
  3825. delete Directories;
  3826. }
  3827. }
  3828. }
  3829. return Result;
  3830. }
  3831. //---------------------------------------------------------------------------
  3832. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3833. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3834. {
  3835. DebugAssert(!IsLocalBrowserMode());
  3836. bool DirectCopy;
  3837. UnicodeString Target, FileMask;
  3838. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3839. if (Result)
  3840. {
  3841. if (!Move && !DirectCopy)
  3842. {
  3843. Configuration->Usage->Inc("RemoteCopyTemp");
  3844. UnicodeString RootTempDir;
  3845. UnicodeString TempDir;
  3846. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3847. TStrings * TemporaryFilesList = new TStringList();
  3848. try
  3849. {
  3850. TMakeLocalFileListParams MakeFileListParam;
  3851. MakeFileListParam.FileList = TemporaryFilesList;
  3852. MakeFileListParam.FileTimes = NULL;
  3853. MakeFileListParam.IncludeDirs = true;
  3854. MakeFileListParam.Recursive = false;
  3855. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3856. TTerminalManager::Instance()->ActiveTerminal = Session;
  3857. if (TemporaryFilesList->Count > 0)
  3858. {
  3859. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3860. CopyParam.FileMask = FileMask;
  3861. DebugAssert(!FAutoOperation);
  3862. FAutoOperation = true;
  3863. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3864. }
  3865. }
  3866. __finally
  3867. {
  3868. delete TemporaryFilesList;
  3869. FAutoOperation = false;
  3870. if (!RootTempDir.IsEmpty())
  3871. {
  3872. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3873. }
  3874. }
  3875. }
  3876. else
  3877. {
  3878. RemoteDirView->SaveSelection();
  3879. RemoteDirView->SaveSelectedNames();
  3880. try
  3881. {
  3882. if (Move)
  3883. {
  3884. Configuration->Usage->Inc("RemoteMove");
  3885. Terminal->MoveFiles(FileList, Target, FileMask);
  3886. }
  3887. else
  3888. {
  3889. Configuration->Usage->Inc("RemoteCopyDirect");
  3890. DebugAssert(DirectCopy);
  3891. DebugAssert(Session == FTerminal);
  3892. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3893. FTerminal->CommandSessionOpened ||
  3894. CommandSessionFallback())
  3895. {
  3896. Terminal->CopyFiles(FileList, Target, FileMask);
  3897. }
  3898. }
  3899. }
  3900. catch(...)
  3901. {
  3902. RemoteDirView->DiscardSavedSelection();
  3903. throw;
  3904. }
  3905. RemoteDirView->RestoreSelection();
  3906. }
  3907. }
  3908. return Result;
  3909. }
  3910. //---------------------------------------------------------------------------
  3911. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3912. const UnicodeString & Path, TRemoteProperties & Properties)
  3913. {
  3914. DebugAssert(!IsLocalBrowserMode());
  3915. Properties.Valid = Properties.Valid << vpEncrypt;
  3916. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3917. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3918. }
  3919. //---------------------------------------------------------------------------
  3920. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3921. {
  3922. Side = GetSide(Side);
  3923. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3924. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3925. UnicodeString Name = LoadStr(NEW_FOLDER);
  3926. int AllowedChanges =
  3927. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3928. bool SaveSettings = false;
  3929. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3930. {
  3931. TWindowLock Lock(this);
  3932. if (!IsSideLocalBrowser(Side))
  3933. {
  3934. if (SaveSettings)
  3935. {
  3936. GUIConfiguration->NewDirectoryProperties = Properties;
  3937. }
  3938. CreateRemoteDirectory(Name, Properties);
  3939. }
  3940. else
  3941. {
  3942. DirView(Side)->CreateDirectory(Name);
  3943. }
  3944. }
  3945. }
  3946. //---------------------------------------------------------------------------
  3947. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3948. {
  3949. TWindowLock Lock(this);
  3950. DirView(Side)->ExecuteHomeDirectory();
  3951. }
  3952. //---------------------------------------------------------------------------
  3953. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3954. {
  3955. DoOpenDirectoryDialog(odBrowse, Side);
  3956. }
  3957. //---------------------------------------------------------------------------
  3958. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3959. {
  3960. UnicodeString Path = Bookmark->GetSideDirectory(Side);
  3961. bool Result = !Path.IsEmpty();
  3962. if (Result)
  3963. {
  3964. // While we might get here when the session is closed (from location profiles),
  3965. // it's not a problem as the Path setter is noop then
  3966. DirView(Side)->Path = Path;
  3967. }
  3968. return Result;
  3969. }
  3970. //---------------------------------------------------------------------------
  3971. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3972. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3973. bool & Close)
  3974. {
  3975. // terminal can be already closed (e.g. dropped connection)
  3976. if (Terminal != NULL)
  3977. {
  3978. try
  3979. {
  3980. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  3981. }
  3982. catch(...)
  3983. {
  3984. if (!Terminal->Active)
  3985. {
  3986. Close = true;
  3987. }
  3988. throw;
  3989. }
  3990. }
  3991. }
  3992. //---------------------------------------------------------------------------
  3993. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  3994. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  3995. bool & Close)
  3996. {
  3997. // terminal can be already closed (e.g. dropped connection)
  3998. if (Terminal != NULL)
  3999. {
  4000. Configuration->Usage->Inc(L"ChecksumCalculated");
  4001. try
  4002. {
  4003. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4004. }
  4005. catch(...)
  4006. {
  4007. if (!Terminal->Active)
  4008. {
  4009. Close = true;
  4010. }
  4011. throw;
  4012. }
  4013. }
  4014. }
  4015. //---------------------------------------------------------------------------
  4016. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4017. {
  4018. bool Result;
  4019. if (!IsSideLocalBrowser(Side))
  4020. {
  4021. TRemoteTokenList * GroupList = NULL;
  4022. TRemoteTokenList * UserList = NULL;
  4023. try
  4024. {
  4025. TRemoteProperties CurrentProperties;
  4026. if (Terminal->LoadFilesProperties(FileList))
  4027. {
  4028. RemoteDirView->Invalidate();
  4029. }
  4030. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4031. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4032. if (CapableGroupChanging || CapableOwnerChanging)
  4033. {
  4034. if (CapableGroupChanging)
  4035. {
  4036. GroupList = Terminal->Groups->Duplicate();
  4037. }
  4038. if (CapableOwnerChanging)
  4039. {
  4040. UserList = Terminal->Users->Duplicate();
  4041. }
  4042. TRemoteDirectory * Files = Terminal->Files;
  4043. int Count = Files->Count;
  4044. if (Count > 100)
  4045. {
  4046. Count = 100;
  4047. }
  4048. for (int Index = 0; Index < Count; Index++)
  4049. {
  4050. TRemoteFile * File = Files->Files[Index];
  4051. if (CapableGroupChanging)
  4052. {
  4053. GroupList->AddUnique(File->Group);
  4054. }
  4055. if (CapableOwnerChanging)
  4056. {
  4057. UserList->AddUnique(File->Owner);
  4058. }
  4059. }
  4060. // if we haven't collected tokens for all files in current directory,
  4061. // make sure we collect them at least for all selected files.
  4062. // (note that so far the files in FileList has to be from current direcotry)
  4063. if (Count < Files->Count)
  4064. {
  4065. for (int Index = 0; Index < FileList->Count; Index++)
  4066. {
  4067. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4068. if (CapableGroupChanging)
  4069. {
  4070. GroupList->AddUnique(File->Group);
  4071. }
  4072. if (CapableOwnerChanging)
  4073. {
  4074. UserList->AddUnique(File->Owner);
  4075. }
  4076. }
  4077. }
  4078. }
  4079. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4080. int Flags = 0;
  4081. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4082. if (CapableOwnerChanging) Flags |= cpOwner;
  4083. if (CapableGroupChanging) Flags |= cpGroup;
  4084. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4085. if (Terminal->IsCapable[fcCalculatingChecksum])
  4086. {
  4087. CalculateChecksumEvent = CalculateChecksum;
  4088. }
  4089. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4090. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4091. TRemoteProperties NewProperties = CurrentProperties;
  4092. Result =
  4093. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4094. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4095. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4096. CalculateSize, CalculateChecksumEvent);
  4097. if (Result)
  4098. {
  4099. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4100. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4101. }
  4102. }
  4103. __finally
  4104. {
  4105. delete GroupList;
  4106. delete UserList;
  4107. }
  4108. }
  4109. else
  4110. {
  4111. DirView(Side)->DisplayPropertiesMenu();
  4112. Result = true;
  4113. }
  4114. return Result;
  4115. }
  4116. //---------------------------------------------------------------------------
  4117. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4118. {
  4119. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4120. {
  4121. FIgnoreNextDialogChar = Key;
  4122. }
  4123. Key = 0;
  4124. }
  4125. //---------------------------------------------------------------------------
  4126. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4127. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4128. {
  4129. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4130. if (Command != NULL)
  4131. {
  4132. KeyProcessed(Key, Shift);
  4133. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4134. {
  4135. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4136. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4137. false, false, const_cast<TCustomCommandType *>(Command));
  4138. }
  4139. }
  4140. }
  4141. //---------------------------------------------------------------------------
  4142. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4143. {
  4144. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4145. {
  4146. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4147. }
  4148. if (!DirView(osCurrent)->IsEditing())
  4149. {
  4150. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4151. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4152. {
  4153. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4154. if (((Action->ShortCut == KeyShortCut) ||
  4155. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4156. AllowedAction(Action, aaShortCut))
  4157. {
  4158. // Has to be called before the action as the dialog char is already in queue.
  4159. // So when the action consumes message queue, we already need to have the
  4160. // FIgnoreNextDialogChar set
  4161. KeyProcessed(Key, Shift);
  4162. // Reset reference to previous component (when menu/toolbar was clicked).
  4163. // Needed to detect that action was invoked by keyboard shortcut
  4164. // in TNonVisualDataModule::ExplorerActionsExecute
  4165. Action->ActionComponent = NULL;
  4166. Action->Execute();
  4167. return;
  4168. }
  4169. }
  4170. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4171. {
  4172. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4173. {
  4174. KeyProcessed(Key, Shift);
  4175. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4176. return;
  4177. }
  4178. }
  4179. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4180. {
  4181. KeyProcessed(Key, Shift);
  4182. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4183. }
  4184. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4185. if (IsCustomShortCut(CustomShortCut))
  4186. {
  4187. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4188. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4189. if (WinConfiguration->SharedBookmarks != NULL)
  4190. {
  4191. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4192. if ((Bookmark != NULL) &&
  4193. OpenBookmark(FCurrentSide, Bookmark))
  4194. {
  4195. KeyProcessed(Key, Shift);
  4196. }
  4197. }
  4198. }
  4199. }
  4200. TForm::KeyDown(Key, Shift);
  4201. }
  4202. //---------------------------------------------------------------------------
  4203. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4204. {
  4205. DebugAssert(Terminal != NULL);
  4206. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4207. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4208. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4209. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4210. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4211. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4212. // expanded from ?: to avoid memory leaks
  4213. if (SecurityEnabled)
  4214. {
  4215. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4216. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4217. }
  4218. else
  4219. {
  4220. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4221. }
  4222. if (FileSystemInfo.ProtocolName.IsEmpty())
  4223. {
  4224. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4225. }
  4226. else
  4227. {
  4228. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4229. }
  4230. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4231. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4232. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4233. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4234. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4235. UnicodeString CompressionStr = CSCompressionStr;
  4236. if (CSCompressionStr != SCCompressionStr)
  4237. {
  4238. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4239. }
  4240. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4241. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4242. UpdateStatusBar();
  4243. }
  4244. //---------------------------------------------------------------------------
  4245. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4246. {
  4247. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4248. DebugAssert(SessionStatusBar != NULL);
  4249. if (!HasActiveTerminal() || (Terminal->Status < ssOpened))
  4250. {
  4251. // note: (Terminal->Status < sshReady) currently never happens here,
  4252. // so STATUS_CONNECTING is never used
  4253. SessionStatusBar->SimplePanel = true;
  4254. SessionStatusBar->SimpleText = LoadStr(
  4255. !HasActiveTerminal() ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4256. }
  4257. else
  4258. {
  4259. DebugAssert(Terminal);
  4260. SessionStatusBar->SimplePanel = false;
  4261. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4262. if (!FNote.IsEmpty())
  4263. {
  4264. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4265. }
  4266. else
  4267. {
  4268. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4269. }
  4270. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4271. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4272. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4273. }
  4274. }
  4275. //---------------------------------------------------------------------------
  4276. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4277. {
  4278. Panel->Caption = L"";
  4279. }
  4280. //---------------------------------------------------------------------------
  4281. void __fastcall TCustomScpExplorerForm::Idle()
  4282. {
  4283. if (FShowing || FStandaloneEditing)
  4284. {
  4285. FEditorManager->Check();
  4286. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4287. // that needs to know if queue view is visible (and it may be closed after queue update)
  4288. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4289. }
  4290. if (FShowing)
  4291. {
  4292. if (!NonVisualDataModule->Busy &&
  4293. // Menu is opened or drag&drop is going on
  4294. (Mouse->Capture == NULL))
  4295. {
  4296. if (FRefreshRemoteDirectory)
  4297. {
  4298. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4299. {
  4300. Terminal->RefreshDirectory();
  4301. }
  4302. FRefreshRemoteDirectory = false;
  4303. }
  4304. if (FRefreshLocalDirectory)
  4305. {
  4306. ReloadLocalDirectory();
  4307. FRefreshLocalDirectory = false;
  4308. }
  4309. if (WinConfiguration->RefreshRemotePanel)
  4310. {
  4311. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4312. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4313. {
  4314. RemoteDirView->ReloadDirectory();
  4315. }
  4316. }
  4317. }
  4318. }
  4319. if (FShowing || FStandaloneEditing)
  4320. {
  4321. if (FQueueStatusInvalidated)
  4322. {
  4323. UpdateQueueStatus(false);
  4324. }
  4325. RefreshQueueItems();
  4326. }
  4327. if (FShowing)
  4328. {
  4329. UpdateStatusBar();
  4330. }
  4331. FIgnoreNextDialogChar = 0;
  4332. }
  4333. //---------------------------------------------------------------------------
  4334. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4335. {
  4336. try
  4337. {
  4338. FUserActionTimer->Enabled = false;
  4339. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4340. {
  4341. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4342. {
  4343. FPendingQueueActionItem->ProcessUserAction();
  4344. }
  4345. }
  4346. }
  4347. __finally
  4348. {
  4349. FPendingQueueActionItem = NULL;
  4350. }
  4351. }
  4352. //---------------------------------------------------------------------------
  4353. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4354. {
  4355. if (WinConfiguration->MinimizeToTray)
  4356. {
  4357. UpdateTrayIcon();
  4358. FTrayIcon->Visible = true;
  4359. if (Visible)
  4360. {
  4361. ShowWindow(Handle, SW_HIDE);
  4362. }
  4363. }
  4364. }
  4365. //---------------------------------------------------------------------------
  4366. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4367. {
  4368. // WORKAROUND
  4369. // When restoring maximized window from minimization,
  4370. // rarely some controls do not align properly.
  4371. // Two instances seen (both for Commander):
  4372. // - When restoring, window is temporarily narrower (not maximized),
  4373. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4374. // Once maximized already, top dock shinks back, but the session PageControl,
  4375. // do not align up, leaving space between TopDock and PageControl.
  4376. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4377. for (int Index = 0; Index < ControlCount; Index++)
  4378. {
  4379. RealignControl(Controls[Index]);
  4380. }
  4381. if (FTrayIcon->Visible)
  4382. {
  4383. FTrayIcon->Visible = false;
  4384. if (Visible)
  4385. {
  4386. ShowWindow(Handle, SW_SHOW);
  4387. }
  4388. }
  4389. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4390. {
  4391. FNeedSession = false;
  4392. NonVisualDataModule->StartBusy();
  4393. try
  4394. {
  4395. NeedSession(true);
  4396. }
  4397. __finally
  4398. {
  4399. NonVisualDataModule->EndBusy();
  4400. }
  4401. }
  4402. }
  4403. //---------------------------------------------------------------------------
  4404. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4405. {
  4406. FTrayIcon->Hint = GetMainForm()->Caption;
  4407. }
  4408. //---------------------------------------------------------------------------
  4409. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4410. {
  4411. UpdateTrayIcon();
  4412. }
  4413. //---------------------------------------------------------------------------
  4414. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4415. {
  4416. // workaround
  4417. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4418. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4419. // But WM_ACTIVATEAPP message can be received even when
  4420. // the main window is minimized to the tray and internal editor window is focused
  4421. // (after another application was previously active)
  4422. if (::IsIconic(Handle))
  4423. {
  4424. if (!IsAppIconic())
  4425. {
  4426. SetAppIconic(true);
  4427. }
  4428. }
  4429. ::ApplicationRestore();
  4430. Application->BringToFront();
  4431. }
  4432. //---------------------------------------------------------------------------
  4433. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4434. {
  4435. RestoreApp();
  4436. }
  4437. //---------------------------------------------------------------------------
  4438. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4439. {
  4440. if (OpenInNewWindow())
  4441. {
  4442. // todo: Pass FromSite
  4443. ExecuteNewInstance(SessionUrl);
  4444. }
  4445. else
  4446. {
  4447. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4448. }
  4449. }
  4450. //---------------------------------------------------------------------------
  4451. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4452. {
  4453. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4454. StoredSessions->NewSession(SessionName, SessionData);
  4455. // modified only, explicit
  4456. StoredSessions->Save(false, true);
  4457. // encode session name because of slashes in hierarchical sessions
  4458. return EncodeUrlString(SessionName);
  4459. }
  4460. //---------------------------------------------------------------------------
  4461. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4462. {
  4463. // current working directories become defaults here, what is not right
  4464. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4465. return SaveHiddenDuplicateSession(SessionData.get());
  4466. }
  4467. //---------------------------------------------------------------------------
  4468. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4469. {
  4470. if (OpenInNewWindow())
  4471. {
  4472. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4473. }
  4474. else
  4475. {
  4476. // current working directories become defaults here, what is not right
  4477. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4478. TTerminalManager * Manager = TTerminalManager::Instance();
  4479. TManagedTerminal * Terminal = Manager->NewManagedTerminal(SessionData.get());
  4480. Manager->ActiveTerminal = Terminal;
  4481. }
  4482. }
  4483. //---------------------------------------------------------------------------
  4484. void __fastcall TCustomScpExplorerForm::RenameSession()
  4485. {
  4486. UnicodeString Name = Terminal->SessionData->SessionName;
  4487. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4488. {
  4489. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4490. TSessionData::ValidateName(Name);
  4491. // This is inconsistent with how color (for example) is handled.
  4492. Terminal->SessionData->Name = Name;
  4493. UpdateControls();
  4494. // Add/Remove distinguishing paths from sessions of the same name.
  4495. DoTerminalListChanged();
  4496. }
  4497. }
  4498. //---------------------------------------------------------------------------
  4499. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4500. {
  4501. DebugAssert(Queue != NULL);
  4502. bool Result = Queue->IsEmpty;
  4503. if (!Result)
  4504. {
  4505. SetFocus();
  4506. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4507. }
  4508. return Result;
  4509. }
  4510. //---------------------------------------------------------------------------
  4511. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4512. {
  4513. return CanCloseQueue(FQueue);
  4514. }
  4515. //---------------------------------------------------------------------------
  4516. void __fastcall TCustomScpExplorerForm::CloseSession()
  4517. {
  4518. if (CanCloseQueue())
  4519. {
  4520. TTerminalManager::Instance()->FreeActiveTerminal();
  4521. }
  4522. }
  4523. //---------------------------------------------------------------------------
  4524. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4525. {
  4526. if (CanCloseQueue())
  4527. {
  4528. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4529. }
  4530. }
  4531. //---------------------------------------------------------------------------
  4532. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4533. {
  4534. DetachTerminal(Terminal);
  4535. RemoteDirView->Terminal = Terminal;
  4536. UpdateRemotePathComboBox(false);
  4537. UpdateControls();
  4538. }
  4539. //---------------------------------------------------------------------------
  4540. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4541. {
  4542. if (DebugAlwaysTrue(!Terminal->Active))
  4543. {
  4544. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4545. }
  4546. }
  4547. //---------------------------------------------------------------------------
  4548. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4549. {
  4550. if (OpenInNewWindow())
  4551. {
  4552. // encode session name because of slashes in hierarchical sessions
  4553. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4554. }
  4555. else
  4556. {
  4557. TTerminalManager * Manager = TTerminalManager::Instance();
  4558. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4559. Manager->ActiveTerminal = Terminal;
  4560. }
  4561. }
  4562. //---------------------------------------------------------------------------
  4563. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4564. {
  4565. TTerminalManager * Manager = TTerminalManager::Instance();
  4566. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4567. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4568. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4569. // FirstTerminal can be null, if some of the
  4570. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4571. {
  4572. FirstTerminal->Disconnected = true;
  4573. FirstTerminal->DisconnectedTemporarily = true;
  4574. }
  4575. Manager->ActiveTerminal = FirstTerminal;
  4576. }
  4577. //---------------------------------------------------------------------------
  4578. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4579. {
  4580. if (OpenInNewWindow())
  4581. {
  4582. ExecuteNewInstance(Name);
  4583. }
  4584. else
  4585. {
  4586. DoOpenFolderOrWorkspace(Name, true);
  4587. }
  4588. }
  4589. //---------------------------------------------------------------------------
  4590. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4591. bool &CanClose)
  4592. {
  4593. // See the comment in CloseApp()
  4594. if (NonVisualDataModule->Busy)
  4595. {
  4596. CanClose = false;
  4597. }
  4598. else if (Terminal != NULL)
  4599. {
  4600. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4601. {
  4602. unsigned int Result;
  4603. TMessageParams Params(mpNeverAskAgainCheck);
  4604. UnicodeString Message;
  4605. int Answers = qaOK | qaCancel;
  4606. if (TTerminalManager::Instance()->Count > 1)
  4607. {
  4608. if (!WinConfiguration->AutoSaveWorkspace)
  4609. {
  4610. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4611. }
  4612. else
  4613. {
  4614. Message = LoadStr(CLOSE_SESSIONS);
  4615. }
  4616. }
  4617. else
  4618. {
  4619. if (!WinConfiguration->AutoSaveWorkspace)
  4620. {
  4621. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4622. }
  4623. else
  4624. {
  4625. Message = LoadStr(CLOSE_SESSION);
  4626. }
  4627. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4628. }
  4629. UnicodeString Note;
  4630. if (WinConfiguration->AutoSaveWorkspace)
  4631. {
  4632. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4633. }
  4634. else
  4635. {
  4636. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4637. Answers = qaYes | qaNo | qaCancel;
  4638. }
  4639. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4640. SetFocus();
  4641. Result = MessageDialog(Message, qtConfirmation,
  4642. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4643. if (Result == qaNeverAskAgain)
  4644. {
  4645. WinConfiguration->ConfirmClosingSession = false;
  4646. }
  4647. if (Result == qaNo)
  4648. {
  4649. CanClose = SaveWorkspace(true);
  4650. // note that the workspace will be saved redundatly again from FormClose
  4651. }
  4652. else
  4653. {
  4654. CanClose =
  4655. (Result == qaOK) ||
  4656. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4657. (Result == qaNeverAskAgain);
  4658. }
  4659. }
  4660. if (CanClose)
  4661. {
  4662. CanClose = CanCloseQueue();
  4663. }
  4664. }
  4665. if (CanClose)
  4666. {
  4667. CanClose =
  4668. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4669. FEditorManager->CloseExternalFilesWithoutProcess();
  4670. if (CanClose)
  4671. {
  4672. while (CanClose && (FLocalEditors->Count > 0))
  4673. {
  4674. int PrevCount = FLocalEditors->Count;
  4675. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4676. CanClose = (FLocalEditors->Count < PrevCount);
  4677. }
  4678. if (CanClose)
  4679. {
  4680. CanClose = FEditorManager->Empty(true);
  4681. if (!CanClose)
  4682. {
  4683. SetFocus();
  4684. CanClose =
  4685. (MessageDialog(
  4686. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4687. }
  4688. }
  4689. }
  4690. }
  4691. }
  4692. //---------------------------------------------------------------------------
  4693. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4694. {
  4695. TForm * Form = dynamic_cast<TForm *>(Sender);
  4696. DebugAssert(Form != NULL);
  4697. Form->Close();
  4698. }
  4699. //---------------------------------------------------------------------------
  4700. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4701. {
  4702. TForm * Form = dynamic_cast<TForm *>(Sender);
  4703. delete Form;
  4704. }
  4705. //---------------------------------------------------------------------------
  4706. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4707. {
  4708. while (FLocalEditors->Count > 0)
  4709. {
  4710. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4711. }
  4712. }
  4713. //---------------------------------------------------------------------------
  4714. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4715. TObject *Sender)
  4716. {
  4717. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4718. try
  4719. {
  4720. SetProperties(osRemote, FileList);
  4721. }
  4722. __finally
  4723. {
  4724. delete FileList;
  4725. }
  4726. }
  4727. //---------------------------------------------------------------------------
  4728. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4729. {
  4730. if (value)
  4731. {
  4732. if (Component == fcCustomCommandsBand)
  4733. {
  4734. UpdateCustomCommandsToolbar();
  4735. }
  4736. if (Component == fcQueueFileList)
  4737. {
  4738. DebugAssert(!QueueFileListSplitter->Visible);
  4739. AdjustQueueLayout();
  4740. UpdateQueueFileList();
  4741. }
  4742. }
  4743. }
  4744. //---------------------------------------------------------------------------
  4745. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4746. {
  4747. int MinHeightLimit =
  4748. GetStaticQueuePanelComponentsHeight() +
  4749. QueueFileListSplitter->Height +
  4750. QueueFileList->Height +
  4751. GetMinQueueViewHeight();
  4752. if (QueuePanel->ClientHeight < MinHeightLimit)
  4753. {
  4754. QueuePanel->ClientHeight = MinHeightLimit;
  4755. }
  4756. }
  4757. //---------------------------------------------------------------------------
  4758. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4759. {
  4760. TControl * Control = GetComponent(Component);
  4761. DebugAssert(Control);
  4762. bool Changed = (Control->Visible != value);
  4763. if (Changed)
  4764. {
  4765. ComponentShowing(Component, value);
  4766. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4767. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4768. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4769. if (value)
  4770. {
  4771. int RemainingHeight = Control->Parent->ClientHeight;
  4772. int RemainingWidth = Control->Parent->ClientWidth;
  4773. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4774. {
  4775. TControl * ChildControl = Control->Parent->Controls[i];
  4776. if (ChildControl->Visible)
  4777. {
  4778. switch (ChildControl->Align)
  4779. {
  4780. case alTop:
  4781. case alBottom:
  4782. RemainingHeight -= ChildControl->Height;
  4783. break;
  4784. case alLeft:
  4785. case alRight:
  4786. RemainingWidth -= ChildControl->Width;
  4787. break;
  4788. }
  4789. }
  4790. }
  4791. int Reserve = ScaleByTextHeight(this, 32);
  4792. // queue in explorer, trees in commander
  4793. if (Control->Height > RemainingHeight - Reserve)
  4794. {
  4795. Control->Height = RemainingHeight / 2;
  4796. }
  4797. if (Control->Width > RemainingWidth - Reserve)
  4798. {
  4799. Control->Width = RemainingWidth / 2;
  4800. }
  4801. }
  4802. Control->Visible = value;
  4803. if (WasFocused && Visible)
  4804. {
  4805. DirView(osCurrent)->SetFocus();
  4806. }
  4807. FixControlsPlacement();
  4808. }
  4809. }
  4810. //---------------------------------------------------------------------------
  4811. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4812. {
  4813. TControl * Control = GetComponent(Component);
  4814. if (Control == NULL)
  4815. {
  4816. return false;
  4817. }
  4818. else
  4819. {
  4820. return Control->Visible;
  4821. }
  4822. }
  4823. //---------------------------------------------------------------------------
  4824. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4825. {
  4826. bool Result;
  4827. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4828. {
  4829. Result = !IsUWP();
  4830. }
  4831. else
  4832. {
  4833. Result = true;
  4834. }
  4835. return Result;
  4836. }
  4837. //---------------------------------------------------------------------------
  4838. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4839. {
  4840. if (DirView(osOther)->ItemFocused != NULL)
  4841. {
  4842. DirView(osOther)->ItemFocused->MakeVisible(false);
  4843. }
  4844. QueueSplitter->Visible = QueuePanel->Visible;
  4845. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4846. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4847. TControl * QueueControlsOrder[] =
  4848. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4849. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4850. }
  4851. //---------------------------------------------------------------------------
  4852. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4853. {
  4854. switch (Component) {
  4855. case fcStatusBar: return RemoteStatusBar;
  4856. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4857. case fcQueueView: return QueuePanel;
  4858. case fcQueueToolbar: return QueueDock;
  4859. case fcRemoteTree: return RemoteDrivePanel;
  4860. case fcSessionsTabs: return SessionsPageControl;
  4861. case fcQueueFileList: return QueueFileList;
  4862. default: return NULL;
  4863. }
  4864. }
  4865. //---------------------------------------------------------------------------
  4866. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4867. TObject *Sender, TListColumn *Column, TPoint &Point)
  4868. {
  4869. DebugAssert(NonVisualDataModule && Column && Sender);
  4870. NonVisualDataModule->ListColumn = Column;
  4871. TPopupMenu * DirViewColumnMenu;
  4872. if (dynamic_cast<TUnixDirView *>(Sender) != NULL)
  4873. {
  4874. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4875. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4876. (Column->Index == uvName);
  4877. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4878. (Column->Index == uvSize);
  4879. }
  4880. else
  4881. {
  4882. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4883. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4884. (Column->Index == dvName);
  4885. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4886. (Column->Index == dvSize);
  4887. }
  4888. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4889. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4890. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4891. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4892. }
  4893. //---------------------------------------------------------------------------
  4894. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4895. TObject *Sender, TListItem *Item, bool &AllowExec)
  4896. {
  4897. DoDirViewExecFile(Sender, Item, AllowExec);
  4898. }
  4899. //---------------------------------------------------------------------------
  4900. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4901. TListItem * Item, bool & AllowExec)
  4902. {
  4903. DebugAssert(Sender && Item && Configuration);
  4904. DebugAssert(AllowExec);
  4905. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4906. bool Remote = (ADirView == DirView(osRemote)) && !IsSideLocalBrowser(osRemote);
  4907. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks;
  4908. TOperationSide Side = (Remote ? osRemote : osLocal); // TODO
  4909. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4910. // on files only (not directories)
  4911. // and only when symlinks are resolved (apply to remote panel only)
  4912. if (!ADirView->ItemIsDirectory(Item) &&
  4913. (ResolvedSymlinks || FForceExecution || Terminal->IsEncryptingFiles()))
  4914. {
  4915. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4916. !FForceExecution &&
  4917. (ResolvedSymlinks || Terminal->IsEncryptingFiles()))
  4918. {
  4919. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4920. {
  4921. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4922. UnlockWindow();
  4923. try
  4924. {
  4925. ExecuteFileOperation(
  4926. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4927. }
  4928. __finally
  4929. {
  4930. LockWindow();
  4931. }
  4932. AllowExec = false;
  4933. }
  4934. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4935. {
  4936. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4937. {
  4938. ExecuteFile(Side, efDefaultEditor);
  4939. AllowExec = false;
  4940. }
  4941. }
  4942. else
  4943. {
  4944. DebugFail();
  4945. }
  4946. }
  4947. // if we have not done anything special, fall back to default behavior
  4948. if (AllowExec)
  4949. {
  4950. if (Remote && !WinConfiguration->DisableOpenEdit)
  4951. {
  4952. ExecuteFile(osRemote, efShell);
  4953. AllowExec = false;
  4954. }
  4955. }
  4956. }
  4957. }
  4958. //---------------------------------------------------------------------------
  4959. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4960. {
  4961. return ((Side == osRemote) || (Side == osCurrent));
  4962. }
  4963. //---------------------------------------------------------------------------
  4964. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  4965. {
  4966. DebugFail();
  4967. }
  4968. //---------------------------------------------------------------------------
  4969. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  4970. {
  4971. DebugFail();
  4972. }
  4973. //---------------------------------------------------------------------------
  4974. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  4975. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  4976. {
  4977. TSynchronizeParamType Params;
  4978. Params.LocalDirectory = LocalDirectory;
  4979. Params.RemoteDirectory = RemoteDirectory;
  4980. int UnusedParams =
  4981. (GUIConfiguration->SynchronizeParams &
  4982. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize));
  4983. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  4984. Params.Options = GUIConfiguration->SynchronizeOptions;
  4985. bool SaveSettings = false;
  4986. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  4987. &DoSynchronizeTooManyDirectories);
  4988. DebugAssert(FSynchronizeController == NULL);
  4989. FSynchronizeController = &Controller;
  4990. bool Result;
  4991. try
  4992. {
  4993. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4994. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  4995. int Options =
  4996. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  4997. DebugAssert(FOnFeedSynchronizeError == NULL);
  4998. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  4999. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5000. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5001. if (Result)
  5002. {
  5003. if (SaveSettings)
  5004. {
  5005. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5006. GUIConfiguration->SynchronizeOptions = Params.Options;
  5007. }
  5008. else
  5009. {
  5010. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5011. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5012. FLAGSET(Params.Options, soSynchronize))
  5013. {
  5014. GUIConfiguration->SynchronizeOptions =
  5015. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5016. soSynchronize;
  5017. }
  5018. }
  5019. LocalDirectory = Params.LocalDirectory;
  5020. RemoteDirectory = Params.RemoteDirectory;
  5021. }
  5022. }
  5023. __finally
  5024. {
  5025. FSynchronizeController = NULL;
  5026. DebugAssert(FOnFeedSynchronizeError == NULL);
  5027. FOnFeedSynchronizeError = NULL;
  5028. }
  5029. return Result;
  5030. }
  5031. //---------------------------------------------------------------------------
  5032. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5033. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5034. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5035. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5036. TSynchronizeOptions * Options, bool Full)
  5037. {
  5038. // Keep-up-to-date mode
  5039. if (Terminal->Status == ssOpened)
  5040. {
  5041. try
  5042. {
  5043. int PParams = Params.Params;
  5044. if (!Full)
  5045. {
  5046. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5047. if (FLAGSET(Params.Options, soRecurse))
  5048. {
  5049. PParams |= TTerminal::spSubDirs;
  5050. }
  5051. }
  5052. else
  5053. {
  5054. // if keepuptodate is non-recursive,
  5055. // full sync before has to be non-recursive as well
  5056. if (FLAGCLEAR(Params.Options, soRecurse))
  5057. {
  5058. PParams |= TTerminal::spNoRecurse;
  5059. }
  5060. }
  5061. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5062. PParams, Checklist, Options);
  5063. }
  5064. catch (Exception & E)
  5065. {
  5066. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5067. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5068. {
  5069. // noop, already logged in MoreMessageDialog
  5070. }
  5071. else
  5072. {
  5073. ShowExtendedExceptionEx(Terminal, &E);
  5074. throw;
  5075. }
  5076. }
  5077. }
  5078. }
  5079. //---------------------------------------------------------------------------
  5080. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5081. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5082. const UnicodeString ErrorStr)
  5083. {
  5084. if (!Directory.IsEmpty())
  5085. {
  5086. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5087. }
  5088. else
  5089. {
  5090. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5091. }
  5092. }
  5093. //---------------------------------------------------------------------------
  5094. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5095. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5096. {
  5097. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5098. {
  5099. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5100. }
  5101. else
  5102. {
  5103. TMessageParams Params(mpNeverAskAgainCheck);
  5104. unsigned int Result = MessageDialog(
  5105. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5106. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5107. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5108. {
  5109. MaxDirectories *= 2;
  5110. if (Result == qaNeverAskAgain)
  5111. {
  5112. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5113. }
  5114. }
  5115. else
  5116. {
  5117. Abort();
  5118. }
  5119. }
  5120. }
  5121. //---------------------------------------------------------------------------
  5122. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5123. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5124. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5125. TSynchronizeOptions * Options)
  5126. {
  5127. // Keep-up-to-date mode
  5128. DebugAssert(!FAutoOperation);
  5129. void * BatchStorage;
  5130. BatchStart(BatchStorage);
  5131. FAutoOperation = true;
  5132. bool AnyOperation = false;
  5133. TDateTime StartTime = Now();
  5134. TSynchronizeChecklist * AChecklist = NULL;
  5135. try
  5136. {
  5137. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5138. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5139. {
  5140. FSynchronizeProgressForm->Start();
  5141. }
  5142. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5143. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5144. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5145. Options);
  5146. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5147. SAFE_DESTROY(FSynchronizeProgressForm);
  5148. AnyOperation = (AChecklist->CheckedCount > 0);
  5149. if (AnyOperation)
  5150. {
  5151. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5152. CreateProgressForm(&SynchronizeProgress);
  5153. try
  5154. {
  5155. Terminal->SynchronizeApply(
  5156. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5157. SynchronizeProcessedItem, NULL, NULL, NULL);
  5158. }
  5159. __finally
  5160. {
  5161. DestroyProgressForm();
  5162. }
  5163. }
  5164. }
  5165. __finally
  5166. {
  5167. if (Checklist == NULL)
  5168. {
  5169. delete AChecklist;
  5170. }
  5171. else
  5172. {
  5173. *Checklist = AChecklist;
  5174. }
  5175. FAutoOperation = false;
  5176. SAFE_DESTROY(FSynchronizeProgressForm);
  5177. BatchEnd(BatchStorage);
  5178. ReloadLocalDirectory();
  5179. if (AnyOperation)
  5180. {
  5181. OperationComplete(StartTime);
  5182. }
  5183. }
  5184. }
  5185. //---------------------------------------------------------------------------
  5186. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5187. {
  5188. // can be called from command line
  5189. return Visible &&
  5190. ((DirView(osRemote)->SelCount > 0) ||
  5191. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5192. }
  5193. //---------------------------------------------------------------------------
  5194. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5195. {
  5196. LogSynchronizeEvent(Terminal, Message);
  5197. }
  5198. //---------------------------------------------------------------------------
  5199. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5200. int Params, TSynchronizeOptions & Options)
  5201. {
  5202. DebugAssert(!IsLocalBrowserMode());
  5203. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5204. {
  5205. Options.Filter = new TStringList();
  5206. Options.Filter->CaseSensitive = false;
  5207. Options.Filter->Duplicates = Types::dupAccept;
  5208. if (DirView(osRemote)->SelCount > 0)
  5209. {
  5210. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5211. }
  5212. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5213. {
  5214. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5215. }
  5216. Options.Filter->Sort();
  5217. }
  5218. }
  5219. //---------------------------------------------------------------------------
  5220. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5221. {
  5222. TCopyParamType Defaults;
  5223. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5224. ConfigStorage->AccessMode = smRead;
  5225. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5226. {
  5227. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5228. }
  5229. ConfigStorage.reset(NULL);
  5230. std::unique_ptr<TStringList> Options(new TStringList());
  5231. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5232. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5233. UnicodeString Result;
  5234. if (Options->Count > 0)
  5235. {
  5236. Result =
  5237. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5238. }
  5239. return Result;
  5240. }
  5241. //---------------------------------------------------------------------------
  5242. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5243. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5244. {
  5245. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5246. UnicodeString AdditionalParams =
  5247. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5248. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5249. SerializeCopyParamForCommandLine(CopyParams),
  5250. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5251. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5252. ExecuteNewInstance(SessionName, AdditionalParams);
  5253. }
  5254. //---------------------------------------------------------------------------
  5255. struct TSynchronizeParams
  5256. {
  5257. UnicodeString LocalDirectory;
  5258. UnicodeString RemoteDirectory;
  5259. TSynchronizeMode Mode;
  5260. TSynchronizeChecklist * Checklist;
  5261. int Params;
  5262. TCopyParamType * CopyParam;
  5263. TDateTime CollectElapsed;
  5264. TDateTime * StartTime;
  5265. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5266. };
  5267. //---------------------------------------------------------------------------
  5268. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5269. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5270. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5271. {
  5272. DebugAssert(!FAutoOperation);
  5273. void * BatchStorage;
  5274. BatchStart(BatchStorage);
  5275. FAutoOperation = true;
  5276. TFileOperationStatistics Statistics;
  5277. TDateTime Start = Now();
  5278. try
  5279. {
  5280. Params.OnProcessedItem = OnProcessedItem;
  5281. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5282. CreateProgressForm(&SynchronizeProgress);
  5283. Terminal->SynchronizeApply(
  5284. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5285. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5286. &Statistics);
  5287. }
  5288. __finally
  5289. {
  5290. Params.OnProcessedItem = NULL;
  5291. FAutoOperation = false;
  5292. DestroyProgressForm();
  5293. BatchEnd(BatchStorage);
  5294. ReloadLocalDirectory();
  5295. }
  5296. if (WinConfiguration->SynchronizeSummary)
  5297. {
  5298. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5299. // The statistics should be 0 anyway in this case
  5300. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5301. {
  5302. Message += L"\n";
  5303. if (Statistics.FilesUploaded > 0)
  5304. {
  5305. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5306. }
  5307. if (Statistics.FilesDownloaded > 0)
  5308. {
  5309. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5310. }
  5311. if (Statistics.FilesDeletedLocal > 0)
  5312. {
  5313. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5314. }
  5315. if (Statistics.FilesDeletedRemote > 0)
  5316. {
  5317. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5318. }
  5319. }
  5320. TDateTime Elapsed = (Now() - Start);
  5321. Message +=
  5322. L"\n" +
  5323. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5324. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5325. TMessageParams Params(mpNeverAskAgainCheck);
  5326. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5327. if (Result == qaNeverAskAgain)
  5328. {
  5329. WinConfiguration->SynchronizeSummary = false;
  5330. }
  5331. }
  5332. }
  5333. //---------------------------------------------------------------------------
  5334. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5335. {
  5336. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5337. {
  5338. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5339. }
  5340. // Not set in keep-up-to-date mode - Synchronize() method
  5341. if (Token != NULL)
  5342. {
  5343. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5344. if (Params.OnProcessedItem != NULL)
  5345. {
  5346. Params.OnProcessedItem(NULL, ChecklistItem);
  5347. }
  5348. }
  5349. }
  5350. //---------------------------------------------------------------------------
  5351. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5352. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5353. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5354. {
  5355. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5356. *Params.StartTime = Now();
  5357. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5358. }
  5359. //---------------------------------------------------------------------------
  5360. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5361. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5362. {
  5363. // terminal can be already closed (e.g. dropped connection)
  5364. if (Terminal != NULL)
  5365. {
  5366. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5367. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5368. }
  5369. }
  5370. //---------------------------------------------------------------------------
  5371. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5372. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5373. {
  5374. DebugAssert(!IsLocalBrowserMode());
  5375. TAutoBatch AutoBatch(this);
  5376. TAutoFlag AutoOperationFlag(FAutoOperation);
  5377. if (Side == osRemote)
  5378. {
  5379. std::unique_ptr<TStrings> FileList(new TStringList());
  5380. FileList->AddObject(FileName, RemoteFile);
  5381. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5382. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5383. RemoteDirView->SaveSelection();
  5384. RemoteDirView->SaveSelectedNames();
  5385. try
  5386. {
  5387. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5388. }
  5389. catch(...)
  5390. {
  5391. RemoteDirView->DiscardSavedSelection();
  5392. throw;
  5393. }
  5394. RemoteDirView->RestoreSelection();
  5395. }
  5396. else if (DebugAlwaysTrue(Side == osLocal))
  5397. {
  5398. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5399. {
  5400. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5401. }
  5402. UnicodeString Directory = ExtractFileDir(FileName);
  5403. ReloadLocalDirectory(Directory);
  5404. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5405. if (!SamePaths(Directory, NewDirectory))
  5406. {
  5407. ReloadLocalDirectory(NewDirectory);
  5408. }
  5409. }
  5410. }
  5411. //---------------------------------------------------------------------------
  5412. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5413. {
  5414. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5415. if (Side == osLocal)
  5416. {
  5417. if (Action == TSynchronizeChecklist::saDownloadNew)
  5418. {
  5419. OpenFolderInExplorer(LocalPath);
  5420. }
  5421. else
  5422. {
  5423. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5424. }
  5425. }
  5426. else if (DebugAlwaysTrue(Side == osRemote))
  5427. {
  5428. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5429. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5430. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5431. if (!LocalPath.IsEmpty())
  5432. {
  5433. SessionData->LocalDirectory = LocalPath;
  5434. }
  5435. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5436. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5437. }
  5438. }
  5439. //---------------------------------------------------------------------------
  5440. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5441. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5442. const TCopyParamType * CopyParams)
  5443. {
  5444. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5445. UnicodeString AdditionalParams =
  5446. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5447. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5448. SerializeCopyParamForCommandLine(CopyParams),
  5449. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5450. LocalDirectory, RemoteDirectory, Mode, Params));
  5451. ExecuteNewInstance(SessionName, AdditionalParams);
  5452. }
  5453. //---------------------------------------------------------------------------
  5454. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5455. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5456. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5457. {
  5458. int Result;
  5459. bool SaveSettings = false;
  5460. int Options =
  5461. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5462. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5463. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5464. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5465. bool Continue =
  5466. (UseDefaults == 0) ||
  5467. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5468. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5469. if (Continue)
  5470. {
  5471. Configuration->Usage->Inc(L"Synchronizations");
  5472. UpdateCopyParamCounters(CopyParam);
  5473. TSynchronizeOptions SynchronizeOptions;
  5474. GetSynchronizeOptions(Params, SynchronizeOptions);
  5475. if (SaveSettings)
  5476. {
  5477. GUIConfiguration->SynchronizeParams = Params;
  5478. }
  5479. else
  5480. {
  5481. SaveMode = false;
  5482. }
  5483. TDateTime StartTime = Now();
  5484. TSynchronizeChecklist * Checklist = NULL;
  5485. try
  5486. {
  5487. DebugAssert(!FAutoOperation);
  5488. FAutoOperation = true;
  5489. try
  5490. {
  5491. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5492. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5493. int Files = -1;
  5494. if (DataList->Count >= 1)
  5495. {
  5496. Files = StrToIntDef(DataList->Strings[0], Files);
  5497. }
  5498. else
  5499. {
  5500. DataList->Add(UnicodeString());
  5501. }
  5502. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5503. FSynchronizeProgressForm->Start();
  5504. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5505. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5506. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5507. &SynchronizeOptions);
  5508. if (Terminal->SessionData->CacheDirectories)
  5509. {
  5510. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5511. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5512. }
  5513. }
  5514. __finally
  5515. {
  5516. FAutoOperation = false;
  5517. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5518. SAFE_DESTROY(FSynchronizeProgressForm);
  5519. }
  5520. TSynchronizeParams SynchronizeParams;
  5521. SynchronizeParams.LocalDirectory = LocalDirectory;
  5522. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5523. SynchronizeParams.Mode = Mode;
  5524. SynchronizeParams.CopyParam = &CopyParam;
  5525. SynchronizeParams.Params = Params;
  5526. SynchronizeParams.Checklist = Checklist;
  5527. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5528. SynchronizeParams.StartTime = &StartTime;
  5529. SynchronizeParams.OnProcessedItem = NULL;
  5530. Result = Checklist->Count;
  5531. if (Checklist->Count > 0)
  5532. {
  5533. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5534. {
  5535. if (!DoSynchronizeChecklistDialog(
  5536. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5537. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5538. {
  5539. Result = -1;
  5540. }
  5541. }
  5542. else
  5543. {
  5544. FullSynchronize(SynchronizeParams, NULL, NULL);
  5545. }
  5546. }
  5547. else
  5548. {
  5549. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5550. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5551. }
  5552. }
  5553. __finally
  5554. {
  5555. delete Checklist;
  5556. }
  5557. OperationComplete(StartTime);
  5558. }
  5559. else
  5560. {
  5561. Result = -1;
  5562. }
  5563. return Result;
  5564. }
  5565. //---------------------------------------------------------------------------
  5566. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5567. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5568. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5569. {
  5570. if (Collect)
  5571. {
  5572. DebugAssert(FSynchronizeProgressForm != NULL);
  5573. if (!FSynchronizeProgressForm->Started)
  5574. {
  5575. FSynchronizeProgressForm->Start();
  5576. }
  5577. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5578. SetTaskbarListProgressValue(CompareProgress);
  5579. }
  5580. else
  5581. {
  5582. DebugAssert(FSynchronizeProgressForm == NULL);
  5583. DebugAssert(FProgressForm != NULL);
  5584. }
  5585. }
  5586. //---------------------------------------------------------------------------
  5587. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5588. {
  5589. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5590. TRemoteFile * File = NULL;
  5591. Terminal->ReadFile(FullFileName, File);
  5592. if (File != NULL)
  5593. {
  5594. std::unique_ptr<TRemoteFile> FileOwner(File);
  5595. TAutoFlag Flag(FStandaloneEditing);
  5596. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5597. Application->ShowMainForm = false;
  5598. Application->Run();
  5599. }
  5600. }
  5601. //---------------------------------------------------------------------------
  5602. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5603. {
  5604. DebugFail();
  5605. }
  5606. //---------------------------------------------------------------------------
  5607. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5608. {
  5609. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5610. SessionData->Assign(Terminal->SessionData);
  5611. UpdateSessionData(SessionData.get());
  5612. Terminal->UpdateSessionCredentials(SessionData.get());
  5613. if (!Terminal->SessionData->HasSessionName())
  5614. {
  5615. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5616. // once IsWorkspace is cleared
  5617. SessionData->Name = UnicodeString();
  5618. SessionData->IsWorkspace = false;
  5619. }
  5620. return SessionData.release();
  5621. }
  5622. //---------------------------------------------------------------------------
  5623. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5624. {
  5625. TSessionData * SessionData = CloneCurrentSessionData();
  5626. try
  5627. {
  5628. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5629. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5630. }
  5631. __finally
  5632. {
  5633. delete SessionData;
  5634. }
  5635. }
  5636. //---------------------------------------------------------------------------
  5637. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5638. {
  5639. TTerminalManager * Manager = TTerminalManager::Instance();
  5640. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5641. if (DebugAlwaysTrue(Terminal != NULL))
  5642. {
  5643. // Update (Managed)Terminal->StateData
  5644. UpdateTerminal(Terminal);
  5645. }
  5646. Manager->SaveWorkspace(DataList.get());
  5647. return DataList.release();
  5648. }
  5649. //---------------------------------------------------------------------------
  5650. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5651. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5652. {
  5653. WinConfiguration->LastWorkspace = Name;
  5654. if (!SavePasswords)
  5655. {
  5656. for (int Index = 0; Index < DataList->Count; Index++)
  5657. {
  5658. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5659. if (SessionData->Link.IsEmpty())
  5660. {
  5661. SessionData->ClearSessionPasswords();
  5662. }
  5663. }
  5664. }
  5665. StoredSessions->NewWorkspace(Name, DataList);
  5666. // modified only
  5667. StoredSessions->Save(false, Explicit);
  5668. }
  5669. //---------------------------------------------------------------------------
  5670. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5671. {
  5672. return
  5673. DefaultStr(WinConfiguration->LastWorkspace,
  5674. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5675. }
  5676. //---------------------------------------------------------------------------
  5677. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5678. {
  5679. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5680. bool AnyNonStoredSessionWithPassword = false;
  5681. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5682. bool AllNonStoredSessionsAnonymous = true;
  5683. TTerminalManager * Manager = TTerminalManager::Instance();
  5684. for (int Index = 0; Index < DataList->Count; Index++)
  5685. {
  5686. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5687. if (SessionData->Link.IsEmpty())
  5688. {
  5689. if (SessionData->HasAnySessionPassword())
  5690. {
  5691. AnyNonStoredSessionWithPassword = true;
  5692. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5693. {
  5694. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5695. }
  5696. }
  5697. if (!SameText(SessionData->UserName, AnonymousUserName))
  5698. {
  5699. AllNonStoredSessionsAnonymous = false;
  5700. }
  5701. }
  5702. }
  5703. bool SavePasswords;
  5704. bool * PSavePasswords;
  5705. bool NotRecommendedSavingPasswords =
  5706. !CustomWinConfiguration->UseMasterPassword &&
  5707. !AllNonStoredSessionsAnonymous;
  5708. if (Configuration->DisablePasswordStoring ||
  5709. !AnyNonStoredSessionWithPassword)
  5710. {
  5711. PSavePasswords = NULL;
  5712. SavePasswords = false;
  5713. }
  5714. else
  5715. {
  5716. PSavePasswords = &SavePasswords;
  5717. SavePasswords =
  5718. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5719. !NotRecommendedSavingPasswords;
  5720. }
  5721. UnicodeString Name = WorkspaceName();
  5722. bool CreateShortcut = false;
  5723. bool Result =
  5724. DoSaveWorkspaceDialog(
  5725. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5726. EnableAutoSave);
  5727. if (Result)
  5728. {
  5729. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5730. if (CreateShortcut)
  5731. {
  5732. TOperationVisualizer Visualizer;
  5733. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5734. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5735. }
  5736. if (EnableAutoSave)
  5737. {
  5738. WinConfiguration->AutoSaveWorkspace = true;
  5739. WinConfiguration->AutoWorkspace = Name;
  5740. if (PSavePasswords != NULL)
  5741. {
  5742. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5743. }
  5744. }
  5745. }
  5746. return Result;
  5747. }
  5748. //---------------------------------------------------------------------------
  5749. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5750. {
  5751. DebugAssert(!IsLocalBrowserMode());
  5752. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5753. if (WinConfiguration->PreservePanelState)
  5754. {
  5755. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5756. }
  5757. UpdateSessionData(Terminal->StateData);
  5758. }
  5759. //---------------------------------------------------------------------------
  5760. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5761. {
  5762. // Keep in sync with TSessionData::CopyStateData
  5763. DebugAssert(!IsLocalBrowserMode());
  5764. DebugAssert(Data != NULL);
  5765. // This is inconsistent with how color (for example) is handled.
  5766. Data->Name = Terminal->SessionData->Name;
  5767. // cannot use RemoteDirView->Path, because it is empty if connection
  5768. // was already closed
  5769. // also only peek, we may not be connected at all atm
  5770. // so make sure we do not try retrieving current directory from the server
  5771. // (particularly with FTP)
  5772. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5773. if (!ACurrentDirectory.IsEmpty())
  5774. {
  5775. Data->RemoteDirectory = ACurrentDirectory;
  5776. }
  5777. Data->Color = SessionColor;
  5778. }
  5779. //---------------------------------------------------------------------------
  5780. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5781. {
  5782. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5783. DebugAssert(Toolbar != NULL);
  5784. for (int i = 0; i < Toolbar->Items->Count; i++)
  5785. {
  5786. TTBXCustomDropDownItem * DropDownItem;
  5787. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5788. if (DropDownItem != NULL)
  5789. {
  5790. ToolbarItemResize(DropDownItem,
  5791. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5792. Toolbar->NonClientWidth);
  5793. break;
  5794. }
  5795. }
  5796. }
  5797. //---------------------------------------------------------------------------
  5798. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5799. {
  5800. Item->EditWidth = Width;
  5801. }
  5802. //---------------------------------------------------------------------------
  5803. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5804. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5805. {
  5806. for (int i = 0; i < Toolbar->Items->Count; i++)
  5807. {
  5808. TTBXCustomDropDownItem * DropDownItem;
  5809. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5810. if (DropDownItem != NULL)
  5811. {
  5812. ASize.x -= DropDownItem->EditWidth;
  5813. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5814. }
  5815. }
  5816. }
  5817. //---------------------------------------------------------------------------
  5818. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5819. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5820. {
  5821. if (WinConfiguration->DDWarnLackOfTempSpace)
  5822. {
  5823. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5824. if (!ADrive.IsEmpty())
  5825. {
  5826. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5827. DebugAssert(RequiredSpace >= 0);
  5828. __int64 RequiredWithReserve;
  5829. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5830. if (FreeSpace < RequiredWithReserve)
  5831. {
  5832. unsigned int Result;
  5833. TMessageParams Params(mpNeverAskAgainCheck);
  5834. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5835. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5836. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5837. if (Result == qaNeverAskAgain)
  5838. {
  5839. WinConfiguration->DDWarnLackOfTempSpace = false;
  5840. }
  5841. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5842. }
  5843. }
  5844. }
  5845. }
  5846. //---------------------------------------------------------------------------
  5847. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5848. {
  5849. DoOpenDirectoryDialog(odAddBookmark, Side);
  5850. }
  5851. //---------------------------------------------------------------------------
  5852. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5853. {
  5854. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5855. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5856. try
  5857. {
  5858. TCustomDirView * DView = DirView(Side);
  5859. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5860. {
  5861. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5862. }
  5863. }
  5864. catch (...)
  5865. {
  5866. delete VisitedDirectories;
  5867. throw;
  5868. }
  5869. return VisitedDirectories;
  5870. }
  5871. //---------------------------------------------------------------------------
  5872. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5873. TOpenDirectoryMode Mode, TOperationSide Side)
  5874. {
  5875. bool Continue = true;
  5876. if (Mode == odAddBookmark)
  5877. {
  5878. TMessageParams Params(mpNeverAskAgainCheck);
  5879. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5880. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5881. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5882. unsigned int Answer =
  5883. MessageDialog(Message,
  5884. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5885. if (Answer == qaNeverAskAgain)
  5886. {
  5887. Continue = true;
  5888. WinConfiguration->UseSharedBookmarks = true;
  5889. }
  5890. else if (Answer == qaOK)
  5891. {
  5892. Continue = true;
  5893. WinConfiguration->UseSharedBookmarks = false;
  5894. }
  5895. else
  5896. {
  5897. Continue = false;
  5898. }
  5899. }
  5900. if (Continue)
  5901. {
  5902. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5903. try
  5904. {
  5905. UnicodeString Name = DirView(Side)->PathName;
  5906. bool Repeat;
  5907. do
  5908. {
  5909. Repeat = false;
  5910. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5911. // do not allow switching to location profiles,
  5912. // if we are not connected
  5913. HasDirView[osLocal] && (Terminal != NULL)))
  5914. {
  5915. TWindowLock Lock(this);
  5916. if (!TryOpenDirectory(Side, Name))
  5917. {
  5918. Repeat = true;
  5919. Mode = odBrowse;
  5920. }
  5921. }
  5922. }
  5923. while (Repeat);
  5924. }
  5925. __finally
  5926. {
  5927. delete VisitedDirectories;
  5928. }
  5929. }
  5930. }
  5931. //---------------------------------------------------------------------------
  5932. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5933. {
  5934. DebugAssert(!FTerminal->CommandSessionOpened);
  5935. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5936. }
  5937. //---------------------------------------------------------------------------
  5938. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5939. {
  5940. bool Result = FTerminal->IsCapable[Capability] ||
  5941. FTerminal->CommandSessionOpened;
  5942. if (!Result)
  5943. {
  5944. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5945. if (!GUIConfiguration->ConfirmCommandSession)
  5946. {
  5947. Result = true;
  5948. }
  5949. else
  5950. {
  5951. TMessageParams Params(mpNeverAskAgainCheck);
  5952. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5953. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5954. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5955. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5956. if (Answer == qaNeverAskAgain)
  5957. {
  5958. GUIConfiguration->ConfirmCommandSession = false;
  5959. Result = true;
  5960. }
  5961. else if (Answer == qaOK)
  5962. {
  5963. Result = true;
  5964. }
  5965. }
  5966. if (Result)
  5967. {
  5968. Result = CommandSessionFallback();
  5969. }
  5970. }
  5971. return Result;
  5972. }
  5973. //---------------------------------------------------------------------------
  5974. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  5975. {
  5976. if (EnsureCommandSessionFallback(fcAnyCommand))
  5977. {
  5978. DoConsoleDialog(Terminal, Command);
  5979. }
  5980. }
  5981. //---------------------------------------------------------------------------
  5982. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  5983. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  5984. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  5985. {
  5986. if (!IsSideLocalBrowser(osRemote) &&
  5987. IsFileControl(DropSourceControl, osRemote) &&
  5988. (FDDExtMapFile != NULL))
  5989. {
  5990. Accept = true;
  5991. }
  5992. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  5993. DebugAssert(FDDTargetControl != NULL);
  5994. }
  5995. //---------------------------------------------------------------------------
  5996. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  5997. _di_IDataObject DataObj, int KeyState,
  5998. const TPoint & Point, int & Effect, bool & Accept)
  5999. {
  6000. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6001. }
  6002. //---------------------------------------------------------------------------
  6003. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6004. _di_IDataObject DataObj, int KeyState,
  6005. const TPoint & Point, int & Effect, bool & Accept)
  6006. {
  6007. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6008. }
  6009. //---------------------------------------------------------------------------
  6010. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6011. TObject * Sender)
  6012. {
  6013. DebugUsedParam(Sender);
  6014. DebugAssert(FDDTargetControl == Sender);
  6015. FDDTargetControl = NULL;
  6016. }
  6017. //---------------------------------------------------------------------------
  6018. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6019. {
  6020. FileControlDDDragLeave(SessionsPageControl);
  6021. }
  6022. //---------------------------------------------------------------------------
  6023. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6024. {
  6025. FileControlDDDragLeave(QueueView3);
  6026. }
  6027. //---------------------------------------------------------------------------
  6028. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6029. {
  6030. DebugAssert(!IsSideLocalBrowser(Side));
  6031. DebugUsedParam(Side);
  6032. bool Edit = false;
  6033. TRemoteFile * File = NULL;
  6034. UnicodeString FileName;
  6035. UnicodeString PointTo;
  6036. bool SymbolicLink = true;
  6037. if (RemoteDirView->ItemFocused)
  6038. {
  6039. DebugAssert(RemoteDirView->ItemFocused->Data);
  6040. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6041. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6042. if (Edit)
  6043. {
  6044. FileName = File->FileName;
  6045. PointTo = File->LinkTo;
  6046. }
  6047. else
  6048. {
  6049. PointTo = File->FileName;
  6050. }
  6051. }
  6052. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6053. Terminal->IsCapable[fcHardLink]))
  6054. {
  6055. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6056. if (Edit)
  6057. {
  6058. DebugAssert(File->FileName == FileName);
  6059. int Params = dfNoRecursive;
  6060. Terminal->ExceptionOnFail = true;
  6061. try
  6062. {
  6063. Terminal->DeleteFile(L"", File, &Params);
  6064. }
  6065. __finally
  6066. {
  6067. Terminal->ExceptionOnFail = false;
  6068. }
  6069. }
  6070. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6071. }
  6072. }
  6073. //---------------------------------------------------------------------------
  6074. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6075. {
  6076. return
  6077. (IsSideLocalBrowser(Side) ||
  6078. (HasActiveTerminal() &&
  6079. Terminal->ResolvingSymlinks &&
  6080. Terminal->IsCapable[fcSymbolicLink]));
  6081. }
  6082. //---------------------------------------------------------------------------
  6083. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6084. {
  6085. return
  6086. !IsSideLocalBrowser(FCurrentSide) &&
  6087. (RemoteDirView->ItemFocused != NULL) &&
  6088. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6089. Terminal->SessionData->ResolveSymlinks;
  6090. }
  6091. //---------------------------------------------------------------------------
  6092. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6093. {
  6094. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6095. FForceExecution = true;
  6096. try
  6097. {
  6098. DirView(osCurrent)->ExecuteCurrentFile();
  6099. }
  6100. __finally
  6101. {
  6102. FForceExecution = false;
  6103. }
  6104. }
  6105. //---------------------------------------------------------------------------
  6106. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6107. {
  6108. TEditorData ExternalEditor;
  6109. ExternalEditor.Editor = edExternal;
  6110. bool Remember = false;
  6111. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6112. {
  6113. if (Remember)
  6114. {
  6115. TEditorList * EditorList = new TEditorList;
  6116. try
  6117. {
  6118. *EditorList = *WinConfiguration->EditorList;
  6119. bool Found = false;
  6120. int i = 0;
  6121. while (!Found && (i < EditorList->Count))
  6122. {
  6123. const TEditorPreferences * Editor = EditorList->Editors[i];
  6124. if ((Editor->Data->Editor == edExternal) &&
  6125. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6126. {
  6127. Found = true;
  6128. }
  6129. i++;
  6130. }
  6131. if (!Found)
  6132. {
  6133. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6134. WinConfiguration->EditorList = EditorList;
  6135. }
  6136. }
  6137. __finally
  6138. {
  6139. delete EditorList;
  6140. }
  6141. }
  6142. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6143. }
  6144. }
  6145. //---------------------------------------------------------------------------
  6146. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6147. {
  6148. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6149. if (FFileFindTerminal == ATerminal)
  6150. {
  6151. FFileFindTerminal = NULL;
  6152. HideFileFindDialog();
  6153. }
  6154. if (FClipboardTerminal == ATerminal)
  6155. {
  6156. ClipboardClear(); // implies ClipboardStop
  6157. }
  6158. }
  6159. //---------------------------------------------------------------------------
  6160. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6161. {
  6162. DetachTerminal(Sender);
  6163. }
  6164. //---------------------------------------------------------------------------
  6165. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6166. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6167. {
  6168. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6169. DebugAssert(Terminal != NULL);
  6170. if (Data->Terminal == Terminal)
  6171. {
  6172. Data->Terminal = NULL;
  6173. }
  6174. }
  6175. //---------------------------------------------------------------------------
  6176. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6177. {
  6178. UpdateControls();
  6179. SessionColor = TColor(0);
  6180. UpdateRemotePathComboBox(false);
  6181. NeedSession(false);
  6182. }
  6183. //---------------------------------------------------------------------------
  6184. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6185. {
  6186. try
  6187. {
  6188. // Cache, as the login dialog can change its value
  6189. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6190. try
  6191. {
  6192. if (ShowLogin)
  6193. {
  6194. bool ReloadSessions = !Startup;
  6195. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  6196. }
  6197. else if (Startup && WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6198. // This detects if workspace was saved the last time the main widow was closed
  6199. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6200. {
  6201. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6202. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6203. }
  6204. }
  6205. __finally
  6206. {
  6207. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6208. // (so there was no chance for the user to open any session yet)
  6209. if ((ShowLogin || !Startup) &&
  6210. !WinConfiguration->KeepOpenWhenNoSession &&
  6211. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6212. {
  6213. TerminateApplication();
  6214. }
  6215. }
  6216. }
  6217. catch (EAbort &)
  6218. {
  6219. // swallow
  6220. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6221. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6222. }
  6223. }
  6224. //---------------------------------------------------------------------------
  6225. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6226. {
  6227. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6228. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6229. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6230. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6231. try
  6232. {
  6233. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6234. // Clear the design time unthemed tab
  6235. ((SessionsPageControl->PageCount > 0) &&
  6236. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6237. {
  6238. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6239. }
  6240. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6241. {
  6242. TThemeTabSheet * TabSheet;
  6243. if (Index >= SessionsPageControl->PageCount)
  6244. {
  6245. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6246. TabSheet->PageControl = SessionsPageControl;
  6247. }
  6248. else
  6249. {
  6250. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6251. }
  6252. bool IsSessionTab = (Index < TerminalList->Count);
  6253. if (IsSessionTab)
  6254. {
  6255. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6256. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6257. UpdateSessionTab(TabSheet);
  6258. }
  6259. else
  6260. {
  6261. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6262. TabSheet->Tag = 0; // not really needed
  6263. TabSheet->Shadowed = false;
  6264. // 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)
  6265. UpdateNewSessionTab();
  6266. }
  6267. TabSheet->ShowCloseButton = IsSessionTab;
  6268. }
  6269. }
  6270. __finally
  6271. {
  6272. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6273. }
  6274. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6275. }
  6276. //---------------------------------------------------------------------------
  6277. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6278. {
  6279. DoTerminalListChanged();
  6280. }
  6281. //---------------------------------------------------------------------------
  6282. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6283. {
  6284. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6285. DebugAssert(TabSheet->ImageIndex == 0);
  6286. TabSheet->Caption =
  6287. WinConfiguration->SelectiveToolbarText ?
  6288. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6289. UnicodeString();
  6290. }
  6291. //---------------------------------------------------------------------------
  6292. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6293. {
  6294. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6295. }
  6296. //---------------------------------------------------------------------------
  6297. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6298. {
  6299. if (DebugAlwaysTrue(TabSheet != NULL))
  6300. {
  6301. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6302. if (DebugAlwaysTrue(ATerminal != NULL))
  6303. {
  6304. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6305. TabSheet->ImageIndex = AddSessionColor(Color);
  6306. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6307. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6308. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6309. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6310. {
  6311. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6312. }
  6313. }
  6314. }
  6315. }
  6316. //---------------------------------------------------------------------------
  6317. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6318. {
  6319. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6320. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6321. bool Result = (Terminal != NULL);
  6322. if (Result)
  6323. {
  6324. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6325. }
  6326. else
  6327. {
  6328. try
  6329. {
  6330. NewSession(false);
  6331. }
  6332. __finally
  6333. {
  6334. DoTerminalListChanged();
  6335. }
  6336. FSessionsPageControlNewSessionTime = Now();
  6337. }
  6338. return Result;
  6339. }
  6340. //---------------------------------------------------------------------------
  6341. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6342. {
  6343. SessionTabSwitched();
  6344. }
  6345. //---------------------------------------------------------------------------
  6346. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6347. {
  6348. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6349. DebugAssert(TransferList != NULL);
  6350. UnicodeString Name;
  6351. if (TransferList->ItemIndex <= 0)
  6352. {
  6353. Name = L"";
  6354. }
  6355. else
  6356. {
  6357. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6358. }
  6359. if (FCopyParamAutoSelected.IsEmpty())
  6360. {
  6361. // if previous preset was not autoselected, make new preset the "default"
  6362. FCopyParamDefault = Name;
  6363. }
  6364. GUIConfiguration->CopyParamCurrent = Name;
  6365. }
  6366. //---------------------------------------------------------------------------
  6367. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6368. {
  6369. // sanity check
  6370. bool ExistingPreset =
  6371. (FTransferListHoverIndex >= 0) &&
  6372. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6373. DebugAssert(ExistingPreset);
  6374. if (ExistingPreset)
  6375. {
  6376. HDC DC = GetDC(0);
  6377. TCanvas * Canvas = new TCanvas();
  6378. try
  6379. {
  6380. Canvas->Handle = DC;
  6381. Canvas->Font = GetToolbarFont(this);
  6382. UnicodeString Name;
  6383. if (FTransferListHoverIndex == 0)
  6384. {
  6385. Name = L"";
  6386. }
  6387. else
  6388. {
  6389. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6390. }
  6391. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6392. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6393. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6394. static_cast<TObject*>(GetComponent(fcTransferList)));
  6395. UnicodeString InfoStr =
  6396. GUIConfiguration->CopyParamPreset[Name].
  6397. GetInfoStr(L"; ",
  6398. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6399. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6400. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6401. {
  6402. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6403. {
  6404. InfoStr.SetLength(InfoStr.Length() - 1);
  6405. }
  6406. InfoStr += Ellipsis;
  6407. }
  6408. // UpdateCaption does not cause invalidation of whole submenu, while
  6409. // setting Caption property does.
  6410. // also it probably does not resize the label, even if necessary
  6411. // (we do not want that anyway)
  6412. TransferLabel->UpdateCaption(InfoStr);
  6413. }
  6414. __finally
  6415. {
  6416. Canvas->Handle = NULL;
  6417. ReleaseDC(0, DC);
  6418. delete Canvas;
  6419. }
  6420. }
  6421. }
  6422. //---------------------------------------------------------------------------
  6423. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6424. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6425. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6426. {
  6427. if (FTransferListHoverIndex != AHoverIndex)
  6428. {
  6429. FTransferListHoverIndex = AHoverIndex;
  6430. UpdateTransferLabel();
  6431. }
  6432. }
  6433. //---------------------------------------------------------------------------
  6434. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6435. {
  6436. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6437. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6438. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6439. {
  6440. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6441. {
  6442. if (!NonVisualDataModule->Busy)
  6443. {
  6444. OpenDirectory(GetSide(osCurrent));
  6445. }
  6446. Message.Result = 1;
  6447. }
  6448. else
  6449. {
  6450. TForm::Dispatch(&Message);
  6451. }
  6452. }
  6453. else
  6454. {
  6455. TForm::Dispatch(&Message);
  6456. }
  6457. }
  6458. //---------------------------------------------------------------------------
  6459. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6460. {
  6461. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6462. if ((FIgnoreNextDialogChar != 0) &&
  6463. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6464. {
  6465. Message.Result = 1;
  6466. }
  6467. else
  6468. {
  6469. TForm::Dispatch(&Message);
  6470. }
  6471. FIgnoreNextDialogChar = 0;
  6472. }
  6473. //---------------------------------------------------------------------------
  6474. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6475. {
  6476. // The four low-order bits are used internally by Windows
  6477. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6478. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6479. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6480. // 61730 - restore thru double click - undocumented
  6481. // 61490 - maximize thru double click - undocumented
  6482. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6483. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6484. {
  6485. SysResizing(Cmd);
  6486. }
  6487. TForm::Dispatch(&Message);
  6488. }
  6489. //---------------------------------------------------------------------------
  6490. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6491. {
  6492. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6493. // Also there no point returning TRUE as we are not able to
  6494. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6495. // Hence the process termination might be safer :)
  6496. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6497. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6498. {
  6499. Message.Result = FALSE;
  6500. }
  6501. else
  6502. {
  6503. Message.Result = TRUE;
  6504. }
  6505. // Do not call default handling as that triggers OnCloseQuery,
  6506. // where our implementation will popup confirmation dialogs, what we do not want,
  6507. // as per Vista guidelines:
  6508. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6509. }
  6510. //---------------------------------------------------------------------------
  6511. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6512. {
  6513. if (Message.EndSession && IsApplicationMinimized())
  6514. {
  6515. // WORKAROUND
  6516. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6517. // when it receives WM_ENDSESSION,
  6518. // but that sometimes (particularly when application is minimized) cause crashes.
  6519. // Crash popups message that blocks log off.
  6520. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6521. // so we call ExitProcess() immediately, not even trying to cleanup.
  6522. // It still causes beep, so there's likely some popup, but it does not block
  6523. // log off.
  6524. ExitProcess(0);
  6525. }
  6526. TForm::Dispatch(&Message);
  6527. }
  6528. #ifdef _DEBUG
  6529. //---------------------------------------------------------------------------
  6530. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6531. {
  6532. TForm::Dispatch(&Message);
  6533. }
  6534. #endif
  6535. //---------------------------------------------------------------------------
  6536. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6537. {
  6538. }
  6539. //---------------------------------------------------------------------------
  6540. void __fastcall TCustomScpExplorerForm::DoShow()
  6541. {
  6542. // only now are the controls resized finally, so the size constraints
  6543. // will not conflict with possibly very small window size
  6544. RestoreFormParams();
  6545. // This indicates that the form was rescaled after parameters were loaded and
  6546. // as most probably the parameters were actually saved with the current form scaling
  6547. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6548. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6549. // and no rounding problems will occur.
  6550. // See also RestoreForm.
  6551. // (we should be safe to call RestoreParams unconditionally)
  6552. if (PixelsPerInch != Screen->PixelsPerInch)
  6553. {
  6554. RestoreParams();
  6555. }
  6556. FixControlsPlacement();
  6557. if (Position == poDefaultPosOnly)
  6558. {
  6559. CutFormToDesktop(this);
  6560. }
  6561. TForm::DoShow();
  6562. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6563. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6564. if (Terminal == NULL)
  6565. {
  6566. StartingDisconnected();
  6567. }
  6568. UpdatePixelsPerInchMainWindowCounter();
  6569. FShowing = true;
  6570. }
  6571. //---------------------------------------------------------------------------
  6572. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6573. {
  6574. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6575. }
  6576. //---------------------------------------------------------------------------
  6577. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6578. {
  6579. DoTerminalListChanged();
  6580. }
  6581. //---------------------------------------------------------------------------
  6582. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6583. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6584. TNotifyEvent OnBalloonClick, TObject * UserData)
  6585. {
  6586. bool Do;
  6587. UnicodeString Message;
  6588. if (E == NULL)
  6589. {
  6590. Message = Str;
  6591. Do = true;
  6592. }
  6593. else
  6594. {
  6595. Do = ExceptionMessage(E, Message);
  6596. }
  6597. if (Do && WinConfiguration->BalloonNotifications)
  6598. {
  6599. UnicodeString Title;
  6600. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6601. {
  6602. Message = TrimLeft(Message);
  6603. }
  6604. else
  6605. {
  6606. Message = UnformatMessage(Message);
  6607. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6608. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6609. Title = LoadResourceString(Captions[Type]);
  6610. if (Terminal != NULL)
  6611. {
  6612. Title = FORMAT(L"%s - %s",
  6613. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6614. }
  6615. }
  6616. if (Seconds == 0)
  6617. {
  6618. Seconds = WinConfiguration->NotificationsTimeout;
  6619. }
  6620. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6621. }
  6622. }
  6623. //---------------------------------------------------------------------------
  6624. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6625. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6626. UnicodeString HelpKeyword, const TMessageParams * Params,
  6627. TTerminal * Terminal)
  6628. {
  6629. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6630. (FOnFeedSynchronizeError != NULL)) &&
  6631. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6632. {
  6633. if (FOnFeedSynchronizeError != NULL)
  6634. {
  6635. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6636. }
  6637. else
  6638. {
  6639. DebugAssert(FErrorList != NULL);
  6640. TStringList * MoreMessagesCopy = NULL;
  6641. if (MoreMessages)
  6642. {
  6643. MoreMessagesCopy = new TStringList();
  6644. MoreMessagesCopy->Assign(MoreMessages);
  6645. }
  6646. FErrorList->AddObject(Message, MoreMessagesCopy);
  6647. }
  6648. PopupTrayBalloon(Terminal, Message, Type);
  6649. return ContinueAnswer(Answers);
  6650. }
  6651. else
  6652. {
  6653. bool UseBalloon = FTrayIcon->Visible;
  6654. if (UseBalloon)
  6655. {
  6656. PopupTrayBalloon(Terminal, Message, Type);
  6657. }
  6658. unsigned int Result;
  6659. try
  6660. {
  6661. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6662. }
  6663. __finally
  6664. {
  6665. // cancel only balloon we popped up, otherwise we may cancel notification
  6666. // balloon that was there before the message dialog
  6667. // (such as "dd confirmation opt in balloon)
  6668. if (UseBalloon)
  6669. {
  6670. FTrayIcon->CancelBalloon();
  6671. }
  6672. }
  6673. return Result;
  6674. }
  6675. }
  6676. //---------------------------------------------------------------------------
  6677. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6678. TTerminal * Terminal, Exception * E)
  6679. {
  6680. if (FTrayIcon->Visible)
  6681. {
  6682. PopupTrayBalloon(Terminal, L"", qtError, E);
  6683. }
  6684. // particularly prevent opening new session from jump list,
  6685. // while exception is shown
  6686. NonVisualDataModule->StartBusy();
  6687. try
  6688. {
  6689. ShowExtendedExceptionEx(Terminal, E);
  6690. }
  6691. __finally
  6692. {
  6693. NonVisualDataModule->EndBusy();
  6694. FTrayIcon->CancelBalloon();
  6695. }
  6696. }
  6697. //---------------------------------------------------------------------------
  6698. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6699. {
  6700. if (Terminal->Active)
  6701. {
  6702. InitStatusBar();
  6703. }
  6704. // cannot rely on active page being page for active terminal,
  6705. // as it can happen that active page is the "new session" page
  6706. // (e.g. when reconnecting active terminal, while login dialog
  6707. // invoked from "new session" page is modal)
  6708. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6709. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6710. }
  6711. //---------------------------------------------------------------------------
  6712. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6713. TTerminal * Terminal, Exception * E)
  6714. {
  6715. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6716. if (!Terminal->Active)
  6717. {
  6718. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6719. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6720. {
  6721. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6722. }
  6723. }
  6724. }
  6725. //---------------------------------------------------------------------------
  6726. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6727. UnicodeString Message, TQueryType Type,
  6728. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6729. {
  6730. if ((E == NULL) ||
  6731. ExceptionMessage(E, Message))
  6732. {
  6733. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6734. if (Important)
  6735. {
  6736. Seconds *= 5;
  6737. }
  6738. UnicodeString NoteMessage(UnformatMessage(Message));
  6739. if (Terminal != NULL)
  6740. {
  6741. NoteMessage = FORMAT(L"%s: %s",
  6742. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6743. }
  6744. if (WinConfiguration->BalloonNotifications)
  6745. {
  6746. AddNote(NoteMessage);
  6747. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6748. }
  6749. else
  6750. {
  6751. FlashOnBackground();
  6752. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6753. }
  6754. }
  6755. }
  6756. //---------------------------------------------------------------------------
  6757. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6758. {
  6759. RestoreApp();
  6760. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6761. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6762. !NonVisualDataModule->Busy)
  6763. {
  6764. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6765. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6766. if (!ComponentVisible[fcQueueView])
  6767. {
  6768. ToggleQueueVisibility();
  6769. GoToQueue();
  6770. }
  6771. }
  6772. }
  6773. //---------------------------------------------------------------------------
  6774. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6775. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6776. {
  6777. UnicodeString Message;
  6778. TNotifyEvent OnClick = NULL;
  6779. TObject * UserData = NULL;
  6780. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6781. switch (Event)
  6782. {
  6783. case qeEmptyButMonitored:
  6784. if ((ATerminal != Terminal) || QueueInvisible)
  6785. {
  6786. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6787. OnClick = QueueEmptyNoteClicked;
  6788. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6789. TerminalNoteData->Terminal = ATerminal;
  6790. UserData = TerminalNoteData;
  6791. }
  6792. break;
  6793. case qeEmpty:
  6794. OperationComplete(ATerminal->QueueOperationStart);
  6795. break;
  6796. case qePendingUserAction:
  6797. if ((ATerminal != Terminal) ||
  6798. (QueueInvisible && !IsQueueAutoPopup()))
  6799. {
  6800. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6801. }
  6802. break;
  6803. default:
  6804. DebugFail();
  6805. }
  6806. if (!Message.IsEmpty())
  6807. {
  6808. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6809. }
  6810. }
  6811. //---------------------------------------------------------------------------
  6812. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6813. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6814. {
  6815. if (FDDExtMapFile != NULL)
  6816. {
  6817. CloseHandle(FDDExtMapFile);
  6818. FDDExtMapFile = NULL;
  6819. }
  6820. if (WinConfiguration->DDFakeFile)
  6821. {
  6822. DDFakeFileInitDrag(FileList, Created);
  6823. }
  6824. }
  6825. //---------------------------------------------------------------------------
  6826. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6827. {
  6828. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6829. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6830. {
  6831. FFakeFileDropTarget = FileName;
  6832. }
  6833. }
  6834. //---------------------------------------------------------------------------
  6835. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6836. {
  6837. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6838. if (!ForceDirectories(ApiPath(Result)))
  6839. {
  6840. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6841. }
  6842. FileSetAttr(ApiPath(Result), faHidden);
  6843. return Result;
  6844. }
  6845. //---------------------------------------------------------------------------
  6846. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6847. bool & Created)
  6848. {
  6849. FFakeFileDropTarget = UnicodeString();
  6850. FDragFakeDirectory = CreateFakeTransferDirectory();
  6851. FileList->AddItem(NULL, FDragFakeDirectory);
  6852. Created = true;
  6853. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6854. {
  6855. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6856. }
  6857. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6858. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6859. {
  6860. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6861. TDragExtCommStruct* CommStruct;
  6862. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6863. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6864. DebugAssert(CommStruct != NULL);
  6865. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6866. CommStruct->Dragging = true;
  6867. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6868. LENOF(CommStruct->DropDest));
  6869. NULL_TERMINATE(CommStruct->DropDest);
  6870. UnmapViewOfFile(CommStruct);
  6871. }
  6872. }
  6873. //---------------------------------------------------------------------------
  6874. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6875. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6876. {
  6877. bool Result;
  6878. DebugAssert(!IsLocalBrowserMode());
  6879. if (Sender == RemoteDirView)
  6880. {
  6881. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6882. }
  6883. else
  6884. {
  6885. DebugAssert(Sender == RemoteDriveView);
  6886. TStrings * FileList = RemoteDriveView->DragFileList();
  6887. try
  6888. {
  6889. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6890. }
  6891. __finally
  6892. {
  6893. delete FileList;
  6894. }
  6895. }
  6896. if (FDDTargetControl == RemoteDriveView)
  6897. {
  6898. RemoteDriveView->UpdateDropTarget();
  6899. }
  6900. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6901. // or from tree view to dir view.
  6902. // foMove happens when file/dir is dragged from remote tree view outside of
  6903. // application via dragex
  6904. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6905. (DropSourceControl == RemoteDriveView))
  6906. {
  6907. RemoteDriveView->UpdateDropSource();
  6908. }
  6909. return Result;
  6910. }
  6911. //---------------------------------------------------------------------------
  6912. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6913. {
  6914. DebugAssert(!IsLocalBrowserMode());
  6915. // This also handles drops of remote files to queue.
  6916. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6917. SAFE_DESTROY(FDDFileList);
  6918. if (!FFakeFileDropTarget.IsEmpty())
  6919. {
  6920. RemoveDir(ApiPath(FFakeFileDropTarget));
  6921. }
  6922. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6923. {
  6924. try
  6925. {
  6926. TDragResult DDResult = (Sender == RemoteDirView) ?
  6927. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6928. // Focus is moved to the target application,
  6929. // but as we are going to present the UI, we need to steal the focus back.
  6930. // This most likely won't work though (windows does not allow application
  6931. // to steal focus most of the time)
  6932. Application->BringToFront();
  6933. // On older version of Windows we never got drMove here, see also comment below.
  6934. // On Windows 10, we get the "move".
  6935. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6936. {
  6937. UnicodeString TargetDirectory;
  6938. TFileOperation Operation;
  6939. // drInvalid may mean drMove, see comment below
  6940. switch (DDResult)
  6941. {
  6942. case drCopy:
  6943. Operation = foCopy;
  6944. break;
  6945. case drMove:
  6946. Operation = foMove;
  6947. break;
  6948. default:
  6949. DebugFail();
  6950. case drInvalid:
  6951. // prefer "copy" for safety
  6952. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6953. break;
  6954. }
  6955. TTransferOperationParam Param;
  6956. UnicodeString CounterName;
  6957. bool ForceQueue;
  6958. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  6959. {
  6960. // we get drInvalid both if d&d was intercepted by ddext,
  6961. // and when users drops on no-drop location.
  6962. // we tell the difference by existence of response from ddext,
  6963. // so we ignore absence of response in this case
  6964. if (DDResult != drInvalid)
  6965. {
  6966. // here we know that the extension is installed,
  6967. // as it is checked as soon as drag&drop starts from
  6968. // RemoteFileControlDDCreateDragFileList
  6969. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  6970. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  6971. {
  6972. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  6973. }
  6974. else
  6975. {
  6976. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  6977. }
  6978. }
  6979. }
  6980. else
  6981. {
  6982. // download using fake file
  6983. Param.Temp = false;
  6984. Param.DragDrop = true;
  6985. if (ForceQueue)
  6986. {
  6987. Param.Queue = asOn;
  6988. }
  6989. if (Sender == RemoteDirView)
  6990. {
  6991. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  6992. }
  6993. if (RemoteFileControlFileOperation(Sender, Operation,
  6994. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  6995. {
  6996. Configuration->Usage->Inc(CounterName);
  6997. }
  6998. }
  6999. }
  7000. }
  7001. __finally
  7002. {
  7003. CloseHandle(FDDExtMapFile);
  7004. FDDExtMapFile = NULL;
  7005. delete FDragFakeMonitors;
  7006. FDragFakeMonitors = NULL;
  7007. RemoveDir(ApiPath(FDragFakeDirectory));
  7008. FDragFakeDirectory = L"";
  7009. FFakeFileDropTarget = UnicodeString();
  7010. }
  7011. }
  7012. if (FDragDropSshTerminate.get() != NULL)
  7013. {
  7014. FDragDropSshTerminate->Rethrow();
  7015. }
  7016. }
  7017. //---------------------------------------------------------------------------
  7018. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7019. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7020. {
  7021. // Remember drop effect so we know (when user drops files), if we copy or move
  7022. FLastDropEffect = dwEffect;
  7023. }
  7024. //---------------------------------------------------------------------------
  7025. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7026. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7027. {
  7028. bool Result;
  7029. if (FDDTargetControl == QueueView3)
  7030. {
  7031. Directory = DefaultDownloadTargetDirectory();
  7032. Result = true;
  7033. CounterName = L"DownloadsDragDropQueue";
  7034. ForceQueue = true;
  7035. }
  7036. else if (!FFakeFileDropTarget.IsEmpty())
  7037. {
  7038. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7039. Result = true;
  7040. ForceQueue = false;
  7041. CounterName = L"DownloadsDragDropFakeFile";
  7042. }
  7043. else
  7044. {
  7045. ForceQueue = false;
  7046. Enabled = false;
  7047. try
  7048. {
  7049. int Timer = 0;
  7050. Result = false;
  7051. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7052. {
  7053. {
  7054. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7055. TDragExtCommStruct* CommStruct;
  7056. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7057. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7058. DebugAssert(CommStruct != NULL);
  7059. Result = !CommStruct->Dragging;
  7060. if (Result)
  7061. {
  7062. Directory = ExtractFilePath(CommStruct->DropDest);
  7063. CounterName = L"DownloadsDragDropExternalExt";
  7064. }
  7065. UnmapViewOfFile(CommStruct);
  7066. }
  7067. if (!Result)
  7068. {
  7069. Sleep(50);
  7070. Timer += 50;
  7071. Application->ProcessMessages();
  7072. }
  7073. }
  7074. }
  7075. __finally
  7076. {
  7077. Enabled = true;
  7078. }
  7079. }
  7080. return Result;
  7081. }
  7082. //---------------------------------------------------------------------------
  7083. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7084. const UnicodeString TempDir, int SecDelay)
  7085. {
  7086. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7087. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7088. if (FDelayedDeletionTimer == NULL)
  7089. {
  7090. DebugAssert(HandleAllocated());
  7091. FDelayedDeletionTimer = new TTimer(this);
  7092. FDelayedDeletionTimer->Interval = 10000;
  7093. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7094. }
  7095. else
  7096. {
  7097. FDelayedDeletionTimer->Enabled = true;
  7098. }
  7099. }
  7100. //---------------------------------------------------------------------------
  7101. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7102. {
  7103. DebugAssert(FDelayedDeletionList != NULL);
  7104. TDateTime N = Now();
  7105. TDateTime Alert;
  7106. UnicodeString Directory;
  7107. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7108. {
  7109. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7110. if ((N >= Alert) || (Sender == NULL))
  7111. {
  7112. Directory = FDelayedDeletionList->Strings[Index];
  7113. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7114. {
  7115. FDelayedDeletionList->Delete(Index);
  7116. }
  7117. }
  7118. }
  7119. if (FDelayedDeletionList->Count == 0)
  7120. {
  7121. FDelayedDeletionTimer->Enabled = false;
  7122. }
  7123. }
  7124. //---------------------------------------------------------------------------
  7125. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7126. {
  7127. DebugAssert(!IsLocalBrowserMode());
  7128. if (IsFileControl(FDDTargetControl, osRemote) ||
  7129. (FDDTargetControl == SessionsPageControl))
  7130. {
  7131. TTerminal * TargetTerminal = NULL;
  7132. TFileOperation Operation = foNone;
  7133. if (FDDTargetControl == SessionsPageControl)
  7134. {
  7135. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7136. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7137. // do not allow dropping on the "+" tab
  7138. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7139. if (TargetTerminal != NULL)
  7140. {
  7141. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7142. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7143. {
  7144. Operation = foRemoteMove;
  7145. }
  7146. else
  7147. {
  7148. Operation = foRemoteCopy;
  7149. }
  7150. }
  7151. }
  7152. else
  7153. {
  7154. if (FLastDropEffect == DROPEFFECT_MOVE)
  7155. {
  7156. Operation = foRemoteMove;
  7157. }
  7158. else if (FLastDropEffect == DROPEFFECT_COPY)
  7159. {
  7160. Operation = foRemoteCopy;
  7161. }
  7162. }
  7163. if (Operation != foNone)
  7164. {
  7165. RemoteFileControlFileOperation(DropSourceControl,
  7166. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7167. }
  7168. // abort drag&drop
  7169. Abort();
  7170. }
  7171. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7172. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7173. (FDDTargetControl != QueueView3))
  7174. {
  7175. DebugAssert(!FDragTempDir.IsEmpty());
  7176. TTransferType Type;
  7177. UnicodeString TempDir = FDragTempDir;
  7178. // We clear FDragTempDir before calling
  7179. // just in case it fail (raises exception)
  7180. FDragTempDir = L"";
  7181. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7182. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7183. // empty directory parameter means temp directory -> don't display it!
  7184. UnicodeString TargetDir = L"";
  7185. int Options = 0;
  7186. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7187. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7188. {
  7189. Abort();
  7190. }
  7191. // TargetDir is set when dropped on local file control
  7192. // (this was workaround for legacy dirview event handling, now it should be
  7193. // made prettier)
  7194. if (TargetDir.IsEmpty())
  7195. {
  7196. TargetDir = TempDir;
  7197. if (ForceDirectories(ApiPath(TargetDir)))
  7198. {
  7199. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7200. FPendingTempSpaceWarn = true;
  7201. try
  7202. {
  7203. FDragDropOperation = true;
  7204. int Params = cpTemporary |
  7205. (Type == ttMove ? cpDelete : 0);
  7206. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7207. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7208. }
  7209. __finally
  7210. {
  7211. FDragDropOperation = false;
  7212. FPendingTempSpaceWarn = false;
  7213. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7214. }
  7215. }
  7216. else
  7217. {
  7218. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7219. }
  7220. }
  7221. }
  7222. }
  7223. //---------------------------------------------------------------------------
  7224. void __fastcall TCustomScpExplorerForm::DDDownload(
  7225. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7226. {
  7227. DebugAssert(!IsLocalBrowserMode());
  7228. TAutoBatch AutoBatch(this);
  7229. UpdateCopyParamCounters(*CopyParam);
  7230. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7231. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7232. {
  7233. RemoteDriveView->UpdateDropSource();
  7234. }
  7235. }
  7236. //---------------------------------------------------------------------------
  7237. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7238. {
  7239. public:
  7240. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7241. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7242. {
  7243. }
  7244. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7245. {
  7246. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7247. TDataObjectFilesEx::AllowData(FormatEtc);
  7248. }
  7249. };
  7250. //---------------------------------------------------------------------------
  7251. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7252. TObject * Sender, TDataObject *& DataObject)
  7253. {
  7254. if (FDDExtMapFile != NULL)
  7255. {
  7256. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7257. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7258. {
  7259. Abort();
  7260. }
  7261. if (FileList->Count > 0)
  7262. {
  7263. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7264. if (!FilesObject->IsValid(true, true))
  7265. {
  7266. FilesObject->_Release();
  7267. }
  7268. else
  7269. {
  7270. DataObject = FilesObject;
  7271. }
  7272. }
  7273. }
  7274. }
  7275. //---------------------------------------------------------------------------
  7276. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7277. {
  7278. DebugFail();
  7279. }
  7280. //---------------------------------------------------------------------------
  7281. void __fastcall TCustomScpExplorerForm::GoToTree()
  7282. {
  7283. ComponentVisible[fcRemoteTree] = true;
  7284. DriveView(osRemote)->SetFocus();
  7285. }
  7286. //---------------------------------------------------------------------------
  7287. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7288. TPanelExport Export)
  7289. {
  7290. TCustomDirView * DirView = this->DirView(Side);
  7291. std::unique_ptr<TStrings> ExportData(new TStringList());
  7292. switch (Export)
  7293. {
  7294. case pePath:
  7295. ExportData->Add(DirView->PathName);
  7296. break;
  7297. case peFileList:
  7298. case peFullFileList:
  7299. {
  7300. bool FullPath = (Export == peFullFileList);
  7301. DirView->CreateFileList(false, FullPath, ExportData.get());
  7302. for (int Index = 0; Index < ExportData->Count; Index++)
  7303. {
  7304. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7305. {
  7306. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7307. }
  7308. }
  7309. }
  7310. break;
  7311. default:
  7312. DebugFail();
  7313. }
  7314. return ExportData.release();
  7315. }
  7316. //---------------------------------------------------------------------------
  7317. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7318. TPanelExport Export, TPanelExportDestination Destination)
  7319. {
  7320. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7321. PanelExportStore(Side, Export, Destination, ExportData.get());
  7322. }
  7323. //---------------------------------------------------------------------------
  7324. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7325. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7326. TStrings * ExportData)
  7327. {
  7328. if (Destination == pedClipboard)
  7329. {
  7330. TInstantOperationVisualizer Visualizer;
  7331. CopyToClipboard(ExportData);
  7332. }
  7333. else
  7334. {
  7335. DebugFail();
  7336. }
  7337. }
  7338. //---------------------------------------------------------------------------
  7339. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7340. {
  7341. TCustomDirView * DirView = this->DirView(Side);
  7342. UnicodeString Mask = DirView->Mask;
  7343. if (DoFilterMaskDialog(DirView, Mask))
  7344. {
  7345. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7346. Configuration->Usage->Inc(L"Filters");
  7347. }
  7348. }
  7349. //---------------------------------------------------------------------------
  7350. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7351. {
  7352. return FQueueController->DefaultOperation();
  7353. }
  7354. //---------------------------------------------------------------------------
  7355. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7356. TQueueOperation Operation, void ** Param)
  7357. {
  7358. switch (Operation)
  7359. {
  7360. case qoPreferences:
  7361. return true;
  7362. case qoGoTo:
  7363. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7364. case qoOnceEmpty:
  7365. return IsAnythingQueued();
  7366. default:
  7367. return FQueueController->AllowOperation(Operation, Param);
  7368. }
  7369. }
  7370. //---------------------------------------------------------------------------
  7371. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7372. {
  7373. if (DebugAlwaysTrue(QueueView3->Visible))
  7374. {
  7375. QueueView3->SetFocus();
  7376. }
  7377. }
  7378. //---------------------------------------------------------------------------
  7379. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7380. TQueueOperation Operation, void * Param)
  7381. {
  7382. if (Operation == qoGoTo)
  7383. {
  7384. GoToQueue();
  7385. }
  7386. else if (Operation == qoPreferences)
  7387. {
  7388. PreferencesDialog(pmQueue);
  7389. }
  7390. else
  7391. {
  7392. FQueueController->ExecuteOperation(Operation, Param);
  7393. }
  7394. }
  7395. //---------------------------------------------------------------------------
  7396. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7397. {
  7398. return (Queue != NULL) && Queue->Enabled;
  7399. }
  7400. //---------------------------------------------------------------------------
  7401. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7402. {
  7403. DebugAssert(Queue != NULL);
  7404. if (Queue != NULL)
  7405. {
  7406. Queue->Enabled = !Queue->Enabled;
  7407. }
  7408. }
  7409. //---------------------------------------------------------------------------
  7410. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7411. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7412. {
  7413. FQueueActedItem = QueueView3->ItemFocused;
  7414. }
  7415. //---------------------------------------------------------------------------
  7416. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7417. {
  7418. return TopDock->Height + QueueSplitter->Height;
  7419. }
  7420. //---------------------------------------------------------------------------
  7421. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7422. {
  7423. return
  7424. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7425. (QueueDock->Visible ? QueueDock->Height : 0) +
  7426. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7427. }
  7428. //---------------------------------------------------------------------------
  7429. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7430. {
  7431. return ScaleByTextHeight(this, 48);
  7432. }
  7433. //---------------------------------------------------------------------------
  7434. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7435. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7436. {
  7437. // when queue is hidden by double-clicking splitter, stray attempt to
  7438. // resize the panel with strange value arrives, make sure it is ignored
  7439. if (ComponentVisible[fcQueueView])
  7440. {
  7441. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7442. if (NewSize > MaxHeightLimit)
  7443. {
  7444. NewSize = MaxHeightLimit;
  7445. }
  7446. int MinHeightLimit =
  7447. GetStaticQueuePanelComponentsHeight() +
  7448. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7449. GetMinQueueViewHeight();
  7450. if (NewSize < MinHeightLimit)
  7451. {
  7452. NewSize = MinHeightLimit;
  7453. }
  7454. }
  7455. else
  7456. {
  7457. Accept = false;
  7458. }
  7459. }
  7460. //---------------------------------------------------------------------------
  7461. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7462. {
  7463. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7464. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7465. if (QueueViewHeight < GetMinQueueViewHeight())
  7466. {
  7467. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7468. }
  7469. }
  7470. //---------------------------------------------------------------------------
  7471. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7472. TDragObject *& /*DragObject*/)
  7473. {
  7474. FQueueActedItem = QueueView3->ItemFocused;
  7475. }
  7476. //---------------------------------------------------------------------------
  7477. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7478. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7479. {
  7480. Accept = true;
  7481. if (Source == QueueView3)
  7482. {
  7483. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7484. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7485. if (Accept)
  7486. {
  7487. TQueueItemProxy * QueueItem;
  7488. TQueueItemProxy * DestQueueItem;
  7489. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7490. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7491. Accept = (QueueItem != DestQueueItem) &&
  7492. (QueueItem->Status == TQueueItem::qsPending) &&
  7493. (DestQueueItem->Status == TQueueItem::qsPending);
  7494. }
  7495. }
  7496. }
  7497. //---------------------------------------------------------------------------
  7498. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7499. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7500. {
  7501. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7502. {
  7503. TQueueItemProxy * QueueItem;
  7504. TQueueItemProxy * DestQueueItem;
  7505. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7506. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7507. QueueItem->Move(DestQueueItem);
  7508. }
  7509. }
  7510. //---------------------------------------------------------------------------
  7511. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7512. {
  7513. if ((QueueView3->ItemFocused == NULL) &&
  7514. (QueueView3->Items->Count > 0))
  7515. {
  7516. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7517. }
  7518. QueueLabelUpdateStatus();
  7519. }
  7520. //---------------------------------------------------------------------------
  7521. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7522. {
  7523. QueueLabelUpdateStatus();
  7524. }
  7525. //---------------------------------------------------------------------------
  7526. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7527. {
  7528. QueueLabel->UpdateStatus();
  7529. }
  7530. //---------------------------------------------------------------------------
  7531. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7532. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7533. {
  7534. if (Selected)
  7535. {
  7536. NonVisualDataModule->UpdateNonVisibleActions();
  7537. }
  7538. }
  7539. //---------------------------------------------------------------------------
  7540. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7541. {
  7542. TDragDropFilesEx * Result = NULL;
  7543. if (Sender == SessionsPageControl)
  7544. {
  7545. Result = FSessionsDragDropFilesEx;
  7546. }
  7547. else if (Sender == QueueView3)
  7548. {
  7549. Result = FQueueDragDropFilesEx;
  7550. }
  7551. else
  7552. {
  7553. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7554. if (DirView != NULL)
  7555. {
  7556. Result = DirView->DragDropFilesEx;
  7557. }
  7558. else
  7559. {
  7560. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7561. if (DriveView != NULL)
  7562. {
  7563. Result = DriveView->DragDropFilesEx;
  7564. }
  7565. }
  7566. }
  7567. DebugAssert(Result != NULL);
  7568. return Result;
  7569. }
  7570. //---------------------------------------------------------------------------
  7571. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7572. {
  7573. return (DView->SelCount == DView->FilesCount);
  7574. }
  7575. //---------------------------------------------------------------------------
  7576. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7577. {
  7578. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7579. }
  7580. //---------------------------------------------------------------------------
  7581. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7582. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7583. {
  7584. DebugAssert(!IsLocalBrowserMode());
  7585. TFileOperation Operation;
  7586. switch (Effect)
  7587. {
  7588. case DROPEFFECT_MOVE:
  7589. Operation = foMove;
  7590. break;
  7591. case DROPEFFECT_COPY:
  7592. // occures on WinXP (reported by user)
  7593. default:
  7594. Operation = foCopy;
  7595. break;
  7596. };
  7597. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7598. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7599. if (DragDropFilesEx->FileList->Count > 0)
  7600. {
  7601. TStrings * FileList = new TStringList();
  7602. try
  7603. {
  7604. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7605. {
  7606. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7607. }
  7608. FDragDropOperation = true;
  7609. TTransferOperationParam Param;
  7610. Param.TargetDirectory = TargetPath;
  7611. // upload, no temp dirs
  7612. Param.Temp = false;
  7613. Param.DragDrop = DragDrop;
  7614. Param.Options =
  7615. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7616. if (ForceQueue)
  7617. {
  7618. Param.Queue = asOn;
  7619. }
  7620. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7621. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7622. {
  7623. if (IsFileControl(DropSourceControl, osLocal))
  7624. {
  7625. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7626. }
  7627. else
  7628. {
  7629. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7630. }
  7631. }
  7632. }
  7633. __finally
  7634. {
  7635. FDragDropOperation = false;
  7636. delete FileList;
  7637. }
  7638. }
  7639. }
  7640. //---------------------------------------------------------------------------
  7641. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7642. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7643. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7644. {
  7645. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7646. }
  7647. //---------------------------------------------------------------------------
  7648. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7649. TObject * Sender, int grfKeyState, int & dwEffect)
  7650. {
  7651. DebugAssert(!IsLocalBrowserMode());
  7652. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7653. if ((dwEffect != DROPEFFECT_NONE) &&
  7654. IsFileControl(DropSourceControl, osRemote))
  7655. {
  7656. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7657. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7658. (RemoteDirView->DropTarget == NULL))
  7659. {
  7660. dwEffect = DROPEFFECT_NONE;
  7661. }
  7662. else
  7663. {
  7664. if (dwEffect == DROPEFFECT_COPY)
  7665. {
  7666. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7667. // currently we support copying always (at least via temporary directory);
  7668. // remove associated checks once this all proves stable and working
  7669. bool CopyCapable = true;
  7670. // if we do not support neither of operations, there's no discussion
  7671. if (!MoveCapable && !CopyCapable)
  7672. {
  7673. dwEffect = DROPEFFECT_NONE;
  7674. }
  7675. else
  7676. {
  7677. // The default effect inside remote panel is move,
  7678. // unless we do not support it, but support copy
  7679. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7680. {
  7681. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7682. }
  7683. else
  7684. {
  7685. // with ctrl-down, we want copy unless it is not supported
  7686. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7687. }
  7688. }
  7689. }
  7690. }
  7691. }
  7692. }
  7693. //---------------------------------------------------------------------------
  7694. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7695. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7696. {
  7697. DebugAssert(!IsLocalBrowserMode());
  7698. if (FDDTotalSize >= 0)
  7699. {
  7700. if (File->IsDirectory)
  7701. {
  7702. FDDTotalSize = -1;
  7703. }
  7704. else
  7705. {
  7706. FDDTotalSize += File->Size;
  7707. }
  7708. }
  7709. DebugAssert(!FDragTempDir.IsEmpty());
  7710. // TODO: this is quite ineffective
  7711. // TODO: what if invalid character replacement is disabled?
  7712. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7713. UnicodeString TransferFileName;
  7714. if (Sender == RemoteDriveView)
  7715. {
  7716. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7717. }
  7718. else
  7719. {
  7720. TransferFileName = File->FileName;
  7721. }
  7722. FDDFileList->AddObject(TransferFileName, File);
  7723. }
  7724. //---------------------------------------------------------------------------
  7725. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7726. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7727. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7728. {
  7729. // sometimes we do not get DDEnd so the list is not released
  7730. SAFE_DESTROY(FDDFileList);
  7731. FDDFileList = new TStringList();
  7732. FDragTempDir = WinConfiguration->TemporaryDir();
  7733. FDDTotalSize = 0;
  7734. FDragDropSshTerminate.reset(NULL);
  7735. }
  7736. //---------------------------------------------------------------------------
  7737. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7738. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7739. HRESULT & Result)
  7740. {
  7741. if (Result == DRAGDROP_S_DROP)
  7742. {
  7743. try
  7744. {
  7745. GlobalDragImageList->HideDragImage();
  7746. try
  7747. {
  7748. RemoteFileControlDDTargetDrop();
  7749. }
  7750. catch(ESshTerminate & E)
  7751. {
  7752. FDragDropSshTerminate.reset(E.Clone());
  7753. }
  7754. }
  7755. catch (Exception &E)
  7756. {
  7757. // If downloading fails we need to cancel drag&drop, otherwise
  7758. // Explorer shows error
  7759. // But by the way exception probably never reach this point as
  7760. // it's catched on way.
  7761. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7762. Result = DRAGDROP_S_CANCEL;
  7763. ShowExtendedException(Terminal, &E);
  7764. }
  7765. }
  7766. }
  7767. //---------------------------------------------------------------------------
  7768. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7769. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7770. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7771. {
  7772. TFileMasks::TParams MaskParams;
  7773. MaskParams.Size = Size;
  7774. MaskParams.Modification = Modification;
  7775. // this does not re-parse the mask if it is the same as the last time
  7776. FDirViewMatchMask = Masks;
  7777. bool ImplicitMatch;
  7778. Matches =
  7779. // RecurseInclude parameter has no effect as the Path is empty
  7780. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7781. (AllowImplicitMatches || !ImplicitMatch);
  7782. }
  7783. //---------------------------------------------------------------------------
  7784. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7785. TObject * Sender, TListItem * Item, WORD & Indexes)
  7786. {
  7787. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7788. UnicodeString Ext;
  7789. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7790. {
  7791. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7792. }
  7793. else
  7794. {
  7795. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7796. }
  7797. if (SameText(Ext, Configuration->PartialExt))
  7798. {
  7799. Indexes |= oiPartial;
  7800. }
  7801. }
  7802. //---------------------------------------------------------------------------
  7803. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7804. {
  7805. return
  7806. DirViewEnabled(osCurrent) &&
  7807. DirView(osCurrent)->CanPasteFromClipBoard();
  7808. }
  7809. //---------------------------------------------------------------------------
  7810. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7811. {
  7812. bool Result = false;
  7813. if (CanPasteToDirViewFromClipBoard())
  7814. {
  7815. Result = true;
  7816. }
  7817. else
  7818. {
  7819. UnicodeString ClipboardText;
  7820. if (NonEmptyTextFromClipboard(ClipboardText))
  7821. {
  7822. if (StoredSessions->IsUrl(ClipboardText))
  7823. {
  7824. Result = true;
  7825. }
  7826. else
  7827. {
  7828. Result = DirViewEnabled(osCurrent);
  7829. }
  7830. }
  7831. }
  7832. return Result;
  7833. }
  7834. //---------------------------------------------------------------------------
  7835. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7836. {
  7837. if (DoesClipboardContainOurFiles())
  7838. {
  7839. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7840. {
  7841. DebugAssert(!IsLocalBrowserMode());
  7842. TTerminalManager * Manager = TTerminalManager::Instance();
  7843. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7844. Manager->ActiveTerminal = FClipboardTerminal;
  7845. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7846. }
  7847. }
  7848. else if (CanPasteToDirViewFromClipBoard())
  7849. {
  7850. DirView(osCurrent)->PasteFromClipBoard();
  7851. }
  7852. else
  7853. {
  7854. UnicodeString ClipboardText;
  7855. if (NonEmptyTextFromClipboard(ClipboardText))
  7856. {
  7857. if (StoredSessions->IsUrl(ClipboardText))
  7858. {
  7859. NewSession(false, ClipboardText);
  7860. }
  7861. else
  7862. {
  7863. DirView(osCurrent)->Path = ClipboardText;
  7864. }
  7865. }
  7866. }
  7867. }
  7868. //---------------------------------------------------------------------------
  7869. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7870. {
  7871. // TBD
  7872. }
  7873. //---------------------------------------------------------------------------
  7874. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7875. {
  7876. TCustomDirView * ADirView = DirView(Side);
  7877. ADirView->SelectAll(Mode);
  7878. ADirView->SetFocus();
  7879. }
  7880. //---------------------------------------------------------------------------
  7881. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7882. {
  7883. TCustomDirView * ADirView = DirView(Side);
  7884. TFileFilter Filter;
  7885. DefaultFileFilter(Filter);
  7886. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7887. {
  7888. Configuration->Usage->Inc(L"MaskSelections");
  7889. ADirView->SelectFiles(Filter, Select);
  7890. ADirView->SetFocus();
  7891. }
  7892. }
  7893. //---------------------------------------------------------------------------
  7894. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7895. {
  7896. TCustomDirView * ADirView = DirView(Side);
  7897. ADirView->RestoreSelectedNames();
  7898. ADirView->SetFocus();
  7899. }
  7900. //---------------------------------------------------------------------------
  7901. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7902. {
  7903. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7904. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7905. {
  7906. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7907. UnicodeString Ext;
  7908. if (!IsSideLocalBrowser(osCurrent))
  7909. {
  7910. Ext = UnixExtractFileExt(FileName);
  7911. }
  7912. else
  7913. {
  7914. Ext = ExtractFileExt(FileName);
  7915. }
  7916. if (Ext.IsEmpty())
  7917. {
  7918. Ext = L".";
  7919. }
  7920. TFileFilter Filter;
  7921. Filter.Masks = FORMAT(L"*%s", (Ext));
  7922. Filter.Directories = false;
  7923. CurrentDirView->SelectFiles(Filter, Select);
  7924. }
  7925. }
  7926. //---------------------------------------------------------------------------
  7927. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7928. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7929. {
  7930. UnicodeString Result;
  7931. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7932. {
  7933. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  7934. }
  7935. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  7936. {
  7937. // noop
  7938. }
  7939. else
  7940. {
  7941. Result =
  7942. FMTLOAD(FILE_INFO_FORMAT,
  7943. (FormatBytes(FileInfo.SelectedSize),
  7944. FormatBytes(FileInfo.FilesSize),
  7945. FormatNumber(FileInfo.SelectedCount),
  7946. FormatNumber(FileInfo.FilesCount)));
  7947. }
  7948. return Result;
  7949. }
  7950. //---------------------------------------------------------------------------
  7951. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7952. TTBXStatusPanel * Panel, TOperationSide Side)
  7953. {
  7954. if (Panel->Index == 1)
  7955. {
  7956. ToggleShowHiddenFiles();
  7957. }
  7958. else if (Panel->Index == 2)
  7959. {
  7960. Filter(Side);
  7961. }
  7962. }
  7963. //---------------------------------------------------------------------------
  7964. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  7965. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  7966. {
  7967. DebugAssert(!StatusBar->SimplePanel);
  7968. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  7969. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  7970. }
  7971. //---------------------------------------------------------------------------
  7972. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  7973. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  7974. {
  7975. DebugAssert(StatusBar->Panels->Count >= 3);
  7976. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  7977. if (FileInfo.HiddenCount > 0)
  7978. {
  7979. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  7980. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7981. }
  7982. else
  7983. {
  7984. HiddenFilesPanel->ViewPriority = 0;
  7985. // not really necessary, just to cleanup no-longer-valid data
  7986. HiddenFilesPanel->Caption = L"";
  7987. }
  7988. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  7989. if (FileInfo.FilteredCount > 0)
  7990. {
  7991. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  7992. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7993. }
  7994. else
  7995. {
  7996. FilteredFilesPanel->ViewPriority = 0;
  7997. // not really necessary, just to cleanup no-longer-valid data
  7998. FilteredFilesPanel->Caption = L"";
  7999. }
  8000. }
  8001. //---------------------------------------------------------------------------
  8002. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8003. TObject * /*Sender*/)
  8004. {
  8005. if (DirView(osRemote)->Enabled)
  8006. {
  8007. DirView(osRemote)->SetFocus();
  8008. }
  8009. }
  8010. //---------------------------------------------------------------------------
  8011. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8012. {
  8013. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8014. switch (Config.Show)
  8015. {
  8016. case qvShow:
  8017. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8018. {
  8019. Config.Show = qvHide;
  8020. }
  8021. else
  8022. {
  8023. Config.Show = Config.LastHideShow;
  8024. }
  8025. break;
  8026. case qvHideWhenEmpty:
  8027. if (ComponentVisible[fcQueueView])
  8028. {
  8029. Config.Show = qvHide;
  8030. }
  8031. else
  8032. {
  8033. Config.LastHideShow = Config.Show;
  8034. Config.Show = qvShow;
  8035. }
  8036. break;
  8037. case qvHide:
  8038. Config.LastHideShow = Config.Show;
  8039. Config.Show = qvShow;
  8040. break;
  8041. }
  8042. WinConfiguration->QueueView = Config;
  8043. }
  8044. //---------------------------------------------------------------------------
  8045. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8046. {
  8047. UnicodeString Result;
  8048. if (FTerminal != NULL)
  8049. {
  8050. switch (WinConfiguration->PathInCaption)
  8051. {
  8052. case picShort:
  8053. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8054. break;
  8055. case picFull:
  8056. Result = FTerminal->CurrentDirectory;
  8057. break;
  8058. }
  8059. }
  8060. return Result;
  8061. }
  8062. //---------------------------------------------------------------------------
  8063. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8064. {
  8065. TColor Result = GetWindowColor(FSessionColor);
  8066. return Result;
  8067. }
  8068. //---------------------------------------------------------------------------
  8069. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8070. {
  8071. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8072. return Result;
  8073. }
  8074. //---------------------------------------------------------------------------
  8075. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8076. {
  8077. TTerminalManager::Instance()->UpdateAppTitle();
  8078. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8079. // background to gray on Windows 7 (works on Windows 10).
  8080. // See also EnableControl
  8081. if (Showing)
  8082. {
  8083. if (Terminal != NULL)
  8084. {
  8085. // Update path when it changes
  8086. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8087. {
  8088. UpdateSessionTab(SessionsPageControl->ActivePage);
  8089. }
  8090. }
  8091. NonVisualDataModule->ReconnectSessionAction->Update();
  8092. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8093. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8094. CenterReconnectToolbar();
  8095. bool HasTerminal = HasActiveTerminal();
  8096. if (HasTerminal)
  8097. {
  8098. // TODO needed yet with second local browser?
  8099. if (!RemoteDirView->Enabled)
  8100. {
  8101. RemoteDirView->Enabled = true;
  8102. if (FRemoteDirViewWasFocused)
  8103. {
  8104. ActiveControl = RemoteDirView;
  8105. }
  8106. }
  8107. RemoteDirView->Color = PanelColor();
  8108. }
  8109. else
  8110. {
  8111. if (RemoteDirView->Enabled)
  8112. {
  8113. // This is first called when the form is being constructed
  8114. // (not anymore due to Showing test above)
  8115. // but the false is overriden in the constructor later.
  8116. // An even later in TScpCommanderForm::DoShow()
  8117. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  8118. RemoteDirView->Enabled = false;
  8119. }
  8120. RemoteDirView->Color = DisabledPanelColor();
  8121. }
  8122. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8123. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8124. RemoteDriveView->Color = RemoteDirView->Color;
  8125. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8126. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8127. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8128. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8129. QueueFileList->Enabled = QueueView3->Enabled;
  8130. QueueFileList->Color = QueueView3->Color;
  8131. QueueFileList->Font->Color = QueueView3->Font->Color;
  8132. QueueLabelUpdateStatus();
  8133. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8134. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8135. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  8136. }
  8137. }
  8138. //---------------------------------------------------------------------------
  8139. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8140. {
  8141. UpdateControls();
  8142. }
  8143. //---------------------------------------------------------------------------
  8144. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8145. TObject * Sender)
  8146. {
  8147. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8148. DebugAssert(DirView != NULL);
  8149. DoDirViewLoaded(DirView);
  8150. TransferPresetAutoSelect();
  8151. }
  8152. //---------------------------------------------------------------------------
  8153. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8154. {
  8155. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8156. // first run after installation
  8157. if (double(Updates.LastCheck) == 0)
  8158. {
  8159. // make sure next time there will be an update (if enabled)
  8160. Updates.LastCheck = TDateTime(1);
  8161. WinConfiguration->Updates = Updates;
  8162. }
  8163. else if ((double(Updates.Period) > 0) &&
  8164. (Now() - Updates.LastCheck >= Updates.Period))
  8165. {
  8166. TThreadMethod OnUpdatesChecked = NULL;
  8167. if (!IsUWP())
  8168. {
  8169. OnUpdatesChecked = UpdatesChecked;
  8170. }
  8171. StartUpdateThread(OnUpdatesChecked);
  8172. }
  8173. }
  8174. //---------------------------------------------------------------------------
  8175. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8176. {
  8177. UnicodeString Message;
  8178. bool New;
  8179. TQueryType Type;
  8180. GetUpdatesMessage(Message, New, Type, false);
  8181. if (!Message.IsEmpty())
  8182. {
  8183. if (New)
  8184. {
  8185. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8186. }
  8187. if (!New && (Type != qtWarning))
  8188. {
  8189. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8190. }
  8191. else
  8192. {
  8193. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8194. }
  8195. if (New)
  8196. {
  8197. Configuration->Usage->Inc(L"UpdateNotifications");
  8198. }
  8199. }
  8200. }
  8201. //---------------------------------------------------------------------------
  8202. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8203. {
  8204. RestoreApp();
  8205. bool CanDisplay = !NonVisualDataModule->Busy;
  8206. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8207. {
  8208. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8209. }
  8210. if (CanDisplay)
  8211. {
  8212. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8213. CheckForUpdates(true);
  8214. }
  8215. else
  8216. {
  8217. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8218. }
  8219. }
  8220. //---------------------------------------------------------------------------
  8221. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8222. TCopyParamRuleData & Data)
  8223. {
  8224. DebugAssert(Terminal != NULL);
  8225. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8226. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8227. Data.RemoteDirectory = RemoteDirView->PathName;
  8228. }
  8229. //---------------------------------------------------------------------------
  8230. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8231. {
  8232. // Terminal can be null when we are changing local directory implicitly,
  8233. // because it has been deleted, while no session is connected
  8234. // (Login dialog is open)
  8235. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8236. {
  8237. DebugAssert(!IsLocalBrowserMode());
  8238. TCopyParamRuleData Data;
  8239. GetTransferPresetAutoSelectData(Data);
  8240. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8241. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8242. if (CopyParamIndex < 0)
  8243. {
  8244. // there is no preset that matches autoselection
  8245. // set preset that we consider "default"
  8246. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8247. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8248. }
  8249. else
  8250. {
  8251. // there is preset matching autoselection
  8252. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8253. if (CopyParamName == FCopyParamAutoSelected)
  8254. {
  8255. // autoselected the same preset as the last time
  8256. // make no change (i.e. preserve custom user preset, if any)
  8257. }
  8258. else
  8259. {
  8260. // autoselected the different preset then the last time (or there
  8261. // was default preset set)
  8262. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8263. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8264. }
  8265. }
  8266. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8267. {
  8268. if (CopyParamIndex >= 0)
  8269. {
  8270. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8271. }
  8272. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8273. try
  8274. {
  8275. int Fmt =
  8276. (CopyParamIndex < 0) ?
  8277. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8278. COPY_PARAM_AUTOSELECTED;
  8279. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8280. Data->Message = MainInstructions(Message);
  8281. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8282. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8283. CopyParamAttrs);
  8284. if (CopyParamIndex >= 0)
  8285. {
  8286. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8287. Info = FORMAT(L"%s\n \n%s", (Info,
  8288. FMTLOAD(COPY_PARAM_RULE,
  8289. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8290. }
  8291. Data->Message += L"\n\n" + Info;
  8292. if (WinConfiguration->CopyParamAutoSelectNotice)
  8293. {
  8294. TransferPresetNoteMessage(Data, true);
  8295. }
  8296. else
  8297. {
  8298. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8299. Data = NULL; // ownership passed
  8300. }
  8301. }
  8302. __finally
  8303. {
  8304. delete Data;
  8305. }
  8306. }
  8307. }
  8308. }
  8309. //---------------------------------------------------------------------------
  8310. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8311. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8312. {
  8313. DebugAssert(NoteData != NULL);
  8314. DebugAssert(!IsLocalBrowserMode());
  8315. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8316. TQueryButtonAlias Aliases[1];
  8317. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8318. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8319. Params.Aliases = Aliases;
  8320. Params.AliasesCount = LENOF(Aliases);
  8321. unsigned int Result =
  8322. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8323. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8324. switch (Result)
  8325. {
  8326. case qaNeverAskAgain:
  8327. DebugAssert(AllowNeverAskAgain);
  8328. WinConfiguration->CopyParamAutoSelectNotice = false;
  8329. break;
  8330. case qaIgnore:
  8331. PreferencesDialog(pmPresets);
  8332. break;
  8333. }
  8334. }
  8335. //---------------------------------------------------------------------------
  8336. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8337. {
  8338. // as of now useless, as this is used for notes only, never for balloons, ...
  8339. RestoreApp();
  8340. // .. and we should never be busy here
  8341. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8342. {
  8343. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8344. }
  8345. }
  8346. //---------------------------------------------------------------------------
  8347. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8348. TPreferencesMode APreferencesMode)
  8349. {
  8350. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8351. TCopyParamRuleData Data;
  8352. if (Terminal != NULL)
  8353. {
  8354. PreferencesData.reset(new TPreferencesDialogData());
  8355. GetTransferPresetAutoSelectData(Data);
  8356. PreferencesData->CopyParamRuleData = &Data;
  8357. }
  8358. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8359. }
  8360. //---------------------------------------------------------------------------
  8361. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8362. const TCustomCommandType & Command)
  8363. {
  8364. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8365. {
  8366. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (Command.Command)));
  8367. }
  8368. }
  8369. //---------------------------------------------------------------------------
  8370. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8371. {
  8372. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8373. TCustomCommandType Command;
  8374. // make sure we use local custom command when remote are not supported
  8375. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8376. {
  8377. Command = FLastCustomCommand;
  8378. }
  8379. else
  8380. {
  8381. Command.Params = Command.Params | ccLocal;
  8382. }
  8383. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8384. FEditingFocusedAdHocCommand = OnFocused;
  8385. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8386. int Options =
  8387. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8388. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8389. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8390. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8391. {
  8392. FLastCustomCommand = Command;
  8393. UpdateCustomCommandsToolbar();
  8394. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8395. }
  8396. }
  8397. //---------------------------------------------------------------------------
  8398. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8399. {
  8400. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8401. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8402. DebugAssert(State > 0);
  8403. if (State <= 0)
  8404. {
  8405. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (FLastCustomCommand.Command)));
  8406. }
  8407. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8408. }
  8409. //---------------------------------------------------------------------------
  8410. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8411. TCustomCommandType & Command, int & State)
  8412. {
  8413. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8414. if (Result)
  8415. {
  8416. Command = FLastCustomCommand;
  8417. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8418. }
  8419. return Result;
  8420. }
  8421. //---------------------------------------------------------------------------
  8422. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8423. {
  8424. ResetIncrementalSearch();
  8425. }
  8426. //---------------------------------------------------------------------------
  8427. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8428. {
  8429. DebugAssert(ComponentVisible[Component]);
  8430. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8431. }
  8432. //---------------------------------------------------------------------------
  8433. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8434. {
  8435. // when queue panel is resized here directly, the status bar is stretched
  8436. // over whole space the panel occupied
  8437. PostComponentHide(fcQueueView);
  8438. }
  8439. //---------------------------------------------------------------------------
  8440. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8441. {
  8442. ComponentVisible[fcQueueFileList] = false;
  8443. }
  8444. //---------------------------------------------------------------------------
  8445. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8446. {
  8447. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8448. RefreshColorMode();
  8449. WinConfiguration->ResetSysDarkTheme();
  8450. ConfigurationChanged();
  8451. ConfigureInterface();
  8452. // Should be called for all controls
  8453. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8454. }
  8455. //---------------------------------------------------------------------------
  8456. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8457. {
  8458. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8459. if (!FInvalid &&
  8460. (Message.LParam != 0) &&
  8461. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8462. {
  8463. ThemeChanged();
  8464. }
  8465. TForm::Dispatch(&Message);
  8466. }
  8467. //---------------------------------------------------------------------------
  8468. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8469. {
  8470. TMessage * M = static_cast<TMessage*>(Message);
  8471. switch (M->Msg)
  8472. {
  8473. case CM_DIALOGCHAR:
  8474. CMDialogChar(*M);
  8475. break;
  8476. case WM_APPCOMMAND:
  8477. WMAppCommand(*M);
  8478. break;
  8479. case WM_SYSCOMMAND:
  8480. WMSysCommand(*M);
  8481. break;
  8482. case WM_QUERYENDSESSION:
  8483. WMQueryEndSession(*M);
  8484. break;
  8485. case WM_ENDSESSION:
  8486. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8487. break;
  8488. #ifdef _DEBUG
  8489. case WM_WINDOWPOSCHANGED:
  8490. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8491. break;
  8492. case CM_CUSTOMSTYLECHANGED:
  8493. TForm::Dispatch(Message);
  8494. break;
  8495. #endif
  8496. case WM_COMPONENT_HIDE:
  8497. {
  8498. Byte Component = static_cast<Byte>(M->WParam);
  8499. // sanity check
  8500. if (ComponentVisible[Component])
  8501. {
  8502. // special treatment
  8503. if (Component == fcQueueView)
  8504. {
  8505. ToggleQueueVisibility();
  8506. DebugAssert(!ComponentVisible[fcQueueView]);
  8507. }
  8508. else
  8509. {
  8510. ComponentVisible[Component] = false;
  8511. }
  8512. }
  8513. }
  8514. break;
  8515. case WM_COPYDATA:
  8516. WMCopyData(*M);
  8517. break;
  8518. case WM_MANAGES_CAPTION:
  8519. // caption managed in TTerminalManager::UpdateAppTitle()
  8520. M->Result = 1;
  8521. break;
  8522. case WM_WANTS_MOUSEWHEEL:
  8523. M->Result = 1;
  8524. break;
  8525. case CM_SHOWINGCHANGED:
  8526. CMShowingChanged(*M);
  8527. break;
  8528. case WM_CLOSE:
  8529. WMClose(*M);
  8530. break;
  8531. case WM_DPICHANGED:
  8532. WMDpiChanged(*M);
  8533. break;
  8534. case CM_DPICHANGED:
  8535. CMDpiChanged(*M);
  8536. break;
  8537. case WM_SETTINGCHANGE:
  8538. WMSettingChange(*M);
  8539. break;
  8540. case CM_DIALOGKEY:
  8541. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8542. break;
  8543. default:
  8544. TForm::Dispatch(Message);
  8545. break;
  8546. }
  8547. }
  8548. //---------------------------------------------------------------------------
  8549. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8550. {
  8551. // noop
  8552. }
  8553. //---------------------------------------------------------------------------
  8554. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8555. {
  8556. TForm::Dispatch(&Message);
  8557. FSessionColors->Clear();
  8558. AddFixedSessionImages();
  8559. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8560. UpdateImages();
  8561. }
  8562. //---------------------------------------------------------------------------
  8563. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8564. {
  8565. TForm::Dispatch(&Message);
  8566. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8567. UpdatePixelsPerInchMainWindowCounter();
  8568. }
  8569. //---------------------------------------------------------------------------
  8570. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8571. {
  8572. // Cannot close window while we are busy.
  8573. // We cannot test this in FormCloseQuery as that is called also from
  8574. // Close(), which is called by CloseApplicationAction. So we can be busy
  8575. // there already even, when it is legitimate to close the application.
  8576. // Possibly a better place to handle this would be WMSysCommand.
  8577. if (NonVisualDataModule->Busy)
  8578. {
  8579. Message.Result = 1;
  8580. }
  8581. else
  8582. {
  8583. TForm::Dispatch(&Message);
  8584. }
  8585. }
  8586. //---------------------------------------------------------------------------
  8587. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8588. {
  8589. TForm::Dispatch(&Message);
  8590. if (Showing && (Terminal == NULL))
  8591. {
  8592. // When we are starting minimized (i.e. from an installer),
  8593. // postpone showing Login dialog until we get restored.
  8594. // Otherwise the Login dialog (and Authentication window) show restored
  8595. // over invisible (minimized) main window.
  8596. if (WindowState == wsMinimized)
  8597. {
  8598. FNeedSession = true;
  8599. }
  8600. else
  8601. {
  8602. // This happens before application ever goes idle, so the toolbars would
  8603. // stay enabled (initial state) until the Login dialog is dismissed.
  8604. UpdateActions();
  8605. NonVisualDataModule->StartBusy();
  8606. try
  8607. {
  8608. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8609. // otherwise the dialog does not receive focus.
  8610. // With Commander interface the ProcessMessages is called already
  8611. // by TDriveView, but with Explorer interface, we need to call it explicily
  8612. Application->ProcessMessages();
  8613. // do not reload sessions, they have been loaded just now (optimization)
  8614. NeedSession(true);
  8615. }
  8616. __finally
  8617. {
  8618. NonVisualDataModule->EndBusy();
  8619. }
  8620. }
  8621. }
  8622. }
  8623. //---------------------------------------------------------------------------
  8624. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8625. {
  8626. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8627. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8628. }
  8629. //---------------------------------------------------------------------------
  8630. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8631. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8632. int & MaxHeight)
  8633. {
  8634. // workaround for bug in TWinControl.CalcConstraints
  8635. // Check for empty rect (restore from iconic state) is done there only after
  8636. // call to AdjustClientRect, which enlarges the rect (for forms).
  8637. TRect R = GetClientRect();
  8638. // when restoring from iconic state, place no restrictions
  8639. if (IsRectEmpty(R))
  8640. {
  8641. MinWidth = 0;
  8642. MinHeight = 0;
  8643. MaxWidth = 32000;
  8644. MaxHeight = 32000;
  8645. }
  8646. }
  8647. //---------------------------------------------------------------------------
  8648. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8649. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8650. {
  8651. // terminal can be already closed (e.g. dropped connection)
  8652. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8653. {
  8654. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8655. try
  8656. {
  8657. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8658. }
  8659. catch(...)
  8660. {
  8661. if (!Terminal->Active)
  8662. {
  8663. Close = true;
  8664. }
  8665. throw;
  8666. }
  8667. }
  8668. }
  8669. //---------------------------------------------------------------------------
  8670. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8671. {
  8672. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8673. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8674. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8675. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8676. {
  8677. OnGetSpaceAvailable = GetSpaceAvailable;
  8678. }
  8679. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8680. OnGetSpaceAvailable);
  8681. }
  8682. //---------------------------------------------------------------------------
  8683. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8684. {
  8685. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8686. Terminal->FillSessionDataForCode(Data.get());
  8687. return Data.release();
  8688. }
  8689. //---------------------------------------------------------------------------
  8690. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8691. {
  8692. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8693. DoGenerateUrlDialog(Data.get(), Paths);
  8694. }
  8695. //---------------------------------------------------------------------------
  8696. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8697. {
  8698. GenerateUrl(NULL);
  8699. }
  8700. //---------------------------------------------------------------------------
  8701. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8702. {
  8703. std::unique_ptr<TStrings> Paths(new TStringList());
  8704. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8705. GenerateUrl(Paths.get());
  8706. }
  8707. //---------------------------------------------------------------------------
  8708. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8709. {
  8710. FSessionColor = value;
  8711. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8712. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8713. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8714. DebugAssert(ColorItem != NULL);
  8715. ColorItem->Color = C;
  8716. NonVisualDataModule->ColorMenuItem->Color = C;
  8717. UpdateControls();
  8718. }
  8719. //---------------------------------------------------------------------------
  8720. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8721. {
  8722. if (value != FSessionColor)
  8723. {
  8724. UpdateSessionColor(value);
  8725. // Is null when called from LastTerminalClosed
  8726. if (Terminal != NULL)
  8727. {
  8728. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8729. }
  8730. }
  8731. }
  8732. //---------------------------------------------------------------------------
  8733. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8734. {
  8735. bool Result = FNoteTimer->Enabled;
  8736. if (Result)
  8737. {
  8738. // cannot cancel note too early
  8739. bool NotEarly =
  8740. (Now() - FNoteShown >
  8741. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8742. if (Force || NotEarly)
  8743. {
  8744. FNoteTimer->Enabled = false;
  8745. FNote = L"";
  8746. SAFE_DESTROY(FNoteData);
  8747. FOnNoteClick = NULL;
  8748. FNoteHints = FNotes->Text;
  8749. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8750. UpdateStatusBar();
  8751. }
  8752. }
  8753. return Result;
  8754. }
  8755. //---------------------------------------------------------------------------
  8756. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8757. {
  8758. DebugAssert(FNoteTimer->Enabled);
  8759. CancelNote(true);
  8760. }
  8761. //---------------------------------------------------------------------------
  8762. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8763. {
  8764. int P = Note.Pos(L"\n");
  8765. if (P > 0)
  8766. {
  8767. Note.SetLength(P - 1);
  8768. }
  8769. FNotes->Add(FORMAT(L"[%s] %s",
  8770. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8771. while (FNotes->Count > 10)
  8772. {
  8773. FNotes->Delete(0);
  8774. }
  8775. if (UpdateNow)
  8776. {
  8777. FNoteHints = FNotes->Text;
  8778. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8779. UpdateStatusBar();
  8780. }
  8781. }
  8782. //---------------------------------------------------------------------------
  8783. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8784. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8785. {
  8786. int P = Note.Pos(L"\n");
  8787. if (P > 0)
  8788. {
  8789. Note.SetLength(P - 1);
  8790. }
  8791. FNoteHints = FNotes->Text;
  8792. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8793. FNote = Note;
  8794. SAFE_DESTROY(FNoteData);
  8795. FNoteData = NoteData;
  8796. FOnNoteClick = OnNoteClick;
  8797. AddNote(Note, false);
  8798. UpdateStatusBar();
  8799. FNoteShown = Now();
  8800. FNoteTimer->Enabled = false;
  8801. if (Seconds == 0)
  8802. {
  8803. Seconds = WinConfiguration->NotificationsTimeout;
  8804. }
  8805. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8806. FNoteTimer->Enabled = true;
  8807. }
  8808. //---------------------------------------------------------------------------
  8809. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8810. {
  8811. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8812. }
  8813. //---------------------------------------------------------------------------
  8814. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8815. {
  8816. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  8817. {
  8818. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8819. }
  8820. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8821. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8822. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  8823. 0, NULL, NULL);
  8824. }
  8825. //---------------------------------------------------------------------------
  8826. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8827. {
  8828. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8829. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8830. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8831. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8832. }
  8833. //---------------------------------------------------------------------------
  8834. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8835. {
  8836. WinConfiguration->FormatSizeBytes = Style;
  8837. }
  8838. //---------------------------------------------------------------------------
  8839. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8840. {
  8841. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8842. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8843. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8844. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8845. }
  8846. //---------------------------------------------------------------------------
  8847. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8848. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8849. {
  8850. if (Panel->Index == 0)
  8851. {
  8852. if (FOnNoteClick != NULL)
  8853. {
  8854. // prevent the user data from being freed by possible call
  8855. // to CancelNote or PostNote during call to OnNoteClick
  8856. std::unique_ptr<TObject> NoteData(FNoteData);
  8857. TNotifyEvent OnNoteClick = FOnNoteClick;
  8858. FNoteData = NULL;
  8859. // need to cancel the note as we are going to delete its user data
  8860. CancelNote(true);
  8861. OnNoteClick(NoteData.get());
  8862. }
  8863. }
  8864. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8865. {
  8866. FileSystemInfo();
  8867. }
  8868. }
  8869. //---------------------------------------------------------------------------
  8870. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8871. {
  8872. // workaround:
  8873. // 1) for unknown reason, disabling window, while minimized,
  8874. // prevents it from restoring, even if it was enabled again meanwhile
  8875. // 2) when disabling the main window, while another has focus
  8876. // minimize is no longer possible
  8877. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8878. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8879. // Shouldn't we use IsApplicationMinimized() here?
  8880. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8881. {
  8882. Enabled = false;
  8883. }
  8884. FLockLevel++;
  8885. }
  8886. //---------------------------------------------------------------------------
  8887. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8888. {
  8889. DebugAssert(FLockLevel > 0);
  8890. FLockLevel--;
  8891. if (FLockLevel == 0)
  8892. {
  8893. DebugAssert(FLockSuspendLevel == 0);
  8894. Enabled = true;
  8895. }
  8896. }
  8897. //---------------------------------------------------------------------------
  8898. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8899. {
  8900. // We need to make sure that window is enabled when the last modal window closes
  8901. // otherwise focus is not restored correctly.
  8902. // So we re-enable the window when modal window opens and
  8903. // disable it back after is closes
  8904. if (FLockLevel > 0)
  8905. {
  8906. // while we have nesting counter, we know that we never be called
  8907. // recursivelly as Application->OnModalBegin is called only
  8908. // for the top-level modal window
  8909. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8910. {
  8911. // won't be disabled when conditions in LockWindow() were not satisfied
  8912. FDisabledOnLockSuspend = !Enabled;
  8913. // When minimized to tray (or actually when set to SW_HIDE),
  8914. // setting Enabled makes the window focusable even when there's
  8915. // modal window over it
  8916. if (!FTrayIcon->Visible)
  8917. {
  8918. Enabled = true;
  8919. }
  8920. }
  8921. FLockSuspendLevel++;
  8922. }
  8923. }
  8924. //---------------------------------------------------------------------------
  8925. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8926. {
  8927. if (FLockSuspendLevel > 0)
  8928. {
  8929. DebugAssert(FLockLevel > 0);
  8930. FLockSuspendLevel--;
  8931. // see comment in SuspendWindowLock
  8932. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8933. {
  8934. // Note that window can be enabled here, when we were minized to tray when
  8935. // was SuspendWindowLock() called.
  8936. // We should possibly do the same check as in LockWindow(),
  8937. // if it is ever possible that the consitions change between
  8938. // SuspendWindowLock() and ResumeWindowLock()
  8939. Enabled = !FDisabledOnLockSuspend;
  8940. }
  8941. }
  8942. }
  8943. //---------------------------------------------------------------------------
  8944. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8945. {
  8946. if (!TextOnly)
  8947. {
  8948. TTBXComboBoxItem * RemotePathComboBox =
  8949. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8950. TStrings * Items = RemotePathComboBox->Strings;
  8951. Items->BeginUpdate();
  8952. try
  8953. {
  8954. Items->Clear();
  8955. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  8956. {
  8957. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8958. while (!IsUnixRootPath(APath))
  8959. {
  8960. int P = APath.LastDelimiter(L'/');
  8961. DebugAssert(P >= 0);
  8962. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8963. APath.SetLength(P - 1);
  8964. }
  8965. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8966. }
  8967. }
  8968. __finally
  8969. {
  8970. RemotePathComboBox->ItemIndex = Items->Count - 1;
  8971. // Setting ItemIndex to -1 does not reset its text
  8972. if (Items->Count == 0)
  8973. {
  8974. RemotePathComboBox->Text = L"";
  8975. }
  8976. Items->EndUpdate();
  8977. }
  8978. }
  8979. }
  8980. //---------------------------------------------------------------------------
  8981. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  8982. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  8983. int & ImageIndex)
  8984. {
  8985. if (AIndex < 0)
  8986. {
  8987. AIndex = Sender->ItemIndex;
  8988. }
  8989. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  8990. }
  8991. //---------------------------------------------------------------------------
  8992. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  8993. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  8994. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  8995. {
  8996. ARect.Left += (10 * AIndex);
  8997. }
  8998. //---------------------------------------------------------------------------
  8999. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9000. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9001. {
  9002. AWidth += (10 * AIndex);
  9003. }
  9004. //---------------------------------------------------------------------------
  9005. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  9006. TObject * Sender)
  9007. {
  9008. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9009. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9010. int Index = RemotePathComboBox->ItemIndex;
  9011. while (Index < RemotePathComboBox->Strings->Count - 1)
  9012. {
  9013. APath = UnixExtractFileDir(APath);
  9014. Index++;
  9015. }
  9016. // VanDyke style paths
  9017. if (APath.IsEmpty())
  9018. {
  9019. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9020. APath = ROOTDIRECTORY;
  9021. }
  9022. if (RemoteDirView->Path != APath)
  9023. {
  9024. RemoteDirView->Path = APath;
  9025. }
  9026. }
  9027. //---------------------------------------------------------------------------
  9028. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9029. {
  9030. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9031. DebugUsedParam(Sender);
  9032. UpdateRemotePathComboBox(true);
  9033. }
  9034. //---------------------------------------------------------------------------
  9035. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9036. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9037. {
  9038. ResetIncrementalSearch();
  9039. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9040. DebugAssert(DirView != NULL);
  9041. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9042. {
  9043. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9044. // OnEditing is called also from TCustomListView::CanEdit
  9045. if (Edit != NULL)
  9046. {
  9047. EditSelectBaseName(Edit);
  9048. }
  9049. }
  9050. }
  9051. //---------------------------------------------------------------------------
  9052. //---------------------------------------------------------------------------
  9053. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9054. {
  9055. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9056. Result->AutoDetectDnD = false;
  9057. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9058. Result->RenderDataOn = rdoEnterAndDropSync;
  9059. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9060. return Result;
  9061. }
  9062. //---------------------------------------------------------------------------
  9063. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9064. {
  9065. TForm::CreateWnd();
  9066. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9067. if (FSessionsDragDropFilesEx == NULL)
  9068. {
  9069. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9070. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9071. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9072. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9073. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9074. }
  9075. if (FQueueDragDropFilesEx == NULL)
  9076. {
  9077. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9078. // No need to set OnDragOver as we do not have any restrictions
  9079. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9080. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9081. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9082. }
  9083. }
  9084. //---------------------------------------------------------------------------
  9085. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9086. {
  9087. TForm::DestroyWnd();
  9088. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9089. FQueueDragDropFilesEx->DragDropControl = NULL;
  9090. }
  9091. //---------------------------------------------------------------------------
  9092. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9093. {
  9094. SideEnter(FCurrentSide);
  9095. FEverShown = true;
  9096. }
  9097. //---------------------------------------------------------------------------
  9098. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9099. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9100. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9101. {
  9102. if (!NonVisualDataModule->Busy)
  9103. {
  9104. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9105. Configuration->Usage->Inc(L"FileFinds");
  9106. LockWindow(true);
  9107. NonVisualDataModule->StartBusy();
  9108. WinConfiguration->LockedInterface = true;
  9109. try
  9110. {
  9111. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9112. }
  9113. __finally
  9114. {
  9115. WinConfiguration->LockedInterface = false;
  9116. NonVisualDataModule->EndBusy();
  9117. UnlockWindow();
  9118. }
  9119. }
  9120. }
  9121. //---------------------------------------------------------------------------
  9122. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9123. {
  9124. if (!NonVisualDataModule->Busy)
  9125. {
  9126. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9127. SetFocus();
  9128. RemoteDirView->Path = UnixExtractFilePath(Path);
  9129. UnicodeString FileName = UnixExtractFileName(Path);
  9130. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9131. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9132. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9133. if (Item == NULL)
  9134. {
  9135. ReloadDirectory(osRemote);
  9136. Item = RemoteDirView->FindFileItem(FileName);
  9137. }
  9138. if (Item != NULL)
  9139. {
  9140. RemoteDirView->ItemFocused = Item;
  9141. RemoteDirView->ItemFocused->MakeVisible(false);
  9142. RemoteDirView->SetFocus();
  9143. }
  9144. }
  9145. }
  9146. //---------------------------------------------------------------------------
  9147. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9148. {
  9149. bool Result = !NonVisualDataModule->Busy;
  9150. if (Result)
  9151. {
  9152. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9153. }
  9154. return Result;
  9155. }
  9156. //---------------------------------------------------------------------------
  9157. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9158. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9159. {
  9160. if (CanOperateOnFoundFiles(ATerminal))
  9161. {
  9162. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9163. FOnFileOperationFinished = OnFileOperationFinished;
  9164. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9165. }
  9166. }
  9167. //---------------------------------------------------------------------------
  9168. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9169. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9170. {
  9171. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9172. }
  9173. //---------------------------------------------------------------------------
  9174. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9175. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9176. {
  9177. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9178. }
  9179. //---------------------------------------------------------------------------
  9180. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9181. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9182. {
  9183. if (CanOperateOnFoundFiles(ATerminal))
  9184. {
  9185. for (int Index = 0; Index < FileList->Count; Index++)
  9186. {
  9187. UnicodeString FileName = FileList->Strings[Index];
  9188. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9189. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9190. OnFileOperationFinished(FileName, true);
  9191. }
  9192. }
  9193. }
  9194. //---------------------------------------------------------------------------
  9195. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9196. {
  9197. FFileFindTerminal = Terminal;
  9198. ShowFileFindDialog(
  9199. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9200. DoDownloadFoundFiles, DoEditFoundFiles);
  9201. }
  9202. //---------------------------------------------------------------------------
  9203. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9204. {
  9205. FTaskbarList = TaskbarList;
  9206. }
  9207. //---------------------------------------------------------------------------
  9208. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9209. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9210. {
  9211. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9212. if (Index >= 0)
  9213. {
  9214. if (Button == mbLeft)
  9215. {
  9216. // "Mouse down" is raised only after tab is switched.
  9217. // If switching tab (switching session) takes long enough for user
  9218. // to actually release the button, "mouse down" is still raised,
  9219. // but we do not get "mouse up" event, so dragging is not cancelled,
  9220. // prevent that by not beginning dragging in the first place.
  9221. if (IsKeyPressed(VK_LBUTTON))
  9222. {
  9223. // when user clicks the "+", we get mouse down only after the session
  9224. // is closed, when new session tab is already on X:Y, so dragging
  9225. // starts, prevent that
  9226. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9227. {
  9228. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9229. if (Terminal != NULL)
  9230. {
  9231. SessionsPageControl->BeginDrag(false);
  9232. }
  9233. }
  9234. }
  9235. }
  9236. else if (Button == mbMiddle)
  9237. {
  9238. // ignore middle-click for "New session tab"
  9239. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9240. if (Terminal != NULL)
  9241. {
  9242. CloseSessionTab(Index);
  9243. }
  9244. }
  9245. }
  9246. }
  9247. //---------------------------------------------------------------------------
  9248. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9249. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9250. {
  9251. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9252. // do not allow dropping on the "+" tab
  9253. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9254. if ((TargetTerminal != NULL) &&
  9255. (SessionsPageControl->ActivePage->PageIndex != Index))
  9256. {
  9257. Configuration->Usage->Inc(L"SessionTabMoves");
  9258. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9259. // but we want to actually prevent that to avoid flicker
  9260. SessionsPageControl->ActivePage->PageIndex = Index;
  9261. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9262. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9263. }
  9264. }
  9265. //---------------------------------------------------------------------------
  9266. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9267. TObject * Sender, TObject * Source, int X, int Y,
  9268. TDragState /*State*/, bool & Accept)
  9269. {
  9270. Accept = (Sender == Source);
  9271. if (Accept)
  9272. {
  9273. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9274. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9275. // do not allow dragging to the "+" tab
  9276. Accept = (Terminal != NULL);
  9277. }
  9278. }
  9279. //---------------------------------------------------------------------------
  9280. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9281. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9282. {
  9283. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9284. if (Index < 0)
  9285. {
  9286. Effect = DROPEFFECT_NONE;
  9287. }
  9288. else
  9289. {
  9290. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9291. // do not allow dropping on the "+" tab
  9292. if (TargetTerminal == NULL)
  9293. {
  9294. Effect = DROPEFFECT_NONE;
  9295. }
  9296. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9297. {
  9298. Effect = DROPEFFECT_COPY;
  9299. }
  9300. }
  9301. }
  9302. //---------------------------------------------------------------------------
  9303. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9304. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9305. {
  9306. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9307. // do not allow dropping on the "+" tab
  9308. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9309. if (TargetTerminal != NULL)
  9310. {
  9311. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9312. if (!IsFileControl(DropSourceControl, osRemote))
  9313. {
  9314. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9315. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9316. // Why don't we use Terminal->CurrentDirectory directly?
  9317. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9318. // do not force queue, drag drop
  9319. false, true);
  9320. }
  9321. }
  9322. }
  9323. //---------------------------------------------------------------------------
  9324. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9325. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9326. {
  9327. // Downloads are handled in RemoteFileControlDDEnd
  9328. if (!IsFileControl(DropSourceControl, osRemote))
  9329. {
  9330. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9331. Terminal->CurrentDirectory,
  9332. // force queue, drag drop
  9333. true, true);
  9334. }
  9335. }
  9336. //---------------------------------------------------------------------------
  9337. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9338. {
  9339. FShowing = false;
  9340. // Do not save empty workspace
  9341. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9342. {
  9343. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9344. UnicodeString Name = WorkspaceName();
  9345. DoSaveWorkspace(
  9346. Name, DataList.get(),
  9347. !Configuration->DisablePasswordStoring &&
  9348. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9349. WinConfiguration->LastStoredSession = Name;
  9350. }
  9351. }
  9352. //---------------------------------------------------------------------------
  9353. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9354. {
  9355. TManagedTerminal * ManagedTerminal =
  9356. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9357. if (ManagedTerminal != NULL)
  9358. {
  9359. ManagedTerminal->DirectoryLoaded = Now();
  9360. }
  9361. }
  9362. //---------------------------------------------------------------------------
  9363. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9364. TListItem * /*Item*/, bool /*Selected*/)
  9365. {
  9366. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9367. switch (DirView->LastSelectMethod)
  9368. {
  9369. case smKeyboard:
  9370. Configuration->Usage->Inc(L"KeyboardSelections");
  9371. break;
  9372. case smMouse:
  9373. Configuration->Usage->Inc(L"MouseSelections");
  9374. break;
  9375. }
  9376. }
  9377. //---------------------------------------------------------------------------
  9378. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9379. {
  9380. if (Color != 0)
  9381. {
  9382. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9383. }
  9384. else
  9385. {
  9386. return FSessionTabImageIndex;
  9387. }
  9388. }
  9389. //---------------------------------------------------------------------------
  9390. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9391. {
  9392. TPngImageCollectionItem * Item =
  9393. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9394. FSessionColors->AddPng(Item->PngImage);
  9395. return FSessionColors->Count - 1;
  9396. }
  9397. //---------------------------------------------------------------------------
  9398. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9399. {
  9400. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9401. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9402. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9403. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9404. }
  9405. //---------------------------------------------------------------------------
  9406. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9407. {
  9408. for (int Index = 0; Index < Control->ControlCount; Index++)
  9409. {
  9410. TControl * AControl = Control->Controls[Index];
  9411. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9412. if (WinControl != NULL)
  9413. {
  9414. CollectItemsWithTextDisplayMode(WinControl);
  9415. }
  9416. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9417. if (Toolbar != NULL)
  9418. {
  9419. // we care for top-level items only
  9420. TTBCustomItem * Items = Toolbar->Items;
  9421. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9422. {
  9423. TTBCustomItem * Item = Items->Items[ItemIndex];
  9424. if (((Item->DisplayMode == nbdmImageAndText) ||
  9425. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9426. EligibleForImageDisplayMode(Item))
  9427. {
  9428. FItemsWithTextDisplayMode.insert(Item);
  9429. }
  9430. }
  9431. }
  9432. }
  9433. }
  9434. //---------------------------------------------------------------------------
  9435. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9436. {
  9437. return true;
  9438. }
  9439. //---------------------------------------------------------------------------
  9440. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9441. {
  9442. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9443. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9444. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9445. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9446. bool Result = true;
  9447. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9448. {
  9449. TTBCustomItem * Item = *i;
  9450. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9451. if (Label != NULL)
  9452. {
  9453. // optimization
  9454. if (Label->Visible == SelectiveToolbarText)
  9455. {
  9456. Result = false;
  9457. }
  9458. else
  9459. {
  9460. Label->Visible = SelectiveToolbarText;
  9461. }
  9462. }
  9463. else
  9464. {
  9465. // optimization
  9466. if (Item->DisplayMode == DisplayMode)
  9467. {
  9468. Result = false;
  9469. }
  9470. else
  9471. {
  9472. Item->DisplayMode = DisplayMode;
  9473. }
  9474. }
  9475. ++i;
  9476. }
  9477. if (Result)
  9478. {
  9479. UpdateNewSessionTab();
  9480. }
  9481. return Result;
  9482. }
  9483. //---------------------------------------------------------------------------
  9484. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9485. {
  9486. DebugFail();
  9487. }
  9488. //---------------------------------------------------------------------------
  9489. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9490. {
  9491. // Among other, a lock level is non zero, while directory is being loaded,
  9492. // even when it happens as a result of dirview navigation,
  9493. // i.e. when TNonVisualDataModule is NOT FBusy.
  9494. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9495. // Among other this prevents a panel auto update to occur while
  9496. // directory is changing.
  9497. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9498. }
  9499. //---------------------------------------------------------------------------
  9500. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  9501. {
  9502. // While the window is disabled, we still seem to process menu shortcuts at least,
  9503. // so stop it at least here.
  9504. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9505. return
  9506. (Allowed == aaUpdate) ||
  9507. !NonVisualDataModule->Busy;
  9508. }
  9509. //---------------------------------------------------------------------------
  9510. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9511. {
  9512. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9513. }
  9514. //---------------------------------------------------------------------------
  9515. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9516. {
  9517. // This is somewhat redundant to LockWindow() call from
  9518. // TTerminalManager::TerminalReadDirectoryProgress.
  9519. // But disabling window is known not to block keyboard shorcuts
  9520. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9521. if (Busy > 0)
  9522. {
  9523. if (NonVisualDataModule->Busy)
  9524. {
  9525. State = false;
  9526. }
  9527. else
  9528. {
  9529. NonVisualDataModule->StartBusy();
  9530. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9531. LockWindow();
  9532. }
  9533. }
  9534. else if (Busy < 0)
  9535. {
  9536. UnlockWindow();
  9537. NonVisualDataModule->EndBusy();
  9538. }
  9539. else
  9540. {
  9541. State = NonVisualDataModule->Busy;
  9542. }
  9543. }
  9544. //---------------------------------------------------------------------------
  9545. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9546. {
  9547. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9548. // no context menu for "New session tab"
  9549. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9550. {
  9551. SessionsPageControl->ActivePageIndex = Index;
  9552. if (DebugAlwaysTrue(SessionTabSwitched()))
  9553. {
  9554. // copied from TControl.WMContextMenu
  9555. SendCancelMode(SessionsPageControl);
  9556. // explicit popup instead of using PopupMenu property
  9557. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9558. // while connecting yet not-connected session and hence
  9559. // allowing an access to commands over not-completelly connected session
  9560. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9561. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9562. PopupMenu->PopupComponent = SessionsPageControl;
  9563. PopupMenu->Popup(Point.x, Point.y);
  9564. }
  9565. }
  9566. Handled = true;
  9567. }
  9568. //---------------------------------------------------------------------------
  9569. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9570. {
  9571. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9572. }
  9573. //---------------------------------------------------------------------------
  9574. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9575. {
  9576. Configuration->Usage->Inc(L"PasswordChanges");
  9577. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9578. ChangePasswordData->DisableAuthentationsExceptPassword();
  9579. ChangePasswordData->ChangePassword = true;
  9580. std::unique_ptr<TTerminal> ChangePasswordSession(
  9581. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9582. ChangePasswordSession->AutoReadDirectory = false;
  9583. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9584. {
  9585. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9586. }
  9587. else
  9588. {
  9589. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9590. }
  9591. }
  9592. //---------------------------------------------------------------------------
  9593. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9594. {
  9595. // No nice way to assert SSH2
  9596. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9597. }
  9598. //---------------------------------------------------------------------------
  9599. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9600. {
  9601. TOperationVisualizer OperationVisualizer;
  9602. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9603. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9604. }
  9605. //---------------------------------------------------------------------------
  9606. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9607. {
  9608. TForm::ChangeScale(M, D);
  9609. int APixelsPerInch = GetControlPixelsPerInch(this);
  9610. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9611. try
  9612. {
  9613. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9614. }
  9615. __finally
  9616. {
  9617. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9618. }
  9619. }
  9620. //---------------------------------------------------------------------------
  9621. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9622. {
  9623. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9624. }
  9625. //---------------------------------------------------------------------
  9626. class TPublicControl : public TControl
  9627. {
  9628. friend class TCustomScpExplorerForm;
  9629. };
  9630. //---------------------------------------------------------------------------
  9631. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9632. {
  9633. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9634. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9635. }
  9636. //---------------------------------------------------------------------------
  9637. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9638. {
  9639. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9640. OpenBookmark(Side, Bookmark);
  9641. }
  9642. //---------------------------------------------------------------------------
  9643. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9644. {
  9645. DoBookmarkClick(osLocal, Sender);
  9646. }
  9647. //---------------------------------------------------------------------------
  9648. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9649. {
  9650. DoBookmarkClick(osRemote, Sender);
  9651. }
  9652. //---------------------------------------------------------------------------
  9653. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9654. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9655. {
  9656. // TODO
  9657. if (BookmarkList != NULL)
  9658. {
  9659. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9660. if (!WinConfiguration->UseLocationProfiles)
  9661. {
  9662. std::unique_ptr<TStringList> Directories(new TStringList());
  9663. Directories->CaseSensitive = (Side == osRemote);
  9664. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9665. {
  9666. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9667. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9668. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9669. {
  9670. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9671. Item->Caption = EscapeHotkey(Directory);
  9672. Item->ShortCut = Bookmark->ShortCut;
  9673. Item->OnClick = OnBookmarkClick;
  9674. Item->Tag = reinterpret_cast<int>(Bookmark);
  9675. Directories->Add(Directory);
  9676. Menu->Add(Item.release());
  9677. }
  9678. }
  9679. }
  9680. else
  9681. {
  9682. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9683. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9684. {
  9685. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9686. if (!Bookmark->Node.IsEmpty())
  9687. {
  9688. Folders->Add(Bookmark->Node);
  9689. }
  9690. }
  9691. for (int Index = 0; Index < Folders->Count; Index++)
  9692. {
  9693. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9694. Item->Caption = Folders->Strings[Index];
  9695. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  9696. Folders->Objects[Index] = Item.get();
  9697. Menu->Add(Item.release());
  9698. }
  9699. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9700. {
  9701. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9702. TTBCustomItem * Parent;
  9703. if (!Bookmark->Node.IsEmpty())
  9704. {
  9705. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9706. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9707. }
  9708. else
  9709. {
  9710. Parent = Menu;
  9711. }
  9712. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9713. Item->Caption = Bookmark->Name;
  9714. Item->ShortCut = Bookmark->ShortCut;
  9715. Item->OnClick = OnBookmarkClick;
  9716. Item->Tag = reinterpret_cast<int>(Bookmark);
  9717. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9718. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9719. {
  9720. // No hint for location profiles that are actually mere "bookmarks"
  9721. }
  9722. else
  9723. {
  9724. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9725. UnicodeString LongHint;
  9726. if (!Bookmark->Local.IsEmpty())
  9727. {
  9728. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9729. }
  9730. if (!Bookmark->Remote.IsEmpty())
  9731. {
  9732. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9733. }
  9734. AddToList(Hint, LongHint, L"|");
  9735. Item->Hint = Hint;
  9736. }
  9737. Parent->Add(Item.release());
  9738. }
  9739. }
  9740. AddMenuSeparator(Menu);
  9741. }
  9742. }
  9743. //---------------------------------------------------------------------------
  9744. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9745. {
  9746. Menu->Clear();
  9747. std::unique_ptr<TTBCustomItem> Item;
  9748. Item.reset(new TTBXItem(Owner));
  9749. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9750. Item->Options = Item->Options << tboDefault;
  9751. Menu->Add(Item.release());
  9752. AddMenuSeparator(Menu);
  9753. if (Terminal != NULL)
  9754. {
  9755. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9756. }
  9757. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9758. Item.reset(new TTBXItem(Owner));
  9759. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  9760. Menu->Add(Item.release());
  9761. }
  9762. //---------------------------------------------------------------------------
  9763. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9764. {
  9765. bool Result = true;
  9766. try
  9767. {
  9768. if (Side == osRemote)
  9769. {
  9770. Terminal->ExceptionOnFail = true;
  9771. }
  9772. try
  9773. {
  9774. DirView(Side)->Path = Path;
  9775. }
  9776. __finally
  9777. {
  9778. if (Side == osRemote)
  9779. {
  9780. Terminal->ExceptionOnFail = false;
  9781. }
  9782. }
  9783. }
  9784. catch (Exception & E)
  9785. {
  9786. if ((Side != osRemote) || Terminal->Active)
  9787. {
  9788. ShowExtendedExceptionEx(Terminal, &E);
  9789. Result = false;
  9790. }
  9791. else
  9792. {
  9793. throw;
  9794. }
  9795. }
  9796. return Result;
  9797. }
  9798. //---------------------------------------------------------------------------
  9799. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9800. {
  9801. // Make sure there some feedback even when loading tiny local folders
  9802. TInstantOperationVisualizer Visualizer;
  9803. DirView(Side)->ReloadDirectory();
  9804. }
  9805. //---------------------------------------------------------------------------
  9806. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9807. {
  9808. if (Index == SessionsPageControl->TabIndex)
  9809. {
  9810. CloseSession();
  9811. }
  9812. else
  9813. {
  9814. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9815. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9816. TTerminalManager * Manager = TTerminalManager::Instance();
  9817. if (!Terminal->Active)
  9818. {
  9819. Manager->FreeTerminal(Terminal);
  9820. }
  9821. else
  9822. {
  9823. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9824. if (CanCloseQueue(Queue))
  9825. {
  9826. Manager->FreeTerminal(Terminal);
  9827. }
  9828. }
  9829. }
  9830. }
  9831. //---------------------------------------------------------------------------
  9832. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9833. {
  9834. CloseSessionTab(Index);
  9835. }
  9836. //---------------------------------------------------------------------------
  9837. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9838. {
  9839. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9840. {
  9841. TInstantOperationVisualizer Visualizer;
  9842. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9843. // before we create a new data object
  9844. ClipboardClear();
  9845. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9846. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9847. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9848. // Intermediate variable to WORKAROUND a crash in compiler
  9849. TObjectList * ClipboardFakeMonitors =
  9850. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9851. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9852. if (FClipboardDragDropFilesEx.get() == NULL)
  9853. {
  9854. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9855. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9856. }
  9857. FClipboardDragDropFilesEx->FileList->Clear();
  9858. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9859. FClipboardDragDropFilesEx->CopyToClipboard();
  9860. FClipboardTerminal = FTerminal;
  9861. // Need full paths, as cwd can be different once files are pasted
  9862. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9863. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9864. {
  9865. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9866. }
  9867. }
  9868. }
  9869. //---------------------------------------------------------------------------
  9870. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9871. {
  9872. if (OpenClipboard(0))
  9873. {
  9874. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9875. CloseClipboard();
  9876. }
  9877. }
  9878. //---------------------------------------------------------------------------
  9879. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9880. {
  9881. return !FClipboardFakeDirectory.IsEmpty();
  9882. }
  9883. //---------------------------------------------------------------------------
  9884. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9885. {
  9886. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9887. FClipboardFakeDirectory = UnicodeString();
  9888. FClipboardTerminal = NULL;
  9889. // Also called in Idle()
  9890. FClipboardFakeMonitors.reset(NULL);
  9891. }
  9892. //---------------------------------------------------------------------------
  9893. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9894. {
  9895. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9896. {
  9897. ClipboardStop();
  9898. }
  9899. }
  9900. //---------------------------------------------------------------------------
  9901. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9902. {
  9903. TTerminalManager * Manager = TTerminalManager::Instance();
  9904. Manager->ActiveTerminal = FClipboardTerminal;
  9905. TTransferOperationParam Params;
  9906. Params.TargetDirectory = TargetDirectory;
  9907. Params.DragDrop = DragDrop;
  9908. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  9909. }
  9910. //---------------------------------------------------------------------------
  9911. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  9912. {
  9913. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  9914. // (as it pumps a Windows message queue while being shutted down)
  9915. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  9916. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  9917. {
  9918. // Can fail as it can be e.g. locked by AV, so we retry that later
  9919. bool Removed = RemoveDir(ApiPath(FileName));
  9920. try
  9921. {
  9922. if (!NonVisualDataModule->Busy)
  9923. {
  9924. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  9925. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  9926. }
  9927. }
  9928. __finally
  9929. {
  9930. if (!Removed)
  9931. {
  9932. RemoveDir(ApiPath(FileName));
  9933. }
  9934. }
  9935. }
  9936. }
  9937. //---------------------------------------------------------------------------
  9938. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  9939. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  9940. {
  9941. TFileMasks::TParams MaskParams;
  9942. MaskParams.Size = Size;
  9943. MaskParams.Modification = Modification;
  9944. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  9945. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  9946. {
  9947. bool ImplicitMatch;
  9948. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  9949. !ImplicitMatch)
  9950. {
  9951. Color = Iter->Color;
  9952. break;
  9953. }
  9954. }
  9955. }
  9956. //---------------------------------------------------------------------------
  9957. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  9958. {
  9959. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9960. if (!DirView->IsEditing())
  9961. {
  9962. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  9963. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  9964. // while searching
  9965. if (Key == VK_BACK)
  9966. {
  9967. if (!FIncrementalSearch.IsEmpty())
  9968. {
  9969. if (FIncrementalSearch.Length() == 1)
  9970. {
  9971. ResetIncrementalSearch();
  9972. }
  9973. else
  9974. {
  9975. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  9976. IncrementalSearch(NewText, false, false);
  9977. }
  9978. Key = 0;
  9979. }
  9980. }
  9981. }
  9982. }
  9983. //---------------------------------------------------------------------------
  9984. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  9985. {
  9986. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9987. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  9988. {
  9989. // Filter control sequences.
  9990. // When not searching yet, prefer use of the space for toggling file selection
  9991. // (so we cannot incrementally search for a string starting with a space).
  9992. if ((Key > VK_SPACE) ||
  9993. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  9994. {
  9995. IncrementalSearch(FIncrementalSearch + Key, false, false);
  9996. Key = 0;
  9997. }
  9998. }
  9999. }
  10000. //---------------------------------------------------------------------------
  10001. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10002. {
  10003. if (!FIncrementalSearch.IsEmpty())
  10004. {
  10005. FIncrementalSearch = L"";
  10006. DirView(osCurrent)->UpdateStatusBar();
  10007. }
  10008. }
  10009. //---------------------------------------------------------------------------
  10010. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10011. {
  10012. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10013. if (Item == NULL)
  10014. {
  10015. MessageBeep(MB_ICONHAND);
  10016. }
  10017. else
  10018. {
  10019. TCustomDirView * ADirView = DirView(osCurrent);
  10020. {
  10021. TAutoNestingCounter Guard(FIncrementalSearching);
  10022. ADirView->FocusItem(Item);
  10023. if (ADirView->NortonLike == nlOff)
  10024. {
  10025. if ((ADirView->Selected != Item) ||
  10026. (ADirView->SelCount > 1))
  10027. {
  10028. ADirView->ClearSelection();
  10029. ADirView->Selected = Item;
  10030. }
  10031. }
  10032. }
  10033. FIncrementalSearch = Text;
  10034. Item->MakeVisible(false);
  10035. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10036. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10037. ADirView->UpdateStatusBar();
  10038. }
  10039. }
  10040. //---------------------------------------------------------------------------
  10041. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10042. {
  10043. int Index = Item->Index;
  10044. if (!Reverse)
  10045. {
  10046. Index++;
  10047. if (Index >= Item->Owner->Count)
  10048. {
  10049. Index = 0;
  10050. }
  10051. }
  10052. else
  10053. {
  10054. Index--;
  10055. if (Index < 0)
  10056. {
  10057. Index = Item->Owner->Count - 1;
  10058. }
  10059. }
  10060. return Item->Owner->Item[Index];
  10061. }
  10062. //---------------------------------------------------------------------------
  10063. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10064. {
  10065. TCustomDirView * ADirView = DirView(osCurrent);
  10066. if (ADirView->Items->Count == 0)
  10067. {
  10068. return NULL;
  10069. }
  10070. else
  10071. {
  10072. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10073. TListItem * Item = CurrentItem;
  10074. if (SkipCurrent)
  10075. {
  10076. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10077. }
  10078. while (true)
  10079. {
  10080. bool Matches = false;
  10081. switch (WinConfiguration->PanelSearch)
  10082. {
  10083. case isNameStartOnly:
  10084. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10085. break;
  10086. case isName:
  10087. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10088. break;
  10089. case isAll:
  10090. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10091. int Index = 0;
  10092. while ((Index < ColCount) && !Matches)
  10093. {
  10094. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10095. if (Visible)
  10096. {
  10097. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10098. }
  10099. Index++;
  10100. }
  10101. break;
  10102. }
  10103. if (Matches)
  10104. {
  10105. return Item;
  10106. }
  10107. Item = GetNextFile(Item, Reverse);
  10108. if (Item == CurrentItem)
  10109. {
  10110. return NULL;
  10111. }
  10112. }
  10113. }
  10114. }
  10115. //---------------------------------------------------------------------------
  10116. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10117. {
  10118. ResetIncrementalSearch();
  10119. }
  10120. //---------------------------------------------------------------------------
  10121. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10122. {
  10123. if (Message.CharCode == VK_TAB)
  10124. {
  10125. if (!FIncrementalSearch.IsEmpty())
  10126. {
  10127. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10128. bool Reverse = Shift.Contains(ssShift);
  10129. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10130. Message.Result = 1;
  10131. return;
  10132. }
  10133. }
  10134. else if (Message.CharCode == VK_ESCAPE)
  10135. {
  10136. if (!FIncrementalSearch.IsEmpty())
  10137. {
  10138. ResetIncrementalSearch();
  10139. Message.Result = 1;
  10140. return;
  10141. }
  10142. }
  10143. TForm::Dispatch(&Message);
  10144. }
  10145. //---------------------------------------------------------------------------
  10146. void __fastcall TCustomScpExplorerForm::Deactivate()
  10147. {
  10148. TForm::Deactivate();
  10149. // E.g. when switching to an internal editor window
  10150. ResetIncrementalSearch();
  10151. }
  10152. //---------------------------------------------------------------------------
  10153. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10154. {
  10155. // When switching to another application
  10156. ResetIncrementalSearch();
  10157. }
  10158. //---------------------------------------------------------------------------
  10159. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10160. {
  10161. ResetIncrementalSearch();
  10162. }
  10163. //---------------------------------------------------------------------------
  10164. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10165. {
  10166. if (FIncrementalSearching <= 0)
  10167. {
  10168. ResetIncrementalSearch();
  10169. }
  10170. }
  10171. //---------------------------------------------------------------------------
  10172. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10173. {
  10174. CountClicksForWindowPrint(this);
  10175. }
  10176. //---------------------------------------------------------------------------
  10177. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10178. {
  10179. CenterReconnectToolbar();
  10180. }
  10181. //---------------------------------------------------------------------------
  10182. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10183. {
  10184. if (RemoteDirView->ItemFocused != NULL)
  10185. {
  10186. RemoteDirView->ItemFocused->Selected = true;
  10187. }
  10188. }
  10189. //---------------------------------------------------------------------------
  10190. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10191. {
  10192. if (!FQueueStatusUpdating)
  10193. {
  10194. bool Refresh;
  10195. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10196. {
  10197. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10198. }
  10199. else
  10200. {
  10201. if (FQueueFileList->GetCount() > 0)
  10202. {
  10203. FQueueFileList->Clear();
  10204. Refresh = true;
  10205. }
  10206. }
  10207. int Count = FQueueFileList->GetCount();
  10208. if (QueueFileList->Items->Count != Count)
  10209. {
  10210. DebugAssert(Refresh);
  10211. QueueFileList->Items->Count = Count;
  10212. }
  10213. if (Refresh)
  10214. {
  10215. QueueFileList->Invalidate();
  10216. }
  10217. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10218. }
  10219. }
  10220. //---------------------------------------------------------------------------
  10221. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10222. {
  10223. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10224. }
  10225. //---------------------------------------------------------------------------
  10226. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10227. {
  10228. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10229. // See TSynchronizeChecklistDialog::UpdateTimer
  10230. if (QueueFileList->Items->Count > 0)
  10231. {
  10232. QueueFileList->Items->Item[0]->MakeVisible(false);
  10233. }
  10234. UpdateQueueFileList();
  10235. }
  10236. //---------------------------------------------------------------------------
  10237. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10238. {
  10239. Active = QueueView3->Focused() || QueueFileList->Focused();
  10240. }
  10241. //---------------------------------------------------------------------------
  10242. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10243. {
  10244. QueueLabelUpdateStatus();
  10245. }
  10246. //---------------------------------------------------------------------------
  10247. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10248. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10249. {
  10250. int State = FQueueFileList->GetState(Item->Index);
  10251. if (State == qfsProcessed)
  10252. {
  10253. Sender->Canvas->Font->Color = clGrayText;
  10254. }
  10255. }
  10256. //---------------------------------------------------------------------------
  10257. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10258. {
  10259. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10260. QueueFileList->Column[0]->Width =
  10261. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10262. }
  10263. //---------------------------------------------------------------------------
  10264. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10265. {
  10266. QueueFileListColumnAutoSize();
  10267. }
  10268. //---------------------------------------------------------------------------
  10269. void __fastcall TCustomScpExplorerForm::CloseApp()
  10270. {
  10271. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10272. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10273. // So we clear the flag here.
  10274. DebugAssert(NonVisualDataModule->Busy);
  10275. NonVisualDataModule->EndBusy();
  10276. try
  10277. {
  10278. Close();
  10279. }
  10280. __finally
  10281. {
  10282. NonVisualDataModule->StartBusy();
  10283. }
  10284. }
  10285. //---------------------------------------------------------------------------
  10286. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10287. {
  10288. return (Terminal != NULL) && Terminal->Active;
  10289. }
  10290. //---------------------------------------------------------------------------
  10291. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10292. {
  10293. return IsActiveTerminal(Terminal);
  10294. }