CustomScpExplorer.cpp 361 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997
  1. //---------------------------------------------------------------------------
  2. #define NO_WIN32_LEAN_AND_MEAN
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <Common.h>
  6. #include "CustomScpExplorer.h"
  7. #include <Bookmarks.h>
  8. #include <Interface.h>
  9. #include <Exceptions.h>
  10. #include <CoreMain.h>
  11. #include <FileSystems.h>
  12. #include <TextsCore.h>
  13. #include <TextsWin.h>
  14. #include <HelpWin.h>
  15. #include <VCLCommon.h>
  16. #include <Progress.h>
  17. #include <SynchronizeProgress.h>
  18. #include <DragExt.h>
  19. #include <WinApi.h>
  20. #include "GUITools.h"
  21. #include "NonVisual.h"
  22. #include "Glyphs.h"
  23. #include "Tools.h"
  24. #include "WinConfiguration.h"
  25. #include "TerminalManager.h"
  26. #include "EditorManager.h"
  27. #include "ProgParams.h"
  28. #include "Setup.h"
  29. #include <Consts.hpp>
  30. #include <DateUtils.hpp>
  31. #include <TB2Common.hpp>
  32. #include <DirectoryMonitor.hpp>
  33. #include <System.IOUtils.hpp>
  34. //---------------------------------------------------------------------------
  35. #pragma package(smart_init)
  36. #pragma link "CustomDirView"
  37. #pragma link "CustomUnixDirView"
  38. #pragma link "IEListView"
  39. #pragma link "NortonLikeListView"
  40. #pragma link "UnixDirView"
  41. #pragma link "CustomDriveView"
  42. #pragma link "UnixDriveView"
  43. #pragma link "CustomDriveView"
  44. #pragma link "TB2Dock"
  45. #pragma link "TBXStatusBars"
  46. #pragma link "TB2Item"
  47. #pragma link "TB2Toolbar"
  48. #pragma link "ThemePageControl"
  49. #pragma link "PathLabel"
  50. #pragma resource "*.dfm"
  51. //---------------------------------------------------------------------------
  52. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  53. static const int SessionPanelCount = 4;
  54. //---------------------------------------------------------------------------
  55. class TMutexGuard
  56. {
  57. public:
  58. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  59. int Timeout = 5000)
  60. {
  61. FMutex = NULL;
  62. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  63. if (WaitResult == WAIT_TIMEOUT)
  64. {
  65. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  66. }
  67. else
  68. {
  69. FMutex = AMutex;
  70. }
  71. }
  72. ~TMutexGuard()
  73. {
  74. if (FMutex != NULL)
  75. {
  76. ReleaseMutex(FMutex);
  77. }
  78. }
  79. private:
  80. HANDLE FMutex;
  81. };
  82. //---------------------------------------------------------------------------
  83. class TWindowLock
  84. {
  85. public:
  86. TWindowLock(TCustomScpExplorerForm * Form) :
  87. FForm(Form)
  88. {
  89. FForm->LockWindow();
  90. }
  91. ~TWindowLock()
  92. {
  93. FForm->UnlockWindow();
  94. }
  95. private:
  96. TCustomScpExplorerForm * FForm;
  97. };
  98. //---------------------------------------------------------------------------
  99. class TAutoBatch
  100. {
  101. public:
  102. TAutoBatch(TCustomScpExplorerForm * Form) :
  103. FForm(Form)
  104. {
  105. FForm->BatchStart(FBatchStorage);
  106. }
  107. ~TAutoBatch()
  108. {
  109. FForm->BatchEnd(FBatchStorage);
  110. }
  111. private:
  112. TCustomScpExplorerForm * FForm;
  113. void * FBatchStorage;
  114. };
  115. //---------------------------------------------------------------------------
  116. struct TTransferOperationParam
  117. {
  118. TTransferOperationParam();
  119. UnicodeString TargetDirectory;
  120. bool Temp;
  121. bool DragDrop;
  122. int Options;
  123. TAutoSwitch Queue;
  124. };
  125. //---------------------------------------------------------------------------
  126. TTransferOperationParam::TTransferOperationParam()
  127. {
  128. Temp = false;
  129. DragDrop = false;
  130. Options = 0;
  131. Queue = asAuto;
  132. }
  133. //---------------------------------------------------------------------------
  134. class TTransferPresetNoteData : public TObject
  135. {
  136. public:
  137. UnicodeString Message;
  138. };
  139. //---------------------------------------------------------------------------
  140. class TTerminalNoteData : public TObject
  141. {
  142. public:
  143. TManagedTerminal * Terminal;
  144. };
  145. //---------------------------------------------------------------------------
  146. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  147. FFormRestored(false),
  148. TForm(Owner)
  149. {
  150. FInvalid = false;
  151. FCurrentSide = osRemote;
  152. FEverShown = false;
  153. FDocks = new TList();
  154. InitControls();
  155. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  156. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  157. NonVisualDataModule->ScpExplorer = this;
  158. RestoreParams();
  159. ConfigurationChanged();
  160. RemoteDirView->Invalidate();
  161. FAutoOperation = false;
  162. FOnFileOperationFinished = NULL;
  163. FForceExecution = false;
  164. FIgnoreNextDialogChar = 0;
  165. FErrorList = NULL;
  166. FSynchronizeProgressForm = NULL;
  167. FProgressForm = NULL;
  168. FRefreshLocalDirectory = false;
  169. FRefreshRemoteDirectory = false;
  170. FDDExtMapFile = NULL;
  171. // CreateMutexW keeps failing with ERROR_NOACCESS
  172. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  173. DebugAssert(FDDExtMutex != NULL);
  174. FDDTargetControl = NULL;
  175. FDelayedDeletionTimer = NULL;
  176. FDelayedDeletionList = new TStringList();
  177. FDDFileList = NULL;
  178. FPendingTempSpaceWarn = false;
  179. FCapturedLog = NULL;
  180. FDragDropOperation = false;
  181. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  182. FAllowTransferPresetAutoSelect = true;
  183. FCopyParamDefault = L"";
  184. FSynchronizeController = NULL;
  185. FPendingQueueActionItem = NULL;
  186. FLockLevel = 0;
  187. FLockSuspendLevel = 0;
  188. FDisabledOnLockSuspend = false;
  189. FAlternativeDelete = false;
  190. FTrayIcon = new ::TTrayIcon(0);
  191. FTrayIcon->OnClick = TrayIconClick;
  192. FMaxQueueLength = 0;
  193. FLastContextPopupScreenPoint = TPoint(-1, -1);
  194. FTransferResumeList = NULL;
  195. FMoveToQueue = false;
  196. FStandaloneEditing = false;
  197. FOnFeedSynchronizeError = NULL;
  198. FNeedSession = false;
  199. FDoNotIdleCurrentTerminal = 0;
  200. FIncrementalSearching = 0;
  201. FIncrementalSearchHaveNext = false;
  202. FQueueFileList.reset(new TQueueFileList());
  203. FEditorManager = new TEditorManager();
  204. FEditorManager->OnFileChange = ExecutedFileChanged;
  205. FEditorManager->OnFileReload = ExecutedFileReload;
  206. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  207. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  208. FLocalEditors = new TList();
  209. FQueueStatus = NULL;
  210. FQueueStatusSection = new TCriticalSection();
  211. FQueueStatusInvalidated = false;
  212. FQueueItemInvalidated = false;
  213. FQueueStatusUpdating = false;
  214. FQueueActedItem = NULL;
  215. FQueueController = new TQueueController(QueueView3);
  216. FUserActionTimer = new TTimer(this);
  217. FUserActionTimer->Enabled = false;
  218. FUserActionTimer->Interval = 10;
  219. FUserActionTimer->OnTimer = UserActionTimer;
  220. FNotes = new TStringList();
  221. FNoteTimer = new TTimer(this);
  222. FNoteTimer->Enabled = false;
  223. FNoteTimer->OnTimer = NoteTimer;
  224. FOnNoteClick = NULL;
  225. FOle32Library = LoadLibrary(L"Ole32.dll");
  226. FDragMoveCursor = FOle32Library != NULL ?
  227. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  228. UseSystemSettings(this);
  229. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  230. static_cast<TObject*>(GetComponent(fcTransferList)));
  231. DebugAssert(TransferList != NULL);
  232. FTransferListHoverIndex = -1;
  233. TransferList->OnChange = TransferListChange;
  234. TransferList->OnDrawItem = TransferListDrawItem;
  235. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  236. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  237. UseDesktopFont(SessionsPageControl);
  238. UpdateSessionsPageControlHeight();
  239. UseDesktopFont(RemoteDirView);
  240. UseDesktopFont(RemoteDriveView);
  241. UseDesktopFont(QueueView3);
  242. UseDesktopFont(QueueFileList);
  243. UseDesktopFont(QueueLabel);
  244. UseDesktopFont(RemoteStatusBar);
  245. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  246. QueueSplitter->ShowHint = true;
  247. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  248. QueueFileListSplitter->ShowHint = true;
  249. RemotePanelSplitter->ShowHint = true;
  250. UpdateImages();
  251. FCustomCommandMenu = CreateTBXPopupMenu(this);
  252. FCustomCommandLocalFileList = NULL;
  253. FCustomCommandRemoteFileList = NULL;
  254. FSessionColors = new TPngImageList(this);
  255. FSessionColors->ColorDepth = cd32Bit;
  256. AddFixedSessionImages();
  257. SessionsPageControl->Images = FSessionColors;
  258. UpdateQueueLabel();
  259. FRemoteDirViewWasFocused = true;
  260. CreateHiddenWindow();
  261. StartUpdates();
  262. }
  263. //---------------------------------------------------------------------------
  264. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  265. {
  266. FInvalid = true;
  267. // this has to be one of the very first things to do
  268. StopUpdateThread();
  269. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  270. TTerminalManager::Instance()->ScpExplorer = NULL;
  271. delete FCustomCommandLocalFileList;
  272. delete FCustomCommandRemoteFileList;
  273. delete FCustomCommandMenu;
  274. delete FTrayIcon;
  275. FTrayIcon = NULL;
  276. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  277. delete FEditorManager;
  278. ForceCloseLocalEditors();
  279. delete FLocalEditors;
  280. HideFileFindDialog();
  281. if (FDelayedDeletionTimer)
  282. {
  283. DoDelayedDeletion(NULL);
  284. SAFE_DESTROY(FDelayedDeletionTimer);
  285. }
  286. SAFE_DESTROY(FDelayedDeletionList);
  287. // sometimes we do not get DDEnd so the list is not released
  288. SAFE_DESTROY(FDDFileList);
  289. DebugAssert(FSynchronizeController == NULL);
  290. CloseHandle(FDDExtMutex);
  291. FDDExtMutex = NULL;
  292. FreeLibrary(FOle32Library);
  293. FOle32Library = NULL;
  294. FDragMoveCursor = NULL;
  295. DebugAssert(!FErrorList);
  296. if (FEverShown)
  297. {
  298. // when window is never shown (like when running command-line operation),
  299. // particularly window site is not restored correctly (BoundsRect value set
  300. // in RestoreForm gets lost during handle allocation), so we do not want
  301. // it to be stored
  302. StoreParams();
  303. }
  304. Terminal = NULL;
  305. Queue = NULL;
  306. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  307. NonVisualDataModule->ScpExplorer = NULL;
  308. delete FQueueController;
  309. FQueueController = NULL;
  310. delete FQueueStatusSection;
  311. FQueueStatusSection = NULL;
  312. delete FQueueStatus;
  313. FQueueStatus = NULL;
  314. delete FUserActionTimer;
  315. FUserActionTimer = NULL;
  316. delete FNoteTimer;
  317. delete FNotes;
  318. delete FNoteData;
  319. SAFE_DESTROY(FDocks);
  320. SessionsPageControl->Images = NULL;
  321. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  322. SAFE_DESTROY(FSessionColors);
  323. SAFE_DESTROY(FSessionsDragDropFilesEx);
  324. SAFE_DESTROY(FHistoryMenu[0][0]);
  325. SAFE_DESTROY(FHistoryMenu[0][1]);
  326. SAFE_DESTROY(FHistoryMenu[1][0]);
  327. SAFE_DESTROY(FHistoryMenu[1][1]);
  328. if (FHiddenWindow != NULL)
  329. {
  330. DestroyWindow(FHiddenWindow);
  331. FHiddenWindow = NULL;
  332. }
  333. }
  334. //---------------------------------------------------------------------------
  335. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  336. {
  337. std::unique_ptr<TSessionData> Data;
  338. if (!Session.IsEmpty())
  339. {
  340. bool DefaultsOnly;
  341. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  342. }
  343. TTerminalManager * Manager = TTerminalManager::Instance();
  344. for (int Index = 0; Index < Manager->Count; Index++)
  345. {
  346. TTerminal * Terminal = Manager->Terminals[Index];
  347. if (Session.IsEmpty() ||
  348. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  349. {
  350. if (Path.IsEmpty())
  351. {
  352. Terminal->ClearCaches();
  353. }
  354. else
  355. {
  356. Terminal->DirectoryModified(Path, true);
  357. }
  358. }
  359. }
  360. // We should flag a pending refresh for the background terminals or busy foreground terminals
  361. if (HasActiveTerminal() &&
  362. CanCommandLineFromAnotherInstance() &&
  363. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  364. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  365. {
  366. Terminal->ReloadDirectory();
  367. }
  368. }
  369. //---------------------------------------------------------------------------
  370. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  371. {
  372. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  373. size_t MessageSize = sizeof(TCopyDataMessage);
  374. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  375. if (Result)
  376. {
  377. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  378. Result = (Message.Version == TCopyDataMessage::Version1);
  379. if (Result)
  380. {
  381. switch (Message.Command)
  382. {
  383. case TCopyDataMessage::CommandCanCommandLine:
  384. Result = CanCommandLineFromAnotherInstance();
  385. break;
  386. case TCopyDataMessage::CommandCommandLine:
  387. {
  388. UnicodeString CommandLine(Message.CommandLine);
  389. Result = CommandLineFromAnotherInstance(CommandLine);
  390. }
  391. break;
  392. case TCopyDataMessage::RefreshPanel:
  393. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  394. break;
  395. case TCopyDataMessage::MainWindowCheck:
  396. Result = true;
  397. break;
  398. default:
  399. Result = false;
  400. break;
  401. }
  402. }
  403. }
  404. Message.Result = Result ? 1 : 0;
  405. }
  406. //---------------------------------------------------------------------------
  407. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  408. {
  409. WNDCLASS WindowClass = {0};
  410. WindowClass.lpfnWndProc = DefWindowProc;
  411. WindowClass.hInstance = HInstance;
  412. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  413. FHiddenWindow = NULL;
  414. if (RegisterClass(&WindowClass))
  415. {
  416. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  417. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  418. }
  419. }
  420. //---------------------------------------------------------------------------
  421. bool __fastcall TCustomScpExplorerForm::CanConsole()
  422. {
  423. return
  424. HasActiveTerminal() &&
  425. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  426. }
  427. //---------------------------------------------------------------------------
  428. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  429. {
  430. bool Result = Visible && !NonVisualDataModule->Busy;
  431. return Result;
  432. }
  433. //---------------------------------------------------------------------------
  434. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  435. const UnicodeString & CommandLine)
  436. {
  437. TProgramParams Params(CommandLine);
  438. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  439. if (Result)
  440. {
  441. NonVisualDataModule->StartBusy();
  442. try
  443. {
  444. // this action is initiated from another process,
  445. // so it's likely that our window is not visible,
  446. // and user won't see what is going on
  447. Application->BringToFront();
  448. // reload sessions as we may be asked to open a session
  449. // just stored by another instance
  450. StoredSessions->Reload();
  451. UnicodeString SessionName = Params.Param[1];
  452. std::unique_ptr<TObjectList> DataList(new TObjectList());
  453. UnicodeString DownloadFile; // unused
  454. try
  455. {
  456. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  457. }
  458. catch (EAbort &)
  459. {
  460. // Happens when opening session in PuTTY and in other situations,
  461. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  462. // to process the command-line on its own (or to pass it to yet another instance)
  463. }
  464. if (DataList->Count > 0)
  465. {
  466. TTerminalManager * Manager = TTerminalManager::Instance();
  467. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  468. }
  469. }
  470. __finally
  471. {
  472. NonVisualDataModule->EndBusy();
  473. }
  474. }
  475. return Result;
  476. }
  477. //---------------------------------------------------------------------------
  478. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  479. {
  480. if (FTerminal != value)
  481. {
  482. TerminalChanging();
  483. DoSetTerminal(value, false);
  484. }
  485. }
  486. //---------------------------------------------------------------------------
  487. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  488. {
  489. FTerminal = value;
  490. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  491. FAllowTransferPresetAutoSelect = false;
  492. try
  493. {
  494. TerminalChanged(Replace);
  495. }
  496. __finally
  497. {
  498. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  499. }
  500. if (Terminal != NULL)
  501. {
  502. TransferPresetAutoSelect();
  503. }
  504. }
  505. //---------------------------------------------------------------------------
  506. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  507. {
  508. DoSetTerminal(value, true);
  509. }
  510. //---------------------------------------------------------------------------
  511. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  512. {
  513. if (FTerminal != NULL)
  514. {
  515. UpdateTerminal(Terminal);
  516. }
  517. }
  518. //---------------------------------------------------------------------------
  519. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  520. {
  521. if (Terminal != NULL)
  522. {
  523. UpdateSessionColor((TColor)Terminal->StateData->Color);
  524. }
  525. DoTerminalListChanged();
  526. DebugAssert(!IsLocalBrowserMode()); // TODO
  527. if (Replaced)
  528. {
  529. RemoteDirView->ReplaceTerminal(Terminal);
  530. }
  531. else
  532. {
  533. RemoteDirView->Terminal = Terminal;
  534. }
  535. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  536. if (Terminal != NULL)
  537. {
  538. if (Terminal->Active)
  539. {
  540. Terminal->RefreshDirectory();
  541. }
  542. if (WinConfiguration->PreservePanelState)
  543. {
  544. if (Terminal->RemoteExplorerState != NULL)
  545. {
  546. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  547. }
  548. else
  549. {
  550. DirView(osRemote)->ClearState();
  551. }
  552. }
  553. if (!Replaced && Terminal->Active)
  554. {
  555. InitStatusBar();
  556. }
  557. }
  558. UpdateTransferList();
  559. // Update panels Enable state before refreshing the labels
  560. UpdateControls();
  561. }
  562. //---------------------------------------------------------------------------
  563. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  564. {
  565. if (Queue != value)
  566. {
  567. if (FQueue != NULL)
  568. {
  569. FQueue->OnListUpdate = NULL;
  570. FQueue->OnQueueItemUpdate = NULL;
  571. }
  572. FQueue = value;
  573. if (FQueue != NULL)
  574. {
  575. DebugAssert(FQueue->OnListUpdate == NULL);
  576. FQueue->OnListUpdate = QueueListUpdate;
  577. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  578. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  579. }
  580. QueueChanged();
  581. }
  582. }
  583. //---------------------------------------------------------------------------
  584. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  585. TListItem * Item)
  586. {
  587. if (FQueueActedItem == Item)
  588. {
  589. FQueueActedItem = NULL;
  590. if ((QueueView3->PopupMenu != NULL) &&
  591. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  592. {
  593. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  594. ReleaseCapture();
  595. }
  596. }
  597. if (Item->Data == FPendingQueueActionItem)
  598. {
  599. FPendingQueueActionItem = NULL;
  600. }
  601. }
  602. //---------------------------------------------------------------------------
  603. bool TCustomScpExplorerForm::IsAnythingQueued()
  604. {
  605. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  606. }
  607. //---------------------------------------------------------------------------
  608. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  609. {
  610. {
  611. TGuard Guard(FQueueStatusSection);
  612. FQueueStatusInvalidated = false;
  613. if (FQueue != NULL)
  614. {
  615. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  616. }
  617. }
  618. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  619. {
  620. FMaxQueueLength = FQueueStatus->Count;
  621. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  622. }
  623. {
  624. TAutoFlag Flag(FQueueStatusUpdating);
  625. FQueueController->UpdateQueueStatus(FQueueStatus);
  626. }
  627. UpdateQueueFileList();
  628. SetQueueProgress();
  629. UpdateQueueView();
  630. bool IsEmpty = !IsAnythingQueued();
  631. if (IsEmpty && (Terminal != NULL))
  632. {
  633. TOnceDoneOperation OnceDoneOperation =
  634. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  635. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  636. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  637. {
  638. FQueue->Enabled = false;
  639. }
  640. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  641. {
  642. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  643. }
  644. }
  645. }
  646. //---------------------------------------------------------------------------
  647. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  648. {
  649. UnicodeString Result;
  650. if (FQueueStatus != NULL)
  651. {
  652. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  653. {
  654. TFileOperationProgressType * ProgressData =
  655. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  656. if ((ProgressData != NULL) && ProgressData->InProgress)
  657. {
  658. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  659. }
  660. }
  661. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  662. {
  663. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  664. }
  665. }
  666. return Result;
  667. }
  668. //---------------------------------------------------------------------------
  669. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  670. {
  671. ComponentVisible[fcQueueView] =
  672. (WinConfiguration->QueueView.Show == qvShow) ||
  673. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  674. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  675. }
  676. //---------------------------------------------------------------------------
  677. void __fastcall TCustomScpExplorerForm::QueueChanged()
  678. {
  679. if (FQueueStatus != NULL)
  680. {
  681. // UpdateFileList implementation relies on the status being recreated when session changes
  682. delete FQueueStatus;
  683. FQueueStatus = NULL;
  684. }
  685. UpdateQueueStatus(true);
  686. }
  687. //---------------------------------------------------------------------------
  688. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  689. {
  690. if (FQueue == Queue)
  691. {
  692. FQueueStatusInvalidated = true;
  693. }
  694. }
  695. //---------------------------------------------------------------------------
  696. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  697. TQueueItem * Item)
  698. {
  699. if (FQueue == Queue)
  700. {
  701. TGuard Guard(FQueueStatusSection);
  702. // this may be running in parallel with QueueChanged
  703. if (FQueueStatus != NULL)
  704. {
  705. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  706. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  707. {
  708. FRefreshLocalDirectory = (QueueItem == NULL) ||
  709. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  710. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  711. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  712. }
  713. if (QueueItem != NULL)
  714. {
  715. QueueItem->UserData = (void*)true;
  716. FQueueItemInvalidated = true;
  717. }
  718. }
  719. }
  720. }
  721. //---------------------------------------------------------------------------
  722. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  723. {
  724. // during standalone editing, we have no way to see/control queue,
  725. // so we have to always popup prompts automatically
  726. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  727. }
  728. //---------------------------------------------------------------------------
  729. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  730. {
  731. if (FQueueStatus != NULL)
  732. {
  733. bool QueueAutoPopup = IsQueueAutoPopup();
  734. bool NeedRefresh = FQueueController->NeedRefresh();
  735. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  736. FQueueItemInvalidated = false;
  737. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  738. bool Updated = false;
  739. TQueueItemProxy * QueueItem;
  740. bool WasUserAction;
  741. for (int Index = 0; Index < Limit; Index++)
  742. {
  743. bool Update = false;
  744. QueueItem = FQueueStatus->Items[Index];
  745. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  746. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  747. (FPendingQueueActionItem == NULL))
  748. {
  749. FPendingQueueActionItem = QueueItem;
  750. FUserActionTimer->Enabled = true;
  751. }
  752. if ((bool)QueueItem->UserData)
  753. {
  754. QueueItem->UserData = (void*)false;
  755. QueueItem->Update();
  756. Updated = true;
  757. Update = true;
  758. }
  759. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  760. {
  761. Update = true;
  762. }
  763. if (Update)
  764. {
  765. FQueueController->RefreshQueueItem(QueueItem);
  766. }
  767. }
  768. if (Updated)
  769. {
  770. NonVisualDataModule->UpdateNonVisibleActions();
  771. SetQueueProgress();
  772. UpdateQueueFileList();
  773. }
  774. }
  775. }
  776. //---------------------------------------------------------------------------
  777. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  778. {
  779. if (FTaskbarList != NULL)
  780. {
  781. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  782. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  783. }
  784. }
  785. //---------------------------------------------------------------------------
  786. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  787. {
  788. if (Progress >= 0)
  789. {
  790. if (FTaskbarList != NULL)
  791. {
  792. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  793. }
  794. }
  795. else
  796. {
  797. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  798. }
  799. }
  800. //---------------------------------------------------------------------------
  801. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  802. {
  803. int OverallProgress;
  804. // FProgressForm is null when this is called from SetQueueProgress
  805. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  806. {
  807. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  808. }
  809. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  810. {
  811. OverallProgress = ProgressData->OverallProgress();
  812. }
  813. else
  814. {
  815. OverallProgress = -1;
  816. }
  817. SetTaskbarListProgressValue(OverallProgress);
  818. }
  819. //---------------------------------------------------------------------------
  820. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  821. {
  822. TTerminalManager::Instance()->QueueStatusUpdated();
  823. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  824. {
  825. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  826. {
  827. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  828. {
  829. TFileOperationProgressType * ProgressData = NULL;
  830. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  831. {
  832. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  833. }
  834. if ((ProgressData != NULL) &&
  835. ProgressData->InProgress)
  836. {
  837. SetTaskbarListProgressValue(ProgressData);
  838. }
  839. else
  840. {
  841. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  842. }
  843. }
  844. else
  845. {
  846. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  847. }
  848. }
  849. else
  850. {
  851. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  852. }
  853. }
  854. UpdateQueueLabel();
  855. }
  856. //---------------------------------------------------------------------------
  857. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  858. {
  859. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  860. if (FQueueStatus != NULL)
  861. {
  862. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  863. if (ActiveAndPendingPrimaryCount > 0)
  864. {
  865. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  866. }
  867. }
  868. QueueLabel->Caption = Caption;
  869. }
  870. //---------------------------------------------------------------------------
  871. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  872. {
  873. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  874. static_cast<TComponent*>(GetComponent(fcTransferList)));
  875. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  876. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  877. TransferList->Strings->BeginUpdate();
  878. try
  879. {
  880. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  881. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  882. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  883. if (FTransferDropDownHint.IsEmpty())
  884. {
  885. FTransferDropDownHint = TransferDropDown->Hint;
  886. }
  887. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  888. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  889. TransferDropDown->Text = StripHotkey(Name);
  890. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  891. (FTransferDropDownHint, StripHotkey(Name),
  892. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  893. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  894. // update the label, otherwise when it is updated only on the first draw
  895. // of the list, it is drawn "bold" for some reason
  896. FTransferListHoverIndex = TransferList->ItemIndex;
  897. UpdateTransferLabel();
  898. }
  899. __finally
  900. {
  901. TransferList->Strings->EndUpdate();
  902. }
  903. }
  904. //---------------------------------------------------------------------------
  905. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  906. {
  907. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  908. DebugAssert(Toolbar != NULL);
  909. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  910. }
  911. //---------------------------------------------------------------------------
  912. void __fastcall TCustomScpExplorerForm::UpdateActions()
  913. {
  914. TForm::UpdateActions();
  915. if (ComponentVisible[fcCustomCommandsBand])
  916. {
  917. UpdateCustomCommandsToolbar();
  918. }
  919. }
  920. //---------------------------------------------------------------------------
  921. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  922. {
  923. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  924. }
  925. //---------------------------------------------------------------------------
  926. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  927. {
  928. Color = GetBtnFaceColor();
  929. DebugAssert(Configuration && RemoteDirView);
  930. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  931. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  932. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  933. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  934. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  935. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  936. if (RemoteDirView->RowSelect != WinConfiguration->FullRowSelect)
  937. {
  938. RemoteDirView->RowSelect = WinConfiguration->FullRowSelect;
  939. // selection is not redrawn automatically when RowSelect changes
  940. RemoteDirView->Invalidate();
  941. }
  942. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  943. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  944. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  945. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  946. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  947. UpdateSessionsPageControlHeight();
  948. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  949. UpdateToolbarDisplayMode();
  950. UpdateTransferList();
  951. if (Terminal != NULL)
  952. {
  953. TransferPresetAutoSelect();
  954. }
  955. UpdateQueueView();
  956. UpdateControls();
  957. // this can be called even before constuctor finishes.
  958. if (FEditorManager != NULL)
  959. {
  960. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  961. }
  962. // this can be called even before constuctor finishes.
  963. if (FLocalEditors != NULL)
  964. {
  965. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  966. {
  967. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  968. }
  969. }
  970. if (ComponentVisible[fcCustomCommandsBand])
  971. {
  972. UpdateCustomCommandsToolbar();
  973. }
  974. // show only when keeping queue items forever,
  975. // otherwise, its enough to have in in the context menu
  976. QueueDeleteAllDoneQueueToolbarItem->Visible =
  977. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  978. if (FFileColorsCurrent != WinConfiguration->FileColors)
  979. {
  980. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  981. FFileColorsCurrent = WinConfiguration->FileColors;
  982. FileColorsChanged();
  983. }
  984. }
  985. //---------------------------------------------------------------------------
  986. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  987. {
  988. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  989. DirView->Invalidate();
  990. }
  991. //---------------------------------------------------------------------------
  992. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  993. {
  994. DoFileColorsChanged(RemoteDirView);
  995. }
  996. //---------------------------------------------------------------------------
  997. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  998. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  999. void * /*Arg*/)
  1000. {
  1001. if (Token != NULL)
  1002. {
  1003. TForm * Editor = dynamic_cast<TForm*>(Token);
  1004. DebugAssert(Editor != NULL);
  1005. ReconfigureEditorForm(Editor);
  1006. }
  1007. }
  1008. //---------------------------------------------------------------------------
  1009. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1010. {
  1011. WinConfiguration->DDTransferConfirmation = asOn;
  1012. }
  1013. //---------------------------------------------------------------------------
  1014. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1015. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1016. {
  1017. // noop
  1018. }
  1019. //---------------------------------------------------------------------------
  1020. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1021. TTransferDirection Direction, TTransferType Type, bool Temp,
  1022. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1023. bool Confirm, bool DragDrop, int Options)
  1024. {
  1025. bool Result = true;
  1026. DebugAssert(HasActiveTerminal());
  1027. // these parameters are known in advance
  1028. int Params =
  1029. FLAGMASK(Type == ttMove, cpDelete);
  1030. bool ToTemp = (Temp && (Direction == tdToLocal));
  1031. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1032. {
  1033. bool DisableNewerOnly =
  1034. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1035. ToTemp;
  1036. Options |=
  1037. FLAGMASK(ToTemp, coTemp) |
  1038. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1039. coDoNotShowAgain;
  1040. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1041. int CopyParamAttrs = (Direction == tdToRemote ?
  1042. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1043. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1044. int OutputOptions =
  1045. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1046. cooDoNotShowAgain);
  1047. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1048. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1049. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1050. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1051. if (Result)
  1052. {
  1053. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1054. {
  1055. if (DragDrop)
  1056. {
  1057. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1058. {
  1059. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1060. NULL, 0, EnableDDTransferConfirmation, NULL);
  1061. }
  1062. WinConfiguration->DDTransferConfirmation = asOff;
  1063. }
  1064. else
  1065. {
  1066. WinConfiguration->ConfirmTransferring = false;
  1067. }
  1068. }
  1069. else
  1070. {
  1071. // User explicitly unchecked "do not show again",
  1072. // so show him the dialog the next time
  1073. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1074. {
  1075. WinConfiguration->DDTransferConfirmation = asOn;
  1076. }
  1077. }
  1078. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1079. }
  1080. }
  1081. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1082. {
  1083. Configuration->Usage->Inc(L"TransfersOnBackground");
  1084. // these parameter are known only after transfer dialog
  1085. Params |=
  1086. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1087. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1088. Result = false;
  1089. ClearTransferSourceSelection(Direction);
  1090. }
  1091. return Result;
  1092. }
  1093. //---------------------------------------------------------------------------
  1094. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1095. {
  1096. if (FOnFileOperationFinished != NULL)
  1097. {
  1098. FOnFileOperationFinished(UnicodeString(), true);
  1099. }
  1100. else
  1101. {
  1102. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1103. if (HasDirView[Side])
  1104. {
  1105. DirView(Side)->SelectAll(smNone);
  1106. }
  1107. }
  1108. }
  1109. //---------------------------------------------------------------------------
  1110. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1111. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1112. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1113. int Params)
  1114. {
  1115. DebugAssert(Queue != NULL);
  1116. bool SingleFile = false;
  1117. if (FileList->Count == 1)
  1118. {
  1119. if (Direction == tdToRemote)
  1120. {
  1121. UnicodeString FileName = FileList->Strings[0];
  1122. SingleFile = FileExists(ApiPath(FileName));
  1123. }
  1124. else
  1125. {
  1126. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1127. SingleFile = !File->IsDirectory;
  1128. }
  1129. }
  1130. TQueueItem * QueueItem;
  1131. if (Direction == tdToRemote)
  1132. {
  1133. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1134. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1135. }
  1136. else
  1137. {
  1138. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1139. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1140. }
  1141. AddQueueItem(Queue, QueueItem, Terminal);
  1142. }
  1143. //---------------------------------------------------------------------------
  1144. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1145. {
  1146. if (Queue->IsEmpty)
  1147. {
  1148. Terminal->QueueOperationStart = Now();
  1149. }
  1150. Queue->AddItem(QueueItem);
  1151. }
  1152. //---------------------------------------------------------------------------
  1153. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1154. {
  1155. }
  1156. //---------------------------------------------------------------------------
  1157. void __fastcall TCustomScpExplorerForm::InitControls()
  1158. {
  1159. DebugAssert(FDocks != NULL);
  1160. for (int Index = 0; Index < ComponentCount; Index++)
  1161. {
  1162. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1163. if ((Dock != NULL) && (Dock->Tag == 0))
  1164. {
  1165. FDocks->Add(Dock);
  1166. }
  1167. }
  1168. CollectItemsWithTextDisplayMode(this);
  1169. }
  1170. //---------------------------------------------------------------------------
  1171. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1172. {
  1173. ConfigurationChanged();
  1174. QueuePanel->Height =
  1175. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1176. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1177. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1178. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1179. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1180. QueueFileList->Height =
  1181. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1182. if (QueueFileList->Visible)
  1183. {
  1184. AdjustQueueLayout();
  1185. }
  1186. UpdateCustomCommandsToolbar();
  1187. }
  1188. //---------------------------------------------------------------------------
  1189. void __fastcall TCustomScpExplorerForm::StoreParams()
  1190. {
  1191. int APixelsPerInch = GetControlPixelsPerInch(this);
  1192. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1193. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1194. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1195. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1196. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1197. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1198. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1199. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1200. }
  1201. //---------------------------------------------------------------------------
  1202. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1203. {
  1204. if (!FFormRestored)
  1205. {
  1206. FFormRestored = true;
  1207. RestoreFormParams();
  1208. }
  1209. TForm::CreateParams(Params);
  1210. }
  1211. //---------------------------------------------------------------------------
  1212. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1213. {
  1214. DebugAssert(FDocks != NULL);
  1215. for (int Index = 0; Index < FDocks->Count; Index++)
  1216. {
  1217. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1218. }
  1219. }
  1220. //---------------------------------------------------------------------------
  1221. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1222. {
  1223. SetDockAllowDrag(true);
  1224. while (!ButtonsStr.IsEmpty())
  1225. {
  1226. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1227. UnicodeString Name = CutToChar(S, L'=', true);
  1228. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1229. {
  1230. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1231. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1232. {
  1233. while (!S.IsEmpty())
  1234. {
  1235. UnicodeString S2 = CutToChar(S, L',', true);
  1236. UnicodeString Name = CutToChar(S2, L':', true);
  1237. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1238. {
  1239. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1240. if (SameText(GetToolbarItemName(Item), Name))
  1241. {
  1242. // forward compatibility
  1243. UnicodeString S3 = CutToChar(S2, L':', true);
  1244. bool Visible = StrToIntDef(S3, 0);
  1245. Item->Visible = Visible;
  1246. }
  1247. }
  1248. }
  1249. }
  1250. }
  1251. }
  1252. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1253. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1254. }
  1255. //---------------------------------------------------------------------------
  1256. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1257. {
  1258. UnicodeString Result;
  1259. SetDockAllowDrag(true);
  1260. Result = ::GetToolbarsLayoutStr(this);
  1261. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1262. return Result;
  1263. }
  1264. //---------------------------------------------------------------------------
  1265. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1266. {
  1267. UnicodeString Result;
  1268. if (Item->Action != NULL)
  1269. {
  1270. Result = Item->Action->Name;
  1271. Result = RemoveSuffix(Result, L"Action", true);
  1272. }
  1273. else
  1274. {
  1275. Result = Item->Name;
  1276. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1277. Result = RemoveSuffix(Result, L"Item", true);
  1278. }
  1279. return Result;
  1280. }
  1281. //---------------------------------------------------------------------------
  1282. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1283. {
  1284. UnicodeString Result;
  1285. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1286. {
  1287. UnicodeString ToolbarStr;
  1288. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1289. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1290. {
  1291. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1292. {
  1293. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1294. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1295. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1296. // and save the changes here only.
  1297. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1298. {
  1299. UnicodeString Name = GetToolbarItemName(Item);
  1300. DebugAssert(Name.Pos(L"TBX") == 0);
  1301. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1302. }
  1303. }
  1304. }
  1305. if (!ToolbarStr.IsEmpty())
  1306. {
  1307. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1308. }
  1309. }
  1310. return Result;
  1311. }
  1312. //---------------------------------------------------------------------------
  1313. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1314. {
  1315. DebugAssert(FProgressForm == NULL);
  1316. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1317. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1318. FProgressForm->DeleteLocalToRecycleBin =
  1319. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1320. FProgressForm->DeleteRemoteToRecycleBin =
  1321. (Terminal != NULL) &&
  1322. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1323. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1324. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1325. LockWindow();
  1326. // Actually, do not know what hides the progress once the operation finishes
  1327. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1328. SetTaskbarListProgressState(TBPF_NORMAL);
  1329. }
  1330. //---------------------------------------------------------------------------
  1331. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1332. {
  1333. UnlockWindow();
  1334. SAFE_DESTROY(FProgressForm);
  1335. SetQueueProgress();
  1336. }
  1337. //---------------------------------------------------------------------------
  1338. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1339. TFileOperationProgressType & ProgressData)
  1340. {
  1341. // Download to temporary local directory
  1342. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1343. {
  1344. bool Continue = true;
  1345. FPendingTempSpaceWarn = false;
  1346. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1347. if (!Continue)
  1348. {
  1349. Abort();
  1350. }
  1351. }
  1352. // operation is being executed and we still didn't show up progress form
  1353. if (ProgressData.InProgress && !FProgressForm)
  1354. {
  1355. CreateProgressForm(NULL);
  1356. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1357. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1358. }
  1359. // operation is finished (or terminated), so we hide progress form
  1360. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1361. {
  1362. DestroyProgressForm();
  1363. if (ProgressData.Operation == foCalculateSize)
  1364. {
  1365. // When calculating size before transfer, the abort caused by
  1366. // cancel flag set due to "MoveToQueue" below,
  1367. // is not propagated back to us in ExecuteFileOperation,
  1368. // as it is silently swallowed.
  1369. // So we explicitly (re)throw it here.
  1370. if (FMoveToQueue)
  1371. {
  1372. Abort();
  1373. }
  1374. }
  1375. else
  1376. {
  1377. if ((ProgressData.Cancel == csContinue) &&
  1378. !FAutoOperation)
  1379. {
  1380. OperationComplete(ProgressData.StartTime);
  1381. }
  1382. }
  1383. }
  1384. if (FProgressForm &&
  1385. // Can happen only during synchronization, when ending one of the operations
  1386. ProgressData.InProgress)
  1387. {
  1388. FProgressForm->SetProgressData(ProgressData);
  1389. DebugAssert(ProgressData.InProgress);
  1390. SetTaskbarListProgressValue(&ProgressData);
  1391. if (FProgressForm->Cancel > csContinue)
  1392. {
  1393. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1394. if (FProgressForm->Cancel == csCancelFile)
  1395. {
  1396. FProgressForm->ClearCancel();
  1397. }
  1398. // cancel cancels even the move
  1399. FMoveToQueue = false;
  1400. }
  1401. else if (FProgressForm->MoveToQueue)
  1402. {
  1403. FMoveToQueue = true;
  1404. ProgressData.SetCancelAtLeast(csCancel);
  1405. }
  1406. if ((FTransferResumeList != NULL) &&
  1407. ProgressData.InProgress &&
  1408. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1409. !ProgressData.FullFileName.IsEmpty())
  1410. {
  1411. if ((FTransferResumeList->Count == 0) ||
  1412. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1413. {
  1414. // note that we do not recognize directories from files here
  1415. FTransferResumeList->Add(ProgressData.FullFileName);
  1416. }
  1417. }
  1418. }
  1419. }
  1420. //---------------------------------------------------------------------------
  1421. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1422. const TDateTime & StartTime)
  1423. {
  1424. if (GUIConfiguration->BeepOnFinish &&
  1425. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1426. {
  1427. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1428. DWORD Sound;
  1429. if (!ExtractFileExt(BeepSound).IsEmpty())
  1430. {
  1431. Sound = SND_FILENAME;
  1432. }
  1433. else
  1434. {
  1435. Sound = SND_ALIAS;
  1436. }
  1437. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1438. }
  1439. }
  1440. //---------------------------------------------------------------------------
  1441. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1442. TFileOperationProgressType & ProgressData)
  1443. {
  1444. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1445. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1446. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1447. FileOperationProgress(ProgressData);
  1448. }
  1449. //---------------------------------------------------------------------------
  1450. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1451. {
  1452. UnicodeString Result;
  1453. if (FProgressForm != NULL)
  1454. {
  1455. Result = FProgressForm->ProgressStr();
  1456. }
  1457. return Result;
  1458. }
  1459. //---------------------------------------------------------------------------
  1460. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1461. bool DragDrop)
  1462. {
  1463. return (!DragDrop && (DropSourceControl == NULL)) ||
  1464. (DropSourceControl == DirView(osOther));
  1465. }
  1466. //---------------------------------------------------------------------------
  1467. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1468. TFileOperation Operation, TOperationSide Side,
  1469. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1470. TOnceDoneOperation & OnceDoneOperation)
  1471. {
  1472. if (!FAutoOperation)
  1473. {
  1474. // no selection on "/upload", form serves only as event handler
  1475. // (it is not displayed)
  1476. if (PanelOperation(Side, FDragDropOperation) &&
  1477. Visible && (Operation != foCalculateSize) &&
  1478. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1479. {
  1480. if (FOnFileOperationFinished != NULL)
  1481. {
  1482. FOnFileOperationFinished(FileName, Success);
  1483. }
  1484. else
  1485. {
  1486. TCustomDirView * DView = DirView(Side);
  1487. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(Side));
  1488. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1489. // this can happen when local drive is unplugged in the middle of the operation
  1490. if (Item != NULL)
  1491. {
  1492. if (Success) Item->Selected = false;
  1493. DView->MakeProgressVisible(Item);
  1494. }
  1495. }
  1496. }
  1497. if ((Operation == foCopy) || (Operation == foMove))
  1498. {
  1499. DebugAssert(!IsLocalBrowserMode()); // TODO
  1500. if (Side == osLocal)
  1501. {
  1502. Configuration->Usage->Inc(L"UploadedFiles");
  1503. }
  1504. else
  1505. {
  1506. Configuration->Usage->Inc(L"DownloadedFiles");
  1507. }
  1508. }
  1509. }
  1510. if (Success && (FSynchronizeController != NULL))
  1511. {
  1512. DebugAssert(!IsSideLocalBrowser(osRemote));
  1513. if (Operation == foCopy)
  1514. {
  1515. DebugAssert(Side == osLocal);
  1516. FSynchronizeController->LogOperation(soUpload, FileName);
  1517. }
  1518. else if (Operation == foDelete)
  1519. {
  1520. DebugAssert(Side == osRemote);
  1521. FSynchronizeController->LogOperation(soDelete, FileName);
  1522. }
  1523. }
  1524. if (FProgressForm)
  1525. {
  1526. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1527. }
  1528. }
  1529. //---------------------------------------------------------------------------
  1530. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1531. TFileOperation Operation, TOperationSide Side,
  1532. bool Temp, const UnicodeString & FileName, Boolean Success,
  1533. TOnceDoneOperation & OnceDoneOperation)
  1534. {
  1535. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1536. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1537. OnceDoneOperation);
  1538. }
  1539. //---------------------------------------------------------------------------
  1540. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1541. {
  1542. return false;
  1543. }
  1544. //---------------------------------------------------------------------------
  1545. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1546. {
  1547. return false;
  1548. }
  1549. //---------------------------------------------------------------------------
  1550. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1551. {
  1552. return NULL;
  1553. }
  1554. //---------------------------------------------------------------------------
  1555. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1556. {
  1557. DebugAssert(GetSide(Side) == osRemote);
  1558. DebugUsedParam(Side);
  1559. return RemoteDirView;
  1560. }
  1561. //---------------------------------------------------------------------------
  1562. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1563. {
  1564. DebugAssert(GetSide(Side) == osRemote);
  1565. DebugUsedParam(Side);
  1566. return RemoteDriveView;
  1567. }
  1568. //---------------------------------------------------------------------------
  1569. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1570. {
  1571. DebugAssert(GetSide(Side) == osRemote);
  1572. DebugUsedParam(Side);
  1573. return HasActiveTerminal();
  1574. }
  1575. //---------------------------------------------------------------------------
  1576. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1577. TOperationSide Side, int FilesOnly)
  1578. {
  1579. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1580. }
  1581. //---------------------------------------------------------------------------
  1582. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1583. TOperationSide Side, int FilesOnly)
  1584. {
  1585. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1586. }
  1587. //---------------------------------------------------------------------------
  1588. struct THistoryItemData
  1589. {
  1590. short int Side;
  1591. short int Index;
  1592. };
  1593. //---------------------------------------------------------------------------
  1594. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1595. {
  1596. DirView(Side)->HistoryGo(Index);
  1597. }
  1598. //---------------------------------------------------------------------------
  1599. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1600. {
  1601. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1602. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1603. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1604. }
  1605. //---------------------------------------------------------------------------
  1606. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1607. bool Back)
  1608. {
  1609. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1610. {
  1611. TCustomDirView * DView = DirView(Side);
  1612. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1613. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1614. if (ICount > 10)
  1615. {
  1616. ICount = 10;
  1617. }
  1618. Menu->Items->Clear();
  1619. THistoryItemData Data;
  1620. Data.Side = Side;
  1621. for (short int i = 1; i <= ICount; i++)
  1622. {
  1623. TTBCustomItem * Item = new TTBXItem(Menu);
  1624. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1625. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1626. Item->Hint = DView->HistoryPath[Data.Index];
  1627. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1628. Item->Tag = *reinterpret_cast<int*>(&Data);
  1629. Item->OnClick = HistoryItemClick;
  1630. Menu->Items->Add(Item);
  1631. }
  1632. }
  1633. }
  1634. //---------------------------------------------------------------------------
  1635. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1636. TOperationSide Side, bool Back)
  1637. {
  1638. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1639. {
  1640. // workaround
  1641. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1642. // operator new allocates memory in Pascal code, but calls inline
  1643. // contructor in C++, leading in problems, the function does
  1644. // both in Pascal code
  1645. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1646. UpdateHistoryMenu(Side, Back);
  1647. }
  1648. return FHistoryMenu[Side == osLocal][Back];
  1649. }
  1650. //---------------------------------------------------------------------------
  1651. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1652. TCustomDirView *Sender)
  1653. {
  1654. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1655. UpdateHistoryMenu(Side, true);
  1656. UpdateHistoryMenu(Side, false);
  1657. }
  1658. //---------------------------------------------------------------------------
  1659. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1660. {
  1661. // remote custom commands can be executed only if the server supports shell commands
  1662. // or have secondary shell
  1663. return HasActiveTerminal() && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1664. }
  1665. //---------------------------------------------------------------------------
  1666. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1667. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1668. {
  1669. // -1 = hidden, 0 = disabled, 1 = enabled
  1670. int Result;
  1671. TFileCustomCommand RemoteCustomCommand;
  1672. TLocalCustomCommand LocalCustomCommand;
  1673. TFileCustomCommand * NonInteractiveCustomCommand =
  1674. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1675. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1676. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1677. if (FLAGCLEAR(Command.Params, ccLocal))
  1678. {
  1679. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1680. // custom command that does not operate with files can be executed anytime ...
  1681. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1682. {
  1683. // ... but do not show such command in remote file menu
  1684. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1685. {
  1686. Result = AllowedState;
  1687. }
  1688. else
  1689. {
  1690. Result = -1;
  1691. }
  1692. }
  1693. else
  1694. {
  1695. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1696. {
  1697. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1698. }
  1699. else
  1700. {
  1701. Result = -1;
  1702. }
  1703. }
  1704. }
  1705. else
  1706. {
  1707. // custom command that does not operate with files can be executed anytime
  1708. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1709. {
  1710. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1711. }
  1712. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1713. {
  1714. if ((ListType == ccltAll) || (ListType == ccltFile))
  1715. {
  1716. // special case is "diff"-style command that can be executed over any side,
  1717. // if we have both sides
  1718. Result =
  1719. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1720. // directly (instead of EnableSelectedOperation) to pass
  1721. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1722. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1723. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1724. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1725. }
  1726. else if (ListType == ccltBoth)
  1727. {
  1728. DebugAssert(!IsLocalBrowserMode());
  1729. Result = 1;
  1730. }
  1731. else
  1732. {
  1733. Result = -1;
  1734. }
  1735. }
  1736. else
  1737. {
  1738. if ((ListType == ccltAll) ||
  1739. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1740. {
  1741. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1742. }
  1743. else
  1744. {
  1745. Result = -1;
  1746. }
  1747. }
  1748. if ((Result > 0) &&
  1749. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1750. !HasActiveTerminal())
  1751. {
  1752. Result = 0;
  1753. }
  1754. }
  1755. return Result;
  1756. }
  1757. //---------------------------------------------------------------------------
  1758. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1759. TStrings * FileList, const TCustomCommandType & ACommand,
  1760. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1761. {
  1762. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1763. {
  1764. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1765. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1766. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1767. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1768. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1769. bool Capture =
  1770. FLAGSET(ACommand.Params, ccShowResults) ||
  1771. FLAGSET(ACommand.Params, ccCopyResults) ||
  1772. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1773. TCaptureOutputEvent OutputEvent = NULL;
  1774. DebugAssert(FCapturedLog == NULL);
  1775. if (Capture)
  1776. {
  1777. FCapturedLog = new TStringList();
  1778. OutputEvent = TerminalCaptureLog;
  1779. }
  1780. try
  1781. {
  1782. if (!RemoteCustomCommand.IsFileCommand(Command))
  1783. {
  1784. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1785. OutputEvent);
  1786. }
  1787. else
  1788. {
  1789. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1790. }
  1791. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1792. {
  1793. if (FLAGSET(ACommand.Params, ccCopyResults))
  1794. {
  1795. CopyToClipboard(FCapturedLog);
  1796. }
  1797. if (FLAGSET(ACommand.Params, ccShowResults))
  1798. {
  1799. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1800. }
  1801. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1802. {
  1803. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1804. }
  1805. }
  1806. }
  1807. __finally
  1808. {
  1809. SAFE_DESTROY(FCapturedLog);
  1810. }
  1811. }
  1812. }
  1813. //---------------------------------------------------------------------------
  1814. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1815. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1816. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1817. {
  1818. DebugAssert(!IsLocalBrowserMode());
  1819. TStrings * LocalFileList = NULL;
  1820. TStrings * RemoteFileList = NULL;
  1821. TStrings * RemoteFileListFull = NULL;
  1822. try
  1823. {
  1824. if (LocalFileCommand)
  1825. {
  1826. if (ALocalFileList == NULL)
  1827. {
  1828. DebugAssert(HasDirView[osLocal]);
  1829. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1830. // directly (instead of EnableSelectedOperation) to pass
  1831. // false to FocusedFileOnlyWhenFocused
  1832. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1833. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1834. }
  1835. else
  1836. {
  1837. LocalFileList = ALocalFileList;
  1838. }
  1839. if (FileListCommand)
  1840. {
  1841. if (LocalFileList->Count != 1)
  1842. {
  1843. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1844. }
  1845. }
  1846. else
  1847. {
  1848. if ((LocalFileList->Count != 1) &&
  1849. (FileList->Count != 1) &&
  1850. (LocalFileList->Count != FileList->Count))
  1851. {
  1852. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1853. }
  1854. }
  1855. }
  1856. UnicodeString RootTempDir;
  1857. UnicodeString TempDir;
  1858. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1859. if (!RemoteFiles)
  1860. {
  1861. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1862. }
  1863. try
  1864. {
  1865. TDateTimes RemoteFileTimes;
  1866. if (RemoteFiles)
  1867. {
  1868. RemoteFileList = FileList;
  1869. }
  1870. else
  1871. {
  1872. RemoteFileList = new TStringList();
  1873. TMakeLocalFileListParams MakeFileListParam;
  1874. MakeFileListParam.FileList = RemoteFileList;
  1875. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1876. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1877. MakeFileListParam.Recursive =
  1878. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1879. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1880. if (!MakeFileListParam.Recursive)
  1881. {
  1882. RemoteFileTimes.clear();
  1883. RemoteFileListFull = new TStringList();
  1884. MakeFileListParam.FileList = RemoteFileListFull;
  1885. MakeFileListParam.Recursive = true;
  1886. MakeFileListParam.IncludeDirs = false;
  1887. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1888. }
  1889. else
  1890. {
  1891. RemoteFileListFull = RemoteFileList;
  1892. }
  1893. }
  1894. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1895. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1896. if (!NonBlocking)
  1897. {
  1898. int Count;
  1899. if (FileListCommand)
  1900. {
  1901. Count = 1;
  1902. }
  1903. else if (LocalFileCommand)
  1904. {
  1905. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1906. }
  1907. else
  1908. {
  1909. Count = RemoteFileList->Count;
  1910. }
  1911. Progress.Start(foCustomCommand, osRemote, Count);
  1912. DebugAssert(FProgressForm != NULL);
  1913. FProgressForm->ReadOnly = true;
  1914. }
  1915. try
  1916. {
  1917. if (FileListCommand)
  1918. {
  1919. UnicodeString LocalFile;
  1920. // MakeFileList does not delimit filenames
  1921. UnicodeString FileList = MakeFileList(RemoteFileList);
  1922. if (LocalFileCommand)
  1923. {
  1924. DebugAssert(LocalFileList->Count == 1);
  1925. LocalFile = LocalFileList->Strings[0];
  1926. }
  1927. TLocalCustomCommand CustomCommand(Data,
  1928. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1929. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1930. if (NonBlocking)
  1931. {
  1932. DebugAssert(!POutput);
  1933. ExecuteShellChecked(ShellCommand);
  1934. }
  1935. else
  1936. {
  1937. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1938. }
  1939. }
  1940. else if (LocalFileCommand)
  1941. {
  1942. if (LocalFileList->Count == 1)
  1943. {
  1944. UnicodeString LocalFile = LocalFileList->Strings[0];
  1945. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1946. {
  1947. UnicodeString FileName = RemoteFileList->Strings[Index];
  1948. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1949. Progress.SetFile(FileNameForProgress);
  1950. TLocalCustomCommand CustomCommand(Data,
  1951. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1952. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1953. TOnceDoneOperation OnceDoneOperation;
  1954. // Do not unselect anything, as it won't work with two panels anyway
  1955. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1956. }
  1957. }
  1958. else if (RemoteFileList->Count == 1)
  1959. {
  1960. UnicodeString FileName = RemoteFileList->Strings[0];
  1961. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1962. {
  1963. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1964. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1965. Progress.SetFile(LocalFileNameOnly);
  1966. TLocalCustomCommand CustomCommand(
  1967. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1968. FileName, LocalFileName, L"");
  1969. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1970. TOnceDoneOperation OnceDoneOperation;
  1971. // Do not unselect anything, as it won't work with two panels anyway
  1972. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1973. }
  1974. }
  1975. else
  1976. {
  1977. if (LocalFileList->Count != RemoteFileList->Count)
  1978. {
  1979. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1980. }
  1981. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1982. {
  1983. UnicodeString FileName = RemoteFileList->Strings[Index];
  1984. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1985. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1986. Progress.SetFile(LocalFileNameOnly); // sic
  1987. TLocalCustomCommand CustomCommand(
  1988. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1989. FileName, LocalFileName, L"");
  1990. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1991. TOnceDoneOperation OnceDoneOperation;
  1992. // Do not unselect anything, as it won't work with two panels anyway
  1993. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1994. }
  1995. }
  1996. }
  1997. else
  1998. {
  1999. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2000. {
  2001. UnicodeString FileName = RemoteFileList->Strings[Index];
  2002. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2003. Progress.SetFile(FileNameForProgress);
  2004. TLocalCustomCommand CustomCommand(Data,
  2005. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2006. FileName, L"", L"");
  2007. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2008. TOnceDoneOperation OnceDoneOperation;
  2009. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2010. }
  2011. }
  2012. }
  2013. __finally
  2014. {
  2015. if (!NonBlocking)
  2016. {
  2017. Progress.Stop();
  2018. }
  2019. }
  2020. DebugAssert(!FAutoOperation);
  2021. if (!RemoteFiles)
  2022. {
  2023. TempDir = IncludeTrailingBackslash(TempDir);
  2024. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2025. {
  2026. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2027. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2028. // Skip directories, process only nested files.
  2029. // The check is redundant as FileAge fails for directories anyway.
  2030. !DirectoryExists(FileName))
  2031. {
  2032. UnicodeString RemoteDir =
  2033. UnixExtractFileDir(
  2034. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2035. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2036. TDateTime NewTime;
  2037. if (FileAge(FileName, NewTime) &&
  2038. (NewTime != RemoteFileTimes[Index]))
  2039. {
  2040. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2041. TemporaryFileCopyParam(CopyParam);
  2042. CopyParam.FileMask = L"";
  2043. FAutoOperation = true;
  2044. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2045. TemporaryFilesList->Add(FileName);
  2046. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2047. }
  2048. }
  2049. }
  2050. }
  2051. }
  2052. __finally
  2053. {
  2054. FAutoOperation = false;
  2055. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2056. {
  2057. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2058. }
  2059. }
  2060. }
  2061. __finally
  2062. {
  2063. if (RemoteFileList != FileList)
  2064. {
  2065. delete RemoteFileList;
  2066. }
  2067. if (LocalFileList != ALocalFileList)
  2068. {
  2069. delete LocalFileList;
  2070. }
  2071. if (RemoteFileListFull != RemoteFileList)
  2072. {
  2073. delete RemoteFileListFull;
  2074. }
  2075. }
  2076. }
  2077. //---------------------------------------------------------------------------
  2078. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2079. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2080. bool FileListCommand, UnicodeString * POutput)
  2081. {
  2082. std::unique_ptr<TStrings> SelectedFileList(DirView(osLocal)->CreateFileList(false, true, NULL));
  2083. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2084. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2085. {
  2086. UnicodeString FileName = SelectedFileList->Strings[Index];
  2087. if (DirectoryExists(FileName))
  2088. {
  2089. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2090. {
  2091. LocalFileList->Add(FileName);
  2092. }
  2093. if (FLAGSET(ACommand.Params, ccRecursive))
  2094. {
  2095. TMakeLocalFileListParams MakeFileListParam;
  2096. MakeFileListParam.FileList = LocalFileList.get();
  2097. MakeFileListParam.FileTimes = NULL;
  2098. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2099. MakeFileListParam.Recursive = true;
  2100. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2101. }
  2102. }
  2103. else
  2104. {
  2105. LocalFileList->Add(FileName);
  2106. }
  2107. }
  2108. UnicodeString RemotePath;
  2109. if (Terminal != NULL)
  2110. {
  2111. RemotePath = Terminal->CurrentDirectory;
  2112. }
  2113. if (FileListCommand)
  2114. {
  2115. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2116. TLocalCustomCommand CustomCommand(
  2117. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2118. L"", L"", FileList);
  2119. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2120. }
  2121. else
  2122. {
  2123. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2124. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2125. DebugAssert(FProgressForm != NULL);
  2126. FProgressForm->ReadOnly = true;
  2127. try
  2128. {
  2129. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2130. {
  2131. UnicodeString FileName = LocalFileList->Strings[Index];
  2132. Progress.SetFile(FileName);
  2133. TLocalCustomCommand CustomCommand(
  2134. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2135. FileName, L"", L"");
  2136. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2137. TOnceDoneOperation OnceDoneOperation;
  2138. Progress.Finish(FileName, true, OnceDoneOperation);
  2139. }
  2140. }
  2141. __finally
  2142. {
  2143. Progress.Stop();
  2144. }
  2145. }
  2146. }
  2147. //---------------------------------------------------------------------------
  2148. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2149. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2150. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2151. {
  2152. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2153. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2154. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2155. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2156. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2157. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2158. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2159. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2160. std::unique_ptr<UnicodeString> POutput;
  2161. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2162. FLAGSET(ACommand.Params, ccCopyResults))
  2163. {
  2164. POutput.reset(new UnicodeString());
  2165. }
  2166. if (!LocalCustomCommand.IsFileCommand(Command))
  2167. {
  2168. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2169. }
  2170. // remote files?
  2171. else if ((FCurrentSide == osRemote) || LocalFileCommand)
  2172. {
  2173. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2174. }
  2175. // local files
  2176. else
  2177. {
  2178. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2179. }
  2180. if (POutput.get() != NULL)
  2181. {
  2182. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2183. int P = POutput->Pos(sLineBreak);
  2184. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2185. {
  2186. POutput->SetLength(P - 1);
  2187. }
  2188. // Copy even empty output to clipboard
  2189. if (FLAGSET(ACommand.Params, ccCopyResults))
  2190. {
  2191. CopyToClipboard(*POutput);
  2192. }
  2193. // But do not show an empty message box.
  2194. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2195. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2196. !POutput->IsEmpty())
  2197. {
  2198. TClipboardHandler ClipboardHandler;
  2199. ClipboardHandler.Text = *POutput;
  2200. TMessageParams Params;
  2201. TQueryButtonAlias Aliases[1];
  2202. Aliases[0].Button = qaRetry;
  2203. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2204. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2205. Params.Aliases = Aliases;
  2206. Params.AliasesCount = LENOF(Aliases);
  2207. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2208. }
  2209. }
  2210. }
  2211. //---------------------------------------------------------------------------
  2212. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2213. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2214. {
  2215. TCustomCommandData Data;
  2216. UnicodeString Site;
  2217. UnicodeString RemotePath;
  2218. if (HasActiveTerminal())
  2219. {
  2220. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2221. Data = TCustomCommandData(SessionData.get());
  2222. Site = Terminal->SessionData->SessionKey;
  2223. RemotePath = Terminal->CurrentDirectory;
  2224. }
  2225. UnicodeString HelpKeyword = ACommand.HomePage;
  2226. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2227. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2228. {
  2229. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2230. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2231. {
  2232. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2233. }
  2234. else
  2235. {
  2236. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2237. }
  2238. if (!DoCustomCommandOptionsDialog(
  2239. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2240. {
  2241. Abort();
  2242. }
  2243. }
  2244. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2245. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2246. {
  2247. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2248. }
  2249. else
  2250. {
  2251. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2252. }
  2253. }
  2254. //---------------------------------------------------------------------------
  2255. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2256. const TCustomCommandType & Command)
  2257. {
  2258. DebugAssert(FCustomCommandLocalFileList != NULL);
  2259. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2260. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2261. TStrings * LocalFileList = new TStringList();
  2262. TStrings * RemoteFileList = new TStringList();
  2263. try
  2264. {
  2265. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2266. {
  2267. LocalFileList->Clear();
  2268. LocalFileList->AddObject(
  2269. FCustomCommandLocalFileList->Strings[Index],
  2270. FCustomCommandLocalFileList->Objects[Index]);
  2271. RemoteFileList->Clear();
  2272. RemoteFileList->AddObject(
  2273. FCustomCommandRemoteFileList->Strings[Index],
  2274. FCustomCommandRemoteFileList->Objects[Index]);
  2275. CustomCommand(RemoteFileList, Command, LocalFileList);
  2276. }
  2277. }
  2278. __finally
  2279. {
  2280. delete LocalFileList;
  2281. delete RemoteFileList;
  2282. }
  2283. }
  2284. //---------------------------------------------------------------------------
  2285. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2286. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2287. {
  2288. delete FCustomCommandLocalFileList;
  2289. delete FCustomCommandRemoteFileList;
  2290. // takeover ownership,
  2291. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2292. FCustomCommandLocalFileList = LocalFileList;
  2293. FCustomCommandRemoteFileList = RemoteFileList;
  2294. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2295. if (Button != NULL)
  2296. {
  2297. FCustomCommandMenu->Items->Clear();
  2298. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2299. MenuPopup(FCustomCommandMenu, Button);
  2300. }
  2301. else
  2302. {
  2303. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2304. }
  2305. }
  2306. //---------------------------------------------------------------------------
  2307. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2308. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2309. {
  2310. DebugAssert(FCapturedLog != NULL);
  2311. if ((OutputType == cotOutput) || (OutputType == cotError))
  2312. {
  2313. FCapturedLog->Add(AddedLine);
  2314. }
  2315. }
  2316. //---------------------------------------------------------------------------
  2317. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2318. TOperationSide Side)
  2319. {
  2320. return
  2321. (Side == osOther) &&
  2322. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2323. }
  2324. //---------------------------------------------------------------------------
  2325. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2326. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2327. {
  2328. TTBItemOptions O;
  2329. O = Item->Options;
  2330. TCustomDirView * DView = DirView(Side);
  2331. if ((DView->ItemFocused != NULL) &&
  2332. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2333. // when resolving links is disabled, default action is to enter the directory,
  2334. // no matter what DoubleClickAction is configured to
  2335. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2336. // Can only Edit files, but can Open/Copy even directories
  2337. ((DoubleClickAction != dcaEdit) ||
  2338. !DView->ItemIsDirectory(DView->ItemFocused)))
  2339. {
  2340. Item->Options = O << tboDefault;
  2341. }
  2342. else
  2343. {
  2344. Item->Options = O >> tboDefault;
  2345. }
  2346. }
  2347. //---------------------------------------------------------------------------
  2348. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2349. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2350. {
  2351. TCustomDirView * DView = DirView(Side);
  2352. TListItem * Item = DView->ItemFocused;
  2353. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2354. EnableFocusedOperation[Side])
  2355. {
  2356. TPoint ClientPoint;
  2357. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2358. TPoint(0, 0) : MousePos;
  2359. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2360. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2361. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2362. }
  2363. }
  2364. //---------------------------------------------------------------------------
  2365. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2366. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2367. {
  2368. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2369. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2370. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2371. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2372. Handled = true;
  2373. }
  2374. //---------------------------------------------------------------------------
  2375. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2376. {
  2377. }
  2378. //---------------------------------------------------------------------------
  2379. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2380. {
  2381. DebugAssert(FErrorList == NULL);
  2382. if (WinConfiguration->ContinueOnError)
  2383. {
  2384. FErrorList = new TStringList();
  2385. Configuration->Usage->Inc(L"ContinuationsOnError");
  2386. }
  2387. NonVisualDataModule->StartBusy();
  2388. }
  2389. //---------------------------------------------------------------------------
  2390. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2391. {
  2392. NonVisualDataModule->EndBusy();
  2393. if (FErrorList)
  2394. {
  2395. HandleErrorList(FErrorList);
  2396. }
  2397. }
  2398. //---------------------------------------------------------------------------
  2399. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2400. const TCopyParamType & CopyParam)
  2401. {
  2402. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2403. {
  2404. Configuration->Usage->Inc(L"FileMaskUses");
  2405. }
  2406. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2407. {
  2408. Configuration->Usage->Inc(L"OperationMaskUses");
  2409. }
  2410. }
  2411. //---------------------------------------------------------------------------
  2412. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2413. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2414. {
  2415. DebugAssert(!IsLocalBrowserMode());
  2416. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2417. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2418. TTransferOperationParam DefaultParam;
  2419. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2420. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2421. switch (Param.Queue)
  2422. {
  2423. case asOn:
  2424. CopyParam.Queue = true;
  2425. break;
  2426. case asOff:
  2427. CopyParam.Queue = false;
  2428. break;
  2429. case asAuto:
  2430. default:
  2431. // keep default
  2432. break;
  2433. }
  2434. bool Result =
  2435. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2436. if (Result)
  2437. {
  2438. DebugAssert(Terminal);
  2439. bool SelectionRestored = false;
  2440. TCustomDirView * DView = NULL;
  2441. if (HasDirView[Side])
  2442. {
  2443. DView = DirView(Side);
  2444. DView->SaveSelection();
  2445. DView->SaveSelectedNames();
  2446. }
  2447. UpdateCopyParamCounters(CopyParam);
  2448. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2449. DebugAssert(FTransferResumeList == NULL);
  2450. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2451. FMoveToQueue = false;
  2452. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2453. try
  2454. {
  2455. TStrings * PermanentFileList;
  2456. std::unique_ptr<TStrings> PermanentFileListOwner;
  2457. try
  2458. {
  2459. if (Side == osLocal)
  2460. {
  2461. PermanentFileList = FileList;
  2462. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2463. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2464. if (Operation == foMove)
  2465. {
  2466. ReloadLocalDirectory();
  2467. if (DView != NULL)
  2468. {
  2469. DView->RestoreSelection();
  2470. }
  2471. SelectionRestored = true;
  2472. }
  2473. }
  2474. else
  2475. {
  2476. // Clone the file list as it may refer to current directory files,
  2477. // which get destroyed, when the source directory is reloaded after foMove operation.
  2478. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2479. // But for a hotfix, we are not going to do such a big change.
  2480. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2481. PermanentFileList = PermanentFileListOwner.get();
  2482. try
  2483. {
  2484. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2485. }
  2486. __finally
  2487. {
  2488. if (Operation == foMove)
  2489. {
  2490. if (DView != NULL)
  2491. {
  2492. DView->RestoreSelection();
  2493. }
  2494. SelectionRestored = true;
  2495. }
  2496. ReloadLocalDirectory(Param.TargetDirectory);
  2497. }
  2498. }
  2499. }
  2500. catch (EAbort &)
  2501. {
  2502. if (FMoveToQueue)
  2503. {
  2504. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2505. DebugAssert(CopyParam.TransferSkipList == NULL);
  2506. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2507. if (TransferResumeList->Count > 0)
  2508. {
  2509. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2510. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2511. }
  2512. CopyParam.TransferSkipList = TransferResumeList.release();
  2513. // not really needed, just to keep it consistent with TransferResumeList
  2514. FTransferResumeList = NULL;
  2515. FMoveToQueue = false;
  2516. Configuration->Usage->Inc("MovesToBackground");
  2517. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2518. ClearTransferSourceSelection(Direction);
  2519. }
  2520. throw;
  2521. }
  2522. }
  2523. __finally
  2524. {
  2525. if (!SelectionRestored && (DView != NULL))
  2526. {
  2527. DView->DiscardSavedSelection();
  2528. }
  2529. FTransferResumeList = NULL;
  2530. }
  2531. }
  2532. return Result;
  2533. }
  2534. //---------------------------------------------------------------------------
  2535. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2536. TOperationSide Side, TStrings * FileList, void * Param)
  2537. {
  2538. DebugAssert(FileList->Count);
  2539. // We deliberately do not toggle alternative flag (Param), but use OR,
  2540. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2541. // shortcut of CurrentDeleteAlternativeAction
  2542. bool Alternative =
  2543. bool(Param) || UseAlternativeFunction();
  2544. bool Recycle;
  2545. if (IsSideLocalBrowser(Side))
  2546. {
  2547. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2548. }
  2549. else
  2550. {
  2551. Recycle =
  2552. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2553. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2554. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2555. }
  2556. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2557. if (!Result)
  2558. {
  2559. UnicodeString Query;
  2560. if (FileList->Count == 1)
  2561. {
  2562. if (IsSideLocalBrowser(Side))
  2563. {
  2564. Query = ExtractFileName(FileList->Strings[0]);
  2565. }
  2566. else
  2567. {
  2568. Query = UnixExtractFileName(FileList->Strings[0]);
  2569. }
  2570. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2571. }
  2572. else
  2573. {
  2574. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2575. }
  2576. TMessageParams Params(mpNeverAskAgainCheck);
  2577. Params.ImageName = L"Delete file";
  2578. unsigned int Answer =
  2579. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2580. if (Answer == qaNeverAskAgain)
  2581. {
  2582. Result = true;
  2583. if (Recycle)
  2584. {
  2585. WinConfiguration->ConfirmRecycling = false;
  2586. }
  2587. else
  2588. {
  2589. WinConfiguration->ConfirmDeleting = false;
  2590. }
  2591. }
  2592. else
  2593. {
  2594. Result = (Answer == qaOK);
  2595. }
  2596. }
  2597. if (Result)
  2598. {
  2599. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2600. }
  2601. return Result;
  2602. }
  2603. //---------------------------------------------------------------------------
  2604. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2605. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2606. {
  2607. TAutoBatch AutoBatch(this);
  2608. bool Result;
  2609. if ((Operation == foCopy) || (Operation == foMove))
  2610. {
  2611. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2612. }
  2613. else if (Operation == foRename)
  2614. {
  2615. DebugAssert(DirView(Side)->ItemFocused);
  2616. DirView(Side)->ItemFocused->EditCaption();
  2617. Result = true;
  2618. }
  2619. else if (Operation == foDelete)
  2620. {
  2621. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2622. }
  2623. else if (Operation == foSetProperties)
  2624. {
  2625. DirView(osRemote)->SaveSelectedNames();
  2626. Result = SetProperties(Side, FileList);
  2627. }
  2628. else if (Operation == foCustomCommand)
  2629. {
  2630. DebugAssert(Param);
  2631. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2632. DirView(osRemote)->SaveSelectedNames();
  2633. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2634. CustomCommand(FileList, *Command, NULL);
  2635. Result = true;
  2636. }
  2637. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2638. {
  2639. DebugAssert(!IsSideLocalBrowser(Side));
  2640. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2641. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2642. }
  2643. else if (Operation == foLock)
  2644. {
  2645. DebugAssert(!IsSideLocalBrowser(Side));
  2646. LockFiles(FileList, true);
  2647. Result = true;
  2648. }
  2649. else if (Operation == foUnlock)
  2650. {
  2651. DebugAssert(!IsSideLocalBrowser(Side));
  2652. LockFiles(FileList, false);
  2653. Result = true;
  2654. }
  2655. else
  2656. {
  2657. DebugFail();
  2658. }
  2659. return Result;
  2660. }
  2661. //---------------------------------------------------------------------------
  2662. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2663. {
  2664. if (Side == osCurrent)
  2665. {
  2666. Side = FCurrentSide;
  2667. }
  2668. return Side;
  2669. }
  2670. //---------------------------------------------------------------------------
  2671. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2672. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2673. {
  2674. Side = GetSide(Side);
  2675. bool Result;
  2676. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2677. try
  2678. {
  2679. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2680. }
  2681. __finally
  2682. {
  2683. delete FileList;
  2684. }
  2685. return Result;
  2686. }
  2687. //---------------------------------------------------------------------------
  2688. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2689. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2690. bool NoConfirmation, void * Param)
  2691. {
  2692. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2693. {
  2694. if ((Operation == foCopy) || (Operation == foMove))
  2695. {
  2696. DebugAssert(!IsLocalBrowserMode());
  2697. if (GetSide(Side) == osLocal)
  2698. {
  2699. Configuration->Usage->Inc(L"UploadsCommand");
  2700. }
  2701. else
  2702. {
  2703. Configuration->Usage->Inc(L"DownloadsCommand");
  2704. }
  2705. }
  2706. }
  2707. }
  2708. //---------------------------------------------------------------------------
  2709. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2710. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2711. {
  2712. TTransferOperationParam Param;
  2713. if ((WinConfiguration->Interface != ifCommander) ||
  2714. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2715. {
  2716. Flags &= ~cocShortCutHint;
  2717. }
  2718. TCustomDirView * DView = DirView(Side);
  2719. Param.Options =
  2720. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2721. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2722. if (FLAGSET(Flags, cocQueue))
  2723. {
  2724. Param.Queue = asOn;
  2725. }
  2726. else if (FLAGSET(Flags, cocNonQueue))
  2727. {
  2728. Param.Queue = asOff;
  2729. }
  2730. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2731. }
  2732. //---------------------------------------------------------------------------
  2733. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2734. {
  2735. try
  2736. {
  2737. if (ErrorList->Count)
  2738. {
  2739. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2740. if (MessageDialog(Message, qtError,
  2741. qaOK | qaCancel, HELP_NONE) == qaOK)
  2742. {
  2743. unsigned int Answer;
  2744. int Index = 0;
  2745. do
  2746. {
  2747. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2748. TQueryButtonAlias Aliases[2];
  2749. Aliases[0].Button = qaYes;
  2750. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2751. Aliases[1].Button = qaNo;
  2752. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2753. TMessageParams Params;
  2754. Params.Aliases = Aliases;
  2755. Params.AliasesCount = LENOF(Aliases);
  2756. Answer = MoreMessageDialog(
  2757. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2758. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2759. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2760. qaOK, HELP_NONE, &Params);
  2761. if (Answer == qaNo)
  2762. {
  2763. Index++;
  2764. }
  2765. if (Answer == qaYes)
  2766. {
  2767. Index--;
  2768. }
  2769. }
  2770. while (Answer != qaOK);
  2771. }
  2772. }
  2773. }
  2774. __finally
  2775. {
  2776. TStrings * List = ErrorList;
  2777. ErrorList = NULL;
  2778. for (int i = 0; i < List->Count; i++)
  2779. {
  2780. delete List->Objects[i];
  2781. }
  2782. delete List;
  2783. }
  2784. }
  2785. //---------------------------------------------------------------------------
  2786. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2787. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2788. {
  2789. // needed for checking filemasks, as there's no directory object
  2790. // associated with the file object
  2791. File->FullFileName = FullFileName;
  2792. TFileMasks::TParams MaskParams;
  2793. MaskParams.Size = File->Size;
  2794. MaskParams.Modification = File->Modification;
  2795. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2796. }
  2797. //---------------------------------------------------------------------------
  2798. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2799. {
  2800. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2801. Side = GetSide(Side);
  2802. TCustomDirView * DView = DirView(Side);
  2803. TListItem * FocusedItem = DView->ItemFocused;
  2804. UnicodeString Name;
  2805. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2806. {
  2807. Name = DView->ItemFileName(FocusedItem);
  2808. }
  2809. else
  2810. {
  2811. Name = LoadStr(NEW_FILE);
  2812. }
  2813. UnicodeString Names = Name;
  2814. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2815. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2816. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  2817. {
  2818. while (!Names.IsEmpty())
  2819. {
  2820. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2821. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2822. UnicodeString TargetFileName;
  2823. UnicodeString LocalFileName;
  2824. UnicodeString RootTempDir;
  2825. UnicodeString TempDir;
  2826. UnicodeString RemoteDirectory;
  2827. bool ExistingFile = false;
  2828. if (!IsSideLocalBrowser(Side))
  2829. {
  2830. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2831. TRemoteFile * File = NULL;
  2832. if (FTerminal->FileExists(Name, &File) &&
  2833. !File->IsDirectory)
  2834. {
  2835. try
  2836. {
  2837. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2838. ExistingFile = true;
  2839. }
  2840. __finally
  2841. {
  2842. delete File;
  2843. }
  2844. }
  2845. if (!ExistingFile)
  2846. {
  2847. RemoteDirectory = UnixExtractFilePath(Name);
  2848. TemporaryDirectoryForRemoteFiles(
  2849. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2850. TargetFileName = UnixExtractFileName(Name);
  2851. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2852. LocalFileName = TempDir +
  2853. // We probably do not want to trim the VMS version here
  2854. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2855. }
  2856. }
  2857. else
  2858. {
  2859. if (ExtractFilePath(Name).IsEmpty())
  2860. {
  2861. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2862. }
  2863. else
  2864. {
  2865. LocalFileName = ExpandFileName(Name);
  2866. }
  2867. TargetFileName = ExtractFileName(Name);
  2868. }
  2869. if (!ExistingFile)
  2870. {
  2871. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2872. if (NewFile)
  2873. {
  2874. int File = FileCreate(ApiPath(LocalFileName));
  2875. if (File < 0)
  2876. {
  2877. if (!RootTempDir.IsEmpty())
  2878. {
  2879. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2880. }
  2881. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2882. }
  2883. else
  2884. {
  2885. FileClose(File);
  2886. }
  2887. }
  2888. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2889. const TEditorData * ExternalEditor = NULL;
  2890. TFileMasks::TParams MaskParams; // size not known
  2891. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2892. false, MaskParams);
  2893. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2894. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2895. }
  2896. }
  2897. }
  2898. }
  2899. //---------------------------------------------------------------------------
  2900. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2901. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2902. {
  2903. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2904. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2905. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2906. return
  2907. ((ExecuteFileBy == efInternalEditor)) ||
  2908. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2909. }
  2910. //---------------------------------------------------------------------------
  2911. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2912. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2913. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2914. UnicodeString RemoteDirectory, bool NewFile)
  2915. {
  2916. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2917. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2918. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2919. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2920. Side = GetSide(Side);
  2921. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2922. if (!IsSideLocalBrowser(Side))
  2923. {
  2924. Data->Terminal = Terminal;
  2925. Data->Queue = Queue;
  2926. Data->SessionData = CloneCurrentSessionData();
  2927. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2928. Data->RemoteDirectory = RemoteDirectory;
  2929. Data->SessionName = Terminal->SessionData->SessionName;
  2930. Data->LocalRootDirectory = LocalRootDirectory;
  2931. Data->OriginalFileName = OriginalFileName;
  2932. Data->Command = L""; // will be changed later for external editor
  2933. }
  2934. if (ExecuteFileBy == efInternalEditor)
  2935. {
  2936. if (!IsSideLocalBrowser(Side))
  2937. {
  2938. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2939. L" - " + Terminal->SessionData->SessionName;
  2940. TForm * Editor;
  2941. try
  2942. {
  2943. TNotifyEvent OnFileChanged = NULL;
  2944. TNotifyEvent OnSaveAll = NULL;
  2945. TAnyModifiedEvent OnAnyModified = NULL;
  2946. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2947. if (Terminal->IsCapable[fcBackgroundTransfers])
  2948. {
  2949. OnFileChanged = FEditorManager->FileChanged;
  2950. OnSaveAll = SaveAllInternalEditors;
  2951. OnAnyModified = AnyInternalEditorModified;
  2952. }
  2953. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2954. FEditorManager->FileReload, FEditorManager->FileClosed,
  2955. OnSaveAll, OnAnyModified,
  2956. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2957. }
  2958. catch(...)
  2959. {
  2960. if (!LocalRootDirectory.IsEmpty())
  2961. {
  2962. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2963. }
  2964. throw;
  2965. }
  2966. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2967. }
  2968. else
  2969. {
  2970. DebugAssert(!FStandaloneEditing);
  2971. TForm * Editor =
  2972. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2973. SaveAllInternalEditors, AnyInternalEditorModified,
  2974. L"", false, SessionColor, -1, NewFile);
  2975. FLocalEditors->Add(Editor);
  2976. }
  2977. }
  2978. else
  2979. {
  2980. HANDLE Process;
  2981. if (ExecuteFileBy == efExternalEditor)
  2982. {
  2983. UnicodeString Program, Params, Dir;
  2984. Data->Command = ExternalEditor->ExternalEditor;
  2985. ReformatFileNameCommand(Data->Command);
  2986. SplitCommand(Data->Command, Program, Params, Dir);
  2987. Params = ExpandFileNameCommand(Params, FileName);
  2988. Program = ExpandEnvironmentVariables(Program);
  2989. if (!ExecuteShell(Program, Params, Process))
  2990. {
  2991. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  2992. }
  2993. }
  2994. else
  2995. {
  2996. DebugAssert(!IsSideLocalBrowser(Side));
  2997. if (!ExecuteShell(FileName, L"", Process))
  2998. {
  2999. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3000. }
  3001. }
  3002. if (IsSideLocalBrowser(Side) ||
  3003. ((ExecuteFileBy == efShell) &&
  3004. !WinConfiguration->Editor.SDIShellEditor) ||
  3005. ((ExecuteFileBy == efExternalEditor) &&
  3006. !ExternalEditor->SDIExternalEditor))
  3007. {
  3008. // no need for handle
  3009. if (Process != NULL)
  3010. {
  3011. DebugCheck(CloseHandle(Process));
  3012. }
  3013. Process = INVALID_HANDLE_VALUE;
  3014. }
  3015. else
  3016. {
  3017. if (Process == NULL)
  3018. {
  3019. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3020. }
  3021. }
  3022. if (!IsSideLocalBrowser(Side))
  3023. {
  3024. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3025. }
  3026. }
  3027. }
  3028. //---------------------------------------------------------------------------
  3029. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3030. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3031. void * /*Arg*/)
  3032. {
  3033. if (Token != NULL)
  3034. {
  3035. EditorFormFileSave(static_cast<TForm *>(Token));
  3036. }
  3037. }
  3038. //---------------------------------------------------------------------------
  3039. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3040. {
  3041. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3042. {
  3043. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3044. }
  3045. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3046. }
  3047. //---------------------------------------------------------------------------
  3048. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3049. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3050. void * Arg)
  3051. {
  3052. if ((Token != NULL) &&
  3053. IsEditorFormModified(static_cast<TForm *>(Token)))
  3054. {
  3055. *static_cast<bool *>(Arg) = true;
  3056. }
  3057. }
  3058. //---------------------------------------------------------------------------
  3059. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3060. TObject * /*Sender*/, bool & Modified)
  3061. {
  3062. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3063. {
  3064. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3065. {
  3066. Modified = true;
  3067. }
  3068. }
  3069. if (!Modified)
  3070. {
  3071. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3072. }
  3073. }
  3074. //---------------------------------------------------------------------------
  3075. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3076. {
  3077. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3078. }
  3079. //---------------------------------------------------------------------------
  3080. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3081. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3082. UnicodeString & Result, UnicodeString & RootDirectory)
  3083. {
  3084. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3085. {
  3086. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3087. Result = RootDirectory;
  3088. }
  3089. else
  3090. {
  3091. RootDirectory = L"";
  3092. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3093. Result = IncludeTrailingBackslash(Result);
  3094. }
  3095. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3096. {
  3097. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3098. }
  3099. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3100. {
  3101. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3102. {
  3103. RemoteDirectory.Delete(1, 1);
  3104. }
  3105. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3106. }
  3107. if (!ForceDirectories(ApiPath(Result)))
  3108. {
  3109. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3110. }
  3111. }
  3112. //---------------------------------------------------------------------------
  3113. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3114. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3115. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3116. {
  3117. DebugAssert(!IsLocalBrowserMode());
  3118. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3119. if (ForceText)
  3120. {
  3121. CopyParam.TransferMode = tmAscii;
  3122. }
  3123. TemporaryFileCopyParam(CopyParam);
  3124. if (AllFiles)
  3125. {
  3126. CopyParam.IncludeFileMask = TFileMasks();
  3127. }
  3128. if (TempDir.IsEmpty())
  3129. {
  3130. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3131. }
  3132. DebugAssert(!FAutoOperation);
  3133. FAutoOperation = AutoOperation;
  3134. Terminal->ExceptionOnFail = true;
  3135. try
  3136. {
  3137. try
  3138. {
  3139. // turn off confirmations, as for MDI editors we may possibly download
  3140. // the same file over
  3141. Terminal->CopyToLocal(
  3142. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3143. if (GetTargetNames)
  3144. {
  3145. for (int i = 0; i < FileList->Count; i++)
  3146. {
  3147. FileList->Strings[i] =
  3148. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3149. }
  3150. }
  3151. }
  3152. catch(...)
  3153. {
  3154. if (!RootTempDir.IsEmpty())
  3155. {
  3156. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3157. }
  3158. throw;
  3159. }
  3160. }
  3161. __finally
  3162. {
  3163. FAutoOperation = false;
  3164. Terminal->ExceptionOnFail = false;
  3165. }
  3166. }
  3167. //---------------------------------------------------------------------------
  3168. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3169. {
  3170. // Do not waste time checking for default editor list the next time,
  3171. // or testing if default editor is not notepad.
  3172. bool TryNextTime = false;
  3173. UnicodeString UsageState;
  3174. if (!WinConfiguration->EditorList->IsDefaultList())
  3175. {
  3176. UsageState = "H";
  3177. }
  3178. else
  3179. {
  3180. UnicodeString Executable;
  3181. UnicodeString ExecutableDescription;
  3182. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3183. {
  3184. UnicodeString Message =
  3185. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3186. unsigned int Answer =
  3187. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3188. if (Answer != qaOK)
  3189. {
  3190. UsageState = "R";
  3191. }
  3192. else
  3193. {
  3194. UsageState = "A";
  3195. TEditorData EditorData;
  3196. EditorData.Editor = edExternal;
  3197. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3198. EditorData.ExternalEditorOptionsAutodetect();
  3199. TEditorList EditorList;
  3200. EditorList = *WinConfiguration->EditorList;
  3201. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3202. WinConfiguration->EditorList = &EditorList;
  3203. }
  3204. }
  3205. }
  3206. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3207. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3208. }
  3209. //---------------------------------------------------------------------------
  3210. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3211. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3212. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3213. {
  3214. if (ExecuteFileBy == efDefaultEditor)
  3215. {
  3216. if (!WinConfiguration->OfferedEditorAutoConfig)
  3217. {
  3218. EditorAutoConfig();
  3219. }
  3220. const TEditorPreferences * Editor =
  3221. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3222. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3223. {
  3224. ExecuteFileBy = efInternalEditor;
  3225. ExternalEditor = NULL;
  3226. }
  3227. else if (Editor->Data->Editor == edOpen)
  3228. {
  3229. ExecuteFileBy = efShell;
  3230. ExternalEditor = NULL;
  3231. }
  3232. else
  3233. {
  3234. ExecuteFileBy = efExternalEditor;
  3235. ExternalEditor = Editor->Data;
  3236. }
  3237. }
  3238. }
  3239. //---------------------------------------------------------------------------
  3240. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3241. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3242. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3243. {
  3244. UnicodeString OriginalFileName;
  3245. UnicodeString LocalRootDirectory;
  3246. UnicodeString RemoteDirectory;
  3247. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3248. IsSideLocalBrowser(Side), MaskParams);
  3249. UnicodeString Counter;
  3250. UnicodeString LocalFileName;
  3251. bool Handled = false;
  3252. if (!IsSideLocalBrowser(Side))
  3253. {
  3254. // We need to trim VMS version here, so that we use name without version
  3255. // when uploading back to create a new version of the file
  3256. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3257. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3258. TObject * Token = NULL;
  3259. UnicodeString LocalDirectory;
  3260. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3261. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3262. LocalDirectory))
  3263. {
  3264. if (Token != NULL)
  3265. {
  3266. TForm * Form = dynamic_cast<TForm *>(Token);
  3267. if (Form->WindowState == wsMinimized)
  3268. {
  3269. ShowWindow(Form->Handle, SW_RESTORE);
  3270. }
  3271. else
  3272. {
  3273. Form->SetFocus();
  3274. }
  3275. Handled = true;
  3276. }
  3277. else
  3278. {
  3279. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3280. }
  3281. }
  3282. if (!Handled)
  3283. {
  3284. TStringList * FileList1 = new TStringList();
  3285. try
  3286. {
  3287. FileList1->AddObject(FullFileName, Object);
  3288. TemporarilyDownloadFiles(FileList1,
  3289. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3290. LocalRootDirectory, LocalDirectory, true, true, true);
  3291. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3292. }
  3293. __finally
  3294. {
  3295. delete FileList1;
  3296. }
  3297. switch (ExecuteFileBy)
  3298. {
  3299. case efShell:
  3300. Counter = "RemoteFilesExecuted";
  3301. break;
  3302. case efInternalEditor:
  3303. Counter = "RemoteFilesOpenedInInternalEditor";
  3304. break;
  3305. case efExternalEditor:
  3306. Counter = "RemoteFilesOpenedInExternalEditor";
  3307. break;
  3308. default:
  3309. DebugFail();
  3310. }
  3311. }
  3312. }
  3313. else
  3314. {
  3315. LocalFileName = FullFileName;
  3316. OriginalFileName = ExtractFileName(FullFileName);
  3317. switch (ExecuteFileBy)
  3318. {
  3319. case efShell:
  3320. Counter = "LocalFilesExecuted";
  3321. break;
  3322. case efInternalEditor:
  3323. Counter = "LocalFilesOpenedInInternalEditor";
  3324. break;
  3325. case efExternalEditor:
  3326. Counter = "LocalFilesOpenedInExternalEditor";
  3327. break;
  3328. default:
  3329. DebugFail();
  3330. }
  3331. }
  3332. if (!Handled)
  3333. {
  3334. Configuration->Usage->Inc(Counter);
  3335. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3336. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3337. }
  3338. }
  3339. //---------------------------------------------------------------------------
  3340. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3341. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3342. bool AllSelected, bool OnFocused)
  3343. {
  3344. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3345. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3346. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3347. Side = GetSide(Side);
  3348. TCustomDirView * DView = DirView(Side);
  3349. TStrings * FileList =
  3350. AllSelected ?
  3351. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3352. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3353. try
  3354. {
  3355. DebugAssert(AllSelected || (FileList->Count == 1));
  3356. for (int i = 0; i < FileList->Count; i++)
  3357. {
  3358. UnicodeString ListFileName = FileList->Strings[i];
  3359. UnicodeString FileNameOnly =
  3360. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3361. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3362. if (!DView->ItemIsDirectory(Item))
  3363. {
  3364. UnicodeString FullFileName;
  3365. if (!IsSideLocalBrowser(Side))
  3366. {
  3367. FullFileName = DirView(Side)->Path + ListFileName;
  3368. }
  3369. else
  3370. {
  3371. FullFileName = ListFileName;
  3372. }
  3373. TFileMasks::TParams MaskParams;
  3374. MaskParams.Size = DView->ItemFileSize(Item);
  3375. TDateTimePrecision Precision;
  3376. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3377. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3378. FileList->Objects[i], MaskParams);
  3379. }
  3380. }
  3381. }
  3382. __finally
  3383. {
  3384. delete FileList;
  3385. }
  3386. }
  3387. //---------------------------------------------------------------------------
  3388. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3389. {
  3390. CopyParam.FileNameCase = ncNoChange;
  3391. CopyParam.PreserveRights = false;
  3392. CopyParam.PreserveReadOnly = false;
  3393. CopyParam.ReplaceInvalidChars = true;
  3394. CopyParam.IncludeFileMask = TFileMasks();
  3395. CopyParam.NewerOnly = false;
  3396. CopyParam.FileMask = L"";
  3397. }
  3398. //---------------------------------------------------------------------------
  3399. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3400. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3401. {
  3402. TTerminalManager * Manager = TTerminalManager::Instance();
  3403. if (!IsActiveTerminal(Data->Terminal))
  3404. {
  3405. if (!NonVisualDataModule->Busy)
  3406. {
  3407. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3408. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3409. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3410. if (Data->Terminal == NULL)
  3411. {
  3412. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3413. if (SameSiteTerminal != NULL)
  3414. {
  3415. UnicodeString Message =
  3416. FMTLOAD(EDIT_SESSION_REATTACH,
  3417. (FileNameOnly, Data->SessionName, FileNameOnly));
  3418. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3419. {
  3420. Data->Terminal = Terminal;
  3421. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3422. Data->SessionName = Terminal->SessionData->SessionName;
  3423. // We might also overwrite session data
  3424. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3425. }
  3426. else
  3427. {
  3428. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3429. Abort();
  3430. }
  3431. }
  3432. }
  3433. // foreground session should reconnect itself
  3434. else if (Terminal != Data->Terminal)
  3435. {
  3436. UnicodeString Message =
  3437. MainInstructions(
  3438. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3439. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3440. {
  3441. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3442. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3443. }
  3444. else
  3445. {
  3446. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3447. Abort();
  3448. }
  3449. }
  3450. }
  3451. if (!IsActiveTerminal(Data->Terminal))
  3452. {
  3453. Configuration->Usage->Inc(L"EditInactiveSession");
  3454. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3455. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3456. (ExtractFileName(FileName), Data->SessionName)));
  3457. }
  3458. }
  3459. TStrings * FileList = new TStringList();
  3460. try
  3461. {
  3462. FileList->Add(FileName);
  3463. // consider using the same settings (preset) as when the file was downloaded
  3464. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3465. TemporaryFileCopyParam(CopyParam);
  3466. if (Data->ForceText)
  3467. {
  3468. CopyParam.TransferMode = tmAscii;
  3469. }
  3470. // so i do not need to worry if masking algorithm works in all cases
  3471. // ("" means "copy file name", no masking is actually done)
  3472. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3473. {
  3474. CopyParam.FileMask = L"";
  3475. }
  3476. else
  3477. {
  3478. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3479. }
  3480. DebugAssert(Data->Queue != NULL);
  3481. int Params = cpNoConfirmation | cpTemporary;
  3482. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3483. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3484. QueueItem->CompleteEvent = UploadCompleteEvent;
  3485. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3486. }
  3487. __finally
  3488. {
  3489. delete FileList;
  3490. }
  3491. }
  3492. //---------------------------------------------------------------------------
  3493. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3494. const UnicodeString FileName, const TEditedFileData * Data)
  3495. {
  3496. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3497. DebugAssert(!NonVisualDataModule->Busy);
  3498. if (!IsActiveTerminal(Data->Terminal))
  3499. {
  3500. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3501. (ExtractFileName(FileName), Data->SessionName)));
  3502. }
  3503. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3504. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3505. NonVisualDataModule->StartBusy();
  3506. try
  3507. {
  3508. std::unique_ptr<TRemoteFile> File;
  3509. UnicodeString RemoteFileName =
  3510. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3511. FTerminal->ExceptionOnFail = true;
  3512. try
  3513. {
  3514. TRemoteFile * AFile = NULL;
  3515. FTerminal->ReadFile(RemoteFileName, AFile);
  3516. File.reset(AFile);
  3517. if (!File->HaveFullFileName)
  3518. {
  3519. File->FullFileName = RemoteFileName;
  3520. }
  3521. }
  3522. __finally
  3523. {
  3524. FTerminal->ExceptionOnFail = false;
  3525. }
  3526. std::unique_ptr<TStrings> FileList(new TStringList());
  3527. FileList->AddObject(RemoteFileName, File.get());
  3528. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3529. UnicodeString TempDir = ExtractFilePath(FileName);
  3530. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3531. TempDir, true, true, true);
  3532. // sanity check, the target file name should be still the same
  3533. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3534. }
  3535. __finally
  3536. {
  3537. NonVisualDataModule->EndBusy();
  3538. // it actually may not exist anymore...
  3539. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3540. }
  3541. }
  3542. //---------------------------------------------------------------------------
  3543. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3544. const TEditedFileData * Data, bool & KeepOpen)
  3545. {
  3546. // Command is set for external editors only (not for "shell" open).
  3547. if (!Data->Command.IsEmpty())
  3548. {
  3549. bool AnyFound = false;
  3550. bool AnyMDI = false;
  3551. bool AnyNonMDI = false;
  3552. bool AnyDetect = false;
  3553. TEditorList * EditorList = new TEditorList();
  3554. try
  3555. {
  3556. *EditorList = *WinConfiguration->EditorList;
  3557. for (int i = 0; i < EditorList->Count; i++)
  3558. {
  3559. const TEditorPreferences * Editor = EditorList->Editors[i];
  3560. if ((Editor->Data->Editor == edExternal) &&
  3561. (Editor->Data->ExternalEditor == Data->Command))
  3562. {
  3563. AnyFound = true;
  3564. if (Editor->Data->SDIExternalEditor)
  3565. {
  3566. AnyNonMDI = true;
  3567. if (Editor->Data->DetectMDIExternalEditor)
  3568. {
  3569. AnyDetect = true;
  3570. }
  3571. }
  3572. else
  3573. {
  3574. AnyMDI = true;
  3575. }
  3576. }
  3577. }
  3578. bool EnableMDI = false;
  3579. bool DisableDetect = false;
  3580. if (AnyMDI)
  3581. {
  3582. KeepOpen = true;
  3583. if (AnyNonMDI)
  3584. {
  3585. // there is at least one instance of the editor with MDI support enabled,
  3586. // and one with disabled, enable it for all instances
  3587. EnableMDI = true;
  3588. }
  3589. }
  3590. else if (AnyFound && !AnyDetect)
  3591. {
  3592. // at least once instance found but all have MDI autodetection disabled
  3593. // => close the file (default action)
  3594. }
  3595. else
  3596. {
  3597. // no instance of the editor has MDI support enabled
  3598. TMessageParams Params;
  3599. if (AnyFound)
  3600. {
  3601. // there is at least one instance of the editor
  3602. Params.Params |= mpNeverAskAgainCheck;
  3603. }
  3604. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3605. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3606. switch (Answer)
  3607. {
  3608. case qaNeverAskAgain:
  3609. DisableDetect = true;
  3610. break;
  3611. case qaNo:
  3612. EnableMDI = true;
  3613. KeepOpen = true;
  3614. break;
  3615. }
  3616. }
  3617. if (AnyFound && (EnableMDI || DisableDetect))
  3618. {
  3619. bool Changed = false;
  3620. for (int i = 0; i < EditorList->Count; i++)
  3621. {
  3622. const TEditorPreferences * Editor = EditorList->Editors[i];
  3623. if ((Editor->Data->Editor == edExternal) &&
  3624. (Editor->Data->ExternalEditor == Data->Command) &&
  3625. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3626. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3627. {
  3628. Changed = true;
  3629. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3630. if (EnableMDI)
  3631. {
  3632. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3633. }
  3634. if (DisableDetect)
  3635. {
  3636. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3637. }
  3638. EditorList->Change(i, UpdatedEditor);
  3639. }
  3640. }
  3641. if (Changed)
  3642. {
  3643. WinConfiguration->EditorList = EditorList;
  3644. }
  3645. }
  3646. }
  3647. __finally
  3648. {
  3649. delete EditorList;
  3650. }
  3651. }
  3652. else
  3653. {
  3654. // "open" case
  3655. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3656. qaOK, HELP_APP_EARLY_CLOSED);
  3657. }
  3658. }
  3659. //---------------------------------------------------------------------------
  3660. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3661. {
  3662. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3663. }
  3664. //---------------------------------------------------------------------------
  3665. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3666. {
  3667. SideEnter(osRemote);
  3668. }
  3669. //---------------------------------------------------------------------------
  3670. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3671. {
  3672. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3673. SideEnter(osRemote);
  3674. }
  3675. //---------------------------------------------------------------------------
  3676. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3677. {
  3678. FCurrentSide = Side;
  3679. if (Visible)
  3680. {
  3681. UpdateControls();
  3682. }
  3683. }
  3684. //---------------------------------------------------------------------------
  3685. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3686. TStrings * FileList, bool Alternative)
  3687. {
  3688. TCustomDirView * DView = DirView(Side);
  3689. DView->SaveSelection();
  3690. DView->SaveSelectedNames();
  3691. DebugAssert(!FAlternativeDelete);
  3692. FAlternativeDelete = Alternative;
  3693. try
  3694. {
  3695. if (!IsSideLocalBrowser(Side))
  3696. {
  3697. DebugAssert(Terminal != NULL);
  3698. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3699. }
  3700. else
  3701. {
  3702. try
  3703. {
  3704. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3705. }
  3706. __finally
  3707. {
  3708. ReloadLocalDirectory();
  3709. }
  3710. }
  3711. FAlternativeDelete = false;
  3712. }
  3713. catch(...)
  3714. {
  3715. FAlternativeDelete = false;
  3716. DView->DiscardSavedSelection();
  3717. throw;
  3718. }
  3719. DView->RestoreSelection();
  3720. }
  3721. //---------------------------------------------------------------------------
  3722. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3723. {
  3724. DebugAssert(Terminal);
  3725. DebugAssert(!IsLocalBrowserMode());
  3726. RemoteDirView->SaveSelection();
  3727. RemoteDirView->SaveSelectedNames();
  3728. try
  3729. {
  3730. if (Lock)
  3731. {
  3732. Terminal->LockFiles(FileList);
  3733. }
  3734. else
  3735. {
  3736. Terminal->UnlockFiles(FileList);
  3737. }
  3738. }
  3739. catch(...)
  3740. {
  3741. RemoteDirView->DiscardSavedSelection();
  3742. throw;
  3743. }
  3744. RemoteDirView->RestoreSelection();
  3745. }
  3746. //---------------------------------------------------------------------------
  3747. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3748. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3749. bool NoConfirmation, bool Move)
  3750. {
  3751. DebugAssert(Terminal != NULL);
  3752. DebugAssert(!IsLocalBrowserMode());
  3753. // update Terminal->StateData->RemoteDirectory
  3754. UpdateTerminal(Terminal);
  3755. if (Session == NULL)
  3756. {
  3757. Session = TTerminalManager::Instance()->ActiveTerminal;
  3758. }
  3759. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3760. {
  3761. if (RemoteDriveView->DropTarget != NULL)
  3762. {
  3763. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3764. }
  3765. else if (RemoteDirView->DropTarget != NULL)
  3766. {
  3767. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3768. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3769. }
  3770. else
  3771. {
  3772. Target = RemoteDirView->Path;
  3773. }
  3774. }
  3775. else
  3776. {
  3777. Target = Session->StateData->RemoteDirectory;
  3778. }
  3779. Target = UnixIncludeTrailingBackslash(Target);
  3780. if (FileList->Count == 1)
  3781. {
  3782. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3783. }
  3784. else
  3785. {
  3786. FileMask = AnyMask;
  3787. }
  3788. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3789. bool Result = true;
  3790. if (!NoConfirmation)
  3791. {
  3792. bool Multi = (FileList->Count > 1);
  3793. if (Move)
  3794. {
  3795. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3796. }
  3797. else
  3798. {
  3799. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3800. TStrings * Directories = new TStringList;
  3801. try
  3802. {
  3803. for (int Index = 0; Index < Sessions->Count; Index++)
  3804. {
  3805. TManagedTerminal * Terminal =
  3806. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3807. Directories->Add(Terminal->StateData->RemoteDirectory);
  3808. }
  3809. TDirectRemoteCopy AllowDirectCopy;
  3810. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3811. {
  3812. DebugAssert(DirectCopy);
  3813. AllowDirectCopy = drcAllow;
  3814. }
  3815. else if (FTerminal->IsCapable[fcSecondaryShell])
  3816. {
  3817. DebugAssert(DirectCopy);
  3818. AllowDirectCopy = drcConfirmCommandSession;
  3819. }
  3820. else
  3821. {
  3822. DebugAssert(!DirectCopy);
  3823. AllowDirectCopy = drcDisallow;
  3824. }
  3825. void * ASession = Session;
  3826. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3827. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3828. Session = static_cast<TManagedTerminal *>(ASession);
  3829. }
  3830. __finally
  3831. {
  3832. delete Directories;
  3833. }
  3834. }
  3835. }
  3836. return Result;
  3837. }
  3838. //---------------------------------------------------------------------------
  3839. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3840. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3841. {
  3842. DebugAssert(!IsLocalBrowserMode());
  3843. bool DirectCopy;
  3844. UnicodeString Target, FileMask;
  3845. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3846. if (Result)
  3847. {
  3848. if (!Move && !DirectCopy)
  3849. {
  3850. Configuration->Usage->Inc("RemoteCopyTemp");
  3851. UnicodeString RootTempDir;
  3852. UnicodeString TempDir;
  3853. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3854. TStrings * TemporaryFilesList = new TStringList();
  3855. try
  3856. {
  3857. TMakeLocalFileListParams MakeFileListParam;
  3858. MakeFileListParam.FileList = TemporaryFilesList;
  3859. MakeFileListParam.FileTimes = NULL;
  3860. MakeFileListParam.IncludeDirs = true;
  3861. MakeFileListParam.Recursive = false;
  3862. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3863. TTerminalManager::Instance()->ActiveTerminal = Session;
  3864. if (TemporaryFilesList->Count > 0)
  3865. {
  3866. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3867. CopyParam.FileMask = FileMask;
  3868. DebugAssert(!FAutoOperation);
  3869. FAutoOperation = true;
  3870. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3871. }
  3872. }
  3873. __finally
  3874. {
  3875. delete TemporaryFilesList;
  3876. FAutoOperation = false;
  3877. if (!RootTempDir.IsEmpty())
  3878. {
  3879. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3880. }
  3881. }
  3882. }
  3883. else
  3884. {
  3885. RemoteDirView->SaveSelection();
  3886. RemoteDirView->SaveSelectedNames();
  3887. try
  3888. {
  3889. if (Move)
  3890. {
  3891. Configuration->Usage->Inc("RemoteMove");
  3892. Terminal->MoveFiles(FileList, Target, FileMask);
  3893. }
  3894. else
  3895. {
  3896. Configuration->Usage->Inc("RemoteCopyDirect");
  3897. DebugAssert(DirectCopy);
  3898. DebugAssert(Session == FTerminal);
  3899. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3900. FTerminal->CommandSessionOpened ||
  3901. CommandSessionFallback())
  3902. {
  3903. Terminal->CopyFiles(FileList, Target, FileMask);
  3904. }
  3905. }
  3906. }
  3907. catch(...)
  3908. {
  3909. RemoteDirView->DiscardSavedSelection();
  3910. throw;
  3911. }
  3912. RemoteDirView->RestoreSelection();
  3913. }
  3914. }
  3915. return Result;
  3916. }
  3917. //---------------------------------------------------------------------------
  3918. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3919. const UnicodeString & Path, TRemoteProperties & Properties)
  3920. {
  3921. DebugAssert(!IsLocalBrowserMode());
  3922. Properties.Valid = Properties.Valid << vpEncrypt;
  3923. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3924. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3925. }
  3926. //---------------------------------------------------------------------------
  3927. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3928. {
  3929. Side = GetSide(Side);
  3930. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3931. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3932. UnicodeString Name = LoadStr(NEW_FOLDER);
  3933. int AllowedChanges =
  3934. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3935. bool SaveSettings = false;
  3936. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3937. {
  3938. TWindowLock Lock(this);
  3939. if (!IsSideLocalBrowser(Side))
  3940. {
  3941. if (SaveSettings)
  3942. {
  3943. GUIConfiguration->NewDirectoryProperties = Properties;
  3944. }
  3945. CreateRemoteDirectory(Name, Properties);
  3946. }
  3947. else
  3948. {
  3949. DirView(Side)->CreateDirectory(Name);
  3950. }
  3951. }
  3952. }
  3953. //---------------------------------------------------------------------------
  3954. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3955. {
  3956. TWindowLock Lock(this);
  3957. DirView(Side)->ExecuteHomeDirectory();
  3958. }
  3959. //---------------------------------------------------------------------------
  3960. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3961. {
  3962. DoOpenDirectoryDialog(odBrowse, Side);
  3963. }
  3964. //---------------------------------------------------------------------------
  3965. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3966. {
  3967. UnicodeString Path = Bookmark->GetSideDirectory(Side);
  3968. bool Result = !Path.IsEmpty();
  3969. if (Result)
  3970. {
  3971. // While we might get here when the session is closed (from location profiles),
  3972. // it's not a problem as the Path setter is noop then
  3973. DirView(Side)->Path = Path;
  3974. }
  3975. return Result;
  3976. }
  3977. //---------------------------------------------------------------------------
  3978. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3979. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3980. bool & Close)
  3981. {
  3982. // terminal can be already closed (e.g. dropped connection)
  3983. if (Terminal != NULL)
  3984. {
  3985. try
  3986. {
  3987. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  3988. }
  3989. catch(...)
  3990. {
  3991. if (!Terminal->Active)
  3992. {
  3993. Close = true;
  3994. }
  3995. throw;
  3996. }
  3997. }
  3998. }
  3999. //---------------------------------------------------------------------------
  4000. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4001. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4002. bool & Close)
  4003. {
  4004. // terminal can be already closed (e.g. dropped connection)
  4005. if (Terminal != NULL)
  4006. {
  4007. Configuration->Usage->Inc(L"ChecksumCalculated");
  4008. try
  4009. {
  4010. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4011. }
  4012. catch(...)
  4013. {
  4014. if (!Terminal->Active)
  4015. {
  4016. Close = true;
  4017. }
  4018. throw;
  4019. }
  4020. }
  4021. }
  4022. //---------------------------------------------------------------------------
  4023. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4024. {
  4025. bool Result;
  4026. if (!IsSideLocalBrowser(Side))
  4027. {
  4028. TRemoteTokenList * GroupList = NULL;
  4029. TRemoteTokenList * UserList = NULL;
  4030. try
  4031. {
  4032. TRemoteProperties CurrentProperties;
  4033. if (Terminal->LoadFilesProperties(FileList))
  4034. {
  4035. RemoteDirView->Invalidate();
  4036. }
  4037. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4038. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4039. if (CapableGroupChanging || CapableOwnerChanging)
  4040. {
  4041. if (CapableGroupChanging)
  4042. {
  4043. GroupList = Terminal->Groups->Duplicate();
  4044. }
  4045. if (CapableOwnerChanging)
  4046. {
  4047. UserList = Terminal->Users->Duplicate();
  4048. }
  4049. TRemoteDirectory * Files = Terminal->Files;
  4050. int Count = Files->Count;
  4051. if (Count > 100)
  4052. {
  4053. Count = 100;
  4054. }
  4055. for (int Index = 0; Index < Count; Index++)
  4056. {
  4057. TRemoteFile * File = Files->Files[Index];
  4058. if (CapableGroupChanging)
  4059. {
  4060. GroupList->AddUnique(File->Group);
  4061. }
  4062. if (CapableOwnerChanging)
  4063. {
  4064. UserList->AddUnique(File->Owner);
  4065. }
  4066. }
  4067. // if we haven't collected tokens for all files in current directory,
  4068. // make sure we collect them at least for all selected files.
  4069. // (note that so far the files in FileList has to be from current direcotry)
  4070. if (Count < Files->Count)
  4071. {
  4072. for (int Index = 0; Index < FileList->Count; Index++)
  4073. {
  4074. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4075. if (CapableGroupChanging)
  4076. {
  4077. GroupList->AddUnique(File->Group);
  4078. }
  4079. if (CapableOwnerChanging)
  4080. {
  4081. UserList->AddUnique(File->Owner);
  4082. }
  4083. }
  4084. }
  4085. }
  4086. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4087. int Flags = 0;
  4088. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4089. if (CapableOwnerChanging) Flags |= cpOwner;
  4090. if (CapableGroupChanging) Flags |= cpGroup;
  4091. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4092. if (Terminal->IsCapable[fcCalculatingChecksum])
  4093. {
  4094. CalculateChecksumEvent = CalculateChecksum;
  4095. }
  4096. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4097. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4098. TRemoteProperties NewProperties = CurrentProperties;
  4099. Result =
  4100. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4101. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4102. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4103. CalculateSize, CalculateChecksumEvent);
  4104. if (Result)
  4105. {
  4106. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4107. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4108. }
  4109. }
  4110. __finally
  4111. {
  4112. delete GroupList;
  4113. delete UserList;
  4114. }
  4115. }
  4116. else
  4117. {
  4118. DirView(Side)->DisplayPropertiesMenu();
  4119. Result = true;
  4120. }
  4121. return Result;
  4122. }
  4123. //---------------------------------------------------------------------------
  4124. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4125. {
  4126. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4127. {
  4128. FIgnoreNextDialogChar = Key;
  4129. }
  4130. Key = 0;
  4131. }
  4132. //---------------------------------------------------------------------------
  4133. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4134. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4135. {
  4136. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4137. if (Command != NULL)
  4138. {
  4139. KeyProcessed(Key, Shift);
  4140. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4141. {
  4142. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4143. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4144. false, false, const_cast<TCustomCommandType *>(Command));
  4145. }
  4146. }
  4147. }
  4148. //---------------------------------------------------------------------------
  4149. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4150. {
  4151. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4152. {
  4153. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4154. }
  4155. if (!DirView(osCurrent)->IsEditing())
  4156. {
  4157. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4158. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4159. {
  4160. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4161. if (((Action->ShortCut == KeyShortCut) ||
  4162. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4163. AllowedAction(Action, aaShortCut))
  4164. {
  4165. // Has to be called before the action as the dialog char is already in queue.
  4166. // So when the action consumes message queue, we already need to have the
  4167. // FIgnoreNextDialogChar set
  4168. KeyProcessed(Key, Shift);
  4169. // Reset reference to previous component (when menu/toolbar was clicked).
  4170. // Needed to detect that action was invoked by keyboard shortcut
  4171. // in TNonVisualDataModule::ExplorerActionsExecute
  4172. Action->ActionComponent = NULL;
  4173. Action->Execute();
  4174. return;
  4175. }
  4176. }
  4177. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4178. {
  4179. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4180. {
  4181. KeyProcessed(Key, Shift);
  4182. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4183. return;
  4184. }
  4185. }
  4186. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4187. {
  4188. KeyProcessed(Key, Shift);
  4189. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4190. }
  4191. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4192. if (IsCustomShortCut(CustomShortCut))
  4193. {
  4194. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4195. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4196. if (WinConfiguration->SharedBookmarks != NULL)
  4197. {
  4198. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4199. if ((Bookmark != NULL) &&
  4200. OpenBookmark(FCurrentSide, Bookmark))
  4201. {
  4202. KeyProcessed(Key, Shift);
  4203. }
  4204. }
  4205. }
  4206. }
  4207. TForm::KeyDown(Key, Shift);
  4208. }
  4209. //---------------------------------------------------------------------------
  4210. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4211. {
  4212. DebugAssert(Terminal != NULL);
  4213. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4214. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4215. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4216. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4217. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4218. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4219. // expanded from ?: to avoid memory leaks
  4220. if (SecurityEnabled)
  4221. {
  4222. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4223. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4224. }
  4225. else
  4226. {
  4227. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4228. }
  4229. if (FileSystemInfo.ProtocolName.IsEmpty())
  4230. {
  4231. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4232. }
  4233. else
  4234. {
  4235. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4236. }
  4237. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4238. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4239. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4240. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4241. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4242. UnicodeString CompressionStr = CSCompressionStr;
  4243. if (CSCompressionStr != SCCompressionStr)
  4244. {
  4245. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4246. }
  4247. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4248. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4249. UpdateStatusBar();
  4250. }
  4251. //---------------------------------------------------------------------------
  4252. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4253. {
  4254. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4255. DebugAssert(SessionStatusBar != NULL);
  4256. if (!HasActiveTerminal() || (Terminal->Status < ssOpened))
  4257. {
  4258. // note: (Terminal->Status < sshReady) currently never happens here,
  4259. // so STATUS_CONNECTING is never used
  4260. SessionStatusBar->SimplePanel = true;
  4261. SessionStatusBar->SimpleText = LoadStr(
  4262. !HasActiveTerminal() ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4263. }
  4264. else
  4265. {
  4266. DebugAssert(Terminal);
  4267. SessionStatusBar->SimplePanel = false;
  4268. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4269. if (!FNote.IsEmpty())
  4270. {
  4271. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4272. }
  4273. else
  4274. {
  4275. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4276. }
  4277. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4278. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4279. }
  4280. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4281. }
  4282. //---------------------------------------------------------------------------
  4283. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4284. {
  4285. Panel->Caption = L"";
  4286. }
  4287. //---------------------------------------------------------------------------
  4288. void __fastcall TCustomScpExplorerForm::Idle()
  4289. {
  4290. if (FShowing || FStandaloneEditing)
  4291. {
  4292. FEditorManager->Check();
  4293. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4294. // that needs to know if queue view is visible (and it may be closed after queue update)
  4295. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4296. }
  4297. if (FShowing)
  4298. {
  4299. if (!NonVisualDataModule->Busy &&
  4300. // Menu is opened or drag&drop is going on
  4301. (Mouse->Capture == NULL))
  4302. {
  4303. if (FRefreshRemoteDirectory)
  4304. {
  4305. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4306. {
  4307. Terminal->RefreshDirectory();
  4308. }
  4309. FRefreshRemoteDirectory = false;
  4310. }
  4311. if (FRefreshLocalDirectory)
  4312. {
  4313. ReloadLocalDirectory();
  4314. FRefreshLocalDirectory = false;
  4315. }
  4316. if (WinConfiguration->RefreshRemotePanel)
  4317. {
  4318. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4319. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4320. {
  4321. RemoteDirView->ReloadDirectory();
  4322. }
  4323. }
  4324. }
  4325. }
  4326. if (FShowing || FStandaloneEditing)
  4327. {
  4328. if (FQueueStatusInvalidated)
  4329. {
  4330. UpdateQueueStatus(false);
  4331. }
  4332. RefreshQueueItems();
  4333. }
  4334. if (FShowing)
  4335. {
  4336. UpdateStatusBar();
  4337. }
  4338. FIgnoreNextDialogChar = 0;
  4339. }
  4340. //---------------------------------------------------------------------------
  4341. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4342. {
  4343. try
  4344. {
  4345. FUserActionTimer->Enabled = false;
  4346. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4347. {
  4348. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4349. {
  4350. FPendingQueueActionItem->ProcessUserAction();
  4351. }
  4352. }
  4353. }
  4354. __finally
  4355. {
  4356. FPendingQueueActionItem = NULL;
  4357. }
  4358. }
  4359. //---------------------------------------------------------------------------
  4360. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4361. {
  4362. if (WinConfiguration->MinimizeToTray)
  4363. {
  4364. UpdateTrayIcon();
  4365. FTrayIcon->Visible = true;
  4366. if (Visible)
  4367. {
  4368. ShowWindow(Handle, SW_HIDE);
  4369. }
  4370. }
  4371. }
  4372. //---------------------------------------------------------------------------
  4373. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4374. {
  4375. // WORKAROUND
  4376. // When restoring maximized window from minimization,
  4377. // rarely some controls do not align properly.
  4378. // Two instances seen (both for Commander):
  4379. // - When restoring, window is temporarily narrower (not maximized),
  4380. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4381. // Once maximized already, top dock shinks back, but the session PageControl,
  4382. // do not align up, leaving space between TopDock and PageControl.
  4383. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4384. for (int Index = 0; Index < ControlCount; Index++)
  4385. {
  4386. RealignControl(Controls[Index]);
  4387. }
  4388. if (FTrayIcon->Visible)
  4389. {
  4390. FTrayIcon->Visible = false;
  4391. if (Visible)
  4392. {
  4393. ShowWindow(Handle, SW_SHOW);
  4394. }
  4395. }
  4396. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4397. {
  4398. FNeedSession = false;
  4399. NonVisualDataModule->StartBusy();
  4400. try
  4401. {
  4402. NeedSession(true);
  4403. }
  4404. __finally
  4405. {
  4406. NonVisualDataModule->EndBusy();
  4407. }
  4408. }
  4409. }
  4410. //---------------------------------------------------------------------------
  4411. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4412. {
  4413. FTrayIcon->Hint = GetMainForm()->Caption;
  4414. }
  4415. //---------------------------------------------------------------------------
  4416. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4417. {
  4418. UpdateTrayIcon();
  4419. }
  4420. //---------------------------------------------------------------------------
  4421. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4422. {
  4423. // workaround
  4424. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4425. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4426. // But WM_ACTIVATEAPP message can be received even when
  4427. // the main window is minimized to the tray and internal editor window is focused
  4428. // (after another application was previously active)
  4429. if (::IsIconic(Handle))
  4430. {
  4431. if (!IsAppIconic())
  4432. {
  4433. SetAppIconic(true);
  4434. }
  4435. }
  4436. ::ApplicationRestore();
  4437. Application->BringToFront();
  4438. }
  4439. //---------------------------------------------------------------------------
  4440. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4441. {
  4442. RestoreApp();
  4443. }
  4444. //---------------------------------------------------------------------------
  4445. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4446. {
  4447. if (OpenInNewWindow())
  4448. {
  4449. ExecuteNewInstance(SessionUrl);
  4450. }
  4451. else
  4452. {
  4453. TTerminalManager::Instance()->NewSession(SessionUrl);
  4454. }
  4455. }
  4456. //---------------------------------------------------------------------------
  4457. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4458. {
  4459. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4460. StoredSessions->NewSession(SessionName, SessionData);
  4461. // modified only, explicit
  4462. StoredSessions->Save(false, true);
  4463. // encode session name because of slashes in hierarchical sessions
  4464. return EncodeUrlString(SessionName);
  4465. }
  4466. //---------------------------------------------------------------------------
  4467. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4468. {
  4469. // current working directories become defaults here, what is not right
  4470. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4471. return SaveHiddenDuplicateSession(SessionData.get());
  4472. }
  4473. //---------------------------------------------------------------------------
  4474. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4475. {
  4476. if (OpenInNewWindow())
  4477. {
  4478. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4479. }
  4480. else
  4481. {
  4482. // current working directories become defaults here, what is not right
  4483. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4484. TTerminalManager * Manager = TTerminalManager::Instance();
  4485. TManagedTerminal * ATerminal = Manager->NewManagedTerminal(SessionData.get());
  4486. // We definitelly want this
  4487. ATerminal->Disconnected = Terminal->Disconnected;
  4488. // Not sure about these two
  4489. ATerminal->Permanent = Terminal->Permanent;
  4490. ATerminal->DisconnectedTemporarily = Terminal->DisconnectedTemporarily; // maybe
  4491. Manager->ActiveTerminal = ATerminal;
  4492. }
  4493. }
  4494. //---------------------------------------------------------------------------
  4495. void __fastcall TCustomScpExplorerForm::RenameSession()
  4496. {
  4497. UnicodeString Name = Terminal->SessionData->SessionName;
  4498. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4499. {
  4500. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4501. TSessionData::ValidateName(Name);
  4502. // This is inconsistent with how color (for example) is handled.
  4503. Terminal->SessionData->Name = Name;
  4504. UpdateControls();
  4505. // Add/Remove distinguishing paths from sessions of the same name.
  4506. DoTerminalListChanged();
  4507. }
  4508. }
  4509. //---------------------------------------------------------------------------
  4510. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4511. {
  4512. DebugAssert(Queue != NULL);
  4513. bool Result = Queue->IsEmpty;
  4514. if (!Result)
  4515. {
  4516. SetFocus();
  4517. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4518. }
  4519. return Result;
  4520. }
  4521. //---------------------------------------------------------------------------
  4522. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4523. {
  4524. return CanCloseQueue(FQueue);
  4525. }
  4526. //---------------------------------------------------------------------------
  4527. void __fastcall TCustomScpExplorerForm::CloseSession()
  4528. {
  4529. if (CanCloseQueue())
  4530. {
  4531. TTerminalManager::Instance()->FreeActiveTerminal();
  4532. }
  4533. }
  4534. //---------------------------------------------------------------------------
  4535. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4536. {
  4537. if (CanCloseQueue())
  4538. {
  4539. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4540. }
  4541. }
  4542. //---------------------------------------------------------------------------
  4543. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4544. {
  4545. DetachTerminal(Terminal);
  4546. RemoteDirView->Terminal = Terminal;
  4547. UpdateRemotePathComboBox(false);
  4548. UpdateControls();
  4549. }
  4550. //---------------------------------------------------------------------------
  4551. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4552. {
  4553. if (DebugAlwaysTrue(!Terminal->Active))
  4554. {
  4555. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4556. }
  4557. }
  4558. //---------------------------------------------------------------------------
  4559. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4560. {
  4561. if (OpenInNewWindow())
  4562. {
  4563. // encode session name because of slashes in hierarchical sessions
  4564. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4565. }
  4566. else
  4567. {
  4568. TTerminalManager * Manager = TTerminalManager::Instance();
  4569. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4570. Manager->ActiveTerminal = Terminal;
  4571. }
  4572. }
  4573. //---------------------------------------------------------------------------
  4574. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4575. {
  4576. TTerminalManager * Manager = TTerminalManager::Instance();
  4577. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4578. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4579. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4580. // FirstTerminal can be null, if some of the
  4581. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4582. {
  4583. FirstTerminal->Disconnected = true;
  4584. FirstTerminal->DisconnectedTemporarily = true;
  4585. }
  4586. Manager->ActiveTerminal = FirstTerminal;
  4587. }
  4588. //---------------------------------------------------------------------------
  4589. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4590. {
  4591. if (OpenInNewWindow())
  4592. {
  4593. ExecuteNewInstance(Name);
  4594. }
  4595. else
  4596. {
  4597. DoOpenFolderOrWorkspace(Name, true);
  4598. }
  4599. }
  4600. //---------------------------------------------------------------------------
  4601. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4602. bool &CanClose)
  4603. {
  4604. // See the comment in CloseApp()
  4605. if (NonVisualDataModule->Busy)
  4606. {
  4607. CanClose = false;
  4608. }
  4609. else
  4610. {
  4611. TTerminalManager * Manager = TTerminalManager::Instance();
  4612. int ActiveSessions = 0;
  4613. for (int Index = 0; Index < Manager->Count; Index++)
  4614. {
  4615. if (Manager->Sessions[Index]->Active)
  4616. {
  4617. ActiveSessions++;
  4618. }
  4619. }
  4620. // Confirm, when there's at least one active remote session
  4621. if ((ActiveSessions > 0) &&
  4622. WinConfiguration->ConfirmClosingSession)
  4623. {
  4624. unsigned int Result;
  4625. TMessageParams Params(mpNeverAskAgainCheck);
  4626. UnicodeString Message;
  4627. int Answers = qaOK | qaCancel;
  4628. // The current session is the only active session
  4629. if ((ActiveSessions == 1) && (Terminal != NULL) && Terminal->Active)
  4630. {
  4631. if (!WinConfiguration->AutoSaveWorkspace)
  4632. {
  4633. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4634. }
  4635. else
  4636. {
  4637. Message = LoadStr(CLOSE_SESSION);
  4638. }
  4639. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4640. }
  4641. // Multiple active sessions or one active session, but it's not the current one
  4642. else if (DebugAlwaysTrue(ActiveSessions > 0))
  4643. {
  4644. if (!WinConfiguration->AutoSaveWorkspace)
  4645. {
  4646. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4647. }
  4648. else
  4649. {
  4650. Message = LoadStr(CLOSE_SESSIONS);
  4651. }
  4652. }
  4653. UnicodeString Note;
  4654. if (WinConfiguration->AutoSaveWorkspace)
  4655. {
  4656. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4657. }
  4658. else
  4659. {
  4660. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4661. Answers = qaYes | qaNo | qaCancel;
  4662. }
  4663. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4664. SetFocus();
  4665. Result = MessageDialog(Message, qtConfirmation,
  4666. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4667. if (Result == qaNeverAskAgain)
  4668. {
  4669. WinConfiguration->ConfirmClosingSession = false;
  4670. }
  4671. if (Result == qaNo)
  4672. {
  4673. CanClose = SaveWorkspace(true);
  4674. // note that the workspace will be saved redundatly again from FormClose
  4675. }
  4676. else
  4677. {
  4678. CanClose =
  4679. (Result == qaOK) ||
  4680. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4681. (Result == qaNeverAskAgain);
  4682. }
  4683. }
  4684. if (CanClose)
  4685. {
  4686. CanClose = CanCloseQueue();
  4687. }
  4688. }
  4689. if (CanClose)
  4690. {
  4691. CanClose =
  4692. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4693. FEditorManager->CloseExternalFilesWithoutProcess();
  4694. if (CanClose)
  4695. {
  4696. while (CanClose && (FLocalEditors->Count > 0))
  4697. {
  4698. int PrevCount = FLocalEditors->Count;
  4699. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4700. CanClose = (FLocalEditors->Count < PrevCount);
  4701. }
  4702. if (CanClose)
  4703. {
  4704. CanClose = FEditorManager->Empty(true);
  4705. if (!CanClose)
  4706. {
  4707. SetFocus();
  4708. CanClose =
  4709. (MessageDialog(
  4710. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4711. }
  4712. }
  4713. }
  4714. }
  4715. }
  4716. //---------------------------------------------------------------------------
  4717. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4718. {
  4719. TForm * Form = dynamic_cast<TForm *>(Sender);
  4720. DebugAssert(Form != NULL);
  4721. Form->Close();
  4722. }
  4723. //---------------------------------------------------------------------------
  4724. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4725. {
  4726. TForm * Form = dynamic_cast<TForm *>(Sender);
  4727. delete Form;
  4728. }
  4729. //---------------------------------------------------------------------------
  4730. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4731. {
  4732. while (FLocalEditors->Count > 0)
  4733. {
  4734. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4735. }
  4736. }
  4737. //---------------------------------------------------------------------------
  4738. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4739. TObject *Sender)
  4740. {
  4741. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4742. try
  4743. {
  4744. SetProperties(osRemote, FileList);
  4745. }
  4746. __finally
  4747. {
  4748. delete FileList;
  4749. }
  4750. }
  4751. //---------------------------------------------------------------------------
  4752. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4753. {
  4754. if (value)
  4755. {
  4756. if (Component == fcCustomCommandsBand)
  4757. {
  4758. UpdateCustomCommandsToolbar();
  4759. }
  4760. if (Component == fcQueueFileList)
  4761. {
  4762. DebugAssert(!QueueFileListSplitter->Visible);
  4763. AdjustQueueLayout();
  4764. UpdateQueueFileList();
  4765. }
  4766. }
  4767. }
  4768. //---------------------------------------------------------------------------
  4769. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4770. {
  4771. int MinHeightLimit =
  4772. GetStaticQueuePanelComponentsHeight() +
  4773. QueueFileListSplitter->Height +
  4774. QueueFileList->Height +
  4775. GetMinQueueViewHeight();
  4776. if (QueuePanel->ClientHeight < MinHeightLimit)
  4777. {
  4778. QueuePanel->ClientHeight = MinHeightLimit;
  4779. }
  4780. }
  4781. //---------------------------------------------------------------------------
  4782. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4783. {
  4784. TControl * Control = GetComponent(Component);
  4785. DebugAssert(Control);
  4786. bool Changed = (Control->Visible != value);
  4787. if (Changed)
  4788. {
  4789. ComponentShowing(Component, value);
  4790. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4791. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4792. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4793. if (value)
  4794. {
  4795. int RemainingHeight = Control->Parent->ClientHeight;
  4796. int RemainingWidth = Control->Parent->ClientWidth;
  4797. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4798. {
  4799. TControl * ChildControl = Control->Parent->Controls[i];
  4800. if (ChildControl->Visible)
  4801. {
  4802. switch (ChildControl->Align)
  4803. {
  4804. case alTop:
  4805. case alBottom:
  4806. RemainingHeight -= ChildControl->Height;
  4807. break;
  4808. case alLeft:
  4809. case alRight:
  4810. RemainingWidth -= ChildControl->Width;
  4811. break;
  4812. }
  4813. }
  4814. }
  4815. int Reserve = ScaleByTextHeight(this, 32);
  4816. // queue in explorer, trees in commander
  4817. if (Control->Height > RemainingHeight - Reserve)
  4818. {
  4819. Control->Height = RemainingHeight / 2;
  4820. }
  4821. if (Control->Width > RemainingWidth - Reserve)
  4822. {
  4823. Control->Width = RemainingWidth / 2;
  4824. }
  4825. }
  4826. Control->Visible = value;
  4827. if (WasFocused && Visible)
  4828. {
  4829. DirView(osCurrent)->SetFocus();
  4830. }
  4831. FixControlsPlacement();
  4832. }
  4833. }
  4834. //---------------------------------------------------------------------------
  4835. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4836. {
  4837. TControl * Control = GetComponent(Component);
  4838. if (Control == NULL)
  4839. {
  4840. return false;
  4841. }
  4842. else
  4843. {
  4844. return Control->Visible;
  4845. }
  4846. }
  4847. //---------------------------------------------------------------------------
  4848. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4849. {
  4850. bool Result;
  4851. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4852. {
  4853. Result = !IsUWP();
  4854. }
  4855. else
  4856. {
  4857. Result = true;
  4858. }
  4859. return Result;
  4860. }
  4861. //---------------------------------------------------------------------------
  4862. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4863. {
  4864. if (DirView(osOther)->ItemFocused != NULL)
  4865. {
  4866. DirView(osOther)->ItemFocused->MakeVisible(false);
  4867. }
  4868. QueueSplitter->Visible = QueuePanel->Visible;
  4869. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4870. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4871. TControl * QueueControlsOrder[] =
  4872. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4873. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4874. }
  4875. //---------------------------------------------------------------------------
  4876. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4877. {
  4878. switch (Component) {
  4879. case fcStatusBar: return RemoteStatusBar;
  4880. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4881. case fcQueueView: return QueuePanel;
  4882. case fcQueueToolbar: return QueueDock;
  4883. case fcRemoteTree: return RemoteDrivePanel;
  4884. case fcSessionsTabs: return SessionsPageControl;
  4885. case fcQueueFileList: return QueueFileList;
  4886. default: return NULL;
  4887. }
  4888. }
  4889. //---------------------------------------------------------------------------
  4890. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4891. TObject *Sender, TListColumn *Column, TPoint &Point)
  4892. {
  4893. DebugAssert(NonVisualDataModule && Column && Sender);
  4894. NonVisualDataModule->ListColumn = Column;
  4895. TPopupMenu * DirViewColumnMenu;
  4896. if (dynamic_cast<TUnixDirView *>(Sender) != NULL)
  4897. {
  4898. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4899. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4900. (Column->Index == uvName);
  4901. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4902. (Column->Index == uvSize);
  4903. }
  4904. else
  4905. {
  4906. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4907. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4908. (Column->Index == dvName);
  4909. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4910. (Column->Index == dvSize);
  4911. }
  4912. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4913. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4914. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4915. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4916. }
  4917. //---------------------------------------------------------------------------
  4918. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4919. TObject *Sender, TListItem *Item, bool &AllowExec)
  4920. {
  4921. DoDirViewExecFile(Sender, Item, AllowExec);
  4922. }
  4923. //---------------------------------------------------------------------------
  4924. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4925. TListItem * Item, bool & AllowExec)
  4926. {
  4927. DebugAssert(Sender && Item && Configuration);
  4928. DebugAssert(AllowExec);
  4929. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4930. bool Remote = (ADirView == DirView(osRemote)) && !IsSideLocalBrowser(osRemote);
  4931. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  4932. TOperationSide Side = (Remote ? osRemote : osLocal); // TODO
  4933. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4934. // on files only (not directories)
  4935. // and only when symlinks are resolved (apply to remote panel only)
  4936. if (!ADirView->ItemIsDirectory(Item) &&
  4937. (ResolvedSymlinks || FForceExecution))
  4938. {
  4939. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4940. !FForceExecution && ResolvedSymlinks)
  4941. {
  4942. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4943. {
  4944. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4945. UnlockWindow();
  4946. try
  4947. {
  4948. ExecuteFileOperation(
  4949. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4950. }
  4951. __finally
  4952. {
  4953. LockWindow();
  4954. }
  4955. AllowExec = false;
  4956. }
  4957. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4958. {
  4959. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4960. {
  4961. ExecuteFile(Side, efDefaultEditor);
  4962. AllowExec = false;
  4963. }
  4964. }
  4965. else
  4966. {
  4967. DebugFail();
  4968. }
  4969. }
  4970. // if we have not done anything special, fall back to default behavior
  4971. if (AllowExec)
  4972. {
  4973. if (Remote && !WinConfiguration->DisableOpenEdit)
  4974. {
  4975. ExecuteFile(osRemote, efShell);
  4976. AllowExec = false;
  4977. }
  4978. }
  4979. }
  4980. }
  4981. //---------------------------------------------------------------------------
  4982. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4983. {
  4984. return ((Side == osRemote) || (Side == osCurrent));
  4985. }
  4986. //---------------------------------------------------------------------------
  4987. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  4988. {
  4989. DebugFail();
  4990. }
  4991. //---------------------------------------------------------------------------
  4992. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  4993. {
  4994. DebugFail();
  4995. }
  4996. //---------------------------------------------------------------------------
  4997. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  4998. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  4999. {
  5000. TSynchronizeParamType Params;
  5001. Params.LocalDirectory = LocalDirectory;
  5002. Params.RemoteDirectory = RemoteDirectory;
  5003. int UnusedParams =
  5004. (GUIConfiguration->SynchronizeParams &
  5005. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5006. TTerminal::spCaseSensitive));
  5007. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5008. Params.Options = GUIConfiguration->SynchronizeOptions;
  5009. bool SaveSettings = false;
  5010. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5011. &DoSynchronizeTooManyDirectories);
  5012. DebugAssert(FSynchronizeController == NULL);
  5013. FSynchronizeController = &Controller;
  5014. bool Result;
  5015. try
  5016. {
  5017. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5018. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5019. int Options =
  5020. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5021. DebugAssert(FOnFeedSynchronizeError == NULL);
  5022. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5023. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5024. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5025. if (Result)
  5026. {
  5027. if (SaveSettings)
  5028. {
  5029. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5030. GUIConfiguration->SynchronizeOptions = Params.Options;
  5031. }
  5032. else
  5033. {
  5034. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5035. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5036. FLAGSET(Params.Options, soSynchronize))
  5037. {
  5038. GUIConfiguration->SynchronizeOptions =
  5039. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5040. soSynchronize;
  5041. }
  5042. }
  5043. LocalDirectory = Params.LocalDirectory;
  5044. RemoteDirectory = Params.RemoteDirectory;
  5045. }
  5046. }
  5047. __finally
  5048. {
  5049. FSynchronizeController = NULL;
  5050. DebugAssert(FOnFeedSynchronizeError == NULL);
  5051. FOnFeedSynchronizeError = NULL;
  5052. }
  5053. return Result;
  5054. }
  5055. //---------------------------------------------------------------------------
  5056. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5057. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5058. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5059. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5060. TSynchronizeOptions * Options, bool Full)
  5061. {
  5062. // Keep-up-to-date mode
  5063. if (Terminal->Status == ssOpened)
  5064. {
  5065. try
  5066. {
  5067. int PParams = Params.Params;
  5068. if (!Full)
  5069. {
  5070. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5071. if (FLAGSET(Params.Options, soRecurse))
  5072. {
  5073. PParams |= TTerminal::spSubDirs;
  5074. }
  5075. }
  5076. else
  5077. {
  5078. // if keepuptodate is non-recursive,
  5079. // full sync before has to be non-recursive as well
  5080. if (FLAGCLEAR(Params.Options, soRecurse))
  5081. {
  5082. PParams |= TTerminal::spNoRecurse;
  5083. }
  5084. }
  5085. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5086. PParams, Checklist, Options);
  5087. }
  5088. catch (Exception & E)
  5089. {
  5090. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5091. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5092. {
  5093. // noop, already logged in MoreMessageDialog
  5094. }
  5095. else
  5096. {
  5097. ShowExtendedExceptionEx(Terminal, &E);
  5098. throw;
  5099. }
  5100. }
  5101. }
  5102. }
  5103. //---------------------------------------------------------------------------
  5104. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5105. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5106. const UnicodeString ErrorStr)
  5107. {
  5108. if (!Directory.IsEmpty())
  5109. {
  5110. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5111. }
  5112. else
  5113. {
  5114. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5115. }
  5116. }
  5117. //---------------------------------------------------------------------------
  5118. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5119. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5120. {
  5121. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5122. {
  5123. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5124. }
  5125. else
  5126. {
  5127. TMessageParams Params(mpNeverAskAgainCheck);
  5128. unsigned int Result = MessageDialog(
  5129. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5130. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5131. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5132. {
  5133. MaxDirectories *= 2;
  5134. if (Result == qaNeverAskAgain)
  5135. {
  5136. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5137. }
  5138. }
  5139. else
  5140. {
  5141. Abort();
  5142. }
  5143. }
  5144. }
  5145. //---------------------------------------------------------------------------
  5146. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5147. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5148. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5149. TSynchronizeOptions * Options)
  5150. {
  5151. // Keep-up-to-date mode
  5152. DebugAssert(!FAutoOperation);
  5153. void * BatchStorage;
  5154. BatchStart(BatchStorage);
  5155. FAutoOperation = true;
  5156. bool AnyOperation = false;
  5157. TDateTime StartTime = Now();
  5158. TSynchronizeChecklist * AChecklist = NULL;
  5159. try
  5160. {
  5161. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5162. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5163. {
  5164. FSynchronizeProgressForm->Start();
  5165. }
  5166. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5167. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5168. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5169. Options);
  5170. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5171. SAFE_DESTROY(FSynchronizeProgressForm);
  5172. AnyOperation = (AChecklist->CheckedCount > 0);
  5173. if (AnyOperation)
  5174. {
  5175. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5176. CreateProgressForm(&SynchronizeProgress);
  5177. try
  5178. {
  5179. Terminal->SynchronizeApply(
  5180. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5181. SynchronizeProcessedItem, NULL, NULL, NULL);
  5182. }
  5183. __finally
  5184. {
  5185. DestroyProgressForm();
  5186. }
  5187. }
  5188. }
  5189. __finally
  5190. {
  5191. if (Checklist == NULL)
  5192. {
  5193. delete AChecklist;
  5194. }
  5195. else
  5196. {
  5197. *Checklist = AChecklist;
  5198. }
  5199. FAutoOperation = false;
  5200. SAFE_DESTROY(FSynchronizeProgressForm);
  5201. BatchEnd(BatchStorage);
  5202. ReloadLocalDirectory();
  5203. if (AnyOperation)
  5204. {
  5205. OperationComplete(StartTime);
  5206. }
  5207. }
  5208. }
  5209. //---------------------------------------------------------------------------
  5210. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5211. {
  5212. // can be called from command line
  5213. return Visible &&
  5214. ((DirView(osRemote)->SelCount > 0) ||
  5215. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5216. }
  5217. //---------------------------------------------------------------------------
  5218. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5219. {
  5220. LogSynchronizeEvent(Terminal, Message);
  5221. }
  5222. //---------------------------------------------------------------------------
  5223. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5224. int Params, TSynchronizeOptions & Options)
  5225. {
  5226. DebugAssert(!IsLocalBrowserMode());
  5227. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5228. {
  5229. Options.Filter = new TStringList();
  5230. Options.Filter->CaseSensitive = false;
  5231. Options.Filter->Duplicates = Types::dupAccept;
  5232. if (DirView(osRemote)->SelCount > 0)
  5233. {
  5234. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5235. }
  5236. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5237. {
  5238. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5239. }
  5240. Options.Filter->Sort();
  5241. }
  5242. }
  5243. //---------------------------------------------------------------------------
  5244. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5245. {
  5246. TCopyParamType Defaults;
  5247. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5248. ConfigStorage->AccessMode = smRead;
  5249. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5250. {
  5251. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5252. }
  5253. ConfigStorage.reset(NULL);
  5254. std::unique_ptr<TStringList> Options(new TStringList());
  5255. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5256. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5257. UnicodeString Result;
  5258. if (Options->Count > 0)
  5259. {
  5260. Result =
  5261. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5262. }
  5263. return Result;
  5264. }
  5265. //---------------------------------------------------------------------------
  5266. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5267. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5268. {
  5269. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5270. UnicodeString AdditionalParams =
  5271. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5272. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5273. SerializeCopyParamForCommandLine(CopyParams),
  5274. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5275. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5276. ExecuteNewInstance(SessionName, AdditionalParams);
  5277. }
  5278. //---------------------------------------------------------------------------
  5279. struct TSynchronizeParams
  5280. {
  5281. UnicodeString LocalDirectory;
  5282. UnicodeString RemoteDirectory;
  5283. TSynchronizeMode Mode;
  5284. TSynchronizeChecklist * Checklist;
  5285. int Params;
  5286. TCopyParamType * CopyParam;
  5287. TDateTime CollectElapsed;
  5288. TDateTime * StartTime;
  5289. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5290. };
  5291. //---------------------------------------------------------------------------
  5292. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5293. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5294. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5295. {
  5296. DebugAssert(!FAutoOperation);
  5297. void * BatchStorage;
  5298. BatchStart(BatchStorage);
  5299. FAutoOperation = true;
  5300. TFileOperationStatistics Statistics;
  5301. TDateTime Start = Now();
  5302. try
  5303. {
  5304. Params.OnProcessedItem = OnProcessedItem;
  5305. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5306. CreateProgressForm(&SynchronizeProgress);
  5307. Terminal->SynchronizeApply(
  5308. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5309. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5310. &Statistics);
  5311. }
  5312. __finally
  5313. {
  5314. Params.OnProcessedItem = NULL;
  5315. FAutoOperation = false;
  5316. DestroyProgressForm();
  5317. BatchEnd(BatchStorage);
  5318. ReloadLocalDirectory();
  5319. }
  5320. if (WinConfiguration->SynchronizeSummary)
  5321. {
  5322. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5323. // The statistics should be 0 anyway in this case
  5324. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5325. {
  5326. Message += L"\n";
  5327. if (Statistics.FilesUploaded > 0)
  5328. {
  5329. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5330. }
  5331. if (Statistics.FilesDownloaded > 0)
  5332. {
  5333. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5334. }
  5335. if (Statistics.FilesDeletedLocal > 0)
  5336. {
  5337. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5338. }
  5339. if (Statistics.FilesDeletedRemote > 0)
  5340. {
  5341. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5342. }
  5343. }
  5344. TDateTime Elapsed = (Now() - Start);
  5345. Message +=
  5346. L"\n" +
  5347. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5348. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5349. TMessageParams Params(mpNeverAskAgainCheck);
  5350. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5351. if (Result == qaNeverAskAgain)
  5352. {
  5353. WinConfiguration->SynchronizeSummary = false;
  5354. }
  5355. }
  5356. }
  5357. //---------------------------------------------------------------------------
  5358. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5359. {
  5360. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5361. {
  5362. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5363. }
  5364. // Not set in keep-up-to-date mode - Synchronize() method
  5365. if (Token != NULL)
  5366. {
  5367. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5368. if (Params.OnProcessedItem != NULL)
  5369. {
  5370. Params.OnProcessedItem(NULL, ChecklistItem);
  5371. }
  5372. }
  5373. }
  5374. //---------------------------------------------------------------------------
  5375. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5376. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5377. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5378. {
  5379. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5380. *Params.StartTime = Now();
  5381. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5382. }
  5383. //---------------------------------------------------------------------------
  5384. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5385. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5386. {
  5387. // terminal can be already closed (e.g. dropped connection)
  5388. if (Terminal != NULL)
  5389. {
  5390. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5391. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5392. }
  5393. }
  5394. //---------------------------------------------------------------------------
  5395. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5396. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5397. {
  5398. DebugAssert(!IsLocalBrowserMode());
  5399. TAutoBatch AutoBatch(this);
  5400. TAutoFlag AutoOperationFlag(FAutoOperation);
  5401. if (Side == osRemote)
  5402. {
  5403. std::unique_ptr<TStrings> FileList(new TStringList());
  5404. FileList->AddObject(FileName, RemoteFile);
  5405. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5406. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5407. RemoteDirView->SaveSelection();
  5408. RemoteDirView->SaveSelectedNames();
  5409. try
  5410. {
  5411. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5412. }
  5413. catch(...)
  5414. {
  5415. RemoteDirView->DiscardSavedSelection();
  5416. throw;
  5417. }
  5418. RemoteDirView->RestoreSelection();
  5419. }
  5420. else if (DebugAlwaysTrue(Side == osLocal))
  5421. {
  5422. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5423. {
  5424. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5425. }
  5426. UnicodeString Directory = ExtractFileDir(FileName);
  5427. ReloadLocalDirectory(Directory);
  5428. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5429. if (!SamePaths(Directory, NewDirectory))
  5430. {
  5431. ReloadLocalDirectory(NewDirectory);
  5432. }
  5433. }
  5434. }
  5435. //---------------------------------------------------------------------------
  5436. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5437. {
  5438. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5439. if (Side == osLocal)
  5440. {
  5441. if (Action == TSynchronizeChecklist::saDownloadNew)
  5442. {
  5443. OpenFolderInExplorer(LocalPath);
  5444. }
  5445. else
  5446. {
  5447. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5448. }
  5449. }
  5450. else if (DebugAlwaysTrue(Side == osRemote))
  5451. {
  5452. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5453. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5454. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5455. if (!LocalPath.IsEmpty())
  5456. {
  5457. SessionData->LocalDirectory = LocalPath;
  5458. }
  5459. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5460. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5461. }
  5462. }
  5463. //---------------------------------------------------------------------------
  5464. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5465. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5466. const TCopyParamType * CopyParams)
  5467. {
  5468. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5469. UnicodeString AdditionalParams =
  5470. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5471. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5472. SerializeCopyParamForCommandLine(CopyParams),
  5473. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5474. LocalDirectory, RemoteDirectory, Mode, Params));
  5475. ExecuteNewInstance(SessionName, AdditionalParams);
  5476. }
  5477. //---------------------------------------------------------------------------
  5478. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5479. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5480. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5481. {
  5482. int Result;
  5483. bool SaveSettings = false;
  5484. int Options =
  5485. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5486. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5487. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5488. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5489. bool Continue =
  5490. (UseDefaults == 0) ||
  5491. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5492. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5493. if (Continue)
  5494. {
  5495. Configuration->Usage->Inc(L"Synchronizations");
  5496. UpdateCopyParamCounters(CopyParam);
  5497. TSynchronizeOptions SynchronizeOptions;
  5498. GetSynchronizeOptions(Params, SynchronizeOptions);
  5499. if (SaveSettings)
  5500. {
  5501. GUIConfiguration->SynchronizeParams = Params;
  5502. }
  5503. else
  5504. {
  5505. SaveMode = false;
  5506. }
  5507. TDateTime StartTime = Now();
  5508. TSynchronizeChecklist * Checklist = NULL;
  5509. try
  5510. {
  5511. DebugAssert(!FAutoOperation);
  5512. FAutoOperation = true;
  5513. try
  5514. {
  5515. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5516. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5517. int Files = -1;
  5518. if (DataList->Count >= 1)
  5519. {
  5520. Files = StrToIntDef(DataList->Strings[0], Files);
  5521. }
  5522. else
  5523. {
  5524. DataList->Add(UnicodeString());
  5525. }
  5526. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5527. FSynchronizeProgressForm->Start();
  5528. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5529. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5530. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5531. &SynchronizeOptions);
  5532. if (Terminal->SessionData->CacheDirectories)
  5533. {
  5534. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5535. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5536. }
  5537. }
  5538. __finally
  5539. {
  5540. FAutoOperation = false;
  5541. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5542. SAFE_DESTROY(FSynchronizeProgressForm);
  5543. }
  5544. TSynchronizeParams SynchronizeParams;
  5545. SynchronizeParams.LocalDirectory = LocalDirectory;
  5546. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5547. SynchronizeParams.Mode = Mode;
  5548. SynchronizeParams.CopyParam = &CopyParam;
  5549. SynchronizeParams.Params = Params;
  5550. SynchronizeParams.Checklist = Checklist;
  5551. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5552. SynchronizeParams.StartTime = &StartTime;
  5553. SynchronizeParams.OnProcessedItem = NULL;
  5554. Result = Checklist->Count;
  5555. if (Checklist->Count > 0)
  5556. {
  5557. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5558. {
  5559. if (!DoSynchronizeChecklistDialog(
  5560. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5561. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5562. {
  5563. Result = -1;
  5564. }
  5565. }
  5566. else
  5567. {
  5568. FullSynchronize(SynchronizeParams, NULL, NULL);
  5569. }
  5570. }
  5571. else
  5572. {
  5573. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5574. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5575. }
  5576. }
  5577. __finally
  5578. {
  5579. delete Checklist;
  5580. }
  5581. OperationComplete(StartTime);
  5582. }
  5583. else
  5584. {
  5585. Result = -1;
  5586. }
  5587. return Result;
  5588. }
  5589. //---------------------------------------------------------------------------
  5590. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5591. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5592. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5593. {
  5594. if (Collect)
  5595. {
  5596. DebugAssert(FSynchronizeProgressForm != NULL);
  5597. if (!FSynchronizeProgressForm->Started)
  5598. {
  5599. FSynchronizeProgressForm->Start();
  5600. }
  5601. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5602. SetTaskbarListProgressValue(CompareProgress);
  5603. }
  5604. else
  5605. {
  5606. DebugAssert(FSynchronizeProgressForm == NULL);
  5607. DebugAssert(FProgressForm != NULL);
  5608. }
  5609. }
  5610. //---------------------------------------------------------------------------
  5611. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5612. {
  5613. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5614. TRemoteFile * File = NULL;
  5615. Terminal->ReadFile(FullFileName, File);
  5616. if (File != NULL)
  5617. {
  5618. std::unique_ptr<TRemoteFile> FileOwner(File);
  5619. TAutoFlag Flag(FStandaloneEditing);
  5620. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5621. Application->ShowMainForm = false;
  5622. Application->Run();
  5623. }
  5624. }
  5625. //---------------------------------------------------------------------------
  5626. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5627. {
  5628. DebugFail();
  5629. }
  5630. //---------------------------------------------------------------------------
  5631. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5632. {
  5633. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5634. SessionData->Assign(Terminal->SessionData);
  5635. UpdateSessionData(SessionData.get());
  5636. Terminal->UpdateSessionCredentials(SessionData.get());
  5637. if (!Terminal->SessionData->HasSessionName())
  5638. {
  5639. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5640. // once IsWorkspace is cleared
  5641. SessionData->Name = UnicodeString();
  5642. SessionData->IsWorkspace = false;
  5643. }
  5644. return SessionData.release();
  5645. }
  5646. //---------------------------------------------------------------------------
  5647. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5648. {
  5649. TSessionData * SessionData = CloneCurrentSessionData();
  5650. try
  5651. {
  5652. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5653. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5654. }
  5655. __finally
  5656. {
  5657. delete SessionData;
  5658. }
  5659. }
  5660. //---------------------------------------------------------------------------
  5661. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5662. {
  5663. TTerminalManager * Manager = TTerminalManager::Instance();
  5664. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5665. if (DebugAlwaysTrue(Terminal != NULL))
  5666. {
  5667. // Update (Managed)Terminal->StateData
  5668. UpdateTerminal(Terminal);
  5669. }
  5670. Manager->SaveWorkspace(DataList.get());
  5671. return DataList.release();
  5672. }
  5673. //---------------------------------------------------------------------------
  5674. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5675. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5676. {
  5677. WinConfiguration->LastWorkspace = Name;
  5678. if (!SavePasswords)
  5679. {
  5680. for (int Index = 0; Index < DataList->Count; Index++)
  5681. {
  5682. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5683. if (SessionData->Link.IsEmpty())
  5684. {
  5685. SessionData->ClearSessionPasswords();
  5686. }
  5687. }
  5688. }
  5689. StoredSessions->NewWorkspace(Name, DataList);
  5690. // modified only
  5691. StoredSessions->Save(false, Explicit);
  5692. }
  5693. //---------------------------------------------------------------------------
  5694. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5695. {
  5696. return
  5697. DefaultStr(WinConfiguration->LastWorkspace,
  5698. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5699. }
  5700. //---------------------------------------------------------------------------
  5701. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5702. {
  5703. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5704. bool AnyNonStoredSessionWithPassword = false;
  5705. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5706. bool AllNonStoredSessionsAnonymous = true;
  5707. TTerminalManager * Manager = TTerminalManager::Instance();
  5708. for (int Index = 0; Index < DataList->Count; Index++)
  5709. {
  5710. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5711. if (SessionData->Link.IsEmpty())
  5712. {
  5713. if (SessionData->HasAnySessionPassword())
  5714. {
  5715. AnyNonStoredSessionWithPassword = true;
  5716. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5717. {
  5718. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5719. }
  5720. }
  5721. if (!SameText(SessionData->UserName, AnonymousUserName))
  5722. {
  5723. AllNonStoredSessionsAnonymous = false;
  5724. }
  5725. }
  5726. }
  5727. bool SavePasswords;
  5728. bool * PSavePasswords;
  5729. bool NotRecommendedSavingPasswords =
  5730. !CustomWinConfiguration->UseMasterPassword &&
  5731. !AllNonStoredSessionsAnonymous;
  5732. if (Configuration->DisablePasswordStoring ||
  5733. !AnyNonStoredSessionWithPassword)
  5734. {
  5735. PSavePasswords = NULL;
  5736. SavePasswords = false;
  5737. }
  5738. else
  5739. {
  5740. PSavePasswords = &SavePasswords;
  5741. SavePasswords =
  5742. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5743. !NotRecommendedSavingPasswords;
  5744. }
  5745. UnicodeString Name = WorkspaceName();
  5746. bool CreateShortcut = false;
  5747. bool Result =
  5748. DoSaveWorkspaceDialog(
  5749. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5750. EnableAutoSave);
  5751. if (Result)
  5752. {
  5753. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5754. if (CreateShortcut)
  5755. {
  5756. TOperationVisualizer Visualizer;
  5757. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5758. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5759. }
  5760. if (EnableAutoSave)
  5761. {
  5762. WinConfiguration->AutoSaveWorkspace = true;
  5763. WinConfiguration->AutoWorkspace = Name;
  5764. if (PSavePasswords != NULL)
  5765. {
  5766. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5767. }
  5768. }
  5769. }
  5770. return Result;
  5771. }
  5772. //---------------------------------------------------------------------------
  5773. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5774. {
  5775. DebugAssert(!IsLocalBrowserMode());
  5776. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5777. if (WinConfiguration->PreservePanelState)
  5778. {
  5779. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5780. }
  5781. UpdateSessionData(Terminal->StateData);
  5782. }
  5783. //---------------------------------------------------------------------------
  5784. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5785. {
  5786. // Keep in sync with TSessionData::CopyStateData
  5787. DebugAssert(!IsLocalBrowserMode());
  5788. DebugAssert(Data != NULL);
  5789. // This is inconsistent with how color (for example) is handled.
  5790. Data->Name = Terminal->SessionData->Name;
  5791. // cannot use RemoteDirView->Path, because it is empty if connection
  5792. // was already closed
  5793. // also only peek, we may not be connected at all atm
  5794. // so make sure we do not try retrieving current directory from the server
  5795. // (particularly with FTP)
  5796. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5797. if (!ACurrentDirectory.IsEmpty())
  5798. {
  5799. Data->RemoteDirectory = ACurrentDirectory;
  5800. }
  5801. Data->Color = SessionColor;
  5802. }
  5803. //---------------------------------------------------------------------------
  5804. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5805. {
  5806. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5807. DebugAssert(Toolbar != NULL);
  5808. for (int i = 0; i < Toolbar->Items->Count; i++)
  5809. {
  5810. TTBXCustomDropDownItem * DropDownItem;
  5811. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5812. if (DropDownItem != NULL)
  5813. {
  5814. ToolbarItemResize(DropDownItem,
  5815. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5816. Toolbar->NonClientWidth);
  5817. break;
  5818. }
  5819. }
  5820. }
  5821. //---------------------------------------------------------------------------
  5822. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5823. {
  5824. Item->EditWidth = Width;
  5825. }
  5826. //---------------------------------------------------------------------------
  5827. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5828. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5829. {
  5830. for (int i = 0; i < Toolbar->Items->Count; i++)
  5831. {
  5832. TTBXCustomDropDownItem * DropDownItem;
  5833. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5834. if (DropDownItem != NULL)
  5835. {
  5836. ASize.x -= DropDownItem->EditWidth;
  5837. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5838. }
  5839. }
  5840. }
  5841. //---------------------------------------------------------------------------
  5842. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5843. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5844. {
  5845. if (WinConfiguration->DDWarnLackOfTempSpace)
  5846. {
  5847. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5848. if (!ADrive.IsEmpty())
  5849. {
  5850. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5851. DebugAssert(RequiredSpace >= 0);
  5852. __int64 RequiredWithReserve;
  5853. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5854. if (FreeSpace < RequiredWithReserve)
  5855. {
  5856. unsigned int Result;
  5857. TMessageParams Params(mpNeverAskAgainCheck);
  5858. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5859. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5860. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5861. if (Result == qaNeverAskAgain)
  5862. {
  5863. WinConfiguration->DDWarnLackOfTempSpace = false;
  5864. }
  5865. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5866. }
  5867. }
  5868. }
  5869. }
  5870. //---------------------------------------------------------------------------
  5871. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5872. {
  5873. DoOpenDirectoryDialog(odAddBookmark, Side);
  5874. }
  5875. //---------------------------------------------------------------------------
  5876. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5877. {
  5878. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5879. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5880. try
  5881. {
  5882. TCustomDirView * DView = DirView(Side);
  5883. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5884. {
  5885. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5886. }
  5887. }
  5888. catch (...)
  5889. {
  5890. delete VisitedDirectories;
  5891. throw;
  5892. }
  5893. return VisitedDirectories;
  5894. }
  5895. //---------------------------------------------------------------------------
  5896. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5897. TOpenDirectoryMode Mode, TOperationSide Side)
  5898. {
  5899. bool Continue = true;
  5900. if (Mode == odAddBookmark)
  5901. {
  5902. TMessageParams Params(mpNeverAskAgainCheck);
  5903. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5904. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5905. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5906. unsigned int Answer =
  5907. MessageDialog(Message,
  5908. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5909. if (Answer == qaNeverAskAgain)
  5910. {
  5911. Continue = true;
  5912. WinConfiguration->UseSharedBookmarks = true;
  5913. }
  5914. else if (Answer == qaOK)
  5915. {
  5916. Continue = true;
  5917. WinConfiguration->UseSharedBookmarks = false;
  5918. }
  5919. else
  5920. {
  5921. Continue = false;
  5922. }
  5923. }
  5924. if (Continue)
  5925. {
  5926. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5927. try
  5928. {
  5929. UnicodeString Name = DirView(Side)->PathName;
  5930. bool Repeat;
  5931. do
  5932. {
  5933. Repeat = false;
  5934. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5935. // do not allow switching to location profiles,
  5936. // if we are not connected
  5937. HasDirView[osLocal] && (Terminal != NULL)))
  5938. {
  5939. TWindowLock Lock(this);
  5940. if (!TryOpenDirectory(Side, Name))
  5941. {
  5942. Repeat = true;
  5943. Mode = odBrowse;
  5944. }
  5945. }
  5946. }
  5947. while (Repeat);
  5948. }
  5949. __finally
  5950. {
  5951. delete VisitedDirectories;
  5952. }
  5953. }
  5954. }
  5955. //---------------------------------------------------------------------------
  5956. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5957. {
  5958. DebugAssert(!FTerminal->CommandSessionOpened);
  5959. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5960. }
  5961. //---------------------------------------------------------------------------
  5962. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5963. {
  5964. bool Result = FTerminal->IsCapable[Capability] ||
  5965. FTerminal->CommandSessionOpened;
  5966. if (!Result)
  5967. {
  5968. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5969. if (!GUIConfiguration->ConfirmCommandSession)
  5970. {
  5971. Result = true;
  5972. }
  5973. else
  5974. {
  5975. TMessageParams Params(mpNeverAskAgainCheck);
  5976. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5977. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5978. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5979. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5980. if (Answer == qaNeverAskAgain)
  5981. {
  5982. GUIConfiguration->ConfirmCommandSession = false;
  5983. Result = true;
  5984. }
  5985. else if (Answer == qaOK)
  5986. {
  5987. Result = true;
  5988. }
  5989. }
  5990. if (Result)
  5991. {
  5992. Result = CommandSessionFallback();
  5993. }
  5994. }
  5995. return Result;
  5996. }
  5997. //---------------------------------------------------------------------------
  5998. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  5999. {
  6000. if (EnsureCommandSessionFallback(fcAnyCommand))
  6001. {
  6002. DoConsoleDialog(Terminal, Command);
  6003. }
  6004. }
  6005. //---------------------------------------------------------------------------
  6006. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6007. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6008. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6009. {
  6010. if (!IsSideLocalBrowser(osRemote) &&
  6011. IsFileControl(DropSourceControl, osRemote) &&
  6012. (FDDExtMapFile != NULL))
  6013. {
  6014. Accept = true;
  6015. }
  6016. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6017. DebugAssert(FDDTargetControl != NULL);
  6018. }
  6019. //---------------------------------------------------------------------------
  6020. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6021. _di_IDataObject DataObj, int KeyState,
  6022. const TPoint & Point, int & Effect, bool & Accept)
  6023. {
  6024. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6025. }
  6026. //---------------------------------------------------------------------------
  6027. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6028. _di_IDataObject DataObj, int KeyState,
  6029. const TPoint & Point, int & Effect, bool & Accept)
  6030. {
  6031. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6032. }
  6033. //---------------------------------------------------------------------------
  6034. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6035. TObject * Sender)
  6036. {
  6037. DebugUsedParam(Sender);
  6038. DebugAssert(FDDTargetControl == Sender);
  6039. FDDTargetControl = NULL;
  6040. }
  6041. //---------------------------------------------------------------------------
  6042. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6043. {
  6044. FileControlDDDragLeave(SessionsPageControl);
  6045. }
  6046. //---------------------------------------------------------------------------
  6047. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6048. {
  6049. FileControlDDDragLeave(QueueView3);
  6050. }
  6051. //---------------------------------------------------------------------------
  6052. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6053. {
  6054. DebugAssert(!IsSideLocalBrowser(Side));
  6055. DebugUsedParam(Side);
  6056. bool Edit = false;
  6057. TRemoteFile * File = NULL;
  6058. UnicodeString FileName;
  6059. UnicodeString PointTo;
  6060. bool SymbolicLink = true;
  6061. if (RemoteDirView->ItemFocused)
  6062. {
  6063. DebugAssert(RemoteDirView->ItemFocused->Data);
  6064. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6065. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6066. if (Edit)
  6067. {
  6068. FileName = File->FileName;
  6069. PointTo = File->LinkTo;
  6070. }
  6071. else
  6072. {
  6073. PointTo = File->FileName;
  6074. }
  6075. }
  6076. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6077. Terminal->IsCapable[fcHardLink]))
  6078. {
  6079. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6080. if (Edit)
  6081. {
  6082. DebugAssert(File->FileName == FileName);
  6083. int Params = dfNoRecursive;
  6084. Terminal->ExceptionOnFail = true;
  6085. try
  6086. {
  6087. Terminal->DeleteFile(L"", File, &Params);
  6088. }
  6089. __finally
  6090. {
  6091. Terminal->ExceptionOnFail = false;
  6092. }
  6093. }
  6094. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6095. }
  6096. }
  6097. //---------------------------------------------------------------------------
  6098. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6099. {
  6100. return
  6101. (IsSideLocalBrowser(Side) ||
  6102. (HasActiveTerminal() &&
  6103. Terminal->ResolvingSymlinks &&
  6104. Terminal->IsCapable[fcSymbolicLink]));
  6105. }
  6106. //---------------------------------------------------------------------------
  6107. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6108. {
  6109. return
  6110. !IsSideLocalBrowser(FCurrentSide) &&
  6111. (RemoteDirView->ItemFocused != NULL) &&
  6112. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6113. Terminal->SessionData->ResolveSymlinks;
  6114. }
  6115. //---------------------------------------------------------------------------
  6116. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6117. {
  6118. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6119. FForceExecution = true;
  6120. try
  6121. {
  6122. DirView(osCurrent)->ExecuteCurrentFile();
  6123. }
  6124. __finally
  6125. {
  6126. FForceExecution = false;
  6127. }
  6128. }
  6129. //---------------------------------------------------------------------------
  6130. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6131. {
  6132. TEditorData ExternalEditor;
  6133. ExternalEditor.Editor = edExternal;
  6134. bool Remember = false;
  6135. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6136. {
  6137. if (Remember)
  6138. {
  6139. TEditorList * EditorList = new TEditorList;
  6140. try
  6141. {
  6142. *EditorList = *WinConfiguration->EditorList;
  6143. bool Found = false;
  6144. int i = 0;
  6145. while (!Found && (i < EditorList->Count))
  6146. {
  6147. const TEditorPreferences * Editor = EditorList->Editors[i];
  6148. if ((Editor->Data->Editor == edExternal) &&
  6149. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6150. {
  6151. Found = true;
  6152. }
  6153. i++;
  6154. }
  6155. if (!Found)
  6156. {
  6157. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6158. WinConfiguration->EditorList = EditorList;
  6159. }
  6160. }
  6161. __finally
  6162. {
  6163. delete EditorList;
  6164. }
  6165. }
  6166. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6167. }
  6168. }
  6169. //---------------------------------------------------------------------------
  6170. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6171. {
  6172. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6173. if (FFileFindTerminal == ATerminal)
  6174. {
  6175. FFileFindTerminal = NULL;
  6176. HideFileFindDialog();
  6177. }
  6178. if (FClipboardTerminal == ATerminal)
  6179. {
  6180. ClipboardClear(); // implies ClipboardStop
  6181. }
  6182. }
  6183. //---------------------------------------------------------------------------
  6184. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6185. {
  6186. DetachTerminal(Sender);
  6187. }
  6188. //---------------------------------------------------------------------------
  6189. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6190. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6191. {
  6192. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6193. DebugAssert(Terminal != NULL);
  6194. if (Data->Terminal == Terminal)
  6195. {
  6196. Data->Terminal = NULL;
  6197. }
  6198. }
  6199. //---------------------------------------------------------------------------
  6200. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6201. {
  6202. UpdateControls();
  6203. SessionColor = TColor(0);
  6204. UpdateRemotePathComboBox(false);
  6205. NeedSession(false);
  6206. }
  6207. //---------------------------------------------------------------------------
  6208. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6209. {
  6210. try
  6211. {
  6212. // Cache, as the login dialog can change its value
  6213. // See also DoShow. Also see TTerminalManager::NewSession.
  6214. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6215. try
  6216. {
  6217. if (ShowLogin)
  6218. {
  6219. bool ReloadSessions = !Startup;
  6220. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this);
  6221. }
  6222. else if (Startup && WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6223. // This detects if workspace was saved the last time the main widow was closed
  6224. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6225. {
  6226. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6227. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6228. }
  6229. }
  6230. __finally
  6231. {
  6232. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6233. // (so there was no chance for the user to open any session yet)
  6234. if ((ShowLogin || !Startup) &&
  6235. !WinConfiguration->KeepOpenWhenNoSession &&
  6236. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6237. {
  6238. TerminateApplication();
  6239. }
  6240. }
  6241. }
  6242. catch (EAbort &)
  6243. {
  6244. // swallow
  6245. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6246. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6247. }
  6248. }
  6249. //---------------------------------------------------------------------------
  6250. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6251. {
  6252. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6253. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6254. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6255. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6256. try
  6257. {
  6258. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6259. // Clear the design time unthemed tab
  6260. ((SessionsPageControl->PageCount > 0) &&
  6261. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6262. {
  6263. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6264. }
  6265. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6266. {
  6267. TThemeTabSheet * TabSheet;
  6268. if (Index >= SessionsPageControl->PageCount)
  6269. {
  6270. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6271. TabSheet->PageControl = SessionsPageControl;
  6272. }
  6273. else
  6274. {
  6275. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6276. }
  6277. bool IsSessionTab = (Index < TerminalList->Count);
  6278. if (IsSessionTab)
  6279. {
  6280. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6281. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6282. UpdateSessionTab(TabSheet);
  6283. }
  6284. else
  6285. {
  6286. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6287. TabSheet->Tag = 0; // not really needed
  6288. TabSheet->Shadowed = false;
  6289. // 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)
  6290. UpdateNewSessionTab();
  6291. }
  6292. TabSheet->ShowCloseButton = IsSessionTab;
  6293. }
  6294. }
  6295. __finally
  6296. {
  6297. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6298. }
  6299. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6300. }
  6301. //---------------------------------------------------------------------------
  6302. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6303. {
  6304. DoTerminalListChanged();
  6305. }
  6306. //---------------------------------------------------------------------------
  6307. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6308. {
  6309. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6310. DebugAssert(TabSheet->ImageIndex == 0);
  6311. TabSheet->Caption =
  6312. WinConfiguration->SelectiveToolbarText ?
  6313. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6314. UnicodeString();
  6315. }
  6316. //---------------------------------------------------------------------------
  6317. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6318. {
  6319. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6320. }
  6321. //---------------------------------------------------------------------------
  6322. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6323. {
  6324. if (DebugAlwaysTrue(TabSheet != NULL))
  6325. {
  6326. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6327. if (DebugAlwaysTrue(ATerminal != NULL))
  6328. {
  6329. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6330. TabSheet->ImageIndex = AddSessionColor(Color);
  6331. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6332. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6333. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6334. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6335. {
  6336. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6337. }
  6338. }
  6339. }
  6340. }
  6341. //---------------------------------------------------------------------------
  6342. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6343. {
  6344. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6345. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6346. bool Result = (Terminal != NULL);
  6347. if (Result)
  6348. {
  6349. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6350. }
  6351. else
  6352. {
  6353. try
  6354. {
  6355. NewSession();
  6356. }
  6357. __finally
  6358. {
  6359. DoTerminalListChanged();
  6360. }
  6361. FSessionsPageControlNewSessionTime = Now();
  6362. }
  6363. return Result;
  6364. }
  6365. //---------------------------------------------------------------------------
  6366. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6367. {
  6368. SessionTabSwitched();
  6369. }
  6370. //---------------------------------------------------------------------------
  6371. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6372. {
  6373. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6374. DebugAssert(TransferList != NULL);
  6375. UnicodeString Name;
  6376. if (TransferList->ItemIndex <= 0)
  6377. {
  6378. Name = L"";
  6379. }
  6380. else
  6381. {
  6382. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6383. }
  6384. if (FCopyParamAutoSelected.IsEmpty())
  6385. {
  6386. // if previous preset was not autoselected, make new preset the "default"
  6387. FCopyParamDefault = Name;
  6388. }
  6389. GUIConfiguration->CopyParamCurrent = Name;
  6390. }
  6391. //---------------------------------------------------------------------------
  6392. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6393. {
  6394. // sanity check
  6395. bool ExistingPreset =
  6396. (FTransferListHoverIndex >= 0) &&
  6397. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6398. DebugAssert(ExistingPreset);
  6399. if (ExistingPreset)
  6400. {
  6401. HDC DC = GetDC(0);
  6402. TCanvas * Canvas = new TCanvas();
  6403. try
  6404. {
  6405. Canvas->Handle = DC;
  6406. Canvas->Font = GetToolbarFont(this);
  6407. UnicodeString Name;
  6408. if (FTransferListHoverIndex == 0)
  6409. {
  6410. Name = L"";
  6411. }
  6412. else
  6413. {
  6414. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6415. }
  6416. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6417. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6418. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6419. static_cast<TObject*>(GetComponent(fcTransferList)));
  6420. UnicodeString InfoStr =
  6421. GUIConfiguration->CopyParamPreset[Name].
  6422. GetInfoStr(L"; ",
  6423. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6424. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6425. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6426. {
  6427. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6428. {
  6429. InfoStr.SetLength(InfoStr.Length() - 1);
  6430. }
  6431. InfoStr += Ellipsis;
  6432. }
  6433. // UpdateCaption does not cause invalidation of whole submenu, while
  6434. // setting Caption property does.
  6435. // also it probably does not resize the label, even if necessary
  6436. // (we do not want that anyway)
  6437. TransferLabel->UpdateCaption(InfoStr);
  6438. }
  6439. __finally
  6440. {
  6441. Canvas->Handle = NULL;
  6442. ReleaseDC(0, DC);
  6443. delete Canvas;
  6444. }
  6445. }
  6446. }
  6447. //---------------------------------------------------------------------------
  6448. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6449. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6450. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6451. {
  6452. if (FTransferListHoverIndex != AHoverIndex)
  6453. {
  6454. FTransferListHoverIndex = AHoverIndex;
  6455. UpdateTransferLabel();
  6456. }
  6457. }
  6458. //---------------------------------------------------------------------------
  6459. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6460. {
  6461. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6462. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6463. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6464. {
  6465. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6466. {
  6467. if (!NonVisualDataModule->Busy)
  6468. {
  6469. OpenDirectory(GetSide(osCurrent));
  6470. }
  6471. Message.Result = 1;
  6472. }
  6473. else
  6474. {
  6475. TForm::Dispatch(&Message);
  6476. }
  6477. }
  6478. else
  6479. {
  6480. TForm::Dispatch(&Message);
  6481. }
  6482. }
  6483. //---------------------------------------------------------------------------
  6484. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6485. {
  6486. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6487. if ((FIgnoreNextDialogChar != 0) &&
  6488. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6489. {
  6490. Message.Result = 1;
  6491. }
  6492. else
  6493. {
  6494. TForm::Dispatch(&Message);
  6495. }
  6496. FIgnoreNextDialogChar = 0;
  6497. }
  6498. //---------------------------------------------------------------------------
  6499. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6500. {
  6501. // The four low-order bits are used internally by Windows
  6502. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6503. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6504. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6505. // 61730 - restore thru double click - undocumented
  6506. // 61490 - maximize thru double click - undocumented
  6507. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6508. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6509. {
  6510. SysResizing(Cmd);
  6511. }
  6512. TForm::Dispatch(&Message);
  6513. }
  6514. //---------------------------------------------------------------------------
  6515. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6516. {
  6517. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6518. // Also there no point returning TRUE as we are not able to
  6519. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6520. // Hence the process termination might be safer :)
  6521. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6522. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6523. {
  6524. Message.Result = FALSE;
  6525. }
  6526. else
  6527. {
  6528. Message.Result = TRUE;
  6529. }
  6530. // Do not call default handling as that triggers OnCloseQuery,
  6531. // where our implementation will popup confirmation dialogs, what we do not want,
  6532. // as per Vista guidelines:
  6533. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6534. }
  6535. //---------------------------------------------------------------------------
  6536. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6537. {
  6538. if (Message.EndSession && IsApplicationMinimized())
  6539. {
  6540. // WORKAROUND
  6541. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6542. // when it receives WM_ENDSESSION,
  6543. // but that sometimes (particularly when application is minimized) cause crashes.
  6544. // Crash popups message that blocks log off.
  6545. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6546. // so we call ExitProcess() immediately, not even trying to cleanup.
  6547. // It still causes beep, so there's likely some popup, but it does not block
  6548. // log off.
  6549. ExitProcess(0);
  6550. }
  6551. TForm::Dispatch(&Message);
  6552. }
  6553. #ifdef _DEBUG
  6554. //---------------------------------------------------------------------------
  6555. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6556. {
  6557. TForm::Dispatch(&Message);
  6558. }
  6559. #endif
  6560. //---------------------------------------------------------------------------
  6561. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6562. {
  6563. }
  6564. //---------------------------------------------------------------------------
  6565. void __fastcall TCustomScpExplorerForm::DoShow()
  6566. {
  6567. // only now are the controls resized finally, so the size constraints
  6568. // will not conflict with possibly very small window size
  6569. RestoreFormParams();
  6570. // This indicates that the form was rescaled after parameters were loaded and
  6571. // as most probably the parameters were actually saved with the current form scaling
  6572. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6573. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6574. // and no rounding problems will occur.
  6575. // See also RestoreForm.
  6576. // (we should be safe to call RestoreParams unconditionally)
  6577. if (PixelsPerInch != Screen->PixelsPerInch)
  6578. {
  6579. RestoreParams();
  6580. }
  6581. FixControlsPlacement();
  6582. if (Position == poDefaultPosOnly)
  6583. {
  6584. CutFormToDesktop(this);
  6585. }
  6586. TForm::DoShow();
  6587. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6588. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6589. if (Terminal == NULL)
  6590. {
  6591. StartingDisconnected();
  6592. }
  6593. UpdatePixelsPerInchMainWindowCounter();
  6594. FShowing = true;
  6595. }
  6596. //---------------------------------------------------------------------------
  6597. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6598. {
  6599. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6600. }
  6601. //---------------------------------------------------------------------------
  6602. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6603. {
  6604. DoTerminalListChanged();
  6605. }
  6606. //---------------------------------------------------------------------------
  6607. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6608. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6609. TNotifyEvent OnBalloonClick, TObject * UserData)
  6610. {
  6611. bool Do;
  6612. UnicodeString Message;
  6613. if (E == NULL)
  6614. {
  6615. Message = Str;
  6616. Do = true;
  6617. }
  6618. else
  6619. {
  6620. Do = ExceptionMessage(E, Message);
  6621. }
  6622. if (Do && WinConfiguration->BalloonNotifications)
  6623. {
  6624. UnicodeString Title;
  6625. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6626. {
  6627. Message = TrimLeft(Message);
  6628. }
  6629. else
  6630. {
  6631. Message = UnformatMessage(Message);
  6632. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6633. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6634. Title = LoadResourceString(Captions[Type]);
  6635. if (Terminal != NULL)
  6636. {
  6637. Title = FORMAT(L"%s - %s",
  6638. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6639. }
  6640. }
  6641. if (Seconds == 0)
  6642. {
  6643. Seconds = WinConfiguration->NotificationsTimeout;
  6644. }
  6645. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6646. }
  6647. }
  6648. //---------------------------------------------------------------------------
  6649. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6650. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6651. UnicodeString HelpKeyword, const TMessageParams * Params,
  6652. TTerminal * Terminal)
  6653. {
  6654. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6655. (FOnFeedSynchronizeError != NULL)) &&
  6656. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6657. {
  6658. if (FOnFeedSynchronizeError != NULL)
  6659. {
  6660. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6661. }
  6662. else
  6663. {
  6664. DebugAssert(FErrorList != NULL);
  6665. TStringList * MoreMessagesCopy = NULL;
  6666. if (MoreMessages)
  6667. {
  6668. MoreMessagesCopy = new TStringList();
  6669. MoreMessagesCopy->Assign(MoreMessages);
  6670. }
  6671. FErrorList->AddObject(Message, MoreMessagesCopy);
  6672. }
  6673. PopupTrayBalloon(Terminal, Message, Type);
  6674. return ContinueAnswer(Answers);
  6675. }
  6676. else
  6677. {
  6678. bool UseBalloon = FTrayIcon->Visible;
  6679. if (UseBalloon)
  6680. {
  6681. PopupTrayBalloon(Terminal, Message, Type);
  6682. }
  6683. unsigned int Result;
  6684. try
  6685. {
  6686. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6687. }
  6688. __finally
  6689. {
  6690. // cancel only balloon we popped up, otherwise we may cancel notification
  6691. // balloon that was there before the message dialog
  6692. // (such as "dd confirmation opt in balloon)
  6693. if (UseBalloon)
  6694. {
  6695. FTrayIcon->CancelBalloon();
  6696. }
  6697. }
  6698. return Result;
  6699. }
  6700. }
  6701. //---------------------------------------------------------------------------
  6702. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6703. TTerminal * Terminal, Exception * E)
  6704. {
  6705. if (FTrayIcon->Visible)
  6706. {
  6707. PopupTrayBalloon(Terminal, L"", qtError, E);
  6708. }
  6709. // particularly prevent opening new session from jump list,
  6710. // while exception is shown
  6711. NonVisualDataModule->StartBusy();
  6712. try
  6713. {
  6714. ShowExtendedExceptionEx(Terminal, E);
  6715. }
  6716. __finally
  6717. {
  6718. NonVisualDataModule->EndBusy();
  6719. FTrayIcon->CancelBalloon();
  6720. }
  6721. }
  6722. //---------------------------------------------------------------------------
  6723. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6724. {
  6725. if (Terminal->Active)
  6726. {
  6727. InitStatusBar();
  6728. }
  6729. // cannot rely on active page being page for active terminal,
  6730. // as it can happen that active page is the "new session" page
  6731. // (e.g. when reconnecting active terminal, while login dialog
  6732. // invoked from "new session" page is modal)
  6733. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6734. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6735. }
  6736. //---------------------------------------------------------------------------
  6737. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6738. TTerminal * Terminal, Exception * E)
  6739. {
  6740. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6741. if (!Terminal->Active)
  6742. {
  6743. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6744. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6745. {
  6746. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6747. }
  6748. }
  6749. }
  6750. //---------------------------------------------------------------------------
  6751. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6752. UnicodeString Message, TQueryType Type,
  6753. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6754. {
  6755. if ((E == NULL) ||
  6756. ExceptionMessage(E, Message))
  6757. {
  6758. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6759. if (Important)
  6760. {
  6761. Seconds *= 5;
  6762. }
  6763. UnicodeString NoteMessage(UnformatMessage(Message));
  6764. if (Terminal != NULL)
  6765. {
  6766. NoteMessage = FORMAT(L"%s: %s",
  6767. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6768. }
  6769. if (WinConfiguration->BalloonNotifications)
  6770. {
  6771. AddNote(NoteMessage);
  6772. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6773. }
  6774. else
  6775. {
  6776. FlashOnBackground();
  6777. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6778. }
  6779. }
  6780. }
  6781. //---------------------------------------------------------------------------
  6782. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6783. {
  6784. RestoreApp();
  6785. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6786. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6787. !NonVisualDataModule->Busy)
  6788. {
  6789. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6790. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6791. if (!ComponentVisible[fcQueueView])
  6792. {
  6793. ToggleQueueVisibility();
  6794. GoToQueue();
  6795. }
  6796. }
  6797. }
  6798. //---------------------------------------------------------------------------
  6799. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6800. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6801. {
  6802. UnicodeString Message;
  6803. TNotifyEvent OnClick = NULL;
  6804. TObject * UserData = NULL;
  6805. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6806. switch (Event)
  6807. {
  6808. case qeEmptyButMonitored:
  6809. if ((ATerminal != Terminal) || QueueInvisible)
  6810. {
  6811. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6812. OnClick = QueueEmptyNoteClicked;
  6813. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6814. TerminalNoteData->Terminal = ATerminal;
  6815. UserData = TerminalNoteData;
  6816. }
  6817. break;
  6818. case qeEmpty:
  6819. OperationComplete(ATerminal->QueueOperationStart);
  6820. break;
  6821. case qePendingUserAction:
  6822. if ((ATerminal != Terminal) ||
  6823. (QueueInvisible && !IsQueueAutoPopup()))
  6824. {
  6825. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6826. }
  6827. break;
  6828. default:
  6829. DebugFail();
  6830. }
  6831. if (!Message.IsEmpty())
  6832. {
  6833. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6834. }
  6835. }
  6836. //---------------------------------------------------------------------------
  6837. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6838. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6839. {
  6840. if (FDDExtMapFile != NULL)
  6841. {
  6842. CloseHandle(FDDExtMapFile);
  6843. FDDExtMapFile = NULL;
  6844. }
  6845. if (WinConfiguration->DDFakeFile)
  6846. {
  6847. DDFakeFileInitDrag(FileList, Created);
  6848. }
  6849. }
  6850. //---------------------------------------------------------------------------
  6851. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6852. {
  6853. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6854. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6855. {
  6856. FFakeFileDropTarget = FileName;
  6857. }
  6858. }
  6859. //---------------------------------------------------------------------------
  6860. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6861. {
  6862. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6863. if (!ForceDirectories(ApiPath(Result)))
  6864. {
  6865. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6866. }
  6867. FileSetAttr(ApiPath(Result), faHidden);
  6868. return Result;
  6869. }
  6870. //---------------------------------------------------------------------------
  6871. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6872. bool & Created)
  6873. {
  6874. FFakeFileDropTarget = UnicodeString();
  6875. FDragFakeDirectory = CreateFakeTransferDirectory();
  6876. FileList->AddItem(NULL, FDragFakeDirectory);
  6877. Created = true;
  6878. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6879. {
  6880. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6881. }
  6882. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6883. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6884. {
  6885. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6886. TDragExtCommStruct* CommStruct;
  6887. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6888. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6889. DebugAssert(CommStruct != NULL);
  6890. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6891. CommStruct->Dragging = true;
  6892. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6893. LENOF(CommStruct->DropDest));
  6894. NULL_TERMINATE(CommStruct->DropDest);
  6895. UnmapViewOfFile(CommStruct);
  6896. }
  6897. }
  6898. //---------------------------------------------------------------------------
  6899. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6900. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6901. {
  6902. bool Result;
  6903. DebugAssert(!IsLocalBrowserMode());
  6904. if (Sender == RemoteDirView)
  6905. {
  6906. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6907. }
  6908. else
  6909. {
  6910. DebugAssert(Sender == RemoteDriveView);
  6911. TStrings * FileList = RemoteDriveView->DragFileList();
  6912. try
  6913. {
  6914. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6915. }
  6916. __finally
  6917. {
  6918. delete FileList;
  6919. }
  6920. }
  6921. if (FDDTargetControl == RemoteDriveView)
  6922. {
  6923. RemoteDriveView->UpdateDropTarget();
  6924. }
  6925. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6926. // or from tree view to dir view.
  6927. // foMove happens when file/dir is dragged from remote tree view outside of
  6928. // application via dragex
  6929. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6930. (DropSourceControl == RemoteDriveView))
  6931. {
  6932. RemoteDriveView->UpdateDropSource();
  6933. }
  6934. return Result;
  6935. }
  6936. //---------------------------------------------------------------------------
  6937. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6938. {
  6939. DebugAssert(!IsLocalBrowserMode());
  6940. // This also handles drops of remote files to queue.
  6941. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6942. SAFE_DESTROY(FDDFileList);
  6943. if (!FFakeFileDropTarget.IsEmpty())
  6944. {
  6945. RemoveDir(ApiPath(FFakeFileDropTarget));
  6946. }
  6947. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6948. {
  6949. try
  6950. {
  6951. TDragResult DDResult = (Sender == RemoteDirView) ?
  6952. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6953. // Focus is moved to the target application,
  6954. // but as we are going to present the UI, we need to steal the focus back.
  6955. // This most likely won't work though (windows does not allow application
  6956. // to steal focus most of the time)
  6957. Application->BringToFront();
  6958. // On older version of Windows we never got drMove here, see also comment below.
  6959. // On Windows 10, we get the "move".
  6960. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6961. {
  6962. UnicodeString TargetDirectory;
  6963. TFileOperation Operation;
  6964. // drInvalid may mean drMove, see comment below
  6965. switch (DDResult)
  6966. {
  6967. case drCopy:
  6968. Operation = foCopy;
  6969. break;
  6970. case drMove:
  6971. Operation = foMove;
  6972. break;
  6973. default:
  6974. DebugFail();
  6975. case drInvalid:
  6976. // prefer "copy" for safety
  6977. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6978. break;
  6979. }
  6980. TTransferOperationParam Param;
  6981. UnicodeString CounterName;
  6982. bool ForceQueue;
  6983. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  6984. {
  6985. // we get drInvalid both if d&d was intercepted by ddext,
  6986. // and when users drops on no-drop location.
  6987. // we tell the difference by existence of response from ddext,
  6988. // so we ignore absence of response in this case
  6989. if (DDResult != drInvalid)
  6990. {
  6991. // here we know that the extension is installed,
  6992. // as it is checked as soon as drag&drop starts from
  6993. // RemoteFileControlDDCreateDragFileList
  6994. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  6995. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  6996. {
  6997. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  6998. }
  6999. else
  7000. {
  7001. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7002. }
  7003. }
  7004. }
  7005. else
  7006. {
  7007. // download using fake file
  7008. Param.Temp = false;
  7009. Param.DragDrop = true;
  7010. if (ForceQueue)
  7011. {
  7012. Param.Queue = asOn;
  7013. }
  7014. if (Sender == RemoteDirView)
  7015. {
  7016. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7017. }
  7018. if (RemoteFileControlFileOperation(Sender, Operation,
  7019. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7020. {
  7021. Configuration->Usage->Inc(CounterName);
  7022. }
  7023. }
  7024. }
  7025. }
  7026. __finally
  7027. {
  7028. CloseHandle(FDDExtMapFile);
  7029. FDDExtMapFile = NULL;
  7030. delete FDragFakeMonitors;
  7031. FDragFakeMonitors = NULL;
  7032. RemoveDir(ApiPath(FDragFakeDirectory));
  7033. FDragFakeDirectory = L"";
  7034. FFakeFileDropTarget = UnicodeString();
  7035. }
  7036. }
  7037. if (FDragDropSshTerminate.get() != NULL)
  7038. {
  7039. FDragDropSshTerminate->Rethrow();
  7040. }
  7041. }
  7042. //---------------------------------------------------------------------------
  7043. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7044. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7045. {
  7046. // Remember drop effect so we know (when user drops files), if we copy or move
  7047. FLastDropEffect = dwEffect;
  7048. }
  7049. //---------------------------------------------------------------------------
  7050. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7051. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7052. {
  7053. bool Result;
  7054. if (FDDTargetControl == QueueView3)
  7055. {
  7056. Directory = DefaultDownloadTargetDirectory();
  7057. Result = true;
  7058. CounterName = L"DownloadsDragDropQueue";
  7059. ForceQueue = true;
  7060. }
  7061. else if (!FFakeFileDropTarget.IsEmpty())
  7062. {
  7063. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7064. Result = true;
  7065. ForceQueue = false;
  7066. CounterName = L"DownloadsDragDropFakeFile";
  7067. }
  7068. else
  7069. {
  7070. ForceQueue = false;
  7071. Enabled = false;
  7072. try
  7073. {
  7074. int Timer = 0;
  7075. Result = false;
  7076. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7077. {
  7078. {
  7079. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7080. TDragExtCommStruct* CommStruct;
  7081. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7082. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7083. DebugAssert(CommStruct != NULL);
  7084. Result = !CommStruct->Dragging;
  7085. if (Result)
  7086. {
  7087. Directory = ExtractFilePath(CommStruct->DropDest);
  7088. CounterName = L"DownloadsDragDropExternalExt";
  7089. }
  7090. UnmapViewOfFile(CommStruct);
  7091. }
  7092. if (!Result)
  7093. {
  7094. Sleep(50);
  7095. Timer += 50;
  7096. Application->ProcessMessages();
  7097. }
  7098. }
  7099. }
  7100. __finally
  7101. {
  7102. Enabled = true;
  7103. }
  7104. }
  7105. return Result;
  7106. }
  7107. //---------------------------------------------------------------------------
  7108. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7109. const UnicodeString TempDir, int SecDelay)
  7110. {
  7111. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7112. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7113. if (FDelayedDeletionTimer == NULL)
  7114. {
  7115. DebugAssert(HandleAllocated());
  7116. FDelayedDeletionTimer = new TTimer(this);
  7117. FDelayedDeletionTimer->Interval = 10000;
  7118. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7119. }
  7120. else
  7121. {
  7122. FDelayedDeletionTimer->Enabled = true;
  7123. }
  7124. }
  7125. //---------------------------------------------------------------------------
  7126. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7127. {
  7128. DebugAssert(FDelayedDeletionList != NULL);
  7129. TDateTime N = Now();
  7130. TDateTime Alert;
  7131. UnicodeString Directory;
  7132. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7133. {
  7134. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7135. if ((N >= Alert) || (Sender == NULL))
  7136. {
  7137. Directory = FDelayedDeletionList->Strings[Index];
  7138. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7139. {
  7140. FDelayedDeletionList->Delete(Index);
  7141. }
  7142. }
  7143. }
  7144. if (FDelayedDeletionList->Count == 0)
  7145. {
  7146. FDelayedDeletionTimer->Enabled = false;
  7147. }
  7148. }
  7149. //---------------------------------------------------------------------------
  7150. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7151. {
  7152. DebugAssert(!IsLocalBrowserMode());
  7153. if (IsFileControl(FDDTargetControl, osRemote) ||
  7154. (FDDTargetControl == SessionsPageControl))
  7155. {
  7156. TTerminal * TargetTerminal = NULL;
  7157. TFileOperation Operation = foNone;
  7158. if (FDDTargetControl == SessionsPageControl)
  7159. {
  7160. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7161. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7162. // do not allow dropping on the "+" tab
  7163. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7164. if (TargetTerminal != NULL)
  7165. {
  7166. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7167. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7168. {
  7169. Operation = foRemoteMove;
  7170. }
  7171. else
  7172. {
  7173. Operation = foRemoteCopy;
  7174. }
  7175. }
  7176. }
  7177. else
  7178. {
  7179. if (FLastDropEffect == DROPEFFECT_MOVE)
  7180. {
  7181. Operation = foRemoteMove;
  7182. }
  7183. else if (FLastDropEffect == DROPEFFECT_COPY)
  7184. {
  7185. Operation = foRemoteCopy;
  7186. }
  7187. }
  7188. if (Operation != foNone)
  7189. {
  7190. RemoteFileControlFileOperation(DropSourceControl,
  7191. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7192. }
  7193. // abort drag&drop
  7194. Abort();
  7195. }
  7196. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7197. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7198. (FDDTargetControl != QueueView3))
  7199. {
  7200. DebugAssert(!FDragTempDir.IsEmpty());
  7201. TTransferType Type;
  7202. UnicodeString TempDir = FDragTempDir;
  7203. // We clear FDragTempDir before calling
  7204. // just in case it fail (raises exception)
  7205. FDragTempDir = L"";
  7206. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7207. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7208. // empty directory parameter means temp directory -> don't display it!
  7209. UnicodeString TargetDir = L"";
  7210. int Options = 0;
  7211. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7212. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7213. {
  7214. Abort();
  7215. }
  7216. // TargetDir is set when dropped on local file control
  7217. // (this was workaround for legacy dirview event handling, now it should be
  7218. // made prettier)
  7219. if (TargetDir.IsEmpty())
  7220. {
  7221. TargetDir = TempDir;
  7222. if (ForceDirectories(ApiPath(TargetDir)))
  7223. {
  7224. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7225. FPendingTempSpaceWarn = true;
  7226. try
  7227. {
  7228. FDragDropOperation = true;
  7229. int Params = cpTemporary |
  7230. (Type == ttMove ? cpDelete : 0);
  7231. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7232. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7233. }
  7234. __finally
  7235. {
  7236. FDragDropOperation = false;
  7237. FPendingTempSpaceWarn = false;
  7238. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7239. }
  7240. }
  7241. else
  7242. {
  7243. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7244. }
  7245. }
  7246. }
  7247. }
  7248. //---------------------------------------------------------------------------
  7249. void __fastcall TCustomScpExplorerForm::DDDownload(
  7250. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7251. {
  7252. DebugAssert(!IsLocalBrowserMode());
  7253. TAutoBatch AutoBatch(this);
  7254. UpdateCopyParamCounters(*CopyParam);
  7255. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7256. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7257. {
  7258. RemoteDriveView->UpdateDropSource();
  7259. }
  7260. }
  7261. //---------------------------------------------------------------------------
  7262. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7263. {
  7264. public:
  7265. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7266. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7267. {
  7268. }
  7269. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7270. {
  7271. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7272. TDataObjectFilesEx::AllowData(FormatEtc);
  7273. }
  7274. };
  7275. //---------------------------------------------------------------------------
  7276. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7277. TObject * Sender, TDataObject *& DataObject)
  7278. {
  7279. if (FDDExtMapFile != NULL)
  7280. {
  7281. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7282. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7283. {
  7284. Abort();
  7285. }
  7286. if (FileList->Count > 0)
  7287. {
  7288. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7289. if (!FilesObject->IsValid(true, true))
  7290. {
  7291. FilesObject->_Release();
  7292. }
  7293. else
  7294. {
  7295. DataObject = FilesObject;
  7296. }
  7297. }
  7298. }
  7299. }
  7300. //---------------------------------------------------------------------------
  7301. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7302. {
  7303. DebugFail();
  7304. }
  7305. //---------------------------------------------------------------------------
  7306. void __fastcall TCustomScpExplorerForm::GoToTree()
  7307. {
  7308. ComponentVisible[fcRemoteTree] = true;
  7309. DriveView(osRemote)->SetFocus();
  7310. }
  7311. //---------------------------------------------------------------------------
  7312. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7313. TPanelExport Export)
  7314. {
  7315. TCustomDirView * DirView = this->DirView(Side);
  7316. std::unique_ptr<TStrings> ExportData(new TStringList());
  7317. switch (Export)
  7318. {
  7319. case pePath:
  7320. ExportData->Add(DirView->PathName);
  7321. break;
  7322. case peFileList:
  7323. case peFullFileList:
  7324. {
  7325. bool FullPath = (Export == peFullFileList);
  7326. DirView->CreateFileList(false, FullPath, ExportData.get());
  7327. for (int Index = 0; Index < ExportData->Count; Index++)
  7328. {
  7329. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7330. {
  7331. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7332. }
  7333. }
  7334. }
  7335. break;
  7336. default:
  7337. DebugFail();
  7338. }
  7339. return ExportData.release();
  7340. }
  7341. //---------------------------------------------------------------------------
  7342. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7343. TPanelExport Export, TPanelExportDestination Destination)
  7344. {
  7345. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7346. PanelExportStore(Side, Export, Destination, ExportData.get());
  7347. }
  7348. //---------------------------------------------------------------------------
  7349. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7350. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7351. TStrings * ExportData)
  7352. {
  7353. if (Destination == pedClipboard)
  7354. {
  7355. TInstantOperationVisualizer Visualizer;
  7356. CopyToClipboard(ExportData);
  7357. }
  7358. else
  7359. {
  7360. DebugFail();
  7361. }
  7362. }
  7363. //---------------------------------------------------------------------------
  7364. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7365. {
  7366. TCustomDirView * DirView = this->DirView(Side);
  7367. UnicodeString Mask = DirView->Mask;
  7368. if (DoFilterMaskDialog(DirView, Mask))
  7369. {
  7370. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7371. Configuration->Usage->Inc(L"Filters");
  7372. }
  7373. }
  7374. //---------------------------------------------------------------------------
  7375. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7376. {
  7377. return FQueueController->DefaultOperation();
  7378. }
  7379. //---------------------------------------------------------------------------
  7380. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7381. TQueueOperation Operation, void ** Param)
  7382. {
  7383. switch (Operation)
  7384. {
  7385. case qoPreferences:
  7386. return true;
  7387. case qoGoTo:
  7388. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7389. case qoOnceEmpty:
  7390. return IsAnythingQueued();
  7391. default:
  7392. return FQueueController->AllowOperation(Operation, Param);
  7393. }
  7394. }
  7395. //---------------------------------------------------------------------------
  7396. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7397. {
  7398. if (DebugAlwaysTrue(QueueView3->Visible))
  7399. {
  7400. QueueView3->SetFocus();
  7401. }
  7402. }
  7403. //---------------------------------------------------------------------------
  7404. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7405. TQueueOperation Operation, void * Param)
  7406. {
  7407. if (Operation == qoGoTo)
  7408. {
  7409. GoToQueue();
  7410. }
  7411. else if (Operation == qoPreferences)
  7412. {
  7413. PreferencesDialog(pmQueue);
  7414. }
  7415. else
  7416. {
  7417. FQueueController->ExecuteOperation(Operation, Param);
  7418. }
  7419. }
  7420. //---------------------------------------------------------------------------
  7421. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7422. {
  7423. return (Queue != NULL) && Queue->Enabled;
  7424. }
  7425. //---------------------------------------------------------------------------
  7426. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7427. {
  7428. DebugAssert(Queue != NULL);
  7429. if (Queue != NULL)
  7430. {
  7431. Queue->Enabled = !Queue->Enabled;
  7432. }
  7433. }
  7434. //---------------------------------------------------------------------------
  7435. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7436. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7437. {
  7438. FQueueActedItem = QueueView3->ItemFocused;
  7439. }
  7440. //---------------------------------------------------------------------------
  7441. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7442. {
  7443. return TopDock->Height + QueueSplitter->Height;
  7444. }
  7445. //---------------------------------------------------------------------------
  7446. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7447. {
  7448. return
  7449. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7450. (QueueDock->Visible ? QueueDock->Height : 0) +
  7451. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7452. }
  7453. //---------------------------------------------------------------------------
  7454. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7455. {
  7456. return ScaleByTextHeight(this, 48);
  7457. }
  7458. //---------------------------------------------------------------------------
  7459. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7460. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7461. {
  7462. // when queue is hidden by double-clicking splitter, stray attempt to
  7463. // resize the panel with strange value arrives, make sure it is ignored
  7464. if (ComponentVisible[fcQueueView])
  7465. {
  7466. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7467. if (NewSize > MaxHeightLimit)
  7468. {
  7469. NewSize = MaxHeightLimit;
  7470. }
  7471. int MinHeightLimit =
  7472. GetStaticQueuePanelComponentsHeight() +
  7473. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7474. GetMinQueueViewHeight();
  7475. if (NewSize < MinHeightLimit)
  7476. {
  7477. NewSize = MinHeightLimit;
  7478. }
  7479. }
  7480. else
  7481. {
  7482. Accept = false;
  7483. }
  7484. }
  7485. //---------------------------------------------------------------------------
  7486. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7487. {
  7488. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7489. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7490. if (QueueViewHeight < GetMinQueueViewHeight())
  7491. {
  7492. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7493. }
  7494. }
  7495. //---------------------------------------------------------------------------
  7496. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7497. TDragObject *& /*DragObject*/)
  7498. {
  7499. FQueueActedItem = QueueView3->ItemFocused;
  7500. }
  7501. //---------------------------------------------------------------------------
  7502. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7503. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7504. {
  7505. Accept = true;
  7506. if (Source == QueueView3)
  7507. {
  7508. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7509. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7510. if (Accept)
  7511. {
  7512. TQueueItemProxy * QueueItem;
  7513. TQueueItemProxy * DestQueueItem;
  7514. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7515. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7516. Accept = (QueueItem != DestQueueItem) &&
  7517. (QueueItem->Status == TQueueItem::qsPending) &&
  7518. (DestQueueItem->Status == TQueueItem::qsPending);
  7519. }
  7520. }
  7521. }
  7522. //---------------------------------------------------------------------------
  7523. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7524. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7525. {
  7526. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7527. {
  7528. TQueueItemProxy * QueueItem;
  7529. TQueueItemProxy * DestQueueItem;
  7530. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7531. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7532. QueueItem->Move(DestQueueItem);
  7533. }
  7534. }
  7535. //---------------------------------------------------------------------------
  7536. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7537. {
  7538. if ((QueueView3->ItemFocused == NULL) &&
  7539. (QueueView3->Items->Count > 0))
  7540. {
  7541. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7542. }
  7543. QueueLabelUpdateStatus();
  7544. }
  7545. //---------------------------------------------------------------------------
  7546. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7547. {
  7548. QueueLabelUpdateStatus();
  7549. }
  7550. //---------------------------------------------------------------------------
  7551. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7552. {
  7553. QueueLabel->UpdateStatus();
  7554. }
  7555. //---------------------------------------------------------------------------
  7556. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7557. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7558. {
  7559. if (Selected)
  7560. {
  7561. NonVisualDataModule->UpdateNonVisibleActions();
  7562. }
  7563. }
  7564. //---------------------------------------------------------------------------
  7565. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7566. {
  7567. TDragDropFilesEx * Result = NULL;
  7568. if (Sender == SessionsPageControl)
  7569. {
  7570. Result = FSessionsDragDropFilesEx;
  7571. }
  7572. else if (Sender == QueueView3)
  7573. {
  7574. Result = FQueueDragDropFilesEx;
  7575. }
  7576. else
  7577. {
  7578. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7579. if (DirView != NULL)
  7580. {
  7581. Result = DirView->DragDropFilesEx;
  7582. }
  7583. else
  7584. {
  7585. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7586. if (DriveView != NULL)
  7587. {
  7588. Result = DriveView->DragDropFilesEx;
  7589. }
  7590. }
  7591. }
  7592. DebugAssert(Result != NULL);
  7593. return Result;
  7594. }
  7595. //---------------------------------------------------------------------------
  7596. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7597. {
  7598. return (DView->SelCount == DView->FilesCount);
  7599. }
  7600. //---------------------------------------------------------------------------
  7601. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7602. {
  7603. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7604. }
  7605. //---------------------------------------------------------------------------
  7606. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7607. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7608. {
  7609. DebugAssert(!IsLocalBrowserMode());
  7610. TFileOperation Operation;
  7611. switch (Effect)
  7612. {
  7613. case DROPEFFECT_MOVE:
  7614. Operation = foMove;
  7615. break;
  7616. case DROPEFFECT_COPY:
  7617. // occures on WinXP (reported by user)
  7618. default:
  7619. Operation = foCopy;
  7620. break;
  7621. };
  7622. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7623. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7624. if (DragDropFilesEx->FileList->Count > 0)
  7625. {
  7626. TStrings * FileList = new TStringList();
  7627. try
  7628. {
  7629. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7630. {
  7631. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7632. }
  7633. FDragDropOperation = true;
  7634. TTransferOperationParam Param;
  7635. Param.TargetDirectory = TargetPath;
  7636. // upload, no temp dirs
  7637. Param.Temp = false;
  7638. Param.DragDrop = DragDrop;
  7639. Param.Options =
  7640. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7641. if (ForceQueue)
  7642. {
  7643. Param.Queue = asOn;
  7644. }
  7645. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7646. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7647. {
  7648. if (IsFileControl(DropSourceControl, osLocal))
  7649. {
  7650. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7651. }
  7652. else
  7653. {
  7654. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7655. }
  7656. }
  7657. }
  7658. __finally
  7659. {
  7660. FDragDropOperation = false;
  7661. delete FileList;
  7662. }
  7663. }
  7664. }
  7665. //---------------------------------------------------------------------------
  7666. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7667. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7668. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7669. {
  7670. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7671. }
  7672. //---------------------------------------------------------------------------
  7673. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7674. TObject * Sender, int grfKeyState, int & dwEffect)
  7675. {
  7676. DebugAssert(!IsLocalBrowserMode());
  7677. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7678. if ((dwEffect != DROPEFFECT_NONE) &&
  7679. IsFileControl(DropSourceControl, osRemote))
  7680. {
  7681. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7682. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7683. (RemoteDirView->DropTarget == NULL))
  7684. {
  7685. dwEffect = DROPEFFECT_NONE;
  7686. }
  7687. else
  7688. {
  7689. if (dwEffect == DROPEFFECT_COPY)
  7690. {
  7691. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7692. // currently we support copying always (at least via temporary directory);
  7693. // remove associated checks once this all proves stable and working
  7694. bool CopyCapable = true;
  7695. // if we do not support neither of operations, there's no discussion
  7696. if (!MoveCapable && !CopyCapable)
  7697. {
  7698. dwEffect = DROPEFFECT_NONE;
  7699. }
  7700. else
  7701. {
  7702. // The default effect inside remote panel is move,
  7703. // unless we do not support it, but support copy
  7704. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7705. {
  7706. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7707. }
  7708. else
  7709. {
  7710. // with ctrl-down, we want copy unless it is not supported
  7711. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7712. }
  7713. }
  7714. }
  7715. }
  7716. }
  7717. }
  7718. //---------------------------------------------------------------------------
  7719. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7720. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7721. {
  7722. DebugAssert(!IsLocalBrowserMode());
  7723. if (FDDTotalSize >= 0)
  7724. {
  7725. if (File->IsDirectory)
  7726. {
  7727. FDDTotalSize = -1;
  7728. }
  7729. else
  7730. {
  7731. FDDTotalSize += File->Size;
  7732. }
  7733. }
  7734. DebugAssert(!FDragTempDir.IsEmpty());
  7735. // TODO: this is quite ineffective
  7736. // TODO: what if invalid character replacement is disabled?
  7737. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7738. UnicodeString TransferFileName;
  7739. if (Sender == RemoteDriveView)
  7740. {
  7741. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7742. }
  7743. else
  7744. {
  7745. TransferFileName = File->FileName;
  7746. }
  7747. FDDFileList->AddObject(TransferFileName, File);
  7748. }
  7749. //---------------------------------------------------------------------------
  7750. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7751. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7752. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7753. {
  7754. // sometimes we do not get DDEnd so the list is not released
  7755. SAFE_DESTROY(FDDFileList);
  7756. FDDFileList = new TStringList();
  7757. FDragTempDir = WinConfiguration->TemporaryDir();
  7758. FDDTotalSize = 0;
  7759. FDragDropSshTerminate.reset(NULL);
  7760. }
  7761. //---------------------------------------------------------------------------
  7762. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7763. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7764. HRESULT & Result)
  7765. {
  7766. if (Result == DRAGDROP_S_DROP)
  7767. {
  7768. try
  7769. {
  7770. GlobalDragImageList->HideDragImage();
  7771. try
  7772. {
  7773. RemoteFileControlDDTargetDrop();
  7774. }
  7775. catch(ESshTerminate & E)
  7776. {
  7777. FDragDropSshTerminate.reset(E.Clone());
  7778. }
  7779. }
  7780. catch (Exception &E)
  7781. {
  7782. // If downloading fails we need to cancel drag&drop, otherwise
  7783. // Explorer shows error
  7784. // But by the way exception probably never reach this point as
  7785. // it's catched on way.
  7786. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7787. Result = DRAGDROP_S_CANCEL;
  7788. ShowExtendedException(Terminal, &E);
  7789. }
  7790. }
  7791. }
  7792. //---------------------------------------------------------------------------
  7793. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7794. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7795. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7796. {
  7797. TFileMasks::TParams MaskParams;
  7798. MaskParams.Size = Size;
  7799. MaskParams.Modification = Modification;
  7800. // this does not re-parse the mask if it is the same as the last time
  7801. FDirViewMatchMask = Masks;
  7802. bool ImplicitMatch;
  7803. Matches =
  7804. // RecurseInclude parameter has no effect as the Path is empty
  7805. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7806. (AllowImplicitMatches || !ImplicitMatch);
  7807. }
  7808. //---------------------------------------------------------------------------
  7809. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7810. TObject * Sender, TListItem * Item, WORD & Indexes)
  7811. {
  7812. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7813. UnicodeString Ext;
  7814. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7815. {
  7816. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7817. }
  7818. else
  7819. {
  7820. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7821. }
  7822. if (SameText(Ext, Configuration->PartialExt))
  7823. {
  7824. Indexes |= oiPartial;
  7825. }
  7826. }
  7827. //---------------------------------------------------------------------------
  7828. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7829. {
  7830. return
  7831. DirViewEnabled(osCurrent) &&
  7832. DirView(osCurrent)->CanPasteFromClipBoard();
  7833. }
  7834. //---------------------------------------------------------------------------
  7835. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7836. {
  7837. bool Result = false;
  7838. if (CanPasteToDirViewFromClipBoard())
  7839. {
  7840. Result = true;
  7841. }
  7842. else
  7843. {
  7844. UnicodeString ClipboardText;
  7845. if (NonEmptyTextFromClipboard(ClipboardText) &&
  7846. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  7847. {
  7848. if (StoredSessions->IsUrl(ClipboardText))
  7849. {
  7850. Result = true;
  7851. }
  7852. else
  7853. {
  7854. Result = DirViewEnabled(osCurrent);
  7855. }
  7856. }
  7857. }
  7858. return Result;
  7859. }
  7860. //---------------------------------------------------------------------------
  7861. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7862. {
  7863. if (DoesClipboardContainOurFiles())
  7864. {
  7865. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7866. {
  7867. DebugAssert(!IsLocalBrowserMode());
  7868. TTerminalManager * Manager = TTerminalManager::Instance();
  7869. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7870. Manager->ActiveTerminal = FClipboardTerminal;
  7871. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7872. }
  7873. }
  7874. else if (CanPasteToDirViewFromClipBoard())
  7875. {
  7876. DirView(osCurrent)->PasteFromClipBoard();
  7877. }
  7878. else
  7879. {
  7880. UnicodeString ClipboardText;
  7881. if (NonEmptyTextFromClipboard(ClipboardText))
  7882. {
  7883. if (StoredSessions->IsUrl(ClipboardText))
  7884. {
  7885. NewSession(ClipboardText);
  7886. }
  7887. else
  7888. {
  7889. DirView(osCurrent)->Path = ClipboardText;
  7890. }
  7891. }
  7892. }
  7893. }
  7894. //---------------------------------------------------------------------------
  7895. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7896. {
  7897. // TBD
  7898. }
  7899. //---------------------------------------------------------------------------
  7900. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7901. {
  7902. TCustomDirView * ADirView = DirView(Side);
  7903. ADirView->SelectAll(Mode);
  7904. ADirView->SetFocus();
  7905. }
  7906. //---------------------------------------------------------------------------
  7907. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7908. {
  7909. TCustomDirView * ADirView = DirView(Side);
  7910. TFileFilter Filter;
  7911. DefaultFileFilter(Filter);
  7912. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7913. {
  7914. Configuration->Usage->Inc(L"MaskSelections");
  7915. ADirView->SelectFiles(Filter, Select);
  7916. ADirView->SetFocus();
  7917. }
  7918. }
  7919. //---------------------------------------------------------------------------
  7920. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7921. {
  7922. TCustomDirView * ADirView = DirView(Side);
  7923. ADirView->RestoreSelectedNames();
  7924. ADirView->SetFocus();
  7925. }
  7926. //---------------------------------------------------------------------------
  7927. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7928. {
  7929. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7930. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7931. {
  7932. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7933. UnicodeString Ext;
  7934. if (!IsSideLocalBrowser(osCurrent))
  7935. {
  7936. Ext = UnixExtractFileExt(FileName);
  7937. }
  7938. else
  7939. {
  7940. Ext = ExtractFileExt(FileName);
  7941. }
  7942. if (Ext.IsEmpty())
  7943. {
  7944. Ext = L".";
  7945. }
  7946. TFileFilter Filter;
  7947. Filter.Masks = FORMAT(L"*%s", (Ext));
  7948. Filter.Directories = false;
  7949. CurrentDirView->SelectFiles(Filter, Select);
  7950. }
  7951. }
  7952. //---------------------------------------------------------------------------
  7953. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7954. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7955. {
  7956. UnicodeString Result;
  7957. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7958. {
  7959. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  7960. }
  7961. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  7962. {
  7963. // noop
  7964. }
  7965. else
  7966. {
  7967. Result =
  7968. FMTLOAD(FILE_INFO_FORMAT,
  7969. (FormatBytes(FileInfo.SelectedSize),
  7970. FormatBytes(FileInfo.FilesSize),
  7971. FormatNumber(FileInfo.SelectedCount),
  7972. FormatNumber(FileInfo.FilesCount)));
  7973. }
  7974. return Result;
  7975. }
  7976. //---------------------------------------------------------------------------
  7977. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7978. TTBXStatusPanel * Panel, TOperationSide Side)
  7979. {
  7980. if (Panel->Index == 1)
  7981. {
  7982. ToggleShowHiddenFiles();
  7983. }
  7984. else if (Panel->Index == 2)
  7985. {
  7986. Filter(Side);
  7987. }
  7988. }
  7989. //---------------------------------------------------------------------------
  7990. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  7991. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  7992. {
  7993. DebugAssert(!StatusBar->SimplePanel);
  7994. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  7995. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  7996. }
  7997. //---------------------------------------------------------------------------
  7998. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  7999. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8000. {
  8001. DebugAssert(StatusBar->Panels->Count >= 3);
  8002. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8003. if (FileInfo.HiddenCount > 0)
  8004. {
  8005. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8006. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8007. }
  8008. else
  8009. {
  8010. HiddenFilesPanel->ViewPriority = 0;
  8011. // not really necessary, just to cleanup no-longer-valid data
  8012. HiddenFilesPanel->Caption = L"";
  8013. }
  8014. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8015. if (FileInfo.FilteredCount > 0)
  8016. {
  8017. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8018. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8019. }
  8020. else
  8021. {
  8022. FilteredFilesPanel->ViewPriority = 0;
  8023. // not really necessary, just to cleanup no-longer-valid data
  8024. FilteredFilesPanel->Caption = L"";
  8025. }
  8026. }
  8027. //---------------------------------------------------------------------------
  8028. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8029. TObject * /*Sender*/)
  8030. {
  8031. if (DirView(osRemote)->Enabled)
  8032. {
  8033. DirView(osRemote)->SetFocus();
  8034. }
  8035. }
  8036. //---------------------------------------------------------------------------
  8037. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8038. {
  8039. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8040. switch (Config.Show)
  8041. {
  8042. case qvShow:
  8043. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8044. {
  8045. Config.Show = qvHide;
  8046. }
  8047. else
  8048. {
  8049. Config.Show = Config.LastHideShow;
  8050. }
  8051. break;
  8052. case qvHideWhenEmpty:
  8053. if (ComponentVisible[fcQueueView])
  8054. {
  8055. Config.Show = qvHide;
  8056. }
  8057. else
  8058. {
  8059. Config.LastHideShow = Config.Show;
  8060. Config.Show = qvShow;
  8061. }
  8062. break;
  8063. case qvHide:
  8064. Config.LastHideShow = Config.Show;
  8065. Config.Show = qvShow;
  8066. break;
  8067. }
  8068. WinConfiguration->QueueView = Config;
  8069. }
  8070. //---------------------------------------------------------------------------
  8071. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8072. {
  8073. UnicodeString Result;
  8074. if (FTerminal != NULL)
  8075. {
  8076. switch (WinConfiguration->PathInCaption)
  8077. {
  8078. case picShort:
  8079. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8080. break;
  8081. case picFull:
  8082. Result = FTerminal->CurrentDirectory;
  8083. break;
  8084. }
  8085. }
  8086. return Result;
  8087. }
  8088. //---------------------------------------------------------------------------
  8089. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8090. {
  8091. TColor Result = GetWindowColor(FSessionColor);
  8092. return Result;
  8093. }
  8094. //---------------------------------------------------------------------------
  8095. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8096. {
  8097. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8098. return Result;
  8099. }
  8100. //---------------------------------------------------------------------------
  8101. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8102. {
  8103. TTerminalManager::Instance()->UpdateAppTitle();
  8104. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8105. // background to gray on Windows 7 (works on Windows 10).
  8106. // See also EnableControl
  8107. if (Showing)
  8108. {
  8109. if (Terminal != NULL)
  8110. {
  8111. // Update path when it changes
  8112. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8113. {
  8114. UpdateSessionTab(SessionsPageControl->ActivePage);
  8115. }
  8116. }
  8117. NonVisualDataModule->ReconnectSessionAction->Update();
  8118. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8119. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8120. CenterReconnectToolbar();
  8121. bool HasTerminal = HasActiveTerminal();
  8122. if (HasTerminal)
  8123. {
  8124. // TODO needed yet with second local browser?
  8125. if (!RemoteDirView->Enabled)
  8126. {
  8127. RemoteDirView->Enabled = true;
  8128. if (FRemoteDirViewWasFocused)
  8129. {
  8130. ActiveControl = RemoteDirView;
  8131. }
  8132. }
  8133. RemoteDirView->Color = PanelColor();
  8134. }
  8135. else
  8136. {
  8137. if (RemoteDirView->Enabled)
  8138. {
  8139. // This is first called when the form is being constructed
  8140. // (not anymore due to Showing test above)
  8141. // but the false is overriden in the constructor later.
  8142. // An even later in TScpCommanderForm::DoShow()
  8143. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  8144. RemoteDirView->Enabled = false;
  8145. }
  8146. RemoteDirView->Color = DisabledPanelColor();
  8147. }
  8148. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8149. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8150. RemoteDriveView->Color = RemoteDirView->Color;
  8151. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8152. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8153. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8154. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8155. QueueFileList->Enabled = QueueView3->Enabled;
  8156. QueueFileList->Color = QueueView3->Color;
  8157. QueueFileList->Font->Color = QueueView3->Font->Color;
  8158. QueueLabelUpdateStatus();
  8159. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8160. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8161. if (FImmersiveDarkMode != WinConfiguration->UseDarkTheme())
  8162. {
  8163. UpdateDarkMode();
  8164. }
  8165. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  8166. }
  8167. }
  8168. //---------------------------------------------------------------------------
  8169. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8170. {
  8171. UpdateControls();
  8172. }
  8173. //---------------------------------------------------------------------------
  8174. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8175. TObject * Sender)
  8176. {
  8177. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8178. DebugAssert(DirView != NULL);
  8179. DoDirViewLoaded(DirView);
  8180. TransferPresetAutoSelect();
  8181. }
  8182. //---------------------------------------------------------------------------
  8183. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8184. {
  8185. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8186. // first run after installation
  8187. if (double(Updates.LastCheck) == 0)
  8188. {
  8189. // make sure next time there will be an update (if enabled)
  8190. Updates.LastCheck = TDateTime(1);
  8191. WinConfiguration->Updates = Updates;
  8192. }
  8193. else if ((double(Updates.Period) > 0) &&
  8194. (Now() - Updates.LastCheck >= Updates.Period))
  8195. {
  8196. TThreadMethod OnUpdatesChecked = NULL;
  8197. if (!IsUWP())
  8198. {
  8199. OnUpdatesChecked = UpdatesChecked;
  8200. }
  8201. StartUpdateThread(OnUpdatesChecked);
  8202. }
  8203. }
  8204. //---------------------------------------------------------------------------
  8205. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8206. {
  8207. UnicodeString Message;
  8208. bool New;
  8209. TQueryType Type;
  8210. GetUpdatesMessage(Message, New, Type, false);
  8211. if (!Message.IsEmpty())
  8212. {
  8213. if (New)
  8214. {
  8215. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8216. }
  8217. if (!New && (Type != qtWarning))
  8218. {
  8219. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8220. }
  8221. else
  8222. {
  8223. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8224. }
  8225. if (New)
  8226. {
  8227. Configuration->Usage->Inc(L"UpdateNotifications");
  8228. }
  8229. }
  8230. }
  8231. //---------------------------------------------------------------------------
  8232. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8233. {
  8234. RestoreApp();
  8235. bool CanDisplay = !NonVisualDataModule->Busy;
  8236. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8237. {
  8238. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8239. }
  8240. if (CanDisplay)
  8241. {
  8242. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8243. CheckForUpdates(true);
  8244. }
  8245. else
  8246. {
  8247. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8248. }
  8249. }
  8250. //---------------------------------------------------------------------------
  8251. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8252. TCopyParamRuleData & Data)
  8253. {
  8254. DebugAssert(Terminal != NULL);
  8255. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8256. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8257. Data.RemoteDirectory = RemoteDirView->PathName;
  8258. }
  8259. //---------------------------------------------------------------------------
  8260. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8261. {
  8262. // Terminal can be null when we are changing local directory implicitly,
  8263. // because it has been deleted, while no session is connected
  8264. // (Login dialog is open)
  8265. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8266. {
  8267. DebugAssert(!IsLocalBrowserMode());
  8268. TCopyParamRuleData Data;
  8269. GetTransferPresetAutoSelectData(Data);
  8270. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8271. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8272. if (CopyParamIndex < 0)
  8273. {
  8274. // there is no preset that matches autoselection
  8275. // set preset that we consider "default"
  8276. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8277. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8278. }
  8279. else
  8280. {
  8281. // there is preset matching autoselection
  8282. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8283. if (CopyParamName == FCopyParamAutoSelected)
  8284. {
  8285. // autoselected the same preset as the last time
  8286. // make no change (i.e. preserve custom user preset, if any)
  8287. }
  8288. else
  8289. {
  8290. // autoselected the different preset then the last time (or there
  8291. // was default preset set)
  8292. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8293. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8294. }
  8295. }
  8296. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8297. {
  8298. if (CopyParamIndex >= 0)
  8299. {
  8300. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8301. }
  8302. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8303. try
  8304. {
  8305. int Fmt =
  8306. (CopyParamIndex < 0) ?
  8307. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8308. COPY_PARAM_AUTOSELECTED;
  8309. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8310. Data->Message = MainInstructions(Message);
  8311. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8312. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8313. CopyParamAttrs);
  8314. if (CopyParamIndex >= 0)
  8315. {
  8316. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8317. Info = FORMAT(L"%s\n \n%s", (Info,
  8318. FMTLOAD(COPY_PARAM_RULE,
  8319. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8320. }
  8321. Data->Message += L"\n\n" + Info;
  8322. if (WinConfiguration->CopyParamAutoSelectNotice)
  8323. {
  8324. TransferPresetNoteMessage(Data, true);
  8325. }
  8326. else
  8327. {
  8328. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8329. Data = NULL; // ownership passed
  8330. }
  8331. }
  8332. __finally
  8333. {
  8334. delete Data;
  8335. }
  8336. }
  8337. }
  8338. }
  8339. //---------------------------------------------------------------------------
  8340. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8341. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8342. {
  8343. DebugAssert(NoteData != NULL);
  8344. DebugAssert(!IsLocalBrowserMode());
  8345. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8346. TQueryButtonAlias Aliases[1];
  8347. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8348. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8349. Params.Aliases = Aliases;
  8350. Params.AliasesCount = LENOF(Aliases);
  8351. unsigned int Result =
  8352. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8353. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8354. switch (Result)
  8355. {
  8356. case qaNeverAskAgain:
  8357. DebugAssert(AllowNeverAskAgain);
  8358. WinConfiguration->CopyParamAutoSelectNotice = false;
  8359. break;
  8360. case qaIgnore:
  8361. PreferencesDialog(pmPresets);
  8362. break;
  8363. }
  8364. }
  8365. //---------------------------------------------------------------------------
  8366. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8367. {
  8368. // as of now useless, as this is used for notes only, never for balloons, ...
  8369. RestoreApp();
  8370. // .. and we should never be busy here
  8371. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8372. {
  8373. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8374. }
  8375. }
  8376. //---------------------------------------------------------------------------
  8377. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8378. TPreferencesMode APreferencesMode)
  8379. {
  8380. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8381. TCopyParamRuleData Data;
  8382. if (Terminal != NULL)
  8383. {
  8384. PreferencesData.reset(new TPreferencesDialogData());
  8385. GetTransferPresetAutoSelectData(Data);
  8386. PreferencesData->CopyParamRuleData = &Data;
  8387. }
  8388. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8389. }
  8390. //---------------------------------------------------------------------------
  8391. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8392. const TCustomCommandType & Command)
  8393. {
  8394. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8395. {
  8396. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8397. }
  8398. }
  8399. //---------------------------------------------------------------------------
  8400. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8401. {
  8402. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8403. TCustomCommandType Command;
  8404. // make sure we use local custom command when remote are not supported
  8405. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8406. {
  8407. Command = FLastCustomCommand;
  8408. }
  8409. else
  8410. {
  8411. Command.Params = Command.Params | ccLocal;
  8412. }
  8413. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8414. FEditingFocusedAdHocCommand = OnFocused;
  8415. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8416. int Options =
  8417. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8418. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8419. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8420. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8421. {
  8422. FLastCustomCommand = Command;
  8423. UpdateCustomCommandsToolbar();
  8424. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8425. }
  8426. }
  8427. //---------------------------------------------------------------------------
  8428. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8429. {
  8430. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8431. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8432. DebugAssert(State > 0);
  8433. if (State <= 0)
  8434. {
  8435. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8436. }
  8437. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8438. }
  8439. //---------------------------------------------------------------------------
  8440. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8441. TCustomCommandType & Command, int & State)
  8442. {
  8443. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8444. if (Result)
  8445. {
  8446. Command = FLastCustomCommand;
  8447. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8448. }
  8449. return Result;
  8450. }
  8451. //---------------------------------------------------------------------------
  8452. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8453. {
  8454. ResetIncrementalSearch();
  8455. }
  8456. //---------------------------------------------------------------------------
  8457. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8458. {
  8459. DebugAssert(ComponentVisible[Component]);
  8460. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8461. }
  8462. //---------------------------------------------------------------------------
  8463. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8464. {
  8465. // when queue panel is resized here directly, the status bar is stretched
  8466. // over whole space the panel occupied
  8467. PostComponentHide(fcQueueView);
  8468. }
  8469. //---------------------------------------------------------------------------
  8470. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8471. {
  8472. ComponentVisible[fcQueueFileList] = false;
  8473. }
  8474. //---------------------------------------------------------------------------
  8475. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8476. {
  8477. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8478. RefreshColorMode();
  8479. ResetSysDarkTheme();
  8480. ConfigurationChanged();
  8481. ConfigureInterface();
  8482. // Should be called for all controls
  8483. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8484. }
  8485. //---------------------------------------------------------------------------
  8486. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8487. {
  8488. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8489. if (!FInvalid &&
  8490. (Message.LParam != 0) &&
  8491. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8492. {
  8493. ThemeChanged();
  8494. }
  8495. TForm::Dispatch(&Message);
  8496. }
  8497. //---------------------------------------------------------------------------
  8498. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8499. {
  8500. TMessage * M = static_cast<TMessage*>(Message);
  8501. switch (M->Msg)
  8502. {
  8503. case CM_DIALOGCHAR:
  8504. CMDialogChar(*M);
  8505. break;
  8506. case WM_APPCOMMAND:
  8507. WMAppCommand(*M);
  8508. break;
  8509. case WM_SYSCOMMAND:
  8510. WMSysCommand(*M);
  8511. break;
  8512. case WM_QUERYENDSESSION:
  8513. WMQueryEndSession(*M);
  8514. break;
  8515. case WM_ENDSESSION:
  8516. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8517. break;
  8518. #ifdef _DEBUG
  8519. case WM_WINDOWPOSCHANGED:
  8520. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8521. break;
  8522. case CM_CUSTOMSTYLECHANGED:
  8523. TForm::Dispatch(Message);
  8524. break;
  8525. #endif
  8526. case WM_COMPONENT_HIDE:
  8527. {
  8528. Byte Component = static_cast<Byte>(M->WParam);
  8529. // sanity check
  8530. if (ComponentVisible[Component])
  8531. {
  8532. // special treatment
  8533. if (Component == fcQueueView)
  8534. {
  8535. ToggleQueueVisibility();
  8536. DebugAssert(!ComponentVisible[fcQueueView]);
  8537. }
  8538. else
  8539. {
  8540. ComponentVisible[Component] = false;
  8541. }
  8542. }
  8543. }
  8544. break;
  8545. case WM_COPYDATA:
  8546. WMCopyData(*M);
  8547. break;
  8548. case WM_MANAGES_CAPTION:
  8549. // caption managed in TTerminalManager::UpdateAppTitle()
  8550. M->Result = 1;
  8551. break;
  8552. case WM_WANTS_MOUSEWHEEL:
  8553. M->Result = 1;
  8554. break;
  8555. case CM_SHOWINGCHANGED:
  8556. CMShowingChanged(*M);
  8557. break;
  8558. case WM_CLOSE:
  8559. WMClose(*M);
  8560. break;
  8561. case WM_DPICHANGED:
  8562. WMDpiChanged(*M);
  8563. break;
  8564. case CM_DPICHANGED:
  8565. CMDpiChanged(*M);
  8566. break;
  8567. case WM_SETTINGCHANGE:
  8568. WMSettingChange(*M);
  8569. break;
  8570. case CM_DIALOGKEY:
  8571. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8572. break;
  8573. default:
  8574. TForm::Dispatch(Message);
  8575. break;
  8576. }
  8577. }
  8578. //---------------------------------------------------------------------------
  8579. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8580. {
  8581. // noop
  8582. }
  8583. //---------------------------------------------------------------------------
  8584. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8585. {
  8586. TForm::Dispatch(&Message);
  8587. FSessionColors->Clear();
  8588. AddFixedSessionImages();
  8589. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8590. UpdateImages();
  8591. }
  8592. //---------------------------------------------------------------------------
  8593. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8594. {
  8595. TForm::Dispatch(&Message);
  8596. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8597. UpdatePixelsPerInchMainWindowCounter();
  8598. }
  8599. //---------------------------------------------------------------------------
  8600. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8601. {
  8602. // Cannot close window while we are busy.
  8603. // We cannot test this in FormCloseQuery as that is called also from
  8604. // Close(), which is called by CloseApplicationAction. So we can be busy
  8605. // there already even, when it is legitimate to close the application.
  8606. // Possibly a better place to handle this would be WMSysCommand.
  8607. if (NonVisualDataModule->Busy)
  8608. {
  8609. Message.Result = 1;
  8610. }
  8611. else
  8612. {
  8613. TForm::Dispatch(&Message);
  8614. }
  8615. }
  8616. //---------------------------------------------------------------------------
  8617. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8618. {
  8619. TForm::Dispatch(&Message);
  8620. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  8621. if (Showing && !FStarted)
  8622. {
  8623. FStarted = true;
  8624. InterfaceStarted();
  8625. }
  8626. if (Showing && (Terminal == NULL))
  8627. {
  8628. // When we are starting minimized (i.e. from an installer),
  8629. // postpone showing Login dialog until we get restored.
  8630. // Otherwise the Login dialog (and Authentication window) show restored
  8631. // over invisible (minimized) main window.
  8632. if (WindowState == wsMinimized)
  8633. {
  8634. FNeedSession = true;
  8635. }
  8636. else
  8637. {
  8638. // This happens before application ever goes idle, so the toolbars would
  8639. // stay enabled (initial state) until the Login dialog is dismissed.
  8640. UpdateActions();
  8641. NonVisualDataModule->StartBusy();
  8642. try
  8643. {
  8644. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8645. // otherwise the dialog does not receive focus.
  8646. // With Commander interface the ProcessMessages is called already
  8647. // by TDriveView, but with Explorer interface, we need to call it explicily
  8648. Application->ProcessMessages();
  8649. // do not reload sessions, they have been loaded just now (optimization)
  8650. NeedSession(true);
  8651. }
  8652. __finally
  8653. {
  8654. NonVisualDataModule->EndBusy();
  8655. }
  8656. }
  8657. }
  8658. }
  8659. //---------------------------------------------------------------------------
  8660. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8661. {
  8662. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8663. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8664. }
  8665. //---------------------------------------------------------------------------
  8666. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8667. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8668. int & MaxHeight)
  8669. {
  8670. // workaround for bug in TWinControl.CalcConstraints
  8671. // Check for empty rect (restore from iconic state) is done there only after
  8672. // call to AdjustClientRect, which enlarges the rect (for forms).
  8673. TRect R = GetClientRect();
  8674. // when restoring from iconic state, place no restrictions
  8675. if (IsRectEmpty(R))
  8676. {
  8677. MinWidth = 0;
  8678. MinHeight = 0;
  8679. MaxWidth = 32000;
  8680. MaxHeight = 32000;
  8681. }
  8682. }
  8683. //---------------------------------------------------------------------------
  8684. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8685. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8686. {
  8687. // terminal can be already closed (e.g. dropped connection)
  8688. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8689. {
  8690. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8691. try
  8692. {
  8693. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8694. }
  8695. catch(...)
  8696. {
  8697. if (!Terminal->Active)
  8698. {
  8699. Close = true;
  8700. }
  8701. throw;
  8702. }
  8703. }
  8704. }
  8705. //---------------------------------------------------------------------------
  8706. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8707. {
  8708. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8709. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8710. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8711. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8712. {
  8713. OnGetSpaceAvailable = GetSpaceAvailable;
  8714. }
  8715. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8716. OnGetSpaceAvailable);
  8717. }
  8718. //---------------------------------------------------------------------------
  8719. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8720. {
  8721. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8722. Terminal->FillSessionDataForCode(Data.get());
  8723. return Data.release();
  8724. }
  8725. //---------------------------------------------------------------------------
  8726. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8727. {
  8728. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8729. DoGenerateUrlDialog(Data.get(), Paths);
  8730. }
  8731. //---------------------------------------------------------------------------
  8732. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8733. {
  8734. GenerateUrl(NULL);
  8735. }
  8736. //---------------------------------------------------------------------------
  8737. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8738. {
  8739. std::unique_ptr<TStrings> Paths(new TStringList());
  8740. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8741. GenerateUrl(Paths.get());
  8742. }
  8743. //---------------------------------------------------------------------------
  8744. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8745. {
  8746. FSessionColor = value;
  8747. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8748. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8749. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8750. DebugAssert(ColorItem != NULL);
  8751. ColorItem->Color = C;
  8752. NonVisualDataModule->ColorMenuItem->Color = C;
  8753. UpdateControls();
  8754. }
  8755. //---------------------------------------------------------------------------
  8756. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8757. {
  8758. if (value != FSessionColor)
  8759. {
  8760. UpdateSessionColor(value);
  8761. // Is null when called from LastTerminalClosed
  8762. if (Terminal != NULL)
  8763. {
  8764. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8765. }
  8766. }
  8767. }
  8768. //---------------------------------------------------------------------------
  8769. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8770. {
  8771. bool Result = FNoteTimer->Enabled;
  8772. if (Result)
  8773. {
  8774. // cannot cancel note too early
  8775. bool NotEarly =
  8776. (Now() - FNoteShown >
  8777. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8778. if (Force || NotEarly)
  8779. {
  8780. FNoteTimer->Enabled = false;
  8781. FNote = L"";
  8782. SAFE_DESTROY(FNoteData);
  8783. FOnNoteClick = NULL;
  8784. FNoteHints = FNotes->Text;
  8785. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8786. UpdateStatusBar();
  8787. }
  8788. }
  8789. return Result;
  8790. }
  8791. //---------------------------------------------------------------------------
  8792. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8793. {
  8794. DebugAssert(FNoteTimer->Enabled);
  8795. CancelNote(true);
  8796. }
  8797. //---------------------------------------------------------------------------
  8798. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  8799. {
  8800. FNoteHints = FNotes->Text.TrimRight();
  8801. }
  8802. //---------------------------------------------------------------------------
  8803. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8804. {
  8805. int P = Note.Pos(L"\n");
  8806. if (P > 0)
  8807. {
  8808. Note.SetLength(P - 1);
  8809. }
  8810. FNotes->Add(FORMAT(L"[%s] %s",
  8811. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8812. while (FNotes->Count > 10)
  8813. {
  8814. FNotes->Delete(0);
  8815. }
  8816. if (UpdateNow)
  8817. {
  8818. UpdateNoteHints();
  8819. UpdateStatusBar();
  8820. }
  8821. }
  8822. //---------------------------------------------------------------------------
  8823. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8824. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8825. {
  8826. int P = Note.Pos(L"\n");
  8827. if (P > 0)
  8828. {
  8829. Note.SetLength(P - 1);
  8830. }
  8831. UpdateNoteHints();
  8832. FNote = Note;
  8833. SAFE_DESTROY(FNoteData);
  8834. FNoteData = NoteData;
  8835. FOnNoteClick = OnNoteClick;
  8836. AddNote(Note, false);
  8837. UpdateStatusBar();
  8838. FNoteShown = Now();
  8839. FNoteTimer->Enabled = false;
  8840. if (Seconds == 0)
  8841. {
  8842. Seconds = WinConfiguration->NotificationsTimeout;
  8843. }
  8844. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8845. FNoteTimer->Enabled = true;
  8846. }
  8847. //---------------------------------------------------------------------------
  8848. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8849. {
  8850. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8851. }
  8852. //---------------------------------------------------------------------------
  8853. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8854. {
  8855. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked)
  8856. {
  8857. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8858. }
  8859. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8860. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8861. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  8862. 0, NULL, NULL);
  8863. }
  8864. //---------------------------------------------------------------------------
  8865. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8866. {
  8867. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8868. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8869. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8870. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  8871. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8872. }
  8873. //---------------------------------------------------------------------------
  8874. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8875. {
  8876. WinConfiguration->FormatSizeBytes = Style;
  8877. }
  8878. //---------------------------------------------------------------------------
  8879. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8880. {
  8881. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8882. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8883. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8884. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8885. }
  8886. //---------------------------------------------------------------------------
  8887. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8888. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8889. {
  8890. if (Panel->Index == 0)
  8891. {
  8892. if (FOnNoteClick != NULL)
  8893. {
  8894. // prevent the user data from being freed by possible call
  8895. // to CancelNote or PostNote during call to OnNoteClick
  8896. std::unique_ptr<TObject> NoteData(FNoteData);
  8897. TNotifyEvent OnNoteClick = FOnNoteClick;
  8898. FNoteData = NULL;
  8899. // need to cancel the note as we are going to delete its user data
  8900. CancelNote(true);
  8901. OnNoteClick(NoteData.get());
  8902. }
  8903. }
  8904. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8905. {
  8906. FileSystemInfo();
  8907. }
  8908. }
  8909. //---------------------------------------------------------------------------
  8910. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8911. {
  8912. // workaround:
  8913. // 1) for unknown reason, disabling window, while minimized,
  8914. // prevents it from restoring, even if it was enabled again meanwhile
  8915. // 2) when disabling the main window, while another has focus
  8916. // minimize is no longer possible
  8917. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8918. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8919. // Shouldn't we use IsApplicationMinimized() here?
  8920. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8921. {
  8922. Enabled = false;
  8923. }
  8924. FLockLevel++;
  8925. }
  8926. //---------------------------------------------------------------------------
  8927. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8928. {
  8929. DebugAssert(FLockLevel > 0);
  8930. FLockLevel--;
  8931. if (FLockLevel == 0)
  8932. {
  8933. DebugAssert(FLockSuspendLevel == 0);
  8934. Enabled = true;
  8935. }
  8936. }
  8937. //---------------------------------------------------------------------------
  8938. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8939. {
  8940. // We need to make sure that window is enabled when the last modal window closes
  8941. // otherwise focus is not restored correctly.
  8942. // So we re-enable the window when modal window opens and
  8943. // disable it back after is closes
  8944. if (FLockLevel > 0)
  8945. {
  8946. // while we have nesting counter, we know that we never be called
  8947. // recursivelly as Application->OnModalBegin is called only
  8948. // for the top-level modal window
  8949. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8950. {
  8951. // won't be disabled when conditions in LockWindow() were not satisfied
  8952. FDisabledOnLockSuspend = !Enabled;
  8953. // When minimized to tray (or actually when set to SW_HIDE),
  8954. // setting Enabled makes the window focusable even when there's
  8955. // modal window over it
  8956. if (!FTrayIcon->Visible)
  8957. {
  8958. Enabled = true;
  8959. }
  8960. }
  8961. FLockSuspendLevel++;
  8962. }
  8963. }
  8964. //---------------------------------------------------------------------------
  8965. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8966. {
  8967. if (FLockSuspendLevel > 0)
  8968. {
  8969. DebugAssert(FLockLevel > 0);
  8970. FLockSuspendLevel--;
  8971. // see comment in SuspendWindowLock
  8972. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8973. {
  8974. // Note that window can be enabled here, when we were minized to tray when
  8975. // was SuspendWindowLock() called.
  8976. // We should possibly do the same check as in LockWindow(),
  8977. // if it is ever possible that the consitions change between
  8978. // SuspendWindowLock() and ResumeWindowLock()
  8979. Enabled = !FDisabledOnLockSuspend;
  8980. }
  8981. }
  8982. }
  8983. //---------------------------------------------------------------------------
  8984. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8985. {
  8986. TTBXComboBoxItem * RemotePathComboBox =
  8987. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8988. if (!TextOnly)
  8989. {
  8990. TStrings * Items = RemotePathComboBox->Strings;
  8991. Items->BeginUpdate();
  8992. try
  8993. {
  8994. Items->Clear();
  8995. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  8996. {
  8997. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8998. while (!IsUnixRootPath(APath))
  8999. {
  9000. int P = APath.LastDelimiter(L'/');
  9001. DebugAssert(P >= 0);
  9002. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9003. APath.SetLength(P - 1);
  9004. }
  9005. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9006. }
  9007. }
  9008. __finally
  9009. {
  9010. Items->EndUpdate();
  9011. }
  9012. }
  9013. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9014. // Setting ItemIndex to -1 does not reset its text
  9015. if (RemotePathComboBox->Strings->Count == 0)
  9016. {
  9017. RemotePathComboBox->Text = L"";
  9018. }
  9019. }
  9020. //---------------------------------------------------------------------------
  9021. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9022. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  9023. int & ImageIndex)
  9024. {
  9025. if (AIndex < 0)
  9026. {
  9027. AIndex = Sender->ItemIndex;
  9028. }
  9029. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9030. }
  9031. //---------------------------------------------------------------------------
  9032. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9033. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9034. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9035. {
  9036. ARect.Left += (10 * AIndex);
  9037. }
  9038. //---------------------------------------------------------------------------
  9039. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9040. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9041. {
  9042. AWidth += (10 * AIndex);
  9043. }
  9044. //---------------------------------------------------------------------------
  9045. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  9046. TObject * Sender)
  9047. {
  9048. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9049. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9050. int Index = RemotePathComboBox->ItemIndex;
  9051. while (Index < RemotePathComboBox->Strings->Count - 1)
  9052. {
  9053. APath = UnixExtractFileDir(APath);
  9054. Index++;
  9055. }
  9056. // VanDyke style paths
  9057. if (APath.IsEmpty())
  9058. {
  9059. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9060. APath = ROOTDIRECTORY;
  9061. }
  9062. if (RemoteDirView->Path != APath)
  9063. {
  9064. RemoteDirView->Path = APath;
  9065. }
  9066. }
  9067. //---------------------------------------------------------------------------
  9068. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9069. {
  9070. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9071. DebugUsedParam(Sender);
  9072. UpdateRemotePathComboBox(true);
  9073. }
  9074. //---------------------------------------------------------------------------
  9075. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9076. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9077. {
  9078. ResetIncrementalSearch();
  9079. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9080. DebugAssert(DirView != NULL);
  9081. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9082. {
  9083. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9084. // OnEditing is called also from TCustomListView::CanEdit
  9085. if (Edit != NULL)
  9086. {
  9087. EditSelectBaseName(Edit);
  9088. }
  9089. }
  9090. }
  9091. //---------------------------------------------------------------------------
  9092. //---------------------------------------------------------------------------
  9093. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9094. {
  9095. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9096. Result->AutoDetectDnD = false;
  9097. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9098. Result->RenderDataOn = rdoEnterAndDropSync;
  9099. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9100. return Result;
  9101. }
  9102. //---------------------------------------------------------------------------
  9103. void __fastcall TCustomScpExplorerForm::UpdateDarkMode()
  9104. {
  9105. if (IsWin10Build(2004))
  9106. {
  9107. FImmersiveDarkMode = WinConfiguration->UseDarkTheme();
  9108. BOOL DarkMode = FImmersiveDarkMode ? TRUE : FALSE;
  9109. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9110. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9111. }
  9112. }
  9113. //---------------------------------------------------------------------------
  9114. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9115. {
  9116. TForm::CreateWnd();
  9117. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9118. UpdateDarkMode();
  9119. if (FSessionsDragDropFilesEx == NULL)
  9120. {
  9121. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9122. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9123. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9124. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9125. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9126. }
  9127. if (FQueueDragDropFilesEx == NULL)
  9128. {
  9129. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9130. // No need to set OnDragOver as we do not have any restrictions
  9131. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9132. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9133. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9134. }
  9135. }
  9136. //---------------------------------------------------------------------------
  9137. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9138. {
  9139. TForm::DestroyWnd();
  9140. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9141. FQueueDragDropFilesEx->DragDropControl = NULL;
  9142. }
  9143. //---------------------------------------------------------------------------
  9144. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9145. {
  9146. SideEnter(FCurrentSide);
  9147. FEverShown = true;
  9148. }
  9149. //---------------------------------------------------------------------------
  9150. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9151. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9152. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9153. {
  9154. if (!NonVisualDataModule->Busy)
  9155. {
  9156. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9157. Configuration->Usage->Inc(L"FileFinds");
  9158. LockWindow(true);
  9159. NonVisualDataModule->StartBusy();
  9160. WinConfiguration->LockedInterface = true;
  9161. try
  9162. {
  9163. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9164. }
  9165. __finally
  9166. {
  9167. WinConfiguration->LockedInterface = false;
  9168. NonVisualDataModule->EndBusy();
  9169. UnlockWindow();
  9170. }
  9171. }
  9172. }
  9173. //---------------------------------------------------------------------------
  9174. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9175. {
  9176. if (!NonVisualDataModule->Busy)
  9177. {
  9178. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9179. SetFocus();
  9180. RemoteDirView->Path = UnixExtractFilePath(Path);
  9181. UnicodeString FileName = UnixExtractFileName(Path);
  9182. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9183. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9184. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9185. if (Item == NULL)
  9186. {
  9187. ReloadDirectory(osRemote);
  9188. Item = RemoteDirView->FindFileItem(FileName);
  9189. }
  9190. if (Item != NULL)
  9191. {
  9192. RemoteDirView->ItemFocused = Item;
  9193. RemoteDirView->ItemFocused->MakeVisible(false);
  9194. RemoteDirView->SetFocus();
  9195. }
  9196. }
  9197. }
  9198. //---------------------------------------------------------------------------
  9199. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9200. {
  9201. bool Result = !NonVisualDataModule->Busy;
  9202. if (Result)
  9203. {
  9204. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9205. }
  9206. return Result;
  9207. }
  9208. //---------------------------------------------------------------------------
  9209. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9210. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9211. {
  9212. if (CanOperateOnFoundFiles(ATerminal))
  9213. {
  9214. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9215. FOnFileOperationFinished = OnFileOperationFinished;
  9216. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9217. }
  9218. }
  9219. //---------------------------------------------------------------------------
  9220. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9221. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9222. {
  9223. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9224. }
  9225. //---------------------------------------------------------------------------
  9226. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9227. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9228. {
  9229. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9230. }
  9231. //---------------------------------------------------------------------------
  9232. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9233. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9234. {
  9235. if (CanOperateOnFoundFiles(ATerminal))
  9236. {
  9237. for (int Index = 0; Index < FileList->Count; Index++)
  9238. {
  9239. UnicodeString FileName = FileList->Strings[Index];
  9240. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9241. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9242. OnFileOperationFinished(FileName, true);
  9243. }
  9244. }
  9245. }
  9246. //---------------------------------------------------------------------------
  9247. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9248. {
  9249. FFileFindTerminal = Terminal;
  9250. ShowFileFindDialog(
  9251. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9252. DoDownloadFoundFiles, DoEditFoundFiles);
  9253. }
  9254. //---------------------------------------------------------------------------
  9255. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9256. {
  9257. FTaskbarList = TaskbarList;
  9258. }
  9259. //---------------------------------------------------------------------------
  9260. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9261. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9262. {
  9263. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9264. if (Index >= 0)
  9265. {
  9266. if (Button == mbLeft)
  9267. {
  9268. // "Mouse down" is raised only after tab is switched.
  9269. // If switching tab (switching session) takes long enough for user
  9270. // to actually release the button, "mouse down" is still raised,
  9271. // but we do not get "mouse up" event, so dragging is not cancelled,
  9272. // prevent that by not beginning dragging in the first place.
  9273. if (IsKeyPressed(VK_LBUTTON))
  9274. {
  9275. // when user clicks the "+", we get mouse down only after the session
  9276. // is closed, when new session tab is already on X:Y, so dragging
  9277. // starts, prevent that
  9278. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9279. {
  9280. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9281. if (Terminal != NULL)
  9282. {
  9283. SessionsPageControl->BeginDrag(false);
  9284. }
  9285. }
  9286. }
  9287. }
  9288. else if (Button == mbMiddle)
  9289. {
  9290. // ignore middle-click for "New session tab"
  9291. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9292. if (Terminal != NULL)
  9293. {
  9294. CloseSessionTab(Index);
  9295. }
  9296. }
  9297. }
  9298. }
  9299. //---------------------------------------------------------------------------
  9300. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9301. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9302. {
  9303. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9304. // do not allow dropping on the "+" tab
  9305. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9306. if ((TargetTerminal != NULL) &&
  9307. (SessionsPageControl->ActivePage->PageIndex != Index))
  9308. {
  9309. Configuration->Usage->Inc(L"SessionTabMoves");
  9310. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9311. // but we want to actually prevent that to avoid flicker
  9312. SessionsPageControl->ActivePage->PageIndex = Index;
  9313. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9314. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9315. }
  9316. }
  9317. //---------------------------------------------------------------------------
  9318. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9319. TObject * Sender, TObject * Source, int X, int Y,
  9320. TDragState /*State*/, bool & Accept)
  9321. {
  9322. Accept = (Sender == Source);
  9323. if (Accept)
  9324. {
  9325. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9326. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9327. // do not allow dragging to the "+" tab
  9328. Accept = (Terminal != NULL);
  9329. }
  9330. }
  9331. //---------------------------------------------------------------------------
  9332. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9333. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9334. {
  9335. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9336. if (Index < 0)
  9337. {
  9338. Effect = DROPEFFECT_NONE;
  9339. }
  9340. else
  9341. {
  9342. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9343. // do not allow dropping on the "+" tab
  9344. if (TargetTerminal == NULL)
  9345. {
  9346. Effect = DROPEFFECT_NONE;
  9347. }
  9348. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9349. {
  9350. Effect = DROPEFFECT_COPY;
  9351. }
  9352. }
  9353. }
  9354. //---------------------------------------------------------------------------
  9355. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9356. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9357. {
  9358. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9359. // do not allow dropping on the "+" tab
  9360. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9361. if (TargetTerminal != NULL)
  9362. {
  9363. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9364. if (!IsFileControl(DropSourceControl, osRemote))
  9365. {
  9366. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9367. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9368. // Why don't we use Terminal->CurrentDirectory directly?
  9369. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9370. // do not force queue, drag drop
  9371. false, true);
  9372. }
  9373. }
  9374. }
  9375. //---------------------------------------------------------------------------
  9376. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9377. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9378. {
  9379. // Downloads are handled in RemoteFileControlDDEnd
  9380. if (!IsFileControl(DropSourceControl, osRemote))
  9381. {
  9382. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9383. Terminal->CurrentDirectory,
  9384. // force queue, drag drop
  9385. true, true);
  9386. }
  9387. }
  9388. //---------------------------------------------------------------------------
  9389. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9390. {
  9391. FShowing = false;
  9392. // Do not save empty workspace
  9393. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9394. {
  9395. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9396. UnicodeString Name = WorkspaceName();
  9397. DoSaveWorkspace(
  9398. Name, DataList.get(),
  9399. !Configuration->DisablePasswordStoring &&
  9400. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9401. WinConfiguration->LastStoredSession = Name;
  9402. }
  9403. }
  9404. //---------------------------------------------------------------------------
  9405. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9406. {
  9407. TManagedTerminal * ManagedTerminal =
  9408. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9409. if (ManagedTerminal != NULL)
  9410. {
  9411. ManagedTerminal->DirectoryLoaded = Now();
  9412. }
  9413. }
  9414. //---------------------------------------------------------------------------
  9415. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9416. TListItem * /*Item*/, bool /*Selected*/)
  9417. {
  9418. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9419. switch (DirView->LastSelectMethod)
  9420. {
  9421. case smKeyboard:
  9422. Configuration->Usage->Inc(L"KeyboardSelections");
  9423. break;
  9424. case smMouse:
  9425. Configuration->Usage->Inc(L"MouseSelections");
  9426. break;
  9427. }
  9428. }
  9429. //---------------------------------------------------------------------------
  9430. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9431. {
  9432. if (Color != 0)
  9433. {
  9434. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9435. }
  9436. else
  9437. {
  9438. return FSessionTabImageIndex;
  9439. }
  9440. }
  9441. //---------------------------------------------------------------------------
  9442. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9443. {
  9444. TPngImageCollectionItem * Item =
  9445. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9446. FSessionColors->AddPng(Item->PngImage);
  9447. return FSessionColors->Count - 1;
  9448. }
  9449. //---------------------------------------------------------------------------
  9450. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9451. {
  9452. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9453. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9454. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9455. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9456. }
  9457. //---------------------------------------------------------------------------
  9458. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9459. {
  9460. for (int Index = 0; Index < Control->ControlCount; Index++)
  9461. {
  9462. TControl * AControl = Control->Controls[Index];
  9463. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9464. if (WinControl != NULL)
  9465. {
  9466. CollectItemsWithTextDisplayMode(WinControl);
  9467. }
  9468. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9469. if (Toolbar != NULL)
  9470. {
  9471. // we care for top-level items only
  9472. TTBCustomItem * Items = Toolbar->Items;
  9473. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9474. {
  9475. TTBCustomItem * Item = Items->Items[ItemIndex];
  9476. if (((Item->DisplayMode == nbdmImageAndText) ||
  9477. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9478. EligibleForImageDisplayMode(Item))
  9479. {
  9480. FItemsWithTextDisplayMode.insert(Item);
  9481. }
  9482. }
  9483. }
  9484. }
  9485. }
  9486. //---------------------------------------------------------------------------
  9487. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9488. {
  9489. return true;
  9490. }
  9491. //---------------------------------------------------------------------------
  9492. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9493. {
  9494. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9495. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9496. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9497. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9498. bool Result = true;
  9499. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9500. {
  9501. TTBCustomItem * Item = *i;
  9502. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9503. if (Label != NULL)
  9504. {
  9505. // optimization
  9506. if (Label->Visible == SelectiveToolbarText)
  9507. {
  9508. Result = false;
  9509. }
  9510. else
  9511. {
  9512. Label->Visible = SelectiveToolbarText;
  9513. }
  9514. }
  9515. else
  9516. {
  9517. // optimization
  9518. if (Item->DisplayMode == DisplayMode)
  9519. {
  9520. Result = false;
  9521. }
  9522. else
  9523. {
  9524. Item->DisplayMode = DisplayMode;
  9525. }
  9526. }
  9527. ++i;
  9528. }
  9529. if (Result)
  9530. {
  9531. UpdateNewSessionTab();
  9532. }
  9533. return Result;
  9534. }
  9535. //---------------------------------------------------------------------------
  9536. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9537. {
  9538. DebugFail();
  9539. }
  9540. //---------------------------------------------------------------------------
  9541. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9542. {
  9543. // Among other, a lock level is non zero, while directory is being loaded,
  9544. // even when it happens as a result of dirview navigation,
  9545. // i.e. when TNonVisualDataModule is NOT FBusy.
  9546. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9547. // Among other this prevents a panel auto update to occur while
  9548. // directory is changing.
  9549. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9550. }
  9551. //---------------------------------------------------------------------------
  9552. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  9553. {
  9554. // While the window is disabled, we still seem to process menu shortcuts at least,
  9555. // so stop it at least here.
  9556. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9557. return
  9558. (Allowed == aaUpdate) ||
  9559. !NonVisualDataModule->Busy;
  9560. }
  9561. //---------------------------------------------------------------------------
  9562. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9563. {
  9564. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9565. }
  9566. //---------------------------------------------------------------------------
  9567. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9568. {
  9569. // This is somewhat redundant to LockWindow() call from
  9570. // TTerminalManager::TerminalReadDirectoryProgress.
  9571. // But disabling window is known not to block keyboard shorcuts
  9572. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9573. if (Busy > 0)
  9574. {
  9575. if (NonVisualDataModule->Busy)
  9576. {
  9577. State = false;
  9578. }
  9579. else
  9580. {
  9581. NonVisualDataModule->StartBusy();
  9582. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9583. LockWindow();
  9584. }
  9585. }
  9586. else if (Busy < 0)
  9587. {
  9588. UnlockWindow();
  9589. NonVisualDataModule->EndBusy();
  9590. }
  9591. else
  9592. {
  9593. State = NonVisualDataModule->Busy;
  9594. }
  9595. }
  9596. //---------------------------------------------------------------------------
  9597. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9598. {
  9599. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9600. // no context menu for "New session tab"
  9601. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9602. {
  9603. SessionsPageControl->ActivePageIndex = Index;
  9604. if (DebugAlwaysTrue(SessionTabSwitched()))
  9605. {
  9606. // copied from TControl.WMContextMenu
  9607. SendCancelMode(SessionsPageControl);
  9608. // explicit popup instead of using PopupMenu property
  9609. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9610. // while connecting yet not-connected session and hence
  9611. // allowing an access to commands over not-completelly connected session
  9612. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9613. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9614. PopupMenu->PopupComponent = SessionsPageControl;
  9615. PopupMenu->Popup(Point.x, Point.y);
  9616. }
  9617. }
  9618. Handled = true;
  9619. }
  9620. //---------------------------------------------------------------------------
  9621. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9622. {
  9623. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9624. }
  9625. //---------------------------------------------------------------------------
  9626. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9627. {
  9628. Configuration->Usage->Inc(L"PasswordChanges");
  9629. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9630. ChangePasswordData->DisableAuthentationsExceptPassword();
  9631. ChangePasswordData->ChangePassword = true;
  9632. std::unique_ptr<TTerminal> ChangePasswordSession(
  9633. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9634. ChangePasswordSession->AutoReadDirectory = false;
  9635. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9636. {
  9637. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9638. }
  9639. else
  9640. {
  9641. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9642. }
  9643. }
  9644. //---------------------------------------------------------------------------
  9645. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9646. {
  9647. // No nice way to assert SSH2
  9648. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9649. }
  9650. //---------------------------------------------------------------------------
  9651. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9652. {
  9653. TOperationVisualizer OperationVisualizer;
  9654. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9655. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9656. }
  9657. //---------------------------------------------------------------------------
  9658. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9659. {
  9660. TForm::ChangeScale(M, D);
  9661. int APixelsPerInch = GetControlPixelsPerInch(this);
  9662. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9663. try
  9664. {
  9665. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9666. }
  9667. __finally
  9668. {
  9669. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9670. }
  9671. }
  9672. //---------------------------------------------------------------------------
  9673. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9674. {
  9675. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9676. }
  9677. //---------------------------------------------------------------------
  9678. class TPublicControl : public TControl
  9679. {
  9680. friend class TCustomScpExplorerForm;
  9681. };
  9682. //---------------------------------------------------------------------------
  9683. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9684. {
  9685. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9686. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9687. }
  9688. //---------------------------------------------------------------------------
  9689. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9690. {
  9691. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9692. OpenBookmark(Side, Bookmark);
  9693. }
  9694. //---------------------------------------------------------------------------
  9695. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9696. {
  9697. DoBookmarkClick(osLocal, Sender);
  9698. }
  9699. //---------------------------------------------------------------------------
  9700. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9701. {
  9702. DoBookmarkClick(osRemote, Sender);
  9703. }
  9704. //---------------------------------------------------------------------------
  9705. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9706. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9707. {
  9708. // TODO
  9709. if (BookmarkList != NULL)
  9710. {
  9711. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9712. if (!WinConfiguration->UseLocationProfiles)
  9713. {
  9714. std::unique_ptr<TStringList> Directories(new TStringList());
  9715. Directories->CaseSensitive = (Side == osRemote);
  9716. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9717. {
  9718. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9719. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9720. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9721. {
  9722. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9723. Item->Caption = EscapeHotkey(Directory);
  9724. Item->ShortCut = Bookmark->ShortCut;
  9725. Item->OnClick = OnBookmarkClick;
  9726. Item->Tag = reinterpret_cast<int>(Bookmark);
  9727. Directories->Add(Directory);
  9728. Menu->Add(Item.release());
  9729. }
  9730. }
  9731. }
  9732. else
  9733. {
  9734. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9735. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9736. {
  9737. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9738. if (!Bookmark->Node.IsEmpty())
  9739. {
  9740. Folders->Add(Bookmark->Node);
  9741. }
  9742. }
  9743. for (int Index = 0; Index < Folders->Count; Index++)
  9744. {
  9745. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9746. Item->Caption = Folders->Strings[Index];
  9747. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction->ImageIndex;
  9748. Folders->Objects[Index] = Item.get();
  9749. Menu->Add(Item.release());
  9750. }
  9751. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9752. {
  9753. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9754. TTBCustomItem * Parent;
  9755. if (!Bookmark->Node.IsEmpty())
  9756. {
  9757. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9758. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9759. }
  9760. else
  9761. {
  9762. Parent = Menu;
  9763. }
  9764. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9765. Item->Caption = Bookmark->Name;
  9766. Item->ShortCut = Bookmark->ShortCut;
  9767. Item->OnClick = OnBookmarkClick;
  9768. Item->Tag = reinterpret_cast<int>(Bookmark);
  9769. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9770. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9771. {
  9772. // No hint for location profiles that are actually mere "bookmarks"
  9773. }
  9774. else
  9775. {
  9776. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9777. UnicodeString LongHint;
  9778. if (!Bookmark->Local.IsEmpty())
  9779. {
  9780. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9781. }
  9782. if (!Bookmark->Remote.IsEmpty())
  9783. {
  9784. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9785. }
  9786. AddToList(Hint, LongHint, L"|");
  9787. Item->Hint = Hint;
  9788. }
  9789. Parent->Add(Item.release());
  9790. }
  9791. }
  9792. AddMenuSeparator(Menu);
  9793. }
  9794. }
  9795. //---------------------------------------------------------------------------
  9796. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9797. {
  9798. Menu->Clear();
  9799. std::unique_ptr<TTBCustomItem> Item;
  9800. Item.reset(new TTBXItem(Owner));
  9801. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9802. Item->Options = Item->Options << tboDefault;
  9803. Menu->Add(Item.release());
  9804. AddMenuSeparator(Menu);
  9805. if (Terminal != NULL)
  9806. {
  9807. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9808. }
  9809. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9810. Item.reset(new TTBXItem(Owner));
  9811. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction : NonVisualDataModule->RemoteAddBookmarkAction;
  9812. Menu->Add(Item.release());
  9813. }
  9814. //---------------------------------------------------------------------------
  9815. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9816. {
  9817. bool Result = true;
  9818. try
  9819. {
  9820. if (Side == osRemote)
  9821. {
  9822. Terminal->ExceptionOnFail = true;
  9823. }
  9824. try
  9825. {
  9826. DirView(Side)->Path = Path;
  9827. }
  9828. __finally
  9829. {
  9830. if (Side == osRemote)
  9831. {
  9832. Terminal->ExceptionOnFail = false;
  9833. }
  9834. }
  9835. }
  9836. catch (Exception & E)
  9837. {
  9838. if ((Side != osRemote) || Terminal->Active)
  9839. {
  9840. ShowExtendedExceptionEx(Terminal, &E);
  9841. Result = false;
  9842. }
  9843. else
  9844. {
  9845. throw;
  9846. }
  9847. }
  9848. return Result;
  9849. }
  9850. //---------------------------------------------------------------------------
  9851. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9852. {
  9853. // Make sure there some feedback even when loading tiny local folders
  9854. TInstantOperationVisualizer Visualizer;
  9855. DirView(Side)->ReloadDirectory();
  9856. }
  9857. //---------------------------------------------------------------------------
  9858. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9859. {
  9860. if (Index == SessionsPageControl->TabIndex)
  9861. {
  9862. CloseSession();
  9863. }
  9864. else
  9865. {
  9866. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9867. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9868. TTerminalManager * Manager = TTerminalManager::Instance();
  9869. if (!Terminal->Active)
  9870. {
  9871. Manager->FreeTerminal(Terminal);
  9872. }
  9873. else
  9874. {
  9875. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9876. if (CanCloseQueue(Queue))
  9877. {
  9878. Manager->FreeTerminal(Terminal);
  9879. }
  9880. }
  9881. }
  9882. }
  9883. //---------------------------------------------------------------------------
  9884. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9885. {
  9886. CloseSessionTab(Index);
  9887. }
  9888. //---------------------------------------------------------------------------
  9889. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9890. {
  9891. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9892. {
  9893. TInstantOperationVisualizer Visualizer;
  9894. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9895. // before we create a new data object
  9896. ClipboardClear();
  9897. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9898. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9899. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9900. // Intermediate variable to WORKAROUND a crash in compiler
  9901. TObjectList * ClipboardFakeMonitors =
  9902. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9903. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9904. if (FClipboardDragDropFilesEx.get() == NULL)
  9905. {
  9906. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9907. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9908. }
  9909. FClipboardDragDropFilesEx->FileList->Clear();
  9910. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9911. FClipboardDragDropFilesEx->CopyToClipboard();
  9912. FClipboardTerminal = FTerminal;
  9913. // Need full paths, as cwd can be different once files are pasted
  9914. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9915. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9916. {
  9917. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9918. }
  9919. }
  9920. }
  9921. //---------------------------------------------------------------------------
  9922. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9923. {
  9924. if (OpenClipboard(0))
  9925. {
  9926. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9927. CloseClipboard();
  9928. }
  9929. }
  9930. //---------------------------------------------------------------------------
  9931. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9932. {
  9933. return !FClipboardFakeDirectory.IsEmpty();
  9934. }
  9935. //---------------------------------------------------------------------------
  9936. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9937. {
  9938. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9939. FClipboardFakeDirectory = UnicodeString();
  9940. FClipboardTerminal = NULL;
  9941. // Also called in Idle()
  9942. FClipboardFakeMonitors.reset(NULL);
  9943. }
  9944. //---------------------------------------------------------------------------
  9945. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9946. {
  9947. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9948. {
  9949. ClipboardStop();
  9950. }
  9951. }
  9952. //---------------------------------------------------------------------------
  9953. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9954. {
  9955. TTerminalManager * Manager = TTerminalManager::Instance();
  9956. Manager->ActiveTerminal = FClipboardTerminal;
  9957. TTransferOperationParam Params;
  9958. Params.TargetDirectory = TargetDirectory;
  9959. Params.DragDrop = DragDrop;
  9960. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  9961. }
  9962. //---------------------------------------------------------------------------
  9963. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  9964. {
  9965. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  9966. // (as it pumps a Windows message queue while being shutted down)
  9967. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  9968. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  9969. {
  9970. // Can fail as it can be e.g. locked by AV, so we retry that later
  9971. bool Removed = RemoveDir(ApiPath(FileName));
  9972. try
  9973. {
  9974. if (!NonVisualDataModule->Busy)
  9975. {
  9976. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  9977. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  9978. }
  9979. }
  9980. __finally
  9981. {
  9982. if (!Removed)
  9983. {
  9984. RemoveDir(ApiPath(FileName));
  9985. }
  9986. }
  9987. }
  9988. }
  9989. //---------------------------------------------------------------------------
  9990. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  9991. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  9992. {
  9993. TFileMasks::TParams MaskParams;
  9994. MaskParams.Size = Size;
  9995. MaskParams.Modification = Modification;
  9996. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  9997. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  9998. {
  9999. bool ImplicitMatch;
  10000. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  10001. !ImplicitMatch)
  10002. {
  10003. Color = Iter->Color;
  10004. break;
  10005. }
  10006. }
  10007. }
  10008. //---------------------------------------------------------------------------
  10009. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10010. {
  10011. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10012. if (!DirView->IsEditing())
  10013. {
  10014. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10015. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10016. // while searching
  10017. if (Key == VK_BACK)
  10018. {
  10019. if (!FIncrementalSearch.IsEmpty())
  10020. {
  10021. if (FIncrementalSearch.Length() == 1)
  10022. {
  10023. ResetIncrementalSearch();
  10024. }
  10025. else
  10026. {
  10027. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10028. IncrementalSearch(NewText, false, false);
  10029. }
  10030. Key = 0;
  10031. }
  10032. }
  10033. }
  10034. }
  10035. //---------------------------------------------------------------------------
  10036. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10037. {
  10038. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10039. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10040. {
  10041. // Filter control sequences.
  10042. // When not searching yet, prefer use of the space for toggling file selection
  10043. // (so we cannot incrementally search for a string starting with a space).
  10044. if ((Key > VK_SPACE) ||
  10045. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10046. {
  10047. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10048. Key = 0;
  10049. }
  10050. }
  10051. }
  10052. //---------------------------------------------------------------------------
  10053. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10054. {
  10055. if (!FIncrementalSearch.IsEmpty())
  10056. {
  10057. FIncrementalSearch = L"";
  10058. DirView(osCurrent)->UpdateStatusBar();
  10059. }
  10060. }
  10061. //---------------------------------------------------------------------------
  10062. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10063. {
  10064. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10065. if (Item == NULL)
  10066. {
  10067. MessageBeep(MB_ICONHAND);
  10068. }
  10069. else
  10070. {
  10071. TCustomDirView * ADirView = DirView(osCurrent);
  10072. {
  10073. TAutoNestingCounter Guard(FIncrementalSearching);
  10074. ADirView->FocusItem(Item);
  10075. if (ADirView->NortonLike == nlOff)
  10076. {
  10077. if ((ADirView->Selected != Item) ||
  10078. (ADirView->SelCount > 1))
  10079. {
  10080. ADirView->ClearSelection();
  10081. ADirView->Selected = Item;
  10082. }
  10083. }
  10084. }
  10085. FIncrementalSearch = Text;
  10086. Item->MakeVisible(false);
  10087. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10088. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10089. ADirView->UpdateStatusBar();
  10090. }
  10091. }
  10092. //---------------------------------------------------------------------------
  10093. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10094. {
  10095. int Index = Item->Index;
  10096. if (!Reverse)
  10097. {
  10098. Index++;
  10099. if (Index >= Item->Owner->Count)
  10100. {
  10101. Index = 0;
  10102. }
  10103. }
  10104. else
  10105. {
  10106. Index--;
  10107. if (Index < 0)
  10108. {
  10109. Index = Item->Owner->Count - 1;
  10110. }
  10111. }
  10112. return Item->Owner->Item[Index];
  10113. }
  10114. //---------------------------------------------------------------------------
  10115. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10116. {
  10117. TCustomDirView * ADirView = DirView(osCurrent);
  10118. if (ADirView->Items->Count == 0)
  10119. {
  10120. return NULL;
  10121. }
  10122. else
  10123. {
  10124. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10125. TListItem * Item = CurrentItem;
  10126. if (SkipCurrent)
  10127. {
  10128. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10129. }
  10130. while (true)
  10131. {
  10132. bool Matches = false;
  10133. switch (WinConfiguration->PanelSearch)
  10134. {
  10135. case isNameStartOnly:
  10136. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10137. break;
  10138. case isName:
  10139. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10140. break;
  10141. case isAll:
  10142. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10143. int Index = 0;
  10144. while ((Index < ColCount) && !Matches)
  10145. {
  10146. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10147. if (Visible)
  10148. {
  10149. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10150. }
  10151. Index++;
  10152. }
  10153. break;
  10154. }
  10155. if (Matches)
  10156. {
  10157. return Item;
  10158. }
  10159. Item = GetNextFile(Item, Reverse);
  10160. if (Item == CurrentItem)
  10161. {
  10162. return NULL;
  10163. }
  10164. }
  10165. }
  10166. }
  10167. //---------------------------------------------------------------------------
  10168. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10169. {
  10170. ResetIncrementalSearch();
  10171. }
  10172. //---------------------------------------------------------------------------
  10173. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10174. {
  10175. if (Message.CharCode == VK_TAB)
  10176. {
  10177. if (!FIncrementalSearch.IsEmpty())
  10178. {
  10179. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10180. bool Reverse = Shift.Contains(ssShift);
  10181. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10182. Message.Result = 1;
  10183. return;
  10184. }
  10185. }
  10186. else if (Message.CharCode == VK_ESCAPE)
  10187. {
  10188. if (!FIncrementalSearch.IsEmpty())
  10189. {
  10190. ResetIncrementalSearch();
  10191. Message.Result = 1;
  10192. return;
  10193. }
  10194. }
  10195. TForm::Dispatch(&Message);
  10196. }
  10197. //---------------------------------------------------------------------------
  10198. void __fastcall TCustomScpExplorerForm::Deactivate()
  10199. {
  10200. TForm::Deactivate();
  10201. // E.g. when switching to an internal editor window
  10202. ResetIncrementalSearch();
  10203. }
  10204. //---------------------------------------------------------------------------
  10205. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10206. {
  10207. // When switching to another application
  10208. ResetIncrementalSearch();
  10209. }
  10210. //---------------------------------------------------------------------------
  10211. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10212. {
  10213. ResetIncrementalSearch();
  10214. }
  10215. //---------------------------------------------------------------------------
  10216. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10217. {
  10218. if (FIncrementalSearching <= 0)
  10219. {
  10220. ResetIncrementalSearch();
  10221. }
  10222. }
  10223. //---------------------------------------------------------------------------
  10224. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10225. {
  10226. CountClicksForWindowPrint(this);
  10227. }
  10228. //---------------------------------------------------------------------------
  10229. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10230. {
  10231. CenterReconnectToolbar();
  10232. }
  10233. //---------------------------------------------------------------------------
  10234. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10235. {
  10236. if (RemoteDirView->ItemFocused != NULL)
  10237. {
  10238. RemoteDirView->ItemFocused->Selected = true;
  10239. }
  10240. }
  10241. //---------------------------------------------------------------------------
  10242. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10243. {
  10244. if (!FQueueStatusUpdating)
  10245. {
  10246. bool Refresh;
  10247. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10248. {
  10249. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10250. }
  10251. else
  10252. {
  10253. if (FQueueFileList->GetCount() > 0)
  10254. {
  10255. FQueueFileList->Clear();
  10256. Refresh = true;
  10257. }
  10258. }
  10259. int Count = FQueueFileList->GetCount();
  10260. if (QueueFileList->Items->Count != Count)
  10261. {
  10262. DebugAssert(Refresh);
  10263. QueueFileList->Items->Count = Count;
  10264. }
  10265. if (Refresh)
  10266. {
  10267. QueueFileList->Invalidate();
  10268. }
  10269. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10270. }
  10271. }
  10272. //---------------------------------------------------------------------------
  10273. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10274. {
  10275. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10276. }
  10277. //---------------------------------------------------------------------------
  10278. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10279. {
  10280. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10281. // See TSynchronizeChecklistDialog::UpdateTimer
  10282. if (QueueFileList->Items->Count > 0)
  10283. {
  10284. QueueFileList->Items->Item[0]->MakeVisible(false);
  10285. }
  10286. UpdateQueueFileList();
  10287. }
  10288. //---------------------------------------------------------------------------
  10289. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10290. {
  10291. Active = QueueView3->Focused() || QueueFileList->Focused();
  10292. }
  10293. //---------------------------------------------------------------------------
  10294. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10295. {
  10296. QueueLabelUpdateStatus();
  10297. }
  10298. //---------------------------------------------------------------------------
  10299. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10300. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10301. {
  10302. int State = FQueueFileList->GetState(Item->Index);
  10303. if (State == qfsProcessed)
  10304. {
  10305. Sender->Canvas->Font->Color = clGrayText;
  10306. }
  10307. }
  10308. //---------------------------------------------------------------------------
  10309. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10310. {
  10311. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10312. QueueFileList->Column[0]->Width =
  10313. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10314. }
  10315. //---------------------------------------------------------------------------
  10316. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10317. {
  10318. QueueFileListColumnAutoSize();
  10319. }
  10320. //---------------------------------------------------------------------------
  10321. void __fastcall TCustomScpExplorerForm::CloseApp()
  10322. {
  10323. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10324. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10325. // So we clear the flag here.
  10326. DebugAssert(NonVisualDataModule->Busy);
  10327. NonVisualDataModule->EndBusy();
  10328. try
  10329. {
  10330. Close();
  10331. }
  10332. __finally
  10333. {
  10334. NonVisualDataModule->StartBusy();
  10335. }
  10336. }
  10337. //---------------------------------------------------------------------------
  10338. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10339. {
  10340. return (Terminal != NULL) && Terminal->Active;
  10341. }
  10342. //---------------------------------------------------------------------------
  10343. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10344. {
  10345. return IsActiveTerminal(Terminal);
  10346. }