CustomScpExplorer.cpp 362 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012
  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. TAutoBatch::TAutoBatch(TCustomScpExplorerForm * Form) :
  100. FForm(Form)
  101. {
  102. FForm->BatchStart(FBatchStorage);
  103. }
  104. //---------------------------------------------------------------------------
  105. TAutoBatch::~TAutoBatch()
  106. {
  107. FForm->BatchEnd(FBatchStorage);
  108. }
  109. //---------------------------------------------------------------------------
  110. struct TTransferOperationParam
  111. {
  112. TTransferOperationParam();
  113. UnicodeString TargetDirectory;
  114. bool Temp;
  115. bool DragDrop;
  116. int Options;
  117. TAutoSwitch Queue;
  118. };
  119. //---------------------------------------------------------------------------
  120. TTransferOperationParam::TTransferOperationParam()
  121. {
  122. Temp = false;
  123. DragDrop = false;
  124. Options = 0;
  125. Queue = asAuto;
  126. }
  127. //---------------------------------------------------------------------------
  128. class TTransferPresetNoteData : public TObject
  129. {
  130. public:
  131. UnicodeString Message;
  132. };
  133. //---------------------------------------------------------------------------
  134. class TTerminalNoteData : public TObject
  135. {
  136. public:
  137. TManagedTerminal * Terminal;
  138. };
  139. //---------------------------------------------------------------------------
  140. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  141. FFormRestored(false),
  142. TForm(Owner)
  143. {
  144. FInvalid = false;
  145. FCurrentSide = osRemote;
  146. FEverShown = false;
  147. FDocks = new TList();
  148. InitControls();
  149. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  150. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  151. NonVisualDataModule->ScpExplorer = this;
  152. RestoreParams();
  153. ConfigurationChanged();
  154. RemoteDirView->Invalidate();
  155. FAutoOperation = false;
  156. FOnFileOperationFinished = NULL;
  157. FForceExecution = false;
  158. FIgnoreNextDialogChar = 0;
  159. FErrorList = NULL;
  160. FSynchronizeProgressForm = NULL;
  161. FProgressForm = NULL;
  162. FRefreshLocalDirectory = false;
  163. FRefreshRemoteDirectory = false;
  164. FDDExtMapFile = NULL;
  165. // CreateMutexW keeps failing with ERROR_NOACCESS
  166. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  167. DebugAssert(FDDExtMutex != NULL);
  168. FDDTargetControl = NULL;
  169. FDelayedDeletionTimer = NULL;
  170. FDelayedDeletionList = new TStringList();
  171. FDDFileList = NULL;
  172. FPendingTempSpaceWarn = false;
  173. FCapturedLog = NULL;
  174. FDragDropOperation = false;
  175. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  176. FAllowTransferPresetAutoSelect = true;
  177. FCopyParamDefault = L"";
  178. FSynchronizeController = NULL;
  179. FPendingQueueActionItem = NULL;
  180. FLockLevel = 0;
  181. FLockSuspendLevel = 0;
  182. FDisabledOnLockSuspend = false;
  183. FAlternativeDelete = false;
  184. FTrayIcon = new ::TTrayIcon(0);
  185. FTrayIcon->OnClick = TrayIconClick;
  186. FMaxQueueLength = 0;
  187. FLastContextPopupScreenPoint = TPoint(-1, -1);
  188. FTransferResumeList = NULL;
  189. FMoveToQueue = false;
  190. FStandaloneEditing = false;
  191. FOnFeedSynchronizeError = NULL;
  192. FNeedSession = false;
  193. FDoNotIdleCurrentTerminal = 0;
  194. FIncrementalSearching = 0;
  195. FIncrementalSearchHaveNext = false;
  196. FQueueFileList.reset(new TQueueFileList());
  197. FProgressSide = osCurrent;
  198. FEditorManager = new TEditorManager();
  199. FEditorManager->OnFileChange = ExecutedFileChanged;
  200. FEditorManager->OnFileReload = ExecutedFileReload;
  201. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  202. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  203. FLocalEditors = new TList();
  204. FQueueStatus = NULL;
  205. FQueueStatusSection = new TCriticalSection();
  206. FQueueStatusInvalidated = false;
  207. FQueueItemInvalidated = false;
  208. FQueueStatusUpdating = false;
  209. FQueueActedItem = NULL;
  210. FQueueController = new TQueueController(QueueView3);
  211. FUserActionTimer = new TTimer(this);
  212. FUserActionTimer->Enabled = false;
  213. FUserActionTimer->Interval = 10;
  214. FUserActionTimer->OnTimer = UserActionTimer;
  215. FNotes = new TStringList();
  216. FNoteTimer = new TTimer(this);
  217. FNoteTimer->Enabled = false;
  218. FNoteTimer->OnTimer = NoteTimer;
  219. FOnNoteClick = NULL;
  220. FOle32Library = LoadLibrary(L"Ole32.dll");
  221. FDragMoveCursor = FOle32Library != NULL ?
  222. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  223. UseSystemSettings(this);
  224. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  225. static_cast<TObject*>(GetComponent(fcTransferList)));
  226. DebugAssert(TransferList != NULL);
  227. FTransferListHoverIndex = -1;
  228. TransferList->OnChange = TransferListChange;
  229. TransferList->OnDrawItem = TransferListDrawItem;
  230. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  231. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  232. UseDesktopFont(SessionsPageControl);
  233. UpdateSessionsPageControlHeight();
  234. UseDesktopFont(RemoteDirView);
  235. UseDesktopFont(RemoteDriveView);
  236. UseDesktopFont(QueueView3);
  237. UseDesktopFont(QueueFileList);
  238. UseDesktopFont(QueueLabel);
  239. UseDesktopFont(RemoteStatusBar);
  240. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  241. QueueSplitter->ShowHint = true;
  242. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  243. QueueFileListSplitter->ShowHint = true;
  244. RemotePanelSplitter->ShowHint = true;
  245. UpdateImages();
  246. FCustomCommandMenu = CreateTBXPopupMenu(this);
  247. FCustomCommandLocalFileList = NULL;
  248. FCustomCommandRemoteFileList = NULL;
  249. FSessionColors = new TPngImageList(this);
  250. FSessionColors->ColorDepth = cd32Bit;
  251. AddFixedSessionImages();
  252. SessionsPageControl->Images = FSessionColors;
  253. UpdateQueueLabel();
  254. CreateHiddenWindow();
  255. StartUpdates();
  256. }
  257. //---------------------------------------------------------------------------
  258. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  259. {
  260. FInvalid = true;
  261. // this has to be one of the very first things to do
  262. StopUpdateThread();
  263. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  264. TTerminalManager::Instance()->ScpExplorer = NULL;
  265. delete FCustomCommandLocalFileList;
  266. delete FCustomCommandRemoteFileList;
  267. delete FCustomCommandMenu;
  268. delete FTrayIcon;
  269. FTrayIcon = NULL;
  270. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  271. delete FEditorManager;
  272. ForceCloseLocalEditors();
  273. delete FLocalEditors;
  274. HideFileFindDialog();
  275. if (FDelayedDeletionTimer)
  276. {
  277. DoDelayedDeletion(NULL);
  278. SAFE_DESTROY(FDelayedDeletionTimer);
  279. }
  280. SAFE_DESTROY(FDelayedDeletionList);
  281. // sometimes we do not get DDEnd so the list is not released
  282. SAFE_DESTROY(FDDFileList);
  283. DebugAssert(FSynchronizeController == NULL);
  284. CloseHandle(FDDExtMutex);
  285. FDDExtMutex = NULL;
  286. FreeLibrary(FOle32Library);
  287. FOle32Library = NULL;
  288. FDragMoveCursor = NULL;
  289. DebugAssert(!FErrorList);
  290. if (FEverShown)
  291. {
  292. // when window is never shown (like when running command-line operation),
  293. // particularly window site is not restored correctly (BoundsRect value set
  294. // in RestoreForm gets lost during handle allocation), so we do not want
  295. // it to be stored
  296. StoreParams();
  297. }
  298. Terminal = NULL;
  299. Queue = NULL;
  300. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  301. NonVisualDataModule->ScpExplorer = NULL;
  302. delete FQueueController;
  303. FQueueController = NULL;
  304. delete FQueueStatusSection;
  305. FQueueStatusSection = NULL;
  306. delete FQueueStatus;
  307. FQueueStatus = NULL;
  308. delete FUserActionTimer;
  309. FUserActionTimer = NULL;
  310. delete FNoteTimer;
  311. delete FNotes;
  312. delete FNoteData;
  313. SAFE_DESTROY(FDocks);
  314. SessionsPageControl->Images = NULL;
  315. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  316. SAFE_DESTROY(FSessionColors);
  317. SAFE_DESTROY(FSessionsDragDropFilesEx);
  318. SAFE_DESTROY(FHistoryMenu[0][0]);
  319. SAFE_DESTROY(FHistoryMenu[0][1]);
  320. SAFE_DESTROY(FHistoryMenu[1][0]);
  321. SAFE_DESTROY(FHistoryMenu[1][1]);
  322. if (FHiddenWindow != NULL)
  323. {
  324. DestroyWindow(FHiddenWindow);
  325. FHiddenWindow = NULL;
  326. }
  327. }
  328. //---------------------------------------------------------------------------
  329. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  330. {
  331. std::unique_ptr<TSessionData> Data;
  332. if (!Session.IsEmpty())
  333. {
  334. bool DefaultsOnly;
  335. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  336. }
  337. TTerminalManager * Manager = TTerminalManager::Instance();
  338. for (int Index = 0; Index < Manager->Count; Index++)
  339. {
  340. TTerminal * Terminal = Manager->Terminals[Index];
  341. if (Session.IsEmpty() ||
  342. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  343. {
  344. if (Path.IsEmpty())
  345. {
  346. Terminal->ClearCaches();
  347. }
  348. else
  349. {
  350. Terminal->DirectoryModified(Path, true);
  351. }
  352. }
  353. }
  354. // We should flag a pending refresh for the background terminals or busy foreground terminals
  355. if (HasActiveTerminal() &&
  356. CanCommandLineFromAnotherInstance() &&
  357. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  358. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  359. {
  360. Terminal->ReloadDirectory();
  361. }
  362. }
  363. //---------------------------------------------------------------------------
  364. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  365. {
  366. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  367. size_t MessageSize = sizeof(TCopyDataMessage);
  368. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  369. if (Result)
  370. {
  371. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  372. Result = (Message.Version == TCopyDataMessage::Version1);
  373. if (Result)
  374. {
  375. switch (Message.Command)
  376. {
  377. case TCopyDataMessage::CommandCanCommandLine:
  378. Result = CanCommandLineFromAnotherInstance();
  379. break;
  380. case TCopyDataMessage::CommandCommandLine:
  381. {
  382. UnicodeString CommandLine(Message.CommandLine);
  383. Result = CommandLineFromAnotherInstance(CommandLine);
  384. }
  385. break;
  386. case TCopyDataMessage::RefreshPanel:
  387. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  388. break;
  389. case TCopyDataMessage::MainWindowCheck:
  390. Result = true;
  391. break;
  392. default:
  393. Result = false;
  394. break;
  395. }
  396. }
  397. }
  398. Message.Result = Result ? 1 : 0;
  399. }
  400. //---------------------------------------------------------------------------
  401. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  402. {
  403. WNDCLASS WindowClass = {0};
  404. WindowClass.lpfnWndProc = DefWindowProc;
  405. WindowClass.hInstance = HInstance;
  406. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  407. FHiddenWindow = NULL;
  408. if (RegisterClass(&WindowClass))
  409. {
  410. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  411. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  412. }
  413. }
  414. //---------------------------------------------------------------------------
  415. bool __fastcall TCustomScpExplorerForm::CanConsole()
  416. {
  417. return
  418. HasActiveTerminal() &&
  419. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  420. }
  421. //---------------------------------------------------------------------------
  422. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  423. {
  424. bool Result = Visible && !NonVisualDataModule->Busy;
  425. return Result;
  426. }
  427. //---------------------------------------------------------------------------
  428. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  429. const UnicodeString & CommandLine)
  430. {
  431. TProgramParams Params(CommandLine);
  432. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  433. if (Result)
  434. {
  435. NonVisualDataModule->StartBusy();
  436. try
  437. {
  438. // this action is initiated from another process,
  439. // so it's likely that our window is not visible,
  440. // and user won't see what is going on
  441. Application->BringToFront();
  442. // reload sessions as we may be asked to open a session
  443. // just stored by another instance
  444. StoredSessions->Reload();
  445. UnicodeString SessionName = Params.Param[1];
  446. std::unique_ptr<TObjectList> DataList(new TObjectList());
  447. UnicodeString DownloadFile; // unused
  448. try
  449. {
  450. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  451. }
  452. catch (EAbort &)
  453. {
  454. // Happens when opening session in PuTTY and in other situations,
  455. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  456. // to process the command-line on its own (or to pass it to yet another instance)
  457. }
  458. if (DataList->Count > 0)
  459. {
  460. TTerminalManager * Manager = TTerminalManager::Instance();
  461. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  462. }
  463. }
  464. __finally
  465. {
  466. NonVisualDataModule->EndBusy();
  467. }
  468. }
  469. return Result;
  470. }
  471. //---------------------------------------------------------------------------
  472. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  473. {
  474. if (FTerminal != value)
  475. {
  476. TerminalChanging();
  477. DoSetTerminal(value, false);
  478. }
  479. }
  480. //---------------------------------------------------------------------------
  481. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  482. {
  483. FTerminal = value;
  484. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  485. FAllowTransferPresetAutoSelect = false;
  486. try
  487. {
  488. TerminalChanged(Replace);
  489. }
  490. __finally
  491. {
  492. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  493. }
  494. if (Terminal != NULL)
  495. {
  496. TransferPresetAutoSelect();
  497. }
  498. }
  499. //---------------------------------------------------------------------------
  500. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  501. {
  502. DoSetTerminal(value, true);
  503. }
  504. //---------------------------------------------------------------------------
  505. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  506. {
  507. if (FTerminal != NULL)
  508. {
  509. UpdateTerminal(Terminal);
  510. }
  511. }
  512. //---------------------------------------------------------------------------
  513. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  514. {
  515. if (Terminal != NULL)
  516. {
  517. UpdateSessionColor((TColor)Terminal->StateData->Color);
  518. }
  519. DoTerminalListChanged();
  520. DebugAssert(!IsLocalBrowserMode());
  521. if (Replaced)
  522. {
  523. RemoteDirView->ReplaceTerminal(Terminal);
  524. }
  525. else
  526. {
  527. RemoteDirView->Terminal = Terminal;
  528. }
  529. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  530. if (Terminal != NULL)
  531. {
  532. if (Terminal->Active)
  533. {
  534. Terminal->RefreshDirectory();
  535. }
  536. if (WinConfiguration->PreservePanelState)
  537. {
  538. if (Terminal->RemoteExplorerState != NULL)
  539. {
  540. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  541. }
  542. else
  543. {
  544. DirView(osRemote)->ClearState();
  545. }
  546. }
  547. if (!Replaced && Terminal->Active)
  548. {
  549. InitStatusBar();
  550. }
  551. }
  552. UpdateTransferList();
  553. // Update panels Enable state before refreshing the labels
  554. UpdateControls();
  555. }
  556. //---------------------------------------------------------------------------
  557. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  558. {
  559. if (Queue != value)
  560. {
  561. if (FQueue != NULL)
  562. {
  563. FQueue->OnListUpdate = NULL;
  564. FQueue->OnQueueItemUpdate = NULL;
  565. }
  566. FQueue = value;
  567. if (FQueue != NULL)
  568. {
  569. DebugAssert(FQueue->OnListUpdate == NULL);
  570. FQueue->OnListUpdate = QueueListUpdate;
  571. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  572. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  573. }
  574. QueueChanged();
  575. }
  576. }
  577. //---------------------------------------------------------------------------
  578. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  579. TListItem * Item)
  580. {
  581. if (FQueueActedItem == Item)
  582. {
  583. FQueueActedItem = NULL;
  584. if ((QueueView3->PopupMenu != NULL) &&
  585. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  586. {
  587. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  588. ReleaseCapture();
  589. }
  590. }
  591. if (Item->Data == FPendingQueueActionItem)
  592. {
  593. FPendingQueueActionItem = NULL;
  594. }
  595. }
  596. //---------------------------------------------------------------------------
  597. bool TCustomScpExplorerForm::IsAnythingQueued()
  598. {
  599. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  600. }
  601. //---------------------------------------------------------------------------
  602. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  603. {
  604. {
  605. TGuard Guard(FQueueStatusSection);
  606. FQueueStatusInvalidated = false;
  607. if (FQueue != NULL)
  608. {
  609. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  610. }
  611. }
  612. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  613. {
  614. FMaxQueueLength = FQueueStatus->Count;
  615. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  616. }
  617. {
  618. TAutoFlag Flag(FQueueStatusUpdating);
  619. FQueueController->UpdateQueueStatus(FQueueStatus);
  620. }
  621. UpdateQueueFileList();
  622. SetQueueProgress();
  623. UpdateQueueView();
  624. bool IsEmpty = !IsAnythingQueued();
  625. if (IsEmpty && (Terminal != NULL))
  626. {
  627. TOnceDoneOperation OnceDoneOperation =
  628. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  629. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  630. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  631. {
  632. FQueue->Enabled = false;
  633. }
  634. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  635. {
  636. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  637. }
  638. }
  639. }
  640. //---------------------------------------------------------------------------
  641. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  642. {
  643. UnicodeString Result;
  644. if (FQueueStatus != NULL)
  645. {
  646. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  647. {
  648. TFileOperationProgressType * ProgressData =
  649. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  650. if ((ProgressData != NULL) && ProgressData->InProgress)
  651. {
  652. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  653. }
  654. }
  655. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  656. {
  657. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  658. }
  659. }
  660. return Result;
  661. }
  662. //---------------------------------------------------------------------------
  663. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  664. {
  665. ComponentVisible[fcQueueView] =
  666. (WinConfiguration->QueueView.Show == qvShow) ||
  667. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  668. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  669. }
  670. //---------------------------------------------------------------------------
  671. void __fastcall TCustomScpExplorerForm::QueueChanged()
  672. {
  673. if (FQueueStatus != NULL)
  674. {
  675. // UpdateFileList implementation relies on the status being recreated when session changes
  676. delete FQueueStatus;
  677. FQueueStatus = NULL;
  678. }
  679. UpdateQueueStatus(true);
  680. }
  681. //---------------------------------------------------------------------------
  682. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  683. {
  684. if (FQueue == Queue)
  685. {
  686. FQueueStatusInvalidated = true;
  687. }
  688. }
  689. //---------------------------------------------------------------------------
  690. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  691. TQueueItem * Item)
  692. {
  693. if (FQueue == Queue)
  694. {
  695. TGuard Guard(FQueueStatusSection);
  696. // this may be running in parallel with QueueChanged
  697. if (FQueueStatus != NULL)
  698. {
  699. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  700. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  701. {
  702. FRefreshLocalDirectory = (QueueItem == NULL) ||
  703. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  704. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  705. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  706. }
  707. if (QueueItem != NULL)
  708. {
  709. QueueItem->UserData = (void*)true;
  710. FQueueItemInvalidated = true;
  711. }
  712. }
  713. }
  714. }
  715. //---------------------------------------------------------------------------
  716. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  717. {
  718. // during standalone editing, we have no way to see/control queue,
  719. // so we have to always popup prompts automatically
  720. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  721. }
  722. //---------------------------------------------------------------------------
  723. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  724. {
  725. if (FQueueStatus != NULL)
  726. {
  727. bool QueueAutoPopup = IsQueueAutoPopup();
  728. bool NeedRefresh = FQueueController->NeedRefresh();
  729. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  730. FQueueItemInvalidated = false;
  731. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  732. bool Updated = false;
  733. TQueueItemProxy * QueueItem;
  734. bool WasUserAction;
  735. for (int Index = 0; Index < Limit; Index++)
  736. {
  737. bool Update = false;
  738. QueueItem = FQueueStatus->Items[Index];
  739. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  740. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  741. (FPendingQueueActionItem == NULL))
  742. {
  743. FPendingQueueActionItem = QueueItem;
  744. FUserActionTimer->Enabled = true;
  745. }
  746. if ((bool)QueueItem->UserData)
  747. {
  748. QueueItem->UserData = (void*)false;
  749. QueueItem->Update();
  750. Updated = true;
  751. Update = true;
  752. }
  753. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  754. {
  755. Update = true;
  756. }
  757. if (Update)
  758. {
  759. FQueueController->RefreshQueueItem(QueueItem);
  760. }
  761. }
  762. if (Updated)
  763. {
  764. NonVisualDataModule->UpdateNonVisibleActions();
  765. SetQueueProgress();
  766. UpdateQueueFileList();
  767. }
  768. }
  769. }
  770. //---------------------------------------------------------------------------
  771. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  772. {
  773. if (FTaskbarList != NULL)
  774. {
  775. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  776. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  777. }
  778. }
  779. //---------------------------------------------------------------------------
  780. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  781. {
  782. if (Progress >= 0)
  783. {
  784. if (FTaskbarList != NULL)
  785. {
  786. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  787. }
  788. }
  789. else
  790. {
  791. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  792. }
  793. }
  794. //---------------------------------------------------------------------------
  795. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  796. {
  797. int OverallProgress;
  798. // FProgressForm is null when this is called from SetQueueProgress
  799. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  800. {
  801. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  802. }
  803. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  804. {
  805. OverallProgress = ProgressData->OverallProgress();
  806. }
  807. else
  808. {
  809. OverallProgress = -1;
  810. }
  811. SetTaskbarListProgressValue(OverallProgress);
  812. }
  813. //---------------------------------------------------------------------------
  814. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  815. {
  816. TTerminalManager::Instance()->QueueStatusUpdated();
  817. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  818. {
  819. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  820. {
  821. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  822. {
  823. TFileOperationProgressType * ProgressData = NULL;
  824. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  825. {
  826. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  827. }
  828. if ((ProgressData != NULL) &&
  829. ProgressData->InProgress)
  830. {
  831. SetTaskbarListProgressValue(ProgressData);
  832. }
  833. else
  834. {
  835. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  836. }
  837. }
  838. else
  839. {
  840. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  841. }
  842. }
  843. else
  844. {
  845. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  846. }
  847. }
  848. UpdateQueueLabel();
  849. }
  850. //---------------------------------------------------------------------------
  851. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  852. {
  853. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  854. if (FQueueStatus != NULL)
  855. {
  856. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  857. if (ActiveAndPendingPrimaryCount > 0)
  858. {
  859. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  860. }
  861. }
  862. QueueLabel->Caption = Caption;
  863. }
  864. //---------------------------------------------------------------------------
  865. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  866. {
  867. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  868. static_cast<TComponent*>(GetComponent(fcTransferList)));
  869. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  870. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  871. TransferList->Strings->BeginUpdate();
  872. try
  873. {
  874. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  875. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  876. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  877. if (FTransferDropDownHint.IsEmpty())
  878. {
  879. FTransferDropDownHint = TransferDropDown->Hint;
  880. }
  881. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  882. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  883. TransferDropDown->Text = StripHotkey(Name);
  884. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  885. (FTransferDropDownHint, StripHotkey(Name),
  886. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  887. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  888. // update the label, otherwise when it is updated only on the first draw
  889. // of the list, it is drawn "bold" for some reason
  890. FTransferListHoverIndex = TransferList->ItemIndex;
  891. UpdateTransferLabel();
  892. }
  893. __finally
  894. {
  895. TransferList->Strings->EndUpdate();
  896. }
  897. }
  898. //---------------------------------------------------------------------------
  899. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  900. {
  901. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  902. DebugAssert(Toolbar != NULL);
  903. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  904. }
  905. //---------------------------------------------------------------------------
  906. void __fastcall TCustomScpExplorerForm::UpdateActions()
  907. {
  908. TForm::UpdateActions();
  909. if (ComponentVisible[fcCustomCommandsBand])
  910. {
  911. UpdateCustomCommandsToolbar();
  912. }
  913. }
  914. //---------------------------------------------------------------------------
  915. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  916. {
  917. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  918. }
  919. //---------------------------------------------------------------------------
  920. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  921. {
  922. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  923. {
  924. DirView->RowSelect = WinConfiguration->FullRowSelect;
  925. // selection is not redrawn automatically when RowSelect changes
  926. DirView->Invalidate();
  927. }
  928. }
  929. //---------------------------------------------------------------------------
  930. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  931. {
  932. Color = GetBtnFaceColor();
  933. DebugAssert(Configuration && RemoteDirView);
  934. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  935. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  936. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  937. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  938. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  939. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  940. UpdateRowSelect(RemoteDirView);
  941. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  942. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  943. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  944. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  945. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  946. UpdateSessionsPageControlHeight();
  947. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  948. UpdateToolbarDisplayMode();
  949. UpdateTransferList();
  950. if (Terminal != NULL)
  951. {
  952. TransferPresetAutoSelect();
  953. }
  954. UpdateQueueView();
  955. UpdateControls();
  956. // this can be called even before constuctor finishes.
  957. if (FEditorManager != NULL)
  958. {
  959. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  960. }
  961. // this can be called even before constuctor finishes.
  962. if (FLocalEditors != NULL)
  963. {
  964. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  965. {
  966. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  967. }
  968. }
  969. if (ComponentVisible[fcCustomCommandsBand])
  970. {
  971. UpdateCustomCommandsToolbar();
  972. }
  973. // show only when keeping queue items forever,
  974. // otherwise, its enough to have in in the context menu
  975. QueueDeleteAllDoneQueueToolbarItem->Visible =
  976. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  977. if (FFileColorsCurrent != WinConfiguration->FileColors)
  978. {
  979. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  980. FFileColorsCurrent = WinConfiguration->FileColors;
  981. FileColorsChanged();
  982. }
  983. }
  984. //---------------------------------------------------------------------------
  985. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  986. {
  987. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  988. DirView->Invalidate();
  989. }
  990. //---------------------------------------------------------------------------
  991. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  992. {
  993. DoFileColorsChanged(RemoteDirView);
  994. }
  995. //---------------------------------------------------------------------------
  996. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  997. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  998. void * /*Arg*/)
  999. {
  1000. if (Token != NULL)
  1001. {
  1002. TForm * Editor = dynamic_cast<TForm*>(Token);
  1003. DebugAssert(Editor != NULL);
  1004. ReconfigureEditorForm(Editor);
  1005. }
  1006. }
  1007. //---------------------------------------------------------------------------
  1008. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1009. {
  1010. WinConfiguration->DDTransferConfirmation = asOn;
  1011. }
  1012. //---------------------------------------------------------------------------
  1013. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1014. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1015. {
  1016. // noop
  1017. }
  1018. //---------------------------------------------------------------------------
  1019. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1020. TTransferDirection Direction, TTransferType Type, bool Temp,
  1021. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1022. bool Confirm, bool DragDrop, int Options)
  1023. {
  1024. bool Result = true;
  1025. DebugAssert(HasActiveTerminal());
  1026. // these parameters are known in advance
  1027. int Params =
  1028. FLAGMASK(Type == ttMove, cpDelete);
  1029. bool ToTemp = (Temp && (Direction == tdToLocal));
  1030. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1031. {
  1032. bool DisableNewerOnly =
  1033. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1034. ToTemp;
  1035. Options |=
  1036. FLAGMASK(ToTemp, coTemp) |
  1037. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1038. coDoNotShowAgain;
  1039. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1040. int CopyParamAttrs = (Direction == tdToRemote ?
  1041. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1042. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1043. int OutputOptions =
  1044. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1045. cooDoNotShowAgain);
  1046. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1047. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1048. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1049. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1050. if (Result)
  1051. {
  1052. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1053. {
  1054. if (DragDrop)
  1055. {
  1056. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1057. {
  1058. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1059. NULL, 0, EnableDDTransferConfirmation, NULL);
  1060. }
  1061. WinConfiguration->DDTransferConfirmation = asOff;
  1062. }
  1063. else
  1064. {
  1065. WinConfiguration->ConfirmTransferring = false;
  1066. }
  1067. }
  1068. else
  1069. {
  1070. // User explicitly unchecked "do not show again",
  1071. // so show him the dialog the next time
  1072. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1073. {
  1074. WinConfiguration->DDTransferConfirmation = asOn;
  1075. }
  1076. }
  1077. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1078. }
  1079. }
  1080. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1081. {
  1082. Configuration->Usage->Inc(L"TransfersOnBackground");
  1083. // these parameter are known only after transfer dialog
  1084. Params |=
  1085. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1086. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1087. Result = false;
  1088. ClearTransferSourceSelection(Direction);
  1089. }
  1090. return Result;
  1091. }
  1092. //---------------------------------------------------------------------------
  1093. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1094. {
  1095. if (FOnFileOperationFinished != NULL)
  1096. {
  1097. FOnFileOperationFinished(UnicodeString(), true);
  1098. }
  1099. else
  1100. {
  1101. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1102. if (HasDirView[Side])
  1103. {
  1104. DirView(Side)->SelectAll(smNone);
  1105. }
  1106. }
  1107. }
  1108. //---------------------------------------------------------------------------
  1109. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1110. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1111. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1112. int Params)
  1113. {
  1114. DebugAssert(Queue != NULL);
  1115. bool SingleFile = false;
  1116. if (FileList->Count == 1)
  1117. {
  1118. if (Direction == tdToRemote)
  1119. {
  1120. UnicodeString FileName = FileList->Strings[0];
  1121. SingleFile = FileExists(ApiPath(FileName));
  1122. }
  1123. else
  1124. {
  1125. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1126. SingleFile = !File->IsDirectory;
  1127. }
  1128. }
  1129. TQueueItem * QueueItem;
  1130. if (Direction == tdToRemote)
  1131. {
  1132. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1133. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1134. }
  1135. else
  1136. {
  1137. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1138. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1139. }
  1140. AddQueueItem(Queue, QueueItem, Terminal);
  1141. }
  1142. //---------------------------------------------------------------------------
  1143. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1144. {
  1145. if (Queue->IsEmpty)
  1146. {
  1147. Terminal->QueueOperationStart = Now();
  1148. }
  1149. Queue->AddItem(QueueItem);
  1150. }
  1151. //---------------------------------------------------------------------------
  1152. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1153. {
  1154. }
  1155. //---------------------------------------------------------------------------
  1156. void __fastcall TCustomScpExplorerForm::InitControls()
  1157. {
  1158. DebugAssert(FDocks != NULL);
  1159. for (int Index = 0; Index < ComponentCount; Index++)
  1160. {
  1161. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1162. if ((Dock != NULL) && (Dock->Tag == 0))
  1163. {
  1164. FDocks->Add(Dock);
  1165. }
  1166. }
  1167. CollectItemsWithTextDisplayMode(this);
  1168. }
  1169. //---------------------------------------------------------------------------
  1170. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1171. {
  1172. ConfigurationChanged();
  1173. QueuePanel->Height =
  1174. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1175. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1176. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1177. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1178. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1179. QueueFileList->Height =
  1180. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1181. if (QueueFileList->Visible)
  1182. {
  1183. AdjustQueueLayout();
  1184. }
  1185. UpdateCustomCommandsToolbar();
  1186. }
  1187. //---------------------------------------------------------------------------
  1188. void __fastcall TCustomScpExplorerForm::StoreParams()
  1189. {
  1190. int APixelsPerInch = GetControlPixelsPerInch(this);
  1191. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1192. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1193. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1194. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1195. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1196. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1197. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1198. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1199. }
  1200. //---------------------------------------------------------------------------
  1201. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1202. {
  1203. if (!FFormRestored)
  1204. {
  1205. FFormRestored = true;
  1206. RestoreFormParams();
  1207. }
  1208. TForm::CreateParams(Params);
  1209. }
  1210. //---------------------------------------------------------------------------
  1211. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1212. {
  1213. DebugAssert(FDocks != NULL);
  1214. for (int Index = 0; Index < FDocks->Count; Index++)
  1215. {
  1216. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1217. }
  1218. }
  1219. //---------------------------------------------------------------------------
  1220. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1221. {
  1222. SetDockAllowDrag(true);
  1223. while (!ButtonsStr.IsEmpty())
  1224. {
  1225. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1226. UnicodeString Name = CutToChar(S, L'=', true);
  1227. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1228. {
  1229. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1230. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1231. {
  1232. while (!S.IsEmpty())
  1233. {
  1234. UnicodeString S2 = CutToChar(S, L',', true);
  1235. UnicodeString Name = CutToChar(S2, L':', true);
  1236. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1237. {
  1238. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1239. if (SameText(GetToolbarItemName(Item), Name))
  1240. {
  1241. // forward compatibility
  1242. UnicodeString S3 = CutToChar(S2, L':', true);
  1243. bool Visible = StrToIntDef(S3, 0);
  1244. Item->Visible = Visible;
  1245. }
  1246. }
  1247. }
  1248. }
  1249. }
  1250. }
  1251. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1252. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1253. }
  1254. //---------------------------------------------------------------------------
  1255. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1256. {
  1257. UnicodeString Result;
  1258. SetDockAllowDrag(true);
  1259. Result = ::GetToolbarsLayoutStr(this);
  1260. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1261. return Result;
  1262. }
  1263. //---------------------------------------------------------------------------
  1264. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1265. {
  1266. UnicodeString Result;
  1267. if (Item->Action != NULL)
  1268. {
  1269. Result = Item->Action->Name;
  1270. Result = RemoveSuffix(Result, L"Action", true);
  1271. }
  1272. else
  1273. {
  1274. Result = Item->Name;
  1275. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1276. Result = RemoveSuffix(Result, L"Item", true);
  1277. }
  1278. return Result;
  1279. }
  1280. //---------------------------------------------------------------------------
  1281. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1282. {
  1283. UnicodeString Result;
  1284. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1285. {
  1286. UnicodeString ToolbarStr;
  1287. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1288. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1289. {
  1290. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1291. {
  1292. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1293. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1294. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1295. // and save the changes here only.
  1296. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1297. {
  1298. UnicodeString Name = GetToolbarItemName(Item);
  1299. DebugAssert(Name.Pos(L"TBX") == 0);
  1300. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1301. }
  1302. }
  1303. }
  1304. if (!ToolbarStr.IsEmpty())
  1305. {
  1306. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1307. }
  1308. }
  1309. return Result;
  1310. }
  1311. //---------------------------------------------------------------------------
  1312. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1313. {
  1314. DebugAssert(FProgressForm == NULL);
  1315. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1316. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1317. FProgressForm->DeleteLocalToRecycleBin =
  1318. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1319. FProgressForm->DeleteRemoteToRecycleBin =
  1320. (Terminal != NULL) &&
  1321. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1322. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1323. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1324. LockWindow();
  1325. // Actually, do not know what hides the progress once the operation finishes
  1326. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1327. SetTaskbarListProgressState(TBPF_NORMAL);
  1328. }
  1329. //---------------------------------------------------------------------------
  1330. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1331. {
  1332. UnlockWindow();
  1333. SAFE_DESTROY(FProgressForm);
  1334. SetQueueProgress();
  1335. }
  1336. //---------------------------------------------------------------------------
  1337. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1338. TFileOperationProgressType & ProgressData)
  1339. {
  1340. // Download to temporary local directory
  1341. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1342. {
  1343. bool Continue = true;
  1344. FPendingTempSpaceWarn = false;
  1345. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1346. if (!Continue)
  1347. {
  1348. Abort();
  1349. }
  1350. }
  1351. // operation is being executed and we still didn't show up progress form
  1352. if (ProgressData.InProgress && !FProgressForm)
  1353. {
  1354. CreateProgressForm(NULL);
  1355. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1356. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1357. }
  1358. // operation is finished (or terminated), so we hide progress form
  1359. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1360. {
  1361. DestroyProgressForm();
  1362. if (ProgressData.Operation == foCalculateSize)
  1363. {
  1364. // When calculating size before transfer, the abort caused by
  1365. // cancel flag set due to "MoveToQueue" below,
  1366. // is not propagated back to us in ExecuteFileOperation,
  1367. // as it is silently swallowed.
  1368. // So we explicitly (re)throw it here.
  1369. if (FMoveToQueue)
  1370. {
  1371. Abort();
  1372. }
  1373. }
  1374. else
  1375. {
  1376. if ((ProgressData.Cancel == csContinue) &&
  1377. !FAutoOperation)
  1378. {
  1379. OperationComplete(ProgressData.StartTime);
  1380. }
  1381. }
  1382. }
  1383. if (FProgressForm &&
  1384. // Can happen only during synchronization, when ending one of the operations
  1385. ProgressData.InProgress)
  1386. {
  1387. FProgressForm->SetProgressData(ProgressData);
  1388. DebugAssert(ProgressData.InProgress);
  1389. SetTaskbarListProgressValue(&ProgressData);
  1390. if (FProgressForm->Cancel > csContinue)
  1391. {
  1392. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1393. if (FProgressForm->Cancel == csCancelFile)
  1394. {
  1395. FProgressForm->ClearCancel();
  1396. }
  1397. // cancel cancels even the move
  1398. FMoveToQueue = false;
  1399. }
  1400. else if (FProgressForm->MoveToQueue)
  1401. {
  1402. FMoveToQueue = true;
  1403. ProgressData.SetCancelAtLeast(csCancel);
  1404. }
  1405. if ((FTransferResumeList != NULL) &&
  1406. ProgressData.InProgress &&
  1407. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1408. !ProgressData.FullFileName.IsEmpty())
  1409. {
  1410. if ((FTransferResumeList->Count == 0) ||
  1411. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1412. {
  1413. // note that we do not recognize directories from files here
  1414. FTransferResumeList->Add(ProgressData.FullFileName);
  1415. }
  1416. }
  1417. }
  1418. }
  1419. //---------------------------------------------------------------------------
  1420. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1421. const TDateTime & StartTime)
  1422. {
  1423. if (GUIConfiguration->BeepOnFinish &&
  1424. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1425. {
  1426. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1427. DWORD Sound;
  1428. if (!ExtractFileExt(BeepSound).IsEmpty())
  1429. {
  1430. Sound = SND_FILENAME;
  1431. }
  1432. else
  1433. {
  1434. Sound = SND_ALIAS;
  1435. }
  1436. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1437. }
  1438. }
  1439. //---------------------------------------------------------------------------
  1440. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1441. TFileOperationProgressType & ProgressData)
  1442. {
  1443. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1444. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1445. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1446. FileOperationProgress(ProgressData);
  1447. }
  1448. //---------------------------------------------------------------------------
  1449. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1450. {
  1451. UnicodeString Result;
  1452. if (FProgressForm != NULL)
  1453. {
  1454. Result = FProgressForm->ProgressStr();
  1455. }
  1456. return Result;
  1457. }
  1458. //---------------------------------------------------------------------------
  1459. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1460. bool DragDrop)
  1461. {
  1462. return (!DragDrop && (DropSourceControl == NULL)) ||
  1463. (DropSourceControl == DirView(osOther));
  1464. }
  1465. //---------------------------------------------------------------------------
  1466. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1467. TFileOperation Operation, TOperationSide Side,
  1468. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1469. TOnceDoneOperation & OnceDoneOperation)
  1470. {
  1471. if (!FAutoOperation)
  1472. {
  1473. // no selection on "/upload", form serves only as event handler
  1474. // (it is not displayed)
  1475. if (PanelOperation(Side, FDragDropOperation) &&
  1476. Visible && (Operation != foCalculateSize) &&
  1477. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1478. {
  1479. if (FOnFileOperationFinished != NULL)
  1480. {
  1481. FOnFileOperationFinished(FileName, Success);
  1482. }
  1483. else
  1484. {
  1485. TOperationSide DViewSide;
  1486. if ((FProgressSide != osCurrent) &&
  1487. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1488. {
  1489. // assume the operation is over the focused panel
  1490. DViewSide = FProgressSide;
  1491. }
  1492. else
  1493. {
  1494. DViewSide = Side;
  1495. }
  1496. TCustomDirView * DView = DirView(DViewSide);
  1497. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(DViewSide));
  1498. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1499. // this can happen when local drive is unplugged in the middle of the operation
  1500. if (Item != NULL)
  1501. {
  1502. if (Success) Item->Selected = false;
  1503. DView->MakeProgressVisible(Item);
  1504. }
  1505. }
  1506. }
  1507. if ((Operation == foCopy) || (Operation == foMove))
  1508. {
  1509. if (DebugAlwaysTrue(!IsLocalBrowserMode()))
  1510. {
  1511. if (Side == osLocal)
  1512. {
  1513. Configuration->Usage->Inc(L"UploadedFiles");
  1514. }
  1515. else
  1516. {
  1517. Configuration->Usage->Inc(L"DownloadedFiles");
  1518. }
  1519. }
  1520. }
  1521. }
  1522. if (Success && (FSynchronizeController != NULL))
  1523. {
  1524. DebugAssert(!IsSideLocalBrowser(osRemote));
  1525. if (Operation == foCopy)
  1526. {
  1527. DebugAssert(Side == osLocal);
  1528. FSynchronizeController->LogOperation(soUpload, FileName);
  1529. }
  1530. else if (Operation == foDelete)
  1531. {
  1532. DebugAssert(Side == osRemote);
  1533. FSynchronizeController->LogOperation(soDelete, FileName);
  1534. }
  1535. }
  1536. if (FProgressForm)
  1537. {
  1538. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1539. }
  1540. }
  1541. //---------------------------------------------------------------------------
  1542. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1543. TFileOperation Operation, TOperationSide Side,
  1544. bool Temp, const UnicodeString & FileName, Boolean Success,
  1545. TOnceDoneOperation & OnceDoneOperation)
  1546. {
  1547. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1548. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1549. OnceDoneOperation);
  1550. }
  1551. //---------------------------------------------------------------------------
  1552. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1553. {
  1554. return false;
  1555. }
  1556. //---------------------------------------------------------------------------
  1557. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1558. {
  1559. return false;
  1560. }
  1561. //---------------------------------------------------------------------------
  1562. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1563. {
  1564. return NULL;
  1565. }
  1566. //---------------------------------------------------------------------------
  1567. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1568. {
  1569. DebugAssert(GetSide(Side) == osRemote);
  1570. DebugUsedParam(Side);
  1571. return RemoteDirView;
  1572. }
  1573. //---------------------------------------------------------------------------
  1574. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1575. {
  1576. DebugAssert(GetSide(Side) == osRemote);
  1577. DebugUsedParam(Side);
  1578. return RemoteDriveView;
  1579. }
  1580. //---------------------------------------------------------------------------
  1581. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1582. {
  1583. DebugAssert(GetSide(Side) == osRemote);
  1584. DebugUsedParam(Side);
  1585. return HasActiveTerminal();
  1586. }
  1587. //---------------------------------------------------------------------------
  1588. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1589. TOperationSide Side, int FilesOnly)
  1590. {
  1591. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1592. }
  1593. //---------------------------------------------------------------------------
  1594. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1595. TOperationSide Side, int FilesOnly)
  1596. {
  1597. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1598. }
  1599. //---------------------------------------------------------------------------
  1600. struct THistoryItemData
  1601. {
  1602. short int Side;
  1603. short int Index;
  1604. };
  1605. //---------------------------------------------------------------------------
  1606. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1607. {
  1608. DirView(Side)->HistoryGo(Index);
  1609. }
  1610. //---------------------------------------------------------------------------
  1611. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1612. {
  1613. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1614. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1615. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1616. }
  1617. //---------------------------------------------------------------------------
  1618. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1619. bool Back)
  1620. {
  1621. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1622. {
  1623. TCustomDirView * DView = DirView(Side);
  1624. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1625. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1626. if (ICount > 10)
  1627. {
  1628. ICount = 10;
  1629. }
  1630. Menu->Items->Clear();
  1631. THistoryItemData Data;
  1632. Data.Side = Side;
  1633. for (short int i = 1; i <= ICount; i++)
  1634. {
  1635. TTBCustomItem * Item = new TTBXItem(Menu);
  1636. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1637. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1638. Item->Hint = DView->HistoryPath[Data.Index];
  1639. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1640. Item->Tag = *reinterpret_cast<int*>(&Data);
  1641. Item->OnClick = HistoryItemClick;
  1642. Menu->Items->Add(Item);
  1643. }
  1644. }
  1645. }
  1646. //---------------------------------------------------------------------------
  1647. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1648. TOperationSide Side, bool Back)
  1649. {
  1650. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1651. {
  1652. // workaround
  1653. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1654. // operator new allocates memory in Pascal code, but calls inline
  1655. // contructor in C++, leading in problems, the function does
  1656. // both in Pascal code
  1657. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1658. UpdateHistoryMenu(Side, Back);
  1659. }
  1660. return FHistoryMenu[Side == osLocal][Back];
  1661. }
  1662. //---------------------------------------------------------------------------
  1663. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1664. TCustomDirView *Sender)
  1665. {
  1666. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1667. UpdateHistoryMenu(Side, true);
  1668. UpdateHistoryMenu(Side, false);
  1669. }
  1670. //---------------------------------------------------------------------------
  1671. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1672. {
  1673. // remote custom commands can be executed only if the server supports shell commands
  1674. // or have secondary shell
  1675. return HasActiveTerminal() && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1676. }
  1677. //---------------------------------------------------------------------------
  1678. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1679. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1680. {
  1681. // -1 = hidden, 0 = disabled, 1 = enabled
  1682. int Result;
  1683. TFileCustomCommand RemoteCustomCommand;
  1684. TLocalCustomCommand LocalCustomCommand;
  1685. TFileCustomCommand * NonInteractiveCustomCommand =
  1686. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1687. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1688. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1689. if (FLAGCLEAR(Command.Params, ccLocal))
  1690. {
  1691. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1692. // custom command that does not operate with files can be executed anytime ...
  1693. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1694. {
  1695. // ... but do not show such command in remote file menu
  1696. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1697. {
  1698. Result = AllowedState;
  1699. }
  1700. else
  1701. {
  1702. Result = -1;
  1703. }
  1704. }
  1705. else
  1706. {
  1707. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1708. {
  1709. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1710. }
  1711. else
  1712. {
  1713. Result = -1;
  1714. }
  1715. }
  1716. }
  1717. else
  1718. {
  1719. // custom command that does not operate with files can be executed anytime
  1720. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1721. {
  1722. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1723. }
  1724. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1725. {
  1726. if ((ListType == ccltAll) || (ListType == ccltFile))
  1727. {
  1728. // special case is "diff"-style command that can be executed over any side,
  1729. // if we have both sides
  1730. Result =
  1731. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1732. // directly (instead of EnableSelectedOperation) to pass
  1733. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1734. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1735. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1736. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1737. }
  1738. else if (ListType == ccltBoth)
  1739. {
  1740. DebugAssert(!IsLocalBrowserMode());
  1741. Result = 1;
  1742. }
  1743. else
  1744. {
  1745. Result = -1;
  1746. }
  1747. }
  1748. else
  1749. {
  1750. if ((ListType == ccltAll) ||
  1751. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1752. {
  1753. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1754. }
  1755. else
  1756. {
  1757. Result = -1;
  1758. }
  1759. }
  1760. if ((Result > 0) &&
  1761. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1762. !HasActiveTerminal())
  1763. {
  1764. Result = 0;
  1765. }
  1766. }
  1767. return Result;
  1768. }
  1769. //---------------------------------------------------------------------------
  1770. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1771. TStrings * FileList, const TCustomCommandType & ACommand,
  1772. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1773. {
  1774. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1775. {
  1776. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1777. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1778. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1779. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1780. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1781. bool Capture =
  1782. FLAGSET(ACommand.Params, ccShowResults) ||
  1783. FLAGSET(ACommand.Params, ccCopyResults) ||
  1784. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1785. TCaptureOutputEvent OutputEvent = NULL;
  1786. DebugAssert(FCapturedLog == NULL);
  1787. if (Capture)
  1788. {
  1789. FCapturedLog = new TStringList();
  1790. OutputEvent = TerminalCaptureLog;
  1791. }
  1792. try
  1793. {
  1794. if (!RemoteCustomCommand.IsFileCommand(Command))
  1795. {
  1796. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1797. OutputEvent);
  1798. }
  1799. else
  1800. {
  1801. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1802. }
  1803. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1804. {
  1805. if (FLAGSET(ACommand.Params, ccCopyResults))
  1806. {
  1807. CopyToClipboard(FCapturedLog);
  1808. }
  1809. if (FLAGSET(ACommand.Params, ccShowResults))
  1810. {
  1811. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1812. }
  1813. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1814. {
  1815. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1816. }
  1817. }
  1818. }
  1819. __finally
  1820. {
  1821. SAFE_DESTROY(FCapturedLog);
  1822. }
  1823. }
  1824. }
  1825. //---------------------------------------------------------------------------
  1826. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1827. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1828. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1829. {
  1830. DebugAssert(!IsLocalBrowserMode());
  1831. TStrings * LocalFileList = NULL;
  1832. TStrings * RemoteFileList = NULL;
  1833. TStrings * RemoteFileListFull = NULL;
  1834. try
  1835. {
  1836. if (LocalFileCommand)
  1837. {
  1838. if (ALocalFileList == NULL)
  1839. {
  1840. DebugAssert(HasDirView[osLocal]);
  1841. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1842. // directly (instead of EnableSelectedOperation) to pass
  1843. // false to FocusedFileOnlyWhenFocused
  1844. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1845. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1846. }
  1847. else
  1848. {
  1849. LocalFileList = ALocalFileList;
  1850. }
  1851. if (FileListCommand)
  1852. {
  1853. if (LocalFileList->Count != 1)
  1854. {
  1855. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1856. }
  1857. }
  1858. else
  1859. {
  1860. if ((LocalFileList->Count != 1) &&
  1861. (FileList->Count != 1) &&
  1862. (LocalFileList->Count != FileList->Count))
  1863. {
  1864. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1865. }
  1866. }
  1867. }
  1868. UnicodeString RootTempDir;
  1869. UnicodeString TempDir;
  1870. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1871. if (!RemoteFiles)
  1872. {
  1873. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1874. }
  1875. try
  1876. {
  1877. TDateTimes RemoteFileTimes;
  1878. if (RemoteFiles)
  1879. {
  1880. RemoteFileList = FileList;
  1881. }
  1882. else
  1883. {
  1884. RemoteFileList = new TStringList();
  1885. TMakeLocalFileListParams MakeFileListParam;
  1886. MakeFileListParam.FileList = RemoteFileList;
  1887. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1888. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1889. MakeFileListParam.Recursive =
  1890. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1891. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1892. if (!MakeFileListParam.Recursive)
  1893. {
  1894. RemoteFileTimes.clear();
  1895. RemoteFileListFull = new TStringList();
  1896. MakeFileListParam.FileList = RemoteFileListFull;
  1897. MakeFileListParam.Recursive = true;
  1898. MakeFileListParam.IncludeDirs = false;
  1899. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1900. }
  1901. else
  1902. {
  1903. RemoteFileListFull = RemoteFileList;
  1904. }
  1905. }
  1906. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1907. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1908. if (!NonBlocking)
  1909. {
  1910. int Count;
  1911. if (FileListCommand)
  1912. {
  1913. Count = 1;
  1914. }
  1915. else if (LocalFileCommand)
  1916. {
  1917. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1918. }
  1919. else
  1920. {
  1921. Count = RemoteFileList->Count;
  1922. }
  1923. Progress.Start(foCustomCommand, osRemote, Count);
  1924. DebugAssert(FProgressForm != NULL);
  1925. FProgressForm->ReadOnly = true;
  1926. }
  1927. try
  1928. {
  1929. if (FileListCommand)
  1930. {
  1931. UnicodeString LocalFile;
  1932. // MakeFileList does not delimit filenames
  1933. UnicodeString FileList = MakeFileList(RemoteFileList);
  1934. if (LocalFileCommand)
  1935. {
  1936. DebugAssert(LocalFileList->Count == 1);
  1937. LocalFile = LocalFileList->Strings[0];
  1938. }
  1939. TLocalCustomCommand CustomCommand(Data,
  1940. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1941. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1942. if (NonBlocking)
  1943. {
  1944. DebugAssert(!POutput);
  1945. ExecuteShellChecked(ShellCommand);
  1946. }
  1947. else
  1948. {
  1949. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1950. }
  1951. }
  1952. else if (LocalFileCommand)
  1953. {
  1954. if (LocalFileList->Count == 1)
  1955. {
  1956. UnicodeString LocalFile = LocalFileList->Strings[0];
  1957. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1958. {
  1959. UnicodeString FileName = RemoteFileList->Strings[Index];
  1960. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1961. Progress.SetFile(FileNameForProgress);
  1962. TLocalCustomCommand CustomCommand(Data,
  1963. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1964. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1965. TOnceDoneOperation OnceDoneOperation;
  1966. // Do not unselect anything, as it won't work with two panels anyway
  1967. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1968. }
  1969. }
  1970. else if (RemoteFileList->Count == 1)
  1971. {
  1972. UnicodeString FileName = RemoteFileList->Strings[0];
  1973. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1974. {
  1975. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1976. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1977. Progress.SetFile(LocalFileNameOnly);
  1978. TLocalCustomCommand CustomCommand(
  1979. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1980. FileName, LocalFileName, L"");
  1981. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1982. TOnceDoneOperation OnceDoneOperation;
  1983. // Do not unselect anything, as it won't work with two panels anyway
  1984. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1985. }
  1986. }
  1987. else
  1988. {
  1989. if (LocalFileList->Count != RemoteFileList->Count)
  1990. {
  1991. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1992. }
  1993. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1994. {
  1995. UnicodeString FileName = RemoteFileList->Strings[Index];
  1996. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1997. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1998. Progress.SetFile(LocalFileNameOnly); // sic
  1999. TLocalCustomCommand CustomCommand(
  2000. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2001. FileName, LocalFileName, L"");
  2002. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2003. TOnceDoneOperation OnceDoneOperation;
  2004. // Do not unselect anything, as it won't work with two panels anyway
  2005. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2006. }
  2007. }
  2008. }
  2009. else
  2010. {
  2011. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2012. {
  2013. UnicodeString FileName = RemoteFileList->Strings[Index];
  2014. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2015. Progress.SetFile(FileNameForProgress);
  2016. TLocalCustomCommand CustomCommand(Data,
  2017. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2018. FileName, L"", L"");
  2019. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2020. TOnceDoneOperation OnceDoneOperation;
  2021. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2022. }
  2023. }
  2024. }
  2025. __finally
  2026. {
  2027. if (!NonBlocking)
  2028. {
  2029. Progress.Stop();
  2030. }
  2031. }
  2032. DebugAssert(!FAutoOperation);
  2033. if (!RemoteFiles)
  2034. {
  2035. TempDir = IncludeTrailingBackslash(TempDir);
  2036. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2037. {
  2038. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2039. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2040. // Skip directories, process only nested files.
  2041. // The check is redundant as FileAge fails for directories anyway.
  2042. !DirectoryExists(FileName))
  2043. {
  2044. UnicodeString RemoteDir =
  2045. UnixExtractFileDir(
  2046. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2047. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2048. TDateTime NewTime;
  2049. if (FileAge(FileName, NewTime) &&
  2050. (NewTime != RemoteFileTimes[Index]))
  2051. {
  2052. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2053. TemporaryFileCopyParam(CopyParam);
  2054. CopyParam.FileMask = L"";
  2055. FAutoOperation = true;
  2056. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2057. TemporaryFilesList->Add(FileName);
  2058. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. __finally
  2065. {
  2066. FAutoOperation = false;
  2067. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2068. {
  2069. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2070. }
  2071. }
  2072. }
  2073. __finally
  2074. {
  2075. if (RemoteFileList != FileList)
  2076. {
  2077. delete RemoteFileList;
  2078. }
  2079. if (LocalFileList != ALocalFileList)
  2080. {
  2081. delete LocalFileList;
  2082. }
  2083. if (RemoteFileListFull != RemoteFileList)
  2084. {
  2085. delete RemoteFileListFull;
  2086. }
  2087. }
  2088. }
  2089. //---------------------------------------------------------------------------
  2090. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2091. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2092. bool FileListCommand, UnicodeString * POutput)
  2093. {
  2094. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2095. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2096. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2097. {
  2098. UnicodeString FileName = SelectedFileList->Strings[Index];
  2099. if (DirectoryExists(FileName))
  2100. {
  2101. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2102. {
  2103. LocalFileList->Add(FileName);
  2104. }
  2105. if (FLAGSET(ACommand.Params, ccRecursive))
  2106. {
  2107. TMakeLocalFileListParams MakeFileListParam;
  2108. MakeFileListParam.FileList = LocalFileList.get();
  2109. MakeFileListParam.FileTimes = NULL;
  2110. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2111. MakeFileListParam.Recursive = true;
  2112. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2113. }
  2114. }
  2115. else
  2116. {
  2117. LocalFileList->Add(FileName);
  2118. }
  2119. }
  2120. UnicodeString RemotePath;
  2121. if (Terminal != NULL)
  2122. {
  2123. RemotePath = Terminal->CurrentDirectory;
  2124. }
  2125. if (FileListCommand)
  2126. {
  2127. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2128. TLocalCustomCommand CustomCommand(
  2129. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2130. L"", L"", FileList);
  2131. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2132. }
  2133. else
  2134. {
  2135. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2136. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2137. DebugAssert(FProgressForm != NULL);
  2138. FProgressForm->ReadOnly = true;
  2139. try
  2140. {
  2141. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2142. {
  2143. UnicodeString FileName = LocalFileList->Strings[Index];
  2144. Progress.SetFile(FileName);
  2145. TLocalCustomCommand CustomCommand(
  2146. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2147. FileName, L"", L"");
  2148. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2149. TOnceDoneOperation OnceDoneOperation;
  2150. Progress.Finish(FileName, true, OnceDoneOperation);
  2151. }
  2152. }
  2153. __finally
  2154. {
  2155. Progress.Stop();
  2156. }
  2157. }
  2158. }
  2159. //---------------------------------------------------------------------------
  2160. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2161. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2162. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2163. {
  2164. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2165. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2166. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2167. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2168. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2169. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2170. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2171. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2172. std::unique_ptr<UnicodeString> POutput;
  2173. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2174. FLAGSET(ACommand.Params, ccCopyResults))
  2175. {
  2176. POutput.reset(new UnicodeString());
  2177. }
  2178. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  2179. FProgressSide = FCurrentSide;
  2180. if (!LocalCustomCommand.IsFileCommand(Command))
  2181. {
  2182. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2183. }
  2184. // remote files?
  2185. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2186. {
  2187. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2188. }
  2189. // local files
  2190. else
  2191. {
  2192. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2193. }
  2194. if (POutput.get() != NULL)
  2195. {
  2196. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2197. int P = POutput->Pos(sLineBreak);
  2198. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2199. {
  2200. POutput->SetLength(P - 1);
  2201. }
  2202. // Copy even empty output to clipboard
  2203. if (FLAGSET(ACommand.Params, ccCopyResults))
  2204. {
  2205. CopyToClipboard(*POutput);
  2206. }
  2207. // But do not show an empty message box.
  2208. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2209. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2210. !POutput->IsEmpty())
  2211. {
  2212. TClipboardHandler ClipboardHandler;
  2213. ClipboardHandler.Text = *POutput;
  2214. TMessageParams Params;
  2215. TQueryButtonAlias Aliases[1];
  2216. Aliases[0].Button = qaRetry;
  2217. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2218. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2219. Params.Aliases = Aliases;
  2220. Params.AliasesCount = LENOF(Aliases);
  2221. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2222. }
  2223. }
  2224. }
  2225. //---------------------------------------------------------------------------
  2226. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2227. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2228. {
  2229. TCustomCommandData Data;
  2230. UnicodeString Site;
  2231. UnicodeString RemotePath;
  2232. if (HasActiveTerminal())
  2233. {
  2234. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2235. Data = TCustomCommandData(SessionData.get());
  2236. Site = Terminal->SessionData->SessionKey;
  2237. RemotePath = Terminal->CurrentDirectory;
  2238. }
  2239. UnicodeString HelpKeyword = ACommand.HomePage;
  2240. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2241. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2242. {
  2243. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2244. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2245. {
  2246. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2247. }
  2248. else
  2249. {
  2250. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2251. }
  2252. if (!DoCustomCommandOptionsDialog(
  2253. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2254. {
  2255. Abort();
  2256. }
  2257. }
  2258. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2259. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2260. {
  2261. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2262. }
  2263. else
  2264. {
  2265. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2266. }
  2267. }
  2268. //---------------------------------------------------------------------------
  2269. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2270. const TCustomCommandType & Command)
  2271. {
  2272. DebugAssert(FCustomCommandLocalFileList != NULL);
  2273. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2274. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2275. TStrings * LocalFileList = new TStringList();
  2276. TStrings * RemoteFileList = new TStringList();
  2277. try
  2278. {
  2279. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2280. {
  2281. LocalFileList->Clear();
  2282. LocalFileList->AddObject(
  2283. FCustomCommandLocalFileList->Strings[Index],
  2284. FCustomCommandLocalFileList->Objects[Index]);
  2285. RemoteFileList->Clear();
  2286. RemoteFileList->AddObject(
  2287. FCustomCommandRemoteFileList->Strings[Index],
  2288. FCustomCommandRemoteFileList->Objects[Index]);
  2289. CustomCommand(RemoteFileList, Command, LocalFileList);
  2290. }
  2291. }
  2292. __finally
  2293. {
  2294. delete LocalFileList;
  2295. delete RemoteFileList;
  2296. }
  2297. }
  2298. //---------------------------------------------------------------------------
  2299. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2300. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2301. {
  2302. delete FCustomCommandLocalFileList;
  2303. delete FCustomCommandRemoteFileList;
  2304. // takeover ownership,
  2305. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2306. FCustomCommandLocalFileList = LocalFileList;
  2307. FCustomCommandRemoteFileList = RemoteFileList;
  2308. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2309. if (Button != NULL)
  2310. {
  2311. FCustomCommandMenu->Items->Clear();
  2312. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2313. MenuPopup(FCustomCommandMenu, Button);
  2314. }
  2315. else
  2316. {
  2317. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2318. }
  2319. }
  2320. //---------------------------------------------------------------------------
  2321. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2322. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2323. {
  2324. DebugAssert(FCapturedLog != NULL);
  2325. if ((OutputType == cotOutput) || (OutputType == cotError))
  2326. {
  2327. FCapturedLog->Add(AddedLine);
  2328. }
  2329. }
  2330. //---------------------------------------------------------------------------
  2331. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2332. TOperationSide Side)
  2333. {
  2334. return
  2335. (Side == osOther) &&
  2336. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2337. }
  2338. //---------------------------------------------------------------------------
  2339. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2340. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2341. {
  2342. TTBItemOptions O;
  2343. O = Item->Options;
  2344. TCustomDirView * DView = DirView(Side);
  2345. if ((DView->ItemFocused != NULL) &&
  2346. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2347. // when resolving links is disabled, default action is to enter the directory,
  2348. // no matter what DoubleClickAction is configured to
  2349. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2350. // Can only Edit files, but can Open/Copy even directories
  2351. ((DoubleClickAction != dcaEdit) ||
  2352. !DView->ItemIsDirectory(DView->ItemFocused)))
  2353. {
  2354. Item->Options = O << tboDefault;
  2355. }
  2356. else
  2357. {
  2358. Item->Options = O >> tboDefault;
  2359. }
  2360. }
  2361. //---------------------------------------------------------------------------
  2362. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2363. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2364. {
  2365. TCustomDirView * DView = DirView(Side);
  2366. TListItem * Item = DView->ItemFocused;
  2367. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2368. EnableFocusedOperation[Side])
  2369. {
  2370. TPoint ClientPoint;
  2371. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2372. TPoint(0, 0) : MousePos;
  2373. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2374. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2375. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2376. }
  2377. }
  2378. //---------------------------------------------------------------------------
  2379. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2380. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2381. {
  2382. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2383. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2384. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2385. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2386. Handled = true;
  2387. }
  2388. //---------------------------------------------------------------------------
  2389. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2390. {
  2391. }
  2392. //---------------------------------------------------------------------------
  2393. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2394. {
  2395. DebugAssert(FErrorList == NULL);
  2396. if (WinConfiguration->ContinueOnError)
  2397. {
  2398. FErrorList = new TStringList();
  2399. Configuration->Usage->Inc(L"ContinuationsOnError");
  2400. }
  2401. NonVisualDataModule->StartBusy();
  2402. }
  2403. //---------------------------------------------------------------------------
  2404. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2405. {
  2406. NonVisualDataModule->EndBusy();
  2407. if (FErrorList)
  2408. {
  2409. HandleErrorList(FErrorList);
  2410. }
  2411. }
  2412. //---------------------------------------------------------------------------
  2413. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2414. const TCopyParamType & CopyParam)
  2415. {
  2416. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2417. {
  2418. Configuration->Usage->Inc(L"FileMaskUses");
  2419. }
  2420. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2421. {
  2422. Configuration->Usage->Inc(L"OperationMaskUses");
  2423. }
  2424. }
  2425. //---------------------------------------------------------------------------
  2426. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2427. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2428. {
  2429. DebugAssert(!IsLocalBrowserMode());
  2430. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2431. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2432. TTransferOperationParam DefaultParam;
  2433. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2434. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2435. switch (Param.Queue)
  2436. {
  2437. case asOn:
  2438. CopyParam.Queue = true;
  2439. break;
  2440. case asOff:
  2441. CopyParam.Queue = false;
  2442. break;
  2443. case asAuto:
  2444. default:
  2445. // keep default
  2446. break;
  2447. }
  2448. bool Result =
  2449. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2450. if (Result)
  2451. {
  2452. DebugAssert(Terminal);
  2453. bool SelectionRestored = false;
  2454. TCustomDirView * DView = NULL;
  2455. if (HasDirView[Side])
  2456. {
  2457. DView = DirView(Side);
  2458. DView->SaveSelection();
  2459. DView->SaveSelectedNames();
  2460. }
  2461. UpdateCopyParamCounters(CopyParam);
  2462. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2463. DebugAssert(FTransferResumeList == NULL);
  2464. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2465. FMoveToQueue = false;
  2466. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2467. try
  2468. {
  2469. TStrings * PermanentFileList;
  2470. std::unique_ptr<TStrings> PermanentFileListOwner;
  2471. try
  2472. {
  2473. if (Side == osLocal)
  2474. {
  2475. PermanentFileList = FileList;
  2476. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2477. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2478. if (Operation == foMove)
  2479. {
  2480. ReloadLocalDirectory();
  2481. if (DView != NULL)
  2482. {
  2483. DView->RestoreSelection();
  2484. }
  2485. SelectionRestored = true;
  2486. }
  2487. }
  2488. else
  2489. {
  2490. // Clone the file list as it may refer to current directory files,
  2491. // which get destroyed, when the source directory is reloaded after foMove operation.
  2492. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2493. // But for a hotfix, we are not going to do such a big change.
  2494. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2495. PermanentFileList = PermanentFileListOwner.get();
  2496. try
  2497. {
  2498. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2499. }
  2500. __finally
  2501. {
  2502. if (Operation == foMove)
  2503. {
  2504. if (DView != NULL)
  2505. {
  2506. DView->RestoreSelection();
  2507. }
  2508. SelectionRestored = true;
  2509. }
  2510. ReloadLocalDirectory(Param.TargetDirectory);
  2511. }
  2512. }
  2513. }
  2514. catch (EAbort &)
  2515. {
  2516. if (FMoveToQueue)
  2517. {
  2518. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2519. DebugAssert(CopyParam.TransferSkipList == NULL);
  2520. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2521. if (TransferResumeList->Count > 0)
  2522. {
  2523. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2524. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2525. }
  2526. CopyParam.TransferSkipList = TransferResumeList.release();
  2527. // not really needed, just to keep it consistent with TransferResumeList
  2528. FTransferResumeList = NULL;
  2529. FMoveToQueue = false;
  2530. Configuration->Usage->Inc("MovesToBackground");
  2531. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2532. ClearTransferSourceSelection(Direction);
  2533. }
  2534. throw;
  2535. }
  2536. }
  2537. __finally
  2538. {
  2539. if (!SelectionRestored && (DView != NULL))
  2540. {
  2541. DView->DiscardSavedSelection();
  2542. }
  2543. FTransferResumeList = NULL;
  2544. }
  2545. }
  2546. return Result;
  2547. }
  2548. //---------------------------------------------------------------------------
  2549. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2550. TOperationSide Side, TStrings * FileList, void * Param)
  2551. {
  2552. DebugAssert(FileList->Count);
  2553. // We deliberately do not toggle alternative flag (Param), but use OR,
  2554. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2555. // shortcut of CurrentDeleteAlternativeAction
  2556. bool Alternative =
  2557. bool(Param) || UseAlternativeFunction();
  2558. bool Recycle;
  2559. if (IsSideLocalBrowser(Side))
  2560. {
  2561. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2562. }
  2563. else
  2564. {
  2565. Recycle =
  2566. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2567. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2568. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2569. }
  2570. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2571. if (!Result)
  2572. {
  2573. UnicodeString Query;
  2574. if (FileList->Count == 1)
  2575. {
  2576. if (IsSideLocalBrowser(Side))
  2577. {
  2578. Query = ExtractFileName(FileList->Strings[0]);
  2579. }
  2580. else
  2581. {
  2582. Query = UnixExtractFileName(FileList->Strings[0]);
  2583. }
  2584. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2585. }
  2586. else
  2587. {
  2588. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2589. }
  2590. TMessageParams Params(mpNeverAskAgainCheck);
  2591. Params.ImageName = L"Delete file";
  2592. unsigned int Answer =
  2593. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2594. if (Answer == qaNeverAskAgain)
  2595. {
  2596. Result = true;
  2597. if (Recycle)
  2598. {
  2599. WinConfiguration->ConfirmRecycling = false;
  2600. }
  2601. else
  2602. {
  2603. WinConfiguration->ConfirmDeleting = false;
  2604. }
  2605. }
  2606. else
  2607. {
  2608. Result = (Answer == qaOK);
  2609. }
  2610. }
  2611. if (Result)
  2612. {
  2613. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2614. }
  2615. return Result;
  2616. }
  2617. //---------------------------------------------------------------------------
  2618. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2619. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2620. {
  2621. TAutoBatch AutoBatch(this);
  2622. bool Result;
  2623. if ((Operation == foCopy) || (Operation == foMove))
  2624. {
  2625. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2626. }
  2627. else if (Operation == foRename)
  2628. {
  2629. DebugAssert(DirView(Side)->ItemFocused);
  2630. DirView(Side)->ItemFocused->EditCaption();
  2631. Result = true;
  2632. }
  2633. else if (Operation == foDelete)
  2634. {
  2635. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2636. }
  2637. else if (Operation == foSetProperties)
  2638. {
  2639. DirView(osRemote)->SaveSelectedNames();
  2640. Result = SetProperties(Side, FileList);
  2641. }
  2642. else if (Operation == foCustomCommand)
  2643. {
  2644. DebugAssert(Param);
  2645. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2646. DirView(osRemote)->SaveSelectedNames();
  2647. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2648. CustomCommand(FileList, *Command, NULL);
  2649. Result = true;
  2650. }
  2651. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2652. {
  2653. DebugAssert(!IsSideLocalBrowser(Side));
  2654. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2655. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2656. }
  2657. else if (Operation == foLock)
  2658. {
  2659. DebugAssert(!IsSideLocalBrowser(Side));
  2660. LockFiles(FileList, true);
  2661. Result = true;
  2662. }
  2663. else if (Operation == foUnlock)
  2664. {
  2665. DebugAssert(!IsSideLocalBrowser(Side));
  2666. LockFiles(FileList, false);
  2667. Result = true;
  2668. }
  2669. else
  2670. {
  2671. DebugFail();
  2672. }
  2673. return Result;
  2674. }
  2675. //---------------------------------------------------------------------------
  2676. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2677. {
  2678. if (Side == osCurrent)
  2679. {
  2680. Side = FCurrentSide;
  2681. }
  2682. return Side;
  2683. }
  2684. //---------------------------------------------------------------------------
  2685. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2686. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2687. {
  2688. Side = GetSide(Side);
  2689. bool Result;
  2690. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2691. try
  2692. {
  2693. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2694. }
  2695. __finally
  2696. {
  2697. delete FileList;
  2698. }
  2699. return Result;
  2700. }
  2701. //---------------------------------------------------------------------------
  2702. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2703. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2704. bool NoConfirmation, void * Param)
  2705. {
  2706. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2707. {
  2708. if ((Operation == foCopy) || (Operation == foMove))
  2709. {
  2710. DebugAssert(!IsLocalBrowserMode());
  2711. if (GetSide(Side) == osLocal)
  2712. {
  2713. Configuration->Usage->Inc(L"UploadsCommand");
  2714. }
  2715. else
  2716. {
  2717. Configuration->Usage->Inc(L"DownloadsCommand");
  2718. }
  2719. }
  2720. }
  2721. }
  2722. //---------------------------------------------------------------------------
  2723. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2724. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2725. {
  2726. TTransferOperationParam Param;
  2727. if ((WinConfiguration->Interface != ifCommander) ||
  2728. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2729. {
  2730. Flags &= ~cocShortCutHint;
  2731. }
  2732. TCustomDirView * DView = DirView(Side);
  2733. Param.Options =
  2734. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2735. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2736. if (FLAGSET(Flags, cocQueue))
  2737. {
  2738. Param.Queue = asOn;
  2739. }
  2740. else if (FLAGSET(Flags, cocNonQueue))
  2741. {
  2742. Param.Queue = asOff;
  2743. }
  2744. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2745. }
  2746. //---------------------------------------------------------------------------
  2747. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2748. {
  2749. try
  2750. {
  2751. if (ErrorList->Count)
  2752. {
  2753. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2754. if (MessageDialog(Message, qtError,
  2755. qaOK | qaCancel, HELP_NONE) == qaOK)
  2756. {
  2757. unsigned int Answer;
  2758. int Index = 0;
  2759. do
  2760. {
  2761. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2762. TQueryButtonAlias Aliases[2];
  2763. Aliases[0].Button = qaYes;
  2764. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2765. Aliases[1].Button = qaNo;
  2766. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2767. TMessageParams Params;
  2768. Params.Aliases = Aliases;
  2769. Params.AliasesCount = LENOF(Aliases);
  2770. Answer = MoreMessageDialog(
  2771. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2772. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2773. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2774. qaOK, HELP_NONE, &Params);
  2775. if (Answer == qaNo)
  2776. {
  2777. Index++;
  2778. }
  2779. if (Answer == qaYes)
  2780. {
  2781. Index--;
  2782. }
  2783. }
  2784. while (Answer != qaOK);
  2785. }
  2786. }
  2787. }
  2788. __finally
  2789. {
  2790. TStrings * List = ErrorList;
  2791. ErrorList = NULL;
  2792. for (int i = 0; i < List->Count; i++)
  2793. {
  2794. delete List->Objects[i];
  2795. }
  2796. delete List;
  2797. }
  2798. }
  2799. //---------------------------------------------------------------------------
  2800. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2801. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2802. {
  2803. // needed for checking filemasks, as there's no directory object
  2804. // associated with the file object
  2805. File->FullFileName = FullFileName;
  2806. TFileMasks::TParams MaskParams;
  2807. MaskParams.Size = File->Size;
  2808. MaskParams.Modification = File->Modification;
  2809. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2810. }
  2811. //---------------------------------------------------------------------------
  2812. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2813. {
  2814. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2815. Side = GetSide(Side);
  2816. TCustomDirView * DView = DirView(Side);
  2817. TListItem * FocusedItem = DView->ItemFocused;
  2818. UnicodeString Name;
  2819. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2820. {
  2821. Name = DView->ItemFileName(FocusedItem);
  2822. }
  2823. else
  2824. {
  2825. Name = LoadStr(NEW_FILE);
  2826. }
  2827. UnicodeString Names = Name;
  2828. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2829. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2830. HELP_EDIT_NEW, History.get(), true))
  2831. {
  2832. while (!Names.IsEmpty())
  2833. {
  2834. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2835. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2836. UnicodeString TargetFileName;
  2837. UnicodeString LocalFileName;
  2838. UnicodeString RootTempDir;
  2839. UnicodeString TempDir;
  2840. UnicodeString RemoteDirectory;
  2841. bool ExistingFile = false;
  2842. if (!IsSideLocalBrowser(Side))
  2843. {
  2844. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2845. TRemoteFile * File = NULL;
  2846. if (FTerminal->FileExists(Name, &File) &&
  2847. !File->IsDirectory)
  2848. {
  2849. try
  2850. {
  2851. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2852. ExistingFile = true;
  2853. }
  2854. __finally
  2855. {
  2856. delete File;
  2857. }
  2858. }
  2859. if (!ExistingFile)
  2860. {
  2861. RemoteDirectory = UnixExtractFilePath(Name);
  2862. TemporaryDirectoryForRemoteFiles(
  2863. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2864. TargetFileName = UnixExtractFileName(Name);
  2865. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2866. LocalFileName = TempDir +
  2867. // We probably do not want to trim the VMS version here
  2868. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2869. }
  2870. }
  2871. else
  2872. {
  2873. if (ExtractFilePath(Name).IsEmpty())
  2874. {
  2875. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2876. }
  2877. else
  2878. {
  2879. LocalFileName = ExpandFileName(Name);
  2880. }
  2881. TargetFileName = ExtractFileName(Name);
  2882. }
  2883. if (!ExistingFile)
  2884. {
  2885. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2886. if (NewFile)
  2887. {
  2888. int File = FileCreate(ApiPath(LocalFileName));
  2889. if (File < 0)
  2890. {
  2891. if (!RootTempDir.IsEmpty())
  2892. {
  2893. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2894. }
  2895. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2896. }
  2897. else
  2898. {
  2899. FileClose(File);
  2900. }
  2901. }
  2902. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2903. const TEditorData * ExternalEditor = NULL;
  2904. TFileMasks::TParams MaskParams; // size not known
  2905. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2906. false, MaskParams);
  2907. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2908. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2909. }
  2910. }
  2911. }
  2912. }
  2913. //---------------------------------------------------------------------------
  2914. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2915. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2916. {
  2917. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2918. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2919. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2920. return
  2921. ((ExecuteFileBy == efInternalEditor)) ||
  2922. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2923. }
  2924. //---------------------------------------------------------------------------
  2925. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2926. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2927. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2928. UnicodeString RemoteDirectory, bool NewFile)
  2929. {
  2930. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2931. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2932. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2933. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2934. Side = GetSide(Side);
  2935. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2936. if (!IsSideLocalBrowser(Side))
  2937. {
  2938. Data->Terminal = Terminal;
  2939. Data->Queue = Queue;
  2940. Data->SessionData = CloneCurrentSessionData();
  2941. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2942. Data->RemoteDirectory = RemoteDirectory;
  2943. Data->SessionName = Terminal->SessionData->SessionName;
  2944. Data->LocalRootDirectory = LocalRootDirectory;
  2945. Data->OriginalFileName = OriginalFileName;
  2946. Data->Command = L""; // will be changed later for external editor
  2947. }
  2948. if (ExecuteFileBy == efInternalEditor)
  2949. {
  2950. if (!IsSideLocalBrowser(Side))
  2951. {
  2952. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2953. L" - " + Terminal->SessionData->SessionName;
  2954. TForm * Editor;
  2955. try
  2956. {
  2957. TNotifyEvent OnFileChanged = NULL;
  2958. TNotifyEvent OnSaveAll = NULL;
  2959. TAnyModifiedEvent OnAnyModified = NULL;
  2960. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2961. if (Terminal->IsCapable[fcBackgroundTransfers])
  2962. {
  2963. OnFileChanged = FEditorManager->FileChanged;
  2964. OnSaveAll = SaveAllInternalEditors;
  2965. OnAnyModified = AnyInternalEditorModified;
  2966. }
  2967. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2968. FEditorManager->FileReload, FEditorManager->FileClosed,
  2969. OnSaveAll, OnAnyModified,
  2970. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2971. }
  2972. catch(...)
  2973. {
  2974. if (!LocalRootDirectory.IsEmpty())
  2975. {
  2976. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2977. }
  2978. throw;
  2979. }
  2980. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2981. }
  2982. else
  2983. {
  2984. DebugAssert(!FStandaloneEditing);
  2985. TForm * Editor =
  2986. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2987. SaveAllInternalEditors, AnyInternalEditorModified,
  2988. L"", false, SessionColor, -1, NewFile);
  2989. FLocalEditors->Add(Editor);
  2990. }
  2991. }
  2992. else
  2993. {
  2994. HANDLE Process;
  2995. if (ExecuteFileBy == efExternalEditor)
  2996. {
  2997. UnicodeString Program, Params, Dir;
  2998. Data->Command = ExternalEditor->ExternalEditor;
  2999. ReformatFileNameCommand(Data->Command);
  3000. SplitCommand(Data->Command, Program, Params, Dir);
  3001. Params = ExpandFileNameCommand(Params, FileName);
  3002. Program = ExpandEnvironmentVariables(Program);
  3003. if (!ExecuteShell(Program, Params, Process))
  3004. {
  3005. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3006. }
  3007. }
  3008. else
  3009. {
  3010. DebugAssert(!IsSideLocalBrowser(Side));
  3011. if (!ExecuteShell(FileName, L"", Process))
  3012. {
  3013. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3014. }
  3015. }
  3016. if (IsSideLocalBrowser(Side) ||
  3017. ((ExecuteFileBy == efShell) &&
  3018. !WinConfiguration->Editor.SDIShellEditor) ||
  3019. ((ExecuteFileBy == efExternalEditor) &&
  3020. !ExternalEditor->SDIExternalEditor))
  3021. {
  3022. // no need for handle
  3023. if (Process != NULL)
  3024. {
  3025. DebugCheck(CloseHandle(Process));
  3026. }
  3027. Process = INVALID_HANDLE_VALUE;
  3028. }
  3029. else
  3030. {
  3031. if (Process == NULL)
  3032. {
  3033. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3034. }
  3035. }
  3036. if (!IsSideLocalBrowser(Side))
  3037. {
  3038. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3039. }
  3040. }
  3041. }
  3042. //---------------------------------------------------------------------------
  3043. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3044. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3045. void * /*Arg*/)
  3046. {
  3047. if (Token != NULL)
  3048. {
  3049. EditorFormFileSave(static_cast<TForm *>(Token));
  3050. }
  3051. }
  3052. //---------------------------------------------------------------------------
  3053. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3054. {
  3055. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3056. {
  3057. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3058. }
  3059. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3060. }
  3061. //---------------------------------------------------------------------------
  3062. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3063. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3064. void * Arg)
  3065. {
  3066. if ((Token != NULL) &&
  3067. IsEditorFormModified(static_cast<TForm *>(Token)))
  3068. {
  3069. *static_cast<bool *>(Arg) = true;
  3070. }
  3071. }
  3072. //---------------------------------------------------------------------------
  3073. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3074. TObject * /*Sender*/, bool & Modified)
  3075. {
  3076. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3077. {
  3078. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3079. {
  3080. Modified = true;
  3081. }
  3082. }
  3083. if (!Modified)
  3084. {
  3085. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3086. }
  3087. }
  3088. //---------------------------------------------------------------------------
  3089. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3090. {
  3091. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3092. }
  3093. //---------------------------------------------------------------------------
  3094. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3095. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3096. UnicodeString & Result, UnicodeString & RootDirectory)
  3097. {
  3098. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3099. {
  3100. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3101. Result = RootDirectory;
  3102. }
  3103. else
  3104. {
  3105. RootDirectory = L"";
  3106. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3107. Result = IncludeTrailingBackslash(Result);
  3108. }
  3109. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3110. {
  3111. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3112. }
  3113. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3114. {
  3115. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3116. {
  3117. RemoteDirectory.Delete(1, 1);
  3118. }
  3119. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3120. }
  3121. if (!ForceDirectories(ApiPath(Result)))
  3122. {
  3123. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3124. }
  3125. }
  3126. //---------------------------------------------------------------------------
  3127. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3128. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3129. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3130. {
  3131. DebugAssert(!IsLocalBrowserMode());
  3132. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3133. if (ForceText)
  3134. {
  3135. CopyParam.TransferMode = tmAscii;
  3136. }
  3137. TemporaryFileCopyParam(CopyParam);
  3138. if (AllFiles)
  3139. {
  3140. CopyParam.IncludeFileMask = TFileMasks();
  3141. }
  3142. if (TempDir.IsEmpty())
  3143. {
  3144. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3145. }
  3146. DebugAssert(!FAutoOperation);
  3147. FAutoOperation = AutoOperation;
  3148. Terminal->ExceptionOnFail = true;
  3149. try
  3150. {
  3151. try
  3152. {
  3153. // turn off confirmations, as for MDI editors we may possibly download
  3154. // the same file over
  3155. Terminal->CopyToLocal(
  3156. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3157. if (GetTargetNames)
  3158. {
  3159. for (int i = 0; i < FileList->Count; i++)
  3160. {
  3161. FileList->Strings[i] =
  3162. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3163. }
  3164. }
  3165. }
  3166. catch(...)
  3167. {
  3168. if (!RootTempDir.IsEmpty())
  3169. {
  3170. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3171. }
  3172. throw;
  3173. }
  3174. }
  3175. __finally
  3176. {
  3177. FAutoOperation = false;
  3178. Terminal->ExceptionOnFail = false;
  3179. }
  3180. }
  3181. //---------------------------------------------------------------------------
  3182. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3183. {
  3184. // Do not waste time checking for default editor list the next time,
  3185. // or testing if default editor is not notepad.
  3186. bool TryNextTime = false;
  3187. UnicodeString UsageState;
  3188. if (!WinConfiguration->EditorList->IsDefaultList())
  3189. {
  3190. UsageState = "H";
  3191. }
  3192. else
  3193. {
  3194. UnicodeString Executable;
  3195. UnicodeString ExecutableDescription;
  3196. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3197. {
  3198. UnicodeString Message =
  3199. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3200. unsigned int Answer =
  3201. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3202. if (Answer != qaOK)
  3203. {
  3204. UsageState = "R";
  3205. }
  3206. else
  3207. {
  3208. UsageState = "A";
  3209. TEditorData EditorData;
  3210. EditorData.Editor = edExternal;
  3211. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3212. EditorData.ExternalEditorOptionsAutodetect();
  3213. TEditorList EditorList;
  3214. EditorList = *WinConfiguration->EditorList;
  3215. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3216. WinConfiguration->EditorList = &EditorList;
  3217. }
  3218. }
  3219. }
  3220. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3221. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3222. }
  3223. //---------------------------------------------------------------------------
  3224. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3225. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3226. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3227. {
  3228. if (ExecuteFileBy == efDefaultEditor)
  3229. {
  3230. if (!WinConfiguration->OfferedEditorAutoConfig)
  3231. {
  3232. EditorAutoConfig();
  3233. }
  3234. const TEditorPreferences * Editor =
  3235. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3236. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3237. {
  3238. ExecuteFileBy = efInternalEditor;
  3239. ExternalEditor = NULL;
  3240. }
  3241. else if (Editor->Data->Editor == edOpen)
  3242. {
  3243. ExecuteFileBy = efShell;
  3244. ExternalEditor = NULL;
  3245. }
  3246. else
  3247. {
  3248. ExecuteFileBy = efExternalEditor;
  3249. ExternalEditor = Editor->Data;
  3250. }
  3251. }
  3252. }
  3253. //---------------------------------------------------------------------------
  3254. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3255. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3256. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3257. {
  3258. UnicodeString OriginalFileName;
  3259. UnicodeString LocalRootDirectory;
  3260. UnicodeString RemoteDirectory;
  3261. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3262. IsSideLocalBrowser(Side), MaskParams);
  3263. UnicodeString Counter;
  3264. UnicodeString LocalFileName;
  3265. bool Handled = false;
  3266. if (!IsSideLocalBrowser(Side))
  3267. {
  3268. // We need to trim VMS version here, so that we use name without version
  3269. // when uploading back to create a new version of the file
  3270. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3271. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3272. TObject * Token = NULL;
  3273. UnicodeString LocalDirectory;
  3274. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3275. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3276. LocalDirectory))
  3277. {
  3278. if (Token != NULL)
  3279. {
  3280. TForm * Form = dynamic_cast<TForm *>(Token);
  3281. if (Form->WindowState == wsMinimized)
  3282. {
  3283. ShowWindow(Form->Handle, SW_RESTORE);
  3284. }
  3285. else
  3286. {
  3287. Form->SetFocus();
  3288. }
  3289. Handled = true;
  3290. }
  3291. else
  3292. {
  3293. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3294. }
  3295. }
  3296. if (!Handled)
  3297. {
  3298. TStringList * FileList1 = new TStringList();
  3299. try
  3300. {
  3301. FileList1->AddObject(FullFileName, Object);
  3302. TemporarilyDownloadFiles(FileList1,
  3303. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3304. LocalRootDirectory, LocalDirectory, true, true, true);
  3305. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3306. }
  3307. __finally
  3308. {
  3309. delete FileList1;
  3310. }
  3311. switch (ExecuteFileBy)
  3312. {
  3313. case efShell:
  3314. Counter = "RemoteFilesExecuted";
  3315. break;
  3316. case efInternalEditor:
  3317. Counter = "RemoteFilesOpenedInInternalEditor";
  3318. break;
  3319. case efExternalEditor:
  3320. Counter = "RemoteFilesOpenedInExternalEditor";
  3321. break;
  3322. default:
  3323. DebugFail();
  3324. }
  3325. }
  3326. }
  3327. else
  3328. {
  3329. LocalFileName = FullFileName;
  3330. OriginalFileName = ExtractFileName(FullFileName);
  3331. switch (ExecuteFileBy)
  3332. {
  3333. case efShell:
  3334. Counter = "LocalFilesExecuted";
  3335. break;
  3336. case efInternalEditor:
  3337. Counter = "LocalFilesOpenedInInternalEditor";
  3338. break;
  3339. case efExternalEditor:
  3340. Counter = "LocalFilesOpenedInExternalEditor";
  3341. break;
  3342. default:
  3343. DebugFail();
  3344. }
  3345. }
  3346. if (!Handled)
  3347. {
  3348. Configuration->Usage->Inc(Counter);
  3349. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3350. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3351. }
  3352. }
  3353. //---------------------------------------------------------------------------
  3354. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3355. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3356. bool AllSelected, bool OnFocused)
  3357. {
  3358. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3359. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3360. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3361. Side = GetSide(Side);
  3362. TCustomDirView * DView = DirView(Side);
  3363. TStrings * FileList =
  3364. AllSelected ?
  3365. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3366. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3367. try
  3368. {
  3369. DebugAssert(AllSelected || (FileList->Count == 1));
  3370. for (int i = 0; i < FileList->Count; i++)
  3371. {
  3372. UnicodeString ListFileName = FileList->Strings[i];
  3373. UnicodeString FileNameOnly =
  3374. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3375. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3376. if (!DView->ItemIsDirectory(Item))
  3377. {
  3378. UnicodeString FullFileName;
  3379. if (!IsSideLocalBrowser(Side))
  3380. {
  3381. FullFileName = DirView(Side)->Path + ListFileName;
  3382. }
  3383. else
  3384. {
  3385. FullFileName = ListFileName;
  3386. }
  3387. TFileMasks::TParams MaskParams;
  3388. MaskParams.Size = DView->ItemFileSize(Item);
  3389. TDateTimePrecision Precision;
  3390. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3391. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3392. FileList->Objects[i], MaskParams);
  3393. }
  3394. }
  3395. }
  3396. __finally
  3397. {
  3398. delete FileList;
  3399. }
  3400. }
  3401. //---------------------------------------------------------------------------
  3402. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3403. {
  3404. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3405. CopyParam.FileNameCase = ncNoChange;
  3406. CopyParam.PreserveRights = false;
  3407. CopyParam.PreserveReadOnly = false;
  3408. CopyParam.ReplaceInvalidChars = true;
  3409. CopyParam.IncludeFileMask = TFileMasks();
  3410. CopyParam.NewerOnly = false;
  3411. CopyParam.FileMask = L"";
  3412. }
  3413. //---------------------------------------------------------------------------
  3414. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3415. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3416. {
  3417. TTerminalManager * Manager = TTerminalManager::Instance();
  3418. if (!IsActiveTerminal(Data->Terminal))
  3419. {
  3420. if (!NonVisualDataModule->Busy)
  3421. {
  3422. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3423. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3424. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3425. if (Data->Terminal == NULL)
  3426. {
  3427. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3428. if (SameSiteTerminal != NULL)
  3429. {
  3430. UnicodeString Message =
  3431. FMTLOAD(EDIT_SESSION_REATTACH,
  3432. (FileNameOnly, Data->SessionName, FileNameOnly));
  3433. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3434. {
  3435. Data->Terminal = Terminal;
  3436. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3437. Data->SessionName = Terminal->SessionData->SessionName;
  3438. // We might also overwrite session data
  3439. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3440. }
  3441. else
  3442. {
  3443. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3444. Abort();
  3445. }
  3446. }
  3447. }
  3448. // foreground session should reconnect itself
  3449. else if (Terminal != Data->Terminal)
  3450. {
  3451. UnicodeString Message =
  3452. MainInstructions(
  3453. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3454. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3455. {
  3456. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3457. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3458. }
  3459. else
  3460. {
  3461. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3462. Abort();
  3463. }
  3464. }
  3465. }
  3466. if (!IsActiveTerminal(Data->Terminal))
  3467. {
  3468. Configuration->Usage->Inc(L"EditInactiveSession");
  3469. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3470. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3471. (ExtractFileName(FileName), Data->SessionName)));
  3472. }
  3473. }
  3474. TStrings * FileList = new TStringList();
  3475. try
  3476. {
  3477. FileList->Add(FileName);
  3478. // consider using the same settings (preset) as when the file was downloaded
  3479. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3480. TemporaryFileCopyParam(CopyParam);
  3481. if (Data->ForceText)
  3482. {
  3483. CopyParam.TransferMode = tmAscii;
  3484. }
  3485. // so i do not need to worry if masking algorithm works in all cases
  3486. // ("" means "copy file name", no masking is actually done)
  3487. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3488. {
  3489. CopyParam.FileMask = L"";
  3490. }
  3491. else
  3492. {
  3493. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3494. }
  3495. DebugAssert(Data->Queue != NULL);
  3496. int Params = cpNoConfirmation | cpTemporary;
  3497. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3498. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3499. QueueItem->CompleteEvent = UploadCompleteEvent;
  3500. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3501. }
  3502. __finally
  3503. {
  3504. delete FileList;
  3505. }
  3506. }
  3507. //---------------------------------------------------------------------------
  3508. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3509. const UnicodeString FileName, const TEditedFileData * Data)
  3510. {
  3511. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3512. DebugAssert(!NonVisualDataModule->Busy);
  3513. if (!IsActiveTerminal(Data->Terminal))
  3514. {
  3515. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3516. (ExtractFileName(FileName), Data->SessionName)));
  3517. }
  3518. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3519. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3520. NonVisualDataModule->StartBusy();
  3521. try
  3522. {
  3523. std::unique_ptr<TRemoteFile> File;
  3524. UnicodeString RemoteFileName =
  3525. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3526. FTerminal->ExceptionOnFail = true;
  3527. try
  3528. {
  3529. TRemoteFile * AFile = NULL;
  3530. FTerminal->ReadFile(RemoteFileName, AFile);
  3531. File.reset(AFile);
  3532. if (!File->HaveFullFileName)
  3533. {
  3534. File->FullFileName = RemoteFileName;
  3535. }
  3536. }
  3537. __finally
  3538. {
  3539. FTerminal->ExceptionOnFail = false;
  3540. }
  3541. std::unique_ptr<TStrings> FileList(new TStringList());
  3542. FileList->AddObject(RemoteFileName, File.get());
  3543. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3544. UnicodeString TempDir = ExtractFilePath(FileName);
  3545. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3546. TempDir, true, true, true);
  3547. // sanity check, the target file name should be still the same
  3548. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3549. }
  3550. __finally
  3551. {
  3552. NonVisualDataModule->EndBusy();
  3553. // it actually may not exist anymore...
  3554. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3555. }
  3556. }
  3557. //---------------------------------------------------------------------------
  3558. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3559. const TEditedFileData * Data, bool & KeepOpen)
  3560. {
  3561. // Command is set for external editors only (not for "shell" open).
  3562. if (!Data->Command.IsEmpty())
  3563. {
  3564. bool AnyFound = false;
  3565. bool AnyMDI = false;
  3566. bool AnyNonMDI = false;
  3567. bool AnyDetect = false;
  3568. TEditorList * EditorList = new TEditorList();
  3569. try
  3570. {
  3571. *EditorList = *WinConfiguration->EditorList;
  3572. for (int i = 0; i < EditorList->Count; i++)
  3573. {
  3574. const TEditorPreferences * Editor = EditorList->Editors[i];
  3575. if ((Editor->Data->Editor == edExternal) &&
  3576. (Editor->Data->ExternalEditor == Data->Command))
  3577. {
  3578. AnyFound = true;
  3579. if (Editor->Data->SDIExternalEditor)
  3580. {
  3581. AnyNonMDI = true;
  3582. if (Editor->Data->DetectMDIExternalEditor)
  3583. {
  3584. AnyDetect = true;
  3585. }
  3586. }
  3587. else
  3588. {
  3589. AnyMDI = true;
  3590. }
  3591. }
  3592. }
  3593. bool EnableMDI = false;
  3594. bool DisableDetect = false;
  3595. if (AnyMDI)
  3596. {
  3597. KeepOpen = true;
  3598. if (AnyNonMDI)
  3599. {
  3600. // there is at least one instance of the editor with MDI support enabled,
  3601. // and one with disabled, enable it for all instances
  3602. EnableMDI = true;
  3603. }
  3604. }
  3605. else if (AnyFound && !AnyDetect)
  3606. {
  3607. // at least once instance found but all have MDI autodetection disabled
  3608. // => close the file (default action)
  3609. }
  3610. else
  3611. {
  3612. // no instance of the editor has MDI support enabled
  3613. TMessageParams Params;
  3614. if (AnyFound)
  3615. {
  3616. // there is at least one instance of the editor
  3617. Params.Params |= mpNeverAskAgainCheck;
  3618. }
  3619. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3620. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3621. switch (Answer)
  3622. {
  3623. case qaNeverAskAgain:
  3624. DisableDetect = true;
  3625. break;
  3626. case qaNo:
  3627. EnableMDI = true;
  3628. KeepOpen = true;
  3629. break;
  3630. }
  3631. }
  3632. if (AnyFound && (EnableMDI || DisableDetect))
  3633. {
  3634. bool Changed = false;
  3635. for (int i = 0; i < EditorList->Count; i++)
  3636. {
  3637. const TEditorPreferences * Editor = EditorList->Editors[i];
  3638. if ((Editor->Data->Editor == edExternal) &&
  3639. (Editor->Data->ExternalEditor == Data->Command) &&
  3640. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3641. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3642. {
  3643. Changed = true;
  3644. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3645. if (EnableMDI)
  3646. {
  3647. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3648. }
  3649. if (DisableDetect)
  3650. {
  3651. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3652. }
  3653. EditorList->Change(i, UpdatedEditor);
  3654. }
  3655. }
  3656. if (Changed)
  3657. {
  3658. WinConfiguration->EditorList = EditorList;
  3659. }
  3660. }
  3661. }
  3662. __finally
  3663. {
  3664. delete EditorList;
  3665. }
  3666. }
  3667. else
  3668. {
  3669. // "open" case
  3670. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3671. qaOK, HELP_APP_EARLY_CLOSED);
  3672. }
  3673. }
  3674. //---------------------------------------------------------------------------
  3675. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3676. {
  3677. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3678. }
  3679. //---------------------------------------------------------------------------
  3680. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3681. {
  3682. SideEnter(osRemote);
  3683. }
  3684. //---------------------------------------------------------------------------
  3685. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3686. {
  3687. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3688. SideEnter(osRemote);
  3689. }
  3690. //---------------------------------------------------------------------------
  3691. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3692. {
  3693. FCurrentSide = Side;
  3694. if (Visible)
  3695. {
  3696. UpdateControls();
  3697. }
  3698. }
  3699. //---------------------------------------------------------------------------
  3700. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3701. TStrings * FileList, bool Alternative)
  3702. {
  3703. TCustomDirView * DView = DirView(Side);
  3704. DView->SaveSelection();
  3705. DView->SaveSelectedNames();
  3706. DebugAssert(!FAlternativeDelete);
  3707. FAlternativeDelete = Alternative;
  3708. try
  3709. {
  3710. if (!IsSideLocalBrowser(Side))
  3711. {
  3712. DebugAssert(Terminal != NULL);
  3713. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3714. }
  3715. else
  3716. {
  3717. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  3718. FProgressSide = FCurrentSide;
  3719. try
  3720. {
  3721. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3722. }
  3723. __finally
  3724. {
  3725. ReloadLocalDirectory();
  3726. }
  3727. }
  3728. FAlternativeDelete = false;
  3729. }
  3730. catch(...)
  3731. {
  3732. FAlternativeDelete = false;
  3733. DView->DiscardSavedSelection();
  3734. throw;
  3735. }
  3736. DView->RestoreSelection();
  3737. }
  3738. //---------------------------------------------------------------------------
  3739. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3740. {
  3741. DebugAssert(Terminal);
  3742. DebugAssert(!IsLocalBrowserMode());
  3743. RemoteDirView->SaveSelection();
  3744. RemoteDirView->SaveSelectedNames();
  3745. try
  3746. {
  3747. if (Lock)
  3748. {
  3749. Terminal->LockFiles(FileList);
  3750. }
  3751. else
  3752. {
  3753. Terminal->UnlockFiles(FileList);
  3754. }
  3755. }
  3756. catch(...)
  3757. {
  3758. RemoteDirView->DiscardSavedSelection();
  3759. throw;
  3760. }
  3761. RemoteDirView->RestoreSelection();
  3762. }
  3763. //---------------------------------------------------------------------------
  3764. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3765. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3766. bool NoConfirmation, bool Move)
  3767. {
  3768. DebugAssert(Terminal != NULL);
  3769. DebugAssert(!IsLocalBrowserMode());
  3770. // update Terminal->StateData->RemoteDirectory
  3771. UpdateTerminal(Terminal);
  3772. if (Session == NULL)
  3773. {
  3774. Session = TTerminalManager::Instance()->ActiveTerminal;
  3775. }
  3776. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3777. {
  3778. if (RemoteDriveView->DropTarget != NULL)
  3779. {
  3780. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3781. }
  3782. else if (RemoteDirView->DropTarget != NULL)
  3783. {
  3784. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3785. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3786. }
  3787. else
  3788. {
  3789. Target = RemoteDirView->Path;
  3790. }
  3791. }
  3792. else
  3793. {
  3794. Target = Session->StateData->RemoteDirectory;
  3795. }
  3796. Target = UnixIncludeTrailingBackslash(Target);
  3797. if (FileList->Count == 1)
  3798. {
  3799. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3800. }
  3801. else
  3802. {
  3803. FileMask = AnyMask;
  3804. }
  3805. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3806. bool Result = true;
  3807. if (!NoConfirmation)
  3808. {
  3809. bool Multi = (FileList->Count > 1);
  3810. if (Move)
  3811. {
  3812. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3813. }
  3814. else
  3815. {
  3816. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3817. TStrings * Directories = new TStringList;
  3818. try
  3819. {
  3820. for (int Index = 0; Index < Sessions->Count; Index++)
  3821. {
  3822. TManagedTerminal * Terminal =
  3823. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3824. Directories->Add(Terminal->StateData->RemoteDirectory);
  3825. }
  3826. TDirectRemoteCopy AllowDirectCopy;
  3827. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3828. {
  3829. DebugAssert(DirectCopy);
  3830. AllowDirectCopy = drcAllow;
  3831. }
  3832. else if (FTerminal->IsCapable[fcSecondaryShell])
  3833. {
  3834. DebugAssert(DirectCopy);
  3835. AllowDirectCopy = drcConfirmCommandSession;
  3836. }
  3837. else
  3838. {
  3839. DebugAssert(!DirectCopy);
  3840. AllowDirectCopy = drcDisallow;
  3841. }
  3842. void * ASession = Session;
  3843. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3844. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3845. Session = static_cast<TManagedTerminal *>(ASession);
  3846. }
  3847. __finally
  3848. {
  3849. delete Directories;
  3850. }
  3851. }
  3852. }
  3853. return Result;
  3854. }
  3855. //---------------------------------------------------------------------------
  3856. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3857. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3858. {
  3859. DebugAssert(!IsLocalBrowserMode());
  3860. bool DirectCopy;
  3861. UnicodeString Target, FileMask;
  3862. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3863. if (Result)
  3864. {
  3865. if (!Move && !DirectCopy)
  3866. {
  3867. Configuration->Usage->Inc("RemoteCopyTemp");
  3868. UnicodeString RootTempDir;
  3869. UnicodeString TempDir;
  3870. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3871. TStrings * TemporaryFilesList = new TStringList();
  3872. try
  3873. {
  3874. TMakeLocalFileListParams MakeFileListParam;
  3875. MakeFileListParam.FileList = TemporaryFilesList;
  3876. MakeFileListParam.FileTimes = NULL;
  3877. MakeFileListParam.IncludeDirs = true;
  3878. MakeFileListParam.Recursive = false;
  3879. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3880. TTerminalManager::Instance()->ActiveTerminal = Session;
  3881. if (TemporaryFilesList->Count > 0)
  3882. {
  3883. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3884. CopyParam.FileMask = FileMask;
  3885. DebugAssert(!FAutoOperation);
  3886. FAutoOperation = true;
  3887. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3888. }
  3889. }
  3890. __finally
  3891. {
  3892. delete TemporaryFilesList;
  3893. FAutoOperation = false;
  3894. if (!RootTempDir.IsEmpty())
  3895. {
  3896. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3897. }
  3898. }
  3899. }
  3900. else
  3901. {
  3902. RemoteDirView->SaveSelection();
  3903. RemoteDirView->SaveSelectedNames();
  3904. try
  3905. {
  3906. if (Move)
  3907. {
  3908. Configuration->Usage->Inc("RemoteMove");
  3909. Terminal->MoveFiles(FileList, Target, FileMask);
  3910. }
  3911. else
  3912. {
  3913. Configuration->Usage->Inc("RemoteCopyDirect");
  3914. DebugAssert(DirectCopy);
  3915. DebugAssert(Session == FTerminal);
  3916. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3917. FTerminal->CommandSessionOpened ||
  3918. CommandSessionFallback())
  3919. {
  3920. Terminal->CopyFiles(FileList, Target, FileMask);
  3921. }
  3922. }
  3923. }
  3924. catch(...)
  3925. {
  3926. RemoteDirView->DiscardSavedSelection();
  3927. throw;
  3928. }
  3929. RemoteDirView->RestoreSelection();
  3930. }
  3931. }
  3932. return Result;
  3933. }
  3934. //---------------------------------------------------------------------------
  3935. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3936. const UnicodeString & Path, TRemoteProperties & Properties)
  3937. {
  3938. DebugAssert(!IsLocalBrowserMode());
  3939. Properties.Valid = Properties.Valid << vpEncrypt;
  3940. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3941. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3942. }
  3943. //---------------------------------------------------------------------------
  3944. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3945. {
  3946. Side = GetSide(Side);
  3947. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3948. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3949. UnicodeString Name = LoadStr(NEW_FOLDER);
  3950. int AllowedChanges =
  3951. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3952. bool SaveSettings = false;
  3953. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3954. {
  3955. TWindowLock Lock(this);
  3956. if (!IsSideLocalBrowser(Side))
  3957. {
  3958. if (SaveSettings)
  3959. {
  3960. GUIConfiguration->NewDirectoryProperties = Properties;
  3961. }
  3962. CreateRemoteDirectory(Name, Properties);
  3963. }
  3964. else
  3965. {
  3966. DirView(Side)->CreateDirectory(Name);
  3967. }
  3968. }
  3969. }
  3970. //---------------------------------------------------------------------------
  3971. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3972. {
  3973. TWindowLock Lock(this);
  3974. DirView(Side)->ExecuteHomeDirectory();
  3975. }
  3976. //---------------------------------------------------------------------------
  3977. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3978. {
  3979. DoOpenDirectoryDialog(odBrowse, Side);
  3980. }
  3981. //---------------------------------------------------------------------------
  3982. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3983. {
  3984. TOperationSide BookmarkSide = IsLocalBrowserMode() ? osLocal : Side;
  3985. UnicodeString Path = Bookmark->GetSideDirectory(BookmarkSide);
  3986. bool Result = !Path.IsEmpty();
  3987. if (Result)
  3988. {
  3989. // While we might get here when the session is closed (from location profiles),
  3990. // it's not a problem as the Path setter is noop then
  3991. DirView(Side)->Path = Path;
  3992. }
  3993. return Result;
  3994. }
  3995. //---------------------------------------------------------------------------
  3996. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3997. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3998. bool & Close)
  3999. {
  4000. // terminal can be already closed (e.g. dropped connection)
  4001. if (Terminal != NULL)
  4002. {
  4003. try
  4004. {
  4005. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  4006. }
  4007. catch(...)
  4008. {
  4009. if (!Terminal->Active)
  4010. {
  4011. Close = true;
  4012. }
  4013. throw;
  4014. }
  4015. }
  4016. }
  4017. //---------------------------------------------------------------------------
  4018. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4019. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4020. bool & Close)
  4021. {
  4022. // terminal can be already closed (e.g. dropped connection)
  4023. if (Terminal != NULL)
  4024. {
  4025. Configuration->Usage->Inc(L"ChecksumCalculated");
  4026. try
  4027. {
  4028. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4029. }
  4030. catch(...)
  4031. {
  4032. if (!Terminal->Active)
  4033. {
  4034. Close = true;
  4035. }
  4036. throw;
  4037. }
  4038. }
  4039. }
  4040. //---------------------------------------------------------------------------
  4041. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4042. {
  4043. bool Result;
  4044. if (!IsSideLocalBrowser(Side))
  4045. {
  4046. TRemoteTokenList * GroupList = NULL;
  4047. TRemoteTokenList * UserList = NULL;
  4048. try
  4049. {
  4050. TRemoteProperties CurrentProperties;
  4051. if (Terminal->LoadFilesProperties(FileList))
  4052. {
  4053. RemoteDirView->Invalidate();
  4054. }
  4055. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4056. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4057. if (CapableGroupChanging || CapableOwnerChanging)
  4058. {
  4059. if (CapableGroupChanging)
  4060. {
  4061. GroupList = Terminal->Groups->Duplicate();
  4062. }
  4063. if (CapableOwnerChanging)
  4064. {
  4065. UserList = Terminal->Users->Duplicate();
  4066. }
  4067. TRemoteDirectory * Files = Terminal->Files;
  4068. int Count = Files->Count;
  4069. if (Count > 100)
  4070. {
  4071. Count = 100;
  4072. }
  4073. for (int Index = 0; Index < Count; Index++)
  4074. {
  4075. TRemoteFile * File = Files->Files[Index];
  4076. if (CapableGroupChanging)
  4077. {
  4078. GroupList->AddUnique(File->Group);
  4079. }
  4080. if (CapableOwnerChanging)
  4081. {
  4082. UserList->AddUnique(File->Owner);
  4083. }
  4084. }
  4085. // if we haven't collected tokens for all files in current directory,
  4086. // make sure we collect them at least for all selected files.
  4087. // (note that so far the files in FileList has to be from current direcotry)
  4088. if (Count < Files->Count)
  4089. {
  4090. for (int Index = 0; Index < FileList->Count; Index++)
  4091. {
  4092. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4093. if (CapableGroupChanging)
  4094. {
  4095. GroupList->AddUnique(File->Group);
  4096. }
  4097. if (CapableOwnerChanging)
  4098. {
  4099. UserList->AddUnique(File->Owner);
  4100. }
  4101. }
  4102. }
  4103. }
  4104. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4105. int Flags = 0;
  4106. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4107. if (CapableOwnerChanging) Flags |= cpOwner;
  4108. if (CapableGroupChanging) Flags |= cpGroup;
  4109. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4110. if (Terminal->IsCapable[fcCalculatingChecksum])
  4111. {
  4112. CalculateChecksumEvent = CalculateChecksum;
  4113. }
  4114. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4115. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4116. TRemoteProperties NewProperties = CurrentProperties;
  4117. Result =
  4118. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4119. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4120. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4121. CalculateSize, CalculateChecksumEvent);
  4122. if (Result)
  4123. {
  4124. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4125. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4126. }
  4127. }
  4128. __finally
  4129. {
  4130. delete GroupList;
  4131. delete UserList;
  4132. }
  4133. }
  4134. else
  4135. {
  4136. DirView(Side)->DisplayPropertiesMenu();
  4137. Result = true;
  4138. }
  4139. return Result;
  4140. }
  4141. //---------------------------------------------------------------------------
  4142. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4143. {
  4144. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4145. {
  4146. FIgnoreNextDialogChar = Key;
  4147. }
  4148. Key = 0;
  4149. }
  4150. //---------------------------------------------------------------------------
  4151. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4152. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4153. {
  4154. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4155. if (Command != NULL)
  4156. {
  4157. KeyProcessed(Key, Shift);
  4158. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4159. {
  4160. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4161. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4162. false, false, const_cast<TCustomCommandType *>(Command));
  4163. }
  4164. }
  4165. }
  4166. //---------------------------------------------------------------------------
  4167. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4168. {
  4169. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4170. {
  4171. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4172. }
  4173. if (!DirView(osCurrent)->IsEditing())
  4174. {
  4175. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4176. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4177. {
  4178. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4179. // But so far it's not a problem, as it does what we want.
  4180. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4181. if (((Action->ShortCut == KeyShortCut) ||
  4182. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4183. AllowedAction(Action, aaShortCut))
  4184. {
  4185. // Has to be called before the action as the dialog char is already in queue.
  4186. // So when the action consumes message queue, we already need to have the
  4187. // FIgnoreNextDialogChar set
  4188. KeyProcessed(Key, Shift);
  4189. // Reset reference to previous component (when menu/toolbar was clicked).
  4190. // Needed to detect that action was invoked by keyboard shortcut
  4191. // in TNonVisualDataModule::ExplorerActionsExecute
  4192. Action->ActionComponent = NULL;
  4193. Action->Execute();
  4194. return;
  4195. }
  4196. }
  4197. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4198. {
  4199. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4200. {
  4201. KeyProcessed(Key, Shift);
  4202. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4203. return;
  4204. }
  4205. }
  4206. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4207. {
  4208. KeyProcessed(Key, Shift);
  4209. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4210. }
  4211. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4212. if (IsCustomShortCut(CustomShortCut))
  4213. {
  4214. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4215. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4216. if (WinConfiguration->SharedBookmarks != NULL)
  4217. {
  4218. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4219. if ((Bookmark != NULL) &&
  4220. OpenBookmark(FCurrentSide, Bookmark))
  4221. {
  4222. KeyProcessed(Key, Shift);
  4223. }
  4224. }
  4225. }
  4226. }
  4227. TForm::KeyDown(Key, Shift);
  4228. }
  4229. //---------------------------------------------------------------------------
  4230. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4231. {
  4232. DebugAssert(Terminal != NULL);
  4233. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4234. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4235. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4236. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4237. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4238. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4239. // expanded from ?: to avoid memory leaks
  4240. if (SecurityEnabled)
  4241. {
  4242. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4243. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4244. }
  4245. else
  4246. {
  4247. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4248. }
  4249. if (FileSystemInfo.ProtocolName.IsEmpty())
  4250. {
  4251. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4252. }
  4253. else
  4254. {
  4255. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4256. }
  4257. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4258. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4259. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4260. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4261. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4262. UnicodeString CompressionStr = CSCompressionStr;
  4263. if (CSCompressionStr != SCCompressionStr)
  4264. {
  4265. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4266. }
  4267. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4268. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4269. UpdateStatusBar();
  4270. }
  4271. //---------------------------------------------------------------------------
  4272. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4273. {
  4274. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4275. DebugAssert(SessionStatusBar != NULL);
  4276. if (!HasActiveTerminal() || (Terminal->Status < ssOpened))
  4277. {
  4278. // note: (Terminal->Status < sshReady) currently never happens here,
  4279. // so STATUS_CONNECTING is never used
  4280. SessionStatusBar->SimplePanel = true;
  4281. SessionStatusBar->SimpleText = LoadStr(
  4282. !HasActiveTerminal() ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4283. }
  4284. else
  4285. {
  4286. DebugAssert(Terminal);
  4287. SessionStatusBar->SimplePanel = false;
  4288. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4289. if (!FNote.IsEmpty())
  4290. {
  4291. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4292. }
  4293. else
  4294. {
  4295. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4296. }
  4297. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4298. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4299. }
  4300. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4301. }
  4302. //---------------------------------------------------------------------------
  4303. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4304. {
  4305. Panel->Caption = L"";
  4306. }
  4307. //---------------------------------------------------------------------------
  4308. void __fastcall TCustomScpExplorerForm::Idle()
  4309. {
  4310. if (FShowing || FStandaloneEditing)
  4311. {
  4312. FEditorManager->Check();
  4313. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4314. // that needs to know if queue view is visible (and it may be closed after queue update)
  4315. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4316. }
  4317. if (FShowing)
  4318. {
  4319. if (!NonVisualDataModule->Busy &&
  4320. // Menu is opened or drag&drop is going on
  4321. (Mouse->Capture == NULL))
  4322. {
  4323. if (FRefreshRemoteDirectory)
  4324. {
  4325. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4326. {
  4327. Terminal->RefreshDirectory();
  4328. }
  4329. FRefreshRemoteDirectory = false;
  4330. }
  4331. if (FRefreshLocalDirectory)
  4332. {
  4333. ReloadLocalDirectory();
  4334. FRefreshLocalDirectory = false;
  4335. }
  4336. if (WinConfiguration->RefreshRemotePanel)
  4337. {
  4338. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4339. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4340. {
  4341. RemoteDirView->ReloadDirectory();
  4342. }
  4343. }
  4344. if (!FStarted)
  4345. {
  4346. FStarted = true;
  4347. InterfaceStarted();
  4348. }
  4349. }
  4350. }
  4351. if (FShowing || FStandaloneEditing)
  4352. {
  4353. if (FQueueStatusInvalidated)
  4354. {
  4355. UpdateQueueStatus(false);
  4356. }
  4357. RefreshQueueItems();
  4358. }
  4359. if (FShowing)
  4360. {
  4361. UpdateStatusBar();
  4362. }
  4363. FIgnoreNextDialogChar = 0;
  4364. }
  4365. //---------------------------------------------------------------------------
  4366. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4367. {
  4368. try
  4369. {
  4370. FUserActionTimer->Enabled = false;
  4371. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4372. {
  4373. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4374. {
  4375. FPendingQueueActionItem->ProcessUserAction();
  4376. }
  4377. }
  4378. }
  4379. __finally
  4380. {
  4381. FPendingQueueActionItem = NULL;
  4382. }
  4383. }
  4384. //---------------------------------------------------------------------------
  4385. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4386. {
  4387. if (WinConfiguration->MinimizeToTray)
  4388. {
  4389. UpdateTrayIcon();
  4390. FTrayIcon->Visible = true;
  4391. if (Visible)
  4392. {
  4393. ShowWindow(Handle, SW_HIDE);
  4394. }
  4395. }
  4396. }
  4397. //---------------------------------------------------------------------------
  4398. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4399. {
  4400. // WORKAROUND
  4401. // When restoring maximized window from minimization,
  4402. // rarely some controls do not align properly.
  4403. // Two instances seen (both for Commander):
  4404. // - When restoring, window is temporarily narrower (not maximized),
  4405. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4406. // Once maximized already, top dock shinks back, but the session PageControl,
  4407. // do not align up, leaving space between TopDock and PageControl.
  4408. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4409. for (int Index = 0; Index < ControlCount; Index++)
  4410. {
  4411. RealignControl(Controls[Index]);
  4412. }
  4413. if (FTrayIcon->Visible)
  4414. {
  4415. FTrayIcon->Visible = false;
  4416. if (Visible)
  4417. {
  4418. ShowWindow(Handle, SW_SHOW);
  4419. }
  4420. }
  4421. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4422. {
  4423. FNeedSession = false;
  4424. NonVisualDataModule->StartBusy();
  4425. try
  4426. {
  4427. NeedSession(true);
  4428. }
  4429. __finally
  4430. {
  4431. NonVisualDataModule->EndBusy();
  4432. }
  4433. }
  4434. }
  4435. //---------------------------------------------------------------------------
  4436. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4437. {
  4438. FTrayIcon->Hint = GetMainForm()->Caption;
  4439. }
  4440. //---------------------------------------------------------------------------
  4441. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4442. {
  4443. UpdateTrayIcon();
  4444. }
  4445. //---------------------------------------------------------------------------
  4446. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4447. {
  4448. // workaround
  4449. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4450. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4451. // But WM_ACTIVATEAPP message can be received even when
  4452. // the main window is minimized to the tray and internal editor window is focused
  4453. // (after another application was previously active)
  4454. if (::IsIconic(Handle))
  4455. {
  4456. if (!IsAppIconic())
  4457. {
  4458. SetAppIconic(true);
  4459. }
  4460. }
  4461. ::ApplicationRestore();
  4462. Application->BringToFront();
  4463. }
  4464. //---------------------------------------------------------------------------
  4465. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4466. {
  4467. RestoreApp();
  4468. }
  4469. //---------------------------------------------------------------------------
  4470. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4471. {
  4472. if (OpenInNewWindow())
  4473. {
  4474. // todo: Pass FromSite
  4475. ExecuteNewInstance(SessionUrl);
  4476. }
  4477. else
  4478. {
  4479. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4480. }
  4481. }
  4482. //---------------------------------------------------------------------------
  4483. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4484. {
  4485. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4486. StoredSessions->NewSession(SessionName, SessionData);
  4487. // modified only, explicit
  4488. StoredSessions->Save(false, true);
  4489. // encode session name because of slashes in hierarchical sessions
  4490. return EncodeUrlString(SessionName);
  4491. }
  4492. //---------------------------------------------------------------------------
  4493. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4494. {
  4495. // current working directories become defaults here, what is not right
  4496. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4497. return SaveHiddenDuplicateSession(SessionData.get());
  4498. }
  4499. //---------------------------------------------------------------------------
  4500. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4501. {
  4502. if (OpenInNewWindow())
  4503. {
  4504. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4505. }
  4506. else
  4507. {
  4508. // current working directories become defaults here, what is not right
  4509. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4510. TTerminalManager * Manager = TTerminalManager::Instance();
  4511. TManagedTerminal * Terminal = Manager->NewManagedTerminal(SessionData.get());
  4512. Manager->ActiveTerminal = Terminal;
  4513. }
  4514. }
  4515. //---------------------------------------------------------------------------
  4516. void __fastcall TCustomScpExplorerForm::RenameSession()
  4517. {
  4518. UnicodeString Name = Terminal->SessionData->SessionName;
  4519. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4520. {
  4521. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4522. TSessionData::ValidateName(Name);
  4523. // This is inconsistent with how color (for example) is handled.
  4524. Terminal->SessionData->Name = Name;
  4525. UpdateControls();
  4526. // Add/Remove distinguishing paths from sessions of the same name.
  4527. DoTerminalListChanged();
  4528. }
  4529. }
  4530. //---------------------------------------------------------------------------
  4531. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4532. {
  4533. DebugAssert(Queue != NULL);
  4534. bool Result = Queue->IsEmpty;
  4535. if (!Result)
  4536. {
  4537. SetFocus();
  4538. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4539. }
  4540. return Result;
  4541. }
  4542. //---------------------------------------------------------------------------
  4543. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4544. {
  4545. return CanCloseQueue(FQueue);
  4546. }
  4547. //---------------------------------------------------------------------------
  4548. void __fastcall TCustomScpExplorerForm::CloseSession()
  4549. {
  4550. if (CanCloseQueue())
  4551. {
  4552. TTerminalManager::Instance()->FreeActiveTerminal();
  4553. }
  4554. }
  4555. //---------------------------------------------------------------------------
  4556. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4557. {
  4558. if (CanCloseQueue())
  4559. {
  4560. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4561. }
  4562. }
  4563. //---------------------------------------------------------------------------
  4564. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4565. {
  4566. DetachTerminal(Terminal);
  4567. RemoteDirView->Terminal = Terminal;
  4568. UpdateRemotePathComboBox(false);
  4569. UpdateControls();
  4570. }
  4571. //---------------------------------------------------------------------------
  4572. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4573. {
  4574. if (DebugAlwaysTrue(!Terminal->Active))
  4575. {
  4576. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4577. }
  4578. }
  4579. //---------------------------------------------------------------------------
  4580. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4581. {
  4582. if (OpenInNewWindow())
  4583. {
  4584. // encode session name because of slashes in hierarchical sessions
  4585. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4586. }
  4587. else
  4588. {
  4589. TTerminalManager * Manager = TTerminalManager::Instance();
  4590. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4591. Manager->ActiveTerminal = Terminal;
  4592. }
  4593. }
  4594. //---------------------------------------------------------------------------
  4595. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4596. {
  4597. TTerminalManager * Manager = TTerminalManager::Instance();
  4598. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4599. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4600. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4601. // FirstTerminal can be null, if some of the
  4602. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4603. {
  4604. FirstTerminal->Disconnected = true;
  4605. FirstTerminal->DisconnectedTemporarily = true;
  4606. }
  4607. Manager->ActiveTerminal = FirstTerminal;
  4608. }
  4609. //---------------------------------------------------------------------------
  4610. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4611. {
  4612. if (OpenInNewWindow())
  4613. {
  4614. ExecuteNewInstance(Name);
  4615. }
  4616. else
  4617. {
  4618. DoOpenFolderOrWorkspace(Name, true);
  4619. }
  4620. }
  4621. //---------------------------------------------------------------------------
  4622. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4623. bool &CanClose)
  4624. {
  4625. // See the comment in CloseApp()
  4626. if (NonVisualDataModule->Busy)
  4627. {
  4628. CanClose = false;
  4629. }
  4630. else if (Terminal != NULL)
  4631. {
  4632. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4633. {
  4634. unsigned int Result;
  4635. TMessageParams Params(mpNeverAskAgainCheck);
  4636. UnicodeString Message;
  4637. int Answers = qaOK | qaCancel;
  4638. if (TTerminalManager::Instance()->Count > 1)
  4639. {
  4640. if (!WinConfiguration->AutoSaveWorkspace)
  4641. {
  4642. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4643. }
  4644. else
  4645. {
  4646. Message = LoadStr(CLOSE_SESSIONS);
  4647. }
  4648. }
  4649. else
  4650. {
  4651. if (!WinConfiguration->AutoSaveWorkspace)
  4652. {
  4653. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4654. }
  4655. else
  4656. {
  4657. Message = LoadStr(CLOSE_SESSION);
  4658. }
  4659. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4660. }
  4661. UnicodeString Note;
  4662. if (WinConfiguration->AutoSaveWorkspace)
  4663. {
  4664. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4665. }
  4666. else
  4667. {
  4668. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4669. Answers = qaYes | qaNo | qaCancel;
  4670. }
  4671. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4672. SetFocus();
  4673. Result = MessageDialog(Message, qtConfirmation,
  4674. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4675. if (Result == qaNeverAskAgain)
  4676. {
  4677. WinConfiguration->ConfirmClosingSession = false;
  4678. }
  4679. if (Result == qaNo)
  4680. {
  4681. CanClose = SaveWorkspace(true);
  4682. // note that the workspace will be saved redundatly again from FormClose
  4683. }
  4684. else
  4685. {
  4686. CanClose =
  4687. (Result == qaOK) ||
  4688. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4689. (Result == qaNeverAskAgain);
  4690. }
  4691. }
  4692. if (CanClose)
  4693. {
  4694. CanClose = CanCloseQueue();
  4695. }
  4696. }
  4697. if (CanClose)
  4698. {
  4699. CanClose =
  4700. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4701. FEditorManager->CloseExternalFilesWithoutProcess();
  4702. if (CanClose)
  4703. {
  4704. while (CanClose && (FLocalEditors->Count > 0))
  4705. {
  4706. int PrevCount = FLocalEditors->Count;
  4707. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4708. CanClose = (FLocalEditors->Count < PrevCount);
  4709. }
  4710. if (CanClose)
  4711. {
  4712. CanClose = FEditorManager->Empty(true);
  4713. if (!CanClose)
  4714. {
  4715. SetFocus();
  4716. CanClose =
  4717. (MessageDialog(
  4718. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4719. }
  4720. }
  4721. }
  4722. }
  4723. }
  4724. //---------------------------------------------------------------------------
  4725. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4726. {
  4727. TForm * Form = dynamic_cast<TForm *>(Sender);
  4728. DebugAssert(Form != NULL);
  4729. Form->Close();
  4730. }
  4731. //---------------------------------------------------------------------------
  4732. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4733. {
  4734. TForm * Form = dynamic_cast<TForm *>(Sender);
  4735. delete Form;
  4736. }
  4737. //---------------------------------------------------------------------------
  4738. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4739. {
  4740. while (FLocalEditors->Count > 0)
  4741. {
  4742. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4743. }
  4744. }
  4745. //---------------------------------------------------------------------------
  4746. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4747. TObject *Sender)
  4748. {
  4749. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4750. try
  4751. {
  4752. SetProperties(osRemote, FileList);
  4753. }
  4754. __finally
  4755. {
  4756. delete FileList;
  4757. }
  4758. }
  4759. //---------------------------------------------------------------------------
  4760. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4761. {
  4762. if (value)
  4763. {
  4764. if (Component == fcCustomCommandsBand)
  4765. {
  4766. UpdateCustomCommandsToolbar();
  4767. }
  4768. if (Component == fcQueueFileList)
  4769. {
  4770. DebugAssert(!QueueFileListSplitter->Visible);
  4771. AdjustQueueLayout();
  4772. UpdateQueueFileList();
  4773. }
  4774. }
  4775. }
  4776. //---------------------------------------------------------------------------
  4777. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4778. {
  4779. int MinHeightLimit =
  4780. GetStaticQueuePanelComponentsHeight() +
  4781. QueueFileListSplitter->Height +
  4782. QueueFileList->Height +
  4783. GetMinQueueViewHeight();
  4784. if (QueuePanel->ClientHeight < MinHeightLimit)
  4785. {
  4786. QueuePanel->ClientHeight = MinHeightLimit;
  4787. }
  4788. }
  4789. //---------------------------------------------------------------------------
  4790. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4791. {
  4792. TControl * Control = GetComponent(Component);
  4793. DebugAssert(Control);
  4794. bool Changed = (Control->Visible != value);
  4795. if (Changed)
  4796. {
  4797. ComponentShowing(Component, value);
  4798. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4799. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4800. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4801. if (value)
  4802. {
  4803. int RemainingHeight = Control->Parent->ClientHeight;
  4804. int RemainingWidth = Control->Parent->ClientWidth;
  4805. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4806. {
  4807. TControl * ChildControl = Control->Parent->Controls[i];
  4808. if (ChildControl->Visible)
  4809. {
  4810. switch (ChildControl->Align)
  4811. {
  4812. case alTop:
  4813. case alBottom:
  4814. RemainingHeight -= ChildControl->Height;
  4815. break;
  4816. case alLeft:
  4817. case alRight:
  4818. RemainingWidth -= ChildControl->Width;
  4819. break;
  4820. }
  4821. }
  4822. }
  4823. int Reserve = ScaleByTextHeight(this, 32);
  4824. // queue in explorer, trees in commander
  4825. if (Control->Height > RemainingHeight - Reserve)
  4826. {
  4827. Control->Height = RemainingHeight / 2;
  4828. }
  4829. if (Control->Width > RemainingWidth - Reserve)
  4830. {
  4831. Control->Width = RemainingWidth / 2;
  4832. }
  4833. }
  4834. Control->Visible = value;
  4835. if (WasFocused && Visible)
  4836. {
  4837. DirView(osCurrent)->SetFocus();
  4838. }
  4839. FixControlsPlacement();
  4840. }
  4841. }
  4842. //---------------------------------------------------------------------------
  4843. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4844. {
  4845. TControl * Control = GetComponent(Component);
  4846. if (Control == NULL)
  4847. {
  4848. return false;
  4849. }
  4850. else
  4851. {
  4852. return Control->Visible;
  4853. }
  4854. }
  4855. //---------------------------------------------------------------------------
  4856. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4857. {
  4858. bool Result;
  4859. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4860. {
  4861. Result = !IsUWP();
  4862. }
  4863. else
  4864. {
  4865. Result = true;
  4866. }
  4867. return Result;
  4868. }
  4869. //---------------------------------------------------------------------------
  4870. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  4871. {
  4872. if (DirView->ItemFocused != NULL)
  4873. {
  4874. DirView->ItemFocused->MakeVisible(false);
  4875. }
  4876. }
  4877. //---------------------------------------------------------------------------
  4878. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4879. {
  4880. MakeFocusedItemVisible(RemoteDirView);
  4881. QueueSplitter->Visible = QueuePanel->Visible;
  4882. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4883. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4884. TControl * QueueControlsOrder[] =
  4885. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4886. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4887. }
  4888. //---------------------------------------------------------------------------
  4889. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4890. {
  4891. switch (Component) {
  4892. case fcStatusBar: return RemoteStatusBar;
  4893. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4894. case fcQueueView: return QueuePanel;
  4895. case fcQueueToolbar: return QueueDock;
  4896. case fcRemoteTree: return RemoteDrivePanel;
  4897. case fcSessionsTabs: return SessionsPageControl;
  4898. case fcQueueFileList: return QueueFileList;
  4899. default: return NULL;
  4900. }
  4901. }
  4902. //---------------------------------------------------------------------------
  4903. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4904. TObject *Sender, TListColumn *Column, TPoint &Point)
  4905. {
  4906. DebugAssert(NonVisualDataModule && Column && Sender);
  4907. NonVisualDataModule->ListColumn = Column;
  4908. TPopupMenu * DirViewColumnMenu;
  4909. if (Sender == DirView(osOther))
  4910. {
  4911. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4912. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4913. (Column->Index == uvName);
  4914. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4915. (Column->Index == uvSize);
  4916. }
  4917. else
  4918. {
  4919. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4920. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4921. (Column->Index == dvName);
  4922. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4923. (Column->Index == dvSize);
  4924. }
  4925. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4926. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4927. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4928. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4929. }
  4930. //---------------------------------------------------------------------------
  4931. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4932. TObject *Sender, TListItem *Item, bool &AllowExec)
  4933. {
  4934. DoDirViewExecFile(Sender, Item, AllowExec);
  4935. }
  4936. //---------------------------------------------------------------------------
  4937. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4938. TListItem * Item, bool & AllowExec)
  4939. {
  4940. DebugAssert(Sender && Item && Configuration);
  4941. DebugAssert(AllowExec);
  4942. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4943. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  4944. bool Remote = !IsSideLocalBrowser(Side);
  4945. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  4946. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4947. // on files only (not directories)
  4948. // and only when symlinks are resolved (apply to remote panel only)
  4949. if (!ADirView->ItemIsDirectory(Item) &&
  4950. (ResolvedSymlinks || FForceExecution))
  4951. {
  4952. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4953. !FForceExecution && ResolvedSymlinks)
  4954. {
  4955. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4956. {
  4957. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4958. UnlockWindow();
  4959. try
  4960. {
  4961. if (IsLocalBrowserMode())
  4962. {
  4963. LocalLocalCopy(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4964. }
  4965. else
  4966. {
  4967. ExecuteFileOperation(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4968. }
  4969. }
  4970. __finally
  4971. {
  4972. LockWindow();
  4973. }
  4974. AllowExec = false;
  4975. }
  4976. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4977. {
  4978. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4979. {
  4980. ExecuteFile(Side, efDefaultEditor);
  4981. AllowExec = false;
  4982. }
  4983. }
  4984. else
  4985. {
  4986. DebugFail();
  4987. }
  4988. }
  4989. // if we have not done anything special, fall back to default behavior
  4990. if (AllowExec)
  4991. {
  4992. if (Remote && !WinConfiguration->DisableOpenEdit)
  4993. {
  4994. ExecuteFile(osRemote, efShell);
  4995. AllowExec = false;
  4996. }
  4997. }
  4998. }
  4999. }
  5000. //---------------------------------------------------------------------------
  5001. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  5002. {
  5003. return ((Side == osRemote) || (Side == osCurrent));
  5004. }
  5005. //---------------------------------------------------------------------------
  5006. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5007. {
  5008. DebugFail();
  5009. }
  5010. //---------------------------------------------------------------------------
  5011. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5012. {
  5013. DebugFail();
  5014. }
  5015. //---------------------------------------------------------------------------
  5016. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5017. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5018. {
  5019. TSynchronizeParamType Params;
  5020. Params.LocalDirectory = LocalDirectory;
  5021. Params.RemoteDirectory = RemoteDirectory;
  5022. int UnusedParams =
  5023. (GUIConfiguration->SynchronizeParams &
  5024. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5025. TTerminal::spCaseSensitive));
  5026. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5027. Params.Options = GUIConfiguration->SynchronizeOptions;
  5028. bool SaveSettings = false;
  5029. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5030. &DoSynchronizeTooManyDirectories);
  5031. DebugAssert(FSynchronizeController == NULL);
  5032. FSynchronizeController = &Controller;
  5033. bool Result;
  5034. try
  5035. {
  5036. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5037. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5038. int Options =
  5039. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5040. DebugAssert(FOnFeedSynchronizeError == NULL);
  5041. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5042. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5043. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5044. if (Result)
  5045. {
  5046. if (SaveSettings)
  5047. {
  5048. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5049. GUIConfiguration->SynchronizeOptions = Params.Options;
  5050. }
  5051. else
  5052. {
  5053. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5054. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5055. FLAGSET(Params.Options, soSynchronize))
  5056. {
  5057. GUIConfiguration->SynchronizeOptions =
  5058. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5059. soSynchronize;
  5060. }
  5061. }
  5062. LocalDirectory = Params.LocalDirectory;
  5063. RemoteDirectory = Params.RemoteDirectory;
  5064. }
  5065. }
  5066. __finally
  5067. {
  5068. FSynchronizeController = NULL;
  5069. DebugAssert(FOnFeedSynchronizeError == NULL);
  5070. FOnFeedSynchronizeError = NULL;
  5071. }
  5072. return Result;
  5073. }
  5074. //---------------------------------------------------------------------------
  5075. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5076. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5077. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5078. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5079. TSynchronizeOptions * Options, bool Full)
  5080. {
  5081. // Keep-up-to-date mode
  5082. if (Terminal->Status == ssOpened)
  5083. {
  5084. try
  5085. {
  5086. int PParams = Params.Params;
  5087. if (!Full)
  5088. {
  5089. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5090. if (FLAGSET(Params.Options, soRecurse))
  5091. {
  5092. PParams |= TTerminal::spSubDirs;
  5093. }
  5094. }
  5095. else
  5096. {
  5097. // if keepuptodate is non-recursive,
  5098. // full sync before has to be non-recursive as well
  5099. if (FLAGCLEAR(Params.Options, soRecurse))
  5100. {
  5101. PParams |= TTerminal::spNoRecurse;
  5102. }
  5103. }
  5104. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5105. PParams, Checklist, Options);
  5106. }
  5107. catch (Exception & E)
  5108. {
  5109. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5110. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5111. {
  5112. // noop, already logged in MoreMessageDialog
  5113. }
  5114. else
  5115. {
  5116. ShowExtendedExceptionEx(Terminal, &E);
  5117. throw;
  5118. }
  5119. }
  5120. }
  5121. }
  5122. //---------------------------------------------------------------------------
  5123. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5124. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5125. const UnicodeString ErrorStr)
  5126. {
  5127. if (!Directory.IsEmpty())
  5128. {
  5129. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5130. }
  5131. else
  5132. {
  5133. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5134. }
  5135. }
  5136. //---------------------------------------------------------------------------
  5137. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5138. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5139. {
  5140. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5141. {
  5142. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5143. }
  5144. else
  5145. {
  5146. TMessageParams Params(mpNeverAskAgainCheck);
  5147. unsigned int Result = MessageDialog(
  5148. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5149. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5150. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5151. {
  5152. MaxDirectories *= 2;
  5153. if (Result == qaNeverAskAgain)
  5154. {
  5155. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5156. }
  5157. }
  5158. else
  5159. {
  5160. Abort();
  5161. }
  5162. }
  5163. }
  5164. //---------------------------------------------------------------------------
  5165. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5166. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5167. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5168. TSynchronizeOptions * Options)
  5169. {
  5170. // Keep-up-to-date mode
  5171. DebugAssert(!FAutoOperation);
  5172. void * BatchStorage;
  5173. BatchStart(BatchStorage);
  5174. FAutoOperation = true;
  5175. bool AnyOperation = false;
  5176. TDateTime StartTime = Now();
  5177. TSynchronizeChecklist * AChecklist = NULL;
  5178. try
  5179. {
  5180. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5181. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5182. {
  5183. FSynchronizeProgressForm->Start();
  5184. }
  5185. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5186. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5187. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5188. Options);
  5189. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5190. SAFE_DESTROY(FSynchronizeProgressForm);
  5191. AnyOperation = (AChecklist->CheckedCount > 0);
  5192. if (AnyOperation)
  5193. {
  5194. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5195. CreateProgressForm(&SynchronizeProgress);
  5196. try
  5197. {
  5198. Terminal->SynchronizeApply(
  5199. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5200. SynchronizeProcessedItem, NULL, NULL, NULL);
  5201. }
  5202. __finally
  5203. {
  5204. DestroyProgressForm();
  5205. }
  5206. }
  5207. }
  5208. __finally
  5209. {
  5210. if (Checklist == NULL)
  5211. {
  5212. delete AChecklist;
  5213. }
  5214. else
  5215. {
  5216. *Checklist = AChecklist;
  5217. }
  5218. FAutoOperation = false;
  5219. SAFE_DESTROY(FSynchronizeProgressForm);
  5220. BatchEnd(BatchStorage);
  5221. ReloadLocalDirectory();
  5222. if (AnyOperation)
  5223. {
  5224. OperationComplete(StartTime);
  5225. }
  5226. }
  5227. }
  5228. //---------------------------------------------------------------------------
  5229. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5230. {
  5231. // can be called from command line
  5232. return Visible &&
  5233. ((DirView(osRemote)->SelCount > 0) ||
  5234. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5235. }
  5236. //---------------------------------------------------------------------------
  5237. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5238. {
  5239. LogSynchronizeEvent(Terminal, Message);
  5240. }
  5241. //---------------------------------------------------------------------------
  5242. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5243. int Params, TSynchronizeOptions & Options)
  5244. {
  5245. DebugAssert(!IsLocalBrowserMode());
  5246. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5247. {
  5248. Options.Filter = new TStringList();
  5249. Options.Filter->CaseSensitive = false;
  5250. Options.Filter->Duplicates = Types::dupAccept;
  5251. if (DirView(osRemote)->SelCount > 0)
  5252. {
  5253. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5254. }
  5255. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5256. {
  5257. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5258. }
  5259. Options.Filter->Sort();
  5260. }
  5261. }
  5262. //---------------------------------------------------------------------------
  5263. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5264. {
  5265. TCopyParamType Defaults;
  5266. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5267. ConfigStorage->AccessMode = smRead;
  5268. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5269. {
  5270. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5271. }
  5272. ConfigStorage.reset(NULL);
  5273. std::unique_ptr<TStringList> Options(new TStringList());
  5274. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5275. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5276. UnicodeString Result;
  5277. if (Options->Count > 0)
  5278. {
  5279. Result =
  5280. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5281. }
  5282. return Result;
  5283. }
  5284. //---------------------------------------------------------------------------
  5285. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5286. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5287. {
  5288. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5289. UnicodeString AdditionalParams =
  5290. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5291. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5292. SerializeCopyParamForCommandLine(CopyParams),
  5293. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5294. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5295. ExecuteNewInstance(SessionName, AdditionalParams);
  5296. }
  5297. //---------------------------------------------------------------------------
  5298. struct TSynchronizeParams
  5299. {
  5300. UnicodeString LocalDirectory;
  5301. UnicodeString RemoteDirectory;
  5302. TSynchronizeMode Mode;
  5303. TSynchronizeChecklist * Checklist;
  5304. int Params;
  5305. TCopyParamType * CopyParam;
  5306. TDateTime CollectElapsed;
  5307. TDateTime * StartTime;
  5308. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5309. };
  5310. //---------------------------------------------------------------------------
  5311. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5312. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5313. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5314. {
  5315. DebugAssert(!FAutoOperation);
  5316. void * BatchStorage;
  5317. BatchStart(BatchStorage);
  5318. FAutoOperation = true;
  5319. TFileOperationStatistics Statistics;
  5320. TDateTime Start = Now();
  5321. try
  5322. {
  5323. Params.OnProcessedItem = OnProcessedItem;
  5324. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5325. CreateProgressForm(&SynchronizeProgress);
  5326. Terminal->SynchronizeApply(
  5327. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5328. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5329. &Statistics);
  5330. }
  5331. __finally
  5332. {
  5333. Params.OnProcessedItem = NULL;
  5334. FAutoOperation = false;
  5335. DestroyProgressForm();
  5336. BatchEnd(BatchStorage);
  5337. ReloadLocalDirectory();
  5338. }
  5339. if (WinConfiguration->SynchronizeSummary)
  5340. {
  5341. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5342. // The statistics should be 0 anyway in this case
  5343. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5344. {
  5345. Message += L"\n";
  5346. if (Statistics.FilesUploaded > 0)
  5347. {
  5348. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5349. }
  5350. if (Statistics.FilesDownloaded > 0)
  5351. {
  5352. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5353. }
  5354. if (Statistics.FilesDeletedLocal > 0)
  5355. {
  5356. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5357. }
  5358. if (Statistics.FilesDeletedRemote > 0)
  5359. {
  5360. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5361. }
  5362. }
  5363. TDateTime Elapsed = (Now() - Start);
  5364. Message +=
  5365. L"\n" +
  5366. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5367. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5368. TMessageParams Params(mpNeverAskAgainCheck);
  5369. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5370. if (Result == qaNeverAskAgain)
  5371. {
  5372. WinConfiguration->SynchronizeSummary = false;
  5373. }
  5374. }
  5375. }
  5376. //---------------------------------------------------------------------------
  5377. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5378. {
  5379. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5380. {
  5381. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5382. }
  5383. // Not set in keep-up-to-date mode - Synchronize() method
  5384. if (Token != NULL)
  5385. {
  5386. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5387. if (Params.OnProcessedItem != NULL)
  5388. {
  5389. Params.OnProcessedItem(NULL, ChecklistItem);
  5390. }
  5391. }
  5392. }
  5393. //---------------------------------------------------------------------------
  5394. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5395. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5396. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5397. {
  5398. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5399. *Params.StartTime = Now();
  5400. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5401. }
  5402. //---------------------------------------------------------------------------
  5403. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5404. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5405. {
  5406. // terminal can be already closed (e.g. dropped connection)
  5407. if (Terminal != NULL)
  5408. {
  5409. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5410. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5411. }
  5412. }
  5413. //---------------------------------------------------------------------------
  5414. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5415. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5416. {
  5417. DebugAssert(!IsLocalBrowserMode());
  5418. TAutoBatch AutoBatch(this);
  5419. TAutoFlag AutoOperationFlag(FAutoOperation);
  5420. if (Side == osRemote)
  5421. {
  5422. std::unique_ptr<TStrings> FileList(new TStringList());
  5423. FileList->AddObject(FileName, RemoteFile);
  5424. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5425. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5426. RemoteDirView->SaveSelection();
  5427. RemoteDirView->SaveSelectedNames();
  5428. try
  5429. {
  5430. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5431. }
  5432. catch(...)
  5433. {
  5434. RemoteDirView->DiscardSavedSelection();
  5435. throw;
  5436. }
  5437. RemoteDirView->RestoreSelection();
  5438. }
  5439. else if (DebugAlwaysTrue(Side == osLocal))
  5440. {
  5441. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5442. {
  5443. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5444. }
  5445. UnicodeString Directory = ExtractFileDir(FileName);
  5446. ReloadLocalDirectory(Directory);
  5447. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5448. if (!SamePaths(Directory, NewDirectory))
  5449. {
  5450. ReloadLocalDirectory(NewDirectory);
  5451. }
  5452. }
  5453. }
  5454. //---------------------------------------------------------------------------
  5455. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5456. {
  5457. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5458. if (Side == osLocal)
  5459. {
  5460. if (Action == TSynchronizeChecklist::saDownloadNew)
  5461. {
  5462. OpenFolderInExplorer(LocalPath);
  5463. }
  5464. else
  5465. {
  5466. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5467. }
  5468. }
  5469. else if (DebugAlwaysTrue(Side == osRemote))
  5470. {
  5471. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5472. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5473. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5474. if (!LocalPath.IsEmpty())
  5475. {
  5476. SessionData->LocalDirectory = LocalPath;
  5477. }
  5478. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5479. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5480. }
  5481. }
  5482. //---------------------------------------------------------------------------
  5483. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5484. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5485. const TCopyParamType * CopyParams)
  5486. {
  5487. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5488. UnicodeString AdditionalParams =
  5489. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5490. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5491. SerializeCopyParamForCommandLine(CopyParams),
  5492. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5493. LocalDirectory, RemoteDirectory, Mode, Params));
  5494. ExecuteNewInstance(SessionName, AdditionalParams);
  5495. }
  5496. //---------------------------------------------------------------------------
  5497. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5498. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5499. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5500. {
  5501. int Result;
  5502. bool SaveSettings = false;
  5503. int Options =
  5504. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5505. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5506. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5507. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5508. bool Continue =
  5509. (UseDefaults == 0) ||
  5510. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5511. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5512. if (Continue)
  5513. {
  5514. Configuration->Usage->Inc(L"Synchronizations");
  5515. UpdateCopyParamCounters(CopyParam);
  5516. TSynchronizeOptions SynchronizeOptions;
  5517. GetSynchronizeOptions(Params, SynchronizeOptions);
  5518. if (SaveSettings)
  5519. {
  5520. GUIConfiguration->SynchronizeParams = Params;
  5521. }
  5522. else
  5523. {
  5524. SaveMode = false;
  5525. }
  5526. TDateTime StartTime = Now();
  5527. TSynchronizeChecklist * Checklist = NULL;
  5528. try
  5529. {
  5530. DebugAssert(!FAutoOperation);
  5531. FAutoOperation = true;
  5532. try
  5533. {
  5534. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5535. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5536. int Files = -1;
  5537. if (DataList->Count >= 1)
  5538. {
  5539. Files = StrToIntDef(DataList->Strings[0], Files);
  5540. }
  5541. else
  5542. {
  5543. DataList->Add(UnicodeString());
  5544. }
  5545. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5546. FSynchronizeProgressForm->Start();
  5547. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5548. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5549. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5550. &SynchronizeOptions);
  5551. if (Terminal->SessionData->CacheDirectories)
  5552. {
  5553. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5554. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5555. }
  5556. }
  5557. __finally
  5558. {
  5559. FAutoOperation = false;
  5560. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5561. SAFE_DESTROY(FSynchronizeProgressForm);
  5562. }
  5563. TSynchronizeParams SynchronizeParams;
  5564. SynchronizeParams.LocalDirectory = LocalDirectory;
  5565. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5566. SynchronizeParams.Mode = Mode;
  5567. SynchronizeParams.CopyParam = &CopyParam;
  5568. SynchronizeParams.Params = Params;
  5569. SynchronizeParams.Checklist = Checklist;
  5570. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5571. SynchronizeParams.StartTime = &StartTime;
  5572. SynchronizeParams.OnProcessedItem = NULL;
  5573. Result = Checklist->Count;
  5574. if (Checklist->Count > 0)
  5575. {
  5576. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5577. {
  5578. if (!DoSynchronizeChecklistDialog(
  5579. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5580. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5581. {
  5582. Result = -1;
  5583. }
  5584. }
  5585. else
  5586. {
  5587. FullSynchronize(SynchronizeParams, NULL, NULL);
  5588. }
  5589. }
  5590. else
  5591. {
  5592. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5593. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5594. }
  5595. }
  5596. __finally
  5597. {
  5598. delete Checklist;
  5599. }
  5600. OperationComplete(StartTime);
  5601. }
  5602. else
  5603. {
  5604. Result = -1;
  5605. }
  5606. return Result;
  5607. }
  5608. //---------------------------------------------------------------------------
  5609. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5610. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5611. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5612. {
  5613. if (Collect)
  5614. {
  5615. DebugAssert(FSynchronizeProgressForm != NULL);
  5616. if (!FSynchronizeProgressForm->Started)
  5617. {
  5618. FSynchronizeProgressForm->Start();
  5619. }
  5620. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5621. SetTaskbarListProgressValue(CompareProgress);
  5622. }
  5623. else
  5624. {
  5625. DebugAssert(FSynchronizeProgressForm == NULL);
  5626. DebugAssert(FProgressForm != NULL);
  5627. }
  5628. }
  5629. //---------------------------------------------------------------------------
  5630. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5631. {
  5632. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5633. TRemoteFile * File = NULL;
  5634. Terminal->ReadFile(FullFileName, File);
  5635. if (File != NULL)
  5636. {
  5637. std::unique_ptr<TRemoteFile> FileOwner(File);
  5638. TAutoFlag Flag(FStandaloneEditing);
  5639. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5640. Application->ShowMainForm = false;
  5641. Application->Run();
  5642. }
  5643. }
  5644. //---------------------------------------------------------------------------
  5645. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  5646. {
  5647. DebugFail();
  5648. }
  5649. //---------------------------------------------------------------------------
  5650. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5651. {
  5652. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5653. SessionData->Assign(Terminal->SessionData);
  5654. UpdateSessionData(SessionData.get());
  5655. Terminal->UpdateSessionCredentials(SessionData.get());
  5656. if (!Terminal->SessionData->HasSessionName())
  5657. {
  5658. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5659. // once IsWorkspace is cleared
  5660. SessionData->Name = UnicodeString();
  5661. SessionData->IsWorkspace = false;
  5662. }
  5663. return SessionData.release();
  5664. }
  5665. //---------------------------------------------------------------------------
  5666. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5667. {
  5668. TSessionData * SessionData = CloneCurrentSessionData();
  5669. try
  5670. {
  5671. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5672. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5673. }
  5674. __finally
  5675. {
  5676. delete SessionData;
  5677. }
  5678. }
  5679. //---------------------------------------------------------------------------
  5680. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5681. {
  5682. TTerminalManager * Manager = TTerminalManager::Instance();
  5683. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5684. if (DebugAlwaysTrue(Terminal != NULL))
  5685. {
  5686. // Update (Managed)Terminal->StateData
  5687. UpdateTerminal(Terminal);
  5688. }
  5689. Manager->SaveWorkspace(DataList.get());
  5690. return DataList.release();
  5691. }
  5692. //---------------------------------------------------------------------------
  5693. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5694. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5695. {
  5696. WinConfiguration->LastWorkspace = Name;
  5697. if (!SavePasswords)
  5698. {
  5699. for (int Index = 0; Index < DataList->Count; Index++)
  5700. {
  5701. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5702. if (SessionData->Link.IsEmpty())
  5703. {
  5704. SessionData->ClearSessionPasswords();
  5705. }
  5706. }
  5707. }
  5708. StoredSessions->NewWorkspace(Name, DataList);
  5709. // modified only
  5710. StoredSessions->Save(false, Explicit);
  5711. }
  5712. //---------------------------------------------------------------------------
  5713. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5714. {
  5715. return
  5716. DefaultStr(WinConfiguration->LastWorkspace,
  5717. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5718. }
  5719. //---------------------------------------------------------------------------
  5720. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5721. {
  5722. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5723. bool AnyNonStoredSessionWithPassword = false;
  5724. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5725. bool AllNonStoredSessionsAnonymous = true;
  5726. TTerminalManager * Manager = TTerminalManager::Instance();
  5727. for (int Index = 0; Index < DataList->Count; Index++)
  5728. {
  5729. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5730. if (SessionData->Link.IsEmpty())
  5731. {
  5732. if (SessionData->HasAnySessionPassword())
  5733. {
  5734. AnyNonStoredSessionWithPassword = true;
  5735. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5736. {
  5737. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5738. }
  5739. }
  5740. if (!SameText(SessionData->UserName, AnonymousUserName))
  5741. {
  5742. AllNonStoredSessionsAnonymous = false;
  5743. }
  5744. }
  5745. }
  5746. bool SavePasswords;
  5747. bool * PSavePasswords;
  5748. bool NotRecommendedSavingPasswords =
  5749. !CustomWinConfiguration->UseMasterPassword &&
  5750. !AllNonStoredSessionsAnonymous;
  5751. if (Configuration->DisablePasswordStoring ||
  5752. !AnyNonStoredSessionWithPassword)
  5753. {
  5754. PSavePasswords = NULL;
  5755. SavePasswords = false;
  5756. }
  5757. else
  5758. {
  5759. PSavePasswords = &SavePasswords;
  5760. SavePasswords =
  5761. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5762. !NotRecommendedSavingPasswords;
  5763. }
  5764. UnicodeString Name = WorkspaceName();
  5765. bool CreateShortcut = false;
  5766. bool Result =
  5767. DoSaveWorkspaceDialog(
  5768. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5769. EnableAutoSave);
  5770. if (Result)
  5771. {
  5772. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5773. if (CreateShortcut)
  5774. {
  5775. TOperationVisualizer Visualizer;
  5776. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5777. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5778. }
  5779. if (EnableAutoSave)
  5780. {
  5781. WinConfiguration->AutoSaveWorkspace = true;
  5782. WinConfiguration->AutoWorkspace = Name;
  5783. if (PSavePasswords != NULL)
  5784. {
  5785. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5786. }
  5787. }
  5788. }
  5789. return Result;
  5790. }
  5791. //---------------------------------------------------------------------------
  5792. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5793. {
  5794. DebugAssert(!IsLocalBrowserMode());
  5795. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5796. if (WinConfiguration->PreservePanelState)
  5797. {
  5798. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5799. }
  5800. UpdateSessionData(Terminal->StateData);
  5801. }
  5802. //---------------------------------------------------------------------------
  5803. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5804. {
  5805. // Keep in sync with TSessionData::CopyStateData
  5806. DebugAssert(!IsLocalBrowserMode());
  5807. DebugAssert(Data != NULL);
  5808. // This is inconsistent with how color (for example) is handled.
  5809. Data->Name = Terminal->SessionData->Name;
  5810. // cannot use RemoteDirView->Path, because it is empty if connection
  5811. // was already closed
  5812. // also only peek, we may not be connected at all atm
  5813. // so make sure we do not try retrieving current directory from the server
  5814. // (particularly with FTP)
  5815. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5816. if (!ACurrentDirectory.IsEmpty())
  5817. {
  5818. Data->RemoteDirectory = ACurrentDirectory;
  5819. }
  5820. Data->Color = SessionColor;
  5821. }
  5822. //---------------------------------------------------------------------------
  5823. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5824. {
  5825. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5826. DebugAssert(Toolbar != NULL);
  5827. for (int i = 0; i < Toolbar->Items->Count; i++)
  5828. {
  5829. TTBXCustomDropDownItem * DropDownItem;
  5830. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5831. if (DropDownItem != NULL)
  5832. {
  5833. ToolbarItemResize(DropDownItem,
  5834. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5835. Toolbar->NonClientWidth);
  5836. break;
  5837. }
  5838. }
  5839. }
  5840. //---------------------------------------------------------------------------
  5841. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5842. {
  5843. Item->EditWidth = Width;
  5844. }
  5845. //---------------------------------------------------------------------------
  5846. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5847. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5848. {
  5849. for (int i = 0; i < Toolbar->Items->Count; i++)
  5850. {
  5851. TTBXCustomDropDownItem * DropDownItem;
  5852. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5853. if (DropDownItem != NULL)
  5854. {
  5855. ASize.x -= DropDownItem->EditWidth;
  5856. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5857. }
  5858. }
  5859. }
  5860. //---------------------------------------------------------------------------
  5861. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5862. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5863. {
  5864. if (WinConfiguration->DDWarnLackOfTempSpace)
  5865. {
  5866. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5867. if (!ADrive.IsEmpty())
  5868. {
  5869. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5870. DebugAssert(RequiredSpace >= 0);
  5871. __int64 RequiredWithReserve;
  5872. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5873. if (FreeSpace < RequiredWithReserve)
  5874. {
  5875. unsigned int Result;
  5876. TMessageParams Params(mpNeverAskAgainCheck);
  5877. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5878. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5879. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5880. if (Result == qaNeverAskAgain)
  5881. {
  5882. WinConfiguration->DDWarnLackOfTempSpace = false;
  5883. }
  5884. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5885. }
  5886. }
  5887. }
  5888. }
  5889. //---------------------------------------------------------------------------
  5890. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5891. {
  5892. DoOpenDirectoryDialog(odAddBookmark, Side);
  5893. }
  5894. //---------------------------------------------------------------------------
  5895. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5896. {
  5897. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5898. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5899. try
  5900. {
  5901. TCustomDirView * DView = DirView(Side);
  5902. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5903. {
  5904. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5905. }
  5906. }
  5907. catch (...)
  5908. {
  5909. delete VisitedDirectories;
  5910. throw;
  5911. }
  5912. return VisitedDirectories;
  5913. }
  5914. //---------------------------------------------------------------------------
  5915. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5916. TOpenDirectoryMode Mode, TOperationSide Side)
  5917. {
  5918. bool Continue = true;
  5919. if (Mode == odAddBookmark)
  5920. {
  5921. TMessageParams Params(mpNeverAskAgainCheck);
  5922. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5923. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5924. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5925. unsigned int Answer =
  5926. MessageDialog(Message,
  5927. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5928. if (Answer == qaNeverAskAgain)
  5929. {
  5930. Continue = true;
  5931. WinConfiguration->UseSharedBookmarks = true;
  5932. }
  5933. else if (Answer == qaOK)
  5934. {
  5935. Continue = true;
  5936. WinConfiguration->UseSharedBookmarks = false;
  5937. }
  5938. else
  5939. {
  5940. Continue = false;
  5941. }
  5942. }
  5943. if (Continue)
  5944. {
  5945. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5946. try
  5947. {
  5948. UnicodeString Name = DirView(Side)->PathName;
  5949. bool Repeat;
  5950. do
  5951. {
  5952. Repeat = false;
  5953. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  5954. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  5955. // do not allow switching to location profiles,
  5956. // if we are not connected
  5957. HasDirView[osLocal] && (Terminal != NULL)))
  5958. {
  5959. TWindowLock Lock(this);
  5960. if (!TryOpenDirectory(Side, Name))
  5961. {
  5962. Repeat = true;
  5963. Mode = odBrowse;
  5964. }
  5965. }
  5966. }
  5967. while (Repeat);
  5968. }
  5969. __finally
  5970. {
  5971. delete VisitedDirectories;
  5972. }
  5973. }
  5974. }
  5975. //---------------------------------------------------------------------------
  5976. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5977. {
  5978. DebugAssert(!FTerminal->CommandSessionOpened);
  5979. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5980. }
  5981. //---------------------------------------------------------------------------
  5982. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5983. {
  5984. bool Result = FTerminal->IsCapable[Capability] ||
  5985. FTerminal->CommandSessionOpened;
  5986. if (!Result)
  5987. {
  5988. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5989. if (!GUIConfiguration->ConfirmCommandSession)
  5990. {
  5991. Result = true;
  5992. }
  5993. else
  5994. {
  5995. TMessageParams Params(mpNeverAskAgainCheck);
  5996. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5997. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5998. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5999. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6000. if (Answer == qaNeverAskAgain)
  6001. {
  6002. GUIConfiguration->ConfirmCommandSession = false;
  6003. Result = true;
  6004. }
  6005. else if (Answer == qaOK)
  6006. {
  6007. Result = true;
  6008. }
  6009. }
  6010. if (Result)
  6011. {
  6012. Result = CommandSessionFallback();
  6013. }
  6014. }
  6015. return Result;
  6016. }
  6017. //---------------------------------------------------------------------------
  6018. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6019. {
  6020. if (EnsureCommandSessionFallback(fcAnyCommand))
  6021. {
  6022. DoConsoleDialog(Terminal, Command);
  6023. }
  6024. }
  6025. //---------------------------------------------------------------------------
  6026. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6027. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6028. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6029. {
  6030. if (!IsSideLocalBrowser(osRemote) &&
  6031. IsFileControl(DropSourceControl, osRemote) &&
  6032. (FDDExtMapFile != NULL))
  6033. {
  6034. Accept = true;
  6035. }
  6036. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6037. DebugAssert(FDDTargetControl != NULL);
  6038. }
  6039. //---------------------------------------------------------------------------
  6040. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6041. _di_IDataObject DataObj, int KeyState,
  6042. const TPoint & Point, int & Effect, bool & Accept)
  6043. {
  6044. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6045. }
  6046. //---------------------------------------------------------------------------
  6047. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6048. _di_IDataObject DataObj, int KeyState,
  6049. const TPoint & Point, int & Effect, bool & Accept)
  6050. {
  6051. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6052. }
  6053. //---------------------------------------------------------------------------
  6054. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6055. TObject * Sender)
  6056. {
  6057. DebugUsedParam(Sender);
  6058. DebugAssert(FDDTargetControl == Sender);
  6059. FDDTargetControl = NULL;
  6060. }
  6061. //---------------------------------------------------------------------------
  6062. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6063. {
  6064. FileControlDDDragLeave(SessionsPageControl);
  6065. }
  6066. //---------------------------------------------------------------------------
  6067. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6068. {
  6069. FileControlDDDragLeave(QueueView3);
  6070. }
  6071. //---------------------------------------------------------------------------
  6072. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6073. {
  6074. DebugAssert(!IsSideLocalBrowser(Side));
  6075. DebugUsedParam(Side);
  6076. bool Edit = false;
  6077. TRemoteFile * File = NULL;
  6078. UnicodeString FileName;
  6079. UnicodeString PointTo;
  6080. bool SymbolicLink = true;
  6081. if (RemoteDirView->ItemFocused)
  6082. {
  6083. DebugAssert(RemoteDirView->ItemFocused->Data);
  6084. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6085. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6086. if (Edit)
  6087. {
  6088. FileName = File->FileName;
  6089. PointTo = File->LinkTo;
  6090. }
  6091. else
  6092. {
  6093. PointTo = File->FileName;
  6094. }
  6095. }
  6096. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6097. Terminal->IsCapable[fcHardLink]))
  6098. {
  6099. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6100. if (Edit)
  6101. {
  6102. DebugAssert(File->FileName == FileName);
  6103. int Params = dfNoRecursive;
  6104. Terminal->ExceptionOnFail = true;
  6105. try
  6106. {
  6107. Terminal->DeleteFile(L"", File, &Params);
  6108. }
  6109. __finally
  6110. {
  6111. Terminal->ExceptionOnFail = false;
  6112. }
  6113. }
  6114. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6115. }
  6116. }
  6117. //---------------------------------------------------------------------------
  6118. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6119. {
  6120. return
  6121. (IsSideLocalBrowser(Side) ||
  6122. (HasActiveTerminal() &&
  6123. Terminal->ResolvingSymlinks &&
  6124. Terminal->IsCapable[fcSymbolicLink]));
  6125. }
  6126. //---------------------------------------------------------------------------
  6127. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6128. {
  6129. return
  6130. !IsSideLocalBrowser(FCurrentSide) &&
  6131. (RemoteDirView->ItemFocused != NULL) &&
  6132. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6133. Terminal->SessionData->ResolveSymlinks;
  6134. }
  6135. //---------------------------------------------------------------------------
  6136. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6137. {
  6138. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6139. FForceExecution = true;
  6140. try
  6141. {
  6142. DirView(osCurrent)->ExecuteCurrentFile();
  6143. }
  6144. __finally
  6145. {
  6146. FForceExecution = false;
  6147. }
  6148. }
  6149. //---------------------------------------------------------------------------
  6150. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6151. {
  6152. TEditorData ExternalEditor;
  6153. ExternalEditor.Editor = edExternal;
  6154. bool Remember = false;
  6155. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6156. {
  6157. if (Remember)
  6158. {
  6159. TEditorList * EditorList = new TEditorList;
  6160. try
  6161. {
  6162. *EditorList = *WinConfiguration->EditorList;
  6163. bool Found = false;
  6164. int i = 0;
  6165. while (!Found && (i < EditorList->Count))
  6166. {
  6167. const TEditorPreferences * Editor = EditorList->Editors[i];
  6168. if ((Editor->Data->Editor == edExternal) &&
  6169. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6170. {
  6171. Found = true;
  6172. }
  6173. i++;
  6174. }
  6175. if (!Found)
  6176. {
  6177. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6178. WinConfiguration->EditorList = EditorList;
  6179. }
  6180. }
  6181. __finally
  6182. {
  6183. delete EditorList;
  6184. }
  6185. }
  6186. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6187. }
  6188. }
  6189. //---------------------------------------------------------------------------
  6190. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6191. {
  6192. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6193. if (FFileFindTerminal == ATerminal)
  6194. {
  6195. FFileFindTerminal = NULL;
  6196. HideFileFindDialog();
  6197. }
  6198. if (FClipboardTerminal == ATerminal)
  6199. {
  6200. ClipboardClear(); // implies ClipboardStop
  6201. }
  6202. }
  6203. //---------------------------------------------------------------------------
  6204. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6205. {
  6206. DetachTerminal(Sender);
  6207. }
  6208. //---------------------------------------------------------------------------
  6209. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6210. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6211. {
  6212. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6213. DebugAssert(Terminal != NULL);
  6214. if (Data->Terminal == Terminal)
  6215. {
  6216. Data->Terminal = NULL;
  6217. }
  6218. }
  6219. //---------------------------------------------------------------------------
  6220. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6221. {
  6222. UpdateControls();
  6223. SessionColor = TColor(0);
  6224. UpdateRemotePathComboBox(false);
  6225. NeedSession(false);
  6226. }
  6227. //---------------------------------------------------------------------------
  6228. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6229. {
  6230. try
  6231. {
  6232. // Cache, as the login dialog can change its value.
  6233. // See also DoShow.
  6234. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6235. try
  6236. {
  6237. if (ShowLogin)
  6238. {
  6239. bool ReloadSessions = !Startup;
  6240. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  6241. }
  6242. }
  6243. __finally
  6244. {
  6245. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6246. // (so there was no chance for the user to open any session yet)
  6247. if ((ShowLogin || !Startup) &&
  6248. !WinConfiguration->KeepOpenWhenNoSession &&
  6249. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6250. {
  6251. TerminateApplication();
  6252. }
  6253. }
  6254. }
  6255. catch (EAbort &)
  6256. {
  6257. // swallow
  6258. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6259. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6260. }
  6261. }
  6262. //---------------------------------------------------------------------------
  6263. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6264. {
  6265. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6266. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6267. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6268. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6269. try
  6270. {
  6271. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6272. // Clear the design time unthemed tab
  6273. ((SessionsPageControl->PageCount > 0) &&
  6274. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6275. {
  6276. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6277. }
  6278. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6279. {
  6280. TThemeTabSheet * TabSheet;
  6281. if (Index >= SessionsPageControl->PageCount)
  6282. {
  6283. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6284. TabSheet->PageControl = SessionsPageControl;
  6285. }
  6286. else
  6287. {
  6288. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6289. }
  6290. bool IsSessionTab = (Index < TerminalList->Count);
  6291. if (IsSessionTab)
  6292. {
  6293. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6294. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6295. UpdateSessionTab(TabSheet);
  6296. }
  6297. else
  6298. {
  6299. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6300. TabSheet->Tag = 0; // not really needed
  6301. TabSheet->Shadowed = false;
  6302. // 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)
  6303. UpdateNewSessionTab();
  6304. }
  6305. TabSheet->ShowCloseButton = IsSessionTab;
  6306. }
  6307. }
  6308. __finally
  6309. {
  6310. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6311. }
  6312. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6313. }
  6314. //---------------------------------------------------------------------------
  6315. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6316. {
  6317. DoTerminalListChanged();
  6318. }
  6319. //---------------------------------------------------------------------------
  6320. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6321. {
  6322. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6323. DebugAssert(TabSheet->ImageIndex == 0);
  6324. TabSheet->Caption =
  6325. WinConfiguration->SelectiveToolbarText ?
  6326. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6327. UnicodeString();
  6328. }
  6329. //---------------------------------------------------------------------------
  6330. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6331. {
  6332. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6333. }
  6334. //---------------------------------------------------------------------------
  6335. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6336. {
  6337. if (DebugAlwaysTrue(TabSheet != NULL))
  6338. {
  6339. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6340. if (DebugAlwaysTrue(ATerminal != NULL))
  6341. {
  6342. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6343. TabSheet->ImageIndex = AddSessionColor(Color);
  6344. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6345. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6346. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6347. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6348. {
  6349. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6350. }
  6351. }
  6352. }
  6353. }
  6354. //---------------------------------------------------------------------------
  6355. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6356. {
  6357. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6358. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6359. bool Result = (Terminal != NULL);
  6360. if (Result)
  6361. {
  6362. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6363. }
  6364. else
  6365. {
  6366. try
  6367. {
  6368. NewSession(false);
  6369. }
  6370. __finally
  6371. {
  6372. DoTerminalListChanged();
  6373. }
  6374. FSessionsPageControlNewSessionTime = Now();
  6375. }
  6376. return Result;
  6377. }
  6378. //---------------------------------------------------------------------------
  6379. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6380. {
  6381. SessionTabSwitched();
  6382. }
  6383. //---------------------------------------------------------------------------
  6384. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6385. {
  6386. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6387. DebugAssert(TransferList != NULL);
  6388. UnicodeString Name;
  6389. if (TransferList->ItemIndex <= 0)
  6390. {
  6391. Name = L"";
  6392. }
  6393. else
  6394. {
  6395. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6396. }
  6397. if (FCopyParamAutoSelected.IsEmpty())
  6398. {
  6399. // if previous preset was not autoselected, make new preset the "default"
  6400. FCopyParamDefault = Name;
  6401. }
  6402. GUIConfiguration->CopyParamCurrent = Name;
  6403. }
  6404. //---------------------------------------------------------------------------
  6405. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6406. {
  6407. // sanity check
  6408. bool ExistingPreset =
  6409. (FTransferListHoverIndex >= 0) &&
  6410. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6411. DebugAssert(ExistingPreset);
  6412. if (ExistingPreset)
  6413. {
  6414. HDC DC = GetDC(0);
  6415. TCanvas * Canvas = new TCanvas();
  6416. try
  6417. {
  6418. Canvas->Handle = DC;
  6419. Canvas->Font = GetToolbarFont(this);
  6420. UnicodeString Name;
  6421. if (FTransferListHoverIndex == 0)
  6422. {
  6423. Name = L"";
  6424. }
  6425. else
  6426. {
  6427. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6428. }
  6429. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6430. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6431. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6432. static_cast<TObject*>(GetComponent(fcTransferList)));
  6433. UnicodeString InfoStr =
  6434. GUIConfiguration->CopyParamPreset[Name].
  6435. GetInfoStr(L"; ",
  6436. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6437. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6438. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6439. {
  6440. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6441. {
  6442. InfoStr.SetLength(InfoStr.Length() - 1);
  6443. }
  6444. InfoStr += Ellipsis;
  6445. }
  6446. // UpdateCaption does not cause invalidation of whole submenu, while
  6447. // setting Caption property does.
  6448. // also it probably does not resize the label, even if necessary
  6449. // (we do not want that anyway)
  6450. TransferLabel->UpdateCaption(InfoStr);
  6451. }
  6452. __finally
  6453. {
  6454. Canvas->Handle = NULL;
  6455. ReleaseDC(0, DC);
  6456. delete Canvas;
  6457. }
  6458. }
  6459. }
  6460. //---------------------------------------------------------------------------
  6461. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6462. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6463. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6464. {
  6465. if (FTransferListHoverIndex != AHoverIndex)
  6466. {
  6467. FTransferListHoverIndex = AHoverIndex;
  6468. UpdateTransferLabel();
  6469. }
  6470. }
  6471. //---------------------------------------------------------------------------
  6472. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6473. {
  6474. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6475. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6476. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6477. {
  6478. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6479. {
  6480. if (!NonVisualDataModule->Busy)
  6481. {
  6482. OpenDirectory(GetSide(osCurrent));
  6483. }
  6484. Message.Result = 1;
  6485. }
  6486. else
  6487. {
  6488. TForm::Dispatch(&Message);
  6489. }
  6490. }
  6491. else
  6492. {
  6493. TForm::Dispatch(&Message);
  6494. }
  6495. }
  6496. //---------------------------------------------------------------------------
  6497. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6498. {
  6499. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6500. if ((FIgnoreNextDialogChar != 0) &&
  6501. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6502. {
  6503. Message.Result = 1;
  6504. }
  6505. else
  6506. {
  6507. TForm::Dispatch(&Message);
  6508. }
  6509. FIgnoreNextDialogChar = 0;
  6510. }
  6511. //---------------------------------------------------------------------------
  6512. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6513. {
  6514. // The four low-order bits are used internally by Windows
  6515. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6516. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6517. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6518. // 61730 - restore thru double click - undocumented
  6519. // 61490 - maximize thru double click - undocumented
  6520. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6521. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6522. {
  6523. SysResizing(Cmd);
  6524. }
  6525. TForm::Dispatch(&Message);
  6526. }
  6527. //---------------------------------------------------------------------------
  6528. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6529. {
  6530. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6531. // Also there no point returning TRUE as we are not able to
  6532. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6533. // Hence the process termination might be safer :)
  6534. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6535. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6536. {
  6537. Message.Result = FALSE;
  6538. }
  6539. else
  6540. {
  6541. Message.Result = TRUE;
  6542. }
  6543. // Do not call default handling as that triggers OnCloseQuery,
  6544. // where our implementation will popup confirmation dialogs, what we do not want,
  6545. // as per Vista guidelines:
  6546. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6547. }
  6548. //---------------------------------------------------------------------------
  6549. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6550. {
  6551. if (Message.EndSession && IsApplicationMinimized())
  6552. {
  6553. // WORKAROUND
  6554. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6555. // when it receives WM_ENDSESSION,
  6556. // but that sometimes (particularly when application is minimized) cause crashes.
  6557. // Crash popups message that blocks log off.
  6558. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6559. // so we call ExitProcess() immediately, not even trying to cleanup.
  6560. // It still causes beep, so there's likely some popup, but it does not block
  6561. // log off.
  6562. ExitProcess(0);
  6563. }
  6564. TForm::Dispatch(&Message);
  6565. }
  6566. #ifdef _DEBUG
  6567. //---------------------------------------------------------------------------
  6568. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6569. {
  6570. TForm::Dispatch(&Message);
  6571. }
  6572. #endif
  6573. //---------------------------------------------------------------------------
  6574. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6575. {
  6576. }
  6577. //---------------------------------------------------------------------------
  6578. void __fastcall TCustomScpExplorerForm::DoShow()
  6579. {
  6580. // only now are the controls resized finally, so the size constraints
  6581. // will not conflict with possibly very small window size
  6582. RestoreFormParams();
  6583. // This indicates that the form was rescaled after parameters were loaded and
  6584. // as most probably the parameters were actually saved with the current form scaling
  6585. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6586. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6587. // and no rounding problems will occur.
  6588. // See also RestoreForm.
  6589. // (we should be safe to call RestoreParams unconditionally)
  6590. if (PixelsPerInch != Screen->PixelsPerInch)
  6591. {
  6592. RestoreParams();
  6593. }
  6594. FixControlsPlacement();
  6595. if (Position == poDefaultPosOnly)
  6596. {
  6597. CutFormToDesktop(this);
  6598. }
  6599. TForm::DoShow();
  6600. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6601. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6602. // This was previously in NeedSession, where other related code is.
  6603. // But that is called form CMShowingChanged, when the window is already visible and the local-local window state
  6604. // unpleasanly shows briefly.
  6605. if (!WinConfiguration->ShowLoginWhenNoSession &&
  6606. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6607. // This detects if workspace was saved the last time the main widow was closed
  6608. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6609. {
  6610. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6611. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6612. }
  6613. if (Terminal == NULL)
  6614. {
  6615. StartingDisconnected();
  6616. }
  6617. UpdatePixelsPerInchMainWindowCounter();
  6618. FShowing = true;
  6619. }
  6620. //---------------------------------------------------------------------------
  6621. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6622. {
  6623. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6624. }
  6625. //---------------------------------------------------------------------------
  6626. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6627. {
  6628. DoTerminalListChanged();
  6629. UpdateControls();
  6630. }
  6631. //---------------------------------------------------------------------------
  6632. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6633. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6634. TNotifyEvent OnBalloonClick, TObject * UserData)
  6635. {
  6636. bool Do;
  6637. UnicodeString Message;
  6638. if (E == NULL)
  6639. {
  6640. Message = Str;
  6641. Do = true;
  6642. }
  6643. else
  6644. {
  6645. Do = ExceptionMessage(E, Message);
  6646. }
  6647. if (Do && WinConfiguration->BalloonNotifications)
  6648. {
  6649. UnicodeString Title;
  6650. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6651. {
  6652. Message = TrimLeft(Message);
  6653. }
  6654. else
  6655. {
  6656. Message = UnformatMessage(Message);
  6657. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6658. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6659. Title = LoadResourceString(Captions[Type]);
  6660. if (Terminal != NULL)
  6661. {
  6662. Title = FORMAT(L"%s - %s",
  6663. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6664. }
  6665. }
  6666. if (Seconds == 0)
  6667. {
  6668. Seconds = WinConfiguration->NotificationsTimeout;
  6669. }
  6670. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6671. }
  6672. }
  6673. //---------------------------------------------------------------------------
  6674. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6675. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6676. UnicodeString HelpKeyword, const TMessageParams * Params,
  6677. TTerminal * Terminal)
  6678. {
  6679. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6680. (FOnFeedSynchronizeError != NULL)) &&
  6681. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6682. {
  6683. if (FOnFeedSynchronizeError != NULL)
  6684. {
  6685. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6686. }
  6687. else
  6688. {
  6689. DebugAssert(FErrorList != NULL);
  6690. TStringList * MoreMessagesCopy = NULL;
  6691. if (MoreMessages)
  6692. {
  6693. MoreMessagesCopy = new TStringList();
  6694. MoreMessagesCopy->Assign(MoreMessages);
  6695. }
  6696. FErrorList->AddObject(Message, MoreMessagesCopy);
  6697. }
  6698. PopupTrayBalloon(Terminal, Message, Type);
  6699. return ContinueAnswer(Answers);
  6700. }
  6701. else
  6702. {
  6703. bool UseBalloon = FTrayIcon->Visible;
  6704. if (UseBalloon)
  6705. {
  6706. PopupTrayBalloon(Terminal, Message, Type);
  6707. }
  6708. unsigned int Result;
  6709. try
  6710. {
  6711. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6712. }
  6713. __finally
  6714. {
  6715. // cancel only balloon we popped up, otherwise we may cancel notification
  6716. // balloon that was there before the message dialog
  6717. // (such as "dd confirmation opt in balloon)
  6718. if (UseBalloon)
  6719. {
  6720. FTrayIcon->CancelBalloon();
  6721. }
  6722. }
  6723. return Result;
  6724. }
  6725. }
  6726. //---------------------------------------------------------------------------
  6727. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6728. TTerminal * Terminal, Exception * E)
  6729. {
  6730. if (FTrayIcon->Visible)
  6731. {
  6732. PopupTrayBalloon(Terminal, L"", qtError, E);
  6733. }
  6734. // particularly prevent opening new session from jump list,
  6735. // while exception is shown
  6736. NonVisualDataModule->StartBusy();
  6737. try
  6738. {
  6739. ShowExtendedExceptionEx(Terminal, E);
  6740. }
  6741. __finally
  6742. {
  6743. NonVisualDataModule->EndBusy();
  6744. FTrayIcon->CancelBalloon();
  6745. }
  6746. }
  6747. //---------------------------------------------------------------------------
  6748. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6749. {
  6750. if (Terminal->Active)
  6751. {
  6752. InitStatusBar();
  6753. }
  6754. // cannot rely on active page being page for active terminal,
  6755. // as it can happen that active page is the "new session" page
  6756. // (e.g. when reconnecting active terminal, while login dialog
  6757. // invoked from "new session" page is modal)
  6758. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6759. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6760. }
  6761. //---------------------------------------------------------------------------
  6762. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6763. TTerminal * Terminal, Exception * E)
  6764. {
  6765. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6766. if (!Terminal->Active)
  6767. {
  6768. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6769. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6770. {
  6771. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6772. }
  6773. }
  6774. }
  6775. //---------------------------------------------------------------------------
  6776. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6777. UnicodeString Message, TQueryType Type,
  6778. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6779. {
  6780. if ((E == NULL) ||
  6781. ExceptionMessage(E, Message))
  6782. {
  6783. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6784. if (Important)
  6785. {
  6786. Seconds *= 5;
  6787. }
  6788. UnicodeString NoteMessage(UnformatMessage(Message));
  6789. if (Terminal != NULL)
  6790. {
  6791. NoteMessage = FORMAT(L"%s: %s",
  6792. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6793. }
  6794. if (WinConfiguration->BalloonNotifications)
  6795. {
  6796. AddNote(NoteMessage);
  6797. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6798. }
  6799. else
  6800. {
  6801. FlashOnBackground();
  6802. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6803. }
  6804. }
  6805. }
  6806. //---------------------------------------------------------------------------
  6807. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6808. {
  6809. RestoreApp();
  6810. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6811. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6812. !NonVisualDataModule->Busy)
  6813. {
  6814. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6815. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6816. if (!ComponentVisible[fcQueueView])
  6817. {
  6818. ToggleQueueVisibility();
  6819. GoToQueue();
  6820. }
  6821. }
  6822. }
  6823. //---------------------------------------------------------------------------
  6824. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6825. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6826. {
  6827. UnicodeString Message;
  6828. TNotifyEvent OnClick = NULL;
  6829. TObject * UserData = NULL;
  6830. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6831. switch (Event)
  6832. {
  6833. case qeEmptyButMonitored:
  6834. if ((ATerminal != Terminal) || QueueInvisible)
  6835. {
  6836. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6837. OnClick = QueueEmptyNoteClicked;
  6838. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6839. TerminalNoteData->Terminal = ATerminal;
  6840. UserData = TerminalNoteData;
  6841. }
  6842. break;
  6843. case qeEmpty:
  6844. OperationComplete(ATerminal->QueueOperationStart);
  6845. break;
  6846. case qePendingUserAction:
  6847. if ((ATerminal != Terminal) ||
  6848. (QueueInvisible && !IsQueueAutoPopup()))
  6849. {
  6850. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6851. }
  6852. break;
  6853. default:
  6854. DebugFail();
  6855. }
  6856. if (!Message.IsEmpty())
  6857. {
  6858. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6859. }
  6860. }
  6861. //---------------------------------------------------------------------------
  6862. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6863. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6864. {
  6865. if (FDDExtMapFile != NULL)
  6866. {
  6867. CloseHandle(FDDExtMapFile);
  6868. FDDExtMapFile = NULL;
  6869. }
  6870. if (WinConfiguration->DDFakeFile)
  6871. {
  6872. DDFakeFileInitDrag(FileList, Created);
  6873. }
  6874. }
  6875. //---------------------------------------------------------------------------
  6876. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6877. {
  6878. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6879. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6880. {
  6881. FFakeFileDropTarget = FileName;
  6882. }
  6883. }
  6884. //---------------------------------------------------------------------------
  6885. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6886. {
  6887. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6888. if (!ForceDirectories(ApiPath(Result)))
  6889. {
  6890. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6891. }
  6892. FileSetAttr(ApiPath(Result), faHidden);
  6893. return Result;
  6894. }
  6895. //---------------------------------------------------------------------------
  6896. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6897. bool & Created)
  6898. {
  6899. FFakeFileDropTarget = UnicodeString();
  6900. FDragFakeDirectory = CreateFakeTransferDirectory();
  6901. FileList->AddItem(NULL, FDragFakeDirectory);
  6902. Created = true;
  6903. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6904. {
  6905. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6906. }
  6907. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6908. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6909. {
  6910. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6911. TDragExtCommStruct* CommStruct;
  6912. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6913. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6914. DebugAssert(CommStruct != NULL);
  6915. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6916. CommStruct->Dragging = true;
  6917. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6918. LENOF(CommStruct->DropDest));
  6919. NULL_TERMINATE(CommStruct->DropDest);
  6920. UnmapViewOfFile(CommStruct);
  6921. }
  6922. }
  6923. //---------------------------------------------------------------------------
  6924. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6925. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6926. {
  6927. bool Result;
  6928. DebugAssert(!IsLocalBrowserMode());
  6929. if (Sender == RemoteDirView)
  6930. {
  6931. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6932. }
  6933. else
  6934. {
  6935. DebugAssert(Sender == RemoteDriveView);
  6936. TStrings * FileList = RemoteDriveView->DragFileList();
  6937. try
  6938. {
  6939. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6940. }
  6941. __finally
  6942. {
  6943. delete FileList;
  6944. }
  6945. }
  6946. if (FDDTargetControl == RemoteDriveView)
  6947. {
  6948. RemoteDriveView->UpdateDropTarget();
  6949. }
  6950. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6951. // or from tree view to dir view.
  6952. // foMove happens when file/dir is dragged from remote tree view outside of
  6953. // application via dragex
  6954. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6955. (DropSourceControl == RemoteDriveView))
  6956. {
  6957. RemoteDriveView->UpdateDropSource();
  6958. }
  6959. return Result;
  6960. }
  6961. //---------------------------------------------------------------------------
  6962. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6963. {
  6964. DebugAssert(!IsLocalBrowserMode());
  6965. // This also handles drops of remote files to queue.
  6966. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6967. SAFE_DESTROY(FDDFileList);
  6968. if (!FFakeFileDropTarget.IsEmpty())
  6969. {
  6970. RemoveDir(ApiPath(FFakeFileDropTarget));
  6971. }
  6972. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6973. {
  6974. try
  6975. {
  6976. TDragResult DDResult = (Sender == RemoteDirView) ?
  6977. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6978. // Focus is moved to the target application,
  6979. // but as we are going to present the UI, we need to steal the focus back.
  6980. // This most likely won't work though (windows does not allow application
  6981. // to steal focus most of the time)
  6982. Application->BringToFront();
  6983. // On older version of Windows we never got drMove here, see also comment below.
  6984. // On Windows 10, we get the "move".
  6985. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6986. {
  6987. UnicodeString TargetDirectory;
  6988. TFileOperation Operation;
  6989. // drInvalid may mean drMove, see comment below
  6990. switch (DDResult)
  6991. {
  6992. case drCopy:
  6993. Operation = foCopy;
  6994. break;
  6995. case drMove:
  6996. Operation = foMove;
  6997. break;
  6998. default:
  6999. DebugFail();
  7000. case drInvalid:
  7001. // prefer "copy" for safety
  7002. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7003. break;
  7004. }
  7005. TTransferOperationParam Param;
  7006. UnicodeString CounterName;
  7007. bool ForceQueue;
  7008. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7009. {
  7010. // we get drInvalid both if d&d was intercepted by ddext,
  7011. // and when users drops on no-drop location.
  7012. // we tell the difference by existence of response from ddext,
  7013. // so we ignore absence of response in this case
  7014. if (DDResult != drInvalid)
  7015. {
  7016. // here we know that the extension is installed,
  7017. // as it is checked as soon as drag&drop starts from
  7018. // RemoteFileControlDDCreateDragFileList
  7019. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7020. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7021. {
  7022. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7023. }
  7024. else
  7025. {
  7026. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7027. }
  7028. }
  7029. }
  7030. else
  7031. {
  7032. // download using fake file
  7033. Param.Temp = false;
  7034. Param.DragDrop = true;
  7035. if (ForceQueue)
  7036. {
  7037. Param.Queue = asOn;
  7038. }
  7039. if (Sender == RemoteDirView)
  7040. {
  7041. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7042. }
  7043. if (RemoteFileControlFileOperation(Sender, Operation,
  7044. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7045. {
  7046. Configuration->Usage->Inc(CounterName);
  7047. }
  7048. }
  7049. }
  7050. }
  7051. __finally
  7052. {
  7053. CloseHandle(FDDExtMapFile);
  7054. FDDExtMapFile = NULL;
  7055. delete FDragFakeMonitors;
  7056. FDragFakeMonitors = NULL;
  7057. RemoveDir(ApiPath(FDragFakeDirectory));
  7058. FDragFakeDirectory = L"";
  7059. FFakeFileDropTarget = UnicodeString();
  7060. }
  7061. }
  7062. if (FDragDropSshTerminate.get() != NULL)
  7063. {
  7064. FDragDropSshTerminate->Rethrow();
  7065. }
  7066. }
  7067. //---------------------------------------------------------------------------
  7068. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7069. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7070. {
  7071. // Remember drop effect so we know (when user drops files), if we copy or move
  7072. FLastDropEffect = dwEffect;
  7073. }
  7074. //---------------------------------------------------------------------------
  7075. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7076. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7077. {
  7078. bool Result;
  7079. if (FDDTargetControl == QueueView3)
  7080. {
  7081. Directory = DefaultDownloadTargetDirectory();
  7082. Result = true;
  7083. CounterName = L"DownloadsDragDropQueue";
  7084. ForceQueue = true;
  7085. }
  7086. else if (!FFakeFileDropTarget.IsEmpty())
  7087. {
  7088. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7089. Result = true;
  7090. ForceQueue = false;
  7091. CounterName = L"DownloadsDragDropFakeFile";
  7092. }
  7093. else
  7094. {
  7095. ForceQueue = false;
  7096. Enabled = false;
  7097. try
  7098. {
  7099. int Timer = 0;
  7100. Result = false;
  7101. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7102. {
  7103. {
  7104. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7105. TDragExtCommStruct* CommStruct;
  7106. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7107. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7108. DebugAssert(CommStruct != NULL);
  7109. Result = !CommStruct->Dragging;
  7110. if (Result)
  7111. {
  7112. Directory = ExtractFilePath(CommStruct->DropDest);
  7113. CounterName = L"DownloadsDragDropExternalExt";
  7114. }
  7115. UnmapViewOfFile(CommStruct);
  7116. }
  7117. if (!Result)
  7118. {
  7119. Sleep(50);
  7120. Timer += 50;
  7121. Application->ProcessMessages();
  7122. }
  7123. }
  7124. }
  7125. __finally
  7126. {
  7127. Enabled = true;
  7128. }
  7129. }
  7130. return Result;
  7131. }
  7132. //---------------------------------------------------------------------------
  7133. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7134. const UnicodeString TempDir, int SecDelay)
  7135. {
  7136. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7137. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7138. if (FDelayedDeletionTimer == NULL)
  7139. {
  7140. DebugAssert(HandleAllocated());
  7141. FDelayedDeletionTimer = new TTimer(this);
  7142. FDelayedDeletionTimer->Interval = 10000;
  7143. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7144. }
  7145. else
  7146. {
  7147. FDelayedDeletionTimer->Enabled = true;
  7148. }
  7149. }
  7150. //---------------------------------------------------------------------------
  7151. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7152. {
  7153. DebugAssert(FDelayedDeletionList != NULL);
  7154. TDateTime N = Now();
  7155. TDateTime Alert;
  7156. UnicodeString Directory;
  7157. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7158. {
  7159. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7160. if ((N >= Alert) || (Sender == NULL))
  7161. {
  7162. Directory = FDelayedDeletionList->Strings[Index];
  7163. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7164. {
  7165. FDelayedDeletionList->Delete(Index);
  7166. }
  7167. }
  7168. }
  7169. if (FDelayedDeletionList->Count == 0)
  7170. {
  7171. FDelayedDeletionTimer->Enabled = false;
  7172. }
  7173. }
  7174. //---------------------------------------------------------------------------
  7175. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7176. {
  7177. DebugAssert(!IsLocalBrowserMode());
  7178. if (IsFileControl(FDDTargetControl, osRemote) ||
  7179. (FDDTargetControl == SessionsPageControl))
  7180. {
  7181. TTerminal * TargetTerminal = NULL;
  7182. TFileOperation Operation = foNone;
  7183. if (FDDTargetControl == SessionsPageControl)
  7184. {
  7185. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7186. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7187. // do not allow dropping on the "+" tab
  7188. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7189. if (TargetTerminal != NULL)
  7190. {
  7191. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7192. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7193. {
  7194. Operation = foRemoteMove;
  7195. }
  7196. else
  7197. {
  7198. Operation = foRemoteCopy;
  7199. }
  7200. }
  7201. }
  7202. else
  7203. {
  7204. if (FLastDropEffect == DROPEFFECT_MOVE)
  7205. {
  7206. Operation = foRemoteMove;
  7207. }
  7208. else if (FLastDropEffect == DROPEFFECT_COPY)
  7209. {
  7210. Operation = foRemoteCopy;
  7211. }
  7212. }
  7213. if (Operation != foNone)
  7214. {
  7215. RemoteFileControlFileOperation(DropSourceControl,
  7216. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7217. }
  7218. // abort drag&drop
  7219. Abort();
  7220. }
  7221. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7222. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7223. (FDDTargetControl != QueueView3))
  7224. {
  7225. DebugAssert(!FDragTempDir.IsEmpty());
  7226. TTransferType Type;
  7227. UnicodeString TempDir = FDragTempDir;
  7228. // We clear FDragTempDir before calling
  7229. // just in case it fail (raises exception)
  7230. FDragTempDir = L"";
  7231. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7232. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7233. // empty directory parameter means temp directory -> don't display it!
  7234. UnicodeString TargetDir = L"";
  7235. int Options = 0;
  7236. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7237. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7238. {
  7239. Abort();
  7240. }
  7241. // TargetDir is set when dropped on local file control
  7242. // (this was workaround for legacy dirview event handling, now it should be
  7243. // made prettier)
  7244. if (TargetDir.IsEmpty())
  7245. {
  7246. TargetDir = TempDir;
  7247. if (ForceDirectories(ApiPath(TargetDir)))
  7248. {
  7249. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7250. FPendingTempSpaceWarn = true;
  7251. try
  7252. {
  7253. FDragDropOperation = true;
  7254. int Params = cpTemporary |
  7255. (Type == ttMove ? cpDelete : 0);
  7256. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7257. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7258. }
  7259. __finally
  7260. {
  7261. FDragDropOperation = false;
  7262. FPendingTempSpaceWarn = false;
  7263. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7264. }
  7265. }
  7266. else
  7267. {
  7268. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7269. }
  7270. }
  7271. }
  7272. }
  7273. //---------------------------------------------------------------------------
  7274. void __fastcall TCustomScpExplorerForm::DDDownload(
  7275. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7276. {
  7277. DebugAssert(!IsLocalBrowserMode());
  7278. TAutoBatch AutoBatch(this);
  7279. UpdateCopyParamCounters(*CopyParam);
  7280. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7281. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7282. {
  7283. RemoteDriveView->UpdateDropSource();
  7284. }
  7285. }
  7286. //---------------------------------------------------------------------------
  7287. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7288. {
  7289. public:
  7290. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7291. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7292. {
  7293. }
  7294. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7295. {
  7296. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7297. TDataObjectFilesEx::AllowData(FormatEtc);
  7298. }
  7299. };
  7300. //---------------------------------------------------------------------------
  7301. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7302. TObject * Sender, TDataObject *& DataObject)
  7303. {
  7304. if (FDDExtMapFile != NULL)
  7305. {
  7306. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7307. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7308. {
  7309. Abort();
  7310. }
  7311. if (FileList->Count > 0)
  7312. {
  7313. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7314. if (!FilesObject->IsValid(true, true))
  7315. {
  7316. FilesObject->_Release();
  7317. }
  7318. else
  7319. {
  7320. DataObject = FilesObject;
  7321. }
  7322. }
  7323. }
  7324. }
  7325. //---------------------------------------------------------------------------
  7326. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7327. {
  7328. DebugFail();
  7329. }
  7330. //---------------------------------------------------------------------------
  7331. void __fastcall TCustomScpExplorerForm::GoToTree()
  7332. {
  7333. ComponentVisible[fcRemoteTree] = true;
  7334. DriveView(osRemote)->SetFocus();
  7335. }
  7336. //---------------------------------------------------------------------------
  7337. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7338. TPanelExport Export)
  7339. {
  7340. TCustomDirView * DirView = this->DirView(Side);
  7341. std::unique_ptr<TStrings> ExportData(new TStringList());
  7342. switch (Export)
  7343. {
  7344. case pePath:
  7345. ExportData->Add(DirView->PathName);
  7346. break;
  7347. case peFileList:
  7348. case peFullFileList:
  7349. {
  7350. bool FullPath = (Export == peFullFileList);
  7351. DirView->CreateFileList(false, FullPath, ExportData.get());
  7352. for (int Index = 0; Index < ExportData->Count; Index++)
  7353. {
  7354. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7355. {
  7356. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7357. }
  7358. }
  7359. }
  7360. break;
  7361. default:
  7362. DebugFail();
  7363. }
  7364. return ExportData.release();
  7365. }
  7366. //---------------------------------------------------------------------------
  7367. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7368. TPanelExport Export, TPanelExportDestination Destination)
  7369. {
  7370. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7371. PanelExportStore(Side, Export, Destination, ExportData.get());
  7372. }
  7373. //---------------------------------------------------------------------------
  7374. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7375. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7376. TStrings * ExportData)
  7377. {
  7378. if (Destination == pedClipboard)
  7379. {
  7380. TInstantOperationVisualizer Visualizer;
  7381. CopyToClipboard(ExportData);
  7382. }
  7383. else
  7384. {
  7385. DebugFail();
  7386. }
  7387. }
  7388. //---------------------------------------------------------------------------
  7389. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7390. {
  7391. TCustomDirView * DirView = this->DirView(Side);
  7392. UnicodeString Mask = DirView->Mask;
  7393. if (DoFilterMaskDialog(DirView, Mask))
  7394. {
  7395. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7396. Configuration->Usage->Inc(L"Filters");
  7397. }
  7398. }
  7399. //---------------------------------------------------------------------------
  7400. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7401. {
  7402. return FQueueController->DefaultOperation();
  7403. }
  7404. //---------------------------------------------------------------------------
  7405. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7406. TQueueOperation Operation, void ** Param)
  7407. {
  7408. switch (Operation)
  7409. {
  7410. case qoPreferences:
  7411. return true;
  7412. case qoGoTo:
  7413. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7414. case qoOnceEmpty:
  7415. return IsAnythingQueued();
  7416. default:
  7417. return FQueueController->AllowOperation(Operation, Param);
  7418. }
  7419. }
  7420. //---------------------------------------------------------------------------
  7421. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7422. {
  7423. if (DebugAlwaysTrue(QueueView3->Visible))
  7424. {
  7425. QueueView3->SetFocus();
  7426. }
  7427. }
  7428. //---------------------------------------------------------------------------
  7429. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7430. TQueueOperation Operation, void * Param)
  7431. {
  7432. if (Operation == qoGoTo)
  7433. {
  7434. GoToQueue();
  7435. }
  7436. else if (Operation == qoPreferences)
  7437. {
  7438. PreferencesDialog(pmQueue);
  7439. }
  7440. else
  7441. {
  7442. FQueueController->ExecuteOperation(Operation, Param);
  7443. }
  7444. }
  7445. //---------------------------------------------------------------------------
  7446. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7447. {
  7448. return (Queue != NULL) && Queue->Enabled;
  7449. }
  7450. //---------------------------------------------------------------------------
  7451. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7452. {
  7453. DebugAssert(Queue != NULL);
  7454. if (Queue != NULL)
  7455. {
  7456. Queue->Enabled = !Queue->Enabled;
  7457. }
  7458. }
  7459. //---------------------------------------------------------------------------
  7460. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7461. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7462. {
  7463. FQueueActedItem = QueueView3->ItemFocused;
  7464. }
  7465. //---------------------------------------------------------------------------
  7466. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7467. {
  7468. return TopDock->Height + QueueSplitter->Height;
  7469. }
  7470. //---------------------------------------------------------------------------
  7471. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7472. {
  7473. return
  7474. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7475. (QueueDock->Visible ? QueueDock->Height : 0) +
  7476. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7477. }
  7478. //---------------------------------------------------------------------------
  7479. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7480. {
  7481. return ScaleByTextHeight(this, 48);
  7482. }
  7483. //---------------------------------------------------------------------------
  7484. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7485. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7486. {
  7487. // when queue is hidden by double-clicking splitter, stray attempt to
  7488. // resize the panel with strange value arrives, make sure it is ignored
  7489. if (ComponentVisible[fcQueueView])
  7490. {
  7491. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7492. if (NewSize > MaxHeightLimit)
  7493. {
  7494. NewSize = MaxHeightLimit;
  7495. }
  7496. int MinHeightLimit =
  7497. GetStaticQueuePanelComponentsHeight() +
  7498. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7499. GetMinQueueViewHeight();
  7500. if (NewSize < MinHeightLimit)
  7501. {
  7502. NewSize = MinHeightLimit;
  7503. }
  7504. }
  7505. else
  7506. {
  7507. Accept = false;
  7508. }
  7509. }
  7510. //---------------------------------------------------------------------------
  7511. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7512. {
  7513. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7514. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7515. if (QueueViewHeight < GetMinQueueViewHeight())
  7516. {
  7517. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7518. }
  7519. }
  7520. //---------------------------------------------------------------------------
  7521. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7522. TDragObject *& /*DragObject*/)
  7523. {
  7524. FQueueActedItem = QueueView3->ItemFocused;
  7525. }
  7526. //---------------------------------------------------------------------------
  7527. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7528. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7529. {
  7530. Accept = true;
  7531. if (Source == QueueView3)
  7532. {
  7533. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7534. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7535. if (Accept)
  7536. {
  7537. TQueueItemProxy * QueueItem;
  7538. TQueueItemProxy * DestQueueItem;
  7539. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7540. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7541. Accept = (QueueItem != DestQueueItem) &&
  7542. (QueueItem->Status == TQueueItem::qsPending) &&
  7543. (DestQueueItem->Status == TQueueItem::qsPending);
  7544. }
  7545. }
  7546. }
  7547. //---------------------------------------------------------------------------
  7548. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7549. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7550. {
  7551. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7552. {
  7553. TQueueItemProxy * QueueItem;
  7554. TQueueItemProxy * DestQueueItem;
  7555. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7556. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7557. QueueItem->Move(DestQueueItem);
  7558. }
  7559. }
  7560. //---------------------------------------------------------------------------
  7561. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7562. {
  7563. if ((QueueView3->ItemFocused == NULL) &&
  7564. (QueueView3->Items->Count > 0))
  7565. {
  7566. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7567. }
  7568. QueueLabelUpdateStatus();
  7569. }
  7570. //---------------------------------------------------------------------------
  7571. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7572. {
  7573. QueueLabelUpdateStatus();
  7574. }
  7575. //---------------------------------------------------------------------------
  7576. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7577. {
  7578. QueueLabel->UpdateStatus();
  7579. }
  7580. //---------------------------------------------------------------------------
  7581. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7582. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7583. {
  7584. if (Selected)
  7585. {
  7586. NonVisualDataModule->UpdateNonVisibleActions();
  7587. }
  7588. }
  7589. //---------------------------------------------------------------------------
  7590. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7591. {
  7592. TDragDropFilesEx * Result = NULL;
  7593. if (Sender == SessionsPageControl)
  7594. {
  7595. Result = FSessionsDragDropFilesEx;
  7596. }
  7597. else if (Sender == QueueView3)
  7598. {
  7599. Result = FQueueDragDropFilesEx;
  7600. }
  7601. else
  7602. {
  7603. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7604. if (DirView != NULL)
  7605. {
  7606. Result = DirView->DragDropFilesEx;
  7607. }
  7608. else
  7609. {
  7610. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7611. if (DriveView != NULL)
  7612. {
  7613. Result = DriveView->DragDropFilesEx;
  7614. }
  7615. }
  7616. }
  7617. DebugAssert(Result != NULL);
  7618. return Result;
  7619. }
  7620. //---------------------------------------------------------------------------
  7621. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7622. {
  7623. return (DView->SelCount == DView->FilesCount);
  7624. }
  7625. //---------------------------------------------------------------------------
  7626. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7627. {
  7628. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7629. }
  7630. //---------------------------------------------------------------------------
  7631. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7632. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7633. {
  7634. DebugAssert(!IsLocalBrowserMode());
  7635. TFileOperation Operation;
  7636. switch (Effect)
  7637. {
  7638. case DROPEFFECT_MOVE:
  7639. Operation = foMove;
  7640. break;
  7641. case DROPEFFECT_COPY:
  7642. // occures on WinXP (reported by user)
  7643. default:
  7644. Operation = foCopy;
  7645. break;
  7646. };
  7647. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7648. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7649. if (DragDropFilesEx->FileList->Count > 0)
  7650. {
  7651. TStrings * FileList = new TStringList();
  7652. try
  7653. {
  7654. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7655. {
  7656. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7657. }
  7658. FDragDropOperation = true;
  7659. TTransferOperationParam Param;
  7660. Param.TargetDirectory = TargetPath;
  7661. // upload, no temp dirs
  7662. Param.Temp = false;
  7663. Param.DragDrop = DragDrop;
  7664. Param.Options =
  7665. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7666. if (ForceQueue)
  7667. {
  7668. Param.Queue = asOn;
  7669. }
  7670. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7671. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7672. {
  7673. if (IsFileControl(DropSourceControl, osLocal))
  7674. {
  7675. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7676. }
  7677. else
  7678. {
  7679. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7680. }
  7681. }
  7682. }
  7683. __finally
  7684. {
  7685. FDragDropOperation = false;
  7686. delete FileList;
  7687. }
  7688. }
  7689. }
  7690. //---------------------------------------------------------------------------
  7691. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7692. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7693. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7694. {
  7695. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7696. }
  7697. //---------------------------------------------------------------------------
  7698. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7699. TObject * Sender, int grfKeyState, int & dwEffect)
  7700. {
  7701. DebugAssert(!IsLocalBrowserMode());
  7702. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7703. if ((dwEffect != DROPEFFECT_NONE) &&
  7704. IsFileControl(DropSourceControl, osRemote))
  7705. {
  7706. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7707. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7708. (RemoteDirView->DropTarget == NULL))
  7709. {
  7710. dwEffect = DROPEFFECT_NONE;
  7711. }
  7712. else
  7713. {
  7714. if (dwEffect == DROPEFFECT_COPY)
  7715. {
  7716. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7717. // currently we support copying always (at least via temporary directory);
  7718. // remove associated checks once this all proves stable and working
  7719. bool CopyCapable = true;
  7720. // if we do not support neither of operations, there's no discussion
  7721. if (!MoveCapable && !CopyCapable)
  7722. {
  7723. dwEffect = DROPEFFECT_NONE;
  7724. }
  7725. else
  7726. {
  7727. // The default effect inside remote panel is move,
  7728. // unless we do not support it, but support copy
  7729. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7730. {
  7731. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7732. }
  7733. else
  7734. {
  7735. // with ctrl-down, we want copy unless it is not supported
  7736. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7737. }
  7738. }
  7739. }
  7740. }
  7741. }
  7742. }
  7743. //---------------------------------------------------------------------------
  7744. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7745. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7746. {
  7747. DebugAssert(!IsLocalBrowserMode());
  7748. if (FDDTotalSize >= 0)
  7749. {
  7750. if (File->IsDirectory)
  7751. {
  7752. FDDTotalSize = -1;
  7753. }
  7754. else
  7755. {
  7756. FDDTotalSize += File->Size;
  7757. }
  7758. }
  7759. DebugAssert(!FDragTempDir.IsEmpty());
  7760. // TODO: this is quite ineffective
  7761. // TODO: what if invalid character replacement is disabled?
  7762. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7763. UnicodeString TransferFileName;
  7764. if (Sender == RemoteDriveView)
  7765. {
  7766. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7767. }
  7768. else
  7769. {
  7770. TransferFileName = File->FileName;
  7771. }
  7772. FDDFileList->AddObject(TransferFileName, File);
  7773. }
  7774. //---------------------------------------------------------------------------
  7775. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7776. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7777. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7778. {
  7779. // sometimes we do not get DDEnd so the list is not released
  7780. SAFE_DESTROY(FDDFileList);
  7781. FDDFileList = new TStringList();
  7782. FDragTempDir = WinConfiguration->TemporaryDir();
  7783. FDDTotalSize = 0;
  7784. FDragDropSshTerminate.reset(NULL);
  7785. }
  7786. //---------------------------------------------------------------------------
  7787. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7788. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7789. HRESULT & Result)
  7790. {
  7791. if (Result == DRAGDROP_S_DROP)
  7792. {
  7793. try
  7794. {
  7795. GlobalDragImageList->HideDragImage();
  7796. try
  7797. {
  7798. RemoteFileControlDDTargetDrop();
  7799. }
  7800. catch(ESshTerminate & E)
  7801. {
  7802. FDragDropSshTerminate.reset(E.Clone());
  7803. }
  7804. }
  7805. catch (Exception &E)
  7806. {
  7807. // If downloading fails we need to cancel drag&drop, otherwise
  7808. // Explorer shows error
  7809. // But by the way exception probably never reach this point as
  7810. // it's catched on way.
  7811. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7812. Result = DRAGDROP_S_CANCEL;
  7813. ShowExtendedException(Terminal, &E);
  7814. }
  7815. }
  7816. }
  7817. //---------------------------------------------------------------------------
  7818. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7819. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7820. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7821. {
  7822. TFileMasks::TParams MaskParams;
  7823. MaskParams.Size = Size;
  7824. MaskParams.Modification = Modification;
  7825. // this does not re-parse the mask if it is the same as the last time
  7826. FDirViewMatchMask = Masks;
  7827. bool ImplicitMatch;
  7828. Matches =
  7829. // RecurseInclude parameter has no effect as the Path is empty
  7830. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7831. (AllowImplicitMatches || !ImplicitMatch);
  7832. }
  7833. //---------------------------------------------------------------------------
  7834. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7835. TObject * Sender, TListItem * Item, WORD & Indexes)
  7836. {
  7837. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7838. UnicodeString Ext;
  7839. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7840. {
  7841. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7842. }
  7843. else
  7844. {
  7845. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7846. }
  7847. if (SameText(Ext, Configuration->PartialExt))
  7848. {
  7849. Indexes |= oiPartial;
  7850. }
  7851. }
  7852. //---------------------------------------------------------------------------
  7853. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7854. {
  7855. return
  7856. DirViewEnabled(osCurrent) &&
  7857. DirView(osCurrent)->CanPasteFromClipBoard();
  7858. }
  7859. //---------------------------------------------------------------------------
  7860. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7861. {
  7862. bool Result = false;
  7863. if (CanPasteToDirViewFromClipBoard())
  7864. {
  7865. Result = true;
  7866. }
  7867. else
  7868. {
  7869. UnicodeString ClipboardText;
  7870. if (NonEmptyTextFromClipboard(ClipboardText) &&
  7871. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  7872. {
  7873. if (StoredSessions->IsUrl(ClipboardText))
  7874. {
  7875. Result = true;
  7876. }
  7877. else
  7878. {
  7879. Result = DirViewEnabled(osCurrent);
  7880. }
  7881. }
  7882. }
  7883. return Result;
  7884. }
  7885. //---------------------------------------------------------------------------
  7886. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7887. {
  7888. if (DoesClipboardContainOurFiles())
  7889. {
  7890. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7891. {
  7892. DebugAssert(!IsLocalBrowserMode());
  7893. TTerminalManager * Manager = TTerminalManager::Instance();
  7894. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7895. Manager->ActiveTerminal = FClipboardTerminal;
  7896. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7897. }
  7898. }
  7899. else if (CanPasteToDirViewFromClipBoard())
  7900. {
  7901. DirView(osCurrent)->PasteFromClipBoard();
  7902. }
  7903. else
  7904. {
  7905. UnicodeString ClipboardText;
  7906. if (NonEmptyTextFromClipboard(ClipboardText))
  7907. {
  7908. if (StoredSessions->IsUrl(ClipboardText))
  7909. {
  7910. NewSession(false, ClipboardText);
  7911. }
  7912. else
  7913. {
  7914. DirView(osCurrent)->Path = ClipboardText;
  7915. }
  7916. }
  7917. }
  7918. }
  7919. //---------------------------------------------------------------------------
  7920. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7921. {
  7922. // TBD
  7923. }
  7924. //---------------------------------------------------------------------------
  7925. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7926. {
  7927. TCustomDirView * ADirView = DirView(Side);
  7928. ADirView->SelectAll(Mode);
  7929. ADirView->SetFocus();
  7930. }
  7931. //---------------------------------------------------------------------------
  7932. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7933. {
  7934. TCustomDirView * ADirView = DirView(Side);
  7935. TFileFilter Filter;
  7936. DefaultFileFilter(Filter);
  7937. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7938. {
  7939. Configuration->Usage->Inc(L"MaskSelections");
  7940. ADirView->SelectFiles(Filter, Select);
  7941. ADirView->SetFocus();
  7942. }
  7943. }
  7944. //---------------------------------------------------------------------------
  7945. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7946. {
  7947. TCustomDirView * ADirView = DirView(Side);
  7948. ADirView->RestoreSelectedNames();
  7949. ADirView->SetFocus();
  7950. }
  7951. //---------------------------------------------------------------------------
  7952. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7953. {
  7954. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7955. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7956. {
  7957. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7958. UnicodeString Ext;
  7959. if (!IsSideLocalBrowser(osCurrent))
  7960. {
  7961. Ext = UnixExtractFileExt(FileName);
  7962. }
  7963. else
  7964. {
  7965. Ext = ExtractFileExt(FileName);
  7966. }
  7967. if (Ext.IsEmpty())
  7968. {
  7969. Ext = L".";
  7970. }
  7971. TFileFilter Filter;
  7972. Filter.Masks = FORMAT(L"*%s", (Ext));
  7973. Filter.Directories = false;
  7974. CurrentDirView->SelectFiles(Filter, Select);
  7975. }
  7976. }
  7977. //---------------------------------------------------------------------------
  7978. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7979. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7980. {
  7981. UnicodeString Result;
  7982. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7983. {
  7984. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  7985. }
  7986. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  7987. {
  7988. // noop
  7989. }
  7990. else
  7991. {
  7992. Result =
  7993. FMTLOAD(FILE_INFO_FORMAT,
  7994. (FormatBytes(FileInfo.SelectedSize),
  7995. FormatBytes(FileInfo.FilesSize),
  7996. FormatNumber(FileInfo.SelectedCount),
  7997. FormatNumber(FileInfo.FilesCount)));
  7998. }
  7999. return Result;
  8000. }
  8001. //---------------------------------------------------------------------------
  8002. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8003. TTBXStatusPanel * Panel, TOperationSide Side)
  8004. {
  8005. if (Panel->Index == 1)
  8006. {
  8007. ToggleShowHiddenFiles();
  8008. }
  8009. else if (Panel->Index == 2)
  8010. {
  8011. Filter(Side);
  8012. }
  8013. }
  8014. //---------------------------------------------------------------------------
  8015. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8016. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8017. {
  8018. DebugAssert(!StatusBar->SimplePanel);
  8019. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8020. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8021. }
  8022. //---------------------------------------------------------------------------
  8023. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8024. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8025. {
  8026. DebugAssert(StatusBar->Panels->Count >= 3);
  8027. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8028. if (FileInfo.HiddenCount > 0)
  8029. {
  8030. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8031. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8032. }
  8033. else
  8034. {
  8035. HiddenFilesPanel->ViewPriority = 0;
  8036. // not really necessary, just to cleanup no-longer-valid data
  8037. HiddenFilesPanel->Caption = L"";
  8038. }
  8039. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8040. if (FileInfo.FilteredCount > 0)
  8041. {
  8042. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8043. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8044. }
  8045. else
  8046. {
  8047. FilteredFilesPanel->ViewPriority = 0;
  8048. // not really necessary, just to cleanup no-longer-valid data
  8049. FilteredFilesPanel->Caption = L"";
  8050. }
  8051. }
  8052. //---------------------------------------------------------------------------
  8053. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8054. TObject * /*Sender*/)
  8055. {
  8056. if (DirView(osOther)->Enabled)
  8057. {
  8058. DirView(osOther)->SetFocus();
  8059. }
  8060. }
  8061. //---------------------------------------------------------------------------
  8062. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8063. {
  8064. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8065. switch (Config.Show)
  8066. {
  8067. case qvShow:
  8068. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8069. {
  8070. Config.Show = qvHide;
  8071. }
  8072. else
  8073. {
  8074. Config.Show = Config.LastHideShow;
  8075. }
  8076. break;
  8077. case qvHideWhenEmpty:
  8078. if (ComponentVisible[fcQueueView])
  8079. {
  8080. Config.Show = qvHide;
  8081. }
  8082. else
  8083. {
  8084. Config.LastHideShow = Config.Show;
  8085. Config.Show = qvShow;
  8086. }
  8087. break;
  8088. case qvHide:
  8089. Config.LastHideShow = Config.Show;
  8090. Config.Show = qvShow;
  8091. break;
  8092. }
  8093. WinConfiguration->QueueView = Config;
  8094. }
  8095. //---------------------------------------------------------------------------
  8096. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8097. {
  8098. UnicodeString Result;
  8099. if (FTerminal != NULL)
  8100. {
  8101. switch (WinConfiguration->PathInCaption)
  8102. {
  8103. case picShort:
  8104. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8105. break;
  8106. case picFull:
  8107. Result = FTerminal->CurrentDirectory;
  8108. break;
  8109. }
  8110. }
  8111. return Result;
  8112. }
  8113. //---------------------------------------------------------------------------
  8114. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8115. {
  8116. TColor Result = GetWindowColor(FSessionColor);
  8117. return Result;
  8118. }
  8119. //---------------------------------------------------------------------------
  8120. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8121. {
  8122. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8123. return Result;
  8124. }
  8125. //---------------------------------------------------------------------------
  8126. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8127. {
  8128. TTerminalManager::Instance()->UpdateAppTitle();
  8129. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8130. // background to gray on Windows 7 (works on Windows 10).
  8131. // See also EnableControl
  8132. if (Showing)
  8133. {
  8134. if (Terminal != NULL)
  8135. {
  8136. // Update path when it changes
  8137. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8138. {
  8139. UpdateSessionTab(SessionsPageControl->ActivePage);
  8140. }
  8141. }
  8142. NonVisualDataModule->ReconnectSessionAction->Update();
  8143. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8144. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8145. CenterReconnectToolbar();
  8146. bool HasTerminal = HasActiveTerminal();
  8147. RemoteDirView->Enabled = HasTerminal;
  8148. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8149. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8150. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8151. RemoteDriveView->Color = RemoteDirView->Color;
  8152. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8153. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8154. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8155. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8156. QueueFileList->Enabled = QueueView3->Enabled;
  8157. QueueFileList->Color = QueueView3->Color;
  8158. QueueFileList->Font->Color = QueueView3->Font->Color;
  8159. QueueLabelUpdateStatus();
  8160. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8161. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8162. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8163. }
  8164. }
  8165. //---------------------------------------------------------------------------
  8166. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8167. {
  8168. UpdateControls();
  8169. }
  8170. //---------------------------------------------------------------------------
  8171. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8172. TObject * Sender)
  8173. {
  8174. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8175. DebugAssert(DirView != NULL);
  8176. DoDirViewLoaded(DirView);
  8177. TransferPresetAutoSelect();
  8178. }
  8179. //---------------------------------------------------------------------------
  8180. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8181. {
  8182. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8183. // first run after installation
  8184. if (double(Updates.LastCheck) == 0)
  8185. {
  8186. // make sure next time there will be an update (if enabled)
  8187. Updates.LastCheck = TDateTime(1);
  8188. WinConfiguration->Updates = Updates;
  8189. }
  8190. else if ((double(Updates.Period) > 0) &&
  8191. (Now() - Updates.LastCheck >= Updates.Period))
  8192. {
  8193. TThreadMethod OnUpdatesChecked = NULL;
  8194. if (!IsUWP())
  8195. {
  8196. OnUpdatesChecked = UpdatesChecked;
  8197. }
  8198. StartUpdateThread(OnUpdatesChecked);
  8199. }
  8200. }
  8201. //---------------------------------------------------------------------------
  8202. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8203. {
  8204. UnicodeString Message;
  8205. bool New;
  8206. TQueryType Type;
  8207. GetUpdatesMessage(Message, New, Type, false);
  8208. if (!Message.IsEmpty())
  8209. {
  8210. if (New)
  8211. {
  8212. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8213. }
  8214. if (!New && (Type != qtWarning))
  8215. {
  8216. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8217. }
  8218. else
  8219. {
  8220. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8221. }
  8222. if (New)
  8223. {
  8224. Configuration->Usage->Inc(L"UpdateNotifications");
  8225. }
  8226. }
  8227. }
  8228. //---------------------------------------------------------------------------
  8229. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8230. {
  8231. RestoreApp();
  8232. bool CanDisplay = !NonVisualDataModule->Busy;
  8233. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8234. {
  8235. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8236. }
  8237. if (CanDisplay)
  8238. {
  8239. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8240. CheckForUpdates(true);
  8241. }
  8242. else
  8243. {
  8244. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8245. }
  8246. }
  8247. //---------------------------------------------------------------------------
  8248. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8249. TCopyParamRuleData & Data)
  8250. {
  8251. DebugAssert(Terminal != NULL);
  8252. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8253. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8254. Data.RemoteDirectory = RemoteDirView->PathName;
  8255. }
  8256. //---------------------------------------------------------------------------
  8257. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8258. {
  8259. // Terminal can be null when we are changing local directory implicitly,
  8260. // because it has been deleted, while no session is connected
  8261. // (Login dialog is open)
  8262. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8263. {
  8264. DebugAssert(!IsLocalBrowserMode());
  8265. TCopyParamRuleData Data;
  8266. GetTransferPresetAutoSelectData(Data);
  8267. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8268. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8269. if (CopyParamIndex < 0)
  8270. {
  8271. // there is no preset that matches autoselection
  8272. // set preset that we consider "default"
  8273. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8274. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8275. }
  8276. else
  8277. {
  8278. // there is preset matching autoselection
  8279. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8280. if (CopyParamName == FCopyParamAutoSelected)
  8281. {
  8282. // autoselected the same preset as the last time
  8283. // make no change (i.e. preserve custom user preset, if any)
  8284. }
  8285. else
  8286. {
  8287. // autoselected the different preset then the last time (or there
  8288. // was default preset set)
  8289. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8290. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8291. }
  8292. }
  8293. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8294. {
  8295. if (CopyParamIndex >= 0)
  8296. {
  8297. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8298. }
  8299. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8300. try
  8301. {
  8302. int Fmt =
  8303. (CopyParamIndex < 0) ?
  8304. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8305. COPY_PARAM_AUTOSELECTED;
  8306. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8307. Data->Message = MainInstructions(Message);
  8308. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8309. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8310. CopyParamAttrs);
  8311. if (CopyParamIndex >= 0)
  8312. {
  8313. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8314. Info = FORMAT(L"%s\n \n%s", (Info,
  8315. FMTLOAD(COPY_PARAM_RULE,
  8316. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8317. }
  8318. Data->Message += L"\n\n" + Info;
  8319. if (WinConfiguration->CopyParamAutoSelectNotice)
  8320. {
  8321. TransferPresetNoteMessage(Data, true);
  8322. }
  8323. else
  8324. {
  8325. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8326. Data = NULL; // ownership passed
  8327. }
  8328. }
  8329. __finally
  8330. {
  8331. delete Data;
  8332. }
  8333. }
  8334. }
  8335. }
  8336. //---------------------------------------------------------------------------
  8337. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8338. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8339. {
  8340. DebugAssert(NoteData != NULL);
  8341. DebugAssert(!IsLocalBrowserMode());
  8342. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8343. TQueryButtonAlias Aliases[1];
  8344. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8345. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8346. Params.Aliases = Aliases;
  8347. Params.AliasesCount = LENOF(Aliases);
  8348. unsigned int Result =
  8349. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8350. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8351. switch (Result)
  8352. {
  8353. case qaNeverAskAgain:
  8354. DebugAssert(AllowNeverAskAgain);
  8355. WinConfiguration->CopyParamAutoSelectNotice = false;
  8356. break;
  8357. case qaIgnore:
  8358. PreferencesDialog(pmPresets);
  8359. break;
  8360. }
  8361. }
  8362. //---------------------------------------------------------------------------
  8363. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8364. {
  8365. // as of now useless, as this is used for notes only, never for balloons, ...
  8366. RestoreApp();
  8367. // .. and we should never be busy here
  8368. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8369. {
  8370. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8371. }
  8372. }
  8373. //---------------------------------------------------------------------------
  8374. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8375. TPreferencesMode APreferencesMode)
  8376. {
  8377. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8378. TCopyParamRuleData Data;
  8379. if (Terminal != NULL)
  8380. {
  8381. PreferencesData.reset(new TPreferencesDialogData());
  8382. GetTransferPresetAutoSelectData(Data);
  8383. PreferencesData->CopyParamRuleData = &Data;
  8384. }
  8385. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8386. }
  8387. //---------------------------------------------------------------------------
  8388. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8389. const TCustomCommandType & Command)
  8390. {
  8391. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8392. {
  8393. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8394. }
  8395. }
  8396. //---------------------------------------------------------------------------
  8397. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8398. {
  8399. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8400. TCustomCommandType Command;
  8401. // make sure we use local custom command when remote are not supported
  8402. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8403. {
  8404. Command = FLastCustomCommand;
  8405. }
  8406. else
  8407. {
  8408. Command.Params = Command.Params | ccLocal;
  8409. }
  8410. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8411. FEditingFocusedAdHocCommand = OnFocused;
  8412. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8413. int Options =
  8414. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8415. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8416. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8417. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8418. {
  8419. FLastCustomCommand = Command;
  8420. UpdateCustomCommandsToolbar();
  8421. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8422. }
  8423. }
  8424. //---------------------------------------------------------------------------
  8425. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8426. {
  8427. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8428. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8429. DebugAssert(State > 0);
  8430. if (State <= 0)
  8431. {
  8432. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8433. }
  8434. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8435. }
  8436. //---------------------------------------------------------------------------
  8437. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8438. TCustomCommandType & Command, int & State)
  8439. {
  8440. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8441. if (Result)
  8442. {
  8443. Command = FLastCustomCommand;
  8444. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8445. }
  8446. return Result;
  8447. }
  8448. //---------------------------------------------------------------------------
  8449. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8450. {
  8451. ResetIncrementalSearch();
  8452. }
  8453. //---------------------------------------------------------------------------
  8454. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8455. {
  8456. DebugAssert(ComponentVisible[Component]);
  8457. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8458. }
  8459. //---------------------------------------------------------------------------
  8460. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8461. {
  8462. // when queue panel is resized here directly, the status bar is stretched
  8463. // over whole space the panel occupied
  8464. PostComponentHide(fcQueueView);
  8465. }
  8466. //---------------------------------------------------------------------------
  8467. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8468. {
  8469. ComponentVisible[fcQueueFileList] = false;
  8470. }
  8471. //---------------------------------------------------------------------------
  8472. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8473. {
  8474. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8475. RefreshColorMode();
  8476. ResetSysDarkTheme();
  8477. ConfigurationChanged();
  8478. ConfigureInterface();
  8479. // Should be called for all controls
  8480. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8481. }
  8482. //---------------------------------------------------------------------------
  8483. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8484. {
  8485. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8486. if (!FInvalid &&
  8487. (Message.LParam != 0) &&
  8488. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8489. {
  8490. ThemeChanged();
  8491. }
  8492. TForm::Dispatch(&Message);
  8493. }
  8494. //---------------------------------------------------------------------------
  8495. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8496. {
  8497. TMessage * M = static_cast<TMessage*>(Message);
  8498. switch (M->Msg)
  8499. {
  8500. case CM_DIALOGCHAR:
  8501. CMDialogChar(*M);
  8502. break;
  8503. case WM_APPCOMMAND:
  8504. WMAppCommand(*M);
  8505. break;
  8506. case WM_SYSCOMMAND:
  8507. WMSysCommand(*M);
  8508. break;
  8509. case WM_QUERYENDSESSION:
  8510. WMQueryEndSession(*M);
  8511. break;
  8512. case WM_ENDSESSION:
  8513. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8514. break;
  8515. #ifdef _DEBUG
  8516. case WM_WINDOWPOSCHANGED:
  8517. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8518. break;
  8519. case CM_CUSTOMSTYLECHANGED:
  8520. TForm::Dispatch(Message);
  8521. break;
  8522. #endif
  8523. case WM_COMPONENT_HIDE:
  8524. {
  8525. Byte Component = static_cast<Byte>(M->WParam);
  8526. // sanity check
  8527. if (ComponentVisible[Component])
  8528. {
  8529. // special treatment
  8530. if (Component == fcQueueView)
  8531. {
  8532. ToggleQueueVisibility();
  8533. DebugAssert(!ComponentVisible[fcQueueView]);
  8534. }
  8535. else
  8536. {
  8537. ComponentVisible[Component] = false;
  8538. }
  8539. }
  8540. }
  8541. break;
  8542. case WM_COPYDATA:
  8543. WMCopyData(*M);
  8544. break;
  8545. case WM_MANAGES_CAPTION:
  8546. // caption managed in TTerminalManager::UpdateAppTitle()
  8547. M->Result = 1;
  8548. break;
  8549. case WM_WANTS_MOUSEWHEEL:
  8550. M->Result = 1;
  8551. break;
  8552. case CM_SHOWINGCHANGED:
  8553. CMShowingChanged(*M);
  8554. break;
  8555. case WM_CLOSE:
  8556. WMClose(*M);
  8557. break;
  8558. case WM_DPICHANGED:
  8559. WMDpiChanged(*M);
  8560. break;
  8561. case CM_DPICHANGED:
  8562. CMDpiChanged(*M);
  8563. break;
  8564. case WM_SETTINGCHANGE:
  8565. WMSettingChange(*M);
  8566. break;
  8567. case CM_DIALOGKEY:
  8568. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8569. break;
  8570. default:
  8571. TForm::Dispatch(Message);
  8572. break;
  8573. }
  8574. }
  8575. //---------------------------------------------------------------------------
  8576. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8577. {
  8578. // noop
  8579. }
  8580. //---------------------------------------------------------------------------
  8581. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8582. {
  8583. TForm::Dispatch(&Message);
  8584. FSessionColors->Clear();
  8585. AddFixedSessionImages();
  8586. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8587. UpdateImages();
  8588. }
  8589. //---------------------------------------------------------------------------
  8590. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8591. {
  8592. TForm::Dispatch(&Message);
  8593. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8594. UpdatePixelsPerInchMainWindowCounter();
  8595. }
  8596. //---------------------------------------------------------------------------
  8597. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8598. {
  8599. // Cannot close window while we are busy.
  8600. // We cannot test this in FormCloseQuery as that is called also from
  8601. // Close(), which is called by CloseApplicationAction. So we can be busy
  8602. // there already even, when it is legitimate to close the application.
  8603. // Possibly a better place to handle this would be WMSysCommand.
  8604. if (NonVisualDataModule->Busy)
  8605. {
  8606. Message.Result = 1;
  8607. }
  8608. else
  8609. {
  8610. TForm::Dispatch(&Message);
  8611. }
  8612. }
  8613. //---------------------------------------------------------------------------
  8614. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8615. {
  8616. TForm::Dispatch(&Message);
  8617. if (Showing && (Terminal == NULL))
  8618. {
  8619. // When we are starting minimized (i.e. from an installer),
  8620. // postpone showing Login dialog until we get restored.
  8621. // Otherwise the Login dialog (and Authentication window) show restored
  8622. // over invisible (minimized) main window.
  8623. if (WindowState == wsMinimized)
  8624. {
  8625. FNeedSession = true;
  8626. }
  8627. else
  8628. {
  8629. // This happens before application ever goes idle, so the toolbars would
  8630. // stay enabled (initial state) until the Login dialog is dismissed.
  8631. UpdateActions();
  8632. NonVisualDataModule->StartBusy();
  8633. try
  8634. {
  8635. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8636. // otherwise the dialog does not receive focus.
  8637. // With Commander interface the ProcessMessages is called already
  8638. // by TDriveView, but with Explorer interface, we need to call it explicily
  8639. Application->ProcessMessages();
  8640. // do not reload sessions, they have been loaded just now (optimization)
  8641. NeedSession(true);
  8642. }
  8643. __finally
  8644. {
  8645. NonVisualDataModule->EndBusy();
  8646. }
  8647. }
  8648. }
  8649. }
  8650. //---------------------------------------------------------------------------
  8651. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8652. {
  8653. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8654. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8655. }
  8656. //---------------------------------------------------------------------------
  8657. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8658. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8659. int & MaxHeight)
  8660. {
  8661. // workaround for bug in TWinControl.CalcConstraints
  8662. // Check for empty rect (restore from iconic state) is done there only after
  8663. // call to AdjustClientRect, which enlarges the rect (for forms).
  8664. TRect R = GetClientRect();
  8665. // when restoring from iconic state, place no restrictions
  8666. if (IsRectEmpty(R))
  8667. {
  8668. MinWidth = 0;
  8669. MinHeight = 0;
  8670. MaxWidth = 32000;
  8671. MaxHeight = 32000;
  8672. }
  8673. }
  8674. //---------------------------------------------------------------------------
  8675. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8676. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8677. {
  8678. // terminal can be already closed (e.g. dropped connection)
  8679. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8680. {
  8681. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8682. try
  8683. {
  8684. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8685. }
  8686. catch(...)
  8687. {
  8688. if (!Terminal->Active)
  8689. {
  8690. Close = true;
  8691. }
  8692. throw;
  8693. }
  8694. }
  8695. }
  8696. //---------------------------------------------------------------------------
  8697. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8698. {
  8699. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8700. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8701. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8702. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8703. {
  8704. OnGetSpaceAvailable = GetSpaceAvailable;
  8705. }
  8706. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8707. OnGetSpaceAvailable);
  8708. }
  8709. //---------------------------------------------------------------------------
  8710. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8711. {
  8712. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8713. Terminal->FillSessionDataForCode(Data.get());
  8714. return Data.release();
  8715. }
  8716. //---------------------------------------------------------------------------
  8717. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8718. {
  8719. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8720. DoGenerateUrlDialog(Data.get(), Paths);
  8721. }
  8722. //---------------------------------------------------------------------------
  8723. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8724. {
  8725. GenerateUrl(NULL);
  8726. }
  8727. //---------------------------------------------------------------------------
  8728. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8729. {
  8730. std::unique_ptr<TStrings> Paths(new TStringList());
  8731. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8732. GenerateUrl(Paths.get());
  8733. }
  8734. //---------------------------------------------------------------------------
  8735. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8736. {
  8737. FSessionColor = value;
  8738. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8739. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8740. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8741. DebugAssert(ColorItem != NULL);
  8742. ColorItem->Color = C;
  8743. NonVisualDataModule->ColorMenuItem->Color = C;
  8744. UpdateControls();
  8745. }
  8746. //---------------------------------------------------------------------------
  8747. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8748. {
  8749. if (value != FSessionColor)
  8750. {
  8751. UpdateSessionColor(value);
  8752. // Is null when called from LastTerminalClosed
  8753. if (Terminal != NULL)
  8754. {
  8755. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8756. }
  8757. }
  8758. }
  8759. //---------------------------------------------------------------------------
  8760. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8761. {
  8762. bool Result = FNoteTimer->Enabled;
  8763. if (Result)
  8764. {
  8765. // cannot cancel note too early
  8766. bool NotEarly =
  8767. (Now() - FNoteShown >
  8768. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8769. if (Force || NotEarly)
  8770. {
  8771. FNoteTimer->Enabled = false;
  8772. FNote = L"";
  8773. SAFE_DESTROY(FNoteData);
  8774. FOnNoteClick = NULL;
  8775. FNoteHints = FNotes->Text;
  8776. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8777. UpdateStatusBar();
  8778. }
  8779. }
  8780. return Result;
  8781. }
  8782. //---------------------------------------------------------------------------
  8783. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8784. {
  8785. DebugAssert(FNoteTimer->Enabled);
  8786. CancelNote(true);
  8787. }
  8788. //---------------------------------------------------------------------------
  8789. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8790. {
  8791. int P = Note.Pos(L"\n");
  8792. if (P > 0)
  8793. {
  8794. Note.SetLength(P - 1);
  8795. }
  8796. FNotes->Add(FORMAT(L"[%s] %s",
  8797. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8798. while (FNotes->Count > 10)
  8799. {
  8800. FNotes->Delete(0);
  8801. }
  8802. if (UpdateNow)
  8803. {
  8804. FNoteHints = FNotes->Text;
  8805. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8806. UpdateStatusBar();
  8807. }
  8808. }
  8809. //---------------------------------------------------------------------------
  8810. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8811. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8812. {
  8813. int P = Note.Pos(L"\n");
  8814. if (P > 0)
  8815. {
  8816. Note.SetLength(P - 1);
  8817. }
  8818. FNoteHints = FNotes->Text;
  8819. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8820. FNote = Note;
  8821. SAFE_DESTROY(FNoteData);
  8822. FNoteData = NoteData;
  8823. FOnNoteClick = OnNoteClick;
  8824. AddNote(Note, false);
  8825. UpdateStatusBar();
  8826. FNoteShown = Now();
  8827. FNoteTimer->Enabled = false;
  8828. if (Seconds == 0)
  8829. {
  8830. Seconds = WinConfiguration->NotificationsTimeout;
  8831. }
  8832. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8833. FNoteTimer->Enabled = true;
  8834. }
  8835. //---------------------------------------------------------------------------
  8836. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8837. {
  8838. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8839. }
  8840. //---------------------------------------------------------------------------
  8841. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8842. {
  8843. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  8844. {
  8845. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8846. }
  8847. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8848. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8849. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  8850. 0, NULL, NULL);
  8851. }
  8852. //---------------------------------------------------------------------------
  8853. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8854. {
  8855. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8856. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8857. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8858. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8859. }
  8860. //---------------------------------------------------------------------------
  8861. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8862. {
  8863. WinConfiguration->FormatSizeBytes = Style;
  8864. }
  8865. //---------------------------------------------------------------------------
  8866. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8867. {
  8868. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8869. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8870. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8871. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8872. }
  8873. //---------------------------------------------------------------------------
  8874. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8875. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8876. {
  8877. if (Panel->Index == 0)
  8878. {
  8879. if (FOnNoteClick != NULL)
  8880. {
  8881. // prevent the user data from being freed by possible call
  8882. // to CancelNote or PostNote during call to OnNoteClick
  8883. std::unique_ptr<TObject> NoteData(FNoteData);
  8884. TNotifyEvent OnNoteClick = FOnNoteClick;
  8885. FNoteData = NULL;
  8886. // need to cancel the note as we are going to delete its user data
  8887. CancelNote(true);
  8888. OnNoteClick(NoteData.get());
  8889. }
  8890. }
  8891. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8892. {
  8893. FileSystemInfo();
  8894. }
  8895. }
  8896. //---------------------------------------------------------------------------
  8897. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8898. {
  8899. // workaround:
  8900. // 1) for unknown reason, disabling window, while minimized,
  8901. // prevents it from restoring, even if it was enabled again meanwhile
  8902. // 2) when disabling the main window, while another has focus
  8903. // minimize is no longer possible
  8904. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8905. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8906. // Shouldn't we use IsApplicationMinimized() here?
  8907. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8908. {
  8909. Enabled = false;
  8910. }
  8911. FLockLevel++;
  8912. }
  8913. //---------------------------------------------------------------------------
  8914. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8915. {
  8916. DebugAssert(FLockLevel > 0);
  8917. FLockLevel--;
  8918. if (FLockLevel == 0)
  8919. {
  8920. DebugAssert(FLockSuspendLevel == 0);
  8921. Enabled = true;
  8922. }
  8923. }
  8924. //---------------------------------------------------------------------------
  8925. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8926. {
  8927. // We need to make sure that window is enabled when the last modal window closes
  8928. // otherwise focus is not restored correctly.
  8929. // So we re-enable the window when modal window opens and
  8930. // disable it back after is closes
  8931. if (FLockLevel > 0)
  8932. {
  8933. // while we have nesting counter, we know that we never be called
  8934. // recursivelly as Application->OnModalBegin is called only
  8935. // for the top-level modal window
  8936. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8937. {
  8938. // won't be disabled when conditions in LockWindow() were not satisfied
  8939. FDisabledOnLockSuspend = !Enabled;
  8940. // When minimized to tray (or actually when set to SW_HIDE),
  8941. // setting Enabled makes the window focusable even when there's
  8942. // modal window over it
  8943. if (!FTrayIcon->Visible)
  8944. {
  8945. Enabled = true;
  8946. }
  8947. }
  8948. FLockSuspendLevel++;
  8949. }
  8950. }
  8951. //---------------------------------------------------------------------------
  8952. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8953. {
  8954. if (FLockSuspendLevel > 0)
  8955. {
  8956. DebugAssert(FLockLevel > 0);
  8957. FLockSuspendLevel--;
  8958. // see comment in SuspendWindowLock
  8959. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8960. {
  8961. // Note that window can be enabled here, when we were minized to tray when
  8962. // was SuspendWindowLock() called.
  8963. // We should possibly do the same check as in LockWindow(),
  8964. // if it is ever possible that the consitions change between
  8965. // SuspendWindowLock() and ResumeWindowLock()
  8966. Enabled = !FDisabledOnLockSuspend;
  8967. }
  8968. }
  8969. }
  8970. //---------------------------------------------------------------------------
  8971. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8972. {
  8973. TTBXComboBoxItem * RemotePathComboBox =
  8974. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8975. if (!TextOnly)
  8976. {
  8977. TStrings * Items = RemotePathComboBox->Strings;
  8978. Items->BeginUpdate();
  8979. try
  8980. {
  8981. Items->Clear();
  8982. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  8983. {
  8984. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8985. while (!IsUnixRootPath(APath))
  8986. {
  8987. int P = APath.LastDelimiter(L'/');
  8988. DebugAssert(P >= 0);
  8989. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8990. APath.SetLength(P - 1);
  8991. }
  8992. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8993. }
  8994. }
  8995. __finally
  8996. {
  8997. Items->EndUpdate();
  8998. }
  8999. }
  9000. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9001. // Setting ItemIndex to -1 does not reset its text
  9002. if (RemotePathComboBox->Strings->Count == 0)
  9003. {
  9004. RemotePathComboBox->Text = L"";
  9005. }
  9006. }
  9007. //---------------------------------------------------------------------------
  9008. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9009. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9010. {
  9011. if (AIndex < 0)
  9012. {
  9013. AIndex = Sender->ItemIndex;
  9014. }
  9015. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9016. }
  9017. //---------------------------------------------------------------------------
  9018. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9019. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9020. int & ImageIndex)
  9021. {
  9022. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9023. }
  9024. //---------------------------------------------------------------------------
  9025. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9026. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9027. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9028. {
  9029. if (!IsLocalBrowserMode())
  9030. {
  9031. ARect.Left += (10 * AIndex);
  9032. }
  9033. }
  9034. //---------------------------------------------------------------------------
  9035. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9036. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9037. {
  9038. AWidth += (10 * AIndex);
  9039. }
  9040. //---------------------------------------------------------------------------
  9041. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9042. {
  9043. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9044. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9045. int Index = RemotePathComboBox->ItemIndex;
  9046. while (Index < RemotePathComboBox->Strings->Count - 1)
  9047. {
  9048. APath = UnixExtractFileDir(APath);
  9049. Index++;
  9050. }
  9051. // VanDyke style paths
  9052. if (APath.IsEmpty())
  9053. {
  9054. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9055. APath = ROOTDIRECTORY;
  9056. }
  9057. if (RemoteDirView->Path != APath)
  9058. {
  9059. RemoteDirView->Path = APath;
  9060. }
  9061. }
  9062. //---------------------------------------------------------------------------
  9063. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9064. {
  9065. DoRemotePathComboBoxItemClick(Sender);
  9066. }
  9067. //---------------------------------------------------------------------------
  9068. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9069. {
  9070. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9071. DebugUsedParam(Sender);
  9072. UpdateRemotePathComboBox(true);
  9073. }
  9074. //---------------------------------------------------------------------------
  9075. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9076. {
  9077. DoRemotePathComboBoxCancel(Sender);
  9078. }
  9079. //---------------------------------------------------------------------------
  9080. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9081. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9082. {
  9083. ResetIncrementalSearch();
  9084. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9085. DebugAssert(DirView != NULL);
  9086. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9087. {
  9088. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9089. // OnEditing is called also from TCustomListView::CanEdit
  9090. if (Edit != NULL)
  9091. {
  9092. EditSelectBaseName(Edit);
  9093. }
  9094. }
  9095. }
  9096. //---------------------------------------------------------------------------
  9097. //---------------------------------------------------------------------------
  9098. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9099. {
  9100. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9101. Result->AutoDetectDnD = false;
  9102. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9103. Result->RenderDataOn = rdoEnterAndDropSync;
  9104. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9105. return Result;
  9106. }
  9107. //---------------------------------------------------------------------------
  9108. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9109. {
  9110. TForm::CreateWnd();
  9111. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9112. if (FSessionsDragDropFilesEx == NULL)
  9113. {
  9114. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9115. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9116. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9117. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9118. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9119. }
  9120. if (FQueueDragDropFilesEx == NULL)
  9121. {
  9122. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9123. // No need to set OnDragOver as we do not have any restrictions
  9124. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9125. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9126. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9127. }
  9128. }
  9129. //---------------------------------------------------------------------------
  9130. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9131. {
  9132. TForm::DestroyWnd();
  9133. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9134. FQueueDragDropFilesEx->DragDropControl = NULL;
  9135. }
  9136. //---------------------------------------------------------------------------
  9137. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9138. {
  9139. SideEnter(FCurrentSide);
  9140. FEverShown = true;
  9141. }
  9142. //---------------------------------------------------------------------------
  9143. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9144. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9145. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9146. {
  9147. if (!NonVisualDataModule->Busy)
  9148. {
  9149. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9150. Configuration->Usage->Inc(L"FileFinds");
  9151. LockWindow(true);
  9152. NonVisualDataModule->StartBusy();
  9153. WinConfiguration->LockedInterface = true;
  9154. try
  9155. {
  9156. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9157. }
  9158. __finally
  9159. {
  9160. WinConfiguration->LockedInterface = false;
  9161. NonVisualDataModule->EndBusy();
  9162. UnlockWindow();
  9163. }
  9164. }
  9165. }
  9166. //---------------------------------------------------------------------------
  9167. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9168. {
  9169. if (!NonVisualDataModule->Busy)
  9170. {
  9171. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9172. SetFocus();
  9173. RemoteDirView->Path = UnixExtractFilePath(Path);
  9174. UnicodeString FileName = UnixExtractFileName(Path);
  9175. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9176. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9177. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9178. if (Item == NULL)
  9179. {
  9180. ReloadDirectory(osRemote);
  9181. Item = RemoteDirView->FindFileItem(FileName);
  9182. }
  9183. if (Item != NULL)
  9184. {
  9185. RemoteDirView->ItemFocused = Item;
  9186. RemoteDirView->ItemFocused->MakeVisible(false);
  9187. RemoteDirView->SetFocus();
  9188. }
  9189. }
  9190. }
  9191. //---------------------------------------------------------------------------
  9192. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9193. {
  9194. bool Result = !NonVisualDataModule->Busy;
  9195. if (Result)
  9196. {
  9197. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9198. }
  9199. return Result;
  9200. }
  9201. //---------------------------------------------------------------------------
  9202. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9203. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9204. {
  9205. if (CanOperateOnFoundFiles(ATerminal))
  9206. {
  9207. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9208. FOnFileOperationFinished = OnFileOperationFinished;
  9209. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9210. }
  9211. }
  9212. //---------------------------------------------------------------------------
  9213. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9214. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9215. {
  9216. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9217. }
  9218. //---------------------------------------------------------------------------
  9219. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9220. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9221. {
  9222. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9223. }
  9224. //---------------------------------------------------------------------------
  9225. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9226. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9227. {
  9228. if (CanOperateOnFoundFiles(ATerminal))
  9229. {
  9230. for (int Index = 0; Index < FileList->Count; Index++)
  9231. {
  9232. UnicodeString FileName = FileList->Strings[Index];
  9233. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9234. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9235. OnFileOperationFinished(FileName, true);
  9236. }
  9237. }
  9238. }
  9239. //---------------------------------------------------------------------------
  9240. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9241. {
  9242. FFileFindTerminal = Terminal;
  9243. ShowFileFindDialog(
  9244. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9245. DoDownloadFoundFiles, DoEditFoundFiles);
  9246. }
  9247. //---------------------------------------------------------------------------
  9248. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9249. {
  9250. FTaskbarList = TaskbarList;
  9251. }
  9252. //---------------------------------------------------------------------------
  9253. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9254. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9255. {
  9256. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9257. if (Index >= 0)
  9258. {
  9259. if (Button == mbLeft)
  9260. {
  9261. // "Mouse down" is raised only after tab is switched.
  9262. // If switching tab (switching session) takes long enough for user
  9263. // to actually release the button, "mouse down" is still raised,
  9264. // but we do not get "mouse up" event, so dragging is not cancelled,
  9265. // prevent that by not beginning dragging in the first place.
  9266. if (IsKeyPressed(VK_LBUTTON))
  9267. {
  9268. // when user clicks the "+", we get mouse down only after the session
  9269. // is closed, when new session tab is already on X:Y, so dragging
  9270. // starts, prevent that
  9271. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9272. {
  9273. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9274. if (Terminal != NULL)
  9275. {
  9276. SessionsPageControl->BeginDrag(false);
  9277. }
  9278. }
  9279. }
  9280. }
  9281. else if (Button == mbMiddle)
  9282. {
  9283. // ignore middle-click for "New session tab"
  9284. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9285. if (Terminal != NULL)
  9286. {
  9287. CloseSessionTab(Index);
  9288. }
  9289. }
  9290. }
  9291. }
  9292. //---------------------------------------------------------------------------
  9293. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9294. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9295. {
  9296. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9297. // do not allow dropping on the "+" tab
  9298. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9299. if ((TargetTerminal != NULL) &&
  9300. (SessionsPageControl->ActivePage->PageIndex != Index))
  9301. {
  9302. Configuration->Usage->Inc(L"SessionTabMoves");
  9303. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9304. // but we want to actually prevent that to avoid flicker
  9305. SessionsPageControl->ActivePage->PageIndex = Index;
  9306. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9307. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9308. }
  9309. }
  9310. //---------------------------------------------------------------------------
  9311. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9312. TObject * Sender, TObject * Source, int X, int Y,
  9313. TDragState /*State*/, bool & Accept)
  9314. {
  9315. Accept = (Sender == Source);
  9316. if (Accept)
  9317. {
  9318. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9319. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9320. // do not allow dragging to the "+" tab
  9321. Accept = (Terminal != NULL);
  9322. }
  9323. }
  9324. //---------------------------------------------------------------------------
  9325. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9326. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9327. {
  9328. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9329. if (Index < 0)
  9330. {
  9331. Effect = DROPEFFECT_NONE;
  9332. }
  9333. else
  9334. {
  9335. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9336. // do not allow dropping on the "+" tab
  9337. if (TargetTerminal == NULL)
  9338. {
  9339. Effect = DROPEFFECT_NONE;
  9340. }
  9341. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9342. {
  9343. Effect = DROPEFFECT_COPY;
  9344. }
  9345. }
  9346. }
  9347. //---------------------------------------------------------------------------
  9348. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9349. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9350. {
  9351. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9352. // do not allow dropping on the "+" tab
  9353. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9354. if (TargetTerminal != NULL)
  9355. {
  9356. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9357. if (!IsFileControl(DropSourceControl, osRemote))
  9358. {
  9359. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9360. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9361. // Why don't we use Terminal->CurrentDirectory directly?
  9362. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9363. // do not force queue, drag drop
  9364. false, true);
  9365. }
  9366. }
  9367. }
  9368. //---------------------------------------------------------------------------
  9369. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9370. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9371. {
  9372. // Downloads are handled in RemoteFileControlDDEnd
  9373. if (!IsFileControl(DropSourceControl, osRemote))
  9374. {
  9375. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9376. Terminal->CurrentDirectory,
  9377. // force queue, drag drop
  9378. true, true);
  9379. }
  9380. }
  9381. //---------------------------------------------------------------------------
  9382. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9383. {
  9384. FShowing = false;
  9385. // Do not save empty workspace
  9386. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9387. {
  9388. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9389. UnicodeString Name = WorkspaceName();
  9390. DoSaveWorkspace(
  9391. Name, DataList.get(),
  9392. !Configuration->DisablePasswordStoring &&
  9393. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9394. WinConfiguration->LastStoredSession = Name;
  9395. }
  9396. }
  9397. //---------------------------------------------------------------------------
  9398. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9399. {
  9400. TManagedTerminal * ManagedTerminal =
  9401. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9402. if (ManagedTerminal != NULL)
  9403. {
  9404. ManagedTerminal->DirectoryLoaded = Now();
  9405. }
  9406. }
  9407. //---------------------------------------------------------------------------
  9408. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9409. TListItem * /*Item*/, bool /*Selected*/)
  9410. {
  9411. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9412. switch (DirView->LastSelectMethod)
  9413. {
  9414. case smKeyboard:
  9415. Configuration->Usage->Inc(L"KeyboardSelections");
  9416. break;
  9417. case smMouse:
  9418. Configuration->Usage->Inc(L"MouseSelections");
  9419. break;
  9420. }
  9421. }
  9422. //---------------------------------------------------------------------------
  9423. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9424. {
  9425. if (Color != 0)
  9426. {
  9427. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9428. }
  9429. else
  9430. {
  9431. return FSessionTabImageIndex;
  9432. }
  9433. }
  9434. //---------------------------------------------------------------------------
  9435. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9436. {
  9437. TPngImageCollectionItem * Item =
  9438. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9439. FSessionColors->AddPng(Item->PngImage);
  9440. return FSessionColors->Count - 1;
  9441. }
  9442. //---------------------------------------------------------------------------
  9443. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9444. {
  9445. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9446. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9447. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9448. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9449. }
  9450. //---------------------------------------------------------------------------
  9451. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9452. {
  9453. for (int Index = 0; Index < Control->ControlCount; Index++)
  9454. {
  9455. TControl * AControl = Control->Controls[Index];
  9456. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9457. if (WinControl != NULL)
  9458. {
  9459. CollectItemsWithTextDisplayMode(WinControl);
  9460. }
  9461. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9462. if (Toolbar != NULL)
  9463. {
  9464. // we care for top-level items only
  9465. TTBCustomItem * Items = Toolbar->Items;
  9466. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9467. {
  9468. TTBCustomItem * Item = Items->Items[ItemIndex];
  9469. if (((Item->DisplayMode == nbdmImageAndText) ||
  9470. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9471. EligibleForImageDisplayMode(Item))
  9472. {
  9473. FItemsWithTextDisplayMode.insert(Item);
  9474. }
  9475. }
  9476. }
  9477. }
  9478. }
  9479. //---------------------------------------------------------------------------
  9480. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9481. {
  9482. return true;
  9483. }
  9484. //---------------------------------------------------------------------------
  9485. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9486. {
  9487. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9488. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9489. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9490. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9491. bool Result = true;
  9492. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9493. {
  9494. TTBCustomItem * Item = *i;
  9495. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9496. if (Label != NULL)
  9497. {
  9498. // optimization
  9499. if (Label->Visible == SelectiveToolbarText)
  9500. {
  9501. Result = false;
  9502. }
  9503. else
  9504. {
  9505. Label->Visible = SelectiveToolbarText;
  9506. }
  9507. }
  9508. else
  9509. {
  9510. // optimization
  9511. if (Item->DisplayMode == DisplayMode)
  9512. {
  9513. Result = false;
  9514. }
  9515. else
  9516. {
  9517. Item->DisplayMode = DisplayMode;
  9518. }
  9519. }
  9520. ++i;
  9521. }
  9522. if (Result)
  9523. {
  9524. UpdateNewSessionTab();
  9525. }
  9526. return Result;
  9527. }
  9528. //---------------------------------------------------------------------------
  9529. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9530. {
  9531. DebugFail();
  9532. }
  9533. //---------------------------------------------------------------------------
  9534. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9535. {
  9536. // Among other, a lock level is non zero, while directory is being loaded,
  9537. // even when it happens as a result of dirview navigation,
  9538. // i.e. when TNonVisualDataModule is NOT FBusy.
  9539. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9540. // Among other this prevents a panel auto update to occur while
  9541. // directory is changing.
  9542. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9543. }
  9544. //---------------------------------------------------------------------------
  9545. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  9546. {
  9547. // While the window is disabled, we still seem to process menu shortcuts at least,
  9548. // so stop it at least here.
  9549. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9550. bool Result;
  9551. if (Allowed == aaUpdate)
  9552. {
  9553. Result = true;
  9554. }
  9555. else
  9556. {
  9557. Result = !NonVisualDataModule->Busy;
  9558. if (Result && (Allowed == aaShortCut))
  9559. {
  9560. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  9561. Action->Update();
  9562. Result = Action->Enabled;
  9563. }
  9564. }
  9565. return Result;
  9566. }
  9567. //---------------------------------------------------------------------------
  9568. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9569. {
  9570. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9571. }
  9572. //---------------------------------------------------------------------------
  9573. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9574. {
  9575. // This is somewhat redundant to LockWindow() call from
  9576. // TTerminalManager::TerminalReadDirectoryProgress.
  9577. // But disabling window is known not to block keyboard shorcuts
  9578. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9579. if (Busy > 0)
  9580. {
  9581. if (NonVisualDataModule->Busy)
  9582. {
  9583. State = false;
  9584. }
  9585. else
  9586. {
  9587. NonVisualDataModule->StartBusy();
  9588. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9589. LockWindow();
  9590. }
  9591. }
  9592. else if (Busy < 0)
  9593. {
  9594. UnlockWindow();
  9595. NonVisualDataModule->EndBusy();
  9596. }
  9597. else
  9598. {
  9599. State = NonVisualDataModule->Busy;
  9600. }
  9601. }
  9602. //---------------------------------------------------------------------------
  9603. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9604. {
  9605. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9606. // no context menu for "New session tab"
  9607. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9608. {
  9609. SessionsPageControl->ActivePageIndex = Index;
  9610. if (DebugAlwaysTrue(SessionTabSwitched()))
  9611. {
  9612. // copied from TControl.WMContextMenu
  9613. SendCancelMode(SessionsPageControl);
  9614. // explicit popup instead of using PopupMenu property
  9615. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9616. // while connecting yet not-connected session and hence
  9617. // allowing an access to commands over not-completelly connected session
  9618. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9619. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9620. PopupMenu->PopupComponent = SessionsPageControl;
  9621. PopupMenu->Popup(Point.x, Point.y);
  9622. }
  9623. }
  9624. Handled = true;
  9625. }
  9626. //---------------------------------------------------------------------------
  9627. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9628. {
  9629. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9630. }
  9631. //---------------------------------------------------------------------------
  9632. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9633. {
  9634. Configuration->Usage->Inc(L"PasswordChanges");
  9635. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9636. ChangePasswordData->DisableAuthentationsExceptPassword();
  9637. ChangePasswordData->ChangePassword = true;
  9638. std::unique_ptr<TTerminal> ChangePasswordSession(
  9639. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9640. ChangePasswordSession->AutoReadDirectory = false;
  9641. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9642. {
  9643. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9644. }
  9645. else
  9646. {
  9647. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9648. }
  9649. }
  9650. //---------------------------------------------------------------------------
  9651. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9652. {
  9653. // No nice way to assert SSH2
  9654. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9655. }
  9656. //---------------------------------------------------------------------------
  9657. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9658. {
  9659. TOperationVisualizer OperationVisualizer;
  9660. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9661. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9662. }
  9663. //---------------------------------------------------------------------------
  9664. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9665. {
  9666. TForm::ChangeScale(M, D);
  9667. int APixelsPerInch = GetControlPixelsPerInch(this);
  9668. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9669. try
  9670. {
  9671. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9672. }
  9673. __finally
  9674. {
  9675. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9676. }
  9677. }
  9678. //---------------------------------------------------------------------------
  9679. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9680. {
  9681. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9682. }
  9683. //---------------------------------------------------------------------
  9684. class TPublicControl : public TControl
  9685. {
  9686. friend class TCustomScpExplorerForm;
  9687. };
  9688. //---------------------------------------------------------------------------
  9689. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9690. {
  9691. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9692. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9693. }
  9694. //---------------------------------------------------------------------------
  9695. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9696. {
  9697. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9698. OpenBookmark(Side, Bookmark);
  9699. }
  9700. //---------------------------------------------------------------------------
  9701. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9702. {
  9703. DoBookmarkClick(osLocal, Sender);
  9704. }
  9705. //---------------------------------------------------------------------------
  9706. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9707. {
  9708. DoBookmarkClick(osRemote, Sender);
  9709. }
  9710. //---------------------------------------------------------------------------
  9711. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9712. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9713. {
  9714. if (BookmarkList != NULL)
  9715. {
  9716. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9717. if (IsLocalBrowserMode())
  9718. {
  9719. Side = osLocal;
  9720. }
  9721. if (!WinConfiguration->UseLocationProfiles)
  9722. {
  9723. std::unique_ptr<TStringList> Directories(new TStringList());
  9724. Directories->CaseSensitive = (Side == osRemote);
  9725. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9726. {
  9727. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9728. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9729. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9730. {
  9731. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9732. Item->Caption = EscapeHotkey(Directory);
  9733. Item->ShortCut = Bookmark->ShortCut;
  9734. Item->OnClick = OnBookmarkClick;
  9735. Item->Tag = reinterpret_cast<int>(Bookmark);
  9736. Directories->Add(Directory);
  9737. Menu->Add(Item.release());
  9738. }
  9739. }
  9740. }
  9741. else
  9742. {
  9743. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9744. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9745. {
  9746. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9747. if (!Bookmark->Node.IsEmpty())
  9748. {
  9749. Folders->Add(Bookmark->Node);
  9750. }
  9751. }
  9752. for (int Index = 0; Index < Folders->Count; Index++)
  9753. {
  9754. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9755. Item->Caption = Folders->Strings[Index];
  9756. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  9757. Folders->Objects[Index] = Item.get();
  9758. Menu->Add(Item.release());
  9759. }
  9760. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9761. {
  9762. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9763. TTBCustomItem * Parent;
  9764. if (!Bookmark->Node.IsEmpty())
  9765. {
  9766. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9767. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9768. }
  9769. else
  9770. {
  9771. Parent = Menu;
  9772. }
  9773. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9774. Item->Caption = Bookmark->Name;
  9775. Item->ShortCut = Bookmark->ShortCut;
  9776. Item->OnClick = OnBookmarkClick;
  9777. Item->Tag = reinterpret_cast<int>(Bookmark);
  9778. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9779. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9780. {
  9781. // No hint for location profiles that are actually mere "bookmarks"
  9782. }
  9783. else
  9784. {
  9785. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9786. UnicodeString LongHint;
  9787. if (!Bookmark->Local.IsEmpty())
  9788. {
  9789. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9790. }
  9791. if (!Bookmark->Remote.IsEmpty())
  9792. {
  9793. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9794. }
  9795. AddToList(Hint, LongHint, L"|");
  9796. Item->Hint = Hint;
  9797. }
  9798. Parent->Add(Item.release());
  9799. }
  9800. }
  9801. AddMenuSeparator(Menu);
  9802. }
  9803. }
  9804. //---------------------------------------------------------------------------
  9805. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9806. {
  9807. Menu->Clear();
  9808. std::unique_ptr<TTBCustomItem> Item;
  9809. Item.reset(new TTBXItem(Owner));
  9810. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9811. Item->Options = Item->Options << tboDefault;
  9812. Menu->Add(Item.release());
  9813. AddMenuSeparator(Menu);
  9814. if (Terminal != NULL)
  9815. {
  9816. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9817. }
  9818. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9819. Item.reset(new TTBXItem(Owner));
  9820. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  9821. Menu->Add(Item.release());
  9822. }
  9823. //---------------------------------------------------------------------------
  9824. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9825. {
  9826. bool Result = true;
  9827. bool Remote = !IsSideLocalBrowser(Side);
  9828. try
  9829. {
  9830. if (Remote)
  9831. {
  9832. Terminal->ExceptionOnFail = true;
  9833. }
  9834. try
  9835. {
  9836. DirView(Side)->Path = Path;
  9837. }
  9838. __finally
  9839. {
  9840. if (Remote)
  9841. {
  9842. Terminal->ExceptionOnFail = false;
  9843. }
  9844. }
  9845. }
  9846. catch (Exception & E)
  9847. {
  9848. if (!Remote || Terminal->Active)
  9849. {
  9850. ShowExtendedExceptionEx(Terminal, &E);
  9851. Result = false;
  9852. }
  9853. else
  9854. {
  9855. throw;
  9856. }
  9857. }
  9858. return Result;
  9859. }
  9860. //---------------------------------------------------------------------------
  9861. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9862. {
  9863. // Make sure there some feedback even when loading tiny local folders
  9864. TInstantOperationVisualizer Visualizer;
  9865. DirView(Side)->ReloadDirectory();
  9866. }
  9867. //---------------------------------------------------------------------------
  9868. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9869. {
  9870. if (Index == SessionsPageControl->TabIndex)
  9871. {
  9872. CloseSession();
  9873. }
  9874. else
  9875. {
  9876. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9877. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9878. TTerminalManager * Manager = TTerminalManager::Instance();
  9879. if (!Terminal->Active)
  9880. {
  9881. Manager->FreeTerminal(Terminal);
  9882. }
  9883. else
  9884. {
  9885. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9886. if (CanCloseQueue(Queue))
  9887. {
  9888. Manager->FreeTerminal(Terminal);
  9889. }
  9890. }
  9891. }
  9892. }
  9893. //---------------------------------------------------------------------------
  9894. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9895. {
  9896. CloseSessionTab(Index);
  9897. }
  9898. //---------------------------------------------------------------------------
  9899. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9900. {
  9901. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9902. {
  9903. TInstantOperationVisualizer Visualizer;
  9904. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9905. // before we create a new data object
  9906. ClipboardClear();
  9907. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9908. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9909. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9910. // Intermediate variable to WORKAROUND a crash in compiler
  9911. TObjectList * ClipboardFakeMonitors =
  9912. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9913. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9914. if (FClipboardDragDropFilesEx.get() == NULL)
  9915. {
  9916. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9917. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9918. }
  9919. FClipboardDragDropFilesEx->FileList->Clear();
  9920. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9921. FClipboardDragDropFilesEx->CopyToClipboard();
  9922. FClipboardTerminal = FTerminal;
  9923. // Need full paths, as cwd can be different once files are pasted
  9924. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9925. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9926. {
  9927. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9928. }
  9929. }
  9930. }
  9931. //---------------------------------------------------------------------------
  9932. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9933. {
  9934. if (OpenClipboard(0))
  9935. {
  9936. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9937. CloseClipboard();
  9938. }
  9939. }
  9940. //---------------------------------------------------------------------------
  9941. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9942. {
  9943. return !FClipboardFakeDirectory.IsEmpty();
  9944. }
  9945. //---------------------------------------------------------------------------
  9946. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9947. {
  9948. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9949. FClipboardFakeDirectory = UnicodeString();
  9950. FClipboardTerminal = NULL;
  9951. // Also called in Idle()
  9952. FClipboardFakeMonitors.reset(NULL);
  9953. }
  9954. //---------------------------------------------------------------------------
  9955. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9956. {
  9957. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9958. {
  9959. ClipboardStop();
  9960. }
  9961. }
  9962. //---------------------------------------------------------------------------
  9963. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9964. {
  9965. TTerminalManager * Manager = TTerminalManager::Instance();
  9966. Manager->ActiveTerminal = FClipboardTerminal;
  9967. TTransferOperationParam Params;
  9968. Params.TargetDirectory = TargetDirectory;
  9969. Params.DragDrop = DragDrop;
  9970. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  9971. }
  9972. //---------------------------------------------------------------------------
  9973. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  9974. {
  9975. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  9976. // (as it pumps a Windows message queue while being shutted down)
  9977. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  9978. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  9979. {
  9980. // Can fail as it can be e.g. locked by AV, so we retry that later
  9981. bool Removed = RemoveDir(ApiPath(FileName));
  9982. try
  9983. {
  9984. if (!NonVisualDataModule->Busy)
  9985. {
  9986. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  9987. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  9988. }
  9989. }
  9990. __finally
  9991. {
  9992. if (!Removed)
  9993. {
  9994. RemoveDir(ApiPath(FileName));
  9995. }
  9996. }
  9997. }
  9998. }
  9999. //---------------------------------------------------------------------------
  10000. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10001. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10002. {
  10003. TFileMasks::TParams MaskParams;
  10004. MaskParams.Size = Size;
  10005. MaskParams.Modification = Modification;
  10006. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10007. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10008. {
  10009. bool ImplicitMatch;
  10010. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  10011. !ImplicitMatch)
  10012. {
  10013. Color = Iter->Color;
  10014. break;
  10015. }
  10016. }
  10017. }
  10018. //---------------------------------------------------------------------------
  10019. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10020. {
  10021. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10022. if (!DirView->IsEditing())
  10023. {
  10024. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10025. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10026. // while searching
  10027. if (Key == VK_BACK)
  10028. {
  10029. if (!FIncrementalSearch.IsEmpty())
  10030. {
  10031. if (FIncrementalSearch.Length() == 1)
  10032. {
  10033. ResetIncrementalSearch();
  10034. }
  10035. else
  10036. {
  10037. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10038. IncrementalSearch(NewText, false, false);
  10039. }
  10040. Key = 0;
  10041. }
  10042. }
  10043. }
  10044. }
  10045. //---------------------------------------------------------------------------
  10046. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10047. {
  10048. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10049. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10050. {
  10051. // Filter control sequences.
  10052. // When not searching yet, prefer use of the space for toggling file selection
  10053. // (so we cannot incrementally search for a string starting with a space).
  10054. if ((Key > VK_SPACE) ||
  10055. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10056. {
  10057. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10058. Key = 0;
  10059. }
  10060. }
  10061. }
  10062. //---------------------------------------------------------------------------
  10063. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10064. {
  10065. if (!FIncrementalSearch.IsEmpty())
  10066. {
  10067. FIncrementalSearch = L"";
  10068. DirView(osCurrent)->UpdateStatusBar();
  10069. }
  10070. }
  10071. //---------------------------------------------------------------------------
  10072. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10073. {
  10074. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10075. if (Item == NULL)
  10076. {
  10077. MessageBeep(MB_ICONHAND);
  10078. }
  10079. else
  10080. {
  10081. TCustomDirView * ADirView = DirView(osCurrent);
  10082. {
  10083. TAutoNestingCounter Guard(FIncrementalSearching);
  10084. ADirView->FocusItem(Item);
  10085. if (ADirView->NortonLike == nlOff)
  10086. {
  10087. if ((ADirView->Selected != Item) ||
  10088. (ADirView->SelCount > 1))
  10089. {
  10090. ADirView->ClearSelection();
  10091. ADirView->Selected = Item;
  10092. }
  10093. }
  10094. }
  10095. FIncrementalSearch = Text;
  10096. Item->MakeVisible(false);
  10097. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10098. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10099. ADirView->UpdateStatusBar();
  10100. }
  10101. }
  10102. //---------------------------------------------------------------------------
  10103. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10104. {
  10105. int Index = Item->Index;
  10106. if (!Reverse)
  10107. {
  10108. Index++;
  10109. if (Index >= Item->Owner->Count)
  10110. {
  10111. Index = 0;
  10112. }
  10113. }
  10114. else
  10115. {
  10116. Index--;
  10117. if (Index < 0)
  10118. {
  10119. Index = Item->Owner->Count - 1;
  10120. }
  10121. }
  10122. return Item->Owner->Item[Index];
  10123. }
  10124. //---------------------------------------------------------------------------
  10125. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10126. {
  10127. TCustomDirView * ADirView = DirView(osCurrent);
  10128. if (ADirView->Items->Count == 0)
  10129. {
  10130. return NULL;
  10131. }
  10132. else
  10133. {
  10134. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10135. TListItem * Item = CurrentItem;
  10136. if (SkipCurrent)
  10137. {
  10138. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10139. }
  10140. while (true)
  10141. {
  10142. bool Matches = false;
  10143. switch (WinConfiguration->PanelSearch)
  10144. {
  10145. case isNameStartOnly:
  10146. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10147. break;
  10148. case isName:
  10149. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10150. break;
  10151. case isAll:
  10152. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10153. int Index = 0;
  10154. while ((Index < ColCount) && !Matches)
  10155. {
  10156. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10157. if (Visible)
  10158. {
  10159. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10160. }
  10161. Index++;
  10162. }
  10163. break;
  10164. }
  10165. if (Matches)
  10166. {
  10167. return Item;
  10168. }
  10169. Item = GetNextFile(Item, Reverse);
  10170. if (Item == CurrentItem)
  10171. {
  10172. return NULL;
  10173. }
  10174. }
  10175. }
  10176. }
  10177. //---------------------------------------------------------------------------
  10178. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10179. {
  10180. ResetIncrementalSearch();
  10181. }
  10182. //---------------------------------------------------------------------------
  10183. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10184. {
  10185. if (Message.CharCode == VK_TAB)
  10186. {
  10187. if (!FIncrementalSearch.IsEmpty())
  10188. {
  10189. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10190. bool Reverse = Shift.Contains(ssShift);
  10191. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10192. Message.Result = 1;
  10193. return;
  10194. }
  10195. }
  10196. else if (Message.CharCode == VK_ESCAPE)
  10197. {
  10198. if (!FIncrementalSearch.IsEmpty())
  10199. {
  10200. ResetIncrementalSearch();
  10201. Message.Result = 1;
  10202. return;
  10203. }
  10204. }
  10205. TForm::Dispatch(&Message);
  10206. }
  10207. //---------------------------------------------------------------------------
  10208. void __fastcall TCustomScpExplorerForm::Deactivate()
  10209. {
  10210. TForm::Deactivate();
  10211. // E.g. when switching to an internal editor window
  10212. ResetIncrementalSearch();
  10213. }
  10214. //---------------------------------------------------------------------------
  10215. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10216. {
  10217. // When switching to another application
  10218. ResetIncrementalSearch();
  10219. }
  10220. //---------------------------------------------------------------------------
  10221. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10222. {
  10223. ResetIncrementalSearch();
  10224. }
  10225. //---------------------------------------------------------------------------
  10226. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10227. {
  10228. if (FIncrementalSearching <= 0)
  10229. {
  10230. ResetIncrementalSearch();
  10231. }
  10232. }
  10233. //---------------------------------------------------------------------------
  10234. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10235. {
  10236. CountClicksForWindowPrint(this);
  10237. }
  10238. //---------------------------------------------------------------------------
  10239. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10240. {
  10241. CenterReconnectToolbar();
  10242. }
  10243. //---------------------------------------------------------------------------
  10244. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10245. {
  10246. if (RemoteDirView->ItemFocused != NULL)
  10247. {
  10248. RemoteDirView->ItemFocused->Selected = true;
  10249. }
  10250. }
  10251. //---------------------------------------------------------------------------
  10252. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10253. {
  10254. if (!FQueueStatusUpdating)
  10255. {
  10256. bool Refresh;
  10257. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10258. {
  10259. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10260. }
  10261. else
  10262. {
  10263. if (FQueueFileList->GetCount() > 0)
  10264. {
  10265. FQueueFileList->Clear();
  10266. Refresh = true;
  10267. }
  10268. }
  10269. int Count = FQueueFileList->GetCount();
  10270. if (QueueFileList->Items->Count != Count)
  10271. {
  10272. DebugAssert(Refresh);
  10273. QueueFileList->Items->Count = Count;
  10274. }
  10275. if (Refresh)
  10276. {
  10277. QueueFileList->Invalidate();
  10278. }
  10279. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10280. }
  10281. }
  10282. //---------------------------------------------------------------------------
  10283. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10284. {
  10285. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10286. }
  10287. //---------------------------------------------------------------------------
  10288. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10289. {
  10290. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10291. // See TSynchronizeChecklistDialog::UpdateTimer
  10292. if (QueueFileList->Items->Count > 0)
  10293. {
  10294. QueueFileList->Items->Item[0]->MakeVisible(false);
  10295. }
  10296. UpdateQueueFileList();
  10297. }
  10298. //---------------------------------------------------------------------------
  10299. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10300. {
  10301. Active = QueueView3->Focused() || QueueFileList->Focused();
  10302. }
  10303. //---------------------------------------------------------------------------
  10304. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10305. {
  10306. QueueLabelUpdateStatus();
  10307. }
  10308. //---------------------------------------------------------------------------
  10309. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10310. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10311. {
  10312. int State = FQueueFileList->GetState(Item->Index);
  10313. if (State == qfsProcessed)
  10314. {
  10315. Sender->Canvas->Font->Color = clGrayText;
  10316. }
  10317. }
  10318. //---------------------------------------------------------------------------
  10319. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10320. {
  10321. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10322. QueueFileList->Column[0]->Width =
  10323. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10324. }
  10325. //---------------------------------------------------------------------------
  10326. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10327. {
  10328. QueueFileListColumnAutoSize();
  10329. }
  10330. //---------------------------------------------------------------------------
  10331. void __fastcall TCustomScpExplorerForm::CloseApp()
  10332. {
  10333. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10334. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10335. // So we clear the flag here.
  10336. DebugAssert(NonVisualDataModule->Busy);
  10337. NonVisualDataModule->EndBusy();
  10338. try
  10339. {
  10340. Close();
  10341. }
  10342. __finally
  10343. {
  10344. NonVisualDataModule->StartBusy();
  10345. }
  10346. }
  10347. //---------------------------------------------------------------------------
  10348. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10349. {
  10350. return (Terminal != NULL) && Terminal->Active;
  10351. }
  10352. //---------------------------------------------------------------------------
  10353. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10354. {
  10355. return IsActiveTerminal(Terminal);
  10356. }
  10357. //---------------------------------------------------------------------------
  10358. void TCustomScpExplorerForm::LocalLocalCopy(
  10359. TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused), bool DebugUsedArg(NoConfirmation))
  10360. {
  10361. DebugFail();
  10362. }