CustomScpExplorer.cpp 363 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039
  1. //---------------------------------------------------------------------------
  2. #define NO_WIN32_LEAN_AND_MEAN
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <Common.h>
  6. #include "CustomScpExplorer.h"
  7. #include <Bookmarks.h>
  8. #include <Interface.h>
  9. #include <Exceptions.h>
  10. #include <CoreMain.h>
  11. #include <FileSystems.h>
  12. #include <TextsCore.h>
  13. #include <TextsWin.h>
  14. #include <HelpWin.h>
  15. #include <VCLCommon.h>
  16. #include <Progress.h>
  17. #include <SynchronizeProgress.h>
  18. #include <DragExt.h>
  19. #include <WinApi.h>
  20. #include "GUITools.h"
  21. #include "NonVisual.h"
  22. #include "Glyphs.h"
  23. #include "Tools.h"
  24. #include "WinConfiguration.h"
  25. #include "TerminalManager.h"
  26. #include "EditorManager.h"
  27. #include "ProgParams.h"
  28. #include "Setup.h"
  29. #include <Consts.hpp>
  30. #include <DateUtils.hpp>
  31. #include <TB2Common.hpp>
  32. #include <DirectoryMonitor.hpp>
  33. #include <System.IOUtils.hpp>
  34. //---------------------------------------------------------------------------
  35. #pragma package(smart_init)
  36. #pragma link "CustomDirView"
  37. #pragma link "CustomUnixDirView"
  38. #pragma link "IEListView"
  39. #pragma link "NortonLikeListView"
  40. #pragma link "UnixDirView"
  41. #pragma link "CustomDriveView"
  42. #pragma link "UnixDriveView"
  43. #pragma link "CustomDriveView"
  44. #pragma link "TB2Dock"
  45. #pragma link "TBXStatusBars"
  46. #pragma link "TB2Item"
  47. #pragma link "TB2Toolbar"
  48. #pragma link "ThemePageControl"
  49. #pragma link "PathLabel"
  50. #pragma resource "*.dfm"
  51. //---------------------------------------------------------------------------
  52. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  53. static const int SessionPanelCount = 4;
  54. //---------------------------------------------------------------------------
  55. class TMutexGuard
  56. {
  57. public:
  58. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  59. int Timeout = 5000)
  60. {
  61. FMutex = NULL;
  62. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  63. if (WaitResult == WAIT_TIMEOUT)
  64. {
  65. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  66. }
  67. else
  68. {
  69. FMutex = AMutex;
  70. }
  71. }
  72. ~TMutexGuard()
  73. {
  74. if (FMutex != NULL)
  75. {
  76. ReleaseMutex(FMutex);
  77. }
  78. }
  79. private:
  80. HANDLE FMutex;
  81. };
  82. //---------------------------------------------------------------------------
  83. class TWindowLock
  84. {
  85. public:
  86. TWindowLock(TCustomScpExplorerForm * Form) :
  87. FForm(Form)
  88. {
  89. FForm->LockWindow();
  90. }
  91. ~TWindowLock()
  92. {
  93. FForm->UnlockWindow();
  94. }
  95. private:
  96. TCustomScpExplorerForm * FForm;
  97. };
  98. //---------------------------------------------------------------------------
  99. class TAutoBatch
  100. {
  101. public:
  102. TAutoBatch(TCustomScpExplorerForm * Form) :
  103. FForm(Form)
  104. {
  105. FForm->BatchStart(FBatchStorage);
  106. }
  107. ~TAutoBatch()
  108. {
  109. FForm->BatchEnd(FBatchStorage);
  110. }
  111. private:
  112. TCustomScpExplorerForm * FForm;
  113. void * FBatchStorage;
  114. };
  115. //---------------------------------------------------------------------------
  116. struct TTransferOperationParam
  117. {
  118. TTransferOperationParam();
  119. UnicodeString TargetDirectory;
  120. bool Temp;
  121. bool DragDrop;
  122. int Options;
  123. TAutoSwitch Queue;
  124. };
  125. //---------------------------------------------------------------------------
  126. TTransferOperationParam::TTransferOperationParam()
  127. {
  128. Temp = false;
  129. DragDrop = false;
  130. Options = 0;
  131. Queue = asAuto;
  132. }
  133. //---------------------------------------------------------------------------
  134. class TTransferPresetNoteData : public TObject
  135. {
  136. public:
  137. UnicodeString Message;
  138. };
  139. //---------------------------------------------------------------------------
  140. class TTerminalNoteData : public TObject
  141. {
  142. public:
  143. TManagedTerminal * Terminal;
  144. };
  145. //---------------------------------------------------------------------------
  146. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  147. FFormRestored(false),
  148. TForm(Owner)
  149. {
  150. FInvalid = false;
  151. FCurrentSide = osRemote;
  152. FEverShown = false;
  153. FDocks = new TList();
  154. InitControls();
  155. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  156. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  157. NonVisualDataModule->ScpExplorer = this;
  158. RestoreParams();
  159. ConfigurationChanged();
  160. RemoteDirView->Invalidate();
  161. FAutoOperation = false;
  162. FOnFileOperationFinished = NULL;
  163. FForceExecution = false;
  164. FIgnoreNextDialogChar = 0;
  165. FErrorList = NULL;
  166. FSynchronizeProgressForm = NULL;
  167. FProgressForm = NULL;
  168. FRefreshLocalDirectory = false;
  169. FRefreshRemoteDirectory = false;
  170. FDDExtMapFile = NULL;
  171. // CreateMutexW keeps failing with ERROR_NOACCESS
  172. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  173. DebugAssert(FDDExtMutex != NULL);
  174. FDDTargetControl = NULL;
  175. FDelayedDeletionTimer = NULL;
  176. FDelayedDeletionList = new TStringList();
  177. FDDFileList = NULL;
  178. FPendingTempSpaceWarn = false;
  179. FCapturedLog = NULL;
  180. FDragDropOperation = false;
  181. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  182. FAllowTransferPresetAutoSelect = true;
  183. FCopyParamDefault = L"";
  184. FSynchronizeController = NULL;
  185. FPendingQueueActionItem = NULL;
  186. FLockLevel = 0;
  187. FLockSuspendLevel = 0;
  188. FDisabledOnLockSuspend = false;
  189. FAlternativeDelete = false;
  190. FTrayIcon = new ::TTrayIcon(0);
  191. FTrayIcon->OnClick = TrayIconClick;
  192. FMaxQueueLength = 0;
  193. FLastContextPopupScreenPoint = TPoint(-1, -1);
  194. FTransferResumeList = NULL;
  195. FMoveToQueue = false;
  196. StandaloneOperation = false;
  197. FOnFeedSynchronizeError = NULL;
  198. FOnSynchronizeAbort = NULL;
  199. FSynchronizeTerminal = NULL;
  200. FNeedSession = false;
  201. FDoNotIdleCurrentTerminal = 0;
  202. FIncrementalSearching = 0;
  203. FIncrementalSearchHaveNext = false;
  204. FQueueFileList.reset(new TQueueFileList());
  205. FEditorManager = new TEditorManager();
  206. FEditorManager->OnFileChange = ExecutedFileChanged;
  207. FEditorManager->OnFileReload = ExecutedFileReload;
  208. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  209. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  210. FLocalEditors = new TList();
  211. FQueueStatus = NULL;
  212. FQueueStatusSection = new TCriticalSection();
  213. FQueueStatusInvalidated = false;
  214. FQueueItemInvalidated = false;
  215. FQueueStatusUpdating = false;
  216. FQueueActedItem = NULL;
  217. FQueueController = new TQueueController(QueueView3);
  218. FUserActionTimer = new TTimer(this);
  219. FUserActionTimer->Enabled = false;
  220. FUserActionTimer->Interval = 10;
  221. FUserActionTimer->OnTimer = UserActionTimer;
  222. FNotes = new TStringList();
  223. FNoteTimer = new TTimer(this);
  224. FNoteTimer->Enabled = false;
  225. FNoteTimer->OnTimer = NoteTimer;
  226. FOnNoteClick = NULL;
  227. FOle32Library = LoadLibrary(L"Ole32.dll");
  228. FDragMoveCursor = FOle32Library != NULL ?
  229. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  230. UseSystemSettings(this);
  231. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  232. static_cast<TObject*>(GetComponent(fcTransferList)));
  233. DebugAssert(TransferList != NULL);
  234. FTransferListHoverIndex = -1;
  235. TransferList->OnChange = TransferListChange;
  236. TransferList->OnDrawItem = TransferListDrawItem;
  237. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  238. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  239. UseDesktopFont(SessionsPageControl);
  240. UpdateSessionsPageControlHeight();
  241. UseDesktopFont(RemoteDirView);
  242. UseDesktopFont(RemoteDriveView);
  243. UseDesktopFont(QueueView3);
  244. UseDesktopFont(QueueFileList);
  245. UseDesktopFont(QueueLabel);
  246. UseDesktopFont(RemoteStatusBar);
  247. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  248. QueueSplitter->ShowHint = true;
  249. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  250. QueueFileListSplitter->ShowHint = true;
  251. RemotePanelSplitter->ShowHint = true;
  252. UpdateImages();
  253. FCustomCommandMenu = CreateTBXPopupMenu(this);
  254. FCustomCommandLocalFileList = NULL;
  255. FCustomCommandRemoteFileList = NULL;
  256. FSessionColors = new TPngImageList(this);
  257. FSessionColors->ColorDepth = cd32Bit;
  258. AddFixedSessionImages();
  259. SessionsPageControl->Images = FSessionColors;
  260. UpdateQueueLabel();
  261. FRemoteDirViewWasFocused = true;
  262. CreateHiddenWindow();
  263. StartUpdates();
  264. }
  265. //---------------------------------------------------------------------------
  266. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  267. {
  268. FInvalid = true;
  269. // this has to be one of the very first things to do
  270. StopUpdateThread();
  271. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  272. TTerminalManager::Instance()->ScpExplorer = NULL;
  273. delete FCustomCommandLocalFileList;
  274. delete FCustomCommandRemoteFileList;
  275. delete FCustomCommandMenu;
  276. delete FTrayIcon;
  277. FTrayIcon = NULL;
  278. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  279. delete FEditorManager;
  280. ForceCloseLocalEditors();
  281. delete FLocalEditors;
  282. HideFileFindDialog();
  283. if (FDelayedDeletionTimer)
  284. {
  285. DoDelayedDeletion(NULL);
  286. SAFE_DESTROY(FDelayedDeletionTimer);
  287. }
  288. SAFE_DESTROY(FDelayedDeletionList);
  289. // sometimes we do not get DDEnd so the list is not released
  290. SAFE_DESTROY(FDDFileList);
  291. DebugAssert(FSynchronizeController == NULL);
  292. CloseHandle(FDDExtMutex);
  293. FDDExtMutex = NULL;
  294. FreeLibrary(FOle32Library);
  295. FOle32Library = NULL;
  296. FDragMoveCursor = NULL;
  297. DebugAssert(!FErrorList);
  298. if (FEverShown)
  299. {
  300. // when window is never shown (like when running command-line operation),
  301. // particularly window site is not restored correctly (BoundsRect value set
  302. // in RestoreForm gets lost during handle allocation), so we do not want
  303. // it to be stored
  304. StoreParams();
  305. }
  306. Terminal = NULL;
  307. Queue = NULL;
  308. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  309. NonVisualDataModule->ScpExplorer = NULL;
  310. delete FQueueController;
  311. FQueueController = NULL;
  312. delete FQueueStatusSection;
  313. FQueueStatusSection = NULL;
  314. delete FQueueStatus;
  315. FQueueStatus = NULL;
  316. delete FUserActionTimer;
  317. FUserActionTimer = NULL;
  318. delete FNoteTimer;
  319. delete FNotes;
  320. delete FNoteData;
  321. SAFE_DESTROY(FDocks);
  322. SessionsPageControl->Images = NULL;
  323. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  324. SAFE_DESTROY(FSessionColors);
  325. SAFE_DESTROY(FSessionsDragDropFilesEx);
  326. SAFE_DESTROY(FHistoryMenu[0][0]);
  327. SAFE_DESTROY(FHistoryMenu[0][1]);
  328. SAFE_DESTROY(FHistoryMenu[1][0]);
  329. SAFE_DESTROY(FHistoryMenu[1][1]);
  330. if (FHiddenWindow != NULL)
  331. {
  332. DestroyWindow(FHiddenWindow);
  333. FHiddenWindow = NULL;
  334. }
  335. }
  336. //---------------------------------------------------------------------------
  337. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  338. {
  339. std::unique_ptr<TSessionData> Data;
  340. if (!Session.IsEmpty())
  341. {
  342. bool DefaultsOnly;
  343. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  344. }
  345. TTerminalManager * Manager = TTerminalManager::Instance();
  346. for (int Index = 0; Index < Manager->Count; Index++)
  347. {
  348. TTerminal * Terminal = Manager->Terminals[Index];
  349. if (Session.IsEmpty() ||
  350. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  351. {
  352. if (Path.IsEmpty())
  353. {
  354. Terminal->ClearCaches();
  355. }
  356. else
  357. {
  358. Terminal->DirectoryModified(Path, true);
  359. }
  360. }
  361. }
  362. // We should flag a pending refresh for the background terminals or busy foreground terminals
  363. if (HasActiveTerminal() &&
  364. CanCommandLineFromAnotherInstance() &&
  365. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  366. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  367. {
  368. Terminal->ReloadDirectory();
  369. }
  370. }
  371. //---------------------------------------------------------------------------
  372. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  373. {
  374. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  375. size_t MessageSize = sizeof(TCopyDataMessage);
  376. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  377. if (Result)
  378. {
  379. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  380. Result = (Message.Version == TCopyDataMessage::Version1);
  381. if (Result)
  382. {
  383. switch (Message.Command)
  384. {
  385. case TCopyDataMessage::CommandCanCommandLine:
  386. Result = CanCommandLineFromAnotherInstance();
  387. break;
  388. case TCopyDataMessage::CommandCommandLine:
  389. {
  390. UnicodeString CommandLine(Message.CommandLine);
  391. Result = CommandLineFromAnotherInstance(CommandLine);
  392. }
  393. break;
  394. case TCopyDataMessage::RefreshPanel:
  395. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  396. break;
  397. case TCopyDataMessage::MainWindowCheck:
  398. Result = true;
  399. break;
  400. default:
  401. Result = false;
  402. break;
  403. }
  404. }
  405. }
  406. Message.Result = Result ? 1 : 0;
  407. }
  408. //---------------------------------------------------------------------------
  409. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  410. {
  411. WNDCLASS WindowClass = {0};
  412. WindowClass.lpfnWndProc = DefWindowProc;
  413. WindowClass.hInstance = HInstance;
  414. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  415. FHiddenWindow = NULL;
  416. if (RegisterClass(&WindowClass))
  417. {
  418. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  419. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  420. }
  421. }
  422. //---------------------------------------------------------------------------
  423. bool __fastcall TCustomScpExplorerForm::CanConsole()
  424. {
  425. return
  426. HasActiveTerminal() &&
  427. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  428. }
  429. //---------------------------------------------------------------------------
  430. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  431. {
  432. bool Result = Visible && !NonVisualDataModule->Busy;
  433. return Result;
  434. }
  435. //---------------------------------------------------------------------------
  436. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  437. const UnicodeString & CommandLine)
  438. {
  439. TProgramParams Params(CommandLine);
  440. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  441. if (Result)
  442. {
  443. NonVisualDataModule->StartBusy();
  444. try
  445. {
  446. // this action is initiated from another process,
  447. // so it's likely that our window is not visible,
  448. // and user won't see what is going on
  449. Application->BringToFront();
  450. // reload sessions as we may be asked to open a session
  451. // just stored by another instance
  452. StoredSessions->Reload();
  453. UnicodeString SessionName = Params.Param[1];
  454. std::unique_ptr<TObjectList> DataList(new TObjectList());
  455. try
  456. {
  457. UnicodeString DownloadFile; // unused
  458. int Flags = GetCommandLineParseUrlFlags(&Params);
  459. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this, Flags);
  460. }
  461. catch (EAbort &)
  462. {
  463. // Happens when opening session in PuTTY and in other situations,
  464. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  465. // to process the command-line on its own (or to pass it to yet another instance)
  466. }
  467. if (DataList->Count > 0)
  468. {
  469. TTerminalManager * Manager = TTerminalManager::Instance();
  470. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  471. }
  472. }
  473. __finally
  474. {
  475. NonVisualDataModule->EndBusy();
  476. }
  477. }
  478. return Result;
  479. }
  480. //---------------------------------------------------------------------------
  481. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  482. {
  483. if (FTerminal != value)
  484. {
  485. TerminalChanging();
  486. DoSetTerminal(value, false);
  487. }
  488. }
  489. //---------------------------------------------------------------------------
  490. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  491. {
  492. FTerminal = value;
  493. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  494. FAllowTransferPresetAutoSelect = false;
  495. try
  496. {
  497. TerminalChanged(Replace);
  498. }
  499. __finally
  500. {
  501. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  502. }
  503. if (Terminal != NULL)
  504. {
  505. TransferPresetAutoSelect();
  506. }
  507. }
  508. //---------------------------------------------------------------------------
  509. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  510. {
  511. DoSetTerminal(value, true);
  512. }
  513. //---------------------------------------------------------------------------
  514. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  515. {
  516. if (FTerminal != NULL)
  517. {
  518. UpdateTerminal(Terminal);
  519. }
  520. }
  521. //---------------------------------------------------------------------------
  522. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  523. {
  524. if (Terminal != NULL)
  525. {
  526. UpdateSessionColor((TColor)Terminal->StateData->Color);
  527. }
  528. DoTerminalListChanged();
  529. DebugAssert(!IsLocalBrowserMode());
  530. if (Replaced)
  531. {
  532. RemoteDirView->ReplaceTerminal(Terminal);
  533. }
  534. else
  535. {
  536. RemoteDirView->Terminal = Terminal;
  537. }
  538. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  539. if (Terminal != NULL)
  540. {
  541. if (Terminal->Active)
  542. {
  543. Terminal->RefreshDirectory();
  544. }
  545. if (WinConfiguration->PreservePanelState)
  546. {
  547. if (Terminal->RemoteExplorerState != NULL)
  548. {
  549. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  550. }
  551. else
  552. {
  553. DirView(osRemote)->ClearState();
  554. }
  555. }
  556. if (!Replaced && Terminal->Active)
  557. {
  558. InitStatusBar();
  559. }
  560. }
  561. UpdateTransferList();
  562. // Update panels Enable state before refreshing the labels
  563. UpdateControls();
  564. }
  565. //---------------------------------------------------------------------------
  566. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  567. {
  568. if (Queue != value)
  569. {
  570. if (FQueue != NULL)
  571. {
  572. FQueue->OnListUpdate = NULL;
  573. FQueue->OnQueueItemUpdate = NULL;
  574. }
  575. FQueue = value;
  576. if (FQueue != NULL)
  577. {
  578. DebugAssert(FQueue->OnListUpdate == NULL);
  579. FQueue->OnListUpdate = QueueListUpdate;
  580. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  581. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  582. }
  583. QueueChanged();
  584. }
  585. }
  586. //---------------------------------------------------------------------------
  587. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  588. TListItem * Item)
  589. {
  590. if (FQueueActedItem == Item)
  591. {
  592. FQueueActedItem = NULL;
  593. if ((QueueView3->PopupMenu != NULL) &&
  594. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  595. {
  596. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  597. ReleaseCapture();
  598. }
  599. }
  600. if (Item->Data == FPendingQueueActionItem)
  601. {
  602. FPendingQueueActionItem = NULL;
  603. }
  604. }
  605. //---------------------------------------------------------------------------
  606. bool TCustomScpExplorerForm::IsAnythingQueued()
  607. {
  608. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  609. }
  610. //---------------------------------------------------------------------------
  611. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  612. {
  613. {
  614. TGuard Guard(FQueueStatusSection);
  615. FQueueStatusInvalidated = false;
  616. if (FQueue != NULL)
  617. {
  618. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  619. }
  620. }
  621. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  622. {
  623. FMaxQueueLength = FQueueStatus->Count;
  624. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  625. }
  626. {
  627. TAutoFlag Flag(FQueueStatusUpdating);
  628. FQueueController->UpdateQueueStatus(FQueueStatus);
  629. }
  630. UpdateQueueFileList();
  631. SetQueueProgress();
  632. UpdateQueueView();
  633. bool IsEmpty = !IsAnythingQueued();
  634. if (IsEmpty && (Terminal != NULL))
  635. {
  636. TOnceDoneOperation OnceDoneOperation =
  637. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  638. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  639. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  640. {
  641. FQueue->Enabled = false;
  642. }
  643. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  644. {
  645. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  646. }
  647. }
  648. }
  649. //---------------------------------------------------------------------------
  650. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  651. {
  652. UnicodeString Result;
  653. if (FQueueStatus != NULL)
  654. {
  655. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  656. {
  657. TFileOperationProgressType * ProgressData =
  658. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  659. if ((ProgressData != NULL) && ProgressData->InProgress)
  660. {
  661. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  662. }
  663. }
  664. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  665. {
  666. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  667. }
  668. }
  669. return Result;
  670. }
  671. //---------------------------------------------------------------------------
  672. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  673. {
  674. ComponentVisible[fcQueueView] =
  675. (WinConfiguration->QueueView.Show == qvShow) ||
  676. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  677. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  678. }
  679. //---------------------------------------------------------------------------
  680. void __fastcall TCustomScpExplorerForm::QueueChanged()
  681. {
  682. if (FQueueStatus != NULL)
  683. {
  684. // UpdateFileList implementation relies on the status being recreated when session changes
  685. delete FQueueStatus;
  686. FQueueStatus = NULL;
  687. }
  688. UpdateQueueStatus(true);
  689. }
  690. //---------------------------------------------------------------------------
  691. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  692. {
  693. if (FQueue == Queue)
  694. {
  695. FQueueStatusInvalidated = true;
  696. }
  697. }
  698. //---------------------------------------------------------------------------
  699. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  700. TQueueItem * Item)
  701. {
  702. if (FQueue == Queue)
  703. {
  704. TGuard Guard(FQueueStatusSection);
  705. // this may be running in parallel with QueueChanged
  706. if (FQueueStatus != NULL)
  707. {
  708. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  709. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  710. {
  711. FRefreshLocalDirectory = (QueueItem == NULL) ||
  712. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  713. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  714. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  715. }
  716. if (QueueItem != NULL)
  717. {
  718. QueueItem->UserData = (void*)true;
  719. FQueueItemInvalidated = true;
  720. }
  721. }
  722. }
  723. }
  724. //---------------------------------------------------------------------------
  725. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  726. {
  727. // during standalone editing, we have no way to see/control queue,
  728. // so we have to always popup prompts automatically
  729. return StandaloneOperation || GUIConfiguration->QueueAutoPopup;
  730. }
  731. //---------------------------------------------------------------------------
  732. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  733. {
  734. if (FQueueStatus != NULL)
  735. {
  736. bool QueueAutoPopup = IsQueueAutoPopup();
  737. bool NeedRefresh = FQueueController->NeedRefresh();
  738. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  739. FQueueItemInvalidated = false;
  740. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  741. bool Updated = false;
  742. TQueueItemProxy * QueueItem;
  743. bool WasUserAction;
  744. for (int Index = 0; Index < Limit; Index++)
  745. {
  746. bool Update = false;
  747. QueueItem = FQueueStatus->Items[Index];
  748. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  749. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  750. (FPendingQueueActionItem == NULL))
  751. {
  752. FPendingQueueActionItem = QueueItem;
  753. FUserActionTimer->Enabled = true;
  754. }
  755. if ((bool)QueueItem->UserData)
  756. {
  757. QueueItem->UserData = (void*)false;
  758. QueueItem->Update();
  759. Updated = true;
  760. Update = true;
  761. }
  762. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  763. {
  764. Update = true;
  765. }
  766. if (Update)
  767. {
  768. FQueueController->RefreshQueueItem(QueueItem);
  769. }
  770. }
  771. if (Updated)
  772. {
  773. NonVisualDataModule->UpdateNonVisibleActions();
  774. SetQueueProgress();
  775. UpdateQueueFileList();
  776. }
  777. }
  778. }
  779. //---------------------------------------------------------------------------
  780. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  781. {
  782. if (FTaskbarList != NULL)
  783. {
  784. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  785. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  786. }
  787. }
  788. //---------------------------------------------------------------------------
  789. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  790. {
  791. if (Progress >= 0)
  792. {
  793. if (FTaskbarList != NULL)
  794. {
  795. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  796. }
  797. }
  798. else
  799. {
  800. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  801. }
  802. }
  803. //---------------------------------------------------------------------------
  804. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  805. {
  806. int OverallProgress;
  807. // FProgressForm is null when this is called from SetQueueProgress
  808. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  809. {
  810. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  811. }
  812. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  813. {
  814. OverallProgress = ProgressData->OverallProgress();
  815. }
  816. else
  817. {
  818. OverallProgress = -1;
  819. }
  820. SetTaskbarListProgressValue(OverallProgress);
  821. }
  822. //---------------------------------------------------------------------------
  823. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  824. {
  825. TTerminalManager::Instance()->QueueStatusUpdated();
  826. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  827. {
  828. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  829. {
  830. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  831. {
  832. TFileOperationProgressType * ProgressData = NULL;
  833. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  834. {
  835. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  836. }
  837. if ((ProgressData != NULL) &&
  838. ProgressData->InProgress)
  839. {
  840. SetTaskbarListProgressValue(ProgressData);
  841. }
  842. else
  843. {
  844. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  845. }
  846. }
  847. else
  848. {
  849. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  850. }
  851. }
  852. else
  853. {
  854. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  855. }
  856. }
  857. UpdateQueueLabel();
  858. }
  859. //---------------------------------------------------------------------------
  860. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  861. {
  862. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  863. if (FQueueStatus != NULL)
  864. {
  865. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  866. if (ActiveAndPendingPrimaryCount > 0)
  867. {
  868. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  869. }
  870. }
  871. QueueLabel->Caption = Caption;
  872. }
  873. //---------------------------------------------------------------------------
  874. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  875. {
  876. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  877. static_cast<TComponent*>(GetComponent(fcTransferList)));
  878. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  879. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  880. TransferList->Strings->BeginUpdate();
  881. try
  882. {
  883. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  884. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  885. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  886. if (FTransferDropDownHint.IsEmpty())
  887. {
  888. FTransferDropDownHint = TransferDropDown->Hint;
  889. }
  890. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  891. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  892. TransferDropDown->Text = StripHotkey(Name);
  893. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  894. (FTransferDropDownHint, StripHotkey(Name),
  895. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  896. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  897. // update the label, otherwise when it is updated only on the first draw
  898. // of the list, it is drawn "bold" for some reason
  899. FTransferListHoverIndex = TransferList->ItemIndex;
  900. UpdateTransferLabel();
  901. }
  902. __finally
  903. {
  904. TransferList->Strings->EndUpdate();
  905. }
  906. }
  907. //---------------------------------------------------------------------------
  908. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  909. {
  910. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  911. DebugAssert(Toolbar != NULL);
  912. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  913. }
  914. //---------------------------------------------------------------------------
  915. void __fastcall TCustomScpExplorerForm::UpdateActions()
  916. {
  917. TForm::UpdateActions();
  918. if (ComponentVisible[fcCustomCommandsBand])
  919. {
  920. UpdateCustomCommandsToolbar();
  921. }
  922. }
  923. //---------------------------------------------------------------------------
  924. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  925. {
  926. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  927. }
  928. //---------------------------------------------------------------------------
  929. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  930. {
  931. Color = GetBtnFaceColor();
  932. DebugAssert(Configuration && RemoteDirView);
  933. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  934. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  935. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  936. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  937. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  938. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  939. if (RemoteDirView->RowSelect != WinConfiguration->FullRowSelect)
  940. {
  941. RemoteDirView->RowSelect = WinConfiguration->FullRowSelect;
  942. // selection is not redrawn automatically when RowSelect changes
  943. RemoteDirView->Invalidate();
  944. }
  945. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  946. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  947. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  948. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  949. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  950. UpdateSessionsPageControlHeight();
  951. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  952. UpdateToolbarDisplayMode();
  953. UpdateTransferList();
  954. if (Terminal != NULL)
  955. {
  956. TransferPresetAutoSelect();
  957. }
  958. UpdateQueueView();
  959. UpdateControls();
  960. // this can be called even before constuctor finishes.
  961. if (FEditorManager != NULL)
  962. {
  963. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  964. }
  965. // this can be called even before constuctor finishes.
  966. if (FLocalEditors != NULL)
  967. {
  968. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  969. {
  970. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  971. }
  972. }
  973. if (ComponentVisible[fcCustomCommandsBand])
  974. {
  975. UpdateCustomCommandsToolbar();
  976. }
  977. // show only when keeping queue items forever,
  978. // otherwise, its enough to have in in the context menu
  979. QueueDeleteAllDoneQueueToolbarItem->Visible =
  980. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  981. if (FFileColorsCurrent != WinConfiguration->FileColors)
  982. {
  983. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  984. FFileColorsCurrent = WinConfiguration->FileColors;
  985. FileColorsChanged();
  986. }
  987. }
  988. //---------------------------------------------------------------------------
  989. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  990. {
  991. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  992. DirView->Invalidate();
  993. }
  994. //---------------------------------------------------------------------------
  995. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  996. {
  997. DoFileColorsChanged(RemoteDirView);
  998. }
  999. //---------------------------------------------------------------------------
  1000. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  1001. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  1002. void * /*Arg*/)
  1003. {
  1004. if (Token != NULL)
  1005. {
  1006. TForm * Editor = dynamic_cast<TForm*>(Token);
  1007. DebugAssert(Editor != NULL);
  1008. ReconfigureEditorForm(Editor);
  1009. }
  1010. }
  1011. //---------------------------------------------------------------------------
  1012. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1013. {
  1014. WinConfiguration->DDTransferConfirmation = asOn;
  1015. }
  1016. //---------------------------------------------------------------------------
  1017. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1018. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1019. {
  1020. // noop
  1021. }
  1022. //---------------------------------------------------------------------------
  1023. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1024. TTransferDirection Direction, TTransferType Type, bool Temp,
  1025. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1026. bool Confirm, bool DragDrop, int Options)
  1027. {
  1028. bool Result = true;
  1029. DebugAssert(HasActiveTerminal());
  1030. // these parameters are known in advance
  1031. int Params =
  1032. FLAGMASK(Type == ttMove, cpDelete);
  1033. bool ToTemp = (Temp && (Direction == tdToLocal));
  1034. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1035. {
  1036. bool DisableNewerOnly =
  1037. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1038. ToTemp;
  1039. Options |=
  1040. FLAGMASK(ToTemp, coTemp) |
  1041. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1042. coDoNotShowAgain;
  1043. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1044. int CopyParamAttrs = (Direction == tdToRemote ?
  1045. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1046. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1047. int OutputOptions =
  1048. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1049. cooDoNotShowAgain);
  1050. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1051. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1052. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1053. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1054. if (Result)
  1055. {
  1056. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1057. {
  1058. if (DragDrop)
  1059. {
  1060. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1061. {
  1062. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1063. NULL, 0, EnableDDTransferConfirmation, NULL);
  1064. }
  1065. WinConfiguration->DDTransferConfirmation = asOff;
  1066. }
  1067. else
  1068. {
  1069. WinConfiguration->ConfirmTransferring = false;
  1070. }
  1071. }
  1072. else
  1073. {
  1074. // User explicitly unchecked "do not show again",
  1075. // so show him the dialog the next time
  1076. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1077. {
  1078. WinConfiguration->DDTransferConfirmation = asOn;
  1079. }
  1080. }
  1081. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1082. }
  1083. }
  1084. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1085. {
  1086. Configuration->Usage->Inc(L"TransfersOnBackground");
  1087. // these parameter are known only after transfer dialog
  1088. Params |=
  1089. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1090. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1091. Result = false;
  1092. ClearTransferSourceSelection(Direction);
  1093. }
  1094. return Result;
  1095. }
  1096. //---------------------------------------------------------------------------
  1097. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1098. {
  1099. if (FOnFileOperationFinished != NULL)
  1100. {
  1101. FOnFileOperationFinished(UnicodeString(), true);
  1102. }
  1103. else
  1104. {
  1105. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1106. if (HasDirView[Side])
  1107. {
  1108. DirView(Side)->SelectAll(smNone);
  1109. }
  1110. }
  1111. }
  1112. //---------------------------------------------------------------------------
  1113. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1114. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1115. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1116. int Params)
  1117. {
  1118. DebugAssert(Queue != NULL);
  1119. bool SingleFile = false;
  1120. if (FileList->Count == 1)
  1121. {
  1122. if (Direction == tdToRemote)
  1123. {
  1124. UnicodeString FileName = FileList->Strings[0];
  1125. SingleFile = FileExists(ApiPath(FileName));
  1126. }
  1127. else
  1128. {
  1129. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1130. SingleFile = !File->IsDirectory;
  1131. }
  1132. }
  1133. TQueueItem * QueueItem;
  1134. if (Direction == tdToRemote)
  1135. {
  1136. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1137. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1138. }
  1139. else
  1140. {
  1141. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1142. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1143. }
  1144. AddQueueItem(Queue, QueueItem, Terminal);
  1145. }
  1146. //---------------------------------------------------------------------------
  1147. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1148. {
  1149. if (Queue->IsEmpty)
  1150. {
  1151. Terminal->QueueOperationStart = Now();
  1152. }
  1153. Queue->AddItem(QueueItem);
  1154. }
  1155. //---------------------------------------------------------------------------
  1156. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1157. {
  1158. }
  1159. //---------------------------------------------------------------------------
  1160. void __fastcall TCustomScpExplorerForm::InitControls()
  1161. {
  1162. DebugAssert(FDocks != NULL);
  1163. for (int Index = 0; Index < ComponentCount; Index++)
  1164. {
  1165. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1166. if ((Dock != NULL) && (Dock->Tag == 0))
  1167. {
  1168. FDocks->Add(Dock);
  1169. }
  1170. }
  1171. CollectItemsWithTextDisplayMode(this);
  1172. }
  1173. //---------------------------------------------------------------------------
  1174. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1175. {
  1176. ConfigurationChanged();
  1177. QueuePanel->Height =
  1178. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1179. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1180. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1181. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1182. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1183. QueueFileList->Height =
  1184. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1185. if (QueueFileList->Visible)
  1186. {
  1187. AdjustQueueLayout();
  1188. }
  1189. UpdateCustomCommandsToolbar();
  1190. }
  1191. //---------------------------------------------------------------------------
  1192. void __fastcall TCustomScpExplorerForm::StoreParams()
  1193. {
  1194. int APixelsPerInch = GetControlPixelsPerInch(this);
  1195. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1196. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1197. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1198. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1199. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1200. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1201. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1202. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1203. }
  1204. //---------------------------------------------------------------------------
  1205. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1206. {
  1207. if (!FFormRestored)
  1208. {
  1209. FFormRestored = true;
  1210. RestoreFormParams();
  1211. }
  1212. TForm::CreateParams(Params);
  1213. }
  1214. //---------------------------------------------------------------------------
  1215. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1216. {
  1217. DebugAssert(FDocks != NULL);
  1218. for (int Index = 0; Index < FDocks->Count; Index++)
  1219. {
  1220. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1221. }
  1222. }
  1223. //---------------------------------------------------------------------------
  1224. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1225. {
  1226. SetDockAllowDrag(true);
  1227. while (!ButtonsStr.IsEmpty())
  1228. {
  1229. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1230. UnicodeString Name = CutToChar(S, L'=', true);
  1231. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1232. {
  1233. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1234. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1235. {
  1236. while (!S.IsEmpty())
  1237. {
  1238. UnicodeString S2 = CutToChar(S, L',', true);
  1239. UnicodeString Name = CutToChar(S2, L':', true);
  1240. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1241. {
  1242. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1243. if (SameText(GetToolbarItemName(Item), Name))
  1244. {
  1245. // forward compatibility
  1246. UnicodeString S3 = CutToChar(S2, L':', true);
  1247. bool Visible = StrToIntDef(S3, 0);
  1248. Item->Visible = Visible;
  1249. }
  1250. }
  1251. }
  1252. }
  1253. }
  1254. }
  1255. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1256. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1257. }
  1258. //---------------------------------------------------------------------------
  1259. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1260. {
  1261. UnicodeString Result;
  1262. SetDockAllowDrag(true);
  1263. Result = ::GetToolbarsLayoutStr(this);
  1264. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1265. return Result;
  1266. }
  1267. //---------------------------------------------------------------------------
  1268. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1269. {
  1270. UnicodeString Result;
  1271. if (Item->Action != NULL)
  1272. {
  1273. Result = Item->Action->Name;
  1274. Result = RemoveSuffix(Result, L"Action", true);
  1275. }
  1276. else
  1277. {
  1278. Result = Item->Name;
  1279. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1280. Result = RemoveSuffix(Result, L"Item", true);
  1281. }
  1282. return Result;
  1283. }
  1284. //---------------------------------------------------------------------------
  1285. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1286. {
  1287. UnicodeString Result;
  1288. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1289. {
  1290. UnicodeString ToolbarStr;
  1291. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1292. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1293. {
  1294. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1295. {
  1296. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1297. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1298. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1299. // and save the changes here only.
  1300. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1301. {
  1302. UnicodeString Name = GetToolbarItemName(Item);
  1303. DebugAssert(Name.Pos(L"TBX") == 0);
  1304. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1305. }
  1306. }
  1307. }
  1308. if (!ToolbarStr.IsEmpty())
  1309. {
  1310. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1311. }
  1312. }
  1313. return Result;
  1314. }
  1315. //---------------------------------------------------------------------------
  1316. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1317. {
  1318. DebugAssert(FProgressForm == NULL);
  1319. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1320. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1321. FProgressForm->DeleteLocalToRecycleBin =
  1322. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1323. FProgressForm->DeleteRemoteToRecycleBin =
  1324. (Terminal != NULL) &&
  1325. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1326. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1327. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1328. LockWindow();
  1329. // Actually, do not know what hides the progress once the operation finishes
  1330. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1331. SetTaskbarListProgressState(TBPF_NORMAL);
  1332. }
  1333. //---------------------------------------------------------------------------
  1334. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1335. {
  1336. UnlockWindow();
  1337. SAFE_DESTROY(FProgressForm);
  1338. SetQueueProgress();
  1339. }
  1340. //---------------------------------------------------------------------------
  1341. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1342. TFileOperationProgressType & ProgressData)
  1343. {
  1344. // Download to temporary local directory
  1345. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1346. {
  1347. bool Continue = true;
  1348. FPendingTempSpaceWarn = false;
  1349. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1350. if (!Continue)
  1351. {
  1352. Abort();
  1353. }
  1354. }
  1355. // operation is being executed and we still didn't show up progress form
  1356. if (ProgressData.InProgress && !FProgressForm)
  1357. {
  1358. CreateProgressForm(NULL);
  1359. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1360. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1361. }
  1362. // operation is finished (or terminated), so we hide progress form
  1363. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1364. {
  1365. DestroyProgressForm();
  1366. if (ProgressData.Operation == foCalculateSize)
  1367. {
  1368. // When calculating size before transfer, the abort caused by
  1369. // cancel flag set due to "MoveToQueue" below,
  1370. // is not propagated back to us in ExecuteFileOperation,
  1371. // as it is silently swallowed.
  1372. // So we explicitly (re)throw it here.
  1373. if (FMoveToQueue)
  1374. {
  1375. Abort();
  1376. }
  1377. }
  1378. else
  1379. {
  1380. if ((ProgressData.Cancel == csContinue) &&
  1381. !FAutoOperation)
  1382. {
  1383. OperationComplete(ProgressData.StartTime);
  1384. }
  1385. }
  1386. }
  1387. if (FProgressForm &&
  1388. // Can happen only during synchronization, when ending one of the operations
  1389. ProgressData.InProgress)
  1390. {
  1391. FProgressForm->SetProgressData(ProgressData);
  1392. DebugAssert(ProgressData.InProgress);
  1393. SetTaskbarListProgressValue(&ProgressData);
  1394. if (FProgressForm->Cancel > csContinue)
  1395. {
  1396. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1397. if (FProgressForm->Cancel == csCancelFile)
  1398. {
  1399. FProgressForm->ClearCancel();
  1400. }
  1401. // cancel cancels even the move
  1402. FMoveToQueue = false;
  1403. }
  1404. else if (FProgressForm->MoveToQueue)
  1405. {
  1406. FMoveToQueue = true;
  1407. ProgressData.SetCancelAtLeast(csCancel);
  1408. }
  1409. if ((FTransferResumeList != NULL) &&
  1410. ProgressData.InProgress &&
  1411. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1412. !ProgressData.FullFileName.IsEmpty())
  1413. {
  1414. if ((FTransferResumeList->Count == 0) ||
  1415. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1416. {
  1417. // note that we do not recognize directories from files here
  1418. FTransferResumeList->Add(ProgressData.FullFileName);
  1419. }
  1420. }
  1421. }
  1422. }
  1423. //---------------------------------------------------------------------------
  1424. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1425. const TDateTime & StartTime)
  1426. {
  1427. if (GUIConfiguration->BeepOnFinish &&
  1428. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1429. {
  1430. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1431. DWORD Sound;
  1432. if (!ExtractFileExt(BeepSound).IsEmpty())
  1433. {
  1434. Sound = SND_FILENAME;
  1435. }
  1436. else
  1437. {
  1438. Sound = SND_ALIAS;
  1439. }
  1440. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1441. }
  1442. }
  1443. //---------------------------------------------------------------------------
  1444. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1445. TFileOperationProgressType & ProgressData)
  1446. {
  1447. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1448. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1449. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1450. FileOperationProgress(ProgressData);
  1451. }
  1452. //---------------------------------------------------------------------------
  1453. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1454. {
  1455. UnicodeString Result;
  1456. if (FProgressForm != NULL)
  1457. {
  1458. Result = FProgressForm->ProgressStr();
  1459. }
  1460. return Result;
  1461. }
  1462. //---------------------------------------------------------------------------
  1463. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1464. bool DragDrop)
  1465. {
  1466. return (!DragDrop && (DropSourceControl == NULL)) ||
  1467. (DropSourceControl == DirView(osOther));
  1468. }
  1469. //---------------------------------------------------------------------------
  1470. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1471. TFileOperation Operation, TOperationSide Side,
  1472. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1473. TOnceDoneOperation & OnceDoneOperation)
  1474. {
  1475. if (!FAutoOperation)
  1476. {
  1477. // no selection on "/upload", form serves only as event handler
  1478. // (it is not displayed)
  1479. if (PanelOperation(Side, FDragDropOperation) &&
  1480. Visible && (Operation != foCalculateSize) &&
  1481. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1482. {
  1483. if (FOnFileOperationFinished != NULL)
  1484. {
  1485. FOnFileOperationFinished(FileName, Success);
  1486. }
  1487. else
  1488. {
  1489. TCustomDirView * DView = DirView(Side);
  1490. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(Side));
  1491. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1492. // this can happen when local drive is unplugged in the middle of the operation
  1493. if (Item != NULL)
  1494. {
  1495. if (Success) Item->Selected = false;
  1496. DView->MakeProgressVisible(Item);
  1497. }
  1498. }
  1499. }
  1500. if ((Operation == foCopy) || (Operation == foMove))
  1501. {
  1502. DebugAssert(!IsLocalBrowserMode());
  1503. if (Side == osLocal)
  1504. {
  1505. Configuration->Usage->Inc(L"UploadedFiles");
  1506. }
  1507. else
  1508. {
  1509. Configuration->Usage->Inc(L"DownloadedFiles");
  1510. }
  1511. }
  1512. }
  1513. if (Success && (FSynchronizeController != NULL))
  1514. {
  1515. DebugAssert(!IsSideLocalBrowser(osRemote));
  1516. if (Operation == foCopy)
  1517. {
  1518. DebugAssert(Side == osLocal);
  1519. FSynchronizeController->LogOperation(soUpload, FileName);
  1520. }
  1521. else if (Operation == foDelete)
  1522. {
  1523. DebugAssert(Side == osRemote);
  1524. FSynchronizeController->LogOperation(soDelete, FileName);
  1525. }
  1526. }
  1527. if (FProgressForm)
  1528. {
  1529. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1530. }
  1531. }
  1532. //---------------------------------------------------------------------------
  1533. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1534. TFileOperation Operation, TOperationSide Side,
  1535. bool Temp, const UnicodeString & FileName, Boolean Success,
  1536. TOnceDoneOperation & OnceDoneOperation)
  1537. {
  1538. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1539. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1540. OnceDoneOperation);
  1541. }
  1542. //---------------------------------------------------------------------------
  1543. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1544. {
  1545. return false;
  1546. }
  1547. //---------------------------------------------------------------------------
  1548. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1549. {
  1550. return false;
  1551. }
  1552. //---------------------------------------------------------------------------
  1553. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1554. {
  1555. return NULL;
  1556. }
  1557. //---------------------------------------------------------------------------
  1558. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1559. {
  1560. DebugAssert(GetSide(Side) == osRemote);
  1561. DebugUsedParam(Side);
  1562. return RemoteDirView;
  1563. }
  1564. //---------------------------------------------------------------------------
  1565. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1566. {
  1567. DebugAssert(GetSide(Side) == osRemote);
  1568. DebugUsedParam(Side);
  1569. return RemoteDriveView;
  1570. }
  1571. //---------------------------------------------------------------------------
  1572. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1573. {
  1574. DebugAssert(GetSide(Side) == osRemote);
  1575. DebugUsedParam(Side);
  1576. return HasActiveTerminal();
  1577. }
  1578. //---------------------------------------------------------------------------
  1579. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1580. TOperationSide Side, int FilesOnly)
  1581. {
  1582. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1583. }
  1584. //---------------------------------------------------------------------------
  1585. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1586. TOperationSide Side, int FilesOnly)
  1587. {
  1588. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1589. }
  1590. //---------------------------------------------------------------------------
  1591. struct THistoryItemData
  1592. {
  1593. short int Side;
  1594. short int Index;
  1595. };
  1596. //---------------------------------------------------------------------------
  1597. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1598. {
  1599. DirView(Side)->HistoryGo(Index);
  1600. }
  1601. //---------------------------------------------------------------------------
  1602. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1603. {
  1604. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1605. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1606. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1607. }
  1608. //---------------------------------------------------------------------------
  1609. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1610. bool Back)
  1611. {
  1612. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1613. {
  1614. TCustomDirView * DView = DirView(Side);
  1615. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1616. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1617. if (ICount > 10)
  1618. {
  1619. ICount = 10;
  1620. }
  1621. Menu->Items->Clear();
  1622. THistoryItemData Data;
  1623. Data.Side = Side;
  1624. for (short int i = 1; i <= ICount; i++)
  1625. {
  1626. TTBCustomItem * Item = new TTBXItem(Menu);
  1627. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1628. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1629. Item->Hint = DView->HistoryPath[Data.Index];
  1630. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1631. Item->Tag = *reinterpret_cast<int*>(&Data);
  1632. Item->OnClick = HistoryItemClick;
  1633. Menu->Items->Add(Item);
  1634. }
  1635. }
  1636. }
  1637. //---------------------------------------------------------------------------
  1638. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1639. TOperationSide Side, bool Back)
  1640. {
  1641. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1642. {
  1643. // workaround
  1644. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1645. // operator new allocates memory in Pascal code, but calls inline
  1646. // contructor in C++, leading in problems, the function does
  1647. // both in Pascal code
  1648. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1649. UpdateHistoryMenu(Side, Back);
  1650. }
  1651. return FHistoryMenu[Side == osLocal][Back];
  1652. }
  1653. //---------------------------------------------------------------------------
  1654. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1655. TCustomDirView *Sender)
  1656. {
  1657. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1658. UpdateHistoryMenu(Side, true);
  1659. UpdateHistoryMenu(Side, false);
  1660. }
  1661. //---------------------------------------------------------------------------
  1662. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1663. {
  1664. // remote custom commands can be executed only if the server supports shell commands
  1665. // or have secondary shell
  1666. return HasActiveTerminal() && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1667. }
  1668. //---------------------------------------------------------------------------
  1669. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1670. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1671. {
  1672. // -1 = hidden, 0 = disabled, 1 = enabled
  1673. int Result;
  1674. TFileCustomCommand RemoteCustomCommand;
  1675. TLocalCustomCommand LocalCustomCommand;
  1676. TFileCustomCommand * NonInteractiveCustomCommand =
  1677. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1678. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1679. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1680. if (FLAGCLEAR(Command.Params, ccLocal))
  1681. {
  1682. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1683. // custom command that does not operate with files can be executed anytime ...
  1684. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1685. {
  1686. // ... but do not show such command in remote file menu
  1687. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1688. {
  1689. Result = AllowedState;
  1690. }
  1691. else
  1692. {
  1693. Result = -1;
  1694. }
  1695. }
  1696. else
  1697. {
  1698. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1699. {
  1700. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1701. }
  1702. else
  1703. {
  1704. Result = -1;
  1705. }
  1706. }
  1707. }
  1708. else
  1709. {
  1710. // custom command that does not operate with files can be executed anytime
  1711. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1712. {
  1713. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1714. }
  1715. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1716. {
  1717. if ((ListType == ccltAll) || (ListType == ccltFile))
  1718. {
  1719. // special case is "diff"-style command that can be executed over any side,
  1720. // if we have both sides
  1721. Result =
  1722. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1723. // directly (instead of EnableSelectedOperation) to pass
  1724. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1725. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1726. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1727. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1728. }
  1729. else if (ListType == ccltBoth)
  1730. {
  1731. DebugAssert(!IsLocalBrowserMode());
  1732. Result = 1;
  1733. }
  1734. else
  1735. {
  1736. Result = -1;
  1737. }
  1738. }
  1739. else
  1740. {
  1741. if ((ListType == ccltAll) ||
  1742. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1743. {
  1744. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1745. }
  1746. else
  1747. {
  1748. Result = -1;
  1749. }
  1750. }
  1751. if ((Result > 0) &&
  1752. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1753. !HasActiveTerminal())
  1754. {
  1755. Result = 0;
  1756. }
  1757. }
  1758. return Result;
  1759. }
  1760. //---------------------------------------------------------------------------
  1761. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1762. TStrings * FileList, const TCustomCommandType & ACommand,
  1763. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1764. {
  1765. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1766. {
  1767. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1768. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1769. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1770. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1771. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1772. bool Capture =
  1773. FLAGSET(ACommand.Params, ccShowResults) ||
  1774. FLAGSET(ACommand.Params, ccCopyResults) ||
  1775. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1776. TCaptureOutputEvent OutputEvent = NULL;
  1777. DebugAssert(FCapturedLog == NULL);
  1778. if (Capture)
  1779. {
  1780. FCapturedLog = new TStringList();
  1781. OutputEvent = TerminalCaptureLog;
  1782. }
  1783. try
  1784. {
  1785. if (!RemoteCustomCommand.IsFileCommand(Command))
  1786. {
  1787. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1788. OutputEvent);
  1789. }
  1790. else
  1791. {
  1792. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1793. }
  1794. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1795. {
  1796. if (FLAGSET(ACommand.Params, ccCopyResults))
  1797. {
  1798. CopyToClipboard(FCapturedLog);
  1799. }
  1800. if (FLAGSET(ACommand.Params, ccShowResults))
  1801. {
  1802. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1803. }
  1804. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1805. {
  1806. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1807. }
  1808. }
  1809. }
  1810. __finally
  1811. {
  1812. SAFE_DESTROY(FCapturedLog);
  1813. }
  1814. }
  1815. }
  1816. //---------------------------------------------------------------------------
  1817. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1818. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1819. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1820. {
  1821. DebugAssert(!IsLocalBrowserMode());
  1822. TStrings * LocalFileList = NULL;
  1823. TStrings * RemoteFileList = NULL;
  1824. TStrings * RemoteFileListFull = NULL;
  1825. try
  1826. {
  1827. if (LocalFileCommand)
  1828. {
  1829. if (ALocalFileList == NULL)
  1830. {
  1831. DebugAssert(HasDirView[osLocal]);
  1832. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1833. // directly (instead of EnableSelectedOperation) to pass
  1834. // false to FocusedFileOnlyWhenFocused
  1835. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1836. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1837. }
  1838. else
  1839. {
  1840. LocalFileList = ALocalFileList;
  1841. }
  1842. if (FileListCommand)
  1843. {
  1844. if (LocalFileList->Count != 1)
  1845. {
  1846. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1847. }
  1848. }
  1849. else
  1850. {
  1851. if ((LocalFileList->Count != 1) &&
  1852. (FileList->Count != 1) &&
  1853. (LocalFileList->Count != FileList->Count))
  1854. {
  1855. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1856. }
  1857. }
  1858. }
  1859. UnicodeString RootTempDir;
  1860. UnicodeString TempDir;
  1861. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1862. if (!RemoteFiles)
  1863. {
  1864. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1865. }
  1866. try
  1867. {
  1868. TDateTimes RemoteFileTimes;
  1869. if (RemoteFiles)
  1870. {
  1871. RemoteFileList = FileList;
  1872. }
  1873. else
  1874. {
  1875. RemoteFileList = new TStringList();
  1876. TMakeLocalFileListParams MakeFileListParam;
  1877. MakeFileListParam.FileList = RemoteFileList;
  1878. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1879. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1880. MakeFileListParam.Recursive =
  1881. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1882. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1883. if (!MakeFileListParam.Recursive)
  1884. {
  1885. RemoteFileTimes.clear();
  1886. RemoteFileListFull = new TStringList();
  1887. MakeFileListParam.FileList = RemoteFileListFull;
  1888. MakeFileListParam.Recursive = true;
  1889. MakeFileListParam.IncludeDirs = false;
  1890. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1891. }
  1892. else
  1893. {
  1894. RemoteFileListFull = RemoteFileList;
  1895. }
  1896. }
  1897. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1898. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1899. if (!NonBlocking)
  1900. {
  1901. int Count;
  1902. if (FileListCommand)
  1903. {
  1904. Count = 1;
  1905. }
  1906. else if (LocalFileCommand)
  1907. {
  1908. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1909. }
  1910. else
  1911. {
  1912. Count = RemoteFileList->Count;
  1913. }
  1914. Progress.Start(foCustomCommand, osRemote, Count);
  1915. DebugAssert(FProgressForm != NULL);
  1916. FProgressForm->ReadOnly = true;
  1917. }
  1918. try
  1919. {
  1920. if (FileListCommand)
  1921. {
  1922. UnicodeString LocalFile;
  1923. // MakeFileList does not delimit filenames
  1924. UnicodeString FileList = MakeFileList(RemoteFileList);
  1925. if (LocalFileCommand)
  1926. {
  1927. DebugAssert(LocalFileList->Count == 1);
  1928. LocalFile = LocalFileList->Strings[0];
  1929. }
  1930. TLocalCustomCommand CustomCommand(Data,
  1931. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1932. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1933. if (NonBlocking)
  1934. {
  1935. DebugAssert(!POutput);
  1936. ExecuteShellChecked(ShellCommand);
  1937. }
  1938. else
  1939. {
  1940. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1941. }
  1942. }
  1943. else if (LocalFileCommand)
  1944. {
  1945. if (LocalFileList->Count == 1)
  1946. {
  1947. UnicodeString LocalFile = LocalFileList->Strings[0];
  1948. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1949. {
  1950. UnicodeString FileName = RemoteFileList->Strings[Index];
  1951. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1952. Progress.SetFile(FileNameForProgress);
  1953. TLocalCustomCommand CustomCommand(Data,
  1954. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1955. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1956. TOnceDoneOperation OnceDoneOperation;
  1957. // Do not unselect anything, as it won't work with two panels anyway
  1958. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1959. }
  1960. }
  1961. else if (RemoteFileList->Count == 1)
  1962. {
  1963. UnicodeString FileName = RemoteFileList->Strings[0];
  1964. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1965. {
  1966. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1967. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1968. Progress.SetFile(LocalFileNameOnly);
  1969. TLocalCustomCommand CustomCommand(
  1970. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1971. FileName, LocalFileName, L"");
  1972. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1973. TOnceDoneOperation OnceDoneOperation;
  1974. // Do not unselect anything, as it won't work with two panels anyway
  1975. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1976. }
  1977. }
  1978. else
  1979. {
  1980. if (LocalFileList->Count != RemoteFileList->Count)
  1981. {
  1982. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1983. }
  1984. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1985. {
  1986. UnicodeString FileName = RemoteFileList->Strings[Index];
  1987. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1988. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1989. Progress.SetFile(LocalFileNameOnly); // sic
  1990. TLocalCustomCommand CustomCommand(
  1991. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1992. FileName, LocalFileName, L"");
  1993. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1994. TOnceDoneOperation OnceDoneOperation;
  1995. // Do not unselect anything, as it won't work with two panels anyway
  1996. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1997. }
  1998. }
  1999. }
  2000. else
  2001. {
  2002. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2003. {
  2004. UnicodeString FileName = RemoteFileList->Strings[Index];
  2005. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2006. Progress.SetFile(FileNameForProgress);
  2007. TLocalCustomCommand CustomCommand(Data,
  2008. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2009. FileName, L"", L"");
  2010. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2011. TOnceDoneOperation OnceDoneOperation;
  2012. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2013. }
  2014. }
  2015. }
  2016. __finally
  2017. {
  2018. if (!NonBlocking)
  2019. {
  2020. Progress.Stop();
  2021. }
  2022. }
  2023. DebugAssert(!FAutoOperation);
  2024. if (!RemoteFiles)
  2025. {
  2026. TempDir = IncludeTrailingBackslash(TempDir);
  2027. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2028. {
  2029. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2030. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2031. // Skip directories, process only nested files.
  2032. // The check is redundant as FileAge fails for directories anyway.
  2033. !DirectoryExists(FileName))
  2034. {
  2035. UnicodeString RemoteDir =
  2036. UnixExtractFileDir(
  2037. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2038. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2039. TDateTime NewTime;
  2040. if (FileAge(FileName, NewTime) &&
  2041. (NewTime != RemoteFileTimes[Index]))
  2042. {
  2043. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2044. TemporaryFileCopyParam(CopyParam);
  2045. CopyParam.FileMask = L"";
  2046. FAutoOperation = true;
  2047. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2048. TemporaryFilesList->Add(FileName);
  2049. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2050. }
  2051. }
  2052. }
  2053. }
  2054. }
  2055. __finally
  2056. {
  2057. FAutoOperation = false;
  2058. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2059. {
  2060. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2061. }
  2062. }
  2063. }
  2064. __finally
  2065. {
  2066. if (RemoteFileList != FileList)
  2067. {
  2068. delete RemoteFileList;
  2069. }
  2070. if (LocalFileList != ALocalFileList)
  2071. {
  2072. delete LocalFileList;
  2073. }
  2074. if (RemoteFileListFull != RemoteFileList)
  2075. {
  2076. delete RemoteFileListFull;
  2077. }
  2078. }
  2079. }
  2080. //---------------------------------------------------------------------------
  2081. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2082. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2083. bool FileListCommand, UnicodeString * POutput)
  2084. {
  2085. std::unique_ptr<TStrings> SelectedFileList(DirView(osLocal)->CreateFileList(false, true, NULL));
  2086. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2087. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2088. {
  2089. UnicodeString FileName = SelectedFileList->Strings[Index];
  2090. if (DirectoryExists(FileName))
  2091. {
  2092. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2093. {
  2094. LocalFileList->Add(FileName);
  2095. }
  2096. if (FLAGSET(ACommand.Params, ccRecursive))
  2097. {
  2098. TMakeLocalFileListParams MakeFileListParam;
  2099. MakeFileListParam.FileList = LocalFileList.get();
  2100. MakeFileListParam.FileTimes = NULL;
  2101. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2102. MakeFileListParam.Recursive = true;
  2103. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2104. }
  2105. }
  2106. else
  2107. {
  2108. LocalFileList->Add(FileName);
  2109. }
  2110. }
  2111. UnicodeString RemotePath;
  2112. if (Terminal != NULL)
  2113. {
  2114. RemotePath = Terminal->CurrentDirectory;
  2115. }
  2116. if (FileListCommand)
  2117. {
  2118. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2119. TLocalCustomCommand CustomCommand(
  2120. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2121. L"", L"", FileList);
  2122. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2123. }
  2124. else
  2125. {
  2126. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2127. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2128. DebugAssert(FProgressForm != NULL);
  2129. FProgressForm->ReadOnly = true;
  2130. try
  2131. {
  2132. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2133. {
  2134. UnicodeString FileName = LocalFileList->Strings[Index];
  2135. Progress.SetFile(FileName);
  2136. TLocalCustomCommand CustomCommand(
  2137. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2138. FileName, L"", L"");
  2139. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2140. TOnceDoneOperation OnceDoneOperation;
  2141. Progress.Finish(FileName, true, OnceDoneOperation);
  2142. }
  2143. }
  2144. __finally
  2145. {
  2146. Progress.Stop();
  2147. }
  2148. }
  2149. }
  2150. //---------------------------------------------------------------------------
  2151. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2152. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2153. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2154. {
  2155. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2156. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2157. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2158. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2159. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2160. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2161. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2162. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2163. std::unique_ptr<UnicodeString> POutput;
  2164. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2165. FLAGSET(ACommand.Params, ccCopyResults))
  2166. {
  2167. POutput.reset(new UnicodeString());
  2168. }
  2169. if (!LocalCustomCommand.IsFileCommand(Command))
  2170. {
  2171. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2172. }
  2173. // remote files?
  2174. else if ((FCurrentSide == osRemote) || LocalFileCommand)
  2175. {
  2176. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2177. }
  2178. // local files
  2179. else
  2180. {
  2181. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2182. }
  2183. if (POutput.get() != NULL)
  2184. {
  2185. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2186. int P = POutput->Pos(sLineBreak);
  2187. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2188. {
  2189. POutput->SetLength(P - 1);
  2190. }
  2191. // Copy even empty output to clipboard
  2192. if (FLAGSET(ACommand.Params, ccCopyResults))
  2193. {
  2194. CopyToClipboard(*POutput);
  2195. }
  2196. // But do not show an empty message box.
  2197. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2198. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2199. !POutput->IsEmpty())
  2200. {
  2201. TClipboardHandler ClipboardHandler;
  2202. ClipboardHandler.Text = *POutput;
  2203. TMessageParams Params;
  2204. TQueryButtonAlias Aliases[1];
  2205. Aliases[0].Button = qaRetry;
  2206. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2207. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2208. Params.Aliases = Aliases;
  2209. Params.AliasesCount = LENOF(Aliases);
  2210. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2211. }
  2212. }
  2213. }
  2214. //---------------------------------------------------------------------------
  2215. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2216. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2217. {
  2218. TCustomCommandData Data;
  2219. UnicodeString Site;
  2220. UnicodeString RemotePath;
  2221. if (HasActiveTerminal())
  2222. {
  2223. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2224. Data = TCustomCommandData(SessionData.get());
  2225. Site = Terminal->SessionData->SessionKey;
  2226. RemotePath = Terminal->CurrentDirectory;
  2227. }
  2228. UnicodeString HelpKeyword = ACommand.HomePage;
  2229. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2230. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2231. {
  2232. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2233. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2234. {
  2235. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2236. }
  2237. else
  2238. {
  2239. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2240. }
  2241. if (!DoCustomCommandOptionsDialog(
  2242. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2243. {
  2244. Abort();
  2245. }
  2246. }
  2247. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2248. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2249. {
  2250. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2251. }
  2252. else
  2253. {
  2254. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2255. }
  2256. }
  2257. //---------------------------------------------------------------------------
  2258. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2259. const TCustomCommandType & Command)
  2260. {
  2261. DebugAssert(FCustomCommandLocalFileList != NULL);
  2262. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2263. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2264. TStrings * LocalFileList = new TStringList();
  2265. TStrings * RemoteFileList = new TStringList();
  2266. try
  2267. {
  2268. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2269. {
  2270. LocalFileList->Clear();
  2271. LocalFileList->AddObject(
  2272. FCustomCommandLocalFileList->Strings[Index],
  2273. FCustomCommandLocalFileList->Objects[Index]);
  2274. RemoteFileList->Clear();
  2275. RemoteFileList->AddObject(
  2276. FCustomCommandRemoteFileList->Strings[Index],
  2277. FCustomCommandRemoteFileList->Objects[Index]);
  2278. CustomCommand(RemoteFileList, Command, LocalFileList);
  2279. }
  2280. }
  2281. __finally
  2282. {
  2283. delete LocalFileList;
  2284. delete RemoteFileList;
  2285. }
  2286. }
  2287. //---------------------------------------------------------------------------
  2288. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2289. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2290. {
  2291. delete FCustomCommandLocalFileList;
  2292. delete FCustomCommandRemoteFileList;
  2293. // takeover ownership,
  2294. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2295. FCustomCommandLocalFileList = LocalFileList;
  2296. FCustomCommandRemoteFileList = RemoteFileList;
  2297. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2298. if (Button != NULL)
  2299. {
  2300. FCustomCommandMenu->Items->Clear();
  2301. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2302. MenuPopup(FCustomCommandMenu, Button);
  2303. }
  2304. else
  2305. {
  2306. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2307. }
  2308. }
  2309. //---------------------------------------------------------------------------
  2310. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2311. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2312. {
  2313. DebugAssert(FCapturedLog != NULL);
  2314. if ((OutputType == cotOutput) || (OutputType == cotError))
  2315. {
  2316. FCapturedLog->Add(AddedLine);
  2317. }
  2318. }
  2319. //---------------------------------------------------------------------------
  2320. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2321. TOperationSide Side)
  2322. {
  2323. return
  2324. (Side == osOther) &&
  2325. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2326. }
  2327. //---------------------------------------------------------------------------
  2328. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2329. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2330. {
  2331. TTBItemOptions O;
  2332. O = Item->Options;
  2333. TCustomDirView * DView = DirView(Side);
  2334. if ((DView->ItemFocused != NULL) &&
  2335. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2336. // when resolving links is disabled, default action is to enter the directory,
  2337. // no matter what DoubleClickAction is configured to
  2338. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2339. // Can only Edit files, but can Open/Copy even directories
  2340. ((DoubleClickAction != dcaEdit) ||
  2341. !DView->ItemIsDirectory(DView->ItemFocused)))
  2342. {
  2343. Item->Options = O << tboDefault;
  2344. }
  2345. else
  2346. {
  2347. Item->Options = O >> tboDefault;
  2348. }
  2349. }
  2350. //---------------------------------------------------------------------------
  2351. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2352. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2353. {
  2354. TCustomDirView * DView = DirView(Side);
  2355. TListItem * Item = DView->ItemFocused;
  2356. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2357. EnableFocusedOperation[Side])
  2358. {
  2359. TPoint ClientPoint;
  2360. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2361. TPoint(0, 0) : MousePos;
  2362. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2363. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2364. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2365. }
  2366. }
  2367. //---------------------------------------------------------------------------
  2368. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2369. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2370. {
  2371. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2372. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2373. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2374. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2375. Handled = true;
  2376. }
  2377. //---------------------------------------------------------------------------
  2378. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2379. {
  2380. }
  2381. //---------------------------------------------------------------------------
  2382. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2383. {
  2384. DebugAssert(FErrorList == NULL);
  2385. if (WinConfiguration->ContinueOnError)
  2386. {
  2387. FErrorList = new TStringList();
  2388. Configuration->Usage->Inc(L"ContinuationsOnError");
  2389. }
  2390. NonVisualDataModule->StartBusy();
  2391. }
  2392. //---------------------------------------------------------------------------
  2393. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2394. {
  2395. NonVisualDataModule->EndBusy();
  2396. if (FErrorList)
  2397. {
  2398. HandleErrorList(FErrorList);
  2399. }
  2400. }
  2401. //---------------------------------------------------------------------------
  2402. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2403. const TCopyParamType & CopyParam)
  2404. {
  2405. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2406. {
  2407. Configuration->Usage->Inc(L"FileMaskUses");
  2408. }
  2409. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2410. {
  2411. Configuration->Usage->Inc(L"OperationMaskUses");
  2412. }
  2413. }
  2414. //---------------------------------------------------------------------------
  2415. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2416. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2417. {
  2418. DebugAssert(!IsLocalBrowserMode());
  2419. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2420. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2421. TTransferOperationParam DefaultParam;
  2422. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2423. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2424. switch (Param.Queue)
  2425. {
  2426. case asOn:
  2427. CopyParam.Queue = true;
  2428. break;
  2429. case asOff:
  2430. CopyParam.Queue = false;
  2431. break;
  2432. case asAuto:
  2433. default:
  2434. // keep default
  2435. break;
  2436. }
  2437. bool Result =
  2438. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2439. if (Result)
  2440. {
  2441. DebugAssert(Terminal);
  2442. bool SelectionRestored = false;
  2443. TCustomDirView * DView = NULL;
  2444. if (HasDirView[Side])
  2445. {
  2446. DView = DirView(Side);
  2447. DView->SaveSelection();
  2448. DView->SaveSelectedNames();
  2449. }
  2450. UpdateCopyParamCounters(CopyParam);
  2451. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2452. DebugAssert(FTransferResumeList == NULL);
  2453. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2454. FMoveToQueue = false;
  2455. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2456. try
  2457. {
  2458. TStrings * PermanentFileList;
  2459. std::unique_ptr<TStrings> PermanentFileListOwner;
  2460. try
  2461. {
  2462. if (Side == osLocal)
  2463. {
  2464. PermanentFileList = FileList;
  2465. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2466. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2467. if (Operation == foMove)
  2468. {
  2469. ReloadLocalDirectory();
  2470. if (DView != NULL)
  2471. {
  2472. DView->RestoreSelection();
  2473. }
  2474. SelectionRestored = true;
  2475. }
  2476. }
  2477. else
  2478. {
  2479. // Clone the file list as it may refer to current directory files,
  2480. // which get destroyed, when the source directory is reloaded after foMove operation.
  2481. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2482. // But for a hotfix, we are not going to do such a big change.
  2483. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2484. PermanentFileList = PermanentFileListOwner.get();
  2485. try
  2486. {
  2487. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2488. }
  2489. __finally
  2490. {
  2491. if (Operation == foMove)
  2492. {
  2493. if (DView != NULL)
  2494. {
  2495. DView->RestoreSelection();
  2496. }
  2497. SelectionRestored = true;
  2498. }
  2499. ReloadLocalDirectory(Param.TargetDirectory);
  2500. }
  2501. }
  2502. // When the transfer batch is aborted between individual file transfers, the Abort is not called.
  2503. if (FMoveToQueue)
  2504. {
  2505. Abort();
  2506. }
  2507. }
  2508. catch (EAbort &)
  2509. {
  2510. if (FMoveToQueue)
  2511. {
  2512. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2513. DebugAssert(CopyParam.TransferSkipList == NULL);
  2514. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2515. if (TransferResumeList->Count > 0)
  2516. {
  2517. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2518. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2519. }
  2520. CopyParam.TransferSkipList = TransferResumeList.release();
  2521. // not really needed, just to keep it consistent with TransferResumeList
  2522. FTransferResumeList = NULL;
  2523. FMoveToQueue = false;
  2524. Configuration->Usage->Inc("MovesToBackground");
  2525. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2526. ClearTransferSourceSelection(Direction);
  2527. }
  2528. throw;
  2529. }
  2530. }
  2531. __finally
  2532. {
  2533. if (!SelectionRestored && (DView != NULL))
  2534. {
  2535. DView->DiscardSavedSelection();
  2536. }
  2537. FTransferResumeList = NULL;
  2538. }
  2539. }
  2540. return Result;
  2541. }
  2542. //---------------------------------------------------------------------------
  2543. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2544. TOperationSide Side, TStrings * FileList, void * Param)
  2545. {
  2546. DebugAssert(FileList->Count);
  2547. // We deliberately do not toggle alternative flag (Param), but use OR,
  2548. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2549. // shortcut of CurrentDeleteAlternativeAction
  2550. bool Alternative =
  2551. bool(Param) || UseAlternativeFunction();
  2552. bool Recycle;
  2553. if (IsSideLocalBrowser(Side))
  2554. {
  2555. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2556. }
  2557. else
  2558. {
  2559. Recycle =
  2560. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2561. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2562. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2563. }
  2564. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2565. if (!Result)
  2566. {
  2567. UnicodeString Query;
  2568. if (FileList->Count == 1)
  2569. {
  2570. if (IsSideLocalBrowser(Side))
  2571. {
  2572. Query = ExtractFileName(FileList->Strings[0]);
  2573. }
  2574. else
  2575. {
  2576. Query = UnixExtractFileName(FileList->Strings[0]);
  2577. }
  2578. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2579. }
  2580. else
  2581. {
  2582. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2583. }
  2584. TMessageParams Params(mpNeverAskAgainCheck);
  2585. Params.ImageName = L"Delete file";
  2586. unsigned int Answer =
  2587. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2588. if (Answer == qaNeverAskAgain)
  2589. {
  2590. Result = true;
  2591. if (Recycle)
  2592. {
  2593. WinConfiguration->ConfirmRecycling = false;
  2594. }
  2595. else
  2596. {
  2597. WinConfiguration->ConfirmDeleting = false;
  2598. }
  2599. }
  2600. else
  2601. {
  2602. Result = (Answer == qaOK);
  2603. }
  2604. }
  2605. if (Result)
  2606. {
  2607. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2608. }
  2609. return Result;
  2610. }
  2611. //---------------------------------------------------------------------------
  2612. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2613. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2614. {
  2615. TAutoBatch AutoBatch(this);
  2616. bool Result;
  2617. if ((Operation == foCopy) || (Operation == foMove))
  2618. {
  2619. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2620. }
  2621. else if (Operation == foRename)
  2622. {
  2623. DebugAssert(DirView(Side)->ItemFocused);
  2624. DirView(Side)->ItemFocused->EditCaption();
  2625. Result = true;
  2626. }
  2627. else if (Operation == foDelete)
  2628. {
  2629. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2630. }
  2631. else if (Operation == foSetProperties)
  2632. {
  2633. DirView(osRemote)->SaveSelectedNames();
  2634. Result = SetProperties(Side, FileList);
  2635. }
  2636. else if (Operation == foCustomCommand)
  2637. {
  2638. DebugAssert(Param);
  2639. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2640. DirView(osRemote)->SaveSelectedNames();
  2641. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2642. CustomCommand(FileList, *Command, NULL);
  2643. Result = true;
  2644. }
  2645. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2646. {
  2647. DebugAssert(!IsSideLocalBrowser(Side));
  2648. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2649. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2650. }
  2651. else if (Operation == foLock)
  2652. {
  2653. DebugAssert(!IsSideLocalBrowser(Side));
  2654. LockFiles(FileList, true);
  2655. Result = true;
  2656. }
  2657. else if (Operation == foUnlock)
  2658. {
  2659. DebugAssert(!IsSideLocalBrowser(Side));
  2660. LockFiles(FileList, false);
  2661. Result = true;
  2662. }
  2663. else
  2664. {
  2665. DebugFail();
  2666. }
  2667. return Result;
  2668. }
  2669. //---------------------------------------------------------------------------
  2670. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2671. {
  2672. if (Side == osCurrent)
  2673. {
  2674. Side = FCurrentSide;
  2675. }
  2676. return Side;
  2677. }
  2678. //---------------------------------------------------------------------------
  2679. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2680. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2681. {
  2682. Side = GetSide(Side);
  2683. bool Result;
  2684. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2685. try
  2686. {
  2687. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2688. }
  2689. __finally
  2690. {
  2691. delete FileList;
  2692. }
  2693. return Result;
  2694. }
  2695. //---------------------------------------------------------------------------
  2696. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2697. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2698. bool NoConfirmation, void * Param)
  2699. {
  2700. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2701. {
  2702. if ((Operation == foCopy) || (Operation == foMove))
  2703. {
  2704. DebugAssert(!IsLocalBrowserMode());
  2705. if (GetSide(Side) == osLocal)
  2706. {
  2707. Configuration->Usage->Inc(L"UploadsCommand");
  2708. }
  2709. else
  2710. {
  2711. Configuration->Usage->Inc(L"DownloadsCommand");
  2712. }
  2713. }
  2714. }
  2715. }
  2716. //---------------------------------------------------------------------------
  2717. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2718. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2719. {
  2720. TTransferOperationParam Param;
  2721. if ((WinConfiguration->Interface != ifCommander) ||
  2722. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2723. {
  2724. Flags &= ~cocShortCutHint;
  2725. }
  2726. TCustomDirView * DView = DirView(Side);
  2727. Param.Options =
  2728. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2729. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2730. if (FLAGSET(Flags, cocQueue))
  2731. {
  2732. Param.Queue = asOn;
  2733. }
  2734. else if (FLAGSET(Flags, cocNonQueue))
  2735. {
  2736. Param.Queue = asOff;
  2737. }
  2738. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2739. }
  2740. //---------------------------------------------------------------------------
  2741. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2742. {
  2743. try
  2744. {
  2745. if (ErrorList->Count)
  2746. {
  2747. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2748. if (MessageDialog(Message, qtError,
  2749. qaOK | qaCancel, HELP_NONE) == qaOK)
  2750. {
  2751. unsigned int Answer;
  2752. int Index = 0;
  2753. do
  2754. {
  2755. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2756. TQueryButtonAlias Aliases[2];
  2757. Aliases[0].Button = qaYes;
  2758. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2759. Aliases[1].Button = qaNo;
  2760. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2761. TMessageParams Params;
  2762. Params.Aliases = Aliases;
  2763. Params.AliasesCount = LENOF(Aliases);
  2764. Answer = MoreMessageDialog(
  2765. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2766. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2767. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2768. qaOK, HELP_NONE, &Params);
  2769. if (Answer == qaNo)
  2770. {
  2771. Index++;
  2772. }
  2773. if (Answer == qaYes)
  2774. {
  2775. Index--;
  2776. }
  2777. }
  2778. while (Answer != qaOK);
  2779. }
  2780. }
  2781. }
  2782. __finally
  2783. {
  2784. TStrings * List = ErrorList;
  2785. ErrorList = NULL;
  2786. for (int i = 0; i < List->Count; i++)
  2787. {
  2788. delete List->Objects[i];
  2789. }
  2790. delete List;
  2791. }
  2792. }
  2793. //---------------------------------------------------------------------------
  2794. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2795. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2796. {
  2797. // needed for checking filemasks, as there's no directory object
  2798. // associated with the file object
  2799. File->FullFileName = FullFileName;
  2800. TFileMasks::TParams MaskParams;
  2801. MaskParams.Size = File->Size;
  2802. MaskParams.Modification = File->Modification;
  2803. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2804. }
  2805. //---------------------------------------------------------------------------
  2806. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2807. {
  2808. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2809. Side = GetSide(Side);
  2810. TCustomDirView * DView = DirView(Side);
  2811. TListItem * FocusedItem = DView->ItemFocused;
  2812. UnicodeString Name;
  2813. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2814. {
  2815. Name = DView->ItemFileName(FocusedItem);
  2816. }
  2817. else
  2818. {
  2819. Name = LoadStr(NEW_FILE);
  2820. }
  2821. UnicodeString Names = Name;
  2822. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2823. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2824. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  2825. {
  2826. while (!Names.IsEmpty())
  2827. {
  2828. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2829. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2830. UnicodeString TargetFileName;
  2831. UnicodeString LocalFileName;
  2832. UnicodeString RootTempDir;
  2833. UnicodeString TempDir;
  2834. UnicodeString RemoteDirectory;
  2835. bool ExistingFile = false;
  2836. if (!IsSideLocalBrowser(Side))
  2837. {
  2838. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2839. TRemoteFile * File = NULL;
  2840. if (FTerminal->FileExists(Name, &File) &&
  2841. !File->IsDirectory)
  2842. {
  2843. try
  2844. {
  2845. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2846. ExistingFile = true;
  2847. }
  2848. __finally
  2849. {
  2850. delete File;
  2851. }
  2852. }
  2853. if (!ExistingFile)
  2854. {
  2855. RemoteDirectory = UnixExtractFilePath(Name);
  2856. TemporaryDirectoryForRemoteFiles(
  2857. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2858. TargetFileName = UnixExtractFileName(Name);
  2859. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2860. LocalFileName = TempDir +
  2861. // We probably do not want to trim the VMS version here
  2862. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2863. }
  2864. }
  2865. else
  2866. {
  2867. if (ExtractFilePath(Name).IsEmpty())
  2868. {
  2869. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2870. }
  2871. else
  2872. {
  2873. LocalFileName = ExpandFileName(Name);
  2874. }
  2875. TargetFileName = ExtractFileName(Name);
  2876. }
  2877. if (!ExistingFile)
  2878. {
  2879. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2880. if (NewFile)
  2881. {
  2882. int File = FileCreate(ApiPath(LocalFileName));
  2883. if (File < 0)
  2884. {
  2885. if (!RootTempDir.IsEmpty())
  2886. {
  2887. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2888. }
  2889. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2890. }
  2891. else
  2892. {
  2893. FileClose(File);
  2894. }
  2895. }
  2896. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2897. const TEditorData * ExternalEditor = NULL;
  2898. TFileMasks::TParams MaskParams; // size not known
  2899. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2900. false, MaskParams);
  2901. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2902. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2903. }
  2904. }
  2905. }
  2906. }
  2907. //---------------------------------------------------------------------------
  2908. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2909. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2910. {
  2911. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2912. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2913. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2914. return
  2915. ((ExecuteFileBy == efInternalEditor)) ||
  2916. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2917. }
  2918. //---------------------------------------------------------------------------
  2919. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2920. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2921. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2922. UnicodeString RemoteDirectory, bool NewFile)
  2923. {
  2924. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2925. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2926. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2927. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2928. Side = GetSide(Side);
  2929. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2930. if (!IsSideLocalBrowser(Side))
  2931. {
  2932. Data->Terminal = Terminal;
  2933. Data->Queue = Queue;
  2934. Data->SessionData = CloneCurrentSessionData();
  2935. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2936. Data->RemoteDirectory = RemoteDirectory;
  2937. Data->SessionName = Terminal->SessionData->SessionName;
  2938. Data->LocalRootDirectory = LocalRootDirectory;
  2939. Data->OriginalFileName = OriginalFileName;
  2940. Data->Command = L""; // will be changed later for external editor
  2941. }
  2942. if (ExecuteFileBy == efInternalEditor)
  2943. {
  2944. if (!IsSideLocalBrowser(Side))
  2945. {
  2946. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2947. L" - " + Terminal->SessionData->SessionName;
  2948. TForm * Editor;
  2949. try
  2950. {
  2951. TNotifyEvent OnFileChanged = NULL;
  2952. TNotifyEvent OnSaveAll = NULL;
  2953. TAnyModifiedEvent OnAnyModified = NULL;
  2954. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2955. if (Terminal->IsCapable[fcBackgroundTransfers])
  2956. {
  2957. OnFileChanged = FEditorManager->FileChanged;
  2958. OnSaveAll = SaveAllInternalEditors;
  2959. OnAnyModified = AnyInternalEditorModified;
  2960. }
  2961. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2962. FEditorManager->FileReload, FEditorManager->FileClosed,
  2963. OnSaveAll, OnAnyModified,
  2964. Caption, StandaloneOperation, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2965. }
  2966. catch(...)
  2967. {
  2968. if (!LocalRootDirectory.IsEmpty())
  2969. {
  2970. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2971. }
  2972. throw;
  2973. }
  2974. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2975. }
  2976. else
  2977. {
  2978. DebugAssert(!StandaloneOperation);
  2979. TForm * Editor =
  2980. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2981. SaveAllInternalEditors, AnyInternalEditorModified,
  2982. L"", false, SessionColor, -1, NewFile);
  2983. FLocalEditors->Add(Editor);
  2984. }
  2985. }
  2986. else
  2987. {
  2988. HANDLE Process;
  2989. if (ExecuteFileBy == efExternalEditor)
  2990. {
  2991. UnicodeString Program, Params, Dir;
  2992. Data->Command = ExternalEditor->ExternalEditor;
  2993. ReformatFileNameCommand(Data->Command);
  2994. SplitCommand(Data->Command, Program, Params, Dir);
  2995. Params = ExpandFileNameCommand(Params, FileName);
  2996. Program = ExpandEnvironmentVariables(Program);
  2997. if (!ExecuteShell(Program, Params, Process))
  2998. {
  2999. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3000. }
  3001. }
  3002. else
  3003. {
  3004. DebugAssert(!IsSideLocalBrowser(Side));
  3005. if (!ExecuteShell(FileName, L"", Process))
  3006. {
  3007. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3008. }
  3009. }
  3010. if (IsSideLocalBrowser(Side) ||
  3011. ((ExecuteFileBy == efShell) &&
  3012. !WinConfiguration->Editor.SDIShellEditor) ||
  3013. ((ExecuteFileBy == efExternalEditor) &&
  3014. !ExternalEditor->SDIExternalEditor))
  3015. {
  3016. // no need for handle
  3017. if (Process != NULL)
  3018. {
  3019. DebugCheck(CloseHandle(Process));
  3020. }
  3021. Process = INVALID_HANDLE_VALUE;
  3022. }
  3023. else
  3024. {
  3025. if (Process == NULL)
  3026. {
  3027. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3028. }
  3029. }
  3030. if (!IsSideLocalBrowser(Side))
  3031. {
  3032. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3033. }
  3034. }
  3035. }
  3036. //---------------------------------------------------------------------------
  3037. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3038. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3039. void * /*Arg*/)
  3040. {
  3041. if (Token != NULL)
  3042. {
  3043. EditorFormFileSave(static_cast<TForm *>(Token));
  3044. }
  3045. }
  3046. //---------------------------------------------------------------------------
  3047. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3048. {
  3049. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3050. {
  3051. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3052. }
  3053. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3054. }
  3055. //---------------------------------------------------------------------------
  3056. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3057. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3058. void * Arg)
  3059. {
  3060. if ((Token != NULL) &&
  3061. IsEditorFormModified(static_cast<TForm *>(Token)))
  3062. {
  3063. *static_cast<bool *>(Arg) = true;
  3064. }
  3065. }
  3066. //---------------------------------------------------------------------------
  3067. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3068. TObject * /*Sender*/, bool & Modified)
  3069. {
  3070. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3071. {
  3072. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3073. {
  3074. Modified = true;
  3075. }
  3076. }
  3077. if (!Modified)
  3078. {
  3079. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3080. }
  3081. }
  3082. //---------------------------------------------------------------------------
  3083. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3084. {
  3085. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3086. }
  3087. //---------------------------------------------------------------------------
  3088. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3089. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3090. UnicodeString & Result, UnicodeString & RootDirectory)
  3091. {
  3092. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3093. {
  3094. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3095. Result = RootDirectory;
  3096. }
  3097. else
  3098. {
  3099. RootDirectory = L"";
  3100. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3101. Result = IncludeTrailingBackslash(Result);
  3102. }
  3103. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3104. {
  3105. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3106. }
  3107. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3108. {
  3109. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3110. {
  3111. RemoteDirectory.Delete(1, 1);
  3112. }
  3113. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3114. }
  3115. if (!ForceDirectories(ApiPath(Result)))
  3116. {
  3117. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3118. }
  3119. }
  3120. //---------------------------------------------------------------------------
  3121. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3122. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3123. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3124. {
  3125. DebugAssert(!IsLocalBrowserMode());
  3126. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3127. if (ForceText)
  3128. {
  3129. CopyParam.TransferMode = tmAscii;
  3130. }
  3131. TemporaryFileCopyParam(CopyParam);
  3132. if (AllFiles)
  3133. {
  3134. CopyParam.IncludeFileMask = TFileMasks();
  3135. }
  3136. if (TempDir.IsEmpty())
  3137. {
  3138. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3139. }
  3140. DebugAssert(!FAutoOperation);
  3141. FAutoOperation = AutoOperation;
  3142. Terminal->ExceptionOnFail = true;
  3143. try
  3144. {
  3145. try
  3146. {
  3147. // turn off confirmations, as for MDI editors we may possibly download
  3148. // the same file over
  3149. Terminal->CopyToLocal(
  3150. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3151. if (GetTargetNames)
  3152. {
  3153. for (int i = 0; i < FileList->Count; i++)
  3154. {
  3155. FileList->Strings[i] =
  3156. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3157. }
  3158. }
  3159. }
  3160. catch(...)
  3161. {
  3162. if (!RootTempDir.IsEmpty())
  3163. {
  3164. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3165. }
  3166. throw;
  3167. }
  3168. }
  3169. __finally
  3170. {
  3171. FAutoOperation = false;
  3172. Terminal->ExceptionOnFail = false;
  3173. }
  3174. }
  3175. //---------------------------------------------------------------------------
  3176. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3177. {
  3178. // Do not waste time checking for default editor list the next time,
  3179. // or testing if default editor is not notepad.
  3180. bool TryNextTime = false;
  3181. UnicodeString UsageState;
  3182. if (!WinConfiguration->EditorList->IsDefaultList())
  3183. {
  3184. UsageState = "H";
  3185. }
  3186. else
  3187. {
  3188. UnicodeString Executable;
  3189. UnicodeString ExecutableDescription;
  3190. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3191. {
  3192. UnicodeString Message =
  3193. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3194. unsigned int Answer =
  3195. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3196. if (Answer != qaOK)
  3197. {
  3198. UsageState = "R";
  3199. }
  3200. else
  3201. {
  3202. UsageState = "A";
  3203. TEditorData EditorData;
  3204. EditorData.Editor = edExternal;
  3205. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3206. EditorData.ExternalEditorOptionsAutodetect();
  3207. TEditorList EditorList;
  3208. EditorList = *WinConfiguration->EditorList;
  3209. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3210. WinConfiguration->EditorList = &EditorList;
  3211. }
  3212. }
  3213. }
  3214. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3215. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3216. }
  3217. //---------------------------------------------------------------------------
  3218. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3219. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3220. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3221. {
  3222. if (ExecuteFileBy == efDefaultEditor)
  3223. {
  3224. if (!WinConfiguration->OfferedEditorAutoConfig)
  3225. {
  3226. EditorAutoConfig();
  3227. }
  3228. const TEditorPreferences * Editor =
  3229. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3230. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3231. {
  3232. ExecuteFileBy = efInternalEditor;
  3233. ExternalEditor = NULL;
  3234. }
  3235. else if (Editor->Data->Editor == edOpen)
  3236. {
  3237. ExecuteFileBy = efShell;
  3238. ExternalEditor = NULL;
  3239. }
  3240. else
  3241. {
  3242. ExecuteFileBy = efExternalEditor;
  3243. ExternalEditor = Editor->Data;
  3244. }
  3245. }
  3246. }
  3247. //---------------------------------------------------------------------------
  3248. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3249. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3250. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3251. {
  3252. UnicodeString OriginalFileName;
  3253. UnicodeString LocalRootDirectory;
  3254. UnicodeString RemoteDirectory;
  3255. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3256. IsSideLocalBrowser(Side), MaskParams);
  3257. UnicodeString Counter;
  3258. UnicodeString LocalFileName;
  3259. bool Handled = false;
  3260. if (!IsSideLocalBrowser(Side))
  3261. {
  3262. // We need to trim VMS version here, so that we use name without version
  3263. // when uploading back to create a new version of the file
  3264. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3265. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3266. TObject * Token = NULL;
  3267. UnicodeString LocalDirectory;
  3268. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3269. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3270. LocalDirectory))
  3271. {
  3272. if (Token != NULL)
  3273. {
  3274. TForm * Form = dynamic_cast<TForm *>(Token);
  3275. if (Form->WindowState == wsMinimized)
  3276. {
  3277. ShowWindow(Form->Handle, SW_RESTORE);
  3278. }
  3279. else
  3280. {
  3281. Form->SetFocus();
  3282. }
  3283. Handled = true;
  3284. }
  3285. else
  3286. {
  3287. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3288. }
  3289. }
  3290. if (!Handled)
  3291. {
  3292. TStringList * FileList1 = new TStringList();
  3293. try
  3294. {
  3295. FileList1->AddObject(FullFileName, Object);
  3296. TemporarilyDownloadFiles(FileList1,
  3297. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3298. LocalRootDirectory, LocalDirectory, true, true, true);
  3299. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3300. }
  3301. __finally
  3302. {
  3303. delete FileList1;
  3304. }
  3305. switch (ExecuteFileBy)
  3306. {
  3307. case efShell:
  3308. Counter = "RemoteFilesExecuted";
  3309. break;
  3310. case efInternalEditor:
  3311. Counter = "RemoteFilesOpenedInInternalEditor";
  3312. break;
  3313. case efExternalEditor:
  3314. Counter = "RemoteFilesOpenedInExternalEditor";
  3315. break;
  3316. default:
  3317. DebugFail();
  3318. }
  3319. }
  3320. }
  3321. else
  3322. {
  3323. LocalFileName = FullFileName;
  3324. OriginalFileName = ExtractFileName(FullFileName);
  3325. switch (ExecuteFileBy)
  3326. {
  3327. case efShell:
  3328. Counter = "LocalFilesExecuted";
  3329. break;
  3330. case efInternalEditor:
  3331. Counter = "LocalFilesOpenedInInternalEditor";
  3332. break;
  3333. case efExternalEditor:
  3334. Counter = "LocalFilesOpenedInExternalEditor";
  3335. break;
  3336. default:
  3337. DebugFail();
  3338. }
  3339. }
  3340. if (!Handled)
  3341. {
  3342. Configuration->Usage->Inc(Counter);
  3343. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3344. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3345. }
  3346. }
  3347. //---------------------------------------------------------------------------
  3348. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3349. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3350. bool AllSelected, bool OnFocused)
  3351. {
  3352. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3353. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3354. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3355. Side = GetSide(Side);
  3356. TCustomDirView * DView = DirView(Side);
  3357. TStrings * FileList =
  3358. AllSelected ?
  3359. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3360. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3361. try
  3362. {
  3363. DebugAssert(AllSelected || (FileList->Count == 1));
  3364. for (int i = 0; i < FileList->Count; i++)
  3365. {
  3366. UnicodeString ListFileName = FileList->Strings[i];
  3367. UnicodeString FileNameOnly =
  3368. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3369. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3370. if (!DView->ItemIsDirectory(Item))
  3371. {
  3372. UnicodeString FullFileName;
  3373. if (!IsSideLocalBrowser(Side))
  3374. {
  3375. FullFileName = DirView(Side)->Path + ListFileName;
  3376. }
  3377. else
  3378. {
  3379. FullFileName = ListFileName;
  3380. }
  3381. TFileMasks::TParams MaskParams;
  3382. MaskParams.Size = DView->ItemFileSize(Item);
  3383. TDateTimePrecision Precision;
  3384. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3385. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3386. FileList->Objects[i], MaskParams);
  3387. }
  3388. }
  3389. }
  3390. __finally
  3391. {
  3392. delete FileList;
  3393. }
  3394. }
  3395. //---------------------------------------------------------------------------
  3396. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3397. {
  3398. CopyParam.FileNameCase = ncNoChange;
  3399. CopyParam.PreserveRights = false;
  3400. CopyParam.PreserveReadOnly = false;
  3401. CopyParam.ReplaceInvalidChars = true;
  3402. CopyParam.IncludeFileMask = TFileMasks();
  3403. CopyParam.NewerOnly = false;
  3404. CopyParam.FileMask = L"";
  3405. }
  3406. //---------------------------------------------------------------------------
  3407. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3408. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3409. {
  3410. TTerminalManager * Manager = TTerminalManager::Instance();
  3411. if (!IsActiveTerminal(Data->Terminal))
  3412. {
  3413. if (!NonVisualDataModule->Busy)
  3414. {
  3415. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3416. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3417. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3418. if (Data->Terminal == NULL)
  3419. {
  3420. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3421. if (SameSiteTerminal != NULL)
  3422. {
  3423. UnicodeString Message =
  3424. FMTLOAD(EDIT_SESSION_REATTACH,
  3425. (FileNameOnly, Data->SessionName, FileNameOnly));
  3426. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3427. {
  3428. Data->Terminal = Terminal;
  3429. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3430. Data->SessionName = Terminal->SessionData->SessionName;
  3431. // We might also overwrite session data
  3432. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3433. }
  3434. else
  3435. {
  3436. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3437. Abort();
  3438. }
  3439. }
  3440. }
  3441. // foreground session should reconnect itself
  3442. else if (Terminal != Data->Terminal)
  3443. {
  3444. UnicodeString Message =
  3445. MainInstructions(
  3446. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3447. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3448. {
  3449. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3450. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3451. }
  3452. else
  3453. {
  3454. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3455. Abort();
  3456. }
  3457. }
  3458. }
  3459. if (!IsActiveTerminal(Data->Terminal))
  3460. {
  3461. Configuration->Usage->Inc(L"EditInactiveSession");
  3462. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3463. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3464. (ExtractFileName(FileName), Data->SessionName)));
  3465. }
  3466. }
  3467. TStrings * FileList = new TStringList();
  3468. try
  3469. {
  3470. FileList->Add(FileName);
  3471. // consider using the same settings (preset) as when the file was downloaded
  3472. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3473. TemporaryFileCopyParam(CopyParam);
  3474. if (Data->ForceText)
  3475. {
  3476. CopyParam.TransferMode = tmAscii;
  3477. }
  3478. // so i do not need to worry if masking algorithm works in all cases
  3479. // ("" means "copy file name", no masking is actually done)
  3480. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3481. {
  3482. CopyParam.FileMask = L"";
  3483. }
  3484. else
  3485. {
  3486. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3487. }
  3488. DebugAssert(Data->Queue != NULL);
  3489. int Params = cpNoConfirmation | cpTemporary;
  3490. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3491. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3492. QueueItem->CompleteEvent = UploadCompleteEvent;
  3493. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3494. }
  3495. __finally
  3496. {
  3497. delete FileList;
  3498. }
  3499. }
  3500. //---------------------------------------------------------------------------
  3501. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3502. const UnicodeString FileName, const TEditedFileData * Data)
  3503. {
  3504. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3505. DebugAssert(!NonVisualDataModule->Busy);
  3506. if (!IsActiveTerminal(Data->Terminal))
  3507. {
  3508. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3509. (ExtractFileName(FileName), Data->SessionName)));
  3510. }
  3511. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3512. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3513. NonVisualDataModule->StartBusy();
  3514. try
  3515. {
  3516. std::unique_ptr<TRemoteFile> File;
  3517. UnicodeString RemoteFileName =
  3518. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3519. FTerminal->ExceptionOnFail = true;
  3520. try
  3521. {
  3522. TRemoteFile * AFile = NULL;
  3523. FTerminal->ReadFile(RemoteFileName, AFile);
  3524. File.reset(AFile);
  3525. if (!File->HaveFullFileName)
  3526. {
  3527. File->FullFileName = RemoteFileName;
  3528. }
  3529. }
  3530. __finally
  3531. {
  3532. FTerminal->ExceptionOnFail = false;
  3533. }
  3534. std::unique_ptr<TStrings> FileList(new TStringList());
  3535. FileList->AddObject(RemoteFileName, File.get());
  3536. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3537. UnicodeString TempDir = ExtractFilePath(FileName);
  3538. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3539. TempDir, true, true, true);
  3540. // sanity check, the target file name should be still the same
  3541. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3542. }
  3543. __finally
  3544. {
  3545. NonVisualDataModule->EndBusy();
  3546. // it actually may not exist anymore...
  3547. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3548. }
  3549. }
  3550. //---------------------------------------------------------------------------
  3551. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3552. const TEditedFileData * Data, bool & KeepOpen)
  3553. {
  3554. // Command is set for external editors only (not for "shell" open).
  3555. if (!Data->Command.IsEmpty())
  3556. {
  3557. bool AnyFound = false;
  3558. bool AnyMDI = false;
  3559. bool AnyNonMDI = false;
  3560. bool AnyDetect = false;
  3561. TEditorList * EditorList = new TEditorList();
  3562. try
  3563. {
  3564. *EditorList = *WinConfiguration->EditorList;
  3565. for (int i = 0; i < EditorList->Count; i++)
  3566. {
  3567. const TEditorPreferences * Editor = EditorList->Editors[i];
  3568. if ((Editor->Data->Editor == edExternal) &&
  3569. (Editor->Data->ExternalEditor == Data->Command))
  3570. {
  3571. AnyFound = true;
  3572. if (Editor->Data->SDIExternalEditor)
  3573. {
  3574. AnyNonMDI = true;
  3575. if (Editor->Data->DetectMDIExternalEditor)
  3576. {
  3577. AnyDetect = true;
  3578. }
  3579. }
  3580. else
  3581. {
  3582. AnyMDI = true;
  3583. }
  3584. }
  3585. }
  3586. bool EnableMDI = false;
  3587. bool DisableDetect = false;
  3588. if (AnyMDI)
  3589. {
  3590. KeepOpen = true;
  3591. if (AnyNonMDI)
  3592. {
  3593. // there is at least one instance of the editor with MDI support enabled,
  3594. // and one with disabled, enable it for all instances
  3595. EnableMDI = true;
  3596. }
  3597. }
  3598. else if (AnyFound && !AnyDetect)
  3599. {
  3600. // at least once instance found but all have MDI autodetection disabled
  3601. // => close the file (default action)
  3602. }
  3603. else
  3604. {
  3605. // no instance of the editor has MDI support enabled
  3606. TMessageParams Params;
  3607. if (AnyFound)
  3608. {
  3609. // there is at least one instance of the editor
  3610. Params.Params |= mpNeverAskAgainCheck;
  3611. }
  3612. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3613. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3614. switch (Answer)
  3615. {
  3616. case qaNeverAskAgain:
  3617. DisableDetect = true;
  3618. break;
  3619. case qaNo:
  3620. EnableMDI = true;
  3621. KeepOpen = true;
  3622. break;
  3623. }
  3624. }
  3625. if (AnyFound && (EnableMDI || DisableDetect))
  3626. {
  3627. bool Changed = false;
  3628. for (int i = 0; i < EditorList->Count; i++)
  3629. {
  3630. const TEditorPreferences * Editor = EditorList->Editors[i];
  3631. if ((Editor->Data->Editor == edExternal) &&
  3632. (Editor->Data->ExternalEditor == Data->Command) &&
  3633. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3634. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3635. {
  3636. Changed = true;
  3637. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3638. if (EnableMDI)
  3639. {
  3640. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3641. }
  3642. if (DisableDetect)
  3643. {
  3644. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3645. }
  3646. EditorList->Change(i, UpdatedEditor);
  3647. }
  3648. }
  3649. if (Changed)
  3650. {
  3651. WinConfiguration->EditorList = EditorList;
  3652. }
  3653. }
  3654. }
  3655. __finally
  3656. {
  3657. delete EditorList;
  3658. }
  3659. }
  3660. else
  3661. {
  3662. // "open" case
  3663. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3664. qaOK, HELP_APP_EARLY_CLOSED);
  3665. }
  3666. }
  3667. //---------------------------------------------------------------------------
  3668. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3669. {
  3670. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3671. }
  3672. //---------------------------------------------------------------------------
  3673. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3674. {
  3675. SideEnter(osRemote);
  3676. }
  3677. //---------------------------------------------------------------------------
  3678. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3679. {
  3680. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3681. SideEnter(osRemote);
  3682. }
  3683. //---------------------------------------------------------------------------
  3684. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3685. {
  3686. FCurrentSide = Side;
  3687. if (Visible)
  3688. {
  3689. UpdateControls();
  3690. }
  3691. }
  3692. //---------------------------------------------------------------------------
  3693. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3694. TStrings * FileList, bool Alternative)
  3695. {
  3696. TCustomDirView * DView = DirView(Side);
  3697. DView->SaveSelection();
  3698. DView->SaveSelectedNames();
  3699. DebugAssert(!FAlternativeDelete);
  3700. FAlternativeDelete = Alternative;
  3701. try
  3702. {
  3703. if (!IsSideLocalBrowser(Side))
  3704. {
  3705. DebugAssert(Terminal != NULL);
  3706. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3707. }
  3708. else
  3709. {
  3710. try
  3711. {
  3712. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3713. }
  3714. __finally
  3715. {
  3716. ReloadLocalDirectory();
  3717. }
  3718. }
  3719. FAlternativeDelete = false;
  3720. }
  3721. catch(...)
  3722. {
  3723. FAlternativeDelete = false;
  3724. DView->DiscardSavedSelection();
  3725. throw;
  3726. }
  3727. DView->RestoreSelection();
  3728. }
  3729. //---------------------------------------------------------------------------
  3730. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3731. {
  3732. DebugAssert(Terminal);
  3733. DebugAssert(!IsLocalBrowserMode());
  3734. RemoteDirView->SaveSelection();
  3735. RemoteDirView->SaveSelectedNames();
  3736. try
  3737. {
  3738. if (Lock)
  3739. {
  3740. Terminal->LockFiles(FileList);
  3741. }
  3742. else
  3743. {
  3744. Terminal->UnlockFiles(FileList);
  3745. }
  3746. }
  3747. catch(...)
  3748. {
  3749. RemoteDirView->DiscardSavedSelection();
  3750. throw;
  3751. }
  3752. RemoteDirView->RestoreSelection();
  3753. }
  3754. //---------------------------------------------------------------------------
  3755. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3756. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3757. bool NoConfirmation, bool Move)
  3758. {
  3759. DebugAssert(Terminal != NULL);
  3760. DebugAssert(!IsLocalBrowserMode());
  3761. // update Terminal->StateData->RemoteDirectory
  3762. UpdateTerminal(Terminal);
  3763. if (Session == NULL)
  3764. {
  3765. Session = TTerminalManager::Instance()->ActiveTerminal;
  3766. }
  3767. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3768. {
  3769. if (RemoteDriveView->DropTarget != NULL)
  3770. {
  3771. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3772. }
  3773. else if (RemoteDirView->DropTarget != NULL)
  3774. {
  3775. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3776. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3777. }
  3778. else
  3779. {
  3780. Target = RemoteDirView->Path;
  3781. }
  3782. }
  3783. else
  3784. {
  3785. Target = Session->StateData->RemoteDirectory;
  3786. }
  3787. Target = UnixIncludeTrailingBackslash(Target);
  3788. if (FileList->Count == 1)
  3789. {
  3790. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3791. }
  3792. else
  3793. {
  3794. FileMask = AnyMask;
  3795. }
  3796. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3797. bool Result = true;
  3798. if (!NoConfirmation)
  3799. {
  3800. bool Multi = (FileList->Count > 1);
  3801. if (Move)
  3802. {
  3803. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3804. }
  3805. else
  3806. {
  3807. std::unique_ptr<TStrings> Sessions(new TStringList);
  3808. std::unique_ptr<TStrings> Directories(new TStringList);
  3809. TStrings * SessionList = TTerminalManager::Instance()->TerminalList;
  3810. for (int Index = 0; Index < SessionList->Count; Index++)
  3811. {
  3812. TManagedTerminal * ASession = DebugNotNull(dynamic_cast<TManagedTerminal *>(SessionList->Objects[Index]));
  3813. if (IsActiveTerminal(ASession))
  3814. {
  3815. Sessions->AddObject(SessionList->Strings[Index], ASession);
  3816. Directories->Add(ASession->StateData->RemoteDirectory);
  3817. }
  3818. }
  3819. TDirectRemoteCopy AllowDirectCopy;
  3820. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3821. {
  3822. DebugAssert(DirectCopy);
  3823. AllowDirectCopy = drcAllow;
  3824. }
  3825. else if (FTerminal->IsCapable[fcSecondaryShell])
  3826. {
  3827. DebugAssert(DirectCopy);
  3828. AllowDirectCopy = drcConfirmCommandSession;
  3829. }
  3830. else
  3831. {
  3832. DebugAssert(!DirectCopy);
  3833. AllowDirectCopy = drcDisallow;
  3834. }
  3835. void * ASession = Session;
  3836. Result = DoRemoteCopyDialog(
  3837. Sessions.get(), Directories.get(), AllowDirectCopy, Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3838. Session = static_cast<TManagedTerminal *>(ASession);
  3839. }
  3840. }
  3841. return Result;
  3842. }
  3843. //---------------------------------------------------------------------------
  3844. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3845. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3846. {
  3847. DebugAssert(!IsLocalBrowserMode());
  3848. bool DirectCopy;
  3849. UnicodeString Target, FileMask;
  3850. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3851. if (Result)
  3852. {
  3853. if (!Move && !DirectCopy)
  3854. {
  3855. Configuration->Usage->Inc("RemoteCopyTemp");
  3856. UnicodeString RootTempDir;
  3857. UnicodeString TempDir;
  3858. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3859. TStrings * TemporaryFilesList = new TStringList();
  3860. try
  3861. {
  3862. TMakeLocalFileListParams MakeFileListParam;
  3863. MakeFileListParam.FileList = TemporaryFilesList;
  3864. MakeFileListParam.FileTimes = NULL;
  3865. MakeFileListParam.IncludeDirs = true;
  3866. MakeFileListParam.Recursive = false;
  3867. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3868. TTerminalManager::Instance()->ActiveTerminal = Session;
  3869. if (TemporaryFilesList->Count > 0)
  3870. {
  3871. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3872. CopyParam.FileMask = FileMask;
  3873. DebugAssert(!FAutoOperation);
  3874. FAutoOperation = true;
  3875. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3876. }
  3877. }
  3878. __finally
  3879. {
  3880. delete TemporaryFilesList;
  3881. FAutoOperation = false;
  3882. if (!RootTempDir.IsEmpty())
  3883. {
  3884. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3885. }
  3886. }
  3887. }
  3888. else
  3889. {
  3890. RemoteDirView->SaveSelection();
  3891. RemoteDirView->SaveSelectedNames();
  3892. try
  3893. {
  3894. if (Move)
  3895. {
  3896. Configuration->Usage->Inc("RemoteMove");
  3897. Terminal->MoveFiles(FileList, Target, FileMask);
  3898. }
  3899. else
  3900. {
  3901. Configuration->Usage->Inc("RemoteCopyDirect");
  3902. DebugAssert(DirectCopy);
  3903. DebugAssert(Session == FTerminal);
  3904. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3905. FTerminal->CommandSessionOpened ||
  3906. CommandSessionFallback())
  3907. {
  3908. Terminal->CopyFiles(FileList, Target, FileMask);
  3909. }
  3910. }
  3911. }
  3912. catch(...)
  3913. {
  3914. RemoteDirView->DiscardSavedSelection();
  3915. throw;
  3916. }
  3917. RemoteDirView->RestoreSelection();
  3918. }
  3919. }
  3920. return Result;
  3921. }
  3922. //---------------------------------------------------------------------------
  3923. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3924. const UnicodeString & Path, TRemoteProperties & Properties)
  3925. {
  3926. DebugAssert(!IsLocalBrowserMode());
  3927. Properties.Valid = Properties.Valid << vpEncrypt;
  3928. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3929. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3930. }
  3931. //---------------------------------------------------------------------------
  3932. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3933. {
  3934. Side = GetSide(Side);
  3935. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3936. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3937. UnicodeString Name = LoadStr(NEW_FOLDER);
  3938. int AllowedChanges =
  3939. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3940. bool SaveSettings = false;
  3941. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3942. {
  3943. TWindowLock Lock(this);
  3944. if (!IsSideLocalBrowser(Side))
  3945. {
  3946. if (SaveSettings)
  3947. {
  3948. GUIConfiguration->NewDirectoryProperties = Properties;
  3949. }
  3950. CreateRemoteDirectory(Name, Properties);
  3951. }
  3952. else
  3953. {
  3954. DirView(Side)->CreateDirectory(Name);
  3955. }
  3956. }
  3957. }
  3958. //---------------------------------------------------------------------------
  3959. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3960. {
  3961. TWindowLock Lock(this);
  3962. DirView(Side)->ExecuteHomeDirectory();
  3963. }
  3964. //---------------------------------------------------------------------------
  3965. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3966. {
  3967. DoOpenDirectoryDialog(odBrowse, Side);
  3968. }
  3969. //---------------------------------------------------------------------------
  3970. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3971. {
  3972. UnicodeString Path = Bookmark->GetSideDirectory(Side);
  3973. bool Result = !Path.IsEmpty();
  3974. if (Result)
  3975. {
  3976. // While we might get here when the session is closed (from location profiles),
  3977. // it's not a problem as the Path setter is noop then
  3978. DirView(Side)->Path = Path;
  3979. }
  3980. return Result;
  3981. }
  3982. //---------------------------------------------------------------------------
  3983. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3984. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3985. bool & Close)
  3986. {
  3987. // terminal can be already closed (e.g. dropped connection)
  3988. if (Terminal != NULL)
  3989. {
  3990. try
  3991. {
  3992. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  3993. }
  3994. catch(...)
  3995. {
  3996. if (!Terminal->Active)
  3997. {
  3998. Close = true;
  3999. }
  4000. throw;
  4001. }
  4002. }
  4003. }
  4004. //---------------------------------------------------------------------------
  4005. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4006. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4007. bool & Close)
  4008. {
  4009. // terminal can be already closed (e.g. dropped connection)
  4010. if (Terminal != NULL)
  4011. {
  4012. Configuration->Usage->Inc(L"ChecksumCalculated");
  4013. try
  4014. {
  4015. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4016. }
  4017. catch(...)
  4018. {
  4019. if (!Terminal->Active)
  4020. {
  4021. Close = true;
  4022. }
  4023. throw;
  4024. }
  4025. }
  4026. }
  4027. //---------------------------------------------------------------------------
  4028. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4029. {
  4030. bool Result;
  4031. if (!IsSideLocalBrowser(Side))
  4032. {
  4033. TRemoteTokenList * GroupList = NULL;
  4034. TRemoteTokenList * UserList = NULL;
  4035. try
  4036. {
  4037. TRemoteProperties CurrentProperties;
  4038. if (Terminal->LoadFilesProperties(FileList))
  4039. {
  4040. RemoteDirView->Invalidate();
  4041. }
  4042. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4043. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4044. if (CapableGroupChanging || CapableOwnerChanging)
  4045. {
  4046. if (CapableGroupChanging)
  4047. {
  4048. GroupList = Terminal->Groups->Duplicate();
  4049. }
  4050. if (CapableOwnerChanging)
  4051. {
  4052. UserList = Terminal->Users->Duplicate();
  4053. }
  4054. TRemoteDirectory * Files = Terminal->Files;
  4055. int Count = Files->Count;
  4056. if (Count > 100)
  4057. {
  4058. Count = 100;
  4059. }
  4060. for (int Index = 0; Index < Count; Index++)
  4061. {
  4062. TRemoteFile * File = Files->Files[Index];
  4063. if (CapableGroupChanging)
  4064. {
  4065. GroupList->AddUnique(File->Group);
  4066. }
  4067. if (CapableOwnerChanging)
  4068. {
  4069. UserList->AddUnique(File->Owner);
  4070. }
  4071. }
  4072. // if we haven't collected tokens for all files in current directory,
  4073. // make sure we collect them at least for all selected files.
  4074. // (note that so far the files in FileList has to be from current direcotry)
  4075. if (Count < Files->Count)
  4076. {
  4077. for (int Index = 0; Index < FileList->Count; Index++)
  4078. {
  4079. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4080. if (CapableGroupChanging)
  4081. {
  4082. GroupList->AddUnique(File->Group);
  4083. }
  4084. if (CapableOwnerChanging)
  4085. {
  4086. UserList->AddUnique(File->Owner);
  4087. }
  4088. }
  4089. }
  4090. }
  4091. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4092. int Flags = 0;
  4093. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4094. if (CapableOwnerChanging) Flags |= cpOwner;
  4095. if (CapableGroupChanging) Flags |= cpGroup;
  4096. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4097. if (Terminal->IsCapable[fcCalculatingChecksum])
  4098. {
  4099. CalculateChecksumEvent = CalculateChecksum;
  4100. }
  4101. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4102. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4103. TRemoteProperties NewProperties = CurrentProperties;
  4104. Result =
  4105. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4106. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4107. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4108. CalculateSize, CalculateChecksumEvent);
  4109. if (Result)
  4110. {
  4111. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4112. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4113. }
  4114. }
  4115. __finally
  4116. {
  4117. delete GroupList;
  4118. delete UserList;
  4119. }
  4120. }
  4121. else
  4122. {
  4123. DirView(Side)->DisplayPropertiesMenu();
  4124. Result = true;
  4125. }
  4126. return Result;
  4127. }
  4128. //---------------------------------------------------------------------------
  4129. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4130. {
  4131. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4132. {
  4133. FIgnoreNextDialogChar = Key;
  4134. }
  4135. Key = 0;
  4136. }
  4137. //---------------------------------------------------------------------------
  4138. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4139. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4140. {
  4141. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4142. if (Command != NULL)
  4143. {
  4144. KeyProcessed(Key, Shift);
  4145. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4146. {
  4147. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4148. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4149. false, false, const_cast<TCustomCommandType *>(Command));
  4150. }
  4151. }
  4152. }
  4153. //---------------------------------------------------------------------------
  4154. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4155. {
  4156. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4157. {
  4158. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4159. }
  4160. if (!DirView(osCurrent)->IsEditing())
  4161. {
  4162. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4163. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4164. {
  4165. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4166. if (((Action->ShortCut == KeyShortCut) ||
  4167. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4168. AllowedAction(Action, aaShortCut))
  4169. {
  4170. // Has to be called before the action as the dialog char is already in queue.
  4171. // So when the action consumes message queue, we already need to have the
  4172. // FIgnoreNextDialogChar set
  4173. KeyProcessed(Key, Shift);
  4174. // Reset reference to previous component (when menu/toolbar was clicked).
  4175. // Needed to detect that action was invoked by keyboard shortcut
  4176. // in TNonVisualDataModule::ExplorerActionsExecute
  4177. Action->ActionComponent = NULL;
  4178. Action->Execute();
  4179. return;
  4180. }
  4181. }
  4182. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4183. {
  4184. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4185. {
  4186. KeyProcessed(Key, Shift);
  4187. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4188. return;
  4189. }
  4190. }
  4191. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4192. {
  4193. KeyProcessed(Key, Shift);
  4194. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4195. }
  4196. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4197. if (IsCustomShortCut(CustomShortCut))
  4198. {
  4199. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4200. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4201. if (WinConfiguration->SharedBookmarks != NULL)
  4202. {
  4203. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4204. if ((Bookmark != NULL) &&
  4205. OpenBookmark(FCurrentSide, Bookmark))
  4206. {
  4207. KeyProcessed(Key, Shift);
  4208. }
  4209. }
  4210. }
  4211. }
  4212. TForm::KeyDown(Key, Shift);
  4213. }
  4214. //---------------------------------------------------------------------------
  4215. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4216. {
  4217. DebugAssert(Terminal != NULL);
  4218. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4219. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4220. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4221. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4222. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4223. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4224. // expanded from ?: to avoid memory leaks
  4225. if (SecurityEnabled)
  4226. {
  4227. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4228. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4229. }
  4230. else
  4231. {
  4232. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4233. }
  4234. if (FileSystemInfo.ProtocolName.IsEmpty())
  4235. {
  4236. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4237. }
  4238. else
  4239. {
  4240. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4241. }
  4242. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4243. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4244. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4245. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4246. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4247. UnicodeString CompressionStr = CSCompressionStr;
  4248. if (CSCompressionStr != SCCompressionStr)
  4249. {
  4250. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4251. }
  4252. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4253. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4254. UpdateStatusBar();
  4255. }
  4256. //---------------------------------------------------------------------------
  4257. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4258. {
  4259. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4260. DebugAssert(SessionStatusBar != NULL);
  4261. if (!HasActiveTerminal() || (Terminal->Status < ssOpened))
  4262. {
  4263. // note: (Terminal->Status < sshReady) currently never happens here,
  4264. // so STATUS_CONNECTING is never used
  4265. SessionStatusBar->SimplePanel = true;
  4266. SessionStatusBar->SimpleText = LoadStr(
  4267. !HasActiveTerminal() ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4268. }
  4269. else
  4270. {
  4271. DebugAssert(Terminal);
  4272. SessionStatusBar->SimplePanel = false;
  4273. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4274. if (!FNote.IsEmpty())
  4275. {
  4276. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4277. }
  4278. else
  4279. {
  4280. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4281. }
  4282. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4283. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4284. }
  4285. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4286. }
  4287. //---------------------------------------------------------------------------
  4288. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4289. {
  4290. Panel->Caption = L"";
  4291. }
  4292. //---------------------------------------------------------------------------
  4293. void __fastcall TCustomScpExplorerForm::Idle()
  4294. {
  4295. if (FShowing ||
  4296. // Particularly to detect closed connection and automatically reconnect it while waiting for changes
  4297. // while "keeping remote directory up to date"
  4298. StandaloneOperation)
  4299. {
  4300. FEditorManager->Check();
  4301. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4302. // that needs to know if queue view is visible (and it may be closed after queue update)
  4303. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4304. }
  4305. if (FShowing)
  4306. {
  4307. if (!NonVisualDataModule->Busy &&
  4308. // Menu is opened or drag&drop is going on
  4309. (Mouse->Capture == NULL))
  4310. {
  4311. if (FRefreshRemoteDirectory)
  4312. {
  4313. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4314. {
  4315. Terminal->RefreshDirectory();
  4316. }
  4317. FRefreshRemoteDirectory = false;
  4318. }
  4319. if (FRefreshLocalDirectory)
  4320. {
  4321. ReloadLocalDirectory();
  4322. FRefreshLocalDirectory = false;
  4323. }
  4324. if (WinConfiguration->RefreshRemotePanel)
  4325. {
  4326. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4327. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4328. {
  4329. RemoteDirView->ReloadDirectory();
  4330. }
  4331. }
  4332. }
  4333. }
  4334. if (FShowing || StandaloneOperation)
  4335. {
  4336. if (FQueueStatusInvalidated)
  4337. {
  4338. UpdateQueueStatus(false);
  4339. }
  4340. RefreshQueueItems();
  4341. }
  4342. if (FShowing)
  4343. {
  4344. UpdateStatusBar();
  4345. }
  4346. FIgnoreNextDialogChar = 0;
  4347. }
  4348. //---------------------------------------------------------------------------
  4349. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4350. {
  4351. try
  4352. {
  4353. FUserActionTimer->Enabled = false;
  4354. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4355. {
  4356. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4357. {
  4358. FPendingQueueActionItem->ProcessUserAction();
  4359. }
  4360. }
  4361. }
  4362. __finally
  4363. {
  4364. FPendingQueueActionItem = NULL;
  4365. }
  4366. }
  4367. //---------------------------------------------------------------------------
  4368. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4369. {
  4370. if (WinConfiguration->MinimizeToTray)
  4371. {
  4372. UpdateTrayIcon();
  4373. FTrayIcon->Visible = true;
  4374. if (Visible)
  4375. {
  4376. ShowWindow(Handle, SW_HIDE);
  4377. }
  4378. }
  4379. }
  4380. //---------------------------------------------------------------------------
  4381. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4382. {
  4383. // WORKAROUND
  4384. // When restoring maximized window from minimization,
  4385. // rarely some controls do not align properly.
  4386. // Two instances seen (both for Commander):
  4387. // - When restoring, window is temporarily narrower (not maximized),
  4388. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4389. // Once maximized already, top dock shinks back, but the session PageControl,
  4390. // do not align up, leaving space between TopDock and PageControl.
  4391. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4392. for (int Index = 0; Index < ControlCount; Index++)
  4393. {
  4394. RealignControl(Controls[Index]);
  4395. }
  4396. if (FTrayIcon->Visible)
  4397. {
  4398. FTrayIcon->Visible = false;
  4399. if (Visible)
  4400. {
  4401. ShowWindow(Handle, SW_SHOW);
  4402. }
  4403. }
  4404. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4405. {
  4406. FNeedSession = false;
  4407. NonVisualDataModule->StartBusy();
  4408. try
  4409. {
  4410. NeedSession(true);
  4411. }
  4412. __finally
  4413. {
  4414. NonVisualDataModule->EndBusy();
  4415. }
  4416. }
  4417. }
  4418. //---------------------------------------------------------------------------
  4419. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4420. {
  4421. FTrayIcon->Hint = GetMainForm()->Caption;
  4422. }
  4423. //---------------------------------------------------------------------------
  4424. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4425. {
  4426. UpdateTrayIcon();
  4427. }
  4428. //---------------------------------------------------------------------------
  4429. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4430. {
  4431. // workaround
  4432. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4433. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4434. // But WM_ACTIVATEAPP message can be received even when
  4435. // the main window is minimized to the tray and internal editor window is focused
  4436. // (after another application was previously active)
  4437. if (::IsIconic(Handle))
  4438. {
  4439. if (!IsAppIconic())
  4440. {
  4441. SetAppIconic(true);
  4442. }
  4443. }
  4444. ::ApplicationRestore();
  4445. Application->BringToFront();
  4446. }
  4447. //---------------------------------------------------------------------------
  4448. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4449. {
  4450. RestoreApp();
  4451. }
  4452. //---------------------------------------------------------------------------
  4453. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4454. {
  4455. if (OpenInNewWindow())
  4456. {
  4457. ExecuteNewInstance(SessionUrl);
  4458. }
  4459. else
  4460. {
  4461. TTerminalManager::Instance()->NewSession(SessionUrl);
  4462. }
  4463. }
  4464. //---------------------------------------------------------------------------
  4465. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4466. {
  4467. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4468. StoredSessions->NewSession(SessionName, SessionData);
  4469. // modified only, explicit
  4470. StoredSessions->Save(false, true);
  4471. // encode session name because of slashes in hierarchical sessions
  4472. return EncodeUrlString(SessionName);
  4473. }
  4474. //---------------------------------------------------------------------------
  4475. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4476. {
  4477. // current working directories become defaults here, what is not right
  4478. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4479. return SaveHiddenDuplicateSession(SessionData.get());
  4480. }
  4481. //---------------------------------------------------------------------------
  4482. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4483. {
  4484. if (OpenInNewWindow())
  4485. {
  4486. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4487. }
  4488. else
  4489. {
  4490. // current working directories become defaults here, what is not right
  4491. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4492. TTerminalManager * Manager = TTerminalManager::Instance();
  4493. TManagedTerminal * ATerminal = Manager->NewManagedTerminal(SessionData.get());
  4494. // We definitelly want this
  4495. ATerminal->Disconnected = Terminal->Disconnected;
  4496. // Not sure about these two
  4497. ATerminal->Permanent = Terminal->Permanent;
  4498. ATerminal->DisconnectedTemporarily = Terminal->DisconnectedTemporarily; // maybe
  4499. Manager->ActiveTerminal = ATerminal;
  4500. }
  4501. }
  4502. //---------------------------------------------------------------------------
  4503. void __fastcall TCustomScpExplorerForm::RenameSession()
  4504. {
  4505. UnicodeString Name = Terminal->SessionData->SessionName;
  4506. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4507. {
  4508. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4509. TSessionData::ValidateName(Name);
  4510. // This is inconsistent with how color (for example) is handled.
  4511. Terminal->SessionData->Name = Name;
  4512. UpdateControls();
  4513. // Add/Remove distinguishing paths from sessions of the same name.
  4514. DoTerminalListChanged();
  4515. }
  4516. }
  4517. //---------------------------------------------------------------------------
  4518. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4519. {
  4520. DebugAssert(Queue != NULL);
  4521. bool Result = Queue->IsEmpty;
  4522. if (!Result)
  4523. {
  4524. SetFocus();
  4525. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4526. }
  4527. return Result;
  4528. }
  4529. //---------------------------------------------------------------------------
  4530. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4531. {
  4532. return CanCloseQueue(FQueue);
  4533. }
  4534. //---------------------------------------------------------------------------
  4535. void __fastcall TCustomScpExplorerForm::CloseSession()
  4536. {
  4537. if (CanCloseQueue())
  4538. {
  4539. TTerminalManager::Instance()->FreeActiveTerminal();
  4540. }
  4541. }
  4542. //---------------------------------------------------------------------------
  4543. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4544. {
  4545. if (CanCloseQueue())
  4546. {
  4547. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4548. }
  4549. }
  4550. //---------------------------------------------------------------------------
  4551. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4552. {
  4553. DetachTerminal(Terminal);
  4554. RemoteDirView->Terminal = Terminal;
  4555. UpdateRemotePathComboBox(false);
  4556. UpdateControls();
  4557. }
  4558. //---------------------------------------------------------------------------
  4559. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4560. {
  4561. if (DebugAlwaysTrue(!Terminal->Active))
  4562. {
  4563. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4564. }
  4565. }
  4566. //---------------------------------------------------------------------------
  4567. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4568. {
  4569. if (OpenInNewWindow())
  4570. {
  4571. // encode session name because of slashes in hierarchical sessions
  4572. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4573. }
  4574. else
  4575. {
  4576. TTerminalManager * Manager = TTerminalManager::Instance();
  4577. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4578. Manager->ActiveTerminal = Terminal;
  4579. }
  4580. }
  4581. //---------------------------------------------------------------------------
  4582. void TCustomScpExplorerForm::DoOpenFolderOrWorkspace(
  4583. const UnicodeString & Name, bool ConnectFirstTerminal, bool CheckMaxSessions)
  4584. {
  4585. TTerminalManager * Manager = TTerminalManager::Instance();
  4586. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4587. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4588. if (!CheckMaxSessions || (DataList->Count <= WinConfiguration->MaxSessions))
  4589. {
  4590. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4591. // FirstTerminal can be null, if some of the
  4592. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4593. {
  4594. FirstTerminal->Disconnected = true;
  4595. FirstTerminal->DisconnectedTemporarily = true;
  4596. }
  4597. Manager->ActiveTerminal = FirstTerminal;
  4598. }
  4599. }
  4600. //---------------------------------------------------------------------------
  4601. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4602. {
  4603. if (OpenInNewWindow())
  4604. {
  4605. ExecuteNewInstance(Name);
  4606. }
  4607. else
  4608. {
  4609. DoOpenFolderOrWorkspace(Name, true, false);
  4610. }
  4611. }
  4612. //---------------------------------------------------------------------------
  4613. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4614. bool &CanClose)
  4615. {
  4616. // See the comment in CloseApp()
  4617. if (NonVisualDataModule->Busy)
  4618. {
  4619. CanClose = false;
  4620. }
  4621. else
  4622. {
  4623. TTerminalManager * Manager = TTerminalManager::Instance();
  4624. int ActiveSessions = 0;
  4625. for (int Index = 0; Index < Manager->Count; Index++)
  4626. {
  4627. if (Manager->Terminals[Index]->Active)
  4628. {
  4629. ActiveSessions++;
  4630. }
  4631. }
  4632. // Confirm, when there's at least one active remote session
  4633. if ((ActiveSessions > 0) &&
  4634. WinConfiguration->ConfirmClosingSession)
  4635. {
  4636. unsigned int Result;
  4637. TMessageParams Params(mpNeverAskAgainCheck);
  4638. UnicodeString Message;
  4639. int Answers = qaOK | qaCancel;
  4640. // The current session is the only active session
  4641. if ((ActiveSessions == 1) && (Terminal != NULL) && Terminal->Active)
  4642. {
  4643. if (!WinConfiguration->AutoSaveWorkspace)
  4644. {
  4645. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4646. }
  4647. else
  4648. {
  4649. Message = LoadStr(CLOSE_SESSION);
  4650. }
  4651. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4652. }
  4653. // Multiple active sessions or one active session, but it's not the current one
  4654. else if (DebugAlwaysTrue(ActiveSessions > 0))
  4655. {
  4656. if (!WinConfiguration->AutoSaveWorkspace)
  4657. {
  4658. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4659. }
  4660. else
  4661. {
  4662. Message = LoadStr(CLOSE_SESSIONS);
  4663. }
  4664. }
  4665. UnicodeString Note;
  4666. if (WinConfiguration->AutoSaveWorkspace)
  4667. {
  4668. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4669. }
  4670. else
  4671. {
  4672. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4673. Answers = qaYes | qaNo | qaCancel;
  4674. }
  4675. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4676. SetFocus();
  4677. Result = MessageDialog(Message, qtConfirmation,
  4678. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4679. if (Result == qaNeverAskAgain)
  4680. {
  4681. WinConfiguration->ConfirmClosingSession = false;
  4682. }
  4683. if (Result == qaNo)
  4684. {
  4685. CanClose = SaveWorkspace(true);
  4686. // note that the workspace will be saved redundatly again from FormClose
  4687. }
  4688. else
  4689. {
  4690. CanClose =
  4691. (Result == qaOK) ||
  4692. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4693. (Result == qaNeverAskAgain);
  4694. }
  4695. }
  4696. if (CanClose && HasActiveTerminal())
  4697. {
  4698. CanClose = CanCloseQueue();
  4699. }
  4700. }
  4701. if (CanClose)
  4702. {
  4703. CanClose =
  4704. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4705. FEditorManager->CloseExternalFilesWithoutProcess();
  4706. if (CanClose)
  4707. {
  4708. while (CanClose && (FLocalEditors->Count > 0))
  4709. {
  4710. int PrevCount = FLocalEditors->Count;
  4711. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4712. CanClose = (FLocalEditors->Count < PrevCount);
  4713. }
  4714. if (CanClose)
  4715. {
  4716. CanClose = FEditorManager->Empty(true);
  4717. if (!CanClose)
  4718. {
  4719. SetFocus();
  4720. CanClose =
  4721. (MessageDialog(
  4722. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4723. }
  4724. }
  4725. }
  4726. }
  4727. }
  4728. //---------------------------------------------------------------------------
  4729. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4730. {
  4731. TForm * Form = dynamic_cast<TForm *>(Sender);
  4732. DebugAssert(Form != NULL);
  4733. Form->Close();
  4734. }
  4735. //---------------------------------------------------------------------------
  4736. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4737. {
  4738. TForm * Form = dynamic_cast<TForm *>(Sender);
  4739. delete Form;
  4740. }
  4741. //---------------------------------------------------------------------------
  4742. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4743. {
  4744. while (FLocalEditors->Count > 0)
  4745. {
  4746. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4747. }
  4748. }
  4749. //---------------------------------------------------------------------------
  4750. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4751. TObject *Sender)
  4752. {
  4753. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4754. try
  4755. {
  4756. SetProperties(osRemote, FileList);
  4757. }
  4758. __finally
  4759. {
  4760. delete FileList;
  4761. }
  4762. }
  4763. //---------------------------------------------------------------------------
  4764. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4765. {
  4766. if (value)
  4767. {
  4768. if (Component == fcCustomCommandsBand)
  4769. {
  4770. UpdateCustomCommandsToolbar();
  4771. }
  4772. if (Component == fcQueueFileList)
  4773. {
  4774. DebugAssert(!QueueFileListSplitter->Visible);
  4775. AdjustQueueLayout();
  4776. UpdateQueueFileList();
  4777. }
  4778. }
  4779. }
  4780. //---------------------------------------------------------------------------
  4781. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4782. {
  4783. int MinHeightLimit =
  4784. GetStaticQueuePanelComponentsHeight() +
  4785. QueueFileListSplitter->Height +
  4786. QueueFileList->Height +
  4787. GetMinQueueViewHeight();
  4788. if (QueuePanel->ClientHeight < MinHeightLimit)
  4789. {
  4790. QueuePanel->ClientHeight = MinHeightLimit;
  4791. }
  4792. }
  4793. //---------------------------------------------------------------------------
  4794. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4795. {
  4796. TControl * Control = GetComponent(Component);
  4797. DebugAssert(Control);
  4798. bool Changed = (Control->Visible != value);
  4799. if (Changed)
  4800. {
  4801. ComponentShowing(Component, value);
  4802. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4803. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4804. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4805. if (value)
  4806. {
  4807. int RemainingHeight = Control->Parent->ClientHeight;
  4808. int RemainingWidth = Control->Parent->ClientWidth;
  4809. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4810. {
  4811. TControl * ChildControl = Control->Parent->Controls[i];
  4812. if (ChildControl->Visible)
  4813. {
  4814. switch (ChildControl->Align)
  4815. {
  4816. case alTop:
  4817. case alBottom:
  4818. RemainingHeight -= ChildControl->Height;
  4819. break;
  4820. case alLeft:
  4821. case alRight:
  4822. RemainingWidth -= ChildControl->Width;
  4823. break;
  4824. }
  4825. }
  4826. }
  4827. int Reserve = ScaleByTextHeight(this, 32);
  4828. // queue in explorer, trees in commander
  4829. if (Control->Height > RemainingHeight - Reserve)
  4830. {
  4831. Control->Height = RemainingHeight / 2;
  4832. }
  4833. if (Control->Width > RemainingWidth - Reserve)
  4834. {
  4835. Control->Width = RemainingWidth / 2;
  4836. }
  4837. }
  4838. Control->Visible = value;
  4839. if (WasFocused && Visible)
  4840. {
  4841. DirView(osCurrent)->SetFocus();
  4842. }
  4843. FixControlsPlacement();
  4844. }
  4845. }
  4846. //---------------------------------------------------------------------------
  4847. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4848. {
  4849. TControl * Control = GetComponent(Component);
  4850. if (Control == NULL)
  4851. {
  4852. return false;
  4853. }
  4854. else
  4855. {
  4856. return Control->Visible;
  4857. }
  4858. }
  4859. //---------------------------------------------------------------------------
  4860. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4861. {
  4862. bool Result;
  4863. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4864. {
  4865. Result = !IsUWP();
  4866. }
  4867. else
  4868. {
  4869. Result = true;
  4870. }
  4871. return Result;
  4872. }
  4873. //---------------------------------------------------------------------------
  4874. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4875. {
  4876. if (DirView(osOther)->ItemFocused != NULL)
  4877. {
  4878. DirView(osOther)->ItemFocused->MakeVisible(false);
  4879. }
  4880. QueueSplitter->Visible = QueuePanel->Visible;
  4881. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4882. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4883. TControl * QueueControlsOrder[] =
  4884. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4885. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4886. }
  4887. //---------------------------------------------------------------------------
  4888. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4889. {
  4890. switch (Component) {
  4891. case fcStatusBar: return RemoteStatusBar;
  4892. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4893. case fcQueueView: return QueuePanel;
  4894. case fcQueueToolbar: return QueueDock;
  4895. case fcRemoteTree: return RemoteDrivePanel;
  4896. case fcSessionsTabs: return SessionsPageControl;
  4897. case fcQueueFileList: return QueueFileList;
  4898. default: return NULL;
  4899. }
  4900. }
  4901. //---------------------------------------------------------------------------
  4902. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4903. TObject *Sender, TListColumn *Column, TPoint &Point)
  4904. {
  4905. DebugAssert(NonVisualDataModule && Column && Sender);
  4906. NonVisualDataModule->ListColumn = Column;
  4907. TPopupMenu * DirViewColumnMenu;
  4908. if (dynamic_cast<TUnixDirView *>(Sender) != NULL)
  4909. {
  4910. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4911. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4912. (Column->Index == uvName);
  4913. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4914. (Column->Index == uvSize);
  4915. }
  4916. else
  4917. {
  4918. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4919. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4920. (Column->Index == dvName);
  4921. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4922. (Column->Index == dvSize);
  4923. }
  4924. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4925. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4926. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4927. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4928. }
  4929. //---------------------------------------------------------------------------
  4930. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4931. TObject *Sender, TListItem *Item, bool &AllowExec)
  4932. {
  4933. DoDirViewExecFile(Sender, Item, AllowExec);
  4934. }
  4935. //---------------------------------------------------------------------------
  4936. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4937. TListItem * Item, bool & AllowExec)
  4938. {
  4939. DebugAssert(Sender && Item && Configuration);
  4940. DebugAssert(AllowExec);
  4941. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4942. bool Remote = (ADirView == DirView(osRemote)) && !IsSideLocalBrowser(osRemote);
  4943. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  4944. TOperationSide Side = (Remote ? osRemote : osLocal);
  4945. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4946. // on files only (not directories)
  4947. // and only when symlinks are resolved (apply to remote panel only)
  4948. if (!ADirView->ItemIsDirectory(Item) &&
  4949. (ResolvedSymlinks || FForceExecution))
  4950. {
  4951. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4952. !FForceExecution && ResolvedSymlinks)
  4953. {
  4954. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4955. {
  4956. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4957. UnlockWindow();
  4958. try
  4959. {
  4960. ExecuteFileOperation(
  4961. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4962. }
  4963. __finally
  4964. {
  4965. LockWindow();
  4966. }
  4967. AllowExec = false;
  4968. }
  4969. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4970. {
  4971. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4972. {
  4973. ExecuteFile(Side, efDefaultEditor);
  4974. AllowExec = false;
  4975. }
  4976. }
  4977. else
  4978. {
  4979. DebugFail();
  4980. }
  4981. }
  4982. // if we have not done anything special, fall back to default behavior
  4983. if (AllowExec)
  4984. {
  4985. if (Remote && !WinConfiguration->DisableOpenEdit)
  4986. {
  4987. ExecuteFile(osRemote, efShell);
  4988. AllowExec = false;
  4989. }
  4990. }
  4991. }
  4992. }
  4993. //---------------------------------------------------------------------------
  4994. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4995. {
  4996. return ((Side == osRemote) || (Side == osCurrent));
  4997. }
  4998. //---------------------------------------------------------------------------
  4999. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5000. {
  5001. DebugFail();
  5002. }
  5003. //---------------------------------------------------------------------------
  5004. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5005. {
  5006. DebugFail();
  5007. }
  5008. //---------------------------------------------------------------------------
  5009. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5010. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5011. {
  5012. TSynchronizeParamType Params;
  5013. Params.LocalDirectory = LocalDirectory;
  5014. Params.RemoteDirectory = RemoteDirectory;
  5015. int UnusedParams =
  5016. (GUIConfiguration->SynchronizeParams &
  5017. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5018. TTerminal::spCaseSensitive));
  5019. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5020. Params.Options = GUIConfiguration->SynchronizeOptions;
  5021. bool SaveSettings = false;
  5022. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5023. &DoSynchronizeTooManyDirectories);
  5024. DebugAssert(FSynchronizeController == NULL);
  5025. FSynchronizeController = &Controller;
  5026. bool Result;
  5027. try
  5028. {
  5029. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5030. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5031. int Options =
  5032. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5033. DebugAssert(FOnFeedSynchronizeError == NULL);
  5034. DebugAssert(FOnSynchronizeAbort == NULL);
  5035. DebugAssert(FSynchronizeTerminal == NULL);
  5036. FSynchronizeTerminal = Terminal;
  5037. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5038. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5039. FOnFeedSynchronizeError, FOnSynchronizeAbort, SynchronizeInNewWindow, UseDefaults);
  5040. if (Result)
  5041. {
  5042. if (SaveSettings)
  5043. {
  5044. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5045. GUIConfiguration->SynchronizeOptions = Params.Options;
  5046. }
  5047. else
  5048. {
  5049. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5050. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5051. FLAGSET(Params.Options, soSynchronize))
  5052. {
  5053. GUIConfiguration->SynchronizeOptions =
  5054. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5055. soSynchronize;
  5056. }
  5057. }
  5058. LocalDirectory = Params.LocalDirectory;
  5059. RemoteDirectory = Params.RemoteDirectory;
  5060. }
  5061. }
  5062. __finally
  5063. {
  5064. FSynchronizeController = NULL;
  5065. DebugAssert(FOnFeedSynchronizeError == NULL);
  5066. FOnFeedSynchronizeError = NULL;
  5067. DebugAssert(FOnSynchronizeAbort == NULL);
  5068. FOnSynchronizeAbort = NULL;
  5069. FSynchronizeTerminal = NULL;
  5070. }
  5071. return Result;
  5072. }
  5073. //---------------------------------------------------------------------------
  5074. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5075. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5076. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5077. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5078. TSynchronizeOptions * Options, bool Full)
  5079. {
  5080. // Keep-up-to-date mode
  5081. if (Terminal->Status == ssOpened)
  5082. {
  5083. try
  5084. {
  5085. int PParams = Params.Params;
  5086. if (!Full)
  5087. {
  5088. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5089. if (FLAGSET(Params.Options, soRecurse))
  5090. {
  5091. PParams |= TTerminal::spSubDirs;
  5092. }
  5093. }
  5094. else
  5095. {
  5096. // if keepuptodate is non-recursive,
  5097. // full sync before has to be non-recursive as well
  5098. if (FLAGCLEAR(Params.Options, soRecurse))
  5099. {
  5100. PParams |= TTerminal::spNoRecurse;
  5101. }
  5102. }
  5103. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5104. PParams, Checklist, Options);
  5105. }
  5106. catch (Exception & E)
  5107. {
  5108. if (!Terminal->Active)
  5109. {
  5110. ShowExtendedExceptionEx(Terminal, &E);
  5111. // Do not abort the "keep up to date" when the session was succesfully reconnected.
  5112. if (!Terminal->Active)
  5113. {
  5114. throw;
  5115. }
  5116. }
  5117. else
  5118. {
  5119. if (FLAGSET(Params.Options, soContinueOnError) &&
  5120. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5121. {
  5122. // noop, already logged in MoreMessageDialog
  5123. }
  5124. else
  5125. {
  5126. // We get mostly EAbort here, so this is noop.
  5127. // Exception is an error when listing directories while looking for differences.
  5128. ShowExtendedExceptionEx(Terminal, &E);
  5129. throw;
  5130. }
  5131. }
  5132. }
  5133. }
  5134. }
  5135. //---------------------------------------------------------------------------
  5136. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5137. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5138. const UnicodeString ErrorStr)
  5139. {
  5140. if (!Directory.IsEmpty())
  5141. {
  5142. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5143. }
  5144. else
  5145. {
  5146. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5147. }
  5148. }
  5149. //---------------------------------------------------------------------------
  5150. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5151. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5152. {
  5153. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5154. {
  5155. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5156. }
  5157. else
  5158. {
  5159. TMessageParams Params(mpNeverAskAgainCheck);
  5160. unsigned int Result = MessageDialog(
  5161. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5162. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5163. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5164. {
  5165. MaxDirectories *= 2;
  5166. if (Result == qaNeverAskAgain)
  5167. {
  5168. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5169. }
  5170. }
  5171. else
  5172. {
  5173. Abort();
  5174. }
  5175. }
  5176. }
  5177. //---------------------------------------------------------------------------
  5178. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5179. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5180. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5181. TSynchronizeOptions * Options)
  5182. {
  5183. // Keep-up-to-date mode
  5184. DebugAssert(!FAutoOperation);
  5185. void * BatchStorage;
  5186. BatchStart(BatchStorage);
  5187. FAutoOperation = true;
  5188. bool AnyOperation = false;
  5189. TDateTime StartTime = Now();
  5190. TSynchronizeChecklist * AChecklist = NULL;
  5191. try
  5192. {
  5193. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5194. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5195. {
  5196. FSynchronizeProgressForm->Start();
  5197. }
  5198. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5199. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5200. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5201. Options);
  5202. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5203. SAFE_DESTROY(FSynchronizeProgressForm);
  5204. AnyOperation = (AChecklist->CheckedCount > 0);
  5205. if (AnyOperation)
  5206. {
  5207. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5208. CreateProgressForm(&SynchronizeProgress);
  5209. try
  5210. {
  5211. Terminal->SynchronizeApply(
  5212. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5213. SynchronizeProcessedItem, NULL, NULL, NULL);
  5214. }
  5215. __finally
  5216. {
  5217. DestroyProgressForm();
  5218. }
  5219. }
  5220. }
  5221. __finally
  5222. {
  5223. if (Checklist == NULL)
  5224. {
  5225. delete AChecklist;
  5226. }
  5227. else
  5228. {
  5229. *Checklist = AChecklist;
  5230. }
  5231. FAutoOperation = false;
  5232. SAFE_DESTROY(FSynchronizeProgressForm);
  5233. BatchEnd(BatchStorage);
  5234. ReloadLocalDirectory();
  5235. if (AnyOperation)
  5236. {
  5237. OperationComplete(StartTime);
  5238. }
  5239. }
  5240. }
  5241. //---------------------------------------------------------------------------
  5242. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5243. {
  5244. // can be called from command line
  5245. return Visible &&
  5246. ((DirView(osRemote)->SelCount > 0) ||
  5247. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5248. }
  5249. //---------------------------------------------------------------------------
  5250. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5251. {
  5252. LogSynchronizeEvent(Terminal, Message);
  5253. }
  5254. //---------------------------------------------------------------------------
  5255. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5256. int Params, TSynchronizeOptions & Options)
  5257. {
  5258. DebugAssert(!IsLocalBrowserMode());
  5259. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5260. {
  5261. Options.Filter = new TStringList();
  5262. Options.Filter->CaseSensitive = false;
  5263. Options.Filter->Duplicates = Types::dupAccept;
  5264. if (DirView(osRemote)->SelCount > 0)
  5265. {
  5266. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5267. }
  5268. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5269. {
  5270. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5271. }
  5272. Options.Filter->Sort();
  5273. }
  5274. }
  5275. //---------------------------------------------------------------------------
  5276. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5277. {
  5278. TCopyParamType Defaults;
  5279. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5280. ConfigStorage->AccessMode = smRead;
  5281. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5282. {
  5283. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5284. }
  5285. ConfigStorage.reset(NULL);
  5286. std::unique_ptr<TStringList> Options(new TStringList());
  5287. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5288. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5289. UnicodeString Result;
  5290. if (Options->Count > 0)
  5291. {
  5292. Result =
  5293. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5294. }
  5295. return Result;
  5296. }
  5297. //---------------------------------------------------------------------------
  5298. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5299. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5300. {
  5301. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5302. UnicodeString AdditionalParams =
  5303. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5304. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5305. SerializeCopyParamForCommandLine(CopyParams),
  5306. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5307. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5308. ExecuteNewInstance(SessionName, AdditionalParams);
  5309. }
  5310. //---------------------------------------------------------------------------
  5311. struct TSynchronizeParams
  5312. {
  5313. UnicodeString LocalDirectory;
  5314. UnicodeString RemoteDirectory;
  5315. TSynchronizeMode Mode;
  5316. TSynchronizeChecklist * Checklist;
  5317. int Params;
  5318. TCopyParamType * CopyParam;
  5319. TDateTime CollectElapsed;
  5320. TDateTime * StartTime;
  5321. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5322. };
  5323. //---------------------------------------------------------------------------
  5324. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5325. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5326. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5327. {
  5328. DebugAssert(!FAutoOperation);
  5329. void * BatchStorage;
  5330. BatchStart(BatchStorage);
  5331. FAutoOperation = true;
  5332. TFileOperationStatistics Statistics;
  5333. TDateTime Start = Now();
  5334. try
  5335. {
  5336. Params.OnProcessedItem = OnProcessedItem;
  5337. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5338. CreateProgressForm(&SynchronizeProgress);
  5339. Terminal->SynchronizeApply(
  5340. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5341. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5342. &Statistics);
  5343. }
  5344. __finally
  5345. {
  5346. Params.OnProcessedItem = NULL;
  5347. FAutoOperation = false;
  5348. DestroyProgressForm();
  5349. BatchEnd(BatchStorage);
  5350. ReloadLocalDirectory();
  5351. }
  5352. if (WinConfiguration->SynchronizeSummary)
  5353. {
  5354. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5355. // The statistics should be 0 anyway in this case
  5356. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5357. {
  5358. Message += L"\n";
  5359. if (Statistics.FilesUploaded > 0)
  5360. {
  5361. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5362. }
  5363. if (Statistics.FilesDownloaded > 0)
  5364. {
  5365. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5366. }
  5367. if (Statistics.FilesDeletedLocal > 0)
  5368. {
  5369. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5370. }
  5371. if (Statistics.FilesDeletedRemote > 0)
  5372. {
  5373. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5374. }
  5375. }
  5376. TDateTime Elapsed = (Now() - Start);
  5377. Message +=
  5378. L"\n" +
  5379. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5380. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5381. TMessageParams Params(mpNeverAskAgainCheck);
  5382. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5383. if (Result == qaNeverAskAgain)
  5384. {
  5385. WinConfiguration->SynchronizeSummary = false;
  5386. }
  5387. }
  5388. }
  5389. //---------------------------------------------------------------------------
  5390. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5391. {
  5392. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5393. {
  5394. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5395. }
  5396. // Not set in keep-up-to-date mode - Synchronize() method
  5397. if (Token != NULL)
  5398. {
  5399. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5400. if (Params.OnProcessedItem != NULL)
  5401. {
  5402. Params.OnProcessedItem(NULL, ChecklistItem);
  5403. }
  5404. }
  5405. }
  5406. //---------------------------------------------------------------------------
  5407. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5408. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5409. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5410. {
  5411. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5412. *Params.StartTime = Now();
  5413. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5414. }
  5415. //---------------------------------------------------------------------------
  5416. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5417. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5418. {
  5419. // terminal can be already closed (e.g. dropped connection)
  5420. if (Terminal != NULL)
  5421. {
  5422. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5423. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5424. }
  5425. }
  5426. //---------------------------------------------------------------------------
  5427. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5428. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5429. {
  5430. DebugAssert(!IsLocalBrowserMode());
  5431. TAutoBatch AutoBatch(this);
  5432. TAutoFlag AutoOperationFlag(FAutoOperation);
  5433. if (Side == osRemote)
  5434. {
  5435. std::unique_ptr<TStrings> FileList(new TStringList());
  5436. FileList->AddObject(FileName, RemoteFile);
  5437. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5438. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5439. RemoteDirView->SaveSelection();
  5440. RemoteDirView->SaveSelectedNames();
  5441. try
  5442. {
  5443. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5444. }
  5445. catch(...)
  5446. {
  5447. RemoteDirView->DiscardSavedSelection();
  5448. throw;
  5449. }
  5450. RemoteDirView->RestoreSelection();
  5451. }
  5452. else if (DebugAlwaysTrue(Side == osLocal))
  5453. {
  5454. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5455. {
  5456. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5457. }
  5458. UnicodeString Directory = ExtractFileDir(FileName);
  5459. ReloadLocalDirectory(Directory);
  5460. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5461. if (!SamePaths(Directory, NewDirectory))
  5462. {
  5463. ReloadLocalDirectory(NewDirectory);
  5464. }
  5465. }
  5466. }
  5467. //---------------------------------------------------------------------------
  5468. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5469. {
  5470. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5471. if (Side == osLocal)
  5472. {
  5473. if (Action == TSynchronizeChecklist::saDownloadNew)
  5474. {
  5475. OpenFolderInExplorer(LocalPath);
  5476. }
  5477. else
  5478. {
  5479. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5480. }
  5481. }
  5482. else if (DebugAlwaysTrue(Side == osRemote))
  5483. {
  5484. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5485. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5486. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5487. if (!LocalPath.IsEmpty())
  5488. {
  5489. SessionData->LocalDirectory = LocalPath;
  5490. }
  5491. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5492. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5493. }
  5494. }
  5495. //---------------------------------------------------------------------------
  5496. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5497. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5498. const TCopyParamType * CopyParams)
  5499. {
  5500. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5501. UnicodeString AdditionalParams =
  5502. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5503. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5504. SerializeCopyParamForCommandLine(CopyParams),
  5505. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5506. LocalDirectory, RemoteDirectory, Mode, Params));
  5507. ExecuteNewInstance(SessionName, AdditionalParams);
  5508. }
  5509. //---------------------------------------------------------------------------
  5510. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5511. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5512. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5513. {
  5514. int Result;
  5515. bool SaveSettings = false;
  5516. int Options =
  5517. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5518. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5519. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5520. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5521. bool Continue =
  5522. (UseDefaults == 0) ||
  5523. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5524. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5525. if (Continue)
  5526. {
  5527. Configuration->Usage->Inc(L"Synchronizations");
  5528. UpdateCopyParamCounters(CopyParam);
  5529. TSynchronizeOptions SynchronizeOptions;
  5530. GetSynchronizeOptions(Params, SynchronizeOptions);
  5531. if (SaveSettings)
  5532. {
  5533. GUIConfiguration->SynchronizeParams = Params;
  5534. }
  5535. else
  5536. {
  5537. SaveMode = false;
  5538. }
  5539. TDateTime StartTime = Now();
  5540. TSynchronizeChecklist * Checklist = NULL;
  5541. try
  5542. {
  5543. DebugAssert(!FAutoOperation);
  5544. FAutoOperation = true;
  5545. try
  5546. {
  5547. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5548. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5549. int Files = -1;
  5550. if (DataList->Count >= 1)
  5551. {
  5552. Files = StrToIntDef(DataList->Strings[0], Files);
  5553. }
  5554. else
  5555. {
  5556. DataList->Add(UnicodeString());
  5557. }
  5558. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5559. FSynchronizeProgressForm->Start();
  5560. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5561. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5562. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5563. &SynchronizeOptions);
  5564. if (Terminal->SessionData->CacheDirectories)
  5565. {
  5566. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5567. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5568. }
  5569. }
  5570. __finally
  5571. {
  5572. FAutoOperation = false;
  5573. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5574. SAFE_DESTROY(FSynchronizeProgressForm);
  5575. }
  5576. TSynchronizeParams SynchronizeParams;
  5577. SynchronizeParams.LocalDirectory = LocalDirectory;
  5578. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5579. SynchronizeParams.Mode = Mode;
  5580. SynchronizeParams.CopyParam = &CopyParam;
  5581. SynchronizeParams.Params = Params;
  5582. SynchronizeParams.Checklist = Checklist;
  5583. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5584. SynchronizeParams.StartTime = &StartTime;
  5585. SynchronizeParams.OnProcessedItem = NULL;
  5586. Result = Checklist->Count;
  5587. if (Checklist->Count > 0)
  5588. {
  5589. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5590. {
  5591. if (!DoSynchronizeChecklistDialog(
  5592. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5593. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5594. {
  5595. Result = -1;
  5596. }
  5597. }
  5598. else
  5599. {
  5600. FullSynchronize(SynchronizeParams, NULL, NULL);
  5601. }
  5602. }
  5603. else
  5604. {
  5605. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5606. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5607. }
  5608. }
  5609. __finally
  5610. {
  5611. delete Checklist;
  5612. }
  5613. OperationComplete(StartTime);
  5614. }
  5615. else
  5616. {
  5617. Result = -1;
  5618. }
  5619. return Result;
  5620. }
  5621. //---------------------------------------------------------------------------
  5622. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5623. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5624. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5625. {
  5626. if (Collect)
  5627. {
  5628. DebugAssert(FSynchronizeProgressForm != NULL);
  5629. if (!FSynchronizeProgressForm->Started)
  5630. {
  5631. FSynchronizeProgressForm->Start();
  5632. }
  5633. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5634. SetTaskbarListProgressValue(CompareProgress);
  5635. }
  5636. else
  5637. {
  5638. DebugAssert(FSynchronizeProgressForm == NULL);
  5639. DebugAssert(FProgressForm != NULL);
  5640. }
  5641. }
  5642. //---------------------------------------------------------------------------
  5643. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5644. {
  5645. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5646. TRemoteFile * File = NULL;
  5647. Terminal->ReadFile(FullFileName, File);
  5648. if (File != NULL)
  5649. {
  5650. std::unique_ptr<TRemoteFile> FileOwner(File);
  5651. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5652. Application->ShowMainForm = false;
  5653. Application->Run();
  5654. }
  5655. }
  5656. //---------------------------------------------------------------------------
  5657. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5658. {
  5659. DebugFail();
  5660. }
  5661. //---------------------------------------------------------------------------
  5662. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5663. {
  5664. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5665. SessionData->Assign(Terminal->SessionData);
  5666. UpdateSessionData(SessionData.get());
  5667. if (Terminal->Active)
  5668. {
  5669. Terminal->UpdateSessionCredentials(SessionData.get());
  5670. }
  5671. if (!Terminal->SessionData->HasSessionName())
  5672. {
  5673. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5674. // once IsWorkspace is cleared
  5675. SessionData->Name = UnicodeString();
  5676. }
  5677. // Most uses of this method ends with saving the session, and we do not want to store the IsWorkspace flag.
  5678. // Particularly, with SaveHiddenDuplicateSession, it won't work as TSessionData::ParseUrl explicitly ignored workspace sessions.
  5679. SessionData->IsWorkspace = false;
  5680. return SessionData.release();
  5681. }
  5682. //---------------------------------------------------------------------------
  5683. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5684. {
  5685. TSessionData * SessionData = CloneCurrentSessionData();
  5686. try
  5687. {
  5688. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5689. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5690. }
  5691. __finally
  5692. {
  5693. delete SessionData;
  5694. }
  5695. }
  5696. //---------------------------------------------------------------------------
  5697. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5698. {
  5699. TTerminalManager * Manager = TTerminalManager::Instance();
  5700. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5701. if (DebugAlwaysTrue(Terminal != NULL))
  5702. {
  5703. // Update (Managed)Terminal->StateData
  5704. UpdateTerminal(Terminal);
  5705. }
  5706. Manager->SaveWorkspace(DataList.get());
  5707. return DataList.release();
  5708. }
  5709. //---------------------------------------------------------------------------
  5710. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5711. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5712. {
  5713. WinConfiguration->LastWorkspace = Name;
  5714. if (!SavePasswords)
  5715. {
  5716. for (int Index = 0; Index < DataList->Count; Index++)
  5717. {
  5718. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5719. if (SessionData->Link.IsEmpty())
  5720. {
  5721. SessionData->ClearSessionPasswords();
  5722. }
  5723. }
  5724. }
  5725. StoredSessions->NewWorkspace(Name, DataList);
  5726. // modified only
  5727. StoredSessions->Save(false, Explicit);
  5728. }
  5729. //---------------------------------------------------------------------------
  5730. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5731. {
  5732. return
  5733. DefaultStr(WinConfiguration->LastWorkspace,
  5734. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5735. }
  5736. //---------------------------------------------------------------------------
  5737. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5738. {
  5739. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5740. bool AnyNonStoredSessionWithPassword = false;
  5741. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5742. bool AllNonStoredSessionsAnonymous = true;
  5743. TTerminalManager * Manager = TTerminalManager::Instance();
  5744. for (int Index = 0; Index < DataList->Count; Index++)
  5745. {
  5746. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5747. if (SessionData->Link.IsEmpty())
  5748. {
  5749. if (SessionData->HasAnySessionPassword())
  5750. {
  5751. AnyNonStoredSessionWithPassword = true;
  5752. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5753. {
  5754. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5755. }
  5756. }
  5757. if (!SameText(SessionData->UserName, AnonymousUserName))
  5758. {
  5759. AllNonStoredSessionsAnonymous = false;
  5760. }
  5761. }
  5762. }
  5763. bool SavePasswords;
  5764. bool * PSavePasswords;
  5765. bool NotRecommendedSavingPasswords =
  5766. !CustomWinConfiguration->UseMasterPassword &&
  5767. !AllNonStoredSessionsAnonymous;
  5768. if (Configuration->DisablePasswordStoring ||
  5769. !AnyNonStoredSessionWithPassword)
  5770. {
  5771. PSavePasswords = NULL;
  5772. SavePasswords = false;
  5773. }
  5774. else
  5775. {
  5776. PSavePasswords = &SavePasswords;
  5777. SavePasswords =
  5778. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5779. !NotRecommendedSavingPasswords;
  5780. }
  5781. UnicodeString Name = WorkspaceName();
  5782. bool CreateShortcut = false;
  5783. bool Result =
  5784. DoSaveWorkspaceDialog(
  5785. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5786. EnableAutoSave);
  5787. if (Result)
  5788. {
  5789. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5790. if (CreateShortcut)
  5791. {
  5792. TOperationVisualizer Visualizer;
  5793. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5794. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5795. }
  5796. if (EnableAutoSave)
  5797. {
  5798. WinConfiguration->AutoSaveWorkspace = true;
  5799. WinConfiguration->AutoWorkspace = Name;
  5800. if (PSavePasswords != NULL)
  5801. {
  5802. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5803. }
  5804. }
  5805. }
  5806. return Result;
  5807. }
  5808. //---------------------------------------------------------------------------
  5809. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5810. {
  5811. DebugAssert(!IsLocalBrowserMode());
  5812. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5813. if (WinConfiguration->PreservePanelState)
  5814. {
  5815. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5816. }
  5817. UpdateSessionData(Terminal->StateData);
  5818. }
  5819. //---------------------------------------------------------------------------
  5820. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5821. {
  5822. // Keep in sync with TSessionData::CopyStateData
  5823. DebugAssert(!IsLocalBrowserMode());
  5824. DebugAssert(Data != NULL);
  5825. // This is inconsistent with how color (for example) is handled.
  5826. Data->Name = Terminal->SessionData->Name;
  5827. // cannot use RemoteDirView->Path, because it is empty if connection
  5828. // was already closed
  5829. // also only peek, we may not be connected at all atm
  5830. // so make sure we do not try retrieving current directory from the server
  5831. // (particularly with FTP)
  5832. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5833. if (!ACurrentDirectory.IsEmpty())
  5834. {
  5835. Data->RemoteDirectory = ACurrentDirectory;
  5836. }
  5837. Data->Color = SessionColor;
  5838. }
  5839. //---------------------------------------------------------------------------
  5840. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5841. {
  5842. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5843. DebugAssert(Toolbar != NULL);
  5844. for (int i = 0; i < Toolbar->Items->Count; i++)
  5845. {
  5846. TTBXCustomDropDownItem * DropDownItem;
  5847. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5848. if (DropDownItem != NULL)
  5849. {
  5850. ToolbarItemResize(DropDownItem,
  5851. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5852. Toolbar->NonClientWidth);
  5853. break;
  5854. }
  5855. }
  5856. }
  5857. //---------------------------------------------------------------------------
  5858. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5859. {
  5860. Item->EditWidth = Width;
  5861. }
  5862. //---------------------------------------------------------------------------
  5863. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5864. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5865. {
  5866. for (int i = 0; i < Toolbar->Items->Count; i++)
  5867. {
  5868. TTBXCustomDropDownItem * DropDownItem;
  5869. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5870. if (DropDownItem != NULL)
  5871. {
  5872. ASize.x -= DropDownItem->EditWidth;
  5873. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5874. }
  5875. }
  5876. }
  5877. //---------------------------------------------------------------------------
  5878. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5879. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5880. {
  5881. if (WinConfiguration->DDWarnLackOfTempSpace)
  5882. {
  5883. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5884. if (!ADrive.IsEmpty())
  5885. {
  5886. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5887. DebugAssert(RequiredSpace >= 0);
  5888. __int64 RequiredWithReserve;
  5889. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5890. if (FreeSpace < RequiredWithReserve)
  5891. {
  5892. unsigned int Result;
  5893. TMessageParams Params(mpNeverAskAgainCheck);
  5894. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5895. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5896. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5897. if (Result == qaNeverAskAgain)
  5898. {
  5899. WinConfiguration->DDWarnLackOfTempSpace = false;
  5900. }
  5901. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5902. }
  5903. }
  5904. }
  5905. }
  5906. //---------------------------------------------------------------------------
  5907. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5908. {
  5909. DoOpenDirectoryDialog(odAddBookmark, Side);
  5910. }
  5911. //---------------------------------------------------------------------------
  5912. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5913. {
  5914. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5915. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5916. try
  5917. {
  5918. TCustomDirView * DView = DirView(Side);
  5919. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5920. {
  5921. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5922. }
  5923. }
  5924. catch (...)
  5925. {
  5926. delete VisitedDirectories;
  5927. throw;
  5928. }
  5929. return VisitedDirectories;
  5930. }
  5931. //---------------------------------------------------------------------------
  5932. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5933. TOpenDirectoryMode Mode, TOperationSide Side)
  5934. {
  5935. bool Continue = true;
  5936. if (Mode == odAddBookmark)
  5937. {
  5938. TMessageParams Params(mpNeverAskAgainCheck);
  5939. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5940. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5941. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5942. unsigned int Answer =
  5943. MessageDialog(Message,
  5944. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5945. if (Answer == qaNeverAskAgain)
  5946. {
  5947. Continue = true;
  5948. WinConfiguration->UseSharedBookmarks = true;
  5949. }
  5950. else if (Answer == qaOK)
  5951. {
  5952. Continue = true;
  5953. WinConfiguration->UseSharedBookmarks = false;
  5954. }
  5955. else
  5956. {
  5957. Continue = false;
  5958. }
  5959. }
  5960. if (Continue)
  5961. {
  5962. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5963. try
  5964. {
  5965. UnicodeString Name = DirView(Side)->PathName;
  5966. bool Repeat;
  5967. do
  5968. {
  5969. Repeat = false;
  5970. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5971. // do not allow switching to location profiles,
  5972. // if we are not connected
  5973. HasDirView[osLocal] && (Terminal != NULL)))
  5974. {
  5975. TWindowLock Lock(this);
  5976. if (!TryOpenDirectory(Side, Name))
  5977. {
  5978. Repeat = true;
  5979. Mode = odBrowse;
  5980. }
  5981. }
  5982. }
  5983. while (Repeat);
  5984. }
  5985. __finally
  5986. {
  5987. delete VisitedDirectories;
  5988. }
  5989. }
  5990. }
  5991. //---------------------------------------------------------------------------
  5992. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5993. {
  5994. DebugAssert(!FTerminal->CommandSessionOpened);
  5995. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5996. }
  5997. //---------------------------------------------------------------------------
  5998. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5999. {
  6000. bool Result = FTerminal->IsCapable[Capability] ||
  6001. FTerminal->CommandSessionOpened;
  6002. if (!Result)
  6003. {
  6004. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  6005. if (!GUIConfiguration->ConfirmCommandSession)
  6006. {
  6007. Result = true;
  6008. }
  6009. else
  6010. {
  6011. TMessageParams Params(mpNeverAskAgainCheck);
  6012. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6013. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6014. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6015. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6016. if (Answer == qaNeverAskAgain)
  6017. {
  6018. GUIConfiguration->ConfirmCommandSession = false;
  6019. Result = true;
  6020. }
  6021. else if (Answer == qaOK)
  6022. {
  6023. Result = true;
  6024. }
  6025. }
  6026. if (Result)
  6027. {
  6028. Result = CommandSessionFallback();
  6029. }
  6030. }
  6031. return Result;
  6032. }
  6033. //---------------------------------------------------------------------------
  6034. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6035. {
  6036. if (EnsureCommandSessionFallback(fcAnyCommand))
  6037. {
  6038. DoConsoleDialog(Terminal, Command);
  6039. }
  6040. }
  6041. //---------------------------------------------------------------------------
  6042. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6043. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6044. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6045. {
  6046. if (!IsSideLocalBrowser(osRemote) &&
  6047. IsFileControl(DropSourceControl, osRemote) &&
  6048. (FDDExtMapFile != NULL))
  6049. {
  6050. Accept = true;
  6051. }
  6052. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6053. DebugAssert(FDDTargetControl != NULL);
  6054. }
  6055. //---------------------------------------------------------------------------
  6056. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6057. _di_IDataObject DataObj, int KeyState,
  6058. const TPoint & Point, int & Effect, bool & Accept)
  6059. {
  6060. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6061. }
  6062. //---------------------------------------------------------------------------
  6063. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6064. _di_IDataObject DataObj, int KeyState,
  6065. const TPoint & Point, int & Effect, bool & Accept)
  6066. {
  6067. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6068. }
  6069. //---------------------------------------------------------------------------
  6070. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6071. TObject * Sender)
  6072. {
  6073. DebugUsedParam(Sender);
  6074. DebugAssert(FDDTargetControl == Sender);
  6075. FDDTargetControl = NULL;
  6076. }
  6077. //---------------------------------------------------------------------------
  6078. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6079. {
  6080. FileControlDDDragLeave(SessionsPageControl);
  6081. }
  6082. //---------------------------------------------------------------------------
  6083. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6084. {
  6085. FileControlDDDragLeave(QueueView3);
  6086. }
  6087. //---------------------------------------------------------------------------
  6088. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6089. {
  6090. DebugAssert(!IsSideLocalBrowser(Side));
  6091. DebugUsedParam(Side);
  6092. bool Edit = false;
  6093. TRemoteFile * File = NULL;
  6094. UnicodeString FileName;
  6095. UnicodeString PointTo;
  6096. bool SymbolicLink = true;
  6097. if (RemoteDirView->ItemFocused)
  6098. {
  6099. DebugAssert(RemoteDirView->ItemFocused->Data);
  6100. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6101. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6102. if (Edit)
  6103. {
  6104. FileName = File->FileName;
  6105. PointTo = File->LinkTo;
  6106. }
  6107. else
  6108. {
  6109. PointTo = File->FileName;
  6110. }
  6111. }
  6112. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6113. Terminal->IsCapable[fcHardLink]))
  6114. {
  6115. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6116. if (Edit)
  6117. {
  6118. DebugAssert(File->FileName == FileName);
  6119. int Params = dfNoRecursive;
  6120. Terminal->ExceptionOnFail = true;
  6121. try
  6122. {
  6123. Terminal->DeleteFile(L"", File, &Params);
  6124. }
  6125. __finally
  6126. {
  6127. Terminal->ExceptionOnFail = false;
  6128. }
  6129. }
  6130. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6131. }
  6132. }
  6133. //---------------------------------------------------------------------------
  6134. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6135. {
  6136. return
  6137. (IsSideLocalBrowser(Side) ||
  6138. (HasActiveTerminal() &&
  6139. Terminal->ResolvingSymlinks &&
  6140. Terminal->IsCapable[fcSymbolicLink]));
  6141. }
  6142. //---------------------------------------------------------------------------
  6143. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6144. {
  6145. return
  6146. !IsSideLocalBrowser(FCurrentSide) &&
  6147. (RemoteDirView->ItemFocused != NULL) &&
  6148. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6149. Terminal->SessionData->ResolveSymlinks;
  6150. }
  6151. //---------------------------------------------------------------------------
  6152. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6153. {
  6154. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6155. FForceExecution = true;
  6156. try
  6157. {
  6158. DirView(osCurrent)->ExecuteCurrentFile();
  6159. }
  6160. __finally
  6161. {
  6162. FForceExecution = false;
  6163. }
  6164. }
  6165. //---------------------------------------------------------------------------
  6166. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6167. {
  6168. TEditorData ExternalEditor;
  6169. ExternalEditor.Editor = edExternal;
  6170. bool Remember = false;
  6171. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6172. {
  6173. if (Remember)
  6174. {
  6175. TEditorList * EditorList = new TEditorList;
  6176. try
  6177. {
  6178. *EditorList = *WinConfiguration->EditorList;
  6179. bool Found = false;
  6180. int i = 0;
  6181. while (!Found && (i < EditorList->Count))
  6182. {
  6183. const TEditorPreferences * Editor = EditorList->Editors[i];
  6184. if ((Editor->Data->Editor == edExternal) &&
  6185. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6186. {
  6187. Found = true;
  6188. }
  6189. i++;
  6190. }
  6191. if (!Found)
  6192. {
  6193. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6194. WinConfiguration->EditorList = EditorList;
  6195. }
  6196. }
  6197. __finally
  6198. {
  6199. delete EditorList;
  6200. }
  6201. }
  6202. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6203. }
  6204. }
  6205. //---------------------------------------------------------------------------
  6206. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6207. {
  6208. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6209. if (FFileFindTerminal == ATerminal)
  6210. {
  6211. FFileFindTerminal = NULL;
  6212. HideFileFindDialog();
  6213. }
  6214. if (FClipboardTerminal == ATerminal)
  6215. {
  6216. ClipboardClear(); // implies ClipboardStop
  6217. }
  6218. if ((FOnSynchronizeAbort != NULL) &&
  6219. (ATerminal == FTerminal))
  6220. {
  6221. FOnSynchronizeAbort(NULL);
  6222. }
  6223. }
  6224. //---------------------------------------------------------------------------
  6225. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6226. {
  6227. DetachTerminal(Sender);
  6228. }
  6229. //---------------------------------------------------------------------------
  6230. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6231. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6232. {
  6233. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6234. DebugAssert(Terminal != NULL);
  6235. if (Data->Terminal == Terminal)
  6236. {
  6237. Data->Terminal = NULL;
  6238. }
  6239. }
  6240. //---------------------------------------------------------------------------
  6241. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6242. {
  6243. UpdateControls();
  6244. SessionColor = TColor(0);
  6245. UpdateRemotePathComboBox(false);
  6246. NeedSession(false);
  6247. }
  6248. //---------------------------------------------------------------------------
  6249. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6250. {
  6251. try
  6252. {
  6253. // Cache, as the login dialog can change its value
  6254. // See also DoShow. Also see TTerminalManager::NewSession.
  6255. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6256. try
  6257. {
  6258. if (ShowLogin)
  6259. {
  6260. bool ReloadSessions = !Startup;
  6261. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this);
  6262. }
  6263. else if (Startup && WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6264. // This detects if workspace was saved the last time the main widow was closed
  6265. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6266. {
  6267. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false, true);
  6268. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6269. }
  6270. }
  6271. __finally
  6272. {
  6273. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6274. // (so there was no chance for the user to open any session yet)
  6275. if ((ShowLogin || !Startup) &&
  6276. !WinConfiguration->KeepOpenWhenNoSession &&
  6277. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6278. {
  6279. TerminateApplication();
  6280. }
  6281. }
  6282. }
  6283. catch (EAbort &)
  6284. {
  6285. // swallow
  6286. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6287. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6288. }
  6289. }
  6290. //---------------------------------------------------------------------------
  6291. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6292. {
  6293. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6294. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6295. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6296. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6297. try
  6298. {
  6299. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6300. // Clear the design time unthemed tab
  6301. ((SessionsPageControl->PageCount > 0) &&
  6302. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6303. {
  6304. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6305. }
  6306. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6307. {
  6308. TThemeTabSheet * TabSheet;
  6309. if (Index >= SessionsPageControl->PageCount)
  6310. {
  6311. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6312. TabSheet->PageControl = SessionsPageControl;
  6313. }
  6314. else
  6315. {
  6316. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6317. }
  6318. bool IsSessionTab = (Index < TerminalList->Count);
  6319. if (IsSessionTab)
  6320. {
  6321. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6322. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6323. UpdateSessionTab(TabSheet);
  6324. }
  6325. else
  6326. {
  6327. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6328. TabSheet->Tag = 0; // not really needed
  6329. TabSheet->Shadowed = false;
  6330. // 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)
  6331. UpdateNewSessionTab();
  6332. }
  6333. TabSheet->ShowCloseButton = IsSessionTab;
  6334. }
  6335. }
  6336. __finally
  6337. {
  6338. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6339. }
  6340. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6341. }
  6342. //---------------------------------------------------------------------------
  6343. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6344. {
  6345. DoTerminalListChanged();
  6346. }
  6347. //---------------------------------------------------------------------------
  6348. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6349. {
  6350. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6351. DebugAssert(TabSheet->ImageIndex == 0);
  6352. TabSheet->Caption =
  6353. WinConfiguration->SelectiveToolbarText ?
  6354. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6355. UnicodeString();
  6356. }
  6357. //---------------------------------------------------------------------------
  6358. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6359. {
  6360. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6361. }
  6362. //---------------------------------------------------------------------------
  6363. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6364. {
  6365. if (DebugAlwaysTrue(TabSheet != NULL))
  6366. {
  6367. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6368. if (DebugAlwaysTrue(ATerminal != NULL))
  6369. {
  6370. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6371. TabSheet->ImageIndex = AddSessionColor(Color);
  6372. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6373. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6374. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6375. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6376. {
  6377. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6378. }
  6379. }
  6380. }
  6381. }
  6382. //---------------------------------------------------------------------------
  6383. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6384. {
  6385. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6386. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6387. bool Result = (Terminal != NULL);
  6388. if (Result)
  6389. {
  6390. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6391. }
  6392. else
  6393. {
  6394. try
  6395. {
  6396. NewSession();
  6397. }
  6398. __finally
  6399. {
  6400. DoTerminalListChanged();
  6401. }
  6402. FSessionsPageControlNewSessionTime = Now();
  6403. }
  6404. return Result;
  6405. }
  6406. //---------------------------------------------------------------------------
  6407. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6408. {
  6409. SessionTabSwitched();
  6410. }
  6411. //---------------------------------------------------------------------------
  6412. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6413. {
  6414. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6415. DebugAssert(TransferList != NULL);
  6416. UnicodeString Name;
  6417. if (TransferList->ItemIndex <= 0)
  6418. {
  6419. Name = L"";
  6420. }
  6421. else
  6422. {
  6423. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6424. }
  6425. if (FCopyParamAutoSelected.IsEmpty())
  6426. {
  6427. // if previous preset was not autoselected, make new preset the "default"
  6428. FCopyParamDefault = Name;
  6429. }
  6430. GUIConfiguration->CopyParamCurrent = Name;
  6431. }
  6432. //---------------------------------------------------------------------------
  6433. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6434. {
  6435. // sanity check
  6436. bool ExistingPreset =
  6437. (FTransferListHoverIndex >= 0) &&
  6438. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6439. DebugAssert(ExistingPreset);
  6440. if (ExistingPreset)
  6441. {
  6442. HDC DC = GetDC(0);
  6443. TCanvas * Canvas = new TCanvas();
  6444. try
  6445. {
  6446. Canvas->Handle = DC;
  6447. Canvas->Font = GetToolbarFont(this);
  6448. UnicodeString Name;
  6449. if (FTransferListHoverIndex == 0)
  6450. {
  6451. Name = L"";
  6452. }
  6453. else
  6454. {
  6455. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6456. }
  6457. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6458. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6459. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6460. static_cast<TObject*>(GetComponent(fcTransferList)));
  6461. UnicodeString InfoStr =
  6462. GUIConfiguration->CopyParamPreset[Name].
  6463. GetInfoStr(L"; ",
  6464. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6465. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6466. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6467. {
  6468. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6469. {
  6470. InfoStr.SetLength(InfoStr.Length() - 1);
  6471. }
  6472. InfoStr += Ellipsis;
  6473. }
  6474. // UpdateCaption does not cause invalidation of whole submenu, while
  6475. // setting Caption property does.
  6476. // also it probably does not resize the label, even if necessary
  6477. // (we do not want that anyway)
  6478. TransferLabel->UpdateCaption(InfoStr);
  6479. }
  6480. __finally
  6481. {
  6482. Canvas->Handle = NULL;
  6483. ReleaseDC(0, DC);
  6484. delete Canvas;
  6485. }
  6486. }
  6487. }
  6488. //---------------------------------------------------------------------------
  6489. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6490. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6491. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6492. {
  6493. if (FTransferListHoverIndex != AHoverIndex)
  6494. {
  6495. FTransferListHoverIndex = AHoverIndex;
  6496. UpdateTransferLabel();
  6497. }
  6498. }
  6499. //---------------------------------------------------------------------------
  6500. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6501. {
  6502. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6503. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6504. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6505. {
  6506. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6507. {
  6508. if (!NonVisualDataModule->Busy)
  6509. {
  6510. OpenDirectory(GetSide(osCurrent));
  6511. }
  6512. Message.Result = 1;
  6513. }
  6514. else
  6515. {
  6516. TForm::Dispatch(&Message);
  6517. }
  6518. }
  6519. else
  6520. {
  6521. TForm::Dispatch(&Message);
  6522. }
  6523. }
  6524. //---------------------------------------------------------------------------
  6525. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6526. {
  6527. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6528. if ((FIgnoreNextDialogChar != 0) &&
  6529. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6530. {
  6531. Message.Result = 1;
  6532. }
  6533. else
  6534. {
  6535. TForm::Dispatch(&Message);
  6536. }
  6537. FIgnoreNextDialogChar = 0;
  6538. }
  6539. //---------------------------------------------------------------------------
  6540. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6541. {
  6542. // The four low-order bits are used internally by Windows
  6543. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6544. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6545. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6546. // 61730 - restore thru double click - undocumented
  6547. // 61490 - maximize thru double click - undocumented
  6548. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6549. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6550. {
  6551. SysResizing(Cmd);
  6552. }
  6553. TForm::Dispatch(&Message);
  6554. }
  6555. //---------------------------------------------------------------------------
  6556. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6557. {
  6558. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6559. // Also there no point returning TRUE as we are not able to
  6560. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6561. // Hence the process termination might be safer :)
  6562. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6563. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6564. {
  6565. Message.Result = FALSE;
  6566. }
  6567. else
  6568. {
  6569. Message.Result = TRUE;
  6570. }
  6571. // Do not call default handling as that triggers OnCloseQuery,
  6572. // where our implementation will popup confirmation dialogs, what we do not want,
  6573. // as per Vista guidelines:
  6574. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6575. }
  6576. //---------------------------------------------------------------------------
  6577. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6578. {
  6579. if (Message.EndSession && IsApplicationMinimized())
  6580. {
  6581. // WORKAROUND
  6582. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6583. // when it receives WM_ENDSESSION,
  6584. // but that sometimes (particularly when application is minimized) cause crashes.
  6585. // Crash popups message that blocks log off.
  6586. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6587. // so we call ExitProcess() immediately, not even trying to cleanup.
  6588. // It still causes beep, so there's likely some popup, but it does not block
  6589. // log off.
  6590. ExitProcess(0);
  6591. }
  6592. TForm::Dispatch(&Message);
  6593. }
  6594. #ifdef _DEBUG
  6595. //---------------------------------------------------------------------------
  6596. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6597. {
  6598. TForm::Dispatch(&Message);
  6599. }
  6600. #endif
  6601. //---------------------------------------------------------------------------
  6602. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6603. {
  6604. }
  6605. //---------------------------------------------------------------------------
  6606. void __fastcall TCustomScpExplorerForm::DoShow()
  6607. {
  6608. // only now are the controls resized finally, so the size constraints
  6609. // will not conflict with possibly very small window size
  6610. RestoreFormParams();
  6611. // This indicates that the form was rescaled after parameters were loaded and
  6612. // as most probably the parameters were actually saved with the current form scaling
  6613. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6614. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6615. // and no rounding problems will occur.
  6616. // See also RestoreForm.
  6617. // (we should be safe to call RestoreParams unconditionally)
  6618. if (PixelsPerInch != Screen->PixelsPerInch)
  6619. {
  6620. RestoreParams();
  6621. }
  6622. FixControlsPlacement();
  6623. if (Position == poDefaultPosOnly)
  6624. {
  6625. CutFormToDesktop(this);
  6626. }
  6627. TForm::DoShow();
  6628. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6629. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6630. if (Terminal == NULL)
  6631. {
  6632. StartingDisconnected();
  6633. }
  6634. UpdatePixelsPerInchMainWindowCounter();
  6635. FShowing = true;
  6636. }
  6637. //---------------------------------------------------------------------------
  6638. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6639. {
  6640. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6641. }
  6642. //---------------------------------------------------------------------------
  6643. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6644. {
  6645. DoTerminalListChanged();
  6646. }
  6647. //---------------------------------------------------------------------------
  6648. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6649. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6650. TNotifyEvent OnBalloonClick, TObject * UserData)
  6651. {
  6652. bool Do;
  6653. UnicodeString Message;
  6654. if (E == NULL)
  6655. {
  6656. Message = Str;
  6657. Do = true;
  6658. }
  6659. else
  6660. {
  6661. Do = ExceptionMessage(E, Message);
  6662. }
  6663. if (Do && WinConfiguration->BalloonNotifications)
  6664. {
  6665. UnicodeString Title;
  6666. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6667. {
  6668. Message = TrimLeft(Message);
  6669. }
  6670. else
  6671. {
  6672. Message = UnformatMessage(Message);
  6673. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6674. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6675. Title = LoadResourceString(Captions[Type]);
  6676. if (Terminal != NULL)
  6677. {
  6678. Title = FORMAT(L"%s - %s",
  6679. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6680. }
  6681. }
  6682. if (Seconds == 0)
  6683. {
  6684. Seconds = WinConfiguration->NotificationsTimeout;
  6685. }
  6686. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6687. }
  6688. }
  6689. //---------------------------------------------------------------------------
  6690. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6691. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6692. UnicodeString HelpKeyword, const TMessageParams * Params,
  6693. TTerminal * Terminal)
  6694. {
  6695. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6696. (FOnFeedSynchronizeError != NULL)) &&
  6697. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6698. {
  6699. if (FOnFeedSynchronizeError != NULL)
  6700. {
  6701. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6702. }
  6703. else
  6704. {
  6705. DebugAssert(FErrorList != NULL);
  6706. TStringList * MoreMessagesCopy = NULL;
  6707. if (MoreMessages)
  6708. {
  6709. MoreMessagesCopy = new TStringList();
  6710. MoreMessagesCopy->Assign(MoreMessages);
  6711. }
  6712. FErrorList->AddObject(Message, MoreMessagesCopy);
  6713. }
  6714. PopupTrayBalloon(Terminal, Message, Type);
  6715. return ContinueAnswer(Answers);
  6716. }
  6717. else
  6718. {
  6719. bool UseBalloon = FTrayIcon->Visible;
  6720. if (UseBalloon)
  6721. {
  6722. PopupTrayBalloon(Terminal, Message, Type);
  6723. }
  6724. unsigned int Result;
  6725. try
  6726. {
  6727. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6728. }
  6729. __finally
  6730. {
  6731. // cancel only balloon we popped up, otherwise we may cancel notification
  6732. // balloon that was there before the message dialog
  6733. // (such as "dd confirmation opt in balloon)
  6734. if (UseBalloon)
  6735. {
  6736. FTrayIcon->CancelBalloon();
  6737. }
  6738. }
  6739. return Result;
  6740. }
  6741. }
  6742. //---------------------------------------------------------------------------
  6743. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6744. TTerminal * Terminal, Exception * E)
  6745. {
  6746. if (FTrayIcon->Visible)
  6747. {
  6748. PopupTrayBalloon(Terminal, L"", qtError, E);
  6749. }
  6750. // particularly prevent opening new session from jump list,
  6751. // while exception is shown
  6752. NonVisualDataModule->StartBusy();
  6753. try
  6754. {
  6755. ShowExtendedExceptionEx(Terminal, E);
  6756. }
  6757. __finally
  6758. {
  6759. NonVisualDataModule->EndBusy();
  6760. FTrayIcon->CancelBalloon();
  6761. }
  6762. }
  6763. //---------------------------------------------------------------------------
  6764. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6765. {
  6766. if (Terminal->Active)
  6767. {
  6768. InitStatusBar();
  6769. }
  6770. // cannot rely on active page being page for active terminal,
  6771. // as it can happen that active page is the "new session" page
  6772. // (e.g. when reconnecting active terminal, while login dialog
  6773. // invoked from "new session" page is modal)
  6774. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6775. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6776. }
  6777. //---------------------------------------------------------------------------
  6778. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6779. TTerminal * Terminal, Exception * E)
  6780. {
  6781. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6782. if (!Terminal->Active)
  6783. {
  6784. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6785. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6786. {
  6787. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6788. }
  6789. }
  6790. }
  6791. //---------------------------------------------------------------------------
  6792. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6793. UnicodeString Message, TQueryType Type,
  6794. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6795. {
  6796. if ((E == NULL) ||
  6797. ExceptionMessage(E, Message))
  6798. {
  6799. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6800. if (Important)
  6801. {
  6802. Seconds *= 5;
  6803. }
  6804. UnicodeString NoteMessage(UnformatMessage(Message));
  6805. if (Terminal != NULL)
  6806. {
  6807. NoteMessage = FORMAT(L"%s: %s",
  6808. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6809. }
  6810. if (WinConfiguration->BalloonNotifications)
  6811. {
  6812. AddNote(NoteMessage);
  6813. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6814. }
  6815. else
  6816. {
  6817. FlashOnBackground();
  6818. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6819. }
  6820. }
  6821. }
  6822. //---------------------------------------------------------------------------
  6823. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6824. {
  6825. RestoreApp();
  6826. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6827. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6828. !NonVisualDataModule->Busy)
  6829. {
  6830. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6831. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6832. if (!ComponentVisible[fcQueueView])
  6833. {
  6834. ToggleQueueVisibility();
  6835. GoToQueue();
  6836. }
  6837. }
  6838. }
  6839. //---------------------------------------------------------------------------
  6840. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6841. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6842. {
  6843. UnicodeString Message;
  6844. TNotifyEvent OnClick = NULL;
  6845. TObject * UserData = NULL;
  6846. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6847. switch (Event)
  6848. {
  6849. case qeEmptyButMonitored:
  6850. if ((ATerminal != Terminal) || QueueInvisible)
  6851. {
  6852. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6853. OnClick = QueueEmptyNoteClicked;
  6854. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6855. TerminalNoteData->Terminal = ATerminal;
  6856. UserData = TerminalNoteData;
  6857. }
  6858. break;
  6859. case qeEmpty:
  6860. OperationComplete(ATerminal->QueueOperationStart);
  6861. break;
  6862. case qePendingUserAction:
  6863. if ((ATerminal != Terminal) ||
  6864. (QueueInvisible && !IsQueueAutoPopup()))
  6865. {
  6866. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6867. }
  6868. break;
  6869. default:
  6870. DebugFail();
  6871. }
  6872. if (!Message.IsEmpty())
  6873. {
  6874. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6875. }
  6876. }
  6877. //---------------------------------------------------------------------------
  6878. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6879. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6880. {
  6881. if (FDDExtMapFile != NULL)
  6882. {
  6883. CloseHandle(FDDExtMapFile);
  6884. FDDExtMapFile = NULL;
  6885. }
  6886. if (WinConfiguration->DDFakeFile)
  6887. {
  6888. DDFakeFileInitDrag(FileList, Created);
  6889. }
  6890. }
  6891. //---------------------------------------------------------------------------
  6892. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6893. {
  6894. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6895. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6896. {
  6897. FFakeFileDropTarget = FileName;
  6898. }
  6899. }
  6900. //---------------------------------------------------------------------------
  6901. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6902. {
  6903. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6904. if (!ForceDirectories(ApiPath(Result)))
  6905. {
  6906. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6907. }
  6908. FileSetAttr(ApiPath(Result), faHidden);
  6909. return Result;
  6910. }
  6911. //---------------------------------------------------------------------------
  6912. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6913. bool & Created)
  6914. {
  6915. FFakeFileDropTarget = UnicodeString();
  6916. FDragFakeDirectory = CreateFakeTransferDirectory();
  6917. FileList->AddItem(NULL, FDragFakeDirectory);
  6918. Created = true;
  6919. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6920. {
  6921. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6922. }
  6923. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6924. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6925. {
  6926. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6927. TDragExtCommStruct* CommStruct;
  6928. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6929. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6930. DebugAssert(CommStruct != NULL);
  6931. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6932. CommStruct->Dragging = true;
  6933. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6934. LENOF(CommStruct->DropDest));
  6935. NULL_TERMINATE(CommStruct->DropDest);
  6936. UnmapViewOfFile(CommStruct);
  6937. }
  6938. }
  6939. //---------------------------------------------------------------------------
  6940. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6941. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6942. {
  6943. bool Result;
  6944. DebugAssert(!IsLocalBrowserMode());
  6945. if (Sender == RemoteDirView)
  6946. {
  6947. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6948. }
  6949. else
  6950. {
  6951. DebugAssert(Sender == RemoteDriveView);
  6952. TStrings * FileList = RemoteDriveView->DragFileList();
  6953. try
  6954. {
  6955. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6956. }
  6957. __finally
  6958. {
  6959. delete FileList;
  6960. }
  6961. }
  6962. if (FDDTargetControl == RemoteDriveView)
  6963. {
  6964. RemoteDriveView->UpdateDropTarget();
  6965. }
  6966. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6967. // or from tree view to dir view.
  6968. // foMove happens when file/dir is dragged from remote tree view outside of
  6969. // application via dragex
  6970. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6971. (DropSourceControl == RemoteDriveView))
  6972. {
  6973. RemoteDriveView->UpdateDropSource();
  6974. }
  6975. return Result;
  6976. }
  6977. //---------------------------------------------------------------------------
  6978. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6979. {
  6980. DebugAssert(!IsLocalBrowserMode());
  6981. // This also handles drops of remote files to queue.
  6982. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6983. SAFE_DESTROY(FDDFileList);
  6984. if (!FFakeFileDropTarget.IsEmpty())
  6985. {
  6986. RemoveDir(ApiPath(FFakeFileDropTarget));
  6987. }
  6988. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6989. {
  6990. try
  6991. {
  6992. TDragResult DDResult = (Sender == RemoteDirView) ?
  6993. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6994. // Focus is moved to the target application,
  6995. // but as we are going to present the UI, we need to steal the focus back.
  6996. // This most likely won't work though (windows does not allow application
  6997. // to steal focus most of the time)
  6998. Application->BringToFront();
  6999. // On older version of Windows we never got drMove here, see also comment below.
  7000. // On Windows 10, we get the "move".
  7001. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  7002. {
  7003. UnicodeString TargetDirectory;
  7004. TFileOperation Operation;
  7005. // drInvalid may mean drMove, see comment below
  7006. switch (DDResult)
  7007. {
  7008. case drCopy:
  7009. Operation = foCopy;
  7010. break;
  7011. case drMove:
  7012. Operation = foMove;
  7013. break;
  7014. default:
  7015. DebugFail();
  7016. case drInvalid:
  7017. // prefer "copy" for safety
  7018. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7019. break;
  7020. }
  7021. TTransferOperationParam Param;
  7022. UnicodeString CounterName;
  7023. bool ForceQueue;
  7024. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7025. {
  7026. // we get drInvalid both if d&d was intercepted by ddext,
  7027. // and when users drops on no-drop location.
  7028. // we tell the difference by existence of response from ddext,
  7029. // so we ignore absence of response in this case
  7030. if (DDResult != drInvalid)
  7031. {
  7032. // here we know that the extension is installed,
  7033. // as it is checked as soon as drag&drop starts from
  7034. // RemoteFileControlDDCreateDragFileList
  7035. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7036. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7037. {
  7038. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7039. }
  7040. else
  7041. {
  7042. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7043. }
  7044. }
  7045. }
  7046. else
  7047. {
  7048. // download using fake file
  7049. Param.Temp = false;
  7050. Param.DragDrop = true;
  7051. if (ForceQueue)
  7052. {
  7053. Param.Queue = asOn;
  7054. }
  7055. if (Sender == RemoteDirView)
  7056. {
  7057. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7058. }
  7059. if (RemoteFileControlFileOperation(Sender, Operation,
  7060. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7061. {
  7062. Configuration->Usage->Inc(CounterName);
  7063. }
  7064. }
  7065. }
  7066. }
  7067. __finally
  7068. {
  7069. CloseHandle(FDDExtMapFile);
  7070. FDDExtMapFile = NULL;
  7071. delete FDragFakeMonitors;
  7072. FDragFakeMonitors = NULL;
  7073. RemoveDir(ApiPath(FDragFakeDirectory));
  7074. FDragFakeDirectory = L"";
  7075. FFakeFileDropTarget = UnicodeString();
  7076. }
  7077. }
  7078. if (FDragDropSshTerminate.get() != NULL)
  7079. {
  7080. FDragDropSshTerminate->Rethrow();
  7081. }
  7082. }
  7083. //---------------------------------------------------------------------------
  7084. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7085. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7086. {
  7087. // Remember drop effect so we know (when user drops files), if we copy or move
  7088. FLastDropEffect = dwEffect;
  7089. }
  7090. //---------------------------------------------------------------------------
  7091. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7092. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7093. {
  7094. bool Result;
  7095. if (FDDTargetControl == QueueView3)
  7096. {
  7097. Directory = DefaultDownloadTargetDirectory();
  7098. Result = true;
  7099. CounterName = L"DownloadsDragDropQueue";
  7100. ForceQueue = true;
  7101. }
  7102. else if (!FFakeFileDropTarget.IsEmpty())
  7103. {
  7104. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7105. Result = true;
  7106. ForceQueue = false;
  7107. CounterName = L"DownloadsDragDropFakeFile";
  7108. }
  7109. else
  7110. {
  7111. ForceQueue = false;
  7112. Enabled = false;
  7113. try
  7114. {
  7115. int Timer = 0;
  7116. Result = false;
  7117. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7118. {
  7119. {
  7120. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7121. TDragExtCommStruct* CommStruct;
  7122. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7123. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7124. DebugAssert(CommStruct != NULL);
  7125. Result = !CommStruct->Dragging;
  7126. if (Result)
  7127. {
  7128. Directory = ExtractFilePath(CommStruct->DropDest);
  7129. CounterName = L"DownloadsDragDropExternalExt";
  7130. }
  7131. UnmapViewOfFile(CommStruct);
  7132. }
  7133. if (!Result)
  7134. {
  7135. Sleep(50);
  7136. Timer += 50;
  7137. Application->ProcessMessages();
  7138. }
  7139. }
  7140. }
  7141. __finally
  7142. {
  7143. Enabled = true;
  7144. }
  7145. }
  7146. return Result;
  7147. }
  7148. //---------------------------------------------------------------------------
  7149. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7150. const UnicodeString TempDir, int SecDelay)
  7151. {
  7152. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7153. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7154. if (FDelayedDeletionTimer == NULL)
  7155. {
  7156. DebugAssert(HandleAllocated());
  7157. FDelayedDeletionTimer = new TTimer(this);
  7158. FDelayedDeletionTimer->Interval = 10000;
  7159. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7160. }
  7161. else
  7162. {
  7163. FDelayedDeletionTimer->Enabled = true;
  7164. }
  7165. }
  7166. //---------------------------------------------------------------------------
  7167. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7168. {
  7169. DebugAssert(FDelayedDeletionList != NULL);
  7170. TDateTime N = Now();
  7171. TDateTime Alert;
  7172. UnicodeString Directory;
  7173. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7174. {
  7175. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7176. if ((N >= Alert) || (Sender == NULL))
  7177. {
  7178. Directory = FDelayedDeletionList->Strings[Index];
  7179. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7180. {
  7181. FDelayedDeletionList->Delete(Index);
  7182. }
  7183. }
  7184. }
  7185. if (FDelayedDeletionList->Count == 0)
  7186. {
  7187. FDelayedDeletionTimer->Enabled = false;
  7188. }
  7189. }
  7190. //---------------------------------------------------------------------------
  7191. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7192. {
  7193. DebugAssert(!IsLocalBrowserMode());
  7194. if (IsFileControl(FDDTargetControl, osRemote) ||
  7195. (FDDTargetControl == SessionsPageControl))
  7196. {
  7197. TTerminal * TargetTerminal = NULL;
  7198. TFileOperation Operation = foNone;
  7199. if (FDDTargetControl == SessionsPageControl)
  7200. {
  7201. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7202. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7203. // do not allow dropping on the "+" and disconnected tabs
  7204. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7205. if (IsActiveTerminal(TargetTerminal))
  7206. {
  7207. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7208. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7209. {
  7210. Operation = foRemoteMove;
  7211. }
  7212. else
  7213. {
  7214. Operation = foRemoteCopy;
  7215. }
  7216. }
  7217. }
  7218. else
  7219. {
  7220. if (FLastDropEffect == DROPEFFECT_MOVE)
  7221. {
  7222. Operation = foRemoteMove;
  7223. }
  7224. else if (FLastDropEffect == DROPEFFECT_COPY)
  7225. {
  7226. Operation = foRemoteCopy;
  7227. }
  7228. }
  7229. if (Operation != foNone)
  7230. {
  7231. RemoteFileControlFileOperation(DropSourceControl,
  7232. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7233. }
  7234. // abort drag&drop
  7235. Abort();
  7236. }
  7237. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7238. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7239. (FDDTargetControl != QueueView3))
  7240. {
  7241. DebugAssert(!FDragTempDir.IsEmpty());
  7242. TTransferType Type;
  7243. UnicodeString TempDir = FDragTempDir;
  7244. // We clear FDragTempDir before calling
  7245. // just in case it fail (raises exception)
  7246. FDragTempDir = L"";
  7247. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7248. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7249. // empty directory parameter means temp directory -> don't display it!
  7250. UnicodeString TargetDir = L"";
  7251. int Options = 0;
  7252. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7253. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7254. {
  7255. Abort();
  7256. }
  7257. // TargetDir is set when dropped on local file control
  7258. // (this was workaround for legacy dirview event handling, now it should be
  7259. // made prettier)
  7260. if (TargetDir.IsEmpty())
  7261. {
  7262. TargetDir = TempDir;
  7263. if (ForceDirectories(ApiPath(TargetDir)))
  7264. {
  7265. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7266. FPendingTempSpaceWarn = true;
  7267. try
  7268. {
  7269. FDragDropOperation = true;
  7270. int Params = cpTemporary |
  7271. (Type == ttMove ? cpDelete : 0);
  7272. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7273. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7274. }
  7275. __finally
  7276. {
  7277. FDragDropOperation = false;
  7278. FPendingTempSpaceWarn = false;
  7279. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7280. }
  7281. }
  7282. else
  7283. {
  7284. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7285. }
  7286. }
  7287. }
  7288. }
  7289. //---------------------------------------------------------------------------
  7290. void __fastcall TCustomScpExplorerForm::DDDownload(
  7291. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7292. {
  7293. DebugAssert(!IsLocalBrowserMode());
  7294. TAutoBatch AutoBatch(this);
  7295. UpdateCopyParamCounters(*CopyParam);
  7296. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7297. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7298. {
  7299. RemoteDriveView->UpdateDropSource();
  7300. }
  7301. }
  7302. //---------------------------------------------------------------------------
  7303. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7304. {
  7305. public:
  7306. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7307. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7308. {
  7309. }
  7310. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7311. {
  7312. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7313. TDataObjectFilesEx::AllowData(FormatEtc);
  7314. }
  7315. };
  7316. //---------------------------------------------------------------------------
  7317. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7318. TObject * Sender, TDataObject *& DataObject)
  7319. {
  7320. if (FDDExtMapFile != NULL)
  7321. {
  7322. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7323. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7324. {
  7325. Abort();
  7326. }
  7327. if (FileList->Count > 0)
  7328. {
  7329. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7330. if (!FilesObject->IsValid(true, true))
  7331. {
  7332. FilesObject->_Release();
  7333. }
  7334. else
  7335. {
  7336. DataObject = FilesObject;
  7337. }
  7338. }
  7339. }
  7340. }
  7341. //---------------------------------------------------------------------------
  7342. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7343. {
  7344. DebugFail();
  7345. }
  7346. //---------------------------------------------------------------------------
  7347. void __fastcall TCustomScpExplorerForm::GoToTree()
  7348. {
  7349. ComponentVisible[fcRemoteTree] = true;
  7350. DriveView(osRemote)->SetFocus();
  7351. }
  7352. //---------------------------------------------------------------------------
  7353. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7354. TPanelExport Export)
  7355. {
  7356. TCustomDirView * DirView = this->DirView(Side);
  7357. std::unique_ptr<TStrings> ExportData(new TStringList());
  7358. switch (Export)
  7359. {
  7360. case pePath:
  7361. ExportData->Add(DirView->PathName);
  7362. break;
  7363. case peFileList:
  7364. case peFullFileList:
  7365. {
  7366. bool FullPath = (Export == peFullFileList);
  7367. DirView->CreateFileList(false, FullPath, ExportData.get());
  7368. for (int Index = 0; Index < ExportData->Count; Index++)
  7369. {
  7370. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7371. {
  7372. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7373. }
  7374. }
  7375. }
  7376. break;
  7377. default:
  7378. DebugFail();
  7379. }
  7380. return ExportData.release();
  7381. }
  7382. //---------------------------------------------------------------------------
  7383. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7384. TPanelExport Export, TPanelExportDestination Destination)
  7385. {
  7386. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7387. PanelExportStore(Side, Export, Destination, ExportData.get());
  7388. }
  7389. //---------------------------------------------------------------------------
  7390. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7391. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7392. TStrings * ExportData)
  7393. {
  7394. if (Destination == pedClipboard)
  7395. {
  7396. TInstantOperationVisualizer Visualizer;
  7397. CopyToClipboard(ExportData);
  7398. }
  7399. else
  7400. {
  7401. DebugFail();
  7402. }
  7403. }
  7404. //---------------------------------------------------------------------------
  7405. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7406. {
  7407. TCustomDirView * DirView = this->DirView(Side);
  7408. UnicodeString Mask = DirView->Mask;
  7409. if (DoFilterMaskDialog(DirView, Mask))
  7410. {
  7411. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7412. Configuration->Usage->Inc(L"Filters");
  7413. }
  7414. }
  7415. //---------------------------------------------------------------------------
  7416. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7417. {
  7418. return FQueueController->DefaultOperation();
  7419. }
  7420. //---------------------------------------------------------------------------
  7421. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7422. TQueueOperation Operation, void ** Param)
  7423. {
  7424. switch (Operation)
  7425. {
  7426. case qoPreferences:
  7427. return true;
  7428. case qoGoTo:
  7429. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7430. case qoOnceEmpty:
  7431. return IsAnythingQueued();
  7432. default:
  7433. return FQueueController->AllowOperation(Operation, Param);
  7434. }
  7435. }
  7436. //---------------------------------------------------------------------------
  7437. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7438. {
  7439. if (DebugAlwaysTrue(QueueView3->Visible))
  7440. {
  7441. QueueView3->SetFocus();
  7442. }
  7443. }
  7444. //---------------------------------------------------------------------------
  7445. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7446. TQueueOperation Operation, void * Param)
  7447. {
  7448. if (Operation == qoGoTo)
  7449. {
  7450. GoToQueue();
  7451. }
  7452. else if (Operation == qoPreferences)
  7453. {
  7454. PreferencesDialog(pmQueue);
  7455. }
  7456. else
  7457. {
  7458. FQueueController->ExecuteOperation(Operation, Param);
  7459. }
  7460. }
  7461. //---------------------------------------------------------------------------
  7462. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7463. {
  7464. return (Queue != NULL) && Queue->Enabled;
  7465. }
  7466. //---------------------------------------------------------------------------
  7467. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7468. {
  7469. DebugAssert(Queue != NULL);
  7470. if (Queue != NULL)
  7471. {
  7472. Queue->Enabled = !Queue->Enabled;
  7473. }
  7474. }
  7475. //---------------------------------------------------------------------------
  7476. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7477. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7478. {
  7479. FQueueActedItem = QueueView3->ItemFocused;
  7480. }
  7481. //---------------------------------------------------------------------------
  7482. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7483. {
  7484. return TopDock->Height + QueueSplitter->Height;
  7485. }
  7486. //---------------------------------------------------------------------------
  7487. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7488. {
  7489. return
  7490. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7491. (QueueDock->Visible ? QueueDock->Height : 0) +
  7492. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7493. }
  7494. //---------------------------------------------------------------------------
  7495. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7496. {
  7497. return ScaleByTextHeight(this, 48);
  7498. }
  7499. //---------------------------------------------------------------------------
  7500. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7501. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7502. {
  7503. // when queue is hidden by double-clicking splitter, stray attempt to
  7504. // resize the panel with strange value arrives, make sure it is ignored
  7505. if (ComponentVisible[fcQueueView])
  7506. {
  7507. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7508. if (NewSize > MaxHeightLimit)
  7509. {
  7510. NewSize = MaxHeightLimit;
  7511. }
  7512. int MinHeightLimit =
  7513. GetStaticQueuePanelComponentsHeight() +
  7514. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7515. GetMinQueueViewHeight();
  7516. if (NewSize < MinHeightLimit)
  7517. {
  7518. NewSize = MinHeightLimit;
  7519. }
  7520. }
  7521. else
  7522. {
  7523. Accept = false;
  7524. }
  7525. }
  7526. //---------------------------------------------------------------------------
  7527. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7528. {
  7529. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7530. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7531. if (QueueViewHeight < GetMinQueueViewHeight())
  7532. {
  7533. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7534. }
  7535. }
  7536. //---------------------------------------------------------------------------
  7537. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7538. TDragObject *& /*DragObject*/)
  7539. {
  7540. FQueueActedItem = QueueView3->ItemFocused;
  7541. }
  7542. //---------------------------------------------------------------------------
  7543. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7544. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7545. {
  7546. Accept = true;
  7547. if (Source == QueueView3)
  7548. {
  7549. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7550. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7551. if (Accept)
  7552. {
  7553. TQueueItemProxy * QueueItem;
  7554. TQueueItemProxy * DestQueueItem;
  7555. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7556. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7557. Accept = (QueueItem != DestQueueItem) &&
  7558. (QueueItem->Status == TQueueItem::qsPending) &&
  7559. (DestQueueItem->Status == TQueueItem::qsPending);
  7560. }
  7561. }
  7562. }
  7563. //---------------------------------------------------------------------------
  7564. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7565. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7566. {
  7567. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7568. {
  7569. TQueueItemProxy * QueueItem;
  7570. TQueueItemProxy * DestQueueItem;
  7571. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7572. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7573. QueueItem->Move(DestQueueItem);
  7574. }
  7575. }
  7576. //---------------------------------------------------------------------------
  7577. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7578. {
  7579. if ((QueueView3->ItemFocused == NULL) &&
  7580. (QueueView3->Items->Count > 0))
  7581. {
  7582. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7583. }
  7584. QueueLabelUpdateStatus();
  7585. }
  7586. //---------------------------------------------------------------------------
  7587. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7588. {
  7589. QueueLabelUpdateStatus();
  7590. }
  7591. //---------------------------------------------------------------------------
  7592. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7593. {
  7594. QueueLabel->UpdateStatus();
  7595. }
  7596. //---------------------------------------------------------------------------
  7597. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7598. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7599. {
  7600. if (Selected)
  7601. {
  7602. NonVisualDataModule->UpdateNonVisibleActions();
  7603. }
  7604. }
  7605. //---------------------------------------------------------------------------
  7606. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7607. {
  7608. TDragDropFilesEx * Result = NULL;
  7609. if (Sender == SessionsPageControl)
  7610. {
  7611. Result = FSessionsDragDropFilesEx;
  7612. }
  7613. else if (Sender == QueueView3)
  7614. {
  7615. Result = FQueueDragDropFilesEx;
  7616. }
  7617. else
  7618. {
  7619. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7620. if (DirView != NULL)
  7621. {
  7622. Result = DirView->DragDropFilesEx;
  7623. }
  7624. else
  7625. {
  7626. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7627. if (DriveView != NULL)
  7628. {
  7629. Result = DriveView->DragDropFilesEx;
  7630. }
  7631. }
  7632. }
  7633. DebugAssert(Result != NULL);
  7634. return Result;
  7635. }
  7636. //---------------------------------------------------------------------------
  7637. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7638. {
  7639. return (DView->SelCount == DView->FilesCount);
  7640. }
  7641. //---------------------------------------------------------------------------
  7642. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7643. {
  7644. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7645. }
  7646. //---------------------------------------------------------------------------
  7647. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7648. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7649. {
  7650. DebugAssert(!IsLocalBrowserMode());
  7651. TFileOperation Operation;
  7652. switch (Effect)
  7653. {
  7654. case DROPEFFECT_MOVE:
  7655. Operation = foMove;
  7656. break;
  7657. case DROPEFFECT_COPY:
  7658. // occures on WinXP (reported by user)
  7659. default:
  7660. Operation = foCopy;
  7661. break;
  7662. };
  7663. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7664. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7665. if (DragDropFilesEx->FileList->Count > 0)
  7666. {
  7667. TStrings * FileList = new TStringList();
  7668. try
  7669. {
  7670. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7671. {
  7672. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7673. }
  7674. FDragDropOperation = true;
  7675. TTransferOperationParam Param;
  7676. Param.TargetDirectory = TargetPath;
  7677. // upload, no temp dirs
  7678. Param.Temp = false;
  7679. Param.DragDrop = DragDrop;
  7680. Param.Options =
  7681. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7682. if (ForceQueue)
  7683. {
  7684. Param.Queue = asOn;
  7685. }
  7686. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7687. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7688. {
  7689. if (IsFileControl(DropSourceControl, osLocal))
  7690. {
  7691. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7692. }
  7693. else
  7694. {
  7695. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7696. }
  7697. }
  7698. }
  7699. __finally
  7700. {
  7701. FDragDropOperation = false;
  7702. delete FileList;
  7703. }
  7704. }
  7705. }
  7706. //---------------------------------------------------------------------------
  7707. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7708. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7709. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7710. {
  7711. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7712. }
  7713. //---------------------------------------------------------------------------
  7714. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7715. TObject * Sender, int grfKeyState, int & dwEffect)
  7716. {
  7717. DebugAssert(!IsLocalBrowserMode());
  7718. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7719. if ((dwEffect != DROPEFFECT_NONE) &&
  7720. IsFileControl(DropSourceControl, osRemote))
  7721. {
  7722. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7723. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7724. (RemoteDirView->DropTarget == NULL))
  7725. {
  7726. dwEffect = DROPEFFECT_NONE;
  7727. }
  7728. else
  7729. {
  7730. if (dwEffect == DROPEFFECT_COPY)
  7731. {
  7732. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7733. // currently we support copying always (at least via temporary directory);
  7734. // remove associated checks once this all proves stable and working
  7735. bool CopyCapable = true;
  7736. // if we do not support neither of operations, there's no discussion
  7737. if (!MoveCapable && !CopyCapable)
  7738. {
  7739. dwEffect = DROPEFFECT_NONE;
  7740. }
  7741. else
  7742. {
  7743. // The default effect inside remote panel is move,
  7744. // unless we do not support it, but support copy
  7745. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7746. {
  7747. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7748. }
  7749. else
  7750. {
  7751. // with ctrl-down, we want copy unless it is not supported
  7752. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7753. }
  7754. }
  7755. }
  7756. }
  7757. }
  7758. }
  7759. //---------------------------------------------------------------------------
  7760. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7761. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7762. {
  7763. DebugAssert(!IsLocalBrowserMode());
  7764. if (FDDTotalSize >= 0)
  7765. {
  7766. if (File->IsDirectory)
  7767. {
  7768. FDDTotalSize = -1;
  7769. }
  7770. else
  7771. {
  7772. FDDTotalSize += File->Size;
  7773. }
  7774. }
  7775. DebugAssert(!FDragTempDir.IsEmpty());
  7776. // TODO: this is quite ineffective
  7777. // TODO: what if invalid character replacement is disabled?
  7778. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7779. UnicodeString TransferFileName;
  7780. if (Sender == RemoteDriveView)
  7781. {
  7782. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7783. }
  7784. else
  7785. {
  7786. TransferFileName = File->FileName;
  7787. }
  7788. FDDFileList->AddObject(TransferFileName, File);
  7789. }
  7790. //---------------------------------------------------------------------------
  7791. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7792. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7793. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7794. {
  7795. // sometimes we do not get DDEnd so the list is not released
  7796. SAFE_DESTROY(FDDFileList);
  7797. FDDFileList = new TStringList();
  7798. FDragTempDir = WinConfiguration->TemporaryDir();
  7799. FDDTotalSize = 0;
  7800. FDragDropSshTerminate.reset(NULL);
  7801. }
  7802. //---------------------------------------------------------------------------
  7803. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7804. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7805. HRESULT & Result)
  7806. {
  7807. if (Result == DRAGDROP_S_DROP)
  7808. {
  7809. try
  7810. {
  7811. GlobalDragImageList->HideDragImage();
  7812. try
  7813. {
  7814. RemoteFileControlDDTargetDrop();
  7815. }
  7816. catch(ESshTerminate & E)
  7817. {
  7818. FDragDropSshTerminate.reset(E.Clone());
  7819. }
  7820. }
  7821. catch (Exception &E)
  7822. {
  7823. // If downloading fails we need to cancel drag&drop, otherwise
  7824. // Explorer shows error
  7825. // But by the way exception probably never reach this point as
  7826. // it's catched on way.
  7827. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7828. Result = DRAGDROP_S_CANCEL;
  7829. ShowExtendedException(Terminal, &E);
  7830. }
  7831. }
  7832. }
  7833. //---------------------------------------------------------------------------
  7834. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7835. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7836. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7837. {
  7838. TFileMasks::TParams MaskParams;
  7839. MaskParams.Size = Size;
  7840. MaskParams.Modification = Modification;
  7841. // this does not re-parse the mask if it is the same as the last time
  7842. FDirViewMatchMask = Masks;
  7843. bool ImplicitMatch;
  7844. Matches =
  7845. // RecurseInclude parameter has no effect as the Path is empty
  7846. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7847. (AllowImplicitMatches || !ImplicitMatch);
  7848. }
  7849. //---------------------------------------------------------------------------
  7850. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7851. TObject * Sender, TListItem * Item, WORD & Indexes)
  7852. {
  7853. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7854. UnicodeString Ext;
  7855. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7856. {
  7857. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7858. }
  7859. else
  7860. {
  7861. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7862. }
  7863. if (SameText(Ext, Configuration->PartialExt))
  7864. {
  7865. Indexes |= oiPartial;
  7866. }
  7867. }
  7868. //---------------------------------------------------------------------------
  7869. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7870. {
  7871. return
  7872. DirViewEnabled(osCurrent) &&
  7873. DirView(osCurrent)->CanPasteFromClipBoard();
  7874. }
  7875. //---------------------------------------------------------------------------
  7876. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7877. {
  7878. bool Result = false;
  7879. if (CanPasteToDirViewFromClipBoard())
  7880. {
  7881. Result = true;
  7882. }
  7883. else
  7884. {
  7885. UnicodeString ClipboardText;
  7886. if (NonEmptyTextFromClipboard(ClipboardText) &&
  7887. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  7888. {
  7889. if (StoredSessions->IsUrl(ClipboardText))
  7890. {
  7891. Result = true;
  7892. }
  7893. else
  7894. {
  7895. Result = DirViewEnabled(osCurrent);
  7896. }
  7897. }
  7898. }
  7899. return Result;
  7900. }
  7901. //---------------------------------------------------------------------------
  7902. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7903. {
  7904. if (DoesClipboardContainOurFiles())
  7905. {
  7906. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7907. {
  7908. DebugAssert(!IsLocalBrowserMode());
  7909. TTerminalManager * Manager = TTerminalManager::Instance();
  7910. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7911. Manager->ActiveTerminal = FClipboardTerminal;
  7912. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7913. }
  7914. }
  7915. else if (CanPasteToDirViewFromClipBoard())
  7916. {
  7917. DirView(osCurrent)->PasteFromClipBoard();
  7918. }
  7919. else
  7920. {
  7921. UnicodeString ClipboardText;
  7922. if (NonEmptyTextFromClipboard(ClipboardText))
  7923. {
  7924. if (StoredSessions->IsUrl(ClipboardText))
  7925. {
  7926. NewSession(ClipboardText);
  7927. }
  7928. else
  7929. {
  7930. DirView(osCurrent)->Path = ClipboardText;
  7931. }
  7932. }
  7933. }
  7934. }
  7935. //---------------------------------------------------------------------------
  7936. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7937. {
  7938. // TBD
  7939. }
  7940. //---------------------------------------------------------------------------
  7941. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7942. {
  7943. TCustomDirView * ADirView = DirView(Side);
  7944. ADirView->SelectAll(Mode);
  7945. ADirView->SetFocus();
  7946. }
  7947. //---------------------------------------------------------------------------
  7948. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7949. {
  7950. TCustomDirView * ADirView = DirView(Side);
  7951. TFileFilter Filter;
  7952. DefaultFileFilter(Filter);
  7953. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7954. {
  7955. Configuration->Usage->Inc(L"MaskSelections");
  7956. ADirView->SelectFiles(Filter, Select);
  7957. ADirView->SetFocus();
  7958. }
  7959. }
  7960. //---------------------------------------------------------------------------
  7961. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7962. {
  7963. TCustomDirView * ADirView = DirView(Side);
  7964. ADirView->RestoreSelectedNames();
  7965. ADirView->SetFocus();
  7966. }
  7967. //---------------------------------------------------------------------------
  7968. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7969. {
  7970. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7971. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7972. {
  7973. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7974. UnicodeString Ext;
  7975. if (!IsSideLocalBrowser(osCurrent))
  7976. {
  7977. Ext = UnixExtractFileExt(FileName);
  7978. }
  7979. else
  7980. {
  7981. Ext = ExtractFileExt(FileName);
  7982. }
  7983. if (Ext.IsEmpty())
  7984. {
  7985. Ext = L".";
  7986. }
  7987. TFileFilter Filter;
  7988. Filter.Masks = FORMAT(L"*%s", (Ext));
  7989. Filter.Directories = false;
  7990. CurrentDirView->SelectFiles(Filter, Select);
  7991. }
  7992. }
  7993. //---------------------------------------------------------------------------
  7994. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7995. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7996. {
  7997. UnicodeString Result;
  7998. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7999. {
  8000. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  8001. }
  8002. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  8003. {
  8004. // noop
  8005. }
  8006. else
  8007. {
  8008. Result =
  8009. FMTLOAD(FILE_INFO_FORMAT,
  8010. (FormatBytes(FileInfo.SelectedSize),
  8011. FormatBytes(FileInfo.FilesSize),
  8012. FormatNumber(FileInfo.SelectedCount),
  8013. FormatNumber(FileInfo.FilesCount)));
  8014. }
  8015. return Result;
  8016. }
  8017. //---------------------------------------------------------------------------
  8018. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8019. TTBXStatusPanel * Panel, TOperationSide Side)
  8020. {
  8021. if (Panel->Index == 1)
  8022. {
  8023. ToggleShowHiddenFiles();
  8024. }
  8025. else if (Panel->Index == 2)
  8026. {
  8027. Filter(Side);
  8028. }
  8029. }
  8030. //---------------------------------------------------------------------------
  8031. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8032. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8033. {
  8034. DebugAssert(!StatusBar->SimplePanel);
  8035. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8036. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8037. }
  8038. //---------------------------------------------------------------------------
  8039. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8040. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8041. {
  8042. DebugAssert(StatusBar->Panels->Count >= 3);
  8043. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8044. if (FileInfo.HiddenCount > 0)
  8045. {
  8046. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8047. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8048. }
  8049. else
  8050. {
  8051. HiddenFilesPanel->ViewPriority = 0;
  8052. // not really necessary, just to cleanup no-longer-valid data
  8053. HiddenFilesPanel->Caption = L"";
  8054. }
  8055. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8056. if (FileInfo.FilteredCount > 0)
  8057. {
  8058. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8059. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8060. }
  8061. else
  8062. {
  8063. FilteredFilesPanel->ViewPriority = 0;
  8064. // not really necessary, just to cleanup no-longer-valid data
  8065. FilteredFilesPanel->Caption = L"";
  8066. }
  8067. }
  8068. //---------------------------------------------------------------------------
  8069. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8070. TObject * /*Sender*/)
  8071. {
  8072. if (DirView(osRemote)->Enabled)
  8073. {
  8074. DirView(osRemote)->SetFocus();
  8075. }
  8076. }
  8077. //---------------------------------------------------------------------------
  8078. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8079. {
  8080. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8081. switch (Config.Show)
  8082. {
  8083. case qvShow:
  8084. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8085. {
  8086. Config.Show = qvHide;
  8087. }
  8088. else
  8089. {
  8090. Config.Show = Config.LastHideShow;
  8091. }
  8092. break;
  8093. case qvHideWhenEmpty:
  8094. if (ComponentVisible[fcQueueView])
  8095. {
  8096. Config.Show = qvHide;
  8097. }
  8098. else
  8099. {
  8100. Config.LastHideShow = Config.Show;
  8101. Config.Show = qvShow;
  8102. }
  8103. break;
  8104. case qvHide:
  8105. Config.LastHideShow = Config.Show;
  8106. Config.Show = qvShow;
  8107. break;
  8108. }
  8109. WinConfiguration->QueueView = Config;
  8110. }
  8111. //---------------------------------------------------------------------------
  8112. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8113. {
  8114. UnicodeString Result;
  8115. if (FTerminal != NULL)
  8116. {
  8117. switch (WinConfiguration->PathInCaption)
  8118. {
  8119. case picShort:
  8120. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8121. break;
  8122. case picFull:
  8123. Result = FTerminal->CurrentDirectory;
  8124. break;
  8125. }
  8126. }
  8127. return Result;
  8128. }
  8129. //---------------------------------------------------------------------------
  8130. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8131. {
  8132. TColor Result = GetWindowColor(FSessionColor);
  8133. return Result;
  8134. }
  8135. //---------------------------------------------------------------------------
  8136. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8137. {
  8138. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8139. return Result;
  8140. }
  8141. //---------------------------------------------------------------------------
  8142. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8143. {
  8144. TTerminalManager::Instance()->UpdateAppTitle();
  8145. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8146. // background to gray on Windows 7 (works on Windows 10).
  8147. // See also EnableControl
  8148. if (Showing)
  8149. {
  8150. if (Terminal != NULL)
  8151. {
  8152. // Update path when it changes
  8153. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8154. {
  8155. UpdateSessionTab(SessionsPageControl->ActivePage);
  8156. }
  8157. }
  8158. NonVisualDataModule->ReconnectSessionAction->Update();
  8159. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8160. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8161. CenterReconnectToolbar();
  8162. bool HasTerminal = HasActiveTerminal();
  8163. if (HasTerminal)
  8164. {
  8165. if (!RemoteDirView->Enabled)
  8166. {
  8167. RemoteDirView->Enabled = true;
  8168. if (FRemoteDirViewWasFocused)
  8169. {
  8170. ActiveControl = RemoteDirView;
  8171. }
  8172. }
  8173. RemoteDirView->Color = PanelColor();
  8174. }
  8175. else
  8176. {
  8177. if (RemoteDirView->Enabled)
  8178. {
  8179. // This is first called when the form is being constructed
  8180. // (not anymore due to Showing test above)
  8181. // but the false is overriden in the constructor later.
  8182. // An even later in TScpCommanderForm::DoShow()
  8183. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  8184. RemoteDirView->Enabled = false;
  8185. }
  8186. RemoteDirView->Color = DisabledPanelColor();
  8187. }
  8188. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8189. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8190. RemoteDriveView->Color = RemoteDirView->Color;
  8191. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8192. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8193. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8194. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8195. QueueFileList->Enabled = QueueView3->Enabled;
  8196. QueueFileList->Color = QueueView3->Color;
  8197. QueueFileList->Font->Color = QueueView3->Font->Color;
  8198. QueueLabelUpdateStatus();
  8199. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8200. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8201. if (FImmersiveDarkMode != WinConfiguration->UseDarkTheme())
  8202. {
  8203. UpdateDarkMode();
  8204. }
  8205. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  8206. }
  8207. }
  8208. //---------------------------------------------------------------------------
  8209. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8210. {
  8211. UpdateControls();
  8212. }
  8213. //---------------------------------------------------------------------------
  8214. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8215. TObject * Sender)
  8216. {
  8217. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8218. DebugAssert(DirView != NULL);
  8219. DoDirViewLoaded(DirView);
  8220. TransferPresetAutoSelect();
  8221. }
  8222. //---------------------------------------------------------------------------
  8223. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8224. {
  8225. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8226. // first run after installation
  8227. if (double(Updates.LastCheck) == 0)
  8228. {
  8229. // make sure next time there will be an update (if enabled)
  8230. Updates.LastCheck = TDateTime(1);
  8231. WinConfiguration->Updates = Updates;
  8232. }
  8233. else if ((double(Updates.Period) > 0) &&
  8234. (Now() - Updates.LastCheck >= Updates.Period))
  8235. {
  8236. TThreadMethod OnUpdatesChecked = NULL;
  8237. if (!IsUWP())
  8238. {
  8239. OnUpdatesChecked = UpdatesChecked;
  8240. }
  8241. StartUpdateThread(OnUpdatesChecked);
  8242. }
  8243. }
  8244. //---------------------------------------------------------------------------
  8245. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8246. {
  8247. UnicodeString Message;
  8248. bool New;
  8249. TQueryType Type;
  8250. GetUpdatesMessage(Message, New, Type, false);
  8251. if (!Message.IsEmpty())
  8252. {
  8253. if (New)
  8254. {
  8255. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8256. }
  8257. if (!New && (Type != qtWarning))
  8258. {
  8259. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8260. }
  8261. else
  8262. {
  8263. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8264. }
  8265. if (New)
  8266. {
  8267. Configuration->Usage->Inc(L"UpdateNotifications");
  8268. }
  8269. }
  8270. }
  8271. //---------------------------------------------------------------------------
  8272. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8273. {
  8274. RestoreApp();
  8275. bool CanDisplay = !NonVisualDataModule->Busy;
  8276. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8277. {
  8278. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8279. }
  8280. if (CanDisplay)
  8281. {
  8282. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8283. CheckForUpdates(true);
  8284. }
  8285. else
  8286. {
  8287. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8288. }
  8289. }
  8290. //---------------------------------------------------------------------------
  8291. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8292. TCopyParamRuleData & Data)
  8293. {
  8294. DebugAssert(Terminal != NULL);
  8295. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8296. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8297. Data.RemoteDirectory = RemoteDirView->PathName;
  8298. }
  8299. //---------------------------------------------------------------------------
  8300. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8301. {
  8302. // Terminal can be null when we are changing local directory implicitly,
  8303. // because it has been deleted, while no session is connected
  8304. // (Login dialog is open)
  8305. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8306. {
  8307. DebugAssert(!IsLocalBrowserMode());
  8308. TCopyParamRuleData Data;
  8309. GetTransferPresetAutoSelectData(Data);
  8310. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8311. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8312. if (CopyParamIndex < 0)
  8313. {
  8314. // there is no preset that matches autoselection
  8315. // set preset that we consider "default"
  8316. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8317. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8318. }
  8319. else
  8320. {
  8321. // there is preset matching autoselection
  8322. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8323. if (CopyParamName == FCopyParamAutoSelected)
  8324. {
  8325. // autoselected the same preset as the last time
  8326. // make no change (i.e. preserve custom user preset, if any)
  8327. }
  8328. else
  8329. {
  8330. // autoselected the different preset then the last time (or there
  8331. // was default preset set)
  8332. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8333. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8334. }
  8335. }
  8336. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8337. {
  8338. if (CopyParamIndex >= 0)
  8339. {
  8340. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8341. }
  8342. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8343. try
  8344. {
  8345. int Fmt =
  8346. (CopyParamIndex < 0) ?
  8347. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8348. COPY_PARAM_AUTOSELECTED;
  8349. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8350. Data->Message = MainInstructions(Message);
  8351. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8352. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8353. CopyParamAttrs);
  8354. if (CopyParamIndex >= 0)
  8355. {
  8356. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8357. Info = FORMAT(L"%s\n \n%s", (Info,
  8358. FMTLOAD(COPY_PARAM_RULE,
  8359. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8360. }
  8361. Data->Message += L"\n\n" + Info;
  8362. if (WinConfiguration->CopyParamAutoSelectNotice)
  8363. {
  8364. TransferPresetNoteMessage(Data, true);
  8365. }
  8366. else
  8367. {
  8368. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8369. Data = NULL; // ownership passed
  8370. }
  8371. }
  8372. __finally
  8373. {
  8374. delete Data;
  8375. }
  8376. }
  8377. }
  8378. }
  8379. //---------------------------------------------------------------------------
  8380. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8381. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8382. {
  8383. DebugAssert(NoteData != NULL);
  8384. DebugAssert(!IsLocalBrowserMode());
  8385. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8386. TQueryButtonAlias Aliases[1];
  8387. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8388. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8389. Params.Aliases = Aliases;
  8390. Params.AliasesCount = LENOF(Aliases);
  8391. unsigned int Result =
  8392. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8393. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8394. switch (Result)
  8395. {
  8396. case qaNeverAskAgain:
  8397. DebugAssert(AllowNeverAskAgain);
  8398. WinConfiguration->CopyParamAutoSelectNotice = false;
  8399. break;
  8400. case qaIgnore:
  8401. PreferencesDialog(pmPresets);
  8402. break;
  8403. }
  8404. }
  8405. //---------------------------------------------------------------------------
  8406. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8407. {
  8408. // as of now useless, as this is used for notes only, never for balloons, ...
  8409. RestoreApp();
  8410. // .. and we should never be busy here
  8411. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8412. {
  8413. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8414. }
  8415. }
  8416. //---------------------------------------------------------------------------
  8417. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8418. TPreferencesMode APreferencesMode)
  8419. {
  8420. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8421. TCopyParamRuleData Data;
  8422. if (Terminal != NULL)
  8423. {
  8424. PreferencesData.reset(new TPreferencesDialogData());
  8425. GetTransferPresetAutoSelectData(Data);
  8426. PreferencesData->CopyParamRuleData = &Data;
  8427. }
  8428. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8429. }
  8430. //---------------------------------------------------------------------------
  8431. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8432. const TCustomCommandType & Command)
  8433. {
  8434. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8435. {
  8436. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8437. }
  8438. }
  8439. //---------------------------------------------------------------------------
  8440. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8441. {
  8442. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8443. TCustomCommandType Command;
  8444. // make sure we use local custom command when remote are not supported
  8445. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8446. {
  8447. Command = FLastCustomCommand;
  8448. }
  8449. else
  8450. {
  8451. Command.Params = Command.Params | ccLocal;
  8452. }
  8453. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8454. FEditingFocusedAdHocCommand = OnFocused;
  8455. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8456. int Options =
  8457. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8458. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8459. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8460. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8461. {
  8462. FLastCustomCommand = Command;
  8463. UpdateCustomCommandsToolbar();
  8464. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8465. }
  8466. }
  8467. //---------------------------------------------------------------------------
  8468. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8469. {
  8470. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8471. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8472. DebugAssert(State > 0);
  8473. if (State <= 0)
  8474. {
  8475. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8476. }
  8477. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8478. }
  8479. //---------------------------------------------------------------------------
  8480. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8481. TCustomCommandType & Command, int & State)
  8482. {
  8483. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8484. if (Result)
  8485. {
  8486. Command = FLastCustomCommand;
  8487. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8488. }
  8489. return Result;
  8490. }
  8491. //---------------------------------------------------------------------------
  8492. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8493. {
  8494. ResetIncrementalSearch();
  8495. }
  8496. //---------------------------------------------------------------------------
  8497. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8498. {
  8499. DebugAssert(ComponentVisible[Component]);
  8500. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8501. }
  8502. //---------------------------------------------------------------------------
  8503. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8504. {
  8505. // when queue panel is resized here directly, the status bar is stretched
  8506. // over whole space the panel occupied
  8507. PostComponentHide(fcQueueView);
  8508. }
  8509. //---------------------------------------------------------------------------
  8510. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8511. {
  8512. ComponentVisible[fcQueueFileList] = false;
  8513. }
  8514. //---------------------------------------------------------------------------
  8515. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8516. {
  8517. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8518. RefreshColorMode();
  8519. ResetSysDarkTheme();
  8520. ConfigurationChanged();
  8521. ConfigureInterface();
  8522. // Should be called for all controls
  8523. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8524. }
  8525. //---------------------------------------------------------------------------
  8526. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8527. {
  8528. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8529. if (!FInvalid &&
  8530. (Message.LParam != 0) &&
  8531. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8532. {
  8533. ThemeChanged();
  8534. }
  8535. TForm::Dispatch(&Message);
  8536. }
  8537. //---------------------------------------------------------------------------
  8538. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8539. {
  8540. TMessage * M = static_cast<TMessage*>(Message);
  8541. switch (M->Msg)
  8542. {
  8543. case CM_DIALOGCHAR:
  8544. CMDialogChar(*M);
  8545. break;
  8546. case WM_APPCOMMAND:
  8547. WMAppCommand(*M);
  8548. break;
  8549. case WM_SYSCOMMAND:
  8550. WMSysCommand(*M);
  8551. break;
  8552. case WM_QUERYENDSESSION:
  8553. WMQueryEndSession(*M);
  8554. break;
  8555. case WM_ENDSESSION:
  8556. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8557. break;
  8558. #ifdef _DEBUG
  8559. case WM_WINDOWPOSCHANGED:
  8560. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8561. break;
  8562. case CM_CUSTOMSTYLECHANGED:
  8563. TForm::Dispatch(Message);
  8564. break;
  8565. #endif
  8566. case WM_COMPONENT_HIDE:
  8567. {
  8568. Byte Component = static_cast<Byte>(M->WParam);
  8569. // sanity check
  8570. if (ComponentVisible[Component])
  8571. {
  8572. // special treatment
  8573. if (Component == fcQueueView)
  8574. {
  8575. ToggleQueueVisibility();
  8576. DebugAssert(!ComponentVisible[fcQueueView]);
  8577. }
  8578. else
  8579. {
  8580. ComponentVisible[Component] = false;
  8581. }
  8582. }
  8583. }
  8584. break;
  8585. case WM_COPYDATA:
  8586. WMCopyData(*M);
  8587. break;
  8588. case WM_MANAGES_CAPTION:
  8589. // caption managed in TTerminalManager::UpdateAppTitle()
  8590. M->Result = 1;
  8591. break;
  8592. case WM_WANTS_MOUSEWHEEL:
  8593. M->Result = 1;
  8594. break;
  8595. case CM_SHOWINGCHANGED:
  8596. CMShowingChanged(*M);
  8597. break;
  8598. case WM_CLOSE:
  8599. WMClose(*M);
  8600. break;
  8601. case WM_DPICHANGED:
  8602. WMDpiChanged(*M);
  8603. break;
  8604. case CM_DPICHANGED:
  8605. CMDpiChanged(*M);
  8606. break;
  8607. case WM_SETTINGCHANGE:
  8608. WMSettingChange(*M);
  8609. break;
  8610. case CM_DIALOGKEY:
  8611. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8612. break;
  8613. default:
  8614. TForm::Dispatch(Message);
  8615. break;
  8616. }
  8617. }
  8618. //---------------------------------------------------------------------------
  8619. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8620. {
  8621. // noop
  8622. }
  8623. //---------------------------------------------------------------------------
  8624. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8625. {
  8626. TForm::Dispatch(&Message);
  8627. FSessionColors->Clear();
  8628. AddFixedSessionImages();
  8629. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8630. UpdateImages();
  8631. }
  8632. //---------------------------------------------------------------------------
  8633. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8634. {
  8635. TForm::Dispatch(&Message);
  8636. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8637. UpdatePixelsPerInchMainWindowCounter();
  8638. }
  8639. //---------------------------------------------------------------------------
  8640. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8641. {
  8642. // Cannot close window while we are busy.
  8643. // We cannot test this in FormCloseQuery as that is called also from
  8644. // Close(), which is called by CloseApplicationAction. So we can be busy
  8645. // there already even, when it is legitimate to close the application.
  8646. // Possibly a better place to handle this would be WMSysCommand.
  8647. if (NonVisualDataModule->Busy)
  8648. {
  8649. Message.Result = 1;
  8650. }
  8651. else
  8652. {
  8653. TForm::Dispatch(&Message);
  8654. }
  8655. }
  8656. //---------------------------------------------------------------------------
  8657. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8658. {
  8659. TForm::Dispatch(&Message);
  8660. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  8661. if (Showing && !FStarted)
  8662. {
  8663. FStarted = true;
  8664. InterfaceStarted();
  8665. }
  8666. if (Showing && (Terminal == NULL))
  8667. {
  8668. // When we are starting minimized (i.e. from an installer),
  8669. // postpone showing Login dialog until we get restored.
  8670. // Otherwise the Login dialog (and Authentication window) show restored
  8671. // over invisible (minimized) main window.
  8672. if (WindowState == wsMinimized)
  8673. {
  8674. FNeedSession = true;
  8675. }
  8676. else
  8677. {
  8678. // This happens before application ever goes idle, so the toolbars would
  8679. // stay enabled (initial state) until the Login dialog is dismissed.
  8680. UpdateActions();
  8681. NonVisualDataModule->StartBusy();
  8682. try
  8683. {
  8684. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8685. // otherwise the dialog does not receive focus.
  8686. // With Commander interface the ProcessMessages is called already
  8687. // by TDriveView, but with Explorer interface, we need to call it explicily
  8688. Application->ProcessMessages();
  8689. // do not reload sessions, they have been loaded just now (optimization)
  8690. NeedSession(true);
  8691. }
  8692. __finally
  8693. {
  8694. NonVisualDataModule->EndBusy();
  8695. }
  8696. }
  8697. }
  8698. }
  8699. //---------------------------------------------------------------------------
  8700. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8701. {
  8702. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8703. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8704. }
  8705. //---------------------------------------------------------------------------
  8706. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8707. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8708. int & MaxHeight)
  8709. {
  8710. // workaround for bug in TWinControl.CalcConstraints
  8711. // Check for empty rect (restore from iconic state) is done there only after
  8712. // call to AdjustClientRect, which enlarges the rect (for forms).
  8713. TRect R = GetClientRect();
  8714. // when restoring from iconic state, place no restrictions
  8715. if (IsRectEmpty(R))
  8716. {
  8717. MinWidth = 0;
  8718. MinHeight = 0;
  8719. MaxWidth = 32000;
  8720. MaxHeight = 32000;
  8721. }
  8722. }
  8723. //---------------------------------------------------------------------------
  8724. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8725. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8726. {
  8727. // terminal can be already closed (e.g. dropped connection)
  8728. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8729. {
  8730. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8731. try
  8732. {
  8733. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8734. }
  8735. catch(...)
  8736. {
  8737. if (!Terminal->Active)
  8738. {
  8739. Close = true;
  8740. }
  8741. throw;
  8742. }
  8743. }
  8744. }
  8745. //---------------------------------------------------------------------------
  8746. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8747. {
  8748. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8749. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8750. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8751. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8752. {
  8753. OnGetSpaceAvailable = GetSpaceAvailable;
  8754. }
  8755. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8756. OnGetSpaceAvailable);
  8757. }
  8758. //---------------------------------------------------------------------------
  8759. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8760. {
  8761. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8762. Terminal->FillSessionDataForCode(Data.get());
  8763. return Data.release();
  8764. }
  8765. //---------------------------------------------------------------------------
  8766. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8767. {
  8768. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8769. DoGenerateUrlDialog(Data.get(), Paths);
  8770. }
  8771. //---------------------------------------------------------------------------
  8772. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8773. {
  8774. GenerateUrl(NULL);
  8775. }
  8776. //---------------------------------------------------------------------------
  8777. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8778. {
  8779. std::unique_ptr<TStrings> Paths(new TStringList());
  8780. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8781. GenerateUrl(Paths.get());
  8782. }
  8783. //---------------------------------------------------------------------------
  8784. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8785. {
  8786. FSessionColor = value;
  8787. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8788. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8789. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8790. DebugAssert(ColorItem != NULL);
  8791. ColorItem->Color = C;
  8792. NonVisualDataModule->ColorMenuItem->Color = C;
  8793. UpdateControls();
  8794. }
  8795. //---------------------------------------------------------------------------
  8796. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8797. {
  8798. if (value != FSessionColor)
  8799. {
  8800. UpdateSessionColor(value);
  8801. // Is null when called from LastTerminalClosed
  8802. if (Terminal != NULL)
  8803. {
  8804. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8805. }
  8806. }
  8807. }
  8808. //---------------------------------------------------------------------------
  8809. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8810. {
  8811. bool Result = FNoteTimer->Enabled;
  8812. if (Result)
  8813. {
  8814. // cannot cancel note too early
  8815. bool NotEarly =
  8816. (Now() - FNoteShown >
  8817. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8818. if (Force || NotEarly)
  8819. {
  8820. FNoteTimer->Enabled = false;
  8821. FNote = L"";
  8822. SAFE_DESTROY(FNoteData);
  8823. FOnNoteClick = NULL;
  8824. FNoteHints = FNotes->Text;
  8825. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8826. UpdateStatusBar();
  8827. }
  8828. }
  8829. return Result;
  8830. }
  8831. //---------------------------------------------------------------------------
  8832. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8833. {
  8834. DebugAssert(FNoteTimer->Enabled);
  8835. CancelNote(true);
  8836. }
  8837. //---------------------------------------------------------------------------
  8838. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  8839. {
  8840. FNoteHints = FNotes->Text.TrimRight();
  8841. }
  8842. //---------------------------------------------------------------------------
  8843. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8844. {
  8845. int P = Note.Pos(L"\n");
  8846. if (P > 0)
  8847. {
  8848. Note.SetLength(P - 1);
  8849. }
  8850. FNotes->Add(FORMAT(L"[%s] %s",
  8851. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8852. while (FNotes->Count > 10)
  8853. {
  8854. FNotes->Delete(0);
  8855. }
  8856. if (UpdateNow)
  8857. {
  8858. UpdateNoteHints();
  8859. UpdateStatusBar();
  8860. }
  8861. }
  8862. //---------------------------------------------------------------------------
  8863. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8864. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8865. {
  8866. int P = Note.Pos(L"\n");
  8867. if (P > 0)
  8868. {
  8869. Note.SetLength(P - 1);
  8870. }
  8871. UpdateNoteHints();
  8872. FNote = Note;
  8873. SAFE_DESTROY(FNoteData);
  8874. FNoteData = NoteData;
  8875. FOnNoteClick = OnNoteClick;
  8876. AddNote(Note, false);
  8877. UpdateStatusBar();
  8878. FNoteShown = Now();
  8879. FNoteTimer->Enabled = false;
  8880. if (Seconds == 0)
  8881. {
  8882. Seconds = WinConfiguration->NotificationsTimeout;
  8883. }
  8884. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8885. FNoteTimer->Enabled = true;
  8886. }
  8887. //---------------------------------------------------------------------------
  8888. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8889. {
  8890. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8891. }
  8892. //---------------------------------------------------------------------------
  8893. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8894. {
  8895. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked)
  8896. {
  8897. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8898. }
  8899. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8900. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8901. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  8902. 0, NULL, NULL);
  8903. }
  8904. //---------------------------------------------------------------------------
  8905. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8906. {
  8907. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8908. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8909. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8910. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  8911. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8912. }
  8913. //---------------------------------------------------------------------------
  8914. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8915. {
  8916. WinConfiguration->FormatSizeBytes = Style;
  8917. }
  8918. //---------------------------------------------------------------------------
  8919. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8920. {
  8921. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8922. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8923. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8924. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8925. }
  8926. //---------------------------------------------------------------------------
  8927. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8928. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8929. {
  8930. if (Panel->Index == 0)
  8931. {
  8932. if (FOnNoteClick != NULL)
  8933. {
  8934. // prevent the user data from being freed by possible call
  8935. // to CancelNote or PostNote during call to OnNoteClick
  8936. std::unique_ptr<TObject> NoteData(FNoteData);
  8937. TNotifyEvent OnNoteClick = FOnNoteClick;
  8938. FNoteData = NULL;
  8939. // need to cancel the note as we are going to delete its user data
  8940. CancelNote(true);
  8941. OnNoteClick(NoteData.get());
  8942. }
  8943. }
  8944. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8945. {
  8946. FileSystemInfo();
  8947. }
  8948. }
  8949. //---------------------------------------------------------------------------
  8950. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8951. {
  8952. // workaround:
  8953. // 1) for unknown reason, disabling window, while minimized,
  8954. // prevents it from restoring, even if it was enabled again meanwhile
  8955. // 2) when disabling the main window, while another has focus
  8956. // minimize is no longer possible
  8957. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8958. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8959. // Shouldn't we use IsApplicationMinimized() here?
  8960. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8961. {
  8962. Enabled = false;
  8963. }
  8964. FLockLevel++;
  8965. }
  8966. //---------------------------------------------------------------------------
  8967. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8968. {
  8969. DebugAssert(FLockLevel > 0);
  8970. FLockLevel--;
  8971. if (FLockLevel == 0)
  8972. {
  8973. DebugAssert(FLockSuspendLevel == 0);
  8974. Enabled = true;
  8975. }
  8976. }
  8977. //---------------------------------------------------------------------------
  8978. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8979. {
  8980. // We need to make sure that window is enabled when the last modal window closes
  8981. // otherwise focus is not restored correctly.
  8982. // So we re-enable the window when modal window opens and
  8983. // disable it back after is closes
  8984. if (FLockLevel > 0)
  8985. {
  8986. // while we have nesting counter, we know that we never be called
  8987. // recursivelly as Application->OnModalBegin is called only
  8988. // for the top-level modal window
  8989. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8990. {
  8991. // won't be disabled when conditions in LockWindow() were not satisfied
  8992. FDisabledOnLockSuspend = !Enabled;
  8993. // When minimized to tray (or actually when set to SW_HIDE),
  8994. // setting Enabled makes the window focusable even when there's
  8995. // modal window over it
  8996. if (!FTrayIcon->Visible)
  8997. {
  8998. Enabled = true;
  8999. }
  9000. }
  9001. FLockSuspendLevel++;
  9002. }
  9003. }
  9004. //---------------------------------------------------------------------------
  9005. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  9006. {
  9007. if (FLockSuspendLevel > 0)
  9008. {
  9009. DebugAssert(FLockLevel > 0);
  9010. FLockSuspendLevel--;
  9011. // see comment in SuspendWindowLock
  9012. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9013. {
  9014. // Note that window can be enabled here, when we were minized to tray when
  9015. // was SuspendWindowLock() called.
  9016. // We should possibly do the same check as in LockWindow(),
  9017. // if it is ever possible that the consitions change between
  9018. // SuspendWindowLock() and ResumeWindowLock()
  9019. Enabled = !FDisabledOnLockSuspend;
  9020. }
  9021. }
  9022. }
  9023. //---------------------------------------------------------------------------
  9024. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9025. {
  9026. TTBXComboBoxItem * RemotePathComboBox =
  9027. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9028. if (!TextOnly)
  9029. {
  9030. TStrings * Items = RemotePathComboBox->Strings;
  9031. Items->BeginUpdate();
  9032. try
  9033. {
  9034. Items->Clear();
  9035. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9036. {
  9037. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9038. while (!IsUnixRootPath(APath))
  9039. {
  9040. int P = APath.LastDelimiter(L'/');
  9041. DebugAssert(P >= 0);
  9042. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9043. APath.SetLength(P - 1);
  9044. }
  9045. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9046. }
  9047. }
  9048. __finally
  9049. {
  9050. Items->EndUpdate();
  9051. }
  9052. }
  9053. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9054. // Setting ItemIndex to -1 does not reset its text
  9055. if (RemotePathComboBox->Strings->Count == 0)
  9056. {
  9057. RemotePathComboBox->Text = L"";
  9058. }
  9059. }
  9060. //---------------------------------------------------------------------------
  9061. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9062. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  9063. int & ImageIndex)
  9064. {
  9065. if (AIndex < 0)
  9066. {
  9067. AIndex = Sender->ItemIndex;
  9068. }
  9069. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9070. }
  9071. //---------------------------------------------------------------------------
  9072. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9073. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9074. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9075. {
  9076. ARect.Left += (10 * AIndex);
  9077. }
  9078. //---------------------------------------------------------------------------
  9079. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9080. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9081. {
  9082. AWidth += (10 * AIndex);
  9083. }
  9084. //---------------------------------------------------------------------------
  9085. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  9086. TObject * Sender)
  9087. {
  9088. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9089. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9090. int Index = RemotePathComboBox->ItemIndex;
  9091. while (Index < RemotePathComboBox->Strings->Count - 1)
  9092. {
  9093. APath = UnixExtractFileDir(APath);
  9094. Index++;
  9095. }
  9096. // VanDyke style paths
  9097. if (APath.IsEmpty())
  9098. {
  9099. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9100. APath = ROOTDIRECTORY;
  9101. }
  9102. if (RemoteDirView->Path != APath)
  9103. {
  9104. RemoteDirView->Path = APath;
  9105. }
  9106. }
  9107. //---------------------------------------------------------------------------
  9108. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9109. {
  9110. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9111. DebugUsedParam(Sender);
  9112. UpdateRemotePathComboBox(true);
  9113. }
  9114. //---------------------------------------------------------------------------
  9115. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9116. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9117. {
  9118. ResetIncrementalSearch();
  9119. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9120. DebugAssert(DirView != NULL);
  9121. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9122. {
  9123. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9124. // OnEditing is called also from TCustomListView::CanEdit
  9125. if (Edit != NULL)
  9126. {
  9127. EditSelectBaseName(Edit);
  9128. }
  9129. }
  9130. }
  9131. //---------------------------------------------------------------------------
  9132. //---------------------------------------------------------------------------
  9133. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9134. {
  9135. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9136. Result->AutoDetectDnD = false;
  9137. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9138. Result->RenderDataOn = rdoEnterAndDropSync;
  9139. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9140. return Result;
  9141. }
  9142. //---------------------------------------------------------------------------
  9143. void __fastcall TCustomScpExplorerForm::UpdateDarkMode()
  9144. {
  9145. if (IsWin10Build(2004))
  9146. {
  9147. FImmersiveDarkMode = WinConfiguration->UseDarkTheme();
  9148. BOOL DarkMode = FImmersiveDarkMode ? TRUE : FALSE;
  9149. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9150. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9151. }
  9152. }
  9153. //---------------------------------------------------------------------------
  9154. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9155. {
  9156. TForm::CreateWnd();
  9157. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9158. UpdateDarkMode();
  9159. if (FSessionsDragDropFilesEx == NULL)
  9160. {
  9161. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9162. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9163. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9164. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9165. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9166. }
  9167. if (FQueueDragDropFilesEx == NULL)
  9168. {
  9169. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9170. // No need to set OnDragOver as we do not have any restrictions
  9171. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9172. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9173. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9174. }
  9175. }
  9176. //---------------------------------------------------------------------------
  9177. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9178. {
  9179. TForm::DestroyWnd();
  9180. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9181. FQueueDragDropFilesEx->DragDropControl = NULL;
  9182. }
  9183. //---------------------------------------------------------------------------
  9184. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9185. {
  9186. SideEnter(FCurrentSide);
  9187. FEverShown = true;
  9188. }
  9189. //---------------------------------------------------------------------------
  9190. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9191. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9192. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9193. {
  9194. if (!NonVisualDataModule->Busy)
  9195. {
  9196. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9197. Configuration->Usage->Inc(L"FileFinds");
  9198. LockWindow(true);
  9199. NonVisualDataModule->StartBusy();
  9200. WinConfiguration->LockedInterface = true;
  9201. try
  9202. {
  9203. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9204. }
  9205. __finally
  9206. {
  9207. WinConfiguration->LockedInterface = false;
  9208. NonVisualDataModule->EndBusy();
  9209. UnlockWindow();
  9210. }
  9211. }
  9212. }
  9213. //---------------------------------------------------------------------------
  9214. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9215. {
  9216. if (!NonVisualDataModule->Busy)
  9217. {
  9218. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9219. SetFocus();
  9220. RemoteDirView->Path = UnixExtractFilePath(Path);
  9221. UnicodeString FileName = UnixExtractFileName(Path);
  9222. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9223. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9224. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9225. if (Item == NULL)
  9226. {
  9227. ReloadDirectory(osRemote);
  9228. Item = RemoteDirView->FindFileItem(FileName);
  9229. }
  9230. if (Item != NULL)
  9231. {
  9232. RemoteDirView->ItemFocused = Item;
  9233. RemoteDirView->ItemFocused->MakeVisible(false);
  9234. RemoteDirView->SetFocus();
  9235. }
  9236. }
  9237. }
  9238. //---------------------------------------------------------------------------
  9239. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9240. {
  9241. bool Result = !NonVisualDataModule->Busy;
  9242. if (Result)
  9243. {
  9244. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9245. }
  9246. return Result;
  9247. }
  9248. //---------------------------------------------------------------------------
  9249. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9250. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9251. {
  9252. if (CanOperateOnFoundFiles(ATerminal))
  9253. {
  9254. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9255. FOnFileOperationFinished = OnFileOperationFinished;
  9256. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9257. }
  9258. }
  9259. //---------------------------------------------------------------------------
  9260. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9261. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9262. {
  9263. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9264. }
  9265. //---------------------------------------------------------------------------
  9266. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9267. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9268. {
  9269. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9270. }
  9271. //---------------------------------------------------------------------------
  9272. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9273. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9274. {
  9275. if (CanOperateOnFoundFiles(ATerminal))
  9276. {
  9277. for (int Index = 0; Index < FileList->Count; Index++)
  9278. {
  9279. UnicodeString FileName = FileList->Strings[Index];
  9280. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9281. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9282. OnFileOperationFinished(FileName, true);
  9283. }
  9284. }
  9285. }
  9286. //---------------------------------------------------------------------------
  9287. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9288. {
  9289. FFileFindTerminal = Terminal;
  9290. ShowFileFindDialog(
  9291. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9292. DoDownloadFoundFiles, DoEditFoundFiles);
  9293. }
  9294. //---------------------------------------------------------------------------
  9295. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9296. {
  9297. FTaskbarList = TaskbarList;
  9298. }
  9299. //---------------------------------------------------------------------------
  9300. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9301. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9302. {
  9303. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9304. if (Index >= 0)
  9305. {
  9306. if (Button == mbLeft)
  9307. {
  9308. // "Mouse down" is raised only after tab is switched.
  9309. // If switching tab (switching session) takes long enough for user
  9310. // to actually release the button, "mouse down" is still raised,
  9311. // but we do not get "mouse up" event, so dragging is not cancelled,
  9312. // prevent that by not beginning dragging in the first place.
  9313. if (IsKeyPressed(VK_LBUTTON))
  9314. {
  9315. // when user clicks the "+", we get mouse down only after the session
  9316. // is closed, when new session tab is already on X:Y, so dragging
  9317. // starts, prevent that
  9318. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9319. {
  9320. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9321. if (Terminal != NULL)
  9322. {
  9323. SessionsPageControl->BeginDrag(false);
  9324. }
  9325. }
  9326. }
  9327. }
  9328. else if (Button == mbMiddle)
  9329. {
  9330. // ignore middle-click for "New session tab"
  9331. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9332. if (Terminal != NULL)
  9333. {
  9334. CloseSessionTab(Index);
  9335. }
  9336. }
  9337. }
  9338. }
  9339. //---------------------------------------------------------------------------
  9340. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9341. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9342. {
  9343. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9344. // do not allow dropping on the "+" tab
  9345. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9346. if ((TargetTerminal != NULL) &&
  9347. (SessionsPageControl->ActivePage->PageIndex != Index))
  9348. {
  9349. Configuration->Usage->Inc(L"SessionTabMoves");
  9350. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9351. // but we want to actually prevent that to avoid flicker
  9352. SessionsPageControl->ActivePage->PageIndex = Index;
  9353. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9354. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9355. }
  9356. }
  9357. //---------------------------------------------------------------------------
  9358. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9359. TObject * Sender, TObject * Source, int X, int Y,
  9360. TDragState /*State*/, bool & Accept)
  9361. {
  9362. Accept = (Sender == Source);
  9363. if (Accept)
  9364. {
  9365. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9366. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9367. // do not allow dragging to the "+" tab
  9368. Accept = (Terminal != NULL);
  9369. }
  9370. }
  9371. //---------------------------------------------------------------------------
  9372. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9373. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9374. {
  9375. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9376. if (Index < 0)
  9377. {
  9378. Effect = DROPEFFECT_NONE;
  9379. }
  9380. else
  9381. {
  9382. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9383. // do not allow dropping on the "+" and disconnected tabs
  9384. if (!IsActiveTerminal(TargetTerminal))
  9385. {
  9386. Effect = DROPEFFECT_NONE;
  9387. }
  9388. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9389. {
  9390. Effect = DROPEFFECT_COPY;
  9391. }
  9392. }
  9393. }
  9394. //---------------------------------------------------------------------------
  9395. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9396. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9397. {
  9398. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9399. // do not allow dropping on the "+" and disconnected tabs
  9400. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9401. if (IsActiveTerminal(TargetTerminal))
  9402. {
  9403. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9404. if (!IsFileControl(DropSourceControl, osRemote))
  9405. {
  9406. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9407. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9408. // Why don't we use Terminal->CurrentDirectory directly?
  9409. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9410. // do not force queue, drag drop
  9411. false, true);
  9412. }
  9413. }
  9414. }
  9415. //---------------------------------------------------------------------------
  9416. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9417. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9418. {
  9419. // Downloads are handled in RemoteFileControlDDEnd
  9420. if (!IsFileControl(DropSourceControl, osRemote))
  9421. {
  9422. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9423. Terminal->CurrentDirectory,
  9424. // force queue, drag drop
  9425. true, true);
  9426. }
  9427. }
  9428. //---------------------------------------------------------------------------
  9429. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9430. {
  9431. FShowing = false;
  9432. // Do not save empty workspace
  9433. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9434. {
  9435. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9436. UnicodeString Name = WorkspaceName();
  9437. DoSaveWorkspace(
  9438. Name, DataList.get(),
  9439. !Configuration->DisablePasswordStoring &&
  9440. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9441. WinConfiguration->LastStoredSession = Name;
  9442. }
  9443. }
  9444. //---------------------------------------------------------------------------
  9445. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9446. {
  9447. TManagedTerminal * ManagedTerminal =
  9448. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9449. if (ManagedTerminal != NULL)
  9450. {
  9451. ManagedTerminal->DirectoryLoaded = Now();
  9452. }
  9453. }
  9454. //---------------------------------------------------------------------------
  9455. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9456. TListItem * /*Item*/, bool /*Selected*/)
  9457. {
  9458. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9459. switch (DirView->LastSelectMethod)
  9460. {
  9461. case smKeyboard:
  9462. Configuration->Usage->Inc(L"KeyboardSelections");
  9463. break;
  9464. case smMouse:
  9465. Configuration->Usage->Inc(L"MouseSelections");
  9466. break;
  9467. }
  9468. }
  9469. //---------------------------------------------------------------------------
  9470. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9471. {
  9472. if (Color != 0)
  9473. {
  9474. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9475. }
  9476. else
  9477. {
  9478. return FSessionTabImageIndex;
  9479. }
  9480. }
  9481. //---------------------------------------------------------------------------
  9482. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9483. {
  9484. TPngImageCollectionItem * Item =
  9485. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9486. FSessionColors->AddPng(Item->PngImage);
  9487. return FSessionColors->Count - 1;
  9488. }
  9489. //---------------------------------------------------------------------------
  9490. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9491. {
  9492. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9493. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9494. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9495. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9496. }
  9497. //---------------------------------------------------------------------------
  9498. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9499. {
  9500. for (int Index = 0; Index < Control->ControlCount; Index++)
  9501. {
  9502. TControl * AControl = Control->Controls[Index];
  9503. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9504. if (WinControl != NULL)
  9505. {
  9506. CollectItemsWithTextDisplayMode(WinControl);
  9507. }
  9508. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9509. if (Toolbar != NULL)
  9510. {
  9511. // we care for top-level items only
  9512. TTBCustomItem * Items = Toolbar->Items;
  9513. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9514. {
  9515. TTBCustomItem * Item = Items->Items[ItemIndex];
  9516. if (((Item->DisplayMode == nbdmImageAndText) ||
  9517. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9518. EligibleForImageDisplayMode(Item))
  9519. {
  9520. FItemsWithTextDisplayMode.insert(Item);
  9521. }
  9522. }
  9523. }
  9524. }
  9525. }
  9526. //---------------------------------------------------------------------------
  9527. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9528. {
  9529. return true;
  9530. }
  9531. //---------------------------------------------------------------------------
  9532. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9533. {
  9534. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9535. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9536. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9537. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9538. bool Result = true;
  9539. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9540. {
  9541. TTBCustomItem * Item = *i;
  9542. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9543. if (Label != NULL)
  9544. {
  9545. // optimization
  9546. if (Label->Visible == SelectiveToolbarText)
  9547. {
  9548. Result = false;
  9549. }
  9550. else
  9551. {
  9552. Label->Visible = SelectiveToolbarText;
  9553. }
  9554. }
  9555. else
  9556. {
  9557. // optimization
  9558. if (Item->DisplayMode == DisplayMode)
  9559. {
  9560. Result = false;
  9561. }
  9562. else
  9563. {
  9564. Item->DisplayMode = DisplayMode;
  9565. }
  9566. }
  9567. ++i;
  9568. }
  9569. if (Result)
  9570. {
  9571. UpdateNewSessionTab();
  9572. }
  9573. return Result;
  9574. }
  9575. //---------------------------------------------------------------------------
  9576. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9577. {
  9578. DebugFail();
  9579. }
  9580. //---------------------------------------------------------------------------
  9581. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9582. {
  9583. // Among other, a lock level is non zero, while directory is being loaded,
  9584. // even when it happens as a result of dirview navigation,
  9585. // i.e. when TNonVisualDataModule is NOT FBusy.
  9586. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9587. // Among other this prevents a panel auto update to occur while
  9588. // directory is changing.
  9589. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9590. }
  9591. //---------------------------------------------------------------------------
  9592. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  9593. {
  9594. // While the window is disabled, we still seem to process menu shortcuts at least,
  9595. // so stop it at least here.
  9596. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9597. return
  9598. (Allowed == aaUpdate) ||
  9599. !NonVisualDataModule->Busy;
  9600. }
  9601. //---------------------------------------------------------------------------
  9602. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9603. {
  9604. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9605. }
  9606. //---------------------------------------------------------------------------
  9607. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9608. {
  9609. // This is somewhat redundant to LockWindow() call from
  9610. // TTerminalManager::TerminalReadDirectoryProgress.
  9611. // But disabling window is known not to block keyboard shorcuts
  9612. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9613. if (Busy > 0)
  9614. {
  9615. if (NonVisualDataModule->Busy)
  9616. {
  9617. State = false;
  9618. }
  9619. else
  9620. {
  9621. NonVisualDataModule->StartBusy();
  9622. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9623. LockWindow();
  9624. }
  9625. }
  9626. else if (Busy < 0)
  9627. {
  9628. UnlockWindow();
  9629. NonVisualDataModule->EndBusy();
  9630. }
  9631. else
  9632. {
  9633. State = NonVisualDataModule->Busy;
  9634. }
  9635. }
  9636. //---------------------------------------------------------------------------
  9637. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9638. {
  9639. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9640. // no context menu for "New session tab"
  9641. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9642. {
  9643. SessionsPageControl->ActivePageIndex = Index;
  9644. if (DebugAlwaysTrue(SessionTabSwitched()))
  9645. {
  9646. // copied from TControl.WMContextMenu
  9647. SendCancelMode(SessionsPageControl);
  9648. // explicit popup instead of using PopupMenu property
  9649. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9650. // while connecting yet not-connected session and hence
  9651. // allowing an access to commands over not-completelly connected session
  9652. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9653. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9654. PopupMenu->PopupComponent = SessionsPageControl;
  9655. PopupMenu->Popup(Point.x, Point.y);
  9656. }
  9657. }
  9658. Handled = true;
  9659. }
  9660. //---------------------------------------------------------------------------
  9661. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9662. {
  9663. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9664. }
  9665. //---------------------------------------------------------------------------
  9666. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9667. {
  9668. Configuration->Usage->Inc(L"PasswordChanges");
  9669. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9670. ChangePasswordData->DisableAuthentationsExceptPassword();
  9671. ChangePasswordData->ChangePassword = true;
  9672. std::unique_ptr<TTerminal> ChangePasswordSession(
  9673. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9674. ChangePasswordSession->AutoReadDirectory = false;
  9675. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9676. {
  9677. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9678. }
  9679. else
  9680. {
  9681. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9682. }
  9683. }
  9684. //---------------------------------------------------------------------------
  9685. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9686. {
  9687. // No nice way to assert SSH2
  9688. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9689. }
  9690. //---------------------------------------------------------------------------
  9691. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9692. {
  9693. TOperationVisualizer OperationVisualizer;
  9694. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9695. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9696. }
  9697. //---------------------------------------------------------------------------
  9698. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9699. {
  9700. TForm::ChangeScale(M, D);
  9701. int APixelsPerInch = GetControlPixelsPerInch(this);
  9702. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9703. try
  9704. {
  9705. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9706. }
  9707. __finally
  9708. {
  9709. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9710. }
  9711. }
  9712. //---------------------------------------------------------------------------
  9713. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9714. {
  9715. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9716. }
  9717. //---------------------------------------------------------------------
  9718. class TPublicControl : public TControl
  9719. {
  9720. friend class TCustomScpExplorerForm;
  9721. };
  9722. //---------------------------------------------------------------------------
  9723. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9724. {
  9725. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9726. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9727. }
  9728. //---------------------------------------------------------------------------
  9729. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9730. {
  9731. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9732. OpenBookmark(Side, Bookmark);
  9733. }
  9734. //---------------------------------------------------------------------------
  9735. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9736. {
  9737. DoBookmarkClick(osLocal, Sender);
  9738. }
  9739. //---------------------------------------------------------------------------
  9740. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9741. {
  9742. DoBookmarkClick(osRemote, Sender);
  9743. }
  9744. //---------------------------------------------------------------------------
  9745. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9746. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9747. {
  9748. if (BookmarkList != NULL)
  9749. {
  9750. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9751. if (!WinConfiguration->UseLocationProfiles)
  9752. {
  9753. std::unique_ptr<TStringList> Directories(new TStringList());
  9754. Directories->CaseSensitive = (Side == osRemote);
  9755. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9756. {
  9757. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9758. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9759. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9760. {
  9761. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9762. Item->Caption = EscapeHotkey(Directory);
  9763. Item->ShortCut = Bookmark->ShortCut;
  9764. Item->OnClick = OnBookmarkClick;
  9765. Item->Tag = reinterpret_cast<int>(Bookmark);
  9766. Directories->Add(Directory);
  9767. Menu->Add(Item.release());
  9768. }
  9769. }
  9770. }
  9771. else
  9772. {
  9773. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9774. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9775. {
  9776. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9777. if (!Bookmark->Node.IsEmpty())
  9778. {
  9779. Folders->Add(Bookmark->Node);
  9780. }
  9781. }
  9782. for (int Index = 0; Index < Folders->Count; Index++)
  9783. {
  9784. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9785. Item->Caption = Folders->Strings[Index];
  9786. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction->ImageIndex;
  9787. Folders->Objects[Index] = Item.get();
  9788. Menu->Add(Item.release());
  9789. }
  9790. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9791. {
  9792. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9793. TTBCustomItem * Parent;
  9794. if (!Bookmark->Node.IsEmpty())
  9795. {
  9796. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9797. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9798. }
  9799. else
  9800. {
  9801. Parent = Menu;
  9802. }
  9803. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9804. Item->Caption = Bookmark->Name;
  9805. Item->ShortCut = Bookmark->ShortCut;
  9806. Item->OnClick = OnBookmarkClick;
  9807. Item->Tag = reinterpret_cast<int>(Bookmark);
  9808. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9809. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9810. {
  9811. // No hint for location profiles that are actually mere "bookmarks"
  9812. }
  9813. else
  9814. {
  9815. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9816. UnicodeString LongHint;
  9817. if (!Bookmark->Local.IsEmpty())
  9818. {
  9819. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9820. }
  9821. if (!Bookmark->Remote.IsEmpty())
  9822. {
  9823. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9824. }
  9825. AddToList(Hint, LongHint, L"|");
  9826. Item->Hint = Hint;
  9827. }
  9828. Parent->Add(Item.release());
  9829. }
  9830. }
  9831. AddMenuSeparator(Menu);
  9832. }
  9833. }
  9834. //---------------------------------------------------------------------------
  9835. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9836. {
  9837. Menu->Clear();
  9838. std::unique_ptr<TTBCustomItem> Item;
  9839. Item.reset(new TTBXItem(Owner));
  9840. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9841. Item->Options = Item->Options << tboDefault;
  9842. Menu->Add(Item.release());
  9843. AddMenuSeparator(Menu);
  9844. if (Terminal != NULL)
  9845. {
  9846. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9847. }
  9848. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9849. Item.reset(new TTBXItem(Owner));
  9850. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction : NonVisualDataModule->RemoteAddBookmarkAction;
  9851. Menu->Add(Item.release());
  9852. }
  9853. //---------------------------------------------------------------------------
  9854. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9855. {
  9856. bool Result = true;
  9857. try
  9858. {
  9859. if (Side == osRemote)
  9860. {
  9861. Terminal->ExceptionOnFail = true;
  9862. }
  9863. try
  9864. {
  9865. DirView(Side)->Path = Path;
  9866. }
  9867. __finally
  9868. {
  9869. if (Side == osRemote)
  9870. {
  9871. Terminal->ExceptionOnFail = false;
  9872. }
  9873. }
  9874. }
  9875. catch (Exception & E)
  9876. {
  9877. if ((Side != osRemote) || Terminal->Active)
  9878. {
  9879. ShowExtendedExceptionEx(Terminal, &E);
  9880. Result = false;
  9881. }
  9882. else
  9883. {
  9884. throw;
  9885. }
  9886. }
  9887. return Result;
  9888. }
  9889. //---------------------------------------------------------------------------
  9890. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9891. {
  9892. // Make sure there some feedback even when loading tiny local folders
  9893. TInstantOperationVisualizer Visualizer;
  9894. DirView(Side)->ReloadDirectory();
  9895. }
  9896. //---------------------------------------------------------------------------
  9897. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9898. {
  9899. if (Index == SessionsPageControl->TabIndex)
  9900. {
  9901. CloseSession();
  9902. }
  9903. else
  9904. {
  9905. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9906. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9907. TTerminalManager * Manager = TTerminalManager::Instance();
  9908. if (!Terminal->Active)
  9909. {
  9910. Manager->FreeTerminal(Terminal);
  9911. }
  9912. else
  9913. {
  9914. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9915. if (CanCloseQueue(Queue))
  9916. {
  9917. Manager->FreeTerminal(Terminal);
  9918. }
  9919. }
  9920. }
  9921. }
  9922. //---------------------------------------------------------------------------
  9923. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9924. {
  9925. CloseSessionTab(Index);
  9926. }
  9927. //---------------------------------------------------------------------------
  9928. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9929. {
  9930. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9931. {
  9932. TInstantOperationVisualizer Visualizer;
  9933. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9934. // before we create a new data object
  9935. ClipboardClear();
  9936. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9937. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9938. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9939. // Intermediate variable to WORKAROUND a crash in compiler
  9940. TObjectList * ClipboardFakeMonitors =
  9941. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9942. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9943. if (FClipboardDragDropFilesEx.get() == NULL)
  9944. {
  9945. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9946. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9947. }
  9948. FClipboardDragDropFilesEx->FileList->Clear();
  9949. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9950. FClipboardDragDropFilesEx->CopyToClipboard();
  9951. FClipboardTerminal = FTerminal;
  9952. // Need full paths, as cwd can be different once files are pasted
  9953. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9954. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9955. {
  9956. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9957. }
  9958. }
  9959. }
  9960. //---------------------------------------------------------------------------
  9961. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9962. {
  9963. if (OpenClipboard(0))
  9964. {
  9965. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9966. CloseClipboard();
  9967. }
  9968. }
  9969. //---------------------------------------------------------------------------
  9970. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9971. {
  9972. return !FClipboardFakeDirectory.IsEmpty();
  9973. }
  9974. //---------------------------------------------------------------------------
  9975. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9976. {
  9977. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9978. FClipboardFakeDirectory = UnicodeString();
  9979. FClipboardTerminal = NULL;
  9980. // Also called in Idle()
  9981. FClipboardFakeMonitors.reset(NULL);
  9982. }
  9983. //---------------------------------------------------------------------------
  9984. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9985. {
  9986. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9987. {
  9988. ClipboardStop();
  9989. }
  9990. }
  9991. //---------------------------------------------------------------------------
  9992. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9993. {
  9994. TTerminalManager * Manager = TTerminalManager::Instance();
  9995. Manager->ActiveTerminal = FClipboardTerminal;
  9996. TTransferOperationParam Params;
  9997. Params.TargetDirectory = TargetDirectory;
  9998. Params.DragDrop = DragDrop;
  9999. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  10000. }
  10001. //---------------------------------------------------------------------------
  10002. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  10003. {
  10004. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  10005. // (as it pumps a Windows message queue while being shutted down)
  10006. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10007. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10008. {
  10009. // Can fail as it can be e.g. locked by AV, so we retry that later
  10010. bool Removed = RemoveDir(ApiPath(FileName));
  10011. try
  10012. {
  10013. if (!NonVisualDataModule->Busy)
  10014. {
  10015. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10016. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  10017. }
  10018. }
  10019. __finally
  10020. {
  10021. if (!Removed)
  10022. {
  10023. RemoveDir(ApiPath(FileName));
  10024. }
  10025. }
  10026. }
  10027. }
  10028. //---------------------------------------------------------------------------
  10029. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10030. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10031. {
  10032. TFileMasks::TParams MaskParams;
  10033. MaskParams.Size = Size;
  10034. MaskParams.Modification = Modification;
  10035. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10036. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10037. {
  10038. bool ImplicitMatch;
  10039. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  10040. !ImplicitMatch)
  10041. {
  10042. Color = Iter->Color;
  10043. break;
  10044. }
  10045. }
  10046. }
  10047. //---------------------------------------------------------------------------
  10048. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10049. {
  10050. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10051. if (!DirView->IsEditing())
  10052. {
  10053. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10054. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10055. // while searching
  10056. if (Key == VK_BACK)
  10057. {
  10058. if (!FIncrementalSearch.IsEmpty())
  10059. {
  10060. if (FIncrementalSearch.Length() == 1)
  10061. {
  10062. ResetIncrementalSearch();
  10063. }
  10064. else
  10065. {
  10066. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10067. IncrementalSearch(NewText, false, false);
  10068. }
  10069. Key = 0;
  10070. }
  10071. }
  10072. }
  10073. }
  10074. //---------------------------------------------------------------------------
  10075. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10076. {
  10077. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10078. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10079. {
  10080. // Filter control sequences.
  10081. // When not searching yet, prefer use of the space for toggling file selection
  10082. // (so we cannot incrementally search for a string starting with a space).
  10083. if ((Key > VK_SPACE) ||
  10084. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10085. {
  10086. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10087. Key = 0;
  10088. }
  10089. }
  10090. }
  10091. //---------------------------------------------------------------------------
  10092. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10093. {
  10094. if (!FIncrementalSearch.IsEmpty())
  10095. {
  10096. FIncrementalSearch = L"";
  10097. DirView(osCurrent)->UpdateStatusBar();
  10098. }
  10099. }
  10100. //---------------------------------------------------------------------------
  10101. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10102. {
  10103. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10104. if (Item == NULL)
  10105. {
  10106. MessageBeep(MB_ICONHAND);
  10107. }
  10108. else
  10109. {
  10110. TCustomDirView * ADirView = DirView(osCurrent);
  10111. {
  10112. TAutoNestingCounter Guard(FIncrementalSearching);
  10113. ADirView->FocusItem(Item);
  10114. if (ADirView->NortonLike == nlOff)
  10115. {
  10116. if ((ADirView->Selected != Item) ||
  10117. (ADirView->SelCount > 1))
  10118. {
  10119. ADirView->ClearSelection();
  10120. ADirView->Selected = Item;
  10121. }
  10122. }
  10123. }
  10124. FIncrementalSearch = Text;
  10125. Item->MakeVisible(false);
  10126. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10127. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10128. ADirView->UpdateStatusBar();
  10129. }
  10130. }
  10131. //---------------------------------------------------------------------------
  10132. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10133. {
  10134. int Index = Item->Index;
  10135. if (!Reverse)
  10136. {
  10137. Index++;
  10138. if (Index >= Item->Owner->Count)
  10139. {
  10140. Index = 0;
  10141. }
  10142. }
  10143. else
  10144. {
  10145. Index--;
  10146. if (Index < 0)
  10147. {
  10148. Index = Item->Owner->Count - 1;
  10149. }
  10150. }
  10151. return Item->Owner->Item[Index];
  10152. }
  10153. //---------------------------------------------------------------------------
  10154. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10155. {
  10156. TCustomDirView * ADirView = DirView(osCurrent);
  10157. if (ADirView->Items->Count == 0)
  10158. {
  10159. return NULL;
  10160. }
  10161. else
  10162. {
  10163. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10164. TListItem * Item = CurrentItem;
  10165. if (SkipCurrent)
  10166. {
  10167. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10168. }
  10169. while (true)
  10170. {
  10171. bool Matches = false;
  10172. switch (WinConfiguration->PanelSearch)
  10173. {
  10174. case isNameStartOnly:
  10175. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10176. break;
  10177. case isName:
  10178. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10179. break;
  10180. case isAll:
  10181. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10182. int Index = 0;
  10183. while ((Index < ColCount) && !Matches)
  10184. {
  10185. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10186. if (Visible)
  10187. {
  10188. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10189. }
  10190. Index++;
  10191. }
  10192. break;
  10193. }
  10194. if (Matches)
  10195. {
  10196. return Item;
  10197. }
  10198. Item = GetNextFile(Item, Reverse);
  10199. if (Item == CurrentItem)
  10200. {
  10201. return NULL;
  10202. }
  10203. }
  10204. }
  10205. }
  10206. //---------------------------------------------------------------------------
  10207. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10208. {
  10209. ResetIncrementalSearch();
  10210. }
  10211. //---------------------------------------------------------------------------
  10212. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10213. {
  10214. if (Message.CharCode == VK_TAB)
  10215. {
  10216. if (!FIncrementalSearch.IsEmpty())
  10217. {
  10218. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10219. bool Reverse = Shift.Contains(ssShift);
  10220. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10221. Message.Result = 1;
  10222. return;
  10223. }
  10224. }
  10225. else if (Message.CharCode == VK_ESCAPE)
  10226. {
  10227. if (!FIncrementalSearch.IsEmpty())
  10228. {
  10229. ResetIncrementalSearch();
  10230. Message.Result = 1;
  10231. return;
  10232. }
  10233. }
  10234. TForm::Dispatch(&Message);
  10235. }
  10236. //---------------------------------------------------------------------------
  10237. void __fastcall TCustomScpExplorerForm::Deactivate()
  10238. {
  10239. TForm::Deactivate();
  10240. // E.g. when switching to an internal editor window
  10241. ResetIncrementalSearch();
  10242. }
  10243. //---------------------------------------------------------------------------
  10244. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10245. {
  10246. // When switching to another application
  10247. ResetIncrementalSearch();
  10248. }
  10249. //---------------------------------------------------------------------------
  10250. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10251. {
  10252. ResetIncrementalSearch();
  10253. }
  10254. //---------------------------------------------------------------------------
  10255. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10256. {
  10257. if (FIncrementalSearching <= 0)
  10258. {
  10259. ResetIncrementalSearch();
  10260. }
  10261. }
  10262. //---------------------------------------------------------------------------
  10263. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10264. {
  10265. CountClicksForWindowPrint(this);
  10266. }
  10267. //---------------------------------------------------------------------------
  10268. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10269. {
  10270. CenterReconnectToolbar();
  10271. }
  10272. //---------------------------------------------------------------------------
  10273. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10274. {
  10275. if (RemoteDirView->ItemFocused != NULL)
  10276. {
  10277. RemoteDirView->ItemFocused->Selected = true;
  10278. }
  10279. }
  10280. //---------------------------------------------------------------------------
  10281. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10282. {
  10283. if (!FQueueStatusUpdating)
  10284. {
  10285. bool Refresh;
  10286. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10287. {
  10288. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10289. }
  10290. else
  10291. {
  10292. if (FQueueFileList->GetCount() > 0)
  10293. {
  10294. FQueueFileList->Clear();
  10295. Refresh = true;
  10296. }
  10297. }
  10298. int Count = FQueueFileList->GetCount();
  10299. if (QueueFileList->Items->Count != Count)
  10300. {
  10301. DebugAssert(Refresh);
  10302. QueueFileList->Items->Count = Count;
  10303. }
  10304. if (Refresh)
  10305. {
  10306. QueueFileList->Invalidate();
  10307. }
  10308. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10309. }
  10310. }
  10311. //---------------------------------------------------------------------------
  10312. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10313. {
  10314. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10315. }
  10316. //---------------------------------------------------------------------------
  10317. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10318. {
  10319. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10320. // See TSynchronizeChecklistDialog::UpdateTimer
  10321. if (QueueFileList->Items->Count > 0)
  10322. {
  10323. QueueFileList->Items->Item[0]->MakeVisible(false);
  10324. }
  10325. UpdateQueueFileList();
  10326. }
  10327. //---------------------------------------------------------------------------
  10328. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10329. {
  10330. Active = QueueView3->Focused() || QueueFileList->Focused();
  10331. }
  10332. //---------------------------------------------------------------------------
  10333. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10334. {
  10335. QueueLabelUpdateStatus();
  10336. }
  10337. //---------------------------------------------------------------------------
  10338. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10339. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10340. {
  10341. int State = FQueueFileList->GetState(Item->Index);
  10342. if (State == qfsProcessed)
  10343. {
  10344. Sender->Canvas->Font->Color = clGrayText;
  10345. }
  10346. }
  10347. //---------------------------------------------------------------------------
  10348. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10349. {
  10350. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10351. QueueFileList->Column[0]->Width =
  10352. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10353. }
  10354. //---------------------------------------------------------------------------
  10355. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10356. {
  10357. QueueFileListColumnAutoSize();
  10358. }
  10359. //---------------------------------------------------------------------------
  10360. void __fastcall TCustomScpExplorerForm::CloseApp()
  10361. {
  10362. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10363. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10364. // So we clear the flag here.
  10365. DebugAssert(NonVisualDataModule->Busy);
  10366. NonVisualDataModule->EndBusy();
  10367. try
  10368. {
  10369. Close();
  10370. }
  10371. __finally
  10372. {
  10373. NonVisualDataModule->StartBusy();
  10374. }
  10375. }
  10376. //---------------------------------------------------------------------------
  10377. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10378. {
  10379. return (Terminal != NULL) && Terminal->Active;
  10380. }
  10381. //---------------------------------------------------------------------------
  10382. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10383. {
  10384. return IsActiveTerminal(Terminal);
  10385. }