CustomScpExplorer.cpp 360 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961
  1. // TODO_OTHER_LOCAL
  2. //---------------------------------------------------------------------------
  3. #define NO_WIN32_LEAN_AND_MEAN
  4. #include <vcl.h>
  5. #pragma hdrstop
  6. #include <Common.h>
  7. #include "CustomScpExplorer.h"
  8. #include <Bookmarks.h>
  9. #include <Interface.h>
  10. #include <Exceptions.h>
  11. #include <CoreMain.h>
  12. #include <FileSystems.h>
  13. #include <TextsCore.h>
  14. #include <TextsWin.h>
  15. #include <HelpWin.h>
  16. #include <VCLCommon.h>
  17. #include <Progress.h>
  18. #include <SynchronizeProgress.h>
  19. #include <DragExt.h>
  20. #include <WinApi.h>
  21. #include "GUITools.h"
  22. #include "NonVisual.h"
  23. #include "Glyphs.h"
  24. #include "Tools.h"
  25. #include "WinConfiguration.h"
  26. #include "TerminalManager.h"
  27. #include "EditorManager.h"
  28. #include "ProgParams.h"
  29. #include "Setup.h"
  30. #include <Consts.hpp>
  31. #include <DateUtils.hpp>
  32. #include <TB2Common.hpp>
  33. #include <DirectoryMonitor.hpp>
  34. #include <System.IOUtils.hpp>
  35. //---------------------------------------------------------------------------
  36. #pragma package(smart_init)
  37. #pragma link "CustomDirView"
  38. #pragma link "CustomUnixDirView"
  39. #pragma link "IEListView"
  40. #pragma link "NortonLikeListView"
  41. #pragma link "UnixDirView"
  42. #pragma link "CustomDriveView"
  43. #pragma link "UnixDriveView"
  44. #pragma link "CustomDriveView"
  45. #pragma link "TB2Dock"
  46. #pragma link "TBXStatusBars"
  47. #pragma link "TB2Item"
  48. #pragma link "TB2Toolbar"
  49. #pragma link "ThemePageControl"
  50. #pragma link "PathLabel"
  51. #pragma resource "*.dfm"
  52. //---------------------------------------------------------------------------
  53. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  54. static const int SessionPanelCount = 4;
  55. //---------------------------------------------------------------------------
  56. class TMutexGuard
  57. {
  58. public:
  59. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  60. int Timeout = 5000)
  61. {
  62. FMutex = NULL;
  63. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  64. if (WaitResult == WAIT_TIMEOUT)
  65. {
  66. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  67. }
  68. else
  69. {
  70. FMutex = AMutex;
  71. }
  72. }
  73. ~TMutexGuard()
  74. {
  75. if (FMutex != NULL)
  76. {
  77. ReleaseMutex(FMutex);
  78. }
  79. }
  80. private:
  81. HANDLE FMutex;
  82. };
  83. //---------------------------------------------------------------------------
  84. class TWindowLock
  85. {
  86. public:
  87. TWindowLock(TCustomScpExplorerForm * Form) :
  88. FForm(Form)
  89. {
  90. FForm->LockWindow();
  91. }
  92. ~TWindowLock()
  93. {
  94. FForm->UnlockWindow();
  95. }
  96. private:
  97. TCustomScpExplorerForm * FForm;
  98. };
  99. //---------------------------------------------------------------------------
  100. class TAutoBatch
  101. {
  102. public:
  103. TAutoBatch(TCustomScpExplorerForm * Form) :
  104. FForm(Form)
  105. {
  106. FForm->BatchStart(FBatchStorage);
  107. }
  108. ~TAutoBatch()
  109. {
  110. FForm->BatchEnd(FBatchStorage);
  111. }
  112. private:
  113. TCustomScpExplorerForm * FForm;
  114. void * FBatchStorage;
  115. };
  116. //---------------------------------------------------------------------------
  117. struct TTransferOperationParam
  118. {
  119. TTransferOperationParam();
  120. UnicodeString TargetDirectory;
  121. bool Temp;
  122. bool DragDrop;
  123. int Options;
  124. TAutoSwitch Queue;
  125. };
  126. //---------------------------------------------------------------------------
  127. TTransferOperationParam::TTransferOperationParam()
  128. {
  129. Temp = false;
  130. DragDrop = false;
  131. Options = 0;
  132. Queue = asAuto;
  133. }
  134. //---------------------------------------------------------------------------
  135. class TTransferPresetNoteData : public TObject
  136. {
  137. public:
  138. UnicodeString Message;
  139. };
  140. //---------------------------------------------------------------------------
  141. class TTerminalNoteData : public TObject
  142. {
  143. public:
  144. TManagedTerminal * Terminal;
  145. };
  146. //---------------------------------------------------------------------------
  147. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  148. FFormRestored(false),
  149. TForm(Owner)
  150. {
  151. FInvalid = false;
  152. FCurrentSide = osRemote;
  153. FEverShown = false;
  154. FDocks = new TList();
  155. InitControls();
  156. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  157. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  158. NonVisualDataModule->ScpExplorer = this;
  159. RestoreParams();
  160. ConfigurationChanged();
  161. RemoteDirView->Invalidate();
  162. FAutoOperation = false;
  163. FOnFileOperationFinished = NULL;
  164. FForceExecution = false;
  165. FIgnoreNextDialogChar = 0;
  166. FErrorList = NULL;
  167. FSynchronizeProgressForm = NULL;
  168. FProgressForm = NULL;
  169. FRefreshLocalDirectory = false;
  170. FRefreshRemoteDirectory = false;
  171. FDDExtMapFile = NULL;
  172. // CreateMutexW keeps failing with ERROR_NOACCESS
  173. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  174. DebugAssert(FDDExtMutex != NULL);
  175. FDDTargetControl = NULL;
  176. FDelayedDeletionTimer = NULL;
  177. FDelayedDeletionList = new TStringList();
  178. FDDFileList = NULL;
  179. FPendingTempSpaceWarn = false;
  180. FCapturedLog = NULL;
  181. FDragDropOperation = false;
  182. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  183. FAllowTransferPresetAutoSelect = true;
  184. FCopyParamDefault = L"";
  185. FSynchronizeController = NULL;
  186. FPendingQueueActionItem = NULL;
  187. FLockLevel = 0;
  188. FLockSuspendLevel = 0;
  189. FDisabledOnLockSuspend = false;
  190. FAlternativeDelete = false;
  191. FTrayIcon = new ::TTrayIcon(0);
  192. FTrayIcon->OnClick = TrayIconClick;
  193. FMaxQueueLength = 0;
  194. FLastContextPopupScreenPoint = TPoint(-1, -1);
  195. FTransferResumeList = NULL;
  196. FMoveToQueue = false;
  197. FStandaloneEditing = false;
  198. FOnFeedSynchronizeError = NULL;
  199. FNeedSession = false;
  200. FDoNotIdleCurrentTerminal = 0;
  201. FIncrementalSearching = 0;
  202. FIncrementalSearchHaveNext = false;
  203. FQueueFileList.reset(new TQueueFileList());
  204. FProgressSide = osCurrent;
  205. FEditorManager = new TEditorManager();
  206. FEditorManager->OnFileChange = ExecutedFileChanged;
  207. FEditorManager->OnFileReload = ExecutedFileReload;
  208. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  209. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  210. FLocalEditors = new TList();
  211. FQueueStatus = NULL;
  212. FQueueStatusSection = new TCriticalSection();
  213. FQueueStatusInvalidated = false;
  214. FQueueItemInvalidated = false;
  215. FQueueStatusUpdating = false;
  216. FQueueActedItem = NULL;
  217. FQueueController = new TQueueController(QueueView3);
  218. FUserActionTimer = new TTimer(this);
  219. FUserActionTimer->Enabled = false;
  220. FUserActionTimer->Interval = 10;
  221. FUserActionTimer->OnTimer = UserActionTimer;
  222. FNotes = new TStringList();
  223. FNoteTimer = new TTimer(this);
  224. FNoteTimer->Enabled = false;
  225. FNoteTimer->OnTimer = NoteTimer;
  226. FOnNoteClick = NULL;
  227. FOle32Library = LoadLibrary(L"Ole32.dll");
  228. FDragMoveCursor = FOle32Library != NULL ?
  229. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  230. UseSystemSettings(this);
  231. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  232. static_cast<TObject*>(GetComponent(fcTransferList)));
  233. DebugAssert(TransferList != NULL);
  234. FTransferListHoverIndex = -1;
  235. TransferList->OnChange = TransferListChange;
  236. TransferList->OnDrawItem = TransferListDrawItem;
  237. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  238. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  239. UseDesktopFont(SessionsPageControl);
  240. UpdateSessionsPageControlHeight();
  241. UseDesktopFont(RemoteDirView);
  242. UseDesktopFont(RemoteDriveView);
  243. UseDesktopFont(QueueView3);
  244. UseDesktopFont(QueueFileList);
  245. UseDesktopFont(QueueLabel);
  246. UseDesktopFont(RemoteStatusBar);
  247. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  248. QueueSplitter->ShowHint = true;
  249. reinterpret_cast<TLabel*>(QueueFileListSplitter)->OnDblClick = QueueFileListSplitterDblClick;
  250. QueueFileListSplitter->ShowHint = true;
  251. RemotePanelSplitter->ShowHint = true;
  252. UpdateImages();
  253. FCustomCommandMenu = CreateTBXPopupMenu(this);
  254. FCustomCommandLocalFileList = NULL;
  255. FCustomCommandRemoteFileList = NULL;
  256. FSessionColors = new TPngImageList(this);
  257. FSessionColors->ColorDepth = cd32Bit;
  258. AddFixedSessionImages();
  259. SessionsPageControl->Images = FSessionColors;
  260. UpdateQueueLabel();
  261. CreateHiddenWindow();
  262. StartUpdates();
  263. }
  264. //---------------------------------------------------------------------------
  265. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  266. {
  267. FInvalid = true;
  268. // this has to be one of the very first things to do
  269. StopUpdateThread();
  270. // This is needed when shuting down Windows only. Otherwise it's already set NULL from Execute()
  271. TTerminalManager::Instance()->ScpExplorer = NULL;
  272. delete FCustomCommandLocalFileList;
  273. delete FCustomCommandRemoteFileList;
  274. delete FCustomCommandMenu;
  275. delete FTrayIcon;
  276. FTrayIcon = NULL;
  277. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  278. delete FEditorManager;
  279. ForceCloseLocalEditors();
  280. delete FLocalEditors;
  281. HideFileFindDialog();
  282. if (FDelayedDeletionTimer)
  283. {
  284. DoDelayedDeletion(NULL);
  285. SAFE_DESTROY(FDelayedDeletionTimer);
  286. }
  287. SAFE_DESTROY(FDelayedDeletionList);
  288. // sometimes we do not get DDEnd so the list is not released
  289. SAFE_DESTROY(FDDFileList);
  290. DebugAssert(FSynchronizeController == NULL);
  291. CloseHandle(FDDExtMutex);
  292. FDDExtMutex = NULL;
  293. FreeLibrary(FOle32Library);
  294. FOle32Library = NULL;
  295. FDragMoveCursor = NULL;
  296. DebugAssert(!FErrorList);
  297. if (FEverShown)
  298. {
  299. // when window is never shown (like when running command-line operation),
  300. // particularly window site is not restored correctly (BoundsRect value set
  301. // in RestoreForm gets lost during handle allocation), so we do not want
  302. // it to be stored
  303. StoreParams();
  304. }
  305. Terminal = NULL;
  306. Queue = NULL;
  307. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  308. NonVisualDataModule->ScpExplorer = NULL;
  309. delete FQueueController;
  310. FQueueController = NULL;
  311. delete FQueueStatusSection;
  312. FQueueStatusSection = NULL;
  313. delete FQueueStatus;
  314. FQueueStatus = NULL;
  315. delete FUserActionTimer;
  316. FUserActionTimer = NULL;
  317. delete FNoteTimer;
  318. delete FNotes;
  319. delete FNoteData;
  320. SAFE_DESTROY(FDocks);
  321. SessionsPageControl->Images = NULL;
  322. // only after clearing Terminal (after DoTerminalListChanged => ... => AddSessionColor is called)
  323. SAFE_DESTROY(FSessionColors);
  324. SAFE_DESTROY(FSessionsDragDropFilesEx);
  325. SAFE_DESTROY(FHistoryMenu[0][0]);
  326. SAFE_DESTROY(FHistoryMenu[0][1]);
  327. SAFE_DESTROY(FHistoryMenu[1][0]);
  328. SAFE_DESTROY(FHistoryMenu[1][1]);
  329. if (FHiddenWindow != NULL)
  330. {
  331. DestroyWindow(FHiddenWindow);
  332. FHiddenWindow = NULL;
  333. }
  334. }
  335. //---------------------------------------------------------------------------
  336. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  337. {
  338. std::unique_ptr<TSessionData> Data;
  339. if (!Session.IsEmpty())
  340. {
  341. bool DefaultsOnly;
  342. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  343. }
  344. TTerminalManager * Manager = TTerminalManager::Instance();
  345. for (int Index = 0; Index < Manager->Count; Index++)
  346. {
  347. TTerminal * Terminal = Manager->Terminals[Index];
  348. if (Session.IsEmpty() ||
  349. Manager->IsActiveTerminalForSite(Terminal, Data.get()))
  350. {
  351. if (Path.IsEmpty())
  352. {
  353. Terminal->ClearCaches();
  354. }
  355. else
  356. {
  357. Terminal->DirectoryModified(Path, true);
  358. }
  359. }
  360. }
  361. // We should flag a pending refresh for the background terminals or busy foreground terminals
  362. if (HasActiveTerminal() &&
  363. CanCommandLineFromAnotherInstance() &&
  364. (Session.IsEmpty() || Manager->IsActiveTerminalForSite(Terminal, Data.get())) &&
  365. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  366. {
  367. Terminal->ReloadDirectory();
  368. }
  369. }
  370. //---------------------------------------------------------------------------
  371. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  372. {
  373. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  374. size_t MessageSize = sizeof(TCopyDataMessage);
  375. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  376. if (Result)
  377. {
  378. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  379. Result = (Message.Version == TCopyDataMessage::Version1);
  380. if (Result)
  381. {
  382. switch (Message.Command)
  383. {
  384. case TCopyDataMessage::CommandCanCommandLine:
  385. Result = CanCommandLineFromAnotherInstance();
  386. break;
  387. case TCopyDataMessage::CommandCommandLine:
  388. {
  389. UnicodeString CommandLine(Message.CommandLine);
  390. Result = CommandLineFromAnotherInstance(CommandLine);
  391. }
  392. break;
  393. case TCopyDataMessage::RefreshPanel:
  394. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  395. break;
  396. case TCopyDataMessage::MainWindowCheck:
  397. Result = true;
  398. break;
  399. default:
  400. Result = false;
  401. break;
  402. }
  403. }
  404. }
  405. Message.Result = Result ? 1 : 0;
  406. }
  407. //---------------------------------------------------------------------------
  408. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  409. {
  410. WNDCLASS WindowClass = {0};
  411. WindowClass.lpfnWndProc = DefWindowProc;
  412. WindowClass.hInstance = HInstance;
  413. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  414. FHiddenWindow = NULL;
  415. if (RegisterClass(&WindowClass))
  416. {
  417. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  418. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  419. }
  420. }
  421. //---------------------------------------------------------------------------
  422. bool __fastcall TCustomScpExplorerForm::CanConsole()
  423. {
  424. return
  425. HasActiveTerminal() &&
  426. (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  427. }
  428. //---------------------------------------------------------------------------
  429. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  430. {
  431. bool Result = Visible && !NonVisualDataModule->Busy;
  432. return Result;
  433. }
  434. //---------------------------------------------------------------------------
  435. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  436. const UnicodeString & CommandLine)
  437. {
  438. TProgramParams Params(CommandLine);
  439. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  440. if (Result)
  441. {
  442. NonVisualDataModule->StartBusy();
  443. try
  444. {
  445. // this action is initiated from another process,
  446. // so it's likely that our window is not visible,
  447. // and user won't see what is going on
  448. Application->BringToFront();
  449. // reload sessions as we may be asked to open a session
  450. // just stored by another instance
  451. StoredSessions->Reload();
  452. UnicodeString SessionName = Params.Param[1];
  453. std::unique_ptr<TObjectList> DataList(new TObjectList());
  454. UnicodeString DownloadFile; // unused
  455. try
  456. {
  457. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  458. }
  459. catch (EAbort &)
  460. {
  461. // Happens when opening session in PuTTY and in other situations,
  462. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  463. // to process the command-line on its own (or to pass it to yet another instance)
  464. }
  465. if (DataList->Count > 0)
  466. {
  467. TTerminalManager * Manager = TTerminalManager::Instance();
  468. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  469. }
  470. }
  471. __finally
  472. {
  473. NonVisualDataModule->EndBusy();
  474. }
  475. }
  476. return Result;
  477. }
  478. //---------------------------------------------------------------------------
  479. void __fastcall TCustomScpExplorerForm::SetTerminal(TManagedTerminal * value)
  480. {
  481. if (FTerminal != value)
  482. {
  483. TerminalChanging();
  484. DoSetTerminal(value, false);
  485. }
  486. }
  487. //---------------------------------------------------------------------------
  488. void __fastcall TCustomScpExplorerForm::DoSetTerminal(TManagedTerminal * value, bool Replace)
  489. {
  490. FTerminal = value;
  491. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  492. FAllowTransferPresetAutoSelect = false;
  493. try
  494. {
  495. TerminalChanged(Replace);
  496. }
  497. __finally
  498. {
  499. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  500. }
  501. if (Terminal != NULL)
  502. {
  503. TransferPresetAutoSelect();
  504. }
  505. }
  506. //---------------------------------------------------------------------------
  507. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  508. {
  509. DoSetTerminal(value, true);
  510. }
  511. //---------------------------------------------------------------------------
  512. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  513. {
  514. if (FTerminal != NULL)
  515. {
  516. UpdateTerminal(Terminal);
  517. }
  518. }
  519. //---------------------------------------------------------------------------
  520. void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
  521. {
  522. if (Terminal != NULL)
  523. {
  524. UpdateSessionColor((TColor)Terminal->StateData->Color);
  525. }
  526. DoTerminalListChanged();
  527. DebugAssert(!IsLocalBrowserMode()); // TODO
  528. if (Replaced)
  529. {
  530. RemoteDirView->ReplaceTerminal(Terminal);
  531. }
  532. else
  533. {
  534. RemoteDirView->Terminal = Terminal;
  535. }
  536. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  537. if (Terminal != NULL)
  538. {
  539. if (Terminal->Active)
  540. {
  541. Terminal->RefreshDirectory();
  542. }
  543. if (WinConfiguration->PreservePanelState)
  544. {
  545. if (Terminal->RemoteExplorerState != NULL)
  546. {
  547. DirView(osRemote)->RestoreState(Terminal->RemoteExplorerState);
  548. }
  549. else
  550. {
  551. DirView(osRemote)->ClearState();
  552. }
  553. }
  554. if (!Replaced && Terminal->Active)
  555. {
  556. InitStatusBar();
  557. }
  558. }
  559. UpdateTransferList();
  560. // Update panels Enable state before refreshing the labels
  561. UpdateControls();
  562. }
  563. //---------------------------------------------------------------------------
  564. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  565. {
  566. if (Queue != value)
  567. {
  568. if (FQueue != NULL)
  569. {
  570. FQueue->OnListUpdate = NULL;
  571. FQueue->OnQueueItemUpdate = NULL;
  572. }
  573. FQueue = value;
  574. if (FQueue != NULL)
  575. {
  576. DebugAssert(FQueue->OnListUpdate == NULL);
  577. FQueue->OnListUpdate = QueueListUpdate;
  578. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  579. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  580. }
  581. QueueChanged();
  582. }
  583. }
  584. //---------------------------------------------------------------------------
  585. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  586. TListItem * Item)
  587. {
  588. if (FQueueActedItem == Item)
  589. {
  590. FQueueActedItem = NULL;
  591. if ((QueueView3->PopupMenu != NULL) &&
  592. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  593. {
  594. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  595. ReleaseCapture();
  596. }
  597. }
  598. if (Item->Data == FPendingQueueActionItem)
  599. {
  600. FPendingQueueActionItem = NULL;
  601. }
  602. }
  603. //---------------------------------------------------------------------------
  604. bool TCustomScpExplorerForm::IsAnythingQueued()
  605. {
  606. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  607. }
  608. //---------------------------------------------------------------------------
  609. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  610. {
  611. {
  612. TGuard Guard(FQueueStatusSection);
  613. FQueueStatusInvalidated = false;
  614. if (FQueue != NULL)
  615. {
  616. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  617. }
  618. }
  619. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  620. {
  621. FMaxQueueLength = FQueueStatus->Count;
  622. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  623. }
  624. {
  625. TAutoFlag Flag(FQueueStatusUpdating);
  626. FQueueController->UpdateQueueStatus(FQueueStatus);
  627. }
  628. UpdateQueueFileList();
  629. SetQueueProgress();
  630. UpdateQueueView();
  631. bool IsEmpty = !IsAnythingQueued();
  632. if (IsEmpty && (Terminal != NULL))
  633. {
  634. TOnceDoneOperation OnceDoneOperation =
  635. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  636. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  637. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  638. {
  639. FQueue->Enabled = false;
  640. }
  641. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  642. {
  643. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  644. }
  645. }
  646. }
  647. //---------------------------------------------------------------------------
  648. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  649. {
  650. UnicodeString Result;
  651. if (FQueueStatus != NULL)
  652. {
  653. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  654. {
  655. TFileOperationProgressType * ProgressData =
  656. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  657. if ((ProgressData != NULL) && ProgressData->InProgress)
  658. {
  659. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  660. }
  661. }
  662. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  663. {
  664. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  665. }
  666. }
  667. return Result;
  668. }
  669. //---------------------------------------------------------------------------
  670. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  671. {
  672. ComponentVisible[fcQueueView] =
  673. (WinConfiguration->QueueView.Show == qvShow) ||
  674. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  675. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  676. }
  677. //---------------------------------------------------------------------------
  678. void __fastcall TCustomScpExplorerForm::QueueChanged()
  679. {
  680. if (FQueueStatus != NULL)
  681. {
  682. // UpdateFileList implementation relies on the status being recreated when session changes
  683. delete FQueueStatus;
  684. FQueueStatus = NULL;
  685. }
  686. UpdateQueueStatus(true);
  687. }
  688. //---------------------------------------------------------------------------
  689. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  690. {
  691. if (FQueue == Queue)
  692. {
  693. FQueueStatusInvalidated = true;
  694. }
  695. }
  696. //---------------------------------------------------------------------------
  697. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  698. TQueueItem * Item)
  699. {
  700. if (FQueue == Queue)
  701. {
  702. TGuard Guard(FQueueStatusSection);
  703. // this may be running in parallel with QueueChanged
  704. if (FQueueStatus != NULL)
  705. {
  706. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  707. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  708. {
  709. FRefreshLocalDirectory = (QueueItem == NULL) ||
  710. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  711. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  712. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  713. }
  714. if (QueueItem != NULL)
  715. {
  716. QueueItem->UserData = (void*)true;
  717. FQueueItemInvalidated = true;
  718. }
  719. }
  720. }
  721. }
  722. //---------------------------------------------------------------------------
  723. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  724. {
  725. // during standalone editing, we have no way to see/control queue,
  726. // so we have to always popup prompts automatically
  727. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  728. }
  729. //---------------------------------------------------------------------------
  730. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  731. {
  732. if (FQueueStatus != NULL)
  733. {
  734. bool QueueAutoPopup = IsQueueAutoPopup();
  735. bool NeedRefresh = FQueueController->NeedRefresh();
  736. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  737. FQueueItemInvalidated = false;
  738. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  739. bool Updated = false;
  740. TQueueItemProxy * QueueItem;
  741. bool WasUserAction;
  742. for (int Index = 0; Index < Limit; Index++)
  743. {
  744. bool Update = false;
  745. QueueItem = FQueueStatus->Items[Index];
  746. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  747. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  748. (FPendingQueueActionItem == NULL))
  749. {
  750. FPendingQueueActionItem = QueueItem;
  751. FUserActionTimer->Enabled = true;
  752. }
  753. if ((bool)QueueItem->UserData)
  754. {
  755. QueueItem->UserData = (void*)false;
  756. QueueItem->Update();
  757. Updated = true;
  758. Update = true;
  759. }
  760. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  761. {
  762. Update = true;
  763. }
  764. if (Update)
  765. {
  766. FQueueController->RefreshQueueItem(QueueItem);
  767. }
  768. }
  769. if (Updated)
  770. {
  771. NonVisualDataModule->UpdateNonVisibleActions();
  772. SetQueueProgress();
  773. UpdateQueueFileList();
  774. }
  775. }
  776. }
  777. //---------------------------------------------------------------------------
  778. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  779. {
  780. if (FTaskbarList != NULL)
  781. {
  782. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  783. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  784. }
  785. }
  786. //---------------------------------------------------------------------------
  787. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  788. {
  789. if (Progress >= 0)
  790. {
  791. if (FTaskbarList != NULL)
  792. {
  793. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  794. }
  795. }
  796. else
  797. {
  798. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  799. }
  800. }
  801. //---------------------------------------------------------------------------
  802. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  803. {
  804. int OverallProgress;
  805. // FProgressForm is null when this is called from SetQueueProgress
  806. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  807. {
  808. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  809. }
  810. else if (!TFileOperationProgressType::IsIndeterminateOperation(ProgressData->Operation))
  811. {
  812. OverallProgress = ProgressData->OverallProgress();
  813. }
  814. else
  815. {
  816. OverallProgress = -1;
  817. }
  818. SetTaskbarListProgressValue(OverallProgress);
  819. }
  820. //---------------------------------------------------------------------------
  821. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  822. {
  823. TTerminalManager::Instance()->QueueStatusUpdated();
  824. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  825. {
  826. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  827. {
  828. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  829. {
  830. TFileOperationProgressType * ProgressData = NULL;
  831. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  832. {
  833. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  834. }
  835. if ((ProgressData != NULL) &&
  836. ProgressData->InProgress)
  837. {
  838. SetTaskbarListProgressValue(ProgressData);
  839. }
  840. else
  841. {
  842. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  843. }
  844. }
  845. else
  846. {
  847. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  848. }
  849. }
  850. else
  851. {
  852. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  853. }
  854. }
  855. UpdateQueueLabel();
  856. }
  857. //---------------------------------------------------------------------------
  858. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  859. {
  860. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  861. if (FQueueStatus != NULL)
  862. {
  863. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  864. if (ActiveAndPendingPrimaryCount > 0)
  865. {
  866. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  867. }
  868. }
  869. QueueLabel->Caption = Caption;
  870. }
  871. //---------------------------------------------------------------------------
  872. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  873. {
  874. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  875. static_cast<TComponent*>(GetComponent(fcTransferList)));
  876. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  877. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  878. TransferList->Strings->BeginUpdate();
  879. try
  880. {
  881. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  882. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  883. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  884. if (FTransferDropDownHint.IsEmpty())
  885. {
  886. FTransferDropDownHint = TransferDropDown->Hint;
  887. }
  888. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  889. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  890. TransferDropDown->Text = StripHotkey(Name);
  891. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  892. (FTransferDropDownHint, StripHotkey(Name),
  893. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  894. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  895. // update the label, otherwise when it is updated only on the first draw
  896. // of the list, it is drawn "bold" for some reason
  897. FTransferListHoverIndex = TransferList->ItemIndex;
  898. UpdateTransferLabel();
  899. }
  900. __finally
  901. {
  902. TransferList->Strings->EndUpdate();
  903. }
  904. }
  905. //---------------------------------------------------------------------------
  906. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  907. {
  908. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  909. DebugAssert(Toolbar != NULL);
  910. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  911. }
  912. //---------------------------------------------------------------------------
  913. void __fastcall TCustomScpExplorerForm::UpdateActions()
  914. {
  915. TForm::UpdateActions();
  916. if (ComponentVisible[fcCustomCommandsBand])
  917. {
  918. UpdateCustomCommandsToolbar();
  919. }
  920. }
  921. //---------------------------------------------------------------------------
  922. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  923. {
  924. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  925. }
  926. //---------------------------------------------------------------------------
  927. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  928. {
  929. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  930. {
  931. DirView->RowSelect = WinConfiguration->FullRowSelect;
  932. // selection is not redrawn automatically when RowSelect changes
  933. DirView->Invalidate();
  934. }
  935. }
  936. //---------------------------------------------------------------------------
  937. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  938. {
  939. Color = GetBtnFaceColor();
  940. DebugAssert(Configuration && RemoteDirView);
  941. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  942. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  943. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  944. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  945. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  946. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  947. UpdateRowSelect(RemoteDirView);
  948. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  949. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  950. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  951. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  952. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  953. UpdateSessionsPageControlHeight();
  954. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  955. UpdateToolbarDisplayMode();
  956. UpdateTransferList();
  957. if (Terminal != NULL)
  958. {
  959. TransferPresetAutoSelect();
  960. }
  961. UpdateQueueView();
  962. UpdateControls();
  963. // this can be called even before constuctor finishes.
  964. if (FEditorManager != NULL)
  965. {
  966. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  967. }
  968. // this can be called even before constuctor finishes.
  969. if (FLocalEditors != NULL)
  970. {
  971. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  972. {
  973. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  974. }
  975. }
  976. if (ComponentVisible[fcCustomCommandsBand])
  977. {
  978. UpdateCustomCommandsToolbar();
  979. }
  980. // show only when keeping queue items forever,
  981. // otherwise, its enough to have in in the context menu
  982. QueueDeleteAllDoneQueueToolbarItem->Visible =
  983. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  984. if (FFileColorsCurrent != WinConfiguration->FileColors)
  985. {
  986. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  987. FFileColorsCurrent = WinConfiguration->FileColors;
  988. FileColorsChanged();
  989. }
  990. }
  991. //---------------------------------------------------------------------------
  992. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  993. {
  994. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  995. DirView->Invalidate();
  996. }
  997. //---------------------------------------------------------------------------
  998. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  999. {
  1000. DoFileColorsChanged(RemoteDirView);
  1001. }
  1002. //---------------------------------------------------------------------------
  1003. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  1004. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  1005. void * /*Arg*/)
  1006. {
  1007. if (Token != NULL)
  1008. {
  1009. TForm * Editor = dynamic_cast<TForm*>(Token);
  1010. DebugAssert(Editor != NULL);
  1011. ReconfigureEditorForm(Editor);
  1012. }
  1013. }
  1014. //---------------------------------------------------------------------------
  1015. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1016. {
  1017. WinConfiguration->DDTransferConfirmation = asOn;
  1018. }
  1019. //---------------------------------------------------------------------------
  1020. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1021. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1022. {
  1023. // noop
  1024. }
  1025. //---------------------------------------------------------------------------
  1026. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1027. TTransferDirection Direction, TTransferType Type, bool Temp,
  1028. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1029. bool Confirm, bool DragDrop, int Options)
  1030. {
  1031. bool Result = true;
  1032. DebugAssert(HasActiveTerminal());
  1033. // these parameters are known in advance
  1034. int Params =
  1035. FLAGMASK(Type == ttMove, cpDelete);
  1036. bool ToTemp = (Temp && (Direction == tdToLocal));
  1037. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1038. {
  1039. bool DisableNewerOnly =
  1040. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1041. ToTemp;
  1042. Options |=
  1043. FLAGMASK(ToTemp, coTemp) |
  1044. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1045. coDoNotShowAgain;
  1046. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1047. int CopyParamAttrs = (Direction == tdToRemote ?
  1048. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1049. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1050. int OutputOptions =
  1051. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  1052. cooDoNotShowAgain);
  1053. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1054. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1055. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1056. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1057. if (Result)
  1058. {
  1059. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  1060. {
  1061. if (DragDrop)
  1062. {
  1063. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1064. {
  1065. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  1066. NULL, 0, EnableDDTransferConfirmation, NULL);
  1067. }
  1068. WinConfiguration->DDTransferConfirmation = asOff;
  1069. }
  1070. else
  1071. {
  1072. WinConfiguration->ConfirmTransferring = false;
  1073. }
  1074. }
  1075. else
  1076. {
  1077. // User explicitly unchecked "do not show again",
  1078. // so show him the dialog the next time
  1079. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1080. {
  1081. WinConfiguration->DDTransferConfirmation = asOn;
  1082. }
  1083. }
  1084. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1085. }
  1086. }
  1087. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1088. {
  1089. Configuration->Usage->Inc(L"TransfersOnBackground");
  1090. // these parameter are known only after transfer dialog
  1091. Params |=
  1092. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1093. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1094. Result = false;
  1095. ClearTransferSourceSelection(Direction);
  1096. }
  1097. return Result;
  1098. }
  1099. //---------------------------------------------------------------------------
  1100. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1101. {
  1102. if (FOnFileOperationFinished != NULL)
  1103. {
  1104. FOnFileOperationFinished(UnicodeString(), true);
  1105. }
  1106. else
  1107. {
  1108. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1109. if (HasDirView[Side])
  1110. {
  1111. DirView(Side)->SelectAll(smNone);
  1112. }
  1113. }
  1114. }
  1115. //---------------------------------------------------------------------------
  1116. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1117. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1118. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1119. int Params)
  1120. {
  1121. DebugAssert(Queue != NULL);
  1122. bool SingleFile = false;
  1123. if (FileList->Count == 1)
  1124. {
  1125. if (Direction == tdToRemote)
  1126. {
  1127. UnicodeString FileName = FileList->Strings[0];
  1128. SingleFile = FileExists(ApiPath(FileName));
  1129. }
  1130. else
  1131. {
  1132. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1133. SingleFile = !File->IsDirectory;
  1134. }
  1135. }
  1136. TQueueItem * QueueItem;
  1137. if (Direction == tdToRemote)
  1138. {
  1139. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1140. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1141. }
  1142. else
  1143. {
  1144. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1145. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1146. }
  1147. AddQueueItem(Queue, QueueItem, Terminal);
  1148. }
  1149. //---------------------------------------------------------------------------
  1150. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1151. {
  1152. if (Queue->IsEmpty)
  1153. {
  1154. Terminal->QueueOperationStart = Now();
  1155. }
  1156. Queue->AddItem(QueueItem);
  1157. }
  1158. //---------------------------------------------------------------------------
  1159. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1160. {
  1161. }
  1162. //---------------------------------------------------------------------------
  1163. void __fastcall TCustomScpExplorerForm::InitControls()
  1164. {
  1165. DebugAssert(FDocks != NULL);
  1166. for (int Index = 0; Index < ComponentCount; Index++)
  1167. {
  1168. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1169. if ((Dock != NULL) && (Dock->Tag == 0))
  1170. {
  1171. FDocks->Add(Dock);
  1172. }
  1173. }
  1174. CollectItemsWithTextDisplayMode(this);
  1175. }
  1176. //---------------------------------------------------------------------------
  1177. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1178. {
  1179. ConfigurationChanged();
  1180. QueuePanel->Height =
  1181. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1182. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1183. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1184. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1185. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1186. QueueFileList->Height =
  1187. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1188. if (QueueFileList->Visible)
  1189. {
  1190. AdjustQueueLayout();
  1191. }
  1192. UpdateCustomCommandsToolbar();
  1193. }
  1194. //---------------------------------------------------------------------------
  1195. void __fastcall TCustomScpExplorerForm::StoreParams()
  1196. {
  1197. int APixelsPerInch = GetControlPixelsPerInch(this);
  1198. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1199. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1200. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1201. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1202. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1203. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1204. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1205. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1206. }
  1207. //---------------------------------------------------------------------------
  1208. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1209. {
  1210. if (!FFormRestored)
  1211. {
  1212. FFormRestored = true;
  1213. RestoreFormParams();
  1214. }
  1215. TForm::CreateParams(Params);
  1216. }
  1217. //---------------------------------------------------------------------------
  1218. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1219. {
  1220. DebugAssert(FDocks != NULL);
  1221. for (int Index = 0; Index < FDocks->Count; Index++)
  1222. {
  1223. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1224. }
  1225. }
  1226. //---------------------------------------------------------------------------
  1227. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1228. {
  1229. SetDockAllowDrag(true);
  1230. while (!ButtonsStr.IsEmpty())
  1231. {
  1232. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1233. UnicodeString Name = CutToChar(S, L'=', true);
  1234. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1235. {
  1236. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1237. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1238. {
  1239. while (!S.IsEmpty())
  1240. {
  1241. UnicodeString S2 = CutToChar(S, L',', true);
  1242. UnicodeString Name = CutToChar(S2, L':', true);
  1243. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1244. {
  1245. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1246. if (SameText(GetToolbarItemName(Item), Name))
  1247. {
  1248. // forward compatibility
  1249. UnicodeString S3 = CutToChar(S2, L':', true);
  1250. bool Visible = StrToIntDef(S3, 0);
  1251. Item->Visible = Visible;
  1252. }
  1253. }
  1254. }
  1255. }
  1256. }
  1257. }
  1258. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1259. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1260. }
  1261. //---------------------------------------------------------------------------
  1262. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1263. {
  1264. UnicodeString Result;
  1265. SetDockAllowDrag(true);
  1266. Result = ::GetToolbarsLayoutStr(this);
  1267. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1268. return Result;
  1269. }
  1270. //---------------------------------------------------------------------------
  1271. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1272. {
  1273. UnicodeString Result;
  1274. if (Item->Action != NULL)
  1275. {
  1276. Result = Item->Action->Name;
  1277. Result = RemoveSuffix(Result, L"Action", true);
  1278. }
  1279. else
  1280. {
  1281. Result = Item->Name;
  1282. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1283. Result = RemoveSuffix(Result, L"Item", true);
  1284. }
  1285. return Result;
  1286. }
  1287. //---------------------------------------------------------------------------
  1288. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1289. {
  1290. UnicodeString Result;
  1291. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1292. {
  1293. UnicodeString ToolbarStr;
  1294. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1295. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1296. {
  1297. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1298. {
  1299. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1300. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1301. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1302. // and save the changes here only.
  1303. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1304. {
  1305. UnicodeString Name = GetToolbarItemName(Item);
  1306. DebugAssert(Name.Pos(L"TBX") == 0);
  1307. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1308. }
  1309. }
  1310. }
  1311. if (!ToolbarStr.IsEmpty())
  1312. {
  1313. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1314. }
  1315. }
  1316. return Result;
  1317. }
  1318. //---------------------------------------------------------------------------
  1319. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1320. {
  1321. DebugAssert(FProgressForm == NULL);
  1322. bool AllowSkip = (Terminal != NULL) ? Terminal->IsCapable[fcSkipTransfer] : false;
  1323. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL), AllowSkip, SynchronizeProgress);
  1324. FProgressForm->DeleteLocalToRecycleBin =
  1325. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1326. FProgressForm->DeleteRemoteToRecycleBin =
  1327. (Terminal != NULL) &&
  1328. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1329. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1330. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1331. LockWindow();
  1332. // Actually, do not know what hides the progress once the operation finishes
  1333. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1334. SetTaskbarListProgressState(TBPF_NORMAL);
  1335. }
  1336. //---------------------------------------------------------------------------
  1337. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1338. {
  1339. UnlockWindow();
  1340. SAFE_DESTROY(FProgressForm);
  1341. SetQueueProgress();
  1342. }
  1343. //---------------------------------------------------------------------------
  1344. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1345. TFileOperationProgressType & ProgressData)
  1346. {
  1347. // Download to temporary local directory
  1348. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1349. {
  1350. bool Continue = true;
  1351. FPendingTempSpaceWarn = false;
  1352. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1353. if (!Continue)
  1354. {
  1355. Abort();
  1356. }
  1357. }
  1358. // operation is being executed and we still didn't show up progress form
  1359. if (ProgressData.InProgress && !FProgressForm)
  1360. {
  1361. CreateProgressForm(NULL);
  1362. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1363. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1364. }
  1365. // operation is finished (or terminated), so we hide progress form
  1366. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1367. {
  1368. DestroyProgressForm();
  1369. if (ProgressData.Operation == foCalculateSize)
  1370. {
  1371. // When calculating size before transfer, the abort caused by
  1372. // cancel flag set due to "MoveToQueue" below,
  1373. // is not propagated back to us in ExecuteFileOperation,
  1374. // as it is silently swallowed.
  1375. // So we explicitly (re)throw it here.
  1376. if (FMoveToQueue)
  1377. {
  1378. Abort();
  1379. }
  1380. }
  1381. else
  1382. {
  1383. if ((ProgressData.Cancel == csContinue) &&
  1384. !FAutoOperation)
  1385. {
  1386. OperationComplete(ProgressData.StartTime);
  1387. }
  1388. }
  1389. }
  1390. if (FProgressForm &&
  1391. // Can happen only during synchronization, when ending one of the operations
  1392. ProgressData.InProgress)
  1393. {
  1394. FProgressForm->SetProgressData(ProgressData);
  1395. DebugAssert(ProgressData.InProgress);
  1396. SetTaskbarListProgressValue(&ProgressData);
  1397. if (FProgressForm->Cancel > csContinue)
  1398. {
  1399. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1400. if (FProgressForm->Cancel == csCancelFile)
  1401. {
  1402. FProgressForm->ClearCancel();
  1403. }
  1404. // cancel cancels even the move
  1405. FMoveToQueue = false;
  1406. }
  1407. else if (FProgressForm->MoveToQueue)
  1408. {
  1409. FMoveToQueue = true;
  1410. ProgressData.SetCancelAtLeast(csCancel);
  1411. }
  1412. if ((FTransferResumeList != NULL) &&
  1413. ProgressData.InProgress &&
  1414. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1415. !ProgressData.FullFileName.IsEmpty())
  1416. {
  1417. if ((FTransferResumeList->Count == 0) ||
  1418. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1419. {
  1420. // note that we do not recognize directories from files here
  1421. FTransferResumeList->Add(ProgressData.FullFileName);
  1422. }
  1423. }
  1424. }
  1425. }
  1426. //---------------------------------------------------------------------------
  1427. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1428. const TDateTime & StartTime)
  1429. {
  1430. if (GUIConfiguration->BeepOnFinish &&
  1431. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1432. {
  1433. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1434. DWORD Sound;
  1435. if (!ExtractFileExt(BeepSound).IsEmpty())
  1436. {
  1437. Sound = SND_FILENAME;
  1438. }
  1439. else
  1440. {
  1441. Sound = SND_ALIAS;
  1442. }
  1443. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1444. }
  1445. }
  1446. //---------------------------------------------------------------------------
  1447. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1448. TFileOperationProgressType & ProgressData)
  1449. {
  1450. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1451. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1452. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1453. FileOperationProgress(ProgressData);
  1454. }
  1455. //---------------------------------------------------------------------------
  1456. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1457. {
  1458. UnicodeString Result;
  1459. if (FProgressForm != NULL)
  1460. {
  1461. Result = FProgressForm->ProgressStr();
  1462. }
  1463. return Result;
  1464. }
  1465. //---------------------------------------------------------------------------
  1466. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1467. bool DragDrop)
  1468. {
  1469. return (!DragDrop && (DropSourceControl == NULL)) ||
  1470. (DropSourceControl == DirView(osOther));
  1471. }
  1472. //---------------------------------------------------------------------------
  1473. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1474. TFileOperation Operation, TOperationSide Side,
  1475. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1476. TOnceDoneOperation & OnceDoneOperation)
  1477. {
  1478. if (!FAutoOperation)
  1479. {
  1480. // no selection on "/upload", form servers only as event handler
  1481. // (it is not displayed)
  1482. if (PanelOperation(Side, FDragDropOperation) &&
  1483. Visible && (Operation != foCalculateSize) &&
  1484. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1485. {
  1486. if (FOnFileOperationFinished != NULL)
  1487. {
  1488. FOnFileOperationFinished(FileName, Success);
  1489. }
  1490. else
  1491. {
  1492. TOperationSide DViewSide;
  1493. if ((FProgressSide != osCurrent) &&
  1494. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1495. {
  1496. // assume the operation is over the focused panel
  1497. DViewSide = FProgressSide;
  1498. }
  1499. else
  1500. {
  1501. DViewSide = Side;
  1502. }
  1503. TCustomDirView * DView = DirView(DViewSide);
  1504. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(DViewSide));
  1505. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1506. // this can happen when local drive is unplugged in the middle of the operation
  1507. if (Item != NULL)
  1508. {
  1509. if (Success) Item->Selected = false;
  1510. DView->MakeProgressVisible(Item);
  1511. }
  1512. }
  1513. }
  1514. if ((Operation == foCopy) || (Operation == foMove))
  1515. {
  1516. // TODO_OTHER_LOCAL
  1517. if (!IsLocalBrowserMode())
  1518. {
  1519. if (Side == osLocal)
  1520. {
  1521. Configuration->Usage->Inc(L"UploadedFiles");
  1522. }
  1523. else
  1524. {
  1525. Configuration->Usage->Inc(L"DownloadedFiles");
  1526. }
  1527. }
  1528. }
  1529. }
  1530. if (Success && (FSynchronizeController != NULL))
  1531. {
  1532. DebugAssert(!IsSideLocalBrowser(osRemote));
  1533. if (Operation == foCopy)
  1534. {
  1535. DebugAssert(Side == osLocal);
  1536. FSynchronizeController->LogOperation(soUpload, FileName);
  1537. }
  1538. else if (Operation == foDelete)
  1539. {
  1540. DebugAssert(Side == osRemote);
  1541. FSynchronizeController->LogOperation(soDelete, FileName);
  1542. }
  1543. }
  1544. if (FProgressForm)
  1545. {
  1546. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1547. }
  1548. }
  1549. //---------------------------------------------------------------------------
  1550. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1551. TFileOperation Operation, TOperationSide Side,
  1552. bool Temp, const UnicodeString & FileName, Boolean Success,
  1553. TOnceDoneOperation & OnceDoneOperation)
  1554. {
  1555. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1556. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1557. OnceDoneOperation);
  1558. }
  1559. //---------------------------------------------------------------------------
  1560. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1561. {
  1562. return false;
  1563. }
  1564. //---------------------------------------------------------------------------
  1565. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1566. {
  1567. return false;
  1568. }
  1569. //---------------------------------------------------------------------------
  1570. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1571. {
  1572. return NULL;
  1573. }
  1574. //---------------------------------------------------------------------------
  1575. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1576. {
  1577. DebugAssert(GetSide(Side) == osRemote);
  1578. DebugUsedParam(Side);
  1579. return RemoteDirView;
  1580. }
  1581. //---------------------------------------------------------------------------
  1582. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1583. {
  1584. DebugAssert(GetSide(Side) == osRemote);
  1585. DebugUsedParam(Side);
  1586. return RemoteDriveView;
  1587. }
  1588. //---------------------------------------------------------------------------
  1589. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1590. {
  1591. DebugAssert(GetSide(Side) == osRemote);
  1592. DebugUsedParam(Side);
  1593. return HasActiveTerminal();
  1594. }
  1595. //---------------------------------------------------------------------------
  1596. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1597. TOperationSide Side, int FilesOnly)
  1598. {
  1599. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1600. }
  1601. //---------------------------------------------------------------------------
  1602. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1603. TOperationSide Side, int FilesOnly)
  1604. {
  1605. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1606. }
  1607. //---------------------------------------------------------------------------
  1608. struct THistoryItemData
  1609. {
  1610. short int Side;
  1611. short int Index;
  1612. };
  1613. //---------------------------------------------------------------------------
  1614. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1615. {
  1616. DirView(Side)->HistoryGo(Index);
  1617. }
  1618. //---------------------------------------------------------------------------
  1619. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1620. {
  1621. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1622. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1623. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1624. }
  1625. //---------------------------------------------------------------------------
  1626. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1627. bool Back)
  1628. {
  1629. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1630. {
  1631. TCustomDirView * DView = DirView(Side);
  1632. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1633. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1634. if (ICount > 10)
  1635. {
  1636. ICount = 10;
  1637. }
  1638. Menu->Items->Clear();
  1639. THistoryItemData Data;
  1640. Data.Side = Side;
  1641. for (short int i = 1; i <= ICount; i++)
  1642. {
  1643. TTBCustomItem * Item = new TTBXItem(Menu);
  1644. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1645. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1646. Item->Hint = DView->HistoryPath[Data.Index];
  1647. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1648. Item->Tag = *reinterpret_cast<int*>(&Data);
  1649. Item->OnClick = HistoryItemClick;
  1650. Menu->Items->Add(Item);
  1651. }
  1652. }
  1653. }
  1654. //---------------------------------------------------------------------------
  1655. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1656. TOperationSide Side, bool Back)
  1657. {
  1658. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1659. {
  1660. // workaround
  1661. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1662. // operator new allocates memory in Pascal code, but calls inline
  1663. // contructor in C++, leading in problems, the function does
  1664. // both in Pascal code
  1665. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1666. UpdateHistoryMenu(Side, Back);
  1667. }
  1668. return FHistoryMenu[Side == osLocal][Back];
  1669. }
  1670. //---------------------------------------------------------------------------
  1671. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1672. TCustomDirView *Sender)
  1673. {
  1674. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1675. UpdateHistoryMenu(Side, true);
  1676. UpdateHistoryMenu(Side, false);
  1677. }
  1678. //---------------------------------------------------------------------------
  1679. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1680. {
  1681. // remote custom commands can be executed only if the server supports shell commands
  1682. // or have secondary shell
  1683. return HasActiveTerminal() && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1684. }
  1685. //---------------------------------------------------------------------------
  1686. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1687. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1688. {
  1689. // -1 = hidden, 0 = disabled, 1 = enabled
  1690. int Result;
  1691. TFileCustomCommand RemoteCustomCommand;
  1692. TLocalCustomCommand LocalCustomCommand;
  1693. TFileCustomCommand * NonInteractiveCustomCommand =
  1694. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1695. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1696. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1697. if (FLAGCLEAR(Command.Params, ccLocal))
  1698. {
  1699. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1700. // custom command that does not operate with files can be executed anytime ...
  1701. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1702. {
  1703. // ... but do not show such command in remote file menu
  1704. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1705. {
  1706. Result = AllowedState;
  1707. }
  1708. else
  1709. {
  1710. Result = -1;
  1711. }
  1712. }
  1713. else
  1714. {
  1715. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1716. {
  1717. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1718. }
  1719. else
  1720. {
  1721. Result = -1;
  1722. }
  1723. }
  1724. }
  1725. else
  1726. {
  1727. // custom command that does not operate with files can be executed anytime
  1728. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1729. {
  1730. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1731. }
  1732. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1733. {
  1734. if ((ListType == ccltAll) || (ListType == ccltFile))
  1735. {
  1736. // special case is "diff"-style command that can be executed over any side,
  1737. // if we have both sides
  1738. Result =
  1739. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1740. // directly (instead of EnableSelectedOperation) to pass
  1741. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1742. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1743. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1744. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1745. }
  1746. else if (ListType == ccltBoth)
  1747. {
  1748. DebugAssert(!IsLocalBrowserMode());
  1749. Result = 1;
  1750. }
  1751. else
  1752. {
  1753. Result = -1;
  1754. }
  1755. }
  1756. else
  1757. {
  1758. if ((ListType == ccltAll) ||
  1759. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1760. {
  1761. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1762. }
  1763. else
  1764. {
  1765. Result = -1;
  1766. }
  1767. }
  1768. if ((Result > 0) &&
  1769. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1770. !HasActiveTerminal())
  1771. {
  1772. Result = 0;
  1773. }
  1774. }
  1775. return Result;
  1776. }
  1777. //---------------------------------------------------------------------------
  1778. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1779. TStrings * FileList, const TCustomCommandType & ACommand,
  1780. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1781. {
  1782. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1783. {
  1784. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1785. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1786. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1787. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1788. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1789. bool Capture =
  1790. FLAGSET(ACommand.Params, ccShowResults) ||
  1791. FLAGSET(ACommand.Params, ccCopyResults) ||
  1792. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1793. TCaptureOutputEvent OutputEvent = NULL;
  1794. DebugAssert(FCapturedLog == NULL);
  1795. if (Capture)
  1796. {
  1797. FCapturedLog = new TStringList();
  1798. OutputEvent = TerminalCaptureLog;
  1799. }
  1800. try
  1801. {
  1802. if (!RemoteCustomCommand.IsFileCommand(Command))
  1803. {
  1804. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1805. OutputEvent);
  1806. }
  1807. else
  1808. {
  1809. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1810. }
  1811. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1812. {
  1813. if (FLAGSET(ACommand.Params, ccCopyResults))
  1814. {
  1815. CopyToClipboard(FCapturedLog);
  1816. }
  1817. if (FLAGSET(ACommand.Params, ccShowResults))
  1818. {
  1819. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1820. }
  1821. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1822. {
  1823. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1824. }
  1825. }
  1826. }
  1827. __finally
  1828. {
  1829. SAFE_DESTROY(FCapturedLog);
  1830. }
  1831. }
  1832. }
  1833. //---------------------------------------------------------------------------
  1834. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1835. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1836. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1837. {
  1838. DebugAssert(!IsLocalBrowserMode());
  1839. TStrings * LocalFileList = NULL;
  1840. TStrings * RemoteFileList = NULL;
  1841. TStrings * RemoteFileListFull = NULL;
  1842. try
  1843. {
  1844. if (LocalFileCommand)
  1845. {
  1846. if (ALocalFileList == NULL)
  1847. {
  1848. DebugAssert(HasDirView[osLocal]);
  1849. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1850. // directly (instead of EnableSelectedOperation) to pass
  1851. // false to FocusedFileOnlyWhenFocused
  1852. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1853. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1854. }
  1855. else
  1856. {
  1857. LocalFileList = ALocalFileList;
  1858. }
  1859. if (FileListCommand)
  1860. {
  1861. if (LocalFileList->Count != 1)
  1862. {
  1863. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1864. }
  1865. }
  1866. else
  1867. {
  1868. if ((LocalFileList->Count != 1) &&
  1869. (FileList->Count != 1) &&
  1870. (LocalFileList->Count != FileList->Count))
  1871. {
  1872. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1873. }
  1874. }
  1875. }
  1876. UnicodeString RootTempDir;
  1877. UnicodeString TempDir;
  1878. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1879. if (!RemoteFiles)
  1880. {
  1881. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1882. }
  1883. try
  1884. {
  1885. TDateTimes RemoteFileTimes;
  1886. if (RemoteFiles)
  1887. {
  1888. RemoteFileList = FileList;
  1889. }
  1890. else
  1891. {
  1892. RemoteFileList = new TStringList();
  1893. TMakeLocalFileListParams MakeFileListParam;
  1894. MakeFileListParam.FileList = RemoteFileList;
  1895. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1896. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1897. MakeFileListParam.Recursive =
  1898. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1899. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1900. if (!MakeFileListParam.Recursive)
  1901. {
  1902. RemoteFileTimes.clear();
  1903. RemoteFileListFull = new TStringList();
  1904. MakeFileListParam.FileList = RemoteFileListFull;
  1905. MakeFileListParam.Recursive = true;
  1906. MakeFileListParam.IncludeDirs = false;
  1907. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1908. }
  1909. else
  1910. {
  1911. RemoteFileListFull = RemoteFileList;
  1912. }
  1913. }
  1914. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1915. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1916. if (!NonBlocking)
  1917. {
  1918. int Count;
  1919. if (FileListCommand)
  1920. {
  1921. Count = 1;
  1922. }
  1923. else if (LocalFileCommand)
  1924. {
  1925. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1926. }
  1927. else
  1928. {
  1929. Count = RemoteFileList->Count;
  1930. }
  1931. Progress.Start(foCustomCommand, osRemote, Count);
  1932. DebugAssert(FProgressForm != NULL);
  1933. FProgressForm->ReadOnly = true;
  1934. }
  1935. try
  1936. {
  1937. if (FileListCommand)
  1938. {
  1939. UnicodeString LocalFile;
  1940. // MakeFileList does not delimit filenames
  1941. UnicodeString FileList = MakeFileList(RemoteFileList);
  1942. if (LocalFileCommand)
  1943. {
  1944. DebugAssert(LocalFileList->Count == 1);
  1945. LocalFile = LocalFileList->Strings[0];
  1946. }
  1947. TLocalCustomCommand CustomCommand(Data,
  1948. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1949. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1950. if (NonBlocking)
  1951. {
  1952. DebugAssert(!POutput);
  1953. ExecuteShellChecked(ShellCommand);
  1954. }
  1955. else
  1956. {
  1957. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  1958. }
  1959. }
  1960. else if (LocalFileCommand)
  1961. {
  1962. if (LocalFileList->Count == 1)
  1963. {
  1964. UnicodeString LocalFile = LocalFileList->Strings[0];
  1965. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1966. {
  1967. UnicodeString FileName = RemoteFileList->Strings[Index];
  1968. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  1969. Progress.SetFile(FileNameForProgress);
  1970. TLocalCustomCommand CustomCommand(Data,
  1971. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1972. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1973. TOnceDoneOperation OnceDoneOperation;
  1974. // Do not unselect anything, as it won't work with two panels anyway
  1975. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1976. }
  1977. }
  1978. else if (RemoteFileList->Count == 1)
  1979. {
  1980. UnicodeString FileName = RemoteFileList->Strings[0];
  1981. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1982. {
  1983. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  1984. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  1985. Progress.SetFile(LocalFileNameOnly);
  1986. TLocalCustomCommand CustomCommand(
  1987. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1988. FileName, LocalFileName, L"");
  1989. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  1990. TOnceDoneOperation OnceDoneOperation;
  1991. // Do not unselect anything, as it won't work with two panels anyway
  1992. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  1993. }
  1994. }
  1995. else
  1996. {
  1997. if (LocalFileList->Count != RemoteFileList->Count)
  1998. {
  1999. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  2000. }
  2001. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2002. {
  2003. UnicodeString FileName = RemoteFileList->Strings[Index];
  2004. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2005. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2006. Progress.SetFile(LocalFileNameOnly); // sic
  2007. TLocalCustomCommand CustomCommand(
  2008. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2009. FileName, LocalFileName, L"");
  2010. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2011. TOnceDoneOperation OnceDoneOperation;
  2012. // Do not unselect anything, as it won't work with two panels anyway
  2013. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2014. }
  2015. }
  2016. }
  2017. else
  2018. {
  2019. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2020. {
  2021. UnicodeString FileName = RemoteFileList->Strings[Index];
  2022. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2023. Progress.SetFile(FileNameForProgress);
  2024. TLocalCustomCommand CustomCommand(Data,
  2025. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2026. FileName, L"", L"");
  2027. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2028. TOnceDoneOperation OnceDoneOperation;
  2029. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2030. }
  2031. }
  2032. }
  2033. __finally
  2034. {
  2035. if (!NonBlocking)
  2036. {
  2037. Progress.Stop();
  2038. }
  2039. }
  2040. DebugAssert(!FAutoOperation);
  2041. if (!RemoteFiles)
  2042. {
  2043. TempDir = IncludeTrailingBackslash(TempDir);
  2044. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2045. {
  2046. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2047. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2048. // Skip directories, process only nested files.
  2049. // The check is redundant as FileAge fails for directories anyway.
  2050. !DirectoryExists(FileName))
  2051. {
  2052. UnicodeString RemoteDir =
  2053. UnixExtractFileDir(
  2054. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  2055. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2056. TDateTime NewTime;
  2057. if (FileAge(FileName, NewTime) &&
  2058. (NewTime != RemoteFileTimes[Index]))
  2059. {
  2060. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2061. TemporaryFileCopyParam(CopyParam);
  2062. CopyParam.FileMask = L"";
  2063. FAutoOperation = true;
  2064. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2065. TemporaryFilesList->Add(FileName);
  2066. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2067. }
  2068. }
  2069. }
  2070. }
  2071. }
  2072. __finally
  2073. {
  2074. FAutoOperation = false;
  2075. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2076. {
  2077. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2078. }
  2079. }
  2080. }
  2081. __finally
  2082. {
  2083. if (RemoteFileList != FileList)
  2084. {
  2085. delete RemoteFileList;
  2086. }
  2087. if (LocalFileList != ALocalFileList)
  2088. {
  2089. delete LocalFileList;
  2090. }
  2091. if (RemoteFileListFull != RemoteFileList)
  2092. {
  2093. delete RemoteFileListFull;
  2094. }
  2095. }
  2096. }
  2097. //---------------------------------------------------------------------------
  2098. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2099. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2100. bool FileListCommand, UnicodeString * POutput)
  2101. {
  2102. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2103. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2104. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2105. {
  2106. UnicodeString FileName = SelectedFileList->Strings[Index];
  2107. if (DirectoryExists(FileName))
  2108. {
  2109. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2110. {
  2111. LocalFileList->Add(FileName);
  2112. }
  2113. if (FLAGSET(ACommand.Params, ccRecursive))
  2114. {
  2115. TMakeLocalFileListParams MakeFileListParam;
  2116. MakeFileListParam.FileList = LocalFileList.get();
  2117. MakeFileListParam.FileTimes = NULL;
  2118. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2119. MakeFileListParam.Recursive = true;
  2120. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2121. }
  2122. }
  2123. else
  2124. {
  2125. LocalFileList->Add(FileName);
  2126. }
  2127. }
  2128. UnicodeString RemotePath;
  2129. if (Terminal != NULL)
  2130. {
  2131. RemotePath = Terminal->CurrentDirectory;
  2132. }
  2133. if (FileListCommand)
  2134. {
  2135. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2136. TLocalCustomCommand CustomCommand(
  2137. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2138. L"", L"", FileList);
  2139. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2140. }
  2141. else
  2142. {
  2143. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2144. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2145. DebugAssert(FProgressForm != NULL);
  2146. FProgressForm->ReadOnly = true;
  2147. try
  2148. {
  2149. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2150. {
  2151. UnicodeString FileName = LocalFileList->Strings[Index];
  2152. Progress.SetFile(FileName);
  2153. TLocalCustomCommand CustomCommand(
  2154. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2155. FileName, L"", L"");
  2156. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2157. TOnceDoneOperation OnceDoneOperation;
  2158. Progress.Finish(FileName, true, OnceDoneOperation);
  2159. }
  2160. }
  2161. __finally
  2162. {
  2163. Progress.Stop();
  2164. }
  2165. }
  2166. }
  2167. //---------------------------------------------------------------------------
  2168. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2169. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2170. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2171. {
  2172. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2173. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2174. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2175. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2176. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2177. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2178. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2179. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2180. std::unique_ptr<UnicodeString> POutput;
  2181. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2182. FLAGSET(ACommand.Params, ccCopyResults))
  2183. {
  2184. POutput.reset(new UnicodeString());
  2185. }
  2186. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  2187. FProgressSide = FCurrentSide;
  2188. if (!LocalCustomCommand.IsFileCommand(Command))
  2189. {
  2190. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2191. }
  2192. // remote files?
  2193. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2194. {
  2195. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2196. }
  2197. // local files
  2198. else
  2199. {
  2200. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2201. }
  2202. if (POutput.get() != NULL)
  2203. {
  2204. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2205. int P = POutput->Pos(sLineBreak);
  2206. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2207. {
  2208. POutput->SetLength(P - 1);
  2209. }
  2210. // Copy even empty output to clipboard
  2211. if (FLAGSET(ACommand.Params, ccCopyResults))
  2212. {
  2213. CopyToClipboard(*POutput);
  2214. }
  2215. // But do not show an empty message box.
  2216. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2217. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2218. !POutput->IsEmpty())
  2219. {
  2220. TClipboardHandler ClipboardHandler;
  2221. ClipboardHandler.Text = *POutput;
  2222. TMessageParams Params;
  2223. TQueryButtonAlias Aliases[1];
  2224. Aliases[0].Button = qaRetry;
  2225. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2226. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2227. Params.Aliases = Aliases;
  2228. Params.AliasesCount = LENOF(Aliases);
  2229. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2230. }
  2231. }
  2232. }
  2233. //---------------------------------------------------------------------------
  2234. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2235. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2236. {
  2237. TCustomCommandData Data;
  2238. UnicodeString Site;
  2239. UnicodeString RemotePath;
  2240. if (HasActiveTerminal())
  2241. {
  2242. Data = TCustomCommandData(Terminal);
  2243. Site = Terminal->SessionData->SessionKey;
  2244. RemotePath = Terminal->CurrentDirectory;
  2245. }
  2246. UnicodeString HelpKeyword = ACommand.HomePage;
  2247. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2248. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2249. {
  2250. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2251. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2252. {
  2253. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2254. }
  2255. else
  2256. {
  2257. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2258. }
  2259. if (!DoCustomCommandOptionsDialog(
  2260. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2261. {
  2262. Abort();
  2263. }
  2264. }
  2265. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2266. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2267. {
  2268. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2269. }
  2270. else
  2271. {
  2272. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2273. }
  2274. }
  2275. //---------------------------------------------------------------------------
  2276. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2277. const TCustomCommandType & Command)
  2278. {
  2279. DebugAssert(FCustomCommandLocalFileList != NULL);
  2280. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2281. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2282. TStrings * LocalFileList = new TStringList();
  2283. TStrings * RemoteFileList = new TStringList();
  2284. try
  2285. {
  2286. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2287. {
  2288. LocalFileList->Clear();
  2289. LocalFileList->AddObject(
  2290. FCustomCommandLocalFileList->Strings[Index],
  2291. FCustomCommandLocalFileList->Objects[Index]);
  2292. RemoteFileList->Clear();
  2293. RemoteFileList->AddObject(
  2294. FCustomCommandRemoteFileList->Strings[Index],
  2295. FCustomCommandRemoteFileList->Objects[Index]);
  2296. CustomCommand(RemoteFileList, Command, LocalFileList);
  2297. }
  2298. }
  2299. __finally
  2300. {
  2301. delete LocalFileList;
  2302. delete RemoteFileList;
  2303. }
  2304. }
  2305. //---------------------------------------------------------------------------
  2306. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2307. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2308. {
  2309. delete FCustomCommandLocalFileList;
  2310. delete FCustomCommandRemoteFileList;
  2311. // takeover ownership,
  2312. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2313. FCustomCommandLocalFileList = LocalFileList;
  2314. FCustomCommandRemoteFileList = RemoteFileList;
  2315. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2316. if (Button != NULL)
  2317. {
  2318. FCustomCommandMenu->Items->Clear();
  2319. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2320. MenuPopup(FCustomCommandMenu, Button);
  2321. }
  2322. else
  2323. {
  2324. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2325. }
  2326. }
  2327. //---------------------------------------------------------------------------
  2328. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2329. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2330. {
  2331. DebugAssert(FCapturedLog != NULL);
  2332. if ((OutputType == cotOutput) || (OutputType == cotError))
  2333. {
  2334. FCapturedLog->Add(AddedLine);
  2335. }
  2336. }
  2337. //---------------------------------------------------------------------------
  2338. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2339. TOperationSide Side)
  2340. {
  2341. return
  2342. (Side == osOther) &&
  2343. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2344. }
  2345. //---------------------------------------------------------------------------
  2346. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2347. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2348. {
  2349. TTBItemOptions O;
  2350. O = Item->Options;
  2351. TCustomDirView * DView = DirView(Side);
  2352. if ((DView->ItemFocused != NULL) &&
  2353. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2354. // when resolving links is disabled, default action is to enter the directory,
  2355. // no matter what DoubleClickAction is configured to
  2356. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2357. // Can only Edit files, but can Open/Copy even directories
  2358. ((DoubleClickAction != dcaEdit) ||
  2359. !DView->ItemIsDirectory(DView->ItemFocused)))
  2360. {
  2361. Item->Options = O << tboDefault;
  2362. }
  2363. else
  2364. {
  2365. Item->Options = O >> tboDefault;
  2366. }
  2367. }
  2368. //---------------------------------------------------------------------------
  2369. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2370. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2371. {
  2372. TCustomDirView * DView = DirView(Side);
  2373. TListItem * Item = DView->ItemFocused;
  2374. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2375. EnableFocusedOperation[Side])
  2376. {
  2377. TPoint ClientPoint;
  2378. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2379. TPoint(0, 0) : MousePos;
  2380. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2381. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2382. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2383. }
  2384. }
  2385. //---------------------------------------------------------------------------
  2386. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2387. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2388. {
  2389. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2390. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2391. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2392. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2393. Handled = true;
  2394. }
  2395. //---------------------------------------------------------------------------
  2396. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2397. {
  2398. }
  2399. //---------------------------------------------------------------------------
  2400. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2401. {
  2402. DebugAssert(FErrorList == NULL);
  2403. if (WinConfiguration->ContinueOnError)
  2404. {
  2405. FErrorList = new TStringList();
  2406. Configuration->Usage->Inc(L"ContinuationsOnError");
  2407. }
  2408. NonVisualDataModule->StartBusy();
  2409. }
  2410. //---------------------------------------------------------------------------
  2411. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2412. {
  2413. NonVisualDataModule->EndBusy();
  2414. if (FErrorList)
  2415. {
  2416. HandleErrorList(FErrorList);
  2417. }
  2418. }
  2419. //---------------------------------------------------------------------------
  2420. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2421. const TCopyParamType & CopyParam)
  2422. {
  2423. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2424. {
  2425. Configuration->Usage->Inc(L"FileMaskUses");
  2426. }
  2427. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2428. {
  2429. Configuration->Usage->Inc(L"OperationMaskUses");
  2430. }
  2431. }
  2432. //---------------------------------------------------------------------------
  2433. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2434. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2435. {
  2436. DebugAssert(!IsLocalBrowserMode());
  2437. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2438. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2439. TTransferOperationParam DefaultParam;
  2440. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2441. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2442. switch (Param.Queue)
  2443. {
  2444. case asOn:
  2445. CopyParam.Queue = true;
  2446. break;
  2447. case asOff:
  2448. CopyParam.Queue = false;
  2449. break;
  2450. case asAuto:
  2451. default:
  2452. // keep default
  2453. break;
  2454. }
  2455. bool Result =
  2456. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2457. if (Result)
  2458. {
  2459. DebugAssert(Terminal);
  2460. bool SelectionRestored = false;
  2461. TCustomDirView * DView = NULL;
  2462. if (HasDirView[Side])
  2463. {
  2464. DView = DirView(Side);
  2465. DView->SaveSelection();
  2466. DView->SaveSelectedNames();
  2467. }
  2468. UpdateCopyParamCounters(CopyParam);
  2469. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2470. DebugAssert(FTransferResumeList == NULL);
  2471. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2472. FMoveToQueue = false;
  2473. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2474. try
  2475. {
  2476. TStrings * PermanentFileList;
  2477. std::unique_ptr<TStrings> PermanentFileListOwner;
  2478. try
  2479. {
  2480. if (Side == osLocal)
  2481. {
  2482. PermanentFileList = FileList;
  2483. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2484. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2485. if (Operation == foMove)
  2486. {
  2487. ReloadLocalDirectory();
  2488. if (DView != NULL)
  2489. {
  2490. DView->RestoreSelection();
  2491. }
  2492. SelectionRestored = true;
  2493. }
  2494. }
  2495. else
  2496. {
  2497. // Clone the file list as it may refer to current directory files,
  2498. // which get destroyed, when the source directory is reloaded after foMove operation.
  2499. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2500. // But for a hotfix, we are not going to do such a big change.
  2501. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2502. PermanentFileList = PermanentFileListOwner.get();
  2503. try
  2504. {
  2505. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2506. }
  2507. __finally
  2508. {
  2509. if (Operation == foMove)
  2510. {
  2511. if (DView != NULL)
  2512. {
  2513. DView->RestoreSelection();
  2514. }
  2515. SelectionRestored = true;
  2516. }
  2517. ReloadLocalDirectory(Param.TargetDirectory);
  2518. }
  2519. }
  2520. }
  2521. catch (EAbort &)
  2522. {
  2523. if (FMoveToQueue)
  2524. {
  2525. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2526. DebugAssert(CopyParam.TransferSkipList == NULL);
  2527. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2528. if (TransferResumeList->Count > 0)
  2529. {
  2530. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2531. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2532. }
  2533. CopyParam.TransferSkipList = TransferResumeList.release();
  2534. // not really needed, just to keep it consistent with TransferResumeList
  2535. FTransferResumeList = NULL;
  2536. FMoveToQueue = false;
  2537. Configuration->Usage->Inc("MovesToBackground");
  2538. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2539. ClearTransferSourceSelection(Direction);
  2540. }
  2541. throw;
  2542. }
  2543. }
  2544. __finally
  2545. {
  2546. if (!SelectionRestored && (DView != NULL))
  2547. {
  2548. DView->DiscardSavedSelection();
  2549. }
  2550. FTransferResumeList = NULL;
  2551. }
  2552. }
  2553. return Result;
  2554. }
  2555. //---------------------------------------------------------------------------
  2556. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2557. TOperationSide Side, TStrings * FileList, void * Param)
  2558. {
  2559. DebugAssert(FileList->Count);
  2560. // We deliberately do not toggle alternative flag (Param), but use OR,
  2561. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2562. // shortcut of CurrentDeleteAlternativeAction
  2563. bool Alternative =
  2564. bool(Param) || UseAlternativeFunction();
  2565. bool Recycle;
  2566. if (IsSideLocalBrowser(Side))
  2567. {
  2568. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2569. }
  2570. else
  2571. {
  2572. Recycle =
  2573. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2574. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2575. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2576. }
  2577. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2578. if (!Result)
  2579. {
  2580. UnicodeString Query;
  2581. if (FileList->Count == 1)
  2582. {
  2583. if (IsSideLocalBrowser(Side))
  2584. {
  2585. Query = ExtractFileName(FileList->Strings[0]);
  2586. }
  2587. else
  2588. {
  2589. Query = UnixExtractFileName(FileList->Strings[0]);
  2590. }
  2591. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2592. }
  2593. else
  2594. {
  2595. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2596. }
  2597. TMessageParams Params(mpNeverAskAgainCheck);
  2598. Params.ImageName = L"Delete file";
  2599. unsigned int Answer =
  2600. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2601. if (Answer == qaNeverAskAgain)
  2602. {
  2603. Result = true;
  2604. if (Recycle)
  2605. {
  2606. WinConfiguration->ConfirmRecycling = false;
  2607. }
  2608. else
  2609. {
  2610. WinConfiguration->ConfirmDeleting = false;
  2611. }
  2612. }
  2613. else
  2614. {
  2615. Result = (Answer == qaOK);
  2616. }
  2617. }
  2618. if (Result)
  2619. {
  2620. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2621. }
  2622. return Result;
  2623. }
  2624. //---------------------------------------------------------------------------
  2625. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2626. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2627. {
  2628. TAutoBatch AutoBatch(this);
  2629. bool Result;
  2630. if ((Operation == foCopy) || (Operation == foMove))
  2631. {
  2632. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2633. }
  2634. else if (Operation == foRename)
  2635. {
  2636. DebugAssert(DirView(Side)->ItemFocused);
  2637. DirView(Side)->ItemFocused->EditCaption();
  2638. Result = true;
  2639. }
  2640. else if (Operation == foDelete)
  2641. {
  2642. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2643. }
  2644. else if (Operation == foSetProperties)
  2645. {
  2646. DirView(osRemote)->SaveSelectedNames();
  2647. Result = SetProperties(Side, FileList);
  2648. }
  2649. else if (Operation == foCustomCommand)
  2650. {
  2651. DebugAssert(Param);
  2652. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2653. DirView(osRemote)->SaveSelectedNames();
  2654. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2655. CustomCommand(FileList, *Command, NULL);
  2656. Result = true;
  2657. }
  2658. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2659. {
  2660. DebugAssert(!IsSideLocalBrowser(Side));
  2661. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2662. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2663. }
  2664. else if (Operation == foLock)
  2665. {
  2666. DebugAssert(!IsSideLocalBrowser(Side));
  2667. LockFiles(FileList, true);
  2668. Result = true;
  2669. }
  2670. else if (Operation == foUnlock)
  2671. {
  2672. DebugAssert(!IsSideLocalBrowser(Side));
  2673. LockFiles(FileList, false);
  2674. Result = true;
  2675. }
  2676. else
  2677. {
  2678. DebugFail();
  2679. }
  2680. return Result;
  2681. }
  2682. //---------------------------------------------------------------------------
  2683. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2684. {
  2685. if (Side == osCurrent)
  2686. {
  2687. Side = FCurrentSide;
  2688. }
  2689. return Side;
  2690. }
  2691. //---------------------------------------------------------------------------
  2692. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2693. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2694. {
  2695. Side = GetSide(Side);
  2696. bool Result;
  2697. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2698. try
  2699. {
  2700. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2701. }
  2702. __finally
  2703. {
  2704. delete FileList;
  2705. }
  2706. return Result;
  2707. }
  2708. //---------------------------------------------------------------------------
  2709. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2710. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2711. bool NoConfirmation, void * Param)
  2712. {
  2713. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2714. {
  2715. if ((Operation == foCopy) || (Operation == foMove))
  2716. {
  2717. DebugAssert(!IsLocalBrowserMode());
  2718. if (GetSide(Side) == osLocal)
  2719. {
  2720. Configuration->Usage->Inc(L"UploadsCommand");
  2721. }
  2722. else
  2723. {
  2724. Configuration->Usage->Inc(L"DownloadsCommand");
  2725. }
  2726. }
  2727. }
  2728. }
  2729. //---------------------------------------------------------------------------
  2730. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2731. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2732. {
  2733. TTransferOperationParam Param;
  2734. if ((WinConfiguration->Interface != ifCommander) ||
  2735. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2736. {
  2737. Flags &= ~cocShortCutHint;
  2738. }
  2739. TCustomDirView * DView = DirView(Side);
  2740. Param.Options =
  2741. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2742. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2743. if (FLAGSET(Flags, cocQueue))
  2744. {
  2745. Param.Queue = asOn;
  2746. }
  2747. else if (FLAGSET(Flags, cocNonQueue))
  2748. {
  2749. Param.Queue = asOff;
  2750. }
  2751. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2752. }
  2753. //---------------------------------------------------------------------------
  2754. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2755. {
  2756. try
  2757. {
  2758. if (ErrorList->Count)
  2759. {
  2760. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2761. if (MessageDialog(Message, qtError,
  2762. qaOK | qaCancel, HELP_NONE) == qaOK)
  2763. {
  2764. unsigned int Answer;
  2765. int Index = 0;
  2766. do
  2767. {
  2768. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2769. TQueryButtonAlias Aliases[2];
  2770. Aliases[0].Button = qaYes;
  2771. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2772. Aliases[1].Button = qaNo;
  2773. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2774. TMessageParams Params;
  2775. Params.Aliases = Aliases;
  2776. Params.AliasesCount = LENOF(Aliases);
  2777. Answer = MoreMessageDialog(
  2778. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2779. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2780. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2781. qaOK, HELP_NONE, &Params);
  2782. if (Answer == qaNo)
  2783. {
  2784. Index++;
  2785. }
  2786. if (Answer == qaYes)
  2787. {
  2788. Index--;
  2789. }
  2790. }
  2791. while (Answer != qaOK);
  2792. }
  2793. }
  2794. }
  2795. __finally
  2796. {
  2797. TStrings * List = ErrorList;
  2798. ErrorList = NULL;
  2799. for (int i = 0; i < List->Count; i++)
  2800. {
  2801. delete List->Objects[i];
  2802. }
  2803. delete List;
  2804. }
  2805. }
  2806. //---------------------------------------------------------------------------
  2807. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2808. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2809. {
  2810. // needed for checking filemasks, as there's no directory object
  2811. // associated with the file object
  2812. File->FullFileName = FullFileName;
  2813. TFileMasks::TParams MaskParams;
  2814. MaskParams.Size = File->Size;
  2815. MaskParams.Modification = File->Modification;
  2816. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2817. }
  2818. //---------------------------------------------------------------------------
  2819. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2820. {
  2821. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2822. Side = GetSide(Side);
  2823. TCustomDirView * DView = DirView(Side);
  2824. TListItem * FocusedItem = DView->ItemFocused;
  2825. UnicodeString Name;
  2826. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2827. {
  2828. Name = DView->ItemFileName(FocusedItem);
  2829. }
  2830. else
  2831. {
  2832. Name = LoadStr(NEW_FILE);
  2833. }
  2834. UnicodeString Names = Name;
  2835. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2836. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2837. HELP_EDIT_NEW, History.get(), true))
  2838. {
  2839. while (!Names.IsEmpty())
  2840. {
  2841. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2842. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2843. UnicodeString TargetFileName;
  2844. UnicodeString LocalFileName;
  2845. UnicodeString RootTempDir;
  2846. UnicodeString TempDir;
  2847. UnicodeString RemoteDirectory;
  2848. bool ExistingFile = false;
  2849. if (!IsSideLocalBrowser(Side))
  2850. {
  2851. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2852. TRemoteFile * File = NULL;
  2853. if (FTerminal->FileExists(Name, &File) &&
  2854. !File->IsDirectory)
  2855. {
  2856. try
  2857. {
  2858. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2859. ExistingFile = true;
  2860. }
  2861. __finally
  2862. {
  2863. delete File;
  2864. }
  2865. }
  2866. if (!ExistingFile)
  2867. {
  2868. RemoteDirectory = UnixExtractFilePath(Name);
  2869. TemporaryDirectoryForRemoteFiles(
  2870. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2871. TargetFileName = UnixExtractFileName(Name);
  2872. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2873. LocalFileName = TempDir +
  2874. // We probably do not want to trim the VMS version here
  2875. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2876. }
  2877. }
  2878. else
  2879. {
  2880. if (ExtractFilePath(Name).IsEmpty())
  2881. {
  2882. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2883. }
  2884. else
  2885. {
  2886. LocalFileName = ExpandFileName(Name);
  2887. }
  2888. TargetFileName = ExtractFileName(Name);
  2889. }
  2890. if (!ExistingFile)
  2891. {
  2892. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2893. if (NewFile)
  2894. {
  2895. int File = FileCreate(ApiPath(LocalFileName));
  2896. if (File < 0)
  2897. {
  2898. if (!RootTempDir.IsEmpty())
  2899. {
  2900. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2901. }
  2902. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2903. }
  2904. else
  2905. {
  2906. FileClose(File);
  2907. }
  2908. }
  2909. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2910. const TEditorData * ExternalEditor = NULL;
  2911. TFileMasks::TParams MaskParams; // size not known
  2912. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2913. false, MaskParams);
  2914. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2915. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2916. }
  2917. }
  2918. }
  2919. }
  2920. //---------------------------------------------------------------------------
  2921. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2922. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2923. {
  2924. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2925. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2926. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2927. return
  2928. ((ExecuteFileBy == efInternalEditor)) ||
  2929. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2930. }
  2931. //---------------------------------------------------------------------------
  2932. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2933. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2934. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2935. UnicodeString RemoteDirectory, bool NewFile)
  2936. {
  2937. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2938. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2939. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2940. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2941. Side = GetSide(Side);
  2942. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2943. if (!IsSideLocalBrowser(Side))
  2944. {
  2945. Data->Terminal = Terminal;
  2946. Data->Queue = Queue;
  2947. Data->SessionData = CloneCurrentSessionData();
  2948. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2949. Data->RemoteDirectory = RemoteDirectory;
  2950. Data->SessionName = Terminal->SessionData->SessionName;
  2951. Data->LocalRootDirectory = LocalRootDirectory;
  2952. Data->OriginalFileName = OriginalFileName;
  2953. Data->Command = L""; // will be changed later for external editor
  2954. }
  2955. if (ExecuteFileBy == efInternalEditor)
  2956. {
  2957. if (!IsSideLocalBrowser(Side))
  2958. {
  2959. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2960. L" - " + Terminal->SessionData->SessionName;
  2961. TForm * Editor;
  2962. try
  2963. {
  2964. TNotifyEvent OnFileChanged = NULL;
  2965. TNotifyEvent OnSaveAll = NULL;
  2966. TAnyModifiedEvent OnAnyModified = NULL;
  2967. // Edited files are uploaded in background queue, what we do not support with encrypted files
  2968. if (Terminal->IsCapable[fcBackgroundTransfers])
  2969. {
  2970. OnFileChanged = FEditorManager->FileChanged;
  2971. OnSaveAll = SaveAllInternalEditors;
  2972. OnAnyModified = AnyInternalEditorModified;
  2973. }
  2974. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  2975. FEditorManager->FileReload, FEditorManager->FileClosed,
  2976. OnSaveAll, OnAnyModified,
  2977. Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  2978. }
  2979. catch(...)
  2980. {
  2981. if (!LocalRootDirectory.IsEmpty())
  2982. {
  2983. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2984. }
  2985. throw;
  2986. }
  2987. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2988. }
  2989. else
  2990. {
  2991. DebugAssert(!FStandaloneEditing);
  2992. TForm * Editor =
  2993. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2994. SaveAllInternalEditors, AnyInternalEditorModified,
  2995. L"", false, SessionColor, -1, NewFile);
  2996. FLocalEditors->Add(Editor);
  2997. }
  2998. }
  2999. else
  3000. {
  3001. HANDLE Process;
  3002. if (ExecuteFileBy == efExternalEditor)
  3003. {
  3004. UnicodeString Program, Params, Dir;
  3005. Data->Command = ExternalEditor->ExternalEditor;
  3006. ReformatFileNameCommand(Data->Command);
  3007. SplitCommand(Data->Command, Program, Params, Dir);
  3008. Params = ExpandFileNameCommand(Params, FileName);
  3009. Program = ExpandEnvironmentVariables(Program);
  3010. if (!ExecuteShell(Program, Params, Process))
  3011. {
  3012. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3013. }
  3014. }
  3015. else
  3016. {
  3017. DebugAssert(!IsSideLocalBrowser(Side));
  3018. if (!ExecuteShell(FileName, L"", Process))
  3019. {
  3020. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3021. }
  3022. }
  3023. if (IsSideLocalBrowser(Side) ||
  3024. ((ExecuteFileBy == efShell) &&
  3025. !WinConfiguration->Editor.SDIShellEditor) ||
  3026. ((ExecuteFileBy == efExternalEditor) &&
  3027. !ExternalEditor->SDIExternalEditor))
  3028. {
  3029. // no need for handle
  3030. if (Process != NULL)
  3031. {
  3032. DebugCheck(CloseHandle(Process));
  3033. }
  3034. Process = INVALID_HANDLE_VALUE;
  3035. }
  3036. else
  3037. {
  3038. if (Process == NULL)
  3039. {
  3040. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3041. }
  3042. }
  3043. if (!IsSideLocalBrowser(Side))
  3044. {
  3045. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3046. }
  3047. }
  3048. }
  3049. //---------------------------------------------------------------------------
  3050. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3051. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3052. void * /*Arg*/)
  3053. {
  3054. if (Token != NULL)
  3055. {
  3056. EditorFormFileSave(static_cast<TForm *>(Token));
  3057. }
  3058. }
  3059. //---------------------------------------------------------------------------
  3060. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3061. {
  3062. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3063. {
  3064. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3065. }
  3066. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3067. }
  3068. //---------------------------------------------------------------------------
  3069. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3070. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3071. void * Arg)
  3072. {
  3073. if ((Token != NULL) &&
  3074. IsEditorFormModified(static_cast<TForm *>(Token)))
  3075. {
  3076. *static_cast<bool *>(Arg) = true;
  3077. }
  3078. }
  3079. //---------------------------------------------------------------------------
  3080. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3081. TObject * /*Sender*/, bool & Modified)
  3082. {
  3083. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3084. {
  3085. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3086. {
  3087. Modified = true;
  3088. }
  3089. }
  3090. if (!Modified)
  3091. {
  3092. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3093. }
  3094. }
  3095. //---------------------------------------------------------------------------
  3096. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3097. {
  3098. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3099. }
  3100. //---------------------------------------------------------------------------
  3101. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3102. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3103. UnicodeString & Result, UnicodeString & RootDirectory)
  3104. {
  3105. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3106. {
  3107. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3108. Result = RootDirectory;
  3109. }
  3110. else
  3111. {
  3112. RootDirectory = L"";
  3113. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3114. Result = IncludeTrailingBackslash(Result);
  3115. }
  3116. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3117. {
  3118. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3119. }
  3120. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3121. {
  3122. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3123. {
  3124. RemoteDirectory.Delete(1, 1);
  3125. }
  3126. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3127. }
  3128. if (!ForceDirectories(ApiPath(Result)))
  3129. {
  3130. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3131. }
  3132. }
  3133. //---------------------------------------------------------------------------
  3134. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3135. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3136. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3137. {
  3138. DebugAssert(!IsLocalBrowserMode());
  3139. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3140. if (ForceText)
  3141. {
  3142. CopyParam.TransferMode = tmAscii;
  3143. }
  3144. TemporaryFileCopyParam(CopyParam);
  3145. if (AllFiles)
  3146. {
  3147. CopyParam.IncludeFileMask = TFileMasks();
  3148. }
  3149. if (TempDir.IsEmpty())
  3150. {
  3151. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3152. }
  3153. DebugAssert(!FAutoOperation);
  3154. FAutoOperation = AutoOperation;
  3155. Terminal->ExceptionOnFail = true;
  3156. try
  3157. {
  3158. try
  3159. {
  3160. // turn off confirmations, as for MDI editors we may possibly download
  3161. // the same file over
  3162. Terminal->CopyToLocal(
  3163. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3164. if (GetTargetNames)
  3165. {
  3166. for (int i = 0; i < FileList->Count; i++)
  3167. {
  3168. FileList->Strings[i] =
  3169. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3170. }
  3171. }
  3172. }
  3173. catch(...)
  3174. {
  3175. if (!RootTempDir.IsEmpty())
  3176. {
  3177. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3178. }
  3179. throw;
  3180. }
  3181. }
  3182. __finally
  3183. {
  3184. FAutoOperation = false;
  3185. Terminal->ExceptionOnFail = false;
  3186. }
  3187. }
  3188. //---------------------------------------------------------------------------
  3189. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3190. {
  3191. // Do not waste time checking for default editor list the next time,
  3192. // or testing if default editor is not notepad.
  3193. bool TryNextTime = false;
  3194. UnicodeString UsageState;
  3195. if (!WinConfiguration->EditorList->IsDefaultList())
  3196. {
  3197. UsageState = "H";
  3198. }
  3199. else
  3200. {
  3201. UnicodeString Executable;
  3202. UnicodeString ExecutableDescription;
  3203. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3204. {
  3205. UnicodeString Message =
  3206. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3207. unsigned int Answer =
  3208. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3209. if (Answer != qaOK)
  3210. {
  3211. UsageState = "R";
  3212. }
  3213. else
  3214. {
  3215. UsageState = "A";
  3216. TEditorData EditorData;
  3217. EditorData.Editor = edExternal;
  3218. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3219. EditorData.ExternalEditorOptionsAutodetect();
  3220. TEditorList EditorList;
  3221. EditorList = *WinConfiguration->EditorList;
  3222. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3223. WinConfiguration->EditorList = &EditorList;
  3224. }
  3225. }
  3226. }
  3227. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3228. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3229. }
  3230. //---------------------------------------------------------------------------
  3231. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3232. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3233. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3234. {
  3235. if (ExecuteFileBy == efDefaultEditor)
  3236. {
  3237. if (!WinConfiguration->OfferedEditorAutoConfig)
  3238. {
  3239. EditorAutoConfig();
  3240. }
  3241. const TEditorPreferences * Editor =
  3242. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3243. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3244. {
  3245. ExecuteFileBy = efInternalEditor;
  3246. ExternalEditor = NULL;
  3247. }
  3248. else if (Editor->Data->Editor == edOpen)
  3249. {
  3250. ExecuteFileBy = efShell;
  3251. ExternalEditor = NULL;
  3252. }
  3253. else
  3254. {
  3255. ExecuteFileBy = efExternalEditor;
  3256. ExternalEditor = Editor->Data;
  3257. }
  3258. }
  3259. }
  3260. //---------------------------------------------------------------------------
  3261. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3262. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3263. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3264. {
  3265. UnicodeString OriginalFileName;
  3266. UnicodeString LocalRootDirectory;
  3267. UnicodeString RemoteDirectory;
  3268. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3269. IsSideLocalBrowser(Side), MaskParams);
  3270. UnicodeString Counter;
  3271. UnicodeString LocalFileName;
  3272. bool Handled = false;
  3273. if (!IsSideLocalBrowser(Side))
  3274. {
  3275. // We need to trim VMS version here, so that we use name without version
  3276. // when uploading back to create a new version of the file
  3277. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3278. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3279. TObject * Token = NULL;
  3280. UnicodeString LocalDirectory;
  3281. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3282. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3283. LocalDirectory))
  3284. {
  3285. if (Token != NULL)
  3286. {
  3287. TForm * Form = dynamic_cast<TForm *>(Token);
  3288. if (Form->WindowState == wsMinimized)
  3289. {
  3290. ShowWindow(Form->Handle, SW_RESTORE);
  3291. }
  3292. else
  3293. {
  3294. Form->SetFocus();
  3295. }
  3296. Handled = true;
  3297. }
  3298. else
  3299. {
  3300. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3301. }
  3302. }
  3303. if (!Handled)
  3304. {
  3305. TStringList * FileList1 = new TStringList();
  3306. try
  3307. {
  3308. FileList1->AddObject(FullFileName, Object);
  3309. TemporarilyDownloadFiles(FileList1,
  3310. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3311. LocalRootDirectory, LocalDirectory, true, true, true);
  3312. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3313. }
  3314. __finally
  3315. {
  3316. delete FileList1;
  3317. }
  3318. switch (ExecuteFileBy)
  3319. {
  3320. case efShell:
  3321. Counter = "RemoteFilesExecuted";
  3322. break;
  3323. case efInternalEditor:
  3324. Counter = "RemoteFilesOpenedInInternalEditor";
  3325. break;
  3326. case efExternalEditor:
  3327. Counter = "RemoteFilesOpenedInExternalEditor";
  3328. break;
  3329. default:
  3330. DebugFail();
  3331. }
  3332. }
  3333. }
  3334. else
  3335. {
  3336. LocalFileName = FullFileName;
  3337. OriginalFileName = ExtractFileName(FullFileName);
  3338. switch (ExecuteFileBy)
  3339. {
  3340. case efShell:
  3341. Counter = "LocalFilesExecuted";
  3342. break;
  3343. case efInternalEditor:
  3344. Counter = "LocalFilesOpenedInInternalEditor";
  3345. break;
  3346. case efExternalEditor:
  3347. Counter = "LocalFilesOpenedInExternalEditor";
  3348. break;
  3349. default:
  3350. DebugFail();
  3351. }
  3352. }
  3353. if (!Handled)
  3354. {
  3355. Configuration->Usage->Inc(Counter);
  3356. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3357. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3358. }
  3359. }
  3360. //---------------------------------------------------------------------------
  3361. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3362. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3363. bool AllSelected, bool OnFocused)
  3364. {
  3365. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3366. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3367. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3368. Side = GetSide(Side);
  3369. TCustomDirView * DView = DirView(Side);
  3370. TStrings * FileList =
  3371. AllSelected ?
  3372. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3373. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3374. try
  3375. {
  3376. DebugAssert(AllSelected || (FileList->Count == 1));
  3377. for (int i = 0; i < FileList->Count; i++)
  3378. {
  3379. UnicodeString ListFileName = FileList->Strings[i];
  3380. UnicodeString FileNameOnly =
  3381. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3382. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3383. if (!DView->ItemIsDirectory(Item))
  3384. {
  3385. UnicodeString FullFileName;
  3386. if (!IsSideLocalBrowser(Side))
  3387. {
  3388. FullFileName = DirView(Side)->Path + ListFileName;
  3389. }
  3390. else
  3391. {
  3392. FullFileName = ListFileName;
  3393. }
  3394. TFileMasks::TParams MaskParams;
  3395. MaskParams.Size = DView->ItemFileSize(Item);
  3396. TDateTimePrecision Precision;
  3397. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3398. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3399. FileList->Objects[i], MaskParams);
  3400. }
  3401. }
  3402. }
  3403. __finally
  3404. {
  3405. delete FileList;
  3406. }
  3407. }
  3408. //---------------------------------------------------------------------------
  3409. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3410. {
  3411. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3412. CopyParam.FileNameCase = ncNoChange;
  3413. CopyParam.PreserveRights = false;
  3414. CopyParam.PreserveReadOnly = false;
  3415. CopyParam.ReplaceInvalidChars = true;
  3416. CopyParam.IncludeFileMask = TFileMasks();
  3417. CopyParam.NewerOnly = false;
  3418. CopyParam.FileMask = L"";
  3419. }
  3420. //---------------------------------------------------------------------------
  3421. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3422. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3423. {
  3424. TTerminalManager * Manager = TTerminalManager::Instance();
  3425. if (!IsActiveTerminal(Data->Terminal))
  3426. {
  3427. if (!NonVisualDataModule->Busy)
  3428. {
  3429. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3430. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3431. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3432. if (Data->Terminal == NULL)
  3433. {
  3434. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3435. if (SameSiteTerminal != NULL)
  3436. {
  3437. UnicodeString Message =
  3438. FMTLOAD(EDIT_SESSION_REATTACH,
  3439. (FileNameOnly, Data->SessionName, FileNameOnly));
  3440. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3441. {
  3442. Data->Terminal = Terminal;
  3443. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3444. Data->SessionName = Terminal->SessionData->SessionName;
  3445. // We might also overwrite session data
  3446. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3447. }
  3448. else
  3449. {
  3450. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3451. Abort();
  3452. }
  3453. }
  3454. }
  3455. // foreground session should reconnect itself
  3456. else if (Terminal != Data->Terminal)
  3457. {
  3458. UnicodeString Message =
  3459. MainInstructions(
  3460. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3461. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3462. {
  3463. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3464. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3465. }
  3466. else
  3467. {
  3468. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3469. Abort();
  3470. }
  3471. }
  3472. }
  3473. if (!IsActiveTerminal(Data->Terminal))
  3474. {
  3475. Configuration->Usage->Inc(L"EditInactiveSession");
  3476. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3477. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3478. (ExtractFileName(FileName), Data->SessionName)));
  3479. }
  3480. }
  3481. TStrings * FileList = new TStringList();
  3482. try
  3483. {
  3484. FileList->Add(FileName);
  3485. // consider using the same settings (preset) as when the file was downloaded
  3486. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3487. TemporaryFileCopyParam(CopyParam);
  3488. if (Data->ForceText)
  3489. {
  3490. CopyParam.TransferMode = tmAscii;
  3491. }
  3492. // so i do not need to worry if masking algorithm works in all cases
  3493. // ("" means "copy file name", no masking is actually done)
  3494. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3495. {
  3496. CopyParam.FileMask = L"";
  3497. }
  3498. else
  3499. {
  3500. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3501. }
  3502. DebugAssert(Data->Queue != NULL);
  3503. int Params = cpNoConfirmation | cpTemporary;
  3504. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3505. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3506. QueueItem->CompleteEvent = UploadCompleteEvent;
  3507. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3508. }
  3509. __finally
  3510. {
  3511. delete FileList;
  3512. }
  3513. }
  3514. //---------------------------------------------------------------------------
  3515. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3516. const UnicodeString FileName, const TEditedFileData * Data)
  3517. {
  3518. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3519. DebugAssert(!NonVisualDataModule->Busy);
  3520. if (!IsActiveTerminal(Data->Terminal))
  3521. {
  3522. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3523. (ExtractFileName(FileName), Data->SessionName)));
  3524. }
  3525. TManagedTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3526. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3527. NonVisualDataModule->StartBusy();
  3528. try
  3529. {
  3530. std::unique_ptr<TRemoteFile> File;
  3531. UnicodeString RemoteFileName =
  3532. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3533. FTerminal->ExceptionOnFail = true;
  3534. try
  3535. {
  3536. TRemoteFile * AFile = NULL;
  3537. FTerminal->ReadFile(RemoteFileName, AFile);
  3538. File.reset(AFile);
  3539. if (!File->HaveFullFileName)
  3540. {
  3541. File->FullFileName = RemoteFileName;
  3542. }
  3543. }
  3544. __finally
  3545. {
  3546. FTerminal->ExceptionOnFail = false;
  3547. }
  3548. std::unique_ptr<TStrings> FileList(new TStringList());
  3549. FileList->AddObject(RemoteFileName, File.get());
  3550. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3551. UnicodeString TempDir = ExtractFilePath(FileName);
  3552. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3553. TempDir, true, true, true);
  3554. // sanity check, the target file name should be still the same
  3555. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3556. }
  3557. __finally
  3558. {
  3559. NonVisualDataModule->EndBusy();
  3560. // it actually may not exist anymore...
  3561. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3562. }
  3563. }
  3564. //---------------------------------------------------------------------------
  3565. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3566. const TEditedFileData * Data, bool & KeepOpen)
  3567. {
  3568. // Command is set for external editors only (not for "shell" open).
  3569. if (!Data->Command.IsEmpty())
  3570. {
  3571. bool AnyFound = false;
  3572. bool AnyMDI = false;
  3573. bool AnyNonMDI = false;
  3574. bool AnyDetect = false;
  3575. TEditorList * EditorList = new TEditorList();
  3576. try
  3577. {
  3578. *EditorList = *WinConfiguration->EditorList;
  3579. for (int i = 0; i < EditorList->Count; i++)
  3580. {
  3581. const TEditorPreferences * Editor = EditorList->Editors[i];
  3582. if ((Editor->Data->Editor == edExternal) &&
  3583. (Editor->Data->ExternalEditor == Data->Command))
  3584. {
  3585. AnyFound = true;
  3586. if (Editor->Data->SDIExternalEditor)
  3587. {
  3588. AnyNonMDI = true;
  3589. if (Editor->Data->DetectMDIExternalEditor)
  3590. {
  3591. AnyDetect = true;
  3592. }
  3593. }
  3594. else
  3595. {
  3596. AnyMDI = true;
  3597. }
  3598. }
  3599. }
  3600. bool EnableMDI = false;
  3601. bool DisableDetect = false;
  3602. if (AnyMDI)
  3603. {
  3604. KeepOpen = true;
  3605. if (AnyNonMDI)
  3606. {
  3607. // there is at least one instance of the editor with MDI support enabled,
  3608. // and one with disabled, enable it for all instances
  3609. EnableMDI = true;
  3610. }
  3611. }
  3612. else if (AnyFound && !AnyDetect)
  3613. {
  3614. // at least once instance found but all have MDI autodetection disabled
  3615. // => close the file (default action)
  3616. }
  3617. else
  3618. {
  3619. // no instance of the editor has MDI support enabled
  3620. TMessageParams Params;
  3621. if (AnyFound)
  3622. {
  3623. // there is at least one instance of the editor
  3624. Params.Params |= mpNeverAskAgainCheck;
  3625. }
  3626. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3627. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3628. switch (Answer)
  3629. {
  3630. case qaNeverAskAgain:
  3631. DisableDetect = true;
  3632. break;
  3633. case qaNo:
  3634. EnableMDI = true;
  3635. KeepOpen = true;
  3636. break;
  3637. }
  3638. }
  3639. if (AnyFound && (EnableMDI || DisableDetect))
  3640. {
  3641. bool Changed = false;
  3642. for (int i = 0; i < EditorList->Count; i++)
  3643. {
  3644. const TEditorPreferences * Editor = EditorList->Editors[i];
  3645. if ((Editor->Data->Editor == edExternal) &&
  3646. (Editor->Data->ExternalEditor == Data->Command) &&
  3647. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3648. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3649. {
  3650. Changed = true;
  3651. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3652. if (EnableMDI)
  3653. {
  3654. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3655. }
  3656. if (DisableDetect)
  3657. {
  3658. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3659. }
  3660. EditorList->Change(i, UpdatedEditor);
  3661. }
  3662. }
  3663. if (Changed)
  3664. {
  3665. WinConfiguration->EditorList = EditorList;
  3666. }
  3667. }
  3668. }
  3669. __finally
  3670. {
  3671. delete EditorList;
  3672. }
  3673. }
  3674. else
  3675. {
  3676. // "open" case
  3677. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3678. qaOK, HELP_APP_EARLY_CLOSED);
  3679. }
  3680. }
  3681. //---------------------------------------------------------------------------
  3682. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3683. {
  3684. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3685. }
  3686. //---------------------------------------------------------------------------
  3687. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3688. {
  3689. SideEnter(osRemote);
  3690. }
  3691. //---------------------------------------------------------------------------
  3692. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3693. {
  3694. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3695. SideEnter(osRemote);
  3696. }
  3697. //---------------------------------------------------------------------------
  3698. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3699. {
  3700. FCurrentSide = Side;
  3701. if (Visible)
  3702. {
  3703. UpdateControls();
  3704. }
  3705. }
  3706. //---------------------------------------------------------------------------
  3707. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3708. TStrings * FileList, bool Alternative)
  3709. {
  3710. TCustomDirView * DView = DirView(Side);
  3711. DView->SaveSelection();
  3712. DView->SaveSelectedNames();
  3713. DebugAssert(!FAlternativeDelete);
  3714. FAlternativeDelete = Alternative;
  3715. try
  3716. {
  3717. if (!IsSideLocalBrowser(Side))
  3718. {
  3719. DebugAssert(Terminal != NULL);
  3720. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3721. }
  3722. else
  3723. {
  3724. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  3725. FProgressSide = FCurrentSide;
  3726. try
  3727. {
  3728. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3729. }
  3730. __finally
  3731. {
  3732. ReloadLocalDirectory();
  3733. }
  3734. }
  3735. FAlternativeDelete = false;
  3736. }
  3737. catch(...)
  3738. {
  3739. FAlternativeDelete = false;
  3740. DView->DiscardSavedSelection();
  3741. throw;
  3742. }
  3743. DView->RestoreSelection();
  3744. }
  3745. //---------------------------------------------------------------------------
  3746. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3747. {
  3748. DebugAssert(Terminal);
  3749. DebugAssert(!IsLocalBrowserMode());
  3750. RemoteDirView->SaveSelection();
  3751. RemoteDirView->SaveSelectedNames();
  3752. try
  3753. {
  3754. if (Lock)
  3755. {
  3756. Terminal->LockFiles(FileList);
  3757. }
  3758. else
  3759. {
  3760. Terminal->UnlockFiles(FileList);
  3761. }
  3762. }
  3763. catch(...)
  3764. {
  3765. RemoteDirView->DiscardSavedSelection();
  3766. throw;
  3767. }
  3768. RemoteDirView->RestoreSelection();
  3769. }
  3770. //---------------------------------------------------------------------------
  3771. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3772. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3773. bool NoConfirmation, bool Move)
  3774. {
  3775. DebugAssert(Terminal != NULL);
  3776. DebugAssert(!IsLocalBrowserMode());
  3777. // update Terminal->StateData->RemoteDirectory
  3778. UpdateTerminal(Terminal);
  3779. if (Session == NULL)
  3780. {
  3781. Session = TTerminalManager::Instance()->ActiveTerminal;
  3782. }
  3783. if (Session == TTerminalManager::Instance()->ActiveTerminal)
  3784. {
  3785. if (RemoteDriveView->DropTarget != NULL)
  3786. {
  3787. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3788. }
  3789. else if (RemoteDirView->DropTarget != NULL)
  3790. {
  3791. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3792. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3793. }
  3794. else
  3795. {
  3796. Target = RemoteDirView->Path;
  3797. }
  3798. }
  3799. else
  3800. {
  3801. Target = Session->StateData->RemoteDirectory;
  3802. }
  3803. Target = UnixIncludeTrailingBackslash(Target);
  3804. if (FileList->Count == 1)
  3805. {
  3806. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3807. }
  3808. else
  3809. {
  3810. FileMask = AnyMask;
  3811. }
  3812. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3813. bool Result = true;
  3814. if (!NoConfirmation)
  3815. {
  3816. bool Multi = (FileList->Count > 1);
  3817. if (Move)
  3818. {
  3819. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3820. }
  3821. else
  3822. {
  3823. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3824. TStrings * Directories = new TStringList;
  3825. try
  3826. {
  3827. for (int Index = 0; Index < Sessions->Count; Index++)
  3828. {
  3829. TManagedTerminal * Terminal =
  3830. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3831. Directories->Add(Terminal->StateData->RemoteDirectory);
  3832. }
  3833. TDirectRemoteCopy AllowDirectCopy;
  3834. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3835. {
  3836. DebugAssert(DirectCopy);
  3837. AllowDirectCopy = drcAllow;
  3838. }
  3839. else if (FTerminal->IsCapable[fcSecondaryShell])
  3840. {
  3841. DebugAssert(DirectCopy);
  3842. AllowDirectCopy = drcConfirmCommandSession;
  3843. }
  3844. else
  3845. {
  3846. DebugAssert(!DirectCopy);
  3847. AllowDirectCopy = drcDisallow;
  3848. }
  3849. void * ASession = Session;
  3850. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3851. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3852. Session = static_cast<TManagedTerminal *>(ASession);
  3853. }
  3854. __finally
  3855. {
  3856. delete Directories;
  3857. }
  3858. }
  3859. }
  3860. return Result;
  3861. }
  3862. //---------------------------------------------------------------------------
  3863. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3864. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3865. {
  3866. DebugAssert(!IsLocalBrowserMode());
  3867. bool DirectCopy;
  3868. UnicodeString Target, FileMask;
  3869. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3870. if (Result)
  3871. {
  3872. if (!Move && !DirectCopy)
  3873. {
  3874. Configuration->Usage->Inc("RemoteCopyTemp");
  3875. UnicodeString RootTempDir;
  3876. UnicodeString TempDir;
  3877. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3878. TStrings * TemporaryFilesList = new TStringList();
  3879. try
  3880. {
  3881. TMakeLocalFileListParams MakeFileListParam;
  3882. MakeFileListParam.FileList = TemporaryFilesList;
  3883. MakeFileListParam.FileTimes = NULL;
  3884. MakeFileListParam.IncludeDirs = true;
  3885. MakeFileListParam.Recursive = false;
  3886. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3887. TTerminalManager::Instance()->ActiveTerminal = Session;
  3888. if (TemporaryFilesList->Count > 0)
  3889. {
  3890. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3891. CopyParam.FileMask = FileMask;
  3892. DebugAssert(!FAutoOperation);
  3893. FAutoOperation = true;
  3894. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  3895. }
  3896. }
  3897. __finally
  3898. {
  3899. delete TemporaryFilesList;
  3900. FAutoOperation = false;
  3901. if (!RootTempDir.IsEmpty())
  3902. {
  3903. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3904. }
  3905. }
  3906. }
  3907. else
  3908. {
  3909. RemoteDirView->SaveSelection();
  3910. RemoteDirView->SaveSelectedNames();
  3911. try
  3912. {
  3913. if (Move)
  3914. {
  3915. Configuration->Usage->Inc("RemoteMove");
  3916. Terminal->MoveFiles(FileList, Target, FileMask);
  3917. }
  3918. else
  3919. {
  3920. Configuration->Usage->Inc("RemoteCopyDirect");
  3921. DebugAssert(DirectCopy);
  3922. DebugAssert(Session == FTerminal);
  3923. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3924. FTerminal->CommandSessionOpened ||
  3925. CommandSessionFallback())
  3926. {
  3927. Terminal->CopyFiles(FileList, Target, FileMask);
  3928. }
  3929. }
  3930. }
  3931. catch(...)
  3932. {
  3933. RemoteDirView->DiscardSavedSelection();
  3934. throw;
  3935. }
  3936. RemoteDirView->RestoreSelection();
  3937. }
  3938. }
  3939. return Result;
  3940. }
  3941. //---------------------------------------------------------------------------
  3942. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  3943. const UnicodeString & Path, TRemoteProperties & Properties)
  3944. {
  3945. DebugAssert(!IsLocalBrowserMode());
  3946. Properties.Valid = Properties.Valid << vpEncrypt;
  3947. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  3948. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  3949. }
  3950. //---------------------------------------------------------------------------
  3951. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3952. {
  3953. Side = GetSide(Side);
  3954. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3955. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  3956. UnicodeString Name = LoadStr(NEW_FOLDER);
  3957. int AllowedChanges =
  3958. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  3959. bool SaveSettings = false;
  3960. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3961. {
  3962. TWindowLock Lock(this);
  3963. if (!IsSideLocalBrowser(Side))
  3964. {
  3965. if (SaveSettings)
  3966. {
  3967. GUIConfiguration->NewDirectoryProperties = Properties;
  3968. }
  3969. CreateRemoteDirectory(Name, Properties);
  3970. }
  3971. else
  3972. {
  3973. DirView(Side)->CreateDirectory(Name);
  3974. }
  3975. }
  3976. }
  3977. //---------------------------------------------------------------------------
  3978. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3979. {
  3980. TWindowLock Lock(this);
  3981. DirView(Side)->ExecuteHomeDirectory();
  3982. }
  3983. //---------------------------------------------------------------------------
  3984. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3985. {
  3986. DoOpenDirectoryDialog(odBrowse, Side);
  3987. }
  3988. //---------------------------------------------------------------------------
  3989. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  3990. {
  3991. UnicodeString Path = Bookmark->GetSideDirectory(Side);
  3992. bool Result = !Path.IsEmpty();
  3993. if (Result)
  3994. {
  3995. // While we might get here when the session is closed (from location profiles),
  3996. // it's not a problem as the Path setter is noop then
  3997. DirView(Side)->Path = Path;
  3998. }
  3999. return Result;
  4000. }
  4001. //---------------------------------------------------------------------------
  4002. void __fastcall TCustomScpExplorerForm::CalculateSize(
  4003. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  4004. bool & Close)
  4005. {
  4006. // terminal can be already closed (e.g. dropped connection)
  4007. if (Terminal != NULL)
  4008. {
  4009. try
  4010. {
  4011. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, Stats);
  4012. }
  4013. catch(...)
  4014. {
  4015. if (!Terminal->Active)
  4016. {
  4017. Close = true;
  4018. }
  4019. throw;
  4020. }
  4021. }
  4022. }
  4023. //---------------------------------------------------------------------------
  4024. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4025. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4026. bool & Close)
  4027. {
  4028. // terminal can be already closed (e.g. dropped connection)
  4029. if (Terminal != NULL)
  4030. {
  4031. Configuration->Usage->Inc(L"ChecksumCalculated");
  4032. try
  4033. {
  4034. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4035. }
  4036. catch(...)
  4037. {
  4038. if (!Terminal->Active)
  4039. {
  4040. Close = true;
  4041. }
  4042. throw;
  4043. }
  4044. }
  4045. }
  4046. //---------------------------------------------------------------------------
  4047. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4048. {
  4049. bool Result;
  4050. if (!IsSideLocalBrowser(Side))
  4051. {
  4052. TRemoteTokenList * GroupList = NULL;
  4053. TRemoteTokenList * UserList = NULL;
  4054. try
  4055. {
  4056. TRemoteProperties CurrentProperties;
  4057. if (Terminal->LoadFilesProperties(FileList))
  4058. {
  4059. RemoteDirView->Invalidate();
  4060. }
  4061. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4062. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4063. if (CapableGroupChanging || CapableOwnerChanging)
  4064. {
  4065. if (CapableGroupChanging)
  4066. {
  4067. GroupList = Terminal->Groups->Duplicate();
  4068. }
  4069. if (CapableOwnerChanging)
  4070. {
  4071. UserList = Terminal->Users->Duplicate();
  4072. }
  4073. TRemoteDirectory * Files = Terminal->Files;
  4074. int Count = Files->Count;
  4075. if (Count > 100)
  4076. {
  4077. Count = 100;
  4078. }
  4079. for (int Index = 0; Index < Count; Index++)
  4080. {
  4081. TRemoteFile * File = Files->Files[Index];
  4082. if (CapableGroupChanging)
  4083. {
  4084. GroupList->AddUnique(File->Group);
  4085. }
  4086. if (CapableOwnerChanging)
  4087. {
  4088. UserList->AddUnique(File->Owner);
  4089. }
  4090. }
  4091. // if we haven't collected tokens for all files in current directory,
  4092. // make sure we collect them at least for all selected files.
  4093. // (note that so far the files in FileList has to be from current direcotry)
  4094. if (Count < Files->Count)
  4095. {
  4096. for (int Index = 0; Index < FileList->Count; Index++)
  4097. {
  4098. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4099. if (CapableGroupChanging)
  4100. {
  4101. GroupList->AddUnique(File->Group);
  4102. }
  4103. if (CapableOwnerChanging)
  4104. {
  4105. UserList->AddUnique(File->Owner);
  4106. }
  4107. }
  4108. }
  4109. }
  4110. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4111. int Flags = 0;
  4112. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4113. if (CapableOwnerChanging) Flags |= cpOwner;
  4114. if (CapableGroupChanging) Flags |= cpGroup;
  4115. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4116. if (Terminal->IsCapable[fcCalculatingChecksum])
  4117. {
  4118. CalculateChecksumEvent = CalculateChecksum;
  4119. }
  4120. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4121. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4122. TRemoteProperties NewProperties = CurrentProperties;
  4123. Result =
  4124. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4125. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4126. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4127. CalculateSize, CalculateChecksumEvent);
  4128. if (Result)
  4129. {
  4130. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4131. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4132. }
  4133. }
  4134. __finally
  4135. {
  4136. delete GroupList;
  4137. delete UserList;
  4138. }
  4139. }
  4140. else
  4141. {
  4142. DirView(Side)->DisplayPropertiesMenu();
  4143. Result = true;
  4144. }
  4145. return Result;
  4146. }
  4147. //---------------------------------------------------------------------------
  4148. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4149. {
  4150. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4151. {
  4152. FIgnoreNextDialogChar = Key;
  4153. }
  4154. Key = 0;
  4155. }
  4156. //---------------------------------------------------------------------------
  4157. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4158. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4159. {
  4160. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4161. if (Command != NULL)
  4162. {
  4163. KeyProcessed(Key, Shift);
  4164. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4165. {
  4166. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4167. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4168. false, false, const_cast<TCustomCommandType *>(Command));
  4169. }
  4170. }
  4171. }
  4172. //---------------------------------------------------------------------------
  4173. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4174. {
  4175. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4176. {
  4177. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4178. }
  4179. if (!DirView(osCurrent)->IsEditing())
  4180. {
  4181. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4182. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4183. {
  4184. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4185. // But so far it's not a problem, as it does what we want.
  4186. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4187. if (((Action->ShortCut == KeyShortCut) ||
  4188. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4189. AllowedAction(Action, aaShortCut))
  4190. {
  4191. // Has to be called before the action as the dialog char is already in queue.
  4192. // So when the action consumes message queue, we already need to have the
  4193. // FIgnoreNextDialogChar set
  4194. KeyProcessed(Key, Shift);
  4195. // Reset reference to previous component (when menu/toolbar was clicked).
  4196. // Needed to detect that action was invoked by keyboard shortcut
  4197. // in TNonVisualDataModule::ExplorerActionsExecute
  4198. Action->ActionComponent = NULL;
  4199. Action->Execute();
  4200. return;
  4201. }
  4202. }
  4203. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4204. {
  4205. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4206. {
  4207. KeyProcessed(Key, Shift);
  4208. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  4209. return;
  4210. }
  4211. }
  4212. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4213. {
  4214. KeyProcessed(Key, Shift);
  4215. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4216. }
  4217. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4218. if (IsCustomShortCut(CustomShortCut))
  4219. {
  4220. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4221. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4222. if (WinConfiguration->SharedBookmarks != NULL)
  4223. {
  4224. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4225. if ((Bookmark != NULL) &&
  4226. OpenBookmark(FCurrentSide, Bookmark))
  4227. {
  4228. KeyProcessed(Key, Shift);
  4229. }
  4230. }
  4231. }
  4232. }
  4233. TForm::KeyDown(Key, Shift);
  4234. }
  4235. //---------------------------------------------------------------------------
  4236. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4237. {
  4238. DebugAssert(Terminal != NULL);
  4239. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4240. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  4241. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4242. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4243. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  4244. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  4245. // expanded from ?: to avoid memory leaks
  4246. if (SecurityEnabled)
  4247. {
  4248. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  4249. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  4250. }
  4251. else
  4252. {
  4253. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  4254. }
  4255. if (FileSystemInfo.ProtocolName.IsEmpty())
  4256. {
  4257. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  4258. }
  4259. else
  4260. {
  4261. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  4262. }
  4263. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  4264. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  4265. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  4266. UnicodeString CSCompressionStr = DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR));
  4267. UnicodeString SCCompressionStr = DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR));
  4268. UnicodeString CompressionStr = CSCompressionStr;
  4269. if (CSCompressionStr != SCCompressionStr)
  4270. {
  4271. CompressionStr += UnicodeString(L"/") + SCCompressionStr;
  4272. }
  4273. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION_HINT, (CompressionStr));
  4274. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  4275. UpdateStatusBar();
  4276. }
  4277. //---------------------------------------------------------------------------
  4278. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4279. {
  4280. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4281. DebugAssert(SessionStatusBar != NULL);
  4282. if (!HasActiveTerminal() || (Terminal->Status < ssOpened))
  4283. {
  4284. // note: (Terminal->Status < sshReady) currently never happens here,
  4285. // so STATUS_CONNECTING is never used
  4286. SessionStatusBar->SimplePanel = true;
  4287. SessionStatusBar->SimpleText = LoadStr(
  4288. !HasActiveTerminal() ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  4289. }
  4290. else
  4291. {
  4292. DebugAssert(Terminal);
  4293. SessionStatusBar->SimplePanel = false;
  4294. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  4295. if (!FNote.IsEmpty())
  4296. {
  4297. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  4298. }
  4299. else
  4300. {
  4301. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  4302. }
  4303. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  4304. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  4305. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4306. }
  4307. }
  4308. //---------------------------------------------------------------------------
  4309. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4310. {
  4311. Panel->Caption = L"";
  4312. }
  4313. //---------------------------------------------------------------------------
  4314. void __fastcall TCustomScpExplorerForm::Idle()
  4315. {
  4316. if (FShowing || FStandaloneEditing)
  4317. {
  4318. FEditorManager->Check();
  4319. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4320. // that needs to know if queue view is visible (and it may be closed after queue update)
  4321. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4322. }
  4323. if (FShowing)
  4324. {
  4325. if (!NonVisualDataModule->Busy &&
  4326. // Menu is opened or drag&drop is going on
  4327. (Mouse->Capture == NULL))
  4328. {
  4329. if (FRefreshRemoteDirectory)
  4330. {
  4331. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4332. {
  4333. Terminal->RefreshDirectory();
  4334. }
  4335. FRefreshRemoteDirectory = false;
  4336. }
  4337. if (FRefreshLocalDirectory)
  4338. {
  4339. ReloadLocalDirectory();
  4340. FRefreshLocalDirectory = false;
  4341. }
  4342. if (WinConfiguration->RefreshRemotePanel)
  4343. {
  4344. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4345. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4346. {
  4347. RemoteDirView->ReloadDirectory();
  4348. }
  4349. }
  4350. }
  4351. }
  4352. if (FShowing || FStandaloneEditing)
  4353. {
  4354. if (FQueueStatusInvalidated)
  4355. {
  4356. UpdateQueueStatus(false);
  4357. }
  4358. RefreshQueueItems();
  4359. }
  4360. if (FShowing)
  4361. {
  4362. UpdateStatusBar();
  4363. }
  4364. FIgnoreNextDialogChar = 0;
  4365. }
  4366. //---------------------------------------------------------------------------
  4367. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4368. {
  4369. try
  4370. {
  4371. FUserActionTimer->Enabled = false;
  4372. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4373. {
  4374. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4375. {
  4376. FPendingQueueActionItem->ProcessUserAction();
  4377. }
  4378. }
  4379. }
  4380. __finally
  4381. {
  4382. FPendingQueueActionItem = NULL;
  4383. }
  4384. }
  4385. //---------------------------------------------------------------------------
  4386. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4387. {
  4388. if (WinConfiguration->MinimizeToTray)
  4389. {
  4390. UpdateTrayIcon();
  4391. FTrayIcon->Visible = true;
  4392. if (Visible)
  4393. {
  4394. ShowWindow(Handle, SW_HIDE);
  4395. }
  4396. }
  4397. }
  4398. //---------------------------------------------------------------------------
  4399. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4400. {
  4401. // WORKAROUND
  4402. // When restoring maximized window from minimization,
  4403. // rarely some controls do not align properly.
  4404. // Two instances seen (both for Commander):
  4405. // - When restoring, window is temporarily narrower (not maximized),
  4406. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4407. // Once maximized already, top dock shinks back, but the session PageControl,
  4408. // do not align up, leaving space between TopDock and PageControl.
  4409. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4410. for (int Index = 0; Index < ControlCount; Index++)
  4411. {
  4412. RealignControl(Controls[Index]);
  4413. }
  4414. if (FTrayIcon->Visible)
  4415. {
  4416. FTrayIcon->Visible = false;
  4417. if (Visible)
  4418. {
  4419. ShowWindow(Handle, SW_SHOW);
  4420. }
  4421. }
  4422. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4423. {
  4424. FNeedSession = false;
  4425. NonVisualDataModule->StartBusy();
  4426. try
  4427. {
  4428. NeedSession(true);
  4429. }
  4430. __finally
  4431. {
  4432. NonVisualDataModule->EndBusy();
  4433. }
  4434. }
  4435. }
  4436. //---------------------------------------------------------------------------
  4437. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4438. {
  4439. FTrayIcon->Hint = GetMainForm()->Caption;
  4440. }
  4441. //---------------------------------------------------------------------------
  4442. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4443. {
  4444. UpdateTrayIcon();
  4445. }
  4446. //---------------------------------------------------------------------------
  4447. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4448. {
  4449. // workaround
  4450. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4451. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4452. // But WM_ACTIVATEAPP message can be received even when
  4453. // the main window is minimized to the tray and internal editor window is focused
  4454. // (after another application was previously active)
  4455. if (::IsIconic(Handle))
  4456. {
  4457. if (!IsAppIconic())
  4458. {
  4459. SetAppIconic(true);
  4460. }
  4461. }
  4462. ::ApplicationRestore();
  4463. Application->BringToFront();
  4464. }
  4465. //---------------------------------------------------------------------------
  4466. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4467. {
  4468. RestoreApp();
  4469. }
  4470. //---------------------------------------------------------------------------
  4471. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4472. {
  4473. if (OpenInNewWindow())
  4474. {
  4475. // todo: Pass FromSite
  4476. ExecuteNewInstance(SessionUrl);
  4477. }
  4478. else
  4479. {
  4480. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4481. }
  4482. }
  4483. //---------------------------------------------------------------------------
  4484. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4485. {
  4486. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->SessionName;
  4487. StoredSessions->NewSession(SessionName, SessionData);
  4488. // modified only, explicit
  4489. StoredSessions->Save(false, true);
  4490. // encode session name because of slashes in hierarchical sessions
  4491. return EncodeUrlString(SessionName);
  4492. }
  4493. //---------------------------------------------------------------------------
  4494. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4495. {
  4496. // current working directories become defaults here, what is not right
  4497. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4498. return SaveHiddenDuplicateSession(SessionData.get());
  4499. }
  4500. //---------------------------------------------------------------------------
  4501. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4502. {
  4503. if (OpenInNewWindow())
  4504. {
  4505. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4506. }
  4507. else
  4508. {
  4509. // current working directories become defaults here, what is not right
  4510. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4511. TTerminalManager * Manager = TTerminalManager::Instance();
  4512. TManagedTerminal * Terminal = Manager->NewManagedTerminal(SessionData.get());
  4513. Manager->ActiveTerminal = Terminal;
  4514. }
  4515. }
  4516. //---------------------------------------------------------------------------
  4517. void __fastcall TCustomScpExplorerForm::RenameSession()
  4518. {
  4519. UnicodeString Name = Terminal->SessionData->SessionName;
  4520. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME))
  4521. {
  4522. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4523. TSessionData::ValidateName(Name);
  4524. // This is inconsistent with how color (for example) is handled.
  4525. Terminal->SessionData->Name = Name;
  4526. UpdateControls();
  4527. // Add/Remove distinguishing paths from sessions of the same name.
  4528. DoTerminalListChanged();
  4529. }
  4530. }
  4531. //---------------------------------------------------------------------------
  4532. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4533. {
  4534. DebugAssert(Queue != NULL);
  4535. bool Result = Queue->IsEmpty;
  4536. if (!Result)
  4537. {
  4538. SetFocus();
  4539. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4540. }
  4541. return Result;
  4542. }
  4543. //---------------------------------------------------------------------------
  4544. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4545. {
  4546. return CanCloseQueue(FQueue);
  4547. }
  4548. //---------------------------------------------------------------------------
  4549. void __fastcall TCustomScpExplorerForm::CloseSession()
  4550. {
  4551. if (CanCloseQueue())
  4552. {
  4553. TTerminalManager::Instance()->FreeActiveTerminal();
  4554. }
  4555. }
  4556. //---------------------------------------------------------------------------
  4557. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4558. {
  4559. if (CanCloseQueue())
  4560. {
  4561. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4562. }
  4563. }
  4564. //---------------------------------------------------------------------------
  4565. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4566. {
  4567. DetachTerminal(Terminal);
  4568. RemoteDirView->Terminal = Terminal;
  4569. UpdateRemotePathComboBox(false);
  4570. UpdateControls();
  4571. }
  4572. //---------------------------------------------------------------------------
  4573. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4574. {
  4575. if (DebugAlwaysTrue(!Terminal->Active))
  4576. {
  4577. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4578. }
  4579. }
  4580. //---------------------------------------------------------------------------
  4581. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4582. {
  4583. if (OpenInNewWindow())
  4584. {
  4585. // encode session name because of slashes in hierarchical sessions
  4586. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4587. }
  4588. else
  4589. {
  4590. TTerminalManager * Manager = TTerminalManager::Instance();
  4591. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4592. Manager->ActiveTerminal = Terminal;
  4593. }
  4594. }
  4595. //---------------------------------------------------------------------------
  4596. void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
  4597. {
  4598. TTerminalManager * Manager = TTerminalManager::Instance();
  4599. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4600. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4601. TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
  4602. // FirstTerminal can be null, if some of the
  4603. if (!ConnectFirstTerminal && (FirstTerminal != NULL))
  4604. {
  4605. FirstTerminal->Disconnected = true;
  4606. FirstTerminal->DisconnectedTemporarily = true;
  4607. }
  4608. Manager->ActiveTerminal = FirstTerminal;
  4609. }
  4610. //---------------------------------------------------------------------------
  4611. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4612. {
  4613. if (OpenInNewWindow())
  4614. {
  4615. ExecuteNewInstance(Name);
  4616. }
  4617. else
  4618. {
  4619. DoOpenFolderOrWorkspace(Name, true);
  4620. }
  4621. }
  4622. //---------------------------------------------------------------------------
  4623. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4624. bool &CanClose)
  4625. {
  4626. // See the comment in CloseApp()
  4627. if (NonVisualDataModule->Busy)
  4628. {
  4629. CanClose = false;
  4630. }
  4631. else if (Terminal != NULL)
  4632. {
  4633. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4634. {
  4635. unsigned int Result;
  4636. TMessageParams Params(mpNeverAskAgainCheck);
  4637. UnicodeString Message;
  4638. int Answers = qaOK | qaCancel;
  4639. if (TTerminalManager::Instance()->Count > 1)
  4640. {
  4641. if (!WinConfiguration->AutoSaveWorkspace)
  4642. {
  4643. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4644. }
  4645. else
  4646. {
  4647. Message = LoadStr(CLOSE_SESSIONS);
  4648. }
  4649. }
  4650. else
  4651. {
  4652. if (!WinConfiguration->AutoSaveWorkspace)
  4653. {
  4654. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4655. }
  4656. else
  4657. {
  4658. Message = LoadStr(CLOSE_SESSION);
  4659. }
  4660. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4661. }
  4662. UnicodeString Note;
  4663. if (WinConfiguration->AutoSaveWorkspace)
  4664. {
  4665. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4666. }
  4667. else
  4668. {
  4669. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4670. Answers = qaYes | qaNo | qaCancel;
  4671. }
  4672. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4673. SetFocus();
  4674. Result = MessageDialog(Message, qtConfirmation,
  4675. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4676. if (Result == qaNeverAskAgain)
  4677. {
  4678. WinConfiguration->ConfirmClosingSession = false;
  4679. }
  4680. if (Result == qaNo)
  4681. {
  4682. CanClose = SaveWorkspace(true);
  4683. // note that the workspace will be saved redundatly again from FormClose
  4684. }
  4685. else
  4686. {
  4687. CanClose =
  4688. (Result == qaOK) ||
  4689. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4690. (Result == qaNeverAskAgain);
  4691. }
  4692. }
  4693. if (CanClose)
  4694. {
  4695. CanClose = CanCloseQueue();
  4696. }
  4697. }
  4698. if (CanClose)
  4699. {
  4700. CanClose =
  4701. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4702. FEditorManager->CloseExternalFilesWithoutProcess();
  4703. if (CanClose)
  4704. {
  4705. while (CanClose && (FLocalEditors->Count > 0))
  4706. {
  4707. int PrevCount = FLocalEditors->Count;
  4708. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4709. CanClose = (FLocalEditors->Count < PrevCount);
  4710. }
  4711. if (CanClose)
  4712. {
  4713. CanClose = FEditorManager->Empty(true);
  4714. if (!CanClose)
  4715. {
  4716. SetFocus();
  4717. CanClose =
  4718. (MessageDialog(
  4719. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4720. }
  4721. }
  4722. }
  4723. }
  4724. }
  4725. //---------------------------------------------------------------------------
  4726. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4727. {
  4728. TForm * Form = dynamic_cast<TForm *>(Sender);
  4729. DebugAssert(Form != NULL);
  4730. Form->Close();
  4731. }
  4732. //---------------------------------------------------------------------------
  4733. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4734. {
  4735. TForm * Form = dynamic_cast<TForm *>(Sender);
  4736. delete Form;
  4737. }
  4738. //---------------------------------------------------------------------------
  4739. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4740. {
  4741. while (FLocalEditors->Count > 0)
  4742. {
  4743. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4744. }
  4745. }
  4746. //---------------------------------------------------------------------------
  4747. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4748. TObject *Sender)
  4749. {
  4750. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4751. try
  4752. {
  4753. SetProperties(osRemote, FileList);
  4754. }
  4755. __finally
  4756. {
  4757. delete FileList;
  4758. }
  4759. }
  4760. //---------------------------------------------------------------------------
  4761. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4762. {
  4763. if (value)
  4764. {
  4765. if (Component == fcCustomCommandsBand)
  4766. {
  4767. UpdateCustomCommandsToolbar();
  4768. }
  4769. if (Component == fcQueueFileList)
  4770. {
  4771. DebugAssert(!QueueFileListSplitter->Visible);
  4772. AdjustQueueLayout();
  4773. UpdateQueueFileList();
  4774. }
  4775. }
  4776. }
  4777. //---------------------------------------------------------------------------
  4778. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4779. {
  4780. int MinHeightLimit =
  4781. GetStaticQueuePanelComponentsHeight() +
  4782. QueueFileListSplitter->Height +
  4783. QueueFileList->Height +
  4784. GetMinQueueViewHeight();
  4785. if (QueuePanel->ClientHeight < MinHeightLimit)
  4786. {
  4787. QueuePanel->ClientHeight = MinHeightLimit;
  4788. }
  4789. }
  4790. //---------------------------------------------------------------------------
  4791. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4792. {
  4793. TControl * Control = GetComponent(Component);
  4794. DebugAssert(Control);
  4795. bool Changed = (Control->Visible != value);
  4796. if (Changed)
  4797. {
  4798. ComponentShowing(Component, value);
  4799. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4800. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4801. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4802. if (value)
  4803. {
  4804. int RemainingHeight = Control->Parent->ClientHeight;
  4805. int RemainingWidth = Control->Parent->ClientWidth;
  4806. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4807. {
  4808. TControl * ChildControl = Control->Parent->Controls[i];
  4809. if (ChildControl->Visible)
  4810. {
  4811. switch (ChildControl->Align)
  4812. {
  4813. case alTop:
  4814. case alBottom:
  4815. RemainingHeight -= ChildControl->Height;
  4816. break;
  4817. case alLeft:
  4818. case alRight:
  4819. RemainingWidth -= ChildControl->Width;
  4820. break;
  4821. }
  4822. }
  4823. }
  4824. int Reserve = ScaleByTextHeight(this, 32);
  4825. // queue in explorer, trees in commander
  4826. if (Control->Height > RemainingHeight - Reserve)
  4827. {
  4828. Control->Height = RemainingHeight / 2;
  4829. }
  4830. if (Control->Width > RemainingWidth - Reserve)
  4831. {
  4832. Control->Width = RemainingWidth / 2;
  4833. }
  4834. }
  4835. Control->Visible = value;
  4836. if (WasFocused && Visible)
  4837. {
  4838. DirView(osCurrent)->SetFocus();
  4839. }
  4840. FixControlsPlacement();
  4841. }
  4842. }
  4843. //---------------------------------------------------------------------------
  4844. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4845. {
  4846. TControl * Control = GetComponent(Component);
  4847. if (Control == NULL)
  4848. {
  4849. return false;
  4850. }
  4851. else
  4852. {
  4853. return Control->Visible;
  4854. }
  4855. }
  4856. //---------------------------------------------------------------------------
  4857. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  4858. {
  4859. bool Result;
  4860. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  4861. {
  4862. Result = !IsUWP();
  4863. }
  4864. else
  4865. {
  4866. Result = true;
  4867. }
  4868. return Result;
  4869. }
  4870. //---------------------------------------------------------------------------
  4871. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  4872. {
  4873. if (DirView->ItemFocused != NULL)
  4874. {
  4875. DirView->ItemFocused->MakeVisible(false);
  4876. }
  4877. }
  4878. //---------------------------------------------------------------------------
  4879. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4880. {
  4881. MakeFocusedItemVisible(RemoteDirView);
  4882. QueueSplitter->Visible = QueuePanel->Visible;
  4883. QueueFileListSplitter->Visible = QueueFileList->Visible;
  4884. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  4885. TControl * QueueControlsOrder[] =
  4886. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  4887. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  4888. }
  4889. //---------------------------------------------------------------------------
  4890. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4891. {
  4892. switch (Component) {
  4893. case fcStatusBar: return RemoteStatusBar;
  4894. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4895. case fcQueueView: return QueuePanel;
  4896. case fcQueueToolbar: return QueueDock;
  4897. case fcRemoteTree: return RemoteDrivePanel;
  4898. case fcSessionsTabs: return SessionsPageControl;
  4899. case fcQueueFileList: return QueueFileList;
  4900. default: return NULL;
  4901. }
  4902. }
  4903. //---------------------------------------------------------------------------
  4904. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4905. TObject *Sender, TListColumn *Column, TPoint &Point)
  4906. {
  4907. DebugAssert(NonVisualDataModule && Column && Sender);
  4908. NonVisualDataModule->ListColumn = Column;
  4909. TPopupMenu * DirViewColumnMenu;
  4910. if (Sender == DirView(osOther))
  4911. {
  4912. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4913. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4914. (Column->Index == uvName);
  4915. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4916. (Column->Index == uvSize);
  4917. }
  4918. else
  4919. {
  4920. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4921. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4922. (Column->Index == dvName);
  4923. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4924. (Column->Index == dvSize);
  4925. }
  4926. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  4927. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  4928. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  4929. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4930. }
  4931. //---------------------------------------------------------------------------
  4932. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4933. TObject *Sender, TListItem *Item, bool &AllowExec)
  4934. {
  4935. DoDirViewExecFile(Sender, Item, AllowExec);
  4936. }
  4937. //---------------------------------------------------------------------------
  4938. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4939. TListItem * Item, bool & AllowExec)
  4940. {
  4941. DebugAssert(Sender && Item && Configuration);
  4942. DebugAssert(AllowExec);
  4943. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4944. bool Remote = (ADirView == DirView(osRemote)) && !IsSideLocalBrowser(osRemote);
  4945. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks;
  4946. TOperationSide Side = (Remote ? osRemote : osLocal); // TODO
  4947. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4948. // on files only (not directories)
  4949. // and only when symlinks are resolved (apply to remote panel only)
  4950. if (!ADirView->ItemIsDirectory(Item) &&
  4951. (ResolvedSymlinks || FForceExecution || Terminal->IsEncryptingFiles()))
  4952. {
  4953. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4954. !FForceExecution &&
  4955. (ResolvedSymlinks || Terminal->IsEncryptingFiles()))
  4956. {
  4957. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4958. {
  4959. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  4960. UnlockWindow();
  4961. try
  4962. {
  4963. ExecuteFileOperation(
  4964. foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4965. }
  4966. __finally
  4967. {
  4968. LockWindow();
  4969. }
  4970. AllowExec = false;
  4971. }
  4972. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4973. {
  4974. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4975. {
  4976. ExecuteFile(Side, efDefaultEditor);
  4977. AllowExec = false;
  4978. }
  4979. }
  4980. else
  4981. {
  4982. DebugFail();
  4983. }
  4984. }
  4985. // if we have not done anything special, fall back to default behavior
  4986. if (AllowExec)
  4987. {
  4988. if (Remote && !WinConfiguration->DisableOpenEdit)
  4989. {
  4990. ExecuteFile(osRemote, efShell);
  4991. AllowExec = false;
  4992. }
  4993. }
  4994. }
  4995. }
  4996. //---------------------------------------------------------------------------
  4997. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4998. {
  4999. return ((Side == osRemote) || (Side == osCurrent));
  5000. }
  5001. //---------------------------------------------------------------------------
  5002. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5003. {
  5004. DebugFail();
  5005. }
  5006. //---------------------------------------------------------------------------
  5007. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5008. {
  5009. DebugFail();
  5010. }
  5011. //---------------------------------------------------------------------------
  5012. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5013. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5014. {
  5015. TSynchronizeParamType Params;
  5016. Params.LocalDirectory = LocalDirectory;
  5017. Params.RemoteDirectory = RemoteDirectory;
  5018. int UnusedParams =
  5019. (GUIConfiguration->SynchronizeParams &
  5020. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize));
  5021. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5022. Params.Options = GUIConfiguration->SynchronizeOptions;
  5023. bool SaveSettings = false;
  5024. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5025. &DoSynchronizeTooManyDirectories);
  5026. DebugAssert(FSynchronizeController == NULL);
  5027. FSynchronizeController = &Controller;
  5028. bool Result;
  5029. try
  5030. {
  5031. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5032. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5033. int Options =
  5034. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5035. DebugAssert(FOnFeedSynchronizeError == NULL);
  5036. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5037. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5038. FOnFeedSynchronizeError, SynchronizeInNewWindow, UseDefaults);
  5039. if (Result)
  5040. {
  5041. if (SaveSettings)
  5042. {
  5043. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5044. GUIConfiguration->SynchronizeOptions = Params.Options;
  5045. }
  5046. else
  5047. {
  5048. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5049. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5050. FLAGSET(Params.Options, soSynchronize))
  5051. {
  5052. GUIConfiguration->SynchronizeOptions =
  5053. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5054. soSynchronize;
  5055. }
  5056. }
  5057. LocalDirectory = Params.LocalDirectory;
  5058. RemoteDirectory = Params.RemoteDirectory;
  5059. }
  5060. }
  5061. __finally
  5062. {
  5063. FSynchronizeController = NULL;
  5064. DebugAssert(FOnFeedSynchronizeError == NULL);
  5065. FOnFeedSynchronizeError = NULL;
  5066. }
  5067. return Result;
  5068. }
  5069. //---------------------------------------------------------------------------
  5070. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5071. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5072. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5073. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5074. TSynchronizeOptions * Options, bool Full)
  5075. {
  5076. // Keep-up-to-date mode
  5077. if (Terminal->Status == ssOpened)
  5078. {
  5079. try
  5080. {
  5081. int PParams = Params.Params;
  5082. if (!Full)
  5083. {
  5084. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5085. if (FLAGSET(Params.Options, soRecurse))
  5086. {
  5087. PParams |= TTerminal::spSubDirs;
  5088. }
  5089. }
  5090. else
  5091. {
  5092. // if keepuptodate is non-recursive,
  5093. // full sync before has to be non-recursive as well
  5094. if (FLAGCLEAR(Params.Options, soRecurse))
  5095. {
  5096. PParams |= TTerminal::spNoRecurse;
  5097. }
  5098. }
  5099. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5100. PParams, Checklist, Options);
  5101. }
  5102. catch (Exception & E)
  5103. {
  5104. if (FLAGSET(Params.Options, soContinueOnError) && Terminal->Active &&
  5105. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5106. {
  5107. // noop, already logged in MoreMessageDialog
  5108. }
  5109. else
  5110. {
  5111. ShowExtendedExceptionEx(Terminal, &E);
  5112. throw;
  5113. }
  5114. }
  5115. }
  5116. }
  5117. //---------------------------------------------------------------------------
  5118. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5119. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5120. const UnicodeString ErrorStr)
  5121. {
  5122. if (!Directory.IsEmpty())
  5123. {
  5124. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5125. }
  5126. else
  5127. {
  5128. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5129. }
  5130. }
  5131. //---------------------------------------------------------------------------
  5132. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5133. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5134. {
  5135. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5136. {
  5137. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5138. }
  5139. else
  5140. {
  5141. TMessageParams Params(mpNeverAskAgainCheck);
  5142. unsigned int Result = MessageDialog(
  5143. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5144. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5145. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5146. {
  5147. MaxDirectories *= 2;
  5148. if (Result == qaNeverAskAgain)
  5149. {
  5150. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5151. }
  5152. }
  5153. else
  5154. {
  5155. Abort();
  5156. }
  5157. }
  5158. }
  5159. //---------------------------------------------------------------------------
  5160. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5161. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5162. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5163. TSynchronizeOptions * Options)
  5164. {
  5165. // Keep-up-to-date mode
  5166. DebugAssert(!FAutoOperation);
  5167. void * BatchStorage;
  5168. BatchStart(BatchStorage);
  5169. FAutoOperation = true;
  5170. bool AnyOperation = false;
  5171. TDateTime StartTime = Now();
  5172. TSynchronizeChecklist * AChecklist = NULL;
  5173. try
  5174. {
  5175. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5176. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5177. {
  5178. FSynchronizeProgressForm->Start();
  5179. }
  5180. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5181. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5182. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5183. Options);
  5184. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5185. SAFE_DESTROY(FSynchronizeProgressForm);
  5186. AnyOperation = (AChecklist->CheckedCount > 0);
  5187. if (AnyOperation)
  5188. {
  5189. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5190. CreateProgressForm(&SynchronizeProgress);
  5191. try
  5192. {
  5193. Terminal->SynchronizeApply(
  5194. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5195. SynchronizeProcessedItem, NULL, NULL, NULL);
  5196. }
  5197. __finally
  5198. {
  5199. DestroyProgressForm();
  5200. }
  5201. }
  5202. }
  5203. __finally
  5204. {
  5205. if (Checklist == NULL)
  5206. {
  5207. delete AChecklist;
  5208. }
  5209. else
  5210. {
  5211. *Checklist = AChecklist;
  5212. }
  5213. FAutoOperation = false;
  5214. SAFE_DESTROY(FSynchronizeProgressForm);
  5215. BatchEnd(BatchStorage);
  5216. ReloadLocalDirectory();
  5217. if (AnyOperation)
  5218. {
  5219. OperationComplete(StartTime);
  5220. }
  5221. }
  5222. }
  5223. //---------------------------------------------------------------------------
  5224. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5225. {
  5226. // can be called from command line
  5227. return Visible &&
  5228. ((DirView(osRemote)->SelCount > 0) ||
  5229. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5230. }
  5231. //---------------------------------------------------------------------------
  5232. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5233. {
  5234. LogSynchronizeEvent(Terminal, Message);
  5235. }
  5236. //---------------------------------------------------------------------------
  5237. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5238. int Params, TSynchronizeOptions & Options)
  5239. {
  5240. DebugAssert(!IsLocalBrowserMode());
  5241. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5242. {
  5243. Options.Filter = new TStringList();
  5244. Options.Filter->CaseSensitive = false;
  5245. Options.Filter->Duplicates = Types::dupAccept;
  5246. if (DirView(osRemote)->SelCount > 0)
  5247. {
  5248. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5249. }
  5250. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5251. {
  5252. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5253. }
  5254. Options.Filter->Sort();
  5255. }
  5256. }
  5257. //---------------------------------------------------------------------------
  5258. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5259. {
  5260. TCopyParamType Defaults;
  5261. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5262. ConfigStorage->AccessMode = smRead;
  5263. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5264. {
  5265. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5266. }
  5267. ConfigStorage.reset(NULL);
  5268. std::unique_ptr<TStringList> Options(new TStringList());
  5269. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5270. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5271. UnicodeString Result;
  5272. if (Options->Count > 0)
  5273. {
  5274. Result =
  5275. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5276. }
  5277. return Result;
  5278. }
  5279. //---------------------------------------------------------------------------
  5280. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5281. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5282. {
  5283. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5284. UnicodeString AdditionalParams =
  5285. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5286. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5287. SerializeCopyParamForCommandLine(CopyParams),
  5288. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5289. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5290. ExecuteNewInstance(SessionName, AdditionalParams);
  5291. }
  5292. //---------------------------------------------------------------------------
  5293. struct TSynchronizeParams
  5294. {
  5295. UnicodeString LocalDirectory;
  5296. UnicodeString RemoteDirectory;
  5297. TSynchronizeMode Mode;
  5298. TSynchronizeChecklist * Checklist;
  5299. int Params;
  5300. TCopyParamType * CopyParam;
  5301. TDateTime CollectElapsed;
  5302. TDateTime * StartTime;
  5303. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5304. };
  5305. //---------------------------------------------------------------------------
  5306. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5307. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5308. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5309. {
  5310. DebugAssert(!FAutoOperation);
  5311. void * BatchStorage;
  5312. BatchStart(BatchStorage);
  5313. FAutoOperation = true;
  5314. TFileOperationStatistics Statistics;
  5315. TDateTime Start = Now();
  5316. try
  5317. {
  5318. Params.OnProcessedItem = OnProcessedItem;
  5319. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5320. CreateProgressForm(&SynchronizeProgress);
  5321. Terminal->SynchronizeApply(
  5322. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5323. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5324. &Statistics);
  5325. }
  5326. __finally
  5327. {
  5328. Params.OnProcessedItem = NULL;
  5329. FAutoOperation = false;
  5330. DestroyProgressForm();
  5331. BatchEnd(BatchStorage);
  5332. ReloadLocalDirectory();
  5333. }
  5334. if (WinConfiguration->SynchronizeSummary)
  5335. {
  5336. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5337. // The statistics should be 0 anyway in this case
  5338. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5339. {
  5340. Message += L"\n";
  5341. if (Statistics.FilesUploaded > 0)
  5342. {
  5343. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5344. }
  5345. if (Statistics.FilesDownloaded > 0)
  5346. {
  5347. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5348. }
  5349. if (Statistics.FilesDeletedLocal > 0)
  5350. {
  5351. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5352. }
  5353. if (Statistics.FilesDeletedRemote > 0)
  5354. {
  5355. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5356. }
  5357. }
  5358. TDateTime Elapsed = (Now() - Start);
  5359. Message +=
  5360. L"\n" +
  5361. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5362. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5363. TMessageParams Params(mpNeverAskAgainCheck);
  5364. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5365. if (Result == qaNeverAskAgain)
  5366. {
  5367. WinConfiguration->SynchronizeSummary = false;
  5368. }
  5369. }
  5370. }
  5371. //---------------------------------------------------------------------------
  5372. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5373. {
  5374. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5375. {
  5376. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5377. }
  5378. // Not set in keep-up-to-date mode - Synchronize() method
  5379. if (Token != NULL)
  5380. {
  5381. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5382. if (Params.OnProcessedItem != NULL)
  5383. {
  5384. Params.OnProcessedItem(NULL, ChecklistItem);
  5385. }
  5386. }
  5387. }
  5388. //---------------------------------------------------------------------------
  5389. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5390. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5391. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5392. {
  5393. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5394. *Params.StartTime = Now();
  5395. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5396. }
  5397. //---------------------------------------------------------------------------
  5398. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5399. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5400. {
  5401. // terminal can be already closed (e.g. dropped connection)
  5402. if (Terminal != NULL)
  5403. {
  5404. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5405. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5406. }
  5407. }
  5408. //---------------------------------------------------------------------------
  5409. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5410. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5411. {
  5412. DebugAssert(!IsLocalBrowserMode());
  5413. TAutoBatch AutoBatch(this);
  5414. TAutoFlag AutoOperationFlag(FAutoOperation);
  5415. if (Side == osRemote)
  5416. {
  5417. std::unique_ptr<TStrings> FileList(new TStringList());
  5418. FileList->AddObject(FileName, RemoteFile);
  5419. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5420. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5421. RemoteDirView->SaveSelection();
  5422. RemoteDirView->SaveSelectedNames();
  5423. try
  5424. {
  5425. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5426. }
  5427. catch(...)
  5428. {
  5429. RemoteDirView->DiscardSavedSelection();
  5430. throw;
  5431. }
  5432. RemoteDirView->RestoreSelection();
  5433. }
  5434. else if (DebugAlwaysTrue(Side == osLocal))
  5435. {
  5436. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5437. {
  5438. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5439. }
  5440. UnicodeString Directory = ExtractFileDir(FileName);
  5441. ReloadLocalDirectory(Directory);
  5442. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5443. if (!SamePaths(Directory, NewDirectory))
  5444. {
  5445. ReloadLocalDirectory(NewDirectory);
  5446. }
  5447. }
  5448. }
  5449. //---------------------------------------------------------------------------
  5450. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5451. {
  5452. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5453. if (Side == osLocal)
  5454. {
  5455. if (Action == TSynchronizeChecklist::saDownloadNew)
  5456. {
  5457. OpenFolderInExplorer(LocalPath);
  5458. }
  5459. else
  5460. {
  5461. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5462. }
  5463. }
  5464. else if (DebugAlwaysTrue(Side == osRemote))
  5465. {
  5466. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5467. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5468. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5469. if (!LocalPath.IsEmpty())
  5470. {
  5471. SessionData->LocalDirectory = LocalPath;
  5472. }
  5473. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5474. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5475. }
  5476. }
  5477. //---------------------------------------------------------------------------
  5478. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5479. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5480. const TCopyParamType * CopyParams)
  5481. {
  5482. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5483. UnicodeString AdditionalParams =
  5484. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5485. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5486. SerializeCopyParamForCommandLine(CopyParams),
  5487. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5488. LocalDirectory, RemoteDirectory, Mode, Params));
  5489. ExecuteNewInstance(SessionName, AdditionalParams);
  5490. }
  5491. //---------------------------------------------------------------------------
  5492. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5493. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5494. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5495. {
  5496. int Result;
  5497. bool SaveSettings = false;
  5498. int Options =
  5499. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5500. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5501. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5502. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5503. bool Continue =
  5504. (UseDefaults == 0) ||
  5505. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5506. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5507. if (Continue)
  5508. {
  5509. Configuration->Usage->Inc(L"Synchronizations");
  5510. UpdateCopyParamCounters(CopyParam);
  5511. TSynchronizeOptions SynchronizeOptions;
  5512. GetSynchronizeOptions(Params, SynchronizeOptions);
  5513. if (SaveSettings)
  5514. {
  5515. GUIConfiguration->SynchronizeParams = Params;
  5516. }
  5517. else
  5518. {
  5519. SaveMode = false;
  5520. }
  5521. TDateTime StartTime = Now();
  5522. TSynchronizeChecklist * Checklist = NULL;
  5523. try
  5524. {
  5525. DebugAssert(!FAutoOperation);
  5526. FAutoOperation = true;
  5527. try
  5528. {
  5529. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5530. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5531. int Files = -1;
  5532. if (DataList->Count >= 1)
  5533. {
  5534. Files = StrToIntDef(DataList->Strings[0], Files);
  5535. }
  5536. else
  5537. {
  5538. DataList->Add(UnicodeString());
  5539. }
  5540. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5541. FSynchronizeProgressForm->Start();
  5542. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5543. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5544. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5545. &SynchronizeOptions);
  5546. if (Terminal->SessionData->CacheDirectories)
  5547. {
  5548. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5549. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5550. }
  5551. }
  5552. __finally
  5553. {
  5554. FAutoOperation = false;
  5555. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5556. SAFE_DESTROY(FSynchronizeProgressForm);
  5557. }
  5558. TSynchronizeParams SynchronizeParams;
  5559. SynchronizeParams.LocalDirectory = LocalDirectory;
  5560. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5561. SynchronizeParams.Mode = Mode;
  5562. SynchronizeParams.CopyParam = &CopyParam;
  5563. SynchronizeParams.Params = Params;
  5564. SynchronizeParams.Checklist = Checklist;
  5565. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5566. SynchronizeParams.StartTime = &StartTime;
  5567. SynchronizeParams.OnProcessedItem = NULL;
  5568. Result = Checklist->Count;
  5569. if (Checklist->Count > 0)
  5570. {
  5571. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5572. {
  5573. if (!DoSynchronizeChecklistDialog(
  5574. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5575. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5576. {
  5577. Result = -1;
  5578. }
  5579. }
  5580. else
  5581. {
  5582. FullSynchronize(SynchronizeParams, NULL, NULL);
  5583. }
  5584. }
  5585. else
  5586. {
  5587. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5588. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5589. }
  5590. }
  5591. __finally
  5592. {
  5593. delete Checklist;
  5594. }
  5595. OperationComplete(StartTime);
  5596. }
  5597. else
  5598. {
  5599. Result = -1;
  5600. }
  5601. return Result;
  5602. }
  5603. //---------------------------------------------------------------------------
  5604. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5605. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5606. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5607. {
  5608. if (Collect)
  5609. {
  5610. DebugAssert(FSynchronizeProgressForm != NULL);
  5611. if (!FSynchronizeProgressForm->Started)
  5612. {
  5613. FSynchronizeProgressForm->Start();
  5614. }
  5615. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5616. SetTaskbarListProgressValue(CompareProgress);
  5617. }
  5618. else
  5619. {
  5620. DebugAssert(FSynchronizeProgressForm == NULL);
  5621. DebugAssert(FProgressForm != NULL);
  5622. }
  5623. }
  5624. //---------------------------------------------------------------------------
  5625. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5626. {
  5627. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  5628. TRemoteFile * File = NULL;
  5629. Terminal->ReadFile(FullFileName, File);
  5630. if (File != NULL)
  5631. {
  5632. std::unique_ptr<TRemoteFile> FileOwner(File);
  5633. TAutoFlag Flag(FStandaloneEditing);
  5634. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5635. Application->ShowMainForm = false;
  5636. Application->Run();
  5637. }
  5638. }
  5639. //---------------------------------------------------------------------------
  5640. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  5641. {
  5642. DebugFail();
  5643. }
  5644. //---------------------------------------------------------------------------
  5645. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5646. {
  5647. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5648. SessionData->Assign(Terminal->SessionData);
  5649. UpdateSessionData(SessionData.get());
  5650. Terminal->UpdateSessionCredentials(SessionData.get());
  5651. if (!Terminal->SessionData->HasSessionName())
  5652. {
  5653. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5654. // once IsWorkspace is cleared
  5655. SessionData->Name = UnicodeString();
  5656. SessionData->IsWorkspace = false;
  5657. }
  5658. return SessionData.release();
  5659. }
  5660. //---------------------------------------------------------------------------
  5661. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5662. {
  5663. TSessionData * SessionData = CloneCurrentSessionData();
  5664. try
  5665. {
  5666. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5667. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5668. }
  5669. __finally
  5670. {
  5671. delete SessionData;
  5672. }
  5673. }
  5674. //---------------------------------------------------------------------------
  5675. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5676. {
  5677. TTerminalManager * Manager = TTerminalManager::Instance();
  5678. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5679. if (DebugAlwaysTrue(Terminal != NULL))
  5680. {
  5681. // Update (Managed)Terminal->StateData
  5682. UpdateTerminal(Terminal);
  5683. }
  5684. Manager->SaveWorkspace(DataList.get());
  5685. return DataList.release();
  5686. }
  5687. //---------------------------------------------------------------------------
  5688. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5689. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5690. {
  5691. WinConfiguration->LastWorkspace = Name;
  5692. if (!SavePasswords)
  5693. {
  5694. for (int Index = 0; Index < DataList->Count; Index++)
  5695. {
  5696. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5697. if (SessionData->Link.IsEmpty())
  5698. {
  5699. SessionData->ClearSessionPasswords();
  5700. }
  5701. }
  5702. }
  5703. StoredSessions->NewWorkspace(Name, DataList);
  5704. // modified only
  5705. StoredSessions->Save(false, Explicit);
  5706. }
  5707. //---------------------------------------------------------------------------
  5708. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5709. {
  5710. return
  5711. DefaultStr(WinConfiguration->LastWorkspace,
  5712. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5713. }
  5714. //---------------------------------------------------------------------------
  5715. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5716. {
  5717. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5718. bool AnyNonStoredSessionWithPassword = false;
  5719. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5720. bool AllNonStoredSessionsAnonymous = true;
  5721. TTerminalManager * Manager = TTerminalManager::Instance();
  5722. for (int Index = 0; Index < DataList->Count; Index++)
  5723. {
  5724. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5725. if (SessionData->Link.IsEmpty())
  5726. {
  5727. if (SessionData->HasAnySessionPassword())
  5728. {
  5729. AnyNonStoredSessionWithPassword = true;
  5730. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  5731. {
  5732. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5733. }
  5734. }
  5735. if (!SameText(SessionData->UserName, AnonymousUserName))
  5736. {
  5737. AllNonStoredSessionsAnonymous = false;
  5738. }
  5739. }
  5740. }
  5741. bool SavePasswords;
  5742. bool * PSavePasswords;
  5743. bool NotRecommendedSavingPasswords =
  5744. !CustomWinConfiguration->UseMasterPassword &&
  5745. !AllNonStoredSessionsAnonymous;
  5746. if (Configuration->DisablePasswordStoring ||
  5747. !AnyNonStoredSessionWithPassword)
  5748. {
  5749. PSavePasswords = NULL;
  5750. SavePasswords = false;
  5751. }
  5752. else
  5753. {
  5754. PSavePasswords = &SavePasswords;
  5755. SavePasswords =
  5756. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5757. !NotRecommendedSavingPasswords;
  5758. }
  5759. UnicodeString Name = WorkspaceName();
  5760. bool CreateShortcut = false;
  5761. bool Result =
  5762. DoSaveWorkspaceDialog(
  5763. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5764. EnableAutoSave);
  5765. if (Result)
  5766. {
  5767. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5768. if (CreateShortcut)
  5769. {
  5770. TOperationVisualizer Visualizer;
  5771. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5772. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5773. }
  5774. if (EnableAutoSave)
  5775. {
  5776. WinConfiguration->AutoSaveWorkspace = true;
  5777. WinConfiguration->AutoWorkspace = Name;
  5778. if (PSavePasswords != NULL)
  5779. {
  5780. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5781. }
  5782. }
  5783. }
  5784. return Result;
  5785. }
  5786. //---------------------------------------------------------------------------
  5787. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TManagedTerminal * Terminal)
  5788. {
  5789. DebugAssert(!IsLocalBrowserMode());
  5790. SAFE_DESTROY(Terminal->RemoteExplorerState);
  5791. if (WinConfiguration->PreservePanelState)
  5792. {
  5793. Terminal->RemoteExplorerState = RemoteDirView->SaveState();
  5794. }
  5795. UpdateSessionData(Terminal->StateData);
  5796. }
  5797. //---------------------------------------------------------------------------
  5798. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5799. {
  5800. // Keep in sync with TSessionData::CopyStateData
  5801. DebugAssert(!IsLocalBrowserMode());
  5802. DebugAssert(Data != NULL);
  5803. // This is inconsistent with how color (for example) is handled.
  5804. Data->Name = Terminal->SessionData->Name;
  5805. // cannot use RemoteDirView->Path, because it is empty if connection
  5806. // was already closed
  5807. // also only peek, we may not be connected at all atm
  5808. // so make sure we do not try retrieving current directory from the server
  5809. // (particularly with FTP)
  5810. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5811. if (!ACurrentDirectory.IsEmpty())
  5812. {
  5813. Data->RemoteDirectory = ACurrentDirectory;
  5814. }
  5815. Data->Color = SessionColor;
  5816. }
  5817. //---------------------------------------------------------------------------
  5818. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5819. {
  5820. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5821. DebugAssert(Toolbar != NULL);
  5822. for (int i = 0; i < Toolbar->Items->Count; i++)
  5823. {
  5824. TTBXCustomDropDownItem * DropDownItem;
  5825. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5826. if (DropDownItem != NULL)
  5827. {
  5828. ToolbarItemResize(DropDownItem,
  5829. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5830. Toolbar->NonClientWidth);
  5831. break;
  5832. }
  5833. }
  5834. }
  5835. //---------------------------------------------------------------------------
  5836. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5837. {
  5838. Item->EditWidth = Width;
  5839. }
  5840. //---------------------------------------------------------------------------
  5841. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5842. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5843. {
  5844. for (int i = 0; i < Toolbar->Items->Count; i++)
  5845. {
  5846. TTBXCustomDropDownItem * DropDownItem;
  5847. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5848. if (DropDownItem != NULL)
  5849. {
  5850. ASize.x -= DropDownItem->EditWidth;
  5851. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5852. }
  5853. }
  5854. }
  5855. //---------------------------------------------------------------------------
  5856. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5857. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5858. {
  5859. if (WinConfiguration->DDWarnLackOfTempSpace)
  5860. {
  5861. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5862. if (!ADrive.IsEmpty())
  5863. {
  5864. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5865. DebugAssert(RequiredSpace >= 0);
  5866. __int64 RequiredWithReserve;
  5867. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5868. if (FreeSpace < RequiredWithReserve)
  5869. {
  5870. unsigned int Result;
  5871. TMessageParams Params(mpNeverAskAgainCheck);
  5872. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5873. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5874. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5875. if (Result == qaNeverAskAgain)
  5876. {
  5877. WinConfiguration->DDWarnLackOfTempSpace = false;
  5878. }
  5879. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5880. }
  5881. }
  5882. }
  5883. }
  5884. //---------------------------------------------------------------------------
  5885. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5886. {
  5887. DoOpenDirectoryDialog(odAddBookmark, Side);
  5888. }
  5889. //---------------------------------------------------------------------------
  5890. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5891. {
  5892. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5893. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  5894. try
  5895. {
  5896. TCustomDirView * DView = DirView(Side);
  5897. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5898. {
  5899. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5900. }
  5901. }
  5902. catch (...)
  5903. {
  5904. delete VisitedDirectories;
  5905. throw;
  5906. }
  5907. return VisitedDirectories;
  5908. }
  5909. //---------------------------------------------------------------------------
  5910. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5911. TOpenDirectoryMode Mode, TOperationSide Side)
  5912. {
  5913. bool Continue = true;
  5914. if (Mode == odAddBookmark)
  5915. {
  5916. TMessageParams Params(mpNeverAskAgainCheck);
  5917. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5918. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5919. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5920. unsigned int Answer =
  5921. MessageDialog(Message,
  5922. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5923. if (Answer == qaNeverAskAgain)
  5924. {
  5925. Continue = true;
  5926. WinConfiguration->UseSharedBookmarks = true;
  5927. }
  5928. else if (Answer == qaOK)
  5929. {
  5930. Continue = true;
  5931. WinConfiguration->UseSharedBookmarks = false;
  5932. }
  5933. else
  5934. {
  5935. Continue = false;
  5936. }
  5937. }
  5938. if (Continue)
  5939. {
  5940. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5941. try
  5942. {
  5943. UnicodeString Name = DirView(Side)->PathName;
  5944. bool Repeat;
  5945. do
  5946. {
  5947. Repeat = false;
  5948. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  5949. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  5950. // do not allow switching to location profiles,
  5951. // if we are not connected
  5952. HasDirView[osLocal] && (Terminal != NULL)))
  5953. {
  5954. TWindowLock Lock(this);
  5955. if (!TryOpenDirectory(Side, Name))
  5956. {
  5957. Repeat = true;
  5958. Mode = odBrowse;
  5959. }
  5960. }
  5961. }
  5962. while (Repeat);
  5963. }
  5964. __finally
  5965. {
  5966. delete VisitedDirectories;
  5967. }
  5968. }
  5969. }
  5970. //---------------------------------------------------------------------------
  5971. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5972. {
  5973. DebugAssert(!FTerminal->CommandSessionOpened);
  5974. return TTerminalManager::Instance()->ConnectTerminal(FTerminal->CommandSession);
  5975. }
  5976. //---------------------------------------------------------------------------
  5977. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5978. {
  5979. bool Result = FTerminal->IsCapable[Capability] ||
  5980. FTerminal->CommandSessionOpened;
  5981. if (!Result)
  5982. {
  5983. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5984. if (!GUIConfiguration->ConfirmCommandSession)
  5985. {
  5986. Result = true;
  5987. }
  5988. else
  5989. {
  5990. TMessageParams Params(mpNeverAskAgainCheck);
  5991. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5992. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5993. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5994. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5995. if (Answer == qaNeverAskAgain)
  5996. {
  5997. GUIConfiguration->ConfirmCommandSession = false;
  5998. Result = true;
  5999. }
  6000. else if (Answer == qaOK)
  6001. {
  6002. Result = true;
  6003. }
  6004. }
  6005. if (Result)
  6006. {
  6007. Result = CommandSessionFallback();
  6008. }
  6009. }
  6010. return Result;
  6011. }
  6012. //---------------------------------------------------------------------------
  6013. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6014. {
  6015. if (EnsureCommandSessionFallback(fcAnyCommand))
  6016. {
  6017. DoConsoleDialog(Terminal, Command);
  6018. }
  6019. }
  6020. //---------------------------------------------------------------------------
  6021. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6022. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6023. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6024. {
  6025. if (!IsSideLocalBrowser(osRemote) &&
  6026. IsFileControl(DropSourceControl, osRemote) &&
  6027. (FDDExtMapFile != NULL))
  6028. {
  6029. Accept = true;
  6030. }
  6031. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6032. DebugAssert(FDDTargetControl != NULL);
  6033. }
  6034. //---------------------------------------------------------------------------
  6035. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6036. _di_IDataObject DataObj, int KeyState,
  6037. const TPoint & Point, int & Effect, bool & Accept)
  6038. {
  6039. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6040. }
  6041. //---------------------------------------------------------------------------
  6042. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6043. _di_IDataObject DataObj, int KeyState,
  6044. const TPoint & Point, int & Effect, bool & Accept)
  6045. {
  6046. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6047. }
  6048. //---------------------------------------------------------------------------
  6049. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6050. TObject * Sender)
  6051. {
  6052. DebugUsedParam(Sender);
  6053. DebugAssert(FDDTargetControl == Sender);
  6054. FDDTargetControl = NULL;
  6055. }
  6056. //---------------------------------------------------------------------------
  6057. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6058. {
  6059. FileControlDDDragLeave(SessionsPageControl);
  6060. }
  6061. //---------------------------------------------------------------------------
  6062. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6063. {
  6064. FileControlDDDragLeave(QueueView3);
  6065. }
  6066. //---------------------------------------------------------------------------
  6067. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6068. {
  6069. DebugAssert(!IsSideLocalBrowser(Side));
  6070. DebugUsedParam(Side);
  6071. bool Edit = false;
  6072. TRemoteFile * File = NULL;
  6073. UnicodeString FileName;
  6074. UnicodeString PointTo;
  6075. bool SymbolicLink = true;
  6076. if (RemoteDirView->ItemFocused)
  6077. {
  6078. DebugAssert(RemoteDirView->ItemFocused->Data);
  6079. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6080. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6081. if (Edit)
  6082. {
  6083. FileName = File->FileName;
  6084. PointTo = File->LinkTo;
  6085. }
  6086. else
  6087. {
  6088. PointTo = File->FileName;
  6089. }
  6090. }
  6091. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6092. Terminal->IsCapable[fcHardLink]))
  6093. {
  6094. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6095. if (Edit)
  6096. {
  6097. DebugAssert(File->FileName == FileName);
  6098. int Params = dfNoRecursive;
  6099. Terminal->ExceptionOnFail = true;
  6100. try
  6101. {
  6102. Terminal->DeleteFile(L"", File, &Params);
  6103. }
  6104. __finally
  6105. {
  6106. Terminal->ExceptionOnFail = false;
  6107. }
  6108. }
  6109. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6110. }
  6111. }
  6112. //---------------------------------------------------------------------------
  6113. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6114. {
  6115. return
  6116. (IsSideLocalBrowser(Side) ||
  6117. (HasActiveTerminal() &&
  6118. Terminal->ResolvingSymlinks &&
  6119. Terminal->IsCapable[fcSymbolicLink]));
  6120. }
  6121. //---------------------------------------------------------------------------
  6122. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6123. {
  6124. return
  6125. !IsSideLocalBrowser(FCurrentSide) &&
  6126. (RemoteDirView->ItemFocused != NULL) &&
  6127. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6128. Terminal->SessionData->ResolveSymlinks;
  6129. }
  6130. //---------------------------------------------------------------------------
  6131. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6132. {
  6133. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6134. FForceExecution = true;
  6135. try
  6136. {
  6137. DirView(osCurrent)->ExecuteCurrentFile();
  6138. }
  6139. __finally
  6140. {
  6141. FForceExecution = false;
  6142. }
  6143. }
  6144. //---------------------------------------------------------------------------
  6145. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6146. {
  6147. TEditorData ExternalEditor;
  6148. ExternalEditor.Editor = edExternal;
  6149. bool Remember = false;
  6150. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6151. {
  6152. if (Remember)
  6153. {
  6154. TEditorList * EditorList = new TEditorList;
  6155. try
  6156. {
  6157. *EditorList = *WinConfiguration->EditorList;
  6158. bool Found = false;
  6159. int i = 0;
  6160. while (!Found && (i < EditorList->Count))
  6161. {
  6162. const TEditorPreferences * Editor = EditorList->Editors[i];
  6163. if ((Editor->Data->Editor == edExternal) &&
  6164. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6165. {
  6166. Found = true;
  6167. }
  6168. i++;
  6169. }
  6170. if (!Found)
  6171. {
  6172. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6173. WinConfiguration->EditorList = EditorList;
  6174. }
  6175. }
  6176. __finally
  6177. {
  6178. delete EditorList;
  6179. }
  6180. }
  6181. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6182. }
  6183. }
  6184. //---------------------------------------------------------------------------
  6185. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6186. {
  6187. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6188. if (FFileFindTerminal == ATerminal)
  6189. {
  6190. FFileFindTerminal = NULL;
  6191. HideFileFindDialog();
  6192. }
  6193. if (FClipboardTerminal == ATerminal)
  6194. {
  6195. ClipboardClear(); // implies ClipboardStop
  6196. }
  6197. }
  6198. //---------------------------------------------------------------------------
  6199. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6200. {
  6201. DetachTerminal(Sender);
  6202. }
  6203. //---------------------------------------------------------------------------
  6204. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6205. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6206. {
  6207. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6208. DebugAssert(Terminal != NULL);
  6209. if (Data->Terminal == Terminal)
  6210. {
  6211. Data->Terminal = NULL;
  6212. }
  6213. }
  6214. //---------------------------------------------------------------------------
  6215. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  6216. {
  6217. UpdateControls();
  6218. SessionColor = TColor(0);
  6219. UpdateRemotePathComboBox(false);
  6220. NeedSession(false);
  6221. }
  6222. //---------------------------------------------------------------------------
  6223. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6224. {
  6225. try
  6226. {
  6227. // Cache, as the login dialog can change its value
  6228. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6229. try
  6230. {
  6231. if (ShowLogin)
  6232. {
  6233. bool ReloadSessions = !Startup;
  6234. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  6235. }
  6236. else if (Startup && WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6237. // This detects if workspace was saved the last time the main widow was closed
  6238. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6239. {
  6240. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
  6241. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6242. }
  6243. }
  6244. __finally
  6245. {
  6246. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6247. // (so there was no chance for the user to open any session yet)
  6248. if ((ShowLogin || !Startup) &&
  6249. !WinConfiguration->KeepOpenWhenNoSession &&
  6250. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6251. {
  6252. TerminateApplication();
  6253. }
  6254. }
  6255. }
  6256. catch (EAbort &)
  6257. {
  6258. // swallow
  6259. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6260. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6261. }
  6262. }
  6263. //---------------------------------------------------------------------------
  6264. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged()
  6265. {
  6266. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  6267. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6268. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  6269. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6270. try
  6271. {
  6272. while ((SessionsPageControl->PageCount > TerminalList->Count + 1) ||
  6273. // Clear the design time unthemed tab
  6274. ((SessionsPageControl->PageCount > 0) &&
  6275. (dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[SessionsPageControl->PageCount - 1]) == NULL)))
  6276. {
  6277. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6278. }
  6279. for (int Index = 0; Index <= TerminalList->Count; Index++)
  6280. {
  6281. TThemeTabSheet * TabSheet;
  6282. if (Index >= SessionsPageControl->PageCount)
  6283. {
  6284. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6285. TabSheet->PageControl = SessionsPageControl;
  6286. }
  6287. else
  6288. {
  6289. TabSheet = DebugNotNull(dynamic_cast<TThemeTabSheet *>(SessionsPageControl->Pages[Index]));
  6290. }
  6291. bool IsSessionTab = (Index < TerminalList->Count);
  6292. if (IsSessionTab)
  6293. {
  6294. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  6295. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6296. UpdateSessionTab(TabSheet);
  6297. }
  6298. else
  6299. {
  6300. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  6301. TabSheet->Tag = 0; // not really needed
  6302. TabSheet->Shadowed = false;
  6303. // 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)
  6304. UpdateNewSessionTab();
  6305. }
  6306. TabSheet->ShowCloseButton = IsSessionTab;
  6307. }
  6308. }
  6309. __finally
  6310. {
  6311. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6312. }
  6313. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  6314. }
  6315. //---------------------------------------------------------------------------
  6316. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  6317. {
  6318. DoTerminalListChanged();
  6319. }
  6320. //---------------------------------------------------------------------------
  6321. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  6322. {
  6323. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6324. DebugAssert(TabSheet->ImageIndex == 0);
  6325. TabSheet->Caption =
  6326. WinConfiguration->SelectiveToolbarText ?
  6327. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  6328. UnicodeString();
  6329. }
  6330. //---------------------------------------------------------------------------
  6331. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  6332. {
  6333. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6334. }
  6335. //---------------------------------------------------------------------------
  6336. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  6337. {
  6338. if (DebugAlwaysTrue(TabSheet != NULL))
  6339. {
  6340. TManagedTerminal * ATerminal = GetSessionTabTerminal(TabSheet);
  6341. if (DebugAlwaysTrue(ATerminal != NULL))
  6342. {
  6343. TColor Color = (ATerminal == FTerminal) ? FSessionColor : ATerminal->StateData->Color;
  6344. TabSheet->ImageIndex = AddSessionColor(Color);
  6345. UnicodeString TabCaption = TTerminalManager::Instance()->GetTerminalTitle(ATerminal, true);
  6346. TabSheet->Caption = SessionsPageControl->FormatCaptionWithCloseButton(TabCaption);
  6347. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  6348. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  6349. {
  6350. ThemeTabSheet->Shadowed = !ATerminal->Active;
  6351. }
  6352. }
  6353. }
  6354. }
  6355. //---------------------------------------------------------------------------
  6356. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6357. {
  6358. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6359. TManagedTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  6360. bool Result = (Terminal != NULL);
  6361. if (Result)
  6362. {
  6363. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6364. }
  6365. else
  6366. {
  6367. try
  6368. {
  6369. NewSession(false);
  6370. }
  6371. __finally
  6372. {
  6373. DoTerminalListChanged();
  6374. }
  6375. FSessionsPageControlNewSessionTime = Now();
  6376. }
  6377. return Result;
  6378. }
  6379. //---------------------------------------------------------------------------
  6380. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6381. {
  6382. SessionTabSwitched();
  6383. }
  6384. //---------------------------------------------------------------------------
  6385. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6386. {
  6387. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6388. DebugAssert(TransferList != NULL);
  6389. UnicodeString Name;
  6390. if (TransferList->ItemIndex <= 0)
  6391. {
  6392. Name = L"";
  6393. }
  6394. else
  6395. {
  6396. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6397. }
  6398. if (FCopyParamAutoSelected.IsEmpty())
  6399. {
  6400. // if previous preset was not autoselected, make new preset the "default"
  6401. FCopyParamDefault = Name;
  6402. }
  6403. GUIConfiguration->CopyParamCurrent = Name;
  6404. }
  6405. //---------------------------------------------------------------------------
  6406. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6407. {
  6408. // sanity check
  6409. bool ExistingPreset =
  6410. (FTransferListHoverIndex >= 0) &&
  6411. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6412. DebugAssert(ExistingPreset);
  6413. if (ExistingPreset)
  6414. {
  6415. HDC DC = GetDC(0);
  6416. TCanvas * Canvas = new TCanvas();
  6417. try
  6418. {
  6419. Canvas->Handle = DC;
  6420. Canvas->Font = GetToolbarFont(this);
  6421. UnicodeString Name;
  6422. if (FTransferListHoverIndex == 0)
  6423. {
  6424. Name = L"";
  6425. }
  6426. else
  6427. {
  6428. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6429. }
  6430. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6431. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6432. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6433. static_cast<TObject*>(GetComponent(fcTransferList)));
  6434. UnicodeString InfoStr =
  6435. GUIConfiguration->CopyParamPreset[Name].
  6436. GetInfoStr(L"; ",
  6437. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6438. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6439. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6440. {
  6441. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6442. {
  6443. InfoStr.SetLength(InfoStr.Length() - 1);
  6444. }
  6445. InfoStr += Ellipsis;
  6446. }
  6447. // UpdateCaption does not cause invalidation of whole submenu, while
  6448. // setting Caption property does.
  6449. // also it probably does not resize the label, even if necessary
  6450. // (we do not want that anyway)
  6451. TransferLabel->UpdateCaption(InfoStr);
  6452. }
  6453. __finally
  6454. {
  6455. Canvas->Handle = NULL;
  6456. ReleaseDC(0, DC);
  6457. delete Canvas;
  6458. }
  6459. }
  6460. }
  6461. //---------------------------------------------------------------------------
  6462. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6463. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6464. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6465. {
  6466. if (FTransferListHoverIndex != AHoverIndex)
  6467. {
  6468. FTransferListHoverIndex = AHoverIndex;
  6469. UpdateTransferLabel();
  6470. }
  6471. }
  6472. //---------------------------------------------------------------------------
  6473. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6474. {
  6475. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6476. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6477. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6478. {
  6479. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6480. {
  6481. if (!NonVisualDataModule->Busy)
  6482. {
  6483. OpenDirectory(GetSide(osCurrent));
  6484. }
  6485. Message.Result = 1;
  6486. }
  6487. else
  6488. {
  6489. TForm::Dispatch(&Message);
  6490. }
  6491. }
  6492. else
  6493. {
  6494. TForm::Dispatch(&Message);
  6495. }
  6496. }
  6497. //---------------------------------------------------------------------------
  6498. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6499. {
  6500. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6501. if ((FIgnoreNextDialogChar != 0) &&
  6502. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6503. {
  6504. Message.Result = 1;
  6505. }
  6506. else
  6507. {
  6508. TForm::Dispatch(&Message);
  6509. }
  6510. FIgnoreNextDialogChar = 0;
  6511. }
  6512. //---------------------------------------------------------------------------
  6513. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6514. {
  6515. // The four low-order bits are used internally by Windows
  6516. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6517. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6518. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6519. // 61730 - restore thru double click - undocumented
  6520. // 61490 - maximize thru double click - undocumented
  6521. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6522. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6523. {
  6524. SysResizing(Cmd);
  6525. }
  6526. TForm::Dispatch(&Message);
  6527. }
  6528. //---------------------------------------------------------------------------
  6529. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6530. {
  6531. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6532. // Also there no point returning TRUE as we are not able to
  6533. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6534. // Hence the process termination might be safer :)
  6535. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6536. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6537. {
  6538. Message.Result = FALSE;
  6539. }
  6540. else
  6541. {
  6542. Message.Result = TRUE;
  6543. }
  6544. // Do not call default handling as that triggers OnCloseQuery,
  6545. // where our implementation will popup confirmation dialogs, what we do not want,
  6546. // as per Vista guidelines:
  6547. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6548. }
  6549. //---------------------------------------------------------------------------
  6550. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6551. {
  6552. if (Message.EndSession && IsApplicationMinimized())
  6553. {
  6554. // WORKAROUND
  6555. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6556. // when it receives WM_ENDSESSION,
  6557. // but that sometimes (particularly when application is minimized) cause crashes.
  6558. // Crash popups message that blocks log off.
  6559. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6560. // so we call ExitProcess() immediately, not even trying to cleanup.
  6561. // It still causes beep, so there's likely some popup, but it does not block
  6562. // log off.
  6563. ExitProcess(0);
  6564. }
  6565. TForm::Dispatch(&Message);
  6566. }
  6567. #ifdef _DEBUG
  6568. //---------------------------------------------------------------------------
  6569. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6570. {
  6571. TForm::Dispatch(&Message);
  6572. }
  6573. #endif
  6574. //---------------------------------------------------------------------------
  6575. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6576. {
  6577. }
  6578. //---------------------------------------------------------------------------
  6579. void __fastcall TCustomScpExplorerForm::DoShow()
  6580. {
  6581. // only now are the controls resized finally, so the size constraints
  6582. // will not conflict with possibly very small window size
  6583. RestoreFormParams();
  6584. // This indicates that the form was rescaled after parameters were loaded and
  6585. // as most probably the parameters were actually saved with the current form scaling
  6586. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6587. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6588. // and no rounding problems will occur.
  6589. // See also RestoreForm.
  6590. // (we should be safe to call RestoreParams unconditionally)
  6591. if (PixelsPerInch != Screen->PixelsPerInch)
  6592. {
  6593. RestoreParams();
  6594. }
  6595. FixControlsPlacement();
  6596. if (Position == poDefaultPosOnly)
  6597. {
  6598. CutFormToDesktop(this);
  6599. }
  6600. TForm::DoShow();
  6601. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6602. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6603. if (Terminal == NULL)
  6604. {
  6605. StartingDisconnected();
  6606. }
  6607. UpdatePixelsPerInchMainWindowCounter();
  6608. FShowing = true;
  6609. }
  6610. //---------------------------------------------------------------------------
  6611. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6612. {
  6613. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6614. }
  6615. //---------------------------------------------------------------------------
  6616. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  6617. {
  6618. DoTerminalListChanged();
  6619. UpdateControls();
  6620. }
  6621. //---------------------------------------------------------------------------
  6622. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6623. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6624. TNotifyEvent OnBalloonClick, TObject * UserData)
  6625. {
  6626. bool Do;
  6627. UnicodeString Message;
  6628. if (E == NULL)
  6629. {
  6630. Message = Str;
  6631. Do = true;
  6632. }
  6633. else
  6634. {
  6635. Do = ExceptionMessage(E, Message);
  6636. }
  6637. if (Do && WinConfiguration->BalloonNotifications)
  6638. {
  6639. UnicodeString Title;
  6640. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6641. {
  6642. Message = TrimLeft(Message);
  6643. }
  6644. else
  6645. {
  6646. Message = UnformatMessage(Message);
  6647. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6648. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6649. Title = LoadResourceString(Captions[Type]);
  6650. if (Terminal != NULL)
  6651. {
  6652. Title = FORMAT(L"%s - %s",
  6653. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), Title));
  6654. }
  6655. }
  6656. if (Seconds == 0)
  6657. {
  6658. Seconds = WinConfiguration->NotificationsTimeout;
  6659. }
  6660. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6661. }
  6662. }
  6663. //---------------------------------------------------------------------------
  6664. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6665. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6666. UnicodeString HelpKeyword, const TMessageParams * Params,
  6667. TTerminal * Terminal)
  6668. {
  6669. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6670. (FOnFeedSynchronizeError != NULL)) &&
  6671. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6672. {
  6673. if (FOnFeedSynchronizeError != NULL)
  6674. {
  6675. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6676. }
  6677. else
  6678. {
  6679. DebugAssert(FErrorList != NULL);
  6680. TStringList * MoreMessagesCopy = NULL;
  6681. if (MoreMessages)
  6682. {
  6683. MoreMessagesCopy = new TStringList();
  6684. MoreMessagesCopy->Assign(MoreMessages);
  6685. }
  6686. FErrorList->AddObject(Message, MoreMessagesCopy);
  6687. }
  6688. PopupTrayBalloon(Terminal, Message, Type);
  6689. return ContinueAnswer(Answers);
  6690. }
  6691. else
  6692. {
  6693. bool UseBalloon = FTrayIcon->Visible;
  6694. if (UseBalloon)
  6695. {
  6696. PopupTrayBalloon(Terminal, Message, Type);
  6697. }
  6698. unsigned int Result;
  6699. try
  6700. {
  6701. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6702. }
  6703. __finally
  6704. {
  6705. // cancel only balloon we popped up, otherwise we may cancel notification
  6706. // balloon that was there before the message dialog
  6707. // (such as "dd confirmation opt in balloon)
  6708. if (UseBalloon)
  6709. {
  6710. FTrayIcon->CancelBalloon();
  6711. }
  6712. }
  6713. return Result;
  6714. }
  6715. }
  6716. //---------------------------------------------------------------------------
  6717. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6718. TTerminal * Terminal, Exception * E)
  6719. {
  6720. if (FTrayIcon->Visible)
  6721. {
  6722. PopupTrayBalloon(Terminal, L"", qtError, E);
  6723. }
  6724. // particularly prevent opening new session from jump list,
  6725. // while exception is shown
  6726. NonVisualDataModule->StartBusy();
  6727. try
  6728. {
  6729. ShowExtendedExceptionEx(Terminal, E);
  6730. }
  6731. __finally
  6732. {
  6733. NonVisualDataModule->EndBusy();
  6734. FTrayIcon->CancelBalloon();
  6735. }
  6736. }
  6737. //---------------------------------------------------------------------------
  6738. void __fastcall TCustomScpExplorerForm::TerminalReady()
  6739. {
  6740. if (Terminal->Active)
  6741. {
  6742. InitStatusBar();
  6743. }
  6744. // cannot rely on active page being page for active terminal,
  6745. // as it can happen that active page is the "new session" page
  6746. // (e.g. when reconnecting active terminal, while login dialog
  6747. // invoked from "new session" page is modal)
  6748. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  6749. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  6750. }
  6751. //---------------------------------------------------------------------------
  6752. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  6753. TTerminal * Terminal, Exception * E)
  6754. {
  6755. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  6756. if (!Terminal->Active)
  6757. {
  6758. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  6759. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  6760. {
  6761. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  6762. }
  6763. }
  6764. }
  6765. //---------------------------------------------------------------------------
  6766. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  6767. UnicodeString Message, TQueryType Type,
  6768. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  6769. {
  6770. if ((E == NULL) ||
  6771. ExceptionMessage(E, Message))
  6772. {
  6773. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  6774. if (Important)
  6775. {
  6776. Seconds *= 5;
  6777. }
  6778. UnicodeString NoteMessage(UnformatMessage(Message));
  6779. if (Terminal != NULL)
  6780. {
  6781. NoteMessage = FORMAT(L"%s: %s",
  6782. (TTerminalManager::Instance()->GetTerminalTitle(Terminal, true), NoteMessage));
  6783. }
  6784. if (WinConfiguration->BalloonNotifications)
  6785. {
  6786. AddNote(NoteMessage);
  6787. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  6788. }
  6789. else
  6790. {
  6791. FlashOnBackground();
  6792. PostNote(NoteMessage, Seconds, OnClick, UserData);
  6793. }
  6794. }
  6795. }
  6796. //---------------------------------------------------------------------------
  6797. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  6798. {
  6799. RestoreApp();
  6800. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  6801. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  6802. !NonVisualDataModule->Busy)
  6803. {
  6804. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  6805. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  6806. if (!ComponentVisible[fcQueueView])
  6807. {
  6808. ToggleQueueVisibility();
  6809. GoToQueue();
  6810. }
  6811. }
  6812. }
  6813. //---------------------------------------------------------------------------
  6814. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  6815. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  6816. {
  6817. UnicodeString Message;
  6818. TNotifyEvent OnClick = NULL;
  6819. TObject * UserData = NULL;
  6820. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  6821. switch (Event)
  6822. {
  6823. case qeEmptyButMonitored:
  6824. if ((ATerminal != Terminal) || QueueInvisible)
  6825. {
  6826. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6827. OnClick = QueueEmptyNoteClicked;
  6828. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6829. TerminalNoteData->Terminal = ATerminal;
  6830. UserData = TerminalNoteData;
  6831. }
  6832. break;
  6833. case qeEmpty:
  6834. OperationComplete(ATerminal->QueueOperationStart);
  6835. break;
  6836. case qePendingUserAction:
  6837. if ((ATerminal != Terminal) ||
  6838. (QueueInvisible && !IsQueueAutoPopup()))
  6839. {
  6840. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6841. }
  6842. break;
  6843. default:
  6844. DebugFail();
  6845. }
  6846. if (!Message.IsEmpty())
  6847. {
  6848. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6849. }
  6850. }
  6851. //---------------------------------------------------------------------------
  6852. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6853. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6854. {
  6855. if (FDDExtMapFile != NULL)
  6856. {
  6857. CloseHandle(FDDExtMapFile);
  6858. FDDExtMapFile = NULL;
  6859. }
  6860. if (WinConfiguration->DDFakeFile)
  6861. {
  6862. DDFakeFileInitDrag(FileList, Created);
  6863. }
  6864. }
  6865. //---------------------------------------------------------------------------
  6866. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  6867. {
  6868. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  6869. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  6870. {
  6871. FFakeFileDropTarget = FileName;
  6872. }
  6873. }
  6874. //---------------------------------------------------------------------------
  6875. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  6876. {
  6877. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6878. if (!ForceDirectories(ApiPath(Result)))
  6879. {
  6880. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  6881. }
  6882. FileSetAttr(ApiPath(Result), faHidden);
  6883. return Result;
  6884. }
  6885. //---------------------------------------------------------------------------
  6886. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  6887. bool & Created)
  6888. {
  6889. FFakeFileDropTarget = UnicodeString();
  6890. FDragFakeDirectory = CreateFakeTransferDirectory();
  6891. FileList->AddItem(NULL, FDragFakeDirectory);
  6892. Created = true;
  6893. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  6894. {
  6895. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  6896. }
  6897. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6898. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6899. {
  6900. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6901. TDragExtCommStruct* CommStruct;
  6902. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6903. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6904. DebugAssert(CommStruct != NULL);
  6905. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6906. CommStruct->Dragging = true;
  6907. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  6908. LENOF(CommStruct->DropDest));
  6909. NULL_TERMINATE(CommStruct->DropDest);
  6910. UnmapViewOfFile(CommStruct);
  6911. }
  6912. }
  6913. //---------------------------------------------------------------------------
  6914. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6915. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6916. {
  6917. bool Result;
  6918. DebugAssert(!IsLocalBrowserMode());
  6919. if (Sender == RemoteDirView)
  6920. {
  6921. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6922. }
  6923. else
  6924. {
  6925. DebugAssert(Sender == RemoteDriveView);
  6926. TStrings * FileList = RemoteDriveView->DragFileList();
  6927. try
  6928. {
  6929. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6930. }
  6931. __finally
  6932. {
  6933. delete FileList;
  6934. }
  6935. }
  6936. if (FDDTargetControl == RemoteDriveView)
  6937. {
  6938. RemoteDriveView->UpdateDropTarget();
  6939. }
  6940. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6941. // or from tree view to dir view.
  6942. // foMove happens when file/dir is dragged from remote tree view outside of
  6943. // application via dragex
  6944. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6945. (DropSourceControl == RemoteDriveView))
  6946. {
  6947. RemoteDriveView->UpdateDropSource();
  6948. }
  6949. return Result;
  6950. }
  6951. //---------------------------------------------------------------------------
  6952. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6953. {
  6954. DebugAssert(!IsLocalBrowserMode());
  6955. // This also handles drops of remote files to queue.
  6956. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6957. SAFE_DESTROY(FDDFileList);
  6958. if (!FFakeFileDropTarget.IsEmpty())
  6959. {
  6960. RemoveDir(ApiPath(FFakeFileDropTarget));
  6961. }
  6962. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6963. {
  6964. try
  6965. {
  6966. TDragResult DDResult = (Sender == RemoteDirView) ?
  6967. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6968. // Focus is moved to the target application,
  6969. // but as we are going to present the UI, we need to steal the focus back.
  6970. // This most likely won't work though (windows does not allow application
  6971. // to steal focus most of the time)
  6972. Application->BringToFront();
  6973. // On older version of Windows we never got drMove here, see also comment below.
  6974. // On Windows 10, we get the "move".
  6975. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6976. {
  6977. UnicodeString TargetDirectory;
  6978. TFileOperation Operation;
  6979. // drInvalid may mean drMove, see comment below
  6980. switch (DDResult)
  6981. {
  6982. case drCopy:
  6983. Operation = foCopy;
  6984. break;
  6985. case drMove:
  6986. Operation = foMove;
  6987. break;
  6988. default:
  6989. DebugFail();
  6990. case drInvalid:
  6991. // prefer "copy" for safety
  6992. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6993. break;
  6994. }
  6995. TTransferOperationParam Param;
  6996. UnicodeString CounterName;
  6997. bool ForceQueue;
  6998. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  6999. {
  7000. // we get drInvalid both if d&d was intercepted by ddext,
  7001. // and when users drops on no-drop location.
  7002. // we tell the difference by existence of response from ddext,
  7003. // so we ignore absence of response in this case
  7004. if (DDResult != drInvalid)
  7005. {
  7006. // here we know that the extension is installed,
  7007. // as it is checked as soon as drag&drop starts from
  7008. // RemoteFileControlDDCreateDragFileList
  7009. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7010. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7011. {
  7012. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7013. }
  7014. else
  7015. {
  7016. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7017. }
  7018. }
  7019. }
  7020. else
  7021. {
  7022. // download using fake file
  7023. Param.Temp = false;
  7024. Param.DragDrop = true;
  7025. if (ForceQueue)
  7026. {
  7027. Param.Queue = asOn;
  7028. }
  7029. if (Sender == RemoteDirView)
  7030. {
  7031. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7032. }
  7033. if (RemoteFileControlFileOperation(Sender, Operation,
  7034. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7035. {
  7036. Configuration->Usage->Inc(CounterName);
  7037. }
  7038. }
  7039. }
  7040. }
  7041. __finally
  7042. {
  7043. CloseHandle(FDDExtMapFile);
  7044. FDDExtMapFile = NULL;
  7045. delete FDragFakeMonitors;
  7046. FDragFakeMonitors = NULL;
  7047. RemoveDir(ApiPath(FDragFakeDirectory));
  7048. FDragFakeDirectory = L"";
  7049. FFakeFileDropTarget = UnicodeString();
  7050. }
  7051. }
  7052. if (FDragDropSshTerminate.get() != NULL)
  7053. {
  7054. FDragDropSshTerminate->Rethrow();
  7055. }
  7056. }
  7057. //---------------------------------------------------------------------------
  7058. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7059. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7060. {
  7061. // Remember drop effect so we know (when user drops files), if we copy or move
  7062. FLastDropEffect = dwEffect;
  7063. }
  7064. //---------------------------------------------------------------------------
  7065. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7066. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7067. {
  7068. bool Result;
  7069. if (FDDTargetControl == QueueView3)
  7070. {
  7071. Directory = DefaultDownloadTargetDirectory();
  7072. Result = true;
  7073. CounterName = L"DownloadsDragDropQueue";
  7074. ForceQueue = true;
  7075. }
  7076. else if (!FFakeFileDropTarget.IsEmpty())
  7077. {
  7078. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7079. Result = true;
  7080. ForceQueue = false;
  7081. CounterName = L"DownloadsDragDropFakeFile";
  7082. }
  7083. else
  7084. {
  7085. ForceQueue = false;
  7086. Enabled = false;
  7087. try
  7088. {
  7089. int Timer = 0;
  7090. Result = false;
  7091. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7092. {
  7093. {
  7094. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7095. TDragExtCommStruct* CommStruct;
  7096. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7097. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7098. DebugAssert(CommStruct != NULL);
  7099. Result = !CommStruct->Dragging;
  7100. if (Result)
  7101. {
  7102. Directory = ExtractFilePath(CommStruct->DropDest);
  7103. CounterName = L"DownloadsDragDropExternalExt";
  7104. }
  7105. UnmapViewOfFile(CommStruct);
  7106. }
  7107. if (!Result)
  7108. {
  7109. Sleep(50);
  7110. Timer += 50;
  7111. Application->ProcessMessages();
  7112. }
  7113. }
  7114. }
  7115. __finally
  7116. {
  7117. Enabled = true;
  7118. }
  7119. }
  7120. return Result;
  7121. }
  7122. //---------------------------------------------------------------------------
  7123. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7124. const UnicodeString TempDir, int SecDelay)
  7125. {
  7126. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7127. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7128. if (FDelayedDeletionTimer == NULL)
  7129. {
  7130. DebugAssert(HandleAllocated());
  7131. FDelayedDeletionTimer = new TTimer(this);
  7132. FDelayedDeletionTimer->Interval = 10000;
  7133. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7134. }
  7135. else
  7136. {
  7137. FDelayedDeletionTimer->Enabled = true;
  7138. }
  7139. }
  7140. //---------------------------------------------------------------------------
  7141. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7142. {
  7143. DebugAssert(FDelayedDeletionList != NULL);
  7144. TDateTime N = Now();
  7145. TDateTime Alert;
  7146. UnicodeString Directory;
  7147. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7148. {
  7149. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7150. if ((N >= Alert) || (Sender == NULL))
  7151. {
  7152. Directory = FDelayedDeletionList->Strings[Index];
  7153. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7154. {
  7155. FDelayedDeletionList->Delete(Index);
  7156. }
  7157. }
  7158. }
  7159. if (FDelayedDeletionList->Count == 0)
  7160. {
  7161. FDelayedDeletionTimer->Enabled = false;
  7162. }
  7163. }
  7164. //---------------------------------------------------------------------------
  7165. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7166. {
  7167. DebugAssert(!IsLocalBrowserMode());
  7168. if (IsFileControl(FDDTargetControl, osRemote) ||
  7169. (FDDTargetControl == SessionsPageControl))
  7170. {
  7171. TTerminal * TargetTerminal = NULL;
  7172. TFileOperation Operation = foNone;
  7173. if (FDDTargetControl == SessionsPageControl)
  7174. {
  7175. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7176. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7177. // do not allow dropping on the "+" tab
  7178. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  7179. if (TargetTerminal != NULL)
  7180. {
  7181. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7182. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7183. {
  7184. Operation = foRemoteMove;
  7185. }
  7186. else
  7187. {
  7188. Operation = foRemoteCopy;
  7189. }
  7190. }
  7191. }
  7192. else
  7193. {
  7194. if (FLastDropEffect == DROPEFFECT_MOVE)
  7195. {
  7196. Operation = foRemoteMove;
  7197. }
  7198. else if (FLastDropEffect == DROPEFFECT_COPY)
  7199. {
  7200. Operation = foRemoteCopy;
  7201. }
  7202. }
  7203. if (Operation != foNone)
  7204. {
  7205. RemoteFileControlFileOperation(DropSourceControl,
  7206. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7207. }
  7208. // abort drag&drop
  7209. Abort();
  7210. }
  7211. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7212. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7213. (FDDTargetControl != QueueView3))
  7214. {
  7215. DebugAssert(!FDragTempDir.IsEmpty());
  7216. TTransferType Type;
  7217. UnicodeString TempDir = FDragTempDir;
  7218. // We clear FDragTempDir before calling
  7219. // just in case it fail (raises exception)
  7220. FDragTempDir = L"";
  7221. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7222. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7223. // empty directory parameter means temp directory -> don't display it!
  7224. UnicodeString TargetDir = L"";
  7225. int Options = 0;
  7226. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7227. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7228. {
  7229. Abort();
  7230. }
  7231. // TargetDir is set when dropped on local file control
  7232. // (this was workaround for legacy dirview event handling, now it should be
  7233. // made prettier)
  7234. if (TargetDir.IsEmpty())
  7235. {
  7236. TargetDir = TempDir;
  7237. if (ForceDirectories(ApiPath(TargetDir)))
  7238. {
  7239. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7240. FPendingTempSpaceWarn = true;
  7241. try
  7242. {
  7243. FDragDropOperation = true;
  7244. int Params = cpTemporary |
  7245. (Type == ttMove ? cpDelete : 0);
  7246. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7247. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7248. }
  7249. __finally
  7250. {
  7251. FDragDropOperation = false;
  7252. FPendingTempSpaceWarn = false;
  7253. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7254. }
  7255. }
  7256. else
  7257. {
  7258. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7259. }
  7260. }
  7261. }
  7262. }
  7263. //---------------------------------------------------------------------------
  7264. void __fastcall TCustomScpExplorerForm::DDDownload(
  7265. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7266. {
  7267. DebugAssert(!IsLocalBrowserMode());
  7268. TAutoBatch AutoBatch(this);
  7269. UpdateCopyParamCounters(*CopyParam);
  7270. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7271. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7272. {
  7273. RemoteDriveView->UpdateDropSource();
  7274. }
  7275. }
  7276. //---------------------------------------------------------------------------
  7277. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7278. {
  7279. public:
  7280. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7281. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7282. {
  7283. }
  7284. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7285. {
  7286. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7287. TDataObjectFilesEx::AllowData(FormatEtc);
  7288. }
  7289. };
  7290. //---------------------------------------------------------------------------
  7291. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7292. TObject * Sender, TDataObject *& DataObject)
  7293. {
  7294. if (FDDExtMapFile != NULL)
  7295. {
  7296. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7297. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7298. {
  7299. Abort();
  7300. }
  7301. if (FileList->Count > 0)
  7302. {
  7303. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7304. if (!FilesObject->IsValid(true, true))
  7305. {
  7306. FilesObject->_Release();
  7307. }
  7308. else
  7309. {
  7310. DataObject = FilesObject;
  7311. }
  7312. }
  7313. }
  7314. }
  7315. //---------------------------------------------------------------------------
  7316. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7317. {
  7318. DebugFail();
  7319. }
  7320. //---------------------------------------------------------------------------
  7321. void __fastcall TCustomScpExplorerForm::GoToTree()
  7322. {
  7323. ComponentVisible[fcRemoteTree] = true;
  7324. DriveView(osRemote)->SetFocus();
  7325. }
  7326. //---------------------------------------------------------------------------
  7327. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7328. TPanelExport Export)
  7329. {
  7330. TCustomDirView * DirView = this->DirView(Side);
  7331. std::unique_ptr<TStrings> ExportData(new TStringList());
  7332. switch (Export)
  7333. {
  7334. case pePath:
  7335. ExportData->Add(DirView->PathName);
  7336. break;
  7337. case peFileList:
  7338. case peFullFileList:
  7339. {
  7340. bool FullPath = (Export == peFullFileList);
  7341. DirView->CreateFileList(false, FullPath, ExportData.get());
  7342. for (int Index = 0; Index < ExportData->Count; Index++)
  7343. {
  7344. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7345. {
  7346. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7347. }
  7348. }
  7349. }
  7350. break;
  7351. default:
  7352. DebugFail();
  7353. }
  7354. return ExportData.release();
  7355. }
  7356. //---------------------------------------------------------------------------
  7357. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7358. TPanelExport Export, TPanelExportDestination Destination)
  7359. {
  7360. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7361. PanelExportStore(Side, Export, Destination, ExportData.get());
  7362. }
  7363. //---------------------------------------------------------------------------
  7364. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7365. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7366. TStrings * ExportData)
  7367. {
  7368. if (Destination == pedClipboard)
  7369. {
  7370. TInstantOperationVisualizer Visualizer;
  7371. CopyToClipboard(ExportData);
  7372. }
  7373. else
  7374. {
  7375. DebugFail();
  7376. }
  7377. }
  7378. //---------------------------------------------------------------------------
  7379. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7380. {
  7381. TCustomDirView * DirView = this->DirView(Side);
  7382. UnicodeString Mask = DirView->Mask;
  7383. if (DoFilterMaskDialog(DirView, Mask))
  7384. {
  7385. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7386. Configuration->Usage->Inc(L"Filters");
  7387. }
  7388. }
  7389. //---------------------------------------------------------------------------
  7390. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7391. {
  7392. return FQueueController->DefaultOperation();
  7393. }
  7394. //---------------------------------------------------------------------------
  7395. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7396. TQueueOperation Operation, void ** Param)
  7397. {
  7398. switch (Operation)
  7399. {
  7400. case qoPreferences:
  7401. return true;
  7402. case qoGoTo:
  7403. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7404. case qoOnceEmpty:
  7405. return IsAnythingQueued();
  7406. default:
  7407. return FQueueController->AllowOperation(Operation, Param);
  7408. }
  7409. }
  7410. //---------------------------------------------------------------------------
  7411. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7412. {
  7413. if (DebugAlwaysTrue(QueueView3->Visible))
  7414. {
  7415. QueueView3->SetFocus();
  7416. }
  7417. }
  7418. //---------------------------------------------------------------------------
  7419. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7420. TQueueOperation Operation, void * Param)
  7421. {
  7422. if (Operation == qoGoTo)
  7423. {
  7424. GoToQueue();
  7425. }
  7426. else if (Operation == qoPreferences)
  7427. {
  7428. PreferencesDialog(pmQueue);
  7429. }
  7430. else
  7431. {
  7432. FQueueController->ExecuteOperation(Operation, Param);
  7433. }
  7434. }
  7435. //---------------------------------------------------------------------------
  7436. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7437. {
  7438. return (Queue != NULL) && Queue->Enabled;
  7439. }
  7440. //---------------------------------------------------------------------------
  7441. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7442. {
  7443. DebugAssert(Queue != NULL);
  7444. if (Queue != NULL)
  7445. {
  7446. Queue->Enabled = !Queue->Enabled;
  7447. }
  7448. }
  7449. //---------------------------------------------------------------------------
  7450. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7451. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7452. {
  7453. FQueueActedItem = QueueView3->ItemFocused;
  7454. }
  7455. //---------------------------------------------------------------------------
  7456. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7457. {
  7458. return TopDock->Height + QueueSplitter->Height;
  7459. }
  7460. //---------------------------------------------------------------------------
  7461. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7462. {
  7463. return
  7464. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7465. (QueueDock->Visible ? QueueDock->Height : 0) +
  7466. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7467. }
  7468. //---------------------------------------------------------------------------
  7469. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7470. {
  7471. return ScaleByTextHeight(this, 48);
  7472. }
  7473. //---------------------------------------------------------------------------
  7474. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7475. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7476. {
  7477. // when queue is hidden by double-clicking splitter, stray attempt to
  7478. // resize the panel with strange value arrives, make sure it is ignored
  7479. if (ComponentVisible[fcQueueView])
  7480. {
  7481. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7482. if (NewSize > MaxHeightLimit)
  7483. {
  7484. NewSize = MaxHeightLimit;
  7485. }
  7486. int MinHeightLimit =
  7487. GetStaticQueuePanelComponentsHeight() +
  7488. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7489. GetMinQueueViewHeight();
  7490. if (NewSize < MinHeightLimit)
  7491. {
  7492. NewSize = MinHeightLimit;
  7493. }
  7494. }
  7495. else
  7496. {
  7497. Accept = false;
  7498. }
  7499. }
  7500. //---------------------------------------------------------------------------
  7501. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7502. {
  7503. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7504. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7505. if (QueueViewHeight < GetMinQueueViewHeight())
  7506. {
  7507. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7508. }
  7509. }
  7510. //---------------------------------------------------------------------------
  7511. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7512. TDragObject *& /*DragObject*/)
  7513. {
  7514. FQueueActedItem = QueueView3->ItemFocused;
  7515. }
  7516. //---------------------------------------------------------------------------
  7517. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7518. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7519. {
  7520. Accept = true;
  7521. if (Source == QueueView3)
  7522. {
  7523. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7524. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7525. if (Accept)
  7526. {
  7527. TQueueItemProxy * QueueItem;
  7528. TQueueItemProxy * DestQueueItem;
  7529. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7530. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7531. Accept = (QueueItem != DestQueueItem) &&
  7532. (QueueItem->Status == TQueueItem::qsPending) &&
  7533. (DestQueueItem->Status == TQueueItem::qsPending);
  7534. }
  7535. }
  7536. }
  7537. //---------------------------------------------------------------------------
  7538. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7539. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7540. {
  7541. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7542. {
  7543. TQueueItemProxy * QueueItem;
  7544. TQueueItemProxy * DestQueueItem;
  7545. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7546. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7547. QueueItem->Move(DestQueueItem);
  7548. }
  7549. }
  7550. //---------------------------------------------------------------------------
  7551. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7552. {
  7553. if ((QueueView3->ItemFocused == NULL) &&
  7554. (QueueView3->Items->Count > 0))
  7555. {
  7556. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7557. }
  7558. QueueLabelUpdateStatus();
  7559. }
  7560. //---------------------------------------------------------------------------
  7561. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7562. {
  7563. QueueLabelUpdateStatus();
  7564. }
  7565. //---------------------------------------------------------------------------
  7566. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7567. {
  7568. QueueLabel->UpdateStatus();
  7569. }
  7570. //---------------------------------------------------------------------------
  7571. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7572. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7573. {
  7574. if (Selected)
  7575. {
  7576. NonVisualDataModule->UpdateNonVisibleActions();
  7577. }
  7578. }
  7579. //---------------------------------------------------------------------------
  7580. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7581. {
  7582. TDragDropFilesEx * Result = NULL;
  7583. if (Sender == SessionsPageControl)
  7584. {
  7585. Result = FSessionsDragDropFilesEx;
  7586. }
  7587. else if (Sender == QueueView3)
  7588. {
  7589. Result = FQueueDragDropFilesEx;
  7590. }
  7591. else
  7592. {
  7593. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7594. if (DirView != NULL)
  7595. {
  7596. Result = DirView->DragDropFilesEx;
  7597. }
  7598. else
  7599. {
  7600. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7601. if (DriveView != NULL)
  7602. {
  7603. Result = DriveView->DragDropFilesEx;
  7604. }
  7605. }
  7606. }
  7607. DebugAssert(Result != NULL);
  7608. return Result;
  7609. }
  7610. //---------------------------------------------------------------------------
  7611. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7612. {
  7613. return (DView->SelCount == DView->FilesCount);
  7614. }
  7615. //---------------------------------------------------------------------------
  7616. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7617. {
  7618. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7619. }
  7620. //---------------------------------------------------------------------------
  7621. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7622. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7623. {
  7624. DebugAssert(!IsLocalBrowserMode());
  7625. TFileOperation Operation;
  7626. switch (Effect)
  7627. {
  7628. case DROPEFFECT_MOVE:
  7629. Operation = foMove;
  7630. break;
  7631. case DROPEFFECT_COPY:
  7632. // occures on WinXP (reported by user)
  7633. default:
  7634. Operation = foCopy;
  7635. break;
  7636. };
  7637. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7638. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7639. if (DragDropFilesEx->FileList->Count > 0)
  7640. {
  7641. TStrings * FileList = new TStringList();
  7642. try
  7643. {
  7644. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7645. {
  7646. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7647. }
  7648. FDragDropOperation = true;
  7649. TTransferOperationParam Param;
  7650. Param.TargetDirectory = TargetPath;
  7651. // upload, no temp dirs
  7652. Param.Temp = false;
  7653. Param.DragDrop = DragDrop;
  7654. Param.Options =
  7655. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7656. if (ForceQueue)
  7657. {
  7658. Param.Queue = asOn;
  7659. }
  7660. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7661. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7662. {
  7663. if (IsFileControl(DropSourceControl, osLocal))
  7664. {
  7665. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7666. }
  7667. else
  7668. {
  7669. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7670. }
  7671. }
  7672. }
  7673. __finally
  7674. {
  7675. FDragDropOperation = false;
  7676. delete FileList;
  7677. }
  7678. }
  7679. }
  7680. //---------------------------------------------------------------------------
  7681. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7682. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7683. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7684. {
  7685. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7686. }
  7687. //---------------------------------------------------------------------------
  7688. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7689. TObject * Sender, int grfKeyState, int & dwEffect)
  7690. {
  7691. DebugAssert(!IsLocalBrowserMode());
  7692. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7693. if ((dwEffect != DROPEFFECT_NONE) &&
  7694. IsFileControl(DropSourceControl, osRemote))
  7695. {
  7696. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7697. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7698. (RemoteDirView->DropTarget == NULL))
  7699. {
  7700. dwEffect = DROPEFFECT_NONE;
  7701. }
  7702. else
  7703. {
  7704. if (dwEffect == DROPEFFECT_COPY)
  7705. {
  7706. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  7707. // currently we support copying always (at least via temporary directory);
  7708. // remove associated checks once this all proves stable and working
  7709. bool CopyCapable = true;
  7710. // if we do not support neither of operations, there's no discussion
  7711. if (!MoveCapable && !CopyCapable)
  7712. {
  7713. dwEffect = DROPEFFECT_NONE;
  7714. }
  7715. else
  7716. {
  7717. // The default effect inside remote panel is move,
  7718. // unless we do not support it, but support copy
  7719. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7720. {
  7721. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7722. }
  7723. else
  7724. {
  7725. // with ctrl-down, we want copy unless it is not supported
  7726. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7727. }
  7728. }
  7729. }
  7730. }
  7731. }
  7732. }
  7733. //---------------------------------------------------------------------------
  7734. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  7735. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  7736. {
  7737. DebugAssert(!IsLocalBrowserMode());
  7738. if (FDDTotalSize >= 0)
  7739. {
  7740. if (File->IsDirectory)
  7741. {
  7742. FDDTotalSize = -1;
  7743. }
  7744. else
  7745. {
  7746. FDDTotalSize += File->Size;
  7747. }
  7748. }
  7749. DebugAssert(!FDragTempDir.IsEmpty());
  7750. // TODO: this is quite ineffective
  7751. // TODO: what if invalid character replacement is disabled?
  7752. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  7753. UnicodeString TransferFileName;
  7754. if (Sender == RemoteDriveView)
  7755. {
  7756. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  7757. }
  7758. else
  7759. {
  7760. TransferFileName = File->FileName;
  7761. }
  7762. FDDFileList->AddObject(TransferFileName, File);
  7763. }
  7764. //---------------------------------------------------------------------------
  7765. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  7766. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  7767. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  7768. {
  7769. // sometimes we do not get DDEnd so the list is not released
  7770. SAFE_DESTROY(FDDFileList);
  7771. FDDFileList = new TStringList();
  7772. FDragTempDir = WinConfiguration->TemporaryDir();
  7773. FDDTotalSize = 0;
  7774. FDragDropSshTerminate.reset(NULL);
  7775. }
  7776. //---------------------------------------------------------------------------
  7777. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  7778. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  7779. HRESULT & Result)
  7780. {
  7781. if (Result == DRAGDROP_S_DROP)
  7782. {
  7783. try
  7784. {
  7785. GlobalDragImageList->HideDragImage();
  7786. try
  7787. {
  7788. RemoteFileControlDDTargetDrop();
  7789. }
  7790. catch(ESshTerminate & E)
  7791. {
  7792. FDragDropSshTerminate.reset(E.Clone());
  7793. }
  7794. }
  7795. catch (Exception &E)
  7796. {
  7797. // If downloading fails we need to cancel drag&drop, otherwise
  7798. // Explorer shows error
  7799. // But by the way exception probably never reach this point as
  7800. // it's catched on way.
  7801. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  7802. Result = DRAGDROP_S_CANCEL;
  7803. ShowExtendedException(Terminal, &E);
  7804. }
  7805. }
  7806. }
  7807. //---------------------------------------------------------------------------
  7808. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  7809. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  7810. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  7811. {
  7812. TFileMasks::TParams MaskParams;
  7813. MaskParams.Size = Size;
  7814. MaskParams.Modification = Modification;
  7815. // this does not re-parse the mask if it is the same as the last time
  7816. FDirViewMatchMask = Masks;
  7817. bool ImplicitMatch;
  7818. Matches =
  7819. // RecurseInclude parameter has no effect as the Path is empty
  7820. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  7821. (AllowImplicitMatches || !ImplicitMatch);
  7822. }
  7823. //---------------------------------------------------------------------------
  7824. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  7825. TObject * Sender, TListItem * Item, WORD & Indexes)
  7826. {
  7827. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  7828. UnicodeString Ext;
  7829. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  7830. {
  7831. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  7832. }
  7833. else
  7834. {
  7835. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  7836. }
  7837. if (SameText(Ext, Configuration->PartialExt))
  7838. {
  7839. Indexes |= oiPartial;
  7840. }
  7841. }
  7842. //---------------------------------------------------------------------------
  7843. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  7844. {
  7845. return
  7846. DirViewEnabled(osCurrent) &&
  7847. DirView(osCurrent)->CanPasteFromClipBoard();
  7848. }
  7849. //---------------------------------------------------------------------------
  7850. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  7851. {
  7852. bool Result = false;
  7853. if (CanPasteToDirViewFromClipBoard())
  7854. {
  7855. Result = true;
  7856. }
  7857. else
  7858. {
  7859. UnicodeString ClipboardText;
  7860. if (NonEmptyTextFromClipboard(ClipboardText))
  7861. {
  7862. if (StoredSessions->IsUrl(ClipboardText))
  7863. {
  7864. Result = true;
  7865. }
  7866. else
  7867. {
  7868. Result = DirViewEnabled(osCurrent);
  7869. }
  7870. }
  7871. }
  7872. return Result;
  7873. }
  7874. //---------------------------------------------------------------------------
  7875. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7876. {
  7877. if (DoesClipboardContainOurFiles())
  7878. {
  7879. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  7880. {
  7881. DebugAssert(!IsLocalBrowserMode());
  7882. TTerminalManager * Manager = TTerminalManager::Instance();
  7883. TTerminal * TergetTerminal = Manager->ActiveTerminal;
  7884. Manager->ActiveTerminal = FClipboardTerminal;
  7885. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TergetTerminal);
  7886. }
  7887. }
  7888. else if (CanPasteToDirViewFromClipBoard())
  7889. {
  7890. DirView(osCurrent)->PasteFromClipBoard();
  7891. }
  7892. else
  7893. {
  7894. UnicodeString ClipboardText;
  7895. if (NonEmptyTextFromClipboard(ClipboardText))
  7896. {
  7897. if (StoredSessions->IsUrl(ClipboardText))
  7898. {
  7899. NewSession(false, ClipboardText);
  7900. }
  7901. else
  7902. {
  7903. DirView(osCurrent)->Path = ClipboardText;
  7904. }
  7905. }
  7906. }
  7907. }
  7908. //---------------------------------------------------------------------------
  7909. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7910. {
  7911. // TBD
  7912. }
  7913. //---------------------------------------------------------------------------
  7914. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  7915. {
  7916. TCustomDirView * ADirView = DirView(Side);
  7917. ADirView->SelectAll(Mode);
  7918. ADirView->SetFocus();
  7919. }
  7920. //---------------------------------------------------------------------------
  7921. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  7922. {
  7923. TCustomDirView * ADirView = DirView(Side);
  7924. TFileFilter Filter;
  7925. DefaultFileFilter(Filter);
  7926. if (DoSelectMaskDialog(ADirView, Select, Filter))
  7927. {
  7928. Configuration->Usage->Inc(L"MaskSelections");
  7929. ADirView->SelectFiles(Filter, Select);
  7930. ADirView->SetFocus();
  7931. }
  7932. }
  7933. //---------------------------------------------------------------------------
  7934. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  7935. {
  7936. TCustomDirView * ADirView = DirView(Side);
  7937. ADirView->RestoreSelectedNames();
  7938. ADirView->SetFocus();
  7939. }
  7940. //---------------------------------------------------------------------------
  7941. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7942. {
  7943. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7944. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7945. {
  7946. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7947. UnicodeString Ext;
  7948. if (!IsSideLocalBrowser(osCurrent))
  7949. {
  7950. Ext = UnixExtractFileExt(FileName);
  7951. }
  7952. else
  7953. {
  7954. Ext = ExtractFileExt(FileName);
  7955. }
  7956. if (Ext.IsEmpty())
  7957. {
  7958. Ext = L".";
  7959. }
  7960. TFileFilter Filter;
  7961. Filter.Masks = FORMAT(L"*%s", (Ext));
  7962. Filter.Directories = false;
  7963. CurrentDirView->SelectFiles(Filter, Select);
  7964. }
  7965. }
  7966. //---------------------------------------------------------------------------
  7967. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7968. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7969. {
  7970. UnicodeString Result;
  7971. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  7972. {
  7973. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  7974. }
  7975. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  7976. {
  7977. // noop
  7978. }
  7979. else
  7980. {
  7981. Result =
  7982. FMTLOAD(FILE_INFO_FORMAT,
  7983. (FormatBytes(FileInfo.SelectedSize),
  7984. FormatBytes(FileInfo.FilesSize),
  7985. FormatNumber(FileInfo.SelectedCount),
  7986. FormatNumber(FileInfo.FilesCount)));
  7987. }
  7988. return Result;
  7989. }
  7990. //---------------------------------------------------------------------------
  7991. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7992. TTBXStatusPanel * Panel, TOperationSide Side)
  7993. {
  7994. if (Panel->Index == 1)
  7995. {
  7996. ToggleShowHiddenFiles();
  7997. }
  7998. else if (Panel->Index == 2)
  7999. {
  8000. Filter(Side);
  8001. }
  8002. }
  8003. //---------------------------------------------------------------------------
  8004. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8005. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8006. {
  8007. DebugAssert(!StatusBar->SimplePanel);
  8008. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8009. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8010. }
  8011. //---------------------------------------------------------------------------
  8012. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8013. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8014. {
  8015. DebugAssert(StatusBar->Panels->Count >= 3);
  8016. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8017. if (FileInfo.HiddenCount > 0)
  8018. {
  8019. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8020. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8021. }
  8022. else
  8023. {
  8024. HiddenFilesPanel->ViewPriority = 0;
  8025. // not really necessary, just to cleanup no-longer-valid data
  8026. HiddenFilesPanel->Caption = L"";
  8027. }
  8028. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8029. if (FileInfo.FilteredCount > 0)
  8030. {
  8031. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8032. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8033. }
  8034. else
  8035. {
  8036. FilteredFilesPanel->ViewPriority = 0;
  8037. // not really necessary, just to cleanup no-longer-valid data
  8038. FilteredFilesPanel->Caption = L"";
  8039. }
  8040. }
  8041. //---------------------------------------------------------------------------
  8042. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8043. TObject * /*Sender*/)
  8044. {
  8045. if (DirView(osOther)->Enabled)
  8046. {
  8047. DirView(osOther)->SetFocus();
  8048. }
  8049. }
  8050. //---------------------------------------------------------------------------
  8051. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8052. {
  8053. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8054. switch (Config.Show)
  8055. {
  8056. case qvShow:
  8057. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8058. {
  8059. Config.Show = qvHide;
  8060. }
  8061. else
  8062. {
  8063. Config.Show = Config.LastHideShow;
  8064. }
  8065. break;
  8066. case qvHideWhenEmpty:
  8067. if (ComponentVisible[fcQueueView])
  8068. {
  8069. Config.Show = qvHide;
  8070. }
  8071. else
  8072. {
  8073. Config.LastHideShow = Config.Show;
  8074. Config.Show = qvShow;
  8075. }
  8076. break;
  8077. case qvHide:
  8078. Config.LastHideShow = Config.Show;
  8079. Config.Show = qvShow;
  8080. break;
  8081. }
  8082. WinConfiguration->QueueView = Config;
  8083. }
  8084. //---------------------------------------------------------------------------
  8085. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8086. {
  8087. UnicodeString Result;
  8088. if (FTerminal != NULL)
  8089. {
  8090. switch (WinConfiguration->PathInCaption)
  8091. {
  8092. case picShort:
  8093. Result = TTerminalManager::Instance()->GetTerminalShortPath(FTerminal);
  8094. break;
  8095. case picFull:
  8096. Result = FTerminal->CurrentDirectory;
  8097. break;
  8098. }
  8099. }
  8100. return Result;
  8101. }
  8102. //---------------------------------------------------------------------------
  8103. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8104. {
  8105. TColor Result = GetWindowColor(FSessionColor);
  8106. return Result;
  8107. }
  8108. //---------------------------------------------------------------------------
  8109. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8110. {
  8111. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8112. return Result;
  8113. }
  8114. //---------------------------------------------------------------------------
  8115. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8116. {
  8117. TTerminalManager::Instance()->UpdateAppTitle();
  8118. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  8119. // background to gray on Windows 7 (works on Windows 10).
  8120. // See also EnableControl
  8121. if (Showing)
  8122. {
  8123. if (Terminal != NULL)
  8124. {
  8125. // Update path when it changes
  8126. if ((SessionsPageControl->ActivePage != NULL) && (GetSessionTabTerminal(SessionsPageControl->ActivePage) == Terminal))
  8127. {
  8128. UpdateSessionTab(SessionsPageControl->ActivePage);
  8129. }
  8130. }
  8131. NonVisualDataModule->ReconnectSessionAction->Update();
  8132. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8133. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8134. CenterReconnectToolbar();
  8135. bool HasTerminal = HasActiveTerminal();
  8136. RemoteDirView->Enabled = HasTerminal;
  8137. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8138. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8139. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8140. RemoteDriveView->Color = RemoteDirView->Color;
  8141. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8142. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8143. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8144. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8145. QueueFileList->Enabled = QueueView3->Enabled;
  8146. QueueFileList->Color = QueueView3->Color;
  8147. QueueFileList->Font->Color = QueueView3->Font->Color;
  8148. QueueLabelUpdateStatus();
  8149. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8150. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8151. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  8152. }
  8153. }
  8154. //---------------------------------------------------------------------------
  8155. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8156. {
  8157. UpdateControls();
  8158. }
  8159. //---------------------------------------------------------------------------
  8160. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8161. TObject * Sender)
  8162. {
  8163. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8164. DebugAssert(DirView != NULL);
  8165. DoDirViewLoaded(DirView);
  8166. TransferPresetAutoSelect();
  8167. }
  8168. //---------------------------------------------------------------------------
  8169. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8170. {
  8171. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8172. // first run after installation
  8173. if (double(Updates.LastCheck) == 0)
  8174. {
  8175. // make sure next time there will be an update (if enabled)
  8176. Updates.LastCheck = TDateTime(1);
  8177. WinConfiguration->Updates = Updates;
  8178. }
  8179. else if ((double(Updates.Period) > 0) &&
  8180. (Now() - Updates.LastCheck >= Updates.Period))
  8181. {
  8182. TThreadMethod OnUpdatesChecked = NULL;
  8183. if (!IsUWP())
  8184. {
  8185. OnUpdatesChecked = UpdatesChecked;
  8186. }
  8187. StartUpdateThread(OnUpdatesChecked);
  8188. }
  8189. }
  8190. //---------------------------------------------------------------------------
  8191. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8192. {
  8193. UnicodeString Message;
  8194. bool New;
  8195. TQueryType Type;
  8196. GetUpdatesMessage(Message, New, Type, false);
  8197. if (!Message.IsEmpty())
  8198. {
  8199. if (New)
  8200. {
  8201. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8202. }
  8203. if (!New && (Type != qtWarning))
  8204. {
  8205. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8206. }
  8207. else
  8208. {
  8209. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8210. }
  8211. if (New)
  8212. {
  8213. Configuration->Usage->Inc(L"UpdateNotifications");
  8214. }
  8215. }
  8216. }
  8217. //---------------------------------------------------------------------------
  8218. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8219. {
  8220. RestoreApp();
  8221. bool CanDisplay = !NonVisualDataModule->Busy;
  8222. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8223. {
  8224. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8225. }
  8226. if (CanDisplay)
  8227. {
  8228. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8229. CheckForUpdates(true);
  8230. }
  8231. else
  8232. {
  8233. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8234. }
  8235. }
  8236. //---------------------------------------------------------------------------
  8237. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8238. TCopyParamRuleData & Data)
  8239. {
  8240. DebugAssert(Terminal != NULL);
  8241. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8242. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8243. Data.RemoteDirectory = RemoteDirView->PathName;
  8244. }
  8245. //---------------------------------------------------------------------------
  8246. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8247. {
  8248. // Terminal can be null when we are changing local directory implicitly,
  8249. // because it has been deleted, while no session is connected
  8250. // (Login dialog is open)
  8251. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8252. {
  8253. DebugAssert(!IsLocalBrowserMode());
  8254. TCopyParamRuleData Data;
  8255. GetTransferPresetAutoSelectData(Data);
  8256. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8257. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8258. if (CopyParamIndex < 0)
  8259. {
  8260. // there is no preset that matches autoselection
  8261. // set preset that we consider "default"
  8262. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8263. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8264. }
  8265. else
  8266. {
  8267. // there is preset matching autoselection
  8268. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8269. if (CopyParamName == FCopyParamAutoSelected)
  8270. {
  8271. // autoselected the same preset as the last time
  8272. // make no change (i.e. preserve custom user preset, if any)
  8273. }
  8274. else
  8275. {
  8276. // autoselected the different preset then the last time (or there
  8277. // was default preset set)
  8278. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8279. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8280. }
  8281. }
  8282. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8283. {
  8284. if (CopyParamIndex >= 0)
  8285. {
  8286. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8287. }
  8288. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8289. try
  8290. {
  8291. int Fmt =
  8292. (CopyParamIndex < 0) ?
  8293. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8294. COPY_PARAM_AUTOSELECTED;
  8295. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8296. Data->Message = MainInstructions(Message);
  8297. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8298. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8299. CopyParamAttrs);
  8300. if (CopyParamIndex >= 0)
  8301. {
  8302. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8303. Info = FORMAT(L"%s\n \n%s", (Info,
  8304. FMTLOAD(COPY_PARAM_RULE,
  8305. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8306. }
  8307. Data->Message += L"\n\n" + Info;
  8308. if (WinConfiguration->CopyParamAutoSelectNotice)
  8309. {
  8310. TransferPresetNoteMessage(Data, true);
  8311. }
  8312. else
  8313. {
  8314. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8315. Data = NULL; // ownership passed
  8316. }
  8317. }
  8318. __finally
  8319. {
  8320. delete Data;
  8321. }
  8322. }
  8323. }
  8324. }
  8325. //---------------------------------------------------------------------------
  8326. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8327. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8328. {
  8329. DebugAssert(NoteData != NULL);
  8330. DebugAssert(!IsLocalBrowserMode());
  8331. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8332. TQueryButtonAlias Aliases[1];
  8333. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8334. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8335. Params.Aliases = Aliases;
  8336. Params.AliasesCount = LENOF(Aliases);
  8337. unsigned int Result =
  8338. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8339. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8340. switch (Result)
  8341. {
  8342. case qaNeverAskAgain:
  8343. DebugAssert(AllowNeverAskAgain);
  8344. WinConfiguration->CopyParamAutoSelectNotice = false;
  8345. break;
  8346. case qaIgnore:
  8347. PreferencesDialog(pmPresets);
  8348. break;
  8349. }
  8350. }
  8351. //---------------------------------------------------------------------------
  8352. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8353. {
  8354. // as of now useless, as this is used for notes only, never for balloons, ...
  8355. RestoreApp();
  8356. // .. and we should never be busy here
  8357. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8358. {
  8359. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8360. }
  8361. }
  8362. //---------------------------------------------------------------------------
  8363. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8364. TPreferencesMode APreferencesMode)
  8365. {
  8366. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8367. TCopyParamRuleData Data;
  8368. if (Terminal != NULL)
  8369. {
  8370. PreferencesData.reset(new TPreferencesDialogData());
  8371. GetTransferPresetAutoSelectData(Data);
  8372. PreferencesData->CopyParamRuleData = &Data;
  8373. }
  8374. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8375. }
  8376. //---------------------------------------------------------------------------
  8377. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8378. const TCustomCommandType & Command)
  8379. {
  8380. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8381. {
  8382. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8383. }
  8384. }
  8385. //---------------------------------------------------------------------------
  8386. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8387. {
  8388. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8389. TCustomCommandType Command;
  8390. // make sure we use local custom command when remote are not supported
  8391. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8392. {
  8393. Command = FLastCustomCommand;
  8394. }
  8395. else
  8396. {
  8397. Command.Params = Command.Params | ccLocal;
  8398. }
  8399. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8400. FEditingFocusedAdHocCommand = OnFocused;
  8401. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8402. int Options =
  8403. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8404. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8405. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8406. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8407. {
  8408. FLastCustomCommand = Command;
  8409. UpdateCustomCommandsToolbar();
  8410. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8411. }
  8412. }
  8413. //---------------------------------------------------------------------------
  8414. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8415. {
  8416. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8417. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8418. DebugAssert(State > 0);
  8419. if (State <= 0)
  8420. {
  8421. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8422. }
  8423. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8424. }
  8425. //---------------------------------------------------------------------------
  8426. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8427. TCustomCommandType & Command, int & State)
  8428. {
  8429. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8430. if (Result)
  8431. {
  8432. Command = FLastCustomCommand;
  8433. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8434. }
  8435. return Result;
  8436. }
  8437. //---------------------------------------------------------------------------
  8438. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8439. {
  8440. ResetIncrementalSearch();
  8441. }
  8442. //---------------------------------------------------------------------------
  8443. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8444. {
  8445. DebugAssert(ComponentVisible[Component]);
  8446. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8447. }
  8448. //---------------------------------------------------------------------------
  8449. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8450. {
  8451. // when queue panel is resized here directly, the status bar is stretched
  8452. // over whole space the panel occupied
  8453. PostComponentHide(fcQueueView);
  8454. }
  8455. //---------------------------------------------------------------------------
  8456. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8457. {
  8458. ComponentVisible[fcQueueFileList] = false;
  8459. }
  8460. //---------------------------------------------------------------------------
  8461. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8462. {
  8463. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8464. RefreshColorMode();
  8465. WinConfiguration->ResetSysDarkTheme();
  8466. ConfigurationChanged();
  8467. ConfigureInterface();
  8468. // Should be called for all controls
  8469. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8470. }
  8471. //---------------------------------------------------------------------------
  8472. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8473. {
  8474. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8475. if (!FInvalid &&
  8476. (Message.LParam != 0) &&
  8477. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8478. {
  8479. ThemeChanged();
  8480. }
  8481. TForm::Dispatch(&Message);
  8482. }
  8483. //---------------------------------------------------------------------------
  8484. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8485. {
  8486. TMessage * M = static_cast<TMessage*>(Message);
  8487. switch (M->Msg)
  8488. {
  8489. case CM_DIALOGCHAR:
  8490. CMDialogChar(*M);
  8491. break;
  8492. case WM_APPCOMMAND:
  8493. WMAppCommand(*M);
  8494. break;
  8495. case WM_SYSCOMMAND:
  8496. WMSysCommand(*M);
  8497. break;
  8498. case WM_QUERYENDSESSION:
  8499. WMQueryEndSession(*M);
  8500. break;
  8501. case WM_ENDSESSION:
  8502. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8503. break;
  8504. #ifdef _DEBUG
  8505. case WM_WINDOWPOSCHANGED:
  8506. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8507. break;
  8508. case CM_CUSTOMSTYLECHANGED:
  8509. TForm::Dispatch(Message);
  8510. break;
  8511. #endif
  8512. case WM_COMPONENT_HIDE:
  8513. {
  8514. Byte Component = static_cast<Byte>(M->WParam);
  8515. // sanity check
  8516. if (ComponentVisible[Component])
  8517. {
  8518. // special treatment
  8519. if (Component == fcQueueView)
  8520. {
  8521. ToggleQueueVisibility();
  8522. DebugAssert(!ComponentVisible[fcQueueView]);
  8523. }
  8524. else
  8525. {
  8526. ComponentVisible[Component] = false;
  8527. }
  8528. }
  8529. }
  8530. break;
  8531. case WM_COPYDATA:
  8532. WMCopyData(*M);
  8533. break;
  8534. case WM_MANAGES_CAPTION:
  8535. // caption managed in TTerminalManager::UpdateAppTitle()
  8536. M->Result = 1;
  8537. break;
  8538. case WM_WANTS_MOUSEWHEEL:
  8539. M->Result = 1;
  8540. break;
  8541. case CM_SHOWINGCHANGED:
  8542. CMShowingChanged(*M);
  8543. break;
  8544. case WM_CLOSE:
  8545. WMClose(*M);
  8546. break;
  8547. case WM_DPICHANGED:
  8548. WMDpiChanged(*M);
  8549. break;
  8550. case CM_DPICHANGED:
  8551. CMDpiChanged(*M);
  8552. break;
  8553. case WM_SETTINGCHANGE:
  8554. WMSettingChange(*M);
  8555. break;
  8556. case CM_DIALOGKEY:
  8557. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8558. break;
  8559. default:
  8560. TForm::Dispatch(Message);
  8561. break;
  8562. }
  8563. }
  8564. //---------------------------------------------------------------------------
  8565. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8566. {
  8567. // noop
  8568. }
  8569. //---------------------------------------------------------------------------
  8570. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8571. {
  8572. TForm::Dispatch(&Message);
  8573. FSessionColors->Clear();
  8574. AddFixedSessionImages();
  8575. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8576. UpdateImages();
  8577. }
  8578. //---------------------------------------------------------------------------
  8579. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8580. {
  8581. TForm::Dispatch(&Message);
  8582. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8583. UpdatePixelsPerInchMainWindowCounter();
  8584. }
  8585. //---------------------------------------------------------------------------
  8586. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8587. {
  8588. // Cannot close window while we are busy.
  8589. // We cannot test this in FormCloseQuery as that is called also from
  8590. // Close(), which is called by CloseApplicationAction. So we can be busy
  8591. // there already even, when it is legitimate to close the application.
  8592. // Possibly a better place to handle this would be WMSysCommand.
  8593. if (NonVisualDataModule->Busy)
  8594. {
  8595. Message.Result = 1;
  8596. }
  8597. else
  8598. {
  8599. TForm::Dispatch(&Message);
  8600. }
  8601. }
  8602. //---------------------------------------------------------------------------
  8603. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8604. {
  8605. TForm::Dispatch(&Message);
  8606. if (Showing && (Terminal == NULL))
  8607. {
  8608. // When we are starting minimized (i.e. from an installer),
  8609. // postpone showing Login dialog until we get restored.
  8610. // Otherwise the Login dialog (and Authentication window) show restored
  8611. // over invisible (minimized) main window.
  8612. if (WindowState == wsMinimized)
  8613. {
  8614. FNeedSession = true;
  8615. }
  8616. else
  8617. {
  8618. // This happens before application ever goes idle, so the toolbars would
  8619. // stay enabled (initial state) until the Login dialog is dismissed.
  8620. UpdateActions();
  8621. NonVisualDataModule->StartBusy();
  8622. try
  8623. {
  8624. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8625. // otherwise the dialog does not receive focus.
  8626. // With Commander interface the ProcessMessages is called already
  8627. // by TDriveView, but with Explorer interface, we need to call it explicily
  8628. Application->ProcessMessages();
  8629. // do not reload sessions, they have been loaded just now (optimization)
  8630. NeedSession(true);
  8631. }
  8632. __finally
  8633. {
  8634. NonVisualDataModule->EndBusy();
  8635. }
  8636. }
  8637. }
  8638. }
  8639. //---------------------------------------------------------------------------
  8640. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8641. {
  8642. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8643. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8644. }
  8645. //---------------------------------------------------------------------------
  8646. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8647. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8648. int & MaxHeight)
  8649. {
  8650. // workaround for bug in TWinControl.CalcConstraints
  8651. // Check for empty rect (restore from iconic state) is done there only after
  8652. // call to AdjustClientRect, which enlarges the rect (for forms).
  8653. TRect R = GetClientRect();
  8654. // when restoring from iconic state, place no restrictions
  8655. if (IsRectEmpty(R))
  8656. {
  8657. MinWidth = 0;
  8658. MinHeight = 0;
  8659. MaxWidth = 32000;
  8660. MaxHeight = 32000;
  8661. }
  8662. }
  8663. //---------------------------------------------------------------------------
  8664. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8665. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8666. {
  8667. // terminal can be already closed (e.g. dropped connection)
  8668. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8669. {
  8670. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8671. try
  8672. {
  8673. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8674. }
  8675. catch(...)
  8676. {
  8677. if (!Terminal->Active)
  8678. {
  8679. Close = true;
  8680. }
  8681. throw;
  8682. }
  8683. }
  8684. }
  8685. //---------------------------------------------------------------------------
  8686. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8687. {
  8688. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8689. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8690. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8691. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8692. {
  8693. OnGetSpaceAvailable = GetSpaceAvailable;
  8694. }
  8695. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8696. OnGetSpaceAvailable);
  8697. }
  8698. //---------------------------------------------------------------------------
  8699. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8700. {
  8701. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8702. Terminal->FillSessionDataForCode(Data.get());
  8703. return Data.release();
  8704. }
  8705. //---------------------------------------------------------------------------
  8706. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8707. {
  8708. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8709. DoGenerateUrlDialog(Data.get(), Paths);
  8710. }
  8711. //---------------------------------------------------------------------------
  8712. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8713. {
  8714. GenerateUrl(NULL);
  8715. }
  8716. //---------------------------------------------------------------------------
  8717. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  8718. {
  8719. std::unique_ptr<TStrings> Paths(new TStringList());
  8720. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  8721. GenerateUrl(Paths.get());
  8722. }
  8723. //---------------------------------------------------------------------------
  8724. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  8725. {
  8726. FSessionColor = value;
  8727. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  8728. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  8729. static_cast<TObject *>(GetComponent(fcColorMenu)));
  8730. DebugAssert(ColorItem != NULL);
  8731. ColorItem->Color = C;
  8732. NonVisualDataModule->ColorMenuItem->Color = C;
  8733. UpdateControls();
  8734. }
  8735. //---------------------------------------------------------------------------
  8736. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  8737. {
  8738. if (value != FSessionColor)
  8739. {
  8740. UpdateSessionColor(value);
  8741. // Is null when called from LastTerminalClosed
  8742. if (Terminal != NULL)
  8743. {
  8744. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  8745. }
  8746. }
  8747. }
  8748. //---------------------------------------------------------------------------
  8749. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  8750. {
  8751. bool Result = FNoteTimer->Enabled;
  8752. if (Result)
  8753. {
  8754. // cannot cancel note too early
  8755. bool NotEarly =
  8756. (Now() - FNoteShown >
  8757. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  8758. if (Force || NotEarly)
  8759. {
  8760. FNoteTimer->Enabled = false;
  8761. FNote = L"";
  8762. SAFE_DESTROY(FNoteData);
  8763. FOnNoteClick = NULL;
  8764. FNoteHints = FNotes->Text;
  8765. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8766. UpdateStatusBar();
  8767. }
  8768. }
  8769. return Result;
  8770. }
  8771. //---------------------------------------------------------------------------
  8772. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  8773. {
  8774. DebugAssert(FNoteTimer->Enabled);
  8775. CancelNote(true);
  8776. }
  8777. //---------------------------------------------------------------------------
  8778. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  8779. {
  8780. int P = Note.Pos(L"\n");
  8781. if (P > 0)
  8782. {
  8783. Note.SetLength(P - 1);
  8784. }
  8785. FNotes->Add(FORMAT(L"[%s] %s",
  8786. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  8787. while (FNotes->Count > 10)
  8788. {
  8789. FNotes->Delete(0);
  8790. }
  8791. if (UpdateNow)
  8792. {
  8793. FNoteHints = FNotes->Text;
  8794. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8795. UpdateStatusBar();
  8796. }
  8797. }
  8798. //---------------------------------------------------------------------------
  8799. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  8800. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  8801. {
  8802. int P = Note.Pos(L"\n");
  8803. if (P > 0)
  8804. {
  8805. Note.SetLength(P - 1);
  8806. }
  8807. FNoteHints = FNotes->Text;
  8808. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  8809. FNote = Note;
  8810. SAFE_DESTROY(FNoteData);
  8811. FNoteData = NoteData;
  8812. FOnNoteClick = OnNoteClick;
  8813. AddNote(Note, false);
  8814. UpdateStatusBar();
  8815. FNoteShown = Now();
  8816. FNoteTimer->Enabled = false;
  8817. if (Seconds == 0)
  8818. {
  8819. Seconds = WinConfiguration->NotificationsTimeout;
  8820. }
  8821. FNoteTimer->Interval = Seconds * MSecsPerSec;
  8822. FNoteTimer->Enabled = true;
  8823. }
  8824. //---------------------------------------------------------------------------
  8825. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  8826. {
  8827. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  8828. }
  8829. //---------------------------------------------------------------------------
  8830. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  8831. {
  8832. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  8833. {
  8834. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  8835. }
  8836. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  8837. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  8838. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  8839. 0, NULL, NULL);
  8840. }
  8841. //---------------------------------------------------------------------------
  8842. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  8843. {
  8844. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  8845. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  8846. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  8847. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  8848. }
  8849. //---------------------------------------------------------------------------
  8850. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  8851. {
  8852. WinConfiguration->FormatSizeBytes = Style;
  8853. }
  8854. //---------------------------------------------------------------------------
  8855. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  8856. {
  8857. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  8858. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  8859. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  8860. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  8861. }
  8862. //---------------------------------------------------------------------------
  8863. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  8864. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  8865. {
  8866. if (Panel->Index == 0)
  8867. {
  8868. if (FOnNoteClick != NULL)
  8869. {
  8870. // prevent the user data from being freed by possible call
  8871. // to CancelNote or PostNote during call to OnNoteClick
  8872. std::unique_ptr<TObject> NoteData(FNoteData);
  8873. TNotifyEvent OnNoteClick = FOnNoteClick;
  8874. FNoteData = NULL;
  8875. // need to cancel the note as we are going to delete its user data
  8876. CancelNote(true);
  8877. OnNoteClick(NoteData.get());
  8878. }
  8879. }
  8880. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  8881. {
  8882. FileSystemInfo();
  8883. }
  8884. }
  8885. //---------------------------------------------------------------------------
  8886. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  8887. {
  8888. // workaround:
  8889. // 1) for unknown reason, disabling window, while minimized,
  8890. // prevents it from restoring, even if it was enabled again meanwhile
  8891. // 2) when disabling the main window, while another has focus
  8892. // minimize is no longer possible
  8893. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  8894. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  8895. // Shouldn't we use IsApplicationMinimized() here?
  8896. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  8897. {
  8898. Enabled = false;
  8899. }
  8900. FLockLevel++;
  8901. }
  8902. //---------------------------------------------------------------------------
  8903. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  8904. {
  8905. DebugAssert(FLockLevel > 0);
  8906. FLockLevel--;
  8907. if (FLockLevel == 0)
  8908. {
  8909. DebugAssert(FLockSuspendLevel == 0);
  8910. Enabled = true;
  8911. }
  8912. }
  8913. //---------------------------------------------------------------------------
  8914. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  8915. {
  8916. // We need to make sure that window is enabled when the last modal window closes
  8917. // otherwise focus is not restored correctly.
  8918. // So we re-enable the window when modal window opens and
  8919. // disable it back after is closes
  8920. if (FLockLevel > 0)
  8921. {
  8922. // while we have nesting counter, we know that we never be called
  8923. // recursivelly as Application->OnModalBegin is called only
  8924. // for the top-level modal window
  8925. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8926. {
  8927. // won't be disabled when conditions in LockWindow() were not satisfied
  8928. FDisabledOnLockSuspend = !Enabled;
  8929. // When minimized to tray (or actually when set to SW_HIDE),
  8930. // setting Enabled makes the window focusable even when there's
  8931. // modal window over it
  8932. if (!FTrayIcon->Visible)
  8933. {
  8934. Enabled = true;
  8935. }
  8936. }
  8937. FLockSuspendLevel++;
  8938. }
  8939. }
  8940. //---------------------------------------------------------------------------
  8941. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  8942. {
  8943. if (FLockSuspendLevel > 0)
  8944. {
  8945. DebugAssert(FLockLevel > 0);
  8946. FLockSuspendLevel--;
  8947. // see comment in SuspendWindowLock
  8948. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  8949. {
  8950. // Note that window can be enabled here, when we were minized to tray when
  8951. // was SuspendWindowLock() called.
  8952. // We should possibly do the same check as in LockWindow(),
  8953. // if it is ever possible that the consitions change between
  8954. // SuspendWindowLock() and ResumeWindowLock()
  8955. Enabled = !FDisabledOnLockSuspend;
  8956. }
  8957. }
  8958. }
  8959. //---------------------------------------------------------------------------
  8960. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  8961. {
  8962. if (!TextOnly)
  8963. {
  8964. TTBXComboBoxItem * RemotePathComboBox =
  8965. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  8966. TStrings * Items = RemotePathComboBox->Strings;
  8967. Items->BeginUpdate();
  8968. try
  8969. {
  8970. Items->Clear();
  8971. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  8972. {
  8973. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8974. while (!IsUnixRootPath(APath))
  8975. {
  8976. int P = APath.LastDelimiter(L'/');
  8977. DebugAssert(P >= 0);
  8978. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  8979. APath.SetLength(P - 1);
  8980. }
  8981. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  8982. }
  8983. }
  8984. __finally
  8985. {
  8986. RemotePathComboBox->ItemIndex = Items->Count - 1;
  8987. // Setting ItemIndex to -1 does not reset its text
  8988. if (Items->Count == 0)
  8989. {
  8990. RemotePathComboBox->Text = L"";
  8991. }
  8992. Items->EndUpdate();
  8993. }
  8994. }
  8995. }
  8996. //---------------------------------------------------------------------------
  8997. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  8998. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  8999. int & ImageIndex)
  9000. {
  9001. if (AIndex < 0)
  9002. {
  9003. AIndex = Sender->ItemIndex;
  9004. }
  9005. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9006. }
  9007. //---------------------------------------------------------------------------
  9008. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9009. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9010. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9011. {
  9012. ARect.Left += (10 * AIndex);
  9013. }
  9014. //---------------------------------------------------------------------------
  9015. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9016. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9017. {
  9018. AWidth += (10 * AIndex);
  9019. }
  9020. //---------------------------------------------------------------------------
  9021. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  9022. TObject * Sender)
  9023. {
  9024. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9025. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9026. int Index = RemotePathComboBox->ItemIndex;
  9027. while (Index < RemotePathComboBox->Strings->Count - 1)
  9028. {
  9029. APath = UnixExtractFileDir(APath);
  9030. Index++;
  9031. }
  9032. // VanDyke style paths
  9033. if (APath.IsEmpty())
  9034. {
  9035. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9036. APath = ROOTDIRECTORY;
  9037. }
  9038. if (RemoteDirView->Path != APath)
  9039. {
  9040. RemoteDirView->Path = APath;
  9041. }
  9042. }
  9043. //---------------------------------------------------------------------------
  9044. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9045. {
  9046. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9047. DebugUsedParam(Sender);
  9048. UpdateRemotePathComboBox(true);
  9049. }
  9050. //---------------------------------------------------------------------------
  9051. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9052. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9053. {
  9054. ResetIncrementalSearch();
  9055. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9056. DebugAssert(DirView != NULL);
  9057. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9058. {
  9059. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9060. // OnEditing is called also from TCustomListView::CanEdit
  9061. if (Edit != NULL)
  9062. {
  9063. EditSelectBaseName(Edit);
  9064. }
  9065. }
  9066. }
  9067. //---------------------------------------------------------------------------
  9068. //---------------------------------------------------------------------------
  9069. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9070. {
  9071. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9072. Result->AutoDetectDnD = false;
  9073. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9074. Result->RenderDataOn = rdoEnterAndDropSync;
  9075. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9076. return Result;
  9077. }
  9078. //---------------------------------------------------------------------------
  9079. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9080. {
  9081. TForm::CreateWnd();
  9082. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9083. if (FSessionsDragDropFilesEx == NULL)
  9084. {
  9085. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9086. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9087. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9088. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9089. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9090. }
  9091. if (FQueueDragDropFilesEx == NULL)
  9092. {
  9093. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9094. // No need to set OnDragOver as we do not have any restrictions
  9095. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9096. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9097. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9098. }
  9099. }
  9100. //---------------------------------------------------------------------------
  9101. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9102. {
  9103. TForm::DestroyWnd();
  9104. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9105. FQueueDragDropFilesEx->DragDropControl = NULL;
  9106. }
  9107. //---------------------------------------------------------------------------
  9108. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9109. {
  9110. SideEnter(FCurrentSide);
  9111. FEverShown = true;
  9112. }
  9113. //---------------------------------------------------------------------------
  9114. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9115. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9116. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9117. {
  9118. if (!NonVisualDataModule->Busy)
  9119. {
  9120. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9121. Configuration->Usage->Inc(L"FileFinds");
  9122. LockWindow(true);
  9123. NonVisualDataModule->StartBusy();
  9124. WinConfiguration->LockedInterface = true;
  9125. try
  9126. {
  9127. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9128. }
  9129. __finally
  9130. {
  9131. WinConfiguration->LockedInterface = false;
  9132. NonVisualDataModule->EndBusy();
  9133. UnlockWindow();
  9134. }
  9135. }
  9136. }
  9137. //---------------------------------------------------------------------------
  9138. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9139. {
  9140. if (!NonVisualDataModule->Busy)
  9141. {
  9142. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9143. SetFocus();
  9144. RemoteDirView->Path = UnixExtractFilePath(Path);
  9145. UnicodeString FileName = UnixExtractFileName(Path);
  9146. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9147. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9148. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9149. if (Item == NULL)
  9150. {
  9151. ReloadDirectory(osRemote);
  9152. Item = RemoteDirView->FindFileItem(FileName);
  9153. }
  9154. if (Item != NULL)
  9155. {
  9156. RemoteDirView->ItemFocused = Item;
  9157. RemoteDirView->ItemFocused->MakeVisible(false);
  9158. RemoteDirView->SetFocus();
  9159. }
  9160. }
  9161. }
  9162. //---------------------------------------------------------------------------
  9163. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9164. {
  9165. bool Result = !NonVisualDataModule->Busy;
  9166. if (Result)
  9167. {
  9168. TTerminalManager::Instance()->ActiveTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9169. }
  9170. return Result;
  9171. }
  9172. //---------------------------------------------------------------------------
  9173. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9174. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9175. {
  9176. if (CanOperateOnFoundFiles(ATerminal))
  9177. {
  9178. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9179. FOnFileOperationFinished = OnFileOperationFinished;
  9180. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9181. }
  9182. }
  9183. //---------------------------------------------------------------------------
  9184. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9185. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9186. {
  9187. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9188. }
  9189. //---------------------------------------------------------------------------
  9190. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9191. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9192. {
  9193. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9194. }
  9195. //---------------------------------------------------------------------------
  9196. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9197. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9198. {
  9199. if (CanOperateOnFoundFiles(ATerminal))
  9200. {
  9201. for (int Index = 0; Index < FileList->Count; Index++)
  9202. {
  9203. UnicodeString FileName = FileList->Strings[Index];
  9204. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9205. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9206. OnFileOperationFinished(FileName, true);
  9207. }
  9208. }
  9209. }
  9210. //---------------------------------------------------------------------------
  9211. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9212. {
  9213. FFileFindTerminal = Terminal;
  9214. ShowFileFindDialog(
  9215. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9216. DoDownloadFoundFiles, DoEditFoundFiles);
  9217. }
  9218. //---------------------------------------------------------------------------
  9219. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9220. {
  9221. FTaskbarList = TaskbarList;
  9222. }
  9223. //---------------------------------------------------------------------------
  9224. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9225. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9226. {
  9227. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9228. if (Index >= 0)
  9229. {
  9230. if (Button == mbLeft)
  9231. {
  9232. // "Mouse down" is raised only after tab is switched.
  9233. // If switching tab (switching session) takes long enough for user
  9234. // to actually release the button, "mouse down" is still raised,
  9235. // but we do not get "mouse up" event, so dragging is not cancelled,
  9236. // prevent that by not beginning dragging in the first place.
  9237. if (IsKeyPressed(VK_LBUTTON))
  9238. {
  9239. // when user clicks the "+", we get mouse down only after the session
  9240. // is closed, when new session tab is already on X:Y, so dragging
  9241. // starts, prevent that
  9242. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  9243. {
  9244. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9245. if (Terminal != NULL)
  9246. {
  9247. SessionsPageControl->BeginDrag(false);
  9248. }
  9249. }
  9250. }
  9251. }
  9252. else if (Button == mbMiddle)
  9253. {
  9254. // ignore middle-click for "New session tab"
  9255. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9256. if (Terminal != NULL)
  9257. {
  9258. CloseSessionTab(Index);
  9259. }
  9260. }
  9261. }
  9262. }
  9263. //---------------------------------------------------------------------------
  9264. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9265. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9266. {
  9267. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9268. // do not allow dropping on the "+" tab
  9269. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9270. if ((TargetTerminal != NULL) &&
  9271. (SessionsPageControl->ActivePage->PageIndex != Index))
  9272. {
  9273. Configuration->Usage->Inc(L"SessionTabMoves");
  9274. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  9275. // but we want to actually prevent that to avoid flicker
  9276. SessionsPageControl->ActivePage->PageIndex = Index;
  9277. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  9278. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9279. }
  9280. }
  9281. //---------------------------------------------------------------------------
  9282. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9283. TObject * Sender, TObject * Source, int X, int Y,
  9284. TDragState /*State*/, bool & Accept)
  9285. {
  9286. Accept = (Sender == Source);
  9287. if (Accept)
  9288. {
  9289. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9290. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9291. // do not allow dragging to the "+" tab
  9292. Accept = (Terminal != NULL);
  9293. }
  9294. }
  9295. //---------------------------------------------------------------------------
  9296. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9297. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9298. {
  9299. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9300. if (Index < 0)
  9301. {
  9302. Effect = DROPEFFECT_NONE;
  9303. }
  9304. else
  9305. {
  9306. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9307. // do not allow dropping on the "+" tab
  9308. if (TargetTerminal == NULL)
  9309. {
  9310. Effect = DROPEFFECT_NONE;
  9311. }
  9312. else if ((TargetTerminal != Terminal) && (Effect == DROPEFFECT_MOVE))
  9313. {
  9314. Effect = DROPEFFECT_COPY;
  9315. }
  9316. }
  9317. }
  9318. //---------------------------------------------------------------------------
  9319. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9320. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9321. {
  9322. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9323. // do not allow dropping on the "+" tab
  9324. TManagedTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  9325. if (TargetTerminal != NULL)
  9326. {
  9327. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9328. if (!IsFileControl(DropSourceControl, osRemote))
  9329. {
  9330. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  9331. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9332. // Why don't we use Terminal->CurrentDirectory directly?
  9333. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9334. // do not force queue, drag drop
  9335. false, true);
  9336. }
  9337. }
  9338. }
  9339. //---------------------------------------------------------------------------
  9340. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9341. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9342. {
  9343. // Downloads are handled in RemoteFileControlDDEnd
  9344. if (!IsFileControl(DropSourceControl, osRemote))
  9345. {
  9346. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9347. Terminal->CurrentDirectory,
  9348. // force queue, drag drop
  9349. true, true);
  9350. }
  9351. }
  9352. //---------------------------------------------------------------------------
  9353. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9354. {
  9355. FShowing = false;
  9356. // Do not save empty workspace
  9357. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  9358. {
  9359. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9360. UnicodeString Name = WorkspaceName();
  9361. DoSaveWorkspace(
  9362. Name, DataList.get(),
  9363. !Configuration->DisablePasswordStoring &&
  9364. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9365. WinConfiguration->LastStoredSession = Name;
  9366. }
  9367. }
  9368. //---------------------------------------------------------------------------
  9369. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9370. {
  9371. TManagedTerminal * ManagedTerminal =
  9372. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9373. if (ManagedTerminal != NULL)
  9374. {
  9375. ManagedTerminal->DirectoryLoaded = Now();
  9376. }
  9377. }
  9378. //---------------------------------------------------------------------------
  9379. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9380. TListItem * /*Item*/, bool /*Selected*/)
  9381. {
  9382. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9383. switch (DirView->LastSelectMethod)
  9384. {
  9385. case smKeyboard:
  9386. Configuration->Usage->Inc(L"KeyboardSelections");
  9387. break;
  9388. case smMouse:
  9389. Configuration->Usage->Inc(L"MouseSelections");
  9390. break;
  9391. }
  9392. }
  9393. //---------------------------------------------------------------------------
  9394. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9395. {
  9396. if (Color != 0)
  9397. {
  9398. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9399. }
  9400. else
  9401. {
  9402. return FSessionTabImageIndex;
  9403. }
  9404. }
  9405. //---------------------------------------------------------------------------
  9406. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9407. {
  9408. TPngImageCollectionItem * Item =
  9409. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9410. FSessionColors->AddPng(Item->PngImage);
  9411. return FSessionColors->Count - 1;
  9412. }
  9413. //---------------------------------------------------------------------------
  9414. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9415. {
  9416. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9417. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  9418. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9419. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9420. }
  9421. //---------------------------------------------------------------------------
  9422. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9423. {
  9424. for (int Index = 0; Index < Control->ControlCount; Index++)
  9425. {
  9426. TControl * AControl = Control->Controls[Index];
  9427. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9428. if (WinControl != NULL)
  9429. {
  9430. CollectItemsWithTextDisplayMode(WinControl);
  9431. }
  9432. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9433. if (Toolbar != NULL)
  9434. {
  9435. // we care for top-level items only
  9436. TTBCustomItem * Items = Toolbar->Items;
  9437. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9438. {
  9439. TTBCustomItem * Item = Items->Items[ItemIndex];
  9440. if (((Item->DisplayMode == nbdmImageAndText) ||
  9441. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9442. EligibleForImageDisplayMode(Item))
  9443. {
  9444. FItemsWithTextDisplayMode.insert(Item);
  9445. }
  9446. }
  9447. }
  9448. }
  9449. }
  9450. //---------------------------------------------------------------------------
  9451. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9452. {
  9453. return true;
  9454. }
  9455. //---------------------------------------------------------------------------
  9456. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9457. {
  9458. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9459. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9460. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9461. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9462. bool Result = true;
  9463. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9464. {
  9465. TTBCustomItem * Item = *i;
  9466. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9467. if (Label != NULL)
  9468. {
  9469. // optimization
  9470. if (Label->Visible == SelectiveToolbarText)
  9471. {
  9472. Result = false;
  9473. }
  9474. else
  9475. {
  9476. Label->Visible = SelectiveToolbarText;
  9477. }
  9478. }
  9479. else
  9480. {
  9481. // optimization
  9482. if (Item->DisplayMode == DisplayMode)
  9483. {
  9484. Result = false;
  9485. }
  9486. else
  9487. {
  9488. Item->DisplayMode = DisplayMode;
  9489. }
  9490. }
  9491. ++i;
  9492. }
  9493. if (Result)
  9494. {
  9495. UpdateNewSessionTab();
  9496. }
  9497. return Result;
  9498. }
  9499. //---------------------------------------------------------------------------
  9500. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9501. {
  9502. DebugFail();
  9503. }
  9504. //---------------------------------------------------------------------------
  9505. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9506. {
  9507. // Among other, a lock level is non zero, while directory is being loaded,
  9508. // even when it happens as a result of dirview navigation,
  9509. // i.e. when TNonVisualDataModule is NOT FBusy.
  9510. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9511. // Among other this prevents a panel auto update to occur while
  9512. // directory is changing.
  9513. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9514. }
  9515. //---------------------------------------------------------------------------
  9516. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  9517. {
  9518. // While the window is disabled, we still seem to process menu shortcuts at least,
  9519. // so stop it at least here.
  9520. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9521. return
  9522. (Allowed == aaUpdate) ||
  9523. !NonVisualDataModule->Busy;
  9524. }
  9525. //---------------------------------------------------------------------------
  9526. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9527. {
  9528. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9529. }
  9530. //---------------------------------------------------------------------------
  9531. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9532. {
  9533. // This is somewhat redundant to LockWindow() call from
  9534. // TTerminalManager::TerminalReadDirectoryProgress.
  9535. // But disabling window is known not to block keyboard shorcuts
  9536. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9537. if (Busy > 0)
  9538. {
  9539. if (NonVisualDataModule->Busy)
  9540. {
  9541. State = false;
  9542. }
  9543. else
  9544. {
  9545. NonVisualDataModule->StartBusy();
  9546. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9547. LockWindow();
  9548. }
  9549. }
  9550. else if (Busy < 0)
  9551. {
  9552. UnlockWindow();
  9553. NonVisualDataModule->EndBusy();
  9554. }
  9555. else
  9556. {
  9557. State = NonVisualDataModule->Busy;
  9558. }
  9559. }
  9560. //---------------------------------------------------------------------------
  9561. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9562. {
  9563. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9564. // no context menu for "New session tab"
  9565. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  9566. {
  9567. SessionsPageControl->ActivePageIndex = Index;
  9568. if (DebugAlwaysTrue(SessionTabSwitched()))
  9569. {
  9570. // copied from TControl.WMContextMenu
  9571. SendCancelMode(SessionsPageControl);
  9572. // explicit popup instead of using PopupMenu property
  9573. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9574. // while connecting yet not-connected session and hence
  9575. // allowing an access to commands over not-completelly connected session
  9576. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9577. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  9578. PopupMenu->PopupComponent = SessionsPageControl;
  9579. PopupMenu->Popup(Point.x, Point.y);
  9580. }
  9581. }
  9582. Handled = true;
  9583. }
  9584. //---------------------------------------------------------------------------
  9585. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9586. {
  9587. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9588. }
  9589. //---------------------------------------------------------------------------
  9590. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9591. {
  9592. Configuration->Usage->Inc(L"PasswordChanges");
  9593. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9594. ChangePasswordData->DisableAuthentationsExceptPassword();
  9595. ChangePasswordData->ChangePassword = true;
  9596. std::unique_ptr<TTerminal> ChangePasswordSession(
  9597. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9598. ChangePasswordSession->AutoReadDirectory = false;
  9599. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9600. {
  9601. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9602. }
  9603. else
  9604. {
  9605. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9606. }
  9607. }
  9608. //---------------------------------------------------------------------------
  9609. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9610. {
  9611. // No nice way to assert SSH2
  9612. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9613. }
  9614. //---------------------------------------------------------------------------
  9615. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9616. {
  9617. TOperationVisualizer OperationVisualizer;
  9618. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9619. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9620. }
  9621. //---------------------------------------------------------------------------
  9622. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9623. {
  9624. TForm::ChangeScale(M, D);
  9625. int APixelsPerInch = GetControlPixelsPerInch(this);
  9626. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9627. try
  9628. {
  9629. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9630. }
  9631. __finally
  9632. {
  9633. GUIConfiguration->ChangeResourceModule(ResourceModule);
  9634. }
  9635. }
  9636. //---------------------------------------------------------------------------
  9637. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  9638. {
  9639. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  9640. }
  9641. //---------------------------------------------------------------------
  9642. class TPublicControl : public TControl
  9643. {
  9644. friend class TCustomScpExplorerForm;
  9645. };
  9646. //---------------------------------------------------------------------------
  9647. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  9648. {
  9649. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  9650. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  9651. }
  9652. //---------------------------------------------------------------------------
  9653. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  9654. {
  9655. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  9656. OpenBookmark(Side, Bookmark);
  9657. }
  9658. //---------------------------------------------------------------------------
  9659. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  9660. {
  9661. DoBookmarkClick(osLocal, Sender);
  9662. }
  9663. //---------------------------------------------------------------------------
  9664. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  9665. {
  9666. DoBookmarkClick(osRemote, Sender);
  9667. }
  9668. //---------------------------------------------------------------------------
  9669. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  9670. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  9671. {
  9672. // TODO
  9673. if (BookmarkList != NULL)
  9674. {
  9675. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  9676. if (!WinConfiguration->UseLocationProfiles)
  9677. {
  9678. std::unique_ptr<TStringList> Directories(new TStringList());
  9679. Directories->CaseSensitive = (Side == osRemote);
  9680. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9681. {
  9682. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9683. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  9684. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  9685. {
  9686. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9687. Item->Caption = EscapeHotkey(Directory);
  9688. Item->ShortCut = Bookmark->ShortCut;
  9689. Item->OnClick = OnBookmarkClick;
  9690. Item->Tag = reinterpret_cast<int>(Bookmark);
  9691. Directories->Add(Directory);
  9692. Menu->Add(Item.release());
  9693. }
  9694. }
  9695. }
  9696. else
  9697. {
  9698. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  9699. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9700. {
  9701. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9702. if (!Bookmark->Node.IsEmpty())
  9703. {
  9704. Folders->Add(Bookmark->Node);
  9705. }
  9706. }
  9707. for (int Index = 0; Index < Folders->Count; Index++)
  9708. {
  9709. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  9710. Item->Caption = Folders->Strings[Index];
  9711. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  9712. Folders->Objects[Index] = Item.get();
  9713. Menu->Add(Item.release());
  9714. }
  9715. for (int Index = 0; Index < BookmarkList->Count; Index++)
  9716. {
  9717. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  9718. TTBCustomItem * Parent;
  9719. if (!Bookmark->Node.IsEmpty())
  9720. {
  9721. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  9722. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  9723. }
  9724. else
  9725. {
  9726. Parent = Menu;
  9727. }
  9728. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  9729. Item->Caption = Bookmark->Name;
  9730. Item->ShortCut = Bookmark->ShortCut;
  9731. Item->OnClick = OnBookmarkClick;
  9732. Item->Tag = reinterpret_cast<int>(Bookmark);
  9733. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  9734. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  9735. {
  9736. // No hint for location profiles that are actually mere "bookmarks"
  9737. }
  9738. else
  9739. {
  9740. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  9741. UnicodeString LongHint;
  9742. if (!Bookmark->Local.IsEmpty())
  9743. {
  9744. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  9745. }
  9746. if (!Bookmark->Remote.IsEmpty())
  9747. {
  9748. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  9749. }
  9750. AddToList(Hint, LongHint, L"|");
  9751. Item->Hint = Hint;
  9752. }
  9753. Parent->Add(Item.release());
  9754. }
  9755. }
  9756. AddMenuSeparator(Menu);
  9757. }
  9758. }
  9759. //---------------------------------------------------------------------------
  9760. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  9761. {
  9762. Menu->Clear();
  9763. std::unique_ptr<TTBCustomItem> Item;
  9764. Item.reset(new TTBXItem(Owner));
  9765. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  9766. Item->Options = Item->Options << tboDefault;
  9767. Menu->Add(Item.release());
  9768. AddMenuSeparator(Menu);
  9769. if (Terminal != NULL)
  9770. {
  9771. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  9772. }
  9773. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  9774. Item.reset(new TTBXItem(Owner));
  9775. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  9776. Menu->Add(Item.release());
  9777. }
  9778. //---------------------------------------------------------------------------
  9779. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  9780. {
  9781. bool Result = true;
  9782. bool Remote = !IsSideLocalBrowser(Side);
  9783. try
  9784. {
  9785. if (Remote)
  9786. {
  9787. Terminal->ExceptionOnFail = true;
  9788. }
  9789. try
  9790. {
  9791. DirView(Side)->Path = Path;
  9792. }
  9793. __finally
  9794. {
  9795. if (Remote)
  9796. {
  9797. Terminal->ExceptionOnFail = false;
  9798. }
  9799. }
  9800. }
  9801. catch (Exception & E)
  9802. {
  9803. if (!Remote || Terminal->Active)
  9804. {
  9805. ShowExtendedExceptionEx(Terminal, &E);
  9806. Result = false;
  9807. }
  9808. else
  9809. {
  9810. throw;
  9811. }
  9812. }
  9813. return Result;
  9814. }
  9815. //---------------------------------------------------------------------------
  9816. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  9817. {
  9818. // Make sure there some feedback even when loading tiny local folders
  9819. TInstantOperationVisualizer Visualizer;
  9820. DirView(Side)->ReloadDirectory();
  9821. }
  9822. //---------------------------------------------------------------------------
  9823. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  9824. {
  9825. if (Index == SessionsPageControl->TabIndex)
  9826. {
  9827. CloseSession();
  9828. }
  9829. else
  9830. {
  9831. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  9832. TTerminal * Terminal = GetSessionTabTerminal(TabSheet);
  9833. TTerminalManager * Manager = TTerminalManager::Instance();
  9834. if (!Terminal->Active)
  9835. {
  9836. Manager->FreeTerminal(Terminal);
  9837. }
  9838. else
  9839. {
  9840. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  9841. if (CanCloseQueue(Queue))
  9842. {
  9843. Manager->FreeTerminal(Terminal);
  9844. }
  9845. }
  9846. }
  9847. }
  9848. //---------------------------------------------------------------------------
  9849. void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPageControl * /*Sender*/, int Index)
  9850. {
  9851. CloseSessionTab(Index);
  9852. }
  9853. //---------------------------------------------------------------------------
  9854. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  9855. {
  9856. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  9857. {
  9858. TInstantOperationVisualizer Visualizer;
  9859. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  9860. // before we create a new data object
  9861. ClipboardClear();
  9862. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  9863. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  9864. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  9865. // Intermediate variable to WORKAROUND a crash in compiler
  9866. TObjectList * ClipboardFakeMonitors =
  9867. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  9868. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  9869. if (FClipboardDragDropFilesEx.get() == NULL)
  9870. {
  9871. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  9872. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  9873. }
  9874. FClipboardDragDropFilesEx->FileList->Clear();
  9875. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  9876. FClipboardDragDropFilesEx->CopyToClipboard();
  9877. FClipboardTerminal = FTerminal;
  9878. // Need full paths, as cwd can be different once files are pasted
  9879. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  9880. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  9881. {
  9882. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  9883. }
  9884. }
  9885. }
  9886. //---------------------------------------------------------------------------
  9887. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  9888. {
  9889. if (OpenClipboard(0))
  9890. {
  9891. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  9892. CloseClipboard();
  9893. }
  9894. }
  9895. //---------------------------------------------------------------------------
  9896. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  9897. {
  9898. return !FClipboardFakeDirectory.IsEmpty();
  9899. }
  9900. //---------------------------------------------------------------------------
  9901. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  9902. {
  9903. RemoveDir(ApiPath(FClipboardFakeDirectory));
  9904. FClipboardFakeDirectory = UnicodeString();
  9905. FClipboardTerminal = NULL;
  9906. // Also called in Idle()
  9907. FClipboardFakeMonitors.reset(NULL);
  9908. }
  9909. //---------------------------------------------------------------------------
  9910. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  9911. {
  9912. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  9913. {
  9914. ClipboardStop();
  9915. }
  9916. }
  9917. //---------------------------------------------------------------------------
  9918. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  9919. {
  9920. TTerminalManager * Manager = TTerminalManager::Instance();
  9921. Manager->ActiveTerminal = FClipboardTerminal;
  9922. TTransferOperationParam Params;
  9923. Params.TargetDirectory = TargetDirectory;
  9924. Params.DragDrop = DragDrop;
  9925. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  9926. }
  9927. //---------------------------------------------------------------------------
  9928. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  9929. {
  9930. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  9931. // (as it pumps a Windows message queue while being shutted down)
  9932. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  9933. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  9934. {
  9935. // Can fail as it can be e.g. locked by AV, so we retry that later
  9936. bool Removed = RemoveDir(ApiPath(FileName));
  9937. try
  9938. {
  9939. if (!NonVisualDataModule->Busy)
  9940. {
  9941. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  9942. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  9943. }
  9944. }
  9945. __finally
  9946. {
  9947. if (!Removed)
  9948. {
  9949. RemoveDir(ApiPath(FileName));
  9950. }
  9951. }
  9952. }
  9953. }
  9954. //---------------------------------------------------------------------------
  9955. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  9956. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  9957. {
  9958. TFileMasks::TParams MaskParams;
  9959. MaskParams.Size = Size;
  9960. MaskParams.Modification = Modification;
  9961. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  9962. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  9963. {
  9964. bool ImplicitMatch;
  9965. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  9966. !ImplicitMatch)
  9967. {
  9968. Color = Iter->Color;
  9969. break;
  9970. }
  9971. }
  9972. }
  9973. //---------------------------------------------------------------------------
  9974. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  9975. {
  9976. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9977. if (!DirView->IsEditing())
  9978. {
  9979. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  9980. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  9981. // while searching
  9982. if (Key == VK_BACK)
  9983. {
  9984. if (!FIncrementalSearch.IsEmpty())
  9985. {
  9986. if (FIncrementalSearch.Length() == 1)
  9987. {
  9988. ResetIncrementalSearch();
  9989. }
  9990. else
  9991. {
  9992. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  9993. IncrementalSearch(NewText, false, false);
  9994. }
  9995. Key = 0;
  9996. }
  9997. }
  9998. }
  9999. }
  10000. //---------------------------------------------------------------------------
  10001. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10002. {
  10003. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10004. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10005. {
  10006. // Filter control sequences.
  10007. // When not searching yet, prefer use of the space for toggling file selection
  10008. // (so we cannot incrementally search for a string starting with a space).
  10009. if ((Key > VK_SPACE) ||
  10010. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10011. {
  10012. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10013. Key = 0;
  10014. }
  10015. }
  10016. }
  10017. //---------------------------------------------------------------------------
  10018. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10019. {
  10020. if (!FIncrementalSearch.IsEmpty())
  10021. {
  10022. FIncrementalSearch = L"";
  10023. DirView(osCurrent)->UpdateStatusBar();
  10024. }
  10025. }
  10026. //---------------------------------------------------------------------------
  10027. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10028. {
  10029. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10030. if (Item == NULL)
  10031. {
  10032. MessageBeep(MB_ICONHAND);
  10033. }
  10034. else
  10035. {
  10036. TCustomDirView * ADirView = DirView(osCurrent);
  10037. {
  10038. TAutoNestingCounter Guard(FIncrementalSearching);
  10039. ADirView->FocusItem(Item);
  10040. if (ADirView->NortonLike == nlOff)
  10041. {
  10042. if ((ADirView->Selected != Item) ||
  10043. (ADirView->SelCount > 1))
  10044. {
  10045. ADirView->ClearSelection();
  10046. ADirView->Selected = Item;
  10047. }
  10048. }
  10049. }
  10050. FIncrementalSearch = Text;
  10051. Item->MakeVisible(false);
  10052. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10053. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10054. ADirView->UpdateStatusBar();
  10055. }
  10056. }
  10057. //---------------------------------------------------------------------------
  10058. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10059. {
  10060. int Index = Item->Index;
  10061. if (!Reverse)
  10062. {
  10063. Index++;
  10064. if (Index >= Item->Owner->Count)
  10065. {
  10066. Index = 0;
  10067. }
  10068. }
  10069. else
  10070. {
  10071. Index--;
  10072. if (Index < 0)
  10073. {
  10074. Index = Item->Owner->Count - 1;
  10075. }
  10076. }
  10077. return Item->Owner->Item[Index];
  10078. }
  10079. //---------------------------------------------------------------------------
  10080. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10081. {
  10082. TCustomDirView * ADirView = DirView(osCurrent);
  10083. if (ADirView->Items->Count == 0)
  10084. {
  10085. return NULL;
  10086. }
  10087. else
  10088. {
  10089. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10090. TListItem * Item = CurrentItem;
  10091. if (SkipCurrent)
  10092. {
  10093. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10094. }
  10095. while (true)
  10096. {
  10097. bool Matches = false;
  10098. switch (WinConfiguration->PanelSearch)
  10099. {
  10100. case isNameStartOnly:
  10101. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10102. break;
  10103. case isName:
  10104. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10105. break;
  10106. case isAll:
  10107. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10108. int Index = 0;
  10109. while ((Index < ColCount) && !Matches)
  10110. {
  10111. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10112. if (Visible)
  10113. {
  10114. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10115. }
  10116. Index++;
  10117. }
  10118. break;
  10119. }
  10120. if (Matches)
  10121. {
  10122. return Item;
  10123. }
  10124. Item = GetNextFile(Item, Reverse);
  10125. if (Item == CurrentItem)
  10126. {
  10127. return NULL;
  10128. }
  10129. }
  10130. }
  10131. }
  10132. //---------------------------------------------------------------------------
  10133. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10134. {
  10135. ResetIncrementalSearch();
  10136. }
  10137. //---------------------------------------------------------------------------
  10138. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10139. {
  10140. if (Message.CharCode == VK_TAB)
  10141. {
  10142. if (!FIncrementalSearch.IsEmpty())
  10143. {
  10144. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10145. bool Reverse = Shift.Contains(ssShift);
  10146. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10147. Message.Result = 1;
  10148. return;
  10149. }
  10150. }
  10151. else if (Message.CharCode == VK_ESCAPE)
  10152. {
  10153. if (!FIncrementalSearch.IsEmpty())
  10154. {
  10155. ResetIncrementalSearch();
  10156. Message.Result = 1;
  10157. return;
  10158. }
  10159. }
  10160. TForm::Dispatch(&Message);
  10161. }
  10162. //---------------------------------------------------------------------------
  10163. void __fastcall TCustomScpExplorerForm::Deactivate()
  10164. {
  10165. TForm::Deactivate();
  10166. // E.g. when switching to an internal editor window
  10167. ResetIncrementalSearch();
  10168. }
  10169. //---------------------------------------------------------------------------
  10170. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10171. {
  10172. // When switching to another application
  10173. ResetIncrementalSearch();
  10174. }
  10175. //---------------------------------------------------------------------------
  10176. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10177. {
  10178. ResetIncrementalSearch();
  10179. }
  10180. //---------------------------------------------------------------------------
  10181. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10182. {
  10183. if (FIncrementalSearching <= 0)
  10184. {
  10185. ResetIncrementalSearch();
  10186. }
  10187. }
  10188. //---------------------------------------------------------------------------
  10189. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10190. {
  10191. CountClicksForWindowPrint(this);
  10192. }
  10193. //---------------------------------------------------------------------------
  10194. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10195. {
  10196. CenterReconnectToolbar();
  10197. }
  10198. //---------------------------------------------------------------------------
  10199. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10200. {
  10201. if (RemoteDirView->ItemFocused != NULL)
  10202. {
  10203. RemoteDirView->ItemFocused->Selected = true;
  10204. }
  10205. }
  10206. //---------------------------------------------------------------------------
  10207. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10208. {
  10209. if (!FQueueStatusUpdating)
  10210. {
  10211. bool Refresh;
  10212. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10213. {
  10214. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10215. }
  10216. else
  10217. {
  10218. if (FQueueFileList->GetCount() > 0)
  10219. {
  10220. FQueueFileList->Clear();
  10221. Refresh = true;
  10222. }
  10223. }
  10224. int Count = FQueueFileList->GetCount();
  10225. if (QueueFileList->Items->Count != Count)
  10226. {
  10227. DebugAssert(Refresh);
  10228. QueueFileList->Items->Count = Count;
  10229. }
  10230. if (Refresh)
  10231. {
  10232. QueueFileList->Invalidate();
  10233. }
  10234. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10235. }
  10236. }
  10237. //---------------------------------------------------------------------------
  10238. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10239. {
  10240. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10241. }
  10242. //---------------------------------------------------------------------------
  10243. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10244. {
  10245. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10246. // See TSynchronizeChecklistDialog::UpdateTimer
  10247. if (QueueFileList->Items->Count > 0)
  10248. {
  10249. QueueFileList->Items->Item[0]->MakeVisible(false);
  10250. }
  10251. UpdateQueueFileList();
  10252. }
  10253. //---------------------------------------------------------------------------
  10254. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10255. {
  10256. Active = QueueView3->Focused() || QueueFileList->Focused();
  10257. }
  10258. //---------------------------------------------------------------------------
  10259. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10260. {
  10261. QueueLabelUpdateStatus();
  10262. }
  10263. //---------------------------------------------------------------------------
  10264. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10265. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10266. {
  10267. int State = FQueueFileList->GetState(Item->Index);
  10268. if (State == qfsProcessed)
  10269. {
  10270. Sender->Canvas->Font->Color = clGrayText;
  10271. }
  10272. }
  10273. //---------------------------------------------------------------------------
  10274. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10275. {
  10276. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10277. QueueFileList->Column[0]->Width =
  10278. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10279. }
  10280. //---------------------------------------------------------------------------
  10281. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10282. {
  10283. QueueFileListColumnAutoSize();
  10284. }
  10285. //---------------------------------------------------------------------------
  10286. void __fastcall TCustomScpExplorerForm::CloseApp()
  10287. {
  10288. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10289. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10290. // So we clear the flag here.
  10291. DebugAssert(NonVisualDataModule->Busy);
  10292. NonVisualDataModule->EndBusy();
  10293. try
  10294. {
  10295. Close();
  10296. }
  10297. __finally
  10298. {
  10299. NonVisualDataModule->StartBusy();
  10300. }
  10301. }
  10302. //---------------------------------------------------------------------------
  10303. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10304. {
  10305. return (Terminal != NULL) && Terminal->Active;
  10306. }
  10307. //---------------------------------------------------------------------------
  10308. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10309. {
  10310. return IsActiveTerminal(Terminal);
  10311. }