CustomScpExplorer.cpp 363 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045
  1. //---------------------------------------------------------------------------
  2. #define NO_WIN32_LEAN_AND_MEAN
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <Common.h>
  6. #include "CustomScpExplorer.h"
  7. #include <Bookmarks.h>
  8. #include <Interface.h>
  9. #include <Exceptions.h>
  10. #include <CoreMain.h>
  11. #include <FileSystems.h>
  12. #include <TextsCore.h>
  13. #include <TextsWin.h>
  14. #include <HelpWin.h>
  15. #include <VCLCommon.h>
  16. #include <Progress.h>
  17. #include <SynchronizeProgress.h>
  18. #include <DragExt.h>
  19. #include <WinApi.h>
  20. #include "GUITools.h"
  21. #include "NonVisual.h"
  22. #include "Glyphs.h"
  23. #include "Tools.h"
  24. #include "WinConfiguration.h"
  25. #include "TerminalManager.h"
  26. #include "EditorManager.h"
  27. #include "ProgParams.h"
  28. #include "Setup.h"
  29. #include <Consts.hpp>
  30. #include <DateUtils.hpp>
  31. #include <TB2Common.hpp>
  32. #include <DirectoryMonitor.hpp>
  33. #include <System.IOUtils.hpp>
  34. //---------------------------------------------------------------------------
  35. #pragma package(smart_init)
  36. #pragma link "CustomDirView"
  37. #pragma link "CustomUnixDirView"
  38. #pragma link "IEListView"
  39. #pragma link "NortonLikeListView"
  40. #pragma link "UnixDirView"
  41. #pragma link "CustomDriveView"
  42. #pragma link "UnixDriveView"
  43. #pragma link "CustomDriveView"
  44. #pragma link "TB2Dock"
  45. #pragma link "TBXStatusBars"
  46. #pragma link "TB2Item"
  47. #pragma link "TB2Toolbar"
  48. #pragma link "ThemePageControl"
  49. #pragma link "PathLabel"
  50. #pragma resource "*.dfm"
  51. //---------------------------------------------------------------------------
  52. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  53. static const int SessionPanelCount = 3;
  54. //---------------------------------------------------------------------------
  55. class TMutexGuard
  56. {
  57. public:
  58. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  59. int Timeout = 5000)
  60. {
  61. FMutex = NULL;
  62. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  63. if (WaitResult == WAIT_TIMEOUT)
  64. {
  65. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  66. }
  67. else
  68. {
  69. FMutex = AMutex;
  70. }
  71. }
  72. ~TMutexGuard()
  73. {
  74. if (FMutex != NULL)
  75. {
  76. ReleaseMutex(FMutex);
  77. }
  78. }
  79. private:
  80. HANDLE FMutex;
  81. };
  82. //---------------------------------------------------------------------------
  83. class TWindowLock
  84. {
  85. public:
  86. TWindowLock(TCustomScpExplorerForm * Form) :
  87. FForm(Form)
  88. {
  89. FForm->LockWindow();
  90. }
  91. ~TWindowLock()
  92. {
  93. FForm->UnlockWindow();
  94. }
  95. private:
  96. TCustomScpExplorerForm * FForm;
  97. };
  98. //---------------------------------------------------------------------------
  99. TAutoBatch::TAutoBatch(TCustomScpExplorerForm * Form) :
  100. FForm(Form)
  101. {
  102. FForm->BatchStart(FBatchStorage);
  103. }
  104. //---------------------------------------------------------------------------
  105. TAutoBatch::~TAutoBatch()
  106. {
  107. FForm->BatchEnd(FBatchStorage);
  108. }
  109. //---------------------------------------------------------------------------
  110. struct TTransferOperationParam
  111. {
  112. TTransferOperationParam();
  113. UnicodeString TargetDirectory;
  114. bool Temp;
  115. bool DragDrop;
  116. int Options;
  117. TAutoSwitch Queue;
  118. };
  119. //---------------------------------------------------------------------------
  120. TTransferOperationParam::TTransferOperationParam()
  121. {
  122. Temp = false;
  123. DragDrop = false;
  124. Options = 0;
  125. Queue = asAuto;
  126. }
  127. //---------------------------------------------------------------------------
  128. class TTransferPresetNoteData : public TObject
  129. {
  130. public:
  131. UnicodeString Message;
  132. };
  133. //---------------------------------------------------------------------------
  134. class TTerminalNoteData : public TObject
  135. {
  136. public:
  137. TManagedTerminal * Terminal;
  138. };
  139. //---------------------------------------------------------------------------
  140. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  141. FFormRestored(false),
  142. TForm(Owner)
  143. {
  144. FInvalid = false;
  145. FCurrentSide = osRemote;
  146. FEverShown = false;
  147. FDocks = new TList();
  148. InitControls();
  149. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  150. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  151. NonVisualDataModule->ScpExplorer = this;
  152. RestoreParams();
  153. ConfigurationChanged();
  154. RemoteDirView->Invalidate();
  155. FAutoOperation = false;
  156. FOnFileOperationFinished = NULL;
  157. FForceExecution = false;
  158. FIgnoreNextDialogChar = 0;
  159. FErrorList = NULL;
  160. FSynchronizeProgressForm = NULL;
  161. FProgressForm = NULL;
  162. FRefreshLocalDirectory = false;
  163. FRefreshRemoteDirectory = false;
  164. FDDExtMapFile = NULL;
  165. // CreateMutexW keeps failing with ERROR_NOACCESS
  166. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  167. DebugAssert(FDDExtMutex != NULL);
  168. FDDTargetControl = NULL;
  169. FDelayedDeletionTimer = NULL;
  170. FDelayedDeletionList = new TStringList();
  171. FDDFileList = NULL;
  172. FPendingTempSpaceWarn = false;
  173. FCapturedLog = NULL;
  174. FDragDropOperation = false;
  175. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  176. FAllowTransferPresetAutoSelect = true;
  177. FCopyParamDefault = L"";
  178. FSynchronizeController = NULL;
  179. FPendingQueueActionItem = NULL;
  180. FLockLevel = 0;
  181. FLockSuspendLevel = 0;
  182. FDisabledOnLockSuspend = false;
  183. FAlternativeDelete = false;
  184. FTrayIcon = new ::TTrayIcon(0);
  185. FTrayIcon->OnClick = TrayIconClick;
  186. FMaxQueueLength = 0;
  187. FLastContextPopupScreenPoint = TPoint(-1, -1);
  188. FTransferResumeList = NULL;
  189. FMoveToQueue = false;
  190. FStandaloneEditing = false;
  191. FOnFeedSynchronizeError = NULL;
  192. FNeedSession = false;
  193. FDoNotIdleCurrentTerminal = 0;
  194. FIncrementalSearching = 0;
  195. FIncrementalSearchHaveNext = false;
  196. FQueueFileList.reset(new TQueueFileList());
  197. FProgressSide = osCurrent;
  198. FEditorManager = new TEditorManager();
  199. FEditorManager->OnFileChange = ExecutedFileChanged;
  200. FEditorManager->OnFileReload = ExecutedFileReload;
  201. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  202. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  203. FLocalEditors = new TList();
  204. FQueueStatus = NULL;
  205. FQueueStatusSection = new TCriticalSection();
  206. FQueueStatusInvalidated = false;
  207. FQueueItemInvalidated = false;
  208. FQueueStatusUpdating = false;
  209. FQueueActedItem = NULL;
  210. FQueueController = new TQueueController(QueueView3);
  211. FUserActionTimer = new TTimer(this);
  212. FUserActionTimer->Enabled = false;
  213. FUserActionTimer->Interval = 10;
  214. FUserActionTimer->OnTimer = UserActionTimer;
  215. FNotes = new TStringList();
  216. FNoteTimer = new TTimer(this);
  217. FNoteTimer->Enabled = false;
  218. FNoteTimer->OnTimer = NoteTimer;
  219. FOnNoteClick = NULL;
  220. FOle32Library = LoadLibrary(L"Ole32.dll");
  221. FDragMoveCursor = FOle32Library != NULL ?
  222. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  223. UseSystemSettings(this);
  224. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  225. static_cast<TObject*>(GetComponent(fcTransferList)));
  226. DebugAssert(TransferList != NULL);
  227. FTransferListHoverIndex = -1;
  228. TransferList->OnChange = TransferListChange;
  229. TransferList->OnDrawItem = TransferListDrawItem;
  230. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  231. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  232. UseDesktopFont(SessionsPageControl);
  233. UpdateSessionsPageControlHeight();
  234. UseDesktopFont(RemoteDirView);
  235. UseDesktopFont(RemoteDriveView);
  236. UseDesktopFont(QueueView3);
  237. UseDesktopFont(QueueFileList);
  238. UseDesktopFont(QueueLabel);
  239. UseDesktopFont(RemoteStatusBar);
  240. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  241. QueueSplitter->ShowHint = true;
  242. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  243. QueueFileListSplitter->ShowHint = true;
  244. RemotePanelSplitter->ShowHint = true;
  245. UpdateImages();
  246. FCustomCommandMenu = CreateTBXPopupMenu(this);
  247. FCustomCommandLocalFileList = NULL;
  248. FCustomCommandRemoteFileList = NULL;
  249. FSessionColors = new TPngImageList(this);
  250. FSessionColors->ColorDepth = cd32Bit;
  251. AddFixedSessionImages();
  252. SessionsPageControl->Images = FSessionColors;
  253. UpdateQueueLabel();
  254. CreateHiddenWindow();
  255. StartUpdates();
  256. }
  257. //---------------------------------------------------------------------------
  258. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  259. {
  260. FInvalid = true;
  261. // this has to be one of the very first things to do
  262. StopUpdateThread();
  263. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  264. TTerminalManager::Instance()->ScpExplorer = NULL;
  265. delete FCustomCommandLocalFileList;
  266. delete FCustomCommandRemoteFileList;
  267. delete FCustomCommandMenu;
  268. delete FTrayIcon;
  269. FTrayIcon = NULL;
  270. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  271. delete FEditorManager;
  272. ForceCloseLocalEditors();
  273. delete FLocalEditors;
  274. HideFileFindDialog();
  275. if (FDelayedDeletionTimer)
  276. {
  277. DoDelayedDeletion(NULL);
  278. SAFE_DESTROY(FDelayedDeletionTimer);
  279. }
  280. SAFE_DESTROY(FDelayedDeletionList);
  281. // sometimes we do not get DDEnd so the list is not released
  282. SAFE_DESTROY(FDDFileList);
  283. DebugAssert(FSynchronizeController == NULL);
  284. CloseHandle(FDDExtMutex);
  285. FDDExtMutex = NULL;
  286. FreeLibrary(FOle32Library);
  287. FOle32Library = NULL;
  288. FDragMoveCursor = NULL;
  289. DebugAssert(!FErrorList);
  290. if (FEverShown)
  291. {
  292. // when window is never shown (like when running command-line operation),
  293. // particularly window site is not restored correctly (BoundsRect value set
  294. // in RestoreForm gets lost during handle allocation), so we do not want
  295. // it to be stored
  296. StoreParams();
  297. }
  298. Terminal = NULL;
  299. Queue = NULL;
  300. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  301. NonVisualDataModule->ScpExplorer = NULL;
  302. delete FQueueController;
  303. FQueueController = NULL;
  304. delete FQueueStatusSection;
  305. FQueueStatusSection = NULL;
  306. delete FQueueStatus;
  307. FQueueStatus = NULL;
  308. delete FUserActionTimer;
  309. FUserActionTimer = NULL;
  310. delete FNoteTimer;
  311. delete FNotes;
  312. delete FNoteData;
  313. SAFE_DESTROY(FDocks);
  314. SessionsPageControl->Images = NULL;
  315. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  316. SAFE_DESTROY(FSessionColors);
  317. SAFE_DESTROY(FSessionsDragDropFilesEx);
  318. SAFE_DESTROY(FHistoryMenu[0][0]);
  319. SAFE_DESTROY(FHistoryMenu[0][1]);
  320. SAFE_DESTROY(FHistoryMenu[1][0]);
  321. SAFE_DESTROY(FHistoryMenu[1][1]);
  322. if (FHiddenWindow != NULL)
  323. {
  324. DestroyWindow(FHiddenWindow);
  325. FHiddenWindow = NULL;
  326. }
  327. }
  328. //---------------------------------------------------------------------------
  329. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  330. {
  331. std::unique_ptr<TSessionData> Data;
  332. if (!Session.IsEmpty())
  333. {
  334. bool DefaultsOnly;
  335. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  336. }
  337. TTerminalManager * Manager = TTerminalManager::Instance();
  338. for (int Index = 0; Index < Manager->Count; Index++)
  339. {
  340. TTerminal * Terminal = Manager->Terminals[Index];
  341. if (Session.IsEmpty() ||
  342. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  343. {
  344. if (Path.IsEmpty())
  345. {
  346. Terminal->ClearCaches();
  347. }
  348. else
  349. {
  350. Terminal->DirectoryModified(Path, true);
  351. }
  352. }
  353. }
  354. // We should flag a pending refresh for the background terminals or busy foreground terminals
  355. if (HasActiveTerminal() &&
  356. CanCommandLineFromAnotherInstance() &&
  357. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  358. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  359. {
  360. Terminal->ReloadDirectory();
  361. }
  362. }
  363. //---------------------------------------------------------------------------
  364. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  365. {
  366. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  367. size_t MessageSize = sizeof(TCopyDataMessage);
  368. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  369. if (Result)
  370. {
  371. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  372. Result = (Message.Version == TCopyDataMessage::Version1);
  373. if (Result)
  374. {
  375. switch (Message.Command)
  376. {
  377. case TCopyDataMessage::CommandCanCommandLine:
  378. Result = CanCommandLineFromAnotherInstance();
  379. break;
  380. case TCopyDataMessage::CommandCommandLine:
  381. {
  382. UnicodeString CommandLine(Message.CommandLine);
  383. Result = CommandLineFromAnotherInstance(CommandLine);
  384. }
  385. break;
  386. case TCopyDataMessage::RefreshPanel:
  387. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  388. break;
  389. case TCopyDataMessage::MainWindowCheck:
  390. Result = true;
  391. break;
  392. default:
  393. Result = false;
  394. break;
  395. }
  396. }
  397. }
  398. Message.Result = Result ? 1 : 0;
  399. }
  400. //---------------------------------------------------------------------------
  401. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  402. {
  403. WNDCLASS WindowClass = {0};
  404. WindowClass.lpfnWndProc = DefWindowProc;
  405. WindowClass.hInstance = HInstance;
  406. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  407. FHiddenWindow = NULL;
  408. if (RegisterClass(&WindowClass))
  409. {
  410. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  411. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  412. }
  413. }
  414. //---------------------------------------------------------------------------
  415. bool __fastcall TCustomScpExplorerForm::CanConsole()
  416. {
  417. return
  418. HasActiveTerminal() &&
  419. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  420. }
  421. //---------------------------------------------------------------------------
  422. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  423. {
  424. bool Result = Visible && !NonVisualDataModule->Busy;
  425. return Result;
  426. }
  427. //---------------------------------------------------------------------------
  428. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  429. const UnicodeString & CommandLine)
  430. {
  431. TProgramParams Params(CommandLine);
  432. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  433. if (Result)
  434. {
  435. NonVisualDataModule->StartBusy();
  436. try
  437. {
  438. // this action is initiated from another process,
  439. // so it's likely that our window is not visible,
  440. // and user won't see what is going on
  441. Application->BringToFront();
  442. // reload sessions as we may be asked to open a session
  443. // just stored by another instance
  444. StoredSessions->Reload();
  445. UnicodeString SessionName = Params.Param[1];
  446. std::unique_ptr<TObjectList> DataList(new TObjectList());
  447. UnicodeString DownloadFile; // unused
  448. try
  449. {
  450. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  451. }
  452. catch (EAbort &)
  453. {
  454. // Happens when opening session in PuTTY and in other situations,
  455. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  456. // to process the command-line on its own (or to pass it to yet another instance)
  457. }
  458. if (DataList->Count > 0)
  459. {
  460. TTerminalManager * Manager = TTerminalManager::Instance();
  461. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  462. }
  463. }
  464. __finally
  465. {
  466. NonVisualDataModule->EndBusy();
  467. }
  468. }
  469. return Result;
  470. }
  471. //---------------------------------------------------------------------------
  472. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  473. {
  474. if (FTerminal != value)
  475. {
  476. TerminalChanging();
  477. DoSetTerminal(value, false);
  478. }
  479. }
  480. //---------------------------------------------------------------------------
  481. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  482. {
  483. FTerminal = value;
  484. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  485. FAllowTransferPresetAutoSelect = false;
  486. try
  487. {
  488. TerminalChanged(Replace);
  489. }
  490. __finally
  491. {
  492. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  493. }
  494. if (Terminal != NULL)
  495. {
  496. TransferPresetAutoSelect();
  497. }
  498. }
  499. //---------------------------------------------------------------------------
  500. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  501. {
  502. DoSetTerminal(value, true);
  503. }
  504. //---------------------------------------------------------------------------
  505. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  506. {
  507. if (FTerminal != NULL)
  508. {
  509. UpdateTerminal(Terminal);
  510. }
  511. }
  512. //---------------------------------------------------------------------------
  513. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  514. {
  515. if (Terminal != NULL)
  516. {
  517. UpdateSessionColor((TColor)Terminal->StateData->Color);
  518. }
  519. DoTerminalListChanged();
  520. DebugAssert(!IsLocalBrowserMode());
  521. if (Replaced)
  522. {
  523. RemoteDirView->ReplaceTerminal(Terminal);
  524. }
  525. else
  526. {
  527. RemoteDirView->Terminal = Terminal;
  528. }
  529. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  530. if (Terminal != NULL)
  531. {
  532. if (Terminal->Active)
  533. {
  534. Terminal->RefreshDirectory();
  535. }
  536. if (WinConfiguration->PreservePanelState)
  537. {
  538. if (Terminal->RemoteExplorerState != NULL)
  539. {
  540. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  541. }
  542. else
  543. {
  544. DirView(osRemote)->ClearState();
  545. }
  546. }
  547. }
  548. InitStatusBar();
  549. UpdateTransferList();
  550. // Update panels Enable state before refreshing the labels
  551. UpdateControls();
  552. }
  553. //---------------------------------------------------------------------------
  554. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  555. {
  556. if (Queue != value)
  557. {
  558. if (FQueue != NULL)
  559. {
  560. FQueue->OnListUpdate = NULL;
  561. FQueue->OnQueueItemUpdate = NULL;
  562. }
  563. FQueue = value;
  564. if (FQueue != NULL)
  565. {
  566. DebugAssert(FQueue->OnListUpdate == NULL);
  567. FQueue->OnListUpdate = QueueListUpdate;
  568. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  569. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  570. }
  571. QueueChanged();
  572. }
  573. }
  574. //---------------------------------------------------------------------------
  575. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  576. TListItem * Item)
  577. {
  578. if (FQueueActedItem == Item)
  579. {
  580. FQueueActedItem = NULL;
  581. if ((QueueView3->PopupMenu != NULL) &&
  582. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  583. {
  584. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  585. ReleaseCapture();
  586. }
  587. }
  588. if (Item->Data == FPendingQueueActionItem)
  589. {
  590. FPendingQueueActionItem = NULL;
  591. }
  592. }
  593. //---------------------------------------------------------------------------
  594. bool TCustomScpExplorerForm::IsAnythingQueued()
  595. {
  596. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  597. }
  598. //---------------------------------------------------------------------------
  599. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  600. {
  601. {
  602. TGuard Guard(FQueueStatusSection);
  603. FQueueStatusInvalidated = false;
  604. if (FQueue != NULL)
  605. {
  606. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  607. }
  608. }
  609. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  610. {
  611. FMaxQueueLength = FQueueStatus->Count;
  612. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  613. }
  614. {
  615. TAutoFlag Flag(FQueueStatusUpdating);
  616. FQueueController->UpdateQueueStatus(FQueueStatus);
  617. }
  618. UpdateQueueFileList();
  619. SetQueueProgress();
  620. UpdateQueueView();
  621. bool IsEmpty = !IsAnythingQueued();
  622. if (IsEmpty && (Terminal != NULL))
  623. {
  624. TOnceDoneOperation OnceDoneOperation =
  625. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  626. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  627. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  628. {
  629. FQueue->Enabled = false;
  630. }
  631. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  632. {
  633. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  634. }
  635. }
  636. }
  637. //---------------------------------------------------------------------------
  638. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  639. {
  640. UnicodeString Result;
  641. if (FQueueStatus != NULL)
  642. {
  643. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  644. {
  645. TFileOperationProgressType * ProgressData =
  646. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  647. if ((ProgressData != NULL) && ProgressData->InProgress)
  648. {
  649. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  650. }
  651. }
  652. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  653. {
  654. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  655. }
  656. }
  657. return Result;
  658. }
  659. //---------------------------------------------------------------------------
  660. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  661. {
  662. ComponentVisible[fcQueueView] =
  663. (WinConfiguration->QueueView.Show == qvShow) ||
  664. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  665. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  666. }
  667. //---------------------------------------------------------------------------
  668. void __fastcall TCustomScpExplorerForm::QueueChanged()
  669. {
  670. if (FQueueStatus != NULL)
  671. {
  672. // UpdateFileList implementation relies on the status being recreated when session changes
  673. delete FQueueStatus;
  674. FQueueStatus = NULL;
  675. }
  676. UpdateQueueStatus(true);
  677. }
  678. //---------------------------------------------------------------------------
  679. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  680. {
  681. if (FQueue == Queue)
  682. {
  683. FQueueStatusInvalidated = true;
  684. }
  685. }
  686. //---------------------------------------------------------------------------
  687. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  688. TQueueItem * Item)
  689. {
  690. if (FQueue == Queue)
  691. {
  692. TGuard Guard(FQueueStatusSection);
  693. // this may be running in parallel with QueueChanged
  694. if (FQueueStatus != NULL)
  695. {
  696. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  697. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  698. {
  699. FRefreshLocalDirectory = (QueueItem == NULL) ||
  700. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  701. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  702. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  703. }
  704. if (QueueItem != NULL)
  705. {
  706. QueueItem->UserData = (void*)true;
  707. FQueueItemInvalidated = true;
  708. }
  709. }
  710. }
  711. }
  712. //---------------------------------------------------------------------------
  713. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  714. {
  715. // during standalone editing, we have no way to see/control queue,
  716. // so we have to always popup prompts automatically
  717. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  718. }
  719. //---------------------------------------------------------------------------
  720. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  721. {
  722. if (FQueueStatus != NULL)
  723. {
  724. bool QueueAutoPopup = IsQueueAutoPopup();
  725. bool NeedRefresh = FQueueController->NeedRefresh();
  726. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  727. FQueueItemInvalidated = false;
  728. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  729. bool Updated = false;
  730. TQueueItemProxy * QueueItem;
  731. bool WasUserAction;
  732. for (int Index = 0; Index < Limit; Index++)
  733. {
  734. bool Update = false;
  735. QueueItem = FQueueStatus->Items[Index];
  736. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  737. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  738. (FPendingQueueActionItem == NULL))
  739. {
  740. FPendingQueueActionItem = QueueItem;
  741. FUserActionTimer->Enabled = true;
  742. }
  743. if ((bool)QueueItem->UserData)
  744. {
  745. QueueItem->UserData = (void*)false;
  746. QueueItem->Update();
  747. Updated = true;
  748. Update = true;
  749. }
  750. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  751. {
  752. Update = true;
  753. }
  754. if (Update)
  755. {
  756. FQueueController->RefreshQueueItem(QueueItem);
  757. }
  758. }
  759. if (Updated)
  760. {
  761. NonVisualDataModule->UpdateNonVisibleActions();
  762. SetQueueProgress();
  763. UpdateQueueFileList();
  764. }
  765. }
  766. }
  767. //---------------------------------------------------------------------------
  768. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  769. {
  770. if (FTaskbarList != NULL)
  771. {
  772. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  773. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  774. }
  775. }
  776. //---------------------------------------------------------------------------
  777. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  778. {
  779. if (Progress >= 0)
  780. {
  781. if (FTaskbarList != NULL)
  782. {
  783. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  784. }
  785. }
  786. else
  787. {
  788. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  789. }
  790. }
  791. //---------------------------------------------------------------------------
  792. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  793. {
  794. int OverallProgress;
  795. // FProgressForm is null when this is called from SetQueueProgress
  796. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  797. {
  798. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  799. }
  800. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  801. {
  802. OverallProgress = ProgressData->OverallProgress();
  803. }
  804. else
  805. {
  806. OverallProgress = -1;
  807. }
  808. SetTaskbarListProgressValue(OverallProgress);
  809. }
  810. //---------------------------------------------------------------------------
  811. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  812. {
  813. TTerminalManager::Instance()->QueueStatusUpdated();
  814. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  815. {
  816. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  817. {
  818. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  819. {
  820. TFileOperationProgressType * ProgressData = NULL;
  821. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  822. {
  823. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  824. }
  825. if ((ProgressData != NULL) &&
  826. ProgressData->InProgress)
  827. {
  828. SetTaskbarListProgressValue(ProgressData);
  829. }
  830. else
  831. {
  832. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  833. }
  834. }
  835. else
  836. {
  837. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  838. }
  839. }
  840. else
  841. {
  842. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  843. }
  844. }
  845. UpdateQueueLabel();
  846. }
  847. //---------------------------------------------------------------------------
  848. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  849. {
  850. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  851. if (FQueueStatus != NULL)
  852. {
  853. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  854. if (ActiveAndPendingPrimaryCount > 0)
  855. {
  856. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  857. }
  858. }
  859. QueueLabel->Caption = Caption;
  860. }
  861. //---------------------------------------------------------------------------
  862. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  863. {
  864. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  865. static_cast<TComponent*>(GetComponent(fcTransferList)));
  866. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  867. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  868. TransferList->Strings->BeginUpdate();
  869. try
  870. {
  871. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  872. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  873. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  874. if (FTransferDropDownHint.IsEmpty())
  875. {
  876. FTransferDropDownHint = TransferDropDown->Hint;
  877. }
  878. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  879. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  880. TransferDropDown->Text = StripHotkey(Name);
  881. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  882. (FTransferDropDownHint, StripHotkey(Name),
  883. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  884. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  885. // update the label, otherwise when it is updated only on the first draw
  886. // of the list, it is drawn "bold" for some reason
  887. FTransferListHoverIndex = TransferList->ItemIndex;
  888. UpdateTransferLabel();
  889. }
  890. __finally
  891. {
  892. TransferList->Strings->EndUpdate();
  893. }
  894. }
  895. //---------------------------------------------------------------------------
  896. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  897. {
  898. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  899. DebugAssert(Toolbar != NULL);
  900. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  901. }
  902. //---------------------------------------------------------------------------
  903. void __fastcall TCustomScpExplorerForm::UpdateActions()
  904. {
  905. TForm::UpdateActions();
  906. if (ComponentVisible[fcCustomCommandsBand])
  907. {
  908. UpdateCustomCommandsToolbar();
  909. }
  910. }
  911. //---------------------------------------------------------------------------
  912. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  913. {
  914. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  915. }
  916. //---------------------------------------------------------------------------
  917. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  918. {
  919. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  920. {
  921. DirView->RowSelect = WinConfiguration->FullRowSelect;
  922. // selection is not redrawn automatically when RowSelect changes
  923. DirView->Invalidate();
  924. }
  925. }
  926. //---------------------------------------------------------------------------
  927. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  928. {
  929. Color = GetBtnFaceColor();
  930. DebugAssert(Configuration && RemoteDirView);
  931. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  932. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  933. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  934. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  935. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  936. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  937. UpdateRowSelect(RemoteDirView);
  938. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  939. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  940. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  941. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  942. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  943. UpdateSessionsPageControlHeight();
  944. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  945. UpdateToolbarDisplayMode();
  946. UpdateTransferList();
  947. if (Terminal != NULL)
  948. {
  949. TransferPresetAutoSelect();
  950. }
  951. UpdateQueueView();
  952. UpdateControls();
  953. // this can be called even before constuctor finishes.
  954. if (FEditorManager != NULL)
  955. {
  956. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  957. }
  958. // this can be called even before constuctor finishes.
  959. if (FLocalEditors != NULL)
  960. {
  961. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  962. {
  963. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  964. }
  965. }
  966. if (ComponentVisible[fcCustomCommandsBand])
  967. {
  968. UpdateCustomCommandsToolbar();
  969. }
  970. // show only when keeping queue items forever,
  971. // otherwise, its enough to have in in the context menu
  972. QueueDeleteAllDoneQueueToolbarItem->Visible =
  973. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  974. if (FFileColorsCurrent != WinConfiguration->FileColors)
  975. {
  976. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  977. FFileColorsCurrent = WinConfiguration->FileColors;
  978. FileColorsChanged();
  979. }
  980. }
  981. //---------------------------------------------------------------------------
  982. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  983. {
  984. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  985. DirView->Invalidate();
  986. }
  987. //---------------------------------------------------------------------------
  988. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  989. {
  990. DoFileColorsChanged(RemoteDirView);
  991. }
  992. //---------------------------------------------------------------------------
  993. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  994. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  995. void * /*Arg*/)
  996. {
  997. if (Token != NULL)
  998. {
  999. TForm * Editor = dynamic_cast<TForm*>(Token);
  1000. DebugAssert(Editor != NULL);
  1001. ReconfigureEditorForm(Editor);
  1002. }
  1003. }
  1004. //---------------------------------------------------------------------------
  1005. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1006. {
  1007. WinConfiguration->DDTransferConfirmation = asOn;
  1008. }
  1009. //---------------------------------------------------------------------------
  1010. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1011. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1012. {
  1013. // noop
  1014. }
  1015. //---------------------------------------------------------------------------
  1016. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1017. TTransferDirection Direction, TTransferType Type, bool Temp,
  1018. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1019. bool Confirm, bool DragDrop, int Options)
  1020. {
  1021. bool Result = true;
  1022. DebugAssert(HasActiveTerminal());
  1023. // these parameters are known in advance
  1024. int Params =
  1025. FLAGMASK(Type == ttMove, cpDelete);
  1026. bool ToTemp = (Temp && (Direction == tdToLocal));
  1027. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1028. {
  1029. bool DisableNewerOnly =
  1030. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1031. ToTemp;
  1032. Options |=
  1033. FLAGMASK(ToTemp, coTemp) |
  1034. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1035. coDoNotShowAgain;
  1036. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1037. int CopyParamAttrs = (Direction == tdToRemote ?
  1038. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1039. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1040. int OutputOptions =
  1041. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1042. cooDoNotShowAgain);
  1043. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1044. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1045. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1046. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1047. if (Result)
  1048. {
  1049. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1050. {
  1051. if (DragDrop)
  1052. {
  1053. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1054. {
  1055. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1056. NULL, 0, EnableDDTransferConfirmation, NULL);
  1057. }
  1058. WinConfiguration->DDTransferConfirmation = asOff;
  1059. }
  1060. else
  1061. {
  1062. WinConfiguration->ConfirmTransferring = false;
  1063. }
  1064. }
  1065. else
  1066. {
  1067. // User explicitly unchecked "do not show again",
  1068. // so show him the dialog the next time
  1069. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1070. {
  1071. WinConfiguration->DDTransferConfirmation = asOn;
  1072. }
  1073. }
  1074. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1075. }
  1076. }
  1077. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1078. {
  1079. Configuration->Usage->Inc(L"TransfersOnBackground");
  1080. // these parameter are known only after transfer dialog
  1081. Params |=
  1082. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1083. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1084. Result = false;
  1085. ClearTransferSourceSelection(Direction);
  1086. }
  1087. return Result;
  1088. }
  1089. //---------------------------------------------------------------------------
  1090. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1091. {
  1092. if (FOnFileOperationFinished != NULL)
  1093. {
  1094. FOnFileOperationFinished(UnicodeString(), true);
  1095. }
  1096. else
  1097. {
  1098. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1099. if (HasDirView[Side])
  1100. {
  1101. DirView(Side)->SelectAll(smNone);
  1102. }
  1103. }
  1104. }
  1105. //---------------------------------------------------------------------------
  1106. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1107. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1108. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1109. int Params)
  1110. {
  1111. DebugAssert(Queue != NULL);
  1112. bool SingleFile = false;
  1113. if (FileList->Count == 1)
  1114. {
  1115. if (Direction == tdToRemote)
  1116. {
  1117. UnicodeString FileName = FileList->Strings[0];
  1118. SingleFile = FileExists(ApiPath(FileName));
  1119. }
  1120. else
  1121. {
  1122. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1123. SingleFile = !File->IsDirectory;
  1124. }
  1125. }
  1126. TQueueItem * QueueItem;
  1127. if (Direction == tdToRemote)
  1128. {
  1129. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1130. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1131. }
  1132. else
  1133. {
  1134. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1135. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1136. }
  1137. AddQueueItem(Queue, QueueItem, Terminal);
  1138. }
  1139. //---------------------------------------------------------------------------
  1140. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1141. {
  1142. if (Queue->IsEmpty)
  1143. {
  1144. Terminal->QueueOperationStart = Now();
  1145. }
  1146. Queue->AddItem(QueueItem);
  1147. }
  1148. //---------------------------------------------------------------------------
  1149. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1150. {
  1151. }
  1152. //---------------------------------------------------------------------------
  1153. void __fastcall TCustomScpExplorerForm::InitControls()
  1154. {
  1155. DebugAssert(FDocks != NULL);
  1156. for (int Index = 0; Index < ComponentCount; Index++)
  1157. {
  1158. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1159. if ((Dock != NULL) && (Dock->Tag == 0))
  1160. {
  1161. FDocks->Add(Dock);
  1162. }
  1163. }
  1164. CollectItemsWithTextDisplayMode(this);
  1165. }
  1166. //---------------------------------------------------------------------------
  1167. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1168. {
  1169. ConfigurationChanged();
  1170. QueuePanel->Height =
  1171. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1172. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1173. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1174. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1175. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1176. QueueFileList->Height =
  1177. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1178. if (QueueFileList->Visible)
  1179. {
  1180. AdjustQueueLayout();
  1181. }
  1182. UpdateCustomCommandsToolbar();
  1183. }
  1184. //---------------------------------------------------------------------------
  1185. void __fastcall TCustomScpExplorerForm::StoreParams()
  1186. {
  1187. int APixelsPerInch = GetControlPixelsPerInch(this);
  1188. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1189. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1190. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1191. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1192. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1193. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1194. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1195. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1196. }
  1197. //---------------------------------------------------------------------------
  1198. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1199. {
  1200. if (!FFormRestored)
  1201. {
  1202. FFormRestored = true;
  1203. RestoreFormParams();
  1204. }
  1205. TForm::CreateParams(Params);
  1206. }
  1207. //---------------------------------------------------------------------------
  1208. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1209. {
  1210. DebugAssert(FDocks != NULL);
  1211. for (int Index = 0; Index < FDocks->Count; Index++)
  1212. {
  1213. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1214. }
  1215. }
  1216. //---------------------------------------------------------------------------
  1217. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1218. {
  1219. SetDockAllowDrag(true);
  1220. while (!ButtonsStr.IsEmpty())
  1221. {
  1222. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1223. UnicodeString Name = CutToChar(S, L'=', true);
  1224. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1225. {
  1226. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1227. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1228. {
  1229. while (!S.IsEmpty())
  1230. {
  1231. UnicodeString S2 = CutToChar(S, L',', true);
  1232. UnicodeString Name = CutToChar(S2, L':', true);
  1233. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1234. {
  1235. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1236. if (SameText(GetToolbarItemName(Item), Name))
  1237. {
  1238. // forward compatibility
  1239. UnicodeString S3 = CutToChar(S2, L':', true);
  1240. bool Visible = StrToIntDef(S3, 0);
  1241. Item->Visible = Visible;
  1242. }
  1243. }
  1244. }
  1245. }
  1246. }
  1247. }
  1248. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1249. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1250. }
  1251. //---------------------------------------------------------------------------
  1252. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1253. {
  1254. UnicodeString Result;
  1255. SetDockAllowDrag(true);
  1256. Result = ::GetToolbarsLayoutStr(this);
  1257. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1258. return Result;
  1259. }
  1260. //---------------------------------------------------------------------------
  1261. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1262. {
  1263. UnicodeString Result;
  1264. if (Item->Action != NULL)
  1265. {
  1266. Result = Item->Action->Name;
  1267. Result = RemoveSuffix(Result, L"Action", true);
  1268. }
  1269. else
  1270. {
  1271. Result = Item->Name;
  1272. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1273. Result = RemoveSuffix(Result, L"Item", true);
  1274. }
  1275. return Result;
  1276. }
  1277. //---------------------------------------------------------------------------
  1278. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1279. {
  1280. UnicodeString Result;
  1281. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1282. {
  1283. UnicodeString ToolbarStr;
  1284. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1285. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1286. {
  1287. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1288. {
  1289. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1290. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1291. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1292. // and save the changes here only.
  1293. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1294. {
  1295. UnicodeString Name = GetToolbarItemName(Item);
  1296. DebugAssert(Name.Pos(L"TBX") == 0);
  1297. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1298. }
  1299. }
  1300. }
  1301. if (!ToolbarStr.IsEmpty())
  1302. {
  1303. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1304. }
  1305. }
  1306. return Result;
  1307. }
  1308. //---------------------------------------------------------------------------
  1309. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1310. {
  1311. DebugAssert(FProgressForm == NULL);
  1312. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1313. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1314. FProgressForm->DeleteLocalToRecycleBin =
  1315. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1316. FProgressForm->DeleteRemoteToRecycleBin =
  1317. (Terminal != NULL) &&
  1318. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1319. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1320. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1321. LockWindow();
  1322. // Actually, do not know what hides the progress once the operation finishes
  1323. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1324. SetTaskbarListProgressState(TBPF_NORMAL);
  1325. }
  1326. //---------------------------------------------------------------------------
  1327. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1328. {
  1329. UnlockWindow();
  1330. SAFE_DESTROY(FProgressForm);
  1331. SetQueueProgress();
  1332. }
  1333. //---------------------------------------------------------------------------
  1334. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1335. TFileOperationProgressType & ProgressData)
  1336. {
  1337. // Download to temporary local directory
  1338. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1339. {
  1340. bool Continue = true;
  1341. FPendingTempSpaceWarn = false;
  1342. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1343. if (!Continue)
  1344. {
  1345. Abort();
  1346. }
  1347. }
  1348. // operation is being executed and we still didn't show up progress form
  1349. if (ProgressData.InProgress && !FProgressForm)
  1350. {
  1351. CreateProgressForm(NULL);
  1352. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1353. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1354. }
  1355. // operation is finished (or terminated), so we hide progress form
  1356. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1357. {
  1358. DestroyProgressForm();
  1359. if (ProgressData.Operation == foCalculateSize)
  1360. {
  1361. // When calculating size before transfer, the abort caused by
  1362. // cancel flag set due to "MoveToQueue" below,
  1363. // is not propagated back to us in ExecuteFileOperation,
  1364. // as it is silently swallowed.
  1365. // So we explicitly (re)throw it here.
  1366. if (FMoveToQueue)
  1367. {
  1368. Abort();
  1369. }
  1370. }
  1371. else
  1372. {
  1373. if ((ProgressData.Cancel == csContinue) &&
  1374. !FAutoOperation)
  1375. {
  1376. OperationComplete(ProgressData.StartTime);
  1377. }
  1378. }
  1379. }
  1380. if (FProgressForm &&
  1381. // Can happen only during synchronization, when ending one of the operations
  1382. ProgressData.InProgress)
  1383. {
  1384. FProgressForm->SetProgressData(ProgressData);
  1385. DebugAssert(ProgressData.InProgress);
  1386. SetTaskbarListProgressValue(&ProgressData);
  1387. if (FProgressForm->Cancel > csContinue)
  1388. {
  1389. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1390. if (FProgressForm->Cancel == csCancelFile)
  1391. {
  1392. FProgressForm->ClearCancel();
  1393. }
  1394. // cancel cancels even the move
  1395. FMoveToQueue = false;
  1396. }
  1397. else if (FProgressForm->MoveToQueue)
  1398. {
  1399. FMoveToQueue = true;
  1400. ProgressData.SetCancelAtLeast(csCancel);
  1401. }
  1402. if ((FTransferResumeList != NULL) &&
  1403. ProgressData.InProgress &&
  1404. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1405. !ProgressData.FullFileName.IsEmpty())
  1406. {
  1407. if ((FTransferResumeList->Count == 0) ||
  1408. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1409. {
  1410. // note that we do not recognize directories from files here
  1411. FTransferResumeList->Add(ProgressData.FullFileName);
  1412. }
  1413. }
  1414. }
  1415. }
  1416. //---------------------------------------------------------------------------
  1417. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1418. const TDateTime & StartTime)
  1419. {
  1420. if (GUIConfiguration->BeepOnFinish &&
  1421. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1422. {
  1423. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1424. DWORD Sound;
  1425. if (!ExtractFileExt(BeepSound).IsEmpty())
  1426. {
  1427. Sound = SND_FILENAME;
  1428. }
  1429. else
  1430. {
  1431. Sound = SND_ALIAS;
  1432. }
  1433. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1434. }
  1435. }
  1436. //---------------------------------------------------------------------------
  1437. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1438. TFileOperationProgressType & ProgressData)
  1439. {
  1440. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1441. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1442. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1443. FileOperationProgress(ProgressData);
  1444. }
  1445. //---------------------------------------------------------------------------
  1446. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1447. {
  1448. UnicodeString Result;
  1449. if (FProgressForm != NULL)
  1450. {
  1451. Result = FProgressForm->ProgressStr();
  1452. }
  1453. return Result;
  1454. }
  1455. //---------------------------------------------------------------------------
  1456. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1457. bool DragDrop)
  1458. {
  1459. return (!DragDrop && (DropSourceControl == NULL)) ||
  1460. (DropSourceControl == DirView(osOther));
  1461. }
  1462. //---------------------------------------------------------------------------
  1463. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1464. TFileOperation Operation, TOperationSide Side,
  1465. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1466. TOnceDoneOperation & OnceDoneOperation)
  1467. {
  1468. if (!FAutoOperation)
  1469. {
  1470. // no selection on "/upload", form serves only as event handler
  1471. // (it is not displayed)
  1472. if (PanelOperation(Side, FDragDropOperation) &&
  1473. Visible && (Operation != foCalculateSize) &&
  1474. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1475. {
  1476. if (FOnFileOperationFinished != NULL)
  1477. {
  1478. FOnFileOperationFinished(FileName, Success);
  1479. }
  1480. else
  1481. {
  1482. TOperationSide DViewSide;
  1483. if ((FProgressSide != osCurrent) &&
  1484. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1485. {
  1486. // assume the operation is over the focused panel
  1487. DViewSide = FProgressSide;
  1488. }
  1489. else
  1490. {
  1491. DViewSide = Side;
  1492. }
  1493. TCustomDirView * DView = DirView(DViewSide);
  1494. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(DViewSide));
  1495. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1496. // this can happen when local drive is unplugged in the middle of the operation
  1497. if (Item != NULL)
  1498. {
  1499. if (Success) Item->Selected = false;
  1500. DView->MakeProgressVisible(Item);
  1501. }
  1502. }
  1503. }
  1504. if ((Operation == foCopy) || (Operation == foMove))
  1505. {
  1506. if (DebugAlwaysTrue(!IsLocalBrowserMode()))
  1507. {
  1508. if (Side == osLocal)
  1509. {
  1510. Configuration->Usage->Inc(L"UploadedFiles");
  1511. }
  1512. else
  1513. {
  1514. Configuration->Usage->Inc(L"DownloadedFiles");
  1515. }
  1516. }
  1517. }
  1518. }
  1519. if (Success && (FSynchronizeController != NULL))
  1520. {
  1521. DebugAssert(!IsSideLocalBrowser(osRemote));
  1522. if (Operation == foCopy)
  1523. {
  1524. DebugAssert(Side == osLocal);
  1525. FSynchronizeController->LogOperation(soUpload, FileName);
  1526. }
  1527. else if (Operation == foDelete)
  1528. {
  1529. DebugAssert(Side == osRemote);
  1530. FSynchronizeController->LogOperation(soDelete, FileName);
  1531. }
  1532. }
  1533. if (FProgressForm)
  1534. {
  1535. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1536. }
  1537. }
  1538. //---------------------------------------------------------------------------
  1539. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1540. TFileOperation Operation, TOperationSide Side,
  1541. bool Temp, const UnicodeString & FileName, Boolean Success,
  1542. TOnceDoneOperation & OnceDoneOperation)
  1543. {
  1544. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1545. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1546. OnceDoneOperation);
  1547. }
  1548. //---------------------------------------------------------------------------
  1549. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1550. {
  1551. return false;
  1552. }
  1553. //---------------------------------------------------------------------------
  1554. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1555. {
  1556. return false;
  1557. }
  1558. //---------------------------------------------------------------------------
  1559. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1560. {
  1561. return NULL;
  1562. }
  1563. //---------------------------------------------------------------------------
  1564. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1565. {
  1566. DebugAssert(GetSide(Side) == osRemote);
  1567. DebugUsedParam(Side);
  1568. return RemoteDirView;
  1569. }
  1570. //---------------------------------------------------------------------------
  1571. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1572. {
  1573. DebugAssert(GetSide(Side) == osRemote);
  1574. DebugUsedParam(Side);
  1575. return RemoteDriveView;
  1576. }
  1577. //---------------------------------------------------------------------------
  1578. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1579. {
  1580. DebugAssert(GetSide(Side) == osRemote);
  1581. DebugUsedParam(Side);
  1582. return HasActiveTerminal();
  1583. }
  1584. //---------------------------------------------------------------------------
  1585. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1586. TOperationSide Side, int FilesOnly)
  1587. {
  1588. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1589. }
  1590. //---------------------------------------------------------------------------
  1591. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1592. TOperationSide Side, int FilesOnly)
  1593. {
  1594. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1595. }
  1596. //---------------------------------------------------------------------------
  1597. struct THistoryItemData
  1598. {
  1599. short int Side;
  1600. short int Index;
  1601. };
  1602. //---------------------------------------------------------------------------
  1603. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1604. {
  1605. DirView(Side)->HistoryGo(Index);
  1606. }
  1607. //---------------------------------------------------------------------------
  1608. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1609. {
  1610. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1611. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1612. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1613. }
  1614. //---------------------------------------------------------------------------
  1615. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1616. bool Back)
  1617. {
  1618. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1619. {
  1620. TCustomDirView * DView = DirView(Side);
  1621. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1622. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1623. if (ICount > 10)
  1624. {
  1625. ICount = 10;
  1626. }
  1627. Menu->Items->Clear();
  1628. THistoryItemData Data;
  1629. Data.Side = Side;
  1630. for (short int i = 1; i <= ICount; i++)
  1631. {
  1632. TTBCustomItem * Item = new TTBXItem(Menu);
  1633. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1634. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1635. Item->Hint = DView->HistoryPath[Data.Index];
  1636. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1637. Item->Tag = *reinterpret_cast<int*>(&Data);
  1638. Item->OnClick = HistoryItemClick;
  1639. Menu->Items->Add(Item);
  1640. }
  1641. }
  1642. }
  1643. //---------------------------------------------------------------------------
  1644. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1645. TOperationSide Side, bool Back)
  1646. {
  1647. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1648. {
  1649. // workaround
  1650. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1651. // operator new allocates memory in Pascal code, but calls inline
  1652. // contructor in C++, leading in problems, the function does
  1653. // both in Pascal code
  1654. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1655. UpdateHistoryMenu(Side, Back);
  1656. }
  1657. return FHistoryMenu[Side == osLocal][Back];
  1658. }
  1659. //---------------------------------------------------------------------------
  1660. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1661. TCustomDirView *Sender)
  1662. {
  1663. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1664. UpdateHistoryMenu(Side, true);
  1665. UpdateHistoryMenu(Side, false);
  1666. }
  1667. //---------------------------------------------------------------------------
  1668. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1669. {
  1670. // remote custom commands can be executed only if the server supports shell commands
  1671. // or have secondary shell
  1672. return HasActiveTerminal() && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1673. }
  1674. //---------------------------------------------------------------------------
  1675. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1676. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1677. {
  1678. // -1 = hidden, 0 = disabled, 1 = enabled
  1679. int Result;
  1680. TFileCustomCommand RemoteCustomCommand;
  1681. TLocalCustomCommand LocalCustomCommand;
  1682. TFileCustomCommand * NonInteractiveCustomCommand =
  1683. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1684. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1685. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1686. if (FLAGCLEAR(Command.Params, ccLocal))
  1687. {
  1688. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1689. // custom command that does not operate with files can be executed anytime ...
  1690. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1691. {
  1692. // ... but do not show such command in remote file menu
  1693. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1694. {
  1695. Result = AllowedState;
  1696. }
  1697. else
  1698. {
  1699. Result = -1;
  1700. }
  1701. }
  1702. else
  1703. {
  1704. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1705. {
  1706. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1707. }
  1708. else
  1709. {
  1710. Result = -1;
  1711. }
  1712. }
  1713. }
  1714. else
  1715. {
  1716. // custom command that does not operate with files can be executed anytime
  1717. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1718. {
  1719. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1720. }
  1721. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1722. {
  1723. if ((ListType == ccltAll) || (ListType == ccltFile))
  1724. {
  1725. // special case is "diff"-style command that can be executed over any side,
  1726. // if we have both sides
  1727. Result =
  1728. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1729. // directly (instead of EnableSelectedOperation) to pass
  1730. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1731. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1732. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1733. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1734. }
  1735. else if (ListType == ccltBoth)
  1736. {
  1737. DebugAssert(!IsLocalBrowserMode());
  1738. Result = 1;
  1739. }
  1740. else
  1741. {
  1742. Result = -1;
  1743. }
  1744. }
  1745. else
  1746. {
  1747. if ((ListType == ccltAll) ||
  1748. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1749. {
  1750. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1751. }
  1752. else
  1753. {
  1754. Result = -1;
  1755. }
  1756. }
  1757. if ((Result > 0) &&
  1758. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1759. !HasActiveTerminal())
  1760. {
  1761. Result = 0;
  1762. }
  1763. }
  1764. return Result;
  1765. }
  1766. //---------------------------------------------------------------------------
  1767. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1768. TStrings * FileList, const TCustomCommandType & ACommand,
  1769. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1770. {
  1771. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1772. {
  1773. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1774. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1775. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1776. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1777. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1778. bool Capture =
  1779. FLAGSET(ACommand.Params, ccShowResults) ||
  1780. FLAGSET(ACommand.Params, ccCopyResults) ||
  1781. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1782. TCaptureOutputEvent OutputEvent = NULL;
  1783. DebugAssert(FCapturedLog == NULL);
  1784. if (Capture)
  1785. {
  1786. FCapturedLog = new TStringList();
  1787. OutputEvent = TerminalCaptureLog;
  1788. }
  1789. try
  1790. {
  1791. if (!RemoteCustomCommand.IsFileCommand(Command))
  1792. {
  1793. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1794. OutputEvent);
  1795. }
  1796. else
  1797. {
  1798. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1799. }
  1800. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1801. {
  1802. if (FLAGSET(ACommand.Params, ccCopyResults))
  1803. {
  1804. CopyToClipboard(FCapturedLog);
  1805. }
  1806. if (FLAGSET(ACommand.Params, ccShowResults))
  1807. {
  1808. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1809. }
  1810. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1811. {
  1812. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1813. }
  1814. }
  1815. }
  1816. __finally
  1817. {
  1818. SAFE_DESTROY(FCapturedLog);
  1819. }
  1820. }
  1821. }
  1822. //---------------------------------------------------------------------------
  1823. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1824. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1825. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1826. {
  1827. DebugAssert(!IsLocalBrowserMode());
  1828. TStrings * LocalFileList = NULL;
  1829. TStrings * RemoteFileList = NULL;
  1830. TStrings * RemoteFileListFull = NULL;
  1831. try
  1832. {
  1833. if (LocalFileCommand)
  1834. {
  1835. if (ALocalFileList == NULL)
  1836. {
  1837. DebugAssert(HasDirView[osLocal]);
  1838. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1839. // directly (instead of EnableSelectedOperation) to pass
  1840. // false to FocusedFileOnlyWhenFocused
  1841. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1842. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1843. }
  1844. else
  1845. {
  1846. LocalFileList = ALocalFileList;
  1847. }
  1848. if (FileListCommand)
  1849. {
  1850. if (LocalFileList->Count != 1)
  1851. {
  1852. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1853. }
  1854. }
  1855. else
  1856. {
  1857. if ((LocalFileList->Count != 1) &&
  1858. (FileList->Count != 1) &&
  1859. (LocalFileList->Count != FileList->Count))
  1860. {
  1861. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1862. }
  1863. }
  1864. }
  1865. UnicodeString RootTempDir;
  1866. UnicodeString TempDir;
  1867. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1868. if (!RemoteFiles)
  1869. {
  1870. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1871. }
  1872. try
  1873. {
  1874. TDateTimes RemoteFileTimes;
  1875. if (RemoteFiles)
  1876. {
  1877. RemoteFileList = FileList;
  1878. }
  1879. else
  1880. {
  1881. RemoteFileList = new TStringList();
  1882. TMakeLocalFileListParams MakeFileListParam;
  1883. MakeFileListParam.FileList = RemoteFileList;
  1884. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1885. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1886. MakeFileListParam.Recursive =
  1887. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1888. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1889. if (!MakeFileListParam.Recursive)
  1890. {
  1891. RemoteFileTimes.clear();
  1892. RemoteFileListFull = new TStringList();
  1893. MakeFileListParam.FileList = RemoteFileListFull;
  1894. MakeFileListParam.Recursive = true;
  1895. MakeFileListParam.IncludeDirs = false;
  1896. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1897. }
  1898. else
  1899. {
  1900. RemoteFileListFull = RemoteFileList;
  1901. }
  1902. }
  1903. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1904. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1905. if (!NonBlocking)
  1906. {
  1907. int Count;
  1908. if (FileListCommand)
  1909. {
  1910. Count = 1;
  1911. }
  1912. else if (LocalFileCommand)
  1913. {
  1914. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1915. }
  1916. else
  1917. {
  1918. Count = RemoteFileList->Count;
  1919. }
  1920. Progress.Start(foCustomCommand, osRemote, Count);
  1921. DebugAssert(FProgressForm != NULL);
  1922. FProgressForm->ReadOnly = true;
  1923. }
  1924. try
  1925. {
  1926. if (FileListCommand)
  1927. {
  1928. UnicodeString LocalFile;
  1929. // MakeFileList does not delimit filenames
  1930. UnicodeString FileList = MakeFileList(RemoteFileList);
  1931. if (LocalFileCommand)
  1932. {
  1933. DebugAssert(LocalFileList->Count == 1);
  1934. LocalFile = LocalFileList->Strings[0];
  1935. }
  1936. TLocalCustomCommand CustomCommand(Data,
  1937. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1938. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1939. if (NonBlocking)
  1940. {
  1941. DebugAssert(!POutput);
  1942. ExecuteShellChecked(ShellCommand);
  1943. }
  1944. else
  1945. {
  1946. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1947. }
  1948. }
  1949. else if (LocalFileCommand)
  1950. {
  1951. if (LocalFileList->Count == 1)
  1952. {
  1953. UnicodeString LocalFile = LocalFileList->Strings[0];
  1954. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1955. {
  1956. UnicodeString FileName = RemoteFileList->Strings[Index];
  1957. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1958. Progress.SetFile(FileNameForProgress);
  1959. TLocalCustomCommand CustomCommand(Data,
  1960. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1961. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1962. TOnceDoneOperation OnceDoneOperation;
  1963. // Do not unselect anything, as it won't work with two panels anyway
  1964. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1965. }
  1966. }
  1967. else if (RemoteFileList->Count == 1)
  1968. {
  1969. UnicodeString FileName = RemoteFileList->Strings[0];
  1970. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1971. {
  1972. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1973. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1974. Progress.SetFile(LocalFileNameOnly);
  1975. TLocalCustomCommand CustomCommand(
  1976. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1977. FileName, LocalFileName, L"");
  1978. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1979. TOnceDoneOperation OnceDoneOperation;
  1980. // Do not unselect anything, as it won't work with two panels anyway
  1981. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1982. }
  1983. }
  1984. else
  1985. {
  1986. if (LocalFileList->Count != RemoteFileList->Count)
  1987. {
  1988. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1989. }
  1990. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1991. {
  1992. UnicodeString FileName = RemoteFileList->Strings[Index];
  1993. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1994. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1995. Progress.SetFile(LocalFileNameOnly); // sic
  1996. TLocalCustomCommand CustomCommand(
  1997. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1998. FileName, LocalFileName, L"");
  1999. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2000. TOnceDoneOperation OnceDoneOperation;
  2001. // Do not unselect anything, as it won't work with two panels anyway
  2002. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2003. }
  2004. }
  2005. }
  2006. else
  2007. {
  2008. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2009. {
  2010. UnicodeString FileName = RemoteFileList->Strings[Index];
  2011. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2012. Progress.SetFile(FileNameForProgress);
  2013. TLocalCustomCommand CustomCommand(Data,
  2014. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2015. FileName, L"", L"");
  2016. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2017. TOnceDoneOperation OnceDoneOperation;
  2018. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2019. }
  2020. }
  2021. }
  2022. __finally
  2023. {
  2024. if (!NonBlocking)
  2025. {
  2026. Progress.Stop();
  2027. }
  2028. }
  2029. DebugAssert(!FAutoOperation);
  2030. if (!RemoteFiles)
  2031. {
  2032. TempDir = IncludeTrailingBackslash(TempDir);
  2033. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2034. {
  2035. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2036. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2037. // Skip directories, process only nested files.
  2038. // The check is redundant as FileAge fails for directories anyway.
  2039. !DirectoryExists(FileName))
  2040. {
  2041. UnicodeString RemoteDir =
  2042. UnixExtractFileDir(
  2043. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2044. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2045. TDateTime NewTime;
  2046. if (FileAge(FileName, NewTime) &&
  2047. (NewTime != RemoteFileTimes[Index]))
  2048. {
  2049. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2050. TemporaryFileCopyParam(CopyParam);
  2051. CopyParam.FileMask = L"";
  2052. FAutoOperation = true;
  2053. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2054. TemporaryFilesList->Add(FileName);
  2055. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2056. }
  2057. }
  2058. }
  2059. }
  2060. }
  2061. __finally
  2062. {
  2063. FAutoOperation = false;
  2064. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2065. {
  2066. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2067. }
  2068. }
  2069. }
  2070. __finally
  2071. {
  2072. if (RemoteFileList != FileList)
  2073. {
  2074. delete RemoteFileList;
  2075. }
  2076. if (LocalFileList != ALocalFileList)
  2077. {
  2078. delete LocalFileList;
  2079. }
  2080. if (RemoteFileListFull != RemoteFileList)
  2081. {
  2082. delete RemoteFileListFull;
  2083. }
  2084. }
  2085. }
  2086. //---------------------------------------------------------------------------
  2087. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2088. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2089. bool FileListCommand, UnicodeString * POutput)
  2090. {
  2091. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2092. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2093. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2094. {
  2095. UnicodeString FileName = SelectedFileList->Strings[Index];
  2096. if (DirectoryExists(FileName))
  2097. {
  2098. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2099. {
  2100. LocalFileList->Add(FileName);
  2101. }
  2102. if (FLAGSET(ACommand.Params, ccRecursive))
  2103. {
  2104. TMakeLocalFileListParams MakeFileListParam;
  2105. MakeFileListParam.FileList = LocalFileList.get();
  2106. MakeFileListParam.FileTimes = NULL;
  2107. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2108. MakeFileListParam.Recursive = true;
  2109. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2110. }
  2111. }
  2112. else
  2113. {
  2114. LocalFileList->Add(FileName);
  2115. }
  2116. }
  2117. UnicodeString RemotePath;
  2118. if (Terminal != NULL)
  2119. {
  2120. RemotePath = Terminal->CurrentDirectory;
  2121. }
  2122. if (FileListCommand)
  2123. {
  2124. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2125. TLocalCustomCommand CustomCommand(
  2126. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2127. L"", L"", FileList);
  2128. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2129. }
  2130. else
  2131. {
  2132. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2133. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2134. DebugAssert(FProgressForm != NULL);
  2135. FProgressForm->ReadOnly = true;
  2136. try
  2137. {
  2138. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2139. {
  2140. UnicodeString FileName = LocalFileList->Strings[Index];
  2141. Progress.SetFile(FileName);
  2142. TLocalCustomCommand CustomCommand(
  2143. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2144. FileName, L"", L"");
  2145. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2146. TOnceDoneOperation OnceDoneOperation;
  2147. Progress.Finish(FileName, true, OnceDoneOperation);
  2148. }
  2149. }
  2150. __finally
  2151. {
  2152. Progress.Stop();
  2153. }
  2154. }
  2155. }
  2156. //---------------------------------------------------------------------------
  2157. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2158. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2159. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2160. {
  2161. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2162. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2163. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2164. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2165. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2166. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2167. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2168. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2169. std::unique_ptr<UnicodeString> POutput;
  2170. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2171. FLAGSET(ACommand.Params, ccCopyResults))
  2172. {
  2173. POutput.reset(new UnicodeString());
  2174. }
  2175. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  2176. FProgressSide = FCurrentSide;
  2177. if (!LocalCustomCommand.IsFileCommand(Command))
  2178. {
  2179. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2180. }
  2181. // remote files?
  2182. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2183. {
  2184. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2185. }
  2186. // local files
  2187. else
  2188. {
  2189. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2190. }
  2191. if (POutput.get() != NULL)
  2192. {
  2193. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2194. int P = POutput->Pos(sLineBreak);
  2195. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2196. {
  2197. POutput->SetLength(P - 1);
  2198. }
  2199. // Copy even empty output to clipboard
  2200. if (FLAGSET(ACommand.Params, ccCopyResults))
  2201. {
  2202. CopyToClipboard(*POutput);
  2203. }
  2204. // But do not show an empty message box.
  2205. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2206. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2207. !POutput->IsEmpty())
  2208. {
  2209. TClipboardHandler ClipboardHandler;
  2210. ClipboardHandler.Text = *POutput;
  2211. TMessageParams Params;
  2212. TQueryButtonAlias Aliases[1];
  2213. Aliases[0].Button = qaRetry;
  2214. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2215. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2216. Params.Aliases = Aliases;
  2217. Params.AliasesCount = LENOF(Aliases);
  2218. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2219. }
  2220. }
  2221. }
  2222. //---------------------------------------------------------------------------
  2223. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2224. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2225. {
  2226. TCustomCommandData Data;
  2227. UnicodeString Site;
  2228. UnicodeString RemotePath;
  2229. if (HasActiveTerminal())
  2230. {
  2231. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2232. Data = TCustomCommandData(SessionData.get());
  2233. Site = Terminal->SessionData->SessionKey;
  2234. RemotePath = Terminal->CurrentDirectory;
  2235. }
  2236. UnicodeString HelpKeyword = ACommand.HomePage;
  2237. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2238. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2239. {
  2240. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2241. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2242. {
  2243. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2244. }
  2245. else
  2246. {
  2247. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2248. }
  2249. if (!DoCustomCommandOptionsDialog(
  2250. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2251. {
  2252. Abort();
  2253. }
  2254. }
  2255. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2256. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2257. {
  2258. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2259. }
  2260. else
  2261. {
  2262. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2263. }
  2264. }
  2265. //---------------------------------------------------------------------------
  2266. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2267. const TCustomCommandType & Command)
  2268. {
  2269. DebugAssert(FCustomCommandLocalFileList != NULL);
  2270. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2271. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2272. TStrings * LocalFileList = new TStringList();
  2273. TStrings * RemoteFileList = new TStringList();
  2274. try
  2275. {
  2276. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2277. {
  2278. LocalFileList->Clear();
  2279. LocalFileList->AddObject(
  2280. FCustomCommandLocalFileList->Strings[Index],
  2281. FCustomCommandLocalFileList->Objects[Index]);
  2282. RemoteFileList->Clear();
  2283. RemoteFileList->AddObject(
  2284. FCustomCommandRemoteFileList->Strings[Index],
  2285. FCustomCommandRemoteFileList->Objects[Index]);
  2286. CustomCommand(RemoteFileList, Command, LocalFileList);
  2287. }
  2288. }
  2289. __finally
  2290. {
  2291. delete LocalFileList;
  2292. delete RemoteFileList;
  2293. }
  2294. }
  2295. //---------------------------------------------------------------------------
  2296. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2297. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2298. {
  2299. delete FCustomCommandLocalFileList;
  2300. delete FCustomCommandRemoteFileList;
  2301. // takeover ownership,
  2302. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2303. FCustomCommandLocalFileList = LocalFileList;
  2304. FCustomCommandRemoteFileList = RemoteFileList;
  2305. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2306. if (Button != NULL)
  2307. {
  2308. FCustomCommandMenu->Items->Clear();
  2309. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2310. MenuPopup(FCustomCommandMenu, Button);
  2311. }
  2312. else
  2313. {
  2314. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2315. }
  2316. }
  2317. //---------------------------------------------------------------------------
  2318. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2319. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2320. {
  2321. DebugAssert(FCapturedLog != NULL);
  2322. if ((OutputType == cotOutput) || (OutputType == cotError))
  2323. {
  2324. FCapturedLog->Add(AddedLine);
  2325. }
  2326. }
  2327. //---------------------------------------------------------------------------
  2328. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2329. TOperationSide Side)
  2330. {
  2331. return
  2332. (Side == osOther) &&
  2333. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2334. }
  2335. //---------------------------------------------------------------------------
  2336. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2337. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2338. {
  2339. TTBItemOptions O;
  2340. O = Item->Options;
  2341. TCustomDirView * DView = DirView(Side);
  2342. if ((DView->ItemFocused != NULL) &&
  2343. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2344. // when resolving links is disabled, default action is to enter the directory,
  2345. // no matter what DoubleClickAction is configured to
  2346. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2347. // Can only Edit files, but can Open/Copy even directories
  2348. ((DoubleClickAction != dcaEdit) ||
  2349. !DView->ItemIsDirectory(DView->ItemFocused)))
  2350. {
  2351. Item->Options = O << tboDefault;
  2352. }
  2353. else
  2354. {
  2355. Item->Options = O >> tboDefault;
  2356. }
  2357. }
  2358. //---------------------------------------------------------------------------
  2359. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2360. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2361. {
  2362. TCustomDirView * DView = DirView(Side);
  2363. TListItem * Item = DView->ItemFocused;
  2364. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2365. EnableFocusedOperation[Side])
  2366. {
  2367. TPoint ClientPoint;
  2368. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2369. TPoint(0, 0) : MousePos;
  2370. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2371. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2372. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2373. }
  2374. }
  2375. //---------------------------------------------------------------------------
  2376. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2377. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2378. {
  2379. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2380. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2381. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2382. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2383. Handled = true;
  2384. }
  2385. //---------------------------------------------------------------------------
  2386. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2387. {
  2388. }
  2389. //---------------------------------------------------------------------------
  2390. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2391. {
  2392. DebugAssert(FErrorList == NULL);
  2393. if (WinConfiguration->ContinueOnError)
  2394. {
  2395. FErrorList = new TStringList();
  2396. Configuration->Usage->Inc(L"ContinuationsOnError");
  2397. }
  2398. NonVisualDataModule->StartBusy();
  2399. }
  2400. //---------------------------------------------------------------------------
  2401. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2402. {
  2403. NonVisualDataModule->EndBusy();
  2404. if (FErrorList)
  2405. {
  2406. HandleErrorList(FErrorList);
  2407. }
  2408. }
  2409. //---------------------------------------------------------------------------
  2410. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2411. const TCopyParamType & CopyParam)
  2412. {
  2413. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2414. {
  2415. Configuration->Usage->Inc(L"FileMaskUses");
  2416. }
  2417. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2418. {
  2419. Configuration->Usage->Inc(L"OperationMaskUses");
  2420. }
  2421. }
  2422. //---------------------------------------------------------------------------
  2423. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2424. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2425. {
  2426. DebugAssert(!IsLocalBrowserMode());
  2427. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2428. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2429. TTransferOperationParam DefaultParam;
  2430. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2431. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2432. switch (Param.Queue)
  2433. {
  2434. case asOn:
  2435. CopyParam.Queue = true;
  2436. break;
  2437. case asOff:
  2438. CopyParam.Queue = false;
  2439. break;
  2440. case asAuto:
  2441. default:
  2442. // keep default
  2443. break;
  2444. }
  2445. bool Result =
  2446. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2447. if (Result)
  2448. {
  2449. DebugAssert(Terminal);
  2450. bool SelectionRestored = false;
  2451. TCustomDirView * DView = NULL;
  2452. if (HasDirView[Side])
  2453. {
  2454. DView = DirView(Side);
  2455. DView->SaveSelection();
  2456. DView->SaveSelectedNames();
  2457. }
  2458. UpdateCopyParamCounters(CopyParam);
  2459. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2460. DebugAssert(FTransferResumeList == NULL);
  2461. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2462. FMoveToQueue = false;
  2463. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2464. try
  2465. {
  2466. TStrings * PermanentFileList;
  2467. std::unique_ptr<TStrings> PermanentFileListOwner;
  2468. try
  2469. {
  2470. if (Side == osLocal)
  2471. {
  2472. PermanentFileList = FileList;
  2473. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2474. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2475. if (Operation == foMove)
  2476. {
  2477. ReloadLocalDirectory();
  2478. if (DView != NULL)
  2479. {
  2480. DView->RestoreSelection();
  2481. }
  2482. SelectionRestored = true;
  2483. }
  2484. }
  2485. else
  2486. {
  2487. // Clone the file list as it may refer to current directory files,
  2488. // which get destroyed, when the source directory is reloaded after foMove operation.
  2489. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2490. // But for a hotfix, we are not going to do such a big change.
  2491. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2492. PermanentFileList = PermanentFileListOwner.get();
  2493. try
  2494. {
  2495. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2496. }
  2497. __finally
  2498. {
  2499. if (Operation == foMove)
  2500. {
  2501. if (DView != NULL)
  2502. {
  2503. DView->RestoreSelection();
  2504. }
  2505. SelectionRestored = true;
  2506. }
  2507. ReloadLocalDirectory(Param.TargetDirectory);
  2508. }
  2509. }
  2510. }
  2511. catch (EAbort &)
  2512. {
  2513. if (FMoveToQueue)
  2514. {
  2515. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2516. DebugAssert(CopyParam.TransferSkipList == NULL);
  2517. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2518. if (TransferResumeList->Count > 0)
  2519. {
  2520. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2521. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2522. }
  2523. CopyParam.TransferSkipList = TransferResumeList.release();
  2524. // not really needed, just to keep it consistent with TransferResumeList
  2525. FTransferResumeList = NULL;
  2526. FMoveToQueue = false;
  2527. Configuration->Usage->Inc("MovesToBackground");
  2528. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2529. ClearTransferSourceSelection(Direction);
  2530. }
  2531. throw;
  2532. }
  2533. }
  2534. __finally
  2535. {
  2536. if (!SelectionRestored && (DView != NULL))
  2537. {
  2538. DView->DiscardSavedSelection();
  2539. }
  2540. FTransferResumeList = NULL;
  2541. }
  2542. }
  2543. return Result;
  2544. }
  2545. //---------------------------------------------------------------------------
  2546. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2547. TOperationSide Side, TStrings * FileList, void * Param)
  2548. {
  2549. DebugAssert(FileList->Count);
  2550. // We deliberately do not toggle alternative flag (Param), but use OR,
  2551. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2552. // shortcut of CurrentDeleteAlternativeAction
  2553. bool Alternative =
  2554. bool(Param) || UseAlternativeFunction();
  2555. bool Recycle;
  2556. if (IsSideLocalBrowser(Side))
  2557. {
  2558. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2559. }
  2560. else
  2561. {
  2562. Recycle =
  2563. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2564. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2565. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2566. }
  2567. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2568. if (!Result)
  2569. {
  2570. UnicodeString Query;
  2571. if (FileList->Count == 1)
  2572. {
  2573. if (IsSideLocalBrowser(Side))
  2574. {
  2575. Query = ExtractFileName(FileList->Strings[0]);
  2576. }
  2577. else
  2578. {
  2579. Query = UnixExtractFileName(FileList->Strings[0]);
  2580. }
  2581. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2582. }
  2583. else
  2584. {
  2585. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2586. }
  2587. TMessageParams Params(mpNeverAskAgainCheck);
  2588. Params.ImageName = L"Delete file";
  2589. unsigned int Answer =
  2590. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2591. if (Answer == qaNeverAskAgain)
  2592. {
  2593. Result = true;
  2594. if (Recycle)
  2595. {
  2596. WinConfiguration->ConfirmRecycling = false;
  2597. }
  2598. else
  2599. {
  2600. WinConfiguration->ConfirmDeleting = false;
  2601. }
  2602. }
  2603. else
  2604. {
  2605. Result = (Answer == qaOK);
  2606. }
  2607. }
  2608. if (Result)
  2609. {
  2610. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2611. }
  2612. return Result;
  2613. }
  2614. //---------------------------------------------------------------------------
  2615. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2616. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2617. {
  2618. TAutoBatch AutoBatch(this);
  2619. bool Result;
  2620. if ((Operation == foCopy) || (Operation == foMove))
  2621. {
  2622. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2623. }
  2624. else if (Operation == foRename)
  2625. {
  2626. DebugAssert(DirView(Side)->ItemFocused);
  2627. DirView(Side)->ItemFocused->EditCaption();
  2628. Result = true;
  2629. }
  2630. else if (Operation == foDelete)
  2631. {
  2632. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2633. }
  2634. else if (Operation == foSetProperties)
  2635. {
  2636. DirView(osRemote)->SaveSelectedNames();
  2637. Result = SetProperties(Side, FileList);
  2638. }
  2639. else if (Operation == foCustomCommand)
  2640. {
  2641. DebugAssert(Param);
  2642. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2643. DirView(osRemote)->SaveSelectedNames();
  2644. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2645. CustomCommand(FileList, *Command, NULL);
  2646. Result = true;
  2647. }
  2648. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2649. {
  2650. DebugAssert(!IsSideLocalBrowser(Side));
  2651. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2652. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2653. }
  2654. else if (Operation == foLock)
  2655. {
  2656. DebugAssert(!IsSideLocalBrowser(Side));
  2657. LockFiles(FileList, true);
  2658. Result = true;
  2659. }
  2660. else if (Operation == foUnlock)
  2661. {
  2662. DebugAssert(!IsSideLocalBrowser(Side));
  2663. LockFiles(FileList, false);
  2664. Result = true;
  2665. }
  2666. else
  2667. {
  2668. DebugFail();
  2669. }
  2670. return Result;
  2671. }
  2672. //---------------------------------------------------------------------------
  2673. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2674. {
  2675. if (Side == osCurrent)
  2676. {
  2677. Side = FCurrentSide;
  2678. }
  2679. return Side;
  2680. }
  2681. //---------------------------------------------------------------------------
  2682. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2683. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2684. {
  2685. Side = GetSide(Side);
  2686. bool Result;
  2687. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2688. try
  2689. {
  2690. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2691. }
  2692. __finally
  2693. {
  2694. delete FileList;
  2695. }
  2696. return Result;
  2697. }
  2698. //---------------------------------------------------------------------------
  2699. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2700. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2701. bool NoConfirmation, void * Param)
  2702. {
  2703. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2704. {
  2705. if ((Operation == foCopy) || (Operation == foMove))
  2706. {
  2707. DebugAssert(!IsLocalBrowserMode());
  2708. if (GetSide(Side) == osLocal)
  2709. {
  2710. Configuration->Usage->Inc(L"UploadsCommand");
  2711. }
  2712. else
  2713. {
  2714. Configuration->Usage->Inc(L"DownloadsCommand");
  2715. }
  2716. }
  2717. }
  2718. }
  2719. //---------------------------------------------------------------------------
  2720. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2721. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2722. {
  2723. TTransferOperationParam Param;
  2724. if ((WinConfiguration->Interface != ifCommander) ||
  2725. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2726. {
  2727. Flags &= ~cocShortCutHint;
  2728. }
  2729. TCustomDirView * DView = DirView(Side);
  2730. Param.Options =
  2731. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2732. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2733. if (FLAGSET(Flags, cocQueue))
  2734. {
  2735. Param.Queue = asOn;
  2736. }
  2737. else if (FLAGSET(Flags, cocNonQueue))
  2738. {
  2739. Param.Queue = asOff;
  2740. }
  2741. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2742. }
  2743. //---------------------------------------------------------------------------
  2744. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2745. {
  2746. try
  2747. {
  2748. if (ErrorList->Count)
  2749. {
  2750. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2751. if (MessageDialog(Message, qtError,
  2752. qaOK | qaCancel, HELP_NONE) == qaOK)
  2753. {
  2754. unsigned int Answer;
  2755. int Index = 0;
  2756. do
  2757. {
  2758. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2759. TQueryButtonAlias Aliases[2];
  2760. Aliases[0].Button = qaYes;
  2761. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2762. Aliases[1].Button = qaNo;
  2763. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2764. TMessageParams Params;
  2765. Params.Aliases = Aliases;
  2766. Params.AliasesCount = LENOF(Aliases);
  2767. Answer = MoreMessageDialog(
  2768. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2769. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2770. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2771. qaOK, HELP_NONE, &Params);
  2772. if (Answer == qaNo)
  2773. {
  2774. Index++;
  2775. }
  2776. if (Answer == qaYes)
  2777. {
  2778. Index--;
  2779. }
  2780. }
  2781. while (Answer != qaOK);
  2782. }
  2783. }
  2784. }
  2785. __finally
  2786. {
  2787. TStrings * List = ErrorList;
  2788. ErrorList = NULL;
  2789. for (int i = 0; i < List->Count; i++)
  2790. {
  2791. delete List->Objects[i];
  2792. }
  2793. delete List;
  2794. }
  2795. }
  2796. //---------------------------------------------------------------------------
  2797. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2798. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2799. {
  2800. // needed for checking filemasks, as there's no directory object
  2801. // associated with the file object
  2802. File->FullFileName = FullFileName;
  2803. TFileMasks::TParams MaskParams;
  2804. MaskParams.Size = File->Size;
  2805. MaskParams.Modification = File->Modification;
  2806. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2807. }
  2808. //---------------------------------------------------------------------------
  2809. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2810. {
  2811. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2812. Side = GetSide(Side);
  2813. TCustomDirView * DView = DirView(Side);
  2814. TListItem * FocusedItem = DView->ItemFocused;
  2815. UnicodeString Name;
  2816. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2817. {
  2818. Name = DView->ItemFileName(FocusedItem);
  2819. }
  2820. else
  2821. {
  2822. Name = LoadStr(NEW_FILE);
  2823. }
  2824. UnicodeString Names = Name;
  2825. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2826. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2827. HELP_EDIT_NEW, History.get(), true))
  2828. {
  2829. while (!Names.IsEmpty())
  2830. {
  2831. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2832. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2833. UnicodeString TargetFileName;
  2834. UnicodeString LocalFileName;
  2835. UnicodeString RootTempDir;
  2836. UnicodeString TempDir;
  2837. UnicodeString RemoteDirectory;
  2838. bool ExistingFile = false;
  2839. if (!IsSideLocalBrowser(Side))
  2840. {
  2841. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2842. TRemoteFile * File = NULL;
  2843. if (FTerminal->FileExists(Name, &File) &&
  2844. !File->IsDirectory)
  2845. {
  2846. try
  2847. {
  2848. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2849. ExistingFile = true;
  2850. }
  2851. __finally
  2852. {
  2853. delete File;
  2854. }
  2855. }
  2856. if (!ExistingFile)
  2857. {
  2858. RemoteDirectory = UnixExtractFilePath(Name);
  2859. TemporaryDirectoryForRemoteFiles(
  2860. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2861. TargetFileName = UnixExtractFileName(Name);
  2862. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2863. LocalFileName = TempDir +
  2864. // We probably do not want to trim the VMS version here
  2865. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2866. }
  2867. }
  2868. else
  2869. {
  2870. if (ExtractFilePath(Name).IsEmpty())
  2871. {
  2872. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2873. }
  2874. else
  2875. {
  2876. LocalFileName = ExpandFileName(Name);
  2877. }
  2878. TargetFileName = ExtractFileName(Name);
  2879. }
  2880. if (!ExistingFile)
  2881. {
  2882. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2883. if (NewFile)
  2884. {
  2885. int File = FileCreate(ApiPath(LocalFileName));
  2886. if (File < 0)
  2887. {
  2888. if (!RootTempDir.IsEmpty())
  2889. {
  2890. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2891. }
  2892. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2893. }
  2894. else
  2895. {
  2896. FileClose(File);
  2897. }
  2898. }
  2899. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2900. const TEditorData * ExternalEditor = NULL;
  2901. TFileMasks::TParams MaskParams; // size not known
  2902. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2903. false, MaskParams);
  2904. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2905. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2906. }
  2907. }
  2908. }
  2909. }
  2910. //---------------------------------------------------------------------------
  2911. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2912. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2913. {
  2914. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2915. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2916. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2917. return
  2918. ((ExecuteFileBy == efInternalEditor)) ||
  2919. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2920. }
  2921. //---------------------------------------------------------------------------
  2922. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2923. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2924. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2925. UnicodeString RemoteDirectory, bool NewFile)
  2926. {
  2927. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2928. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2929. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2930. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2931. Side = GetSide(Side);
  2932. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2933. if (!IsSideLocalBrowser(Side))
  2934. {
  2935. Data->Terminal = Terminal;
  2936. Data->Queue = Queue;
  2937. Data->SessionData = CloneCurrentSessionData();
  2938. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2939. Data->RemoteDirectory = RemoteDirectory;
  2940. Data->SessionName = Terminal->SessionData->SessionName;
  2941. Data->LocalRootDirectory = LocalRootDirectory;
  2942. Data->OriginalFileName = OriginalFileName;
  2943. Data->Command = L""; // will be changed later for external editor
  2944. }
  2945. if (ExecuteFileBy == efInternalEditor)
  2946. {
  2947. if (!IsSideLocalBrowser(Side))
  2948. {
  2949. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2950. L" - " + Terminal->SessionData->SessionName;
  2951. TForm * Editor;
  2952. try
  2953. {
  2954. TNotifyEvent OnFileChanged = NULL;
  2955. TNotifyEvent OnSaveAll = NULL;
  2956. TAnyModifiedEvent OnAnyModified = NULL;
  2957. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2958. if (Terminal->IsCapable[fcBackgroundTransfers])
  2959. {
  2960. OnFileChanged = FEditorManager->FileChanged;
  2961. OnSaveAll = SaveAllInternalEditors;
  2962. OnAnyModified = AnyInternalEditorModified;
  2963. }
  2964. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2965. FEditorManager->FileReload, FEditorManager->FileClosed,
  2966. OnSaveAll, OnAnyModified,
  2967. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2968. }
  2969. catch(...)
  2970. {
  2971. if (!LocalRootDirectory.IsEmpty())
  2972. {
  2973. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2974. }
  2975. throw;
  2976. }
  2977. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2978. }
  2979. else
  2980. {
  2981. DebugAssert(!FStandaloneEditing);
  2982. TForm * Editor =
  2983. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2984. SaveAllInternalEditors, AnyInternalEditorModified,
  2985. L"", false, SessionColor, -1, NewFile);
  2986. FLocalEditors->Add(Editor);
  2987. }
  2988. }
  2989. else
  2990. {
  2991. HANDLE Process;
  2992. if (ExecuteFileBy == efExternalEditor)
  2993. {
  2994. UnicodeString Program, Params, Dir;
  2995. Data->Command = ExternalEditor->ExternalEditor;
  2996. ReformatFileNameCommand(Data->Command);
  2997. SplitCommand(Data->Command, Program, Params, Dir);
  2998. Params = ExpandFileNameCommand(Params, FileName);
  2999. Program = ExpandEnvironmentVariables(Program);
  3000. if (!ExecuteShell(Program, Params, Process))
  3001. {
  3002. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3003. }
  3004. }
  3005. else
  3006. {
  3007. DebugAssert(!IsSideLocalBrowser(Side));
  3008. if (!ExecuteShell(FileName, L"", Process))
  3009. {
  3010. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3011. }
  3012. }
  3013. if (IsSideLocalBrowser(Side) ||
  3014. ((ExecuteFileBy == efShell) &&
  3015. !WinConfiguration->Editor.SDIShellEditor) ||
  3016. ((ExecuteFileBy == efExternalEditor) &&
  3017. !ExternalEditor->SDIExternalEditor))
  3018. {
  3019. // no need for handle
  3020. if (Process != NULL)
  3021. {
  3022. DebugCheck(CloseHandle(Process));
  3023. }
  3024. Process = INVALID_HANDLE_VALUE;
  3025. }
  3026. else
  3027. {
  3028. if (Process == NULL)
  3029. {
  3030. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3031. }
  3032. }
  3033. if (!IsSideLocalBrowser(Side))
  3034. {
  3035. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3036. }
  3037. }
  3038. }
  3039. //---------------------------------------------------------------------------
  3040. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3041. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3042. void * /*Arg*/)
  3043. {
  3044. if (Token != NULL)
  3045. {
  3046. EditorFormFileSave(static_cast<TForm *>(Token));
  3047. }
  3048. }
  3049. //---------------------------------------------------------------------------
  3050. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3051. {
  3052. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3053. {
  3054. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3055. }
  3056. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3057. }
  3058. //---------------------------------------------------------------------------
  3059. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3060. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3061. void * Arg)
  3062. {
  3063. if ((Token != NULL) &&
  3064. IsEditorFormModified(static_cast<TForm *>(Token)))
  3065. {
  3066. *static_cast<bool *>(Arg) = true;
  3067. }
  3068. }
  3069. //---------------------------------------------------------------------------
  3070. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3071. TObject * /*Sender*/, bool & Modified)
  3072. {
  3073. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3074. {
  3075. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3076. {
  3077. Modified = true;
  3078. }
  3079. }
  3080. if (!Modified)
  3081. {
  3082. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3083. }
  3084. }
  3085. //---------------------------------------------------------------------------
  3086. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3087. {
  3088. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3089. }
  3090. //---------------------------------------------------------------------------
  3091. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3092. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3093. UnicodeString & Result, UnicodeString & RootDirectory)
  3094. {
  3095. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3096. {
  3097. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3098. Result = RootDirectory;
  3099. }
  3100. else
  3101. {
  3102. RootDirectory = L"";
  3103. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3104. Result = IncludeTrailingBackslash(Result);
  3105. }
  3106. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3107. {
  3108. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3109. }
  3110. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3111. {
  3112. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3113. {
  3114. RemoteDirectory.Delete(1, 1);
  3115. }
  3116. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3117. }
  3118. if (!ForceDirectories(ApiPath(Result)))
  3119. {
  3120. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3121. }
  3122. }
  3123. //---------------------------------------------------------------------------
  3124. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3125. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3126. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3127. {
  3128. DebugAssert(!IsLocalBrowserMode());
  3129. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3130. if (ForceText)
  3131. {
  3132. CopyParam.TransferMode = tmAscii;
  3133. }
  3134. TemporaryFileCopyParam(CopyParam);
  3135. if (AllFiles)
  3136. {
  3137. CopyParam.IncludeFileMask = TFileMasks();
  3138. }
  3139. if (TempDir.IsEmpty())
  3140. {
  3141. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3142. }
  3143. DebugAssert(!FAutoOperation);
  3144. FAutoOperation = AutoOperation;
  3145. Terminal->ExceptionOnFail = true;
  3146. try
  3147. {
  3148. try
  3149. {
  3150. // turn off confirmations, as for MDI editors we may possibly download
  3151. // the same file over
  3152. Terminal->CopyToLocal(
  3153. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3154. if (GetTargetNames)
  3155. {
  3156. for (int i = 0; i < FileList->Count; i++)
  3157. {
  3158. FileList->Strings[i] =
  3159. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3160. }
  3161. }
  3162. }
  3163. catch(...)
  3164. {
  3165. if (!RootTempDir.IsEmpty())
  3166. {
  3167. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3168. }
  3169. throw;
  3170. }
  3171. }
  3172. __finally
  3173. {
  3174. FAutoOperation = false;
  3175. Terminal->ExceptionOnFail = false;
  3176. }
  3177. }
  3178. //---------------------------------------------------------------------------
  3179. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3180. {
  3181. // Do not waste time checking for default editor list the next time,
  3182. // or testing if default editor is not notepad.
  3183. bool TryNextTime = false;
  3184. UnicodeString UsageState;
  3185. if (!WinConfiguration->EditorList->IsDefaultList())
  3186. {
  3187. UsageState = "H";
  3188. }
  3189. else
  3190. {
  3191. UnicodeString Executable;
  3192. UnicodeString ExecutableDescription;
  3193. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3194. {
  3195. UnicodeString Message =
  3196. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3197. unsigned int Answer =
  3198. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3199. if (Answer != qaOK)
  3200. {
  3201. UsageState = "R";
  3202. }
  3203. else
  3204. {
  3205. UsageState = "A";
  3206. TEditorData EditorData;
  3207. EditorData.Editor = edExternal;
  3208. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3209. EditorData.ExternalEditorOptionsAutodetect();
  3210. TEditorList EditorList;
  3211. EditorList = *WinConfiguration->EditorList;
  3212. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3213. WinConfiguration->EditorList = &EditorList;
  3214. }
  3215. }
  3216. }
  3217. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3218. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3219. }
  3220. //---------------------------------------------------------------------------
  3221. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3222. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3223. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3224. {
  3225. if (ExecuteFileBy == efDefaultEditor)
  3226. {
  3227. if (!WinConfiguration->OfferedEditorAutoConfig)
  3228. {
  3229. EditorAutoConfig();
  3230. }
  3231. const TEditorPreferences * Editor =
  3232. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3233. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3234. {
  3235. ExecuteFileBy = efInternalEditor;
  3236. ExternalEditor = NULL;
  3237. }
  3238. else if (Editor->Data->Editor == edOpen)
  3239. {
  3240. ExecuteFileBy = efShell;
  3241. ExternalEditor = NULL;
  3242. }
  3243. else
  3244. {
  3245. ExecuteFileBy = efExternalEditor;
  3246. ExternalEditor = Editor->Data;
  3247. }
  3248. }
  3249. }
  3250. //---------------------------------------------------------------------------
  3251. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3252. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3253. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3254. {
  3255. UnicodeString OriginalFileName;
  3256. UnicodeString LocalRootDirectory;
  3257. UnicodeString RemoteDirectory;
  3258. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3259. IsSideLocalBrowser(Side), MaskParams);
  3260. UnicodeString Counter;
  3261. UnicodeString LocalFileName;
  3262. bool Handled = false;
  3263. if (!IsSideLocalBrowser(Side))
  3264. {
  3265. // We need to trim VMS version here, so that we use name without version
  3266. // when uploading back to create a new version of the file
  3267. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3268. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3269. TObject * Token = NULL;
  3270. UnicodeString LocalDirectory;
  3271. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3272. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3273. LocalDirectory))
  3274. {
  3275. if (Token != NULL)
  3276. {
  3277. TForm * Form = dynamic_cast<TForm *>(Token);
  3278. if (Form->WindowState == wsMinimized)
  3279. {
  3280. ShowWindow(Form->Handle, SW_RESTORE);
  3281. }
  3282. else
  3283. {
  3284. Form->SetFocus();
  3285. }
  3286. Handled = true;
  3287. }
  3288. else
  3289. {
  3290. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3291. }
  3292. }
  3293. if (!Handled)
  3294. {
  3295. TStringList * FileList1 = new TStringList();
  3296. try
  3297. {
  3298. FileList1->AddObject(FullFileName, Object);
  3299. TemporarilyDownloadFiles(FileList1,
  3300. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3301. LocalRootDirectory, LocalDirectory, true, true, true);
  3302. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3303. }
  3304. __finally
  3305. {
  3306. delete FileList1;
  3307. }
  3308. switch (ExecuteFileBy)
  3309. {
  3310. case efShell:
  3311. Counter = "RemoteFilesExecuted";
  3312. break;
  3313. case efInternalEditor:
  3314. Counter = "RemoteFilesOpenedInInternalEditor";
  3315. break;
  3316. case efExternalEditor:
  3317. Counter = "RemoteFilesOpenedInExternalEditor";
  3318. break;
  3319. default:
  3320. DebugFail();
  3321. }
  3322. }
  3323. }
  3324. else
  3325. {
  3326. LocalFileName = FullFileName;
  3327. OriginalFileName = ExtractFileName(FullFileName);
  3328. switch (ExecuteFileBy)
  3329. {
  3330. case efShell:
  3331. Counter = "LocalFilesExecuted";
  3332. break;
  3333. case efInternalEditor:
  3334. Counter = "LocalFilesOpenedInInternalEditor";
  3335. break;
  3336. case efExternalEditor:
  3337. Counter = "LocalFilesOpenedInExternalEditor";
  3338. break;
  3339. default:
  3340. DebugFail();
  3341. }
  3342. }
  3343. if (!Handled)
  3344. {
  3345. Configuration->Usage->Inc(Counter);
  3346. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3347. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3348. }
  3349. }
  3350. //---------------------------------------------------------------------------
  3351. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3352. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3353. bool AllSelected, bool OnFocused)
  3354. {
  3355. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3356. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3357. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3358. Side = GetSide(Side);
  3359. TCustomDirView * DView = DirView(Side);
  3360. TStrings * FileList =
  3361. AllSelected ?
  3362. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3363. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3364. try
  3365. {
  3366. DebugAssert(AllSelected || (FileList->Count == 1));
  3367. for (int i = 0; i < FileList->Count; i++)
  3368. {
  3369. UnicodeString ListFileName = FileList->Strings[i];
  3370. UnicodeString FileNameOnly =
  3371. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3372. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3373. if (!DView->ItemIsDirectory(Item))
  3374. {
  3375. UnicodeString FullFileName;
  3376. if (!IsSideLocalBrowser(Side))
  3377. {
  3378. FullFileName = DirView(Side)->Path + ListFileName;
  3379. }
  3380. else
  3381. {
  3382. FullFileName = ListFileName;
  3383. }
  3384. TFileMasks::TParams MaskParams;
  3385. MaskParams.Size = DView->ItemFileSize(Item);
  3386. TDateTimePrecision Precision;
  3387. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3388. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3389. FileList->Objects[i], MaskParams);
  3390. }
  3391. }
  3392. }
  3393. __finally
  3394. {
  3395. delete FileList;
  3396. }
  3397. }
  3398. //---------------------------------------------------------------------------
  3399. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3400. {
  3401. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3402. CopyParam.FileNameCase = ncNoChange;
  3403. CopyParam.PreserveRights = false;
  3404. CopyParam.PreserveReadOnly = false;
  3405. CopyParam.ReplaceInvalidChars = true;
  3406. CopyParam.IncludeFileMask = TFileMasks();
  3407. CopyParam.NewerOnly = false;
  3408. CopyParam.FileMask = L"";
  3409. }
  3410. //---------------------------------------------------------------------------
  3411. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3412. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3413. {
  3414. TTerminalManager * Manager = TTerminalManager::Instance();
  3415. if (!IsActiveTerminal(Data->Terminal))
  3416. {
  3417. if (!NonVisualDataModule->Busy)
  3418. {
  3419. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3420. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3421. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3422. if (Data->Terminal == NULL)
  3423. {
  3424. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3425. if (SameSiteTerminal != NULL)
  3426. {
  3427. UnicodeString Message =
  3428. FMTLOAD(EDIT_SESSION_REATTACH,
  3429. (FileNameOnly, Data->SessionName, FileNameOnly));
  3430. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3431. {
  3432. Data->Terminal = Terminal;
  3433. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3434. Data->SessionName = Terminal->SessionData->SessionName;
  3435. // We might also overwrite session data
  3436. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3437. }
  3438. else
  3439. {
  3440. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3441. Abort();
  3442. }
  3443. }
  3444. }
  3445. // foreground session should reconnect itself
  3446. else if (Terminal != Data->Terminal)
  3447. {
  3448. UnicodeString Message =
  3449. MainInstructions(
  3450. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3451. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3452. {
  3453. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3454. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3455. }
  3456. else
  3457. {
  3458. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3459. Abort();
  3460. }
  3461. }
  3462. }
  3463. if (!IsActiveTerminal(Data->Terminal))
  3464. {
  3465. Configuration->Usage->Inc(L"EditInactiveSession");
  3466. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3467. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3468. (ExtractFileName(FileName), Data->SessionName)));
  3469. }
  3470. }
  3471. TStrings * FileList = new TStringList();
  3472. try
  3473. {
  3474. FileList->Add(FileName);
  3475. // consider using the same settings (preset) as when the file was downloaded
  3476. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3477. TemporaryFileCopyParam(CopyParam);
  3478. if (Data->ForceText)
  3479. {
  3480. CopyParam.TransferMode = tmAscii;
  3481. }
  3482. // so i do not need to worry if masking algorithm works in all cases
  3483. // ("" means "copy file name", no masking is actually done)
  3484. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3485. {
  3486. CopyParam.FileMask = L"";
  3487. }
  3488. else
  3489. {
  3490. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3491. }
  3492. DebugAssert(Data->Queue != NULL);
  3493. int Params = cpNoConfirmation | cpTemporary;
  3494. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3495. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3496. QueueItem->CompleteEvent = UploadCompleteEvent;
  3497. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3498. }
  3499. __finally
  3500. {
  3501. delete FileList;
  3502. }
  3503. }
  3504. //---------------------------------------------------------------------------
  3505. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3506. const UnicodeString FileName, const TEditedFileData * Data)
  3507. {
  3508. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3509. DebugAssert(!NonVisualDataModule->Busy);
  3510. if (!IsActiveTerminal(Data->Terminal))
  3511. {
  3512. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3513. (ExtractFileName(FileName), Data->SessionName)));
  3514. }
  3515. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3516. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3517. NonVisualDataModule->StartBusy();
  3518. try
  3519. {
  3520. std::unique_ptr<TRemoteFile> File;
  3521. UnicodeString RemoteFileName =
  3522. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3523. FTerminal->ExceptionOnFail = true;
  3524. try
  3525. {
  3526. TRemoteFile * AFile = NULL;
  3527. FTerminal->ReadFile(RemoteFileName, AFile);
  3528. File.reset(AFile);
  3529. if (!File->HaveFullFileName)
  3530. {
  3531. File->FullFileName = RemoteFileName;
  3532. }
  3533. }
  3534. __finally
  3535. {
  3536. FTerminal->ExceptionOnFail = false;
  3537. }
  3538. std::unique_ptr<TStrings> FileList(new TStringList());
  3539. FileList->AddObject(RemoteFileName, File.get());
  3540. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3541. UnicodeString TempDir = ExtractFilePath(FileName);
  3542. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3543. TempDir, true, true, true);
  3544. // sanity check, the target file name should be still the same
  3545. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3546. }
  3547. __finally
  3548. {
  3549. NonVisualDataModule->EndBusy();
  3550. // it actually may not exist anymore...
  3551. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3552. }
  3553. }
  3554. //---------------------------------------------------------------------------
  3555. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3556. const TEditedFileData * Data, bool & KeepOpen)
  3557. {
  3558. // Command is set for external editors only (not for "shell" open).
  3559. if (!Data->Command.IsEmpty())
  3560. {
  3561. bool AnyFound = false;
  3562. bool AnyMDI = false;
  3563. bool AnyNonMDI = false;
  3564. bool AnyDetect = false;
  3565. TEditorList * EditorList = new TEditorList();
  3566. try
  3567. {
  3568. *EditorList = *WinConfiguration->EditorList;
  3569. for (int i = 0; i < EditorList->Count; i++)
  3570. {
  3571. const TEditorPreferences * Editor = EditorList->Editors[i];
  3572. if ((Editor->Data->Editor == edExternal) &&
  3573. (Editor->Data->ExternalEditor == Data->Command))
  3574. {
  3575. AnyFound = true;
  3576. if (Editor->Data->SDIExternalEditor)
  3577. {
  3578. AnyNonMDI = true;
  3579. if (Editor->Data->DetectMDIExternalEditor)
  3580. {
  3581. AnyDetect = true;
  3582. }
  3583. }
  3584. else
  3585. {
  3586. AnyMDI = true;
  3587. }
  3588. }
  3589. }
  3590. bool EnableMDI = false;
  3591. bool DisableDetect = false;
  3592. if (AnyMDI)
  3593. {
  3594. KeepOpen = true;
  3595. if (AnyNonMDI)
  3596. {
  3597. // there is at least one instance of the editor with MDI support enabled,
  3598. // and one with disabled, enable it for all instances
  3599. EnableMDI = true;
  3600. }
  3601. }
  3602. else if (AnyFound && !AnyDetect)
  3603. {
  3604. // at least once instance found but all have MDI autodetection disabled
  3605. // => close the file (default action)
  3606. }
  3607. else
  3608. {
  3609. // no instance of the editor has MDI support enabled
  3610. TMessageParams Params;
  3611. if (AnyFound)
  3612. {
  3613. // there is at least one instance of the editor
  3614. Params.Params |= mpNeverAskAgainCheck;
  3615. }
  3616. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3617. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3618. switch (Answer)
  3619. {
  3620. case qaNeverAskAgain:
  3621. DisableDetect = true;
  3622. break;
  3623. case qaNo:
  3624. EnableMDI = true;
  3625. KeepOpen = true;
  3626. break;
  3627. }
  3628. }
  3629. if (AnyFound && (EnableMDI || DisableDetect))
  3630. {
  3631. bool Changed = false;
  3632. for (int i = 0; i < EditorList->Count; i++)
  3633. {
  3634. const TEditorPreferences * Editor = EditorList->Editors[i];
  3635. if ((Editor->Data->Editor == edExternal) &&
  3636. (Editor->Data->ExternalEditor == Data->Command) &&
  3637. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3638. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3639. {
  3640. Changed = true;
  3641. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3642. if (EnableMDI)
  3643. {
  3644. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3645. }
  3646. if (DisableDetect)
  3647. {
  3648. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3649. }
  3650. EditorList->Change(i, UpdatedEditor);
  3651. }
  3652. }
  3653. if (Changed)
  3654. {
  3655. WinConfiguration->EditorList = EditorList;
  3656. }
  3657. }
  3658. }
  3659. __finally
  3660. {
  3661. delete EditorList;
  3662. }
  3663. }
  3664. else
  3665. {
  3666. // "open" case
  3667. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3668. qaOK, HELP_APP_EARLY_CLOSED);
  3669. }
  3670. }
  3671. //---------------------------------------------------------------------------
  3672. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3673. {
  3674. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3675. }
  3676. //---------------------------------------------------------------------------
  3677. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3678. {
  3679. SideEnter(osRemote);
  3680. }
  3681. //---------------------------------------------------------------------------
  3682. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3683. {
  3684. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3685. SideEnter(osRemote);
  3686. }
  3687. //---------------------------------------------------------------------------
  3688. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3689. {
  3690. FCurrentSide = Side;
  3691. if (Visible)
  3692. {
  3693. UpdateControls();
  3694. }
  3695. }
  3696. //---------------------------------------------------------------------------
  3697. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3698. TStrings * FileList, bool Alternative)
  3699. {
  3700. TCustomDirView * DView = DirView(Side);
  3701. DView->SaveSelection();
  3702. DView->SaveSelectedNames();
  3703. DebugAssert(!FAlternativeDelete);
  3704. FAlternativeDelete = Alternative;
  3705. try
  3706. {
  3707. if (!IsSideLocalBrowser(Side))
  3708. {
  3709. DebugAssert(Terminal != NULL);
  3710. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3711. }
  3712. else
  3713. {
  3714. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  3715. FProgressSide = FCurrentSide;
  3716. try
  3717. {
  3718. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3719. }
  3720. __finally
  3721. {
  3722. ReloadLocalDirectory();
  3723. }
  3724. }
  3725. FAlternativeDelete = false;
  3726. }
  3727. catch(...)
  3728. {
  3729. FAlternativeDelete = false;
  3730. DView->DiscardSavedSelection();
  3731. throw;
  3732. }
  3733. DView->RestoreSelection();
  3734. }
  3735. //---------------------------------------------------------------------------
  3736. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3737. {
  3738. DebugAssert(Terminal);
  3739. DebugAssert(!IsLocalBrowserMode());
  3740. RemoteDirView->SaveSelection();
  3741. RemoteDirView->SaveSelectedNames();
  3742. try
  3743. {
  3744. if (Lock)
  3745. {
  3746. Terminal->LockFiles(FileList);
  3747. }
  3748. else
  3749. {
  3750. Terminal->UnlockFiles(FileList);
  3751. }
  3752. }
  3753. catch(...)
  3754. {
  3755. RemoteDirView->DiscardSavedSelection();
  3756. throw;
  3757. }
  3758. RemoteDirView->RestoreSelection();
  3759. }
  3760. //---------------------------------------------------------------------------
  3761. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3762. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3763. bool NoConfirmation, bool Move)
  3764. {
  3765. DebugAssert(Terminal != NULL);
  3766. DebugAssert(!IsLocalBrowserMode());
  3767. // update Terminal->StateData->RemoteDirectory
  3768. UpdateTerminal(Terminal);
  3769. if (Session == NULL)
  3770. {
  3771. Session = TTerminalManager::Instance()->ActiveTerminal;
  3772. }
  3773. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3774. {
  3775. if (RemoteDriveView->DropTarget != NULL)
  3776. {
  3777. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3778. }
  3779. else if (RemoteDirView->DropTarget != NULL)
  3780. {
  3781. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3782. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3783. }
  3784. else
  3785. {
  3786. Target = RemoteDirView->Path;
  3787. }
  3788. }
  3789. else
  3790. {
  3791. Target = Session->StateData->RemoteDirectory;
  3792. }
  3793. Target = UnixIncludeTrailingBackslash(Target);
  3794. if (FileList->Count == 1)
  3795. {
  3796. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3797. }
  3798. else
  3799. {
  3800. FileMask = AnyMask;
  3801. }
  3802. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3803. bool Result = true;
  3804. if (!NoConfirmation)
  3805. {
  3806. bool Multi = (FileList->Count > 1);
  3807. if (Move)
  3808. {
  3809. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3810. }
  3811. else
  3812. {
  3813. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3814. TStrings * Directories = new TStringList;
  3815. try
  3816. {
  3817. for (int Index = 0; Index < Sessions->Count; Index++)
  3818. {
  3819. TManagedTerminal * Terminal =
  3820. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3821. Directories->Add(Terminal->StateData->RemoteDirectory);
  3822. }
  3823. TDirectRemoteCopy AllowDirectCopy;
  3824. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3825. {
  3826. DebugAssert(DirectCopy);
  3827. AllowDirectCopy = drcAllow;
  3828. }
  3829. else if (FTerminal->IsCapable[fcSecondaryShell])
  3830. {
  3831. DebugAssert(DirectCopy);
  3832. AllowDirectCopy = drcConfirmCommandSession;
  3833. }
  3834. else
  3835. {
  3836. DebugAssert(!DirectCopy);
  3837. AllowDirectCopy = drcDisallow;
  3838. }
  3839. void * ASession = Session;
  3840. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3841. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3842. Session = static_cast<TManagedTerminal *>(ASession);
  3843. }
  3844. __finally
  3845. {
  3846. delete Directories;
  3847. }
  3848. }
  3849. }
  3850. return Result;
  3851. }
  3852. //---------------------------------------------------------------------------
  3853. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3854. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3855. {
  3856. DebugAssert(!IsLocalBrowserMode());
  3857. bool DirectCopy;
  3858. UnicodeString Target, FileMask;
  3859. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3860. if (Result)
  3861. {
  3862. if (!Move && !DirectCopy)
  3863. {
  3864. Configuration->Usage->Inc("RemoteCopyTemp");
  3865. UnicodeString RootTempDir;
  3866. UnicodeString TempDir;
  3867. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3868. TStrings * TemporaryFilesList = new TStringList();
  3869. try
  3870. {
  3871. TMakeLocalFileListParams MakeFileListParam;
  3872. MakeFileListParam.FileList = TemporaryFilesList;
  3873. MakeFileListParam.FileTimes = NULL;
  3874. MakeFileListParam.IncludeDirs = true;
  3875. MakeFileListParam.Recursive = false;
  3876. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3877. TTerminalManager::Instance()->ActiveTerminal = Session;
  3878. if (TemporaryFilesList->Count > 0)
  3879. {
  3880. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3881. CopyParam.FileMask = FileMask;
  3882. DebugAssert(!FAutoOperation);
  3883. FAutoOperation = true;
  3884. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3885. }
  3886. }
  3887. __finally
  3888. {
  3889. delete TemporaryFilesList;
  3890. FAutoOperation = false;
  3891. if (!RootTempDir.IsEmpty())
  3892. {
  3893. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3894. }
  3895. }
  3896. }
  3897. else
  3898. {
  3899. RemoteDirView->SaveSelection();
  3900. RemoteDirView->SaveSelectedNames();
  3901. try
  3902. {
  3903. if (Move)
  3904. {
  3905. Configuration->Usage->Inc("RemoteMove");
  3906. Terminal->MoveFiles(FileList, Target, FileMask);
  3907. }
  3908. else
  3909. {
  3910. Configuration->Usage->Inc("RemoteCopyDirect");
  3911. DebugAssert(DirectCopy);
  3912. DebugAssert(Session == FTerminal);
  3913. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3914. FTerminal->CommandSessionOpened ||
  3915. CommandSessionFallback())
  3916. {
  3917. Terminal->CopyFiles(FileList, Target, FileMask);
  3918. }
  3919. }
  3920. }
  3921. catch(...)
  3922. {
  3923. RemoteDirView->DiscardSavedSelection();
  3924. throw;
  3925. }
  3926. RemoteDirView->RestoreSelection();
  3927. }
  3928. }
  3929. return Result;
  3930. }
  3931. //---------------------------------------------------------------------------
  3932. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3933. const UnicodeString & Path, TRemoteProperties & Properties)
  3934. {
  3935. DebugAssert(!IsLocalBrowserMode());
  3936. Properties.Valid = Properties.Valid << vpEncrypt;
  3937. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3938. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3939. }
  3940. //---------------------------------------------------------------------------
  3941. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3942. {
  3943. Side = GetSide(Side);
  3944. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3945. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3946. UnicodeString Name = LoadStr(NEW_FOLDER);
  3947. int AllowedChanges =
  3948. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3949. bool SaveSettings = false;
  3950. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3951. {
  3952. TWindowLock Lock(this);
  3953. if (!IsSideLocalBrowser(Side))
  3954. {
  3955. if (SaveSettings)
  3956. {
  3957. GUIConfiguration->NewDirectoryProperties = Properties;
  3958. }
  3959. CreateRemoteDirectory(Name, Properties);
  3960. }
  3961. else
  3962. {
  3963. DirView(Side)->CreateDirectory(Name);
  3964. }
  3965. }
  3966. }
  3967. //---------------------------------------------------------------------------
  3968. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3969. {
  3970. TWindowLock Lock(this);
  3971. DirView(Side)->ExecuteHomeDirectory();
  3972. }
  3973. //---------------------------------------------------------------------------
  3974. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3975. {
  3976. DoOpenDirectoryDialog(odBrowse, Side);
  3977. }
  3978. //---------------------------------------------------------------------------
  3979. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3980. {
  3981. TOperationSide BookmarkSide = IsLocalBrowserMode() ? osLocal : Side;
  3982. UnicodeString Path = Bookmark->GetSideDirectory(BookmarkSide);
  3983. bool Result = !Path.IsEmpty();
  3984. if (Result)
  3985. {
  3986. // While we might get here when the session is closed (from location profiles),
  3987. // it's not a problem as the Path setter is noop then
  3988. DirView(Side)->Path = Path;
  3989. }
  3990. return Result;
  3991. }
  3992. //---------------------------------------------------------------------------
  3993. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3994. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3995. bool & Close)
  3996. {
  3997. // terminal can be already closed (e.g. dropped connection)
  3998. if (Terminal != NULL)
  3999. {
  4000. try
  4001. {
  4002. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  4003. }
  4004. catch(...)
  4005. {
  4006. if (!Terminal->Active)
  4007. {
  4008. Close = true;
  4009. }
  4010. throw;
  4011. }
  4012. }
  4013. }
  4014. //---------------------------------------------------------------------------
  4015. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4016. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4017. bool & Close)
  4018. {
  4019. // terminal can be already closed (e.g. dropped connection)
  4020. if (Terminal != NULL)
  4021. {
  4022. Configuration->Usage->Inc(L"ChecksumCalculated");
  4023. try
  4024. {
  4025. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4026. }
  4027. catch(...)
  4028. {
  4029. if (!Terminal->Active)
  4030. {
  4031. Close = true;
  4032. }
  4033. throw;
  4034. }
  4035. }
  4036. }
  4037. //---------------------------------------------------------------------------
  4038. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4039. {
  4040. bool Result;
  4041. if (!IsSideLocalBrowser(Side))
  4042. {
  4043. TRemoteTokenList * GroupList = NULL;
  4044. TRemoteTokenList * UserList = NULL;
  4045. try
  4046. {
  4047. TRemoteProperties CurrentProperties;
  4048. if (Terminal->LoadFilesProperties(FileList))
  4049. {
  4050. RemoteDirView->Invalidate();
  4051. }
  4052. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4053. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4054. if (CapableGroupChanging || CapableOwnerChanging)
  4055. {
  4056. if (CapableGroupChanging)
  4057. {
  4058. GroupList = Terminal->Groups->Duplicate();
  4059. }
  4060. if (CapableOwnerChanging)
  4061. {
  4062. UserList = Terminal->Users->Duplicate();
  4063. }
  4064. TRemoteDirectory * Files = Terminal->Files;
  4065. int Count = Files->Count;
  4066. if (Count > 100)
  4067. {
  4068. Count = 100;
  4069. }
  4070. for (int Index = 0; Index < Count; Index++)
  4071. {
  4072. TRemoteFile * File = Files->Files[Index];
  4073. if (CapableGroupChanging)
  4074. {
  4075. GroupList->AddUnique(File->Group);
  4076. }
  4077. if (CapableOwnerChanging)
  4078. {
  4079. UserList->AddUnique(File->Owner);
  4080. }
  4081. }
  4082. // if we haven't collected tokens for all files in current directory,
  4083. // make sure we collect them at least for all selected files.
  4084. // (note that so far the files in FileList has to be from current direcotry)
  4085. if (Count < Files->Count)
  4086. {
  4087. for (int Index = 0; Index < FileList->Count; Index++)
  4088. {
  4089. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4090. if (CapableGroupChanging)
  4091. {
  4092. GroupList->AddUnique(File->Group);
  4093. }
  4094. if (CapableOwnerChanging)
  4095. {
  4096. UserList->AddUnique(File->Owner);
  4097. }
  4098. }
  4099. }
  4100. }
  4101. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4102. int Flags = 0;
  4103. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4104. if (CapableOwnerChanging) Flags |= cpOwner;
  4105. if (CapableGroupChanging) Flags |= cpGroup;
  4106. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4107. if (Terminal->IsCapable[fcCalculatingChecksum])
  4108. {
  4109. CalculateChecksumEvent = CalculateChecksum;
  4110. }
  4111. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4112. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4113. TRemoteProperties NewProperties = CurrentProperties;
  4114. Result =
  4115. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4116. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4117. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4118. CalculateSize, CalculateChecksumEvent);
  4119. if (Result)
  4120. {
  4121. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4122. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4123. }
  4124. }
  4125. __finally
  4126. {
  4127. delete GroupList;
  4128. delete UserList;
  4129. }
  4130. }
  4131. else
  4132. {
  4133. DirView(Side)->DisplayPropertiesMenu();
  4134. Result = true;
  4135. }
  4136. return Result;
  4137. }
  4138. //---------------------------------------------------------------------------
  4139. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4140. {
  4141. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4142. {
  4143. FIgnoreNextDialogChar = Key;
  4144. }
  4145. Key = 0;
  4146. }
  4147. //---------------------------------------------------------------------------
  4148. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4149. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4150. {
  4151. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4152. if (Command != NULL)
  4153. {
  4154. KeyProcessed(Key, Shift);
  4155. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4156. {
  4157. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4158. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4159. false, false, const_cast<TCustomCommandType *>(Command));
  4160. }
  4161. }
  4162. }
  4163. //---------------------------------------------------------------------------
  4164. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4165. {
  4166. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4167. {
  4168. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4169. }
  4170. if (!DirView(osCurrent)->IsEditing())
  4171. {
  4172. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4173. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4174. {
  4175. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4176. // But so far it's not a problem, as it does what we want.
  4177. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4178. if (((Action->ShortCut == KeyShortCut) ||
  4179. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4180. AllowedAction(Action, aaShortCut))
  4181. {
  4182. // Has to be called before the action as the dialog char is already in queue.
  4183. // So when the action consumes message queue, we already need to have the
  4184. // FIgnoreNextDialogChar set
  4185. KeyProcessed(Key, Shift);
  4186. // Reset reference to previous component (when menu/toolbar was clicked).
  4187. // Needed to detect that action was invoked by keyboard shortcut
  4188. // in TNonVisualDataModule::ExplorerActionsExecute
  4189. Action->ActionComponent = NULL;
  4190. Action->Execute();
  4191. return;
  4192. }
  4193. }
  4194. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4195. {
  4196. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4197. {
  4198. KeyProcessed(Key, Shift);
  4199. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4200. return;
  4201. }
  4202. }
  4203. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4204. {
  4205. KeyProcessed(Key, Shift);
  4206. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4207. }
  4208. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4209. if (IsCustomShortCut(CustomShortCut))
  4210. {
  4211. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4212. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4213. if (WinConfiguration->SharedBookmarks != NULL)
  4214. {
  4215. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4216. if ((Bookmark != NULL) &&
  4217. OpenBookmark(FCurrentSide, Bookmark))
  4218. {
  4219. KeyProcessed(Key, Shift);
  4220. }
  4221. }
  4222. }
  4223. }
  4224. TForm::KeyDown(Key, Shift);
  4225. }
  4226. //---------------------------------------------------------------------------
  4227. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4228. {
  4229. bool OpenedTerminal = false;
  4230. UnicodeString ProtocolName;
  4231. UnicodeString ProtocolNameHint;
  4232. UnicodeString SecurityProtocolName;
  4233. UnicodeString DurationHint;
  4234. // See the comment in TScpCommanderForm::UpdateControls()
  4235. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4236. if (ActiveTerminal != NULL)
  4237. {
  4238. // Active is not enough here
  4239. if (ActiveTerminal->Status == ssOpened)
  4240. {
  4241. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4242. const TFileSystemInfo & FileSystemInfo = ActiveTerminal->GetFileSystemInfo();
  4243. if (FileSystemInfo.ProtocolName.IsEmpty())
  4244. {
  4245. ProtocolName = SessionInfo.ProtocolName;
  4246. }
  4247. else
  4248. {
  4249. ProtocolName = FileSystemInfo.ProtocolName;
  4250. }
  4251. ProtocolNameHint = LoadStr(STATUS_PROTOCOL_HINT);
  4252. SecurityProtocolName = SessionInfo.SecurityProtocolName;
  4253. DurationHint = LoadStr(STATUS_DURATION_HINT);
  4254. OpenedTerminal = true;
  4255. }
  4256. else if (ActiveTerminal->Status > ssClosed)
  4257. {
  4258. ProtocolName = LoadStr(STATUS_CONNECTING);
  4259. }
  4260. else
  4261. {
  4262. ProtocolName = LoadStr(STATUS_NOT_CONNECTED2);
  4263. }
  4264. }
  4265. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4266. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4267. TTBXStatusPanel * ProtocolStatusPanel = SessionStatusBar->Panels->Items[Offset + 0];
  4268. ProtocolStatusPanel->ViewPriority = (ActiveTerminal != NULL) ? 100 : 0;
  4269. if (ProtocolStatusPanel->Caption != ProtocolName)
  4270. {
  4271. ProtocolStatusPanel->Caption = ProtocolName;
  4272. std::unique_ptr<TCanvas> Canvas(CreateControlCanvas(SessionStatusBar));
  4273. ProtocolStatusPanel->Size = Canvas->TextWidth(ProtocolName) + ScaleByTextHeight(SessionStatusBar, 32);
  4274. }
  4275. ProtocolStatusPanel->Hint = ProtocolNameHint;
  4276. TTBXStatusPanel * SecurityStatusPanel = SessionStatusBar->Panels->Items[Offset + 1];
  4277. SecurityStatusPanel->ViewPriority = OpenedTerminal ? 98 : 0;
  4278. bool SecurityEnabled = !SecurityProtocolName.IsEmpty();
  4279. SecurityStatusPanel->Enabled = SecurityEnabled;
  4280. UnicodeString SecurityProtocolHint;
  4281. if (SecurityEnabled)
  4282. {
  4283. SecurityProtocolHint = FMTLOAD(STATUS_SECURE, (SecurityProtocolName));
  4284. }
  4285. else
  4286. {
  4287. SecurityProtocolHint = LoadStr(STATUS_INSECURE);
  4288. }
  4289. SecurityStatusPanel->Hint = SecurityProtocolHint;
  4290. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[Offset + 2];
  4291. DurationStatusPanel->ViewPriority = OpenedTerminal ? 99 : 0;
  4292. DurationStatusPanel->Hint = DurationHint;
  4293. UpdateStatusBar();
  4294. }
  4295. //---------------------------------------------------------------------------
  4296. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4297. {
  4298. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4299. DebugAssert(SessionStatusBar != NULL);
  4300. TTBXStatusPanel * NoteStatusPanel = SessionStatusBar->Panels->Items[0];
  4301. if (!FNote.IsEmpty())
  4302. {
  4303. NoteStatusPanel->Caption = FNote;
  4304. }
  4305. else
  4306. {
  4307. UpdateStatusPanelText(NoteStatusPanel);
  4308. }
  4309. NoteStatusPanel->Hint = FNoteHints;
  4310. UnicodeString LoginTime;
  4311. // See the comment in TScpCommanderForm::UpdateControls()
  4312. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4313. // Active is not enough here
  4314. if ((ActiveTerminal != NULL) && (ActiveTerminal->Status == ssOpened))
  4315. {
  4316. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4317. LoginTime = FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4318. }
  4319. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1];
  4320. DurationStatusPanel->Caption = LoginTime;
  4321. }
  4322. //---------------------------------------------------------------------------
  4323. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4324. {
  4325. Panel->Caption = L"";
  4326. }
  4327. //---------------------------------------------------------------------------
  4328. void __fastcall TCustomScpExplorerForm::Idle()
  4329. {
  4330. if (FShowing || FStandaloneEditing)
  4331. {
  4332. FEditorManager->Check();
  4333. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4334. // that needs to know if queue view is visible (and it may be closed after queue update)
  4335. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4336. }
  4337. if (FShowing)
  4338. {
  4339. if (!NonVisualDataModule->Busy &&
  4340. // Menu is opened or drag&drop is going on
  4341. (Mouse->Capture == NULL))
  4342. {
  4343. if (FRefreshRemoteDirectory)
  4344. {
  4345. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4346. {
  4347. Terminal->RefreshDirectory();
  4348. }
  4349. FRefreshRemoteDirectory = false;
  4350. }
  4351. if (FRefreshLocalDirectory)
  4352. {
  4353. ReloadLocalDirectory();
  4354. FRefreshLocalDirectory = false;
  4355. }
  4356. if (WinConfiguration->RefreshRemotePanel)
  4357. {
  4358. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4359. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4360. {
  4361. RemoteDirView->ReloadDirectory();
  4362. }
  4363. }
  4364. if (!FStarted)
  4365. {
  4366. FStarted = true;
  4367. InterfaceStarted();
  4368. }
  4369. }
  4370. }
  4371. if (FShowing || FStandaloneEditing)
  4372. {
  4373. if (FQueueStatusInvalidated)
  4374. {
  4375. UpdateQueueStatus(false);
  4376. }
  4377. RefreshQueueItems();
  4378. }
  4379. if (FShowing)
  4380. {
  4381. UpdateStatusBar();
  4382. }
  4383. FIgnoreNextDialogChar = 0;
  4384. }
  4385. //---------------------------------------------------------------------------
  4386. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4387. {
  4388. try
  4389. {
  4390. FUserActionTimer->Enabled = false;
  4391. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4392. {
  4393. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4394. {
  4395. FPendingQueueActionItem->ProcessUserAction();
  4396. }
  4397. }
  4398. }
  4399. __finally
  4400. {
  4401. FPendingQueueActionItem = NULL;
  4402. }
  4403. }
  4404. //---------------------------------------------------------------------------
  4405. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4406. {
  4407. if (WinConfiguration->MinimizeToTray)
  4408. {
  4409. UpdateTrayIcon();
  4410. FTrayIcon->Visible = true;
  4411. if (Visible)
  4412. {
  4413. ShowWindow(Handle, SW_HIDE);
  4414. }
  4415. }
  4416. }
  4417. //---------------------------------------------------------------------------
  4418. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4419. {
  4420. // WORKAROUND
  4421. // When restoring maximized window from minimization,
  4422. // rarely some controls do not align properly.
  4423. // Two instances seen (both for Commander):
  4424. // - When restoring, window is temporarily narrower (not maximized),
  4425. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4426. // Once maximized already, top dock shinks back, but the session PageControl,
  4427. // do not align up, leaving space between TopDock and PageControl.
  4428. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4429. for (int Index = 0; Index < ControlCount; Index++)
  4430. {
  4431. RealignControl(Controls[Index]);
  4432. }
  4433. if (FTrayIcon->Visible)
  4434. {
  4435. FTrayIcon->Visible = false;
  4436. if (Visible)
  4437. {
  4438. ShowWindow(Handle, SW_SHOW);
  4439. }
  4440. }
  4441. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4442. {
  4443. FNeedSession = false;
  4444. NonVisualDataModule->StartBusy();
  4445. try
  4446. {
  4447. NeedSession(true);
  4448. }
  4449. __finally
  4450. {
  4451. NonVisualDataModule->EndBusy();
  4452. }
  4453. }
  4454. }
  4455. //---------------------------------------------------------------------------
  4456. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4457. {
  4458. FTrayIcon->Hint = GetMainForm()->Caption;
  4459. }
  4460. //---------------------------------------------------------------------------
  4461. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4462. {
  4463. UpdateTrayIcon();
  4464. }
  4465. //---------------------------------------------------------------------------
  4466. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4467. {
  4468. // workaround
  4469. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4470. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4471. // But WM_ACTIVATEAPP message can be received even when
  4472. // the main window is minimized to the tray and internal editor window is focused
  4473. // (after another application was previously active)
  4474. if (::IsIconic(Handle))
  4475. {
  4476. if (!IsAppIconic())
  4477. {
  4478. SetAppIconic(true);
  4479. }
  4480. }
  4481. ::ApplicationRestore();
  4482. Application->BringToFront();
  4483. }
  4484. //---------------------------------------------------------------------------
  4485. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4486. {
  4487. RestoreApp();
  4488. }
  4489. //---------------------------------------------------------------------------
  4490. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4491. {
  4492. if (OpenInNewWindow())
  4493. {
  4494. // todo: Pass FromSite
  4495. ExecuteNewInstance(SessionUrl);
  4496. }
  4497. else
  4498. {
  4499. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4500. }
  4501. }
  4502. //---------------------------------------------------------------------------
  4503. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4504. {
  4505. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4506. StoredSessions->NewSession(SessionName, SessionData);
  4507. // modified only, explicit
  4508. StoredSessions->Save(false, true);
  4509. // encode session name because of slashes in hierarchical sessions
  4510. return EncodeUrlString(SessionName);
  4511. }
  4512. //---------------------------------------------------------------------------
  4513. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4514. {
  4515. // current working directories become defaults here, what is not right
  4516. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4517. return SaveHiddenDuplicateSession(SessionData.get());
  4518. }
  4519. //---------------------------------------------------------------------------
  4520. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4521. {
  4522. if (OpenInNewWindow())
  4523. {
  4524. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4525. }
  4526. else
  4527. {
  4528. // current working directories become defaults here, what is not right
  4529. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4530. TTerminalManager * Manager = TTerminalManager::Instance();
  4531. TManagedTerminal * Terminal = Manager->NewManagedTerminal(SessionData.get());
  4532. Manager->ActiveTerminal = Terminal;
  4533. }
  4534. }
  4535. //---------------------------------------------------------------------------
  4536. void __fastcall TCustomScpExplorerForm::RenameSession()
  4537. {
  4538. UnicodeString Name = Terminal->SessionData->SessionName;
  4539. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4540. {
  4541. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4542. TSessionData::ValidateName(Name);
  4543. // This is inconsistent with how color (for example) is handled.
  4544. Terminal->SessionData->Name = Name;
  4545. UpdateControls();
  4546. // Add/Remove distinguishing paths from sessions of the same name.
  4547. DoTerminalListChanged();
  4548. }
  4549. }
  4550. //---------------------------------------------------------------------------
  4551. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4552. {
  4553. DebugAssert(Queue != NULL);
  4554. bool Result = Queue->IsEmpty;
  4555. if (!Result)
  4556. {
  4557. SetFocus();
  4558. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4559. }
  4560. return Result;
  4561. }
  4562. //---------------------------------------------------------------------------
  4563. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4564. {
  4565. return CanCloseQueue(FQueue);
  4566. }
  4567. //---------------------------------------------------------------------------
  4568. void __fastcall TCustomScpExplorerForm::CloseSession()
  4569. {
  4570. if (CanCloseQueue())
  4571. {
  4572. TTerminalManager::Instance()->FreeActiveTerminal();
  4573. }
  4574. }
  4575. //---------------------------------------------------------------------------
  4576. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4577. {
  4578. if (CanCloseQueue())
  4579. {
  4580. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4581. }
  4582. }
  4583. //---------------------------------------------------------------------------
  4584. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4585. {
  4586. DetachTerminal(Terminal);
  4587. RemoteDirView->Terminal = Terminal;
  4588. UpdateRemotePathComboBox(false);
  4589. InitStatusBar();
  4590. UpdateControls();
  4591. }
  4592. //---------------------------------------------------------------------------
  4593. void __fastcall TCustomScpExplorerForm::TerminalConnecting()
  4594. {
  4595. InitStatusBar();
  4596. }
  4597. //---------------------------------------------------------------------------
  4598. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4599. {
  4600. if (DebugAlwaysTrue(!Terminal->Active))
  4601. {
  4602. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4603. }
  4604. }
  4605. //---------------------------------------------------------------------------
  4606. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4607. {
  4608. if (OpenInNewWindow())
  4609. {
  4610. // encode session name because of slashes in hierarchical sessions
  4611. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4612. }
  4613. else
  4614. {
  4615. TTerminalManager * Manager = TTerminalManager::Instance();
  4616. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4617. Manager->ActiveTerminal = Terminal;
  4618. }
  4619. }
  4620. //---------------------------------------------------------------------------
  4621. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4622. {
  4623. TTerminalManager * Manager = TTerminalManager::Instance();
  4624. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4625. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4626. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4627. // FirstTerminal can be null, if some of the
  4628. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4629. {
  4630. FirstTerminal->Disconnected = true;
  4631. FirstTerminal->DisconnectedTemporarily = true;
  4632. }
  4633. Manager->ActiveTerminal = FirstTerminal;
  4634. }
  4635. //---------------------------------------------------------------------------
  4636. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4637. {
  4638. if (OpenInNewWindow())
  4639. {
  4640. ExecuteNewInstance(Name);
  4641. }
  4642. else
  4643. {
  4644. DoOpenFolderOrWorkspace(Name, true);
  4645. }
  4646. }
  4647. //---------------------------------------------------------------------------
  4648. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4649. bool &CanClose)
  4650. {
  4651. // See the comment in CloseApp()
  4652. if (NonVisualDataModule->Busy)
  4653. {
  4654. CanClose = false;
  4655. }
  4656. else if (Terminal != NULL)
  4657. {
  4658. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4659. {
  4660. unsigned int Result;
  4661. TMessageParams Params(mpNeverAskAgainCheck);
  4662. UnicodeString Message;
  4663. int Answers = qaOK | qaCancel;
  4664. if (TTerminalManager::Instance()->Count > 1)
  4665. {
  4666. if (!WinConfiguration->AutoSaveWorkspace)
  4667. {
  4668. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4669. }
  4670. else
  4671. {
  4672. Message = LoadStr(CLOSE_SESSIONS);
  4673. }
  4674. }
  4675. else
  4676. {
  4677. if (!WinConfiguration->AutoSaveWorkspace)
  4678. {
  4679. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4680. }
  4681. else
  4682. {
  4683. Message = LoadStr(CLOSE_SESSION);
  4684. }
  4685. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4686. }
  4687. UnicodeString Note;
  4688. if (WinConfiguration->AutoSaveWorkspace)
  4689. {
  4690. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4691. }
  4692. else
  4693. {
  4694. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4695. Answers = qaYes | qaNo | qaCancel;
  4696. }
  4697. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4698. SetFocus();
  4699. Result = MessageDialog(Message, qtConfirmation,
  4700. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4701. if (Result == qaNeverAskAgain)
  4702. {
  4703. WinConfiguration->ConfirmClosingSession = false;
  4704. }
  4705. if (Result == qaNo)
  4706. {
  4707. CanClose = SaveWorkspace(true);
  4708. // note that the workspace will be saved redundatly again from FormClose
  4709. }
  4710. else
  4711. {
  4712. CanClose =
  4713. (Result == qaOK) ||
  4714. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4715. (Result == qaNeverAskAgain);
  4716. }
  4717. }
  4718. if (CanClose)
  4719. {
  4720. CanClose = CanCloseQueue();
  4721. }
  4722. }
  4723. if (CanClose)
  4724. {
  4725. CanClose =
  4726. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4727. FEditorManager->CloseExternalFilesWithoutProcess();
  4728. if (CanClose)
  4729. {
  4730. while (CanClose && (FLocalEditors->Count > 0))
  4731. {
  4732. int PrevCount = FLocalEditors->Count;
  4733. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4734. CanClose = (FLocalEditors->Count < PrevCount);
  4735. }
  4736. if (CanClose)
  4737. {
  4738. CanClose = FEditorManager->Empty(true);
  4739. if (!CanClose)
  4740. {
  4741. SetFocus();
  4742. CanClose =
  4743. (MessageDialog(
  4744. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4745. }
  4746. }
  4747. }
  4748. }
  4749. }
  4750. //---------------------------------------------------------------------------
  4751. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4752. {
  4753. TForm * Form = dynamic_cast<TForm *>(Sender);
  4754. DebugAssert(Form != NULL);
  4755. Form->Close();
  4756. }
  4757. //---------------------------------------------------------------------------
  4758. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4759. {
  4760. TForm * Form = dynamic_cast<TForm *>(Sender);
  4761. delete Form;
  4762. }
  4763. //---------------------------------------------------------------------------
  4764. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4765. {
  4766. while (FLocalEditors->Count > 0)
  4767. {
  4768. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4769. }
  4770. }
  4771. //---------------------------------------------------------------------------
  4772. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4773. TObject *Sender)
  4774. {
  4775. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4776. try
  4777. {
  4778. SetProperties(osRemote, FileList);
  4779. }
  4780. __finally
  4781. {
  4782. delete FileList;
  4783. }
  4784. }
  4785. //---------------------------------------------------------------------------
  4786. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4787. {
  4788. if (value)
  4789. {
  4790. if (Component == fcCustomCommandsBand)
  4791. {
  4792. UpdateCustomCommandsToolbar();
  4793. }
  4794. if (Component == fcQueueFileList)
  4795. {
  4796. DebugAssert(!QueueFileListSplitter->Visible);
  4797. AdjustQueueLayout();
  4798. UpdateQueueFileList();
  4799. }
  4800. }
  4801. }
  4802. //---------------------------------------------------------------------------
  4803. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4804. {
  4805. int MinHeightLimit =
  4806. GetStaticQueuePanelComponentsHeight() +
  4807. QueueFileListSplitter->Height +
  4808. QueueFileList->Height +
  4809. GetMinQueueViewHeight();
  4810. if (QueuePanel->ClientHeight < MinHeightLimit)
  4811. {
  4812. QueuePanel->ClientHeight = MinHeightLimit;
  4813. }
  4814. }
  4815. //---------------------------------------------------------------------------
  4816. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4817. {
  4818. TControl * Control = GetComponent(Component);
  4819. DebugAssert(Control);
  4820. bool Changed = (Control->Visible != value);
  4821. if (Changed)
  4822. {
  4823. ComponentShowing(Component, value);
  4824. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4825. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4826. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4827. if (value)
  4828. {
  4829. int RemainingHeight = Control->Parent->ClientHeight;
  4830. int RemainingWidth = Control->Parent->ClientWidth;
  4831. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4832. {
  4833. TControl * ChildControl = Control->Parent->Controls[i];
  4834. if (ChildControl->Visible)
  4835. {
  4836. switch (ChildControl->Align)
  4837. {
  4838. case alTop:
  4839. case alBottom:
  4840. RemainingHeight -= ChildControl->Height;
  4841. break;
  4842. case alLeft:
  4843. case alRight:
  4844. RemainingWidth -= ChildControl->Width;
  4845. break;
  4846. }
  4847. }
  4848. }
  4849. int Reserve = ScaleByTextHeight(this, 32);
  4850. // queue in explorer, trees in commander
  4851. if (Control->Height > RemainingHeight - Reserve)
  4852. {
  4853. Control->Height = RemainingHeight / 2;
  4854. }
  4855. if (Control->Width > RemainingWidth - Reserve)
  4856. {
  4857. Control->Width = RemainingWidth / 2;
  4858. }
  4859. }
  4860. Control->Visible = value;
  4861. if (WasFocused && Visible)
  4862. {
  4863. DirView(osCurrent)->SetFocus();
  4864. }
  4865. FixControlsPlacement();
  4866. }
  4867. }
  4868. //---------------------------------------------------------------------------
  4869. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4870. {
  4871. TControl * Control = GetComponent(Component);
  4872. if (Control == NULL)
  4873. {
  4874. return false;
  4875. }
  4876. else
  4877. {
  4878. return Control->Visible;
  4879. }
  4880. }
  4881. //---------------------------------------------------------------------------
  4882. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4883. {
  4884. bool Result;
  4885. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4886. {
  4887. Result = !IsUWP();
  4888. }
  4889. else
  4890. {
  4891. Result = true;
  4892. }
  4893. return Result;
  4894. }
  4895. //---------------------------------------------------------------------------
  4896. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  4897. {
  4898. if (DirView->ItemFocused != NULL)
  4899. {
  4900. DirView->ItemFocused->MakeVisible(false);
  4901. }
  4902. }
  4903. //---------------------------------------------------------------------------
  4904. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4905. {
  4906. MakeFocusedItemVisible(RemoteDirView);
  4907. QueueSplitter->Visible = QueuePanel->Visible;
  4908. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4909. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4910. TControl * QueueControlsOrder[] =
  4911. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4912. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4913. }
  4914. //---------------------------------------------------------------------------
  4915. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4916. {
  4917. switch (Component) {
  4918. case fcStatusBar: return RemoteStatusBar;
  4919. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4920. case fcQueueView: return QueuePanel;
  4921. case fcQueueToolbar: return QueueDock;
  4922. case fcRemoteTree: return RemoteDrivePanel;
  4923. case fcSessionsTabs: return SessionsPageControl;
  4924. case fcQueueFileList: return QueueFileList;
  4925. default: return NULL;
  4926. }
  4927. }
  4928. //---------------------------------------------------------------------------
  4929. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4930. TObject *Sender, TListColumn *Column, TPoint &Point)
  4931. {
  4932. DebugAssert(NonVisualDataModule && Column && Sender);
  4933. NonVisualDataModule->ListColumn = Column;
  4934. TPopupMenu * DirViewColumnMenu;
  4935. if (Sender == DirView(osOther))
  4936. {
  4937. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4938. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4939. (Column->Index == uvName);
  4940. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4941. (Column->Index == uvSize);
  4942. }
  4943. else
  4944. {
  4945. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4946. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4947. (Column->Index == dvName);
  4948. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4949. (Column->Index == dvSize);
  4950. }
  4951. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4952. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4953. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4954. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4955. }
  4956. //---------------------------------------------------------------------------
  4957. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4958. TObject *Sender, TListItem *Item, bool &AllowExec)
  4959. {
  4960. DoDirViewExecFile(Sender, Item, AllowExec);
  4961. }
  4962. //---------------------------------------------------------------------------
  4963. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4964. TListItem * Item, bool & AllowExec)
  4965. {
  4966. DebugAssert(Sender && Item && Configuration);
  4967. DebugAssert(AllowExec);
  4968. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4969. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  4970. bool Remote = !IsSideLocalBrowser(Side);
  4971. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  4972. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4973. // on files only (not directories)
  4974. // and only when symlinks are resolved (apply to remote panel only)
  4975. if (!ADirView->ItemIsDirectory(Item) &&
  4976. (ResolvedSymlinks || FForceExecution))
  4977. {
  4978. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4979. !FForceExecution && ResolvedSymlinks)
  4980. {
  4981. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4982. {
  4983. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4984. UnlockWindow();
  4985. try
  4986. {
  4987. if (IsLocalBrowserMode())
  4988. {
  4989. LocalLocalCopy(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4990. }
  4991. else
  4992. {
  4993. ExecuteFileOperation(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4994. }
  4995. }
  4996. __finally
  4997. {
  4998. LockWindow();
  4999. }
  5000. AllowExec = false;
  5001. }
  5002. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  5003. {
  5004. if (!Remote || !WinConfiguration->DisableOpenEdit)
  5005. {
  5006. ExecuteFile(Side, efDefaultEditor);
  5007. AllowExec = false;
  5008. }
  5009. }
  5010. else
  5011. {
  5012. DebugFail();
  5013. }
  5014. }
  5015. // if we have not done anything special, fall back to default behavior
  5016. if (AllowExec)
  5017. {
  5018. if (Remote && !WinConfiguration->DisableOpenEdit)
  5019. {
  5020. ExecuteFile(osRemote, efShell);
  5021. AllowExec = false;
  5022. }
  5023. }
  5024. }
  5025. }
  5026. //---------------------------------------------------------------------------
  5027. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  5028. {
  5029. return ((Side == osRemote) || (Side == osCurrent));
  5030. }
  5031. //---------------------------------------------------------------------------
  5032. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5033. {
  5034. DebugFail();
  5035. }
  5036. //---------------------------------------------------------------------------
  5037. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5038. {
  5039. DebugFail();
  5040. }
  5041. //---------------------------------------------------------------------------
  5042. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5043. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5044. {
  5045. TSynchronizeParamType Params;
  5046. Params.LocalDirectory = LocalDirectory;
  5047. Params.RemoteDirectory = RemoteDirectory;
  5048. int UnusedParams =
  5049. (GUIConfiguration->SynchronizeParams &
  5050. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5051. TTerminal::spCaseSensitive));
  5052. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5053. Params.Options = GUIConfiguration->SynchronizeOptions;
  5054. bool SaveSettings = false;
  5055. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5056. &DoSynchronizeTooManyDirectories);
  5057. DebugAssert(FSynchronizeController == NULL);
  5058. FSynchronizeController = &Controller;
  5059. bool Result;
  5060. try
  5061. {
  5062. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5063. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5064. int Options =
  5065. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5066. DebugAssert(FOnFeedSynchronizeError == NULL);
  5067. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5068. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5069. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5070. if (Result)
  5071. {
  5072. if (SaveSettings)
  5073. {
  5074. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5075. GUIConfiguration->SynchronizeOptions = Params.Options;
  5076. }
  5077. else
  5078. {
  5079. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5080. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5081. FLAGSET(Params.Options, soSynchronize))
  5082. {
  5083. GUIConfiguration->SynchronizeOptions =
  5084. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5085. soSynchronize;
  5086. }
  5087. }
  5088. LocalDirectory = Params.LocalDirectory;
  5089. RemoteDirectory = Params.RemoteDirectory;
  5090. }
  5091. }
  5092. __finally
  5093. {
  5094. FSynchronizeController = NULL;
  5095. DebugAssert(FOnFeedSynchronizeError == NULL);
  5096. FOnFeedSynchronizeError = NULL;
  5097. }
  5098. return Result;
  5099. }
  5100. //---------------------------------------------------------------------------
  5101. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5102. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5103. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5104. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5105. TSynchronizeOptions * Options, bool Full)
  5106. {
  5107. // Keep-up-to-date mode
  5108. if (Terminal->Status == ssOpened)
  5109. {
  5110. try
  5111. {
  5112. int PParams = Params.Params;
  5113. if (!Full)
  5114. {
  5115. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5116. if (FLAGSET(Params.Options, soRecurse))
  5117. {
  5118. PParams |= TTerminal::spSubDirs;
  5119. }
  5120. }
  5121. else
  5122. {
  5123. // if keepuptodate is non-recursive,
  5124. // full sync before has to be non-recursive as well
  5125. if (FLAGCLEAR(Params.Options, soRecurse))
  5126. {
  5127. PParams |= TTerminal::spNoRecurse;
  5128. }
  5129. }
  5130. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5131. PParams, Checklist, Options);
  5132. }
  5133. catch (Exception & E)
  5134. {
  5135. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5136. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5137. {
  5138. // noop, already logged in MoreMessageDialog
  5139. }
  5140. else
  5141. {
  5142. ShowExtendedExceptionEx(Terminal, &E);
  5143. throw;
  5144. }
  5145. }
  5146. }
  5147. }
  5148. //---------------------------------------------------------------------------
  5149. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5150. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5151. const UnicodeString ErrorStr)
  5152. {
  5153. if (!Directory.IsEmpty())
  5154. {
  5155. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5156. }
  5157. else
  5158. {
  5159. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5160. }
  5161. }
  5162. //---------------------------------------------------------------------------
  5163. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5164. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5165. {
  5166. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5167. {
  5168. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5169. }
  5170. else
  5171. {
  5172. TMessageParams Params(mpNeverAskAgainCheck);
  5173. unsigned int Result = MessageDialog(
  5174. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5175. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5176. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5177. {
  5178. MaxDirectories *= 2;
  5179. if (Result == qaNeverAskAgain)
  5180. {
  5181. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5182. }
  5183. }
  5184. else
  5185. {
  5186. Abort();
  5187. }
  5188. }
  5189. }
  5190. //---------------------------------------------------------------------------
  5191. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5192. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5193. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5194. TSynchronizeOptions * Options)
  5195. {
  5196. // Keep-up-to-date mode
  5197. DebugAssert(!FAutoOperation);
  5198. void * BatchStorage;
  5199. BatchStart(BatchStorage);
  5200. FAutoOperation = true;
  5201. bool AnyOperation = false;
  5202. TDateTime StartTime = Now();
  5203. TSynchronizeChecklist * AChecklist = NULL;
  5204. try
  5205. {
  5206. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5207. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5208. {
  5209. FSynchronizeProgressForm->Start();
  5210. }
  5211. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5212. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5213. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5214. Options);
  5215. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5216. SAFE_DESTROY(FSynchronizeProgressForm);
  5217. AnyOperation = (AChecklist->CheckedCount > 0);
  5218. if (AnyOperation)
  5219. {
  5220. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5221. CreateProgressForm(&SynchronizeProgress);
  5222. try
  5223. {
  5224. Terminal->SynchronizeApply(
  5225. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5226. SynchronizeProcessedItem, NULL, NULL, NULL);
  5227. }
  5228. __finally
  5229. {
  5230. DestroyProgressForm();
  5231. }
  5232. }
  5233. }
  5234. __finally
  5235. {
  5236. if (Checklist == NULL)
  5237. {
  5238. delete AChecklist;
  5239. }
  5240. else
  5241. {
  5242. *Checklist = AChecklist;
  5243. }
  5244. FAutoOperation = false;
  5245. SAFE_DESTROY(FSynchronizeProgressForm);
  5246. BatchEnd(BatchStorage);
  5247. ReloadLocalDirectory();
  5248. if (AnyOperation)
  5249. {
  5250. OperationComplete(StartTime);
  5251. }
  5252. }
  5253. }
  5254. //---------------------------------------------------------------------------
  5255. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5256. {
  5257. // can be called from command line
  5258. return Visible &&
  5259. ((DirView(osRemote)->SelCount > 0) ||
  5260. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5261. }
  5262. //---------------------------------------------------------------------------
  5263. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5264. {
  5265. LogSynchronizeEvent(Terminal, Message);
  5266. }
  5267. //---------------------------------------------------------------------------
  5268. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5269. int Params, TSynchronizeOptions & Options)
  5270. {
  5271. DebugAssert(!IsLocalBrowserMode());
  5272. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5273. {
  5274. Options.Filter = new TStringList();
  5275. Options.Filter->CaseSensitive = false;
  5276. Options.Filter->Duplicates = Types::dupAccept;
  5277. if (DirView(osRemote)->SelCount > 0)
  5278. {
  5279. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5280. }
  5281. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5282. {
  5283. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5284. }
  5285. Options.Filter->Sort();
  5286. }
  5287. }
  5288. //---------------------------------------------------------------------------
  5289. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5290. {
  5291. TCopyParamType Defaults;
  5292. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5293. ConfigStorage->AccessMode = smRead;
  5294. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5295. {
  5296. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5297. }
  5298. ConfigStorage.reset(NULL);
  5299. std::unique_ptr<TStringList> Options(new TStringList());
  5300. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5301. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5302. UnicodeString Result;
  5303. if (Options->Count > 0)
  5304. {
  5305. Result =
  5306. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5307. }
  5308. return Result;
  5309. }
  5310. //---------------------------------------------------------------------------
  5311. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5312. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5313. {
  5314. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5315. UnicodeString AdditionalParams =
  5316. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5317. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5318. SerializeCopyParamForCommandLine(CopyParams),
  5319. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5320. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5321. ExecuteNewInstance(SessionName, AdditionalParams);
  5322. }
  5323. //---------------------------------------------------------------------------
  5324. struct TSynchronizeParams
  5325. {
  5326. UnicodeString LocalDirectory;
  5327. UnicodeString RemoteDirectory;
  5328. TSynchronizeMode Mode;
  5329. TSynchronizeChecklist * Checklist;
  5330. int Params;
  5331. TCopyParamType * CopyParam;
  5332. TDateTime CollectElapsed;
  5333. TDateTime * StartTime;
  5334. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5335. };
  5336. //---------------------------------------------------------------------------
  5337. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5338. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5339. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5340. {
  5341. DebugAssert(!FAutoOperation);
  5342. void * BatchStorage;
  5343. BatchStart(BatchStorage);
  5344. FAutoOperation = true;
  5345. TFileOperationStatistics Statistics;
  5346. TDateTime Start = Now();
  5347. try
  5348. {
  5349. Params.OnProcessedItem = OnProcessedItem;
  5350. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5351. CreateProgressForm(&SynchronizeProgress);
  5352. Terminal->SynchronizeApply(
  5353. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5354. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5355. &Statistics);
  5356. }
  5357. __finally
  5358. {
  5359. Params.OnProcessedItem = NULL;
  5360. FAutoOperation = false;
  5361. DestroyProgressForm();
  5362. BatchEnd(BatchStorage);
  5363. ReloadLocalDirectory();
  5364. }
  5365. if (WinConfiguration->SynchronizeSummary)
  5366. {
  5367. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5368. // The statistics should be 0 anyway in this case
  5369. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5370. {
  5371. Message += L"\n";
  5372. if (Statistics.FilesUploaded > 0)
  5373. {
  5374. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5375. }
  5376. if (Statistics.FilesDownloaded > 0)
  5377. {
  5378. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5379. }
  5380. if (Statistics.FilesDeletedLocal > 0)
  5381. {
  5382. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5383. }
  5384. if (Statistics.FilesDeletedRemote > 0)
  5385. {
  5386. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5387. }
  5388. }
  5389. TDateTime Elapsed = (Now() - Start);
  5390. Message +=
  5391. L"\n" +
  5392. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5393. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5394. TMessageParams Params(mpNeverAskAgainCheck);
  5395. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5396. if (Result == qaNeverAskAgain)
  5397. {
  5398. WinConfiguration->SynchronizeSummary = false;
  5399. }
  5400. }
  5401. }
  5402. //---------------------------------------------------------------------------
  5403. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5404. {
  5405. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5406. {
  5407. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5408. }
  5409. // Not set in keep-up-to-date mode - Synchronize() method
  5410. if (Token != NULL)
  5411. {
  5412. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5413. if (Params.OnProcessedItem != NULL)
  5414. {
  5415. Params.OnProcessedItem(NULL, ChecklistItem);
  5416. }
  5417. }
  5418. }
  5419. //---------------------------------------------------------------------------
  5420. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5421. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5422. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5423. {
  5424. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5425. *Params.StartTime = Now();
  5426. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5427. }
  5428. //---------------------------------------------------------------------------
  5429. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5430. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5431. {
  5432. // terminal can be already closed (e.g. dropped connection)
  5433. if (Terminal != NULL)
  5434. {
  5435. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5436. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5437. }
  5438. }
  5439. //---------------------------------------------------------------------------
  5440. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5441. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5442. {
  5443. DebugAssert(!IsLocalBrowserMode());
  5444. TAutoBatch AutoBatch(this);
  5445. TAutoFlag AutoOperationFlag(FAutoOperation);
  5446. if (Side == osRemote)
  5447. {
  5448. std::unique_ptr<TStrings> FileList(new TStringList());
  5449. FileList->AddObject(FileName, RemoteFile);
  5450. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5451. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5452. RemoteDirView->SaveSelection();
  5453. RemoteDirView->SaveSelectedNames();
  5454. try
  5455. {
  5456. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5457. }
  5458. catch(...)
  5459. {
  5460. RemoteDirView->DiscardSavedSelection();
  5461. throw;
  5462. }
  5463. RemoteDirView->RestoreSelection();
  5464. }
  5465. else if (DebugAlwaysTrue(Side == osLocal))
  5466. {
  5467. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5468. {
  5469. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5470. }
  5471. UnicodeString Directory = ExtractFileDir(FileName);
  5472. ReloadLocalDirectory(Directory);
  5473. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5474. if (!SamePaths(Directory, NewDirectory))
  5475. {
  5476. ReloadLocalDirectory(NewDirectory);
  5477. }
  5478. }
  5479. }
  5480. //---------------------------------------------------------------------------
  5481. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5482. {
  5483. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5484. if (Side == osLocal)
  5485. {
  5486. if (Action == TSynchronizeChecklist::saDownloadNew)
  5487. {
  5488. OpenFolderInExplorer(LocalPath);
  5489. }
  5490. else
  5491. {
  5492. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5493. }
  5494. }
  5495. else if (DebugAlwaysTrue(Side == osRemote))
  5496. {
  5497. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5498. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5499. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5500. if (!LocalPath.IsEmpty())
  5501. {
  5502. SessionData->LocalDirectory = LocalPath;
  5503. }
  5504. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5505. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5506. }
  5507. }
  5508. //---------------------------------------------------------------------------
  5509. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5510. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5511. const TCopyParamType * CopyParams)
  5512. {
  5513. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5514. UnicodeString AdditionalParams =
  5515. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5516. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5517. SerializeCopyParamForCommandLine(CopyParams),
  5518. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5519. LocalDirectory, RemoteDirectory, Mode, Params));
  5520. ExecuteNewInstance(SessionName, AdditionalParams);
  5521. }
  5522. //---------------------------------------------------------------------------
  5523. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5524. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5525. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5526. {
  5527. int Result;
  5528. bool SaveSettings = false;
  5529. int Options =
  5530. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5531. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5532. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5533. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5534. bool Continue =
  5535. (UseDefaults == 0) ||
  5536. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5537. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5538. if (Continue)
  5539. {
  5540. Configuration->Usage->Inc(L"Synchronizations");
  5541. UpdateCopyParamCounters(CopyParam);
  5542. TSynchronizeOptions SynchronizeOptions;
  5543. GetSynchronizeOptions(Params, SynchronizeOptions);
  5544. if (SaveSettings)
  5545. {
  5546. GUIConfiguration->SynchronizeParams = Params;
  5547. }
  5548. else
  5549. {
  5550. SaveMode = false;
  5551. }
  5552. TDateTime StartTime = Now();
  5553. TSynchronizeChecklist * Checklist = NULL;
  5554. try
  5555. {
  5556. DebugAssert(!FAutoOperation);
  5557. FAutoOperation = true;
  5558. try
  5559. {
  5560. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5561. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5562. int Files = -1;
  5563. if (DataList->Count >= 1)
  5564. {
  5565. Files = StrToIntDef(DataList->Strings[0], Files);
  5566. }
  5567. else
  5568. {
  5569. DataList->Add(UnicodeString());
  5570. }
  5571. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5572. FSynchronizeProgressForm->Start();
  5573. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5574. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5575. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5576. &SynchronizeOptions);
  5577. if (Terminal->SessionData->CacheDirectories)
  5578. {
  5579. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5580. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5581. }
  5582. }
  5583. __finally
  5584. {
  5585. FAutoOperation = false;
  5586. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5587. SAFE_DESTROY(FSynchronizeProgressForm);
  5588. }
  5589. TSynchronizeParams SynchronizeParams;
  5590. SynchronizeParams.LocalDirectory = LocalDirectory;
  5591. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5592. SynchronizeParams.Mode = Mode;
  5593. SynchronizeParams.CopyParam = &CopyParam;
  5594. SynchronizeParams.Params = Params;
  5595. SynchronizeParams.Checklist = Checklist;
  5596. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5597. SynchronizeParams.StartTime = &StartTime;
  5598. SynchronizeParams.OnProcessedItem = NULL;
  5599. Result = Checklist->Count;
  5600. if (Checklist->Count > 0)
  5601. {
  5602. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5603. {
  5604. if (!DoSynchronizeChecklistDialog(
  5605. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5606. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5607. {
  5608. Result = -1;
  5609. }
  5610. }
  5611. else
  5612. {
  5613. FullSynchronize(SynchronizeParams, NULL, NULL);
  5614. }
  5615. }
  5616. else
  5617. {
  5618. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5619. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5620. }
  5621. }
  5622. __finally
  5623. {
  5624. delete Checklist;
  5625. }
  5626. OperationComplete(StartTime);
  5627. }
  5628. else
  5629. {
  5630. Result = -1;
  5631. }
  5632. return Result;
  5633. }
  5634. //---------------------------------------------------------------------------
  5635. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5636. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5637. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5638. {
  5639. if (Collect)
  5640. {
  5641. DebugAssert(FSynchronizeProgressForm != NULL);
  5642. if (!FSynchronizeProgressForm->Started)
  5643. {
  5644. FSynchronizeProgressForm->Start();
  5645. }
  5646. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5647. SetTaskbarListProgressValue(CompareProgress);
  5648. }
  5649. else
  5650. {
  5651. DebugAssert(FSynchronizeProgressForm == NULL);
  5652. DebugAssert(FProgressForm != NULL);
  5653. }
  5654. }
  5655. //---------------------------------------------------------------------------
  5656. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5657. {
  5658. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5659. TRemoteFile * File = NULL;
  5660. Terminal->ReadFile(FullFileName, File);
  5661. if (File != NULL)
  5662. {
  5663. std::unique_ptr<TRemoteFile> FileOwner(File);
  5664. TAutoFlag Flag(FStandaloneEditing);
  5665. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5666. Application->ShowMainForm = false;
  5667. Application->Run();
  5668. }
  5669. }
  5670. //---------------------------------------------------------------------------
  5671. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  5672. {
  5673. DebugFail();
  5674. }
  5675. //---------------------------------------------------------------------------
  5676. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5677. {
  5678. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5679. SessionData->Assign(Terminal->SessionData);
  5680. UpdateSessionData(SessionData.get());
  5681. Terminal->UpdateSessionCredentials(SessionData.get());
  5682. if (!Terminal->SessionData->HasSessionName())
  5683. {
  5684. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5685. // once IsWorkspace is cleared
  5686. SessionData->Name = UnicodeString();
  5687. SessionData->IsWorkspace = false;
  5688. }
  5689. return SessionData.release();
  5690. }
  5691. //---------------------------------------------------------------------------
  5692. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5693. {
  5694. TSessionData * SessionData = CloneCurrentSessionData();
  5695. try
  5696. {
  5697. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5698. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5699. }
  5700. __finally
  5701. {
  5702. delete SessionData;
  5703. }
  5704. }
  5705. //---------------------------------------------------------------------------
  5706. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5707. {
  5708. TTerminalManager * Manager = TTerminalManager::Instance();
  5709. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5710. if (DebugAlwaysTrue(Terminal != NULL))
  5711. {
  5712. // Update (Managed)Terminal->StateData
  5713. UpdateTerminal(Terminal);
  5714. }
  5715. Manager->SaveWorkspace(DataList.get());
  5716. return DataList.release();
  5717. }
  5718. //---------------------------------------------------------------------------
  5719. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5720. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5721. {
  5722. WinConfiguration->LastWorkspace = Name;
  5723. if (!SavePasswords)
  5724. {
  5725. for (int Index = 0; Index < DataList->Count; Index++)
  5726. {
  5727. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5728. if (SessionData->Link.IsEmpty())
  5729. {
  5730. SessionData->ClearSessionPasswords();
  5731. }
  5732. }
  5733. }
  5734. StoredSessions->NewWorkspace(Name, DataList);
  5735. // modified only
  5736. StoredSessions->Save(false, Explicit);
  5737. }
  5738. //---------------------------------------------------------------------------
  5739. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5740. {
  5741. return
  5742. DefaultStr(WinConfiguration->LastWorkspace,
  5743. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5744. }
  5745. //---------------------------------------------------------------------------
  5746. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5747. {
  5748. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5749. bool AnyNonStoredSessionWithPassword = false;
  5750. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5751. bool AllNonStoredSessionsAnonymous = true;
  5752. TTerminalManager * Manager = TTerminalManager::Instance();
  5753. for (int Index = 0; Index < DataList->Count; Index++)
  5754. {
  5755. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5756. if (SessionData->Link.IsEmpty())
  5757. {
  5758. if (SessionData->HasAnySessionPassword())
  5759. {
  5760. AnyNonStoredSessionWithPassword = true;
  5761. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5762. {
  5763. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5764. }
  5765. }
  5766. if (!SameText(SessionData->UserName, AnonymousUserName))
  5767. {
  5768. AllNonStoredSessionsAnonymous = false;
  5769. }
  5770. }
  5771. }
  5772. bool SavePasswords;
  5773. bool * PSavePasswords;
  5774. bool NotRecommendedSavingPasswords =
  5775. !CustomWinConfiguration->UseMasterPassword &&
  5776. !AllNonStoredSessionsAnonymous;
  5777. if (Configuration->DisablePasswordStoring ||
  5778. !AnyNonStoredSessionWithPassword)
  5779. {
  5780. PSavePasswords = NULL;
  5781. SavePasswords = false;
  5782. }
  5783. else
  5784. {
  5785. PSavePasswords = &SavePasswords;
  5786. SavePasswords =
  5787. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5788. !NotRecommendedSavingPasswords;
  5789. }
  5790. UnicodeString Name = WorkspaceName();
  5791. bool CreateShortcut = false;
  5792. bool Result =
  5793. DoSaveWorkspaceDialog(
  5794. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5795. EnableAutoSave);
  5796. if (Result)
  5797. {
  5798. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5799. if (CreateShortcut)
  5800. {
  5801. TOperationVisualizer Visualizer;
  5802. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5803. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5804. }
  5805. if (EnableAutoSave)
  5806. {
  5807. WinConfiguration->AutoSaveWorkspace = true;
  5808. WinConfiguration->AutoWorkspace = Name;
  5809. if (PSavePasswords != NULL)
  5810. {
  5811. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5812. }
  5813. }
  5814. }
  5815. return Result;
  5816. }
  5817. //---------------------------------------------------------------------------
  5818. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5819. {
  5820. DebugAssert(!IsLocalBrowserMode());
  5821. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5822. if (WinConfiguration->PreservePanelState)
  5823. {
  5824. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5825. }
  5826. UpdateSessionData(Terminal->StateData);
  5827. }
  5828. //---------------------------------------------------------------------------
  5829. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5830. {
  5831. // Keep in sync with TSessionData::CopyStateData
  5832. DebugAssert(!IsLocalBrowserMode());
  5833. DebugAssert(Data != NULL);
  5834. // This is inconsistent with how color (for example) is handled.
  5835. Data->Name = Terminal->SessionData->Name;
  5836. // cannot use RemoteDirView->Path, because it is empty if connection
  5837. // was already closed
  5838. // also only peek, we may not be connected at all atm
  5839. // so make sure we do not try retrieving current directory from the server
  5840. // (particularly with FTP)
  5841. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5842. if (!ACurrentDirectory.IsEmpty())
  5843. {
  5844. Data->RemoteDirectory = ACurrentDirectory;
  5845. }
  5846. Data->Color = SessionColor;
  5847. }
  5848. //---------------------------------------------------------------------------
  5849. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5850. {
  5851. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5852. DebugAssert(Toolbar != NULL);
  5853. for (int i = 0; i < Toolbar->Items->Count; i++)
  5854. {
  5855. TTBXCustomDropDownItem * DropDownItem;
  5856. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5857. if (DropDownItem != NULL)
  5858. {
  5859. ToolbarItemResize(DropDownItem,
  5860. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5861. Toolbar->NonClientWidth);
  5862. break;
  5863. }
  5864. }
  5865. }
  5866. //---------------------------------------------------------------------------
  5867. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5868. {
  5869. Item->EditWidth = Width;
  5870. }
  5871. //---------------------------------------------------------------------------
  5872. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5873. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5874. {
  5875. for (int i = 0; i < Toolbar->Items->Count; i++)
  5876. {
  5877. TTBXCustomDropDownItem * DropDownItem;
  5878. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5879. if (DropDownItem != NULL)
  5880. {
  5881. ASize.x -= DropDownItem->EditWidth;
  5882. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5883. }
  5884. }
  5885. }
  5886. //---------------------------------------------------------------------------
  5887. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5888. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5889. {
  5890. if (WinConfiguration->DDWarnLackOfTempSpace)
  5891. {
  5892. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5893. if (!ADrive.IsEmpty())
  5894. {
  5895. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5896. DebugAssert(RequiredSpace >= 0);
  5897. __int64 RequiredWithReserve;
  5898. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5899. if (FreeSpace < RequiredWithReserve)
  5900. {
  5901. unsigned int Result;
  5902. TMessageParams Params(mpNeverAskAgainCheck);
  5903. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5904. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5905. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5906. if (Result == qaNeverAskAgain)
  5907. {
  5908. WinConfiguration->DDWarnLackOfTempSpace = false;
  5909. }
  5910. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5911. }
  5912. }
  5913. }
  5914. }
  5915. //---------------------------------------------------------------------------
  5916. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5917. {
  5918. DoOpenDirectoryDialog(odAddBookmark, Side);
  5919. }
  5920. //---------------------------------------------------------------------------
  5921. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5922. {
  5923. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5924. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5925. try
  5926. {
  5927. TCustomDirView * DView = DirView(Side);
  5928. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5929. {
  5930. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5931. }
  5932. }
  5933. catch (...)
  5934. {
  5935. delete VisitedDirectories;
  5936. throw;
  5937. }
  5938. return VisitedDirectories;
  5939. }
  5940. //---------------------------------------------------------------------------
  5941. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5942. TOpenDirectoryMode Mode, TOperationSide Side)
  5943. {
  5944. bool Continue = true;
  5945. if (Mode == odAddBookmark)
  5946. {
  5947. TMessageParams Params(mpNeverAskAgainCheck);
  5948. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5949. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5950. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5951. unsigned int Answer =
  5952. MessageDialog(Message,
  5953. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5954. if (Answer == qaNeverAskAgain)
  5955. {
  5956. Continue = true;
  5957. WinConfiguration->UseSharedBookmarks = true;
  5958. }
  5959. else if (Answer == qaOK)
  5960. {
  5961. Continue = true;
  5962. WinConfiguration->UseSharedBookmarks = false;
  5963. }
  5964. else
  5965. {
  5966. Continue = false;
  5967. }
  5968. }
  5969. if (Continue)
  5970. {
  5971. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5972. try
  5973. {
  5974. UnicodeString Name = DirView(Side)->PathName;
  5975. bool Repeat;
  5976. do
  5977. {
  5978. Repeat = false;
  5979. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  5980. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  5981. // do not allow switching to location profiles,
  5982. // if we are not connected
  5983. HasDirView[osLocal] && (Terminal != NULL)))
  5984. {
  5985. TWindowLock Lock(this);
  5986. if (!TryOpenDirectory(Side, Name))
  5987. {
  5988. Repeat = true;
  5989. Mode = odBrowse;
  5990. }
  5991. }
  5992. }
  5993. while (Repeat);
  5994. }
  5995. __finally
  5996. {
  5997. delete VisitedDirectories;
  5998. }
  5999. }
  6000. }
  6001. //---------------------------------------------------------------------------
  6002. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  6003. {
  6004. DebugAssert(!FTerminal->CommandSessionOpened);
  6005. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  6006. }
  6007. //---------------------------------------------------------------------------
  6008. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  6009. {
  6010. bool Result = FTerminal->IsCapable[Capability] ||
  6011. FTerminal->CommandSessionOpened;
  6012. if (!Result)
  6013. {
  6014. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  6015. if (!GUIConfiguration->ConfirmCommandSession)
  6016. {
  6017. Result = true;
  6018. }
  6019. else
  6020. {
  6021. TMessageParams Params(mpNeverAskAgainCheck);
  6022. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6023. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6024. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6025. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6026. if (Answer == qaNeverAskAgain)
  6027. {
  6028. GUIConfiguration->ConfirmCommandSession = false;
  6029. Result = true;
  6030. }
  6031. else if (Answer == qaOK)
  6032. {
  6033. Result = true;
  6034. }
  6035. }
  6036. if (Result)
  6037. {
  6038. Result = CommandSessionFallback();
  6039. }
  6040. }
  6041. return Result;
  6042. }
  6043. //---------------------------------------------------------------------------
  6044. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6045. {
  6046. if (EnsureCommandSessionFallback(fcAnyCommand))
  6047. {
  6048. DoConsoleDialog(Terminal, Command);
  6049. }
  6050. }
  6051. //---------------------------------------------------------------------------
  6052. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6053. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6054. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6055. {
  6056. if (!IsSideLocalBrowser(osRemote) &&
  6057. IsFileControl(DropSourceControl, osRemote) &&
  6058. (FDDExtMapFile != NULL))
  6059. {
  6060. Accept = true;
  6061. }
  6062. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6063. DebugAssert(FDDTargetControl != NULL);
  6064. }
  6065. //---------------------------------------------------------------------------
  6066. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6067. _di_IDataObject DataObj, int KeyState,
  6068. const TPoint & Point, int & Effect, bool & Accept)
  6069. {
  6070. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6071. }
  6072. //---------------------------------------------------------------------------
  6073. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6074. _di_IDataObject DataObj, int KeyState,
  6075. const TPoint & Point, int & Effect, bool & Accept)
  6076. {
  6077. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6078. }
  6079. //---------------------------------------------------------------------------
  6080. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6081. TObject * Sender)
  6082. {
  6083. DebugUsedParam(Sender);
  6084. DebugAssert(FDDTargetControl == Sender);
  6085. FDDTargetControl = NULL;
  6086. }
  6087. //---------------------------------------------------------------------------
  6088. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6089. {
  6090. FileControlDDDragLeave(SessionsPageControl);
  6091. }
  6092. //---------------------------------------------------------------------------
  6093. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6094. {
  6095. FileControlDDDragLeave(QueueView3);
  6096. }
  6097. //---------------------------------------------------------------------------
  6098. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6099. {
  6100. DebugAssert(!IsSideLocalBrowser(Side));
  6101. DebugUsedParam(Side);
  6102. bool Edit = false;
  6103. TRemoteFile * File = NULL;
  6104. UnicodeString FileName;
  6105. UnicodeString PointTo;
  6106. bool SymbolicLink = true;
  6107. if (RemoteDirView->ItemFocused)
  6108. {
  6109. DebugAssert(RemoteDirView->ItemFocused->Data);
  6110. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6111. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6112. if (Edit)
  6113. {
  6114. FileName = File->FileName;
  6115. PointTo = File->LinkTo;
  6116. }
  6117. else
  6118. {
  6119. PointTo = File->FileName;
  6120. }
  6121. }
  6122. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6123. Terminal->IsCapable[fcHardLink]))
  6124. {
  6125. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6126. if (Edit)
  6127. {
  6128. DebugAssert(File->FileName == FileName);
  6129. int Params = dfNoRecursive;
  6130. Terminal->ExceptionOnFail = true;
  6131. try
  6132. {
  6133. Terminal->DeleteFile(L"", File, &Params);
  6134. }
  6135. __finally
  6136. {
  6137. Terminal->ExceptionOnFail = false;
  6138. }
  6139. }
  6140. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6141. }
  6142. }
  6143. //---------------------------------------------------------------------------
  6144. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6145. {
  6146. return
  6147. (IsSideLocalBrowser(Side) ||
  6148. (HasActiveTerminal() &&
  6149. Terminal->ResolvingSymlinks &&
  6150. Terminal->IsCapable[fcSymbolicLink]));
  6151. }
  6152. //---------------------------------------------------------------------------
  6153. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6154. {
  6155. return
  6156. !IsSideLocalBrowser(FCurrentSide) &&
  6157. (RemoteDirView->ItemFocused != NULL) &&
  6158. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6159. Terminal->SessionData->ResolveSymlinks;
  6160. }
  6161. //---------------------------------------------------------------------------
  6162. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6163. {
  6164. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6165. FForceExecution = true;
  6166. try
  6167. {
  6168. DirView(osCurrent)->ExecuteCurrentFile();
  6169. }
  6170. __finally
  6171. {
  6172. FForceExecution = false;
  6173. }
  6174. }
  6175. //---------------------------------------------------------------------------
  6176. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6177. {
  6178. TEditorData ExternalEditor;
  6179. ExternalEditor.Editor = edExternal;
  6180. bool Remember = false;
  6181. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6182. {
  6183. if (Remember)
  6184. {
  6185. TEditorList * EditorList = new TEditorList;
  6186. try
  6187. {
  6188. *EditorList = *WinConfiguration->EditorList;
  6189. bool Found = false;
  6190. int i = 0;
  6191. while (!Found && (i < EditorList->Count))
  6192. {
  6193. const TEditorPreferences * Editor = EditorList->Editors[i];
  6194. if ((Editor->Data->Editor == edExternal) &&
  6195. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6196. {
  6197. Found = true;
  6198. }
  6199. i++;
  6200. }
  6201. if (!Found)
  6202. {
  6203. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6204. WinConfiguration->EditorList = EditorList;
  6205. }
  6206. }
  6207. __finally
  6208. {
  6209. delete EditorList;
  6210. }
  6211. }
  6212. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6213. }
  6214. }
  6215. //---------------------------------------------------------------------------
  6216. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6217. {
  6218. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6219. if (FFileFindTerminal == ATerminal)
  6220. {
  6221. FFileFindTerminal = NULL;
  6222. HideFileFindDialog();
  6223. }
  6224. if (FClipboardTerminal == ATerminal)
  6225. {
  6226. ClipboardClear(); // implies ClipboardStop
  6227. }
  6228. }
  6229. //---------------------------------------------------------------------------
  6230. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6231. {
  6232. DetachTerminal(Sender);
  6233. }
  6234. //---------------------------------------------------------------------------
  6235. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6236. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6237. {
  6238. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6239. DebugAssert(Terminal != NULL);
  6240. if (Data->Terminal == Terminal)
  6241. {
  6242. Data->Terminal = NULL;
  6243. }
  6244. }
  6245. //---------------------------------------------------------------------------
  6246. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6247. {
  6248. UpdateControls();
  6249. SessionColor = TColor(0);
  6250. UpdateRemotePathComboBox(false);
  6251. NeedSession(false);
  6252. }
  6253. //---------------------------------------------------------------------------
  6254. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6255. {
  6256. try
  6257. {
  6258. // Cache, as the login dialog can change its value.
  6259. // See also DoShow.
  6260. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6261. try
  6262. {
  6263. if (ShowLogin)
  6264. {
  6265. bool ReloadSessions = !Startup;
  6266. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  6267. }
  6268. }
  6269. __finally
  6270. {
  6271. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6272. // (so there was no chance for the user to open any session yet)
  6273. if ((ShowLogin || !Startup) &&
  6274. !WinConfiguration->KeepOpenWhenNoSession &&
  6275. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6276. {
  6277. TerminateApplication();
  6278. }
  6279. }
  6280. }
  6281. catch (EAbort &)
  6282. {
  6283. // swallow
  6284. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6285. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6286. }
  6287. }
  6288. //---------------------------------------------------------------------------
  6289. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6290. {
  6291. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6292. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6293. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6294. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6295. try
  6296. {
  6297. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6298. // Clear the design time unthemed tab
  6299. ((SessionsPageControl->PageCount > 0) &&
  6300. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6301. {
  6302. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6303. }
  6304. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6305. {
  6306. TThemeTabSheet * TabSheet;
  6307. if (Index >= SessionsPageControl->PageCount)
  6308. {
  6309. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6310. TabSheet->PageControl = SessionsPageControl;
  6311. }
  6312. else
  6313. {
  6314. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6315. }
  6316. bool IsSessionTab = (Index < TerminalList->Count);
  6317. if (IsSessionTab)
  6318. {
  6319. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6320. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6321. UpdateSessionTab(TabSheet);
  6322. }
  6323. else
  6324. {
  6325. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6326. TabSheet->Tag = 0; // not really needed
  6327. TabSheet->Shadowed = false;
  6328. // 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)
  6329. UpdateNewSessionTab();
  6330. }
  6331. TabSheet->ShowCloseButton = IsSessionTab;
  6332. }
  6333. }
  6334. __finally
  6335. {
  6336. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6337. }
  6338. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6339. }
  6340. //---------------------------------------------------------------------------
  6341. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6342. {
  6343. DoTerminalListChanged();
  6344. }
  6345. //---------------------------------------------------------------------------
  6346. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6347. {
  6348. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6349. DebugAssert(TabSheet->ImageIndex == 0);
  6350. TabSheet->Caption =
  6351. WinConfiguration->SelectiveToolbarText ?
  6352. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6353. UnicodeString();
  6354. }
  6355. //---------------------------------------------------------------------------
  6356. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6357. {
  6358. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6359. }
  6360. //---------------------------------------------------------------------------
  6361. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6362. {
  6363. if (DebugAlwaysTrue(TabSheet != NULL))
  6364. {
  6365. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6366. if (DebugAlwaysTrue(ATerminal != NULL))
  6367. {
  6368. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6369. TabSheet->ImageIndex = AddSessionColor(Color);
  6370. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6371. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6372. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6373. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6374. {
  6375. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6376. }
  6377. }
  6378. }
  6379. }
  6380. //---------------------------------------------------------------------------
  6381. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6382. {
  6383. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6384. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6385. bool Result = (Terminal != NULL);
  6386. if (Result)
  6387. {
  6388. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6389. }
  6390. else
  6391. {
  6392. try
  6393. {
  6394. NewSession(false);
  6395. }
  6396. __finally
  6397. {
  6398. DoTerminalListChanged();
  6399. }
  6400. FSessionsPageControlNewSessionTime = Now();
  6401. }
  6402. return Result;
  6403. }
  6404. //---------------------------------------------------------------------------
  6405. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6406. {
  6407. SessionTabSwitched();
  6408. }
  6409. //---------------------------------------------------------------------------
  6410. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6411. {
  6412. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6413. DebugAssert(TransferList != NULL);
  6414. UnicodeString Name;
  6415. if (TransferList->ItemIndex <= 0)
  6416. {
  6417. Name = L"";
  6418. }
  6419. else
  6420. {
  6421. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6422. }
  6423. if (FCopyParamAutoSelected.IsEmpty())
  6424. {
  6425. // if previous preset was not autoselected, make new preset the "default"
  6426. FCopyParamDefault = Name;
  6427. }
  6428. GUIConfiguration->CopyParamCurrent = Name;
  6429. }
  6430. //---------------------------------------------------------------------------
  6431. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6432. {
  6433. // sanity check
  6434. bool ExistingPreset =
  6435. (FTransferListHoverIndex >= 0) &&
  6436. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6437. DebugAssert(ExistingPreset);
  6438. if (ExistingPreset)
  6439. {
  6440. HDC DC = GetDC(0);
  6441. TCanvas * Canvas = new TCanvas();
  6442. try
  6443. {
  6444. Canvas->Handle = DC;
  6445. Canvas->Font = GetToolbarFont(this);
  6446. UnicodeString Name;
  6447. if (FTransferListHoverIndex == 0)
  6448. {
  6449. Name = L"";
  6450. }
  6451. else
  6452. {
  6453. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6454. }
  6455. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6456. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6457. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6458. static_cast<TObject*>(GetComponent(fcTransferList)));
  6459. UnicodeString InfoStr =
  6460. GUIConfiguration->CopyParamPreset[Name].
  6461. GetInfoStr(L"; ",
  6462. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6463. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6464. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6465. {
  6466. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6467. {
  6468. InfoStr.SetLength(InfoStr.Length() - 1);
  6469. }
  6470. InfoStr += Ellipsis;
  6471. }
  6472. // UpdateCaption does not cause invalidation of whole submenu, while
  6473. // setting Caption property does.
  6474. // also it probably does not resize the label, even if necessary
  6475. // (we do not want that anyway)
  6476. TransferLabel->UpdateCaption(InfoStr);
  6477. }
  6478. __finally
  6479. {
  6480. Canvas->Handle = NULL;
  6481. ReleaseDC(0, DC);
  6482. delete Canvas;
  6483. }
  6484. }
  6485. }
  6486. //---------------------------------------------------------------------------
  6487. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6488. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6489. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6490. {
  6491. if (FTransferListHoverIndex != AHoverIndex)
  6492. {
  6493. FTransferListHoverIndex = AHoverIndex;
  6494. UpdateTransferLabel();
  6495. }
  6496. }
  6497. //---------------------------------------------------------------------------
  6498. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6499. {
  6500. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6501. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6502. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6503. {
  6504. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6505. {
  6506. if (!NonVisualDataModule->Busy)
  6507. {
  6508. OpenDirectory(GetSide(osCurrent));
  6509. }
  6510. Message.Result = 1;
  6511. }
  6512. else
  6513. {
  6514. TForm::Dispatch(&Message);
  6515. }
  6516. }
  6517. else
  6518. {
  6519. TForm::Dispatch(&Message);
  6520. }
  6521. }
  6522. //---------------------------------------------------------------------------
  6523. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6524. {
  6525. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6526. if ((FIgnoreNextDialogChar != 0) &&
  6527. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6528. {
  6529. Message.Result = 1;
  6530. }
  6531. else
  6532. {
  6533. TForm::Dispatch(&Message);
  6534. }
  6535. FIgnoreNextDialogChar = 0;
  6536. }
  6537. //---------------------------------------------------------------------------
  6538. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6539. {
  6540. // The four low-order bits are used internally by Windows
  6541. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6542. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6543. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6544. // 61730 - restore thru double click - undocumented
  6545. // 61490 - maximize thru double click - undocumented
  6546. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6547. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6548. {
  6549. SysResizing(Cmd);
  6550. }
  6551. TForm::Dispatch(&Message);
  6552. }
  6553. //---------------------------------------------------------------------------
  6554. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6555. {
  6556. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6557. // Also there no point returning TRUE as we are not able to
  6558. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6559. // Hence the process termination might be safer :)
  6560. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6561. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6562. {
  6563. Message.Result = FALSE;
  6564. }
  6565. else
  6566. {
  6567. Message.Result = TRUE;
  6568. }
  6569. // Do not call default handling as that triggers OnCloseQuery,
  6570. // where our implementation will popup confirmation dialogs, what we do not want,
  6571. // as per Vista guidelines:
  6572. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6573. }
  6574. //---------------------------------------------------------------------------
  6575. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6576. {
  6577. if (Message.EndSession && IsApplicationMinimized())
  6578. {
  6579. // WORKAROUND
  6580. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6581. // when it receives WM_ENDSESSION,
  6582. // but that sometimes (particularly when application is minimized) cause crashes.
  6583. // Crash popups message that blocks log off.
  6584. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6585. // so we call ExitProcess() immediately, not even trying to cleanup.
  6586. // It still causes beep, so there's likely some popup, but it does not block
  6587. // log off.
  6588. ExitProcess(0);
  6589. }
  6590. TForm::Dispatch(&Message);
  6591. }
  6592. #ifdef _DEBUG
  6593. //---------------------------------------------------------------------------
  6594. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6595. {
  6596. TForm::Dispatch(&Message);
  6597. }
  6598. #endif
  6599. //---------------------------------------------------------------------------
  6600. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6601. {
  6602. }
  6603. //---------------------------------------------------------------------------
  6604. void __fastcall TCustomScpExplorerForm::DoShow()
  6605. {
  6606. // only now are the controls resized finally, so the size constraints
  6607. // will not conflict with possibly very small window size
  6608. RestoreFormParams();
  6609. // This indicates that the form was rescaled after parameters were loaded and
  6610. // as most probably the parameters were actually saved with the current form scaling
  6611. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6612. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6613. // and no rounding problems will occur.
  6614. // See also RestoreForm.
  6615. // (we should be safe to call RestoreParams unconditionally)
  6616. if (PixelsPerInch != Screen->PixelsPerInch)
  6617. {
  6618. RestoreParams();
  6619. }
  6620. FixControlsPlacement();
  6621. if (Position == poDefaultPosOnly)
  6622. {
  6623. CutFormToDesktop(this);
  6624. }
  6625. TForm::DoShow();
  6626. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6627. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6628. // This was previously in NeedSession, where other related code is.
  6629. // But that is called form CMShowingChanged, when the window is already visible and the local-local window state
  6630. // unpleasanly shows briefly.
  6631. if (!WinConfiguration->ShowLoginWhenNoSession &&
  6632. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6633. // This detects if workspace was saved the last time the main widow was closed
  6634. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6635. {
  6636. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6637. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6638. }
  6639. if (Terminal == NULL)
  6640. {
  6641. StartingDisconnected();
  6642. }
  6643. UpdatePixelsPerInchMainWindowCounter();
  6644. FShowing = true;
  6645. }
  6646. //---------------------------------------------------------------------------
  6647. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6648. {
  6649. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6650. }
  6651. //---------------------------------------------------------------------------
  6652. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6653. {
  6654. DoTerminalListChanged();
  6655. InitStatusBar();
  6656. UpdateControls();
  6657. }
  6658. //---------------------------------------------------------------------------
  6659. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6660. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6661. TNotifyEvent OnBalloonClick, TObject * UserData)
  6662. {
  6663. bool Do;
  6664. UnicodeString Message;
  6665. if (E == NULL)
  6666. {
  6667. Message = Str;
  6668. Do = true;
  6669. }
  6670. else
  6671. {
  6672. Do = ExceptionMessage(E, Message);
  6673. }
  6674. if (Do && WinConfiguration->BalloonNotifications)
  6675. {
  6676. UnicodeString Title;
  6677. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6678. {
  6679. Message = TrimLeft(Message);
  6680. }
  6681. else
  6682. {
  6683. Message = UnformatMessage(Message);
  6684. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6685. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6686. Title = LoadResourceString(Captions[Type]);
  6687. if (Terminal != NULL)
  6688. {
  6689. Title = FORMAT(L"%s - %s",
  6690. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6691. }
  6692. }
  6693. if (Seconds == 0)
  6694. {
  6695. Seconds = WinConfiguration->NotificationsTimeout;
  6696. }
  6697. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6698. }
  6699. }
  6700. //---------------------------------------------------------------------------
  6701. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6702. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6703. UnicodeString HelpKeyword, const TMessageParams * Params,
  6704. TTerminal * Terminal)
  6705. {
  6706. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6707. (FOnFeedSynchronizeError != NULL)) &&
  6708. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6709. {
  6710. if (FOnFeedSynchronizeError != NULL)
  6711. {
  6712. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6713. }
  6714. else
  6715. {
  6716. DebugAssert(FErrorList != NULL);
  6717. TStringList * MoreMessagesCopy = NULL;
  6718. if (MoreMessages)
  6719. {
  6720. MoreMessagesCopy = new TStringList();
  6721. MoreMessagesCopy->Assign(MoreMessages);
  6722. }
  6723. FErrorList->AddObject(Message, MoreMessagesCopy);
  6724. }
  6725. PopupTrayBalloon(Terminal, Message, Type);
  6726. return ContinueAnswer(Answers);
  6727. }
  6728. else
  6729. {
  6730. bool UseBalloon = FTrayIcon->Visible;
  6731. if (UseBalloon)
  6732. {
  6733. PopupTrayBalloon(Terminal, Message, Type);
  6734. }
  6735. unsigned int Result;
  6736. try
  6737. {
  6738. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6739. }
  6740. __finally
  6741. {
  6742. // cancel only balloon we popped up, otherwise we may cancel notification
  6743. // balloon that was there before the message dialog
  6744. // (such as "dd confirmation opt in balloon)
  6745. if (UseBalloon)
  6746. {
  6747. FTrayIcon->CancelBalloon();
  6748. }
  6749. }
  6750. return Result;
  6751. }
  6752. }
  6753. //---------------------------------------------------------------------------
  6754. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6755. TTerminal * Terminal, Exception * E)
  6756. {
  6757. if (FTrayIcon->Visible)
  6758. {
  6759. PopupTrayBalloon(Terminal, L"", qtError, E);
  6760. }
  6761. // particularly prevent opening new session from jump list,
  6762. // while exception is shown
  6763. NonVisualDataModule->StartBusy();
  6764. try
  6765. {
  6766. ShowExtendedExceptionEx(Terminal, E);
  6767. }
  6768. __finally
  6769. {
  6770. NonVisualDataModule->EndBusy();
  6771. FTrayIcon->CancelBalloon();
  6772. }
  6773. }
  6774. //---------------------------------------------------------------------------
  6775. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6776. {
  6777. if (Terminal->Active)
  6778. {
  6779. InitStatusBar();
  6780. }
  6781. // cannot rely on active page being page for active terminal,
  6782. // as it can happen that active page is the "new session" page
  6783. // (e.g. when reconnecting active terminal, while login dialog
  6784. // invoked from "new session" page is modal)
  6785. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6786. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6787. }
  6788. //---------------------------------------------------------------------------
  6789. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6790. TTerminal * Terminal, Exception * E)
  6791. {
  6792. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6793. if (!Terminal->Active)
  6794. {
  6795. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6796. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6797. {
  6798. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6799. }
  6800. }
  6801. }
  6802. //---------------------------------------------------------------------------
  6803. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6804. UnicodeString Message, TQueryType Type,
  6805. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6806. {
  6807. if ((E == NULL) ||
  6808. ExceptionMessage(E, Message))
  6809. {
  6810. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6811. if (Important)
  6812. {
  6813. Seconds *= 5;
  6814. }
  6815. UnicodeString NoteMessage(UnformatMessage(Message));
  6816. if (Terminal != NULL)
  6817. {
  6818. NoteMessage = FORMAT(L"%s: %s",
  6819. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6820. }
  6821. if (WinConfiguration->BalloonNotifications)
  6822. {
  6823. AddNote(NoteMessage);
  6824. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6825. }
  6826. else
  6827. {
  6828. FlashOnBackground();
  6829. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6830. }
  6831. }
  6832. }
  6833. //---------------------------------------------------------------------------
  6834. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6835. {
  6836. RestoreApp();
  6837. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6838. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6839. !NonVisualDataModule->Busy)
  6840. {
  6841. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6842. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6843. if (!ComponentVisible[fcQueueView])
  6844. {
  6845. ToggleQueueVisibility();
  6846. GoToQueue();
  6847. }
  6848. }
  6849. }
  6850. //---------------------------------------------------------------------------
  6851. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6852. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6853. {
  6854. UnicodeString Message;
  6855. TNotifyEvent OnClick = NULL;
  6856. TObject * UserData = NULL;
  6857. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6858. switch (Event)
  6859. {
  6860. case qeEmptyButMonitored:
  6861. if ((ATerminal != Terminal) || QueueInvisible)
  6862. {
  6863. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6864. OnClick = QueueEmptyNoteClicked;
  6865. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6866. TerminalNoteData->Terminal = ATerminal;
  6867. UserData = TerminalNoteData;
  6868. }
  6869. break;
  6870. case qeEmpty:
  6871. OperationComplete(ATerminal->QueueOperationStart);
  6872. break;
  6873. case qePendingUserAction:
  6874. if ((ATerminal != Terminal) ||
  6875. (QueueInvisible && !IsQueueAutoPopup()))
  6876. {
  6877. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6878. }
  6879. break;
  6880. default:
  6881. DebugFail();
  6882. }
  6883. if (!Message.IsEmpty())
  6884. {
  6885. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6886. }
  6887. }
  6888. //---------------------------------------------------------------------------
  6889. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6890. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6891. {
  6892. if (FDDExtMapFile != NULL)
  6893. {
  6894. CloseHandle(FDDExtMapFile);
  6895. FDDExtMapFile = NULL;
  6896. }
  6897. if (WinConfiguration->DDFakeFile)
  6898. {
  6899. DDFakeFileInitDrag(FileList, Created);
  6900. }
  6901. }
  6902. //---------------------------------------------------------------------------
  6903. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6904. {
  6905. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6906. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6907. {
  6908. FFakeFileDropTarget = FileName;
  6909. }
  6910. }
  6911. //---------------------------------------------------------------------------
  6912. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6913. {
  6914. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6915. if (!ForceDirectories(ApiPath(Result)))
  6916. {
  6917. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6918. }
  6919. FileSetAttr(ApiPath(Result), faHidden);
  6920. return Result;
  6921. }
  6922. //---------------------------------------------------------------------------
  6923. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6924. bool & Created)
  6925. {
  6926. FFakeFileDropTarget = UnicodeString();
  6927. FDragFakeDirectory = CreateFakeTransferDirectory();
  6928. FileList->AddItem(NULL, FDragFakeDirectory);
  6929. Created = true;
  6930. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6931. {
  6932. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6933. }
  6934. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6935. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6936. {
  6937. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6938. TDragExtCommStruct* CommStruct;
  6939. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6940. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6941. DebugAssert(CommStruct != NULL);
  6942. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6943. CommStruct->Dragging = true;
  6944. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6945. LENOF(CommStruct->DropDest));
  6946. NULL_TERMINATE(CommStruct->DropDest);
  6947. UnmapViewOfFile(CommStruct);
  6948. }
  6949. }
  6950. //---------------------------------------------------------------------------
  6951. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6952. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6953. {
  6954. bool Result;
  6955. DebugAssert(!IsLocalBrowserMode());
  6956. if (Sender == RemoteDirView)
  6957. {
  6958. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6959. }
  6960. else
  6961. {
  6962. DebugAssert(Sender == RemoteDriveView);
  6963. TStrings * FileList = RemoteDriveView->DragFileList();
  6964. try
  6965. {
  6966. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6967. }
  6968. __finally
  6969. {
  6970. delete FileList;
  6971. }
  6972. }
  6973. if (FDDTargetControl == RemoteDriveView)
  6974. {
  6975. RemoteDriveView->UpdateDropTarget();
  6976. }
  6977. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6978. // or from tree view to dir view.
  6979. // foMove happens when file/dir is dragged from remote tree view outside of
  6980. // application via dragex
  6981. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6982. (DropSourceControl == RemoteDriveView))
  6983. {
  6984. RemoteDriveView->UpdateDropSource();
  6985. }
  6986. return Result;
  6987. }
  6988. //---------------------------------------------------------------------------
  6989. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6990. {
  6991. DebugAssert(!IsLocalBrowserMode());
  6992. // This also handles drops of remote files to queue.
  6993. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6994. SAFE_DESTROY(FDDFileList);
  6995. if (!FFakeFileDropTarget.IsEmpty())
  6996. {
  6997. RemoveDir(ApiPath(FFakeFileDropTarget));
  6998. }
  6999. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  7000. {
  7001. try
  7002. {
  7003. TDragResult DDResult = (Sender == RemoteDirView) ?
  7004. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  7005. // Focus is moved to the target application,
  7006. // but as we are going to present the UI, we need to steal the focus back.
  7007. // This most likely won't work though (windows does not allow application
  7008. // to steal focus most of the time)
  7009. Application->BringToFront();
  7010. // On older version of Windows we never got drMove here, see also comment below.
  7011. // On Windows 10, we get the "move".
  7012. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  7013. {
  7014. UnicodeString TargetDirectory;
  7015. TFileOperation Operation;
  7016. // drInvalid may mean drMove, see comment below
  7017. switch (DDResult)
  7018. {
  7019. case drCopy:
  7020. Operation = foCopy;
  7021. break;
  7022. case drMove:
  7023. Operation = foMove;
  7024. break;
  7025. default:
  7026. DebugFail();
  7027. case drInvalid:
  7028. // prefer "copy" for safety
  7029. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7030. break;
  7031. }
  7032. TTransferOperationParam Param;
  7033. UnicodeString CounterName;
  7034. bool ForceQueue;
  7035. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7036. {
  7037. // we get drInvalid both if d&d was intercepted by ddext,
  7038. // and when users drops on no-drop location.
  7039. // we tell the difference by existence of response from ddext,
  7040. // so we ignore absence of response in this case
  7041. if (DDResult != drInvalid)
  7042. {
  7043. // here we know that the extension is installed,
  7044. // as it is checked as soon as drag&drop starts from
  7045. // RemoteFileControlDDCreateDragFileList
  7046. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7047. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7048. {
  7049. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7050. }
  7051. else
  7052. {
  7053. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7054. }
  7055. }
  7056. }
  7057. else
  7058. {
  7059. // download using fake file
  7060. Param.Temp = false;
  7061. Param.DragDrop = true;
  7062. if (ForceQueue)
  7063. {
  7064. Param.Queue = asOn;
  7065. }
  7066. if (Sender == RemoteDirView)
  7067. {
  7068. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7069. }
  7070. if (RemoteFileControlFileOperation(Sender, Operation,
  7071. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7072. {
  7073. Configuration->Usage->Inc(CounterName);
  7074. }
  7075. }
  7076. }
  7077. }
  7078. __finally
  7079. {
  7080. CloseHandle(FDDExtMapFile);
  7081. FDDExtMapFile = NULL;
  7082. delete FDragFakeMonitors;
  7083. FDragFakeMonitors = NULL;
  7084. RemoveDir(ApiPath(FDragFakeDirectory));
  7085. FDragFakeDirectory = L"";
  7086. FFakeFileDropTarget = UnicodeString();
  7087. }
  7088. }
  7089. if (FDragDropSshTerminate.get() != NULL)
  7090. {
  7091. FDragDropSshTerminate->Rethrow();
  7092. }
  7093. }
  7094. //---------------------------------------------------------------------------
  7095. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7096. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7097. {
  7098. // Remember drop effect so we know (when user drops files), if we copy or move
  7099. FLastDropEffect = dwEffect;
  7100. }
  7101. //---------------------------------------------------------------------------
  7102. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7103. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7104. {
  7105. bool Result;
  7106. if (FDDTargetControl == QueueView3)
  7107. {
  7108. Directory = DefaultDownloadTargetDirectory();
  7109. Result = true;
  7110. CounterName = L"DownloadsDragDropQueue";
  7111. ForceQueue = true;
  7112. }
  7113. else if (!FFakeFileDropTarget.IsEmpty())
  7114. {
  7115. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7116. Result = true;
  7117. ForceQueue = false;
  7118. CounterName = L"DownloadsDragDropFakeFile";
  7119. }
  7120. else
  7121. {
  7122. ForceQueue = false;
  7123. Enabled = false;
  7124. try
  7125. {
  7126. int Timer = 0;
  7127. Result = false;
  7128. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7129. {
  7130. {
  7131. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7132. TDragExtCommStruct* CommStruct;
  7133. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7134. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7135. DebugAssert(CommStruct != NULL);
  7136. Result = !CommStruct->Dragging;
  7137. if (Result)
  7138. {
  7139. Directory = ExtractFilePath(CommStruct->DropDest);
  7140. CounterName = L"DownloadsDragDropExternalExt";
  7141. }
  7142. UnmapViewOfFile(CommStruct);
  7143. }
  7144. if (!Result)
  7145. {
  7146. Sleep(50);
  7147. Timer += 50;
  7148. Application->ProcessMessages();
  7149. }
  7150. }
  7151. }
  7152. __finally
  7153. {
  7154. Enabled = true;
  7155. }
  7156. }
  7157. return Result;
  7158. }
  7159. //---------------------------------------------------------------------------
  7160. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7161. const UnicodeString TempDir, int SecDelay)
  7162. {
  7163. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7164. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7165. if (FDelayedDeletionTimer == NULL)
  7166. {
  7167. DebugAssert(HandleAllocated());
  7168. FDelayedDeletionTimer = new TTimer(this);
  7169. FDelayedDeletionTimer->Interval = 10000;
  7170. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7171. }
  7172. else
  7173. {
  7174. FDelayedDeletionTimer->Enabled = true;
  7175. }
  7176. }
  7177. //---------------------------------------------------------------------------
  7178. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7179. {
  7180. DebugAssert(FDelayedDeletionList != NULL);
  7181. TDateTime N = Now();
  7182. TDateTime Alert;
  7183. UnicodeString Directory;
  7184. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7185. {
  7186. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7187. if ((N >= Alert) || (Sender == NULL))
  7188. {
  7189. Directory = FDelayedDeletionList->Strings[Index];
  7190. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7191. {
  7192. FDelayedDeletionList->Delete(Index);
  7193. }
  7194. }
  7195. }
  7196. if (FDelayedDeletionList->Count == 0)
  7197. {
  7198. FDelayedDeletionTimer->Enabled = false;
  7199. }
  7200. }
  7201. //---------------------------------------------------------------------------
  7202. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7203. {
  7204. DebugAssert(!IsLocalBrowserMode());
  7205. if (IsFileControl(FDDTargetControl, osRemote) ||
  7206. (FDDTargetControl == SessionsPageControl))
  7207. {
  7208. TTerminal * TargetTerminal = NULL;
  7209. TFileOperation Operation = foNone;
  7210. if (FDDTargetControl == SessionsPageControl)
  7211. {
  7212. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7213. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7214. // do not allow dropping on the "+" tab
  7215. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7216. if (TargetTerminal != NULL)
  7217. {
  7218. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7219. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7220. {
  7221. Operation = foRemoteMove;
  7222. }
  7223. else
  7224. {
  7225. Operation = foRemoteCopy;
  7226. }
  7227. }
  7228. }
  7229. else
  7230. {
  7231. if (FLastDropEffect == DROPEFFECT_MOVE)
  7232. {
  7233. Operation = foRemoteMove;
  7234. }
  7235. else if (FLastDropEffect == DROPEFFECT_COPY)
  7236. {
  7237. Operation = foRemoteCopy;
  7238. }
  7239. }
  7240. if (Operation != foNone)
  7241. {
  7242. RemoteFileControlFileOperation(DropSourceControl,
  7243. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7244. }
  7245. // abort drag&drop
  7246. Abort();
  7247. }
  7248. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7249. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7250. (FDDTargetControl != QueueView3))
  7251. {
  7252. DebugAssert(!FDragTempDir.IsEmpty());
  7253. TTransferType Type;
  7254. UnicodeString TempDir = FDragTempDir;
  7255. // We clear FDragTempDir before calling
  7256. // just in case it fail (raises exception)
  7257. FDragTempDir = L"";
  7258. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7259. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7260. // empty directory parameter means temp directory -> don't display it!
  7261. UnicodeString TargetDir = L"";
  7262. int Options = 0;
  7263. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7264. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7265. {
  7266. Abort();
  7267. }
  7268. // TargetDir is set when dropped on local file control
  7269. // (this was workaround for legacy dirview event handling, now it should be
  7270. // made prettier)
  7271. if (TargetDir.IsEmpty())
  7272. {
  7273. TargetDir = TempDir;
  7274. if (ForceDirectories(ApiPath(TargetDir)))
  7275. {
  7276. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7277. FPendingTempSpaceWarn = true;
  7278. try
  7279. {
  7280. FDragDropOperation = true;
  7281. int Params = cpTemporary |
  7282. (Type == ttMove ? cpDelete : 0);
  7283. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7284. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7285. }
  7286. __finally
  7287. {
  7288. FDragDropOperation = false;
  7289. FPendingTempSpaceWarn = false;
  7290. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7291. }
  7292. }
  7293. else
  7294. {
  7295. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7296. }
  7297. }
  7298. }
  7299. }
  7300. //---------------------------------------------------------------------------
  7301. void __fastcall TCustomScpExplorerForm::DDDownload(
  7302. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7303. {
  7304. DebugAssert(!IsLocalBrowserMode());
  7305. TAutoBatch AutoBatch(this);
  7306. UpdateCopyParamCounters(*CopyParam);
  7307. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7308. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7309. {
  7310. RemoteDriveView->UpdateDropSource();
  7311. }
  7312. }
  7313. //---------------------------------------------------------------------------
  7314. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7315. {
  7316. public:
  7317. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7318. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7319. {
  7320. }
  7321. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7322. {
  7323. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7324. TDataObjectFilesEx::AllowData(FormatEtc);
  7325. }
  7326. };
  7327. //---------------------------------------------------------------------------
  7328. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7329. TObject * Sender, TDataObject *& DataObject)
  7330. {
  7331. if (FDDExtMapFile != NULL)
  7332. {
  7333. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7334. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7335. {
  7336. Abort();
  7337. }
  7338. if (FileList->Count > 0)
  7339. {
  7340. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7341. if (!FilesObject->IsValid(true, true))
  7342. {
  7343. FilesObject->_Release();
  7344. }
  7345. else
  7346. {
  7347. DataObject = FilesObject;
  7348. }
  7349. }
  7350. }
  7351. }
  7352. //---------------------------------------------------------------------------
  7353. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7354. {
  7355. DebugFail();
  7356. }
  7357. //---------------------------------------------------------------------------
  7358. void __fastcall TCustomScpExplorerForm::GoToTree()
  7359. {
  7360. ComponentVisible[fcRemoteTree] = true;
  7361. DriveView(osRemote)->SetFocus();
  7362. }
  7363. //---------------------------------------------------------------------------
  7364. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7365. TPanelExport Export)
  7366. {
  7367. TCustomDirView * DirView = this->DirView(Side);
  7368. std::unique_ptr<TStrings> ExportData(new TStringList());
  7369. switch (Export)
  7370. {
  7371. case pePath:
  7372. ExportData->Add(DirView->PathName);
  7373. break;
  7374. case peFileList:
  7375. case peFullFileList:
  7376. {
  7377. bool FullPath = (Export == peFullFileList);
  7378. DirView->CreateFileList(false, FullPath, ExportData.get());
  7379. for (int Index = 0; Index < ExportData->Count; Index++)
  7380. {
  7381. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7382. {
  7383. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7384. }
  7385. }
  7386. }
  7387. break;
  7388. default:
  7389. DebugFail();
  7390. }
  7391. return ExportData.release();
  7392. }
  7393. //---------------------------------------------------------------------------
  7394. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7395. TPanelExport Export, TPanelExportDestination Destination)
  7396. {
  7397. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7398. PanelExportStore(Side, Export, Destination, ExportData.get());
  7399. }
  7400. //---------------------------------------------------------------------------
  7401. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7402. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7403. TStrings * ExportData)
  7404. {
  7405. if (Destination == pedClipboard)
  7406. {
  7407. TInstantOperationVisualizer Visualizer;
  7408. CopyToClipboard(ExportData);
  7409. }
  7410. else
  7411. {
  7412. DebugFail();
  7413. }
  7414. }
  7415. //---------------------------------------------------------------------------
  7416. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7417. {
  7418. TCustomDirView * DirView = this->DirView(Side);
  7419. UnicodeString Mask = DirView->Mask;
  7420. if (DoFilterMaskDialog(DirView, Mask))
  7421. {
  7422. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7423. Configuration->Usage->Inc(L"Filters");
  7424. }
  7425. }
  7426. //---------------------------------------------------------------------------
  7427. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7428. {
  7429. return FQueueController->DefaultOperation();
  7430. }
  7431. //---------------------------------------------------------------------------
  7432. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7433. TQueueOperation Operation, void ** Param)
  7434. {
  7435. switch (Operation)
  7436. {
  7437. case qoPreferences:
  7438. return true;
  7439. case qoGoTo:
  7440. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7441. case qoOnceEmpty:
  7442. return IsAnythingQueued();
  7443. default:
  7444. return FQueueController->AllowOperation(Operation, Param);
  7445. }
  7446. }
  7447. //---------------------------------------------------------------------------
  7448. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7449. {
  7450. if (DebugAlwaysTrue(QueueView3->Visible))
  7451. {
  7452. QueueView3->SetFocus();
  7453. }
  7454. }
  7455. //---------------------------------------------------------------------------
  7456. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7457. TQueueOperation Operation, void * Param)
  7458. {
  7459. if (Operation == qoGoTo)
  7460. {
  7461. GoToQueue();
  7462. }
  7463. else if (Operation == qoPreferences)
  7464. {
  7465. PreferencesDialog(pmQueue);
  7466. }
  7467. else
  7468. {
  7469. FQueueController->ExecuteOperation(Operation, Param);
  7470. }
  7471. }
  7472. //---------------------------------------------------------------------------
  7473. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7474. {
  7475. return (Queue != NULL) && Queue->Enabled;
  7476. }
  7477. //---------------------------------------------------------------------------
  7478. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7479. {
  7480. DebugAssert(Queue != NULL);
  7481. if (Queue != NULL)
  7482. {
  7483. Queue->Enabled = !Queue->Enabled;
  7484. }
  7485. }
  7486. //---------------------------------------------------------------------------
  7487. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7488. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7489. {
  7490. FQueueActedItem = QueueView3->ItemFocused;
  7491. }
  7492. //---------------------------------------------------------------------------
  7493. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7494. {
  7495. return TopDock->Height + QueueSplitter->Height;
  7496. }
  7497. //---------------------------------------------------------------------------
  7498. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7499. {
  7500. return
  7501. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7502. (QueueDock->Visible ? QueueDock->Height : 0) +
  7503. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7504. }
  7505. //---------------------------------------------------------------------------
  7506. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7507. {
  7508. return ScaleByTextHeight(this, 48);
  7509. }
  7510. //---------------------------------------------------------------------------
  7511. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7512. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7513. {
  7514. // when queue is hidden by double-clicking splitter, stray attempt to
  7515. // resize the panel with strange value arrives, make sure it is ignored
  7516. if (ComponentVisible[fcQueueView])
  7517. {
  7518. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7519. if (NewSize > MaxHeightLimit)
  7520. {
  7521. NewSize = MaxHeightLimit;
  7522. }
  7523. int MinHeightLimit =
  7524. GetStaticQueuePanelComponentsHeight() +
  7525. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7526. GetMinQueueViewHeight();
  7527. if (NewSize < MinHeightLimit)
  7528. {
  7529. NewSize = MinHeightLimit;
  7530. }
  7531. }
  7532. else
  7533. {
  7534. Accept = false;
  7535. }
  7536. }
  7537. //---------------------------------------------------------------------------
  7538. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7539. {
  7540. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7541. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7542. if (QueueViewHeight < GetMinQueueViewHeight())
  7543. {
  7544. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7545. }
  7546. }
  7547. //---------------------------------------------------------------------------
  7548. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7549. TDragObject *& /*DragObject*/)
  7550. {
  7551. FQueueActedItem = QueueView3->ItemFocused;
  7552. }
  7553. //---------------------------------------------------------------------------
  7554. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7555. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7556. {
  7557. Accept = true;
  7558. if (Source == QueueView3)
  7559. {
  7560. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7561. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7562. if (Accept)
  7563. {
  7564. TQueueItemProxy * QueueItem;
  7565. TQueueItemProxy * DestQueueItem;
  7566. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7567. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7568. Accept = (QueueItem != DestQueueItem) &&
  7569. (QueueItem->Status == TQueueItem::qsPending) &&
  7570. (DestQueueItem->Status == TQueueItem::qsPending);
  7571. }
  7572. }
  7573. }
  7574. //---------------------------------------------------------------------------
  7575. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7576. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7577. {
  7578. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7579. {
  7580. TQueueItemProxy * QueueItem;
  7581. TQueueItemProxy * DestQueueItem;
  7582. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7583. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7584. QueueItem->Move(DestQueueItem);
  7585. }
  7586. }
  7587. //---------------------------------------------------------------------------
  7588. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7589. {
  7590. if ((QueueView3->ItemFocused == NULL) &&
  7591. (QueueView3->Items->Count > 0))
  7592. {
  7593. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7594. }
  7595. QueueLabelUpdateStatus();
  7596. }
  7597. //---------------------------------------------------------------------------
  7598. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7599. {
  7600. QueueLabelUpdateStatus();
  7601. }
  7602. //---------------------------------------------------------------------------
  7603. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7604. {
  7605. QueueLabel->UpdateStatus();
  7606. }
  7607. //---------------------------------------------------------------------------
  7608. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7609. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7610. {
  7611. if (Selected)
  7612. {
  7613. NonVisualDataModule->UpdateNonVisibleActions();
  7614. }
  7615. }
  7616. //---------------------------------------------------------------------------
  7617. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7618. {
  7619. TDragDropFilesEx * Result = NULL;
  7620. if (Sender == SessionsPageControl)
  7621. {
  7622. Result = FSessionsDragDropFilesEx;
  7623. }
  7624. else if (Sender == QueueView3)
  7625. {
  7626. Result = FQueueDragDropFilesEx;
  7627. }
  7628. else
  7629. {
  7630. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7631. if (DirView != NULL)
  7632. {
  7633. Result = DirView->DragDropFilesEx;
  7634. }
  7635. else
  7636. {
  7637. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7638. if (DriveView != NULL)
  7639. {
  7640. Result = DriveView->DragDropFilesEx;
  7641. }
  7642. }
  7643. }
  7644. DebugAssert(Result != NULL);
  7645. return Result;
  7646. }
  7647. //---------------------------------------------------------------------------
  7648. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7649. {
  7650. return (DView->SelCount == DView->FilesCount);
  7651. }
  7652. //---------------------------------------------------------------------------
  7653. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7654. {
  7655. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7656. }
  7657. //---------------------------------------------------------------------------
  7658. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7659. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7660. {
  7661. DebugAssert(!IsLocalBrowserMode());
  7662. TFileOperation Operation;
  7663. switch (Effect)
  7664. {
  7665. case DROPEFFECT_MOVE:
  7666. Operation = foMove;
  7667. break;
  7668. case DROPEFFECT_COPY:
  7669. // occures on WinXP (reported by user)
  7670. default:
  7671. Operation = foCopy;
  7672. break;
  7673. };
  7674. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7675. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7676. if (DragDropFilesEx->FileList->Count > 0)
  7677. {
  7678. TStrings * FileList = new TStringList();
  7679. try
  7680. {
  7681. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7682. {
  7683. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7684. }
  7685. FDragDropOperation = true;
  7686. TTransferOperationParam Param;
  7687. Param.TargetDirectory = TargetPath;
  7688. // upload, no temp dirs
  7689. Param.Temp = false;
  7690. Param.DragDrop = DragDrop;
  7691. Param.Options =
  7692. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7693. if (ForceQueue)
  7694. {
  7695. Param.Queue = asOn;
  7696. }
  7697. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7698. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7699. {
  7700. if (IsFileControl(DropSourceControl, osLocal))
  7701. {
  7702. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7703. }
  7704. else
  7705. {
  7706. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7707. }
  7708. }
  7709. }
  7710. __finally
  7711. {
  7712. FDragDropOperation = false;
  7713. delete FileList;
  7714. }
  7715. }
  7716. }
  7717. //---------------------------------------------------------------------------
  7718. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7719. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7720. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7721. {
  7722. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7723. }
  7724. //---------------------------------------------------------------------------
  7725. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7726. TObject * Sender, int grfKeyState, int & dwEffect)
  7727. {
  7728. DebugAssert(!IsLocalBrowserMode());
  7729. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7730. if ((dwEffect != DROPEFFECT_NONE) &&
  7731. IsFileControl(DropSourceControl, osRemote))
  7732. {
  7733. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7734. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7735. (RemoteDirView->DropTarget == NULL))
  7736. {
  7737. dwEffect = DROPEFFECT_NONE;
  7738. }
  7739. else
  7740. {
  7741. if (dwEffect == DROPEFFECT_COPY)
  7742. {
  7743. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7744. // currently we support copying always (at least via temporary directory);
  7745. // remove associated checks once this all proves stable and working
  7746. bool CopyCapable = true;
  7747. // if we do not support neither of operations, there's no discussion
  7748. if (!MoveCapable && !CopyCapable)
  7749. {
  7750. dwEffect = DROPEFFECT_NONE;
  7751. }
  7752. else
  7753. {
  7754. // The default effect inside remote panel is move,
  7755. // unless we do not support it, but support copy
  7756. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7757. {
  7758. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7759. }
  7760. else
  7761. {
  7762. // with ctrl-down, we want copy unless it is not supported
  7763. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7764. }
  7765. }
  7766. }
  7767. }
  7768. }
  7769. }
  7770. //---------------------------------------------------------------------------
  7771. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7772. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7773. {
  7774. DebugAssert(!IsLocalBrowserMode());
  7775. if (FDDTotalSize >= 0)
  7776. {
  7777. if (File->IsDirectory)
  7778. {
  7779. FDDTotalSize = -1;
  7780. }
  7781. else
  7782. {
  7783. FDDTotalSize += File->Size;
  7784. }
  7785. }
  7786. DebugAssert(!FDragTempDir.IsEmpty());
  7787. // TODO: this is quite ineffective
  7788. // TODO: what if invalid character replacement is disabled?
  7789. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7790. UnicodeString TransferFileName;
  7791. if (Sender == RemoteDriveView)
  7792. {
  7793. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7794. }
  7795. else
  7796. {
  7797. TransferFileName = File->FileName;
  7798. }
  7799. FDDFileList->AddObject(TransferFileName, File);
  7800. }
  7801. //---------------------------------------------------------------------------
  7802. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7803. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7804. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7805. {
  7806. // sometimes we do not get DDEnd so the list is not released
  7807. SAFE_DESTROY(FDDFileList);
  7808. FDDFileList = new TStringList();
  7809. FDragTempDir = WinConfiguration->TemporaryDir();
  7810. FDDTotalSize = 0;
  7811. FDragDropSshTerminate.reset(NULL);
  7812. }
  7813. //---------------------------------------------------------------------------
  7814. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7815. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7816. HRESULT & Result)
  7817. {
  7818. if (Result == DRAGDROP_S_DROP)
  7819. {
  7820. try
  7821. {
  7822. GlobalDragImageList->HideDragImage();
  7823. try
  7824. {
  7825. RemoteFileControlDDTargetDrop();
  7826. }
  7827. catch(ESshTerminate & E)
  7828. {
  7829. FDragDropSshTerminate.reset(E.Clone());
  7830. }
  7831. }
  7832. catch (Exception &E)
  7833. {
  7834. // If downloading fails we need to cancel drag&drop, otherwise
  7835. // Explorer shows error
  7836. // But by the way exception probably never reach this point as
  7837. // it's catched on way.
  7838. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7839. Result = DRAGDROP_S_CANCEL;
  7840. ShowExtendedException(Terminal, &E);
  7841. }
  7842. }
  7843. }
  7844. //---------------------------------------------------------------------------
  7845. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7846. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7847. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7848. {
  7849. TFileMasks::TParams MaskParams;
  7850. MaskParams.Size = Size;
  7851. MaskParams.Modification = Modification;
  7852. // this does not re-parse the mask if it is the same as the last time
  7853. FDirViewMatchMask = Masks;
  7854. bool ImplicitMatch;
  7855. Matches =
  7856. // RecurseInclude parameter has no effect as the Path is empty
  7857. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7858. (AllowImplicitMatches || !ImplicitMatch);
  7859. }
  7860. //---------------------------------------------------------------------------
  7861. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7862. TObject * Sender, TListItem * Item, WORD & Indexes)
  7863. {
  7864. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7865. UnicodeString Ext;
  7866. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7867. {
  7868. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7869. }
  7870. else
  7871. {
  7872. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7873. }
  7874. if (SameText(Ext, Configuration->PartialExt))
  7875. {
  7876. Indexes |= oiPartial;
  7877. }
  7878. }
  7879. //---------------------------------------------------------------------------
  7880. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7881. {
  7882. return
  7883. DirViewEnabled(osCurrent) &&
  7884. DirView(osCurrent)->CanPasteFromClipBoard();
  7885. }
  7886. //---------------------------------------------------------------------------
  7887. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7888. {
  7889. bool Result = false;
  7890. if (CanPasteToDirViewFromClipBoard())
  7891. {
  7892. Result = true;
  7893. }
  7894. else
  7895. {
  7896. UnicodeString ClipboardText;
  7897. if (NonEmptyTextFromClipboard(ClipboardText) &&
  7898. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  7899. {
  7900. if (StoredSessions->IsUrl(ClipboardText))
  7901. {
  7902. Result = true;
  7903. }
  7904. else
  7905. {
  7906. Result = DirViewEnabled(osCurrent);
  7907. }
  7908. }
  7909. }
  7910. return Result;
  7911. }
  7912. //---------------------------------------------------------------------------
  7913. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7914. {
  7915. if (DoesClipboardContainOurFiles())
  7916. {
  7917. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7918. {
  7919. DebugAssert(!IsLocalBrowserMode());
  7920. TTerminalManager * Manager = TTerminalManager::Instance();
  7921. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7922. Manager->ActiveTerminal = FClipboardTerminal;
  7923. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7924. }
  7925. }
  7926. else if (CanPasteToDirViewFromClipBoard())
  7927. {
  7928. DirView(osCurrent)->PasteFromClipBoard();
  7929. }
  7930. else
  7931. {
  7932. UnicodeString ClipboardText;
  7933. if (NonEmptyTextFromClipboard(ClipboardText))
  7934. {
  7935. if (StoredSessions->IsUrl(ClipboardText))
  7936. {
  7937. NewSession(false, ClipboardText);
  7938. }
  7939. else
  7940. {
  7941. DirView(osCurrent)->Path = ClipboardText;
  7942. }
  7943. }
  7944. }
  7945. }
  7946. //---------------------------------------------------------------------------
  7947. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7948. {
  7949. // TBD
  7950. }
  7951. //---------------------------------------------------------------------------
  7952. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7953. {
  7954. TCustomDirView * ADirView = DirView(Side);
  7955. ADirView->SelectAll(Mode);
  7956. ADirView->SetFocus();
  7957. }
  7958. //---------------------------------------------------------------------------
  7959. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7960. {
  7961. TCustomDirView * ADirView = DirView(Side);
  7962. TFileFilter Filter;
  7963. DefaultFileFilter(Filter);
  7964. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7965. {
  7966. Configuration->Usage->Inc(L"MaskSelections");
  7967. ADirView->SelectFiles(Filter, Select);
  7968. ADirView->SetFocus();
  7969. }
  7970. }
  7971. //---------------------------------------------------------------------------
  7972. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7973. {
  7974. TCustomDirView * ADirView = DirView(Side);
  7975. ADirView->RestoreSelectedNames();
  7976. ADirView->SetFocus();
  7977. }
  7978. //---------------------------------------------------------------------------
  7979. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7980. {
  7981. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7982. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7983. {
  7984. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7985. UnicodeString Ext;
  7986. if (!IsSideLocalBrowser(osCurrent))
  7987. {
  7988. Ext = UnixExtractFileExt(FileName);
  7989. }
  7990. else
  7991. {
  7992. Ext = ExtractFileExt(FileName);
  7993. }
  7994. if (Ext.IsEmpty())
  7995. {
  7996. Ext = L".";
  7997. }
  7998. TFileFilter Filter;
  7999. Filter.Masks = FORMAT(L"*%s", (Ext));
  8000. Filter.Directories = false;
  8001. CurrentDirView->SelectFiles(Filter, Select);
  8002. }
  8003. }
  8004. //---------------------------------------------------------------------------
  8005. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  8006. const TStatusFileInfo & FileInfo, TOperationSide Side)
  8007. {
  8008. UnicodeString Result;
  8009. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  8010. {
  8011. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  8012. }
  8013. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  8014. {
  8015. // noop
  8016. }
  8017. else
  8018. {
  8019. Result =
  8020. FMTLOAD(FILE_INFO_FORMAT,
  8021. (FormatBytes(FileInfo.SelectedSize),
  8022. FormatBytes(FileInfo.FilesSize),
  8023. FormatNumber(FileInfo.SelectedCount),
  8024. FormatNumber(FileInfo.FilesCount)));
  8025. }
  8026. return Result;
  8027. }
  8028. //---------------------------------------------------------------------------
  8029. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8030. TTBXStatusPanel * Panel, TOperationSide Side)
  8031. {
  8032. if (Panel->Index == 1)
  8033. {
  8034. ToggleShowHiddenFiles();
  8035. }
  8036. else if (Panel->Index == 2)
  8037. {
  8038. Filter(Side);
  8039. }
  8040. }
  8041. //---------------------------------------------------------------------------
  8042. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8043. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8044. {
  8045. DebugAssert(!StatusBar->SimplePanel);
  8046. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8047. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8048. }
  8049. //---------------------------------------------------------------------------
  8050. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8051. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8052. {
  8053. DebugAssert(StatusBar->Panels->Count >= 3);
  8054. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8055. if (FileInfo.HiddenCount > 0)
  8056. {
  8057. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8058. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8059. }
  8060. else
  8061. {
  8062. HiddenFilesPanel->ViewPriority = 0;
  8063. // not really necessary, just to cleanup no-longer-valid data
  8064. HiddenFilesPanel->Caption = L"";
  8065. }
  8066. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8067. if (FileInfo.FilteredCount > 0)
  8068. {
  8069. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8070. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8071. }
  8072. else
  8073. {
  8074. FilteredFilesPanel->ViewPriority = 0;
  8075. // not really necessary, just to cleanup no-longer-valid data
  8076. FilteredFilesPanel->Caption = L"";
  8077. }
  8078. }
  8079. //---------------------------------------------------------------------------
  8080. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8081. TObject * /*Sender*/)
  8082. {
  8083. if (DirView(osOther)->Enabled)
  8084. {
  8085. DirView(osOther)->SetFocus();
  8086. }
  8087. }
  8088. //---------------------------------------------------------------------------
  8089. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8090. {
  8091. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8092. switch (Config.Show)
  8093. {
  8094. case qvShow:
  8095. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8096. {
  8097. Config.Show = qvHide;
  8098. }
  8099. else
  8100. {
  8101. Config.Show = Config.LastHideShow;
  8102. }
  8103. break;
  8104. case qvHideWhenEmpty:
  8105. if (ComponentVisible[fcQueueView])
  8106. {
  8107. Config.Show = qvHide;
  8108. }
  8109. else
  8110. {
  8111. Config.LastHideShow = Config.Show;
  8112. Config.Show = qvShow;
  8113. }
  8114. break;
  8115. case qvHide:
  8116. Config.LastHideShow = Config.Show;
  8117. Config.Show = qvShow;
  8118. break;
  8119. }
  8120. WinConfiguration->QueueView = Config;
  8121. }
  8122. //---------------------------------------------------------------------------
  8123. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8124. {
  8125. UnicodeString Result;
  8126. if (FTerminal != NULL)
  8127. {
  8128. switch (WinConfiguration->PathInCaption)
  8129. {
  8130. case picShort:
  8131. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8132. break;
  8133. case picFull:
  8134. Result = FTerminal->CurrentDirectory;
  8135. break;
  8136. }
  8137. }
  8138. return Result;
  8139. }
  8140. //---------------------------------------------------------------------------
  8141. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8142. {
  8143. TColor Result = GetWindowColor(FSessionColor);
  8144. return Result;
  8145. }
  8146. //---------------------------------------------------------------------------
  8147. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8148. {
  8149. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8150. return Result;
  8151. }
  8152. //---------------------------------------------------------------------------
  8153. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8154. {
  8155. TTerminalManager::Instance()->UpdateAppTitle();
  8156. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8157. // background to gray on Windows 7 (works on Windows 10).
  8158. // See also EnableControl
  8159. if (Showing)
  8160. {
  8161. if (Terminal != NULL)
  8162. {
  8163. // Update path when it changes
  8164. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8165. {
  8166. UpdateSessionTab(SessionsPageControl->ActivePage);
  8167. }
  8168. }
  8169. NonVisualDataModule->ReconnectSessionAction->Update();
  8170. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8171. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8172. CenterReconnectToolbar();
  8173. bool HasTerminal = HasActiveTerminal();
  8174. RemoteDirView->Enabled = HasTerminal;
  8175. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8176. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8177. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8178. RemoteDriveView->Color = RemoteDirView->Color;
  8179. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8180. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8181. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8182. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8183. QueueFileList->Enabled = QueueView3->Enabled;
  8184. QueueFileList->Color = QueueView3->Color;
  8185. QueueFileList->Font->Color = QueueView3->Font->Color;
  8186. QueueLabelUpdateStatus();
  8187. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8188. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8189. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8190. }
  8191. }
  8192. //---------------------------------------------------------------------------
  8193. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8194. {
  8195. UpdateControls();
  8196. }
  8197. //---------------------------------------------------------------------------
  8198. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8199. TObject * Sender)
  8200. {
  8201. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8202. DebugAssert(DirView != NULL);
  8203. DoDirViewLoaded(DirView);
  8204. TransferPresetAutoSelect();
  8205. }
  8206. //---------------------------------------------------------------------------
  8207. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8208. {
  8209. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8210. // first run after installation
  8211. if (double(Updates.LastCheck) == 0)
  8212. {
  8213. // make sure next time there will be an update (if enabled)
  8214. Updates.LastCheck = TDateTime(1);
  8215. WinConfiguration->Updates = Updates;
  8216. }
  8217. else if ((double(Updates.Period) > 0) &&
  8218. (Now() - Updates.LastCheck >= Updates.Period))
  8219. {
  8220. TThreadMethod OnUpdatesChecked = NULL;
  8221. if (!IsUWP())
  8222. {
  8223. OnUpdatesChecked = UpdatesChecked;
  8224. }
  8225. StartUpdateThread(OnUpdatesChecked);
  8226. }
  8227. }
  8228. //---------------------------------------------------------------------------
  8229. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8230. {
  8231. UnicodeString Message;
  8232. bool New;
  8233. TQueryType Type;
  8234. GetUpdatesMessage(Message, New, Type, false);
  8235. if (!Message.IsEmpty())
  8236. {
  8237. if (New)
  8238. {
  8239. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8240. }
  8241. if (!New && (Type != qtWarning))
  8242. {
  8243. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8244. }
  8245. else
  8246. {
  8247. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8248. }
  8249. if (New)
  8250. {
  8251. Configuration->Usage->Inc(L"UpdateNotifications");
  8252. }
  8253. }
  8254. }
  8255. //---------------------------------------------------------------------------
  8256. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8257. {
  8258. RestoreApp();
  8259. bool CanDisplay = !NonVisualDataModule->Busy;
  8260. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8261. {
  8262. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8263. }
  8264. if (CanDisplay)
  8265. {
  8266. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8267. CheckForUpdates(true);
  8268. }
  8269. else
  8270. {
  8271. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8272. }
  8273. }
  8274. //---------------------------------------------------------------------------
  8275. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8276. TCopyParamRuleData & Data)
  8277. {
  8278. DebugAssert(Terminal != NULL);
  8279. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8280. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8281. Data.RemoteDirectory = RemoteDirView->PathName;
  8282. }
  8283. //---------------------------------------------------------------------------
  8284. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8285. {
  8286. // Terminal can be null when we are changing local directory implicitly,
  8287. // because it has been deleted, while no session is connected
  8288. // (Login dialog is open)
  8289. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8290. {
  8291. DebugAssert(!IsLocalBrowserMode());
  8292. TCopyParamRuleData Data;
  8293. GetTransferPresetAutoSelectData(Data);
  8294. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8295. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8296. if (CopyParamIndex < 0)
  8297. {
  8298. // there is no preset that matches autoselection
  8299. // set preset that we consider "default"
  8300. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8301. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8302. }
  8303. else
  8304. {
  8305. // there is preset matching autoselection
  8306. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8307. if (CopyParamName == FCopyParamAutoSelected)
  8308. {
  8309. // autoselected the same preset as the last time
  8310. // make no change (i.e. preserve custom user preset, if any)
  8311. }
  8312. else
  8313. {
  8314. // autoselected the different preset then the last time (or there
  8315. // was default preset set)
  8316. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8317. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8318. }
  8319. }
  8320. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8321. {
  8322. if (CopyParamIndex >= 0)
  8323. {
  8324. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8325. }
  8326. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8327. try
  8328. {
  8329. int Fmt =
  8330. (CopyParamIndex < 0) ?
  8331. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8332. COPY_PARAM_AUTOSELECTED;
  8333. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8334. Data->Message = MainInstructions(Message);
  8335. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8336. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8337. CopyParamAttrs);
  8338. if (CopyParamIndex >= 0)
  8339. {
  8340. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8341. Info = FORMAT(L"%s\n \n%s", (Info,
  8342. FMTLOAD(COPY_PARAM_RULE,
  8343. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8344. }
  8345. Data->Message += L"\n\n" + Info;
  8346. if (WinConfiguration->CopyParamAutoSelectNotice)
  8347. {
  8348. TransferPresetNoteMessage(Data, true);
  8349. }
  8350. else
  8351. {
  8352. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8353. Data = NULL; // ownership passed
  8354. }
  8355. }
  8356. __finally
  8357. {
  8358. delete Data;
  8359. }
  8360. }
  8361. }
  8362. }
  8363. //---------------------------------------------------------------------------
  8364. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8365. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8366. {
  8367. DebugAssert(NoteData != NULL);
  8368. DebugAssert(!IsLocalBrowserMode());
  8369. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8370. TQueryButtonAlias Aliases[1];
  8371. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8372. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8373. Params.Aliases = Aliases;
  8374. Params.AliasesCount = LENOF(Aliases);
  8375. unsigned int Result =
  8376. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8377. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8378. switch (Result)
  8379. {
  8380. case qaNeverAskAgain:
  8381. DebugAssert(AllowNeverAskAgain);
  8382. WinConfiguration->CopyParamAutoSelectNotice = false;
  8383. break;
  8384. case qaIgnore:
  8385. PreferencesDialog(pmPresets);
  8386. break;
  8387. }
  8388. }
  8389. //---------------------------------------------------------------------------
  8390. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8391. {
  8392. // as of now useless, as this is used for notes only, never for balloons, ...
  8393. RestoreApp();
  8394. // .. and we should never be busy here
  8395. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8396. {
  8397. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8398. }
  8399. }
  8400. //---------------------------------------------------------------------------
  8401. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8402. TPreferencesMode APreferencesMode)
  8403. {
  8404. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8405. TCopyParamRuleData Data;
  8406. if (Terminal != NULL)
  8407. {
  8408. PreferencesData.reset(new TPreferencesDialogData());
  8409. GetTransferPresetAutoSelectData(Data);
  8410. PreferencesData->CopyParamRuleData = &Data;
  8411. }
  8412. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8413. }
  8414. //---------------------------------------------------------------------------
  8415. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8416. const TCustomCommandType & Command)
  8417. {
  8418. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8419. {
  8420. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8421. }
  8422. }
  8423. //---------------------------------------------------------------------------
  8424. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8425. {
  8426. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8427. TCustomCommandType Command;
  8428. // make sure we use local custom command when remote are not supported
  8429. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8430. {
  8431. Command = FLastCustomCommand;
  8432. }
  8433. else
  8434. {
  8435. Command.Params = Command.Params | ccLocal;
  8436. }
  8437. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8438. FEditingFocusedAdHocCommand = OnFocused;
  8439. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8440. int Options =
  8441. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8442. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8443. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8444. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8445. {
  8446. FLastCustomCommand = Command;
  8447. UpdateCustomCommandsToolbar();
  8448. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8449. }
  8450. }
  8451. //---------------------------------------------------------------------------
  8452. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8453. {
  8454. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8455. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8456. DebugAssert(State > 0);
  8457. if (State <= 0)
  8458. {
  8459. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8460. }
  8461. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8462. }
  8463. //---------------------------------------------------------------------------
  8464. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8465. TCustomCommandType & Command, int & State)
  8466. {
  8467. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8468. if (Result)
  8469. {
  8470. Command = FLastCustomCommand;
  8471. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8472. }
  8473. return Result;
  8474. }
  8475. //---------------------------------------------------------------------------
  8476. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8477. {
  8478. ResetIncrementalSearch();
  8479. }
  8480. //---------------------------------------------------------------------------
  8481. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8482. {
  8483. DebugAssert(ComponentVisible[Component]);
  8484. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8485. }
  8486. //---------------------------------------------------------------------------
  8487. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8488. {
  8489. // when queue panel is resized here directly, the status bar is stretched
  8490. // over whole space the panel occupied
  8491. PostComponentHide(fcQueueView);
  8492. }
  8493. //---------------------------------------------------------------------------
  8494. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8495. {
  8496. ComponentVisible[fcQueueFileList] = false;
  8497. }
  8498. //---------------------------------------------------------------------------
  8499. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8500. {
  8501. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8502. RefreshColorMode();
  8503. ResetSysDarkTheme();
  8504. ConfigurationChanged();
  8505. ConfigureInterface();
  8506. // Should be called for all controls
  8507. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8508. }
  8509. //---------------------------------------------------------------------------
  8510. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8511. {
  8512. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8513. if (!FInvalid &&
  8514. (Message.LParam != 0) &&
  8515. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8516. {
  8517. ThemeChanged();
  8518. }
  8519. TForm::Dispatch(&Message);
  8520. }
  8521. //---------------------------------------------------------------------------
  8522. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8523. {
  8524. TMessage * M = static_cast<TMessage*>(Message);
  8525. switch (M->Msg)
  8526. {
  8527. case CM_DIALOGCHAR:
  8528. CMDialogChar(*M);
  8529. break;
  8530. case WM_APPCOMMAND:
  8531. WMAppCommand(*M);
  8532. break;
  8533. case WM_SYSCOMMAND:
  8534. WMSysCommand(*M);
  8535. break;
  8536. case WM_QUERYENDSESSION:
  8537. WMQueryEndSession(*M);
  8538. break;
  8539. case WM_ENDSESSION:
  8540. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8541. break;
  8542. #ifdef _DEBUG
  8543. case WM_WINDOWPOSCHANGED:
  8544. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8545. break;
  8546. case CM_CUSTOMSTYLECHANGED:
  8547. TForm::Dispatch(Message);
  8548. break;
  8549. #endif
  8550. case WM_COMPONENT_HIDE:
  8551. {
  8552. Byte Component = static_cast<Byte>(M->WParam);
  8553. // sanity check
  8554. if (ComponentVisible[Component])
  8555. {
  8556. // special treatment
  8557. if (Component == fcQueueView)
  8558. {
  8559. ToggleQueueVisibility();
  8560. DebugAssert(!ComponentVisible[fcQueueView]);
  8561. }
  8562. else
  8563. {
  8564. ComponentVisible[Component] = false;
  8565. }
  8566. }
  8567. }
  8568. break;
  8569. case WM_COPYDATA:
  8570. WMCopyData(*M);
  8571. break;
  8572. case WM_MANAGES_CAPTION:
  8573. // caption managed in TTerminalManager::UpdateAppTitle()
  8574. M->Result = 1;
  8575. break;
  8576. case WM_WANTS_MOUSEWHEEL:
  8577. M->Result = 1;
  8578. break;
  8579. case CM_SHOWINGCHANGED:
  8580. CMShowingChanged(*M);
  8581. break;
  8582. case WM_CLOSE:
  8583. WMClose(*M);
  8584. break;
  8585. case WM_DPICHANGED:
  8586. WMDpiChanged(*M);
  8587. break;
  8588. case CM_DPICHANGED:
  8589. CMDpiChanged(*M);
  8590. break;
  8591. case WM_SETTINGCHANGE:
  8592. WMSettingChange(*M);
  8593. break;
  8594. case CM_DIALOGKEY:
  8595. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8596. break;
  8597. default:
  8598. TForm::Dispatch(Message);
  8599. break;
  8600. }
  8601. }
  8602. //---------------------------------------------------------------------------
  8603. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8604. {
  8605. // noop
  8606. }
  8607. //---------------------------------------------------------------------------
  8608. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8609. {
  8610. TForm::Dispatch(&Message);
  8611. FSessionColors->Clear();
  8612. AddFixedSessionImages();
  8613. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8614. UpdateImages();
  8615. }
  8616. //---------------------------------------------------------------------------
  8617. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8618. {
  8619. TForm::Dispatch(&Message);
  8620. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8621. UpdatePixelsPerInchMainWindowCounter();
  8622. }
  8623. //---------------------------------------------------------------------------
  8624. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8625. {
  8626. // Cannot close window while we are busy.
  8627. // We cannot test this in FormCloseQuery as that is called also from
  8628. // Close(), which is called by CloseApplicationAction. So we can be busy
  8629. // there already even, when it is legitimate to close the application.
  8630. // Possibly a better place to handle this would be WMSysCommand.
  8631. if (NonVisualDataModule->Busy)
  8632. {
  8633. Message.Result = 1;
  8634. }
  8635. else
  8636. {
  8637. TForm::Dispatch(&Message);
  8638. }
  8639. }
  8640. //---------------------------------------------------------------------------
  8641. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8642. {
  8643. TForm::Dispatch(&Message);
  8644. if (Showing && (Terminal == NULL))
  8645. {
  8646. // When we are starting minimized (i.e. from an installer),
  8647. // postpone showing Login dialog until we get restored.
  8648. // Otherwise the Login dialog (and Authentication window) show restored
  8649. // over invisible (minimized) main window.
  8650. if (WindowState == wsMinimized)
  8651. {
  8652. FNeedSession = true;
  8653. }
  8654. else
  8655. {
  8656. // This happens before application ever goes idle, so the toolbars would
  8657. // stay enabled (initial state) until the Login dialog is dismissed.
  8658. UpdateActions();
  8659. NonVisualDataModule->StartBusy();
  8660. try
  8661. {
  8662. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8663. // otherwise the dialog does not receive focus.
  8664. // With Commander interface the ProcessMessages is called already
  8665. // by TDriveView, but with Explorer interface, we need to call it explicily
  8666. Application->ProcessMessages();
  8667. // do not reload sessions, they have been loaded just now (optimization)
  8668. NeedSession(true);
  8669. }
  8670. __finally
  8671. {
  8672. NonVisualDataModule->EndBusy();
  8673. }
  8674. }
  8675. }
  8676. }
  8677. //---------------------------------------------------------------------------
  8678. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8679. {
  8680. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8681. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8682. }
  8683. //---------------------------------------------------------------------------
  8684. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8685. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8686. int & MaxHeight)
  8687. {
  8688. // workaround for bug in TWinControl.CalcConstraints
  8689. // Check for empty rect (restore from iconic state) is done there only after
  8690. // call to AdjustClientRect, which enlarges the rect (for forms).
  8691. TRect R = GetClientRect();
  8692. // when restoring from iconic state, place no restrictions
  8693. if (IsRectEmpty(R))
  8694. {
  8695. MinWidth = 0;
  8696. MinHeight = 0;
  8697. MaxWidth = 32000;
  8698. MaxHeight = 32000;
  8699. }
  8700. }
  8701. //---------------------------------------------------------------------------
  8702. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8703. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8704. {
  8705. // terminal can be already closed (e.g. dropped connection)
  8706. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8707. {
  8708. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8709. try
  8710. {
  8711. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8712. }
  8713. catch(...)
  8714. {
  8715. if (!Terminal->Active)
  8716. {
  8717. Close = true;
  8718. }
  8719. throw;
  8720. }
  8721. }
  8722. }
  8723. //---------------------------------------------------------------------------
  8724. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8725. {
  8726. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8727. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8728. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8729. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8730. {
  8731. OnGetSpaceAvailable = GetSpaceAvailable;
  8732. }
  8733. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8734. OnGetSpaceAvailable);
  8735. }
  8736. //---------------------------------------------------------------------------
  8737. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8738. {
  8739. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8740. Terminal->FillSessionDataForCode(Data.get());
  8741. return Data.release();
  8742. }
  8743. //---------------------------------------------------------------------------
  8744. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8745. {
  8746. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8747. DoGenerateUrlDialog(Data.get(), Paths);
  8748. }
  8749. //---------------------------------------------------------------------------
  8750. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8751. {
  8752. GenerateUrl(NULL);
  8753. }
  8754. //---------------------------------------------------------------------------
  8755. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8756. {
  8757. std::unique_ptr<TStrings> Paths(new TStringList());
  8758. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8759. GenerateUrl(Paths.get());
  8760. }
  8761. //---------------------------------------------------------------------------
  8762. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8763. {
  8764. FSessionColor = value;
  8765. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8766. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8767. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8768. DebugAssert(ColorItem != NULL);
  8769. ColorItem->Color = C;
  8770. NonVisualDataModule->ColorMenuItem->Color = C;
  8771. UpdateControls();
  8772. }
  8773. //---------------------------------------------------------------------------
  8774. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8775. {
  8776. if (value != FSessionColor)
  8777. {
  8778. UpdateSessionColor(value);
  8779. // Is null when called from LastTerminalClosed
  8780. if (Terminal != NULL)
  8781. {
  8782. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8783. }
  8784. }
  8785. }
  8786. //---------------------------------------------------------------------------
  8787. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8788. {
  8789. bool Result = FNoteTimer->Enabled;
  8790. if (Result)
  8791. {
  8792. // cannot cancel note too early
  8793. bool NotEarly =
  8794. (Now() - FNoteShown >
  8795. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8796. if (Force || NotEarly)
  8797. {
  8798. FNoteTimer->Enabled = false;
  8799. FNote = L"";
  8800. SAFE_DESTROY(FNoteData);
  8801. FOnNoteClick = NULL;
  8802. FNoteHints = FNotes->Text;
  8803. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8804. UpdateStatusBar();
  8805. }
  8806. }
  8807. return Result;
  8808. }
  8809. //---------------------------------------------------------------------------
  8810. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8811. {
  8812. DebugAssert(FNoteTimer->Enabled);
  8813. CancelNote(true);
  8814. }
  8815. //---------------------------------------------------------------------------
  8816. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  8817. {
  8818. FNoteHints = FNotes->Text.TrimRight();
  8819. }
  8820. //---------------------------------------------------------------------------
  8821. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8822. {
  8823. int P = Note.Pos(L"\n");
  8824. if (P > 0)
  8825. {
  8826. Note.SetLength(P - 1);
  8827. }
  8828. FNotes->Add(FORMAT(L"[%s] %s",
  8829. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8830. while (FNotes->Count > 10)
  8831. {
  8832. FNotes->Delete(0);
  8833. }
  8834. if (UpdateNow)
  8835. {
  8836. UpdateNoteHints();
  8837. UpdateStatusBar();
  8838. }
  8839. }
  8840. //---------------------------------------------------------------------------
  8841. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8842. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8843. {
  8844. int P = Note.Pos(L"\n");
  8845. if (P > 0)
  8846. {
  8847. Note.SetLength(P - 1);
  8848. }
  8849. UpdateNoteHints();
  8850. FNote = Note;
  8851. SAFE_DESTROY(FNoteData);
  8852. FNoteData = NoteData;
  8853. FOnNoteClick = OnNoteClick;
  8854. AddNote(Note, false);
  8855. UpdateStatusBar();
  8856. FNoteShown = Now();
  8857. FNoteTimer->Enabled = false;
  8858. if (Seconds == 0)
  8859. {
  8860. Seconds = WinConfiguration->NotificationsTimeout;
  8861. }
  8862. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8863. FNoteTimer->Enabled = true;
  8864. }
  8865. //---------------------------------------------------------------------------
  8866. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8867. {
  8868. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8869. }
  8870. //---------------------------------------------------------------------------
  8871. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8872. {
  8873. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  8874. {
  8875. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8876. }
  8877. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8878. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8879. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  8880. 0, NULL, NULL);
  8881. }
  8882. //---------------------------------------------------------------------------
  8883. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8884. {
  8885. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8886. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8887. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8888. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  8889. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8890. }
  8891. //---------------------------------------------------------------------------
  8892. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8893. {
  8894. WinConfiguration->FormatSizeBytes = Style;
  8895. }
  8896. //---------------------------------------------------------------------------
  8897. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8898. {
  8899. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8900. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8901. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8902. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8903. }
  8904. //---------------------------------------------------------------------------
  8905. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8906. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8907. {
  8908. if (Panel->Index == 0)
  8909. {
  8910. if (FOnNoteClick != NULL)
  8911. {
  8912. // prevent the user data from being freed by possible call
  8913. // to CancelNote or PostNote during call to OnNoteClick
  8914. std::unique_ptr<TObject> NoteData(FNoteData);
  8915. TNotifyEvent OnNoteClick = FOnNoteClick;
  8916. FNoteData = NULL;
  8917. // need to cancel the note as we are going to delete its user data
  8918. CancelNote(true);
  8919. OnNoteClick(NoteData.get());
  8920. }
  8921. }
  8922. if (HasActiveTerminal() &&
  8923. (Panel->Index >= Sender->Panels->Count - SessionPanelCount))
  8924. {
  8925. FileSystemInfo();
  8926. }
  8927. }
  8928. //---------------------------------------------------------------------------
  8929. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8930. {
  8931. // workaround:
  8932. // 1) for unknown reason, disabling window, while minimized,
  8933. // prevents it from restoring, even if it was enabled again meanwhile
  8934. // 2) when disabling the main window, while another has focus
  8935. // minimize is no longer possible
  8936. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8937. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8938. // Shouldn't we use IsApplicationMinimized() here?
  8939. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8940. {
  8941. Enabled = false;
  8942. }
  8943. FLockLevel++;
  8944. }
  8945. //---------------------------------------------------------------------------
  8946. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8947. {
  8948. DebugAssert(FLockLevel > 0);
  8949. FLockLevel--;
  8950. if (FLockLevel == 0)
  8951. {
  8952. DebugAssert(FLockSuspendLevel == 0);
  8953. Enabled = true;
  8954. }
  8955. }
  8956. //---------------------------------------------------------------------------
  8957. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8958. {
  8959. // We need to make sure that window is enabled when the last modal window closes
  8960. // otherwise focus is not restored correctly.
  8961. // So we re-enable the window when modal window opens and
  8962. // disable it back after is closes
  8963. if (FLockLevel > 0)
  8964. {
  8965. // while we have nesting counter, we know that we never be called
  8966. // recursivelly as Application->OnModalBegin is called only
  8967. // for the top-level modal window
  8968. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8969. {
  8970. // won't be disabled when conditions in LockWindow() were not satisfied
  8971. FDisabledOnLockSuspend = !Enabled;
  8972. // When minimized to tray (or actually when set to SW_HIDE),
  8973. // setting Enabled makes the window focusable even when there's
  8974. // modal window over it
  8975. if (!FTrayIcon->Visible)
  8976. {
  8977. Enabled = true;
  8978. }
  8979. }
  8980. FLockSuspendLevel++;
  8981. }
  8982. }
  8983. //---------------------------------------------------------------------------
  8984. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8985. {
  8986. if (FLockSuspendLevel > 0)
  8987. {
  8988. DebugAssert(FLockLevel > 0);
  8989. FLockSuspendLevel--;
  8990. // see comment in SuspendWindowLock
  8991. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8992. {
  8993. // Note that window can be enabled here, when we were minized to tray when
  8994. // was SuspendWindowLock() called.
  8995. // We should possibly do the same check as in LockWindow(),
  8996. // if it is ever possible that the consitions change between
  8997. // SuspendWindowLock() and ResumeWindowLock()
  8998. Enabled = !FDisabledOnLockSuspend;
  8999. }
  9000. }
  9001. }
  9002. //---------------------------------------------------------------------------
  9003. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9004. {
  9005. TTBXComboBoxItem * RemotePathComboBox =
  9006. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9007. if (!TextOnly)
  9008. {
  9009. TStrings * Items = RemotePathComboBox->Strings;
  9010. Items->BeginUpdate();
  9011. try
  9012. {
  9013. Items->Clear();
  9014. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9015. {
  9016. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9017. while (!IsUnixRootPath(APath))
  9018. {
  9019. int P = APath.LastDelimiter(L'/');
  9020. DebugAssert(P >= 0);
  9021. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9022. APath.SetLength(P - 1);
  9023. }
  9024. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9025. }
  9026. }
  9027. __finally
  9028. {
  9029. Items->EndUpdate();
  9030. }
  9031. }
  9032. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9033. // Setting ItemIndex to -1 does not reset its text
  9034. if (RemotePathComboBox->Strings->Count == 0)
  9035. {
  9036. RemotePathComboBox->Text = L"";
  9037. }
  9038. }
  9039. //---------------------------------------------------------------------------
  9040. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9041. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9042. {
  9043. if (AIndex < 0)
  9044. {
  9045. AIndex = Sender->ItemIndex;
  9046. }
  9047. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9048. }
  9049. //---------------------------------------------------------------------------
  9050. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9051. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9052. int & ImageIndex)
  9053. {
  9054. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9055. }
  9056. //---------------------------------------------------------------------------
  9057. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9058. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9059. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9060. {
  9061. if (!IsLocalBrowserMode())
  9062. {
  9063. ARect.Left += (10 * AIndex);
  9064. }
  9065. }
  9066. //---------------------------------------------------------------------------
  9067. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9068. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9069. {
  9070. AWidth += (10 * AIndex);
  9071. }
  9072. //---------------------------------------------------------------------------
  9073. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9074. {
  9075. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9076. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9077. int Index = RemotePathComboBox->ItemIndex;
  9078. while (Index < RemotePathComboBox->Strings->Count - 1)
  9079. {
  9080. APath = UnixExtractFileDir(APath);
  9081. Index++;
  9082. }
  9083. // VanDyke style paths
  9084. if (APath.IsEmpty())
  9085. {
  9086. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9087. APath = ROOTDIRECTORY;
  9088. }
  9089. if (RemoteDirView->Path != APath)
  9090. {
  9091. RemoteDirView->Path = APath;
  9092. }
  9093. }
  9094. //---------------------------------------------------------------------------
  9095. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9096. {
  9097. DoRemotePathComboBoxItemClick(Sender);
  9098. }
  9099. //---------------------------------------------------------------------------
  9100. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9101. {
  9102. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9103. DebugUsedParam(Sender);
  9104. UpdateRemotePathComboBox(true);
  9105. }
  9106. //---------------------------------------------------------------------------
  9107. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9108. {
  9109. DoRemotePathComboBoxCancel(Sender);
  9110. }
  9111. //---------------------------------------------------------------------------
  9112. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9113. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9114. {
  9115. ResetIncrementalSearch();
  9116. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9117. DebugAssert(DirView != NULL);
  9118. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9119. {
  9120. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9121. // OnEditing is called also from TCustomListView::CanEdit
  9122. if (Edit != NULL)
  9123. {
  9124. EditSelectBaseName(Edit);
  9125. }
  9126. }
  9127. }
  9128. //---------------------------------------------------------------------------
  9129. //---------------------------------------------------------------------------
  9130. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9131. {
  9132. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9133. Result->AutoDetectDnD = false;
  9134. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9135. Result->RenderDataOn = rdoEnterAndDropSync;
  9136. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9137. return Result;
  9138. }
  9139. //---------------------------------------------------------------------------
  9140. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9141. {
  9142. TForm::CreateWnd();
  9143. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9144. if (FSessionsDragDropFilesEx == NULL)
  9145. {
  9146. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9147. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9148. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9149. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9150. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9151. }
  9152. if (FQueueDragDropFilesEx == NULL)
  9153. {
  9154. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9155. // No need to set OnDragOver as we do not have any restrictions
  9156. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9157. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9158. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9159. }
  9160. }
  9161. //---------------------------------------------------------------------------
  9162. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9163. {
  9164. TForm::DestroyWnd();
  9165. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9166. FQueueDragDropFilesEx->DragDropControl = NULL;
  9167. }
  9168. //---------------------------------------------------------------------------
  9169. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9170. {
  9171. SideEnter(FCurrentSide);
  9172. FEverShown = true;
  9173. }
  9174. //---------------------------------------------------------------------------
  9175. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9176. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9177. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9178. {
  9179. if (!NonVisualDataModule->Busy)
  9180. {
  9181. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9182. Configuration->Usage->Inc(L"FileFinds");
  9183. LockWindow(true);
  9184. NonVisualDataModule->StartBusy();
  9185. WinConfiguration->LockedInterface = true;
  9186. try
  9187. {
  9188. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9189. }
  9190. __finally
  9191. {
  9192. WinConfiguration->LockedInterface = false;
  9193. NonVisualDataModule->EndBusy();
  9194. UnlockWindow();
  9195. }
  9196. }
  9197. }
  9198. //---------------------------------------------------------------------------
  9199. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9200. {
  9201. if (!NonVisualDataModule->Busy)
  9202. {
  9203. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9204. SetFocus();
  9205. RemoteDirView->Path = UnixExtractFilePath(Path);
  9206. UnicodeString FileName = UnixExtractFileName(Path);
  9207. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9208. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9209. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9210. if (Item == NULL)
  9211. {
  9212. ReloadDirectory(osRemote);
  9213. Item = RemoteDirView->FindFileItem(FileName);
  9214. }
  9215. if (Item != NULL)
  9216. {
  9217. RemoteDirView->ItemFocused = Item;
  9218. RemoteDirView->ItemFocused->MakeVisible(false);
  9219. RemoteDirView->SetFocus();
  9220. }
  9221. }
  9222. }
  9223. //---------------------------------------------------------------------------
  9224. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9225. {
  9226. bool Result = !NonVisualDataModule->Busy;
  9227. if (Result)
  9228. {
  9229. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9230. }
  9231. return Result;
  9232. }
  9233. //---------------------------------------------------------------------------
  9234. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9235. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9236. {
  9237. if (CanOperateOnFoundFiles(ATerminal))
  9238. {
  9239. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9240. FOnFileOperationFinished = OnFileOperationFinished;
  9241. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9242. }
  9243. }
  9244. //---------------------------------------------------------------------------
  9245. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9246. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9247. {
  9248. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9249. }
  9250. //---------------------------------------------------------------------------
  9251. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9252. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9253. {
  9254. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9255. }
  9256. //---------------------------------------------------------------------------
  9257. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9258. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9259. {
  9260. if (CanOperateOnFoundFiles(ATerminal))
  9261. {
  9262. for (int Index = 0; Index < FileList->Count; Index++)
  9263. {
  9264. UnicodeString FileName = FileList->Strings[Index];
  9265. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9266. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9267. OnFileOperationFinished(FileName, true);
  9268. }
  9269. }
  9270. }
  9271. //---------------------------------------------------------------------------
  9272. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9273. {
  9274. FFileFindTerminal = Terminal;
  9275. ShowFileFindDialog(
  9276. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9277. DoDownloadFoundFiles, DoEditFoundFiles);
  9278. }
  9279. //---------------------------------------------------------------------------
  9280. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9281. {
  9282. FTaskbarList = TaskbarList;
  9283. }
  9284. //---------------------------------------------------------------------------
  9285. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9286. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9287. {
  9288. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9289. if (Index >= 0)
  9290. {
  9291. if (Button == mbLeft)
  9292. {
  9293. // "Mouse down" is raised only after tab is switched.
  9294. // If switching tab (switching session) takes long enough for user
  9295. // to actually release the button, "mouse down" is still raised,
  9296. // but we do not get "mouse up" event, so dragging is not cancelled,
  9297. // prevent that by not beginning dragging in the first place.
  9298. if (IsKeyPressed(VK_LBUTTON))
  9299. {
  9300. // when user clicks the "+", we get mouse down only after the session
  9301. // is closed, when new session tab is already on X:Y, so dragging
  9302. // starts, prevent that
  9303. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9304. {
  9305. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9306. if (Terminal != NULL)
  9307. {
  9308. SessionsPageControl->BeginDrag(false);
  9309. }
  9310. }
  9311. }
  9312. }
  9313. else if (Button == mbMiddle)
  9314. {
  9315. // ignore middle-click for "New session tab"
  9316. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9317. if (Terminal != NULL)
  9318. {
  9319. CloseSessionTab(Index);
  9320. }
  9321. }
  9322. }
  9323. }
  9324. //---------------------------------------------------------------------------
  9325. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9326. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9327. {
  9328. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9329. // do not allow dropping on the "+" tab
  9330. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9331. if ((TargetTerminal != NULL) &&
  9332. (SessionsPageControl->ActivePage->PageIndex != Index))
  9333. {
  9334. Configuration->Usage->Inc(L"SessionTabMoves");
  9335. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9336. // but we want to actually prevent that to avoid flicker
  9337. SessionsPageControl->ActivePage->PageIndex = Index;
  9338. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9339. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9340. }
  9341. }
  9342. //---------------------------------------------------------------------------
  9343. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9344. TObject * Sender, TObject * Source, int X, int Y,
  9345. TDragState /*State*/, bool & Accept)
  9346. {
  9347. Accept = (Sender == Source);
  9348. if (Accept)
  9349. {
  9350. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9351. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9352. // do not allow dragging to the "+" tab
  9353. Accept = (Terminal != NULL);
  9354. }
  9355. }
  9356. //---------------------------------------------------------------------------
  9357. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9358. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9359. {
  9360. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9361. if (Index < 0)
  9362. {
  9363. Effect = DROPEFFECT_NONE;
  9364. }
  9365. else
  9366. {
  9367. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9368. // do not allow dropping on the "+" tab
  9369. if (TargetTerminal == NULL)
  9370. {
  9371. Effect = DROPEFFECT_NONE;
  9372. }
  9373. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9374. {
  9375. Effect = DROPEFFECT_COPY;
  9376. }
  9377. }
  9378. }
  9379. //---------------------------------------------------------------------------
  9380. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9381. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9382. {
  9383. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9384. // do not allow dropping on the "+" tab
  9385. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9386. if (TargetTerminal != NULL)
  9387. {
  9388. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9389. if (!IsFileControl(DropSourceControl, osRemote))
  9390. {
  9391. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9392. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9393. // Why don't we use Terminal->CurrentDirectory directly?
  9394. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9395. // do not force queue, drag drop
  9396. false, true);
  9397. }
  9398. }
  9399. }
  9400. //---------------------------------------------------------------------------
  9401. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9402. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9403. {
  9404. // Downloads are handled in RemoteFileControlDDEnd
  9405. if (!IsFileControl(DropSourceControl, osRemote))
  9406. {
  9407. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9408. Terminal->CurrentDirectory,
  9409. // force queue, drag drop
  9410. true, true);
  9411. }
  9412. }
  9413. //---------------------------------------------------------------------------
  9414. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9415. {
  9416. FShowing = false;
  9417. // Do not save empty workspace
  9418. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9419. {
  9420. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9421. UnicodeString Name = WorkspaceName();
  9422. DoSaveWorkspace(
  9423. Name, DataList.get(),
  9424. !Configuration->DisablePasswordStoring &&
  9425. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9426. WinConfiguration->LastStoredSession = Name;
  9427. }
  9428. }
  9429. //---------------------------------------------------------------------------
  9430. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9431. {
  9432. TManagedTerminal * ManagedTerminal =
  9433. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9434. if (ManagedTerminal != NULL)
  9435. {
  9436. ManagedTerminal->DirectoryLoaded = Now();
  9437. }
  9438. }
  9439. //---------------------------------------------------------------------------
  9440. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9441. TListItem * /*Item*/, bool /*Selected*/)
  9442. {
  9443. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9444. switch (DirView->LastSelectMethod)
  9445. {
  9446. case smKeyboard:
  9447. Configuration->Usage->Inc(L"KeyboardSelections");
  9448. break;
  9449. case smMouse:
  9450. Configuration->Usage->Inc(L"MouseSelections");
  9451. break;
  9452. }
  9453. }
  9454. //---------------------------------------------------------------------------
  9455. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9456. {
  9457. if (Color != 0)
  9458. {
  9459. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9460. }
  9461. else
  9462. {
  9463. return FSessionTabImageIndex;
  9464. }
  9465. }
  9466. //---------------------------------------------------------------------------
  9467. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9468. {
  9469. TPngImageCollectionItem * Item =
  9470. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9471. FSessionColors->AddPng(Item->PngImage);
  9472. return FSessionColors->Count - 1;
  9473. }
  9474. //---------------------------------------------------------------------------
  9475. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9476. {
  9477. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9478. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9479. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9480. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9481. }
  9482. //---------------------------------------------------------------------------
  9483. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9484. {
  9485. for (int Index = 0; Index < Control->ControlCount; Index++)
  9486. {
  9487. TControl * AControl = Control->Controls[Index];
  9488. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9489. if (WinControl != NULL)
  9490. {
  9491. CollectItemsWithTextDisplayMode(WinControl);
  9492. }
  9493. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9494. if (Toolbar != NULL)
  9495. {
  9496. // we care for top-level items only
  9497. TTBCustomItem * Items = Toolbar->Items;
  9498. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9499. {
  9500. TTBCustomItem * Item = Items->Items[ItemIndex];
  9501. if (((Item->DisplayMode == nbdmImageAndText) ||
  9502. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9503. EligibleForImageDisplayMode(Item))
  9504. {
  9505. FItemsWithTextDisplayMode.insert(Item);
  9506. }
  9507. }
  9508. }
  9509. }
  9510. }
  9511. //---------------------------------------------------------------------------
  9512. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9513. {
  9514. return true;
  9515. }
  9516. //---------------------------------------------------------------------------
  9517. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9518. {
  9519. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9520. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9521. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9522. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9523. bool Result = true;
  9524. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9525. {
  9526. TTBCustomItem * Item = *i;
  9527. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9528. if (Label != NULL)
  9529. {
  9530. // optimization
  9531. if (Label->Visible == SelectiveToolbarText)
  9532. {
  9533. Result = false;
  9534. }
  9535. else
  9536. {
  9537. Label->Visible = SelectiveToolbarText;
  9538. }
  9539. }
  9540. else
  9541. {
  9542. // optimization
  9543. if (Item->DisplayMode == DisplayMode)
  9544. {
  9545. Result = false;
  9546. }
  9547. else
  9548. {
  9549. Item->DisplayMode = DisplayMode;
  9550. }
  9551. }
  9552. ++i;
  9553. }
  9554. if (Result)
  9555. {
  9556. UpdateNewSessionTab();
  9557. }
  9558. return Result;
  9559. }
  9560. //---------------------------------------------------------------------------
  9561. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9562. {
  9563. DebugFail();
  9564. }
  9565. //---------------------------------------------------------------------------
  9566. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9567. {
  9568. // Among other, a lock level is non zero, while directory is being loaded,
  9569. // even when it happens as a result of dirview navigation,
  9570. // i.e. when TNonVisualDataModule is NOT FBusy.
  9571. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9572. // Among other this prevents a panel auto update to occur while
  9573. // directory is changing.
  9574. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9575. }
  9576. //---------------------------------------------------------------------------
  9577. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  9578. {
  9579. // While the window is disabled, we still seem to process menu shortcuts at least,
  9580. // so stop it at least here.
  9581. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9582. bool Result;
  9583. if (Allowed == aaUpdate)
  9584. {
  9585. Result = true;
  9586. }
  9587. else
  9588. {
  9589. Result = !NonVisualDataModule->Busy;
  9590. if (Result && (Allowed == aaShortCut))
  9591. {
  9592. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  9593. Action->Update();
  9594. Result = Action->Enabled;
  9595. }
  9596. }
  9597. return Result;
  9598. }
  9599. //---------------------------------------------------------------------------
  9600. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9601. {
  9602. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9603. }
  9604. //---------------------------------------------------------------------------
  9605. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9606. {
  9607. // This is somewhat redundant to LockWindow() call from
  9608. // TTerminalManager::TerminalReadDirectoryProgress.
  9609. // But disabling window is known not to block keyboard shorcuts
  9610. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9611. if (Busy > 0)
  9612. {
  9613. if (NonVisualDataModule->Busy)
  9614. {
  9615. State = false;
  9616. }
  9617. else
  9618. {
  9619. NonVisualDataModule->StartBusy();
  9620. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9621. LockWindow();
  9622. }
  9623. }
  9624. else if (Busy < 0)
  9625. {
  9626. UnlockWindow();
  9627. NonVisualDataModule->EndBusy();
  9628. }
  9629. else
  9630. {
  9631. State = NonVisualDataModule->Busy;
  9632. }
  9633. }
  9634. //---------------------------------------------------------------------------
  9635. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9636. {
  9637. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9638. // no context menu for "New session tab"
  9639. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9640. {
  9641. SessionsPageControl->ActivePageIndex = Index;
  9642. if (DebugAlwaysTrue(SessionTabSwitched()))
  9643. {
  9644. // copied from TControl.WMContextMenu
  9645. SendCancelMode(SessionsPageControl);
  9646. // explicit popup instead of using PopupMenu property
  9647. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9648. // while connecting yet not-connected session and hence
  9649. // allowing an access to commands over not-completelly connected session
  9650. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9651. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9652. PopupMenu->PopupComponent = SessionsPageControl;
  9653. PopupMenu->Popup(Point.x, Point.y);
  9654. }
  9655. }
  9656. Handled = true;
  9657. }
  9658. //---------------------------------------------------------------------------
  9659. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9660. {
  9661. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9662. }
  9663. //---------------------------------------------------------------------------
  9664. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9665. {
  9666. Configuration->Usage->Inc(L"PasswordChanges");
  9667. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9668. ChangePasswordData->DisableAuthentationsExceptPassword();
  9669. ChangePasswordData->ChangePassword = true;
  9670. std::unique_ptr<TTerminal> ChangePasswordSession(
  9671. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9672. ChangePasswordSession->AutoReadDirectory = false;
  9673. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9674. {
  9675. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9676. }
  9677. else
  9678. {
  9679. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9680. }
  9681. }
  9682. //---------------------------------------------------------------------------
  9683. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9684. {
  9685. // No nice way to assert SSH2
  9686. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9687. }
  9688. //---------------------------------------------------------------------------
  9689. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9690. {
  9691. TOperationVisualizer OperationVisualizer;
  9692. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9693. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9694. }
  9695. //---------------------------------------------------------------------------
  9696. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9697. {
  9698. TForm::ChangeScale(M, D);
  9699. int APixelsPerInch = GetControlPixelsPerInch(this);
  9700. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9701. try
  9702. {
  9703. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9704. }
  9705. __finally
  9706. {
  9707. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9708. }
  9709. }
  9710. //---------------------------------------------------------------------------
  9711. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9712. {
  9713. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9714. }
  9715. //---------------------------------------------------------------------
  9716. class TPublicControl : public TControl
  9717. {
  9718. friend class TCustomScpExplorerForm;
  9719. };
  9720. //---------------------------------------------------------------------------
  9721. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9722. {
  9723. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9724. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9725. }
  9726. //---------------------------------------------------------------------------
  9727. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9728. {
  9729. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9730. OpenBookmark(Side, Bookmark);
  9731. }
  9732. //---------------------------------------------------------------------------
  9733. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9734. {
  9735. DoBookmarkClick(osLocal, Sender);
  9736. }
  9737. //---------------------------------------------------------------------------
  9738. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9739. {
  9740. DoBookmarkClick(osRemote, Sender);
  9741. }
  9742. //---------------------------------------------------------------------------
  9743. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9744. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9745. {
  9746. if (BookmarkList != NULL)
  9747. {
  9748. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9749. if (IsLocalBrowserMode())
  9750. {
  9751. Side = osLocal;
  9752. }
  9753. if (!WinConfiguration->UseLocationProfiles)
  9754. {
  9755. std::unique_ptr<TStringList> Directories(new TStringList());
  9756. Directories->CaseSensitive = (Side == osRemote);
  9757. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9758. {
  9759. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9760. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9761. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9762. {
  9763. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9764. Item->Caption = EscapeHotkey(Directory);
  9765. Item->ShortCut = Bookmark->ShortCut;
  9766. Item->OnClick = OnBookmarkClick;
  9767. Item->Tag = reinterpret_cast<int>(Bookmark);
  9768. Directories->Add(Directory);
  9769. Menu->Add(Item.release());
  9770. }
  9771. }
  9772. }
  9773. else
  9774. {
  9775. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9776. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9777. {
  9778. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9779. if (!Bookmark->Node.IsEmpty())
  9780. {
  9781. Folders->Add(Bookmark->Node);
  9782. }
  9783. }
  9784. for (int Index = 0; Index < Folders->Count; Index++)
  9785. {
  9786. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9787. Item->Caption = Folders->Strings[Index];
  9788. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  9789. Folders->Objects[Index] = Item.get();
  9790. Menu->Add(Item.release());
  9791. }
  9792. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9793. {
  9794. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9795. TTBCustomItem * Parent;
  9796. if (!Bookmark->Node.IsEmpty())
  9797. {
  9798. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9799. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9800. }
  9801. else
  9802. {
  9803. Parent = Menu;
  9804. }
  9805. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9806. Item->Caption = Bookmark->Name;
  9807. Item->ShortCut = Bookmark->ShortCut;
  9808. Item->OnClick = OnBookmarkClick;
  9809. Item->Tag = reinterpret_cast<int>(Bookmark);
  9810. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9811. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9812. {
  9813. // No hint for location profiles that are actually mere "bookmarks"
  9814. }
  9815. else
  9816. {
  9817. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9818. UnicodeString LongHint;
  9819. if (!Bookmark->Local.IsEmpty())
  9820. {
  9821. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9822. }
  9823. if (!Bookmark->Remote.IsEmpty())
  9824. {
  9825. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9826. }
  9827. AddToList(Hint, LongHint, L"|");
  9828. Item->Hint = Hint;
  9829. }
  9830. Parent->Add(Item.release());
  9831. }
  9832. }
  9833. AddMenuSeparator(Menu);
  9834. }
  9835. }
  9836. //---------------------------------------------------------------------------
  9837. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9838. {
  9839. Menu->Clear();
  9840. std::unique_ptr<TTBCustomItem> Item;
  9841. Item.reset(new TTBXItem(Owner));
  9842. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9843. Item->Options = Item->Options << tboDefault;
  9844. Menu->Add(Item.release());
  9845. AddMenuSeparator(Menu);
  9846. if (Terminal != NULL)
  9847. {
  9848. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9849. }
  9850. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9851. Item.reset(new TTBXItem(Owner));
  9852. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  9853. Menu->Add(Item.release());
  9854. }
  9855. //---------------------------------------------------------------------------
  9856. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9857. {
  9858. bool Result = true;
  9859. bool Remote = !IsSideLocalBrowser(Side);
  9860. try
  9861. {
  9862. if (Remote)
  9863. {
  9864. Terminal->ExceptionOnFail = true;
  9865. }
  9866. try
  9867. {
  9868. DirView(Side)->Path = Path;
  9869. }
  9870. __finally
  9871. {
  9872. if (Remote)
  9873. {
  9874. Terminal->ExceptionOnFail = false;
  9875. }
  9876. }
  9877. }
  9878. catch (Exception & E)
  9879. {
  9880. if (!Remote || Terminal->Active)
  9881. {
  9882. ShowExtendedExceptionEx(Terminal, &E);
  9883. Result = false;
  9884. }
  9885. else
  9886. {
  9887. throw;
  9888. }
  9889. }
  9890. return Result;
  9891. }
  9892. //---------------------------------------------------------------------------
  9893. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9894. {
  9895. // Make sure there some feedback even when loading tiny local folders
  9896. TInstantOperationVisualizer Visualizer;
  9897. DirView(Side)->ReloadDirectory();
  9898. }
  9899. //---------------------------------------------------------------------------
  9900. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9901. {
  9902. if (Index == SessionsPageControl->TabIndex)
  9903. {
  9904. CloseSession();
  9905. }
  9906. else
  9907. {
  9908. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9909. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9910. TTerminalManager * Manager = TTerminalManager::Instance();
  9911. if (!Terminal->Active)
  9912. {
  9913. Manager->FreeTerminal(Terminal);
  9914. }
  9915. else
  9916. {
  9917. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9918. if (CanCloseQueue(Queue))
  9919. {
  9920. Manager->FreeTerminal(Terminal);
  9921. }
  9922. }
  9923. }
  9924. }
  9925. //---------------------------------------------------------------------------
  9926. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9927. {
  9928. CloseSessionTab(Index);
  9929. }
  9930. //---------------------------------------------------------------------------
  9931. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9932. {
  9933. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9934. {
  9935. TInstantOperationVisualizer Visualizer;
  9936. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9937. // before we create a new data object
  9938. ClipboardClear();
  9939. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9940. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9941. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9942. // Intermediate variable to WORKAROUND a crash in compiler
  9943. TObjectList * ClipboardFakeMonitors =
  9944. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9945. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9946. if (FClipboardDragDropFilesEx.get() == NULL)
  9947. {
  9948. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9949. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9950. }
  9951. FClipboardDragDropFilesEx->FileList->Clear();
  9952. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9953. FClipboardDragDropFilesEx->CopyToClipboard();
  9954. FClipboardTerminal = FTerminal;
  9955. // Need full paths, as cwd can be different once files are pasted
  9956. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9957. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9958. {
  9959. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9960. }
  9961. }
  9962. }
  9963. //---------------------------------------------------------------------------
  9964. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9965. {
  9966. if (OpenClipboard(0))
  9967. {
  9968. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9969. CloseClipboard();
  9970. }
  9971. }
  9972. //---------------------------------------------------------------------------
  9973. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9974. {
  9975. return !FClipboardFakeDirectory.IsEmpty();
  9976. }
  9977. //---------------------------------------------------------------------------
  9978. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9979. {
  9980. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9981. FClipboardFakeDirectory = UnicodeString();
  9982. FClipboardTerminal = NULL;
  9983. // Also called in Idle()
  9984. FClipboardFakeMonitors.reset(NULL);
  9985. }
  9986. //---------------------------------------------------------------------------
  9987. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9988. {
  9989. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9990. {
  9991. ClipboardStop();
  9992. }
  9993. }
  9994. //---------------------------------------------------------------------------
  9995. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9996. {
  9997. TTerminalManager * Manager = TTerminalManager::Instance();
  9998. Manager->ActiveTerminal = FClipboardTerminal;
  9999. TTransferOperationParam Params;
  10000. Params.TargetDirectory = TargetDirectory;
  10001. Params.DragDrop = DragDrop;
  10002. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  10003. }
  10004. //---------------------------------------------------------------------------
  10005. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  10006. {
  10007. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  10008. // (as it pumps a Windows message queue while being shutted down)
  10009. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10010. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10011. {
  10012. // Can fail as it can be e.g. locked by AV, so we retry that later
  10013. bool Removed = RemoveDir(ApiPath(FileName));
  10014. try
  10015. {
  10016. if (!NonVisualDataModule->Busy)
  10017. {
  10018. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10019. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  10020. }
  10021. }
  10022. __finally
  10023. {
  10024. if (!Removed)
  10025. {
  10026. RemoveDir(ApiPath(FileName));
  10027. }
  10028. }
  10029. }
  10030. }
  10031. //---------------------------------------------------------------------------
  10032. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10033. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10034. {
  10035. TFileMasks::TParams MaskParams;
  10036. MaskParams.Size = Size;
  10037. MaskParams.Modification = Modification;
  10038. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10039. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10040. {
  10041. bool ImplicitMatch;
  10042. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  10043. !ImplicitMatch)
  10044. {
  10045. Color = Iter->Color;
  10046. break;
  10047. }
  10048. }
  10049. }
  10050. //---------------------------------------------------------------------------
  10051. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10052. {
  10053. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10054. if (!DirView->IsEditing())
  10055. {
  10056. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10057. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10058. // while searching
  10059. if (Key == VK_BACK)
  10060. {
  10061. if (!FIncrementalSearch.IsEmpty())
  10062. {
  10063. if (FIncrementalSearch.Length() == 1)
  10064. {
  10065. ResetIncrementalSearch();
  10066. }
  10067. else
  10068. {
  10069. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10070. IncrementalSearch(NewText, false, false);
  10071. }
  10072. Key = 0;
  10073. }
  10074. }
  10075. }
  10076. }
  10077. //---------------------------------------------------------------------------
  10078. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10079. {
  10080. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10081. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10082. {
  10083. // Filter control sequences.
  10084. // When not searching yet, prefer use of the space for toggling file selection
  10085. // (so we cannot incrementally search for a string starting with a space).
  10086. if ((Key > VK_SPACE) ||
  10087. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10088. {
  10089. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10090. Key = 0;
  10091. }
  10092. }
  10093. }
  10094. //---------------------------------------------------------------------------
  10095. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10096. {
  10097. if (!FIncrementalSearch.IsEmpty())
  10098. {
  10099. FIncrementalSearch = L"";
  10100. DirView(osCurrent)->UpdateStatusBar();
  10101. }
  10102. }
  10103. //---------------------------------------------------------------------------
  10104. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10105. {
  10106. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10107. if (Item == NULL)
  10108. {
  10109. MessageBeep(MB_ICONHAND);
  10110. }
  10111. else
  10112. {
  10113. TCustomDirView * ADirView = DirView(osCurrent);
  10114. {
  10115. TAutoNestingCounter Guard(FIncrementalSearching);
  10116. ADirView->FocusItem(Item);
  10117. if (ADirView->NortonLike == nlOff)
  10118. {
  10119. if ((ADirView->Selected != Item) ||
  10120. (ADirView->SelCount > 1))
  10121. {
  10122. ADirView->ClearSelection();
  10123. ADirView->Selected = Item;
  10124. }
  10125. }
  10126. }
  10127. FIncrementalSearch = Text;
  10128. Item->MakeVisible(false);
  10129. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10130. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10131. ADirView->UpdateStatusBar();
  10132. }
  10133. }
  10134. //---------------------------------------------------------------------------
  10135. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10136. {
  10137. int Index = Item->Index;
  10138. if (!Reverse)
  10139. {
  10140. Index++;
  10141. if (Index >= Item->Owner->Count)
  10142. {
  10143. Index = 0;
  10144. }
  10145. }
  10146. else
  10147. {
  10148. Index--;
  10149. if (Index < 0)
  10150. {
  10151. Index = Item->Owner->Count - 1;
  10152. }
  10153. }
  10154. return Item->Owner->Item[Index];
  10155. }
  10156. //---------------------------------------------------------------------------
  10157. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10158. {
  10159. TCustomDirView * ADirView = DirView(osCurrent);
  10160. if (ADirView->Items->Count == 0)
  10161. {
  10162. return NULL;
  10163. }
  10164. else
  10165. {
  10166. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10167. TListItem * Item = CurrentItem;
  10168. if (SkipCurrent)
  10169. {
  10170. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10171. }
  10172. while (true)
  10173. {
  10174. bool Matches = false;
  10175. switch (WinConfiguration->PanelSearch)
  10176. {
  10177. case isNameStartOnly:
  10178. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10179. break;
  10180. case isName:
  10181. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10182. break;
  10183. case isAll:
  10184. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10185. int Index = 0;
  10186. while ((Index < ColCount) && !Matches)
  10187. {
  10188. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10189. if (Visible)
  10190. {
  10191. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10192. }
  10193. Index++;
  10194. }
  10195. break;
  10196. }
  10197. if (Matches)
  10198. {
  10199. return Item;
  10200. }
  10201. Item = GetNextFile(Item, Reverse);
  10202. if (Item == CurrentItem)
  10203. {
  10204. return NULL;
  10205. }
  10206. }
  10207. }
  10208. }
  10209. //---------------------------------------------------------------------------
  10210. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10211. {
  10212. ResetIncrementalSearch();
  10213. }
  10214. //---------------------------------------------------------------------------
  10215. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10216. {
  10217. if (Message.CharCode == VK_TAB)
  10218. {
  10219. if (!FIncrementalSearch.IsEmpty())
  10220. {
  10221. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10222. bool Reverse = Shift.Contains(ssShift);
  10223. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10224. Message.Result = 1;
  10225. return;
  10226. }
  10227. }
  10228. else if (Message.CharCode == VK_ESCAPE)
  10229. {
  10230. if (!FIncrementalSearch.IsEmpty())
  10231. {
  10232. ResetIncrementalSearch();
  10233. Message.Result = 1;
  10234. return;
  10235. }
  10236. }
  10237. TForm::Dispatch(&Message);
  10238. }
  10239. //---------------------------------------------------------------------------
  10240. void __fastcall TCustomScpExplorerForm::Deactivate()
  10241. {
  10242. TForm::Deactivate();
  10243. // E.g. when switching to an internal editor window
  10244. ResetIncrementalSearch();
  10245. }
  10246. //---------------------------------------------------------------------------
  10247. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10248. {
  10249. // When switching to another application
  10250. ResetIncrementalSearch();
  10251. }
  10252. //---------------------------------------------------------------------------
  10253. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10254. {
  10255. ResetIncrementalSearch();
  10256. }
  10257. //---------------------------------------------------------------------------
  10258. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10259. {
  10260. if (FIncrementalSearching <= 0)
  10261. {
  10262. ResetIncrementalSearch();
  10263. }
  10264. }
  10265. //---------------------------------------------------------------------------
  10266. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10267. {
  10268. CountClicksForWindowPrint(this);
  10269. }
  10270. //---------------------------------------------------------------------------
  10271. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10272. {
  10273. CenterReconnectToolbar();
  10274. }
  10275. //---------------------------------------------------------------------------
  10276. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10277. {
  10278. if (RemoteDirView->ItemFocused != NULL)
  10279. {
  10280. RemoteDirView->ItemFocused->Selected = true;
  10281. }
  10282. }
  10283. //---------------------------------------------------------------------------
  10284. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10285. {
  10286. if (!FQueueStatusUpdating)
  10287. {
  10288. bool Refresh;
  10289. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10290. {
  10291. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10292. }
  10293. else
  10294. {
  10295. if (FQueueFileList->GetCount() > 0)
  10296. {
  10297. FQueueFileList->Clear();
  10298. Refresh = true;
  10299. }
  10300. }
  10301. int Count = FQueueFileList->GetCount();
  10302. if (QueueFileList->Items->Count != Count)
  10303. {
  10304. DebugAssert(Refresh);
  10305. QueueFileList->Items->Count = Count;
  10306. }
  10307. if (Refresh)
  10308. {
  10309. QueueFileList->Invalidate();
  10310. }
  10311. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10312. }
  10313. }
  10314. //---------------------------------------------------------------------------
  10315. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10316. {
  10317. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10318. }
  10319. //---------------------------------------------------------------------------
  10320. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10321. {
  10322. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10323. // See TSynchronizeChecklistDialog::UpdateTimer
  10324. if (QueueFileList->Items->Count > 0)
  10325. {
  10326. QueueFileList->Items->Item[0]->MakeVisible(false);
  10327. }
  10328. UpdateQueueFileList();
  10329. }
  10330. //---------------------------------------------------------------------------
  10331. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10332. {
  10333. Active = QueueView3->Focused() || QueueFileList->Focused();
  10334. }
  10335. //---------------------------------------------------------------------------
  10336. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10337. {
  10338. QueueLabelUpdateStatus();
  10339. }
  10340. //---------------------------------------------------------------------------
  10341. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10342. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10343. {
  10344. int State = FQueueFileList->GetState(Item->Index);
  10345. if (State == qfsProcessed)
  10346. {
  10347. Sender->Canvas->Font->Color = clGrayText;
  10348. }
  10349. }
  10350. //---------------------------------------------------------------------------
  10351. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10352. {
  10353. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10354. QueueFileList->Column[0]->Width =
  10355. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10356. }
  10357. //---------------------------------------------------------------------------
  10358. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10359. {
  10360. QueueFileListColumnAutoSize();
  10361. }
  10362. //---------------------------------------------------------------------------
  10363. void __fastcall TCustomScpExplorerForm::CloseApp()
  10364. {
  10365. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10366. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10367. // So we clear the flag here.
  10368. DebugAssert(NonVisualDataModule->Busy);
  10369. NonVisualDataModule->EndBusy();
  10370. try
  10371. {
  10372. Close();
  10373. }
  10374. __finally
  10375. {
  10376. NonVisualDataModule->StartBusy();
  10377. }
  10378. }
  10379. //---------------------------------------------------------------------------
  10380. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10381. {
  10382. return (Terminal != NULL) && Terminal->Active;
  10383. }
  10384. //---------------------------------------------------------------------------
  10385. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10386. {
  10387. return IsActiveTerminal(Terminal);
  10388. }
  10389. //---------------------------------------------------------------------------
  10390. void TCustomScpExplorerForm::LocalLocalCopy(
  10391. TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused), bool DebugUsedArg(NoConfirmation))
  10392. {
  10393. DebugFail();
  10394. }