CustomScpExplorer.cpp 382 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537
  1. //---------------------------------------------------------------------------
  2. #define NO_WIN32_LEAN_AND_MEAN
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <Common.h>
  6. #include "CustomScpExplorer.h"
  7. #include <algorithm>
  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 = 3;
  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. TAutoBatch::TAutoBatch(TCustomScpExplorerForm * Form) :
  101. FForm(Form)
  102. {
  103. FForm->BatchStart(FBatchStorage);
  104. }
  105. //---------------------------------------------------------------------------
  106. TAutoBatch::~TAutoBatch()
  107. {
  108. FForm->BatchEnd(FBatchStorage);
  109. }
  110. //---------------------------------------------------------------------------
  111. struct TTransferOperationParam
  112. {
  113. TTransferOperationParam();
  114. UnicodeString TargetDirectory;
  115. bool Temp;
  116. bool DragDrop;
  117. int Options;
  118. TAutoSwitch Queue;
  119. };
  120. //---------------------------------------------------------------------------
  121. TTransferOperationParam::TTransferOperationParam()
  122. {
  123. Temp = false;
  124. DragDrop = false;
  125. Options = 0;
  126. Queue = asAuto;
  127. }
  128. //---------------------------------------------------------------------------
  129. class TTransferPresetNoteData : public TObject
  130. {
  131. public:
  132. UnicodeString Message;
  133. };
  134. //---------------------------------------------------------------------------
  135. class TTerminalNoteData : public TObject
  136. {
  137. public:
  138. TManagedTerminal * Terminal;
  139. };
  140. //---------------------------------------------------------------------------
  141. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  142. FFormRestored(false),
  143. TForm(Owner)
  144. {
  145. FInvalid = false;
  146. FCurrentSide = osRemote;
  147. FEverShown = false;
  148. FDocks = new TList();
  149. InitControls();
  150. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  151. // So that UpdateCustomCommandsToolbar called from RestoreParams works
  152. NonVisualDataModule->ScpExplorer = this;
  153. RestoreParams();
  154. ConfigurationChanged();
  155. RemoteDirView->Invalidate();
  156. FAutoOperation = false;
  157. FOnFileOperationFinished = NULL;
  158. FPrimaryOperation = foNone;
  159. FForceExecution = false;
  160. FIgnoreNextDialogChar = 0;
  161. FErrorList = NULL;
  162. FSynchronizeProgressForm = NULL;
  163. FProgressForm = NULL;
  164. FRefreshLocalDirectory = false;
  165. FRefreshRemoteDirectory = false;
  166. FDDExtMapFile = NULL;
  167. // CreateMutexW keeps failing with ERROR_NOACCESS
  168. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  169. DebugAssert(FDDExtMutex != NULL);
  170. FDDTargetControl = NULL;
  171. FDelayedDeletionTimer = NULL;
  172. FDelayedDeletionList = new TStringList();
  173. FDDFileList = NULL;
  174. FPendingTempSpaceWarn = false;
  175. FCapturedLog = NULL;
  176. FDragDropOperation = false;
  177. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  178. FAllowTransferPresetAutoSelect = true;
  179. FSessionChanging = false;
  180. FCopyParamDefault = L"";
  181. FSynchronizeController = NULL;
  182. FPendingQueueActionItem = NULL;
  183. FLockLevel = 0;
  184. FLockSuspendLevel = 0;
  185. FDisabledOnLockSuspend = false;
  186. FAlternativeDelete = false;
  187. FTrayIcon = new ::TTrayIcon(0);
  188. FTrayIcon->OnClick = TrayIconClick;
  189. FMaxQueueLength = 0;
  190. FLastContextPopupScreenPoint = TPoint(-1, -1);
  191. FTransferResumeList = NULL;
  192. FDeletedFiles = NULL;
  193. FMoveToQueue = false;
  194. StandaloneOperation = false;
  195. FOnFeedSynchronizeError = NULL;
  196. FOnSynchronizeAbort = NULL;
  197. FSynchronizeTerminal = NULL;
  198. FNeedSession = false;
  199. FDoNotIdleCurrentTerminal = 0;
  200. FIncrementalSearching = 0;
  201. FIncrementalSearchHaveNext = false;
  202. FQueueFileList.reset(new TQueueFileList());
  203. FProgressSide = osCurrent;
  204. FCalculateSizeOperation = NULL;
  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))), true);
  238. SetSubmenu(NonVisualDataModule->ColorMenuItem, true);
  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. ManagedSession = 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 SessionListChanged => ... => 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->Sessions[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. try
  455. {
  456. UnicodeString DownloadFile; // unused
  457. int Flags = GetCommandLineParseUrlFlags(&Params);
  458. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this, Flags);
  459. }
  460. catch (EAbort &)
  461. {
  462. // Happens when opening session in PuTTY and in other situations,
  463. // in which we do not want to fail WM_COPYDATA, as that would cause master instance
  464. // to process the command-line on its own (or to pass it to yet another instance)
  465. }
  466. if (DataList->Count > 0)
  467. {
  468. TTerminalManager * Manager = TTerminalManager::Instance();
  469. Manager->ActiveSession = Manager->NewSessions(DataList.get());
  470. }
  471. }
  472. __finally
  473. {
  474. NonVisualDataModule->EndBusy();
  475. }
  476. }
  477. return Result;
  478. }
  479. //---------------------------------------------------------------------------
  480. TManagedTerminal * TCustomScpExplorerForm::GetTerminal()
  481. {
  482. TManagedTerminal * Result;
  483. if ((FManagedSession != NULL) && !FManagedSession->LocalBrowser)
  484. {
  485. Result = FManagedSession;
  486. }
  487. else
  488. {
  489. Result = NULL;
  490. }
  491. return Result;
  492. }
  493. //---------------------------------------------------------------------------
  494. void __fastcall TCustomScpExplorerForm::SetManagedSession(TManagedTerminal * value)
  495. {
  496. if (FManagedSession != value)
  497. {
  498. SessionChanging();
  499. DoSetManagedSession(value, false);
  500. }
  501. }
  502. //---------------------------------------------------------------------------
  503. void __fastcall TCustomScpExplorerForm::DoSetManagedSession(TManagedTerminal * value, bool Replace)
  504. {
  505. DebugAssert(!Replace || ((value != NULL) && !value->LocalBrowser));
  506. FManagedSession = value;
  507. {
  508. TValueRestorer<bool> AllowTransferPresetAutoSelectRestorer(FAllowTransferPresetAutoSelect);
  509. FAllowTransferPresetAutoSelect = false;
  510. TAutoFlag SessionChangingFlag(FSessionChanging);
  511. SessionChanged(Replace);
  512. }
  513. if (Terminal != NULL)
  514. {
  515. TransferPresetAutoSelect();
  516. }
  517. // Update app and tab titles, prevented above by FSessionChanging.
  518. UpdateControls();
  519. }
  520. //---------------------------------------------------------------------------
  521. void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TManagedTerminal * value)
  522. {
  523. DoSetManagedSession(value, true);
  524. }
  525. //---------------------------------------------------------------------------
  526. void __fastcall TCustomScpExplorerForm::SessionChanging()
  527. {
  528. if (ManagedSession != NULL)
  529. {
  530. UpdateSession(ManagedSession);
  531. }
  532. }
  533. //---------------------------------------------------------------------------
  534. void __fastcall TCustomScpExplorerForm::SessionChanged(bool Replaced)
  535. {
  536. if (Terminal != NULL)
  537. {
  538. UpdateSessionColor((TColor)Terminal->StateData->Color);
  539. }
  540. if (!TTerminalManager::Instance()->Updating)
  541. {
  542. SessionListChanged();
  543. }
  544. if (Terminal != NULL)
  545. {
  546. TObject * State = NULL;
  547. if (WinConfiguration->PreservePanelState)
  548. {
  549. State = Terminal->RemoteExplorerState;
  550. DirView(osRemote)->AnnounceState(State);
  551. }
  552. try
  553. {
  554. if (Replaced)
  555. {
  556. RemoteDirView->ReplaceTerminal(Terminal);
  557. }
  558. else
  559. {
  560. RemoteDirView->Terminal = Terminal;
  561. }
  562. if (Terminal->Active)
  563. {
  564. Terminal->RefreshDirectory();
  565. }
  566. if (State != NULL)
  567. {
  568. DirView(osRemote)->RestoreState(State);
  569. }
  570. }
  571. __finally
  572. {
  573. DirView(osRemote)->AnnounceState(NULL);
  574. }
  575. }
  576. else
  577. {
  578. RemoteDirView->Terminal = NULL;
  579. }
  580. InitStatusBar();
  581. UpdateTransferList();
  582. // Update panels Enable state before refreshing the labels
  583. UpdateControls();
  584. }
  585. //---------------------------------------------------------------------------
  586. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  587. {
  588. if (Queue != value)
  589. {
  590. if (FQueue != NULL)
  591. {
  592. FQueue->OnListUpdate = NULL;
  593. FQueue->OnQueueItemUpdate = NULL;
  594. }
  595. FQueue = value;
  596. if (FQueue != NULL)
  597. {
  598. DebugAssert(FQueue->OnListUpdate == NULL);
  599. FQueue->OnListUpdate = QueueListUpdate;
  600. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  601. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  602. }
  603. QueueChanged();
  604. }
  605. }
  606. //---------------------------------------------------------------------------
  607. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  608. TListItem * Item)
  609. {
  610. if (FQueueActedItem == Item)
  611. {
  612. FQueueActedItem = NULL;
  613. if ((QueueView3->PopupMenu != NULL) &&
  614. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  615. {
  616. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  617. ReleaseCapture();
  618. }
  619. }
  620. if (Item->Data == FPendingQueueActionItem)
  621. {
  622. FPendingQueueActionItem = NULL;
  623. }
  624. }
  625. //---------------------------------------------------------------------------
  626. bool TCustomScpExplorerForm::IsAnythingQueued()
  627. {
  628. return (FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0);
  629. }
  630. //---------------------------------------------------------------------------
  631. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  632. {
  633. {
  634. TGuard Guard(FQueueStatusSection);
  635. FQueueStatusInvalidated = false;
  636. if (FQueue != NULL)
  637. {
  638. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  639. }
  640. }
  641. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  642. {
  643. FMaxQueueLength = FQueueStatus->Count;
  644. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  645. }
  646. {
  647. TAutoFlag Flag(FQueueStatusUpdating);
  648. FQueueController->UpdateQueueStatus(FQueueStatus);
  649. }
  650. UpdateQueueFileList();
  651. SetQueueProgress();
  652. UpdateQueueView();
  653. bool IsEmpty = !IsAnythingQueued();
  654. if (IsEmpty && (Terminal != NULL))
  655. {
  656. TOnceDoneOperation OnceDoneOperation =
  657. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  658. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  659. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  660. {
  661. FQueue->Enabled = false;
  662. }
  663. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  664. {
  665. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  666. }
  667. }
  668. }
  669. //---------------------------------------------------------------------------
  670. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  671. {
  672. UnicodeString Result;
  673. if (FQueueStatus != NULL)
  674. {
  675. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  676. {
  677. TFileOperationProgressType * ProgressData =
  678. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  679. if ((ProgressData != NULL) && ProgressData->InProgress)
  680. {
  681. Result = TProgressForm::ProgressStr(NULL, ProgressData);
  682. }
  683. }
  684. else if (FQueueStatus->ActiveAndPendingPrimaryCount > 1)
  685. {
  686. Result = FMTLOAD(PROGRESS_IN_QUEUE, (FQueueStatus->ActiveAndPendingPrimaryCount));
  687. }
  688. }
  689. return Result;
  690. }
  691. //---------------------------------------------------------------------------
  692. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  693. {
  694. ComponentVisible[fcQueueView] =
  695. !IsLocalBrowserMode() &&
  696. ((WinConfiguration->QueueView.Show == qvShow) ||
  697. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  698. (FQueueStatus != NULL) && (FQueueStatus->Count > 0)));
  699. }
  700. //---------------------------------------------------------------------------
  701. void __fastcall TCustomScpExplorerForm::QueueChanged()
  702. {
  703. if (FQueueStatus != NULL)
  704. {
  705. // UpdateFileList implementation relies on the status being recreated when session changes
  706. delete FQueueStatus;
  707. FQueueStatus = NULL;
  708. }
  709. UpdateQueueStatus(true);
  710. }
  711. //---------------------------------------------------------------------------
  712. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  713. {
  714. if (FQueue == Queue)
  715. {
  716. FQueueStatusInvalidated = true;
  717. }
  718. }
  719. //---------------------------------------------------------------------------
  720. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  721. TQueueItem * Item)
  722. {
  723. if (FQueue == Queue)
  724. {
  725. TGuard Guard(FQueueStatusSection);
  726. // this may be running in parallel with QueueChanged
  727. if (FQueueStatus != NULL)
  728. {
  729. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  730. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  731. {
  732. FRefreshLocalDirectory = (QueueItem == NULL) ||
  733. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  734. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  735. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  736. }
  737. if (QueueItem != NULL)
  738. {
  739. QueueItem->UserData = (void*)true;
  740. FQueueItemInvalidated = true;
  741. }
  742. }
  743. }
  744. }
  745. //---------------------------------------------------------------------------
  746. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  747. {
  748. // during standalone editing, we have no way to see/control queue,
  749. // so we have to always popup prompts automatically
  750. return StandaloneOperation || GUIConfiguration->QueueAutoPopup;
  751. }
  752. //---------------------------------------------------------------------------
  753. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  754. {
  755. if (FQueueStatus != NULL)
  756. {
  757. bool QueueAutoPopup = IsQueueAutoPopup();
  758. bool NeedRefresh = FQueueController->NeedRefresh();
  759. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  760. FQueueItemInvalidated = false;
  761. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  762. bool Updated = false;
  763. TQueueItemProxy * QueueItem;
  764. bool WasUserAction;
  765. for (int Index = 0; Index < Limit; Index++)
  766. {
  767. bool Update = false;
  768. QueueItem = FQueueStatus->Items[Index];
  769. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  770. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  771. (FPendingQueueActionItem == NULL))
  772. {
  773. FPendingQueueActionItem = QueueItem;
  774. FUserActionTimer->Enabled = true;
  775. }
  776. if ((bool)QueueItem->UserData)
  777. {
  778. QueueItem->UserData = (void*)false;
  779. QueueItem->Update();
  780. Updated = true;
  781. Update = true;
  782. }
  783. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  784. {
  785. Update = true;
  786. }
  787. if (Update)
  788. {
  789. FQueueController->RefreshQueueItem(QueueItem);
  790. }
  791. }
  792. if (Updated)
  793. {
  794. NonVisualDataModule->UpdateNonVisibleActions();
  795. SetQueueProgress();
  796. UpdateQueueFileList();
  797. }
  798. }
  799. }
  800. //---------------------------------------------------------------------------
  801. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  802. {
  803. if (FTaskbarList != NULL)
  804. {
  805. // Could now use Application->MainFormHandle, now that we implement Application->OnGetMainFormHandle
  806. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  807. }
  808. }
  809. //---------------------------------------------------------------------------
  810. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(int Progress)
  811. {
  812. if (Progress >= 0)
  813. {
  814. if (FTaskbarList != NULL)
  815. {
  816. FTaskbarList->SetProgressValue(GetMainForm()->Handle, Progress, 100);
  817. }
  818. }
  819. else
  820. {
  821. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  822. }
  823. }
  824. //---------------------------------------------------------------------------
  825. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  826. {
  827. int OverallProgress;
  828. // FProgressForm is null when this is called from SetQueueProgress
  829. if ((FProgressForm != NULL) && (FProgressForm->SynchronizeProgress != NULL))
  830. {
  831. OverallProgress = FProgressForm->SynchronizeProgress->Progress(ProgressData);
  832. }
  833. else if (!ProgressData->IsIndeterminate())
  834. {
  835. OverallProgress = ProgressData->OverallProgress();
  836. }
  837. else
  838. {
  839. OverallProgress = -1;
  840. }
  841. SetTaskbarListProgressValue(OverallProgress);
  842. }
  843. //---------------------------------------------------------------------------
  844. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  845. {
  846. TTerminalManager::Instance()->QueueStatusUpdated();
  847. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  848. {
  849. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveAndPendingPrimaryCount > 0))
  850. {
  851. if (FQueueStatus->IsOnlyOneActiveAndNoPending())
  852. {
  853. TFileOperationProgressType * ProgressData = NULL;
  854. if (FQueueStatus->Items[FQueueStatus->DoneCount] != NULL)
  855. {
  856. ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  857. }
  858. if ((ProgressData != NULL) &&
  859. ProgressData->InProgress)
  860. {
  861. SetTaskbarListProgressValue(ProgressData);
  862. }
  863. else
  864. {
  865. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  866. }
  867. }
  868. else
  869. {
  870. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  871. }
  872. }
  873. else
  874. {
  875. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  876. }
  877. }
  878. UpdateQueueLabel();
  879. }
  880. //---------------------------------------------------------------------------
  881. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  882. {
  883. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  884. if (FQueueStatus != NULL)
  885. {
  886. int ActiveAndPendingPrimaryCount = FQueueStatus->ActiveAndPendingPrimaryCount;
  887. if (ActiveAndPendingPrimaryCount > 0)
  888. {
  889. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingPrimaryCount));
  890. }
  891. }
  892. QueueLabel->Caption = Caption;
  893. }
  894. //---------------------------------------------------------------------------
  895. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  896. {
  897. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  898. static_cast<TComponent*>(GetComponent(fcTransferList)));
  899. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  900. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  901. TransferList->Strings->BeginUpdate();
  902. try
  903. {
  904. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  905. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  906. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  907. if (FTransferDropDownHint.IsEmpty())
  908. {
  909. FTransferDropDownHint = TransferDropDown->Hint;
  910. }
  911. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  912. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  913. TransferDropDown->Text = StripHotkey(Name);
  914. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  915. (FTransferDropDownHint, StripHotkey(Name),
  916. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  917. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General))));
  918. // update the label, otherwise when it is updated only on the first draw
  919. // of the list, it is drawn "bold" for some reason
  920. FTransferListHoverIndex = TransferList->ItemIndex;
  921. UpdateTransferLabel();
  922. }
  923. __finally
  924. {
  925. TransferList->Strings->EndUpdate();
  926. }
  927. }
  928. //---------------------------------------------------------------------------
  929. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  930. {
  931. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  932. DebugAssert(Toolbar != NULL);
  933. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  934. }
  935. //---------------------------------------------------------------------------
  936. void __fastcall TCustomScpExplorerForm::UpdateActions()
  937. {
  938. TForm::UpdateActions();
  939. if (ComponentVisible[fcCustomCommandsBand])
  940. {
  941. UpdateCustomCommandsToolbar();
  942. }
  943. }
  944. //---------------------------------------------------------------------------
  945. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  946. {
  947. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  948. }
  949. //---------------------------------------------------------------------------
  950. void __fastcall TCustomScpExplorerForm::UpdateRowSelect(TCustomDirView * DirView)
  951. {
  952. if (DirView->RowSelect != WinConfiguration->FullRowSelect)
  953. {
  954. DirView->RowSelect = WinConfiguration->FullRowSelect;
  955. // Without this, the panel turns gray and unused part of header turns black
  956. DirView->Perform(CM_COLORCHANGED, 0, 0);
  957. }
  958. }
  959. //---------------------------------------------------------------------------
  960. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  961. {
  962. Color = GetBtnFaceColor();
  963. DebugAssert(Configuration && RemoteDirView);
  964. RemoteDirView->DDAllowMove = !WinConfiguration->DDDisableMove;
  965. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  966. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  967. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  968. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  969. RemoteDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  970. UpdateRowSelect(RemoteDirView);
  971. RemoteDriveView->DDAllowMove = !WinConfiguration->DDDisableMove;
  972. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  973. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  974. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  975. RemoteDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  976. UpdateSessionsPageControlHeight();
  977. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  978. UpdateToolbarDisplayMode();
  979. UpdateTransferList();
  980. if (Terminal != NULL)
  981. {
  982. TransferPresetAutoSelect();
  983. }
  984. UpdateQueueView();
  985. UpdateControls();
  986. // this can be called even before constuctor finishes.
  987. if (FEditorManager != NULL)
  988. {
  989. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  990. }
  991. // this can be called even before constuctor finishes.
  992. if (FLocalEditors != NULL)
  993. {
  994. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  995. {
  996. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  997. }
  998. }
  999. if (ComponentVisible[fcCustomCommandsBand])
  1000. {
  1001. UpdateCustomCommandsToolbar();
  1002. }
  1003. // show only when keeping queue items forever,
  1004. // otherwise, it's enough to have it in the context menu
  1005. QueueDeleteAllDoneQueueToolbarItem->Visible =
  1006. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  1007. if (FFileColorsCurrent != WinConfiguration->FileColors)
  1008. {
  1009. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  1010. FFileColorsCurrent = WinConfiguration->FileColors;
  1011. FileColorsChanged();
  1012. }
  1013. }
  1014. //---------------------------------------------------------------------------
  1015. void __fastcall TCustomScpExplorerForm::DoFileColorsChanged(TCustomDirView * DirView)
  1016. {
  1017. DirView->OnGetItemColor = FFileColors.empty() ? TDirViewGetItemColorEvent(NULL) : TDirViewGetItemColorEvent(&DirViewGetItemColor);
  1018. DirView->Invalidate();
  1019. }
  1020. //---------------------------------------------------------------------------
  1021. void __fastcall TCustomScpExplorerForm::FileColorsChanged()
  1022. {
  1023. DoFileColorsChanged(RemoteDirView);
  1024. }
  1025. //---------------------------------------------------------------------------
  1026. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  1027. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  1028. void * /*Arg*/)
  1029. {
  1030. if (Token != NULL)
  1031. {
  1032. TForm * Editor = dynamic_cast<TForm*>(Token);
  1033. DebugAssert(Editor != NULL);
  1034. ReconfigureEditorForm(Editor);
  1035. }
  1036. }
  1037. //---------------------------------------------------------------------------
  1038. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  1039. {
  1040. WinConfiguration->DDTransferConfirmation = asOn;
  1041. }
  1042. //---------------------------------------------------------------------------
  1043. void __fastcall TCustomScpExplorerForm::CopyParamDialogAfter(
  1044. TTransferDirection /*Direction*/, bool /*Temp*/, const UnicodeString & /*TargetDirectory*/)
  1045. {
  1046. // noop
  1047. }
  1048. //---------------------------------------------------------------------------
  1049. bool TCustomScpExplorerForm::GetDoNotShowCopyDialogDefault(bool DragDrop)
  1050. {
  1051. return DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto);
  1052. }
  1053. //---------------------------------------------------------------------------
  1054. void TCustomScpExplorerForm::HandleDoNotShowCopyDialogAgain(bool DragDrop, bool DoNotShowAgain)
  1055. {
  1056. if (DoNotShowAgain)
  1057. {
  1058. if (DragDrop)
  1059. {
  1060. if (WinConfiguration->DDTransferConfirmation == asAuto)
  1061. {
  1062. PopupTrayBalloon(
  1063. NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation, NULL, 0, EnableDDTransferConfirmation, NULL);
  1064. }
  1065. WinConfiguration->DDTransferConfirmation = asOff;
  1066. }
  1067. else
  1068. {
  1069. WinConfiguration->ConfirmTransferring = false;
  1070. }
  1071. }
  1072. else
  1073. {
  1074. // User explicitly unchecked "do not show again",
  1075. // so show him the dialog the next time
  1076. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  1077. {
  1078. WinConfiguration->DDTransferConfirmation = asOn;
  1079. }
  1080. }
  1081. }
  1082. //---------------------------------------------------------------------------
  1083. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  1084. TTransferDirection Direction, TTransferType Type, bool Temp,
  1085. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  1086. bool Confirm, bool DragDrop, int Options)
  1087. {
  1088. bool Result = true;
  1089. DebugAssert(HasActiveTerminal());
  1090. // these parameters are known in advance
  1091. int Params =
  1092. FLAGMASK(Type == ttMove, cpDelete);
  1093. bool ToTemp = (Temp && (Direction == tdToLocal));
  1094. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  1095. {
  1096. bool DisableNewerOnly =
  1097. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  1098. ToTemp;
  1099. Options |=
  1100. FLAGMASK(ToTemp, coTemp) |
  1101. FLAGMASK(!Terminal->IsCapable[fcBackgroundTransfers], coDisableQueue) |
  1102. coDoNotShowAgain;
  1103. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  1104. int CopyParamAttrs = (Direction == tdToRemote ?
  1105. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  1106. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  1107. int OutputOptions = FLAGMASK(GetDoNotShowCopyDialogDefault(DragDrop), cooDoNotShowAgain);
  1108. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  1109. FlashOnBackground(); // Particularly when called from ClipboardFakeCreated
  1110. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  1111. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions, -1);
  1112. if (Result)
  1113. {
  1114. HandleDoNotShowCopyDialogAgain(DragDrop, FLAGSET(OutputOptions, cooDoNotShowAgain));
  1115. CopyParamDialogAfter(Direction, Temp, TargetDirectory);
  1116. }
  1117. }
  1118. if (Result && CopyParam.Queue && !ToTemp && Terminal->IsCapable[fcBackgroundTransfers])
  1119. {
  1120. Configuration->Usage->Inc(L"TransfersOnBackground");
  1121. // these parameter are known only after transfer dialog
  1122. Params |=
  1123. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1124. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1125. Result = false;
  1126. ClearTransferSourceSelection(Direction);
  1127. }
  1128. return Result;
  1129. }
  1130. //---------------------------------------------------------------------------
  1131. void TCustomScpExplorerForm::ClearOperationSelection(TOperationSide Side)
  1132. {
  1133. if (FOnFileOperationFinished != NULL)
  1134. {
  1135. FOnFileOperationFinished(Side, UnicodeString(), true);
  1136. }
  1137. else
  1138. {
  1139. if (HasDirView[Side])
  1140. {
  1141. DirView(Side)->SelectAll(smNone);
  1142. }
  1143. }
  1144. }
  1145. //---------------------------------------------------------------------------
  1146. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1147. {
  1148. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1149. ClearOperationSelection(Side);
  1150. }
  1151. //---------------------------------------------------------------------------
  1152. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1153. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1154. const UnicodeString TargetDirectory, const TGUICopyParamType & CopyParam,
  1155. int Params)
  1156. {
  1157. DebugAssert(Queue != NULL);
  1158. bool SingleFile = false;
  1159. if (FileList->Count == 1)
  1160. {
  1161. if (Direction == tdToRemote)
  1162. {
  1163. UnicodeString FileName = FileList->Strings[0];
  1164. SingleFile = FileExists(ApiPath(FileName));
  1165. }
  1166. else
  1167. {
  1168. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1169. SingleFile = !File->IsDirectory;
  1170. }
  1171. }
  1172. TQueueItem * QueueItem;
  1173. if (Direction == tdToRemote)
  1174. {
  1175. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1176. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1177. }
  1178. else
  1179. {
  1180. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1181. &CopyParam, Params, SingleFile, CopyParam.QueueParallel);
  1182. }
  1183. AddQueueItem(Queue, QueueItem, Terminal);
  1184. }
  1185. //---------------------------------------------------------------------------
  1186. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TManagedTerminal * Terminal)
  1187. {
  1188. if (Queue->IsEmpty)
  1189. {
  1190. Terminal->QueueOperationStart = Now();
  1191. }
  1192. Queue->AddItem(QueueItem);
  1193. }
  1194. //---------------------------------------------------------------------------
  1195. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1196. {
  1197. }
  1198. //---------------------------------------------------------------------------
  1199. void __fastcall TCustomScpExplorerForm::InitControls()
  1200. {
  1201. DebugAssert(FDocks != NULL);
  1202. for (int Index = 0; Index < ComponentCount; Index++)
  1203. {
  1204. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1205. if ((Dock != NULL) && (Dock->Tag == 0))
  1206. {
  1207. FDocks->Add(Dock);
  1208. }
  1209. }
  1210. CollectItemsWithTextDisplayMode(this);
  1211. }
  1212. //---------------------------------------------------------------------------
  1213. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1214. {
  1215. ConfigurationChanged();
  1216. QueuePanel->Height =
  1217. LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch, this);
  1218. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1219. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1220. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1221. QueueFileList->Visible = WinConfiguration->QueueView.FileList;
  1222. QueueFileList->Height =
  1223. LoadDimension(WinConfiguration->QueueView.FileListHeight, WinConfiguration->QueueView.FileListHeightPixelsPerInch, this);
  1224. if (QueueFileList->Visible)
  1225. {
  1226. AdjustQueueLayout();
  1227. }
  1228. UpdateCustomCommandsToolbar();
  1229. }
  1230. //---------------------------------------------------------------------------
  1231. void __fastcall TCustomScpExplorerForm::StoreParams()
  1232. {
  1233. int APixelsPerInch = GetControlPixelsPerInch(this);
  1234. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1235. WinConfiguration->QueueView.HeightPixelsPerInch = APixelsPerInch;
  1236. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1237. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1238. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1239. WinConfiguration->QueueView.FileList = QueueFileList->Visible;
  1240. WinConfiguration->QueueView.FileListHeight = QueueFileList->Height;
  1241. WinConfiguration->QueueView.FileListHeightPixelsPerInch = APixelsPerInch;
  1242. }
  1243. //---------------------------------------------------------------------------
  1244. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1245. {
  1246. if (!FFormRestored)
  1247. {
  1248. FFormRestored = true;
  1249. RestoreFormParams();
  1250. }
  1251. TForm::CreateParams(Params);
  1252. }
  1253. //---------------------------------------------------------------------------
  1254. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1255. {
  1256. DebugAssert(FDocks != NULL);
  1257. for (int Index = 0; Index < FDocks->Count; Index++)
  1258. {
  1259. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1260. }
  1261. }
  1262. //---------------------------------------------------------------------------
  1263. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr, UnicodeString ButtonsStr)
  1264. {
  1265. SetDockAllowDrag(true);
  1266. while (!ButtonsStr.IsEmpty())
  1267. {
  1268. UnicodeString S = CutToChar(ButtonsStr, L';', true);
  1269. UnicodeString Name = CutToChar(S, L'=', true);
  1270. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1271. {
  1272. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1273. if ((Toolbar != NULL) && SameText(Name, GetToolbarKey(Toolbar->Name)))
  1274. {
  1275. while (!S.IsEmpty())
  1276. {
  1277. UnicodeString S2 = CutToChar(S, L',', true);
  1278. UnicodeString Name = CutToChar(S2, L':', true);
  1279. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1280. {
  1281. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1282. if (SameText(GetToolbarItemName(Item), Name))
  1283. {
  1284. // forward compatibility
  1285. UnicodeString S3 = CutToChar(S2, L':', true);
  1286. bool Visible = StrToIntDef(S3, 0);
  1287. Item->Visible = Visible;
  1288. }
  1289. }
  1290. }
  1291. }
  1292. }
  1293. }
  1294. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1295. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1296. }
  1297. //---------------------------------------------------------------------------
  1298. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1299. {
  1300. UnicodeString Result;
  1301. SetDockAllowDrag(true);
  1302. Result = ::GetToolbarsLayoutStr(this);
  1303. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1304. return Result;
  1305. }
  1306. //---------------------------------------------------------------------------
  1307. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarItemName(TTBCustomItem * Item)
  1308. {
  1309. UnicodeString Result;
  1310. if (Item->Action != NULL)
  1311. {
  1312. Result = Item->Action->Name;
  1313. Result = RemoveSuffix(Result, L"Action", true);
  1314. }
  1315. else
  1316. {
  1317. Result = Item->Name;
  1318. Result = RemoveSuffix(Result, L"SubmenuItem", true);
  1319. Result = RemoveSuffix(Result, L"Item", true);
  1320. }
  1321. return Result;
  1322. }
  1323. //---------------------------------------------------------------------------
  1324. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsButtonsStr()
  1325. {
  1326. UnicodeString Result;
  1327. for (int ToolbarIndex = 0; ToolbarIndex < ComponentCount; ToolbarIndex++)
  1328. {
  1329. UnicodeString ToolbarStr;
  1330. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(Components[ToolbarIndex]);
  1331. if ((Toolbar != NULL) && (Toolbar != QueueToolbar))
  1332. {
  1333. for (int ItemIndex = 0; ItemIndex < Toolbar->Items->Count; ItemIndex++)
  1334. {
  1335. TTBCustomItem * Item = Toolbar->Items->Items[ItemIndex];
  1336. // Currently all buttons are visible by default, so we can safely remember all hidden buttons.
  1337. // Once we introduce any buttons that are hidden by default, we would have to remember their initial state
  1338. // and save the changes here only.
  1339. if (NonVisualDataModule->IsCustomizableToolbarItem(Item) && !Item->Visible)
  1340. {
  1341. UnicodeString Name = GetToolbarItemName(Item);
  1342. DebugAssert(Name.Pos(L"TBX") == 0);
  1343. AddToList(ToolbarStr, FORMAT(L"%s:0", (Name)), L",");
  1344. }
  1345. }
  1346. }
  1347. if (!ToolbarStr.IsEmpty())
  1348. {
  1349. AddToList(Result, FORMAT(L"%s=%s", (GetToolbarKey(Toolbar->Name), ToolbarStr)), L";");
  1350. }
  1351. }
  1352. return Result;
  1353. }
  1354. //---------------------------------------------------------------------------
  1355. void __fastcall TCustomScpExplorerForm::CreateProgressForm(TSynchronizeProgress * SynchronizeProgress)
  1356. {
  1357. DebugAssert(FProgressForm == NULL);
  1358. bool AllowSkip = HasActiveTerminal() ? Terminal->IsCapable[fcSkipTransfer] : false;
  1359. bool AllowMoveToQueue = (FTransferResumeList != NULL) || (FDeletedFiles != NULL);
  1360. FProgressForm = new TProgressForm(Application, AllowMoveToQueue, AllowSkip, SynchronizeProgress);
  1361. FProgressForm->DeleteLocalToRecycleBin =
  1362. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete);
  1363. FProgressForm->DeleteRemoteToRecycleBin =
  1364. HasActiveTerminal() &&
  1365. (Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1366. !Terminal->SessionData->RecycleBinPath.IsEmpty();
  1367. // As progress window has delayed show now, we need to lock ourselves, (at least) until then
  1368. LockWindow();
  1369. // Actually, do not know what hides the progress once the operation finishes
  1370. // (it is possibly the SetQueueProgress - and we should not rely on that)
  1371. SetTaskbarListProgressState(TBPF_NORMAL);
  1372. }
  1373. //---------------------------------------------------------------------------
  1374. void __fastcall TCustomScpExplorerForm::DestroyProgressForm()
  1375. {
  1376. UnlockWindow();
  1377. SAFE_DESTROY(FProgressForm);
  1378. SetQueueProgress();
  1379. }
  1380. //---------------------------------------------------------------------------
  1381. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1382. TFileOperationProgressType & ProgressData)
  1383. {
  1384. // Download to temporary local directory
  1385. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1386. {
  1387. bool Continue = true;
  1388. FPendingTempSpaceWarn = false;
  1389. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1390. if (!Continue)
  1391. {
  1392. Abort();
  1393. }
  1394. }
  1395. // operation is being executed and we still didn't show up progress form
  1396. if (ProgressData.InProgress && !FProgressForm)
  1397. {
  1398. CreateProgressForm(NULL);
  1399. DebugAssert(FProgressForm->OnceDoneOperation == odoIdle);
  1400. FProgressForm->OnceDoneOperation = ProgressData.InitialOnceDoneOperation;
  1401. }
  1402. // operation is finished (or terminated), so we hide progress form
  1403. else if (!ProgressData.InProgress && (FProgressForm != NULL) && (FProgressForm->SynchronizeProgress == NULL))
  1404. {
  1405. DestroyProgressForm();
  1406. if (ProgressData.Operation == foCalculateSize)
  1407. {
  1408. // When calculating size before transfer, the abort caused by
  1409. // cancel flag set due to "MoveToQueue" below,
  1410. // is not propagated back to us in ExecuteFileOperation,
  1411. // as it is silently swallowed.
  1412. // So we explicitly (re)throw it here.
  1413. if (FMoveToQueue)
  1414. {
  1415. Abort();
  1416. }
  1417. }
  1418. else
  1419. {
  1420. if ((ProgressData.Cancel == csContinue) &&
  1421. !FAutoOperation)
  1422. {
  1423. OperationComplete(ProgressData.StartTime);
  1424. }
  1425. }
  1426. }
  1427. if (FProgressForm &&
  1428. // Can happen only during synchronization, when ending one of the operations
  1429. ProgressData.InProgress)
  1430. {
  1431. FProgressForm->SetProgressData(ProgressData);
  1432. DebugAssert(ProgressData.InProgress);
  1433. SetTaskbarListProgressValue(&ProgressData);
  1434. if (FProgressForm->Cancel > csContinue)
  1435. {
  1436. ProgressData.SetCancelAtLeast(FProgressForm->Cancel);
  1437. if (FProgressForm->Cancel == csCancelFile)
  1438. {
  1439. FProgressForm->ClearCancel();
  1440. }
  1441. // cancel cancels even the move
  1442. FMoveToQueue = false;
  1443. }
  1444. else if (FProgressForm->MoveToQueue)
  1445. {
  1446. FMoveToQueue = true;
  1447. ProgressData.SetCancelAtLeast(csCancel);
  1448. }
  1449. if ((FTransferResumeList != NULL) &&
  1450. ProgressData.InProgress &&
  1451. ProgressData.IsTransfer() &&
  1452. !ProgressData.FullFileName.IsEmpty())
  1453. {
  1454. if ((FTransferResumeList->Count == 0) ||
  1455. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1456. {
  1457. // note that we do not recognize directories from files here
  1458. FTransferResumeList->Add(ProgressData.FullFileName);
  1459. }
  1460. }
  1461. }
  1462. }
  1463. //---------------------------------------------------------------------------
  1464. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1465. const TDateTime & StartTime)
  1466. {
  1467. if (GUIConfiguration->BeepOnFinish &&
  1468. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1469. {
  1470. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1471. DWORD Sound;
  1472. if (!ExtractFileExt(BeepSound).IsEmpty())
  1473. {
  1474. Sound = SND_FILENAME;
  1475. }
  1476. else
  1477. {
  1478. Sound = SND_ALIAS;
  1479. }
  1480. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1481. }
  1482. }
  1483. //---------------------------------------------------------------------------
  1484. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1485. TFileOperationProgressType & ProgressData)
  1486. {
  1487. // For example, when calling TFileOperationProgressType::Suspend in TTerminal::QueryReopen,
  1488. // we cannot recurse back to TTerminal::Idle as that may detect another error, calling "suspend" again.
  1489. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1490. FileOperationProgress(ProgressData);
  1491. }
  1492. //---------------------------------------------------------------------------
  1493. UnicodeString __fastcall TCustomScpExplorerForm::GetProgressTitle()
  1494. {
  1495. UnicodeString Result;
  1496. if (FProgressForm != NULL)
  1497. {
  1498. Result = FProgressForm->ProgressStr();
  1499. }
  1500. return Result;
  1501. }
  1502. //---------------------------------------------------------------------------
  1503. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1504. bool DragDrop)
  1505. {
  1506. return (!DragDrop && (DropSourceControl == NULL)) ||
  1507. (DropSourceControl == DirView(osOther));
  1508. }
  1509. //---------------------------------------------------------------------------
  1510. TListItem * TCustomScpExplorerForm::VisualiseOperationFinished(TOperationSide Side, const UnicodeString & FileName, bool Unselect)
  1511. {
  1512. TCustomDirView * ADirView = DirView(Side);
  1513. UnicodeString FileNameOnly = ExtractFileName(FileName, !IsSideLocalBrowser(Side));
  1514. TListItem * Item = ADirView->FindFileItem(FileNameOnly);
  1515. // this can happen when local drive is unplugged in the middle of the operation
  1516. if (Item != NULL)
  1517. {
  1518. if (Unselect)
  1519. {
  1520. Item->Selected = false;
  1521. }
  1522. ADirView->MakeProgressVisible(Item);
  1523. }
  1524. return Item;
  1525. }
  1526. //---------------------------------------------------------------------------
  1527. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1528. TFileOperation Operation, TOperationSide Side,
  1529. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1530. TOnceDoneOperation & OnceDoneOperation)
  1531. {
  1532. if (!FAutoOperation)
  1533. {
  1534. // no selection on "/upload", form serves only as event handler
  1535. // (it is not displayed)
  1536. if (PanelOperation(Side, FDragDropOperation) && Visible &&
  1537. ((Operation == FPrimaryOperation) ||
  1538. ((Operation != foCalculateSize) && (Operation != foGetProperties) && (Operation != foCalculateChecksum))))
  1539. {
  1540. TOperationSide DViewSide;
  1541. if ((FProgressSide != osCurrent) &&
  1542. IsLocalBrowserMode() && (Side == osLocal)) // Only to limit the impact
  1543. {
  1544. // assume the operation is over the focused panel
  1545. DViewSide = FProgressSide;
  1546. }
  1547. else
  1548. {
  1549. DViewSide = Side;
  1550. }
  1551. if (FOnFileOperationFinished != NULL)
  1552. {
  1553. FOnFileOperationFinished(DViewSide, FileName, Success);
  1554. }
  1555. else
  1556. {
  1557. VisualiseOperationFinished(DViewSide, FileName, Success);
  1558. }
  1559. }
  1560. if (TFileOperationProgressType::IsTransferOperation(Operation))
  1561. {
  1562. if (DebugAlwaysTrue(!IsLocalBrowserMode()))
  1563. {
  1564. if (Side == osLocal)
  1565. {
  1566. Configuration->Usage->Inc(L"UploadedFiles");
  1567. }
  1568. else
  1569. {
  1570. Configuration->Usage->Inc(L"DownloadedFiles");
  1571. }
  1572. }
  1573. }
  1574. }
  1575. if (Success && (FSynchronizeController != NULL))
  1576. {
  1577. DebugAssert(!IsSideLocalBrowser(osRemote));
  1578. if (Operation == foCopy)
  1579. {
  1580. DebugAssert(Side == osLocal);
  1581. FSynchronizeController->LogOperation(soUpload, FileName);
  1582. }
  1583. else if (Operation == foDelete)
  1584. {
  1585. DebugAssert(Side == osRemote);
  1586. FSynchronizeController->LogOperation(soDelete, FileName);
  1587. }
  1588. }
  1589. if (FProgressForm)
  1590. {
  1591. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1592. }
  1593. }
  1594. //---------------------------------------------------------------------------
  1595. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1596. TFileOperation Operation, TOperationSide Side,
  1597. bool Temp, const UnicodeString & FileName, Boolean Success,
  1598. TOnceDoneOperation & OnceDoneOperation)
  1599. {
  1600. TAutoNestingCounter Counter(FDoNotIdleCurrentTerminal);
  1601. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1602. OnceDoneOperation);
  1603. }
  1604. //---------------------------------------------------------------------------
  1605. bool TCustomScpExplorerForm::IsLocalBrowserMode()
  1606. {
  1607. return false;
  1608. }
  1609. //---------------------------------------------------------------------------
  1610. bool TCustomScpExplorerForm::SupportsLocalBrowser()
  1611. {
  1612. return false;
  1613. }
  1614. //---------------------------------------------------------------------------
  1615. bool TCustomScpExplorerForm::IsSideLocalBrowser(TOperationSide)
  1616. {
  1617. return false;
  1618. }
  1619. //---------------------------------------------------------------------------
  1620. TCustomDirView * TCustomScpExplorerForm::GetCurrentLocalBrowser()
  1621. {
  1622. return NULL;
  1623. }
  1624. //---------------------------------------------------------------------------
  1625. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1626. {
  1627. DebugAssert(GetSide(Side) == osRemote);
  1628. DebugUsedParam(Side);
  1629. return RemoteDirView;
  1630. }
  1631. //---------------------------------------------------------------------------
  1632. TCustomDriveView * __fastcall TCustomScpExplorerForm::DriveView(TOperationSide Side)
  1633. {
  1634. DebugAssert(GetSide(Side) == osRemote);
  1635. DebugUsedParam(Side);
  1636. return RemoteDriveView;
  1637. }
  1638. //---------------------------------------------------------------------------
  1639. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1640. {
  1641. DebugAssert(GetSide(Side) == osRemote);
  1642. DebugUsedParam(Side);
  1643. return HasActiveTerminal();
  1644. }
  1645. //---------------------------------------------------------------------------
  1646. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1647. TOperationSide Side, int FilesOnly)
  1648. {
  1649. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1650. }
  1651. //---------------------------------------------------------------------------
  1652. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1653. TOperationSide Side, int FilesOnly)
  1654. {
  1655. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1656. }
  1657. //---------------------------------------------------------------------------
  1658. struct THistoryItemData
  1659. {
  1660. short int Side;
  1661. short int Index;
  1662. };
  1663. //---------------------------------------------------------------------------
  1664. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1665. {
  1666. DirView(Side)->HistoryGo(Index);
  1667. }
  1668. //---------------------------------------------------------------------------
  1669. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1670. {
  1671. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1672. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1673. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1674. }
  1675. //---------------------------------------------------------------------------
  1676. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1677. bool Back)
  1678. {
  1679. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1680. {
  1681. TCustomDirView * DView = DirView(Side);
  1682. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1683. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1684. if (ICount > 10)
  1685. {
  1686. ICount = 10;
  1687. }
  1688. Menu->Items->Clear();
  1689. THistoryItemData Data;
  1690. Data.Side = Side;
  1691. for (short int i = 1; i <= ICount; i++)
  1692. {
  1693. TTBCustomItem * Item = new TTBXItem(Menu);
  1694. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1695. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, !IsSideLocalBrowser(Side));
  1696. Item->Hint = DView->HistoryPath[Data.Index];
  1697. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1698. Item->Tag = *reinterpret_cast<int*>(&Data);
  1699. Item->OnClick = HistoryItemClick;
  1700. Menu->Items->Add(Item);
  1701. }
  1702. }
  1703. }
  1704. //---------------------------------------------------------------------------
  1705. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1706. TOperationSide Side, bool Back)
  1707. {
  1708. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1709. {
  1710. // workaround
  1711. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1712. // operator new allocates memory in Pascal code, but calls inline
  1713. // contructor in C++, leading in problems, the function does
  1714. // both in Pascal code
  1715. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1716. UpdateHistoryMenu(Side, Back);
  1717. }
  1718. return FHistoryMenu[Side == osLocal][Back];
  1719. }
  1720. //---------------------------------------------------------------------------
  1721. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1722. TCustomDirView *Sender)
  1723. {
  1724. TOperationSide Side = (Sender == DirView(osOther) ? osOther : osLocal);
  1725. UpdateHistoryMenu(Side, true);
  1726. UpdateHistoryMenu(Side, false);
  1727. }
  1728. //---------------------------------------------------------------------------
  1729. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1730. {
  1731. // remote custom commands can be executed only if the server supports shell commands
  1732. // or have secondary shell
  1733. return HasActiveTerminal() && (Terminal->IsCapable[fcSecondaryShell] || Terminal->IsCapable[fcShellAnyCommand]);
  1734. }
  1735. //---------------------------------------------------------------------------
  1736. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1737. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1738. {
  1739. // -1 = hidden, 0 = disabled, 1 = enabled
  1740. int Result;
  1741. TFileCustomCommand RemoteCustomCommand;
  1742. TLocalCustomCommand LocalCustomCommand;
  1743. TFileCustomCommand * NonInteractiveCustomCommand =
  1744. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1745. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1746. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1747. if (FLAGCLEAR(Command.Params, ccLocal))
  1748. {
  1749. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1750. // custom command that does not operate with files can be executed anytime ...
  1751. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1752. {
  1753. // ... but do not show such command in remote file menu
  1754. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1755. {
  1756. Result = AllowedState;
  1757. }
  1758. else
  1759. {
  1760. Result = -1;
  1761. }
  1762. }
  1763. else
  1764. {
  1765. if ((ListType == ccltAll) || ((ListType == ccltFile) && !IsSideLocalBrowser(FCurrentSide)))
  1766. {
  1767. Result = (DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1768. }
  1769. else
  1770. {
  1771. Result = -1;
  1772. }
  1773. }
  1774. }
  1775. else
  1776. {
  1777. // custom command that does not operate with files can be executed anytime
  1778. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1779. {
  1780. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1781. }
  1782. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1783. {
  1784. if ((ListType == ccltAll) || (ListType == ccltFile))
  1785. {
  1786. // special case is "diff"-style command that can be executed over any side,
  1787. // if we have both sides
  1788. Result =
  1789. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1790. // directly (instead of EnableSelectedOperation) to pass
  1791. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1792. ((HasDirView[osLocal] && !IsSideLocalBrowser(osRemote) &&
  1793. DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1794. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1795. }
  1796. else if (ListType == ccltBoth)
  1797. {
  1798. DebugAssert(!IsLocalBrowserMode());
  1799. Result = 1;
  1800. }
  1801. else
  1802. {
  1803. Result = -1;
  1804. }
  1805. }
  1806. else
  1807. {
  1808. if ((ListType == ccltAll) ||
  1809. ((ListType == ccltFile) && (!IsSideLocalBrowser(FCurrentSide) || FLAGCLEAR(Command.Params, ccRemoteFiles))))
  1810. {
  1811. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1812. }
  1813. else
  1814. {
  1815. Result = -1;
  1816. }
  1817. }
  1818. if ((Result > 0) &&
  1819. LocalCustomCommand.IsSessionCommand(Cmd) &&
  1820. !HasActiveTerminal())
  1821. {
  1822. Result = 0;
  1823. }
  1824. }
  1825. return Result;
  1826. }
  1827. //---------------------------------------------------------------------------
  1828. void __fastcall TCustomScpExplorerForm::RemoteCustomCommand(
  1829. TStrings * FileList, const TCustomCommandType & ACommand,
  1830. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  1831. {
  1832. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1833. {
  1834. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1835. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1836. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1837. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1838. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1839. bool Capture =
  1840. FLAGSET(ACommand.Params, ccShowResults) ||
  1841. FLAGSET(ACommand.Params, ccCopyResults) ||
  1842. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1843. TCaptureOutputEvent OutputEvent = NULL;
  1844. DebugAssert(FCapturedLog == NULL);
  1845. if (Capture)
  1846. {
  1847. FCapturedLog = new TStringList();
  1848. OutputEvent = TerminalCaptureLog;
  1849. }
  1850. try
  1851. {
  1852. if (!RemoteCustomCommand.IsFileCommand(Command))
  1853. {
  1854. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1855. OutputEvent);
  1856. }
  1857. else
  1858. {
  1859. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1860. }
  1861. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1862. {
  1863. if (FLAGSET(ACommand.Params, ccCopyResults))
  1864. {
  1865. CopyToClipboard(FCapturedLog);
  1866. }
  1867. if (FLAGSET(ACommand.Params, ccShowResults))
  1868. {
  1869. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1870. }
  1871. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1872. {
  1873. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1874. }
  1875. }
  1876. }
  1877. __finally
  1878. {
  1879. SAFE_DESTROY(FCapturedLog);
  1880. }
  1881. }
  1882. }
  1883. //---------------------------------------------------------------------------
  1884. void __fastcall TCustomScpExplorerForm::LocalCustomCommandPure(
  1885. TStrings * FileList, const TCustomCommandType & ACommand, const UnicodeString & Command, TStrings * ALocalFileList,
  1886. const TCustomCommandData & Data, bool LocalFileCommand, bool FileListCommand, UnicodeString * POutput)
  1887. {
  1888. DebugAssert(!IsLocalBrowserMode());
  1889. TStrings * LocalFileList = NULL;
  1890. TStrings * RemoteFileList = NULL;
  1891. TStrings * RemoteFileListFull = NULL;
  1892. try
  1893. {
  1894. if (LocalFileCommand)
  1895. {
  1896. if (ALocalFileList == NULL)
  1897. {
  1898. DebugAssert(HasDirView[osLocal]);
  1899. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1900. // directly (instead of EnableSelectedOperation) to pass
  1901. // false to FocusedFileOnlyWhenFocused
  1902. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1903. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1904. }
  1905. else
  1906. {
  1907. LocalFileList = ALocalFileList;
  1908. }
  1909. if (FileListCommand)
  1910. {
  1911. if (LocalFileList->Count != 1)
  1912. {
  1913. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1914. }
  1915. }
  1916. else
  1917. {
  1918. if ((LocalFileList->Count != 1) &&
  1919. (FileList->Count != 1) &&
  1920. (LocalFileList->Count != FileList->Count))
  1921. {
  1922. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1923. }
  1924. }
  1925. }
  1926. UnicodeString RootTempDir;
  1927. UnicodeString TempDir;
  1928. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1929. if (!RemoteFiles)
  1930. {
  1931. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1932. }
  1933. try
  1934. {
  1935. TDateTimes RemoteFileTimes;
  1936. if (RemoteFiles)
  1937. {
  1938. RemoteFileList = FileList;
  1939. }
  1940. else
  1941. {
  1942. RemoteFileList = new TStringList();
  1943. TMakeLocalFileListParams MakeFileListParam;
  1944. MakeFileListParam.FileList = RemoteFileList;
  1945. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1946. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1947. MakeFileListParam.Recursive =
  1948. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1949. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1950. if (!MakeFileListParam.Recursive)
  1951. {
  1952. RemoteFileTimes.clear();
  1953. RemoteFileListFull = new TStringList();
  1954. MakeFileListParam.FileList = RemoteFileListFull;
  1955. MakeFileListParam.Recursive = true;
  1956. MakeFileListParam.IncludeDirs = false;
  1957. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1958. }
  1959. else
  1960. {
  1961. RemoteFileListFull = RemoteFileList;
  1962. }
  1963. }
  1964. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1965. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1966. if (!NonBlocking)
  1967. {
  1968. int Count;
  1969. if (FileListCommand)
  1970. {
  1971. Count = 1;
  1972. }
  1973. else if (LocalFileCommand)
  1974. {
  1975. Count = std::max(LocalFileList->Count, RemoteFileList->Count);
  1976. }
  1977. else
  1978. {
  1979. Count = RemoteFileList->Count;
  1980. }
  1981. Progress.Start(foCustomCommand, osRemote, Count);
  1982. DebugAssert(FProgressForm != NULL);
  1983. FProgressForm->ReadOnly = true;
  1984. }
  1985. try
  1986. {
  1987. if (FileListCommand)
  1988. {
  1989. UnicodeString LocalFile;
  1990. // MakeFileList does not delimit filenames
  1991. UnicodeString FileList = MakeFileList(RemoteFileList);
  1992. if (LocalFileCommand)
  1993. {
  1994. DebugAssert(LocalFileList->Count == 1);
  1995. LocalFile = LocalFileList->Strings[0];
  1996. }
  1997. TLocalCustomCommand CustomCommand(Data,
  1998. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1999. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  2000. if (NonBlocking)
  2001. {
  2002. DebugAssert(!POutput);
  2003. ExecuteShellChecked(ShellCommand);
  2004. }
  2005. else
  2006. {
  2007. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput);
  2008. }
  2009. }
  2010. else if (LocalFileCommand)
  2011. {
  2012. if (LocalFileList->Count == 1)
  2013. {
  2014. UnicodeString LocalFile = LocalFileList->Strings[0];
  2015. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2016. {
  2017. UnicodeString FileName = RemoteFileList->Strings[Index];
  2018. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2019. Progress.SetFile(FileNameForProgress);
  2020. TLocalCustomCommand CustomCommand(Data,
  2021. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  2022. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2023. TOnceDoneOperation OnceDoneOperation;
  2024. // Do not unselect anything, as it won't work with two panels anyway
  2025. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2026. }
  2027. }
  2028. else if (RemoteFileList->Count == 1)
  2029. {
  2030. UnicodeString FileName = RemoteFileList->Strings[0];
  2031. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2032. {
  2033. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2034. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2035. Progress.SetFile(LocalFileNameOnly);
  2036. TLocalCustomCommand CustomCommand(
  2037. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2038. FileName, LocalFileName, L"");
  2039. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2040. TOnceDoneOperation OnceDoneOperation;
  2041. // Do not unselect anything, as it won't work with two panels anyway
  2042. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2043. }
  2044. }
  2045. else
  2046. {
  2047. if (LocalFileList->Count != RemoteFileList->Count)
  2048. {
  2049. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  2050. }
  2051. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2052. {
  2053. UnicodeString FileName = RemoteFileList->Strings[Index];
  2054. UnicodeString LocalFileName = LocalFileList->Strings[Index];
  2055. UnicodeString LocalFileNameOnly = ExtractFileName(LocalFileName);
  2056. Progress.SetFile(LocalFileNameOnly); // sic
  2057. TLocalCustomCommand CustomCommand(
  2058. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2059. FileName, LocalFileName, L"");
  2060. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2061. TOnceDoneOperation OnceDoneOperation;
  2062. // Do not unselect anything, as it won't work with two panels anyway
  2063. Progress.Finish(UnicodeString(), true, OnceDoneOperation);
  2064. }
  2065. }
  2066. }
  2067. else
  2068. {
  2069. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  2070. {
  2071. UnicodeString FileName = RemoteFileList->Strings[Index];
  2072. UnicodeString FileNameForProgress = RemoteFiles ? FileName : ExtractFileName(FileName);
  2073. Progress.SetFile(FileNameForProgress);
  2074. TLocalCustomCommand CustomCommand(Data,
  2075. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  2076. FileName, L"", L"");
  2077. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2078. TOnceDoneOperation OnceDoneOperation;
  2079. Progress.Finish(FileNameForProgress, true, OnceDoneOperation);
  2080. }
  2081. }
  2082. }
  2083. __finally
  2084. {
  2085. if (!NonBlocking)
  2086. {
  2087. Progress.Stop();
  2088. }
  2089. }
  2090. DebugAssert(!FAutoOperation);
  2091. if (!RemoteFiles)
  2092. {
  2093. TempDir = IncludeTrailingBackslash(TempDir);
  2094. for (int Index = 0; Index < RemoteFileListFull->Count; Index++)
  2095. {
  2096. UnicodeString FileName = RemoteFileListFull->Strings[Index];
  2097. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  2098. // Skip directories, process only nested files.
  2099. // The check is redundant as FileAge fails for directories anyway.
  2100. !DirectoryExists(FileName))
  2101. {
  2102. UnicodeString RemoteDir =
  2103. UnixExtractFileDir(
  2104. UnixIncludeTrailingBackslash(Terminal->CurrentDirectory) +
  2105. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  2106. TDateTime NewTime;
  2107. if (FileAge(FileName, NewTime) &&
  2108. (NewTime != RemoteFileTimes[Index]))
  2109. {
  2110. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2111. TemporaryFileCopyParam(CopyParam);
  2112. CopyParam.FileMask = L"";
  2113. FAutoOperation = true;
  2114. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  2115. TemporaryFilesList->Add(FileName);
  2116. Terminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary, NULL);
  2117. }
  2118. }
  2119. }
  2120. }
  2121. }
  2122. __finally
  2123. {
  2124. FAutoOperation = false;
  2125. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  2126. {
  2127. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2128. }
  2129. }
  2130. }
  2131. __finally
  2132. {
  2133. if (RemoteFileList != FileList)
  2134. {
  2135. delete RemoteFileList;
  2136. }
  2137. if (LocalFileList != ALocalFileList)
  2138. {
  2139. delete LocalFileList;
  2140. }
  2141. if (RemoteFileListFull != RemoteFileList)
  2142. {
  2143. delete RemoteFileListFull;
  2144. }
  2145. }
  2146. }
  2147. //---------------------------------------------------------------------------
  2148. void __fastcall TCustomScpExplorerForm::LocalCustomCommandWithLocalFiles(
  2149. const TCustomCommandType & ACommand, const UnicodeString & Command, const TCustomCommandData & Data,
  2150. bool FileListCommand, UnicodeString * POutput)
  2151. {
  2152. std::unique_ptr<TStrings> SelectedFileList(DirView(osCurrent)->CreateFileList(false, true, NULL));
  2153. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  2154. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  2155. {
  2156. UnicodeString FileName = SelectedFileList->Strings[Index];
  2157. if (DirectoryExists(FileName))
  2158. {
  2159. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  2160. {
  2161. LocalFileList->Add(FileName);
  2162. }
  2163. if (FLAGSET(ACommand.Params, ccRecursive))
  2164. {
  2165. TMakeLocalFileListParams MakeFileListParam;
  2166. MakeFileListParam.FileList = LocalFileList.get();
  2167. MakeFileListParam.FileTimes = NULL;
  2168. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  2169. MakeFileListParam.Recursive = true;
  2170. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  2171. }
  2172. }
  2173. else
  2174. {
  2175. LocalFileList->Add(FileName);
  2176. }
  2177. }
  2178. UnicodeString RemotePath;
  2179. if (Terminal != NULL)
  2180. {
  2181. RemotePath = Terminal->CurrentDirectory;
  2182. }
  2183. if (FileListCommand)
  2184. {
  2185. UnicodeString FileList = MakeFileList(LocalFileList.get());
  2186. TLocalCustomCommand CustomCommand(
  2187. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2188. L"", L"", FileList);
  2189. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2190. }
  2191. else
  2192. {
  2193. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  2194. Progress.Start(foCustomCommand, osLocal, LocalFileList->Count);
  2195. DebugAssert(FProgressForm != NULL);
  2196. FProgressForm->ReadOnly = true;
  2197. try
  2198. {
  2199. for (int Index = 0; Index < LocalFileList->Count; Index++)
  2200. {
  2201. UnicodeString FileName = LocalFileList->Strings[Index];
  2202. Progress.SetFile(FileName);
  2203. TLocalCustomCommand CustomCommand(
  2204. Data, RemotePath, DefaultDownloadTargetDirectory(),
  2205. FileName, L"", L"");
  2206. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput);
  2207. TOnceDoneOperation OnceDoneOperation;
  2208. Progress.Finish(FileName, true, OnceDoneOperation);
  2209. }
  2210. }
  2211. __finally
  2212. {
  2213. Progress.Stop();
  2214. }
  2215. }
  2216. }
  2217. //---------------------------------------------------------------------------
  2218. void __fastcall TCustomScpExplorerForm::LocalCustomCommand(TStrings * FileList,
  2219. const TCustomCommandType & ACommand, TStrings * ALocalFileList,
  2220. const TCustomCommandData & Data, const UnicodeString & CommandCommand)
  2221. {
  2222. UnicodeString RemotePath = (Terminal != NULL) ? Terminal->CurrentDirectory : UnicodeString();
  2223. TLocalCustomCommand LocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory());
  2224. TWinInteractiveCustomCommand InteractiveCustomCommand(
  2225. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  2226. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  2227. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  2228. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  2229. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  2230. std::unique_ptr<UnicodeString> POutput;
  2231. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  2232. FLAGSET(ACommand.Params, ccCopyResults))
  2233. {
  2234. POutput.reset(new UnicodeString());
  2235. }
  2236. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  2237. FProgressSide = FCurrentSide;
  2238. if (!LocalCustomCommand.IsFileCommand(Command))
  2239. {
  2240. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  2241. }
  2242. // remote files?
  2243. else if (!IsSideLocalBrowser(FCurrentSide) || LocalFileCommand)
  2244. {
  2245. LocalCustomCommandPure(FileList, ACommand, Command, ALocalFileList, Data, LocalFileCommand, FileListCommand, POutput.get());
  2246. }
  2247. // local files
  2248. else
  2249. {
  2250. LocalCustomCommandWithLocalFiles(ACommand, Command, Data, FileListCommand, POutput.get());
  2251. }
  2252. if (POutput.get() != NULL)
  2253. {
  2254. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  2255. int P = POutput->Pos(sLineBreak);
  2256. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  2257. {
  2258. POutput->SetLength(P - 1);
  2259. }
  2260. // Copy even empty output to clipboard
  2261. if (FLAGSET(ACommand.Params, ccCopyResults))
  2262. {
  2263. CopyToClipboard(*POutput);
  2264. }
  2265. // But do not show an empty message box.
  2266. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  2267. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  2268. !POutput->IsEmpty())
  2269. {
  2270. TClipboardHandler ClipboardHandler;
  2271. ClipboardHandler.Text = *POutput;
  2272. TMessageParams Params;
  2273. TQueryButtonAlias Aliases[1];
  2274. Aliases[0].Button = qaRetry;
  2275. Aliases[0].Alias = LoadStr(EDIT_COPY);
  2276. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  2277. Params.Aliases = Aliases;
  2278. Params.AliasesCount = LENOF(Aliases);
  2279. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  2280. }
  2281. }
  2282. }
  2283. //---------------------------------------------------------------------------
  2284. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  2285. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  2286. {
  2287. TCustomCommandData Data;
  2288. UnicodeString Site;
  2289. UnicodeString RemotePath;
  2290. if (HasActiveTerminal())
  2291. {
  2292. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  2293. Data = TCustomCommandData(SessionData.get());
  2294. Site = Terminal->SessionData->SessionKey;
  2295. RemotePath = Terminal->CurrentDirectory;
  2296. }
  2297. UnicodeString HelpKeyword = ACommand.HomePage;
  2298. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  2299. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  2300. {
  2301. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  2302. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2303. {
  2304. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, RemotePath));
  2305. }
  2306. else
  2307. {
  2308. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, RemotePath, DefaultDownloadTargetDirectory()));
  2309. }
  2310. if (!DoCustomCommandOptionsDialog(
  2311. &ACommand, CustomCommandOptions.get(), NULL, TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site, NULL))
  2312. {
  2313. Abort();
  2314. }
  2315. }
  2316. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  2317. if (FLAGCLEAR(ACommand.Params, ccLocal))
  2318. {
  2319. RemoteCustomCommand(FileList, ACommand, Data, CommandCommand);
  2320. }
  2321. else
  2322. {
  2323. LocalCustomCommand(FileList, ACommand, ALocalFileList, Data, CommandCommand);
  2324. }
  2325. }
  2326. //---------------------------------------------------------------------------
  2327. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  2328. const TCustomCommandType & Command)
  2329. {
  2330. DebugAssert(FCustomCommandLocalFileList != NULL);
  2331. DebugAssert(FCustomCommandRemoteFileList != NULL);
  2332. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  2333. TStrings * LocalFileList = new TStringList();
  2334. TStrings * RemoteFileList = new TStringList();
  2335. try
  2336. {
  2337. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  2338. {
  2339. LocalFileList->Clear();
  2340. LocalFileList->AddObject(
  2341. FCustomCommandLocalFileList->Strings[Index],
  2342. FCustomCommandLocalFileList->Objects[Index]);
  2343. RemoteFileList->Clear();
  2344. RemoteFileList->AddObject(
  2345. FCustomCommandRemoteFileList->Strings[Index],
  2346. FCustomCommandRemoteFileList->Objects[Index]);
  2347. CustomCommand(RemoteFileList, Command, LocalFileList);
  2348. }
  2349. }
  2350. __finally
  2351. {
  2352. delete LocalFileList;
  2353. delete RemoteFileList;
  2354. }
  2355. }
  2356. //---------------------------------------------------------------------------
  2357. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  2358. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  2359. {
  2360. delete FCustomCommandLocalFileList;
  2361. delete FCustomCommandRemoteFileList;
  2362. // takeover ownership,
  2363. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  2364. FCustomCommandLocalFileList = LocalFileList;
  2365. FCustomCommandRemoteFileList = RemoteFileList;
  2366. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  2367. if (Button != NULL)
  2368. {
  2369. FCustomCommandMenu->Items->Clear();
  2370. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth, NULL);
  2371. MenuPopup(FCustomCommandMenu, Button);
  2372. }
  2373. else
  2374. {
  2375. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  2376. }
  2377. }
  2378. //---------------------------------------------------------------------------
  2379. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  2380. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  2381. {
  2382. DebugAssert(FCapturedLog != NULL);
  2383. if ((OutputType == cotOutput) || (OutputType == cotError))
  2384. {
  2385. FCapturedLog->Add(AddedLine);
  2386. }
  2387. }
  2388. //---------------------------------------------------------------------------
  2389. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2390. TOperationSide Side)
  2391. {
  2392. return
  2393. (Side == osOther) &&
  2394. ((Control == DirView(osOther)) || (Control == DriveView(osOther)));
  2395. }
  2396. //---------------------------------------------------------------------------
  2397. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2398. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2399. {
  2400. TTBItemOptions O;
  2401. O = Item->Options;
  2402. TCustomDirView * DView = DirView(Side);
  2403. if ((DView->ItemFocused != NULL) &&
  2404. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2405. // when resolving links is disabled, default action is to enter the directory,
  2406. // no matter what DoubleClickAction is configured to
  2407. (IsSideLocalBrowser(Side) || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles()) &&
  2408. // Can only Edit files, but can Open/Copy even directories
  2409. ((DoubleClickAction != dcaEdit) ||
  2410. !DView->ItemIsDirectory(DView->ItemFocused)))
  2411. {
  2412. Item->Options = O << tboDefault;
  2413. }
  2414. else
  2415. {
  2416. Item->Options = O >> tboDefault;
  2417. }
  2418. }
  2419. //---------------------------------------------------------------------------
  2420. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2421. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2422. {
  2423. TCustomDirView * DView = DirView(Side);
  2424. TListItem * Item = DView->ItemFocused;
  2425. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2426. EnableFocusedOperation[Side])
  2427. {
  2428. TPoint ClientPoint;
  2429. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2430. TPoint(0, 0) : MousePos;
  2431. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2432. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2433. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2434. }
  2435. }
  2436. //---------------------------------------------------------------------------
  2437. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2438. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2439. {
  2440. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2441. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2442. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2443. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2444. Handled = true;
  2445. }
  2446. //---------------------------------------------------------------------------
  2447. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2448. {
  2449. }
  2450. //---------------------------------------------------------------------------
  2451. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2452. {
  2453. DebugAssert(FErrorList == NULL);
  2454. if (WinConfiguration->ContinueOnError)
  2455. {
  2456. FErrorList = new TStringList();
  2457. Configuration->Usage->Inc(L"ContinuationsOnError");
  2458. }
  2459. NonVisualDataModule->StartBusy();
  2460. }
  2461. //---------------------------------------------------------------------------
  2462. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2463. {
  2464. NonVisualDataModule->EndBusy();
  2465. if (FErrorList)
  2466. {
  2467. HandleErrorList(FErrorList);
  2468. }
  2469. }
  2470. //---------------------------------------------------------------------------
  2471. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2472. const TCopyParamType & CopyParam)
  2473. {
  2474. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2475. {
  2476. Configuration->Usage->Inc(L"FileMaskUses");
  2477. }
  2478. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2479. {
  2480. Configuration->Usage->Inc(L"OperationMaskUses");
  2481. }
  2482. }
  2483. //---------------------------------------------------------------------------
  2484. bool __fastcall TCustomScpExplorerForm::ExecuteCopyMoveFileOperation(
  2485. TFileOperation Operation, TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * AParam)
  2486. {
  2487. DebugAssert(!IsLocalBrowserMode());
  2488. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2489. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2490. TTransferOperationParam DefaultParam;
  2491. TTransferOperationParam & Param = (AParam != NULL) ? *static_cast<TTransferOperationParam *>(AParam) : DefaultParam;
  2492. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2493. switch (Param.Queue)
  2494. {
  2495. case asOn:
  2496. CopyParam.Queue = true;
  2497. break;
  2498. case asOff:
  2499. CopyParam.Queue = false;
  2500. break;
  2501. case asAuto:
  2502. default:
  2503. // keep default
  2504. break;
  2505. }
  2506. bool Result =
  2507. CopyParamDialog(Direction, Type, Param.Temp, FileList, Param.TargetDirectory, CopyParam, !NoConfirmation, Param.DragDrop, Param.Options);
  2508. if (Result)
  2509. {
  2510. DebugAssert(Terminal);
  2511. bool SelectionRestored = false;
  2512. TCustomDirView * DView = NULL;
  2513. if (HasDirView[Side])
  2514. {
  2515. DView = DirView(Side);
  2516. DView->SaveSelection();
  2517. DView->SaveSelectedNames();
  2518. }
  2519. UpdateCopyParamCounters(CopyParam);
  2520. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2521. DebugAssert(FTransferResumeList == NULL);
  2522. FTransferResumeList = Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2523. FMoveToQueue = false;
  2524. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2525. try
  2526. {
  2527. TStrings * PermanentFileList;
  2528. std::unique_ptr<TStrings> PermanentFileListOwner;
  2529. try
  2530. {
  2531. if (Side == osLocal)
  2532. {
  2533. PermanentFileList = FileList;
  2534. Params |= FLAGMASK(Param.Temp, cpTemporary);
  2535. Terminal->CopyToRemote(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2536. if (Operation == foMove)
  2537. {
  2538. ReloadLocalDirectory();
  2539. if (DView != NULL)
  2540. {
  2541. DView->RestoreSelection();
  2542. }
  2543. SelectionRestored = true;
  2544. }
  2545. }
  2546. else
  2547. {
  2548. // Clone the file list as it may refer to current directory files,
  2549. // which get destroyed, when the source directory is reloaded after foMove operation.
  2550. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2551. // But for a hotfix, we are not going to do such a big change.
  2552. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2553. PermanentFileList = PermanentFileListOwner.get();
  2554. try
  2555. {
  2556. Terminal->CopyToLocal(FileList, Param.TargetDirectory, &CopyParam, Params, NULL);
  2557. }
  2558. __finally
  2559. {
  2560. if (Operation == foMove)
  2561. {
  2562. if (DView != NULL)
  2563. {
  2564. DView->RestoreSelection();
  2565. }
  2566. SelectionRestored = true;
  2567. }
  2568. ReloadLocalDirectory(Param.TargetDirectory);
  2569. }
  2570. }
  2571. // When the transfer batch is aborted between individual file transfers, the Abort is not called.
  2572. if (FMoveToQueue)
  2573. {
  2574. Abort();
  2575. }
  2576. }
  2577. catch (EAbort &)
  2578. {
  2579. if (FMoveToQueue)
  2580. {
  2581. Params |= (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2582. DebugAssert(CopyParam.TransferSkipList == NULL);
  2583. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2584. if (TransferResumeList->Count > 0)
  2585. {
  2586. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2587. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2588. }
  2589. CopyParam.TransferSkipList = TransferResumeList.release();
  2590. // not really needed, just to keep it consistent with TransferResumeList
  2591. FTransferResumeList = NULL;
  2592. FMoveToQueue = false;
  2593. Configuration->Usage->Inc("MovesToBackground");
  2594. AddQueueItem(Queue, Direction, PermanentFileList, Param.TargetDirectory, CopyParam, Params);
  2595. ClearTransferSourceSelection(Direction);
  2596. }
  2597. throw;
  2598. }
  2599. }
  2600. __finally
  2601. {
  2602. if (!SelectionRestored && (DView != NULL))
  2603. {
  2604. DView->DiscardSavedSelection();
  2605. }
  2606. FTransferResumeList = NULL;
  2607. }
  2608. }
  2609. return Result;
  2610. }
  2611. //---------------------------------------------------------------------------
  2612. bool __fastcall TCustomScpExplorerForm::ExecuteDeleteFileOperation(
  2613. TOperationSide Side, TStrings * FileList, void * Param)
  2614. {
  2615. DebugAssert(FileList->Count);
  2616. // We deliberately do not toggle alternative flag (Param), but use OR,
  2617. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2618. // shortcut of CurrentDeleteAlternativeAction
  2619. bool Alternative =
  2620. bool(Param) || UseAlternativeFunction();
  2621. bool Recycle;
  2622. if (IsSideLocalBrowser(Side))
  2623. {
  2624. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2625. }
  2626. else
  2627. {
  2628. Recycle =
  2629. (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2630. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2631. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2632. }
  2633. bool Result = !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2634. if (!Result)
  2635. {
  2636. UnicodeString Query;
  2637. if (FileList->Count == 1)
  2638. {
  2639. if (IsSideLocalBrowser(Side))
  2640. {
  2641. Query = ExtractFileName(FileList->Strings[0]);
  2642. }
  2643. else
  2644. {
  2645. Query = UnixExtractFileName(FileList->Strings[0]);
  2646. }
  2647. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2648. }
  2649. else
  2650. {
  2651. Query = FMTLOAD((Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2652. }
  2653. TMessageParams Params(mpNeverAskAgainCheck);
  2654. Params.ImageName = L"Delete file";
  2655. unsigned int Answer =
  2656. MessageDialog(MainInstructions(Query), qtConfirmation, qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2657. if (Answer == qaNeverAskAgain)
  2658. {
  2659. Result = true;
  2660. if (Recycle)
  2661. {
  2662. WinConfiguration->ConfirmRecycling = false;
  2663. }
  2664. else
  2665. {
  2666. WinConfiguration->ConfirmDeleting = false;
  2667. }
  2668. }
  2669. else
  2670. {
  2671. Result = (Answer == qaOK);
  2672. }
  2673. }
  2674. if (Result)
  2675. {
  2676. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2677. }
  2678. return Result;
  2679. }
  2680. //---------------------------------------------------------------------------
  2681. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2682. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2683. {
  2684. TAutoBatch AutoBatch(this);
  2685. bool Result;
  2686. if (TFileOperationProgressType::IsTransferOperation(Operation))
  2687. {
  2688. Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2689. }
  2690. else if (Operation == foRename)
  2691. {
  2692. DebugAssert(DirView(Side)->ItemFocused);
  2693. DirView(Side)->ItemFocused->EditCaption();
  2694. Result = true;
  2695. }
  2696. else if (Operation == foDelete)
  2697. {
  2698. Result = ExecuteDeleteFileOperation(Side, FileList, Param);
  2699. }
  2700. else if (Operation == foSetProperties)
  2701. {
  2702. DirView(osRemote)->SaveSelectedNames();
  2703. Result = SetProperties(Side, FileList);
  2704. }
  2705. else if (Operation == foCustomCommand)
  2706. {
  2707. DebugAssert(Param);
  2708. DebugAssert(Side == osRemote); // Side carries no meaning for foCustomCommand
  2709. DirView(osRemote)->SaveSelectedNames();
  2710. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2711. CustomCommand(FileList, *Command, NULL);
  2712. Result = true;
  2713. }
  2714. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2715. {
  2716. DebugAssert(!IsSideLocalBrowser(Side));
  2717. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2718. (Operation == foRemoteMove), reinterpret_cast<TManagedTerminal *>(Param));
  2719. }
  2720. else if (Operation == foLock)
  2721. {
  2722. DebugAssert(!IsSideLocalBrowser(Side));
  2723. LockFiles(FileList, true);
  2724. Result = true;
  2725. }
  2726. else if (Operation == foUnlock)
  2727. {
  2728. DebugAssert(!IsSideLocalBrowser(Side));
  2729. LockFiles(FileList, false);
  2730. Result = true;
  2731. }
  2732. else
  2733. {
  2734. DebugFail();
  2735. }
  2736. return Result;
  2737. }
  2738. //---------------------------------------------------------------------------
  2739. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2740. {
  2741. if (Side == osCurrent)
  2742. {
  2743. Side = FCurrentSide;
  2744. }
  2745. return Side;
  2746. }
  2747. //---------------------------------------------------------------------------
  2748. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2749. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2750. {
  2751. Side = GetSide(Side);
  2752. bool Result;
  2753. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, IsSideLocalBrowser(Side), NULL);
  2754. try
  2755. {
  2756. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2757. }
  2758. __finally
  2759. {
  2760. delete FileList;
  2761. }
  2762. return Result;
  2763. }
  2764. //---------------------------------------------------------------------------
  2765. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2766. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2767. bool NoConfirmation, void * Param)
  2768. {
  2769. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2770. {
  2771. if (TFileOperationProgressType::IsTransferOperation(Operation))
  2772. {
  2773. DebugAssert(!IsLocalBrowserMode());
  2774. if (GetSide(Side) == osLocal)
  2775. {
  2776. Configuration->Usage->Inc(L"UploadsCommand");
  2777. }
  2778. else
  2779. {
  2780. Configuration->Usage->Inc(L"DownloadsCommand");
  2781. }
  2782. }
  2783. }
  2784. }
  2785. //---------------------------------------------------------------------------
  2786. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2787. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2788. {
  2789. TTransferOperationParam Param;
  2790. if ((WinConfiguration->Interface != ifCommander) ||
  2791. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2792. {
  2793. Flags &= ~cocShortCutHint;
  2794. }
  2795. TCustomDirView * DView = DirView(Side);
  2796. Param.Options =
  2797. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2798. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2799. if (FLAGSET(Flags, cocQueue))
  2800. {
  2801. Param.Queue = asOn;
  2802. }
  2803. else if (FLAGSET(Flags, cocNonQueue))
  2804. {
  2805. Param.Queue = asOff;
  2806. }
  2807. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2808. }
  2809. //---------------------------------------------------------------------------
  2810. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2811. {
  2812. int Count = ErrorList->Count;
  2813. try
  2814. {
  2815. if (ErrorList->Count)
  2816. {
  2817. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2818. if (MessageDialog(Message, qtError,
  2819. qaOK | qaCancel, HELP_NONE) == qaOK)
  2820. {
  2821. unsigned int Answer;
  2822. int Index = 0;
  2823. do
  2824. {
  2825. DebugAssert(Index >= 0 && Index < Count);
  2826. TQueryButtonAlias Aliases[2];
  2827. Aliases[0].Button = qaYes;
  2828. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2829. Aliases[1].Button = qaNo;
  2830. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2831. TMessageParams Params;
  2832. Params.Aliases = Aliases;
  2833. Params.AliasesCount = LENOF(Aliases);
  2834. int No = Index + 1;
  2835. UnicodeString Message = ErrorList->Strings[Index];
  2836. UnicodeString AMainInstructions;
  2837. UnicodeString Details;
  2838. if (ExtractMainInstructions(Message, AMainInstructions))
  2839. {
  2840. Details = Message;
  2841. Message = AMainInstructions;
  2842. }
  2843. Message = MainInstructions(FMTLOAD(ERROR_LIST_NUMBER, (No, Count, Message))) + Details;
  2844. Answer = MoreMessageDialog(
  2845. Message,
  2846. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2847. (Index ? qaYes : 0) | (Index < Count - 1 ? qaNo : 0) |
  2848. qaOK, HELP_NONE, &Params);
  2849. if (Answer == qaNo)
  2850. {
  2851. Index++;
  2852. }
  2853. if (Answer == qaYes)
  2854. {
  2855. Index--;
  2856. }
  2857. }
  2858. while (Answer != qaOK);
  2859. }
  2860. }
  2861. }
  2862. __finally
  2863. {
  2864. TStrings * List = ErrorList;
  2865. ErrorList = NULL;
  2866. for (int i = 0; i < Count; i++)
  2867. {
  2868. delete List->Objects[i];
  2869. }
  2870. delete List;
  2871. }
  2872. }
  2873. //---------------------------------------------------------------------------
  2874. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2875. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2876. {
  2877. // needed for checking filemasks, as there's no directory object
  2878. // associated with the file object
  2879. File->FullFileName = FullFileName;
  2880. TFileMasks::TParams MaskParams;
  2881. MaskParams.Size = File->Size;
  2882. MaskParams.Modification = File->Modification;
  2883. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2884. }
  2885. //---------------------------------------------------------------------------
  2886. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2887. {
  2888. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2889. Side = GetSide(Side);
  2890. TCustomDirView * DView = DirView(Side);
  2891. TListItem * FocusedItem = DView->ItemFocused;
  2892. UnicodeString Name;
  2893. if ((FocusedItem != NULL) && !DView->ItemIsDirectory(FocusedItem))
  2894. {
  2895. Name = DView->ItemFileName(FocusedItem);
  2896. }
  2897. else
  2898. {
  2899. Name = LoadStr(NEW_FILE);
  2900. }
  2901. UnicodeString Names = Name;
  2902. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2903. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2904. HELP_EDIT_NEW, History.get(), true, NULL, true, 400))
  2905. {
  2906. while (!Names.IsEmpty())
  2907. {
  2908. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2909. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2910. UnicodeString TargetFileName;
  2911. UnicodeString LocalFileName;
  2912. UnicodeString RootTempDir;
  2913. UnicodeString TempDir;
  2914. UnicodeString RemoteDirectory;
  2915. bool ExistingFile = false;
  2916. if (!IsSideLocalBrowser(Side))
  2917. {
  2918. Name = AbsolutePath(Terminal->CurrentDirectory, Name);
  2919. TRemoteFile * File = NULL;
  2920. if (Terminal->FileExists(Name, &File) &&
  2921. !File->IsDirectory)
  2922. {
  2923. try
  2924. {
  2925. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2926. ExistingFile = true;
  2927. }
  2928. __finally
  2929. {
  2930. delete File;
  2931. }
  2932. }
  2933. if (!ExistingFile)
  2934. {
  2935. RemoteDirectory = UnixExtractFilePath(Name);
  2936. TemporaryDirectoryForRemoteFiles(
  2937. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2938. TargetFileName = UnixExtractFileName(Name);
  2939. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2940. LocalFileName = TempDir +
  2941. // We probably do not want to trim the VMS version here
  2942. Terminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2943. }
  2944. }
  2945. else
  2946. {
  2947. if (ExtractFilePath(Name).IsEmpty())
  2948. {
  2949. LocalFileName = IncludeTrailingBackslash(DView->PathName) + Name;
  2950. }
  2951. else
  2952. {
  2953. LocalFileName = ExpandFileName(Name);
  2954. }
  2955. TargetFileName = ExtractFileName(Name);
  2956. }
  2957. if (!ExistingFile)
  2958. {
  2959. bool NewFile = !FileExists(ApiPath(LocalFileName));
  2960. if (NewFile)
  2961. {
  2962. int File = FileCreate(ApiPath(LocalFileName));
  2963. if (File < 0)
  2964. {
  2965. if (!RootTempDir.IsEmpty())
  2966. {
  2967. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2968. }
  2969. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2970. }
  2971. else
  2972. {
  2973. FileClose(File);
  2974. }
  2975. }
  2976. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2977. const TEditorData * ExternalEditor = NULL;
  2978. TFileMasks::TParams MaskParams; // size not known
  2979. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2980. false, MaskParams);
  2981. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2982. ExternalEditor, RootTempDir, RemoteDirectory, NewFile);
  2983. }
  2984. }
  2985. }
  2986. }
  2987. //---------------------------------------------------------------------------
  2988. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2989. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2990. {
  2991. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2992. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2993. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2994. return
  2995. ((ExecuteFileBy == efInternalEditor)) ||
  2996. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2997. }
  2998. //---------------------------------------------------------------------------
  2999. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  3000. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  3001. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  3002. UnicodeString RemoteDirectory, bool NewFile)
  3003. {
  3004. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3005. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3006. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3007. DebugAssert(ExecuteFileBy != efDefaultEditor);
  3008. Side = GetSide(Side);
  3009. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  3010. if (!IsSideLocalBrowser(Side))
  3011. {
  3012. Data->Terminal = Terminal;
  3013. Data->Queue = Queue;
  3014. Data->SessionData = CloneCurrentSessionData();
  3015. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  3016. Data->RemoteDirectory = RemoteDirectory;
  3017. Data->SessionName = Terminal->SessionData->SessionName;
  3018. Data->LocalRootDirectory = LocalRootDirectory;
  3019. Data->OriginalFileName = OriginalFileName;
  3020. Data->Command = L""; // will be changed later for external editor
  3021. }
  3022. if (ExecuteFileBy == efInternalEditor)
  3023. {
  3024. if (!IsSideLocalBrowser(Side))
  3025. {
  3026. UnicodeString RemotePath = UnixCombinePaths(RemoteDirectory, OriginalFileName);
  3027. UnicodeString Caption = RemotePath + TitleSeparator + Terminal->SessionData->SessionName;
  3028. TForm * Editor;
  3029. try
  3030. {
  3031. TNotifyEvent OnFileChanged = NULL;
  3032. TNotifyEvent OnSaveAll = NULL;
  3033. TAnyModifiedEvent OnAnyModified = NULL;
  3034. // Edited files are uploaded in background queue, what we do not support with encrypted files
  3035. if (Terminal->IsCapable[fcBackgroundTransfers])
  3036. {
  3037. OnFileChanged = FEditorManager->FileChanged;
  3038. OnSaveAll = SaveAllInternalEditors;
  3039. OnAnyModified = AnyInternalEditorModified;
  3040. }
  3041. Editor = ShowEditorForm(FileName, this, OnFileChanged,
  3042. FEditorManager->FileReload, FEditorManager->FileClosed,
  3043. OnSaveAll, OnAnyModified,
  3044. Caption, StandaloneOperation, SessionColor, Terminal->SessionData->InternalEditorEncoding, NewFile);
  3045. }
  3046. catch(...)
  3047. {
  3048. if (!LocalRootDirectory.IsEmpty())
  3049. {
  3050. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  3051. }
  3052. throw;
  3053. }
  3054. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  3055. }
  3056. else
  3057. {
  3058. DebugAssert(!StandaloneOperation);
  3059. TForm * Editor =
  3060. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  3061. SaveAllInternalEditors, AnyInternalEditorModified,
  3062. L"", false, SessionColor, -1, NewFile);
  3063. FLocalEditors->Add(Editor);
  3064. }
  3065. }
  3066. else
  3067. {
  3068. HANDLE Process;
  3069. if (ExecuteFileBy == efExternalEditor)
  3070. {
  3071. UnicodeString Program, Params, Dir;
  3072. Data->Command = ExternalEditor->ExternalEditor;
  3073. ReformatFileNameCommand(Data->Command);
  3074. SplitCommand(Data->Command, Program, Params, Dir);
  3075. Params = ExpandFileNameCommand(Params, FileName);
  3076. Program = ExpandEnvironmentVariables(Program);
  3077. if (!ExecuteShell(Program, Params, Process))
  3078. {
  3079. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  3080. }
  3081. }
  3082. else
  3083. {
  3084. DebugAssert(!IsSideLocalBrowser(Side));
  3085. if (!ExecuteShell(FileName, L"", Process))
  3086. {
  3087. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  3088. }
  3089. }
  3090. if (IsSideLocalBrowser(Side) ||
  3091. ((ExecuteFileBy == efShell) &&
  3092. !WinConfiguration->Editor.SDIShellEditor) ||
  3093. ((ExecuteFileBy == efExternalEditor) &&
  3094. !ExternalEditor->SDIExternalEditor))
  3095. {
  3096. // no need for handle
  3097. if (Process != NULL)
  3098. {
  3099. DebugCheck(CloseHandle(Process));
  3100. }
  3101. Process = INVALID_HANDLE_VALUE;
  3102. }
  3103. else
  3104. {
  3105. if (Process == NULL)
  3106. {
  3107. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  3108. }
  3109. }
  3110. if (!IsSideLocalBrowser(Side))
  3111. {
  3112. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  3113. }
  3114. }
  3115. }
  3116. //---------------------------------------------------------------------------
  3117. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  3118. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3119. void * /*Arg*/)
  3120. {
  3121. if (Token != NULL)
  3122. {
  3123. EditorFormFileSave(static_cast<TForm *>(Token));
  3124. }
  3125. }
  3126. //---------------------------------------------------------------------------
  3127. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  3128. {
  3129. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  3130. {
  3131. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  3132. }
  3133. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  3134. }
  3135. //---------------------------------------------------------------------------
  3136. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  3137. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  3138. void * Arg)
  3139. {
  3140. if ((Token != NULL) &&
  3141. IsEditorFormModified(static_cast<TForm *>(Token)))
  3142. {
  3143. *static_cast<bool *>(Arg) = true;
  3144. }
  3145. }
  3146. //---------------------------------------------------------------------------
  3147. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  3148. TObject * /*Sender*/, bool & Modified)
  3149. {
  3150. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  3151. {
  3152. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  3153. {
  3154. Modified = true;
  3155. }
  3156. }
  3157. if (!Modified)
  3158. {
  3159. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  3160. }
  3161. }
  3162. //---------------------------------------------------------------------------
  3163. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  3164. {
  3165. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  3166. }
  3167. //---------------------------------------------------------------------------
  3168. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  3169. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  3170. UnicodeString & Result, UnicodeString & RootDirectory)
  3171. {
  3172. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  3173. {
  3174. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3175. Result = RootDirectory;
  3176. }
  3177. else
  3178. {
  3179. RootDirectory = L"";
  3180. Result = WinConfiguration->ExpandedTemporaryDirectory();
  3181. Result = IncludeTrailingBackslash(Result);
  3182. }
  3183. if (WinConfiguration->TemporaryDirectoryAppendSession)
  3184. {
  3185. Result = IncludeTrailingBackslash(Result + MakeValidFileName(Terminal->SessionData->SessionName));
  3186. }
  3187. if (WinConfiguration->TemporaryDirectoryAppendPath)
  3188. {
  3189. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  3190. {
  3191. RemoteDirectory.Delete(1, 1);
  3192. }
  3193. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  3194. }
  3195. if (!ForceDirectories(ApiPath(Result)))
  3196. {
  3197. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  3198. }
  3199. }
  3200. //---------------------------------------------------------------------------
  3201. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  3202. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  3203. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  3204. {
  3205. DebugAssert(!IsLocalBrowserMode());
  3206. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3207. if (ForceText)
  3208. {
  3209. CopyParam.TransferMode = tmAscii;
  3210. }
  3211. TemporaryFileCopyParam(CopyParam);
  3212. if (AllFiles)
  3213. {
  3214. CopyParam.IncludeFileMask = TFileMasks();
  3215. }
  3216. if (TempDir.IsEmpty())
  3217. {
  3218. TemporaryDirectoryForRemoteFiles(Terminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  3219. }
  3220. DebugAssert(!FAutoOperation);
  3221. FAutoOperation = AutoOperation;
  3222. Terminal->ExceptionOnFail = true;
  3223. try
  3224. {
  3225. try
  3226. {
  3227. // turn off confirmations, as for MDI editors we may possibly download
  3228. // the same file over
  3229. Terminal->CopyToLocal(
  3230. FileList, TempDir, &CopyParam, cpNoConfirmation | cpTemporary, NULL);
  3231. if (GetTargetNames)
  3232. {
  3233. for (int i = 0; i < FileList->Count; i++)
  3234. {
  3235. FileList->Strings[i] =
  3236. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  3237. }
  3238. }
  3239. }
  3240. catch(...)
  3241. {
  3242. if (!RootTempDir.IsEmpty())
  3243. {
  3244. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3245. }
  3246. throw;
  3247. }
  3248. }
  3249. __finally
  3250. {
  3251. FAutoOperation = false;
  3252. Terminal->ExceptionOnFail = false;
  3253. }
  3254. }
  3255. //---------------------------------------------------------------------------
  3256. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  3257. {
  3258. // Do not waste time checking for default editor list the next time,
  3259. // or testing if default editor is not notepad.
  3260. bool TryNextTime = false;
  3261. UnicodeString UsageState;
  3262. if (!WinConfiguration->EditorList->IsDefaultList())
  3263. {
  3264. UsageState = "H";
  3265. }
  3266. else
  3267. {
  3268. UnicodeString Executable;
  3269. UnicodeString ExecutableDescription;
  3270. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  3271. {
  3272. UnicodeString Message =
  3273. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  3274. unsigned int Answer =
  3275. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  3276. if (Answer != qaOK)
  3277. {
  3278. UsageState = "R";
  3279. }
  3280. else
  3281. {
  3282. UsageState = "A";
  3283. TEditorData EditorData;
  3284. EditorData.Editor = edExternal;
  3285. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  3286. EditorData.ExternalEditorOptionsAutodetect();
  3287. TEditorList EditorList;
  3288. EditorList = *WinConfiguration->EditorList;
  3289. EditorList.Insert(0, new TEditorPreferences(EditorData));
  3290. WinConfiguration->EditorList = &EditorList;
  3291. }
  3292. }
  3293. }
  3294. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  3295. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  3296. }
  3297. //---------------------------------------------------------------------------
  3298. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  3299. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  3300. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  3301. {
  3302. if (ExecuteFileBy == efDefaultEditor)
  3303. {
  3304. if (!WinConfiguration->OfferedEditorAutoConfig)
  3305. {
  3306. EditorAutoConfig();
  3307. }
  3308. const TEditorPreferences * Editor =
  3309. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  3310. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  3311. {
  3312. ExecuteFileBy = efInternalEditor;
  3313. ExternalEditor = NULL;
  3314. }
  3315. else if (Editor->Data->Editor == edOpen)
  3316. {
  3317. ExecuteFileBy = efShell;
  3318. ExternalEditor = NULL;
  3319. }
  3320. else
  3321. {
  3322. ExecuteFileBy = efExternalEditor;
  3323. ExternalEditor = Editor->Data;
  3324. }
  3325. }
  3326. }
  3327. //---------------------------------------------------------------------------
  3328. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3329. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3330. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  3331. {
  3332. UnicodeString OriginalFileName;
  3333. UnicodeString LocalRootDirectory;
  3334. UnicodeString RemoteDirectory;
  3335. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  3336. IsSideLocalBrowser(Side), MaskParams);
  3337. UnicodeString Counter;
  3338. UnicodeString LocalFileName;
  3339. bool Handled = false;
  3340. if (!IsSideLocalBrowser(Side))
  3341. {
  3342. // We need to trim VMS version here, so that we use name without version
  3343. // when uploading back to create a new version of the file
  3344. OriginalFileName = Terminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  3345. RemoteDirectory = UnixExtractFilePath(FullFileName);
  3346. TObject * Token = NULL;
  3347. UnicodeString LocalDirectory;
  3348. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  3349. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  3350. LocalDirectory))
  3351. {
  3352. if (Token != NULL)
  3353. {
  3354. TForm * Form = dynamic_cast<TForm *>(Token);
  3355. if (Form->WindowState == wsMinimized)
  3356. {
  3357. ShowWindow(Form->Handle, SW_RESTORE);
  3358. }
  3359. else
  3360. {
  3361. Form->SetFocus();
  3362. }
  3363. Handled = true;
  3364. }
  3365. else
  3366. {
  3367. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  3368. }
  3369. }
  3370. if (!Handled)
  3371. {
  3372. TStringList * FileList1 = new TStringList();
  3373. try
  3374. {
  3375. FileList1->AddObject(FullFileName, Object);
  3376. TemporarilyDownloadFiles(FileList1,
  3377. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  3378. LocalRootDirectory, LocalDirectory, true, true, true);
  3379. LocalFileName = LocalDirectory + FileList1->Strings[0];
  3380. }
  3381. __finally
  3382. {
  3383. delete FileList1;
  3384. }
  3385. switch (ExecuteFileBy)
  3386. {
  3387. case efShell:
  3388. Counter = "RemoteFilesExecuted";
  3389. break;
  3390. case efInternalEditor:
  3391. Counter = "RemoteFilesOpenedInInternalEditor";
  3392. break;
  3393. case efExternalEditor:
  3394. Counter = "RemoteFilesOpenedInExternalEditor";
  3395. break;
  3396. default:
  3397. DebugFail();
  3398. }
  3399. }
  3400. }
  3401. else
  3402. {
  3403. LocalFileName = FullFileName;
  3404. OriginalFileName = ExtractFileName(FullFileName);
  3405. switch (ExecuteFileBy)
  3406. {
  3407. case efShell:
  3408. Counter = "LocalFilesExecuted";
  3409. break;
  3410. case efInternalEditor:
  3411. Counter = "LocalFilesOpenedInInternalEditor";
  3412. break;
  3413. case efExternalEditor:
  3414. Counter = "LocalFilesOpenedInExternalEditor";
  3415. break;
  3416. default:
  3417. DebugFail();
  3418. }
  3419. }
  3420. if (!Handled)
  3421. {
  3422. Configuration->Usage->Inc(Counter);
  3423. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3424. ExternalEditor, LocalRootDirectory, RemoteDirectory, false);
  3425. }
  3426. }
  3427. //---------------------------------------------------------------------------
  3428. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3429. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3430. bool AllSelected, bool OnFocused)
  3431. {
  3432. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3433. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3434. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3435. Side = GetSide(Side);
  3436. TCustomDirView * DView = DirView(Side);
  3437. TStrings * FileList =
  3438. AllSelected ?
  3439. DView->CreateFileList(OnFocused, IsSideLocalBrowser(Side)) :
  3440. DView->CreateFocusedFileList(IsSideLocalBrowser(Side));
  3441. try
  3442. {
  3443. DebugAssert(AllSelected || (FileList->Count == 1));
  3444. for (int i = 0; i < FileList->Count; i++)
  3445. {
  3446. UnicodeString ListFileName = FileList->Strings[i];
  3447. UnicodeString FileNameOnly =
  3448. !IsSideLocalBrowser(Side) ? UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3449. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3450. if (!DView->ItemIsDirectory(Item))
  3451. {
  3452. UnicodeString FullFileName;
  3453. if (!IsSideLocalBrowser(Side))
  3454. {
  3455. FullFileName = DirView(Side)->Path + ListFileName;
  3456. }
  3457. else
  3458. {
  3459. FullFileName = ListFileName;
  3460. }
  3461. TFileMasks::TParams MaskParams;
  3462. MaskParams.Size = DView->ItemFileSize(Item);
  3463. TDateTimePrecision Precision;
  3464. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3465. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3466. FileList->Objects[i], MaskParams);
  3467. }
  3468. }
  3469. }
  3470. __finally
  3471. {
  3472. delete FileList;
  3473. }
  3474. }
  3475. //---------------------------------------------------------------------------
  3476. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3477. {
  3478. CopyParam.FileNameCase = ncNoChange;
  3479. CopyParam.PreserveRights = false;
  3480. CopyParam.PreserveReadOnly = false;
  3481. CopyParam.ReplaceInvalidChars = true;
  3482. CopyParam.IncludeFileMask = TFileMasks();
  3483. CopyParam.NewerOnly = false;
  3484. CopyParam.FileMask = L"";
  3485. }
  3486. //---------------------------------------------------------------------------
  3487. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3488. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3489. {
  3490. TTerminalManager * Manager = TTerminalManager::Instance();
  3491. if (!IsActiveTerminal(Data->Terminal))
  3492. {
  3493. if (!NonVisualDataModule->Busy)
  3494. {
  3495. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3496. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3497. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3498. if (Data->Terminal == NULL)
  3499. {
  3500. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3501. if (SameSiteTerminal != NULL)
  3502. {
  3503. UnicodeString Message =
  3504. FMTLOAD(EDIT_SESSION_REATTACH,
  3505. (FileNameOnly, Data->SessionName, FileNameOnly));
  3506. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3507. {
  3508. Data->Terminal = Terminal;
  3509. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3510. Data->SessionName = Terminal->SessionData->SessionName;
  3511. // We might also overwrite session data
  3512. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3513. }
  3514. else
  3515. {
  3516. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3517. Abort();
  3518. }
  3519. }
  3520. }
  3521. // foreground session should reconnect itself
  3522. else if (Terminal != Data->Terminal)
  3523. {
  3524. UnicodeString Message =
  3525. MainInstructions(
  3526. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3527. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3528. {
  3529. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3530. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3531. }
  3532. else
  3533. {
  3534. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3535. Abort();
  3536. }
  3537. }
  3538. }
  3539. if (!IsActiveTerminal(Data->Terminal))
  3540. {
  3541. Configuration->Usage->Inc(L"EditInactiveSession");
  3542. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3543. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3544. (ExtractFileName(FileName), Data->SessionName)));
  3545. }
  3546. }
  3547. TStrings * FileList = new TStringList();
  3548. try
  3549. {
  3550. FileList->Add(FileName);
  3551. // consider using the same settings (preset) as when the file was downloaded
  3552. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3553. TemporaryFileCopyParam(CopyParam);
  3554. if (Data->ForceText)
  3555. {
  3556. CopyParam.TransferMode = tmAscii;
  3557. }
  3558. // so i do not need to worry if masking algorithm works in all cases
  3559. // ("" means "copy file name", no masking is actually done)
  3560. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3561. {
  3562. CopyParam.FileMask = L"";
  3563. }
  3564. else
  3565. {
  3566. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3567. }
  3568. DebugAssert(Data->Queue != NULL);
  3569. int Params = cpNoConfirmation | cpTemporary;
  3570. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3571. Data->RemoteDirectory, &CopyParam, Params, true, false);
  3572. QueueItem->CompleteEvent = UploadCompleteEvent;
  3573. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3574. }
  3575. __finally
  3576. {
  3577. delete FileList;
  3578. }
  3579. }
  3580. //---------------------------------------------------------------------------
  3581. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3582. const UnicodeString FileName, const TEditedFileData * Data)
  3583. {
  3584. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3585. DebugAssert(!NonVisualDataModule->Busy);
  3586. if (!IsActiveTerminal(Data->Terminal))
  3587. {
  3588. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3589. (ExtractFileName(FileName), Data->SessionName)));
  3590. }
  3591. TManagedTerminal * PrevSession = TTerminalManager::Instance()->ActiveSession;
  3592. TTerminalManager::Instance()->ActiveSession = Data->Terminal;
  3593. NonVisualDataModule->StartBusy();
  3594. try
  3595. {
  3596. std::unique_ptr<TRemoteFile> File;
  3597. UnicodeString RemoteFileName =
  3598. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3599. Terminal->ExceptionOnFail = true;
  3600. try
  3601. {
  3602. TRemoteFile * AFile = NULL;
  3603. Terminal->ReadFile(RemoteFileName, AFile);
  3604. File.reset(AFile);
  3605. if (!File->HaveFullFileName)
  3606. {
  3607. File->FullFileName = RemoteFileName;
  3608. }
  3609. }
  3610. __finally
  3611. {
  3612. Terminal->ExceptionOnFail = false;
  3613. }
  3614. std::unique_ptr<TStrings> FileList(new TStringList());
  3615. FileList->AddObject(RemoteFileName, File.get());
  3616. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3617. UnicodeString TempDir = ExtractFilePath(FileName);
  3618. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3619. TempDir, true, true, true);
  3620. // sanity check, the target file name should be still the same
  3621. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3622. }
  3623. __finally
  3624. {
  3625. NonVisualDataModule->EndBusy();
  3626. // it actually may not exist anymore...
  3627. TTerminalManager::Instance()->ActiveSession = PrevSession;
  3628. }
  3629. }
  3630. //---------------------------------------------------------------------------
  3631. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3632. const TEditedFileData * Data, bool & KeepOpen)
  3633. {
  3634. // Command is set for external editors only (not for "shell" open).
  3635. if (!Data->Command.IsEmpty())
  3636. {
  3637. bool AnyFound = false;
  3638. bool AnyMDI = false;
  3639. bool AnyNonMDI = false;
  3640. bool AnyDetect = false;
  3641. TEditorList * EditorList = new TEditorList();
  3642. try
  3643. {
  3644. *EditorList = *WinConfiguration->EditorList;
  3645. for (int i = 0; i < EditorList->Count; i++)
  3646. {
  3647. const TEditorPreferences * Editor = EditorList->Editors[i];
  3648. if ((Editor->Data->Editor == edExternal) &&
  3649. (Editor->Data->ExternalEditor == Data->Command))
  3650. {
  3651. AnyFound = true;
  3652. if (Editor->Data->SDIExternalEditor)
  3653. {
  3654. AnyNonMDI = true;
  3655. if (Editor->Data->DetectMDIExternalEditor)
  3656. {
  3657. AnyDetect = true;
  3658. }
  3659. }
  3660. else
  3661. {
  3662. AnyMDI = true;
  3663. }
  3664. }
  3665. }
  3666. bool EnableMDI = false;
  3667. bool DisableDetect = false;
  3668. if (AnyMDI)
  3669. {
  3670. KeepOpen = true;
  3671. if (AnyNonMDI)
  3672. {
  3673. // there is at least one instance of the editor with MDI support enabled,
  3674. // and one with disabled, enable it for all instances
  3675. EnableMDI = true;
  3676. }
  3677. }
  3678. else if (AnyFound && !AnyDetect)
  3679. {
  3680. // at least once instance found but all have MDI autodetection disabled
  3681. // => close the file (default action)
  3682. }
  3683. else
  3684. {
  3685. // no instance of the editor has MDI support enabled
  3686. TMessageParams Params;
  3687. if (AnyFound)
  3688. {
  3689. // there is at least one instance of the editor
  3690. Params.Params |= mpNeverAskAgainCheck;
  3691. }
  3692. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3693. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3694. switch (Answer)
  3695. {
  3696. case qaNeverAskAgain:
  3697. DisableDetect = true;
  3698. break;
  3699. case qaNo:
  3700. EnableMDI = true;
  3701. KeepOpen = true;
  3702. break;
  3703. }
  3704. }
  3705. if (AnyFound && (EnableMDI || DisableDetect))
  3706. {
  3707. bool Changed = false;
  3708. for (int i = 0; i < EditorList->Count; i++)
  3709. {
  3710. const TEditorPreferences * Editor = EditorList->Editors[i];
  3711. if ((Editor->Data->Editor == edExternal) &&
  3712. (Editor->Data->ExternalEditor == Data->Command) &&
  3713. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3714. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3715. {
  3716. Changed = true;
  3717. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3718. if (EnableMDI)
  3719. {
  3720. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3721. }
  3722. if (DisableDetect)
  3723. {
  3724. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3725. }
  3726. EditorList->Change(i, UpdatedEditor);
  3727. }
  3728. }
  3729. if (Changed)
  3730. {
  3731. WinConfiguration->EditorList = EditorList;
  3732. }
  3733. }
  3734. }
  3735. __finally
  3736. {
  3737. delete EditorList;
  3738. }
  3739. }
  3740. else
  3741. {
  3742. // "open" case
  3743. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3744. qaOK, HELP_APP_EARLY_CLOSED);
  3745. }
  3746. }
  3747. //---------------------------------------------------------------------------
  3748. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3749. {
  3750. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3751. }
  3752. //---------------------------------------------------------------------------
  3753. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3754. {
  3755. SideEnter(osRemote);
  3756. }
  3757. //---------------------------------------------------------------------------
  3758. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3759. {
  3760. MakeNextInTabOrder(RemoteDirPanel, RemoteDrivePanel);
  3761. SideEnter(osRemote);
  3762. }
  3763. //---------------------------------------------------------------------------
  3764. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3765. {
  3766. FCurrentSide = Side;
  3767. if (Visible)
  3768. {
  3769. UpdateControls();
  3770. }
  3771. }
  3772. //---------------------------------------------------------------------------
  3773. void __fastcall TCustomScpExplorerForm::FileDeleted(TOperationSide Side, const UnicodeString & FileName, bool Success)
  3774. {
  3775. VisualiseOperationFinished(Side, FileName, Success);
  3776. if (DebugAlwaysTrue(FDeletedFiles != NULL) && Success)
  3777. {
  3778. FDeletedFiles->Add(FileName);
  3779. }
  3780. }
  3781. //---------------------------------------------------------------------------
  3782. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3783. TStrings * FileList, bool Alternative)
  3784. {
  3785. TCustomDirView * DView = DirView(Side);
  3786. DView->SaveSelection();
  3787. DView->SaveSelectedNames();
  3788. DebugAssert(!FAlternativeDelete);
  3789. FAlternativeDelete = Alternative;
  3790. try
  3791. {
  3792. if (!IsSideLocalBrowser(Side))
  3793. {
  3794. DebugAssert(Terminal != NULL);
  3795. // Clone the file list as it may refer to current directory files, which get destroyed, when the directory is reloaded after the operation
  3796. std::unique_ptr<TStrings> PermanentFileList(TRemoteFileList::CloneStrings(FileList));
  3797. std::unique_ptr<TStringList> DeletedFiles(new TStringList());
  3798. DeletedFiles->CaseSensitive = DebugAlwaysTrue(!IsSideLocalBrowser(Side));
  3799. int Params = FLAGMASK(Alternative, dfAlternative);
  3800. try
  3801. {
  3802. TValueRestorer<TStrings *> DeletedFilesRestorer(FDeletedFiles);
  3803. DebugAssert(FDeletedFiles == NULL);
  3804. FDeletedFiles = DeletedFiles.get();
  3805. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  3806. FOnFileOperationFinished = FileDeleted;
  3807. FMoveToQueue = false;
  3808. Terminal->DeleteFiles(FileList, Params);
  3809. // Probably not needed for deleting, just for consistency with transfer code
  3810. if (FMoveToQueue)
  3811. {
  3812. Abort();
  3813. }
  3814. }
  3815. catch (EAbort &)
  3816. {
  3817. if (FMoveToQueue)
  3818. {
  3819. DeletedFiles->Sorted = true;
  3820. for (int Index = 0; Index < PermanentFileList->Count; Index++)
  3821. {
  3822. if (DeletedFiles->IndexOf(PermanentFileList->Strings[Index]) >= 0)
  3823. {
  3824. // We should always be deleting the first item => what can be used to optimize this code, if needed
  3825. DebugAssert(Index == 0);
  3826. PermanentFileList->Delete(Index);
  3827. Index--;
  3828. }
  3829. }
  3830. Configuration->Usage->Inc("MovesToBackgroundDelete");
  3831. TQueueItem * QueueItem = new TDeleteQueueItem(Terminal, PermanentFileList.get(), Params);
  3832. AddQueueItem(Queue, QueueItem, Terminal);
  3833. ClearOperationSelection(osRemote);
  3834. }
  3835. }
  3836. }
  3837. else
  3838. {
  3839. if (IsLocalBrowserMode())
  3840. {
  3841. Configuration->Usage->Inc(L"LocalLocalDeletes");
  3842. }
  3843. TValueRestorer<TOperationSide> ProgressSideRestorer(FProgressSide);
  3844. FProgressSide = FCurrentSide;
  3845. try
  3846. {
  3847. TTerminalManager::Instance()->LocalTerminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3848. }
  3849. __finally
  3850. {
  3851. ReloadLocalDirectory();
  3852. }
  3853. }
  3854. FAlternativeDelete = false;
  3855. }
  3856. catch(...)
  3857. {
  3858. FAlternativeDelete = false;
  3859. DView->DiscardSavedSelection();
  3860. throw;
  3861. }
  3862. DView->RestoreSelection();
  3863. }
  3864. //---------------------------------------------------------------------------
  3865. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3866. {
  3867. DebugAssert(Terminal);
  3868. DebugAssert(!IsLocalBrowserMode());
  3869. RemoteDirView->SaveSelection();
  3870. RemoteDirView->SaveSelectedNames();
  3871. try
  3872. {
  3873. if (Lock)
  3874. {
  3875. Terminal->LockFiles(FileList);
  3876. }
  3877. else
  3878. {
  3879. Terminal->UnlockFiles(FileList);
  3880. }
  3881. }
  3882. catch(...)
  3883. {
  3884. RemoteDirView->DiscardSavedSelection();
  3885. throw;
  3886. }
  3887. RemoteDirView->RestoreSelection();
  3888. }
  3889. //---------------------------------------------------------------------------
  3890. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *& Session,
  3891. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3892. bool NoConfirmation, bool Move)
  3893. {
  3894. DebugAssert(Terminal != NULL);
  3895. DebugAssert(Terminal == TTerminalManager::Instance()->ActiveTerminal);
  3896. DebugAssert(!IsLocalBrowserMode());
  3897. if (Session == NULL)
  3898. {
  3899. Session = Terminal;
  3900. }
  3901. if (Session == Terminal)
  3902. {
  3903. if (RemoteDriveView->DropTarget != NULL)
  3904. {
  3905. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3906. }
  3907. else if (RemoteDirView->DropTarget != NULL)
  3908. {
  3909. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3910. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3911. }
  3912. else
  3913. {
  3914. Target = RemoteDirView->Path;
  3915. }
  3916. }
  3917. else
  3918. {
  3919. Target = GetSessionPath(Session, osRemote);
  3920. }
  3921. Target = UnixIncludeTrailingBackslash(Target);
  3922. if (FileList->Count == 1)
  3923. {
  3924. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3925. }
  3926. else
  3927. {
  3928. FileMask = AnyMask;
  3929. }
  3930. DirectCopy = Terminal->IsCapable[fcRemoteCopy] || Terminal->IsCapable[fcSecondaryShell];
  3931. bool Result = true;
  3932. if (!NoConfirmation)
  3933. {
  3934. bool Multi = (FileList->Count > 1);
  3935. if (Move)
  3936. {
  3937. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3938. }
  3939. else
  3940. {
  3941. std::unique_ptr<TStrings> Sessions(new TStringList);
  3942. std::unique_ptr<TStrings> Directories(new TStringList);
  3943. TStrings * SessionList = TTerminalManager::Instance()->SessionList;
  3944. for (int Index = 0; Index < SessionList->Count; Index++)
  3945. {
  3946. TManagedTerminal * ASession = DebugNotNull(dynamic_cast<TManagedTerminal *>(SessionList->Objects[Index]));
  3947. if (IsActiveTerminal(ASession) && DebugAlwaysTrue(!ASession->LocalBrowser))
  3948. {
  3949. Sessions->AddObject(SessionList->Strings[Index], ASession);
  3950. Directories->Add(GetSessionPath(ASession, osRemote));
  3951. }
  3952. }
  3953. TDirectRemoteCopy AllowDirectCopy;
  3954. if (Terminal->IsCapable[fcRemoteCopy] || Terminal->CommandSessionOpened)
  3955. {
  3956. DebugAssert(DirectCopy);
  3957. AllowDirectCopy = drcAllow;
  3958. }
  3959. else if (Terminal->IsCapable[fcSecondaryShell])
  3960. {
  3961. DebugAssert(DirectCopy);
  3962. AllowDirectCopy = drcConfirmCommandSession;
  3963. }
  3964. else
  3965. {
  3966. DebugAssert(!DirectCopy);
  3967. AllowDirectCopy = drcDisallow;
  3968. }
  3969. void * ASession = Session;
  3970. Result = DoRemoteCopyDialog(
  3971. Sessions.get(), Directories.get(), AllowDirectCopy, Multi, ASession, Target, FileMask, DirectCopy, Terminal);
  3972. Session = static_cast<TManagedTerminal *>(ASession);
  3973. }
  3974. }
  3975. return Result;
  3976. }
  3977. //---------------------------------------------------------------------------
  3978. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3979. TStrings * FileList, bool NoConfirmation, bool Move, TManagedTerminal * Session)
  3980. {
  3981. DebugAssert(!IsLocalBrowserMode());
  3982. bool DirectCopy;
  3983. UnicodeString Target, FileMask;
  3984. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3985. if (Result)
  3986. {
  3987. if (!Move && !DirectCopy)
  3988. {
  3989. Configuration->Usage->Inc("RemoteCopyTemp");
  3990. UnicodeString RootTempDir;
  3991. UnicodeString TempDir;
  3992. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3993. TStrings * TemporaryFilesList = new TStringList();
  3994. try
  3995. {
  3996. TMakeLocalFileListParams MakeFileListParam;
  3997. MakeFileListParam.FileList = TemporaryFilesList;
  3998. MakeFileListParam.FileTimes = NULL;
  3999. MakeFileListParam.IncludeDirs = true;
  4000. MakeFileListParam.Recursive = false;
  4001. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  4002. TTerminalManager::Instance()->ActiveSession = Session;
  4003. if (TemporaryFilesList->Count > 0)
  4004. {
  4005. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4006. CopyParam.FileMask = FileMask;
  4007. DebugAssert(!FAutoOperation);
  4008. FAutoOperation = true;
  4009. Terminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary, NULL);
  4010. }
  4011. }
  4012. __finally
  4013. {
  4014. delete TemporaryFilesList;
  4015. FAutoOperation = false;
  4016. if (!RootTempDir.IsEmpty())
  4017. {
  4018. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  4019. }
  4020. }
  4021. }
  4022. else
  4023. {
  4024. RemoteDirView->SaveSelection();
  4025. RemoteDirView->SaveSelectedNames();
  4026. try
  4027. {
  4028. if (Move)
  4029. {
  4030. Configuration->Usage->Inc("RemoteMove");
  4031. Terminal->MoveFiles(FileList, Target, FileMask);
  4032. }
  4033. else
  4034. {
  4035. Configuration->Usage->Inc("RemoteCopyDirect");
  4036. DebugAssert(DirectCopy);
  4037. DebugAssert(Session == Terminal);
  4038. if (Terminal->IsCapable[fcRemoteCopy] ||
  4039. Terminal->CommandSessionOpened ||
  4040. CommandSessionFallback())
  4041. {
  4042. Terminal->CopyFiles(FileList, Target, FileMask);
  4043. }
  4044. }
  4045. }
  4046. catch(...)
  4047. {
  4048. RemoteDirView->DiscardSavedSelection();
  4049. throw;
  4050. }
  4051. RemoteDirView->RestoreSelection();
  4052. }
  4053. }
  4054. return Result;
  4055. }
  4056. //---------------------------------------------------------------------------
  4057. void __fastcall TCustomScpExplorerForm::CreateRemoteDirectory(
  4058. const UnicodeString & Path, TRemoteProperties & Properties)
  4059. {
  4060. DebugAssert(!IsLocalBrowserMode());
  4061. Properties.Valid = Properties.Valid << vpEncrypt;
  4062. Properties.Encrypt = GUIConfiguration->CurrentCopyParam.EncryptNewFiles;
  4063. RemoteDirView->CreateDirectoryEx(Path, &Properties);
  4064. }
  4065. //---------------------------------------------------------------------------
  4066. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  4067. {
  4068. Side = GetSide(Side);
  4069. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  4070. TRemoteProperties * AProperties = (!IsSideLocalBrowser(Side) ? &Properties : NULL);
  4071. UnicodeString Name = LoadStr(NEW_FOLDER);
  4072. int AllowedChanges =
  4073. FLAGMASK(!IsSideLocalBrowser(Side) && Terminal->IsCapable[fcModeChanging], cpMode);
  4074. bool SaveSettings = false;
  4075. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  4076. {
  4077. TWindowLock Lock(this);
  4078. if (!IsSideLocalBrowser(Side))
  4079. {
  4080. if (SaveSettings)
  4081. {
  4082. GUIConfiguration->NewDirectoryProperties = Properties;
  4083. }
  4084. CreateRemoteDirectory(Name, Properties);
  4085. }
  4086. else
  4087. {
  4088. DirView(Side)->CreateDirectory(Name);
  4089. }
  4090. }
  4091. }
  4092. //---------------------------------------------------------------------------
  4093. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  4094. {
  4095. TWindowLock Lock(this);
  4096. DirView(Side)->ExecuteHomeDirectory();
  4097. }
  4098. //---------------------------------------------------------------------------
  4099. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  4100. {
  4101. DoOpenDirectoryDialog(odBrowse, Side);
  4102. }
  4103. //---------------------------------------------------------------------------
  4104. bool __fastcall TCustomScpExplorerForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  4105. {
  4106. TOperationSide BookmarkSide = IsLocalBrowserMode() ? osLocal : Side;
  4107. UnicodeString Path = Bookmark->GetSideDirectory(BookmarkSide);
  4108. bool Result = !Path.IsEmpty();
  4109. if (Result)
  4110. {
  4111. // While we might get here when the session is closed (from location profiles),
  4112. // it's not a problem as the Path setter is noop then
  4113. DirView(Side)->Path = Path;
  4114. }
  4115. return Result;
  4116. }
  4117. //---------------------------------------------------------------------------
  4118. void __fastcall TCustomScpExplorerForm::CalculateSize(
  4119. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  4120. bool & Close)
  4121. {
  4122. // terminal can be already closed (e.g. dropped connection)
  4123. if (Terminal != NULL)
  4124. {
  4125. try
  4126. {
  4127. TCalculateSizeParams Params;
  4128. Params.Stats = &Stats;
  4129. Terminal->CalculateFilesSize(FileList, Size, Params);
  4130. }
  4131. catch(...)
  4132. {
  4133. if (!Terminal->Active)
  4134. {
  4135. Close = true;
  4136. }
  4137. throw;
  4138. }
  4139. }
  4140. }
  4141. //---------------------------------------------------------------------------
  4142. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  4143. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  4144. bool & Close)
  4145. {
  4146. // terminal can be already closed (e.g. dropped connection)
  4147. if (Terminal != NULL)
  4148. {
  4149. Configuration->Usage->Inc(L"ChecksumCalculated");
  4150. try
  4151. {
  4152. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  4153. }
  4154. catch(...)
  4155. {
  4156. if (!Terminal->Active)
  4157. {
  4158. Close = true;
  4159. }
  4160. throw;
  4161. }
  4162. }
  4163. }
  4164. //---------------------------------------------------------------------------
  4165. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  4166. {
  4167. bool Result;
  4168. if (!IsSideLocalBrowser(Side))
  4169. {
  4170. TRemoteTokenList * GroupList = NULL;
  4171. TRemoteTokenList * UserList = NULL;
  4172. try
  4173. {
  4174. TRemoteProperties CurrentProperties;
  4175. if (Terminal->LoadFilesProperties(FileList))
  4176. {
  4177. RemoteDirView->Invalidate();
  4178. }
  4179. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  4180. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  4181. if (CapableGroupChanging || CapableOwnerChanging)
  4182. {
  4183. if (CapableGroupChanging)
  4184. {
  4185. GroupList = Terminal->Groups->Duplicate();
  4186. }
  4187. if (CapableOwnerChanging)
  4188. {
  4189. UserList = Terminal->Users->Duplicate();
  4190. }
  4191. TRemoteDirectory * Files = Terminal->Files;
  4192. int Count = Files->Count;
  4193. if (Count > 100)
  4194. {
  4195. Count = 100;
  4196. }
  4197. for (int Index = 0; Index < Count; Index++)
  4198. {
  4199. TRemoteFile * File = Files->Files[Index];
  4200. if (CapableGroupChanging)
  4201. {
  4202. GroupList->AddUnique(File->Group);
  4203. }
  4204. if (CapableOwnerChanging)
  4205. {
  4206. UserList->AddUnique(File->Owner);
  4207. }
  4208. }
  4209. // if we haven't collected tokens for all files in current directory,
  4210. // make sure we collect them at least for all selected files.
  4211. // (note that so far the files in FileList has to be from current direcotry)
  4212. if (Count < Files->Count)
  4213. {
  4214. for (int Index = 0; Index < FileList->Count; Index++)
  4215. {
  4216. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  4217. if (CapableGroupChanging)
  4218. {
  4219. GroupList->AddUnique(File->Group);
  4220. }
  4221. if (CapableOwnerChanging)
  4222. {
  4223. UserList->AddUnique(File->Owner);
  4224. }
  4225. }
  4226. }
  4227. }
  4228. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  4229. int Flags = 0;
  4230. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  4231. if (CapableOwnerChanging) Flags |= cpOwner;
  4232. if (CapableGroupChanging) Flags |= cpGroup;
  4233. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  4234. if (Terminal->IsCapable[fcCalculatingChecksum])
  4235. {
  4236. CalculateChecksumEvent = CalculateChecksum;
  4237. }
  4238. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  4239. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  4240. TRemoteProperties NewProperties = CurrentProperties;
  4241. Result =
  4242. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  4243. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  4244. Terminal->IsCapable[fcGroupOwnerChangingByID],
  4245. CalculateSize, CalculateChecksumEvent);
  4246. if (Result)
  4247. {
  4248. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  4249. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  4250. }
  4251. }
  4252. __finally
  4253. {
  4254. delete GroupList;
  4255. delete UserList;
  4256. }
  4257. }
  4258. else
  4259. {
  4260. DirView(Side)->DisplayPropertiesMenu();
  4261. Result = true;
  4262. }
  4263. return Result;
  4264. }
  4265. //---------------------------------------------------------------------------
  4266. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  4267. {
  4268. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  4269. {
  4270. FIgnoreNextDialogChar = Key;
  4271. }
  4272. Key = 0;
  4273. }
  4274. //---------------------------------------------------------------------------
  4275. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  4276. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  4277. {
  4278. const TCustomCommandType * Command = List->Find(KeyShortCut);
  4279. if (Command != NULL)
  4280. {
  4281. KeyProcessed(Key, Shift);
  4282. if (CustomCommandState(*Command, false, ccltAll) > 0)
  4283. {
  4284. TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
  4285. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  4286. false, false, const_cast<TCustomCommandType *>(Command));
  4287. }
  4288. }
  4289. }
  4290. //---------------------------------------------------------------------------
  4291. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  4292. {
  4293. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  4294. {
  4295. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  4296. }
  4297. if ((Key != 0) && !DirView(osCurrent)->IsEditing())
  4298. {
  4299. TShortCut KeyShortCut = ShortCut(Key, Shift);
  4300. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  4301. {
  4302. // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
  4303. // But so far it's not a problem, as it does what we want.
  4304. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  4305. if (((Action->ShortCut == KeyShortCut) ||
  4306. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  4307. AllowedAction(Action, aaShortCut))
  4308. {
  4309. // Has to be called before the action as the dialog char is already in queue.
  4310. // So when the action consumes message queue, we already need to have the
  4311. // FIgnoreNextDialogChar set
  4312. KeyProcessed(Key, Shift);
  4313. // Reset reference to previous component (when menu/toolbar was clicked).
  4314. // Needed to detect that action was invoked by keyboard shortcut
  4315. // in TNonVisualDataModule::ExplorerActionsExecute
  4316. Action->ActionComponent = NULL;
  4317. Action->Execute();
  4318. return;
  4319. }
  4320. }
  4321. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  4322. {
  4323. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  4324. {
  4325. KeyProcessed(Key, Shift);
  4326. TTerminalManager::Instance()->ActiveSessionIndex = i;
  4327. return;
  4328. }
  4329. }
  4330. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  4331. {
  4332. KeyProcessed(Key, Shift);
  4333. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  4334. }
  4335. TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
  4336. if (IsCustomShortCut(CustomShortCut))
  4337. {
  4338. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
  4339. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
  4340. if (WinConfiguration->SharedBookmarks != NULL)
  4341. {
  4342. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
  4343. if ((Bookmark != NULL) &&
  4344. OpenBookmark(FCurrentSide, Bookmark))
  4345. {
  4346. KeyProcessed(Key, Shift);
  4347. }
  4348. }
  4349. }
  4350. }
  4351. TForm::KeyDown(Key, Shift);
  4352. }
  4353. //---------------------------------------------------------------------------
  4354. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  4355. {
  4356. bool OpenedTerminal = false;
  4357. UnicodeString ProtocolName;
  4358. UnicodeString ProtocolNameHint;
  4359. UnicodeString SecurityProtocolName;
  4360. UnicodeString DurationHint;
  4361. // See the comment in TScpCommanderForm::UpdateControls()
  4362. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4363. if (ActiveTerminal != NULL)
  4364. {
  4365. // Active is not enough here
  4366. if (ActiveTerminal->Status == ssOpened)
  4367. {
  4368. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4369. const TFileSystemInfo & FileSystemInfo = ActiveTerminal->GetFileSystemInfo();
  4370. if (FileSystemInfo.ProtocolName.IsEmpty())
  4371. {
  4372. ProtocolName = SessionInfo.ProtocolName;
  4373. }
  4374. else
  4375. {
  4376. ProtocolName = FileSystemInfo.ProtocolName;
  4377. }
  4378. ProtocolNameHint = LoadStr(STATUS_PROTOCOL_HINT);
  4379. SecurityProtocolName = SessionInfo.SecurityProtocolName;
  4380. DurationHint = LoadStr(STATUS_DURATION_HINT);
  4381. OpenedTerminal = true;
  4382. }
  4383. else if (ActiveTerminal->Status > ssClosed)
  4384. {
  4385. ProtocolName = LoadStr(STATUS_CONNECTING);
  4386. }
  4387. else
  4388. {
  4389. ProtocolName = LoadStr(STATUS_NOT_CONNECTED2);
  4390. }
  4391. }
  4392. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4393. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  4394. TTBXStatusPanel * ProtocolStatusPanel = SessionStatusBar->Panels->Items[Offset + 0];
  4395. ProtocolStatusPanel->ViewPriority = (ActiveTerminal != NULL) ? 100 : 0;
  4396. if (ProtocolStatusPanel->Caption != ProtocolName)
  4397. {
  4398. ProtocolStatusPanel->Caption = ProtocolName;
  4399. std::unique_ptr<TCanvas> Canvas(CreateControlCanvas(SessionStatusBar));
  4400. ProtocolStatusPanel->Size = Canvas->TextWidth(ProtocolName) + ScaleByTextHeight(SessionStatusBar, 32);
  4401. }
  4402. ProtocolStatusPanel->Hint = ProtocolNameHint;
  4403. TTBXStatusPanel * SecurityStatusPanel = SessionStatusBar->Panels->Items[Offset + 1];
  4404. SecurityStatusPanel->ViewPriority = OpenedTerminal ? 98 : 0;
  4405. bool SecurityEnabled = !SecurityProtocolName.IsEmpty();
  4406. SecurityStatusPanel->Enabled = SecurityEnabled;
  4407. UnicodeString SecurityProtocolHint;
  4408. if (SecurityEnabled)
  4409. {
  4410. SecurityProtocolHint = FMTLOAD(STATUS_SECURE, (SecurityProtocolName));
  4411. }
  4412. else
  4413. {
  4414. SecurityProtocolHint = LoadStr(STATUS_INSECURE);
  4415. }
  4416. SecurityStatusPanel->Hint = SecurityProtocolHint;
  4417. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[Offset + 2];
  4418. DurationStatusPanel->ViewPriority = OpenedTerminal ? 99 : 0;
  4419. DurationStatusPanel->Hint = DurationHint;
  4420. UpdateStatusBar();
  4421. }
  4422. //---------------------------------------------------------------------------
  4423. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  4424. {
  4425. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  4426. DebugAssert(SessionStatusBar != NULL);
  4427. TTBXStatusPanel * NoteStatusPanel = SessionStatusBar->Panels->Items[0];
  4428. if (!FNote.IsEmpty())
  4429. {
  4430. NoteStatusPanel->Caption = FNote;
  4431. }
  4432. else
  4433. {
  4434. UpdateStatusPanelText(NoteStatusPanel);
  4435. }
  4436. NoteStatusPanel->Hint = FNoteHints;
  4437. UnicodeString LoginTime;
  4438. // See the comment in TScpCommanderForm::UpdateControls()
  4439. TTerminal * ActiveTerminal = TTerminalManager::Instance()->ActiveTerminal;
  4440. // Active is not enough here
  4441. if ((ActiveTerminal != NULL) && (ActiveTerminal->Status == ssOpened))
  4442. {
  4443. const TSessionInfo & SessionInfo = ActiveTerminal->GetSessionInfo();
  4444. LoginTime = FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  4445. }
  4446. TTBXStatusPanel * DurationStatusPanel = SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1];
  4447. DurationStatusPanel->Caption = LoginTime;
  4448. }
  4449. //---------------------------------------------------------------------------
  4450. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  4451. {
  4452. Panel->Caption = L"";
  4453. }
  4454. //---------------------------------------------------------------------------
  4455. void __fastcall TCustomScpExplorerForm::Idle()
  4456. {
  4457. if (FShowing ||
  4458. // Particularly for
  4459. // - Standalone editing
  4460. // - Detecting closed connection and automatically reconnect it while waiting for changes
  4461. // while "keeping remote directory up to date".
  4462. StandaloneOperation)
  4463. {
  4464. FEditorManager->Check();
  4465. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  4466. // that needs to know if queue view is visible (and it may be closed after queue update)
  4467. TTerminalManager::Instance()->Idle(FDoNotIdleCurrentTerminal > 0);
  4468. }
  4469. if (FShowing)
  4470. {
  4471. if (!NonVisualDataModule->Busy &&
  4472. // Menu is opened or drag&drop is going on
  4473. (Mouse->Capture == NULL))
  4474. {
  4475. if (FRefreshRemoteDirectory)
  4476. {
  4477. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  4478. {
  4479. Terminal->RefreshDirectory();
  4480. }
  4481. FRefreshRemoteDirectory = false;
  4482. }
  4483. if (FRefreshLocalDirectory)
  4484. {
  4485. ReloadLocalDirectory();
  4486. FRefreshLocalDirectory = false;
  4487. }
  4488. if (WinConfiguration->RefreshRemotePanel)
  4489. {
  4490. if ((Terminal != NULL) && (Terminal->Status == ssOpened) &&
  4491. (Now() - Terminal->DirectoryLoaded > WinConfiguration->RefreshRemotePanelInterval))
  4492. {
  4493. RemoteDirView->ReloadDirectory();
  4494. }
  4495. }
  4496. }
  4497. }
  4498. if (FShowing || StandaloneOperation)
  4499. {
  4500. if (FQueueStatusInvalidated)
  4501. {
  4502. UpdateQueueStatus(false);
  4503. }
  4504. RefreshQueueItems();
  4505. }
  4506. if (FShowing)
  4507. {
  4508. UpdateStatusBar();
  4509. }
  4510. FIgnoreNextDialogChar = 0;
  4511. }
  4512. //---------------------------------------------------------------------------
  4513. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4514. {
  4515. try
  4516. {
  4517. FUserActionTimer->Enabled = false;
  4518. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4519. {
  4520. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4521. {
  4522. FPendingQueueActionItem->ProcessUserAction();
  4523. }
  4524. }
  4525. }
  4526. __finally
  4527. {
  4528. FPendingQueueActionItem = NULL;
  4529. }
  4530. }
  4531. //---------------------------------------------------------------------------
  4532. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4533. {
  4534. if (WinConfiguration->MinimizeToTray)
  4535. {
  4536. UpdateTrayIcon();
  4537. FTrayIcon->Visible = true;
  4538. if (Visible)
  4539. {
  4540. ShowWindow(Handle, SW_HIDE);
  4541. }
  4542. }
  4543. }
  4544. //---------------------------------------------------------------------------
  4545. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4546. {
  4547. // WORKAROUND
  4548. // When restoring maximized window from minimization,
  4549. // rarely some controls do not align properly.
  4550. // Two instances seen (both for Commander):
  4551. // - When restoring, window is temporarily narrower (not maximized),
  4552. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4553. // Once maximized already, top dock shinks back, but the session PageControl,
  4554. // do not align up, leaving space between TopDock and PageControl.
  4555. // - Similar issue seen with LocalDirView not aligning down to status bar.
  4556. for (int Index = 0; Index < ControlCount; Index++)
  4557. {
  4558. RealignControl(Controls[Index]);
  4559. }
  4560. if (FTrayIcon->Visible)
  4561. {
  4562. FTrayIcon->Visible = false;
  4563. if (Visible)
  4564. {
  4565. ShowWindow(Handle, SW_SHOW);
  4566. }
  4567. }
  4568. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4569. {
  4570. FNeedSession = false;
  4571. NonVisualDataModule->StartBusy();
  4572. try
  4573. {
  4574. NeedSession(true);
  4575. }
  4576. __finally
  4577. {
  4578. NonVisualDataModule->EndBusy();
  4579. }
  4580. }
  4581. }
  4582. //---------------------------------------------------------------------------
  4583. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4584. {
  4585. FTrayIcon->Hint = GetMainForm()->Caption;
  4586. }
  4587. //---------------------------------------------------------------------------
  4588. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4589. {
  4590. UpdateTrayIcon();
  4591. }
  4592. //---------------------------------------------------------------------------
  4593. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4594. {
  4595. // workaround
  4596. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4597. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4598. // But WM_ACTIVATEAPP message can be received even when
  4599. // the main window is minimized to the tray and internal editor window is focused
  4600. // (after another application was previously active)
  4601. if (::IsIconic(Handle))
  4602. {
  4603. if (!IsAppIconic())
  4604. {
  4605. SetAppIconic(true);
  4606. }
  4607. }
  4608. ::ApplicationRestore();
  4609. Application->BringToFront();
  4610. }
  4611. //---------------------------------------------------------------------------
  4612. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4613. {
  4614. RestoreApp();
  4615. }
  4616. //---------------------------------------------------------------------------
  4617. void __fastcall TCustomScpExplorerForm::NewSession(const UnicodeString & SessionUrl)
  4618. {
  4619. if (OpenInNewWindow())
  4620. {
  4621. ExecuteNewInstance(SessionUrl);
  4622. }
  4623. else
  4624. {
  4625. TTerminalManager::Instance()->NewSession(SessionUrl);
  4626. }
  4627. }
  4628. //---------------------------------------------------------------------------
  4629. void TCustomScpExplorerForm::NewTab(TOperationSide)
  4630. {
  4631. NewSession();
  4632. }
  4633. //---------------------------------------------------------------------------
  4634. UnicodeString __fastcall TCustomScpExplorerForm::SaveHiddenDuplicateSession(TSessionData * SessionData)
  4635. {
  4636. UnicodeString SessionName = StoredSessions->HiddenPrefix + ManagedSession->SessionData->SessionName;
  4637. StoredSessions->NewSession(SessionName, SessionData);
  4638. // modified only, explicit
  4639. StoredSessions->Save(false, true);
  4640. // encode session name because of slashes in hierarchical sessions
  4641. return EncodeUrlString(SessionName);
  4642. }
  4643. //---------------------------------------------------------------------------
  4644. UnicodeString __fastcall TCustomScpExplorerForm::CreateHiddenDuplicateSession()
  4645. {
  4646. // current working directories become defaults here, what is not right
  4647. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4648. return SaveHiddenDuplicateSession(SessionData.get());
  4649. }
  4650. //---------------------------------------------------------------------------
  4651. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4652. {
  4653. if (OpenInNewWindow())
  4654. {
  4655. ExecuteNewInstance(CreateHiddenDuplicateSession());
  4656. }
  4657. else
  4658. {
  4659. // current working directories become defaults here, what is not right
  4660. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  4661. TTerminalManager * Manager = TTerminalManager::Instance();
  4662. TManagedTerminal * ASession = Manager->NewManagedTerminal(SessionData.get());
  4663. DebugAssert(ASession->LocalBrowser == ManagedSession->LocalBrowser);
  4664. // We definitelly want these
  4665. ASession->Disconnected = ManagedSession->Disconnected;
  4666. // Not sure about these two
  4667. ASession->Permanent = ManagedSession->Permanent;
  4668. ASession->DisconnectedTemporarily = ManagedSession->DisconnectedTemporarily;
  4669. Manager->ActiveSession = ASession;
  4670. }
  4671. }
  4672. //---------------------------------------------------------------------------
  4673. void __fastcall TCustomScpExplorerForm::RenameSession()
  4674. {
  4675. UnicodeString Name = ManagedSession->SessionData->SessionName;
  4676. if (InputDialog(LoadStr(RENAME_SESSION_TITLE), LoadStr(RENAME_SESSION_PROMPT), Name, HELP_SESSION_RENAME) &&
  4677. // When submitting the default name, do not fix it
  4678. (Name != ManagedSession->SessionData->SessionName))
  4679. {
  4680. // Checks for a slash only, so it's not that big deal that we do the check after submitting the dialog only.
  4681. TSessionData::ValidateName(Name);
  4682. // This is inconsistent with how color (for example) is handled.
  4683. ManagedSession->SessionData->Name = Name;
  4684. UpdateControls();
  4685. // Add/Remove distinguishing paths from sessions of the same name.
  4686. SessionListChanged();
  4687. }
  4688. }
  4689. //---------------------------------------------------------------------------
  4690. bool __fastcall TCustomScpExplorerForm::CanCloseQueue(TTerminalQueue * Queue)
  4691. {
  4692. DebugAssert(Queue != NULL);
  4693. bool Result = Queue->IsEmpty;
  4694. if (!Result)
  4695. {
  4696. SetFocus();
  4697. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4698. }
  4699. return Result;
  4700. }
  4701. //---------------------------------------------------------------------------
  4702. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4703. {
  4704. return CanCloseQueue(FQueue);
  4705. }
  4706. //---------------------------------------------------------------------------
  4707. void __fastcall TCustomScpExplorerForm::CloseSession()
  4708. {
  4709. if (CanCloseQueue())
  4710. {
  4711. TTerminalManager::Instance()->FreeActiveTerminal();
  4712. }
  4713. }
  4714. //---------------------------------------------------------------------------
  4715. void __fastcall TCustomScpExplorerForm::DisconnectSession()
  4716. {
  4717. if (CanCloseQueue())
  4718. {
  4719. TTerminalManager::Instance()->DisconnectActiveTerminal();
  4720. }
  4721. }
  4722. //---------------------------------------------------------------------------
  4723. void __fastcall TCustomScpExplorerForm::TerminalDisconnected()
  4724. {
  4725. DetachTerminal(Terminal);
  4726. RemoteDirView->Terminal = Terminal;
  4727. UpdateRemotePathComboBox(false);
  4728. InitStatusBar();
  4729. UpdateControls();
  4730. }
  4731. //---------------------------------------------------------------------------
  4732. void __fastcall TCustomScpExplorerForm::TerminalConnecting()
  4733. {
  4734. InitStatusBar();
  4735. }
  4736. //---------------------------------------------------------------------------
  4737. void __fastcall TCustomScpExplorerForm::ReconnectSession()
  4738. {
  4739. if (DebugAlwaysTrue(!Terminal->Active))
  4740. {
  4741. TTerminalManager::Instance()->ReconnectActiveTerminal();
  4742. }
  4743. }
  4744. //---------------------------------------------------------------------------
  4745. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4746. {
  4747. if (OpenInNewWindow())
  4748. {
  4749. // encode session name because of slashes in hierarchical sessions
  4750. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4751. }
  4752. else
  4753. {
  4754. TTerminalManager * Manager = TTerminalManager::Instance();
  4755. TManagedTerminal * Terminal = Manager->NewManagedTerminal(Data);
  4756. Manager->ActiveSession = Terminal;
  4757. }
  4758. }
  4759. //---------------------------------------------------------------------------
  4760. void TCustomScpExplorerForm::DoOpenFolderOrWorkspace(
  4761. const UnicodeString & Name, bool ConnectFirstTerminal, bool CheckMaxSessions)
  4762. {
  4763. TTerminalManager * Manager = TTerminalManager::Instance();
  4764. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4765. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4766. if (!CheckMaxSessions || (DataList->Count <= WinConfiguration->MaxSessions))
  4767. {
  4768. TManagedTerminal * FirstSession = Manager->NewSessions(DataList.get());
  4769. // FirstSession can be null, if some of the
  4770. if (!ConnectFirstTerminal && (FirstSession != NULL))
  4771. {
  4772. FirstSession->Disconnected = true;
  4773. FirstSession->DisconnectedTemporarily = true;
  4774. }
  4775. Manager->ActiveSession = FirstSession;
  4776. }
  4777. }
  4778. //---------------------------------------------------------------------------
  4779. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4780. {
  4781. if (OpenInNewWindow())
  4782. {
  4783. ExecuteNewInstance(Name);
  4784. }
  4785. else
  4786. {
  4787. DoOpenFolderOrWorkspace(Name, true, false);
  4788. }
  4789. }
  4790. //---------------------------------------------------------------------------
  4791. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4792. bool &CanClose)
  4793. {
  4794. // See the comment in CloseApp()
  4795. if (NonVisualDataModule->Busy)
  4796. {
  4797. CanClose = false;
  4798. }
  4799. else
  4800. {
  4801. TTerminalManager * Manager = TTerminalManager::Instance();
  4802. int ActiveSessions = 0;
  4803. for (int Index = 0; Index < Manager->Count; Index++)
  4804. {
  4805. if (Manager->Sessions[Index]->Active)
  4806. {
  4807. ActiveSessions++;
  4808. }
  4809. }
  4810. // Confirm, when there's at least one active remote session or
  4811. // when there are multiple (inactive or local) sessions and auto workspace saving is not enabled.
  4812. if (((ActiveSessions > 0) || ((Manager->Count > 1) && !WinConfiguration->AutoSaveWorkspace)) &&
  4813. WinConfiguration->ConfirmClosingSession)
  4814. {
  4815. unsigned int Result;
  4816. TMessageParams Params(mpNeverAskAgainCheck);
  4817. UnicodeString Message;
  4818. int Answers = qaOK | qaCancel;
  4819. // The current session is the only active session
  4820. if ((ActiveSessions == 1) && (Terminal != NULL) && Terminal->Active)
  4821. {
  4822. if (!WinConfiguration->AutoSaveWorkspace)
  4823. {
  4824. Message = LoadStr(CLOSE_SESSION_WORKSPACE);
  4825. }
  4826. else
  4827. {
  4828. Message = LoadStr(CLOSE_SESSION);
  4829. }
  4830. Message = FORMAT(Message, (Terminal->SessionData->SessionName));
  4831. }
  4832. // Multiple active sessions or one active session, but it's not the current one
  4833. else if (ActiveSessions > 0)
  4834. {
  4835. if (!WinConfiguration->AutoSaveWorkspace)
  4836. {
  4837. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
  4838. }
  4839. else
  4840. {
  4841. Message = LoadStr(CLOSE_SESSIONS);
  4842. }
  4843. }
  4844. // Multiple tabs, but all are intactive or local, and saving of worspace is not enabled
  4845. else
  4846. {
  4847. DebugAlwaysTrue(Manager->Count > 1);
  4848. DebugAlwaysTrue(!WinConfiguration->AutoSaveWorkspace);
  4849. Message = LoadStr(CLOSE_WORKSPACE);
  4850. }
  4851. UnicodeString Note;
  4852. if (WinConfiguration->AutoSaveWorkspace)
  4853. {
  4854. Note = FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()));
  4855. }
  4856. else
  4857. {
  4858. Note = LoadStr(AUTO_WORKSPACE_ENABLE);
  4859. Answers = qaYes | qaNo | qaCancel;
  4860. }
  4861. Message = FORMAT("%s\n\n%s", (MainInstructions(Message), Note));
  4862. SetFocus();
  4863. Result = MessageDialog(Message, qtConfirmation,
  4864. Answers, HELP_CLOSE_SESSION_WORKSPACE, &Params);
  4865. if (Result == qaNeverAskAgain)
  4866. {
  4867. WinConfiguration->ConfirmClosingSession = false;
  4868. }
  4869. if (Result == qaNo)
  4870. {
  4871. CanClose = SaveWorkspace(true);
  4872. // note that the workspace will be saved redundatly again from FormClose
  4873. }
  4874. else
  4875. {
  4876. CanClose =
  4877. (Result == qaOK) ||
  4878. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4879. (Result == qaNeverAskAgain);
  4880. }
  4881. }
  4882. if (CanClose && HasActiveTerminal())
  4883. {
  4884. CanClose = CanCloseQueue();
  4885. }
  4886. }
  4887. if (CanClose)
  4888. {
  4889. CanClose =
  4890. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4891. FEditorManager->CloseExternalFilesWithoutProcess();
  4892. if (CanClose)
  4893. {
  4894. while (CanClose && (FLocalEditors->Count > 0))
  4895. {
  4896. int PrevCount = FLocalEditors->Count;
  4897. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4898. CanClose = (FLocalEditors->Count < PrevCount);
  4899. }
  4900. if (CanClose)
  4901. {
  4902. CanClose = FEditorManager->Empty(true);
  4903. if (!CanClose)
  4904. {
  4905. SetFocus();
  4906. CanClose =
  4907. (MessageDialog(
  4908. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4909. }
  4910. }
  4911. }
  4912. }
  4913. }
  4914. //---------------------------------------------------------------------------
  4915. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4916. {
  4917. TForm * Form = dynamic_cast<TForm *>(Sender);
  4918. DebugAssert(Form != NULL);
  4919. Form->Close();
  4920. }
  4921. //---------------------------------------------------------------------------
  4922. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4923. {
  4924. TForm * Form = dynamic_cast<TForm *>(Sender);
  4925. delete Form;
  4926. }
  4927. //---------------------------------------------------------------------------
  4928. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4929. {
  4930. while (FLocalEditors->Count > 0)
  4931. {
  4932. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4933. }
  4934. }
  4935. //---------------------------------------------------------------------------
  4936. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4937. TObject *Sender)
  4938. {
  4939. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4940. try
  4941. {
  4942. SetProperties(osRemote, FileList);
  4943. }
  4944. __finally
  4945. {
  4946. delete FileList;
  4947. }
  4948. }
  4949. //---------------------------------------------------------------------------
  4950. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4951. {
  4952. if (value)
  4953. {
  4954. if (Component == fcCustomCommandsBand)
  4955. {
  4956. UpdateCustomCommandsToolbar();
  4957. }
  4958. if (Component == fcQueueFileList)
  4959. {
  4960. DebugAssert(!QueueFileListSplitter->Visible);
  4961. AdjustQueueLayout();
  4962. UpdateQueueFileList();
  4963. }
  4964. }
  4965. }
  4966. //---------------------------------------------------------------------------
  4967. void __fastcall TCustomScpExplorerForm::AdjustQueueLayout()
  4968. {
  4969. int MinHeightLimit =
  4970. GetStaticQueuePanelComponentsHeight() +
  4971. QueueFileListSplitter->Height +
  4972. QueueFileList->Height +
  4973. GetMinQueueViewHeight();
  4974. if (QueuePanel->ClientHeight < MinHeightLimit)
  4975. {
  4976. QueuePanel->ClientHeight = MinHeightLimit;
  4977. }
  4978. }
  4979. //---------------------------------------------------------------------------
  4980. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4981. {
  4982. TControl * Control = GetComponent(Component);
  4983. DebugAssert(Control);
  4984. bool Changed = (Control->Visible != value);
  4985. if (Changed)
  4986. {
  4987. ComponentShowing(Component, value);
  4988. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4989. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4990. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4991. if (value)
  4992. {
  4993. int RemainingHeight = Control->Parent->ClientHeight;
  4994. int RemainingWidth = Control->Parent->ClientWidth;
  4995. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4996. {
  4997. TControl * ChildControl = Control->Parent->Controls[i];
  4998. if (ChildControl->Visible)
  4999. {
  5000. switch (ChildControl->Align)
  5001. {
  5002. case alTop:
  5003. case alBottom:
  5004. RemainingHeight -= ChildControl->Height;
  5005. break;
  5006. case alLeft:
  5007. case alRight:
  5008. RemainingWidth -= ChildControl->Width;
  5009. break;
  5010. }
  5011. }
  5012. }
  5013. int Reserve = ScaleByTextHeight(this, 32);
  5014. // queue in explorer, trees in commander
  5015. if (Control->Height > RemainingHeight - Reserve)
  5016. {
  5017. Control->Height = RemainingHeight / 2;
  5018. }
  5019. if (Control->Width > RemainingWidth - Reserve)
  5020. {
  5021. Control->Width = RemainingWidth / 2;
  5022. }
  5023. }
  5024. Control->Visible = value;
  5025. if (WasFocused && Visible)
  5026. {
  5027. DirView(osCurrent)->SetFocus();
  5028. }
  5029. FixControlsPlacement();
  5030. }
  5031. }
  5032. //---------------------------------------------------------------------------
  5033. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  5034. {
  5035. TControl * Control = GetComponent(Component);
  5036. if (Control == NULL)
  5037. {
  5038. return false;
  5039. }
  5040. else
  5041. {
  5042. return Control->Visible;
  5043. }
  5044. }
  5045. //---------------------------------------------------------------------------
  5046. bool __fastcall TCustomScpExplorerForm::IsComponentPossible(Byte Component)
  5047. {
  5048. bool Result;
  5049. if ((Component == fcExplorerUpdatesBand) || (Component == fcCommanderUpdatesBand))
  5050. {
  5051. Result = !IsUWP();
  5052. }
  5053. else
  5054. {
  5055. Result = true;
  5056. }
  5057. return Result;
  5058. }
  5059. //---------------------------------------------------------------------------
  5060. void __fastcall TCustomScpExplorerForm::MakeFocusedItemVisible(TCustomDirView * DirView)
  5061. {
  5062. if (DirView->ItemFocused != NULL)
  5063. {
  5064. DirView->ItemFocused->MakeVisible(false);
  5065. }
  5066. }
  5067. //---------------------------------------------------------------------------
  5068. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  5069. {
  5070. MakeFocusedItemVisible(RemoteDirView);
  5071. QueueSplitter->Visible = QueuePanel->Visible;
  5072. QueueFileListSplitter->Visible = QueueFileList->Visible;
  5073. RemotePanelSplitter->Visible = RemoteDrivePanel->Visible;
  5074. TControl * QueueControlsOrder[] =
  5075. { QueueDock, QueueView3, QueueFileListSplitter, QueueFileList };
  5076. SetVerticalControlsOrder(QueueControlsOrder, LENOF(QueueControlsOrder));
  5077. }
  5078. //---------------------------------------------------------------------------
  5079. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  5080. {
  5081. switch (Component) {
  5082. case fcStatusBar: return RemoteStatusBar;
  5083. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  5084. case fcQueueView: return QueuePanel;
  5085. case fcQueueToolbar: return QueueDock;
  5086. case fcRemoteTree: return RemoteDrivePanel;
  5087. case fcSessionsTabs: return SessionsPageControl;
  5088. case fcQueueFileList: return QueueFileList;
  5089. default: return NULL;
  5090. }
  5091. }
  5092. //---------------------------------------------------------------------------
  5093. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  5094. TObject *Sender, TListColumn *Column, TPoint &Point)
  5095. {
  5096. DebugAssert(NonVisualDataModule && Column && Sender);
  5097. NonVisualDataModule->ListColumn = Column;
  5098. TPopupMenu * DirViewColumnMenu;
  5099. if (Sender == DirView(osOther))
  5100. {
  5101. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  5102. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  5103. (Column->Index == uvName);
  5104. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  5105. (Column->Index == uvSize);
  5106. }
  5107. else
  5108. {
  5109. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  5110. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  5111. (Column->Index == dvName);
  5112. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  5113. (Column->Index == dvSize);
  5114. }
  5115. TCustomListView * ListView = DebugNotNull(dynamic_cast<TCustomListView *>(Sender));
  5116. TPoint ScreenPoint = ListView->ClientToScreen(Point);
  5117. ScreenPoint.x -= GetScrollPos(ListView->Handle, SB_HORZ);
  5118. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  5119. }
  5120. //---------------------------------------------------------------------------
  5121. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  5122. TObject *Sender, TListItem *Item, bool &AllowExec)
  5123. {
  5124. DoDirViewExecFile(Sender, Item, AllowExec);
  5125. }
  5126. //---------------------------------------------------------------------------
  5127. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  5128. TListItem * Item, bool & AllowExec)
  5129. {
  5130. DebugAssert(Sender && Item && Configuration);
  5131. DebugAssert(AllowExec);
  5132. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  5133. TOperationSide Side = ((ADirView == DirView(osRemote)) ? osRemote : osLocal);
  5134. bool Remote = !IsSideLocalBrowser(Side);
  5135. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks || Terminal->IsEncryptingFiles();
  5136. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  5137. // on files only (not directories)
  5138. // and only when symlinks are resolved (apply to remote panel only)
  5139. if (!ADirView->ItemIsDirectory(Item) &&
  5140. (ResolvedSymlinks || FForceExecution))
  5141. {
  5142. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  5143. !FForceExecution && ResolvedSymlinks)
  5144. {
  5145. if (WinConfiguration->DoubleClickAction == dcaCopy)
  5146. {
  5147. // To counter the lock in DirViewBusy (called from TCustomDirView.DoExecute)
  5148. UnlockWindow();
  5149. try
  5150. {
  5151. if (IsLocalBrowserMode())
  5152. {
  5153. LocalLocalCopy(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation, false, 0);
  5154. }
  5155. else
  5156. {
  5157. ExecuteFileOperation(foCopy, Side, true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  5158. }
  5159. }
  5160. __finally
  5161. {
  5162. LockWindow();
  5163. }
  5164. AllowExec = false;
  5165. }
  5166. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  5167. {
  5168. if (!Remote || !WinConfiguration->DisableOpenEdit)
  5169. {
  5170. ExecuteFile(Side, efDefaultEditor);
  5171. AllowExec = false;
  5172. }
  5173. }
  5174. else
  5175. {
  5176. DebugFail();
  5177. }
  5178. }
  5179. // if we have not done anything special, fall back to default behavior
  5180. if (AllowExec)
  5181. {
  5182. if (Remote && !WinConfiguration->DisableOpenEdit)
  5183. {
  5184. ExecuteFile(osRemote, efShell);
  5185. AllowExec = false;
  5186. }
  5187. }
  5188. }
  5189. }
  5190. //---------------------------------------------------------------------------
  5191. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  5192. {
  5193. return ((Side == osRemote) || (Side == osCurrent));
  5194. }
  5195. //---------------------------------------------------------------------------
  5196. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  5197. {
  5198. DebugFail();
  5199. }
  5200. //---------------------------------------------------------------------------
  5201. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  5202. {
  5203. DebugFail();
  5204. }
  5205. //---------------------------------------------------------------------------
  5206. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  5207. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, int UseDefaults)
  5208. {
  5209. TSynchronizeParamType Params;
  5210. Params.LocalDirectory = LocalDirectory;
  5211. Params.RemoteDirectory = RemoteDirectory;
  5212. int UnusedParams =
  5213. (GUIConfiguration->SynchronizeParams &
  5214. (TTerminal::spPreviewChanges | TTerminal::spTimestamp | TTerminal::spNotByTime | TTerminal::spBySize |
  5215. TTerminal::spCaseSensitive));
  5216. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  5217. Params.Options = GUIConfiguration->SynchronizeOptions;
  5218. bool SaveSettings = false;
  5219. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  5220. &DoSynchronizeTooManyDirectories);
  5221. DebugAssert(FSynchronizeController == NULL);
  5222. FSynchronizeController = &Controller;
  5223. bool Result;
  5224. try
  5225. {
  5226. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5227. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  5228. int Options =
  5229. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  5230. DebugAssert(FOnFeedSynchronizeError == NULL);
  5231. DebugAssert(FOnSynchronizeAbort == NULL);
  5232. DebugAssert(FSynchronizeTerminal == NULL);
  5233. FSynchronizeTerminal = Terminal;
  5234. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  5235. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  5236. FOnFeedSynchronizeError, FOnSynchronizeAbort, SynchronizeInNewWindow, UseDefaults);
  5237. if (Result)
  5238. {
  5239. if (SaveSettings)
  5240. {
  5241. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  5242. GUIConfiguration->SynchronizeOptions = Params.Options;
  5243. }
  5244. else
  5245. {
  5246. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  5247. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  5248. FLAGSET(Params.Options, soSynchronize))
  5249. {
  5250. GUIConfiguration->SynchronizeOptions =
  5251. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  5252. soSynchronize;
  5253. }
  5254. }
  5255. LocalDirectory = Params.LocalDirectory;
  5256. RemoteDirectory = Params.RemoteDirectory;
  5257. }
  5258. }
  5259. __finally
  5260. {
  5261. FSynchronizeController = NULL;
  5262. DebugAssert(FOnFeedSynchronizeError == NULL);
  5263. FOnFeedSynchronizeError = NULL;
  5264. DebugAssert(FOnSynchronizeAbort == NULL);
  5265. FOnSynchronizeAbort = NULL;
  5266. FSynchronizeTerminal = NULL;
  5267. }
  5268. return Result;
  5269. }
  5270. //---------------------------------------------------------------------------
  5271. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  5272. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  5273. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  5274. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  5275. TSynchronizeOptions * Options, bool Full)
  5276. {
  5277. // Keep-up-to-date mode
  5278. if (Terminal->Status == ssOpened)
  5279. {
  5280. try
  5281. {
  5282. int PParams = Params.Params;
  5283. if (!Full)
  5284. {
  5285. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache | TTerminal::spDelayProgress;
  5286. if (FLAGSET(Params.Options, soRecurse))
  5287. {
  5288. PParams |= TTerminal::spSubDirs;
  5289. }
  5290. }
  5291. else
  5292. {
  5293. // if keepuptodate is non-recursive,
  5294. // full sync before has to be non-recursive as well
  5295. if (FLAGCLEAR(Params.Options, soRecurse))
  5296. {
  5297. PParams |= TTerminal::spNoRecurse;
  5298. }
  5299. }
  5300. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  5301. PParams, Checklist, Options);
  5302. }
  5303. catch (Exception & E)
  5304. {
  5305. if (!Terminal->Active)
  5306. {
  5307. ShowExtendedExceptionEx(Terminal, &E);
  5308. // Do not abort the "keep up to date" when the session was succesfully reconnected.
  5309. if (!Terminal->Active)
  5310. {
  5311. throw;
  5312. }
  5313. }
  5314. else
  5315. {
  5316. if (FLAGSET(Params.Options, soContinueOnError) &&
  5317. DebugAlwaysTrue(FOnFeedSynchronizeError != NULL))
  5318. {
  5319. // noop, already logged in MoreMessageDialog
  5320. }
  5321. else
  5322. {
  5323. // We get mostly EAbort here, so this is noop.
  5324. // Exception is an error when listing directories while looking for differences.
  5325. ShowExtendedExceptionEx(Terminal, &E);
  5326. throw;
  5327. }
  5328. }
  5329. }
  5330. }
  5331. }
  5332. //---------------------------------------------------------------------------
  5333. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  5334. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  5335. const UnicodeString ErrorStr)
  5336. {
  5337. if (!Directory.IsEmpty())
  5338. {
  5339. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  5340. }
  5341. else
  5342. {
  5343. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  5344. }
  5345. }
  5346. //---------------------------------------------------------------------------
  5347. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  5348. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  5349. {
  5350. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  5351. {
  5352. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  5353. }
  5354. else
  5355. {
  5356. TMessageParams Params(mpNeverAskAgainCheck);
  5357. unsigned int Result = MessageDialog(
  5358. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  5359. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  5360. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  5361. {
  5362. MaxDirectories *= 2;
  5363. if (Result == qaNeverAskAgain)
  5364. {
  5365. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  5366. }
  5367. }
  5368. else
  5369. {
  5370. Abort();
  5371. }
  5372. }
  5373. }
  5374. //---------------------------------------------------------------------------
  5375. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  5376. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  5377. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  5378. TSynchronizeOptions * Options)
  5379. {
  5380. // Keep-up-to-date mode
  5381. DebugAssert(!FAutoOperation);
  5382. void * BatchStorage;
  5383. BatchStart(BatchStorage);
  5384. FAutoOperation = true;
  5385. bool AnyOperation = false;
  5386. TDateTime StartTime = Now();
  5387. TSynchronizeChecklist * AChecklist = NULL;
  5388. try
  5389. {
  5390. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, -1);
  5391. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  5392. {
  5393. FSynchronizeProgressForm->Start();
  5394. }
  5395. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5396. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5397. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5398. Options);
  5399. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5400. SAFE_DESTROY(FSynchronizeProgressForm);
  5401. AnyOperation = (AChecklist->CheckedCount > 0);
  5402. if (AnyOperation)
  5403. {
  5404. TSynchronizeProgress SynchronizeProgress(AChecklist);
  5405. CreateProgressForm(&SynchronizeProgress);
  5406. try
  5407. {
  5408. Terminal->SynchronizeApply(
  5409. AChecklist, &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5410. SynchronizeProcessedItem, NULL, NULL, NULL);
  5411. }
  5412. __finally
  5413. {
  5414. DestroyProgressForm();
  5415. }
  5416. }
  5417. }
  5418. __finally
  5419. {
  5420. if (Checklist == NULL)
  5421. {
  5422. delete AChecklist;
  5423. }
  5424. else
  5425. {
  5426. *Checklist = AChecklist;
  5427. }
  5428. FAutoOperation = false;
  5429. SAFE_DESTROY(FSynchronizeProgressForm);
  5430. BatchEnd(BatchStorage);
  5431. ReloadLocalDirectory();
  5432. if (AnyOperation)
  5433. {
  5434. OperationComplete(StartTime);
  5435. }
  5436. }
  5437. }
  5438. //---------------------------------------------------------------------------
  5439. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  5440. {
  5441. // can be called from command line
  5442. return Visible &&
  5443. ((DirView(osRemote)->SelCount > 0) ||
  5444. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  5445. }
  5446. //---------------------------------------------------------------------------
  5447. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  5448. {
  5449. LogSynchronizeEvent(Terminal, Message);
  5450. }
  5451. //---------------------------------------------------------------------------
  5452. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  5453. int Params, TSynchronizeOptions & Options)
  5454. {
  5455. DebugAssert(!IsLocalBrowserMode());
  5456. if (FLAGSET(Params, TTerminal::spSelectedOnly) && SynchronizeAllowSelectedOnly())
  5457. {
  5458. Options.Filter = new TStringList();
  5459. Options.Filter->CaseSensitive = false;
  5460. Options.Filter->Duplicates = Types::dupAccept;
  5461. if (DirView(osRemote)->SelCount > 0)
  5462. {
  5463. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  5464. }
  5465. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  5466. {
  5467. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  5468. }
  5469. Options.Filter->Sort();
  5470. }
  5471. }
  5472. //---------------------------------------------------------------------------
  5473. UnicodeString __fastcall TCustomScpExplorerForm::SerializeCopyParamForCommandLine(const TCopyParamType * CopyParams)
  5474. {
  5475. TCopyParamType Defaults;
  5476. std::unique_ptr<THierarchicalStorage> ConfigStorage(Configuration->CreateConfigStorage());
  5477. ConfigStorage->AccessMode = smRead;
  5478. if (ConfigStorage->OpenSubKey(Configuration->ConfigurationSubKey, false))
  5479. {
  5480. GUIConfiguration->LoadCopyParam(ConfigStorage.get(), &Defaults);
  5481. }
  5482. ConfigStorage.reset(NULL);
  5483. std::unique_ptr<TStringList> Options(new TStringList());
  5484. std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
  5485. CopyParams->Save(OptionsStorage.get(), &Defaults);
  5486. UnicodeString Result;
  5487. if (Options->Count > 0)
  5488. {
  5489. Result =
  5490. FORMAT(L" %s%s", (TProgramParams::FormatSwitch(RAWTRANSFERSETTINGS_SWITCH), StringsToParams(Options.get())));
  5491. }
  5492. return Result;
  5493. }
  5494. //---------------------------------------------------------------------------
  5495. void __fastcall TCustomScpExplorerForm::SynchronizeInNewWindow(
  5496. const TSynchronizeParamType & Params, const TCopyParamType * CopyParams)
  5497. {
  5498. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5499. UnicodeString AdditionalParams =
  5500. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5501. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5502. SerializeCopyParamForCommandLine(CopyParams),
  5503. TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH),
  5504. Params.LocalDirectory, Params.RemoteDirectory, Params.Params, Params.Options));
  5505. ExecuteNewInstance(SessionName, AdditionalParams);
  5506. }
  5507. //---------------------------------------------------------------------------
  5508. struct TSynchronizeParams
  5509. {
  5510. UnicodeString LocalDirectory;
  5511. UnicodeString RemoteDirectory;
  5512. TSynchronizeMode Mode;
  5513. TSynchronizeChecklist * Checklist;
  5514. int Params;
  5515. TCopyParamType * CopyParam;
  5516. TDateTime CollectElapsed;
  5517. TDateTime * StartTime;
  5518. TProcessedSynchronizationChecklistItem OnProcessedItem;
  5519. };
  5520. //---------------------------------------------------------------------------
  5521. void __fastcall TCustomScpExplorerForm::FullSynchronize(
  5522. TSynchronizeParams & Params, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5523. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5524. {
  5525. DebugAssert(!FAutoOperation);
  5526. void * BatchStorage;
  5527. BatchStart(BatchStorage);
  5528. FAutoOperation = true;
  5529. TFileOperationStatistics Statistics;
  5530. TDateTime Start = Now();
  5531. try
  5532. {
  5533. Params.OnProcessedItem = OnProcessedItem;
  5534. TSynchronizeProgress SynchronizeProgress(Params.Checklist);
  5535. CreateProgressForm(&SynchronizeProgress);
  5536. Terminal->SynchronizeApply(
  5537. Params.Checklist, Params.CopyParam, Params.Params | TTerminal::spNoConfirmation,
  5538. TerminalSynchronizeDirectory, SynchronizeProcessedItem, OnUpdatedSynchronizationChecklistItems, &Params,
  5539. &Statistics);
  5540. }
  5541. __finally
  5542. {
  5543. Params.OnProcessedItem = NULL;
  5544. FAutoOperation = false;
  5545. DestroyProgressForm();
  5546. BatchEnd(BatchStorage);
  5547. ReloadLocalDirectory();
  5548. }
  5549. if (WinConfiguration->SynchronizeSummary)
  5550. {
  5551. UnicodeString Message = MainInstructions(LoadStr(SYNCHRONIZE_COMPLETE)) + L"\n";
  5552. // The statistics should be 0 anyway in this case
  5553. if (FLAGCLEAR(Params.Params, TTerminal::spTimestamp))
  5554. {
  5555. Message += L"\n";
  5556. if (Statistics.FilesUploaded > 0)
  5557. {
  5558. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 1), (FormatNumber(Statistics.FilesUploaded), FormatBytes(Statistics.TotalUploaded))) + L"\n";
  5559. }
  5560. if (Statistics.FilesDownloaded > 0)
  5561. {
  5562. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 2), (FormatNumber(Statistics.FilesDownloaded), FormatBytes(Statistics.TotalDownloaded))) + L"\n";
  5563. }
  5564. if (Statistics.FilesDeletedLocal > 0)
  5565. {
  5566. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 3), (FormatNumber(Statistics.FilesDeletedLocal))) + L"\n";
  5567. }
  5568. if (Statistics.FilesDeletedRemote > 0)
  5569. {
  5570. Message += FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 4), (FormatNumber(Statistics.FilesDeletedRemote))) + L"\n";
  5571. }
  5572. }
  5573. TDateTime Elapsed = (Now() - Start);
  5574. Message +=
  5575. L"\n" +
  5576. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 5), (FormatDateTimeSpan(Configuration->TimeFormat, Params.CollectElapsed))) + L"\n" +
  5577. FORMAT(LoadStrPart(SYNCHRONIZE_SUMMARY, 6), (FormatDateTimeSpan(Configuration->TimeFormat, Elapsed)));
  5578. TMessageParams Params(mpNeverAskAgainCheck);
  5579. unsigned int Result = MessageDialog(Message, qtInformation, qaOK, HELP_NONE, &Params);
  5580. if (Result == qaNeverAskAgain)
  5581. {
  5582. WinConfiguration->SynchronizeSummary = false;
  5583. }
  5584. }
  5585. }
  5586. //---------------------------------------------------------------------------
  5587. void __fastcall TCustomScpExplorerForm::SynchronizeProcessedItem(void * Token, const TSynchronizeChecklist::TItem * ChecklistItem)
  5588. {
  5589. if (DebugAlwaysTrue(FProgressForm != NULL) && DebugAlwaysTrue(FProgressForm->SynchronizeProgress != NULL))
  5590. {
  5591. FProgressForm->SynchronizeProgress->ItemProcessed(ChecklistItem);
  5592. }
  5593. // Not set in keep-up-to-date mode - Synchronize() method
  5594. if (Token != NULL)
  5595. {
  5596. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5597. if (Params.OnProcessedItem != NULL)
  5598. {
  5599. Params.OnProcessedItem(NULL, ChecklistItem);
  5600. }
  5601. }
  5602. }
  5603. //---------------------------------------------------------------------------
  5604. void __fastcall TCustomScpExplorerForm::DoFullSynchronize(
  5605. void * Token, TProcessedSynchronizationChecklistItem OnProcessedItem,
  5606. TUpdatedSynchronizationChecklistItems OnUpdatedSynchronizationChecklistItems)
  5607. {
  5608. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5609. *Params.StartTime = Now();
  5610. FullSynchronize(Params, OnProcessedItem, OnUpdatedSynchronizationChecklistItems);
  5611. }
  5612. //---------------------------------------------------------------------------
  5613. void __fastcall TCustomScpExplorerForm::DoSynchronizeChecklistCalculateSize(
  5614. TSynchronizeChecklist * Checklist, const TSynchronizeChecklist::TItemList & Items, void * Token)
  5615. {
  5616. // terminal can be already closed (e.g. dropped connection)
  5617. if (Terminal != NULL)
  5618. {
  5619. TSynchronizeParams & Params = *static_cast<TSynchronizeParams *>(Token);
  5620. Terminal->SynchronizeChecklistCalculateSize(Checklist, Items, Params.CopyParam);
  5621. }
  5622. }
  5623. //---------------------------------------------------------------------------
  5624. void __fastcall TCustomScpExplorerForm::DoSynchronizeMove(
  5625. TOperationSide Side, const UnicodeString & FileName, const UnicodeString & NewFileName, TRemoteFile * RemoteFile)
  5626. {
  5627. DebugAssert(!IsLocalBrowserMode());
  5628. TAutoBatch AutoBatch(this);
  5629. TAutoFlag AutoOperationFlag(FAutoOperation);
  5630. if (Side == osRemote)
  5631. {
  5632. std::unique_ptr<TStrings> FileList(new TStringList());
  5633. FileList->AddObject(FileName, RemoteFile);
  5634. UnicodeString Target = UnixExtractFileDir(NewFileName);
  5635. UnicodeString FileMask = DelimitFileNameMask(UnixExtractFileName(NewFileName));
  5636. RemoteDirView->SaveSelection();
  5637. RemoteDirView->SaveSelectedNames();
  5638. try
  5639. {
  5640. Terminal->MoveFiles(FileList.get(), Target, FileMask);
  5641. }
  5642. catch(...)
  5643. {
  5644. RemoteDirView->DiscardSavedSelection();
  5645. throw;
  5646. }
  5647. RemoteDirView->RestoreSelection();
  5648. }
  5649. else if (DebugAlwaysTrue(Side == osLocal))
  5650. {
  5651. if (!MoveFile(FileName.c_str(), NewFileName.c_str()))
  5652. {
  5653. throw EOSExtException(FMTLOAD(RENAME_FILE_ERROR, (FileName, NewFileName)));
  5654. }
  5655. UnicodeString Directory = ExtractFileDir(FileName);
  5656. ReloadLocalDirectory(Directory);
  5657. UnicodeString NewDirectory = ExtractFileDir(NewFileName);
  5658. if (!SamePaths(Directory, NewDirectory))
  5659. {
  5660. ReloadLocalDirectory(NewDirectory);
  5661. }
  5662. }
  5663. }
  5664. //---------------------------------------------------------------------------
  5665. void __fastcall TCustomScpExplorerForm::DoSynchronizeBrowse(TOperationSide Side, TSynchronizeChecklist::TAction Action, const TSynchronizeChecklist::TItem * Item)
  5666. {
  5667. UnicodeString LocalPath = ExcludeTrailingBackslash(Item->Local.Directory);
  5668. if (Side == osLocal)
  5669. {
  5670. if (Action == TSynchronizeChecklist::saDownloadNew)
  5671. {
  5672. OpenFolderInExplorer(LocalPath);
  5673. }
  5674. else
  5675. {
  5676. OpenFileInExplorer(TPath::Combine(LocalPath, Item->GetFileName()));
  5677. }
  5678. }
  5679. else if (DebugAlwaysTrue(Side == osRemote))
  5680. {
  5681. // Similar to CreateHiddenDuplicateSession, except that it modifies the initial directories
  5682. std::unique_ptr<TSessionData> SessionData(CloneCurrentSessionData());
  5683. SessionData->RemoteDirectory = UnixExcludeTrailingBackslash(Item->Remote.Directory);
  5684. if (!LocalPath.IsEmpty())
  5685. {
  5686. SessionData->LocalDirectory = LocalPath;
  5687. }
  5688. UnicodeString SessionName = SaveHiddenDuplicateSession(SessionData.get());
  5689. ExecuteNewInstance(SessionName, FORMAT(L"%s=%s", (TProgramParams::FormatSwitch(BROWSE_SWITCH), Item->GetFileName())));
  5690. }
  5691. }
  5692. //---------------------------------------------------------------------------
  5693. void __fastcall TCustomScpExplorerForm::FullSynchronizeInNewWindow(
  5694. TSynchronizeMode Mode, int Params, const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5695. const TCopyParamType * CopyParams)
  5696. {
  5697. UnicodeString SessionName = CreateHiddenDuplicateSession();
  5698. UnicodeString AdditionalParams =
  5699. FORMAT(L"%s%s %s // \"%s\" \"%s\" %d %d", (
  5700. TProgramParams::FormatSwitch(DEFAULTS_SWITCH),
  5701. SerializeCopyParamForCommandLine(CopyParams),
  5702. TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH),
  5703. LocalDirectory, RemoteDirectory, Mode, Params));
  5704. ExecuteNewInstance(SessionName, AdditionalParams);
  5705. }
  5706. //---------------------------------------------------------------------------
  5707. int __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  5708. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  5709. TSynchronizeMode & Mode, int Params, bool & SaveMode, int UseDefaults)
  5710. {
  5711. int Result;
  5712. bool SaveSettings = false;
  5713. int Options =
  5714. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  5715. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  5716. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  5717. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  5718. bool Continue =
  5719. (UseDefaults == 0) ||
  5720. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  5721. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs, FullSynchronizeInNewWindow, UseDefaults);
  5722. if (Continue)
  5723. {
  5724. Configuration->Usage->Inc(L"Synchronizations");
  5725. UpdateCopyParamCounters(CopyParam);
  5726. TSynchronizeOptions SynchronizeOptions;
  5727. GetSynchronizeOptions(Params, SynchronizeOptions);
  5728. if (SaveSettings)
  5729. {
  5730. GUIConfiguration->SynchronizeParams = Params;
  5731. }
  5732. else
  5733. {
  5734. SaveMode = false;
  5735. }
  5736. TDateTime StartTime = Now();
  5737. TSynchronizeChecklist * Checklist = NULL;
  5738. try
  5739. {
  5740. DebugAssert(!FAutoOperation);
  5741. FAutoOperation = true;
  5742. try
  5743. {
  5744. UnicodeString SessionKey = Terminal->SessionData->SessionKey;
  5745. std::unique_ptr<TStrings> DataList(Configuration->LoadDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam));
  5746. int Files = -1;
  5747. if (DataList->Count >= 1)
  5748. {
  5749. Files = StrToIntDef(DataList->Strings[0], Files);
  5750. }
  5751. else
  5752. {
  5753. DataList->Add(UnicodeString());
  5754. }
  5755. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, Files);
  5756. FSynchronizeProgressForm->Start();
  5757. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  5758. static_cast<TTerminal::TSynchronizeMode>(Mode),
  5759. &CopyParam, Params | TTerminal::spNoConfirmation, TerminalSynchronizeDirectory,
  5760. &SynchronizeOptions);
  5761. if (Terminal->SessionData->CacheDirectories)
  5762. {
  5763. DataList->Strings[0] = IntToStr(SynchronizeOptions.Files);
  5764. Configuration->SaveDirectoryStatisticsCache(SessionKey, RemoteDirectory, CopyParam, DataList.get());
  5765. }
  5766. }
  5767. __finally
  5768. {
  5769. FAutoOperation = false;
  5770. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  5771. SAFE_DESTROY(FSynchronizeProgressForm);
  5772. }
  5773. TSynchronizeParams SynchronizeParams;
  5774. SynchronizeParams.LocalDirectory = LocalDirectory;
  5775. SynchronizeParams.RemoteDirectory = RemoteDirectory;
  5776. SynchronizeParams.Mode = Mode;
  5777. SynchronizeParams.CopyParam = &CopyParam;
  5778. SynchronizeParams.Params = Params;
  5779. SynchronizeParams.Checklist = Checklist;
  5780. SynchronizeParams.CollectElapsed = (Now() - StartTime);
  5781. SynchronizeParams.StartTime = &StartTime;
  5782. SynchronizeParams.OnProcessedItem = NULL;
  5783. Result = Checklist->Count;
  5784. if (Checklist->Count > 0)
  5785. {
  5786. if (FLAGSET(Params, TTerminal::spPreviewChanges))
  5787. {
  5788. if (!DoSynchronizeChecklistDialog(
  5789. Checklist, Mode, Params, LocalDirectory, RemoteDirectory, CustomCommandMenu, DoFullSynchronize,
  5790. DoSynchronizeChecklistCalculateSize, DoSynchronizeMove, DoSynchronizeBrowse, &SynchronizeParams))
  5791. {
  5792. Result = -1;
  5793. }
  5794. }
  5795. else
  5796. {
  5797. FullSynchronize(SynchronizeParams, NULL, NULL);
  5798. }
  5799. }
  5800. else
  5801. {
  5802. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  5803. MessageDialog(Message, qtInformation, qaOK, HELP_SYNCHRONIZE_NO_DIFFERENCES);
  5804. }
  5805. }
  5806. __finally
  5807. {
  5808. delete Checklist;
  5809. }
  5810. OperationComplete(StartTime);
  5811. }
  5812. else
  5813. {
  5814. Result = -1;
  5815. }
  5816. return Result;
  5817. }
  5818. //---------------------------------------------------------------------------
  5819. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  5820. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  5821. bool & Continue, bool Collect, const TSynchronizeOptions * Options)
  5822. {
  5823. if (Collect)
  5824. {
  5825. DebugAssert(FSynchronizeProgressForm != NULL);
  5826. if (!FSynchronizeProgressForm->Started)
  5827. {
  5828. FSynchronizeProgressForm->Start();
  5829. }
  5830. int CompareProgress = FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Options->Files, Continue);
  5831. SetTaskbarListProgressValue(CompareProgress);
  5832. }
  5833. else
  5834. {
  5835. DebugAssert(FSynchronizeProgressForm == NULL);
  5836. DebugAssert(FProgressForm != NULL);
  5837. }
  5838. }
  5839. //---------------------------------------------------------------------------
  5840. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  5841. {
  5842. UnicodeString FullFileName = AbsolutePath(Terminal->CurrentDirectory, FileName);
  5843. TRemoteFile * File = NULL;
  5844. Terminal->ReadFile(FullFileName, File);
  5845. if (File != NULL)
  5846. {
  5847. std::unique_ptr<TRemoteFile> FileOwner(File);
  5848. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  5849. Application->ShowMainForm = false;
  5850. Application->Run();
  5851. }
  5852. }
  5853. //---------------------------------------------------------------------------
  5854. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory(TOperationSide)
  5855. {
  5856. DebugFail();
  5857. }
  5858. //---------------------------------------------------------------------------
  5859. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  5860. {
  5861. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  5862. SessionData->Assign(ManagedSession->SessionData);
  5863. UpdateSessionData(SessionData.get());
  5864. DebugAssert(SessionData->IsLocalBrowser == IsLocalBrowserMode());
  5865. if (IsActiveTerminal(ManagedSession))
  5866. {
  5867. ManagedSession->UpdateSessionCredentials(SessionData.get());
  5868. }
  5869. if (!ManagedSession->SessionData->HasSessionName())
  5870. {
  5871. // Particularly for "Workspace/XXXX" name, we need to reset it, as it would become user-visible
  5872. // once IsWorkspace is cleared
  5873. SessionData->Name = UnicodeString();
  5874. }
  5875. // Most uses of this method ends with saving the session, and we do not want to store the IsWorkspace flag.
  5876. // Particularly, with SaveHiddenDuplicateSession, it won't work as TSessionData::ParseUrl explicitly ignored workspace sessions.
  5877. SessionData->IsWorkspace = false;
  5878. return SessionData.release();
  5879. }
  5880. //---------------------------------------------------------------------------
  5881. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  5882. {
  5883. TSessionData * SessionData = CloneCurrentSessionData();
  5884. try
  5885. {
  5886. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  5887. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  5888. }
  5889. __finally
  5890. {
  5891. delete SessionData;
  5892. }
  5893. }
  5894. //---------------------------------------------------------------------------
  5895. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  5896. {
  5897. TTerminalManager * Manager = TTerminalManager::Instance();
  5898. std::unique_ptr<TObjectList> DataList(new TObjectList());
  5899. if (DebugAlwaysTrue(ManagedSession != NULL))
  5900. {
  5901. // Update ManagedSession->StateData
  5902. UpdateSession(ManagedSession);
  5903. }
  5904. Manager->SaveWorkspace(DataList.get());
  5905. return DataList.release();
  5906. }
  5907. //---------------------------------------------------------------------------
  5908. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  5909. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords, bool Explicit)
  5910. {
  5911. WinConfiguration->LastWorkspace = Name;
  5912. if (!SavePasswords)
  5913. {
  5914. for (int Index = 0; Index < DataList->Count; Index++)
  5915. {
  5916. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5917. if (SessionData->Link.IsEmpty())
  5918. {
  5919. SessionData->ClearSessionPasswords();
  5920. }
  5921. }
  5922. }
  5923. StoredSessions->NewWorkspace(Name, DataList);
  5924. // modified only
  5925. StoredSessions->Save(false, Explicit);
  5926. }
  5927. //---------------------------------------------------------------------------
  5928. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  5929. {
  5930. return
  5931. DefaultStr(WinConfiguration->LastWorkspace,
  5932. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  5933. }
  5934. //---------------------------------------------------------------------------
  5935. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  5936. {
  5937. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  5938. bool AnyNonStoredSessionWithPassword = false;
  5939. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  5940. bool AllNonStoredSessionsAnonymous = true;
  5941. TTerminalManager * Manager = TTerminalManager::Instance();
  5942. for (int Index = 0; Index < DataList->Count; Index++)
  5943. {
  5944. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  5945. if (SessionData->Link.IsEmpty())
  5946. {
  5947. if (SessionData->HasAnySessionPassword())
  5948. {
  5949. AnyNonStoredSessionWithPassword = true;
  5950. if (!Manager->Sessions[Index]->SessionData->IsWorkspace)
  5951. {
  5952. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  5953. }
  5954. }
  5955. if (!SameText(SessionData->UserName, AnonymousUserName))
  5956. {
  5957. AllNonStoredSessionsAnonymous = false;
  5958. }
  5959. }
  5960. }
  5961. bool SavePasswords;
  5962. bool * PSavePasswords;
  5963. bool NotRecommendedSavingPasswords =
  5964. !CustomWinConfiguration->UseMasterPassword &&
  5965. !AllNonStoredSessionsAnonymous;
  5966. if (Configuration->DisablePasswordStoring ||
  5967. !AnyNonStoredSessionWithPassword)
  5968. {
  5969. PSavePasswords = NULL;
  5970. SavePasswords = false;
  5971. }
  5972. else
  5973. {
  5974. PSavePasswords = &SavePasswords;
  5975. SavePasswords =
  5976. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  5977. !NotRecommendedSavingPasswords;
  5978. }
  5979. UnicodeString Name = WorkspaceName();
  5980. bool CreateShortcut = false;
  5981. bool Result =
  5982. DoSaveWorkspaceDialog(
  5983. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5984. EnableAutoSave);
  5985. if (Result)
  5986. {
  5987. DoSaveWorkspace(Name, DataList.get(), SavePasswords, true);
  5988. if (CreateShortcut)
  5989. {
  5990. TOperationVisualizer Visualizer;
  5991. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5992. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5993. }
  5994. if (EnableAutoSave)
  5995. {
  5996. WinConfiguration->AutoSaveWorkspace = true;
  5997. WinConfiguration->AutoWorkspace = Name;
  5998. if (PSavePasswords != NULL)
  5999. {
  6000. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  6001. }
  6002. }
  6003. }
  6004. return Result;
  6005. }
  6006. //---------------------------------------------------------------------------
  6007. void __fastcall TCustomScpExplorerForm::UpdateSession(TManagedTerminal * Session)
  6008. {
  6009. DebugAssert(IsLocalBrowserMode() == Session->LocalBrowser);
  6010. DebugAssert(Session == ManagedSession);
  6011. if (!IsLocalBrowserMode())
  6012. {
  6013. SAFE_DESTROY(Session->RemoteExplorerState);
  6014. if (WinConfiguration->PreservePanelState)
  6015. {
  6016. Session->RemoteExplorerState = RemoteDirView->SaveState();
  6017. }
  6018. }
  6019. UpdateSessionData(Session->StateData);
  6020. }
  6021. //---------------------------------------------------------------------------
  6022. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  6023. {
  6024. // Keep in sync with TSessionData::CopyStateData
  6025. DebugAssert(Data != NULL);
  6026. // This is inconsistent with how color (for example) is handled.
  6027. Data->Name = ManagedSession->SessionData->Name;
  6028. if (!IsLocalBrowserMode())
  6029. {
  6030. // cannot use RemoteDirView->Path, because it is empty if connection
  6031. // was already closed
  6032. // also only peek, we may not be connected at all atm
  6033. // so make sure we do not try retrieving current directory from the server
  6034. // (particularly with FTP)
  6035. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  6036. if (!ACurrentDirectory.IsEmpty())
  6037. {
  6038. Data->RemoteDirectory = ACurrentDirectory;
  6039. }
  6040. }
  6041. Data->Color = SessionColor;
  6042. }
  6043. //---------------------------------------------------------------------------
  6044. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  6045. {
  6046. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  6047. DebugAssert(Toolbar != NULL);
  6048. for (int i = 0; i < Toolbar->Items->Count; i++)
  6049. {
  6050. TTBXCustomDropDownItem * DropDownItem;
  6051. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  6052. if (DropDownItem != NULL)
  6053. {
  6054. ToolbarItemResize(DropDownItem,
  6055. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  6056. Toolbar->NonClientWidth);
  6057. break;
  6058. }
  6059. }
  6060. }
  6061. //---------------------------------------------------------------------------
  6062. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  6063. {
  6064. Item->EditWidth = Width;
  6065. }
  6066. //---------------------------------------------------------------------------
  6067. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  6068. TTBCustomToolbar * Toolbar, TPoint & ASize)
  6069. {
  6070. for (int i = 0; i < Toolbar->Items->Count; i++)
  6071. {
  6072. TTBXCustomDropDownItem * DropDownItem;
  6073. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  6074. if (DropDownItem != NULL)
  6075. {
  6076. ASize.x -= DropDownItem->EditWidth;
  6077. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  6078. }
  6079. }
  6080. }
  6081. //---------------------------------------------------------------------------
  6082. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  6083. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  6084. {
  6085. if (WinConfiguration->DDWarnLackOfTempSpace)
  6086. {
  6087. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  6088. if (!ADrive.IsEmpty())
  6089. {
  6090. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  6091. DebugAssert(RequiredSpace >= 0);
  6092. __int64 RequiredWithReserve;
  6093. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  6094. if (FreeSpace < RequiredWithReserve)
  6095. {
  6096. unsigned int Result;
  6097. TMessageParams Params(mpNeverAskAgainCheck);
  6098. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  6099. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  6100. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  6101. if (Result == qaNeverAskAgain)
  6102. {
  6103. WinConfiguration->DDWarnLackOfTempSpace = false;
  6104. }
  6105. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  6106. }
  6107. }
  6108. }
  6109. }
  6110. //---------------------------------------------------------------------------
  6111. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  6112. {
  6113. DoOpenDirectoryDialog(odAddBookmark, Side);
  6114. }
  6115. //---------------------------------------------------------------------------
  6116. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  6117. {
  6118. // we should better use TCustomDirView::FCaseSensitive, but it is private
  6119. TStringList * VisitedDirectories = CreateSortedStringList(!IsSideLocalBrowser(Side));
  6120. try
  6121. {
  6122. TCustomDirView * DView = DirView(Side);
  6123. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  6124. {
  6125. VisitedDirectories->Add(DView->HistoryPath[Index]);
  6126. }
  6127. }
  6128. catch (...)
  6129. {
  6130. delete VisitedDirectories;
  6131. throw;
  6132. }
  6133. return VisitedDirectories;
  6134. }
  6135. //---------------------------------------------------------------------------
  6136. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  6137. TOpenDirectoryMode Mode, TOperationSide Side)
  6138. {
  6139. bool Continue = true;
  6140. if (Mode == odAddBookmark)
  6141. {
  6142. TMessageParams Params(mpNeverAskAgainCheck);
  6143. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  6144. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  6145. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  6146. unsigned int Answer =
  6147. MessageDialog(Message,
  6148. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  6149. if (Answer == qaNeverAskAgain)
  6150. {
  6151. Continue = true;
  6152. WinConfiguration->UseSharedBookmarks = true;
  6153. }
  6154. else if (Answer == qaOK)
  6155. {
  6156. Continue = true;
  6157. WinConfiguration->UseSharedBookmarks = false;
  6158. }
  6159. else
  6160. {
  6161. Continue = false;
  6162. }
  6163. }
  6164. if (Continue)
  6165. {
  6166. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  6167. try
  6168. {
  6169. UnicodeString Name = DirView(Side)->PathName;
  6170. bool Repeat;
  6171. do
  6172. {
  6173. Repeat = false;
  6174. TOperationSide BookmarkSide = IsSideLocalBrowser(Side) ? osLocal : osRemote;
  6175. if (::DoOpenDirectoryDialog(Mode, BookmarkSide, Name, VisitedDirectories, Terminal,
  6176. // do not allow switching to location profiles,
  6177. // if we are not connected
  6178. HasDirView[osLocal] && (Terminal != NULL)))
  6179. {
  6180. TWindowLock Lock(this);
  6181. if (!TryOpenDirectory(Side, Name))
  6182. {
  6183. Repeat = true;
  6184. Mode = odBrowse;
  6185. }
  6186. }
  6187. }
  6188. while (Repeat);
  6189. }
  6190. __finally
  6191. {
  6192. delete VisitedDirectories;
  6193. }
  6194. }
  6195. }
  6196. //---------------------------------------------------------------------------
  6197. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  6198. {
  6199. DebugAssert(!Terminal->CommandSessionOpened);
  6200. return TTerminalManager::Instance()->ConnectTerminal(Terminal->CommandSession);
  6201. }
  6202. //---------------------------------------------------------------------------
  6203. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  6204. {
  6205. bool Result = Terminal->IsCapable[Capability] ||
  6206. Terminal->CommandSessionOpened;
  6207. if (!Result)
  6208. {
  6209. DebugAssert(Terminal->IsCapable[fcSecondaryShell]);
  6210. if (!GUIConfiguration->ConfirmCommandSession)
  6211. {
  6212. Result = true;
  6213. }
  6214. else
  6215. {
  6216. TMessageParams Params(mpNeverAskAgainCheck);
  6217. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  6218. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  6219. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  6220. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  6221. if (Answer == qaNeverAskAgain)
  6222. {
  6223. GUIConfiguration->ConfirmCommandSession = false;
  6224. Result = true;
  6225. }
  6226. else if (Answer == qaOK)
  6227. {
  6228. Result = true;
  6229. }
  6230. }
  6231. if (Result)
  6232. {
  6233. Result = CommandSessionFallback();
  6234. }
  6235. }
  6236. return Result;
  6237. }
  6238. //---------------------------------------------------------------------------
  6239. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  6240. {
  6241. if (EnsureCommandSessionFallback(fcAnyCommand))
  6242. {
  6243. DoConsoleDialog(Terminal, Command);
  6244. }
  6245. }
  6246. //---------------------------------------------------------------------------
  6247. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  6248. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  6249. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  6250. {
  6251. if (!IsSideLocalBrowser(osRemote) &&
  6252. IsFileControl(DropSourceControl, osRemote) &&
  6253. (FDDExtMapFile != NULL))
  6254. {
  6255. Accept = true;
  6256. }
  6257. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  6258. DebugAssert(FDDTargetControl != NULL);
  6259. }
  6260. //---------------------------------------------------------------------------
  6261. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  6262. _di_IDataObject DataObj, int KeyState,
  6263. const TPoint & Point, int & Effect, bool & Accept)
  6264. {
  6265. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  6266. }
  6267. //---------------------------------------------------------------------------
  6268. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  6269. _di_IDataObject DataObj, int KeyState,
  6270. const TPoint & Point, int & Effect, bool & Accept)
  6271. {
  6272. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  6273. }
  6274. //---------------------------------------------------------------------------
  6275. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  6276. TObject * Sender)
  6277. {
  6278. DebugUsedParam(Sender);
  6279. DebugAssert(FDDTargetControl == Sender);
  6280. FDDTargetControl = NULL;
  6281. }
  6282. //---------------------------------------------------------------------------
  6283. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  6284. {
  6285. FileControlDDDragLeave(SessionsPageControl);
  6286. }
  6287. //---------------------------------------------------------------------------
  6288. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  6289. {
  6290. FileControlDDDragLeave(QueueView3);
  6291. }
  6292. //---------------------------------------------------------------------------
  6293. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  6294. {
  6295. DebugAssert(!IsSideLocalBrowser(Side));
  6296. DebugUsedParam(Side);
  6297. bool Edit = false;
  6298. TRemoteFile * File = NULL;
  6299. UnicodeString FileName;
  6300. UnicodeString PointTo;
  6301. bool SymbolicLink = true;
  6302. if (RemoteDirView->ItemFocused)
  6303. {
  6304. DebugAssert(RemoteDirView->ItemFocused->Data);
  6305. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  6306. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  6307. if (Edit)
  6308. {
  6309. FileName = File->FileName;
  6310. PointTo = File->LinkTo;
  6311. }
  6312. else
  6313. {
  6314. PointTo = File->FileName;
  6315. }
  6316. }
  6317. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  6318. Terminal->IsCapable[fcHardLink]))
  6319. {
  6320. Configuration->Usage->Inc(L"RemoteLinksCreated");
  6321. if (Edit)
  6322. {
  6323. DebugAssert(File->FileName == FileName);
  6324. int Params = dfNoRecursive;
  6325. Terminal->ExceptionOnFail = true;
  6326. try
  6327. {
  6328. Terminal->DeleteFile(L"", File, &Params);
  6329. }
  6330. __finally
  6331. {
  6332. Terminal->ExceptionOnFail = false;
  6333. }
  6334. }
  6335. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  6336. }
  6337. }
  6338. //---------------------------------------------------------------------------
  6339. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  6340. {
  6341. return
  6342. (IsSideLocalBrowser(Side) ||
  6343. (HasActiveTerminal() &&
  6344. Terminal->ResolvingSymlinks &&
  6345. Terminal->IsCapable[fcSymbolicLink]));
  6346. }
  6347. //---------------------------------------------------------------------------
  6348. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  6349. {
  6350. return
  6351. !IsSideLocalBrowser(FCurrentSide) &&
  6352. (RemoteDirView->ItemFocused != NULL) &&
  6353. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  6354. Terminal->SessionData->ResolveSymlinks;
  6355. }
  6356. //---------------------------------------------------------------------------
  6357. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  6358. {
  6359. DebugAssert(!WinConfiguration->DisableOpenEdit);
  6360. FForceExecution = true;
  6361. try
  6362. {
  6363. DirView(osCurrent)->ExecuteCurrentFile();
  6364. }
  6365. __finally
  6366. {
  6367. FForceExecution = false;
  6368. }
  6369. }
  6370. //---------------------------------------------------------------------------
  6371. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  6372. {
  6373. TEditorData ExternalEditor;
  6374. ExternalEditor.Editor = edExternal;
  6375. bool Remember = false;
  6376. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc, !IsSideLocalBrowser(osCurrent)))
  6377. {
  6378. if (Remember)
  6379. {
  6380. TEditorList * EditorList = new TEditorList;
  6381. try
  6382. {
  6383. *EditorList = *WinConfiguration->EditorList;
  6384. bool Found = false;
  6385. int i = 0;
  6386. while (!Found && (i < EditorList->Count))
  6387. {
  6388. const TEditorPreferences * Editor = EditorList->Editors[i];
  6389. if ((Editor->Data->Editor == edExternal) &&
  6390. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  6391. {
  6392. Found = true;
  6393. }
  6394. i++;
  6395. }
  6396. if (!Found)
  6397. {
  6398. EditorList->Add(new TEditorPreferences(ExternalEditor));
  6399. WinConfiguration->EditorList = EditorList;
  6400. }
  6401. }
  6402. __finally
  6403. {
  6404. delete EditorList;
  6405. }
  6406. }
  6407. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  6408. }
  6409. }
  6410. //---------------------------------------------------------------------------
  6411. void __fastcall TCustomScpExplorerForm::DetachTerminal(TObject * ATerminal)
  6412. {
  6413. FEditorManager->ProcessFiles(FileTerminalRemoved, ATerminal);
  6414. if (FFileFindTerminal == ATerminal)
  6415. {
  6416. FFileFindTerminal = NULL;
  6417. HideFileFindDialog();
  6418. }
  6419. if (FClipboardTerminal == ATerminal)
  6420. {
  6421. ClipboardClear(); // implies ClipboardStop
  6422. }
  6423. if ((FOnSynchronizeAbort != NULL) &&
  6424. (ATerminal == FManagedSession))
  6425. {
  6426. FOnSynchronizeAbort(NULL);
  6427. }
  6428. }
  6429. //---------------------------------------------------------------------------
  6430. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  6431. {
  6432. DetachTerminal(Sender);
  6433. }
  6434. //---------------------------------------------------------------------------
  6435. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  6436. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  6437. {
  6438. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  6439. DebugAssert(Terminal != NULL);
  6440. if (Data->Terminal == Terminal)
  6441. {
  6442. Data->Terminal = NULL;
  6443. }
  6444. }
  6445. //---------------------------------------------------------------------------
  6446. TManagedTerminal * TCustomScpExplorerForm::GetReplacementForLastSession()
  6447. {
  6448. return NULL;
  6449. }
  6450. //---------------------------------------------------------------------------
  6451. void __fastcall TCustomScpExplorerForm::LastTerminalClosed()
  6452. {
  6453. UpdateControls();
  6454. SessionColor = TColor(0);
  6455. UpdateRemotePathComboBox(false);
  6456. NeedSession(false);
  6457. }
  6458. //---------------------------------------------------------------------------
  6459. void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
  6460. {
  6461. try
  6462. {
  6463. // Cache, as the login dialog can change its value.
  6464. // See also DoShow. Also see TTerminalManager::NewSession.
  6465. bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
  6466. try
  6467. {
  6468. if (ShowLogin)
  6469. {
  6470. bool ReloadSessions = !Startup;
  6471. TTerminalManager::Instance()->NewSession(L"", ReloadSessions, this, true);
  6472. }
  6473. }
  6474. __finally
  6475. {
  6476. // Do not terminate, if we are only starting up and we are not showing Login dialog
  6477. // (so there was no chance for the user to open any session yet)
  6478. if ((ShowLogin || !Startup) &&
  6479. !WinConfiguration->KeepOpenWhenNoSession &&
  6480. // this rules out the implicit Commander's local-local browser
  6481. ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
  6482. {
  6483. TerminateApplication();
  6484. }
  6485. }
  6486. }
  6487. catch (EAbort &)
  6488. {
  6489. // swallow
  6490. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect.
  6491. // Also when called from TWinControl.UpdateShowing => CMShowingChanged, the showing is aborted on exception
  6492. }
  6493. }
  6494. //---------------------------------------------------------------------------
  6495. void __fastcall TCustomScpExplorerForm::SessionListChanged(bool ForceTruncationUpdate)
  6496. {
  6497. TTerminalManager * Manager = TTerminalManager::Instance();
  6498. DebugAssert(!Manager->Updating);
  6499. TAutoFlag UpdatingSessionTabsFlag(FUpdatingSessionTabs);
  6500. int ActiveSessionIndex = Manager->ActiveSessionIndex;
  6501. Configuration->Usage->SetMax(L"MaxOpenedSessions", Manager->Count);
  6502. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  6503. try
  6504. {
  6505. int PrevTabsWidth = SessionsPageControl->TotalTabsWidth();
  6506. while (SessionsPageControl->PageCount > Manager->Count + 1)
  6507. {
  6508. delete SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6509. }
  6510. for (int Index = 0; Index <= Manager->Count; Index++)
  6511. {
  6512. TThemeTabSheet * TabSheet;
  6513. if (Index >= SessionsPageControl->PageCount)
  6514. {
  6515. TabSheet = new TThemeTabSheet(SessionsPageControl);
  6516. TabSheet->PageControl = SessionsPageControl;
  6517. }
  6518. else
  6519. {
  6520. TabSheet = SessionsPageControl->Pages[Index];
  6521. }
  6522. bool IsSessionTab = (Index < Manager->Count);
  6523. if (IsSessionTab)
  6524. {
  6525. TTerminal * Terminal = Manager->Sessions[Index];
  6526. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  6527. TabSheet->CaptionTruncation = tttEllipsis;
  6528. UpdateSessionTab(TabSheet);
  6529. }
  6530. else
  6531. {
  6532. TabSheet->Tag = 0; // not really needed
  6533. TabSheet->Shadowed = false;
  6534. TabSheet->Button = SupportsLocalBrowser() ? ttbDropDown : ttbNone;
  6535. TabSheet->CaptionTruncation = tttNoText;
  6536. // 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)
  6537. UpdateNewTabTab();
  6538. }
  6539. }
  6540. // Prevent flicker on the right side where scrolling buttons would be, unless really needed
  6541. if (ForceTruncationUpdate || (SessionsPageControl->TotalTabsWidth() != PrevTabsWidth))
  6542. {
  6543. SessionsPageControl->UpdateTabsCaptionTruncation();
  6544. }
  6545. }
  6546. __finally
  6547. {
  6548. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  6549. }
  6550. SessionsPageControl->ActivePageIndex = ActiveSessionIndex;
  6551. }
  6552. //---------------------------------------------------------------------------
  6553. UnicodeString TCustomScpExplorerForm::GetNewTabTabCaption()
  6554. {
  6555. return StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewTabAction->Caption));
  6556. }
  6557. //---------------------------------------------------------------------------
  6558. void __fastcall TCustomScpExplorerForm::UpdateNewTabTab()
  6559. {
  6560. TThemeTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  6561. UnicodeString TabCaption;
  6562. if (WinConfiguration->SelectiveToolbarText)
  6563. {
  6564. TabCaption = GetNewTabTabCaption();
  6565. }
  6566. TabSheet->BaseCaption = TabCaption;
  6567. TabSheet->ImageIndex = GetNewTabTabImageIndex(osCurrent);
  6568. }
  6569. //---------------------------------------------------------------------------
  6570. TManagedTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabSession(TTabSheet * TabSheet)
  6571. {
  6572. return reinterpret_cast<TManagedTerminal *>(TabSheet->Tag);
  6573. }
  6574. //---------------------------------------------------------------------------
  6575. UnicodeString TCustomScpExplorerForm::GetLocalBrowserSessionTitle(TManagedTerminal *)
  6576. {
  6577. DebugFail();
  6578. return UnicodeString();
  6579. }
  6580. //---------------------------------------------------------------------------
  6581. void TCustomScpExplorerForm::UpdateSessionTab(TThemeTabSheet * TabSheet)
  6582. {
  6583. if (DebugAlwaysTrue(TabSheet != NULL))
  6584. {
  6585. TManagedTerminal * ASession = GetSessionTabSession(TabSheet);
  6586. if (DebugAlwaysTrue(ASession != NULL))
  6587. {
  6588. TColor Color = (ASession == Terminal) ? FSessionColor : ASession->StateData->Color;
  6589. if (ASession->LocalBrowser)
  6590. {
  6591. TabSheet->ImageIndex = FLocalBrowserTabImageIndex;
  6592. }
  6593. else
  6594. {
  6595. TabSheet->ImageIndex = AddSessionColor(Color);
  6596. }
  6597. TTerminalManager * Manager = TTerminalManager::Instance();
  6598. TabSheet->Shadowed = !ASession->Active && !ASession->LocalBrowser;
  6599. TabSheet->Button = CanCloseSession(ASession) ? ttbClose : ttbNone;
  6600. TabSheet->BaseCaption = Manager->GetSessionTitle(ASession, true);
  6601. }
  6602. }
  6603. }
  6604. //---------------------------------------------------------------------------
  6605. bool TCustomScpExplorerForm::CanCloseSession(TManagedTerminal * Session)
  6606. {
  6607. return !Session->LocalBrowser || (TTerminalManager::Instance()->Count > 1);
  6608. }
  6609. //---------------------------------------------------------------------------
  6610. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  6611. {
  6612. DebugAssert(SessionsPageControl->ActivePage != NULL);
  6613. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->ActivePage);
  6614. bool Result = (Session != NULL);
  6615. if (Result)
  6616. {
  6617. TTerminalManager::Instance()->ActiveSession = Session;
  6618. }
  6619. else
  6620. {
  6621. try
  6622. {
  6623. NewTab();
  6624. }
  6625. __finally
  6626. {
  6627. SessionListChanged();
  6628. }
  6629. FSessionsPageControlNewTabTime = Now();
  6630. }
  6631. return Result;
  6632. }
  6633. //---------------------------------------------------------------------------
  6634. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  6635. {
  6636. SessionTabSwitched();
  6637. }
  6638. //---------------------------------------------------------------------------
  6639. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  6640. {
  6641. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  6642. DebugAssert(TransferList != NULL);
  6643. UnicodeString Name;
  6644. if (TransferList->ItemIndex <= 0)
  6645. {
  6646. Name = L"";
  6647. }
  6648. else
  6649. {
  6650. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  6651. }
  6652. if (FCopyParamAutoSelected.IsEmpty())
  6653. {
  6654. // if previous preset was not autoselected, make new preset the "default"
  6655. FCopyParamDefault = Name;
  6656. }
  6657. GUIConfiguration->CopyParamCurrent = Name;
  6658. }
  6659. //---------------------------------------------------------------------------
  6660. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  6661. {
  6662. // sanity check
  6663. bool ExistingPreset =
  6664. (FTransferListHoverIndex >= 0) &&
  6665. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  6666. DebugAssert(ExistingPreset);
  6667. if (ExistingPreset)
  6668. {
  6669. HDC DC = GetDC(0);
  6670. TCanvas * Canvas = new TCanvas();
  6671. try
  6672. {
  6673. Canvas->Handle = DC;
  6674. Canvas->Font = GetToolbarFont(this);
  6675. UnicodeString Name;
  6676. if (FTransferListHoverIndex == 0)
  6677. {
  6678. Name = L"";
  6679. }
  6680. else
  6681. {
  6682. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  6683. }
  6684. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  6685. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  6686. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  6687. static_cast<TObject*>(GetComponent(fcTransferList)));
  6688. UnicodeString InfoStr =
  6689. GUIConfiguration->CopyParamPreset[Name].
  6690. GetInfoStr(L"; ",
  6691. FLAGMASK(HasActiveTerminal(), Terminal->UsableCopyParamAttrs(0).General));
  6692. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  6693. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  6694. {
  6695. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  6696. {
  6697. InfoStr.SetLength(InfoStr.Length() - 1);
  6698. }
  6699. InfoStr += Ellipsis;
  6700. }
  6701. // UpdateCaption does not cause invalidation of whole submenu, while
  6702. // setting Caption property does.
  6703. // also it probably does not resize the label, even if necessary
  6704. // (we do not want that anyway)
  6705. TransferLabel->UpdateCaption(InfoStr);
  6706. }
  6707. __finally
  6708. {
  6709. Canvas->Handle = NULL;
  6710. ReleaseDC(0, DC);
  6711. delete Canvas;
  6712. }
  6713. }
  6714. }
  6715. //---------------------------------------------------------------------------
  6716. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  6717. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  6718. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  6719. {
  6720. if (FTransferListHoverIndex != AHoverIndex)
  6721. {
  6722. FTransferListHoverIndex = AHoverIndex;
  6723. UpdateTransferLabel();
  6724. }
  6725. }
  6726. //---------------------------------------------------------------------------
  6727. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  6728. {
  6729. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  6730. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  6731. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  6732. {
  6733. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  6734. {
  6735. if (!NonVisualDataModule->Busy)
  6736. {
  6737. OpenDirectory(GetSide(osCurrent));
  6738. }
  6739. Message.Result = 1;
  6740. }
  6741. else
  6742. {
  6743. TForm::Dispatch(&Message);
  6744. }
  6745. }
  6746. else
  6747. {
  6748. TForm::Dispatch(&Message);
  6749. }
  6750. }
  6751. //---------------------------------------------------------------------------
  6752. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  6753. {
  6754. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  6755. if ((FIgnoreNextDialogChar != 0) &&
  6756. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  6757. {
  6758. Message.Result = 1;
  6759. }
  6760. else
  6761. {
  6762. TForm::Dispatch(&Message);
  6763. }
  6764. FIgnoreNextDialogChar = 0;
  6765. }
  6766. //---------------------------------------------------------------------------
  6767. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  6768. {
  6769. // The four low-order bits are used internally by Windows
  6770. unsigned int Cmd = (Message.WParam & 0xFFF0);
  6771. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  6772. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  6773. // 61730 - restore thru double click - undocumented
  6774. // 61490 - maximize thru double click - undocumented
  6775. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  6776. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  6777. {
  6778. SysResizing(Cmd);
  6779. }
  6780. TForm::Dispatch(&Message);
  6781. }
  6782. //---------------------------------------------------------------------------
  6783. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  6784. {
  6785. // We were actually never able to make ENDSESSION_CRITICAL happen.
  6786. // Also there no point returning TRUE as we are not able to
  6787. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  6788. // Hence the process termination might be safer :)
  6789. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  6790. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  6791. {
  6792. Message.Result = FALSE;
  6793. }
  6794. else
  6795. {
  6796. Message.Result = TRUE;
  6797. }
  6798. // Do not call default handling as that triggers OnCloseQuery,
  6799. // where our implementation will popup confirmation dialogs, what we do not want,
  6800. // as per Vista guidelines:
  6801. // https://docs.microsoft.com/en-us/windows/win32/shutdown/shutting-down
  6802. }
  6803. //---------------------------------------------------------------------------
  6804. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  6805. {
  6806. if (Message.EndSession && IsApplicationMinimized())
  6807. {
  6808. // WORKAROUND
  6809. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  6810. // when it receives WM_ENDSESSION,
  6811. // but that sometimes (particularly when application is minimized) cause crashes.
  6812. // Crash popups message that blocks log off.
  6813. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  6814. // so we call ExitProcess() immediately, not even trying to cleanup.
  6815. // It still causes beep, so there's likely some popup, but it does not block
  6816. // log off.
  6817. ExitProcess(0);
  6818. }
  6819. TForm::Dispatch(&Message);
  6820. }
  6821. #ifdef _DEBUG
  6822. //---------------------------------------------------------------------------
  6823. void __fastcall TCustomScpExplorerForm::WMWindowPosChanged(TWMWindowPosMsg & Message)
  6824. {
  6825. TForm::Dispatch(&Message);
  6826. }
  6827. #endif
  6828. //---------------------------------------------------------------------------
  6829. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  6830. {
  6831. }
  6832. //---------------------------------------------------------------------------
  6833. void __fastcall TCustomScpExplorerForm::DoShow()
  6834. {
  6835. // Called from TCustomScpExplorerForm::CMShowingChanged
  6836. // only now are the controls resized finally, so the size constraints
  6837. // will not conflict with possibly very small window size
  6838. RestoreFormParams();
  6839. // This indicates that the form was rescaled after parameters were loaded and
  6840. // as most probably the parameters were actually saved with the current form scaling
  6841. // (windows was the last time likely closed on the same monitor, where it is starting now),
  6842. // rescaling happened twice already. Reload the parameters, as now they likely won't need any scaling
  6843. // and no rounding problems will occur.
  6844. // See also RestoreForm.
  6845. // (we should be safe to call RestoreParams unconditionally)
  6846. if (PixelsPerInch != Screen->PixelsPerInch)
  6847. {
  6848. RestoreParams();
  6849. }
  6850. FixControlsPlacement();
  6851. if (Position == poDefaultPosOnly)
  6852. {
  6853. CutFormToDesktop(this);
  6854. }
  6855. TForm::DoShow();
  6856. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  6857. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  6858. // This was previously in NeedSession, where other related code is.
  6859. // But that is called from CMShowingChanged, when the window is already visible and the local-local window state
  6860. // unpleasantly shows briefly.
  6861. if ((ManagedSession == NULL) &&
  6862. !WinConfiguration->ShowLoginWhenNoSession &&
  6863. WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
  6864. // This detects if workspace was saved the last time the main widow was closed
  6865. SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
  6866. {
  6867. DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false, true);
  6868. Configuration->Usage->Inc(L"OpenedWorkspacesAuto");
  6869. }
  6870. // Before main window displays
  6871. if (ManagedSession == NULL)
  6872. {
  6873. StartingWithoutSession();
  6874. }
  6875. UpdatePixelsPerInchMainWindowCounter();
  6876. FShowing = true;
  6877. }
  6878. //---------------------------------------------------------------------------
  6879. void __fastcall TCustomScpExplorerForm::UpdatePixelsPerInchMainWindowCounter()
  6880. {
  6881. Configuration->Usage->Set(L"PixelsPerInchMainWindow", PixelsPerInch);
  6882. }
  6883. //---------------------------------------------------------------------------
  6884. void __fastcall TCustomScpExplorerForm::StartingWithoutSession()
  6885. {
  6886. SessionListChanged();
  6887. InitStatusBar();
  6888. UpdateControls();
  6889. }
  6890. //---------------------------------------------------------------------------
  6891. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  6892. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  6893. TNotifyEvent OnBalloonClick, TObject * UserData)
  6894. {
  6895. bool Do;
  6896. UnicodeString Message;
  6897. if (E == NULL)
  6898. {
  6899. Message = Str;
  6900. Do = true;
  6901. }
  6902. else
  6903. {
  6904. Do = ExceptionMessage(E, Message);
  6905. }
  6906. if (Do && WinConfiguration->BalloonNotifications)
  6907. {
  6908. UnicodeString Title;
  6909. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  6910. {
  6911. Message = TrimLeft(Message);
  6912. }
  6913. else
  6914. {
  6915. Message = UnformatMessage(Message);
  6916. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  6917. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  6918. Title = LoadResourceString(Captions[Type]);
  6919. if (Terminal != NULL)
  6920. {
  6921. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  6922. Title = TTerminalManager::Instance()->GetSessionTitle(Session, true) + TitleSeparator + Title;
  6923. }
  6924. }
  6925. if (Seconds == 0)
  6926. {
  6927. Seconds = WinConfiguration->NotificationsTimeout;
  6928. }
  6929. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  6930. }
  6931. }
  6932. //---------------------------------------------------------------------------
  6933. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  6934. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  6935. UnicodeString HelpKeyword, const TMessageParams * Params,
  6936. TTerminal * Terminal)
  6937. {
  6938. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  6939. (FOnFeedSynchronizeError != NULL)) &&
  6940. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  6941. {
  6942. if (FOnFeedSynchronizeError != NULL)
  6943. {
  6944. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  6945. }
  6946. else
  6947. {
  6948. DebugAssert(FErrorList != NULL);
  6949. TStringList * MoreMessagesCopy = NULL;
  6950. if (MoreMessages)
  6951. {
  6952. MoreMessagesCopy = new TStringList();
  6953. MoreMessagesCopy->Assign(MoreMessages);
  6954. }
  6955. FErrorList->AddObject(Message, MoreMessagesCopy);
  6956. }
  6957. PopupTrayBalloon(Terminal, Message, Type);
  6958. return ContinueAnswer(Answers);
  6959. }
  6960. else
  6961. {
  6962. bool UseBalloon = FTrayIcon->Visible;
  6963. if (UseBalloon)
  6964. {
  6965. PopupTrayBalloon(Terminal, Message, Type);
  6966. }
  6967. unsigned int Result;
  6968. try
  6969. {
  6970. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  6971. }
  6972. __finally
  6973. {
  6974. // cancel only balloon we popped up, otherwise we may cancel notification
  6975. // balloon that was there before the message dialog
  6976. // (such as "dd confirmation opt in balloon)
  6977. if (UseBalloon)
  6978. {
  6979. FTrayIcon->CancelBalloon();
  6980. }
  6981. }
  6982. return Result;
  6983. }
  6984. }
  6985. //---------------------------------------------------------------------------
  6986. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  6987. TTerminal * Terminal, Exception * E)
  6988. {
  6989. if (FTrayIcon->Visible)
  6990. {
  6991. PopupTrayBalloon(Terminal, L"", qtError, E);
  6992. }
  6993. // particularly prevent opening new session from jump list,
  6994. // while exception is shown
  6995. NonVisualDataModule->StartBusy();
  6996. try
  6997. {
  6998. ShowExtendedExceptionEx(Terminal, E);
  6999. }
  7000. __finally
  7001. {
  7002. NonVisualDataModule->EndBusy();
  7003. FTrayIcon->CancelBalloon();
  7004. }
  7005. }
  7006. //---------------------------------------------------------------------------
  7007. void __fastcall TCustomScpExplorerForm::SessionReady()
  7008. {
  7009. InitStatusBar();
  7010. // cannot rely on active page being page for active terminal,
  7011. // as it can happen that active page is the "new session" page
  7012. // (e.g. when reconnecting active terminal, while login dialog
  7013. // invoked from "new session" page is modal)
  7014. int ActiveSessionIndex = TTerminalManager::Instance()->ActiveSessionIndex;
  7015. UpdateSessionTab(SessionsPageControl->Pages[ActiveSessionIndex]);
  7016. }
  7017. //---------------------------------------------------------------------------
  7018. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  7019. TTerminal * Terminal, Exception * E)
  7020. {
  7021. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  7022. if (!Terminal->Active)
  7023. {
  7024. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  7025. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  7026. {
  7027. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  7028. }
  7029. }
  7030. }
  7031. //---------------------------------------------------------------------------
  7032. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  7033. UnicodeString Message, TQueryType Type,
  7034. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  7035. {
  7036. if ((E == NULL) ||
  7037. ExceptionMessage(E, Message))
  7038. {
  7039. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  7040. if (Important)
  7041. {
  7042. Seconds *= 5;
  7043. }
  7044. UnicodeString NoteMessage(UnformatMessage(Message));
  7045. if (Terminal != NULL)
  7046. {
  7047. TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  7048. NoteMessage = FORMAT(L"%s: %s",
  7049. (TTerminalManager::Instance()->GetSessionTitle(Session, true), NoteMessage));
  7050. }
  7051. if (WinConfiguration->BalloonNotifications)
  7052. {
  7053. AddNote(NoteMessage);
  7054. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  7055. }
  7056. else
  7057. {
  7058. FlashOnBackground();
  7059. PostNote(NoteMessage, Seconds, OnClick, UserData);
  7060. }
  7061. }
  7062. }
  7063. //---------------------------------------------------------------------------
  7064. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  7065. {
  7066. RestoreApp();
  7067. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  7068. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  7069. !NonVisualDataModule->Busy)
  7070. {
  7071. TManagedTerminal * Terminal = TerminalNoteData->Terminal;
  7072. TTerminalManager::Instance()->ActiveSession = Terminal;
  7073. if (!ComponentVisible[fcQueueView])
  7074. {
  7075. ToggleQueueVisibility();
  7076. GoToQueue();
  7077. }
  7078. }
  7079. }
  7080. //---------------------------------------------------------------------------
  7081. void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal,
  7082. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  7083. {
  7084. UnicodeString Message;
  7085. TNotifyEvent OnClick = NULL;
  7086. TObject * UserData = NULL;
  7087. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  7088. switch (Event)
  7089. {
  7090. case qeEmptyButMonitored:
  7091. if ((ATerminal != Terminal) || QueueInvisible)
  7092. {
  7093. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  7094. OnClick = QueueEmptyNoteClicked;
  7095. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  7096. TerminalNoteData->Terminal = ATerminal;
  7097. UserData = TerminalNoteData;
  7098. }
  7099. break;
  7100. case qeEmpty:
  7101. OperationComplete(ATerminal->QueueOperationStart);
  7102. break;
  7103. case qePendingUserAction:
  7104. if ((ATerminal != Terminal) ||
  7105. (QueueInvisible && !IsQueueAutoPopup()))
  7106. {
  7107. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  7108. }
  7109. break;
  7110. default:
  7111. DebugFail();
  7112. }
  7113. if (!Message.IsEmpty())
  7114. {
  7115. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  7116. }
  7117. }
  7118. //---------------------------------------------------------------------------
  7119. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  7120. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  7121. {
  7122. if (FDDExtMapFile != NULL)
  7123. {
  7124. CloseHandle(FDDExtMapFile);
  7125. FDDExtMapFile = NULL;
  7126. }
  7127. if (WinConfiguration->DDFakeFile)
  7128. {
  7129. DDFakeFileInitDrag(FileList, Created);
  7130. }
  7131. }
  7132. //---------------------------------------------------------------------------
  7133. void __fastcall TCustomScpExplorerForm::DDFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  7134. {
  7135. if (DebugAlwaysTrue(!FDragFakeDirectory.IsEmpty()) &&
  7136. SameText(ExtractFileName(FileName), ExtractFileName(FDragFakeDirectory)))
  7137. {
  7138. FFakeFileDropTarget = FileName;
  7139. }
  7140. }
  7141. //---------------------------------------------------------------------------
  7142. UnicodeString __fastcall TCustomScpExplorerForm::CreateFakeTransferDirectory()
  7143. {
  7144. UnicodeString Result = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  7145. if (!ForceDirectories(ApiPath(Result)))
  7146. {
  7147. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  7148. }
  7149. FileSetAttr(ApiPath(Result), faHidden);
  7150. return Result;
  7151. }
  7152. //---------------------------------------------------------------------------
  7153. void __fastcall TCustomScpExplorerForm::DDFakeFileInitDrag(TFileList * FileList,
  7154. bool & Created)
  7155. {
  7156. FFakeFileDropTarget = UnicodeString();
  7157. FDragFakeDirectory = CreateFakeTransferDirectory();
  7158. FileList->AddItem(NULL, FDragFakeDirectory);
  7159. Created = true;
  7160. if (!WinConfiguration->IsDDExtRunning() || WinConfiguration->IsDDExtBroken())
  7161. {
  7162. FDragFakeMonitors = StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, DDFakeCreated);
  7163. }
  7164. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  7165. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  7166. {
  7167. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7168. TDragExtCommStruct* CommStruct;
  7169. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7170. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7171. DebugAssert(CommStruct != NULL);
  7172. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  7173. CommStruct->Dragging = true;
  7174. wcsncpy(CommStruct->DropDest, FDragFakeDirectory.c_str(),
  7175. LENOF(CommStruct->DropDest));
  7176. NULL_TERMINATE(CommStruct->DropDest);
  7177. UnmapViewOfFile(CommStruct);
  7178. }
  7179. }
  7180. //---------------------------------------------------------------------------
  7181. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  7182. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  7183. {
  7184. bool Result;
  7185. DebugAssert(!IsLocalBrowserMode());
  7186. if (Sender == RemoteDirView)
  7187. {
  7188. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  7189. }
  7190. else
  7191. {
  7192. DebugAssert(Sender == RemoteDriveView);
  7193. TStrings * FileList = RemoteDriveView->DragFileList();
  7194. try
  7195. {
  7196. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  7197. }
  7198. __finally
  7199. {
  7200. delete FileList;
  7201. }
  7202. }
  7203. if (FDDTargetControl == RemoteDriveView)
  7204. {
  7205. RemoteDriveView->UpdateDropTarget();
  7206. }
  7207. // foRemoteMove happens when file/dir is dragged within the remote tree view
  7208. // or from tree view to dir view.
  7209. // foMove happens when file/dir is dragged from remote tree view outside of
  7210. // application via dragex
  7211. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  7212. (DropSourceControl == RemoteDriveView))
  7213. {
  7214. RemoteDriveView->UpdateDropSource();
  7215. }
  7216. return Result;
  7217. }
  7218. //---------------------------------------------------------------------------
  7219. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  7220. {
  7221. DebugAssert(!IsLocalBrowserMode());
  7222. // This also handles drops of remote files to queue.
  7223. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  7224. SAFE_DESTROY(FDDFileList);
  7225. if (!FFakeFileDropTarget.IsEmpty())
  7226. {
  7227. RemoveDir(ApiPath(FFakeFileDropTarget));
  7228. }
  7229. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  7230. {
  7231. try
  7232. {
  7233. TDragResult DDResult = (Sender == RemoteDirView) ?
  7234. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  7235. // Focus is moved to the target application,
  7236. // but as we are going to present the UI, we need to steal the focus back.
  7237. // This most likely won't work though (windows does not allow application
  7238. // to steal focus most of the time)
  7239. Application->BringToFront();
  7240. // On older version of Windows we never got drMove here, see also comment below.
  7241. // On Windows 10, we get the "move".
  7242. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  7243. {
  7244. UnicodeString TargetDirectory;
  7245. TFileOperation Operation;
  7246. // drInvalid may mean drMove, see comment below
  7247. switch (DDResult)
  7248. {
  7249. case drCopy:
  7250. Operation = foCopy;
  7251. break;
  7252. case drMove:
  7253. Operation = foMove;
  7254. break;
  7255. default:
  7256. DebugFail();
  7257. case drInvalid:
  7258. // prefer "copy" for safety
  7259. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  7260. break;
  7261. }
  7262. TTransferOperationParam Param;
  7263. UnicodeString CounterName;
  7264. bool ForceQueue;
  7265. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, CounterName))
  7266. {
  7267. // we get drInvalid both if d&d was intercepted by ddext,
  7268. // and when users drops on no-drop location.
  7269. // we tell the difference by existence of response from ddext,
  7270. // so we ignore absence of response in this case
  7271. if (DDResult != drInvalid)
  7272. {
  7273. // here we know that the extension is installed,
  7274. // as it is checked as soon as drag&drop starts from
  7275. // RemoteFileControlDDCreateDragFileList
  7276. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  7277. if (!WinConfiguration->DDExtInstalled || WinConfiguration->IsDDExtBroken())
  7278. {
  7279. throw ExtException(NULL, LoadStr(DD_TARGET_UNKNOWN), HELP_DD_TARGET_UNKNOWN);
  7280. }
  7281. else
  7282. {
  7283. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  7284. }
  7285. }
  7286. }
  7287. else
  7288. {
  7289. // download using fake file
  7290. Param.Temp = false;
  7291. Param.DragDrop = true;
  7292. if (ForceQueue)
  7293. {
  7294. Param.Queue = asOn;
  7295. }
  7296. if (Sender == RemoteDirView)
  7297. {
  7298. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  7299. }
  7300. if (RemoteFileControlFileOperation(Sender, Operation,
  7301. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  7302. {
  7303. Configuration->Usage->Inc(CounterName);
  7304. }
  7305. }
  7306. }
  7307. }
  7308. __finally
  7309. {
  7310. CloseHandle(FDDExtMapFile);
  7311. FDDExtMapFile = NULL;
  7312. delete FDragFakeMonitors;
  7313. FDragFakeMonitors = NULL;
  7314. RemoveDir(ApiPath(FDragFakeDirectory));
  7315. FDragFakeDirectory = L"";
  7316. FFakeFileDropTarget = UnicodeString();
  7317. }
  7318. }
  7319. if (FDragDropSshTerminate.get() != NULL)
  7320. {
  7321. FDragDropSshTerminate->Rethrow();
  7322. }
  7323. }
  7324. //---------------------------------------------------------------------------
  7325. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  7326. TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
  7327. {
  7328. // Remember drop effect so we know (when user drops files), if we copy or move
  7329. FLastDropEffect = dwEffect;
  7330. }
  7331. //---------------------------------------------------------------------------
  7332. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  7333. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  7334. {
  7335. bool Result;
  7336. if (FDDTargetControl == QueueView3)
  7337. {
  7338. Directory = DefaultDownloadTargetDirectory();
  7339. Result = true;
  7340. CounterName = L"DownloadsDragDropQueue";
  7341. ForceQueue = true;
  7342. }
  7343. else if (!FFakeFileDropTarget.IsEmpty())
  7344. {
  7345. Directory = ExcludeTrailingBackslash(ExtractFilePath(FFakeFileDropTarget));
  7346. Result = true;
  7347. ForceQueue = false;
  7348. CounterName = L"DownloadsDragDropFakeFile";
  7349. }
  7350. else
  7351. {
  7352. ForceQueue = false;
  7353. Enabled = false;
  7354. try
  7355. {
  7356. int Timer = 0;
  7357. Result = false;
  7358. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  7359. {
  7360. {
  7361. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  7362. TDragExtCommStruct* CommStruct;
  7363. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  7364. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  7365. DebugAssert(CommStruct != NULL);
  7366. Result = !CommStruct->Dragging;
  7367. if (Result)
  7368. {
  7369. Directory = ExtractFilePath(CommStruct->DropDest);
  7370. CounterName = L"DownloadsDragDropExternalExt";
  7371. }
  7372. UnmapViewOfFile(CommStruct);
  7373. }
  7374. if (!Result)
  7375. {
  7376. Sleep(50);
  7377. Timer += 50;
  7378. Application->ProcessMessages();
  7379. }
  7380. }
  7381. }
  7382. __finally
  7383. {
  7384. Enabled = true;
  7385. }
  7386. }
  7387. return Result;
  7388. }
  7389. //---------------------------------------------------------------------------
  7390. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  7391. const UnicodeString TempDir, int SecDelay)
  7392. {
  7393. TDateTime Alarm = IncSecond(Now(), SecDelay);
  7394. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  7395. if (FDelayedDeletionTimer == NULL)
  7396. {
  7397. DebugAssert(HandleAllocated());
  7398. FDelayedDeletionTimer = new TTimer(this);
  7399. FDelayedDeletionTimer->Interval = 10000;
  7400. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  7401. }
  7402. else
  7403. {
  7404. FDelayedDeletionTimer->Enabled = true;
  7405. }
  7406. }
  7407. //---------------------------------------------------------------------------
  7408. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  7409. {
  7410. DebugAssert(FDelayedDeletionList != NULL);
  7411. TDateTime N = Now();
  7412. TDateTime Alert;
  7413. UnicodeString Directory;
  7414. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  7415. {
  7416. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  7417. if ((N >= Alert) || (Sender == NULL))
  7418. {
  7419. Directory = FDelayedDeletionList->Strings[Index];
  7420. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  7421. {
  7422. FDelayedDeletionList->Delete(Index);
  7423. }
  7424. }
  7425. }
  7426. if (FDelayedDeletionList->Count == 0)
  7427. {
  7428. FDelayedDeletionTimer->Enabled = false;
  7429. }
  7430. }
  7431. //---------------------------------------------------------------------------
  7432. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  7433. {
  7434. DebugAssert(!IsLocalBrowserMode());
  7435. if (IsFileControl(FDDTargetControl, osRemote) ||
  7436. (FDDTargetControl == SessionsPageControl))
  7437. {
  7438. TManagedTerminal * TargetTerminal = NULL;
  7439. TFileOperation Operation = foNone;
  7440. if (FDDTargetControl == SessionsPageControl)
  7441. {
  7442. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  7443. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  7444. // do not allow dropping on local-local, disconnected and the "+" tab (see also SessionsDDProcessDropped)
  7445. TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  7446. if (IsActiveTerminal(TargetTerminal) && DebugAlwaysTrue(!TargetTerminal->LocalBrowser))
  7447. {
  7448. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  7449. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  7450. {
  7451. Operation = foRemoteMove;
  7452. }
  7453. else
  7454. {
  7455. Operation = foRemoteCopy;
  7456. }
  7457. }
  7458. }
  7459. else
  7460. {
  7461. if (FLastDropEffect == DROPEFFECT_MOVE)
  7462. {
  7463. Operation = foRemoteMove;
  7464. }
  7465. else if (FLastDropEffect == DROPEFFECT_COPY)
  7466. {
  7467. Operation = foRemoteCopy;
  7468. }
  7469. }
  7470. if (Operation != foNone)
  7471. {
  7472. RemoteFileControlFileOperation(DropSourceControl,
  7473. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  7474. }
  7475. // abort drag&drop
  7476. Abort();
  7477. }
  7478. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  7479. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  7480. (FDDTargetControl != QueueView3))
  7481. {
  7482. DebugAssert(!FDragTempDir.IsEmpty());
  7483. TTransferType Type;
  7484. UnicodeString TempDir = FDragTempDir;
  7485. // We clear FDragTempDir before calling
  7486. // just in case it fail (raises exception)
  7487. FDragTempDir = L"";
  7488. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  7489. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  7490. // empty directory parameter means temp directory -> don't display it!
  7491. UnicodeString TargetDir = L"";
  7492. int Options = 0;
  7493. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  7494. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  7495. {
  7496. Abort();
  7497. }
  7498. // TargetDir is set when dropped on local file control
  7499. // (this was workaround for legacy dirview event handling, now it should be
  7500. // made prettier)
  7501. if (TargetDir.IsEmpty())
  7502. {
  7503. TargetDir = TempDir;
  7504. if (ForceDirectories(ApiPath(TargetDir)))
  7505. {
  7506. DebugAssert(Terminal && !TargetDir.IsEmpty());
  7507. FPendingTempSpaceWarn = true;
  7508. try
  7509. {
  7510. FDragDropOperation = true;
  7511. int Params = cpTemporary |
  7512. (Type == ttMove ? cpDelete : 0);
  7513. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  7514. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  7515. }
  7516. __finally
  7517. {
  7518. FDragDropOperation = false;
  7519. FPendingTempSpaceWarn = false;
  7520. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  7521. }
  7522. }
  7523. else
  7524. {
  7525. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  7526. }
  7527. }
  7528. }
  7529. }
  7530. //---------------------------------------------------------------------------
  7531. void __fastcall TCustomScpExplorerForm::DDDownload(
  7532. TStrings * FilesToCopy, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params)
  7533. {
  7534. DebugAssert(!IsLocalBrowserMode());
  7535. TAutoBatch AutoBatch(this);
  7536. UpdateCopyParamCounters(*CopyParam);
  7537. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params, NULL);
  7538. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  7539. {
  7540. RemoteDriveView->UpdateDropSource();
  7541. }
  7542. }
  7543. //---------------------------------------------------------------------------
  7544. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  7545. {
  7546. public:
  7547. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  7548. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename, true)
  7549. {
  7550. }
  7551. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  7552. {
  7553. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  7554. TDataObjectFilesEx::AllowData(FormatEtc);
  7555. }
  7556. };
  7557. //---------------------------------------------------------------------------
  7558. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  7559. TObject * Sender, TDataObject *& DataObject)
  7560. {
  7561. if (FDDExtMapFile != NULL)
  7562. {
  7563. TFileList * FileList = DragDropFiles(Sender)->FileList;
  7564. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  7565. {
  7566. Abort();
  7567. }
  7568. if (FileList->Count > 0)
  7569. {
  7570. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  7571. if (!FilesObject->IsValid(true, true))
  7572. {
  7573. FilesObject->_Release();
  7574. }
  7575. else
  7576. {
  7577. DataObject = FilesObject;
  7578. }
  7579. }
  7580. }
  7581. }
  7582. //---------------------------------------------------------------------------
  7583. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  7584. {
  7585. DebugFail();
  7586. }
  7587. //---------------------------------------------------------------------------
  7588. void __fastcall TCustomScpExplorerForm::GoToTree()
  7589. {
  7590. ComponentVisible[fcRemoteTree] = true;
  7591. DriveView(osRemote)->SetFocus();
  7592. }
  7593. //---------------------------------------------------------------------------
  7594. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7595. TPanelExport Export)
  7596. {
  7597. TCustomDirView * DirView = this->DirView(Side);
  7598. std::unique_ptr<TStrings> ExportData(new TStringList());
  7599. switch (Export)
  7600. {
  7601. case pePath:
  7602. ExportData->Add(DirView->PathName);
  7603. break;
  7604. case peFileList:
  7605. case peFullFileList:
  7606. {
  7607. bool FullPath = (Export == peFullFileList);
  7608. DirView->CreateFileList(false, FullPath, ExportData.get());
  7609. for (int Index = 0; Index < ExportData->Count; Index++)
  7610. {
  7611. if (ExportData->Strings[Index].Pos(L" ") > 0)
  7612. {
  7613. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  7614. }
  7615. }
  7616. }
  7617. break;
  7618. default:
  7619. DebugFail();
  7620. }
  7621. return ExportData.release();
  7622. }
  7623. //---------------------------------------------------------------------------
  7624. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  7625. TPanelExport Export, TPanelExportDestination Destination)
  7626. {
  7627. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  7628. PanelExportStore(Side, Export, Destination, ExportData.get());
  7629. }
  7630. //---------------------------------------------------------------------------
  7631. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  7632. TPanelExport /*Export*/, TPanelExportDestination Destination,
  7633. TStrings * ExportData)
  7634. {
  7635. if (Destination == pedClipboard)
  7636. {
  7637. TInstantOperationVisualizer Visualizer;
  7638. CopyToClipboard(ExportData);
  7639. }
  7640. else
  7641. {
  7642. DebugFail();
  7643. }
  7644. }
  7645. //---------------------------------------------------------------------------
  7646. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  7647. {
  7648. TCustomDirView * DirView = this->DirView(Side);
  7649. UnicodeString Mask = DirView->Mask;
  7650. if (DoFilterMaskDialog(DirView, Mask))
  7651. {
  7652. DirView->Mask = TFileMasks::NormalizeMask(Mask);
  7653. Configuration->Usage->Inc(L"Filters");
  7654. }
  7655. }
  7656. //---------------------------------------------------------------------------
  7657. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  7658. {
  7659. return FQueueController->DefaultOperation();
  7660. }
  7661. //---------------------------------------------------------------------------
  7662. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  7663. TQueueOperation Operation, void ** Param)
  7664. {
  7665. switch (Operation)
  7666. {
  7667. case qoPreferences:
  7668. return true;
  7669. case qoGoTo:
  7670. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  7671. case qoOnceEmpty:
  7672. return IsAnythingQueued();
  7673. default:
  7674. return FQueueController->AllowOperation(Operation, Param);
  7675. }
  7676. }
  7677. //---------------------------------------------------------------------------
  7678. void __fastcall TCustomScpExplorerForm::GoToQueue()
  7679. {
  7680. if (DebugAlwaysTrue(QueueView3->Visible))
  7681. {
  7682. QueueView3->SetFocus();
  7683. }
  7684. }
  7685. //---------------------------------------------------------------------------
  7686. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  7687. TQueueOperation Operation, void * Param)
  7688. {
  7689. if (Operation == qoGoTo)
  7690. {
  7691. GoToQueue();
  7692. }
  7693. else if (Operation == qoPreferences)
  7694. {
  7695. PreferencesDialog(pmQueue);
  7696. }
  7697. else
  7698. {
  7699. FQueueController->ExecuteOperation(Operation, Param);
  7700. }
  7701. }
  7702. //---------------------------------------------------------------------------
  7703. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  7704. {
  7705. return (Queue != NULL) && Queue->Enabled;
  7706. }
  7707. //---------------------------------------------------------------------------
  7708. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  7709. {
  7710. DebugAssert(Queue != NULL);
  7711. if (Queue != NULL)
  7712. {
  7713. Queue->Enabled = !Queue->Enabled;
  7714. }
  7715. }
  7716. //---------------------------------------------------------------------------
  7717. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  7718. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  7719. {
  7720. FQueueActedItem = QueueView3->ItemFocused;
  7721. }
  7722. //---------------------------------------------------------------------------
  7723. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  7724. {
  7725. return TopDock->Height + QueueSplitter->Height;
  7726. }
  7727. //---------------------------------------------------------------------------
  7728. int __fastcall TCustomScpExplorerForm::GetStaticQueuePanelComponentsHeight()
  7729. {
  7730. return
  7731. (QueueFileListSplitter->Visible ? QueueFileListSplitter->Height : 0) +
  7732. (QueueDock->Visible ? QueueDock->Height : 0) +
  7733. (QueueLabel->Visible ? QueueLabel->Height : 0);
  7734. }
  7735. //---------------------------------------------------------------------------
  7736. int __fastcall TCustomScpExplorerForm::GetMinQueueViewHeight()
  7737. {
  7738. return ScaleByTextHeight(this, 48);
  7739. }
  7740. //---------------------------------------------------------------------------
  7741. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  7742. TObject * /*Sender*/, int & NewSize, bool & Accept)
  7743. {
  7744. // when queue is hidden by double-clicking splitter, stray attempt to
  7745. // resize the panel with strange value arrives, make sure it is ignored
  7746. if (ComponentVisible[fcQueueView])
  7747. {
  7748. int MaxHeightLimit = ClientHeight - GetStaticComponentsHeight() - RemotePanel->Constraints->MinHeight;
  7749. if (NewSize > MaxHeightLimit)
  7750. {
  7751. NewSize = MaxHeightLimit;
  7752. }
  7753. int MinHeightLimit =
  7754. GetStaticQueuePanelComponentsHeight() +
  7755. (QueueFileList->Visible ? QueueFileList->Height : 0) +
  7756. GetMinQueueViewHeight();
  7757. if (NewSize < MinHeightLimit)
  7758. {
  7759. NewSize = MinHeightLimit;
  7760. }
  7761. }
  7762. else
  7763. {
  7764. Accept = false;
  7765. }
  7766. }
  7767. //---------------------------------------------------------------------------
  7768. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterCanResize(TObject *, int & NewSize, bool &)
  7769. {
  7770. int TotalHeight = GetStaticQueuePanelComponentsHeight() + NewSize;
  7771. int QueueViewHeight = QueuePanel->ClientHeight - TotalHeight;
  7772. if (QueueViewHeight < GetMinQueueViewHeight())
  7773. {
  7774. NewSize -= (GetMinQueueViewHeight() - QueueViewHeight);
  7775. }
  7776. }
  7777. //---------------------------------------------------------------------------
  7778. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  7779. TDragObject *& /*DragObject*/)
  7780. {
  7781. FQueueActedItem = QueueView3->ItemFocused;
  7782. }
  7783. //---------------------------------------------------------------------------
  7784. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  7785. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  7786. {
  7787. Accept = true;
  7788. if (Source == QueueView3)
  7789. {
  7790. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  7791. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  7792. if (Accept)
  7793. {
  7794. TQueueItemProxy * QueueItem;
  7795. TQueueItemProxy * DestQueueItem;
  7796. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7797. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  7798. Accept = (QueueItem != DestQueueItem) &&
  7799. (QueueItem->Status == TQueueItem::qsPending) &&
  7800. (DestQueueItem->Status == TQueueItem::qsPending);
  7801. }
  7802. }
  7803. }
  7804. //---------------------------------------------------------------------------
  7805. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  7806. TObject * /*Source*/, int /*X*/, int /*Y*/)
  7807. {
  7808. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  7809. {
  7810. TQueueItemProxy * QueueItem;
  7811. TQueueItemProxy * DestQueueItem;
  7812. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  7813. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  7814. QueueItem->Move(DestQueueItem);
  7815. }
  7816. }
  7817. //---------------------------------------------------------------------------
  7818. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  7819. {
  7820. if ((QueueView3->ItemFocused == NULL) &&
  7821. (QueueView3->Items->Count > 0))
  7822. {
  7823. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  7824. }
  7825. QueueLabelUpdateStatus();
  7826. }
  7827. //---------------------------------------------------------------------------
  7828. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  7829. {
  7830. QueueLabelUpdateStatus();
  7831. }
  7832. //---------------------------------------------------------------------------
  7833. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  7834. {
  7835. QueueLabel->UpdateStatus();
  7836. }
  7837. //---------------------------------------------------------------------------
  7838. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  7839. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  7840. {
  7841. if (Selected)
  7842. {
  7843. NonVisualDataModule->UpdateNonVisibleActions();
  7844. }
  7845. }
  7846. //---------------------------------------------------------------------------
  7847. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  7848. {
  7849. TDragDropFilesEx * Result = NULL;
  7850. if (Sender == SessionsPageControl)
  7851. {
  7852. Result = FSessionsDragDropFilesEx;
  7853. }
  7854. else if (Sender == QueueView3)
  7855. {
  7856. Result = FQueueDragDropFilesEx;
  7857. }
  7858. else
  7859. {
  7860. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7861. if (DirView != NULL)
  7862. {
  7863. Result = DirView->DragDropFilesEx;
  7864. }
  7865. else
  7866. {
  7867. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  7868. if (DriveView != NULL)
  7869. {
  7870. Result = DriveView->DragDropFilesEx;
  7871. }
  7872. }
  7873. }
  7874. DebugAssert(Result != NULL);
  7875. return Result;
  7876. }
  7877. //---------------------------------------------------------------------------
  7878. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  7879. {
  7880. return (DView->SelCount == DView->FilesCount);
  7881. }
  7882. //---------------------------------------------------------------------------
  7883. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  7884. {
  7885. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  7886. }
  7887. //---------------------------------------------------------------------------
  7888. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  7889. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue, bool DragDrop)
  7890. {
  7891. DebugAssert(!IsLocalBrowserMode());
  7892. TFileOperation Operation;
  7893. switch (Effect)
  7894. {
  7895. case DROPEFFECT_MOVE:
  7896. Operation = foMove;
  7897. break;
  7898. case DROPEFFECT_COPY:
  7899. // occures on WinXP (reported by user)
  7900. default:
  7901. Operation = foCopy;
  7902. break;
  7903. };
  7904. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  7905. // see a comment in TUnixDirView::PerformItemDragDropOperation
  7906. if (DragDropFilesEx->FileList->Count > 0)
  7907. {
  7908. TStrings * FileList = new TStringList();
  7909. try
  7910. {
  7911. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  7912. {
  7913. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  7914. }
  7915. FDragDropOperation = true;
  7916. TTransferOperationParam Param;
  7917. Param.TargetDirectory = TargetPath;
  7918. // upload, no temp dirs
  7919. Param.Temp = false;
  7920. Param.DragDrop = DragDrop;
  7921. Param.Options =
  7922. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  7923. if (ForceQueue)
  7924. {
  7925. Param.Queue = asOn;
  7926. }
  7927. bool NoConfirmation = DragDrop ? (WinConfiguration->DDTransferConfirmation == asOff) : false;
  7928. if (ExecuteFileOperation(Operation, osLocal, FileList, NoConfirmation, &Param))
  7929. {
  7930. if (IsFileControl(DropSourceControl, osLocal))
  7931. {
  7932. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  7933. }
  7934. else
  7935. {
  7936. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  7937. }
  7938. }
  7939. }
  7940. __finally
  7941. {
  7942. FDragDropOperation = false;
  7943. delete FileList;
  7944. }
  7945. }
  7946. }
  7947. //---------------------------------------------------------------------------
  7948. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  7949. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  7950. UnicodeString TargetPath, bool Paste, bool & /*DoOperation*/)
  7951. {
  7952. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false, !Paste);
  7953. }
  7954. //---------------------------------------------------------------------------
  7955. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  7956. TObject * Sender, int grfKeyState, int & dwEffect)
  7957. {
  7958. DebugAssert(!IsLocalBrowserMode());
  7959. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  7960. if ((dwEffect != DROPEFFECT_NONE) &&
  7961. IsFileControl(DropSourceControl, osRemote))
  7962. {
  7963. // do not allow drop on remote panel (on free space, still allow drop on directories)
  7964. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  7965. (RemoteDirView->DropTarget == NULL))
  7966. {
  7967. dwEffect = DROPEFFECT_NONE;
  7968. }
  7969. else
  7970. {
  7971. if (dwEffect == DROPEFFECT_COPY)
  7972. {
  7973. bool MoveCapable = Terminal->IsCapable[fcRemoteMove];
  7974. // currently we support copying always (at least via temporary directory);
  7975. // remove associated checks once this all proves stable and working
  7976. bool CopyCapable = true;
  7977. // if we do not support neither of operations, there's no discussion
  7978. if (!MoveCapable && !CopyCapable)
  7979. {
  7980. dwEffect = DROPEFFECT_NONE;
  7981. }
  7982. else
  7983. {
  7984. // The default effect inside remote panel is move,
  7985. // unless we do not support it, but support copy
  7986. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  7987. {
  7988. dwEffect = MoveCapable ? DROPEFFECT_MOVE : DROPEFFECT_COPY;
  7989. }
  7990. else
  7991. {
  7992. // with ctrl-down, we want copy unless it is not supported
  7993. dwEffect = CopyCapable ? DROPEFFECT_COPY : DROPEFFECT_NONE;
  7994. }
  7995. }
  7996. }
  7997. }
  7998. }
  7999. }
  8000. //---------------------------------------------------------------------------
  8001. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  8002. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  8003. {
  8004. DebugAssert(!IsLocalBrowserMode());
  8005. if (FDDTotalSize >= 0)
  8006. {
  8007. if (File->IsDirectory)
  8008. {
  8009. FDDTotalSize = -1;
  8010. }
  8011. else
  8012. {
  8013. FDDTotalSize += File->Size;
  8014. }
  8015. }
  8016. DebugAssert(!FDragTempDir.IsEmpty());
  8017. // TODO: this is quite ineffective
  8018. // TODO: what if invalid character replacement is disabled?
  8019. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  8020. UnicodeString TransferFileName;
  8021. if (Sender == RemoteDriveView)
  8022. {
  8023. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  8024. }
  8025. else
  8026. {
  8027. TransferFileName = File->FileName;
  8028. }
  8029. FDDFileList->AddObject(TransferFileName, File);
  8030. }
  8031. //---------------------------------------------------------------------------
  8032. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  8033. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  8034. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  8035. {
  8036. // sometimes we do not get DDEnd so the list is not released
  8037. SAFE_DESTROY(FDDFileList);
  8038. FDDFileList = new TStringList();
  8039. FDragTempDir = WinConfiguration->TemporaryDir();
  8040. FDDTotalSize = 0;
  8041. FDragDropSshTerminate.reset(NULL);
  8042. }
  8043. //---------------------------------------------------------------------------
  8044. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  8045. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  8046. HRESULT & Result)
  8047. {
  8048. if (Result == DRAGDROP_S_DROP)
  8049. {
  8050. try
  8051. {
  8052. GlobalDragImageList->HideDragImage();
  8053. try
  8054. {
  8055. RemoteFileControlDDTargetDrop();
  8056. }
  8057. catch(ESshTerminate & E)
  8058. {
  8059. FDragDropSshTerminate.reset(E.Clone());
  8060. }
  8061. }
  8062. catch (Exception &E)
  8063. {
  8064. // If downloading fails we need to cancel drag&drop, otherwise
  8065. // Explorer shows error
  8066. // But by the way exception probably never reach this point as
  8067. // it's catched on way.
  8068. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  8069. Result = DRAGDROP_S_CANCEL;
  8070. ShowExtendedException(Terminal, &E);
  8071. }
  8072. }
  8073. }
  8074. //---------------------------------------------------------------------------
  8075. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  8076. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  8077. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  8078. {
  8079. TFileMasks::TParams MaskParams;
  8080. MaskParams.Size = Size;
  8081. MaskParams.Modification = Modification;
  8082. // this does not re-parse the mask if it is the same as the last time
  8083. FDirViewMatchMask = Masks;
  8084. bool ImplicitMatch;
  8085. Matches =
  8086. // RecurseInclude parameter has no effect as the Path is empty
  8087. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  8088. (AllowImplicitMatches || !ImplicitMatch);
  8089. }
  8090. //---------------------------------------------------------------------------
  8091. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  8092. TObject * Sender, TListItem * Item, WORD & Indexes)
  8093. {
  8094. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  8095. UnicodeString Ext;
  8096. if (dynamic_cast<TUnixDirView *>(DirView) != NULL)
  8097. {
  8098. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  8099. }
  8100. else
  8101. {
  8102. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  8103. }
  8104. if (SameText(Ext, Configuration->PartialExt))
  8105. {
  8106. Indexes |= oiPartial;
  8107. }
  8108. }
  8109. //---------------------------------------------------------------------------
  8110. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  8111. {
  8112. return
  8113. DirViewEnabled(osCurrent) &&
  8114. DirView(osCurrent)->CanPasteFromClipBoard();
  8115. }
  8116. //---------------------------------------------------------------------------
  8117. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  8118. {
  8119. bool Result = false;
  8120. if (CanPasteToDirViewFromClipBoard())
  8121. {
  8122. Result = true;
  8123. }
  8124. else
  8125. {
  8126. UnicodeString ClipboardText;
  8127. if (NonEmptyTextFromClipboard(ClipboardText) &&
  8128. (ClipboardText.Pos(L"\n") == 0)) // it's already trimmed
  8129. {
  8130. if (StoredSessions->IsUrl(ClipboardText))
  8131. {
  8132. Result = true;
  8133. }
  8134. else
  8135. {
  8136. Result = DirViewEnabled(osCurrent);
  8137. }
  8138. }
  8139. }
  8140. return Result;
  8141. }
  8142. //---------------------------------------------------------------------------
  8143. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  8144. {
  8145. // Pasting to any local panel is handled in TScpCommanderForm::PasteFromClipBoard()
  8146. if (DoesClipboardContainOurFiles())
  8147. {
  8148. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  8149. {
  8150. DebugAssert(!IsLocalBrowserMode());
  8151. TTerminalManager * Manager = TTerminalManager::Instance();
  8152. TTerminal * TargetTerminal = Manager->ActiveTerminal;
  8153. Manager->ActiveSession = FClipboardTerminal;
  8154. ExecuteFileOperation(foRemoteCopy, osRemote, FClipboardFileList.get(), false, TargetTerminal);
  8155. }
  8156. }
  8157. else if (CanPasteToDirViewFromClipBoard())
  8158. {
  8159. DirView(osCurrent)->PasteFromClipBoard();
  8160. }
  8161. else
  8162. {
  8163. UnicodeString ClipboardText;
  8164. if (NonEmptyTextFromClipboard(ClipboardText))
  8165. {
  8166. if (StoredSessions->IsUrl(ClipboardText))
  8167. {
  8168. NewSession(ClipboardText);
  8169. }
  8170. else
  8171. {
  8172. DirView(osCurrent)->Path = ClipboardText;
  8173. }
  8174. }
  8175. }
  8176. }
  8177. //---------------------------------------------------------------------------
  8178. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  8179. {
  8180. // TBD
  8181. }
  8182. //---------------------------------------------------------------------------
  8183. void __fastcall TCustomScpExplorerForm::SelectAll(TOperationSide Side, TSelectMode Mode)
  8184. {
  8185. TCustomDirView * ADirView = DirView(Side);
  8186. ADirView->SelectAll(Mode);
  8187. ADirView->SetFocus();
  8188. }
  8189. //---------------------------------------------------------------------------
  8190. void __fastcall TCustomScpExplorerForm::SelectByMask(TOperationSide Side, bool Select)
  8191. {
  8192. TCustomDirView * ADirView = DirView(Side);
  8193. TFileFilter Filter;
  8194. DefaultFileFilter(Filter);
  8195. if (DoSelectMaskDialog(ADirView, Select, Filter))
  8196. {
  8197. Configuration->Usage->Inc(L"MaskSelections");
  8198. ADirView->SelectFiles(Filter, Select);
  8199. ADirView->SetFocus();
  8200. }
  8201. }
  8202. //---------------------------------------------------------------------------
  8203. void __fastcall TCustomScpExplorerForm::RestoreSelectedNames(TOperationSide Side)
  8204. {
  8205. TCustomDirView * ADirView = DirView(Side);
  8206. ADirView->RestoreSelectedNames();
  8207. ADirView->SetFocus();
  8208. }
  8209. //---------------------------------------------------------------------------
  8210. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  8211. {
  8212. TCustomDirView * CurrentDirView = DirView(osCurrent);
  8213. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  8214. {
  8215. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  8216. UnicodeString Ext;
  8217. if (!IsSideLocalBrowser(osCurrent))
  8218. {
  8219. Ext = UnixExtractFileExt(FileName);
  8220. }
  8221. else
  8222. {
  8223. Ext = ExtractFileExt(FileName);
  8224. }
  8225. if (Ext.IsEmpty())
  8226. {
  8227. Ext = L".";
  8228. }
  8229. TFileFilter Filter;
  8230. Filter.Masks = FORMAT(L"*%s", (Ext));
  8231. Filter.Directories = false;
  8232. CurrentDirView->SelectFiles(Filter, Select);
  8233. }
  8234. }
  8235. //---------------------------------------------------------------------------
  8236. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  8237. const TStatusFileInfo & FileInfo, TOperationSide Side)
  8238. {
  8239. UnicodeString Result;
  8240. if (!FIncrementalSearch.IsEmpty() && (Side == GetSide(osCurrent)))
  8241. {
  8242. Result = FormatIncrementalSearchStatus(FIncrementalSearch, FIncrementalSearchHaveNext);
  8243. }
  8244. else if (!IsSideLocalBrowser(Side) && ((Terminal == NULL) || Terminal->Disconnected))
  8245. {
  8246. // noop
  8247. }
  8248. else
  8249. {
  8250. Result =
  8251. FMTLOAD(FILE_INFO_FORMAT,
  8252. (FormatBytes(FileInfo.SelectedSize),
  8253. FormatBytes(FileInfo.FilesSize),
  8254. FormatNumber(FileInfo.SelectedCount),
  8255. FormatNumber(FileInfo.FilesCount)));
  8256. }
  8257. return Result;
  8258. }
  8259. //---------------------------------------------------------------------------
  8260. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  8261. TTBXStatusPanel * Panel, TOperationSide Side)
  8262. {
  8263. if (Panel->Index == 1)
  8264. {
  8265. ToggleShowHiddenFiles();
  8266. }
  8267. else if (Panel->Index == 2)
  8268. {
  8269. Filter(Side);
  8270. }
  8271. }
  8272. //---------------------------------------------------------------------------
  8273. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  8274. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  8275. {
  8276. DebugAssert(!StatusBar->SimplePanel);
  8277. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  8278. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  8279. }
  8280. //---------------------------------------------------------------------------
  8281. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  8282. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  8283. {
  8284. DebugAssert(StatusBar->Panels->Count >= 3);
  8285. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  8286. if (FileInfo.HiddenCount > 0)
  8287. {
  8288. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  8289. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8290. }
  8291. else
  8292. {
  8293. HiddenFilesPanel->ViewPriority = 0;
  8294. // not really necessary, just to cleanup no-longer-valid data
  8295. HiddenFilesPanel->Caption = L"";
  8296. }
  8297. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  8298. if (FileInfo.FilteredCount > 0)
  8299. {
  8300. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  8301. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  8302. }
  8303. else
  8304. {
  8305. FilteredFilesPanel->ViewPriority = 0;
  8306. // not really necessary, just to cleanup no-longer-valid data
  8307. FilteredFilesPanel->Caption = L"";
  8308. }
  8309. }
  8310. //---------------------------------------------------------------------------
  8311. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  8312. TObject * /*Sender*/)
  8313. {
  8314. if (DirView(osOther)->Enabled)
  8315. {
  8316. DirView(osOther)->SetFocus();
  8317. }
  8318. }
  8319. //---------------------------------------------------------------------------
  8320. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  8321. {
  8322. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  8323. switch (Config.Show)
  8324. {
  8325. case qvShow:
  8326. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  8327. {
  8328. Config.Show = qvHide;
  8329. }
  8330. else
  8331. {
  8332. Config.Show = Config.LastHideShow;
  8333. }
  8334. break;
  8335. case qvHideWhenEmpty:
  8336. if (ComponentVisible[fcQueueView])
  8337. {
  8338. Config.Show = qvHide;
  8339. }
  8340. else
  8341. {
  8342. Config.LastHideShow = Config.Show;
  8343. Config.Show = qvShow;
  8344. }
  8345. break;
  8346. case qvHide:
  8347. Config.LastHideShow = Config.Show;
  8348. Config.Show = qvShow;
  8349. break;
  8350. }
  8351. WinConfiguration->QueueView = Config;
  8352. }
  8353. //---------------------------------------------------------------------------
  8354. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  8355. {
  8356. UnicodeString Result;
  8357. if (Terminal != NULL)
  8358. {
  8359. switch (WinConfiguration->PathInCaption)
  8360. {
  8361. case picShort:
  8362. Result = ExtractShortName(Terminal->CurrentDirectory, true);
  8363. break;
  8364. case picFull:
  8365. Result = Terminal->CurrentDirectory;
  8366. break;
  8367. }
  8368. }
  8369. return Result;
  8370. }
  8371. //---------------------------------------------------------------------------
  8372. TColor __fastcall TCustomScpExplorerForm::PanelColor()
  8373. {
  8374. TColor Result = GetWindowColor(FSessionColor);
  8375. return Result;
  8376. }
  8377. //---------------------------------------------------------------------------
  8378. TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
  8379. {
  8380. TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
  8381. return Result;
  8382. }
  8383. //---------------------------------------------------------------------------
  8384. void __fastcall TCustomScpExplorerForm::UpdateControls()
  8385. {
  8386. if (!FSessionChanging)
  8387. {
  8388. TTerminalManager::Instance()->UpdateAppTitle();
  8389. }
  8390. // WORKAROUND: Disabling list view when it is not showing yet does not set its
  8391. // background to gray on Windows 7 (works on Windows 10).
  8392. // See also EnableControl
  8393. if (Showing)
  8394. {
  8395. if (ManagedSession != NULL)
  8396. {
  8397. // Update path when it changes
  8398. if ((SessionsPageControl->ActivePage != NULL) &&
  8399. (GetSessionTabSession(SessionsPageControl->ActivePage) == ManagedSession))
  8400. {
  8401. UpdateSessionTab(SessionsPageControl->ActivePage);
  8402. }
  8403. }
  8404. NonVisualDataModule->ReconnectSessionAction->Update();
  8405. ReconnectToolbar->Visible = NonVisualDataModule->ReconnectSessionAction->Visible;
  8406. // ReconnectSessionAction is hidden when disabled, so enabling it actualy resizes the toolbar
  8407. CenterReconnectToolbar();
  8408. bool HasTerminal = HasActiveTerminal();
  8409. RemoteDirView->Enabled = HasTerminal;
  8410. RemoteDirView->Color = HasTerminal ? PanelColor() : DisabledPanelColor();
  8411. RemoteDirView->Font->Color = GetWindowTextColor(RemoteDirView->Color);
  8412. RemoteDriveView->Enabled = RemoteDirView->Enabled;
  8413. RemoteDriveView->Color = RemoteDirView->Color;
  8414. RemoteDriveView->Font->Color = RemoteDirView->Font->Color;
  8415. QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fcBackgroundTransfers];
  8416. QueueView3->Color = QueueView3->Enabled ? GetWindowColor() : DisabledPanelColor();
  8417. QueueView3->Font->Color = GetWindowTextColor(QueueView3->Color);
  8418. QueueFileList->Enabled = QueueView3->Enabled;
  8419. QueueFileList->Color = QueueView3->Color;
  8420. QueueFileList->Font->Color = QueueView3->Font->Color;
  8421. QueueLabelUpdateStatus();
  8422. RemoteDirView->DarkMode = WinConfiguration->UseDarkTheme();
  8423. RemoteDriveView->DarkMode = RemoteDirView->DarkMode;
  8424. if (FImmersiveDarkMode != WinConfiguration->UseDarkTheme())
  8425. {
  8426. UpdateDarkMode();
  8427. }
  8428. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal || IsLocalBrowserMode();
  8429. }
  8430. }
  8431. //---------------------------------------------------------------------------
  8432. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  8433. {
  8434. UpdateControls();
  8435. }
  8436. //---------------------------------------------------------------------------
  8437. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  8438. TObject * Sender)
  8439. {
  8440. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8441. DebugAssert(DirView != NULL);
  8442. DoDirViewLoaded(DirView);
  8443. TransferPresetAutoSelect();
  8444. }
  8445. //---------------------------------------------------------------------------
  8446. void __fastcall TCustomScpExplorerForm::StartUpdates()
  8447. {
  8448. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  8449. // first run after installation
  8450. if (double(Updates.LastCheck) == 0)
  8451. {
  8452. // make sure next time there will be an update (if enabled)
  8453. Updates.LastCheck = TDateTime(1);
  8454. WinConfiguration->Updates = Updates;
  8455. }
  8456. else if ((double(Updates.Period) > 0) &&
  8457. (Now() - Updates.LastCheck >= Updates.Period))
  8458. {
  8459. TThreadMethod OnUpdatesChecked = NULL;
  8460. if (!IsUWP())
  8461. {
  8462. OnUpdatesChecked = UpdatesChecked;
  8463. }
  8464. StartUpdateThread(OnUpdatesChecked);
  8465. }
  8466. }
  8467. //---------------------------------------------------------------------------
  8468. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  8469. {
  8470. UnicodeString Message;
  8471. bool New;
  8472. TQueryType Type;
  8473. GetUpdatesMessage(Message, New, Type, false);
  8474. if (!Message.IsEmpty())
  8475. {
  8476. if (New)
  8477. {
  8478. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  8479. }
  8480. if (!New && (Type != qtWarning))
  8481. {
  8482. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  8483. }
  8484. else
  8485. {
  8486. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  8487. }
  8488. if (New)
  8489. {
  8490. Configuration->Usage->Inc(L"UpdateNotifications");
  8491. }
  8492. }
  8493. }
  8494. //---------------------------------------------------------------------------
  8495. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  8496. {
  8497. RestoreApp();
  8498. bool CanDisplay = !NonVisualDataModule->Busy;
  8499. if (!CanDisplay && (Screen->ActiveForm != NULL))
  8500. {
  8501. CanDisplay = (Screen->ActiveForm->Perform(WM_CAN_DISPLAY_UPDATES, 0, 0) != 0);
  8502. }
  8503. if (CanDisplay)
  8504. {
  8505. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  8506. CheckForUpdates(true);
  8507. }
  8508. else
  8509. {
  8510. Configuration->Usage->Inc(L"UpdateNotificationsBusy");
  8511. }
  8512. }
  8513. //---------------------------------------------------------------------------
  8514. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  8515. TCopyParamRuleData & Data)
  8516. {
  8517. DebugAssert(Terminal != NULL);
  8518. Data.HostName = Terminal->SessionData->HostNameExpanded;
  8519. Data.UserName = Terminal->SessionData->UserNameExpanded;
  8520. Data.RemoteDirectory = RemoteDirView->PathName;
  8521. }
  8522. //---------------------------------------------------------------------------
  8523. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  8524. {
  8525. // Terminal can be null when we are changing local directory implicitly,
  8526. // because it has been deleted, while no session is connected
  8527. // (Login dialog is open)
  8528. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  8529. {
  8530. DebugAssert(!IsLocalBrowserMode());
  8531. TCopyParamRuleData Data;
  8532. GetTransferPresetAutoSelectData(Data);
  8533. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  8534. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  8535. if (CopyParamIndex < 0)
  8536. {
  8537. // there is no preset that matches autoselection
  8538. // set preset that we consider "default"
  8539. FCopyParamAutoSelected = L""; // forget last autoselected preset
  8540. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  8541. }
  8542. else
  8543. {
  8544. // there is preset matching autoselection
  8545. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  8546. if (CopyParamName == FCopyParamAutoSelected)
  8547. {
  8548. // autoselected the same preset as the last time
  8549. // make no change (i.e. preserve custom user preset, if any)
  8550. }
  8551. else
  8552. {
  8553. // autoselected the different preset then the last time (or there
  8554. // was default preset set)
  8555. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  8556. GUIConfiguration->CopyParamCurrent = CopyParamName;
  8557. }
  8558. }
  8559. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  8560. {
  8561. if (CopyParamIndex >= 0)
  8562. {
  8563. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  8564. }
  8565. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  8566. try
  8567. {
  8568. int Fmt =
  8569. (CopyParamIndex < 0) ?
  8570. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  8571. COPY_PARAM_AUTOSELECTED;
  8572. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  8573. Data->Message = MainInstructions(Message);
  8574. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  8575. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  8576. CopyParamAttrs);
  8577. if (CopyParamIndex >= 0)
  8578. {
  8579. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  8580. Info = FORMAT(L"%s\n \n%s", (Info,
  8581. FMTLOAD(COPY_PARAM_RULE,
  8582. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  8583. }
  8584. Data->Message += L"\n\n" + Info;
  8585. if (WinConfiguration->CopyParamAutoSelectNotice)
  8586. {
  8587. TransferPresetNoteMessage(Data, true);
  8588. }
  8589. else
  8590. {
  8591. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  8592. Data = NULL; // ownership passed
  8593. }
  8594. }
  8595. __finally
  8596. {
  8597. delete Data;
  8598. }
  8599. }
  8600. }
  8601. }
  8602. //---------------------------------------------------------------------------
  8603. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  8604. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  8605. {
  8606. DebugAssert(NoteData != NULL);
  8607. DebugAssert(!IsLocalBrowserMode());
  8608. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  8609. TQueryButtonAlias Aliases[1];
  8610. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  8611. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  8612. Params.Aliases = Aliases;
  8613. Params.AliasesCount = LENOF(Aliases);
  8614. unsigned int Result =
  8615. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  8616. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  8617. switch (Result)
  8618. {
  8619. case qaNeverAskAgain:
  8620. DebugAssert(AllowNeverAskAgain);
  8621. WinConfiguration->CopyParamAutoSelectNotice = false;
  8622. break;
  8623. case qaIgnore:
  8624. PreferencesDialog(pmPresets);
  8625. break;
  8626. }
  8627. }
  8628. //---------------------------------------------------------------------------
  8629. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  8630. {
  8631. // as of now useless, as this is used for notes only, never for balloons, ...
  8632. RestoreApp();
  8633. // .. and we should never be busy here
  8634. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  8635. {
  8636. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  8637. }
  8638. }
  8639. //---------------------------------------------------------------------------
  8640. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  8641. TPreferencesMode APreferencesMode)
  8642. {
  8643. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  8644. TCopyParamRuleData Data;
  8645. if (Terminal != NULL)
  8646. {
  8647. PreferencesData.reset(new TPreferencesDialogData());
  8648. GetTransferPresetAutoSelectData(Data);
  8649. PreferencesData->CopyParamRuleData = &Data;
  8650. }
  8651. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  8652. }
  8653. //---------------------------------------------------------------------------
  8654. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  8655. const TCustomCommandType & Command)
  8656. {
  8657. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  8658. {
  8659. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
  8660. }
  8661. }
  8662. //---------------------------------------------------------------------------
  8663. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  8664. {
  8665. bool RemoteAllowed = CustomCommandRemoteAllowed();
  8666. TCustomCommandType Command;
  8667. // make sure we use local custom command when remote are not supported
  8668. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  8669. {
  8670. Command = FLastCustomCommand;
  8671. }
  8672. else
  8673. {
  8674. Command.Params = Command.Params | ccLocal;
  8675. }
  8676. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  8677. FEditingFocusedAdHocCommand = OnFocused;
  8678. bool LocalSide = IsSideLocalBrowser(FCurrentSide);
  8679. int Options =
  8680. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  8681. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  8682. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  8683. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  8684. {
  8685. FLastCustomCommand = Command;
  8686. UpdateCustomCommandsToolbar();
  8687. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  8688. }
  8689. }
  8690. //---------------------------------------------------------------------------
  8691. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  8692. {
  8693. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  8694. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8695. DebugAssert(State > 0);
  8696. if (State <= 0)
  8697. {
  8698. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
  8699. }
  8700. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  8701. }
  8702. //---------------------------------------------------------------------------
  8703. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  8704. TCustomCommandType & Command, int & State)
  8705. {
  8706. bool Result = !FLastCustomCommand.Command.IsEmpty();
  8707. if (Result)
  8708. {
  8709. Command = FLastCustomCommand;
  8710. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  8711. }
  8712. return Result;
  8713. }
  8714. //---------------------------------------------------------------------------
  8715. void __fastcall TCustomScpExplorerForm::BeforeAction()
  8716. {
  8717. ResetIncrementalSearch();
  8718. }
  8719. //---------------------------------------------------------------------------
  8720. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  8721. {
  8722. DebugAssert(ComponentVisible[Component]);
  8723. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  8724. }
  8725. //---------------------------------------------------------------------------
  8726. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  8727. {
  8728. // when queue panel is resized here directly, the status bar is stretched
  8729. // over whole space the panel occupied
  8730. PostComponentHide(fcQueueView);
  8731. }
  8732. //---------------------------------------------------------------------------
  8733. void __fastcall TCustomScpExplorerForm::QueueFileListSplitterDblClick(TObject *)
  8734. {
  8735. ComponentVisible[fcQueueFileList] = false;
  8736. }
  8737. //---------------------------------------------------------------------------
  8738. void __fastcall TCustomScpExplorerForm::ThemeChanged()
  8739. {
  8740. // We hoped this will refresh scrollbar colors, but it does not have any effect here.
  8741. RefreshColorMode();
  8742. ResetSysDarkTheme();
  8743. ConfigurationChanged();
  8744. ConfigureInterface();
  8745. // Should be called for all controls
  8746. RemoteDirView->Perform(WM_THEMECHANGED, 0, 0);
  8747. }
  8748. //---------------------------------------------------------------------------
  8749. void __fastcall TCustomScpExplorerForm::WMSettingChange(TMessage & Message)
  8750. {
  8751. // Do not handle, when shutting down anyway (maybe also when not setup completelly yet?)
  8752. if (!FInvalid &&
  8753. (Message.LParam != 0) &&
  8754. (wcscmp(reinterpret_cast<LPCWCH>(Message.LParam), L"ImmersiveColorSet") == 0))
  8755. {
  8756. ThemeChanged();
  8757. }
  8758. TForm::Dispatch(&Message);
  8759. }
  8760. //---------------------------------------------------------------------------
  8761. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  8762. {
  8763. TMessage * M = static_cast<TMessage*>(Message);
  8764. switch (M->Msg)
  8765. {
  8766. case CM_DIALOGCHAR:
  8767. CMDialogChar(*M);
  8768. break;
  8769. case WM_APPCOMMAND:
  8770. WMAppCommand(*M);
  8771. break;
  8772. case WM_SYSCOMMAND:
  8773. WMSysCommand(*M);
  8774. break;
  8775. case WM_QUERYENDSESSION:
  8776. WMQueryEndSession(*M);
  8777. break;
  8778. case WM_ENDSESSION:
  8779. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  8780. break;
  8781. #ifdef _DEBUG
  8782. case WM_WINDOWPOSCHANGED:
  8783. WMWindowPosChanged(*reinterpret_cast<TWMWindowPosMsg *>(M));
  8784. break;
  8785. case CM_CUSTOMSTYLECHANGED:
  8786. TForm::Dispatch(Message);
  8787. break;
  8788. #endif
  8789. case WM_COMPONENT_HIDE:
  8790. {
  8791. Byte Component = static_cast<Byte>(M->WParam);
  8792. // sanity check
  8793. if (ComponentVisible[Component])
  8794. {
  8795. // special treatment
  8796. if (Component == fcQueueView)
  8797. {
  8798. ToggleQueueVisibility();
  8799. DebugAssert(!ComponentVisible[fcQueueView]);
  8800. }
  8801. else
  8802. {
  8803. ComponentVisible[Component] = false;
  8804. }
  8805. }
  8806. }
  8807. break;
  8808. case WM_COPYDATA:
  8809. WMCopyData(*M);
  8810. break;
  8811. case WM_MANAGES_CAPTION:
  8812. // caption managed in TTerminalManager::UpdateAppTitle()
  8813. M->Result = 1;
  8814. break;
  8815. case WM_WANTS_MOUSEWHEEL:
  8816. M->Result = 1;
  8817. break;
  8818. case CM_SHOWINGCHANGED:
  8819. CMShowingChanged(*M);
  8820. break;
  8821. case WM_CLOSE:
  8822. WMClose(*M);
  8823. break;
  8824. case WM_DPICHANGED:
  8825. WMDpiChanged(*M);
  8826. break;
  8827. case CM_DPICHANGED:
  8828. CMDpiChanged(*M);
  8829. break;
  8830. case WM_SETTINGCHANGE:
  8831. WMSettingChange(*M);
  8832. break;
  8833. case CM_DIALOGKEY:
  8834. CMDialogKey(*reinterpret_cast<TWMKeyDown *>(M));
  8835. break;
  8836. default:
  8837. TForm::Dispatch(Message);
  8838. break;
  8839. }
  8840. }
  8841. //---------------------------------------------------------------------------
  8842. void __fastcall TCustomScpExplorerForm::UpdateImages()
  8843. {
  8844. // noop
  8845. }
  8846. //---------------------------------------------------------------------------
  8847. void __fastcall TCustomScpExplorerForm::CMDpiChanged(TMessage & Message)
  8848. {
  8849. TForm::Dispatch(&Message);
  8850. FSessionColors->Clear();
  8851. AddFixedSessionImages();
  8852. RegenerateSessionColorsImageList(FSessionColors, FSessionColorMaskImageIndex);
  8853. UpdateImages();
  8854. }
  8855. //---------------------------------------------------------------------------
  8856. void __fastcall TCustomScpExplorerForm::WMDpiChanged(TMessage & Message)
  8857. {
  8858. TForm::Dispatch(&Message);
  8859. Configuration->Usage->Inc(L"PixelsPerInchChanged");
  8860. UpdatePixelsPerInchMainWindowCounter();
  8861. }
  8862. //---------------------------------------------------------------------------
  8863. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  8864. {
  8865. // Cannot close window while we are busy.
  8866. // We cannot test this in FormCloseQuery as that is called also from
  8867. // Close(), which is called by CloseApplicationAction. So we can be busy
  8868. // there already even, when it is legitimate to close the application.
  8869. // Possibly a better place to handle this would be WMSysCommand.
  8870. if (NonVisualDataModule->Busy)
  8871. {
  8872. Message.Result = 1;
  8873. }
  8874. else
  8875. {
  8876. TForm::Dispatch(&Message);
  8877. }
  8878. }
  8879. //---------------------------------------------------------------------------
  8880. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  8881. {
  8882. // Ignoring implicit local-local browser of Commander, opened from DoShow
  8883. bool NoSession = (ManagedSession == NULL);
  8884. // This calls TCustomScpExplorerForm::DoShow
  8885. TForm::Dispatch(&Message);
  8886. // Now the window is visible (TForm::Dispatch is what usually takes long, like when loading a "local" network directory)
  8887. if (Showing && !FStarted)
  8888. {
  8889. FStarted = true;
  8890. InterfaceStarted();
  8891. }
  8892. if (Showing && NoSession)
  8893. {
  8894. // When we are starting minimized (i.e. from an installer),
  8895. // postpone showing Login dialog until we get restored.
  8896. // Otherwise the Login dialog (and Authentication window) show restored
  8897. // over invisible (minimized) main window.
  8898. if (WindowState == wsMinimized)
  8899. {
  8900. FNeedSession = true;
  8901. }
  8902. else
  8903. {
  8904. // This happens before application ever goes idle, so the toolbars would
  8905. // stay enabled (initial state) until the Login dialog is dismissed.
  8906. UpdateActions();
  8907. NonVisualDataModule->StartBusy();
  8908. try
  8909. {
  8910. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  8911. // otherwise the dialog does not receive focus.
  8912. // With Commander interface the ProcessMessages is called already
  8913. // by TDriveView, but with Explorer interface, we need to call it explicily
  8914. Application->ProcessMessages();
  8915. // do not reload sessions, they have been loaded just now (optimization)
  8916. NeedSession(true);
  8917. }
  8918. __finally
  8919. {
  8920. NonVisualDataModule->EndBusy();
  8921. }
  8922. }
  8923. }
  8924. }
  8925. //---------------------------------------------------------------------------
  8926. void __fastcall TCustomScpExplorerForm::CenterReconnectToolbar()
  8927. {
  8928. ReconnectToolbar->Left = (ReconnectToolbar->Parent->ClientWidth - ReconnectToolbar->Width) / 2;
  8929. ReconnectToolbar->Top = (ReconnectToolbar->Parent->ClientHeight - ReconnectToolbar->Height) / 2;
  8930. }
  8931. //---------------------------------------------------------------------------
  8932. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  8933. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  8934. int & MaxHeight)
  8935. {
  8936. // workaround for bug in TWinControl.CalcConstraints
  8937. // Check for empty rect (restore from iconic state) is done there only after
  8938. // call to AdjustClientRect, which enlarges the rect (for forms).
  8939. TRect R = GetClientRect();
  8940. // when restoring from iconic state, place no restrictions
  8941. if (IsRectEmpty(R))
  8942. {
  8943. MinWidth = 0;
  8944. MinHeight = 0;
  8945. MaxWidth = 32000;
  8946. MaxHeight = 32000;
  8947. }
  8948. }
  8949. //---------------------------------------------------------------------------
  8950. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  8951. TSpaceAvailable & ASpaceAvailable, bool & Close)
  8952. {
  8953. // terminal can be already closed (e.g. dropped connection)
  8954. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  8955. {
  8956. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  8957. try
  8958. {
  8959. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  8960. }
  8961. catch(...)
  8962. {
  8963. if (!Terminal->Active)
  8964. {
  8965. Close = true;
  8966. }
  8967. throw;
  8968. }
  8969. }
  8970. }
  8971. //---------------------------------------------------------------------------
  8972. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  8973. {
  8974. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  8975. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  8976. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  8977. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  8978. {
  8979. OnGetSpaceAvailable = GetSpaceAvailable;
  8980. }
  8981. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  8982. OnGetSpaceAvailable);
  8983. }
  8984. //---------------------------------------------------------------------------
  8985. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  8986. {
  8987. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  8988. Terminal->FillSessionDataForCode(Data.get());
  8989. return Data.release();
  8990. }
  8991. //---------------------------------------------------------------------------
  8992. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  8993. {
  8994. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  8995. DoGenerateUrlDialog(Data.get(), Paths);
  8996. }
  8997. //---------------------------------------------------------------------------
  8998. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  8999. {
  9000. GenerateUrl(NULL);
  9001. }
  9002. //---------------------------------------------------------------------------
  9003. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  9004. {
  9005. std::unique_ptr<TStrings> Paths(new TStringList());
  9006. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  9007. GenerateUrl(Paths.get());
  9008. }
  9009. //---------------------------------------------------------------------------
  9010. void __fastcall TCustomScpExplorerForm::UpdateSessionColor(TColor value)
  9011. {
  9012. FSessionColor = value;
  9013. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  9014. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  9015. static_cast<TObject *>(GetComponent(fcColorMenu)));
  9016. DebugAssert(ColorItem != NULL);
  9017. ColorItem->Color = C;
  9018. NonVisualDataModule->ColorMenuItem->Color = C;
  9019. UpdateControls();
  9020. }
  9021. //---------------------------------------------------------------------------
  9022. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  9023. {
  9024. if (value != FSessionColor)
  9025. {
  9026. UpdateSessionColor(value);
  9027. // Is null when called from LastTerminalClosed
  9028. if (Terminal != NULL)
  9029. {
  9030. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  9031. }
  9032. }
  9033. }
  9034. //---------------------------------------------------------------------------
  9035. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  9036. {
  9037. bool Result = FNoteTimer->Enabled;
  9038. if (Result)
  9039. {
  9040. // cannot cancel note too early
  9041. bool NotEarly =
  9042. (Now() - FNoteShown >
  9043. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  9044. if (Force || NotEarly)
  9045. {
  9046. FNoteTimer->Enabled = false;
  9047. FNote = L"";
  9048. SAFE_DESTROY(FNoteData);
  9049. FOnNoteClick = NULL;
  9050. FNoteHints = FNotes->Text;
  9051. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  9052. UpdateStatusBar();
  9053. }
  9054. }
  9055. return Result;
  9056. }
  9057. //---------------------------------------------------------------------------
  9058. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  9059. {
  9060. DebugAssert(FNoteTimer->Enabled);
  9061. CancelNote(true);
  9062. }
  9063. //---------------------------------------------------------------------------
  9064. void __fastcall TCustomScpExplorerForm::UpdateNoteHints()
  9065. {
  9066. FNoteHints = FNotes->Text.TrimRight();
  9067. }
  9068. //---------------------------------------------------------------------------
  9069. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  9070. {
  9071. int P = Note.Pos(L"\n");
  9072. if (P > 0)
  9073. {
  9074. Note.SetLength(P - 1);
  9075. }
  9076. FNotes->Add(FORMAT(L"[%s] %s",
  9077. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  9078. while (FNotes->Count > 10)
  9079. {
  9080. FNotes->Delete(0);
  9081. }
  9082. if (UpdateNow)
  9083. {
  9084. UpdateNoteHints();
  9085. UpdateStatusBar();
  9086. }
  9087. }
  9088. //---------------------------------------------------------------------------
  9089. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  9090. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  9091. {
  9092. int P = Note.Pos(L"\n");
  9093. if (P > 0)
  9094. {
  9095. Note.SetLength(P - 1);
  9096. }
  9097. UpdateNoteHints();
  9098. FNote = Note;
  9099. SAFE_DESTROY(FNoteData);
  9100. FNoteData = NoteData;
  9101. FOnNoteClick = OnNoteClick;
  9102. AddNote(Note, false);
  9103. UpdateStatusBar();
  9104. FNoteShown = Now();
  9105. FNoteTimer->Enabled = false;
  9106. if (Seconds == 0)
  9107. {
  9108. Seconds = WinConfiguration->NotificationsTimeout;
  9109. }
  9110. FNoteTimer->Interval = Seconds * MSecsPerSec;
  9111. FNoteTimer->Enabled = true;
  9112. }
  9113. //---------------------------------------------------------------------------
  9114. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  9115. {
  9116. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  9117. }
  9118. //---------------------------------------------------------------------------
  9119. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  9120. {
  9121. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked)
  9122. {
  9123. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  9124. }
  9125. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  9126. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  9127. (NonVisualDataModule->SynchronizeBrowsingAction2->Checked ? 2 : 3)))),
  9128. 0, NULL, NULL);
  9129. }
  9130. //---------------------------------------------------------------------------
  9131. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  9132. {
  9133. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  9134. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  9135. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  9136. GetComponent(fcStatusBar)->Repaint(); // toggling ShowHiddenFiles takes time, force repaint beforehand
  9137. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  9138. }
  9139. //---------------------------------------------------------------------------
  9140. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  9141. {
  9142. WinConfiguration->FormatSizeBytes = Style;
  9143. }
  9144. //---------------------------------------------------------------------------
  9145. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  9146. {
  9147. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  9148. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  9149. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  9150. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  9151. }
  9152. //---------------------------------------------------------------------------
  9153. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  9154. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  9155. {
  9156. if (Panel->Index == 0)
  9157. {
  9158. if (FOnNoteClick != NULL)
  9159. {
  9160. // prevent the user data from being freed by possible call
  9161. // to CancelNote or PostNote during call to OnNoteClick
  9162. std::unique_ptr<TObject> NoteData(FNoteData);
  9163. TNotifyEvent OnNoteClick = FOnNoteClick;
  9164. FNoteData = NULL;
  9165. // need to cancel the note as we are going to delete its user data
  9166. CancelNote(true);
  9167. OnNoteClick(NoteData.get());
  9168. }
  9169. }
  9170. if (HasActiveTerminal() &&
  9171. (Panel->Index >= Sender->Panels->Count - SessionPanelCount))
  9172. {
  9173. FileSystemInfo();
  9174. }
  9175. }
  9176. //---------------------------------------------------------------------------
  9177. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  9178. {
  9179. // workaround:
  9180. // 1) for unknown reason, disabling window, while minimized,
  9181. // prevents it from restoring, even if it was enabled again meanwhile
  9182. // 2) when disabling the main window, while another has focus
  9183. // minimize is no longer possible
  9184. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  9185. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  9186. // Shouldn't we use IsApplicationMinimized() here?
  9187. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  9188. {
  9189. Enabled = false;
  9190. }
  9191. FLockLevel++;
  9192. }
  9193. //---------------------------------------------------------------------------
  9194. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  9195. {
  9196. DebugAssert(FLockLevel > 0);
  9197. FLockLevel--;
  9198. if (FLockLevel == 0)
  9199. {
  9200. DebugAssert(FLockSuspendLevel == 0);
  9201. Enabled = true;
  9202. }
  9203. }
  9204. //---------------------------------------------------------------------------
  9205. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  9206. {
  9207. // We need to make sure that window is enabled when the last modal window closes
  9208. // otherwise focus is not restored correctly.
  9209. // So we re-enable the window when modal window opens and
  9210. // disable it back after is closes
  9211. if (FLockLevel > 0)
  9212. {
  9213. // while we have nesting counter, we know that we never be called
  9214. // recursivelly as Application->OnModalBegin is called only
  9215. // for the top-level modal window
  9216. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9217. {
  9218. // won't be disabled when conditions in LockWindow() were not satisfied
  9219. FDisabledOnLockSuspend = !Enabled;
  9220. // When minimized to tray (or actually when set to SW_HIDE),
  9221. // setting Enabled makes the window focusable even when there's
  9222. // modal window over it
  9223. if (!FTrayIcon->Visible)
  9224. {
  9225. Enabled = true;
  9226. }
  9227. }
  9228. FLockSuspendLevel++;
  9229. }
  9230. }
  9231. //---------------------------------------------------------------------------
  9232. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  9233. {
  9234. if (FLockSuspendLevel > 0)
  9235. {
  9236. DebugAssert(FLockLevel > 0);
  9237. FLockSuspendLevel--;
  9238. // see comment in SuspendWindowLock
  9239. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  9240. {
  9241. // Note that window can be enabled here, when we were minized to tray when
  9242. // was SuspendWindowLock() called.
  9243. // We should possibly do the same check as in LockWindow(),
  9244. // if it is ever possible that the consitions change between
  9245. // SuspendWindowLock() and ResumeWindowLock()
  9246. Enabled = !FDisabledOnLockSuspend;
  9247. }
  9248. }
  9249. }
  9250. //---------------------------------------------------------------------------
  9251. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  9252. {
  9253. TTBXComboBoxItem * RemotePathComboBox =
  9254. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  9255. if (!TextOnly)
  9256. {
  9257. TStrings * Items = RemotePathComboBox->Strings;
  9258. Items->BeginUpdate();
  9259. try
  9260. {
  9261. Items->Clear();
  9262. if ((Terminal != NULL) && !RemoteDirView->Path.IsEmpty())
  9263. {
  9264. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9265. while (!IsUnixRootPath(APath))
  9266. {
  9267. int P = APath.LastDelimiter(L'/');
  9268. DebugAssert(P >= 0);
  9269. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  9270. APath.SetLength(P - 1);
  9271. }
  9272. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  9273. }
  9274. }
  9275. __finally
  9276. {
  9277. Items->EndUpdate();
  9278. }
  9279. }
  9280. RemotePathComboBox->ItemIndex = RemotePathComboBox->Strings->Count - 1;
  9281. // Setting ItemIndex to -1 does not reset its text
  9282. if (RemotePathComboBox->Strings->Count == 0)
  9283. {
  9284. RemotePathComboBox->Text = L"";
  9285. }
  9286. }
  9287. //---------------------------------------------------------------------------
  9288. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(
  9289. TTBXComboBoxItem * Sender, const UnicodeString DebugUsedArg(AText), int AIndex, int & ImageIndex)
  9290. {
  9291. if (AIndex < 0)
  9292. {
  9293. AIndex = Sender->ItemIndex;
  9294. }
  9295. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  9296. }
  9297. //---------------------------------------------------------------------------
  9298. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  9299. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  9300. int & ImageIndex)
  9301. {
  9302. DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  9303. }
  9304. //---------------------------------------------------------------------------
  9305. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  9306. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  9307. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  9308. {
  9309. if (!IsLocalBrowserMode())
  9310. {
  9311. ARect.Left += (10 * AIndex);
  9312. }
  9313. }
  9314. //---------------------------------------------------------------------------
  9315. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  9316. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  9317. {
  9318. AWidth += (10 * AIndex);
  9319. }
  9320. //---------------------------------------------------------------------------
  9321. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  9322. {
  9323. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  9324. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  9325. int Index = RemotePathComboBox->ItemIndex;
  9326. while (Index < RemotePathComboBox->Strings->Count - 1)
  9327. {
  9328. APath = UnixExtractFileDir(APath);
  9329. Index++;
  9330. }
  9331. // VanDyke style paths
  9332. if (APath.IsEmpty())
  9333. {
  9334. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  9335. APath = ROOTDIRECTORY;
  9336. }
  9337. if (RemoteDirView->Path != APath)
  9338. {
  9339. RemoteDirView->Path = APath;
  9340. }
  9341. }
  9342. //---------------------------------------------------------------------------
  9343. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(TObject * Sender)
  9344. {
  9345. DoRemotePathComboBoxItemClick(Sender);
  9346. }
  9347. //---------------------------------------------------------------------------
  9348. void __fastcall TCustomScpExplorerForm::DoRemotePathComboBoxCancel(TObject * Sender)
  9349. {
  9350. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  9351. DebugUsedParam(Sender);
  9352. UpdateRemotePathComboBox(true);
  9353. }
  9354. //---------------------------------------------------------------------------
  9355. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  9356. {
  9357. DoRemotePathComboBoxCancel(Sender);
  9358. }
  9359. //---------------------------------------------------------------------------
  9360. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  9361. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  9362. {
  9363. ResetIncrementalSearch();
  9364. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  9365. DebugAssert(DirView != NULL);
  9366. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  9367. {
  9368. HWND Edit = ListView_GetEditControl(DirView->Handle);
  9369. // OnEditing is called also from TCustomListView::CanEdit
  9370. if (Edit != NULL)
  9371. {
  9372. EditSelectBaseName(Edit);
  9373. }
  9374. }
  9375. }
  9376. //---------------------------------------------------------------------------
  9377. //---------------------------------------------------------------------------
  9378. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  9379. {
  9380. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  9381. Result->AutoDetectDnD = false;
  9382. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  9383. Result->RenderDataOn = rdoEnterAndDropSync;
  9384. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  9385. return Result;
  9386. }
  9387. //---------------------------------------------------------------------------
  9388. void __fastcall TCustomScpExplorerForm::UpdateDarkMode()
  9389. {
  9390. if (IsWin10Build(2004))
  9391. {
  9392. FImmersiveDarkMode = WinConfiguration->UseDarkTheme();
  9393. BOOL DarkMode = FImmersiveDarkMode ? TRUE : FALSE;
  9394. const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
  9395. DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
  9396. }
  9397. }
  9398. //---------------------------------------------------------------------------
  9399. void __fastcall TCustomScpExplorerForm::CreateWnd()
  9400. {
  9401. TForm::CreateWnd();
  9402. // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
  9403. UpdateDarkMode();
  9404. if (FSessionsDragDropFilesEx == NULL)
  9405. {
  9406. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  9407. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  9408. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  9409. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  9410. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  9411. }
  9412. if (FQueueDragDropFilesEx == NULL)
  9413. {
  9414. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  9415. // No need to set OnDragOver as we do not have any restrictions
  9416. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  9417. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  9418. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  9419. }
  9420. }
  9421. //---------------------------------------------------------------------------
  9422. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  9423. {
  9424. TForm::DestroyWnd();
  9425. FSessionsDragDropFilesEx->DragDropControl = NULL;
  9426. FQueueDragDropFilesEx->DragDropControl = NULL;
  9427. }
  9428. //---------------------------------------------------------------------------
  9429. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  9430. {
  9431. SideEnter(FCurrentSide);
  9432. FEverShown = true;
  9433. }
  9434. //---------------------------------------------------------------------------
  9435. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  9436. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  9437. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  9438. {
  9439. if (!NonVisualDataModule->Busy)
  9440. {
  9441. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9442. Configuration->Usage->Inc(L"FileFinds");
  9443. LockWindow(true);
  9444. NonVisualDataModule->StartBusy();
  9445. WinConfiguration->LockedInterface = true;
  9446. try
  9447. {
  9448. Terminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  9449. }
  9450. __finally
  9451. {
  9452. WinConfiguration->LockedInterface = false;
  9453. NonVisualDataModule->EndBusy();
  9454. UnlockWindow();
  9455. }
  9456. }
  9457. }
  9458. //---------------------------------------------------------------------------
  9459. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  9460. {
  9461. if (!NonVisualDataModule->Busy)
  9462. {
  9463. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9464. SetFocus();
  9465. RemoteDirView->Path = UnixExtractFilePath(Path);
  9466. UnicodeString FileName = UnixExtractFileName(Path);
  9467. TListItem * Item = RemoteDirView->FindFileItem(FileName);
  9468. // If not found, it can because we have loaded directory from cache and the file is new, try again after reload.
  9469. // (tbd: we should not even try this, if we have not loaded the directory from the cache)
  9470. if (Item == NULL)
  9471. {
  9472. ReloadDirectory(osRemote);
  9473. Item = RemoteDirView->FindFileItem(FileName);
  9474. }
  9475. if (Item != NULL)
  9476. {
  9477. RemoteDirView->ItemFocused = Item;
  9478. RemoteDirView->ItemFocused->MakeVisible(false);
  9479. RemoteDirView->SetFocus();
  9480. }
  9481. }
  9482. }
  9483. //---------------------------------------------------------------------------
  9484. bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
  9485. {
  9486. bool Result = !NonVisualDataModule->Busy;
  9487. if (Result)
  9488. {
  9489. TTerminalManager::Instance()->ActiveSession = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  9490. }
  9491. return Result;
  9492. }
  9493. //---------------------------------------------------------------------------
  9494. void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
  9495. TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9496. {
  9497. if (CanOperateOnFoundFiles(ATerminal))
  9498. {
  9499. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  9500. FOnFileOperationFinished = OnFileOperationFinished;
  9501. ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
  9502. }
  9503. }
  9504. //---------------------------------------------------------------------------
  9505. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  9506. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9507. {
  9508. DoOperationOnFoundFiles(foDelete, ATerminal, FileList, OnFileOperationFinished);
  9509. }
  9510. //---------------------------------------------------------------------------
  9511. void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
  9512. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9513. {
  9514. DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
  9515. }
  9516. //---------------------------------------------------------------------------
  9517. void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
  9518. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  9519. {
  9520. if (CanOperateOnFoundFiles(ATerminal))
  9521. {
  9522. for (int Index = 0; Index < FileList->Count; Index++)
  9523. {
  9524. UnicodeString FileName = FileList->Strings[Index];
  9525. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
  9526. ExecuteRemoteFile(FileName, File, efDefaultEditor);
  9527. OnFileOperationFinished(osRemote, FileName, true);
  9528. }
  9529. }
  9530. }
  9531. //---------------------------------------------------------------------------
  9532. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  9533. {
  9534. FFileFindTerminal = Terminal;
  9535. ShowFileFindDialog(
  9536. Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
  9537. DoDownloadFoundFiles, DoEditFoundFiles);
  9538. }
  9539. //---------------------------------------------------------------------------
  9540. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  9541. {
  9542. FTaskbarList = TaskbarList;
  9543. }
  9544. //---------------------------------------------------------------------------
  9545. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  9546. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  9547. {
  9548. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9549. if (Index >= 0)
  9550. {
  9551. if (Button == mbLeft)
  9552. {
  9553. // WORKAROUND: "Mouse down" is raised only after tab is switched.
  9554. // If switching tab (switching session) takes long enough for user
  9555. // to actually release the button, "mouse down" is still raised,
  9556. // but we do not get "mouse up" event, so dragging is not cancelled,
  9557. // prevent that by not beginning dragging in the first place.
  9558. if (IsKeyPressed(VK_LBUTTON))
  9559. {
  9560. // when user clicks the "+", we get mouse down only after the session
  9561. // is closed, when new session tab is already on X:Y, so dragging
  9562. // starts, prevent that
  9563. if (MilliSecondsBetween(Now(), FSessionsPageControlNewTabTime) > 500)
  9564. {
  9565. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9566. if (Terminal != NULL)
  9567. {
  9568. SessionsPageControl->BeginDrag(false);
  9569. }
  9570. }
  9571. }
  9572. }
  9573. else if (Button == mbMiddle)
  9574. {
  9575. // ignore middle-click for "New session tab" and the last local-local tab
  9576. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9577. if ((Session != NULL) && CanCloseSession(Session))
  9578. {
  9579. CloseSessionTab(Index);
  9580. }
  9581. }
  9582. }
  9583. }
  9584. //---------------------------------------------------------------------------
  9585. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  9586. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  9587. {
  9588. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9589. // do not allow dropping on the "+" tab
  9590. TTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9591. if ((TargetTerminal != NULL) &&
  9592. (SessionsPageControl->ActivePage->PageIndex != Index))
  9593. {
  9594. Configuration->Usage->Inc(L"SessionTabMoves");
  9595. // this is almost redundant as we would recreate tabs in SessionListChanged,
  9596. // but we want to actually prevent that to avoid flicker
  9597. SessionsPageControl->ActivePage->PageIndex = Index;
  9598. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->ActivePage);
  9599. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  9600. }
  9601. }
  9602. //---------------------------------------------------------------------------
  9603. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  9604. TObject * Sender, TObject * Source, int X, int Y,
  9605. TDragState /*State*/, bool & Accept)
  9606. {
  9607. Accept = (Sender == Source);
  9608. if (Accept)
  9609. {
  9610. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  9611. TTerminal * Terminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9612. // do not allow dragging to the "+" tab
  9613. Accept = (Terminal != NULL);
  9614. }
  9615. }
  9616. //---------------------------------------------------------------------------
  9617. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(
  9618. int DebugUsedArg(KeyState), const TPoint & Point, int & Effect, int DebugUsedArg(PreferredEffect))
  9619. {
  9620. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9621. if (Index < 0)
  9622. {
  9623. Effect = DROPEFFECT_NONE;
  9624. }
  9625. else
  9626. {
  9627. TManagedTerminal * TargetSession = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9628. // do not allow dropping on the "+" tab or on disconnected or local-local tabs
  9629. if (!IsActiveTerminal(TargetSession) || DebugAlwaysFalse(TargetSession->LocalBrowser))
  9630. {
  9631. Effect = DROPEFFECT_NONE;
  9632. }
  9633. else if ((TargetSession != Terminal) && (Effect == DROPEFFECT_MOVE))
  9634. {
  9635. Effect = DROPEFFECT_COPY;
  9636. }
  9637. }
  9638. }
  9639. //---------------------------------------------------------------------------
  9640. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  9641. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  9642. {
  9643. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  9644. // do not allow dropping on local-local, disconnected and the "+" tab
  9645. // (though we do not seem to get here in that case anyway, contrary to RemoteFileControlDDTargetDrop)
  9646. TManagedTerminal * TargetTerminal = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9647. if (DebugAlwaysTrue(IsActiveTerminal(TargetTerminal) && !TargetTerminal->LocalBrowser))
  9648. {
  9649. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  9650. if (!IsFileControl(DropSourceControl, osRemote))
  9651. {
  9652. TTerminalManager::Instance()->ActiveSession = TargetTerminal;
  9653. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  9654. // Why don't we use Terminal->CurrentDirectory directly?
  9655. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory,
  9656. // do not force queue, drag drop
  9657. false, true);
  9658. }
  9659. }
  9660. }
  9661. //---------------------------------------------------------------------------
  9662. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  9663. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  9664. {
  9665. // Downloads are handled in RemoteFileControlDDEnd
  9666. if (!IsFileControl(DropSourceControl, osRemote))
  9667. {
  9668. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  9669. Terminal->CurrentDirectory,
  9670. // force queue, drag drop
  9671. true, true);
  9672. }
  9673. }
  9674. //---------------------------------------------------------------------------
  9675. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  9676. {
  9677. FShowing = false;
  9678. // Do not save empty workspace
  9679. if (WinConfiguration->AutoSaveWorkspace && (ManagedSession != NULL))
  9680. {
  9681. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  9682. UnicodeString Name = WorkspaceName();
  9683. DoSaveWorkspace(
  9684. Name, DataList.get(),
  9685. !Configuration->DisablePasswordStoring &&
  9686. WinConfiguration->AutoSaveWorkspacePasswords, false);
  9687. WinConfiguration->LastStoredSession = Name;
  9688. }
  9689. }
  9690. //---------------------------------------------------------------------------
  9691. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  9692. {
  9693. TManagedTerminal * ManagedTerminal =
  9694. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  9695. if (ManagedTerminal != NULL)
  9696. {
  9697. ManagedTerminal->DirectoryLoaded = Now();
  9698. }
  9699. }
  9700. //---------------------------------------------------------------------------
  9701. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  9702. TListItem * /*Item*/, bool /*Selected*/)
  9703. {
  9704. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  9705. switch (DirView->LastSelectMethod)
  9706. {
  9707. case smKeyboard:
  9708. Configuration->Usage->Inc(L"KeyboardSelections");
  9709. break;
  9710. case smMouse:
  9711. Configuration->Usage->Inc(L"MouseSelections");
  9712. break;
  9713. }
  9714. }
  9715. //---------------------------------------------------------------------------
  9716. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  9717. {
  9718. if (Color != 0)
  9719. {
  9720. return GetSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  9721. }
  9722. else
  9723. {
  9724. return FSessionTabImageIndex;
  9725. }
  9726. }
  9727. //---------------------------------------------------------------------------
  9728. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  9729. {
  9730. TPngImageCollectionItem * Item =
  9731. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  9732. FSessionColors->AddPng(Item->PngImage);
  9733. return FSessionColors->Count - 1;
  9734. }
  9735. //---------------------------------------------------------------------------
  9736. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  9737. {
  9738. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  9739. FNewRemoteTabTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewRemoteTabAction->ImageIndex);
  9740. FNewLocalTabTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewLocalTabAction->ImageIndex);
  9741. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  9742. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  9743. FLocalBrowserTabImageIndex = AddFixedSessionImage(LocalBrowserImageIndex);
  9744. }
  9745. //---------------------------------------------------------------------------
  9746. int TCustomScpExplorerForm::GetNewTabActionImageIndex()
  9747. {
  9748. return NonVisualDataModule->NewRemoteTabAction->ImageIndex;
  9749. }
  9750. //---------------------------------------------------------------------------
  9751. int TCustomScpExplorerForm::GetNewTabTabImageIndex(TOperationSide Side)
  9752. {
  9753. switch (Side)
  9754. {
  9755. case osLocal:
  9756. return FNewLocalTabTabImageIndex;
  9757. case osRemote:
  9758. case osCurrent:
  9759. return FNewRemoteTabTabImageIndex;
  9760. default:
  9761. DebugFail();
  9762. return -1;
  9763. }
  9764. }
  9765. //---------------------------------------------------------------------------
  9766. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  9767. {
  9768. for (int Index = 0; Index < Control->ControlCount; Index++)
  9769. {
  9770. TControl * AControl = Control->Controls[Index];
  9771. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  9772. if (WinControl != NULL)
  9773. {
  9774. CollectItemsWithTextDisplayMode(WinControl);
  9775. }
  9776. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  9777. if (Toolbar != NULL)
  9778. {
  9779. // we care for top-level items only
  9780. TTBCustomItem * Items = Toolbar->Items;
  9781. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  9782. {
  9783. TTBCustomItem * Item = Items->Items[ItemIndex];
  9784. if (((Item->DisplayMode == nbdmImageAndText) ||
  9785. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  9786. EligibleForImageDisplayMode(Item))
  9787. {
  9788. FItemsWithTextDisplayMode.insert(Item);
  9789. }
  9790. }
  9791. }
  9792. }
  9793. }
  9794. //---------------------------------------------------------------------------
  9795. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  9796. {
  9797. return true;
  9798. }
  9799. //---------------------------------------------------------------------------
  9800. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  9801. {
  9802. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  9803. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  9804. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  9805. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  9806. bool Result = true;
  9807. while (Result && (i != FItemsWithTextDisplayMode.end()))
  9808. {
  9809. TTBCustomItem * Item = *i;
  9810. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  9811. if (Label != NULL)
  9812. {
  9813. // optimization
  9814. if (Label->Visible == SelectiveToolbarText)
  9815. {
  9816. Result = false;
  9817. }
  9818. else
  9819. {
  9820. Label->Visible = SelectiveToolbarText;
  9821. }
  9822. }
  9823. else
  9824. {
  9825. // optimization
  9826. if (Item->DisplayMode == DisplayMode)
  9827. {
  9828. Result = false;
  9829. }
  9830. else
  9831. {
  9832. Item->DisplayMode = DisplayMode;
  9833. }
  9834. }
  9835. ++i;
  9836. }
  9837. UpdateNewTabTab();
  9838. return Result;
  9839. }
  9840. //---------------------------------------------------------------------------
  9841. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  9842. {
  9843. DebugFail();
  9844. }
  9845. //---------------------------------------------------------------------------
  9846. bool __fastcall TCustomScpExplorerForm::IsBusy()
  9847. {
  9848. // Among other, a lock level is non zero, while directory is being loaded,
  9849. // even when it happens as a result of dirview navigation,
  9850. // i.e. when TNonVisualDataModule is NOT FBusy.
  9851. // That's why the TNonVisualDataModule::GetBusy calls this method.
  9852. // Among other this prevents a panel auto update to occur while
  9853. // directory is changing.
  9854. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  9855. }
  9856. //---------------------------------------------------------------------------
  9857. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  9858. {
  9859. // While the window is disabled, we still seem to process menu shortcuts at least,
  9860. // so stop it at least here.
  9861. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  9862. bool Result;
  9863. if (Allowed == aaUpdate)
  9864. {
  9865. Result = true;
  9866. }
  9867. else
  9868. {
  9869. Result = !NonVisualDataModule->Busy;
  9870. if (Result && (Allowed == aaShortCut))
  9871. {
  9872. // Otherwise F5 for local-local will be swallowed by disabled local<>remote actions in TCustomScpExplorerForm::KeyDown
  9873. Action->Update();
  9874. Result = Action->Enabled;
  9875. }
  9876. }
  9877. return Result;
  9878. }
  9879. //---------------------------------------------------------------------------
  9880. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  9881. {
  9882. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  9883. }
  9884. //---------------------------------------------------------------------------
  9885. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  9886. {
  9887. // This is somewhat redundant to LockWindow() call from
  9888. // TTerminalManager::TerminalReadDirectoryProgress.
  9889. // But disabling window is known not to block keyboard shorcuts
  9890. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  9891. if (Busy > 0)
  9892. {
  9893. if (NonVisualDataModule->Busy)
  9894. {
  9895. State = false;
  9896. }
  9897. else
  9898. {
  9899. NonVisualDataModule->StartBusy();
  9900. // Will be countered for TCustomDirView.DoExecute in DoDirViewExecFile
  9901. LockWindow();
  9902. }
  9903. }
  9904. else if (Busy < 0)
  9905. {
  9906. UnlockWindow();
  9907. NonVisualDataModule->EndBusy();
  9908. }
  9909. else
  9910. {
  9911. State = NonVisualDataModule->Busy;
  9912. }
  9913. }
  9914. //---------------------------------------------------------------------------
  9915. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  9916. {
  9917. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  9918. if (Index >= 0)
  9919. {
  9920. TPopupMenu * PopupMenu = NULL;
  9921. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  9922. if (Session != NULL)
  9923. {
  9924. SessionsPageControl->ActivePageIndex = Index;
  9925. if (DebugAlwaysTrue(SessionTabSwitched()))
  9926. {
  9927. // copied from TControl.WMContextMenu
  9928. SendCancelMode(SessionsPageControl);
  9929. // explicit popup instead of using PopupMenu property
  9930. // to avoid menu to popup somewhere within SessionTabSwitched above,
  9931. // while connecting yet not-connected session and hence
  9932. // allowing an access to commands over not-completelly connected session
  9933. PopupMenu = Session->LocalBrowser ? NonVisualDataModule->LocalBrowserPopup : NonVisualDataModule->SessionsPopup;
  9934. }
  9935. }
  9936. else
  9937. {
  9938. if (SupportsLocalBrowser())
  9939. {
  9940. PopupMenu = NonVisualDataModule->NewTabPopup;
  9941. }
  9942. }
  9943. if (PopupMenu != NULL)
  9944. {
  9945. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  9946. PopupMenu->PopupComponent = SessionsPageControl;
  9947. PopupMenu->Popup(Point.x, Point.y);
  9948. }
  9949. }
  9950. Handled = true;
  9951. }
  9952. //---------------------------------------------------------------------------
  9953. bool __fastcall TCustomScpExplorerForm::CanChangePassword()
  9954. {
  9955. return HasActiveTerminal() && Terminal->IsCapable[fcChangePassword];
  9956. }
  9957. //---------------------------------------------------------------------------
  9958. void __fastcall TCustomScpExplorerForm::ChangePassword()
  9959. {
  9960. Configuration->Usage->Inc(L"PasswordChanges");
  9961. std::unique_ptr<TSessionData> ChangePasswordData(Terminal->SessionData->Clone());
  9962. ChangePasswordData->DisableAuthentationsExceptPassword();
  9963. ChangePasswordData->ChangePassword = true;
  9964. std::unique_ptr<TTerminal> ChangePasswordSession(
  9965. Terminal->CreateSecondarySession(L"ChangePassword", ChangePasswordData.get()));
  9966. ChangePasswordSession->AutoReadDirectory = false;
  9967. if (TTerminalManager::Instance()->ConnectTerminal(ChangePasswordSession.get()))
  9968. {
  9969. MessageDialog(MainInstructions(LoadStr(PASSWORD_CHANGED)), qtInformation, qaOK, HELP_CHANGE_PASSWORD);
  9970. }
  9971. else
  9972. {
  9973. Configuration->Usage->Inc(L"PasswordChangesFailed");
  9974. }
  9975. }
  9976. //---------------------------------------------------------------------------
  9977. bool __fastcall TCustomScpExplorerForm::CanPrivateKeyUpload()
  9978. {
  9979. // No nice way to assert SSH2
  9980. return HasActiveTerminal() && (Terminal->FSProtocol == cfsSFTP);
  9981. }
  9982. //---------------------------------------------------------------------------
  9983. void __fastcall TCustomScpExplorerForm::PrivateKeyUpload()
  9984. {
  9985. TOperationVisualizer OperationVisualizer;
  9986. UnicodeString FileName = Terminal->SessionData->PublicKeyFile;
  9987. TTerminalManager::Instance()->UploadPublicKey(Terminal, NULL, FileName);
  9988. }
  9989. //---------------------------------------------------------------------------
  9990. void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
  9991. {
  9992. TForm::ChangeScale(M, D);
  9993. int APixelsPerInch = GetControlPixelsPerInch(this);
  9994. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  9995. try
  9996. {
  9997. GlyphsModule->SetPixelsPerInch(APixelsPerInch);
  9998. }
  9999. __finally
  10000. {
  10001. GUIConfiguration->ChangeResourceModule(ResourceModule);
  10002. }
  10003. }
  10004. //---------------------------------------------------------------------------
  10005. void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
  10006. {
  10007. NonVisualDataModule->ControlContextPopup(Sender, MousePos);
  10008. }
  10009. //---------------------------------------------------------------------
  10010. class TPublicControl : public TControl
  10011. {
  10012. friend class TCustomScpExplorerForm;
  10013. };
  10014. //---------------------------------------------------------------------------
  10015. void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
  10016. {
  10017. static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
  10018. static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
  10019. }
  10020. //---------------------------------------------------------------------------
  10021. void __fastcall TCustomScpExplorerForm::DoBookmarkClick(TOperationSide Side, TObject * Sender)
  10022. {
  10023. TBookmark * Bookmark = DebugNotNull(reinterpret_cast<TBookmark *>(dynamic_cast<TTBCustomItem *>(Sender)->Tag));
  10024. OpenBookmark(Side, Bookmark);
  10025. }
  10026. //---------------------------------------------------------------------------
  10027. void __fastcall TCustomScpExplorerForm::LocalBookmarkClick(TObject * Sender)
  10028. {
  10029. DoBookmarkClick(osLocal, Sender);
  10030. }
  10031. //---------------------------------------------------------------------------
  10032. void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
  10033. {
  10034. DoBookmarkClick(osRemote, Sender);
  10035. }
  10036. //---------------------------------------------------------------------------
  10037. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
  10038. TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
  10039. {
  10040. if (BookmarkList != NULL)
  10041. {
  10042. TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
  10043. if (IsLocalBrowserMode())
  10044. {
  10045. Side = osLocal;
  10046. }
  10047. if (!WinConfiguration->UseLocationProfiles)
  10048. {
  10049. std::unique_ptr<TStringList> Directories(new TStringList());
  10050. Directories->CaseSensitive = (Side == osRemote);
  10051. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10052. {
  10053. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10054. UnicodeString Directory = Bookmark->GetSideDirectory(Side);
  10055. if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
  10056. {
  10057. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  10058. Item->Caption = EscapeHotkey(Directory);
  10059. Item->ShortCut = Bookmark->ShortCut;
  10060. Item->OnClick = OnBookmarkClick;
  10061. Item->Tag = reinterpret_cast<int>(Bookmark);
  10062. Directories->Add(Directory);
  10063. Menu->Add(Item.release());
  10064. }
  10065. }
  10066. }
  10067. else
  10068. {
  10069. std::unique_ptr<TStrings> Folders(CreateSortedStringList());
  10070. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10071. {
  10072. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10073. if (!Bookmark->Node.IsEmpty())
  10074. {
  10075. Folders->Add(Bookmark->Node);
  10076. }
  10077. }
  10078. for (int Index = 0; Index < Folders->Count; Index++)
  10079. {
  10080. std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
  10081. Item->Caption = Folders->Strings[Index];
  10082. Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction2->ImageIndex;
  10083. Folders->Objects[Index] = Item.get();
  10084. Menu->Add(Item.release());
  10085. }
  10086. for (int Index = 0; Index < BookmarkList->Count; Index++)
  10087. {
  10088. TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
  10089. TTBCustomItem * Parent;
  10090. if (!Bookmark->Node.IsEmpty())
  10091. {
  10092. DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
  10093. Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
  10094. }
  10095. else
  10096. {
  10097. Parent = Menu;
  10098. }
  10099. std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
  10100. Item->Caption = Bookmark->Name;
  10101. Item->ShortCut = Bookmark->ShortCut;
  10102. Item->OnClick = OnBookmarkClick;
  10103. Item->Tag = reinterpret_cast<int>(Bookmark);
  10104. if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
  10105. (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
  10106. {
  10107. // No hint for location profiles that are actually mere "bookmarks"
  10108. }
  10109. else
  10110. {
  10111. UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
  10112. UnicodeString LongHint;
  10113. if (!Bookmark->Local.IsEmpty())
  10114. {
  10115. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
  10116. }
  10117. if (!Bookmark->Remote.IsEmpty())
  10118. {
  10119. AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
  10120. }
  10121. AddToList(Hint, LongHint, L"|");
  10122. Item->Hint = Hint;
  10123. }
  10124. Parent->Add(Item.release());
  10125. }
  10126. }
  10127. AddMenuSeparator(Menu);
  10128. }
  10129. }
  10130. //---------------------------------------------------------------------------
  10131. void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu, TOperationSide Side)
  10132. {
  10133. Menu->Clear();
  10134. std::unique_ptr<TTBCustomItem> Item;
  10135. Item.reset(new TTBXItem(Owner));
  10136. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalOpenDirAction : NonVisualDataModule->RemoteOpenDirAction;
  10137. Item->Options = Item->Options << tboDefault;
  10138. Menu->Add(Item.release());
  10139. AddMenuSeparator(Menu);
  10140. if (Terminal != NULL)
  10141. {
  10142. CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
  10143. }
  10144. CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
  10145. Item.reset(new TTBXItem(Owner));
  10146. Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction2 : NonVisualDataModule->RemoteAddBookmarkAction2;
  10147. Menu->Add(Item.release());
  10148. }
  10149. //---------------------------------------------------------------------------
  10150. bool __fastcall TCustomScpExplorerForm::TryOpenDirectory(TOperationSide Side, const UnicodeString & Path)
  10151. {
  10152. bool Result = true;
  10153. bool Remote = !IsSideLocalBrowser(Side);
  10154. try
  10155. {
  10156. if (Remote)
  10157. {
  10158. Terminal->ExceptionOnFail = true;
  10159. }
  10160. try
  10161. {
  10162. DirView(Side)->Path = Path;
  10163. }
  10164. __finally
  10165. {
  10166. if (Remote)
  10167. {
  10168. Terminal->ExceptionOnFail = false;
  10169. }
  10170. }
  10171. }
  10172. catch (Exception & E)
  10173. {
  10174. if (!Remote || Terminal->Active)
  10175. {
  10176. ShowExtendedExceptionEx(Terminal, &E);
  10177. Result = false;
  10178. }
  10179. else
  10180. {
  10181. throw;
  10182. }
  10183. }
  10184. return Result;
  10185. }
  10186. //---------------------------------------------------------------------------
  10187. void __fastcall TCustomScpExplorerForm::ReloadDirectory(TOperationSide Side)
  10188. {
  10189. // Make sure there some feedback even when loading tiny local folders
  10190. TInstantOperationVisualizer Visualizer;
  10191. DirView(Side)->ReloadDirectory();
  10192. }
  10193. //---------------------------------------------------------------------------
  10194. void __fastcall TCustomScpExplorerForm::CloseSessionTab(int Index)
  10195. {
  10196. if (Index == SessionsPageControl->TabIndex)
  10197. {
  10198. CloseSession();
  10199. }
  10200. else
  10201. {
  10202. TTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  10203. TTerminal * Terminal = GetSessionTabSession(TabSheet);
  10204. TTerminalManager * Manager = TTerminalManager::Instance();
  10205. if (!Terminal->Active)
  10206. {
  10207. Manager->FreeTerminal(Terminal);
  10208. }
  10209. else
  10210. {
  10211. TTerminalQueue * Queue = Manager->FindQueueForTerminal(Terminal);
  10212. if (CanCloseQueue(Queue))
  10213. {
  10214. Manager->FreeTerminal(Terminal);
  10215. }
  10216. }
  10217. }
  10218. }
  10219. //---------------------------------------------------------------------------
  10220. void __fastcall TCustomScpExplorerForm::SessionsPageControlTabButtonClick(TPageControl *, int Index)
  10221. {
  10222. TManagedTerminal * Session = GetSessionTabSession(SessionsPageControl->Pages[Index]);
  10223. if (Session == NULL)
  10224. {
  10225. TRect ButtonRect = SessionsPageControl->TabButtonRect(Index);
  10226. ButtonRect = TRect(SessionsPageControl->ClientToScreen(ButtonRect.TopLeft()), SessionsPageControl->ClientToScreen(ButtonRect.BottomRight()));
  10227. //TPoint P = TPoint(ButtonRect.Left, ButtonRect.Bottom);
  10228. //P = SessionsPageControl->ClientToScreen(P);
  10229. MenuPopup(NonVisualDataModule->NewTabPopup, ButtonRect, SessionsPageControl);
  10230. }
  10231. else
  10232. {
  10233. CloseSessionTab(Index);
  10234. }
  10235. }
  10236. //---------------------------------------------------------------------------
  10237. void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  10238. {
  10239. if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
  10240. {
  10241. TInstantOperationVisualizer Visualizer;
  10242. // To trigger ClipboardDataObjectRelease (in case the clipboard already contains our data)
  10243. // before we create a new data object
  10244. ClipboardClear();
  10245. DebugAssert(FClipboardFakeDirectory.IsEmpty());
  10246. DebugAssert(FClipboardFakeMonitors.get() == NULL);
  10247. FClipboardFakeDirectory = CreateFakeTransferDirectory();
  10248. // Intermediate variable to WORKAROUND a crash in compiler
  10249. TObjectList * ClipboardFakeMonitors =
  10250. StartCreationDirectoryMonitorsOnEachDrive(FILE_NOTIFY_CHANGE_DIR_NAME, ClipboardFakeCreated);
  10251. FClipboardFakeMonitors.reset(ClipboardFakeMonitors);
  10252. if (FClipboardDragDropFilesEx.get() == NULL)
  10253. {
  10254. FClipboardDragDropFilesEx.reset(new TDragDropFilesEx(this));
  10255. FClipboardDragDropFilesEx->OnDataObjectRelease = ClipboardDataObjectRelease;
  10256. }
  10257. FClipboardDragDropFilesEx->FileList->Clear();
  10258. FClipboardDragDropFilesEx->FileList->AddItem(NULL, FClipboardFakeDirectory);
  10259. FClipboardDragDropFilesEx->CopyToClipboard();
  10260. FClipboardTerminal = Terminal;
  10261. // Need full paths, as cwd can be different once files are pasted
  10262. FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
  10263. for (int Index = 0; Index < FClipboardFileList->Count; Index++)
  10264. {
  10265. FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
  10266. }
  10267. }
  10268. }
  10269. //---------------------------------------------------------------------------
  10270. void __fastcall TCustomScpExplorerForm::ClipboardClear()
  10271. {
  10272. if (OpenClipboard(0))
  10273. {
  10274. EmptyClipboard(); // Calls ClipboardDataObjectRelease, if clipboard contains our data
  10275. CloseClipboard();
  10276. }
  10277. }
  10278. //---------------------------------------------------------------------------
  10279. bool __fastcall TCustomScpExplorerForm::DoesClipboardContainOurFiles()
  10280. {
  10281. return !FClipboardFakeDirectory.IsEmpty();
  10282. }
  10283. //---------------------------------------------------------------------------
  10284. void __fastcall TCustomScpExplorerForm::ClipboardStop()
  10285. {
  10286. RemoveDir(ApiPath(FClipboardFakeDirectory));
  10287. FClipboardFakeDirectory = UnicodeString();
  10288. FClipboardTerminal = NULL;
  10289. // Also called in Idle()
  10290. FClipboardFakeMonitors.reset(NULL);
  10291. }
  10292. //---------------------------------------------------------------------------
  10293. void __fastcall TCustomScpExplorerForm::ClipboardDataObjectRelease(TObject * /*Sender*/)
  10294. {
  10295. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()))
  10296. {
  10297. ClipboardStop();
  10298. }
  10299. }
  10300. //---------------------------------------------------------------------------
  10301. void __fastcall TCustomScpExplorerForm::ClipboardDownload(const UnicodeString & TargetDirectory, bool NoConfirmation, bool DragDrop)
  10302. {
  10303. TTerminalManager * Manager = TTerminalManager::Instance();
  10304. Manager->ActiveSession = FClipboardTerminal;
  10305. TTransferOperationParam Params;
  10306. Params.TargetDirectory = TargetDirectory;
  10307. Params.DragDrop = DragDrop;
  10308. ExecuteFileOperation(foCopy, osRemote, FClipboardFileList.get(), NoConfirmation, &Params);
  10309. }
  10310. //---------------------------------------------------------------------------
  10311. void __fastcall TCustomScpExplorerForm::ClipboardFakeCreated(TObject * /*Sender*/, const UnicodeString FileName)
  10312. {
  10313. // It can actually rarelly happen that some random file is created, while we are shuttting down the monitor
  10314. // (as it pumps a Windows message queue while being shutted down)
  10315. if (DebugAlwaysTrue(!FClipboardFakeDirectory.IsEmpty()) &&
  10316. SameText(ExtractFileName(FileName), ExtractFileName(FClipboardFakeDirectory)))
  10317. {
  10318. // Can fail as it can be e.g. locked by AV, so we retry that later
  10319. bool Removed = RemoveDir(ApiPath(FileName));
  10320. try
  10321. {
  10322. if (!NonVisualDataModule->Busy)
  10323. {
  10324. bool NoConfirmation = (WinConfiguration->DDTransferConfirmation == asOff);
  10325. ClipboardDownload(ExtractFilePath(FileName), NoConfirmation, true);
  10326. }
  10327. }
  10328. __finally
  10329. {
  10330. if (!Removed)
  10331. {
  10332. RemoveDir(ApiPath(FileName));
  10333. }
  10334. }
  10335. }
  10336. }
  10337. //---------------------------------------------------------------------------
  10338. void __fastcall TCustomScpExplorerForm::DirViewGetItemColor(
  10339. TObject * Sender, UnicodeString FileName, bool Directory, __int64 Size, TDateTime Modification, TColor & Color)
  10340. {
  10341. TFileMasks::TParams MaskParams;
  10342. MaskParams.Size = Size;
  10343. MaskParams.Modification = Modification;
  10344. TCustomDirView * DirView = DebugNotNull(dynamic_cast<TCustomDirView *>(Sender));
  10345. for (TFileColorData::TList::const_iterator Iter = FFileColors.begin(); Iter != FFileColors.end(); Iter++)
  10346. {
  10347. bool ImplicitMatch;
  10348. if (Iter->FileMask.Matches(FileName, Directory, DirView->PathName, &MaskParams, false, ImplicitMatch) &&
  10349. !ImplicitMatch)
  10350. {
  10351. Color = Iter->Color;
  10352. break;
  10353. }
  10354. }
  10355. }
  10356. //---------------------------------------------------------------------------
  10357. void __fastcall TCustomScpExplorerForm::DirViewKeyDown(TObject * Sender, WORD & Key, TShiftState)
  10358. {
  10359. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10360. if (!DirView->IsEditing())
  10361. {
  10362. // Handled here, instead of RemoteDirViewKeyPress (as on Login dialog),
  10363. // as VK_BACK is handled by TCustomDirView.KeyDown and we can swallow it here,
  10364. // while searching
  10365. if (Key == VK_BACK)
  10366. {
  10367. if (!FIncrementalSearch.IsEmpty())
  10368. {
  10369. if (FIncrementalSearch.Length() == 1)
  10370. {
  10371. ResetIncrementalSearch();
  10372. }
  10373. else
  10374. {
  10375. UnicodeString NewText = FIncrementalSearch.SubString(1, FIncrementalSearch.Length() - 1);
  10376. IncrementalSearch(NewText, false, false);
  10377. }
  10378. Key = 0;
  10379. }
  10380. }
  10381. }
  10382. }
  10383. //---------------------------------------------------------------------------
  10384. void __fastcall TCustomScpExplorerForm::DirViewKeyPress(TObject * Sender, wchar_t & Key)
  10385. {
  10386. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  10387. if (!DirView->IsEditing() && (WinConfiguration->PanelSearch != isOff))
  10388. {
  10389. // Filter control sequences.
  10390. // When not searching yet, prefer use of the space for toggling file selection
  10391. // (so we cannot incrementally search for a string starting with a space).
  10392. if ((Key > VK_SPACE) ||
  10393. ((Key == VK_SPACE) && (GetKeyState(VK_CONTROL) >= 0) && !FIncrementalSearch.IsEmpty()))
  10394. {
  10395. IncrementalSearch(FIncrementalSearch + Key, false, false);
  10396. Key = 0;
  10397. }
  10398. }
  10399. }
  10400. //---------------------------------------------------------------------------
  10401. void __fastcall TCustomScpExplorerForm::ResetIncrementalSearch()
  10402. {
  10403. if (!FIncrementalSearch.IsEmpty())
  10404. {
  10405. FIncrementalSearch = L"";
  10406. DirView(osCurrent)->UpdateStatusBar();
  10407. }
  10408. }
  10409. //---------------------------------------------------------------------------
  10410. void __fastcall TCustomScpExplorerForm::IncrementalSearch(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10411. {
  10412. TListItem * Item = SearchFile(Text, SkipCurrent, Reverse);
  10413. if (Item == NULL)
  10414. {
  10415. MessageBeep(MB_ICONHAND);
  10416. }
  10417. else
  10418. {
  10419. TCustomDirView * ADirView = DirView(osCurrent);
  10420. {
  10421. TAutoNestingCounter Guard(FIncrementalSearching);
  10422. ADirView->FocusItem(Item);
  10423. if (ADirView->NortonLike == nlOff)
  10424. {
  10425. if ((ADirView->Selected != Item) ||
  10426. (ADirView->SelCount > 1))
  10427. {
  10428. ADirView->ClearSelection();
  10429. ADirView->Selected = Item;
  10430. }
  10431. }
  10432. }
  10433. FIncrementalSearch = Text;
  10434. Item->MakeVisible(false);
  10435. TListItem * NextItem = SearchFile(Text, true, Reverse);
  10436. FIncrementalSearchHaveNext = (NextItem != NULL) && (NextItem != Item);
  10437. ADirView->UpdateStatusBar();
  10438. }
  10439. }
  10440. //---------------------------------------------------------------------------
  10441. TListItem * __fastcall TCustomScpExplorerForm::GetNextFile(TListItem * Item, bool Reverse)
  10442. {
  10443. int Index = Item->Index;
  10444. if (!Reverse)
  10445. {
  10446. Index++;
  10447. if (Index >= Item->Owner->Count)
  10448. {
  10449. Index = 0;
  10450. }
  10451. }
  10452. else
  10453. {
  10454. Index--;
  10455. if (Index < 0)
  10456. {
  10457. Index = Item->Owner->Count - 1;
  10458. }
  10459. }
  10460. return Item->Owner->Item[Index];
  10461. }
  10462. //---------------------------------------------------------------------------
  10463. TListItem * __fastcall TCustomScpExplorerForm::SearchFile(const UnicodeString & Text, bool SkipCurrent, bool Reverse)
  10464. {
  10465. TCustomDirView * ADirView = DirView(osCurrent);
  10466. if (ADirView->Items->Count == 0)
  10467. {
  10468. return NULL;
  10469. }
  10470. else
  10471. {
  10472. TListItem * CurrentItem = (ADirView->ItemFocused != NULL) ? ADirView->ItemFocused : ADirView->Items->Item[0];
  10473. TListItem * Item = CurrentItem;
  10474. if (SkipCurrent)
  10475. {
  10476. Item = DebugNotNull(GetNextFile(Item, Reverse));
  10477. }
  10478. while (true)
  10479. {
  10480. bool Matches = false;
  10481. switch (WinConfiguration->PanelSearch)
  10482. {
  10483. case isNameStartOnly:
  10484. Matches = ContainsTextSemiCaseSensitive(Item->Caption.SubString(1, Text.Length()), Text);
  10485. break;
  10486. case isName:
  10487. Matches = ContainsTextSemiCaseSensitive(Item->Caption, Text);
  10488. break;
  10489. case isAll:
  10490. int ColCount = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Count : 1;
  10491. int Index = 0;
  10492. while ((Index < ColCount) && !Matches)
  10493. {
  10494. bool Visible = (ADirView->ViewStyle == vsReport) ? ADirView->ColProperties->Visible[Index] : true;
  10495. if (Visible)
  10496. {
  10497. Matches = ContainsTextSemiCaseSensitive(ADirView->GetColumnText(Item, Index), Text);
  10498. }
  10499. Index++;
  10500. }
  10501. break;
  10502. }
  10503. if (Matches)
  10504. {
  10505. return Item;
  10506. }
  10507. Item = GetNextFile(Item, Reverse);
  10508. if (Item == CurrentItem)
  10509. {
  10510. return NULL;
  10511. }
  10512. }
  10513. }
  10514. }
  10515. //---------------------------------------------------------------------------
  10516. void __fastcall TCustomScpExplorerForm::DirViewExit(TObject *)
  10517. {
  10518. ResetIncrementalSearch();
  10519. }
  10520. //---------------------------------------------------------------------------
  10521. void __fastcall TCustomScpExplorerForm::CMDialogKey(TWMKeyDown & Message)
  10522. {
  10523. if (Message.CharCode == VK_TAB)
  10524. {
  10525. if (!FIncrementalSearch.IsEmpty())
  10526. {
  10527. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  10528. bool Reverse = Shift.Contains(ssShift);
  10529. IncrementalSearch(FIncrementalSearch, true, Reverse);
  10530. Message.Result = 1;
  10531. return;
  10532. }
  10533. }
  10534. else if (Message.CharCode == VK_ESCAPE)
  10535. {
  10536. if (!FIncrementalSearch.IsEmpty())
  10537. {
  10538. ResetIncrementalSearch();
  10539. Message.Result = 1;
  10540. return;
  10541. }
  10542. }
  10543. TForm::Dispatch(&Message);
  10544. }
  10545. //---------------------------------------------------------------------------
  10546. void __fastcall TCustomScpExplorerForm::Deactivate()
  10547. {
  10548. TForm::Deactivate();
  10549. // E.g. when switching to an internal editor window
  10550. ResetIncrementalSearch();
  10551. }
  10552. //---------------------------------------------------------------------------
  10553. void __fastcall TCustomScpExplorerForm::ApplicationEventsDeactivate(TObject *)
  10554. {
  10555. // When switching to another application
  10556. ResetIncrementalSearch();
  10557. }
  10558. //---------------------------------------------------------------------------
  10559. void __fastcall TCustomScpExplorerForm::ApplicationEventsModalBegin(TObject *)
  10560. {
  10561. ResetIncrementalSearch();
  10562. }
  10563. //---------------------------------------------------------------------------
  10564. void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem *)
  10565. {
  10566. if (FIncrementalSearching <= 0)
  10567. {
  10568. ResetIncrementalSearch();
  10569. }
  10570. }
  10571. //---------------------------------------------------------------------------
  10572. void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
  10573. {
  10574. CountClicksForWindowPrint(this);
  10575. }
  10576. //---------------------------------------------------------------------------
  10577. void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
  10578. {
  10579. CenterReconnectToolbar();
  10580. }
  10581. //---------------------------------------------------------------------------
  10582. void __fastcall TCustomScpExplorerForm::BrowseFile()
  10583. {
  10584. if (RemoteDirView->ItemFocused != NULL)
  10585. {
  10586. RemoteDirView->ItemFocused->Selected = true;
  10587. }
  10588. }
  10589. //---------------------------------------------------------------------------
  10590. void __fastcall TCustomScpExplorerForm::UpdateQueueFileList()
  10591. {
  10592. if (!FQueueStatusUpdating)
  10593. {
  10594. bool Refresh;
  10595. if ((FQueueStatus != NULL) && QueueFileList->Visible)
  10596. {
  10597. Refresh = FQueueStatus->UpdateFileList(FQueueController->GetFocusedPrimaryItem(), FQueueFileList.get());
  10598. }
  10599. else
  10600. {
  10601. if (FQueueFileList->GetCount() > 0)
  10602. {
  10603. FQueueFileList->Clear();
  10604. Refresh = true;
  10605. }
  10606. }
  10607. int Count = FQueueFileList->GetCount();
  10608. if (QueueFileList->Items->Count != Count)
  10609. {
  10610. DebugAssert(Refresh);
  10611. QueueFileList->Items->Count = Count;
  10612. }
  10613. if (Refresh)
  10614. {
  10615. QueueFileList->Invalidate();
  10616. }
  10617. DebugAssert(QueueFileList->Items->Count == FQueueFileList->GetCount());
  10618. }
  10619. }
  10620. //---------------------------------------------------------------------------
  10621. void __fastcall TCustomScpExplorerForm::QueueFileListData(TObject *, TListItem * Item)
  10622. {
  10623. Item->Caption = FQueueFileList->GetFileName(Item->Index);
  10624. }
  10625. //---------------------------------------------------------------------------
  10626. void __fastcall TCustomScpExplorerForm::QueueView3Change(TObject *, TListItem *, TItemChange)
  10627. {
  10628. // Should be improved, once we do not refresh the list when switching between details of the same batch.
  10629. // See TSynchronizeChecklistDialog::UpdateTimer
  10630. if (QueueFileList->Items->Count > 0)
  10631. {
  10632. QueueFileList->Items->Item[0]->MakeVisible(false);
  10633. }
  10634. UpdateQueueFileList();
  10635. }
  10636. //---------------------------------------------------------------------------
  10637. void __fastcall TCustomScpExplorerForm::QueueLabelGetStatus(TCustomPathLabel *, bool & Active)
  10638. {
  10639. Active = QueueView3->Focused() || QueueFileList->Focused();
  10640. }
  10641. //---------------------------------------------------------------------------
  10642. void __fastcall TCustomScpExplorerForm::QueueFileListEnterExit(TObject *)
  10643. {
  10644. QueueLabelUpdateStatus();
  10645. }
  10646. //---------------------------------------------------------------------------
  10647. void __fastcall TCustomScpExplorerForm::QueueFileListCustomDrawItem(
  10648. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  10649. {
  10650. int State = FQueueFileList->GetState(Item->Index);
  10651. if (State == qfsProcessed)
  10652. {
  10653. Sender->Canvas->Font->Color = clGrayText;
  10654. }
  10655. }
  10656. //---------------------------------------------------------------------------
  10657. void __fastcall TCustomScpExplorerForm::QueueFileListColumnAutoSize()
  10658. {
  10659. // We do not really need whole width, so we always preemptivelly keep free space for the vertical scrollbar
  10660. QueueFileList->Column[0]->Width =
  10661. QueueFileList->ClientWidth - GetSystemMetricsForControl(QueueFileList, SM_CXVSCROLL) - ScaleByTextHeight(QueueFileList, 8);
  10662. }
  10663. //---------------------------------------------------------------------------
  10664. void __fastcall TCustomScpExplorerForm::QueueFileListResize(TObject *)
  10665. {
  10666. QueueFileListColumnAutoSize();
  10667. }
  10668. //---------------------------------------------------------------------------
  10669. void __fastcall TCustomScpExplorerForm::CloseApp()
  10670. {
  10671. // Called from TNonVisualDataModule::ExplorerActionsExecute, which sets busy flag.
  10672. // FormCloseQuery must check busy state, so that the application cannot be closed while busy by Alt+F4 and X button.
  10673. // So we clear the flag here.
  10674. DebugAssert(NonVisualDataModule->Busy);
  10675. NonVisualDataModule->EndBusy();
  10676. try
  10677. {
  10678. Close();
  10679. }
  10680. __finally
  10681. {
  10682. NonVisualDataModule->StartBusy();
  10683. }
  10684. }
  10685. //---------------------------------------------------------------------------
  10686. bool __fastcall TCustomScpExplorerForm::IsActiveTerminal(TTerminal * Terminal)
  10687. {
  10688. return (Terminal != NULL) && Terminal->Active;
  10689. }
  10690. //---------------------------------------------------------------------------
  10691. bool __fastcall TCustomScpExplorerForm::HasManagedSession()
  10692. {
  10693. return (ManagedSession != NULL);
  10694. }
  10695. //---------------------------------------------------------------------------
  10696. bool __fastcall TCustomScpExplorerForm::HasActiveTerminal()
  10697. {
  10698. return IsActiveTerminal(Terminal);
  10699. }
  10700. //---------------------------------------------------------------------------
  10701. void TCustomScpExplorerForm::LocalLocalCopy(
  10702. TFileOperation, TOperationSide, bool DebugUsedArg(OnFocused), bool DebugUsedArg(NoConfirmation),
  10703. bool DebugUsedArg(DragDrop), unsigned int DebugUsedArg(Flags))
  10704. {
  10705. DebugFail();
  10706. }
  10707. //---------------------------------------------------------------------------
  10708. void TCustomScpExplorerForm::LocalLocalCopyCommand(TFileOperation Operation, TOperationSide Side, bool OnFocused, unsigned int Flags)
  10709. {
  10710. LocalLocalCopy(Operation, Side, OnFocused, !WinConfiguration->ConfirmTransferring, false, Flags);
  10711. }
  10712. //---------------------------------------------------------------------------
  10713. void __fastcall TCustomScpExplorerForm::SessionsPageControlResize(TObject *)
  10714. {
  10715. // Changing tab list triggers the OnResize.
  10716. if (!FUpdatingSessionTabs)
  10717. {
  10718. // UpdateTabsCaptionTruncation should be enough
  10719. SessionListChanged(true);
  10720. }
  10721. }
  10722. //---------------------------------------------------------------------------
  10723. UnicodeString TCustomScpExplorerForm::GetSessionPath(TManagedTerminal * ASession, TOperationSide Side)
  10724. {
  10725. if (ASession == ManagedSession)
  10726. {
  10727. UpdateSession(ASession);
  10728. }
  10729. TSessionData * Data = ASession->StateData;
  10730. UnicodeString Result;
  10731. if (Side == osLocal)
  10732. {
  10733. Result = Data->LocalDirectory;
  10734. }
  10735. else if (DebugAlwaysTrue(Side == osOther))
  10736. {
  10737. Result = ASession->LocalBrowser ? Data->OtherLocalDirectory : Data->RemoteDirectory;
  10738. }
  10739. return Result;
  10740. }
  10741. //---------------------------------------------------------------------------
  10742. UnicodeString TCustomScpExplorerForm::GetTabHintDetails(TManagedTerminal * ASession)
  10743. {
  10744. UnicodeString Result;
  10745. if (!ASession->Active)
  10746. {
  10747. Result = LoadStr(STATUS_NOT_CONNECTED2);
  10748. }
  10749. else
  10750. {
  10751. Result = GetSessionPath(ASession, osRemote);
  10752. }
  10753. return Result;
  10754. }
  10755. //---------------------------------------------------------------------------
  10756. UnicodeString TCustomScpExplorerForm::GetNewTabHintDetails()
  10757. {
  10758. return LoadStr(NEW_REMOTE_TAB_HINT);
  10759. }
  10760. //---------------------------------------------------------------------------
  10761. void __fastcall TCustomScpExplorerForm::SessionsPageControlTabHint(TPageControl *, int Index, UnicodeString & Hint)
  10762. {
  10763. if (Index >= 0)
  10764. {
  10765. TThemeTabSheet * TabSheet = SessionsPageControl->Pages[Index];
  10766. TManagedTerminal * TabSession = GetSessionTabSession(TabSheet);
  10767. if (TabSession == NULL)
  10768. {
  10769. UnicodeString NewTabTabCaption = GetNewTabTabCaption();
  10770. if (NewTabTabCaption != TabSheet->Caption)
  10771. {
  10772. Hint = NewTabTabCaption + L"|" + GetNewTabHintDetails();
  10773. }
  10774. }
  10775. else
  10776. {
  10777. TTerminalManager * Manager = TTerminalManager::Instance();
  10778. UnicodeString TabCaption = Manager->GetSessionTitle(TabSession, true);
  10779. Hint = TabCaption + L"|" + GetTabHintDetails(TabSession);
  10780. }
  10781. }
  10782. }
  10783. //---------------------------------------------------------------------------
  10784. typedef std::vector<TListItem *> TListItemsVector;
  10785. struct TCalculateSizeOperation
  10786. {
  10787. TCalculateSizeStats Stats;
  10788. TListItemsVector ListItems;
  10789. size_t Index;
  10790. };
  10791. //---------------------------------------------------------------------------
  10792. void TCustomScpExplorerForm::CalculateDirectorySizes()
  10793. {
  10794. TCalculateSizeOperation CalculateSizeOperation;
  10795. TOperationSide Side = GetSide(osCurrent);
  10796. TCustomDirView * ADirView = DirView(Side);
  10797. bool FullPath = IsSideLocalBrowser(Side);
  10798. std::unique_ptr<TStrings> AllFileList(ADirView->CreateFileList(false, FullPath, NULL, true));
  10799. std::unique_ptr<TStrings> FileList(new TStringList());
  10800. for (int Index = 0; Index < AllFileList->Count; Index++)
  10801. {
  10802. TListItem * Item = DebugNotNull(dynamic_cast<TListItem *>(AllFileList->Objects[Index]));
  10803. if (ADirView->ItemIsDirectory(Item))
  10804. {
  10805. FileList->AddObject(AllFileList->Strings[Index], ADirView->ItemData(Item));
  10806. CalculateSizeOperation.ListItems.push_back(Item);
  10807. }
  10808. }
  10809. CalculateSizeOperation.Index = 0;
  10810. __int64 Size = 0;
  10811. TValueRestorer<TCalculateSizeOperation *> DirectorySizeOperationRestorer(FCalculateSizeOperation);
  10812. FCalculateSizeOperation = &CalculateSizeOperation;
  10813. TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
  10814. FOnFileOperationFinished = DirectorySizeCalculated;
  10815. TValueRestorer<TFileOperation> PrimaryOperationRestorer(FPrimaryOperation);
  10816. FPrimaryOperation = foCalculateSize;
  10817. TCalculatedSizes CalculatedSizes;
  10818. CalculateSizeOperation.Stats.CalculatedSizes = &CalculatedSizes;
  10819. if (Side == osLocal)
  10820. {
  10821. Terminal->CalculateLocalFilesSize(FileList.get(), Size, NULL, true, NULL, &CalculatedSizes);
  10822. }
  10823. else
  10824. {
  10825. TCalculateSizeParams Params;
  10826. Params.Stats = &CalculateSizeOperation.Stats;
  10827. Params.UseCache = true;
  10828. Terminal->CalculateFilesSize(FileList.get(), Size, Params);
  10829. }
  10830. }
  10831. //---------------------------------------------------------------------------
  10832. void __fastcall TCustomScpExplorerForm::DirectorySizeCalculated(TOperationSide Side, const UnicodeString & FileName, bool)
  10833. {
  10834. DebugAlwaysTrue(FCalculateSizeOperation != NULL);
  10835. TListItem * Item = VisualiseOperationFinished(Side, FileName, false);
  10836. TCustomDirView * ADirView = dynamic_cast<TCustomDirView *>(Item->Owner->Owner);
  10837. // optimization
  10838. bool GotExpectedItem =
  10839. (FCalculateSizeOperation->Index < FCalculateSizeOperation->ListItems.size()) &&
  10840. (FCalculateSizeOperation->ListItems[FCalculateSizeOperation->Index] == Item);
  10841. int Index = -1;
  10842. if (DebugAlwaysTrue(GotExpectedItem))
  10843. {
  10844. Index = FCalculateSizeOperation->Index;
  10845. FCalculateSizeOperation->Index++;
  10846. }
  10847. else
  10848. {
  10849. TListItemsVector::iterator I =
  10850. std::find(FCalculateSizeOperation->ListItems.begin(), FCalculateSizeOperation->ListItems.end(), Item);
  10851. if (DebugAlwaysTrue(I != FCalculateSizeOperation->ListItems.end()))
  10852. {
  10853. Index = I - FCalculateSizeOperation->ListItems.begin();
  10854. }
  10855. }
  10856. if (DebugAlwaysTrue(Index >= 0))
  10857. {
  10858. __int64 Size = (*FCalculateSizeOperation->Stats.CalculatedSizes)[Index];
  10859. ADirView->SetItemCalculatedSize(Item, Size);
  10860. }
  10861. }