1
0

CustomScpExplorer.cpp 293 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115
  1. //---------------------------------------------------------------------------
  2. #define NO_WIN32_LEAN_AND_MEAN
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <Common.h>
  6. #include "CustomScpExplorer.h"
  7. #include <Bookmarks.h>
  8. #include <Interface.h>
  9. #include <Exceptions.h>
  10. #include <CoreMain.h>
  11. #include <FileSystems.h>
  12. #include <TextsCore.h>
  13. #include <TextsWin.h>
  14. #include <HelpWin.h>
  15. #include <VCLCommon.h>
  16. #include <Log.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. //---------------------------------------------------------------------------
  34. #pragma package(smart_init)
  35. #pragma link "CustomDirView"
  36. #pragma link "CustomUnixDirView"
  37. #pragma link "IEListView"
  38. #pragma link "NortonLikeListView"
  39. #pragma link "UnixDirView"
  40. #pragma link "CustomDriveView"
  41. #pragma link "UnixDriveView"
  42. #pragma link "CustomDriveView"
  43. #pragma link "TB2Dock"
  44. #pragma link "TBXStatusBars"
  45. #pragma link "TB2Item"
  46. #pragma link "TB2Toolbar"
  47. #pragma link "ThemePageControl"
  48. #pragma link "PathLabel"
  49. #ifndef NO_RESOURCES
  50. #pragma resource "*.dfm"
  51. #endif
  52. //---------------------------------------------------------------------------
  53. #define SAVE_SELECTION(DIRVIEW) \
  54. UnicodeString FocusFile = L""; \
  55. UnicodeString LastFocusedFile = L""; \
  56. if (DIRVIEW->ItemFocused) LastFocusedFile = DIRVIEW->ItemFocused->Caption; \
  57. { TListItem * ClosestUnselected = DIRVIEW->ClosestUnselected(DIRVIEW->ItemFocused); \
  58. if (ClosestUnselected) FocusFile = ClosestUnselected->Caption; }
  59. #define RESTORE_SELECTION(DIRVIEW) \
  60. if (!LastFocusedFile.IsEmpty() && \
  61. (!DIRVIEW->ItemFocused || (DIRVIEW->ItemFocused->Caption != LastFocusedFile))) \
  62. { \
  63. TListItem *ItemToSelect = DIRVIEW->FindFileItem(FocusFile); \
  64. if (ItemToSelect) \
  65. { \
  66. DIRVIEW->ItemFocused = ItemToSelect; \
  67. DIRVIEW->ItemFocused->MakeVisible(False); \
  68. } \
  69. }
  70. //---------------------------------------------------------------------------
  71. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  72. static const int SessionPanelCount = 4;
  73. //---------------------------------------------------------------------------
  74. class TMutexGuard
  75. {
  76. public:
  77. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  78. int Timeout = 5000)
  79. {
  80. FMutex = NULL;
  81. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  82. if (WaitResult == WAIT_TIMEOUT)
  83. {
  84. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  85. }
  86. else
  87. {
  88. FMutex = AMutex;
  89. }
  90. }
  91. ~TMutexGuard()
  92. {
  93. if (FMutex != NULL)
  94. {
  95. ReleaseMutex(FMutex);
  96. }
  97. }
  98. private:
  99. HANDLE FMutex;
  100. };
  101. //---------------------------------------------------------------------------
  102. class TWindowLock
  103. {
  104. public:
  105. TWindowLock(TCustomScpExplorerForm * Form) :
  106. FForm(Form)
  107. {
  108. FForm->LockWindow();
  109. }
  110. ~TWindowLock()
  111. {
  112. FForm->UnlockWindow();
  113. }
  114. private:
  115. TCustomScpExplorerForm * FForm;
  116. };
  117. //---------------------------------------------------------------------------
  118. struct TTransferOperationParam
  119. {
  120. TTransferOperationParam();
  121. UnicodeString TargetDirectory;
  122. bool Temp;
  123. bool DragDrop;
  124. int Options;
  125. TAutoSwitch Queue;
  126. };
  127. //---------------------------------------------------------------------------
  128. TTransferOperationParam::TTransferOperationParam()
  129. {
  130. Temp = false;
  131. DragDrop = false;
  132. Options = 0;
  133. Queue = asAuto;
  134. }
  135. //---------------------------------------------------------------------------
  136. class TTransferPresetNoteData : public TObject
  137. {
  138. public:
  139. UnicodeString Message;
  140. };
  141. //---------------------------------------------------------------------------
  142. class TTerminalNoteData : public TObject
  143. {
  144. public:
  145. TTerminal * Terminal;
  146. };
  147. //---------------------------------------------------------------------------
  148. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  149. FFormRestored(false),
  150. TForm(Owner)
  151. {
  152. FCurrentSide = osRemote;
  153. FEverShown = false;
  154. FDocks = new TList();
  155. RestoreParams();
  156. ConfigurationChanged();
  157. RemoteDirView->Invalidate();
  158. DebugAssert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  159. NonVisualDataModule->ScpExplorer = this;
  160. FAutoOperation = false;
  161. FOnFileOperationFinished = NULL;
  162. FForceExecution = false;
  163. FIgnoreNextDialogChar = 0;
  164. FErrorList = NULL;
  165. FSynchronizeProgressForm = NULL;
  166. FProgressForm = NULL;
  167. FRefreshLocalDirectory = false;
  168. FRefreshRemoteDirectory = false;
  169. FDDMoveSlipped = false;
  170. FDDExtMapFile = NULL;
  171. // CreateMutexW keeps failing with ERROR_NOACCESS
  172. FDDExtMutex = CreateMutexA(NULL, false, AnsiString(DRAG_EXT_MUTEX).c_str());
  173. DebugAssert(FDDExtMutex != NULL);
  174. FDDTargetControl = NULL;
  175. FDelayedDeletionTimer = NULL;
  176. FDelayedDeletionList = new TStringList();
  177. FDDFileList = NULL;
  178. FPendingTempSpaceWarn = false;
  179. FCapturedLog = NULL;
  180. FDragDropOperation = false;
  181. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  182. FAllowTransferPresetAutoSelect = true;
  183. FCopyParamDefault = L"";
  184. FSynchronizeController = NULL;
  185. FPendingQueueActionItem = NULL;
  186. FLockLevel = 0;
  187. FLockSuspendLevel = 0;
  188. FDisabledOnLockSuspend = false;
  189. FAlternativeDelete = false;
  190. FTrayIcon = new ::TTrayIcon(0);
  191. FTrayIcon->OnClick = TrayIconClick;
  192. FMaxQueueLength = 0;
  193. FLastContextPopupScreenPoint = TPoint(-1, -1);
  194. FTransferResumeList = NULL;
  195. FMoveToQueue = false;
  196. FStandaloneEditing = false;
  197. FOnFeedSynchronizeError = NULL;
  198. FNeedSession = false;
  199. FEditorManager = new TEditorManager();
  200. FEditorManager->OnFileChange = ExecutedFileChanged;
  201. FEditorManager->OnFileReload = ExecutedFileReload;
  202. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  203. FEditorManager->OnFileUploadComplete = ExecutedFileUploadComplete;
  204. FLocalEditors = new TList();
  205. FQueueStatus = NULL;
  206. FQueueStatusSection = new TCriticalSection();
  207. FQueueStatusInvalidated = false;
  208. FQueueItemInvalidated = false;
  209. FQueueActedItem = NULL;
  210. FQueueController = new TQueueController(QueueView3);
  211. FUserActionTimer = new TTimer(this);
  212. FUserActionTimer->Enabled = false;
  213. FUserActionTimer->Interval = 10;
  214. FUserActionTimer->OnTimer = UserActionTimer;
  215. FNotes = new TStringList();
  216. FNoteTimer = new TTimer(this);
  217. FNoteTimer->Enabled = false;
  218. FNoteTimer->OnTimer = NoteTimer;
  219. FOnNoteClick = NULL;
  220. FOle32Library = LoadLibrary(L"Ole32.dll");
  221. FDragMoveCursor = FOle32Library != NULL ?
  222. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  223. UseSystemSettings(this);
  224. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  225. static_cast<TObject*>(GetComponent(fcTransferList)));
  226. DebugAssert(TransferList != NULL);
  227. FTransferListHoverIndex = -1;
  228. TransferList->OnChange = TransferListChange;
  229. TransferList->OnDrawItem = TransferListDrawItem;
  230. SetSubmenu(dynamic_cast<TTBXCustomItem *>(static_cast<TObject *>(GetComponent(fcColorMenu))));
  231. SetSubmenu(NonVisualDataModule->ColorMenuItem);
  232. UseDesktopFont(SessionsPageControl);
  233. UpdateSessionsPageControlHeight();
  234. UseDesktopFont(RemoteDirView);
  235. UseDesktopFont(RemoteDriveView);
  236. UseDesktopFont(QueueView3);
  237. UseDesktopFont(QueueLabel);
  238. UseDesktopFont(RemoteStatusBar);
  239. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  240. QueueSplitter->ShowHint = true;
  241. RemotePanelSplitter->ShowHint = true;
  242. FSystemImageList = SharedSystemImageList(false);
  243. FSystemImageList->DrawingStyle = dsTransparent;
  244. FCustomCommandMenu = CreateTBXPopupMenu(this);
  245. FCustomCommandLocalFileList = NULL;
  246. FCustomCommandRemoteFileList = NULL;
  247. FSessionColors = new TPngImageList(this);
  248. FSessionColors->SetSize(GlyphsModule->ExplorerImages->Width, GlyphsModule->ExplorerImages->Height);
  249. FSessionColors->ColorDepth = cd32Bit;
  250. AddFixedSessionImages();
  251. SessionsPageControl->Images = FSessionColors;
  252. QueueLabel->FocusControl = QueueView3;
  253. UpdateQueueLabel();
  254. FRemoteDirViewWasFocused = true;
  255. CreateHiddenWindow();
  256. StartUpdates();
  257. }
  258. //---------------------------------------------------------------------------
  259. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  260. {
  261. // this has to be one of the very first things to do
  262. StopUpdateThread();
  263. SessionsPageControl->Images = NULL;
  264. SAFE_DESTROY(FSessionColors);
  265. SAFE_DESTROY(FSessionsDragDropFilesEx);
  266. delete FCustomCommandLocalFileList;
  267. delete FCustomCommandRemoteFileList;
  268. delete FCustomCommandMenu;
  269. delete FSystemImageList;
  270. FSystemImageList = NULL;
  271. delete FTrayIcon;
  272. FTrayIcon = NULL;
  273. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  274. delete FEditorManager;
  275. ForceCloseLocalEditors();
  276. delete FLocalEditors;
  277. HideFileFindDialog();
  278. if (FDelayedDeletionTimer)
  279. {
  280. DoDelayedDeletion(NULL);
  281. SAFE_DESTROY(FDelayedDeletionTimer);
  282. }
  283. SAFE_DESTROY(FDelayedDeletionList);
  284. // sometimes we do not get DDEnd so the list is not released
  285. SAFE_DESTROY(FDDFileList);
  286. DebugAssert(FSynchronizeController == NULL);
  287. CloseHandle(FDDExtMutex);
  288. FDDExtMutex = NULL;
  289. FreeLibrary(FOle32Library);
  290. FOle32Library = NULL;
  291. FDragMoveCursor = NULL;
  292. DebugAssert(!FErrorList);
  293. if (FEverShown)
  294. {
  295. // when window is never shown (like when running command-line operation),
  296. // particularly window site is not restored correctly (BoundsRect value set
  297. // in RestoreForm gets lost during handle allocation), so we do not want
  298. // it to be stored
  299. StoreParams();
  300. }
  301. Terminal = NULL;
  302. Queue = NULL;
  303. DebugAssert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  304. NonVisualDataModule->ScpExplorer = NULL;
  305. delete FQueueController;
  306. FQueueController = NULL;
  307. delete FQueueStatusSection;
  308. FQueueStatusSection = NULL;
  309. delete FQueueStatus;
  310. FQueueStatus = NULL;
  311. delete FUserActionTimer;
  312. FUserActionTimer = NULL;
  313. delete FNoteTimer;
  314. delete FNotes;
  315. delete FNoteData;
  316. SAFE_DESTROY(FDocks);
  317. SAFE_DESTROY(FHistoryMenu[0][0]);
  318. SAFE_DESTROY(FHistoryMenu[0][1]);
  319. SAFE_DESTROY(FHistoryMenu[1][0]);
  320. SAFE_DESTROY(FHistoryMenu[1][1]);
  321. if (FHiddenWindow != NULL)
  322. {
  323. DestroyWindow(FHiddenWindow);
  324. FHiddenWindow = NULL;
  325. }
  326. }
  327. //---------------------------------------------------------------------------
  328. void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
  329. {
  330. std::unique_ptr<TSessionData> Data;
  331. if (!Session.IsEmpty())
  332. {
  333. bool DefaultsOnly;
  334. Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
  335. }
  336. TTerminalManager * Manager = TTerminalManager::Instance();
  337. for (int Index = 0; Index < Manager->Count; Index++)
  338. {
  339. TTerminal * Terminal = Manager->Terminals[Index];
  340. if (Session.IsEmpty() ||
  341. Terminal->SessionData->IsSameSite(Data.get()))
  342. {
  343. if (Path.IsEmpty())
  344. {
  345. Terminal->ClearCaches();
  346. }
  347. else
  348. {
  349. Terminal->DirectoryModified(Path, true);
  350. }
  351. }
  352. }
  353. // We should flag a pending refresh for the background terminals or busy foreground terminals
  354. if ((Terminal != NULL) && Terminal->Active &&
  355. CanCommandLineFromAnotherInstance() &&
  356. (Session.IsEmpty() || Terminal->SessionData->IsSameSite(Data.get())) &&
  357. (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
  358. {
  359. Terminal->ReloadDirectory();
  360. }
  361. }
  362. //---------------------------------------------------------------------------
  363. void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
  364. {
  365. PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
  366. size_t MessageSize = sizeof(TCopyDataMessage);
  367. bool Result = DebugAlwaysTrue(CopyData->cbData == MessageSize);
  368. if (Result)
  369. {
  370. const TCopyDataMessage & Message = *reinterpret_cast<const TCopyDataMessage *>(CopyData->lpData);
  371. Result = (Message.Version == TCopyDataMessage::Version1);
  372. if (Result)
  373. {
  374. switch (Message.Command)
  375. {
  376. case TCopyDataMessage::CommandCanCommandLine:
  377. Result = CanCommandLineFromAnotherInstance();
  378. break;
  379. case TCopyDataMessage::CommandCommandLine:
  380. {
  381. UnicodeString CommandLine(Message.CommandLine);
  382. Result = CommandLineFromAnotherInstance(CommandLine);
  383. }
  384. break;
  385. case TCopyDataMessage::RefreshPanel:
  386. RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
  387. break;
  388. case TCopyDataMessage::MainWindowCheck:
  389. Result = true;
  390. break;
  391. default:
  392. Result = false;
  393. break;
  394. }
  395. }
  396. }
  397. Message.Result = Result ? 1 : 0;
  398. }
  399. //---------------------------------------------------------------------------
  400. void __fastcall TCustomScpExplorerForm::CreateHiddenWindow()
  401. {
  402. WNDCLASS WindowClass = {0};
  403. WindowClass.lpfnWndProc = DefWindowProc;
  404. WindowClass.hInstance = HInstance;
  405. WindowClass.lpszClassName = HIDDEN_WINDOW_NAME;
  406. FHiddenWindow = NULL;
  407. if (RegisterClass(&WindowClass))
  408. {
  409. FHiddenWindow = CreateWindow(HIDDEN_WINDOW_NAME, L"",
  410. WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, NULL);
  411. }
  412. }
  413. //---------------------------------------------------------------------------
  414. bool __fastcall TCustomScpExplorerForm::CanConsole()
  415. {
  416. return (Terminal != NULL) && (Terminal->IsCapable[fcAnyCommand] || Terminal->IsCapable[fcSecondaryShell]);
  417. }
  418. //---------------------------------------------------------------------------
  419. bool __fastcall TCustomScpExplorerForm::CanCommandLineFromAnotherInstance()
  420. {
  421. bool Result = !NonVisualDataModule->Busy;
  422. return Result;
  423. }
  424. //---------------------------------------------------------------------------
  425. bool __fastcall TCustomScpExplorerForm::CommandLineFromAnotherInstance(
  426. const UnicodeString & CommandLine)
  427. {
  428. TProgramParams Params(CommandLine);
  429. bool Result = CanCommandLineFromAnotherInstance() && DebugAlwaysTrue(Params.ParamCount > 0);
  430. if (Result)
  431. {
  432. NonVisualDataModule->StartBusy();
  433. try
  434. {
  435. // this action is initiated from another process,
  436. // so it's likely that our window is not visible,
  437. // and user won't see what is going on
  438. Application->BringToFront();
  439. // reload sessions as we may be asked to open a session
  440. // just stored by another instance
  441. StoredSessions->Load();
  442. UnicodeString SessionName = Params.Param[1];
  443. std::unique_ptr<TObjectList> DataList(new TObjectList());
  444. UnicodeString DownloadFile; // unused
  445. GetLoginData(SessionName, &Params, DataList.get(), DownloadFile, true, this);
  446. if (DataList->Count > 0)
  447. {
  448. TTerminalManager * Manager = TTerminalManager::Instance();
  449. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  450. }
  451. }
  452. __finally
  453. {
  454. NonVisualDataModule->EndBusy();
  455. }
  456. }
  457. return Result;
  458. }
  459. //---------------------------------------------------------------------------
  460. void __fastcall TCustomScpExplorerForm::SetTerminal(TTerminal * value)
  461. {
  462. if (FTerminal != value)
  463. {
  464. TerminalChanging();
  465. FTerminal = value;
  466. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  467. FAllowTransferPresetAutoSelect = false;
  468. try
  469. {
  470. TerminalChanged();
  471. }
  472. __finally
  473. {
  474. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  475. }
  476. if (Terminal != NULL)
  477. {
  478. TransferPresetAutoSelect();
  479. }
  480. }
  481. }
  482. //---------------------------------------------------------------------------
  483. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  484. {
  485. if (FTerminal != NULL)
  486. {
  487. UpdateTerminal(Terminal);
  488. }
  489. }
  490. //---------------------------------------------------------------------------
  491. void __fastcall TCustomScpExplorerForm::TerminalChanged()
  492. {
  493. RemoteDirView->Terminal = Terminal;
  494. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  495. TManagedTerminal * ManagedTerminal = NULL;
  496. if (Terminal != NULL)
  497. {
  498. if (Terminal->Active)
  499. {
  500. Terminal->RefreshDirectory();
  501. }
  502. ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  503. DebugAssert(ManagedTerminal != NULL);
  504. if (WinConfiguration->PreservePanelState)
  505. {
  506. if (ManagedTerminal->RemoteExplorerState != NULL)
  507. {
  508. RemoteDirView->RestoreState(ManagedTerminal->RemoteExplorerState);
  509. }
  510. else
  511. {
  512. RemoteDirView->ClearState();
  513. }
  514. }
  515. InitStatusBar();
  516. }
  517. DoTerminalListChanged(false);
  518. if (ManagedTerminal != NULL)
  519. {
  520. // this has to be set only after the tab is switched from DoTerminalListChanged,
  521. // otherwise we are changing color of wrong tab
  522. SessionColor = (TColor)ManagedTerminal->StateData->Color;
  523. }
  524. UpdateTransferList();
  525. // Update panels Enable state before refreshing the labels
  526. UpdateControls();
  527. }
  528. //---------------------------------------------------------------------------
  529. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  530. {
  531. if (Queue != value)
  532. {
  533. if (FQueue != NULL)
  534. {
  535. FQueue->OnListUpdate = NULL;
  536. FQueue->OnQueueItemUpdate = NULL;
  537. }
  538. FQueue = value;
  539. if (FQueue != NULL)
  540. {
  541. DebugAssert(FQueue->OnListUpdate == NULL);
  542. FQueue->OnListUpdate = QueueListUpdate;
  543. DebugAssert(FQueue->OnQueueItemUpdate == NULL);
  544. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  545. }
  546. QueueChanged();
  547. }
  548. }
  549. //---------------------------------------------------------------------------
  550. void __fastcall TCustomScpExplorerForm::QueueView3Deletion(TObject * /*Sender*/,
  551. TListItem * Item)
  552. {
  553. if (FQueueActedItem == Item)
  554. {
  555. FQueueActedItem = NULL;
  556. if ((QueueView3->PopupMenu != NULL) &&
  557. (QueueView3->PopupMenu->PopupComponent == QueueView3))
  558. {
  559. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  560. ReleaseCapture();
  561. }
  562. }
  563. if (Item->Data == FPendingQueueActionItem)
  564. {
  565. FPendingQueueActionItem = NULL;
  566. }
  567. }
  568. //---------------------------------------------------------------------------
  569. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool QueueChanging)
  570. {
  571. {
  572. TGuard Guard(FQueueStatusSection);
  573. FQueueStatusInvalidated = false;
  574. if (FQueue != NULL)
  575. {
  576. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  577. }
  578. }
  579. if ((FQueueStatus != NULL) && (FQueueStatus->Count > FMaxQueueLength))
  580. {
  581. FMaxQueueLength = FQueueStatus->Count;
  582. Configuration->Usage->SetMax(L"MaxQueueLength", FMaxQueueLength);
  583. }
  584. FQueueController->UpdateQueueStatus(FQueueStatus);
  585. SetQueueProgress();
  586. UpdateQueueView();
  587. bool IsEmpty = (FQueueStatus == NULL) || (FQueueStatus->Count == 0);
  588. if (IsEmpty && (Terminal != NULL))
  589. {
  590. TOnceDoneOperation OnceDoneOperation =
  591. NonVisualDataModule->CurrentQueueOnceEmptyOperation();
  592. NonVisualDataModule->ResetQueueOnceEmptyOperation();
  593. if ((FQueue != NULL) && !WinConfiguration->EnableQueueByDefault && !QueueChanging)
  594. {
  595. FQueue->Enabled = false;
  596. }
  597. if ((OnceDoneOperation != odoIdle) && !NonVisualDataModule->Busy)
  598. {
  599. Terminal->CloseOnCompletion(OnceDoneOperation, LoadStr(CLOSED_ON_QUEUE_EMPTY));
  600. }
  601. }
  602. }
  603. //---------------------------------------------------------------------------
  604. UnicodeString __fastcall TCustomScpExplorerForm::GetQueueProgressTitle()
  605. {
  606. UnicodeString Result;
  607. if (FQueueStatus != NULL)
  608. {
  609. int ActiveAndPendingCount = FQueueStatus->ActiveAndPendingCount;
  610. if ((ActiveAndPendingCount == 1) && (FQueueStatus->ActiveCount == 1))
  611. {
  612. TFileOperationProgressType * ProgressData =
  613. FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData;
  614. if ((ProgressData != NULL) && ProgressData->InProgress)
  615. {
  616. Result = TProgressForm::ProgressStr(ProgressData);
  617. }
  618. }
  619. else if (ActiveAndPendingCount > 1)
  620. {
  621. Result = FMTLOAD(PROGRESS_IN_QUEUE, (ActiveAndPendingCount));
  622. }
  623. }
  624. return Result;
  625. }
  626. //---------------------------------------------------------------------------
  627. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  628. {
  629. ComponentVisible[fcQueueView] =
  630. (WinConfiguration->QueueView.Show == qvShow) ||
  631. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  632. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  633. }
  634. //---------------------------------------------------------------------------
  635. void __fastcall TCustomScpExplorerForm::QueueChanged()
  636. {
  637. if (FQueueStatus != NULL)
  638. {
  639. delete FQueueStatus;
  640. FQueueStatus = NULL;
  641. }
  642. UpdateQueueStatus(true);
  643. }
  644. //---------------------------------------------------------------------------
  645. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  646. {
  647. if (FQueue == Queue)
  648. {
  649. FQueueStatusInvalidated = true;
  650. }
  651. }
  652. //---------------------------------------------------------------------------
  653. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  654. TQueueItem * Item)
  655. {
  656. if (FQueue == Queue)
  657. {
  658. TGuard Guard(FQueueStatusSection);
  659. // this may be running in parallel with QueueChanged
  660. if (FQueueStatus != NULL)
  661. {
  662. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  663. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  664. {
  665. FRefreshLocalDirectory = (QueueItem == NULL) ||
  666. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  667. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  668. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  669. }
  670. if (QueueItem != NULL)
  671. {
  672. QueueItem->UserData = (void*)true;
  673. FQueueItemInvalidated = true;
  674. }
  675. }
  676. }
  677. }
  678. //---------------------------------------------------------------------------
  679. bool __fastcall TCustomScpExplorerForm::IsQueueAutoPopup()
  680. {
  681. // during standalone editing, we have no way to see/control queue,
  682. // so we have to always popup prompts automatically
  683. return FStandaloneEditing || GUIConfiguration->QueueAutoPopup;
  684. }
  685. //---------------------------------------------------------------------------
  686. void __fastcall TCustomScpExplorerForm::RefreshQueueItems()
  687. {
  688. if (FQueueStatus != NULL)
  689. {
  690. bool QueueAutoPopup = IsQueueAutoPopup();
  691. bool NeedRefresh = FQueueController->NeedRefresh();
  692. bool Refresh = FQueueItemInvalidated || NeedRefresh;
  693. FQueueItemInvalidated = false;
  694. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->DoneAndActiveCount;
  695. bool Updated = false;
  696. TQueueItemProxy * QueueItem;
  697. bool WasUserAction;
  698. for (int Index = 0; Index < Limit; Index++)
  699. {
  700. bool Update = false;
  701. QueueItem = FQueueStatus->Items[Index];
  702. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  703. if (!NonVisualDataModule->Busy && QueueAutoPopup && WasUserAction &&
  704. (FPendingQueueActionItem == NULL))
  705. {
  706. FPendingQueueActionItem = QueueItem;
  707. FUserActionTimer->Enabled = true;
  708. }
  709. if ((bool)QueueItem->UserData)
  710. {
  711. QueueItem->UserData = (void*)false;
  712. QueueItem->Update();
  713. Updated = true;
  714. Update = true;
  715. }
  716. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem) || NeedRefresh)
  717. {
  718. Update = true;
  719. }
  720. if (Update)
  721. {
  722. FQueueController->RefreshQueueItem(QueueItem);
  723. }
  724. }
  725. if (Updated)
  726. {
  727. NonVisualDataModule->UpdateNonVisibleActions();
  728. SetQueueProgress();
  729. }
  730. }
  731. }
  732. //---------------------------------------------------------------------------
  733. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressState(TBPFLAG Flags)
  734. {
  735. FTaskbarList->SetProgressState(GetMainForm()->Handle, Flags);
  736. }
  737. //---------------------------------------------------------------------------
  738. void __fastcall TCustomScpExplorerForm::SetTaskbarListProgressValue(TFileOperationProgressType * ProgressData)
  739. {
  740. if (ProgressData->Operation != foCalculateSize)
  741. {
  742. // implies TBPF_NORMAL
  743. FTaskbarList->SetProgressValue(GetMainForm()->Handle, ProgressData->OverallProgress(), 100);
  744. }
  745. else
  746. {
  747. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  748. }
  749. }
  750. //---------------------------------------------------------------------------
  751. void __fastcall TCustomScpExplorerForm::SetQueueProgress()
  752. {
  753. TTerminalManager::Instance()->QueueStatusUpdated();
  754. if ((FTaskbarList != NULL) && (FProgressForm == NULL))
  755. {
  756. if ((FQueueStatus != NULL) && (FQueueStatus->ActiveCount > 0))
  757. {
  758. if (FQueueStatus->ActiveCount == 1)
  759. {
  760. TFileOperationProgressType * ProgressData;
  761. if ((FQueueStatus->Items[FQueueStatus->DoneCount] != NULL) &&
  762. ((ProgressData = FQueueStatus->Items[FQueueStatus->DoneCount]->ProgressData) != NULL) &&
  763. ProgressData->InProgress)
  764. {
  765. SetTaskbarListProgressValue(ProgressData);
  766. }
  767. else
  768. {
  769. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  770. }
  771. }
  772. else
  773. {
  774. SetTaskbarListProgressState(TBPF_INDETERMINATE);
  775. }
  776. }
  777. else
  778. {
  779. SetTaskbarListProgressState(TBPF_NOPROGRESS);
  780. }
  781. }
  782. UpdateQueueLabel();
  783. }
  784. //---------------------------------------------------------------------------
  785. void __fastcall TCustomScpExplorerForm::UpdateQueueLabel()
  786. {
  787. UnicodeString Caption = LoadStr(QUEUE_CAPTION);
  788. if (FQueueStatus != NULL)
  789. {
  790. int ActiveAndPendingCount = FQueueStatus->ActiveAndPendingCount;
  791. if (ActiveAndPendingCount > 0)
  792. {
  793. Caption = FORMAT("%s (%d)", (Caption, ActiveAndPendingCount));
  794. }
  795. }
  796. QueueLabel->Caption = Caption;
  797. }
  798. //---------------------------------------------------------------------------
  799. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  800. {
  801. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  802. static_cast<TComponent*>(GetComponent(fcTransferList)));
  803. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  804. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  805. TransferList->Strings->BeginUpdate();
  806. try
  807. {
  808. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  809. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  810. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  811. if (FTransferDropDownHint.IsEmpty())
  812. {
  813. FTransferDropDownHint = TransferDropDown->Hint;
  814. }
  815. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  816. UnicodeString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  817. TransferDropDown->Text = StripHotkey(Name);
  818. TransferDropDown->Hint = FORMAT(L"%s|%s:\n%s",
  819. (FTransferDropDownHint, StripHotkey(Name),
  820. GUIConfiguration->CurrentCopyParam.GetInfoStr(L"; ",
  821. FLAGMASK(Terminal != NULL, Terminal->UsableCopyParamAttrs(0).General))));
  822. // update the label, otherwise when it is updated only on the first draw
  823. // of the list, it is drawn "bold" for some reason
  824. FTransferListHoverIndex = TransferList->ItemIndex;
  825. UpdateTransferLabel();
  826. }
  827. __finally
  828. {
  829. TransferList->Strings->EndUpdate();
  830. }
  831. }
  832. //---------------------------------------------------------------------------
  833. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  834. {
  835. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  836. DebugAssert(Toolbar != NULL);
  837. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  838. }
  839. //---------------------------------------------------------------------------
  840. void __fastcall TCustomScpExplorerForm::UpdateActions()
  841. {
  842. TForm::UpdateActions();
  843. if (ComponentVisible[fcCustomCommandsBand])
  844. {
  845. UpdateCustomCommandsToolbar();
  846. }
  847. }
  848. //---------------------------------------------------------------------------
  849. void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
  850. {
  851. SessionsPageControl->Height = SessionsPageControl->GetTabsHeight();
  852. }
  853. //---------------------------------------------------------------------------
  854. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  855. {
  856. DebugAssert(Configuration && RemoteDirView);
  857. RemoteDirView->DDAllowMove = WinConfiguration->DDAllowMoveInit;
  858. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  859. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  860. RemoteDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  861. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  862. if (RemoteDirView->RowSelect != WinConfiguration->FullRowSelect)
  863. {
  864. RemoteDirView->RowSelect = WinConfiguration->FullRowSelect;
  865. // selection is not redrawn automatically when RowSelect changes
  866. RemoteDirView->Invalidate();
  867. }
  868. RemoteDriveView->DDAllowMove = WinConfiguration->DDAllowMoveInit;
  869. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  870. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  871. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  872. UpdateSessionsPageControlHeight();
  873. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  874. UpdateToolbarDisplayMode();
  875. UpdateTransferList();
  876. if (Terminal != NULL)
  877. {
  878. TransferPresetAutoSelect();
  879. }
  880. UpdateQueueView();
  881. UpdateControls();
  882. // this can be called even before constuctor finishes.
  883. if (FEditorManager != NULL)
  884. {
  885. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  886. }
  887. // this can be called even before constuctor finishes.
  888. if (FLocalEditors != NULL)
  889. {
  890. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  891. {
  892. ReconfigureEditorForm(static_cast<TForm *>(FLocalEditors->Items[Index]));
  893. }
  894. }
  895. if (ComponentVisible[fcCustomCommandsBand])
  896. {
  897. UpdateCustomCommandsToolbar();
  898. }
  899. // show only when keeping queue items forever,
  900. // otherwise, its enough to have in in the context menu
  901. QueueDeleteAllDoneQueueToolbarItem->Visible =
  902. WinConfiguration->QueueKeepDoneItems && (WinConfiguration->QueueKeepDoneItemsFor < 0);
  903. }
  904. //---------------------------------------------------------------------------
  905. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  906. const UnicodeString FileName, TEditedFileData * /*Data*/, TObject * Token,
  907. void * /*Arg*/)
  908. {
  909. if (Token != NULL)
  910. {
  911. TForm * Editor = dynamic_cast<TForm*>(Token);
  912. DebugAssert(Editor != NULL);
  913. ReconfigureEditorForm(Editor);
  914. }
  915. }
  916. //---------------------------------------------------------------------------
  917. void __fastcall TCustomScpExplorerForm::EnableDDTransferConfirmation(TObject * /*Sender*/)
  918. {
  919. WinConfiguration->DDTransferConfirmation = asOn;
  920. }
  921. //---------------------------------------------------------------------------
  922. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  923. TTransferDirection Direction, TTransferType Type, bool Temp,
  924. TStrings * FileList, UnicodeString & TargetDirectory, TGUICopyParamType & CopyParam,
  925. bool Confirm, bool DragDrop, int Options)
  926. {
  927. bool Result = true;
  928. DebugAssert(Terminal && Terminal->Active);
  929. // Temp means d&d here so far, may change in future!
  930. if (Temp && (Direction == tdToLocal) && (Type == ttMove) &&
  931. !WinConfiguration->DDAllowMove)
  932. {
  933. TMessageParams Params(mpNeverAskAgainCheck);
  934. unsigned int Answer = MessageDialog(LoadStr(DND_DOWNLOAD_MOVE_WARNING), qtWarning,
  935. qaOK | qaCancel, HELP_DND_DOWNLOAD_MOVE_WARNING, &Params);
  936. if (Answer == qaNeverAskAgain)
  937. {
  938. WinConfiguration->DDAllowMove = true;
  939. }
  940. else if (Answer == qaCancel)
  941. {
  942. Result = false;
  943. }
  944. }
  945. // these parameters are known in advance
  946. int Params =
  947. FLAGMASK(Type == ttMove, cpDelete);
  948. bool ToTemp = (Temp && (Direction == tdToLocal));
  949. if (Result && Confirm && WinConfiguration->ConfirmTransferring)
  950. {
  951. bool DisableNewerOnly =
  952. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  953. ToTemp;
  954. Options |=
  955. FLAGMASK(ToTemp, coTemp) |
  956. coDoNotShowAgain;
  957. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  958. int CopyParamAttrs = (Direction == tdToRemote ?
  959. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download) |
  960. FLAGMASK(DisableNewerOnly, cpaNoNewerOnly);
  961. int OutputOptions =
  962. FLAGMASK(DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto),
  963. cooDoNotShowAgain);
  964. std::unique_ptr<TSessionData> SessionData(SessionDataForCode());
  965. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  966. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, SessionData.get(), &OutputOptions);
  967. if (Result)
  968. {
  969. if (FLAGSET(OutputOptions, cooDoNotShowAgain))
  970. {
  971. if (DragDrop)
  972. {
  973. if (WinConfiguration->DDTransferConfirmation == asAuto)
  974. {
  975. PopupTrayBalloon(NULL, LoadStr(DD_TRANSFER_CONFIRM_OFF2), qtInformation,
  976. NULL, 0, EnableDDTransferConfirmation, NULL);
  977. }
  978. WinConfiguration->DDTransferConfirmation = asOff;
  979. }
  980. else
  981. {
  982. WinConfiguration->ConfirmTransferring = false;
  983. }
  984. }
  985. else
  986. {
  987. // User exclicitly unchecked "do not show again",
  988. // so show him the dialog the next time
  989. if (DragDrop && (WinConfiguration->DDTransferConfirmation == asAuto))
  990. {
  991. WinConfiguration->DDTransferConfirmation = asOn;
  992. }
  993. }
  994. }
  995. }
  996. if (Result && CopyParam.Queue && !ToTemp)
  997. {
  998. Configuration->Usage->Inc(L"TransfersOnBackground");
  999. // these parameter are known only after transfer dialog
  1000. Params |=
  1001. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  1002. if (CopyParam.QueueIndividually)
  1003. {
  1004. for (int Index = 0; Index < FileList->Count; Index++)
  1005. {
  1006. TStrings * FileList1 = new TStringList();
  1007. try
  1008. {
  1009. FileList1->AddObject(FileList->Strings[Index], FileList->Objects[Index]);
  1010. AddQueueItem(Queue, Direction, FileList1, TargetDirectory, CopyParam, Params);
  1011. }
  1012. __finally
  1013. {
  1014. delete FileList1;
  1015. }
  1016. }
  1017. }
  1018. else
  1019. {
  1020. AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
  1021. }
  1022. Result = false;
  1023. ClearTransferSourceSelection(Direction);
  1024. }
  1025. return Result;
  1026. }
  1027. //---------------------------------------------------------------------------
  1028. void __fastcall TCustomScpExplorerForm::ClearTransferSourceSelection(TTransferDirection Direction)
  1029. {
  1030. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  1031. if (HasDirView[Side])
  1032. {
  1033. DirView(Side)->SelectAll(smNone);
  1034. }
  1035. }
  1036. //---------------------------------------------------------------------------
  1037. void __fastcall TCustomScpExplorerForm::AddQueueItem(
  1038. TTerminalQueue * Queue, TTransferDirection Direction, TStrings * FileList,
  1039. const UnicodeString TargetDirectory, const TCopyParamType & CopyParam,
  1040. int Params)
  1041. {
  1042. DebugAssert(Queue != NULL);
  1043. bool SingleFile = false;
  1044. if (FileList->Count == 1)
  1045. {
  1046. if (Direction == tdToRemote)
  1047. {
  1048. UnicodeString FileName = FileList->Strings[0];
  1049. SingleFile = FileExists(ApiPath(FileName));
  1050. }
  1051. else
  1052. {
  1053. TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[0]);
  1054. SingleFile = !File->IsDirectory;
  1055. }
  1056. }
  1057. TQueueItem * QueueItem;
  1058. if (Direction == tdToRemote)
  1059. {
  1060. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  1061. &CopyParam, Params, SingleFile);
  1062. }
  1063. else
  1064. {
  1065. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  1066. &CopyParam, Params, SingleFile);
  1067. }
  1068. AddQueueItem(Queue, QueueItem, Terminal);
  1069. }
  1070. //---------------------------------------------------------------------------
  1071. void __fastcall TCustomScpExplorerForm::AddQueueItem(TTerminalQueue * Queue, TQueueItem * QueueItem, TTerminal * Terminal)
  1072. {
  1073. if (Queue->IsEmpty)
  1074. {
  1075. TManagedTerminal * ManagedTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(Terminal));
  1076. ManagedTerminal->QueueOperationStart = Now();
  1077. }
  1078. Queue->AddItem(QueueItem);
  1079. }
  1080. //---------------------------------------------------------------------------
  1081. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  1082. {
  1083. }
  1084. //---------------------------------------------------------------------------
  1085. void __fastcall TCustomScpExplorerForm::RestoreParams()
  1086. {
  1087. DebugAssert(FDocks != NULL);
  1088. for (int Index = 0; Index < ComponentCount; Index++)
  1089. {
  1090. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  1091. if ((Dock != NULL) && (Dock->Tag == 0))
  1092. {
  1093. FDocks->Add(Dock);
  1094. }
  1095. }
  1096. CollectItemsWithTextDisplayMode(this);
  1097. ConfigurationChanged();
  1098. QueuePanel->Height = LoadDimension(WinConfiguration->QueueView.Height, WinConfiguration->QueueView.HeightPixelsPerInch);
  1099. LoadListViewStr(QueueView3, WinConfiguration->QueueView.Layout);
  1100. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  1101. QueueLabel->Visible = WinConfiguration->QueueView.Label;
  1102. }
  1103. //---------------------------------------------------------------------------
  1104. void __fastcall TCustomScpExplorerForm::StoreParams()
  1105. {
  1106. WinConfiguration->QueueView.Height = QueuePanel->Height;
  1107. WinConfiguration->QueueView.HeightPixelsPerInch = Screen->PixelsPerInch;
  1108. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView3);
  1109. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  1110. WinConfiguration->QueueView.Label = QueueLabel->Visible;
  1111. }
  1112. //---------------------------------------------------------------------------
  1113. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  1114. {
  1115. if (!FFormRestored)
  1116. {
  1117. FFormRestored = true;
  1118. RestoreFormParams();
  1119. }
  1120. TForm::CreateParams(Params);
  1121. }
  1122. //---------------------------------------------------------------------------
  1123. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  1124. {
  1125. DebugAssert(FDocks != NULL);
  1126. for (int Index = 0; Index < FDocks->Count; Index++)
  1127. {
  1128. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  1129. }
  1130. }
  1131. //---------------------------------------------------------------------------
  1132. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(UnicodeString LayoutStr)
  1133. {
  1134. SetDockAllowDrag(true);
  1135. ::LoadToolbarsLayoutStr(this, LayoutStr);
  1136. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1137. }
  1138. //---------------------------------------------------------------------------
  1139. UnicodeString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  1140. {
  1141. UnicodeString Result;
  1142. SetDockAllowDrag(true);
  1143. Result = ::GetToolbarsLayoutStr(this);
  1144. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  1145. return Result;
  1146. }
  1147. //---------------------------------------------------------------------------
  1148. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  1149. TFileOperationProgressType & ProgressData)
  1150. {
  1151. // Download to temporary local directory
  1152. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  1153. {
  1154. bool Continue = true;
  1155. FPendingTempSpaceWarn = false;
  1156. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  1157. if (!Continue)
  1158. {
  1159. Abort();
  1160. }
  1161. }
  1162. // operation is being executed and we still didn't show up progress form
  1163. if (ProgressData.InProgress && !FProgressForm)
  1164. {
  1165. FProgressForm = new TProgressForm(Application, (FTransferResumeList != NULL));
  1166. // As progress window has delayed show now, we need to lock ourselves,
  1167. // (at least) until then
  1168. LockWindow();
  1169. FProgressForm->DeleteToRecycleBin = (ProgressData.Side == osLocal ?
  1170. (WinConfiguration->DeleteToRecycleBin != FAlternativeDelete) :
  1171. ((Terminal->SessionData->DeleteToRecycleBin != FAlternativeDelete) &&
  1172. !Terminal->SessionData->RecycleBinPath.IsEmpty()));
  1173. // When main window is hidden, synchronisation form does not exist,
  1174. // we suppose "/upload" or URL download mode
  1175. if (!Visible && (ProgressData.Operation != foCalculateSize) &&
  1176. (ProgressData.Operation != foCalculateChecksum) &&
  1177. (FSynchronizeProgressForm == NULL) &&
  1178. !FStandaloneEditing)
  1179. {
  1180. FProgressForm->OnceDoneOperation = odoDisconnect;
  1181. }
  1182. if (FTaskbarList != NULL)
  1183. {
  1184. // Actually, do not know what hides the progress once the operation finishes
  1185. SetTaskbarListProgressState(TBPF_NORMAL);
  1186. }
  1187. }
  1188. // operation is finished (or terminated), so we hide progress form
  1189. else if (!ProgressData.InProgress && FProgressForm)
  1190. {
  1191. UnlockWindow();
  1192. SAFE_DESTROY(FProgressForm);
  1193. SetQueueProgress();
  1194. if (ProgressData.Operation == foCalculateSize)
  1195. {
  1196. // When calculating size before transfer, the abort caused by
  1197. // cancel flag set due to "MoveToQueue" below,
  1198. // is not propagated back to us in ExecuteFileOperation,
  1199. // as it is silently swallowed.
  1200. // So we explicitly (re)throw it here.
  1201. if (FMoveToQueue)
  1202. {
  1203. Abort();
  1204. }
  1205. }
  1206. else
  1207. {
  1208. if ((ProgressData.Cancel == csContinue) &&
  1209. !FAutoOperation)
  1210. {
  1211. OperationComplete(ProgressData.StartTime);
  1212. }
  1213. }
  1214. }
  1215. if (FProgressForm)
  1216. {
  1217. FProgressForm->SetProgressData(ProgressData);
  1218. if (FTaskbarList != NULL)
  1219. {
  1220. DebugAssert(ProgressData.InProgress);
  1221. SetTaskbarListProgressValue(&ProgressData);
  1222. }
  1223. if (FProgressForm->Cancel > csContinue)
  1224. {
  1225. if (FProgressForm->Cancel > ProgressData.Cancel)
  1226. {
  1227. ProgressData.Cancel = FProgressForm->Cancel;
  1228. }
  1229. // cancel cancels even the move
  1230. FMoveToQueue = false;
  1231. }
  1232. else if (FProgressForm->MoveToQueue)
  1233. {
  1234. FMoveToQueue = true;
  1235. if (ProgressData.Cancel < csCancel)
  1236. {
  1237. ProgressData.Cancel = csCancel;
  1238. }
  1239. }
  1240. if ((FTransferResumeList != NULL) &&
  1241. ProgressData.InProgress &&
  1242. ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
  1243. !ProgressData.FullFileName.IsEmpty())
  1244. {
  1245. if ((FTransferResumeList->Count == 0) ||
  1246. (FTransferResumeList->Strings[FTransferResumeList->Count - 1] != ProgressData.FullFileName))
  1247. {
  1248. // note that we do not recognize directories from files here
  1249. FTransferResumeList->Add(ProgressData.FullFileName);
  1250. }
  1251. }
  1252. }
  1253. }
  1254. //---------------------------------------------------------------------------
  1255. void __fastcall TCustomScpExplorerForm::OperationComplete(
  1256. const TDateTime & StartTime)
  1257. {
  1258. if (GUIConfiguration->BeepOnFinish &&
  1259. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  1260. {
  1261. UnicodeString BeepSound = GUIConfiguration->BeepSound;
  1262. DWORD Sound;
  1263. if (!ExtractFileExt(BeepSound).IsEmpty())
  1264. {
  1265. Sound = SND_FILENAME;
  1266. }
  1267. else
  1268. {
  1269. Sound = SND_ALIAS;
  1270. }
  1271. PlaySound(BeepSound.c_str(), NULL, Sound | SND_ASYNC);
  1272. }
  1273. }
  1274. //---------------------------------------------------------------------------
  1275. void __fastcall TCustomScpExplorerForm::OperationProgress(
  1276. TFileOperationProgressType & ProgressData)
  1277. {
  1278. FileOperationProgress(ProgressData);
  1279. }
  1280. //---------------------------------------------------------------------------
  1281. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  1282. bool DragDrop)
  1283. {
  1284. return (!DragDrop && (DropSourceControl == NULL)) ||
  1285. (DropSourceControl == RemoteDirView);
  1286. }
  1287. //---------------------------------------------------------------------------
  1288. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  1289. TFileOperation Operation, TOperationSide Side,
  1290. bool /*Temp*/, const UnicodeString & FileName, bool Success,
  1291. TOnceDoneOperation & OnceDoneOperation)
  1292. {
  1293. if (!FAutoOperation)
  1294. {
  1295. // no selection on "/upload", form servers only as event handler
  1296. // (it is not displayed)
  1297. if (PanelOperation(Side, FDragDropOperation) &&
  1298. Visible && (Operation != foCalculateSize) &&
  1299. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  1300. {
  1301. if (FOnFileOperationFinished != NULL)
  1302. {
  1303. FOnFileOperationFinished(FileName, Success);
  1304. }
  1305. else
  1306. {
  1307. TCustomDirView * DView = DirView(Side);
  1308. UnicodeString FileNameOnly = ExtractFileName(FileName, (Side == osRemote));
  1309. TListItem *Item = DView->FindFileItem(FileNameOnly);
  1310. // this can happen when local drive is unplugged in the middle of the operation
  1311. if (Item != NULL)
  1312. {
  1313. if (Success) Item->Selected = false;
  1314. DView->MakeProgressVisible(Item);
  1315. }
  1316. }
  1317. }
  1318. if ((Operation == foCopy) || (Operation == foMove))
  1319. {
  1320. if (Side == osLocal)
  1321. {
  1322. Configuration->Usage->Inc(L"UploadedFiles");
  1323. }
  1324. else
  1325. {
  1326. Configuration->Usage->Inc(L"DownloadedFiles");
  1327. }
  1328. }
  1329. }
  1330. if (Success && (FSynchronizeController != NULL))
  1331. {
  1332. if (Operation == foCopy)
  1333. {
  1334. DebugAssert(Side == osLocal);
  1335. FSynchronizeController->LogOperation(soUpload, FileName);
  1336. }
  1337. else if (Operation == foDelete)
  1338. {
  1339. DebugAssert(Side == osRemote);
  1340. FSynchronizeController->LogOperation(soDelete, FileName);
  1341. }
  1342. }
  1343. if (FProgressForm)
  1344. {
  1345. OnceDoneOperation = FProgressForm->OnceDoneOperation;
  1346. }
  1347. }
  1348. //---------------------------------------------------------------------------
  1349. void __fastcall TCustomScpExplorerForm::OperationFinished(
  1350. TFileOperation Operation, TOperationSide Side,
  1351. bool Temp, const UnicodeString & FileName, Boolean Success,
  1352. TOnceDoneOperation & OnceDoneOperation)
  1353. {
  1354. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  1355. OnceDoneOperation);
  1356. }
  1357. //---------------------------------------------------------------------------
  1358. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  1359. {
  1360. DebugAssert(GetSide(Side) == osRemote);
  1361. DebugUsedParam(Side);
  1362. return RemoteDirView;
  1363. }
  1364. //---------------------------------------------------------------------------
  1365. bool __fastcall TCustomScpExplorerForm::DirViewEnabled(TOperationSide Side)
  1366. {
  1367. DebugAssert(GetSide(Side) == osRemote);
  1368. DebugUsedParam(Side);
  1369. return (Terminal != NULL);
  1370. }
  1371. //---------------------------------------------------------------------------
  1372. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  1373. TOperationSide Side, int FilesOnly)
  1374. {
  1375. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0), true);
  1376. }
  1377. //---------------------------------------------------------------------------
  1378. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  1379. TOperationSide Side, int FilesOnly)
  1380. {
  1381. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0), true);
  1382. }
  1383. //---------------------------------------------------------------------------
  1384. struct THistoryItemData
  1385. {
  1386. short int Side;
  1387. short int Index;
  1388. };
  1389. //---------------------------------------------------------------------------
  1390. void __fastcall TCustomScpExplorerForm::HistoryGo(TOperationSide Side, int Index)
  1391. {
  1392. DirView(Side)->HistoryGo(Index);
  1393. }
  1394. //---------------------------------------------------------------------------
  1395. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  1396. {
  1397. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1398. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  1399. HistoryGo((TOperationSide)Data.Side, Data.Index);
  1400. }
  1401. //---------------------------------------------------------------------------
  1402. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  1403. bool Back)
  1404. {
  1405. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  1406. {
  1407. TCustomDirView * DView = DirView(Side);
  1408. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  1409. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  1410. if (ICount > 10)
  1411. {
  1412. ICount = 10;
  1413. }
  1414. Menu->Items->Clear();
  1415. THistoryItemData Data;
  1416. Data.Side = Side;
  1417. for (short int i = 1; i <= ICount; i++)
  1418. {
  1419. TTBCustomItem * Item = new TTBXItem(Menu);
  1420. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  1421. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, (Side == osRemote));
  1422. Item->Hint = DView->HistoryPath[Data.Index];
  1423. DebugAssert(sizeof(int) == sizeof(THistoryItemData));
  1424. Item->Tag = *reinterpret_cast<int*>(&Data);
  1425. Item->OnClick = HistoryItemClick;
  1426. Menu->Items->Add(Item);
  1427. }
  1428. }
  1429. }
  1430. //---------------------------------------------------------------------------
  1431. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  1432. TOperationSide Side, bool Back)
  1433. {
  1434. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  1435. {
  1436. // workaround
  1437. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  1438. // operator new allocates memory in Pascal code, but calls inline
  1439. // contructor in C++, leading in problems, the function does
  1440. // both in Pascal code
  1441. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  1442. UpdateHistoryMenu(Side, Back);
  1443. }
  1444. return FHistoryMenu[Side == osLocal][Back];
  1445. }
  1446. //---------------------------------------------------------------------------
  1447. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  1448. TCustomDirView *Sender)
  1449. {
  1450. TOperationSide Side = (Sender == DirView(osRemote) ? osRemote : osLocal);
  1451. UpdateHistoryMenu(Side, true);
  1452. UpdateHistoryMenu(Side, false);
  1453. }
  1454. //---------------------------------------------------------------------------
  1455. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  1456. {
  1457. // remote custom commands can be executed only if the server supports shell commands
  1458. // or have secondary shell
  1459. return (FTerminal != NULL) && (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  1460. }
  1461. //---------------------------------------------------------------------------
  1462. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  1463. const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
  1464. {
  1465. int Result;
  1466. TFileCustomCommand RemoteCustomCommand;
  1467. TLocalCustomCommand LocalCustomCommand;
  1468. TFileCustomCommand * NonInteractiveCustomCommand =
  1469. FLAGCLEAR(Command.Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  1470. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  1471. UnicodeString Cmd = InteractiveCustomCommand.Complete(Command.Command, false);
  1472. if (FLAGCLEAR(Command.Params, ccLocal))
  1473. {
  1474. int AllowedState = CustomCommandRemoteAllowed() ? 1 : 0;
  1475. // custom command that does not operate with files can be executed anytime ...
  1476. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1477. {
  1478. if ((ListType == ccltAll) || (ListType == ccltNonFile))
  1479. {
  1480. // ... but do not show such command in remote file menu (TODO)
  1481. Result = AllowedState;
  1482. }
  1483. else
  1484. {
  1485. Result = -1;
  1486. }
  1487. }
  1488. else
  1489. {
  1490. if ((ListType == ccltAll) || (ListType == ccltFile))
  1491. {
  1492. Result = ((FCurrentSide == osRemote) && DirView(osRemote)->AnyFileSelected(OnFocused, false, true)) ? AllowedState : 0;
  1493. }
  1494. else
  1495. {
  1496. Result = -1;
  1497. }
  1498. }
  1499. }
  1500. else
  1501. {
  1502. // custom command that does not operate with files can be executed anytime
  1503. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  1504. {
  1505. Result = ((ListType == ccltAll) || (ListType == ccltNonFile)) ? 1 : -1;
  1506. }
  1507. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  1508. {
  1509. if ((ListType == ccltAll) || (ListType == ccltFile))
  1510. {
  1511. // special case is "diff"-style command that can be executed over any side,
  1512. // if we have both sides
  1513. Result =
  1514. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1515. // directly (instead of EnableSelectedOperation) to pass
  1516. // false to FocusedFileOnlyWhenFocused when panel is inactive.
  1517. ((HasDirView[osLocal] && DirView(osLocal)->AnyFileSelected(false, false, (FCurrentSide == osLocal))) &&
  1518. DirView(osRemote)->AnyFileSelected(false, false, (FCurrentSide == osRemote))) ? 1 : 0;
  1519. }
  1520. else if (ListType == ccltBoth)
  1521. {
  1522. Result = 1;
  1523. }
  1524. else
  1525. {
  1526. Result = -1;
  1527. }
  1528. }
  1529. else
  1530. {
  1531. if ((ListType == ccltAll) || (ListType == ccltFile))
  1532. {
  1533. Result = DirView(FCurrentSide)->AnyFileSelected(OnFocused, false, true) ? 1 : 0;
  1534. }
  1535. else
  1536. {
  1537. Result = -1;
  1538. }
  1539. }
  1540. }
  1541. return Result;
  1542. }
  1543. //---------------------------------------------------------------------------
  1544. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  1545. const TCustomCommandType & ACommand, TStrings * ALocalFileList)
  1546. {
  1547. TCustomCommandData Data(Terminal);
  1548. UnicodeString Site = Terminal->SessionData->SessionKey;
  1549. UnicodeString HelpKeyword = ACommand.HomePage;
  1550. std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
  1551. if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
  1552. {
  1553. std::unique_ptr<TCustomCommand> CustomCommandForOptions;
  1554. if (FLAGCLEAR(ACommand.Params, ccLocal))
  1555. {
  1556. CustomCommandForOptions.reset(new TRemoteCustomCommand(Data, Terminal->CurrentDirectory));
  1557. }
  1558. else
  1559. {
  1560. CustomCommandForOptions.reset(new TLocalCustomCommand(Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory()));
  1561. }
  1562. if (!DoCustomCommandOptionsDialog(
  1563. &ACommand, CustomCommandOptions.get(), TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site))
  1564. {
  1565. Abort();
  1566. }
  1567. }
  1568. UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
  1569. if (FLAGCLEAR(ACommand.Params, ccLocal))
  1570. {
  1571. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1572. {
  1573. TRemoteCustomCommand RemoteCustomCommand(Data, Terminal->CurrentDirectory);
  1574. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1575. &RemoteCustomCommand, ACommand.Name, ACommand.HomePage);
  1576. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1577. Configuration->Usage->Inc(L"RemoteCustomCommandRuns2");
  1578. bool Capture =
  1579. FLAGSET(ACommand.Params, ccShowResults) ||
  1580. FLAGSET(ACommand.Params, ccCopyResults) ||
  1581. FLAGSET(ACommand.Params, ccShowResultsInMsgBox);
  1582. TCaptureOutputEvent OutputEvent = NULL;
  1583. DebugAssert(FCapturedLog == NULL);
  1584. if (Capture)
  1585. {
  1586. FCapturedLog = new TStringList();
  1587. OutputEvent = TerminalCaptureLog;
  1588. }
  1589. try
  1590. {
  1591. if (!RemoteCustomCommand.IsFileCommand(Command))
  1592. {
  1593. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1594. OutputEvent);
  1595. }
  1596. else
  1597. {
  1598. Terminal->CustomCommandOnFiles(Command, ACommand.Params, FileList, OutputEvent);
  1599. }
  1600. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1601. {
  1602. if (FLAGSET(ACommand.Params, ccCopyResults))
  1603. {
  1604. CopyToClipboard(FCapturedLog);
  1605. }
  1606. if (FLAGSET(ACommand.Params, ccShowResults))
  1607. {
  1608. DoConsoleDialog(Terminal, L"", FCapturedLog);
  1609. }
  1610. else if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox))
  1611. {
  1612. MessageDialog(FCapturedLog->Text, qtInformation, qaOK);
  1613. }
  1614. }
  1615. }
  1616. __finally
  1617. {
  1618. SAFE_DESTROY(FCapturedLog);
  1619. }
  1620. }
  1621. }
  1622. else
  1623. {
  1624. TLocalCustomCommand LocalCustomCommand(Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory());
  1625. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1626. &LocalCustomCommand, ACommand.Name, ACommand.HomePage);
  1627. UnicodeString Command = InteractiveCustomCommand.Complete(CommandCommand, false);
  1628. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  1629. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  1630. Configuration->Usage->Inc(L"LocalCustomCommandRuns2");
  1631. std::unique_ptr<UnicodeString> POutput;
  1632. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) ||
  1633. FLAGSET(ACommand.Params, ccCopyResults))
  1634. {
  1635. POutput.reset(new UnicodeString());
  1636. }
  1637. if (!LocalCustomCommand.IsFileCommand(Command))
  1638. {
  1639. ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  1640. }
  1641. // remote files?
  1642. else if ((FCurrentSide == osRemote) || LocalFileCommand)
  1643. {
  1644. TStrings * LocalFileList = NULL;
  1645. TStrings * RemoteFileList = NULL;
  1646. try
  1647. {
  1648. if (LocalFileCommand)
  1649. {
  1650. if (ALocalFileList == NULL)
  1651. {
  1652. DebugAssert(HasDirView[osLocal]);
  1653. // Cannot have focus on both panels, so we have to call AnyFileSelected
  1654. // directly (instead of EnableSelectedOperation) to pass
  1655. // false to FocusedFileOnlyWhenFocused
  1656. DebugAssert(DirView(osLocal)->AnyFileSelected(false, false, false));
  1657. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1658. }
  1659. else
  1660. {
  1661. LocalFileList = ALocalFileList;
  1662. }
  1663. if (FileListCommand)
  1664. {
  1665. if (LocalFileList->Count != 1)
  1666. {
  1667. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1668. }
  1669. }
  1670. else
  1671. {
  1672. if ((LocalFileList->Count != 1) &&
  1673. (FileList->Count != 1) &&
  1674. (LocalFileList->Count != FileList->Count))
  1675. {
  1676. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1677. }
  1678. }
  1679. }
  1680. UnicodeString RootTempDir;
  1681. UnicodeString TempDir;
  1682. bool RemoteFiles = FLAGSET(ACommand.Params, ccRemoteFiles);
  1683. if (!RemoteFiles)
  1684. {
  1685. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, true);
  1686. }
  1687. try
  1688. {
  1689. TDateTimes RemoteFileTimes;
  1690. if (RemoteFiles)
  1691. {
  1692. RemoteFileList = FileList;
  1693. }
  1694. else
  1695. {
  1696. RemoteFileList = new TStringList();
  1697. TMakeLocalFileListParams MakeFileListParam;
  1698. MakeFileListParam.FileList = RemoteFileList;
  1699. MakeFileListParam.FileTimes = &RemoteFileTimes;
  1700. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1701. MakeFileListParam.Recursive =
  1702. FLAGSET(ACommand.Params, ccRecursive) && !FileListCommand;
  1703. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1704. }
  1705. bool NonBlocking = FileListCommand && RemoteFiles && !POutput;
  1706. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1707. if (!NonBlocking)
  1708. {
  1709. Progress.Start(foCustomCommand, osRemote, FileListCommand ? 1 : FileList->Count);
  1710. DebugAssert(FProgressForm != NULL);
  1711. FProgressForm->ReadOnly = true;
  1712. }
  1713. try
  1714. {
  1715. if (FileListCommand)
  1716. {
  1717. UnicodeString LocalFile;
  1718. // MakeFileList does not delimit filenames
  1719. UnicodeString FileList = MakeFileList(RemoteFileList);
  1720. if (LocalFileCommand)
  1721. {
  1722. DebugAssert(LocalFileList->Count == 1);
  1723. LocalFile = LocalFileList->Strings[0];
  1724. }
  1725. TLocalCustomCommand CustomCommand(Data,
  1726. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), L"", LocalFile, FileList);
  1727. UnicodeString ShellCommand = CustomCommand.Complete(Command, true);
  1728. if (NonBlocking)
  1729. {
  1730. DebugAssert(!POutput);
  1731. ExecuteShellChecked(ShellCommand);
  1732. }
  1733. else
  1734. {
  1735. ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput.get());
  1736. }
  1737. }
  1738. else if (LocalFileCommand)
  1739. {
  1740. if (LocalFileList->Count == 1)
  1741. {
  1742. UnicodeString LocalFile = LocalFileList->Strings[0];
  1743. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1744. {
  1745. UnicodeString FileName = RemoteFileList->Strings[Index];
  1746. TLocalCustomCommand CustomCommand(Data,
  1747. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
  1748. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  1749. }
  1750. }
  1751. else if (RemoteFileList->Count == 1)
  1752. {
  1753. UnicodeString FileName = RemoteFileList->Strings[0];
  1754. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1755. {
  1756. TLocalCustomCommand CustomCommand(
  1757. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1758. FileName, LocalFileList->Strings[Index], L"");
  1759. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  1760. }
  1761. }
  1762. else
  1763. {
  1764. if (LocalFileList->Count != RemoteFileList->Count)
  1765. {
  1766. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1767. }
  1768. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1769. {
  1770. UnicodeString FileName = RemoteFileList->Strings[Index];
  1771. TLocalCustomCommand CustomCommand(
  1772. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1773. FileName, LocalFileList->Strings[Index], L"");
  1774. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  1775. }
  1776. }
  1777. }
  1778. else
  1779. {
  1780. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1781. {
  1782. TLocalCustomCommand CustomCommand(Data,
  1783. Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1784. RemoteFileList->Strings[Index], L"", L"");
  1785. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  1786. }
  1787. }
  1788. }
  1789. __finally
  1790. {
  1791. if (!NonBlocking)
  1792. {
  1793. Progress.Stop();
  1794. }
  1795. }
  1796. DebugAssert(!FAutoOperation);
  1797. if (!RemoteFiles)
  1798. {
  1799. TempDir = IncludeTrailingBackslash(TempDir);
  1800. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1801. {
  1802. UnicodeString FileName = RemoteFileList->Strings[Index];
  1803. if (DebugAlwaysTrue(SameText(TempDir, FileName.SubString(1, TempDir.Length()))) &&
  1804. // Skip directories for now, they require recursion,
  1805. // and we do not have original nested files times available here yet.
  1806. // The check is redundant as FileAge fails for directories anyway.
  1807. !DirectoryExists(FileName))
  1808. {
  1809. UnicodeString RemoteDir =
  1810. UnixExtractFileDir(
  1811. UnixIncludeTrailingBackslash(FTerminal->CurrentDirectory) +
  1812. ToUnixPath(FileName.SubString(TempDir.Length() + 1, FileName.Length() - TempDir.Length())));
  1813. TDateTime NewTime;
  1814. if (FileAge(FileName, NewTime) &&
  1815. (NewTime != RemoteFileTimes[Index]))
  1816. {
  1817. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  1818. TemporaryFileCopyParam(CopyParam);
  1819. CopyParam.FileMask = L"";
  1820. FAutoOperation = true;
  1821. std::unique_ptr<TStrings> TemporaryFilesList(new TStringList());
  1822. TemporaryFilesList->Add(FileName);
  1823. FTerminal->CopyToRemote(TemporaryFilesList.get(), RemoteDir, &CopyParam, cpTemporary);
  1824. }
  1825. }
  1826. }
  1827. }
  1828. }
  1829. __finally
  1830. {
  1831. FAutoOperation = false;
  1832. if (!RootTempDir.IsEmpty() && DebugAlwaysTrue(!RemoteFiles))
  1833. {
  1834. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  1835. }
  1836. }
  1837. }
  1838. __finally
  1839. {
  1840. if (RemoteFileList != FileList)
  1841. {
  1842. delete RemoteFileList;
  1843. }
  1844. if (LocalFileList != ALocalFileList)
  1845. {
  1846. delete LocalFileList;
  1847. }
  1848. }
  1849. }
  1850. // local files
  1851. else
  1852. {
  1853. std::unique_ptr<TStrings> SelectedFileList(DirView(osLocal)->CreateFileList(false, true, NULL));
  1854. std::unique_ptr<TStrings> LocalFileList(new TStringList());
  1855. for (int Index = 0; Index < SelectedFileList->Count; Index++)
  1856. {
  1857. UnicodeString FileName = SelectedFileList->Strings[Index];
  1858. if (DirectoryExists(FileName))
  1859. {
  1860. if (FLAGSET(ACommand.Params, ccApplyToDirectories))
  1861. {
  1862. LocalFileList->Add(FileName);
  1863. }
  1864. if (FLAGSET(ACommand.Params, ccRecursive))
  1865. {
  1866. TMakeLocalFileListParams MakeFileListParam;
  1867. MakeFileListParam.FileList = LocalFileList.get();
  1868. MakeFileListParam.FileTimes = NULL;
  1869. MakeFileListParam.IncludeDirs = FLAGSET(ACommand.Params, ccApplyToDirectories);
  1870. MakeFileListParam.Recursive = true;
  1871. ProcessLocalDirectory(FileName, Terminal->MakeLocalFileList, &MakeFileListParam);
  1872. }
  1873. }
  1874. else
  1875. {
  1876. LocalFileList->Add(FileName);
  1877. }
  1878. }
  1879. if (FileListCommand)
  1880. {
  1881. UnicodeString FileList = MakeFileList(LocalFileList.get());
  1882. TLocalCustomCommand CustomCommand(
  1883. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1884. L"", L"", FileList);
  1885. ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  1886. }
  1887. else
  1888. {
  1889. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1890. Progress.Start(foCustomCommand, osRemote, FileListCommand ? 1 : LocalFileList->Count);
  1891. DebugAssert(FProgressForm != NULL);
  1892. FProgressForm->ReadOnly = true;
  1893. try
  1894. {
  1895. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1896. {
  1897. UnicodeString FileName = LocalFileList->Strings[Index];
  1898. TLocalCustomCommand CustomCommand(
  1899. Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
  1900. FileName, L"", L"");
  1901. ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
  1902. }
  1903. }
  1904. __finally
  1905. {
  1906. Progress.Stop();
  1907. }
  1908. }
  1909. }
  1910. if (POutput.get() != NULL)
  1911. {
  1912. // If the output is single-line, we do not want the trailing CRLF, as the CopyToClipboard(TStrings *) does
  1913. int P = POutput->Pos(sLineBreak);
  1914. if (P == POutput->Length() - static_cast<int>(strlen(sLineBreak)) + 1)
  1915. {
  1916. POutput->SetLength(P - 1);
  1917. }
  1918. // Copy even empty output to clipboard
  1919. if (FLAGSET(ACommand.Params, ccCopyResults))
  1920. {
  1921. CopyToClipboard(*POutput);
  1922. }
  1923. // But do not show an empty message box.
  1924. // This way the ShowResultsInMsgBox can be used to suppress a console window of commands with no output
  1925. if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
  1926. !POutput->IsEmpty())
  1927. {
  1928. TClipboardHandler ClipboardHandler;
  1929. ClipboardHandler.Text = *POutput;
  1930. TMessageParams Params;
  1931. TQueryButtonAlias Aliases[1];
  1932. Aliases[0].Button = qaRetry;
  1933. Aliases[0].Alias = LoadStr(URL_LINK_COPY); // misuse
  1934. Aliases[0].OnClick = &ClipboardHandler.Copy;
  1935. Params.Aliases = Aliases;
  1936. Params.AliasesCount = LENOF(Aliases);
  1937. MessageDialog(*POutput, qtInformation, qaOK | qaRetry, HelpKeyword, &Params);
  1938. }
  1939. }
  1940. }
  1941. }
  1942. //---------------------------------------------------------------------------
  1943. void __fastcall TCustomScpExplorerForm::BothCustomCommand(
  1944. const TCustomCommandType & Command)
  1945. {
  1946. DebugAssert(FCustomCommandLocalFileList != NULL);
  1947. DebugAssert(FCustomCommandRemoteFileList != NULL);
  1948. DebugAssert(FCustomCommandLocalFileList->Count == FCustomCommandRemoteFileList->Count);
  1949. TStrings * LocalFileList = new TStringList();
  1950. TStrings * RemoteFileList = new TStringList();
  1951. try
  1952. {
  1953. for (int Index = 0; Index < FCustomCommandLocalFileList->Count; Index++)
  1954. {
  1955. LocalFileList->Clear();
  1956. LocalFileList->AddObject(
  1957. FCustomCommandLocalFileList->Strings[Index],
  1958. FCustomCommandLocalFileList->Objects[Index]);
  1959. RemoteFileList->Clear();
  1960. RemoteFileList->AddObject(
  1961. FCustomCommandRemoteFileList->Strings[Index],
  1962. FCustomCommandRemoteFileList->Objects[Index]);
  1963. CustomCommand(RemoteFileList, Command, LocalFileList);
  1964. }
  1965. }
  1966. __finally
  1967. {
  1968. delete LocalFileList;
  1969. delete RemoteFileList;
  1970. }
  1971. }
  1972. //---------------------------------------------------------------------------
  1973. void __fastcall TCustomScpExplorerForm::CustomCommandMenu(
  1974. TAction * Action, TStrings * LocalFileList, TStrings * RemoteFileList)
  1975. {
  1976. delete FCustomCommandLocalFileList;
  1977. delete FCustomCommandRemoteFileList;
  1978. // takeover ownership,
  1979. // the lists must survive the MenuPopup as OnClick occurs only after it exits
  1980. FCustomCommandLocalFileList = LocalFileList;
  1981. FCustomCommandRemoteFileList = RemoteFileList;
  1982. TButton * Button = dynamic_cast<TButton *>(Action->ActionComponent);
  1983. if (Button != NULL)
  1984. {
  1985. FCustomCommandMenu->Items->Clear();
  1986. NonVisualDataModule->CreateCustomCommandsMenu(FCustomCommandMenu->Items, false, false, ccltBoth);
  1987. MenuPopup(FCustomCommandMenu, Button);
  1988. }
  1989. else
  1990. {
  1991. NonVisualDataModule->CreateCustomCommandsMenu(Action, false, ccltBoth);
  1992. }
  1993. }
  1994. //---------------------------------------------------------------------------
  1995. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  1996. const UnicodeString & AddedLine, TCaptureOutputType OutputType)
  1997. {
  1998. DebugAssert(FCapturedLog != NULL);
  1999. if ((OutputType == cotOutput) || (OutputType == cotError))
  2000. {
  2001. FCapturedLog->Add(AddedLine);
  2002. }
  2003. }
  2004. //---------------------------------------------------------------------------
  2005. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  2006. TOperationSide Side)
  2007. {
  2008. return (Side == osRemote) &&
  2009. ((Control == RemoteDirView) || (Control == RemoteDriveView));
  2010. }
  2011. //---------------------------------------------------------------------------
  2012. void __fastcall TCustomScpExplorerForm::DirViewContextPopupDefaultItem(
  2013. TOperationSide Side, TTBXCustomItem * Item, TDoubleClickAction DoubleClickAction)
  2014. {
  2015. TTBItemOptions O;
  2016. O = Item->Options;
  2017. TCustomDirView * DView = DirView(Side);
  2018. if ((DView->ItemFocused != NULL) &&
  2019. (WinConfiguration->DoubleClickAction == DoubleClickAction) &&
  2020. // when resolving links is disabled, default action is to enter the directory,
  2021. // no matter what DoubleClickAction is configured to
  2022. ((Side != osRemote) || Terminal->ResolvingSymlinks) &&
  2023. // Can only Edit files, but can Open/Copy even directories
  2024. ((DoubleClickAction != dcaEdit) ||
  2025. !DView->ItemIsDirectory(DView->ItemFocused)))
  2026. {
  2027. Item->Options = O << tboDefault;
  2028. }
  2029. else
  2030. {
  2031. Item->Options = O >> tboDefault;
  2032. }
  2033. }
  2034. //---------------------------------------------------------------------------
  2035. void __fastcall TCustomScpExplorerForm::DirViewContextPopup(
  2036. TOperationSide Side, Byte PopupComponent, const TPoint &MousePos)
  2037. {
  2038. TCustomDirView * DView = DirView(Side);
  2039. TListItem * Item = DView->ItemFocused;
  2040. if ((DView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  2041. EnableFocusedOperation[Side])
  2042. {
  2043. TPoint ClientPoint;
  2044. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  2045. TPoint(0, 0) : MousePos;
  2046. FLastContextPopupScreenPoint = DView->ClientToScreen(ClientPoint);
  2047. reinterpret_cast<TPopupMenu*>(GetComponent(PopupComponent))->Popup(
  2048. FLastContextPopupScreenPoint.x, FLastContextPopupScreenPoint.y);
  2049. }
  2050. }
  2051. //---------------------------------------------------------------------------
  2052. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  2053. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  2054. {
  2055. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteOpenMenuItem, dcaOpen);
  2056. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteEditMenuItem, dcaEdit);
  2057. DirViewContextPopupDefaultItem(osRemote, NonVisualDataModule->RemoteCopyMenuItem, dcaCopy);
  2058. DirViewContextPopup(osRemote, fcRemotePopup, MousePos);
  2059. Handled = true;
  2060. }
  2061. //---------------------------------------------------------------------------
  2062. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const UnicodeString Directory)
  2063. {
  2064. }
  2065. //---------------------------------------------------------------------------
  2066. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  2067. {
  2068. DebugAssert(FErrorList == NULL);
  2069. if (WinConfiguration->ContinueOnError)
  2070. {
  2071. FErrorList = new TStringList();
  2072. Configuration->Usage->Inc(L"ContinuationsOnError");
  2073. }
  2074. NonVisualDataModule->StartBusy();
  2075. }
  2076. //---------------------------------------------------------------------------
  2077. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  2078. {
  2079. NonVisualDataModule->EndBusy();
  2080. if (FErrorList)
  2081. {
  2082. HandleErrorList(FErrorList);
  2083. }
  2084. }
  2085. //---------------------------------------------------------------------------
  2086. void __fastcall TCustomScpExplorerForm::UpdateCopyParamCounters(
  2087. const TCopyParamType & CopyParam)
  2088. {
  2089. if (!CopyParam.IncludeFileMask.Masks.IsEmpty())
  2090. {
  2091. Configuration->Usage->Inc(L"FileMaskUses");
  2092. }
  2093. if (IsEffectiveFileNameMask(CopyParam.FileMask))
  2094. {
  2095. Configuration->Usage->Inc(L"OperationMaskUses");
  2096. }
  2097. }
  2098. //---------------------------------------------------------------------------
  2099. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2100. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  2101. {
  2102. void * BatchStorage;
  2103. BatchStart(BatchStorage);
  2104. bool Result;
  2105. try
  2106. {
  2107. if ((Operation == foCopy) || (Operation == foMove))
  2108. {
  2109. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  2110. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  2111. UnicodeString TargetDirectory;
  2112. bool Temp = false;
  2113. bool DragDrop = false;
  2114. int Options = 0;
  2115. TAutoSwitch UseQueue = asAuto;
  2116. if (Param != NULL)
  2117. {
  2118. TTransferOperationParam& TParam =
  2119. *static_cast<TTransferOperationParam*>(Param);
  2120. TargetDirectory = TParam.TargetDirectory;
  2121. Temp = TParam.Temp;
  2122. DragDrop = TParam.DragDrop;
  2123. Options = TParam.Options;
  2124. UseQueue = TParam.Queue;
  2125. }
  2126. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2127. switch (UseQueue)
  2128. {
  2129. case asOn:
  2130. CopyParam.Queue = true;
  2131. break;
  2132. case asOff:
  2133. CopyParam.Queue = false;
  2134. break;
  2135. case asAuto:
  2136. default:
  2137. // keep default
  2138. break;
  2139. }
  2140. Result =
  2141. CopyParamDialog(Direction, Type, Temp, FileList, TargetDirectory,
  2142. CopyParam, !NoConfirmation, DragDrop, Options);
  2143. if (Result)
  2144. {
  2145. DebugAssert(Terminal);
  2146. bool SelectionRestored = false;
  2147. TCustomDirView * DView = NULL;
  2148. if (HasDirView[Side])
  2149. {
  2150. DView = DirView(Side);
  2151. DView->SaveSelection();
  2152. DView->SaveSelectedNames();
  2153. }
  2154. UpdateCopyParamCounters(CopyParam);
  2155. std::unique_ptr<TStringList> TransferResumeList(new TStringList());
  2156. DebugAssert(FTransferResumeList == NULL);
  2157. FTransferResumeList =
  2158. Terminal->IsCapable[fcMoveToQueue] ? TransferResumeList.get() : NULL;
  2159. FMoveToQueue = false;
  2160. int Params = FLAGMASK(Operation == foMove, cpDelete);
  2161. try
  2162. {
  2163. TStrings * PermanentFileList;
  2164. std::unique_ptr<TStrings> PermanentFileListOwner;
  2165. try
  2166. {
  2167. if (Side == osLocal)
  2168. {
  2169. PermanentFileList = FileList;
  2170. Params |= FLAGMASK(Temp, cpTemporary);
  2171. Terminal->CopyToRemote(FileList, TargetDirectory, &CopyParam, Params);
  2172. if (Operation == foMove)
  2173. {
  2174. ReloadLocalDirectory();
  2175. if (DView != NULL)
  2176. {
  2177. DView->RestoreSelection();
  2178. }
  2179. SelectionRestored = true;
  2180. }
  2181. }
  2182. else
  2183. {
  2184. // Clone the file list as it may refer to current directory files,
  2185. // which get destroyed, when the source directory is reloaded after foMove operation.
  2186. // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
  2187. // But for a hotfix, we are not going to do such a big change.
  2188. PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
  2189. PermanentFileList = PermanentFileListOwner.get();
  2190. try
  2191. {
  2192. Terminal->CopyToLocal(FileList, TargetDirectory, &CopyParam,
  2193. Params);
  2194. }
  2195. __finally
  2196. {
  2197. if (Operation == foMove)
  2198. {
  2199. if (DView != NULL)
  2200. {
  2201. DView->RestoreSelection();
  2202. }
  2203. SelectionRestored = true;
  2204. }
  2205. ReloadLocalDirectory(TargetDirectory);
  2206. }
  2207. }
  2208. }
  2209. catch (EAbort &)
  2210. {
  2211. if (FMoveToQueue)
  2212. {
  2213. Params |=
  2214. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0);
  2215. DebugAssert(CopyParam.TransferSkipList == NULL);
  2216. DebugAssert(CopyParam.TransferResumeFile.IsEmpty());
  2217. if (TransferResumeList->Count > 0)
  2218. {
  2219. CopyParam.TransferResumeFile = TransferResumeList->Strings[TransferResumeList->Count - 1];
  2220. TransferResumeList->Delete(TransferResumeList->Count - 1);
  2221. }
  2222. CopyParam.TransferSkipList = TransferResumeList.release();
  2223. // not really needed, just to keep it consistent with TransferResumeList
  2224. FTransferResumeList = NULL;
  2225. FMoveToQueue = false;
  2226. Configuration->Usage->Inc("MovesToBackground");
  2227. AddQueueItem(Queue, Direction, PermanentFileList, TargetDirectory, CopyParam, Params);
  2228. ClearTransferSourceSelection(Direction);
  2229. }
  2230. throw;
  2231. }
  2232. }
  2233. __finally
  2234. {
  2235. if (!SelectionRestored && (DView != NULL))
  2236. {
  2237. DView->DiscardSavedSelection();
  2238. }
  2239. FTransferResumeList = NULL;
  2240. }
  2241. }
  2242. }
  2243. else if (Operation == foRename)
  2244. {
  2245. DebugAssert(DirView(Side)->ItemFocused);
  2246. DirView(Side)->ItemFocused->EditCaption();
  2247. Result = true;
  2248. }
  2249. else if (Operation == foDelete)
  2250. {
  2251. DebugAssert(FileList->Count);
  2252. // We deliberately do not toggle alternative flag (Param), but use OR,
  2253. // because the Param is set only when command is invoked using Shift-Del/F8 keyboard
  2254. // shortcut of CurrentDeleteAlternativeAction
  2255. bool Alternative =
  2256. bool(Param) || UseAlternativeFunction();
  2257. bool Recycle;
  2258. if (Side == osLocal)
  2259. {
  2260. Recycle = (WinConfiguration->DeleteToRecycleBin != Alternative);
  2261. }
  2262. else
  2263. {
  2264. Recycle = (Terminal->SessionData->DeleteToRecycleBin != Alternative) &&
  2265. !Terminal->SessionData->RecycleBinPath.IsEmpty() &&
  2266. !Terminal->IsRecycledFile(FileList->Strings[0]);
  2267. }
  2268. Result =
  2269. !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  2270. if (!Result)
  2271. {
  2272. UnicodeString Query;
  2273. if (FileList->Count == 1)
  2274. {
  2275. if (Side == osLocal)
  2276. {
  2277. Query = ExtractFileName(FileList->Strings[0]);
  2278. }
  2279. else
  2280. {
  2281. Query = UnixExtractFileName(FileList->Strings[0]);
  2282. }
  2283. Query = FMTLOAD(
  2284. (Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  2285. }
  2286. else
  2287. {
  2288. Query = FMTLOAD(
  2289. (Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  2290. }
  2291. TMessageParams Params(mpNeverAskAgainCheck);
  2292. Params.ImageName = L"Delete file";
  2293. unsigned int Answer = MessageDialog(MainInstructions(Query), qtConfirmation,
  2294. qaOK | qaCancel, HELP_DELETE_FILE, &Params);
  2295. if (Answer == qaNeverAskAgain)
  2296. {
  2297. Result = true;
  2298. if (Recycle)
  2299. {
  2300. WinConfiguration->ConfirmRecycling = false;
  2301. }
  2302. else
  2303. {
  2304. WinConfiguration->ConfirmDeleting = false;
  2305. }
  2306. }
  2307. else
  2308. {
  2309. Result = (Answer == qaOK);
  2310. }
  2311. }
  2312. if (Result)
  2313. {
  2314. DeleteFiles(Side, FileList, FLAGMASK(Alternative, dfAlternative));
  2315. }
  2316. }
  2317. else if (Operation == foSetProperties)
  2318. {
  2319. RemoteDirView->SaveSelectedNames();
  2320. Result = SetProperties(Side, FileList);
  2321. }
  2322. else if (Operation == foCustomCommand)
  2323. {
  2324. DebugAssert(Param);
  2325. DebugAssert(Side == osRemote);
  2326. RemoteDirView->SaveSelectedNames();
  2327. const TCustomCommandType * Command = static_cast<const TCustomCommandType*>(Param);
  2328. CustomCommand(FileList, *Command, NULL);
  2329. Result = true;
  2330. }
  2331. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  2332. {
  2333. DebugAssert(Side == osRemote);
  2334. Result = RemoteTransferFiles(FileList, NoConfirmation,
  2335. (Operation == foRemoteMove), reinterpret_cast<TTerminal *>(Param));
  2336. }
  2337. else if (Operation == foLock)
  2338. {
  2339. DebugAssert(Side == osRemote);
  2340. LockFiles(FileList, true);
  2341. Result = true;
  2342. }
  2343. else if (Operation == foUnlock)
  2344. {
  2345. DebugAssert(Side == osRemote);
  2346. LockFiles(FileList, false);
  2347. Result = true;
  2348. }
  2349. else
  2350. {
  2351. DebugFail();
  2352. }
  2353. }
  2354. __finally
  2355. {
  2356. BatchEnd(BatchStorage);
  2357. }
  2358. return Result;
  2359. }
  2360. //---------------------------------------------------------------------------
  2361. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  2362. {
  2363. if (Side == osCurrent)
  2364. {
  2365. Side = FCurrentSide;
  2366. }
  2367. return Side;
  2368. }
  2369. //---------------------------------------------------------------------------
  2370. bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  2371. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  2372. {
  2373. Side = GetSide(Side);
  2374. bool Result;
  2375. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, (Side == osLocal), NULL);
  2376. try
  2377. {
  2378. Result = ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  2379. }
  2380. __finally
  2381. {
  2382. delete FileList;
  2383. }
  2384. return Result;
  2385. }
  2386. //---------------------------------------------------------------------------
  2387. void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
  2388. TFileOperation Operation, TOperationSide Side, bool OnFocused,
  2389. bool NoConfirmation, void * Param)
  2390. {
  2391. if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
  2392. {
  2393. if ((Operation == foCopy) || (Operation == foMove))
  2394. {
  2395. if (GetSide(Side) == osLocal)
  2396. {
  2397. Configuration->Usage->Inc(L"UploadsCommand");
  2398. }
  2399. else
  2400. {
  2401. Configuration->Usage->Inc(L"DownloadsCommand");
  2402. }
  2403. }
  2404. }
  2405. }
  2406. //---------------------------------------------------------------------------
  2407. void __fastcall TCustomScpExplorerForm::ExecuteCopyOperationCommand(
  2408. TOperationSide Side, bool OnFocused, unsigned int Flags)
  2409. {
  2410. TTransferOperationParam Param;
  2411. if ((WinConfiguration->Interface != ifCommander) ||
  2412. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  2413. {
  2414. Flags &= ~cocShortCutHint;
  2415. }
  2416. TCustomDirView * DView = DirView(Side);
  2417. Param.Options =
  2418. FLAGMASK(FLAGSET(Flags, cocShortCutHint), coShortCutHint) |
  2419. FLAGMASK(SelectedAllFilesInDirView(DView), coAllFiles);
  2420. if (FLAGSET(Flags, cocQueue))
  2421. {
  2422. Param.Queue = asOn;
  2423. }
  2424. else if (FLAGSET(Flags, cocNonQueue))
  2425. {
  2426. Param.Queue = asOff;
  2427. }
  2428. ExecuteFileOperationCommand(foCopy, Side, OnFocused, false, &Param);
  2429. }
  2430. //---------------------------------------------------------------------------
  2431. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  2432. {
  2433. try
  2434. {
  2435. if (ErrorList->Count)
  2436. {
  2437. UnicodeString Message = MainInstructions(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)));
  2438. if (MessageDialog(Message, qtError,
  2439. qaOK | qaCancel, HELP_NONE) == qaOK)
  2440. {
  2441. unsigned int Answer;
  2442. int Index = 0;
  2443. do
  2444. {
  2445. DebugAssert(Index >= 0 && Index < ErrorList->Count);
  2446. TQueryButtonAlias Aliases[2];
  2447. Aliases[0].Button = qaYes;
  2448. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  2449. Aliases[1].Button = qaNo;
  2450. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  2451. TMessageParams Params;
  2452. Params.Aliases = Aliases;
  2453. Params.AliasesCount = LENOF(Aliases);
  2454. Answer = MoreMessageDialog(
  2455. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  2456. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  2457. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  2458. qaOK, HELP_NONE, &Params);
  2459. if (Answer == qaNo)
  2460. {
  2461. Index++;
  2462. }
  2463. if (Answer == qaYes)
  2464. {
  2465. Index--;
  2466. }
  2467. }
  2468. while (Answer != qaOK);
  2469. }
  2470. }
  2471. }
  2472. __finally
  2473. {
  2474. TStrings * List = ErrorList;
  2475. ErrorList = NULL;
  2476. for (int i = 0; i < List->Count; i++)
  2477. {
  2478. delete List->Objects[i];
  2479. }
  2480. delete List;
  2481. }
  2482. }
  2483. //---------------------------------------------------------------------------
  2484. void __fastcall TCustomScpExplorerForm::ExecuteRemoteFile(
  2485. const UnicodeString & FullFileName, TRemoteFile * File, TExecuteFileBy ExecuteFileBy)
  2486. {
  2487. // needed for checking filemasks, as there's no directory object
  2488. // associated with the file object
  2489. File->FullFileName = FullFileName;
  2490. TFileMasks::TParams MaskParams;
  2491. MaskParams.Size = File->Size;
  2492. MaskParams.Modification = File->Modification;
  2493. ExecuteFile(osRemote, ExecuteFileBy, NULL, FullFileName, File, MaskParams);
  2494. }
  2495. //---------------------------------------------------------------------------
  2496. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  2497. {
  2498. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2499. Side = GetSide(Side);
  2500. TCustomDirView * CurrentDirView = DirView(osCurrent);
  2501. TListItem * FocusedItem = CurrentDirView->ItemFocused;
  2502. UnicodeString Name;
  2503. if ((FocusedItem != NULL) && !CurrentDirView->ItemIsParentDirectory(FocusedItem))
  2504. {
  2505. Name = CurrentDirView->ItemFileName(FocusedItem);
  2506. }
  2507. else
  2508. {
  2509. Name = LoadStr(NEW_FILE);
  2510. }
  2511. UnicodeString Names = Name;
  2512. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[L"EditFile"]));
  2513. if (InputDialog(LoadStr(EDIT_FILE_CAPTION), LoadStr(EDIT_FILE_PROMPT), Names,
  2514. HELP_EDIT_NEW, History.get(), true))
  2515. {
  2516. while (!Names.IsEmpty())
  2517. {
  2518. Name = CutToChar(Names, FileMasksDelimiters[1], false);
  2519. CustomWinConfiguration->History[L"EditFile"] = History.get();
  2520. UnicodeString TargetFileName;
  2521. UnicodeString LocalFileName;
  2522. UnicodeString RootTempDir;
  2523. UnicodeString TempDir;
  2524. UnicodeString RemoteDirectory;
  2525. bool ExistingFile = false;
  2526. if (Side == osRemote)
  2527. {
  2528. Name = AbsolutePath(FTerminal->CurrentDirectory, Name);
  2529. TRemoteFile * File = NULL;
  2530. if (FTerminal->FileExists(Name, &File))
  2531. {
  2532. try
  2533. {
  2534. ExecuteRemoteFile(Name, File, efDefaultEditor);
  2535. ExistingFile = true;
  2536. }
  2537. __finally
  2538. {
  2539. delete File;
  2540. }
  2541. }
  2542. if (!ExistingFile)
  2543. {
  2544. RemoteDirectory = UnixExtractFilePath(Name);
  2545. TemporaryDirectoryForRemoteFiles(
  2546. RemoteDirectory, GUIConfiguration->CurrentCopyParam, TempDir, RootTempDir);
  2547. TargetFileName = UnixExtractFileName(Name);
  2548. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2549. LocalFileName = TempDir +
  2550. // We probably do not want to trim the VMS version here
  2551. FTerminal->ChangeFileName(&CopyParam, TargetFileName, osRemote, false);
  2552. }
  2553. }
  2554. else
  2555. {
  2556. if (ExtractFilePath(Name).IsEmpty())
  2557. {
  2558. LocalFileName = IncludeTrailingBackslash(DirView(Side)->PathName) + Name;
  2559. }
  2560. else
  2561. {
  2562. LocalFileName = ExpandFileName(Name);
  2563. }
  2564. TargetFileName = ExtractFileName(Name);
  2565. }
  2566. if (!ExistingFile)
  2567. {
  2568. if (!FileExists(ApiPath(LocalFileName)))
  2569. {
  2570. int File = FileCreate(ApiPath(LocalFileName));
  2571. if (File < 0)
  2572. {
  2573. if (!RootTempDir.IsEmpty())
  2574. {
  2575. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2576. }
  2577. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  2578. }
  2579. else
  2580. {
  2581. FileClose(File);
  2582. }
  2583. }
  2584. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  2585. const TEditorData * ExternalEditor = NULL;
  2586. TFileMasks::TParams MaskParams; // size not known
  2587. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  2588. false, MaskParams);
  2589. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  2590. ExternalEditor, RootTempDir, RemoteDirectory);
  2591. }
  2592. }
  2593. }
  2594. }
  2595. //---------------------------------------------------------------------------
  2596. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  2597. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor)
  2598. {
  2599. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2600. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2601. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2602. return
  2603. ((ExecuteFileBy == efInternalEditor)) ||
  2604. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->ExternalEditorText);
  2605. }
  2606. //---------------------------------------------------------------------------
  2607. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  2608. TExecuteFileBy ExecuteFileBy, UnicodeString FileName, UnicodeString OriginalFileName,
  2609. const TEditorData * ExternalEditor, UnicodeString LocalRootDirectory,
  2610. UnicodeString RemoteDirectory)
  2611. {
  2612. DebugAssert(!WinConfiguration->DisableOpenEdit);
  2613. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  2614. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  2615. DebugAssert(ExecuteFileBy != efDefaultEditor);
  2616. Side = GetSide(Side);
  2617. std::unique_ptr<TEditedFileData> Data(new TEditedFileData);
  2618. if (Side == osRemote)
  2619. {
  2620. Data->Terminal = Terminal;
  2621. Data->Queue = Queue;
  2622. Data->SessionData = CloneCurrentSessionData();
  2623. Data->ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  2624. Data->RemoteDirectory = RemoteDirectory;
  2625. Data->SessionName = Terminal->SessionData->SessionName;
  2626. Data->LocalRootDirectory = LocalRootDirectory;
  2627. Data->OriginalFileName = OriginalFileName;
  2628. Data->Command = L""; // will be changed later for external editor
  2629. }
  2630. if (ExecuteFileBy == efInternalEditor)
  2631. {
  2632. if (Side == osRemote)
  2633. {
  2634. UnicodeString Caption = UnixIncludeTrailingBackslash(RemoteDirectory) + OriginalFileName +
  2635. L" - " + Terminal->SessionData->SessionName;
  2636. TForm * Editor;
  2637. try
  2638. {
  2639. Editor = ShowEditorForm(FileName, this, FEditorManager->FileChanged,
  2640. FEditorManager->FileReload, FEditorManager->FileClosed,
  2641. SaveAllInternalEditors, AnyInternalEditorModified,
  2642. Caption, FStandaloneEditing, SessionColor);
  2643. }
  2644. catch(...)
  2645. {
  2646. if (!LocalRootDirectory.IsEmpty())
  2647. {
  2648. RecursiveDeleteFile(ExcludeTrailingBackslash(LocalRootDirectory), false);
  2649. }
  2650. throw;
  2651. }
  2652. FEditorManager->AddFileInternal(FileName, Data.release(), Editor);
  2653. }
  2654. else
  2655. {
  2656. DebugAssert(!FStandaloneEditing);
  2657. TForm * Editor =
  2658. ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
  2659. SaveAllInternalEditors, AnyInternalEditorModified,
  2660. L"", false, SessionColor);
  2661. FLocalEditors->Add(Editor);
  2662. }
  2663. }
  2664. else
  2665. {
  2666. HANDLE Process;
  2667. if (ExecuteFileBy == efExternalEditor)
  2668. {
  2669. UnicodeString Program, Params, Dir;
  2670. Data->Command = ExternalEditor->ExternalEditor;
  2671. ReformatFileNameCommand(Data->Command);
  2672. SplitCommand(Data->Command, Program, Params, Dir);
  2673. Params = ExpandFileNameCommand(Params, FileName);
  2674. Program = ExpandEnvironmentVariables(Program);
  2675. if (!ExecuteShell(Program, Params, Process))
  2676. {
  2677. throw EOSExtException(FMTLOAD(EDITOR_ERROR, (Program)));
  2678. }
  2679. }
  2680. else
  2681. {
  2682. DebugAssert(Side == osRemote);
  2683. if (!ExecuteShell(FileName, L"", Process))
  2684. {
  2685. throw EOSExtException(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  2686. }
  2687. }
  2688. if ((Side == osLocal) ||
  2689. ((ExecuteFileBy == efShell) &&
  2690. !WinConfiguration->Editor.SDIShellEditor) ||
  2691. ((ExecuteFileBy == efExternalEditor) &&
  2692. !ExternalEditor->SDIExternalEditor))
  2693. {
  2694. // no need for handle
  2695. if (Process != NULL)
  2696. {
  2697. DebugCheck(CloseHandle(Process));
  2698. }
  2699. Process = INVALID_HANDLE_VALUE;
  2700. }
  2701. else
  2702. {
  2703. if (Process == NULL)
  2704. {
  2705. throw ExtException(LoadStr(OPEN_FILE_NO_PROCESS2), L"", HELP_OPEN_FILE_NO_PROCESS);
  2706. }
  2707. }
  2708. if (Side == osRemote)
  2709. {
  2710. FEditorManager->AddFileExternal(FileName, Data.release(), Process);
  2711. }
  2712. }
  2713. }
  2714. //---------------------------------------------------------------------------
  2715. void __fastcall TCustomScpExplorerForm::SaveInternalEditor(
  2716. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  2717. void * /*Arg*/)
  2718. {
  2719. if (Token != NULL)
  2720. {
  2721. EditorFormFileSave(static_cast<TForm *>(Token));
  2722. }
  2723. }
  2724. //---------------------------------------------------------------------------
  2725. void __fastcall TCustomScpExplorerForm::SaveAllInternalEditors(TObject * /*Sender*/)
  2726. {
  2727. for (int Index = 0; Index < FLocalEditors->Count; Index++)
  2728. {
  2729. EditorFormFileSave(static_cast<TForm *>(FLocalEditors->Items[Index]));
  2730. }
  2731. FEditorManager->ProcessFiles(SaveInternalEditor, NULL);
  2732. }
  2733. //---------------------------------------------------------------------------
  2734. void __fastcall TCustomScpExplorerForm::InternalEditorModified(
  2735. const UnicodeString /*FileName*/, TEditedFileData * /*Data*/, TObject * Token,
  2736. void * Arg)
  2737. {
  2738. if ((Token != NULL) &&
  2739. IsEditorFormModified(static_cast<TForm *>(Token)))
  2740. {
  2741. *static_cast<bool *>(Arg) = true;
  2742. }
  2743. }
  2744. //---------------------------------------------------------------------------
  2745. void __fastcall TCustomScpExplorerForm::AnyInternalEditorModified(
  2746. TObject * /*Sender*/, bool & Modified)
  2747. {
  2748. for (int Index = 0; !Modified && (Index < FLocalEditors->Count); Index++)
  2749. {
  2750. if (IsEditorFormModified(static_cast<TForm *>(FLocalEditors->Items[Index])))
  2751. {
  2752. Modified = true;
  2753. }
  2754. }
  2755. if (!Modified)
  2756. {
  2757. FEditorManager->ProcessFiles(InternalEditorModified, &Modified);
  2758. }
  2759. }
  2760. //---------------------------------------------------------------------------
  2761. void __fastcall TCustomScpExplorerForm::LocalEditorClosed(TObject * Sender, bool /*Forced*/)
  2762. {
  2763. DebugCheck(FLocalEditors->Extract(Sender) >= 0);
  2764. }
  2765. //---------------------------------------------------------------------------
  2766. void __fastcall TCustomScpExplorerForm::TemporaryDirectoryForRemoteFiles(
  2767. UnicodeString RemoteDirectory, TCopyParamType CopyParam,
  2768. UnicodeString & Result, UnicodeString & RootDirectory)
  2769. {
  2770. if (!WinConfiguration->TemporaryDirectoryDeterministic)
  2771. {
  2772. RootDirectory = IncludeTrailingBackslash(WinConfiguration->TemporaryDir());
  2773. Result = RootDirectory;
  2774. }
  2775. else
  2776. {
  2777. RootDirectory = L"";
  2778. Result = WinConfiguration->ExpandedTemporaryDirectory();
  2779. Result = IncludeTrailingBackslash(Result);
  2780. }
  2781. if (WinConfiguration->TemporaryDirectoryAppendSession)
  2782. {
  2783. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(Terminal->SessionData->SessionName));
  2784. }
  2785. if (WinConfiguration->TemporaryDirectoryAppendPath)
  2786. {
  2787. if (!RemoteDirectory.IsEmpty() && (RemoteDirectory[1] == L'/'))
  2788. {
  2789. RemoteDirectory.Delete(1, 1);
  2790. }
  2791. Result = IncludeTrailingBackslash(Result + CopyParam.ValidLocalPath(FromUnixPath(RemoteDirectory)));
  2792. }
  2793. if (!ForceDirectories(ApiPath(Result)))
  2794. {
  2795. throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (Result)));
  2796. }
  2797. }
  2798. //---------------------------------------------------------------------------
  2799. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  2800. TStrings * FileList, bool ForceText, UnicodeString & RootTempDir, UnicodeString & TempDir,
  2801. bool AllFiles, bool GetTargetNames, bool AutoOperation)
  2802. {
  2803. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2804. if (ForceText)
  2805. {
  2806. CopyParam.TransferMode = tmAscii;
  2807. }
  2808. TemporaryFileCopyParam(CopyParam);
  2809. if (AllFiles)
  2810. {
  2811. CopyParam.IncludeFileMask = TFileMasks();
  2812. }
  2813. if (TempDir.IsEmpty())
  2814. {
  2815. TemporaryDirectoryForRemoteFiles(FTerminal->CurrentDirectory, CopyParam, TempDir, RootTempDir);
  2816. }
  2817. DebugAssert(!FAutoOperation);
  2818. FAutoOperation = AutoOperation;
  2819. Terminal->ExceptionOnFail = true;
  2820. try
  2821. {
  2822. try
  2823. {
  2824. // turn off confirmations, as for MDI editors we may possibly download
  2825. // the same file over
  2826. Terminal->CopyToLocal(FileList, TempDir, &CopyParam,
  2827. cpNoConfirmation | cpTemporary);
  2828. if (GetTargetNames)
  2829. {
  2830. for (int i = 0; i < FileList->Count; i++)
  2831. {
  2832. FileList->Strings[i] =
  2833. Terminal->ChangeFileName(&CopyParam, UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  2834. }
  2835. }
  2836. }
  2837. catch(...)
  2838. {
  2839. if (!RootTempDir.IsEmpty())
  2840. {
  2841. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  2842. }
  2843. throw;
  2844. }
  2845. }
  2846. __finally
  2847. {
  2848. FAutoOperation = false;
  2849. Terminal->ExceptionOnFail = false;
  2850. }
  2851. }
  2852. //---------------------------------------------------------------------------
  2853. void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
  2854. {
  2855. // Do not waste time checking for default editor list the next time,
  2856. // or testing if default editor is not notepad.
  2857. bool TryNextTime = false;
  2858. UnicodeString UsageState;
  2859. if (!WinConfiguration->EditorList->IsDefaultList())
  2860. {
  2861. UsageState = "H";
  2862. }
  2863. else
  2864. {
  2865. UnicodeString Executable;
  2866. UnicodeString ExecutableDescription;
  2867. if (DetectSystemExternalEditor(false, Executable, ExecutableDescription, UsageState, TryNextTime))
  2868. {
  2869. UnicodeString Message =
  2870. FMTLOAD(EDITOR_AUTO_CONFIG2, (ExecutableDescription, ExecutableDescription));
  2871. unsigned int Answer =
  2872. MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_EDITOR_AUTO_CONFIG);
  2873. if (Answer != qaOK)
  2874. {
  2875. UsageState = "R";
  2876. }
  2877. else
  2878. {
  2879. UsageState = "A";
  2880. TEditorData EditorData;
  2881. EditorData.Editor = edExternal;
  2882. EditorData.ExternalEditor = FormatCommand(Executable, L"");
  2883. EditorData.DecideExternalEditorText();
  2884. TEditorList EditorList;
  2885. EditorList = *WinConfiguration->EditorList;
  2886. EditorList.Insert(0, new TEditorPreferences(EditorData));
  2887. WinConfiguration->EditorList = &EditorList;
  2888. }
  2889. }
  2890. }
  2891. WinConfiguration->OfferedEditorAutoConfig = !TryNextTime;
  2892. WinConfiguration->Usage->Set(L"EditorAutoConfig", UsageState);
  2893. }
  2894. //---------------------------------------------------------------------------
  2895. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  2896. TExecuteFileBy & ExecuteFileBy, const TEditorData *& ExternalEditor,
  2897. const UnicodeString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  2898. {
  2899. if (ExecuteFileBy == efDefaultEditor)
  2900. {
  2901. if (!WinConfiguration->OfferedEditorAutoConfig)
  2902. {
  2903. EditorAutoConfig();
  2904. }
  2905. const TEditorPreferences * Editor =
  2906. WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  2907. if ((Editor == NULL) || (Editor->Data->Editor == edInternal))
  2908. {
  2909. ExecuteFileBy = efInternalEditor;
  2910. ExternalEditor = NULL;
  2911. }
  2912. else if (Editor->Data->Editor == edOpen)
  2913. {
  2914. ExecuteFileBy = efShell;
  2915. ExternalEditor = NULL;
  2916. }
  2917. else
  2918. {
  2919. ExecuteFileBy = efExternalEditor;
  2920. ExternalEditor = Editor->Data;
  2921. }
  2922. }
  2923. }
  2924. //---------------------------------------------------------------------------
  2925. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  2926. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  2927. UnicodeString FullFileName, TObject * Object, const TFileMasks::TParams & MaskParams)
  2928. {
  2929. UnicodeString OriginalFileName;
  2930. UnicodeString LocalRootDirectory;
  2931. UnicodeString RemoteDirectory;
  2932. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  2933. (Side == osLocal), MaskParams);
  2934. UnicodeString Counter;
  2935. UnicodeString LocalFileName;
  2936. if (Side == osRemote)
  2937. {
  2938. // We need to trim VMS version here, so that we use name without version
  2939. // when uploading back to create a new version of the file
  2940. OriginalFileName = FTerminal->GetBaseFileName(UnixExtractFileName(FullFileName));
  2941. RemoteDirectory = UnixExtractFilePath(FullFileName);
  2942. TObject * Token = NULL;
  2943. UnicodeString LocalDirectory;
  2944. if (!FEditorManager->CanAddFile(RemoteDirectory, OriginalFileName,
  2945. Terminal->SessionData->SessionName, Token, LocalRootDirectory,
  2946. LocalDirectory))
  2947. {
  2948. if (Token != NULL)
  2949. {
  2950. TForm * Form = dynamic_cast<TForm *>(Token);
  2951. if (Form->WindowState == wsMinimized)
  2952. {
  2953. ShowWindow(Form->Handle, SW_RESTORE);
  2954. }
  2955. else
  2956. {
  2957. Form->SetFocus();
  2958. }
  2959. Abort();
  2960. }
  2961. else
  2962. {
  2963. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, (OriginalFileName)));
  2964. }
  2965. }
  2966. TStringList * FileList1 = new TStringList();
  2967. try
  2968. {
  2969. FileList1->AddObject(FullFileName, Object);
  2970. TemporarilyDownloadFiles(FileList1,
  2971. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor),
  2972. LocalRootDirectory, LocalDirectory, true, true, true);
  2973. LocalFileName = LocalDirectory + FileList1->Strings[0];
  2974. }
  2975. __finally
  2976. {
  2977. delete FileList1;
  2978. }
  2979. switch (ExecuteFileBy)
  2980. {
  2981. case efShell:
  2982. Counter = "RemoteFilesExecuted";
  2983. break;
  2984. case efInternalEditor:
  2985. Counter = "RemoteFilesOpenedInInternalEditor";
  2986. break;
  2987. case efExternalEditor:
  2988. Counter = "RemoteFilesOpenedInExternalEditor";
  2989. break;
  2990. default:
  2991. DebugFail();
  2992. }
  2993. }
  2994. else
  2995. {
  2996. LocalFileName = FullFileName;
  2997. OriginalFileName = ExtractFileName(FullFileName);
  2998. switch (ExecuteFileBy)
  2999. {
  3000. case efShell:
  3001. Counter = "LocalFilesExecuted";
  3002. break;
  3003. case efInternalEditor:
  3004. Counter = "LocalFilesOpenedInInternalEditor";
  3005. break;
  3006. case efExternalEditor:
  3007. Counter = "LocalFilesOpenedInExternalEditor";
  3008. break;
  3009. default:
  3010. DebugFail();
  3011. }
  3012. }
  3013. Configuration->Usage->Inc(Counter);
  3014. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, OriginalFileName,
  3015. ExternalEditor, LocalRootDirectory, RemoteDirectory);
  3016. }
  3017. //---------------------------------------------------------------------------
  3018. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  3019. TExecuteFileBy ExecuteFileBy, const TEditorData * ExternalEditor,
  3020. bool AllSelected, bool OnFocused)
  3021. {
  3022. DebugAssert(!WinConfiguration->DisableOpenEdit);
  3023. DebugAssert((ExecuteFileBy == efExternalEditor) ==
  3024. ((ExternalEditor != NULL) && (ExternalEditor->Editor == edExternal)));
  3025. Side = GetSide(Side);
  3026. TCustomDirView * DView = DirView(Side);
  3027. TStrings * FileList = AllSelected ?
  3028. DView->CreateFileList(OnFocused, Side == osLocal) :
  3029. DView->CreateFocusedFileList(Side == osLocal);
  3030. try
  3031. {
  3032. DebugAssert(AllSelected || (FileList->Count == 1));
  3033. for (int i = 0; i < FileList->Count; i++)
  3034. {
  3035. UnicodeString ListFileName = FileList->Strings[i];
  3036. UnicodeString FileNameOnly = (Side == osRemote) ?
  3037. UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  3038. TListItem * Item = DView->FindFileItem(FileNameOnly);
  3039. if (!DView->ItemIsDirectory(Item))
  3040. {
  3041. UnicodeString FullFileName;
  3042. if (Side == osRemote)
  3043. {
  3044. FullFileName = RemoteDirView->Path + ListFileName;
  3045. }
  3046. else
  3047. {
  3048. FullFileName = ListFileName;
  3049. }
  3050. TFileMasks::TParams MaskParams;
  3051. MaskParams.Size = DView->ItemFileSize(Item);
  3052. TDateTimePrecision Precision;
  3053. MaskParams.Modification = DView->ItemFileTime(Item, Precision);
  3054. ExecuteFile(Side, ExecuteFileBy, ExternalEditor, FullFileName,
  3055. FileList->Objects[i], MaskParams);
  3056. }
  3057. }
  3058. }
  3059. __finally
  3060. {
  3061. delete FileList;
  3062. }
  3063. }
  3064. //---------------------------------------------------------------------------
  3065. void __fastcall TCustomScpExplorerForm::TemporaryFileCopyParam(TCopyParamType & CopyParam)
  3066. {
  3067. // do not forget to add additional options to TemporarilyDownloadFiles, and AS
  3068. CopyParam.FileNameCase = ncNoChange;
  3069. CopyParam.PreserveRights = false;
  3070. CopyParam.PreserveReadOnly = false;
  3071. CopyParam.ReplaceInvalidChars = true;
  3072. CopyParam.IncludeFileMask = TFileMasks();
  3073. CopyParam.NewerOnly = false;
  3074. CopyParam.FileMask = L"";
  3075. }
  3076. //---------------------------------------------------------------------------
  3077. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const UnicodeString FileName,
  3078. TEditedFileData * Data, HANDLE UploadCompleteEvent)
  3079. {
  3080. TTerminalManager * Manager = TTerminalManager::Instance();
  3081. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3082. {
  3083. if (!NonVisualDataModule->Busy)
  3084. {
  3085. UnicodeString FileNameOnly = ExtractFileName(FileName);
  3086. UnicodeString EditInactiveSessionReopenAcceptedCounter = L"EditInactiveSessionReopenAccepted";
  3087. UnicodeString EditInactiveSessionReopenRejectedCounter = L"EditInactiveSessionReopenRejected";
  3088. if (Data->Terminal == NULL)
  3089. {
  3090. TTerminal * SameSiteTerminal = Manager->FindActiveTerminalForSite(Data->SessionData);
  3091. if (SameSiteTerminal != NULL)
  3092. {
  3093. UnicodeString Message =
  3094. FMTLOAD(EDIT_SESSION_REATTACH,
  3095. (FileNameOnly, Data->SessionName, FileNameOnly));
  3096. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3097. {
  3098. Data->Terminal = Terminal;
  3099. Data->Queue = Manager->FindQueueForTerminal(Terminal);
  3100. Data->SessionName = Terminal->SessionData->SessionName;
  3101. // We might also overwrite session data
  3102. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3103. }
  3104. else
  3105. {
  3106. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3107. Abort();
  3108. }
  3109. }
  3110. }
  3111. // foreground session should reconnect itself
  3112. else if (Terminal != Data->Terminal)
  3113. {
  3114. UnicodeString Message =
  3115. MainInstructions(
  3116. FMTLOAD(EDIT_SESSION_RECONNECT, (Data->SessionName, FileNameOnly)));
  3117. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel) == qaOK)
  3118. {
  3119. Manager->SetActiveTerminalWithAutoReconnect(Data->Terminal);
  3120. Configuration->Usage->Inc(EditInactiveSessionReopenAcceptedCounter);
  3121. }
  3122. else
  3123. {
  3124. Configuration->Usage->Inc(EditInactiveSessionReopenRejectedCounter);
  3125. Abort();
  3126. }
  3127. }
  3128. }
  3129. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3130. {
  3131. Configuration->Usage->Inc(L"EditInactiveSession");
  3132. // Prevent this when not idle (!NonVisualDataModule->Busy)?
  3133. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED2,
  3134. (ExtractFileName(FileName), Data->SessionName)));
  3135. }
  3136. }
  3137. TStrings * FileList = new TStringList();
  3138. try
  3139. {
  3140. FileList->Add(FileName);
  3141. // consider using the same settings (preset) as when the file was downloaded
  3142. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3143. TemporaryFileCopyParam(CopyParam);
  3144. if (Data->ForceText)
  3145. {
  3146. CopyParam.TransferMode = tmAscii;
  3147. }
  3148. // so i do not need to worry if masking algorithm works in all cases
  3149. // ("" means "copy file name", no masking is actually done)
  3150. if (ExtractFileName(FileName) == Data->OriginalFileName)
  3151. {
  3152. CopyParam.FileMask = L"";
  3153. }
  3154. else
  3155. {
  3156. CopyParam.FileMask = DelimitFileNameMask(Data->OriginalFileName);
  3157. }
  3158. DebugAssert(Data->Queue != NULL);
  3159. int Params = cpNoConfirmation | cpTemporary;
  3160. TQueueItem * QueueItem = new TUploadQueueItem(Data->Terminal, FileList,
  3161. Data->RemoteDirectory, &CopyParam, Params, true);
  3162. QueueItem->CompleteEvent = UploadCompleteEvent;
  3163. AddQueueItem(Data->Queue, QueueItem, Data->Terminal);
  3164. }
  3165. __finally
  3166. {
  3167. delete FileList;
  3168. }
  3169. }
  3170. //---------------------------------------------------------------------------
  3171. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  3172. const UnicodeString FileName, const TEditedFileData * Data)
  3173. {
  3174. // Sanity check, we should not be busy otherwise user would not be able to click Reload button.
  3175. DebugAssert(!NonVisualDataModule->Busy);
  3176. if ((Data->Terminal == NULL) || !Data->Terminal->Active)
  3177. {
  3178. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  3179. (ExtractFileName(FileName), Data->SessionName)));
  3180. }
  3181. TTerminal * PrevTerminal = TTerminalManager::Instance()->ActiveTerminal;
  3182. TTerminalManager::Instance()->ActiveTerminal = Data->Terminal;
  3183. NonVisualDataModule->StartBusy();
  3184. try
  3185. {
  3186. std::unique_ptr<TRemoteFile> File;
  3187. UnicodeString RemoteFileName =
  3188. UnixIncludeTrailingBackslash(Data->RemoteDirectory) + Data->OriginalFileName;
  3189. FTerminal->ExceptionOnFail = true;
  3190. try
  3191. {
  3192. TRemoteFile * AFile = NULL;
  3193. FTerminal->ReadFile(RemoteFileName, AFile);
  3194. File.reset(AFile);
  3195. if (!File->HaveFullFileName)
  3196. {
  3197. File->FullFileName = RemoteFileName;
  3198. }
  3199. }
  3200. __finally
  3201. {
  3202. FTerminal->ExceptionOnFail = false;
  3203. }
  3204. std::unique_ptr<TStrings> FileList(new TStringList());
  3205. FileList->AddObject(RemoteFileName, File.get());
  3206. UnicodeString RootTempDir = Data->LocalRootDirectory;
  3207. UnicodeString TempDir = ExtractFilePath(FileName);
  3208. TemporarilyDownloadFiles(FileList.get(), Data->ForceText, RootTempDir,
  3209. TempDir, true, true, true);
  3210. // sanity check, the target file name should be still the same
  3211. DebugAssert(ExtractFileName(FileName) == FileList->Strings[0]);
  3212. }
  3213. __finally
  3214. {
  3215. NonVisualDataModule->EndBusy();
  3216. // it actually may not exist anymore...
  3217. TTerminalManager::Instance()->ActiveTerminal = PrevTerminal;
  3218. }
  3219. }
  3220. //---------------------------------------------------------------------------
  3221. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  3222. const TEditedFileData * Data, bool & KeepOpen)
  3223. {
  3224. // Command is set for external editors only (not for "shell" open).
  3225. if (!Data->Command.IsEmpty())
  3226. {
  3227. bool AnyFound = false;
  3228. bool AnyMDI = false;
  3229. bool AnyNonMDI = false;
  3230. bool AnyDetect = false;
  3231. TEditorList * EditorList = new TEditorList();
  3232. try
  3233. {
  3234. *EditorList = *WinConfiguration->EditorList;
  3235. for (int i = 0; i < EditorList->Count; i++)
  3236. {
  3237. const TEditorPreferences * Editor = EditorList->Editors[i];
  3238. if ((Editor->Data->Editor == edExternal) &&
  3239. (Editor->Data->ExternalEditor == Data->Command))
  3240. {
  3241. AnyFound = true;
  3242. if (Editor->Data->SDIExternalEditor)
  3243. {
  3244. AnyNonMDI = true;
  3245. if (Editor->Data->DetectMDIExternalEditor)
  3246. {
  3247. AnyDetect = true;
  3248. }
  3249. }
  3250. else
  3251. {
  3252. AnyMDI = true;
  3253. }
  3254. }
  3255. }
  3256. bool EnableMDI = false;
  3257. bool DisableDetect = false;
  3258. if (AnyMDI)
  3259. {
  3260. KeepOpen = true;
  3261. if (AnyNonMDI)
  3262. {
  3263. // there is at least one instance of the editor with MDI support enabled,
  3264. // and one with disabled, enable it for all instances
  3265. EnableMDI = true;
  3266. }
  3267. }
  3268. else if (AnyFound && !AnyDetect)
  3269. {
  3270. // at least once instance found but all have MDI autodetection disabled
  3271. // => close the file (default action)
  3272. }
  3273. else
  3274. {
  3275. // no instance of the editor has MDI support enabled
  3276. TMessageParams Params;
  3277. if (AnyFound)
  3278. {
  3279. // there is at least one instance of the editor
  3280. Params.Params |= mpNeverAskAgainCheck;
  3281. }
  3282. unsigned int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED2, (Data->OriginalFileName)), qtWarning,
  3283. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  3284. switch (Answer)
  3285. {
  3286. case qaNeverAskAgain:
  3287. DisableDetect = true;
  3288. break;
  3289. case qaNo:
  3290. EnableMDI = true;
  3291. KeepOpen = true;
  3292. break;
  3293. }
  3294. }
  3295. if (AnyFound && (EnableMDI || DisableDetect))
  3296. {
  3297. bool Changed = false;
  3298. for (int i = 0; i < EditorList->Count; i++)
  3299. {
  3300. const TEditorPreferences * Editor = EditorList->Editors[i];
  3301. if ((Editor->Data->Editor == edExternal) &&
  3302. (Editor->Data->ExternalEditor == Data->Command) &&
  3303. ((EnableMDI && Editor->Data->SDIExternalEditor) ||
  3304. (DisableDetect && Editor->Data->DetectMDIExternalEditor)))
  3305. {
  3306. Changed = true;
  3307. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  3308. if (EnableMDI)
  3309. {
  3310. UpdatedEditor->GetData()->SDIExternalEditor = false;
  3311. }
  3312. if (DisableDetect)
  3313. {
  3314. UpdatedEditor->GetData()->DetectMDIExternalEditor = false;
  3315. }
  3316. EditorList->Change(i, UpdatedEditor);
  3317. }
  3318. }
  3319. if (Changed)
  3320. {
  3321. WinConfiguration->EditorList = EditorList;
  3322. }
  3323. }
  3324. }
  3325. __finally
  3326. {
  3327. delete EditorList;
  3328. }
  3329. }
  3330. else
  3331. {
  3332. // "open" case
  3333. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data->OriginalFileName)), qtWarning,
  3334. qaOK, HELP_APP_EARLY_CLOSED);
  3335. }
  3336. }
  3337. //---------------------------------------------------------------------------
  3338. void __fastcall TCustomScpExplorerForm::ExecutedFileUploadComplete(TObject * Sender)
  3339. {
  3340. EditorFormFileUploadComplete(DebugNotNull(dynamic_cast<TForm *>(Sender)));
  3341. }
  3342. //---------------------------------------------------------------------------
  3343. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  3344. {
  3345. SideEnter(osRemote);
  3346. }
  3347. //---------------------------------------------------------------------------
  3348. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  3349. {
  3350. MakeNextInTabOrder(RemoteDirView, RemoteDriveView);
  3351. SideEnter(osRemote);
  3352. }
  3353. //---------------------------------------------------------------------------
  3354. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  3355. {
  3356. FCurrentSide = Side;
  3357. if (Visible)
  3358. {
  3359. UpdateControls();
  3360. }
  3361. }
  3362. //---------------------------------------------------------------------------
  3363. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  3364. TStrings * FileList, bool Alternative)
  3365. {
  3366. DebugAssert(Terminal);
  3367. TCustomDirView * DView = DirView(Side);
  3368. DView->SaveSelection();
  3369. DView->SaveSelectedNames();
  3370. DebugAssert(!FAlternativeDelete);
  3371. FAlternativeDelete = Alternative;
  3372. try
  3373. {
  3374. if (Side == osRemote)
  3375. {
  3376. Terminal->DeleteFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3377. }
  3378. else
  3379. {
  3380. try
  3381. {
  3382. Terminal->DeleteLocalFiles(FileList, FLAGMASK(Alternative, dfAlternative));
  3383. }
  3384. __finally
  3385. {
  3386. ReloadLocalDirectory();
  3387. }
  3388. }
  3389. FAlternativeDelete = false;
  3390. }
  3391. catch(...)
  3392. {
  3393. FAlternativeDelete = false;
  3394. DView->DiscardSavedSelection();
  3395. throw;
  3396. }
  3397. DView->RestoreSelection();
  3398. }
  3399. //---------------------------------------------------------------------------
  3400. void __fastcall TCustomScpExplorerForm::LockFiles(TStrings * FileList, bool Lock)
  3401. {
  3402. DebugAssert(Terminal);
  3403. RemoteDirView->SaveSelection();
  3404. RemoteDirView->SaveSelectedNames();
  3405. try
  3406. {
  3407. if (Lock)
  3408. {
  3409. Terminal->LockFiles(FileList);
  3410. }
  3411. else
  3412. {
  3413. Terminal->UnlockFiles(FileList);
  3414. }
  3415. }
  3416. catch(...)
  3417. {
  3418. RemoteDirView->DiscardSavedSelection();
  3419. throw;
  3420. }
  3421. RemoteDirView->RestoreSelection();
  3422. }
  3423. //---------------------------------------------------------------------------
  3424. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TTerminal *& Session,
  3425. TStrings * FileList, UnicodeString & Target, UnicodeString & FileMask, bool & DirectCopy,
  3426. bool NoConfirmation, bool Move)
  3427. {
  3428. if (RemoteDriveView->DropTarget != NULL)
  3429. {
  3430. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  3431. }
  3432. else if (RemoteDirView->DropTarget != NULL)
  3433. {
  3434. DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  3435. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  3436. }
  3437. else
  3438. {
  3439. Target = RemoteDirView->Path;
  3440. }
  3441. if (Session == NULL)
  3442. {
  3443. Session = TTerminalManager::Instance()->ActiveTerminal;
  3444. }
  3445. Target = UnixIncludeTrailingBackslash(Target);
  3446. if (FileList->Count == 1)
  3447. {
  3448. FileMask = DelimitFileNameMask(UnixExtractFileName(FileList->Strings[0]));
  3449. }
  3450. else
  3451. {
  3452. FileMask = L"*.*";
  3453. }
  3454. DirectCopy = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  3455. bool Result = true;
  3456. if (!NoConfirmation)
  3457. {
  3458. bool Multi = (FileList->Count > 1);
  3459. if (Move)
  3460. {
  3461. Result = DoRemoteMoveDialog(Multi, Target, FileMask);
  3462. }
  3463. else
  3464. {
  3465. DebugAssert(Terminal != NULL);
  3466. // update Terminal->StateData->RemoteDirectory
  3467. UpdateTerminal(Terminal);
  3468. TStrings * Sessions = TTerminalManager::Instance()->TerminalList;
  3469. TStrings * Directories = new TStringList;
  3470. try
  3471. {
  3472. for (int Index = 0; Index < Sessions->Count; Index++)
  3473. {
  3474. TManagedTerminal * Terminal =
  3475. dynamic_cast<TManagedTerminal *>(Sessions->Objects[Index]);
  3476. Directories->Add(Terminal->StateData->RemoteDirectory);
  3477. }
  3478. TDirectRemoteCopy AllowDirectCopy;
  3479. if (FTerminal->IsCapable[fcRemoteCopy] || FTerminal->CommandSessionOpened)
  3480. {
  3481. DebugAssert(DirectCopy);
  3482. AllowDirectCopy = drcAllow;
  3483. }
  3484. else if (FTerminal->IsCapable[fcSecondaryShell])
  3485. {
  3486. DebugAssert(DirectCopy);
  3487. AllowDirectCopy = drcConfirmCommandSession;
  3488. }
  3489. else
  3490. {
  3491. DebugAssert(!DirectCopy);
  3492. AllowDirectCopy = drcDisallow;
  3493. }
  3494. void * ASession = Session;
  3495. Result = DoRemoteCopyDialog(Sessions, Directories, AllowDirectCopy,
  3496. Multi, ASession, Target, FileMask, DirectCopy, TTerminalManager::Instance()->ActiveTerminal);
  3497. Session = static_cast<TTerminal *>(ASession);
  3498. }
  3499. __finally
  3500. {
  3501. delete Directories;
  3502. }
  3503. }
  3504. }
  3505. return Result;
  3506. }
  3507. //---------------------------------------------------------------------------
  3508. bool __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  3509. TStrings * FileList, bool NoConfirmation, bool Move, TTerminal * Session)
  3510. {
  3511. bool DirectCopy;
  3512. UnicodeString Target, FileMask;
  3513. bool Result = RemoteTransferDialog(Session, FileList, Target, FileMask, DirectCopy, NoConfirmation, Move);
  3514. if (Result)
  3515. {
  3516. if (!Move && !DirectCopy)
  3517. {
  3518. Configuration->Usage->Inc("RemoteCopyTemp");
  3519. UnicodeString RootTempDir;
  3520. UnicodeString TempDir;
  3521. TemporarilyDownloadFiles(FileList, false, RootTempDir, TempDir, false, false, false);
  3522. TStrings * TemporaryFilesList = new TStringList();
  3523. try
  3524. {
  3525. TMakeLocalFileListParams MakeFileListParam;
  3526. MakeFileListParam.FileList = TemporaryFilesList;
  3527. MakeFileListParam.FileTimes = NULL;
  3528. MakeFileListParam.IncludeDirs = true;
  3529. MakeFileListParam.Recursive = false;
  3530. ProcessLocalDirectory(TempDir, FTerminal->MakeLocalFileList, &MakeFileListParam);
  3531. TTerminalManager::Instance()->ActiveTerminal = Session;
  3532. if (TemporaryFilesList->Count > 0)
  3533. {
  3534. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3535. CopyParam.FileMask = FileMask;
  3536. DebugAssert(!FAutoOperation);
  3537. FAutoOperation = true;
  3538. FTerminal->CopyToRemote(TemporaryFilesList, Target, &CopyParam, cpTemporary);
  3539. }
  3540. }
  3541. __finally
  3542. {
  3543. delete TemporaryFilesList;
  3544. FAutoOperation = false;
  3545. if (!RootTempDir.IsEmpty())
  3546. {
  3547. RecursiveDeleteFile(ExcludeTrailingBackslash(RootTempDir), false);
  3548. }
  3549. }
  3550. }
  3551. else
  3552. {
  3553. RemoteDirView->SaveSelection();
  3554. RemoteDirView->SaveSelectedNames();
  3555. try
  3556. {
  3557. if (Move)
  3558. {
  3559. Configuration->Usage->Inc("RemoteMove");
  3560. Terminal->MoveFiles(FileList, Target, FileMask);
  3561. }
  3562. else
  3563. {
  3564. Configuration->Usage->Inc("RemoteCopyDirect");
  3565. DebugAssert(DirectCopy);
  3566. DebugAssert(Session == FTerminal);
  3567. if (FTerminal->IsCapable[fcRemoteCopy] ||
  3568. FTerminal->CommandSessionOpened ||
  3569. CommandSessionFallback())
  3570. {
  3571. Terminal->CopyFiles(FileList, Target, FileMask);
  3572. }
  3573. }
  3574. }
  3575. catch(...)
  3576. {
  3577. RemoteDirView->DiscardSavedSelection();
  3578. throw;
  3579. }
  3580. RemoteDirView->RestoreSelection();
  3581. }
  3582. }
  3583. return Result;
  3584. }
  3585. //---------------------------------------------------------------------------
  3586. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  3587. {
  3588. Side = GetSide(Side);
  3589. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  3590. TRemoteProperties * AProperties = (Side == osRemote ? &Properties : NULL);
  3591. UnicodeString Name = LoadStr(NEW_FOLDER);
  3592. int AllowedChanges =
  3593. FLAGMASK(Terminal->IsCapable[fcModeChanging], cpMode);
  3594. bool SaveSettings = false;
  3595. if (DoCreateDirectoryDialog(Name, AProperties, AllowedChanges, SaveSettings))
  3596. {
  3597. TWindowLock Lock(this);
  3598. if (Side == osRemote)
  3599. {
  3600. if (SaveSettings)
  3601. {
  3602. GUIConfiguration->NewDirectoryProperties = Properties;
  3603. }
  3604. RemoteDirView->CreateDirectoryEx(Name, &Properties);
  3605. }
  3606. else
  3607. {
  3608. DirView(Side)->CreateDirectory(Name);
  3609. }
  3610. }
  3611. }
  3612. //---------------------------------------------------------------------------
  3613. void __fastcall TCustomScpExplorerForm::HomeDirectory(TOperationSide Side)
  3614. {
  3615. TWindowLock Lock(this);
  3616. DirView(Side)->ExecuteHomeDirectory();
  3617. }
  3618. //---------------------------------------------------------------------------
  3619. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  3620. {
  3621. DoOpenDirectoryDialog(odBrowse, Side);
  3622. }
  3623. //---------------------------------------------------------------------------
  3624. bool __fastcall TCustomScpExplorerForm::OpenBookmark(UnicodeString Local, UnicodeString Remote)
  3625. {
  3626. UnicodeString Path;
  3627. if (FCurrentSide == osRemote)
  3628. {
  3629. Path = Remote;
  3630. }
  3631. else
  3632. {
  3633. Path = Local;
  3634. }
  3635. bool Result = !Path.IsEmpty();
  3636. if (Result)
  3637. {
  3638. // While we might get here when the session is closed (from location profiles),
  3639. // it's not a problem as the Path setter is noop then
  3640. DirView(FCurrentSide)->Path = Path;
  3641. }
  3642. return Result;
  3643. }
  3644. //---------------------------------------------------------------------------
  3645. void __fastcall TCustomScpExplorerForm::RemoteDirViewGetSelectFilter(
  3646. TCustomDirView *Sender, bool Select, TFileFilter &Filter)
  3647. {
  3648. DebugAssert(Sender);
  3649. if (!DoSelectMaskDialog(Sender, Select, &Filter, Configuration)) Abort();
  3650. }
  3651. //---------------------------------------------------------------------------
  3652. void __fastcall TCustomScpExplorerForm::CalculateSize(
  3653. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  3654. bool & Close)
  3655. {
  3656. // terminal can be already closed (e.g. dropped connection)
  3657. if (Terminal != NULL)
  3658. {
  3659. try
  3660. {
  3661. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, true, &Stats);
  3662. }
  3663. catch(...)
  3664. {
  3665. if (!Terminal->Active)
  3666. {
  3667. Close = true;
  3668. }
  3669. throw;
  3670. }
  3671. }
  3672. }
  3673. //---------------------------------------------------------------------------
  3674. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const UnicodeString & Alg,
  3675. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  3676. bool & Close)
  3677. {
  3678. // terminal can be already closed (e.g. dropped connection)
  3679. if (Terminal != NULL)
  3680. {
  3681. Configuration->Usage->Inc(L"ChecksumCalculated");
  3682. try
  3683. {
  3684. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  3685. }
  3686. catch(...)
  3687. {
  3688. if (!Terminal->Active)
  3689. {
  3690. Close = true;
  3691. }
  3692. throw;
  3693. }
  3694. }
  3695. }
  3696. //---------------------------------------------------------------------------
  3697. bool __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  3698. {
  3699. bool Result;
  3700. if (Side == osRemote)
  3701. {
  3702. TRemoteTokenList * GroupList = NULL;
  3703. TRemoteTokenList * UserList = NULL;
  3704. try
  3705. {
  3706. TRemoteProperties CurrentProperties;
  3707. if (Terminal->LoadFilesProperties(FileList))
  3708. {
  3709. RemoteDirView->Invalidate();
  3710. }
  3711. bool CapableGroupChanging = Terminal->IsCapable[fcGroupChanging];
  3712. bool CapableOwnerChanging = Terminal->IsCapable[fcOwnerChanging];
  3713. if (CapableGroupChanging || CapableOwnerChanging)
  3714. {
  3715. if (CapableGroupChanging)
  3716. {
  3717. GroupList = Terminal->Groups->Duplicate();
  3718. }
  3719. if (CapableOwnerChanging)
  3720. {
  3721. UserList = Terminal->Users->Duplicate();
  3722. }
  3723. TRemoteDirectory * Files = Terminal->Files;
  3724. int Count = Files->Count;
  3725. if (Count > 100)
  3726. {
  3727. Count = 100;
  3728. }
  3729. for (int Index = 0; Index < Count; Index++)
  3730. {
  3731. TRemoteFile * File = Files->Files[Index];
  3732. if (CapableGroupChanging)
  3733. {
  3734. GroupList->AddUnique(File->Group);
  3735. }
  3736. if (CapableOwnerChanging)
  3737. {
  3738. UserList->AddUnique(File->Owner);
  3739. }
  3740. }
  3741. // if we haven't collected tokens for all files in current directory,
  3742. // make sure we collect them at least for all selected files.
  3743. // (note that so far the files in FileList has to be from current direcotry)
  3744. if (Count < Files->Count)
  3745. {
  3746. for (int Index = 0; Index < FileList->Count; Index++)
  3747. {
  3748. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  3749. if (CapableGroupChanging)
  3750. {
  3751. GroupList->AddUnique(File->Group);
  3752. }
  3753. if (CapableOwnerChanging)
  3754. {
  3755. UserList->AddUnique(File->Owner);
  3756. }
  3757. }
  3758. }
  3759. }
  3760. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  3761. int Flags = 0;
  3762. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  3763. if (CapableOwnerChanging) Flags |= cpOwner;
  3764. if (CapableGroupChanging) Flags |= cpGroup;
  3765. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  3766. if (Terminal->IsCapable[fcCalculatingChecksum])
  3767. {
  3768. CalculateChecksumEvent = CalculateChecksum;
  3769. }
  3770. std::unique_ptr<TStrings> ChecksumAlgs(new TStringList());
  3771. Terminal->GetSupportedChecksumAlgs(ChecksumAlgs.get());
  3772. TRemoteProperties NewProperties = CurrentProperties;
  3773. Result =
  3774. DoPropertiesDialog(FileList, RemoteDirView->PathName,
  3775. GroupList, UserList, ChecksumAlgs.get(), &NewProperties, Flags,
  3776. Terminal->IsCapable[fcGroupOwnerChangingByID],
  3777. CalculateSize, CalculateChecksumEvent);
  3778. if (Result)
  3779. {
  3780. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  3781. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  3782. }
  3783. }
  3784. __finally
  3785. {
  3786. delete GroupList;
  3787. delete UserList;
  3788. }
  3789. }
  3790. else
  3791. {
  3792. DirView(Side)->DisplayPropertiesMenu();
  3793. Result = true;
  3794. }
  3795. return Result;
  3796. }
  3797. //---------------------------------------------------------------------------
  3798. void __fastcall TCustomScpExplorerForm::KeyProcessed(Word & Key, TShiftState Shift)
  3799. {
  3800. if (Shift * AllKeyShiftStates() == (TShiftState() << ssAlt))
  3801. {
  3802. FIgnoreNextDialogChar = Key;
  3803. }
  3804. Key = 0;
  3805. }
  3806. //---------------------------------------------------------------------------
  3807. void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
  3808. TCustomCommandList * List, Word & Key, Classes::TShiftState Shift, TShortCut KeyShortCut)
  3809. {
  3810. const TCustomCommandType * Command = List->Find(KeyShortCut);
  3811. if (Command != NULL)
  3812. {
  3813. KeyProcessed(Key, Shift);
  3814. if (CustomCommandState(*Command, false, ccltAll) > 0)
  3815. {
  3816. ExecuteFileOperationCommand(foCustomCommand, osRemote,
  3817. false, false, const_cast<TCustomCommandType *>(Command));
  3818. }
  3819. }
  3820. }
  3821. //---------------------------------------------------------------------------
  3822. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  3823. {
  3824. if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
  3825. {
  3826. QueueView3->OnKeyDown(QueueView3, Key, Shift);
  3827. }
  3828. if (!DirView(osCurrent)->IsEditing())
  3829. {
  3830. TShortCut KeyShortCut = ShortCut(Key, Shift);
  3831. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  3832. {
  3833. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  3834. if (((Action->ShortCut == KeyShortCut) ||
  3835. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  3836. AllowedAction(Action, aaShortCut))
  3837. {
  3838. // Has to be called before the action as the dialog char is already in queue.
  3839. // So when the action consumes message queue, we already need to have the
  3840. // FIgnoreNextDialogChar set
  3841. KeyProcessed(Key, Shift);
  3842. // Reset reference to previous component (when menu/toolbar was clicked).
  3843. // Needed to detect that action was invoked by keyboard shortcut
  3844. // in TNonVisualDataModule::ExplorerActionsExecute
  3845. Action->ActionComponent = NULL;
  3846. Action->Execute();
  3847. return;
  3848. }
  3849. }
  3850. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  3851. {
  3852. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  3853. {
  3854. KeyProcessed(Key, Shift);
  3855. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  3856. return;
  3857. }
  3858. }
  3859. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  3860. {
  3861. KeyProcessed(Key, Shift);
  3862. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  3863. }
  3864. if (IsCustomShortCut(KeyShortCut))
  3865. {
  3866. CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, KeyShortCut);
  3867. CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, KeyShortCut);
  3868. if (WinConfiguration->SharedBookmarks != NULL)
  3869. {
  3870. TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(KeyShortCut);
  3871. if ((Bookmark != NULL) &&
  3872. OpenBookmark(Bookmark->Local, Bookmark->Remote))
  3873. {
  3874. KeyProcessed(Key, Shift);
  3875. }
  3876. }
  3877. }
  3878. }
  3879. TForm::KeyDown(Key, Shift);
  3880. }
  3881. //---------------------------------------------------------------------------
  3882. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  3883. {
  3884. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  3885. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  3886. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  3887. DebugAssert(Terminal);
  3888. int Offset = SessionStatusBar->Panels->Count - SessionPanelCount;
  3889. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  3890. SessionStatusBar->Panels->Items[Offset + 0]->Enabled = SecurityEnabled;
  3891. // expanded from ?: to avoid memory leaks
  3892. if (SecurityEnabled)
  3893. {
  3894. SessionStatusBar->Panels->Items[Offset + 0]->Hint =
  3895. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  3896. }
  3897. else
  3898. {
  3899. SessionStatusBar->Panels->Items[Offset + 0]->Hint = LoadStr(STATUS_INSECURE);
  3900. }
  3901. if (FileSystemInfo.ProtocolName.IsEmpty())
  3902. {
  3903. SessionStatusBar->Panels->Items[Offset + 1]->Caption = SessionInfo.ProtocolName;
  3904. }
  3905. else
  3906. {
  3907. SessionStatusBar->Panels->Items[Offset + 1]->Caption = FileSystemInfo.ProtocolName;
  3908. }
  3909. SessionStatusBar->Panels->Items[Offset + 1]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  3910. SessionStatusBar->Panels->Items[Offset + 2]->Enabled =
  3911. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  3912. if (SessionInfo.CSCompression == SessionInfo.SCCompression)
  3913. {
  3914. SessionStatusBar->Panels->Items[Offset + 2]->Hint =
  3915. FMTLOAD(STATUS_COMPRESSION_HINT, (DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR))));
  3916. }
  3917. else
  3918. {
  3919. SessionStatusBar->Panels->Items[Offset + 2]->Hint = FMTLOAD(STATUS_COMPRESSION2_HINT,
  3920. (DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR)),
  3921. DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR))));
  3922. }
  3923. SessionStatusBar->Panels->Items[Offset + 3]->Hint = LoadStr(STATUS_DURATION_HINT);
  3924. UpdateStatusBar();
  3925. }
  3926. //---------------------------------------------------------------------------
  3927. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  3928. {
  3929. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  3930. DebugAssert(SessionStatusBar != NULL);
  3931. if (!Terminal || !Terminal->Active || Terminal->Status < ssOpened)
  3932. {
  3933. // note: (Terminal->Status < sshReady) currently never happens here,
  3934. // so STATUS_CONNECTING is never used
  3935. SessionStatusBar->SimplePanel = true;
  3936. SessionStatusBar->SimpleText = LoadStr(
  3937. !Terminal || !Terminal->Active ? STATUS_NOT_CONNECTED : STATUS_CONNECTING);
  3938. }
  3939. else
  3940. {
  3941. DebugAssert(Terminal);
  3942. SessionStatusBar->SimplePanel = false;
  3943. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  3944. if (!FNote.IsEmpty())
  3945. {
  3946. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  3947. }
  3948. else
  3949. {
  3950. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  3951. }
  3952. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  3953. SessionStatusBar->Panels->Items[SessionStatusBar->Panels->Count - 1]->Caption =
  3954. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  3955. }
  3956. }
  3957. //---------------------------------------------------------------------------
  3958. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  3959. {
  3960. Panel->Caption = L"";
  3961. }
  3962. //---------------------------------------------------------------------------
  3963. void __fastcall TCustomScpExplorerForm::Idle()
  3964. {
  3965. if (FShowing || FStandaloneEditing)
  3966. {
  3967. FEditorManager->Check();
  3968. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  3969. // that needs to know if queue view is visible (and it may be closed after queue update)
  3970. TTerminalManager::Instance()->Idle();
  3971. }
  3972. if (FShowing)
  3973. {
  3974. if (!NonVisualDataModule->Busy &&
  3975. // Menu is opened or drag&drop is going on
  3976. (Mouse->Capture == NULL))
  3977. {
  3978. if (FRefreshRemoteDirectory)
  3979. {
  3980. if ((Terminal != NULL) && (Terminal->Status == ssOpened))
  3981. {
  3982. Terminal->RefreshDirectory();
  3983. }
  3984. FRefreshRemoteDirectory = false;
  3985. }
  3986. if (FRefreshLocalDirectory)
  3987. {
  3988. ReloadLocalDirectory();
  3989. FRefreshLocalDirectory = false;
  3990. }
  3991. if (WinConfiguration->RefreshRemotePanel)
  3992. {
  3993. TManagedTerminal * ManagedTerminal =
  3994. dynamic_cast<TManagedTerminal *>(Terminal);
  3995. if ((ManagedTerminal != NULL) && (Terminal->Status == ssOpened) &&
  3996. (Now() - ManagedTerminal->DirectoryLoaded >
  3997. WinConfiguration->RefreshRemotePanelInterval))
  3998. {
  3999. RemoteDirView->ReloadDirectory();
  4000. }
  4001. }
  4002. }
  4003. }
  4004. if (FShowing || FStandaloneEditing)
  4005. {
  4006. if (FQueueStatusInvalidated)
  4007. {
  4008. UpdateQueueStatus(false);
  4009. }
  4010. RefreshQueueItems();
  4011. }
  4012. if (FShowing)
  4013. {
  4014. UpdateStatusBar();
  4015. }
  4016. FIgnoreNextDialogChar = 0;
  4017. }
  4018. //---------------------------------------------------------------------------
  4019. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  4020. {
  4021. try
  4022. {
  4023. FUserActionTimer->Enabled = false;
  4024. if (IsQueueAutoPopup() && (FPendingQueueActionItem != NULL))
  4025. {
  4026. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  4027. {
  4028. FPendingQueueActionItem->ProcessUserAction();
  4029. }
  4030. }
  4031. }
  4032. __finally
  4033. {
  4034. FPendingQueueActionItem = NULL;
  4035. }
  4036. }
  4037. //---------------------------------------------------------------------------
  4038. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  4039. {
  4040. if (WinConfiguration->MinimizeToTray)
  4041. {
  4042. UpdateTrayIcon();
  4043. FTrayIcon->Visible = true;
  4044. if (Visible)
  4045. {
  4046. ShowWindow(Handle, SW_HIDE);
  4047. }
  4048. }
  4049. }
  4050. //---------------------------------------------------------------------------
  4051. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  4052. {
  4053. // WORKAROUND
  4054. // When restoring maximized window from minimization,
  4055. // rarely some controls do not align properly.
  4056. // Two instances seen (both for Commander):
  4057. // - When restoring, window is temporarily narrower (not maximizer),
  4058. // causing toolbars on TopDock to wrap and dock to expand horizontally.
  4059. // Once maximized already, top dock shinks back, but the session PageControl,
  4060. // do not align up, leaving space between TopDock and PageControl.
  4061. // - Similar issue seem with LocalDirView not aligning down to status bar.
  4062. for (int Index = 0; Index < ControlCount; Index++)
  4063. {
  4064. RealignControl(Controls[Index]);
  4065. }
  4066. if (FTrayIcon->Visible)
  4067. {
  4068. FTrayIcon->Visible = false;
  4069. if (Visible)
  4070. {
  4071. ShowWindow(Handle, SW_SHOW);
  4072. }
  4073. }
  4074. if (FNeedSession && DebugAlwaysTrue(Terminal == NULL))
  4075. {
  4076. FNeedSession = false;
  4077. NonVisualDataModule->StartBusy();
  4078. try
  4079. {
  4080. NeedSession(false);
  4081. }
  4082. __finally
  4083. {
  4084. NonVisualDataModule->EndBusy();
  4085. }
  4086. }
  4087. }
  4088. //---------------------------------------------------------------------------
  4089. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  4090. {
  4091. FTrayIcon->Hint = Caption;
  4092. }
  4093. //---------------------------------------------------------------------------
  4094. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  4095. {
  4096. UpdateTrayIcon();
  4097. }
  4098. //---------------------------------------------------------------------------
  4099. void __fastcall TCustomScpExplorerForm::RestoreApp()
  4100. {
  4101. // workaround
  4102. // TApplication.WndProc sets TApplication.FAppIconic to false,
  4103. // on WM_ACTIVATEAPP, what renders TApplication.Restore no-op function.
  4104. // But WM_ACTIVATEAPP message can be received even when
  4105. // the main window is minimized to the tray and internal editor window is focused
  4106. // (after another application was previously active)
  4107. if (::IsIconic(Handle))
  4108. {
  4109. if (!IsAppIconic())
  4110. {
  4111. SetAppIconic(true);
  4112. }
  4113. }
  4114. ::ApplicationRestore();
  4115. Application->BringToFront();
  4116. }
  4117. //---------------------------------------------------------------------------
  4118. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  4119. {
  4120. RestoreApp();
  4121. }
  4122. //---------------------------------------------------------------------------
  4123. void __fastcall TCustomScpExplorerForm::NewSession(bool FromSite, const UnicodeString & SessionUrl)
  4124. {
  4125. if (OpenInNewWindow())
  4126. {
  4127. // todo: Pass FromSite
  4128. ExecuteNewInstance(SessionUrl);
  4129. }
  4130. else
  4131. {
  4132. TTerminalManager::Instance()->NewSession(FromSite, SessionUrl);
  4133. }
  4134. }
  4135. //---------------------------------------------------------------------------
  4136. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  4137. {
  4138. // current working directories become defaults here, what is not right
  4139. TSessionData * SessionData = CloneCurrentSessionData();
  4140. try
  4141. {
  4142. if (OpenInNewWindow())
  4143. {
  4144. UnicodeString SessionName = StoredSessions->HiddenPrefix + Terminal->SessionData->Name;
  4145. StoredSessions->NewSession(SessionName, SessionData);
  4146. // modified only, explicit
  4147. StoredSessions->Save(false, true);
  4148. // encode session name because of slashes in hierarchical sessions
  4149. ExecuteNewInstance(EncodeUrlString(SessionName));
  4150. }
  4151. else
  4152. {
  4153. TTerminalManager * Manager = TTerminalManager::Instance();
  4154. TTerminal * Terminal = Manager->NewTerminal(SessionData);
  4155. Manager->ActiveTerminal = Terminal;
  4156. }
  4157. }
  4158. __finally
  4159. {
  4160. delete SessionData;
  4161. }
  4162. }
  4163. //---------------------------------------------------------------------------
  4164. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  4165. {
  4166. DebugAssert(FQueue != NULL);
  4167. bool Result = FQueue->IsEmpty;
  4168. if (!Result)
  4169. {
  4170. SetFocus();
  4171. Result = (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS2), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK);
  4172. }
  4173. return Result;
  4174. }
  4175. //---------------------------------------------------------------------------
  4176. void __fastcall TCustomScpExplorerForm::CloseSession()
  4177. {
  4178. if (CanCloseQueue())
  4179. {
  4180. TTerminalManager::Instance()->FreeActiveTerminal();
  4181. }
  4182. }
  4183. //---------------------------------------------------------------------------
  4184. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  4185. {
  4186. if (OpenInNewWindow())
  4187. {
  4188. // encode session name because of slashes in hierarchical sessions
  4189. ExecuteNewInstance(EncodeUrlString(Data->Name));
  4190. }
  4191. else
  4192. {
  4193. TTerminalManager * Manager = TTerminalManager::Instance();
  4194. TTerminal * Terminal = Manager->NewTerminal(Data);
  4195. Manager->ActiveTerminal = Terminal;
  4196. }
  4197. }
  4198. //---------------------------------------------------------------------------
  4199. void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
  4200. {
  4201. if (OpenInNewWindow())
  4202. {
  4203. ExecuteNewInstance(Name);
  4204. }
  4205. else
  4206. {
  4207. TTerminalManager * Manager = TTerminalManager::Instance();
  4208. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4209. StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
  4210. Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
  4211. }
  4212. }
  4213. //---------------------------------------------------------------------------
  4214. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  4215. bool &CanClose)
  4216. {
  4217. if (Terminal != NULL)
  4218. {
  4219. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  4220. {
  4221. unsigned int Result;
  4222. TMessageParams Params(mpNeverAskAgainCheck);
  4223. UnicodeString Message;
  4224. int Answers = qaOK | qaCancel;
  4225. if (TTerminalManager::Instance()->Count > 1)
  4226. {
  4227. if (!WinConfiguration->AutoSaveWorkspace)
  4228. {
  4229. Message = LoadStr(CLOSE_SESSIONS_WORKSPACE2);
  4230. Answers = qaYes | qaNo | qaCancel;
  4231. }
  4232. else
  4233. {
  4234. Message = MainInstructions(LoadStr(CLOSE_SESSIONS));
  4235. }
  4236. }
  4237. else
  4238. {
  4239. Message = MainInstructions(FMTLOAD(CLOSE_SESSION, (Terminal->SessionData->SessionName)));
  4240. }
  4241. if (WinConfiguration->AutoSaveWorkspace)
  4242. {
  4243. Message =
  4244. FORMAT("%s\n\n%s", (Message,
  4245. FMTLOAD(AUTO_WORKSPACE, (WorkspaceName()))));
  4246. }
  4247. SetFocus();
  4248. Result = MessageDialog(Message, qtConfirmation,
  4249. Answers, HELP_NONE, &Params);
  4250. if (Result == qaNeverAskAgain)
  4251. {
  4252. WinConfiguration->ConfirmClosingSession = false;
  4253. }
  4254. if (Result == qaNo)
  4255. {
  4256. CanClose = SaveWorkspace(true);
  4257. // note that the workspace will be saved redundatly again from FormClose
  4258. }
  4259. else
  4260. {
  4261. CanClose =
  4262. (Result == qaOK) ||
  4263. (Result == qaYes) || // CLOSE_SESSIONS_WORKSPACE variant
  4264. (Result == qaNeverAskAgain);
  4265. }
  4266. }
  4267. if (CanClose)
  4268. {
  4269. CanClose = CanCloseQueue();
  4270. }
  4271. }
  4272. if (CanClose)
  4273. {
  4274. CanClose =
  4275. FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  4276. FEditorManager->CloseExternalFilesWithoutProcess();
  4277. if (CanClose)
  4278. {
  4279. while (CanClose && (FLocalEditors->Count > 0))
  4280. {
  4281. int PrevCount = FLocalEditors->Count;
  4282. static_cast<TForm *>(FLocalEditors->Items[0])->Close();
  4283. CanClose = (FLocalEditors->Count < PrevCount);
  4284. }
  4285. if (CanClose)
  4286. {
  4287. CanClose = FEditorManager->Empty(true);
  4288. if (!CanClose)
  4289. {
  4290. SetFocus();
  4291. CanClose =
  4292. (MessageDialog(
  4293. LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel, HELP_NONE) == qaIgnore);
  4294. }
  4295. }
  4296. }
  4297. }
  4298. }
  4299. //---------------------------------------------------------------------------
  4300. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  4301. {
  4302. TForm * Form = dynamic_cast<TForm *>(Sender);
  4303. DebugAssert(Form != NULL);
  4304. Form->Close();
  4305. }
  4306. //---------------------------------------------------------------------------
  4307. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  4308. {
  4309. TForm * Form = dynamic_cast<TForm *>(Sender);
  4310. delete Form;
  4311. }
  4312. //---------------------------------------------------------------------------
  4313. void __fastcall TCustomScpExplorerForm::ForceCloseLocalEditors()
  4314. {
  4315. while (FLocalEditors->Count > 0)
  4316. {
  4317. delete static_cast<TForm *>(FLocalEditors->Items[0]);
  4318. }
  4319. }
  4320. //---------------------------------------------------------------------------
  4321. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  4322. TObject *Sender)
  4323. {
  4324. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  4325. try
  4326. {
  4327. SetProperties(osRemote, FileList);
  4328. }
  4329. __finally
  4330. {
  4331. delete FileList;
  4332. }
  4333. }
  4334. //---------------------------------------------------------------------------
  4335. void __fastcall TCustomScpExplorerForm::ComponentShowing(Byte Component, bool value)
  4336. {
  4337. if (value)
  4338. {
  4339. if (Component == fcCustomCommandsBand)
  4340. {
  4341. UpdateCustomCommandsToolbar();
  4342. }
  4343. }
  4344. }
  4345. //---------------------------------------------------------------------------
  4346. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Byte Component, Boolean value)
  4347. {
  4348. TControl * Control = GetComponent(Component);
  4349. DebugAssert(Control);
  4350. bool Changed = (Control->Visible != value);
  4351. if (Changed)
  4352. {
  4353. ComponentShowing(Component, value);
  4354. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  4355. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  4356. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  4357. if (value)
  4358. {
  4359. int RemainingHeight = Control->Parent->ClientHeight;
  4360. int RemainingWidth = Control->Parent->ClientWidth;
  4361. for (int i = 0; i < Control->Parent->ControlCount; i++)
  4362. {
  4363. TControl * ChildControl = Control->Parent->Controls[i];
  4364. if (ChildControl->Visible)
  4365. {
  4366. switch (ChildControl->Align)
  4367. {
  4368. case alTop:
  4369. case alBottom:
  4370. RemainingHeight -= ChildControl->Height;
  4371. break;
  4372. case alLeft:
  4373. case alRight:
  4374. RemainingWidth -= ChildControl->Width;
  4375. break;
  4376. }
  4377. }
  4378. }
  4379. int Reserve = ScaleByTextHeight(this, 32);
  4380. // queue in explorer, trees in commander
  4381. if (Control->Height > RemainingHeight - Reserve)
  4382. {
  4383. Control->Height = RemainingHeight / 2;
  4384. }
  4385. if (Control->Width > RemainingWidth - Reserve)
  4386. {
  4387. Control->Width = RemainingWidth / 2;
  4388. }
  4389. }
  4390. Control->Visible = value;
  4391. if (WasFocused && Visible)
  4392. {
  4393. DirView(osCurrent)->SetFocus();
  4394. }
  4395. FixControlsPlacement();
  4396. }
  4397. }
  4398. //---------------------------------------------------------------------------
  4399. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Byte Component)
  4400. {
  4401. TControl * Control = GetComponent(Component);
  4402. if (Control == NULL)
  4403. {
  4404. return false;
  4405. }
  4406. else
  4407. {
  4408. return Control->Visible;
  4409. }
  4410. }
  4411. //---------------------------------------------------------------------------
  4412. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  4413. {
  4414. if (RemoteDirView->ItemFocused != NULL)
  4415. {
  4416. RemoteDirView->ItemFocused->MakeVisible(false);
  4417. }
  4418. QueueSplitter->Visible = QueuePanel->Visible;
  4419. RemotePanelSplitter->Visible = RemoteDriveView->Visible;
  4420. }
  4421. //---------------------------------------------------------------------------
  4422. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  4423. {
  4424. switch (Component) {
  4425. case fcStatusBar: return RemoteStatusBar;
  4426. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  4427. case fcQueueView: return QueuePanel;
  4428. case fcQueueToolbar: return QueueDock;
  4429. case fcRemoteTree: return RemoteDriveView;
  4430. case fcSessionsTabs: return SessionsPageControl;
  4431. default: return NULL;
  4432. }
  4433. }
  4434. //---------------------------------------------------------------------------
  4435. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  4436. TObject *Sender, TListColumn *Column, TPoint &Point)
  4437. {
  4438. DebugAssert(NonVisualDataModule && Column && Sender);
  4439. NonVisualDataModule->ListColumn = Column;
  4440. TPoint ScreenPoint = ((TControl*)Sender)->ClientToScreen(Point);
  4441. TPopupMenu * DirViewColumnMenu;
  4442. if (Sender == RemoteDirView)
  4443. {
  4444. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  4445. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  4446. (Column->Index == uvName);
  4447. NonVisualDataModule->RemoteFormatSizeBytesPopupItem->Visible =
  4448. (Column->Index == uvSize);
  4449. }
  4450. else
  4451. {
  4452. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  4453. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  4454. (Column->Index == dvName);
  4455. NonVisualDataModule->LocalFormatSizeBytesPopupItem->Visible =
  4456. (Column->Index == dvSize);
  4457. }
  4458. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  4459. }
  4460. //---------------------------------------------------------------------------
  4461. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  4462. TObject *Sender, TListItem *Item, bool &AllowExec)
  4463. {
  4464. DoDirViewExecFile(Sender, Item, AllowExec);
  4465. }
  4466. //---------------------------------------------------------------------------
  4467. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  4468. TListItem * Item, bool & AllowExec)
  4469. {
  4470. DebugAssert(Sender && Item && Configuration);
  4471. DebugAssert(AllowExec);
  4472. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  4473. bool Remote = (ADirView == DirView(osRemote));
  4474. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks;
  4475. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  4476. // on files only (not directories)
  4477. // and only when symlinks are resolved (apply to remote panel only)
  4478. if (!ADirView->ItemIsDirectory(Item) &&
  4479. (ResolvedSymlinks || FForceExecution))
  4480. {
  4481. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  4482. !FForceExecution &&
  4483. ResolvedSymlinks)
  4484. {
  4485. if (WinConfiguration->DoubleClickAction == dcaCopy)
  4486. {
  4487. ExecuteFileOperation(foCopy,
  4488. (ADirView == DirView(osRemote) ? osRemote : osLocal),
  4489. true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  4490. AllowExec = false;
  4491. }
  4492. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  4493. {
  4494. if (!Remote || !WinConfiguration->DisableOpenEdit)
  4495. {
  4496. ExecuteFile(osCurrent, efDefaultEditor);
  4497. AllowExec = false;
  4498. }
  4499. }
  4500. else
  4501. {
  4502. DebugFail();
  4503. }
  4504. }
  4505. // if we have not done anything special, fall back to default behavior
  4506. if (AllowExec)
  4507. {
  4508. if (Remote && !WinConfiguration->DisableOpenEdit)
  4509. {
  4510. ExecuteFile(osRemote, efShell);
  4511. AllowExec = false;
  4512. }
  4513. }
  4514. }
  4515. }
  4516. //---------------------------------------------------------------------------
  4517. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  4518. {
  4519. return ((Side == osRemote) || (Side == osCurrent));
  4520. }
  4521. //---------------------------------------------------------------------------
  4522. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  4523. {
  4524. DebugFail();
  4525. }
  4526. //---------------------------------------------------------------------------
  4527. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  4528. {
  4529. DebugFail();
  4530. }
  4531. //---------------------------------------------------------------------------
  4532. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  4533. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory, bool UseDefaults)
  4534. {
  4535. TSynchronizeParamType Params;
  4536. Params.LocalDirectory = LocalDirectory;
  4537. Params.RemoteDirectory = RemoteDirectory;
  4538. int UnusedParams =
  4539. (GUIConfiguration->SynchronizeParams &
  4540. (spPreviewChanges | spTimestamp | spNotByTime | spBySize));
  4541. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  4542. Params.Options = GUIConfiguration->SynchronizeOptions;
  4543. bool SaveSettings = false;
  4544. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  4545. &DoSynchronizeTooManyDirectories);
  4546. DebugAssert(FSynchronizeController == NULL);
  4547. FSynchronizeController = &Controller;
  4548. bool Result;
  4549. try
  4550. {
  4551. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4552. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  4553. int Options =
  4554. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  4555. DebugAssert(FOnFeedSynchronizeError == NULL);
  4556. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  4557. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, SynchronizeSessionLog,
  4558. FOnFeedSynchronizeError, UseDefaults);
  4559. if (Result)
  4560. {
  4561. if (SaveSettings)
  4562. {
  4563. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  4564. GUIConfiguration->SynchronizeOptions = Params.Options;
  4565. }
  4566. else
  4567. {
  4568. if (FLAGSET(GUIConfiguration->SynchronizeOptions, soSynchronizeAsk) &&
  4569. FLAGCLEAR(Params.Options, soSynchronizeAsk) &&
  4570. FLAGSET(Params.Options, soSynchronize))
  4571. {
  4572. GUIConfiguration->SynchronizeOptions =
  4573. (GUIConfiguration->SynchronizeOptions & ~soSynchronizeAsk) |
  4574. soSynchronize;
  4575. }
  4576. }
  4577. LocalDirectory = Params.LocalDirectory;
  4578. RemoteDirectory = Params.RemoteDirectory;
  4579. }
  4580. }
  4581. __finally
  4582. {
  4583. FSynchronizeController = NULL;
  4584. DebugAssert(FOnFeedSynchronizeError == NULL);
  4585. FOnFeedSynchronizeError = NULL;
  4586. }
  4587. return Result;
  4588. }
  4589. //---------------------------------------------------------------------------
  4590. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  4591. TSynchronizeController * /*Sender*/, const UnicodeString LocalDirectory,
  4592. const UnicodeString RemoteDirectory, const TCopyParamType & CopyParam,
  4593. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  4594. TSynchronizeOptions * Options, bool Full)
  4595. {
  4596. if (Terminal->Status == ssOpened)
  4597. {
  4598. try
  4599. {
  4600. int PParams = Params.Params;
  4601. if (!Full)
  4602. {
  4603. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache |
  4604. TTerminal::spDelayProgress | TTerminal::spSubDirs;
  4605. }
  4606. else
  4607. {
  4608. // if keepuptodate is non-recursive,
  4609. // full sync before has to be non-recursive as well
  4610. if (FLAGCLEAR(Params.Options, soRecurse))
  4611. {
  4612. PParams |= TTerminal::spNoRecurse;
  4613. }
  4614. }
  4615. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  4616. PParams, Checklist, Options);
  4617. }
  4618. catch(Exception & E)
  4619. {
  4620. ShowExtendedExceptionEx(Terminal, &E);
  4621. throw;
  4622. }
  4623. }
  4624. }
  4625. //---------------------------------------------------------------------------
  4626. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  4627. TSynchronizeController * /*Sender*/, const UnicodeString Directory,
  4628. const UnicodeString ErrorStr)
  4629. {
  4630. if (!Directory.IsEmpty())
  4631. {
  4632. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  4633. }
  4634. else
  4635. {
  4636. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  4637. }
  4638. }
  4639. //---------------------------------------------------------------------------
  4640. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  4641. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  4642. {
  4643. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  4644. {
  4645. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  4646. }
  4647. else
  4648. {
  4649. TMessageParams Params(mpNeverAskAgainCheck);
  4650. unsigned int Result = MessageDialog(
  4651. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  4652. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  4653. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  4654. {
  4655. MaxDirectories *= 2;
  4656. if (Result == qaNeverAskAgain)
  4657. {
  4658. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  4659. }
  4660. }
  4661. else
  4662. {
  4663. Abort();
  4664. }
  4665. }
  4666. }
  4667. //---------------------------------------------------------------------------
  4668. void __fastcall TCustomScpExplorerForm::Synchronize(const UnicodeString LocalDirectory,
  4669. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  4670. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  4671. TSynchronizeOptions * Options)
  4672. {
  4673. DebugAssert(!FAutoOperation);
  4674. void * BatchStorage;
  4675. BatchStart(BatchStorage);
  4676. FAutoOperation = true;
  4677. bool AnyOperation = false;
  4678. TDateTime StartTime = Now();
  4679. TSynchronizeChecklist * AChecklist = NULL;
  4680. try
  4681. {
  4682. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  4683. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  4684. {
  4685. FSynchronizeProgressForm->Start();
  4686. }
  4687. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  4688. static_cast<TTerminal::TSynchronizeMode>(Mode),
  4689. &CopyParam, Params | spNoConfirmation, TerminalSynchronizeDirectory,
  4690. Options);
  4691. SAFE_DESTROY(FSynchronizeProgressForm);
  4692. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, false);
  4693. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  4694. {
  4695. FSynchronizeProgressForm->Start();
  4696. }
  4697. for (int Index = 0; !AnyOperation && (Index < AChecklist->Count); Index++)
  4698. {
  4699. AnyOperation = AChecklist->Item[Index]->Checked;
  4700. }
  4701. // No need to call if !AnyOperation
  4702. Terminal->SynchronizeApply(AChecklist, LocalDirectory, RemoteDirectory,
  4703. &CopyParam, Params | spNoConfirmation, TerminalSynchronizeDirectory);
  4704. }
  4705. __finally
  4706. {
  4707. if (Checklist == NULL)
  4708. {
  4709. delete AChecklist;
  4710. }
  4711. else
  4712. {
  4713. *Checklist = AChecklist;
  4714. }
  4715. FAutoOperation = false;
  4716. SAFE_DESTROY(FSynchronizeProgressForm);
  4717. BatchEnd(BatchStorage);
  4718. ReloadLocalDirectory();
  4719. if (AnyOperation)
  4720. {
  4721. OperationComplete(StartTime);
  4722. }
  4723. }
  4724. }
  4725. //---------------------------------------------------------------------------
  4726. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  4727. {
  4728. // can be called from command line
  4729. return Visible &&
  4730. ((DirView(osRemote)->SelCount > 0) ||
  4731. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  4732. }
  4733. //---------------------------------------------------------------------------
  4734. void __fastcall TCustomScpExplorerForm::SynchronizeSessionLog(const UnicodeString & Message)
  4735. {
  4736. LogSynchronizeEvent(Terminal, Message);
  4737. }
  4738. //---------------------------------------------------------------------------
  4739. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  4740. int Params, TSynchronizeOptions & Options)
  4741. {
  4742. if (FLAGSET(Params, spSelectedOnly) && SynchronizeAllowSelectedOnly())
  4743. {
  4744. Options.Filter = new TStringList();
  4745. Options.Filter->CaseSensitive = false;
  4746. Options.Filter->Duplicates = Types::dupAccept;
  4747. if (DirView(osRemote)->SelCount > 0)
  4748. {
  4749. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  4750. }
  4751. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  4752. {
  4753. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  4754. }
  4755. Options.Filter->Sort();
  4756. }
  4757. }
  4758. //---------------------------------------------------------------------------
  4759. bool __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  4760. UnicodeString & LocalDirectory, UnicodeString & RemoteDirectory,
  4761. TSynchronizeMode & Mode, bool & SaveMode, bool UseDefaults)
  4762. {
  4763. bool Result;
  4764. int Params = GUIConfiguration->SynchronizeParams;
  4765. bool SaveSettings = false;
  4766. int Options =
  4767. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  4768. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  4769. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  4770. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  4771. Result = UseDefaults ||
  4772. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  4773. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs);
  4774. if (Result)
  4775. {
  4776. Configuration->Usage->Inc(L"Synchronizations");
  4777. UpdateCopyParamCounters(CopyParam);
  4778. TSynchronizeOptions SynchronizeOptions;
  4779. GetSynchronizeOptions(Params, SynchronizeOptions);
  4780. if (SaveSettings)
  4781. {
  4782. GUIConfiguration->SynchronizeParams = Params;
  4783. }
  4784. else
  4785. {
  4786. SaveMode = false;
  4787. }
  4788. TDateTime StartTime = Now();
  4789. TSynchronizeChecklist * Checklist = NULL;
  4790. try
  4791. {
  4792. DebugAssert(!FAutoOperation);
  4793. FAutoOperation = true;
  4794. try
  4795. {
  4796. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  4797. FSynchronizeProgressForm->Start();
  4798. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  4799. static_cast<TTerminal::TSynchronizeMode>(Mode),
  4800. &CopyParam, Params | spNoConfirmation, TerminalSynchronizeDirectory,
  4801. &SynchronizeOptions);
  4802. }
  4803. __finally
  4804. {
  4805. FAutoOperation = false;
  4806. SAFE_DESTROY(FSynchronizeProgressForm);
  4807. }
  4808. if (Checklist->Count == 0)
  4809. {
  4810. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  4811. MessageDialog(Message, qtInformation, qaOK,
  4812. HELP_SYNCHRONIZE_NO_DIFFERENCES);
  4813. }
  4814. else if (FLAGCLEAR(Params, spPreviewChanges) ||
  4815. DoSynchronizeChecklistDialog(Checklist, Mode, Params,
  4816. LocalDirectory, RemoteDirectory, CustomCommandMenu))
  4817. {
  4818. DebugAssert(!FAutoOperation);
  4819. void * BatchStorage;
  4820. BatchStart(BatchStorage);
  4821. FAutoOperation = true;
  4822. if (FLAGSET(Params, spPreviewChanges))
  4823. {
  4824. StartTime = Now();
  4825. }
  4826. try
  4827. {
  4828. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, false);
  4829. FSynchronizeProgressForm->Start();
  4830. Terminal->SynchronizeApply(Checklist, LocalDirectory, RemoteDirectory,
  4831. &CopyParam, Params | spNoConfirmation, TerminalSynchronizeDirectory);
  4832. }
  4833. __finally
  4834. {
  4835. FAutoOperation = false;
  4836. SAFE_DESTROY(FSynchronizeProgressForm);
  4837. BatchEnd(BatchStorage);
  4838. ReloadLocalDirectory();
  4839. }
  4840. }
  4841. }
  4842. __finally
  4843. {
  4844. delete Checklist;
  4845. }
  4846. OperationComplete(StartTime);
  4847. }
  4848. return Result;
  4849. }
  4850. //---------------------------------------------------------------------------
  4851. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  4852. const UnicodeString LocalDirectory, const UnicodeString RemoteDirectory,
  4853. bool & Continue, bool /*Collect*/)
  4854. {
  4855. DebugAssert(FSynchronizeProgressForm != NULL);
  4856. if (!FSynchronizeProgressForm->Started)
  4857. {
  4858. FSynchronizeProgressForm->Start();
  4859. }
  4860. FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Continue);
  4861. }
  4862. //---------------------------------------------------------------------------
  4863. void __fastcall TCustomScpExplorerForm::StandaloneEdit(const UnicodeString & FileName)
  4864. {
  4865. UnicodeString FullFileName = AbsolutePath(FTerminal->CurrentDirectory, FileName);
  4866. TRemoteFile * File = NULL;
  4867. Terminal->ReadFile(FullFileName, File);
  4868. if (File != NULL)
  4869. {
  4870. std::unique_ptr<TRemoteFile> FileOwner(File);
  4871. TAutoFlag Flag(FStandaloneEditing);
  4872. ExecuteRemoteFile(FullFileName, File, efInternalEditor);
  4873. Application->ShowMainForm = false;
  4874. Application->Run();
  4875. }
  4876. }
  4877. //---------------------------------------------------------------------------
  4878. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  4879. {
  4880. DebugFail();
  4881. }
  4882. //---------------------------------------------------------------------------
  4883. TSessionData * __fastcall TCustomScpExplorerForm::CloneCurrentSessionData()
  4884. {
  4885. std::unique_ptr<TSessionData> SessionData(new TSessionData(L""));
  4886. SessionData->Assign(Terminal->SessionData);
  4887. UpdateSessionData(SessionData.get());
  4888. TTerminalManager::Instance()->UpdateSessionCredentials(SessionData.get());
  4889. if (Terminal->SessionData->IsWorkspace)
  4890. {
  4891. // Have to reset the "Workspace/XXX" name which would become user-visible
  4892. // once IsWorkspace is cleared
  4893. SessionData->Name = UnicodeString();
  4894. SessionData->IsWorkspace = false;
  4895. }
  4896. return SessionData.release();
  4897. }
  4898. //---------------------------------------------------------------------------
  4899. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  4900. {
  4901. TSessionData * SessionData = CloneCurrentSessionData();
  4902. try
  4903. {
  4904. TSessionData * EditingSessionData = StoredSessions->FindSame(SessionData);
  4905. DoSaveSession(SessionData, EditingSessionData, true, NULL);
  4906. }
  4907. __finally
  4908. {
  4909. delete SessionData;
  4910. }
  4911. }
  4912. //---------------------------------------------------------------------------
  4913. TObjectList * __fastcall TCustomScpExplorerForm::DoCollectWorkspace()
  4914. {
  4915. TTerminalManager * Manager = TTerminalManager::Instance();
  4916. std::unique_ptr<TObjectList> DataList(new TObjectList());
  4917. if (DebugAlwaysTrue(Terminal != NULL))
  4918. {
  4919. // Update (Managed)Terminal->StateData
  4920. UpdateTerminal(Terminal);
  4921. }
  4922. Manager->SaveWorkspace(DataList.get());
  4923. return DataList.release();
  4924. }
  4925. //---------------------------------------------------------------------------
  4926. void __fastcall TCustomScpExplorerForm::DoSaveWorkspace(
  4927. const UnicodeString & Name, TObjectList * DataList, bool SavePasswords)
  4928. {
  4929. WinConfiguration->LastWorkspace = Name;
  4930. if (!SavePasswords)
  4931. {
  4932. for (int Index = 0; Index < DataList->Count; Index++)
  4933. {
  4934. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  4935. if (SessionData->Link.IsEmpty())
  4936. {
  4937. SessionData->ClearSessionPasswords();
  4938. }
  4939. }
  4940. }
  4941. StoredSessions->NewWorkspace(Name, DataList);
  4942. // modified only, explicit
  4943. StoredSessions->Save(false, true);
  4944. }
  4945. //---------------------------------------------------------------------------
  4946. UnicodeString __fastcall TCustomScpExplorerForm::WorkspaceName()
  4947. {
  4948. return
  4949. DefaultStr(WinConfiguration->LastWorkspace,
  4950. DefaultStr(WinConfiguration->AutoWorkspace, LoadStr(NEW_WORKSPACE)));
  4951. }
  4952. //---------------------------------------------------------------------------
  4953. bool __fastcall TCustomScpExplorerForm::SaveWorkspace(bool EnableAutoSave)
  4954. {
  4955. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  4956. bool AnyNonStoredSessionWithPassword = false;
  4957. bool AnyNonStoredNonWorkspaceSessionWithPassword = false;
  4958. bool AllNonStoredSessionsAnonymous = true;
  4959. TTerminalManager * Manager = TTerminalManager::Instance();
  4960. for (int Index = 0; Index < DataList->Count; Index++)
  4961. {
  4962. TSessionData * SessionData = dynamic_cast<TSessionData *>(DataList->Items[Index]);
  4963. if (SessionData->Link.IsEmpty())
  4964. {
  4965. if (SessionData->HasAnySessionPassword())
  4966. {
  4967. AnyNonStoredSessionWithPassword = true;
  4968. if (!Manager->Terminals[Index]->SessionData->IsWorkspace)
  4969. {
  4970. AnyNonStoredNonWorkspaceSessionWithPassword = true;
  4971. }
  4972. }
  4973. if (!SameText(SessionData->UserName, AnonymousUserName))
  4974. {
  4975. AllNonStoredSessionsAnonymous = false;
  4976. }
  4977. }
  4978. }
  4979. bool SavePasswords;
  4980. bool * PSavePasswords;
  4981. bool NotRecommendedSavingPasswords =
  4982. !CustomWinConfiguration->UseMasterPassword &&
  4983. !AllNonStoredSessionsAnonymous;
  4984. if (Configuration->DisablePasswordStoring ||
  4985. !AnyNonStoredSessionWithPassword)
  4986. {
  4987. PSavePasswords = NULL;
  4988. SavePasswords = false;
  4989. }
  4990. else
  4991. {
  4992. PSavePasswords = &SavePasswords;
  4993. SavePasswords =
  4994. !AnyNonStoredNonWorkspaceSessionWithPassword ||
  4995. !NotRecommendedSavingPasswords;
  4996. }
  4997. UnicodeString Name = WorkspaceName();
  4998. bool CreateShortcut = false;
  4999. bool Result =
  5000. DoSaveWorkspaceDialog(
  5001. Name, PSavePasswords, NotRecommendedSavingPasswords, CreateShortcut,
  5002. EnableAutoSave);
  5003. if (Result)
  5004. {
  5005. DoSaveWorkspace(Name, DataList.get(), SavePasswords);
  5006. if (CreateShortcut)
  5007. {
  5008. TOperationVisualizer Visualizer;
  5009. UnicodeString AdditionalParams = TProgramParams::FormatSwitch(DESKTOP_SWITCH);
  5010. CreateDesktopSessionShortCut(Name, L"", AdditionalParams, -1, WORKSPACE_ICON);
  5011. }
  5012. if (EnableAutoSave)
  5013. {
  5014. WinConfiguration->AutoSaveWorkspace = true;
  5015. WinConfiguration->AutoWorkspace = Name;
  5016. if (PSavePasswords != NULL)
  5017. {
  5018. WinConfiguration->AutoSaveWorkspacePasswords = SavePasswords;
  5019. }
  5020. }
  5021. }
  5022. return Result;
  5023. }
  5024. //---------------------------------------------------------------------------
  5025. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TTerminal * Terminal)
  5026. {
  5027. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  5028. DebugAssert(ManagedTerminal != NULL);
  5029. SAFE_DESTROY(ManagedTerminal->RemoteExplorerState);
  5030. if (WinConfiguration->PreservePanelState)
  5031. {
  5032. ManagedTerminal->RemoteExplorerState = RemoteDirView->SaveState();
  5033. }
  5034. UpdateSessionData(ManagedTerminal->StateData);
  5035. }
  5036. //---------------------------------------------------------------------------
  5037. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  5038. {
  5039. // Keep in sync with TSessionData::CopyStateData
  5040. DebugAssert(Data != NULL);
  5041. // cannot use RemoteDirView->Path, because it is empty if connection
  5042. // was already closed
  5043. // also only peek, we may not be connected at all atm
  5044. // so make sure we do not try retrieving current directory from the server
  5045. // (particularly with FTP)
  5046. UnicodeString ACurrentDirectory = Terminal->PeekCurrentDirectory();
  5047. if (!ACurrentDirectory.IsEmpty())
  5048. {
  5049. Data->RemoteDirectory = ACurrentDirectory;
  5050. }
  5051. Data->Color = SessionColor;
  5052. }
  5053. //---------------------------------------------------------------------------
  5054. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  5055. {
  5056. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar*>(Sender);
  5057. DebugAssert(Toolbar != NULL);
  5058. for (int i = 0; i < Toolbar->Items->Count; i++)
  5059. {
  5060. TTBXCustomDropDownItem * DropDownItem;
  5061. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5062. if (DropDownItem != NULL)
  5063. {
  5064. ToolbarItemResize(DropDownItem,
  5065. Toolbar->Width - (Toolbar->View->BaseSize.x - DropDownItem->EditWidth) -
  5066. Toolbar->NonClientWidth);
  5067. break;
  5068. }
  5069. }
  5070. }
  5071. //---------------------------------------------------------------------------
  5072. void __fastcall TCustomScpExplorerForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  5073. {
  5074. Item->EditWidth = Width;
  5075. }
  5076. //---------------------------------------------------------------------------
  5077. void __fastcall TCustomScpExplorerForm::ToolbarGetBaseSize(
  5078. TTBCustomToolbar * Toolbar, TPoint & ASize)
  5079. {
  5080. for (int i = 0; i < Toolbar->Items->Count; i++)
  5081. {
  5082. TTBXCustomDropDownItem * DropDownItem;
  5083. DropDownItem = dynamic_cast<TTBXCustomDropDownItem *>(Toolbar->Items->Items[i]);
  5084. if (DropDownItem != NULL)
  5085. {
  5086. ASize.x -= DropDownItem->EditWidth;
  5087. ASize.x += ScaleByTextHeight(this, 50) /* minimal combo width */;
  5088. }
  5089. }
  5090. }
  5091. //---------------------------------------------------------------------------
  5092. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  5093. const UnicodeString Path, __int64 RequiredSpace, bool & Continue)
  5094. {
  5095. if (WinConfiguration->DDWarnLackOfTempSpace)
  5096. {
  5097. UnicodeString ADrive = ExtractFileDrive(ExpandFileName(Path));
  5098. if (!ADrive.IsEmpty())
  5099. {
  5100. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  5101. DebugAssert(RequiredSpace >= 0);
  5102. __int64 RequiredWithReserve;
  5103. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  5104. if (FreeSpace < RequiredWithReserve)
  5105. {
  5106. unsigned int Result;
  5107. TMessageParams Params(mpNeverAskAgainCheck);
  5108. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  5109. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  5110. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  5111. if (Result == qaNeverAskAgain)
  5112. {
  5113. WinConfiguration->DDWarnLackOfTempSpace = false;
  5114. }
  5115. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  5116. }
  5117. }
  5118. }
  5119. }
  5120. //---------------------------------------------------------------------------
  5121. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  5122. {
  5123. DoOpenDirectoryDialog(odAddBookmark, Side);
  5124. }
  5125. //---------------------------------------------------------------------------
  5126. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  5127. {
  5128. // we should better use TCustomDirView::FCaseSensitive, but it is private
  5129. TStringList * VisitedDirectories = CreateSortedStringList((Side == osRemote));
  5130. try
  5131. {
  5132. TCustomDirView * DView = DirView(Side);
  5133. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  5134. {
  5135. VisitedDirectories->Add(DView->HistoryPath[Index]);
  5136. }
  5137. }
  5138. catch (...)
  5139. {
  5140. delete VisitedDirectories;
  5141. throw;
  5142. }
  5143. return VisitedDirectories;
  5144. }
  5145. //---------------------------------------------------------------------------
  5146. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  5147. TOpenDirectoryMode Mode, TOperationSide Side)
  5148. {
  5149. bool Continue = true;
  5150. if (Mode == odAddBookmark)
  5151. {
  5152. TMessageParams Params(mpNeverAskAgainCheck);
  5153. Params.NeverAskAgainTitle = LoadStr(ADD_BOOKMARK_SHARED);
  5154. Params.NeverAskAgainCheckedInitially = WinConfiguration->UseSharedBookmarks;
  5155. UnicodeString Message = MainInstructions(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)));
  5156. unsigned int Answer =
  5157. MessageDialog(Message,
  5158. qtConfirmation, qaOK | qaCancel, HELP_ADD_BOOKMARK_CONFIRM, &Params);
  5159. if (Answer == qaNeverAskAgain)
  5160. {
  5161. Continue = true;
  5162. WinConfiguration->UseSharedBookmarks = true;
  5163. }
  5164. else if (Answer == qaOK)
  5165. {
  5166. Continue = true;
  5167. WinConfiguration->UseSharedBookmarks = false;
  5168. }
  5169. else
  5170. {
  5171. Continue = false;
  5172. }
  5173. }
  5174. if (Continue)
  5175. {
  5176. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  5177. try
  5178. {
  5179. UnicodeString Name = DirView(Side)->PathName;
  5180. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  5181. // do not allow switching to location profiles,
  5182. // if we are not connected
  5183. HasDirView[osLocal] && (Terminal != NULL)))
  5184. {
  5185. TWindowLock Lock(this);
  5186. DirView(Side)->Path = Name;
  5187. }
  5188. }
  5189. __finally
  5190. {
  5191. delete VisitedDirectories;
  5192. }
  5193. }
  5194. }
  5195. //---------------------------------------------------------------------------
  5196. bool __fastcall TCustomScpExplorerForm::CommandSessionFallback()
  5197. {
  5198. bool Result = true;
  5199. DebugAssert(!FTerminal->CommandSessionOpened);
  5200. try
  5201. {
  5202. TTerminalManager::ConnectTerminal(FTerminal->CommandSession, false);
  5203. }
  5204. catch(Exception & E)
  5205. {
  5206. ShowExtendedExceptionEx(FTerminal->CommandSession, &E);
  5207. Result = false;
  5208. }
  5209. return Result;
  5210. }
  5211. //---------------------------------------------------------------------------
  5212. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  5213. {
  5214. bool Result = FTerminal->IsCapable[Capability] ||
  5215. FTerminal->CommandSessionOpened;
  5216. if (!Result)
  5217. {
  5218. DebugAssert(FTerminal->IsCapable[fcSecondaryShell]);
  5219. if (!GUIConfiguration->ConfirmCommandSession)
  5220. {
  5221. Result = true;
  5222. }
  5223. else
  5224. {
  5225. TMessageParams Params(mpNeverAskAgainCheck);
  5226. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  5227. unsigned int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION2,
  5228. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  5229. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  5230. if (Answer == qaNeverAskAgain)
  5231. {
  5232. GUIConfiguration->ConfirmCommandSession = false;
  5233. Result = true;
  5234. }
  5235. else if (Answer == qaOK)
  5236. {
  5237. Result = true;
  5238. }
  5239. }
  5240. if (Result)
  5241. {
  5242. Result = CommandSessionFallback();
  5243. }
  5244. }
  5245. return Result;
  5246. }
  5247. //---------------------------------------------------------------------------
  5248. void __fastcall TCustomScpExplorerForm::OpenConsole(UnicodeString Command)
  5249. {
  5250. if (EnsureCommandSessionFallback(fcAnyCommand))
  5251. {
  5252. DoConsoleDialog(Terminal, Command);
  5253. }
  5254. }
  5255. //---------------------------------------------------------------------------
  5256. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  5257. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  5258. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  5259. {
  5260. if (IsFileControl(DropSourceControl, osRemote) &&
  5261. (FDDExtMapFile != NULL))
  5262. {
  5263. Accept = true;
  5264. }
  5265. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  5266. DebugAssert(FDDTargetControl != NULL);
  5267. }
  5268. //---------------------------------------------------------------------------
  5269. void __fastcall TCustomScpExplorerForm::SessionsDDDragEnter(
  5270. _di_IDataObject DataObj, int KeyState,
  5271. const TPoint & Point, int & Effect, bool & Accept)
  5272. {
  5273. FileControlDDDragEnter(SessionsPageControl, DataObj, KeyState, Point, Effect, Accept);
  5274. }
  5275. //---------------------------------------------------------------------------
  5276. void __fastcall TCustomScpExplorerForm::QueueDDDragEnter(
  5277. _di_IDataObject DataObj, int KeyState,
  5278. const TPoint & Point, int & Effect, bool & Accept)
  5279. {
  5280. FileControlDDDragEnter(QueueView3, DataObj, KeyState, Point, Effect, Accept);
  5281. }
  5282. //---------------------------------------------------------------------------
  5283. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  5284. TObject * Sender)
  5285. {
  5286. DebugUsedParam(Sender);
  5287. DebugAssert(FDDTargetControl == Sender);
  5288. FDDTargetControl = NULL;
  5289. }
  5290. //---------------------------------------------------------------------------
  5291. void __fastcall TCustomScpExplorerForm::SessionsDDDragLeave()
  5292. {
  5293. FileControlDDDragLeave(SessionsPageControl);
  5294. }
  5295. //---------------------------------------------------------------------------
  5296. void __fastcall TCustomScpExplorerForm::QueueDDDragLeave()
  5297. {
  5298. FileControlDDDragLeave(QueueView3);
  5299. }
  5300. //---------------------------------------------------------------------------
  5301. void __fastcall TCustomScpExplorerForm::AddEditLink(TOperationSide Side, bool Add)
  5302. {
  5303. DebugAssert(GetSide(Side) == osRemote);
  5304. DebugUsedParam(Side);
  5305. bool Edit = false;
  5306. TRemoteFile * File = NULL;
  5307. UnicodeString FileName;
  5308. UnicodeString PointTo;
  5309. bool SymbolicLink = true;
  5310. if (RemoteDirView->ItemFocused)
  5311. {
  5312. DebugAssert(RemoteDirView->ItemFocused->Data);
  5313. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  5314. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  5315. if (Edit)
  5316. {
  5317. FileName = File->FileName;
  5318. PointTo = File->LinkTo;
  5319. }
  5320. else
  5321. {
  5322. PointTo = File->FileName;
  5323. }
  5324. }
  5325. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  5326. Terminal->IsCapable[fcHardLink]))
  5327. {
  5328. Configuration->Usage->Inc(L"RemoteLinksCreated");
  5329. if (Edit)
  5330. {
  5331. DebugAssert(File->FileName == FileName);
  5332. int Params = dfNoRecursive;
  5333. Terminal->ExceptionOnFail = true;
  5334. try
  5335. {
  5336. Terminal->DeleteFile(L"", File, &Params);
  5337. }
  5338. __finally
  5339. {
  5340. Terminal->ExceptionOnFail = false;
  5341. }
  5342. }
  5343. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  5344. }
  5345. }
  5346. //---------------------------------------------------------------------------
  5347. bool __fastcall TCustomScpExplorerForm::CanAddEditLink(TOperationSide Side)
  5348. {
  5349. return
  5350. (Terminal != NULL) &&
  5351. ((GetSide(Side) != osRemote) ||
  5352. (Terminal->ResolvingSymlinks &&
  5353. Terminal->IsCapable[fcSymbolicLink]));
  5354. }
  5355. //---------------------------------------------------------------------------
  5356. bool __fastcall TCustomScpExplorerForm::LinkFocused()
  5357. {
  5358. return
  5359. (FCurrentSide == osRemote) &&
  5360. (RemoteDirView->ItemFocused != NULL) &&
  5361. ((TRemoteFile *)RemoteDirView->ItemFocused->Data)->IsSymLink &&
  5362. Terminal->SessionData->ResolveSymlinks;
  5363. }
  5364. //---------------------------------------------------------------------------
  5365. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  5366. {
  5367. DebugAssert(!WinConfiguration->DisableOpenEdit);
  5368. FForceExecution = true;
  5369. try
  5370. {
  5371. DirView(osCurrent)->ExecuteCurrentFile();
  5372. }
  5373. __finally
  5374. {
  5375. FForceExecution = false;
  5376. }
  5377. }
  5378. //---------------------------------------------------------------------------
  5379. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFileWith(bool OnFocused)
  5380. {
  5381. TEditorData ExternalEditor;
  5382. ExternalEditor.Editor = edExternal;
  5383. bool Remember = false;
  5384. if (DoEditorPreferencesDialog(&ExternalEditor, Remember, epmAdHoc,
  5385. (GetSide(osCurrent) == osRemote)))
  5386. {
  5387. if (Remember)
  5388. {
  5389. TEditorList * EditorList = new TEditorList;
  5390. try
  5391. {
  5392. *EditorList = *WinConfiguration->EditorList;
  5393. bool Found = false;
  5394. int i = 0;
  5395. while (!Found && (i < EditorList->Count))
  5396. {
  5397. const TEditorPreferences * Editor = EditorList->Editors[i];
  5398. if ((Editor->Data->Editor == edExternal) &&
  5399. (Editor->Data->ExternalEditor == ExternalEditor.ExternalEditor))
  5400. {
  5401. Found = true;
  5402. }
  5403. i++;
  5404. }
  5405. if (!Found)
  5406. {
  5407. EditorList->Add(new TEditorPreferences(ExternalEditor));
  5408. WinConfiguration->EditorList = EditorList;
  5409. }
  5410. }
  5411. __finally
  5412. {
  5413. delete EditorList;
  5414. }
  5415. }
  5416. ExecuteFile(osCurrent, efExternalEditor, &ExternalEditor, true, OnFocused);
  5417. }
  5418. }
  5419. //---------------------------------------------------------------------------
  5420. void __fastcall TCustomScpExplorerForm::TerminalRemoved(TObject * Sender)
  5421. {
  5422. FEditorManager->ProcessFiles(FileTerminalRemoved, Sender);
  5423. if (FFileFindTerminal == Sender)
  5424. {
  5425. FFileFindTerminal = NULL;
  5426. HideFileFindDialog();
  5427. }
  5428. }
  5429. //---------------------------------------------------------------------------
  5430. void __fastcall TCustomScpExplorerForm::FileTerminalRemoved(const UnicodeString FileName,
  5431. TEditedFileData * Data, TObject * /*Token*/, void * Arg)
  5432. {
  5433. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  5434. DebugAssert(Terminal != NULL);
  5435. if (Data->Terminal == Terminal)
  5436. {
  5437. Data->Terminal = NULL;
  5438. }
  5439. }
  5440. //---------------------------------------------------------------------------
  5441. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  5442. {
  5443. UpdateControls();
  5444. SessionColor = TColor(0);
  5445. UpdateRemotePathComboBox(false);
  5446. try
  5447. {
  5448. NeedSession(true);
  5449. }
  5450. catch (EAbort &)
  5451. {
  5452. // swallow
  5453. // The TTerminalManager does not expect the OnLastTerminalClose to throw without trying to connect
  5454. }
  5455. }
  5456. //---------------------------------------------------------------------------
  5457. void __fastcall TCustomScpExplorerForm::NeedSession(bool ReloadSessions)
  5458. {
  5459. try
  5460. {
  5461. TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
  5462. }
  5463. __finally
  5464. {
  5465. if (!WinConfiguration->KeepOpenWhenNoSession &&
  5466. (!Terminal || !Terminal->Active))
  5467. {
  5468. TerminateApplication();
  5469. }
  5470. }
  5471. }
  5472. //---------------------------------------------------------------------------
  5473. void __fastcall TCustomScpExplorerForm::DoTerminalListChanged(bool Force)
  5474. {
  5475. TStrings * TerminalList = TTerminalManager::Instance()->TerminalList;
  5476. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  5477. Configuration->Usage->SetMax(L"MaxOpenedSessions", TerminalList->Count);
  5478. bool ListChanged = Force || (TerminalList->Count + 1 != SessionsPageControl->PageCount);
  5479. if (!ListChanged)
  5480. {
  5481. int Index = 0;
  5482. while (!ListChanged && (Index < TerminalList->Count))
  5483. {
  5484. ListChanged =
  5485. (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != TerminalList->Objects[Index]) ||
  5486. (SessionsPageControl->Pages[Index]->Caption != TerminalList->Strings[Index]);
  5487. Index++;
  5488. }
  5489. }
  5490. if (ListChanged)
  5491. {
  5492. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 0, 0);
  5493. try
  5494. {
  5495. FSessionColors->Clear();
  5496. AddFixedSessionImages();
  5497. while (SessionsPageControl->PageCount > 0)
  5498. {
  5499. delete SessionsPageControl->Pages[0];
  5500. }
  5501. for (int Index = 0; Index < TerminalList->Count; Index++)
  5502. {
  5503. TThemeTabSheet * TabSheet = new TThemeTabSheet(SessionsPageControl);
  5504. TabSheet->Caption = TerminalList->Strings[Index];
  5505. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  5506. TabSheet->Tag = reinterpret_cast<int>(Terminal);
  5507. TabSheet->PageControl = SessionsPageControl;
  5508. UpdateSessionTab(TabSheet);
  5509. }
  5510. TTabSheet * TabSheet = new TTabSheet(SessionsPageControl);
  5511. TabSheet->PageControl = SessionsPageControl;
  5512. TabSheet->ImageIndex = FNewSessionTabImageIndex;
  5513. UpdateNewSessionTab();
  5514. }
  5515. __finally
  5516. {
  5517. SendMessage(SessionsPageControl->Handle, WM_SETREDRAW, 1, 0);
  5518. }
  5519. }
  5520. SessionsPageControl->ActivePageIndex = ActiveTerminalIndex;
  5521. }
  5522. //---------------------------------------------------------------------------
  5523. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  5524. {
  5525. DoTerminalListChanged(false);
  5526. }
  5527. //---------------------------------------------------------------------------
  5528. void __fastcall TCustomScpExplorerForm::UpdateNewSessionTab()
  5529. {
  5530. TTabSheet * TabSheet = SessionsPageControl->Pages[SessionsPageControl->PageCount - 1];
  5531. DebugAssert(TabSheet->ImageIndex == 0);
  5532. TabSheet->Caption =
  5533. WinConfiguration->SelectiveToolbarText ?
  5534. StripHotkey(StripTrailingPunctuation(NonVisualDataModule->NewSessionAction->Caption)) :
  5535. UnicodeString();
  5536. }
  5537. //---------------------------------------------------------------------------
  5538. TTerminal * __fastcall TCustomScpExplorerForm::GetSessionTabTerminal(TTabSheet * TabSheet)
  5539. {
  5540. return reinterpret_cast<TTerminal *>(TabSheet->Tag);
  5541. }
  5542. //---------------------------------------------------------------------------
  5543. void __fastcall TCustomScpExplorerForm::UpdateSessionTab(TTabSheet * TabSheet)
  5544. {
  5545. if (DebugAlwaysTrue(TabSheet != NULL))
  5546. {
  5547. TManagedTerminal * ManagedTerminal =
  5548. dynamic_cast<TManagedTerminal *>(GetSessionTabTerminal(TabSheet));
  5549. if (DebugAlwaysTrue(ManagedTerminal != NULL))
  5550. {
  5551. TColor Color =
  5552. (ManagedTerminal == FTerminal) ? FSessionColor : ManagedTerminal->StateData->Color;
  5553. TabSheet->ImageIndex = AddSessionColor(Color);
  5554. TThemeTabSheet * ThemeTabSheet = dynamic_cast<TThemeTabSheet *>(TabSheet);
  5555. if (DebugAlwaysTrue(ThemeTabSheet != NULL))
  5556. {
  5557. ThemeTabSheet->Shadowed = !ManagedTerminal->Active;
  5558. }
  5559. }
  5560. }
  5561. }
  5562. //---------------------------------------------------------------------------
  5563. bool __fastcall TCustomScpExplorerForm::SessionTabSwitched()
  5564. {
  5565. DebugAssert(SessionsPageControl->ActivePage != NULL);
  5566. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  5567. bool Result = (Terminal != NULL);
  5568. if (Result)
  5569. {
  5570. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  5571. }
  5572. else
  5573. {
  5574. try
  5575. {
  5576. NewSession(false);
  5577. }
  5578. __finally
  5579. {
  5580. DoTerminalListChanged(false);
  5581. }
  5582. FSessionsPageControlNewSessionTime = Now();
  5583. }
  5584. return Result;
  5585. }
  5586. //---------------------------------------------------------------------------
  5587. void __fastcall TCustomScpExplorerForm::SessionsPageControlChange(TObject * /*Sender*/)
  5588. {
  5589. SessionTabSwitched();
  5590. }
  5591. //---------------------------------------------------------------------------
  5592. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  5593. {
  5594. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  5595. DebugAssert(TransferList != NULL);
  5596. UnicodeString Name;
  5597. if (TransferList->ItemIndex <= 0)
  5598. {
  5599. Name = L"";
  5600. }
  5601. else
  5602. {
  5603. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  5604. }
  5605. if (FCopyParamAutoSelected.IsEmpty())
  5606. {
  5607. // if previous preset was not autoselected, make new preset the "default"
  5608. FCopyParamDefault = Name;
  5609. }
  5610. GUIConfiguration->CopyParamCurrent = Name;
  5611. }
  5612. //---------------------------------------------------------------------------
  5613. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  5614. {
  5615. // sanity check
  5616. bool ExistingPreset =
  5617. (FTransferListHoverIndex >= 0) &&
  5618. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  5619. DebugAssert(ExistingPreset);
  5620. if (ExistingPreset)
  5621. {
  5622. HDC DC = GetDC(0);
  5623. TCanvas * Canvas = new TCanvas();
  5624. try
  5625. {
  5626. Canvas->Handle = DC;
  5627. Canvas->Font = ToolbarFont;
  5628. UnicodeString Name;
  5629. if (FTransferListHoverIndex == 0)
  5630. {
  5631. Name = L"";
  5632. }
  5633. else
  5634. {
  5635. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  5636. }
  5637. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  5638. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  5639. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  5640. static_cast<TObject*>(GetComponent(fcTransferList)));
  5641. UnicodeString InfoStr =
  5642. GUIConfiguration->CopyParamPreset[Name].
  5643. GetInfoStr(L"; ",
  5644. FLAGMASK(Terminal != NULL, Terminal->UsableCopyParamAttrs(0).General));
  5645. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - ScaleByTextHeight(this, 10);
  5646. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  5647. {
  5648. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  5649. {
  5650. InfoStr.SetLength(InfoStr.Length() - 1);
  5651. }
  5652. InfoStr += Ellipsis;
  5653. }
  5654. // UpdateCaption does not cause invalidation of whole submenu, while
  5655. // setting Caption property does.
  5656. // also it probably does not resize the label, even if necessary
  5657. // (we do not want that anyway)
  5658. TransferLabel->UpdateCaption(InfoStr);
  5659. }
  5660. __finally
  5661. {
  5662. Canvas->Handle = NULL;
  5663. ReleaseDC(0, DC);
  5664. delete Canvas;
  5665. }
  5666. }
  5667. }
  5668. //---------------------------------------------------------------------------
  5669. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  5670. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  5671. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  5672. {
  5673. if (FTransferListHoverIndex != AHoverIndex)
  5674. {
  5675. FTransferListHoverIndex = AHoverIndex;
  5676. UpdateTransferLabel();
  5677. }
  5678. }
  5679. //---------------------------------------------------------------------------
  5680. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  5681. {
  5682. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  5683. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  5684. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  5685. {
  5686. if (Command == APPCOMMAND_BROWSER_FAVORITES)
  5687. {
  5688. OpenDirectory(GetSide(osCurrent));
  5689. Message.Result = 1;
  5690. }
  5691. else
  5692. {
  5693. TForm::Dispatch(&Message);
  5694. }
  5695. }
  5696. else
  5697. {
  5698. TForm::Dispatch(&Message);
  5699. }
  5700. }
  5701. //---------------------------------------------------------------------------
  5702. void __fastcall TCustomScpExplorerForm::CMDialogChar(TMessage & AMessage)
  5703. {
  5704. TCMDialogChar & Message = reinterpret_cast<TCMDialogChar &>(AMessage);
  5705. if ((FIgnoreNextDialogChar != 0) &&
  5706. (toupper(Message.CharCode) == toupper(FIgnoreNextDialogChar)))
  5707. {
  5708. Message.Result = 1;
  5709. }
  5710. else
  5711. {
  5712. TForm::Dispatch(&Message);
  5713. }
  5714. FIgnoreNextDialogChar = 0;
  5715. }
  5716. //---------------------------------------------------------------------------
  5717. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  5718. {
  5719. // The four low-order bits are used internally by Windows
  5720. unsigned int Cmd = (Message.WParam & 0xFFF0);
  5721. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  5722. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  5723. // 61730 - restore thru double click - undocumented
  5724. // 61490 - maximize thru double click - undocumented
  5725. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  5726. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  5727. {
  5728. SysResizing(Cmd);
  5729. }
  5730. TForm::Dispatch(&Message);
  5731. }
  5732. //---------------------------------------------------------------------------
  5733. void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message)
  5734. {
  5735. // We were actually never able to make ENDSESSION_CRITICAL happen.
  5736. // Also there no point returning TRUE as we are not able to
  5737. // handle the abrupt termination caused by subsequent WM_ENDSESSION cleanly.
  5738. // Hence the process termination might be safer :)
  5739. if ((Message.LParam != ENDSESSION_CRITICAL) &&
  5740. (((FQueue != NULL) && !FQueue->IsEmpty) || (FProgressForm != NULL)))
  5741. {
  5742. Message.Result = FALSE;
  5743. }
  5744. else
  5745. {
  5746. Message.Result = TRUE;
  5747. }
  5748. // Do not call default handling as that triggers OnCloseQuery,
  5749. // where our implementation will popup configuration dialogs, what we do not want,
  5750. // as per Vista guidelines:
  5751. // msdn.microsoft.com/en-us/library/ms700677.aspx
  5752. }
  5753. //---------------------------------------------------------------------------
  5754. void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message)
  5755. {
  5756. if (Message.EndSession && IsApplicationMinimized())
  5757. {
  5758. // WORKAROUND
  5759. // TApplication.WndProc() calls Application.Terminate() before Halt(),
  5760. // when it receives WM_ENDSESSION,
  5761. // but that sometimes (particularly when application is minimized) cause crashes.
  5762. // Crash popups message that blocks log off.
  5763. // Obviously application cannot shutdown cleanly after WM_ENDSESSION,
  5764. // so we call ExitProcess() immediately, not even trying to cleanup.
  5765. // It still causes beep, so there's likely some popup, but it does not block
  5766. // log off.
  5767. ExitProcess(0);
  5768. }
  5769. TForm::Dispatch(&Message);
  5770. }
  5771. //---------------------------------------------------------------------------
  5772. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  5773. {
  5774. }
  5775. //---------------------------------------------------------------------------
  5776. void __fastcall TCustomScpExplorerForm::DoShow()
  5777. {
  5778. // only now are the controls resized finally, so the size constraints
  5779. // will not conflict with possibly very small window size
  5780. RestoreFormParams();
  5781. FixControlsPlacement();
  5782. if (Position == poDefaultPosOnly)
  5783. {
  5784. CutFormToDesktop(this);
  5785. }
  5786. TForm::DoShow();
  5787. FSessionsDragDropFilesEx->DragDropControl = SessionsPageControl;
  5788. FQueueDragDropFilesEx->DragDropControl = QueueView3;
  5789. if (Terminal == NULL)
  5790. {
  5791. StartingDisconnected();
  5792. }
  5793. FShowing = true;
  5794. }
  5795. //---------------------------------------------------------------------------
  5796. void __fastcall TCustomScpExplorerForm::StartingDisconnected()
  5797. {
  5798. DoTerminalListChanged(true);
  5799. }
  5800. //---------------------------------------------------------------------------
  5801. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  5802. const UnicodeString & Str, TQueryType Type, Exception * E, unsigned int Seconds,
  5803. TNotifyEvent OnBalloonClick, TObject * UserData)
  5804. {
  5805. bool Do;
  5806. UnicodeString Message;
  5807. if (E == NULL)
  5808. {
  5809. Message = Str;
  5810. Do = true;
  5811. }
  5812. else
  5813. {
  5814. Do = ExceptionMessage(E, Message);
  5815. }
  5816. if (Do && WinConfiguration->BalloonNotifications)
  5817. {
  5818. UnicodeString Title;
  5819. if ((Terminal == NULL) && (Type == qtInformation) && ExtractMainInstructions(Message, Title))
  5820. {
  5821. Message = TrimLeft(Message);
  5822. }
  5823. else
  5824. {
  5825. Message = UnformatMessage(Message);
  5826. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  5827. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  5828. Title = LoadResourceString(Captions[Type]);
  5829. if (Terminal != NULL)
  5830. {
  5831. Title = FORMAT(L"%s - %s",
  5832. (TTerminalManager::Instance()->TerminalTitle(Terminal), Title));
  5833. }
  5834. }
  5835. if (Seconds == 0)
  5836. {
  5837. Seconds = WinConfiguration->NotificationsTimeout;
  5838. }
  5839. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * MSecsPerSec, OnBalloonClick, UserData);
  5840. }
  5841. }
  5842. //---------------------------------------------------------------------------
  5843. unsigned int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const UnicodeString Message,
  5844. TStrings * MoreMessages, TQueryType Type, unsigned int Answers,
  5845. UnicodeString HelpKeyword, const TMessageParams * Params,
  5846. TTerminal * Terminal)
  5847. {
  5848. if (((WinConfiguration->ContinueOnError && (FErrorList != NULL)) ||
  5849. (FOnFeedSynchronizeError != NULL)) &&
  5850. (Params != NULL) && (Params->Params & mpAllowContinueOnError) )
  5851. {
  5852. if (FOnFeedSynchronizeError != NULL)
  5853. {
  5854. FOnFeedSynchronizeError(Message, MoreMessages, Type, HelpKeyword);
  5855. }
  5856. else
  5857. {
  5858. DebugAssert(FErrorList != NULL);
  5859. TStringList * MoreMessagesCopy = NULL;
  5860. if (MoreMessages)
  5861. {
  5862. MoreMessagesCopy = new TStringList();
  5863. MoreMessagesCopy->Assign(MoreMessages);
  5864. }
  5865. FErrorList->AddObject(Message, MoreMessagesCopy);
  5866. }
  5867. PopupTrayBalloon(Terminal, Message, Type);
  5868. return ContinueAnswer(Answers);
  5869. }
  5870. else
  5871. {
  5872. bool UseBalloon = FTrayIcon->Visible;
  5873. if (UseBalloon)
  5874. {
  5875. PopupTrayBalloon(Terminal, Message, Type);
  5876. }
  5877. unsigned int Result;
  5878. try
  5879. {
  5880. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  5881. }
  5882. __finally
  5883. {
  5884. // cancel only balloon we popped up, otherwise we may cancel notification
  5885. // balloon that was there before the message dialog
  5886. // (such as "dd confirmation opt in balloon)
  5887. if (UseBalloon)
  5888. {
  5889. FTrayIcon->CancelBalloon();
  5890. }
  5891. }
  5892. return Result;
  5893. }
  5894. }
  5895. //---------------------------------------------------------------------------
  5896. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  5897. TTerminal * Terminal, Exception * E)
  5898. {
  5899. if (FTrayIcon->Visible)
  5900. {
  5901. PopupTrayBalloon(Terminal, L"", qtError, E);
  5902. }
  5903. // particularly prevent opening new session from jump list,
  5904. // while exception is shown
  5905. NonVisualDataModule->StartBusy();
  5906. try
  5907. {
  5908. ShowExtendedExceptionEx(Terminal, E);
  5909. }
  5910. __finally
  5911. {
  5912. NonVisualDataModule->EndBusy();
  5913. FTrayIcon->CancelBalloon();
  5914. }
  5915. }
  5916. //---------------------------------------------------------------------------
  5917. void __fastcall TCustomScpExplorerForm::TerminalReady()
  5918. {
  5919. // cannot rely on active page being page for active terminal,
  5920. // as it can happen that active page is the "new session" page
  5921. // (e.g. when reconnecting active terminal, while login dialog
  5922. // invoked from "new session" page is modal)
  5923. int ActiveTerminalIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  5924. UpdateSessionTab(SessionsPageControl->Pages[ActiveTerminalIndex]);
  5925. }
  5926. //---------------------------------------------------------------------------
  5927. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  5928. TTerminal * Terminal, Exception * E)
  5929. {
  5930. Notify(Terminal, L"", qtError, false, NULL, NULL, E);
  5931. if (!Terminal->Active)
  5932. {
  5933. int Index = TTerminalManager::Instance()->IndexOf(Terminal);
  5934. if (DebugAlwaysTrue((Index >= 0) && (Index < SessionsPageControl->PageCount)))
  5935. {
  5936. UpdateSessionTab(SessionsPageControl->Pages[Index]);
  5937. }
  5938. }
  5939. }
  5940. //---------------------------------------------------------------------------
  5941. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  5942. UnicodeString Message, TQueryType Type,
  5943. bool Important, TNotifyEvent OnClick, TObject * UserData, Exception * E)
  5944. {
  5945. if ((E == NULL) ||
  5946. ExceptionMessage(E, Message))
  5947. {
  5948. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  5949. if (Important)
  5950. {
  5951. Seconds *= 5;
  5952. }
  5953. UnicodeString NoteMessage(UnformatMessage(Message));
  5954. if (Terminal != NULL)
  5955. {
  5956. NoteMessage = FORMAT(L"%s: %s",
  5957. (TTerminalManager::Instance()->TerminalTitle(Terminal), NoteMessage));
  5958. }
  5959. if (WinConfiguration->BalloonNotifications)
  5960. {
  5961. AddNote(NoteMessage);
  5962. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds, OnClick, UserData);
  5963. }
  5964. else
  5965. {
  5966. FlashOnBackground();
  5967. PostNote(NoteMessage, Seconds, OnClick, UserData);
  5968. }
  5969. }
  5970. }
  5971. //---------------------------------------------------------------------------
  5972. void __fastcall TCustomScpExplorerForm::QueueEmptyNoteClicked(TObject * Sender)
  5973. {
  5974. RestoreApp();
  5975. TTerminalNoteData * TerminalNoteData = dynamic_cast<TTerminalNoteData *>(Sender);
  5976. if (DebugAlwaysTrue(TerminalNoteData != NULL) &&
  5977. !NonVisualDataModule->Busy)
  5978. {
  5979. TTerminal * Terminal = TerminalNoteData->Terminal;
  5980. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  5981. if (!ComponentVisible[fcQueueView])
  5982. {
  5983. ToggleQueueVisibility();
  5984. GoToQueue();
  5985. }
  5986. }
  5987. }
  5988. //---------------------------------------------------------------------------
  5989. void __fastcall TCustomScpExplorerForm::QueueEvent(TTerminal * ATerminal,
  5990. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  5991. {
  5992. TManagedTerminal * ManagedTerminal = DebugNotNull(dynamic_cast<TManagedTerminal *>(ATerminal));
  5993. UnicodeString Message;
  5994. TNotifyEvent OnClick = NULL;
  5995. TObject * UserData = NULL;
  5996. bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized();
  5997. switch (Event)
  5998. {
  5999. case qeEmptyButMonitored:
  6000. if ((ATerminal != Terminal) || QueueInvisible)
  6001. {
  6002. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  6003. OnClick = QueueEmptyNoteClicked;
  6004. TTerminalNoteData * TerminalNoteData = new TTerminalNoteData();
  6005. TerminalNoteData->Terminal = ATerminal;
  6006. UserData = TerminalNoteData;
  6007. }
  6008. break;
  6009. case qeEmpty:
  6010. OperationComplete(ManagedTerminal->QueueOperationStart);
  6011. break;
  6012. case qePendingUserAction:
  6013. if ((ATerminal != Terminal) ||
  6014. (QueueInvisible && !IsQueueAutoPopup()))
  6015. {
  6016. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  6017. }
  6018. break;
  6019. default:
  6020. DebugFail();
  6021. }
  6022. if (!Message.IsEmpty())
  6023. {
  6024. Notify(ATerminal, Message, qtInformation, false, OnClick, UserData);
  6025. }
  6026. }
  6027. //---------------------------------------------------------------------------
  6028. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  6029. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  6030. {
  6031. if (FDDExtMapFile != NULL)
  6032. {
  6033. CloseHandle(FDDExtMapFile);
  6034. FDDExtMapFile = NULL;
  6035. }
  6036. if (WinConfiguration->DDExtEnabled)
  6037. {
  6038. if (!WinConfiguration->DDExtInstalled)
  6039. {
  6040. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtNotInstalled");
  6041. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_NOT_INSTALLED2), HELP_DRAGEXT_TARGET_NOT_INSTALLED);
  6042. }
  6043. DDExtInitDrag(FileList, Created);
  6044. }
  6045. }
  6046. //---------------------------------------------------------------------------
  6047. void __fastcall TCustomScpExplorerForm::DDExtInitDrag(TFileList * FileList,
  6048. bool & Created)
  6049. {
  6050. FDragExtFakeDirectory =
  6051. ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  6052. if (!ForceDirectories(ApiPath(FDragExtFakeDirectory)))
  6053. {
  6054. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (FDragExtFakeDirectory)));
  6055. }
  6056. FileList->AddItem(NULL, FDragExtFakeDirectory);
  6057. Created = true;
  6058. FDDExtMapFile = CreateFileMappingA((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  6059. 0, sizeof(TDragExtCommStruct), AnsiString(DRAG_EXT_MAPPING).c_str());
  6060. {
  6061. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6062. TDragExtCommStruct* CommStruct;
  6063. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6064. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6065. DebugAssert(CommStruct != NULL);
  6066. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  6067. CommStruct->Dragging = true;
  6068. wcsncpy(CommStruct->DropDest, FDragExtFakeDirectory.c_str(),
  6069. LENOF(CommStruct->DropDest));
  6070. NULL_TERMINATE(CommStruct->DropDest);
  6071. UnmapViewOfFile(CommStruct);
  6072. }
  6073. FDDMoveSlipped = false;
  6074. }
  6075. //---------------------------------------------------------------------------
  6076. bool __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  6077. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  6078. {
  6079. bool Result;
  6080. if (Sender == RemoteDirView)
  6081. {
  6082. Result = ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  6083. }
  6084. else
  6085. {
  6086. DebugAssert(Sender == RemoteDriveView);
  6087. TStrings * FileList = RemoteDriveView->DragFileList();
  6088. try
  6089. {
  6090. Result = ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  6091. }
  6092. __finally
  6093. {
  6094. delete FileList;
  6095. }
  6096. }
  6097. if (FDDTargetControl == RemoteDriveView)
  6098. {
  6099. RemoteDriveView->UpdateDropTarget();
  6100. }
  6101. // foRemoteMove happens when file/dir is dragged within the remote tree view
  6102. // or from tree view to dir view.
  6103. // foMove happens when file/dir is dragged from remote tree view outside of
  6104. // application via dragex
  6105. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  6106. (DropSourceControl == RemoteDriveView))
  6107. {
  6108. RemoteDriveView->UpdateDropSource();
  6109. }
  6110. return Result;
  6111. }
  6112. //---------------------------------------------------------------------------
  6113. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  6114. {
  6115. // This also handles drops of remote files to queue.
  6116. // Drops of local files (uploads) are handled in QueueDDProcessDropped.
  6117. SAFE_DESTROY(FDDFileList);
  6118. if ((FDDExtMapFile != NULL) || (FDDTargetControl == QueueView3))
  6119. {
  6120. try
  6121. {
  6122. TDragResult DDResult = (Sender == RemoteDirView) ?
  6123. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  6124. // Focus is moved to the target application,
  6125. // but as we are going to present the UI, we need to steal the focus back.
  6126. // This most likely won't work though (windows does not allow application
  6127. // to steal focus most of the time)
  6128. Application->BringToFront();
  6129. // On older version of Windows we never got drMove here, see also comment below.
  6130. // On Windows 10, we get the "move".
  6131. if ((DDResult == drCopy) || (DDResult == drMove) || (DDResult == drInvalid))
  6132. {
  6133. UnicodeString TargetDirectory;
  6134. TFileOperation Operation;
  6135. // drInvalid may mean drMove, see comment below
  6136. switch (DDResult)
  6137. {
  6138. case drCopy:
  6139. Operation = foCopy;
  6140. break;
  6141. case drMove:
  6142. Operation = foMove;
  6143. break;
  6144. default:
  6145. DebugFail();
  6146. case drInvalid:
  6147. // prefer "copy" for safety
  6148. Operation = FLAGSET(FLastDropEffect, DROPEFFECT_MOVE) ? foMove : foCopy;
  6149. break;
  6150. }
  6151. if (FDDMoveSlipped)
  6152. {
  6153. Operation = foMove;
  6154. }
  6155. TTransferOperationParam Param;
  6156. bool Internal;
  6157. bool ForceQueue;
  6158. if (!DDGetTarget(Param.TargetDirectory, ForceQueue, Internal))
  6159. {
  6160. // we get drInvalid both if d&d was intercepted by ddext,
  6161. // and when users drops on no-drop location.
  6162. // we tell the difference by existence of response from ddext,
  6163. // so we ignore absence of response in this case
  6164. if (DDResult != drInvalid)
  6165. {
  6166. // here we know that the extension is installed,
  6167. // as it is checked as soon as drag&drop starts from
  6168. // RemoteFileControlDDCreateDragFileList
  6169. Configuration->Usage->Inc(L"DownloadsDragDropExternalExtTargetUnknown");
  6170. throw ExtException(NULL, LoadStr(DRAGEXT_TARGET_UNKNOWN2), HELP_DRAGEXT_TARGET_UNKNOWN);
  6171. }
  6172. }
  6173. else
  6174. {
  6175. // download using ddext
  6176. Param.Temp = false;
  6177. Param.DragDrop = true;
  6178. if (ForceQueue)
  6179. {
  6180. Param.Queue = asOn;
  6181. }
  6182. if (Sender == RemoteDirView)
  6183. {
  6184. Param.Options = FLAGMASK(SelectedAllFilesInDirView(RemoteDirView), coAllFiles);
  6185. }
  6186. if (RemoteFileControlFileOperation(Sender, Operation,
  6187. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  6188. {
  6189. Configuration->Usage->Inc(
  6190. Internal ? L"DownloadsDragDropInternal" : L"DownloadsDragDropExternalExt");
  6191. }
  6192. }
  6193. }
  6194. }
  6195. __finally
  6196. {
  6197. CloseHandle(FDDExtMapFile);
  6198. FDDExtMapFile = NULL;
  6199. RemoveDir(ApiPath(FDragExtFakeDirectory));
  6200. FDragExtFakeDirectory = L"";
  6201. }
  6202. }
  6203. if (!FDragDropSshTerminate.IsEmpty())
  6204. {
  6205. throw ESshTerminate(NULL, FDragDropSshTerminate, FDragDropOnceDoneOperation);
  6206. }
  6207. }
  6208. //---------------------------------------------------------------------------
  6209. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  6210. TObject * Sender, int dwEffect, HRESULT & /*Result*/)
  6211. {
  6212. HCURSOR SlippedCopyCursor;
  6213. FDDMoveSlipped =
  6214. (FDragMoveCursor != NULL) &&
  6215. (!WinConfiguration->DDAllowMoveInit) && (dwEffect == DROPEFFECT_Copy) &&
  6216. ((IsFileControl(FDDTargetControl, osRemote) && (GetKeyState(VK_CONTROL) >= 0) &&
  6217. FTerminal->IsCapable[fcRemoteMove]) ||
  6218. (IsFileControl(FDDTargetControl, osLocal) && (GetKeyState(VK_SHIFT) < 0)));
  6219. SlippedCopyCursor = FDDMoveSlipped ? FDragMoveCursor : Dragdrop::DefaultCursor;
  6220. DragDropFiles(Sender)->CHCopy = SlippedCopyCursor;
  6221. DragDropFiles(Sender)->CHScrollCopy = SlippedCopyCursor;
  6222. // Remember drop effect so we know (when user drops files), if we copy or move
  6223. FLastDropEffect = dwEffect;
  6224. }
  6225. //---------------------------------------------------------------------------
  6226. bool __fastcall TCustomScpExplorerForm::DDGetTarget(
  6227. UnicodeString & Directory, bool & ForceQueue, bool & Internal)
  6228. {
  6229. bool Result;
  6230. if (FDDTargetControl == QueueView3)
  6231. {
  6232. Directory = DefaultDownloadTargetDirectory();
  6233. Result = true;
  6234. Internal = true;
  6235. ForceQueue = true;
  6236. }
  6237. else
  6238. {
  6239. ForceQueue = false;
  6240. Enabled = false;
  6241. try
  6242. {
  6243. int Timer = 0;
  6244. Result = false;
  6245. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  6246. {
  6247. {
  6248. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  6249. TDragExtCommStruct* CommStruct;
  6250. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  6251. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  6252. DebugAssert(CommStruct != NULL);
  6253. Result = !CommStruct->Dragging;
  6254. if (Result)
  6255. {
  6256. Directory = ExtractFilePath(CommStruct->DropDest);
  6257. Internal = false;
  6258. }
  6259. UnmapViewOfFile(CommStruct);
  6260. }
  6261. if (!Result)
  6262. {
  6263. Sleep(50);
  6264. Timer += 50;
  6265. Application->ProcessMessages();
  6266. }
  6267. }
  6268. }
  6269. __finally
  6270. {
  6271. Enabled = true;
  6272. }
  6273. }
  6274. return Result;
  6275. }
  6276. //---------------------------------------------------------------------------
  6277. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  6278. const UnicodeString TempDir, int SecDelay)
  6279. {
  6280. TDateTime Alarm = Now() + (double)((double)SecDelay*OneMillisecond);
  6281. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  6282. if (FDelayedDeletionTimer == NULL)
  6283. {
  6284. DebugAssert(HandleAllocated());
  6285. FDelayedDeletionTimer = new TTimer(this);
  6286. FDelayedDeletionTimer->Interval = 10000;
  6287. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  6288. }
  6289. else
  6290. {
  6291. FDelayedDeletionTimer->Enabled = true;
  6292. }
  6293. }
  6294. //---------------------------------------------------------------------------
  6295. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  6296. {
  6297. DebugAssert(FDelayedDeletionList != NULL);
  6298. TDateTime N = Now();
  6299. TDateTime Alert;
  6300. UnicodeString Directory;
  6301. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  6302. {
  6303. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  6304. if ((N >= Alert) || (Sender == NULL))
  6305. {
  6306. Directory = FDelayedDeletionList->Strings[Index];
  6307. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  6308. {
  6309. FDelayedDeletionList->Delete(Index);
  6310. }
  6311. }
  6312. }
  6313. if (FDelayedDeletionList->Count == 0)
  6314. {
  6315. FDelayedDeletionTimer->Enabled = false;
  6316. }
  6317. }
  6318. //---------------------------------------------------------------------------
  6319. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  6320. {
  6321. if (IsFileControl(FDDTargetControl, osRemote) ||
  6322. (FDDTargetControl == SessionsPageControl))
  6323. {
  6324. TTerminal * TargetTerminal = NULL;
  6325. TFileOperation Operation = foNone;
  6326. if (FDDTargetControl == SessionsPageControl)
  6327. {
  6328. TPoint Point = SessionsPageControl->ScreenToClient(Mouse->CursorPos);
  6329. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  6330. // do not allow dropping on the "+" tab
  6331. TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  6332. if (TargetTerminal != NULL)
  6333. {
  6334. if ((FLastDropEffect == DROPEFFECT_MOVE) &&
  6335. (TargetTerminal == TTerminalManager::Instance()->ActiveTerminal))
  6336. {
  6337. Operation = foRemoteMove;
  6338. }
  6339. else
  6340. {
  6341. Operation = foRemoteCopy;
  6342. }
  6343. }
  6344. }
  6345. else
  6346. {
  6347. // when move from remote side is disabled, we allow copying inside the remote
  6348. // panel, but we interpret is as moving (we also slip in the move cursor)
  6349. if ((FLastDropEffect == DROPEFFECT_MOVE) ||
  6350. (!WinConfiguration->DDAllowMoveInit && (FLastDropEffect == DROPEFFECT_COPY) &&
  6351. FDDMoveSlipped))
  6352. {
  6353. Operation = foRemoteMove;
  6354. }
  6355. else if (FLastDropEffect == DROPEFFECT_COPY)
  6356. {
  6357. Operation = foRemoteCopy;
  6358. }
  6359. }
  6360. if (Operation != foNone)
  6361. {
  6362. RemoteFileControlFileOperation(DropSourceControl,
  6363. Operation, (WinConfiguration->DDTransferConfirmation == asOff), TargetTerminal);
  6364. }
  6365. // abort drag&drop
  6366. Abort();
  6367. }
  6368. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE) &&
  6369. // Drops of remote files to queue are handled in RemoteFileControlDDEnd
  6370. (FDDTargetControl != QueueView3))
  6371. {
  6372. DebugAssert(!FDragTempDir.IsEmpty());
  6373. TTransferType Type;
  6374. UnicodeString TempDir = FDragTempDir;
  6375. // We clear FDragTempDir before calling
  6376. // just in case it fail (raises exception)
  6377. FDragTempDir = L"";
  6378. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  6379. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  6380. // empty directory parameter means temp directory -> don't display it!
  6381. UnicodeString TargetDir = L"";
  6382. int Options = 0;
  6383. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  6384. TargetDir, CopyParams, (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  6385. {
  6386. Abort();
  6387. }
  6388. // TargetDir is set when dropped on local file control
  6389. // (this was workaround for legacy dirview event handling, now it should be
  6390. // made prettier)
  6391. if (TargetDir.IsEmpty())
  6392. {
  6393. TargetDir = TempDir;
  6394. if (ForceDirectories(ApiPath(TargetDir)))
  6395. {
  6396. DebugAssert(Terminal && !TargetDir.IsEmpty());
  6397. FPendingTempSpaceWarn = true;
  6398. try
  6399. {
  6400. FDragDropOperation = true;
  6401. int Params = cpTemporary |
  6402. (Type == ttMove ? cpDelete : 0);
  6403. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  6404. Configuration->Usage->Inc(L"DownloadsDragDropExternalTemp");
  6405. }
  6406. __finally
  6407. {
  6408. FDragDropOperation = false;
  6409. FPendingTempSpaceWarn = false;
  6410. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  6411. }
  6412. }
  6413. else
  6414. {
  6415. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  6416. }
  6417. }
  6418. }
  6419. }
  6420. //---------------------------------------------------------------------------
  6421. void __fastcall TCustomScpExplorerForm::DDDownload(TStrings * FilesToCopy,
  6422. const UnicodeString TargetDir, const TCopyParamType * CopyParam, int Params)
  6423. {
  6424. void * BatchStorage;
  6425. BatchStart(BatchStorage);
  6426. try
  6427. {
  6428. UpdateCopyParamCounters(*CopyParam);
  6429. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params);
  6430. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  6431. {
  6432. RemoteDriveView->UpdateDropSource();
  6433. }
  6434. }
  6435. __finally
  6436. {
  6437. BatchEnd(BatchStorage);
  6438. }
  6439. }
  6440. //---------------------------------------------------------------------------
  6441. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  6442. {
  6443. public:
  6444. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  6445. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename)
  6446. {
  6447. }
  6448. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  6449. {
  6450. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  6451. TDataObjectFilesEx::AllowData(FormatEtc);
  6452. }
  6453. };
  6454. //---------------------------------------------------------------------------
  6455. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  6456. TObject * Sender, TDataObject *& DataObject)
  6457. {
  6458. if (FDDExtMapFile != NULL)
  6459. {
  6460. TFileList * FileList = DragDropFiles(Sender)->FileList;
  6461. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  6462. {
  6463. Abort();
  6464. }
  6465. if (FileList->Count > 0)
  6466. {
  6467. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  6468. if (!FilesObject->IsValid(true, true))
  6469. {
  6470. FilesObject->_Release();
  6471. }
  6472. else
  6473. {
  6474. DataObject = FilesObject;
  6475. }
  6476. }
  6477. }
  6478. }
  6479. //---------------------------------------------------------------------------
  6480. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  6481. {
  6482. DebugFail();
  6483. }
  6484. //---------------------------------------------------------------------------
  6485. void __fastcall TCustomScpExplorerForm::GoToTree()
  6486. {
  6487. ComponentVisible[fcRemoteTree] = true;
  6488. RemoteDriveView->SetFocus();
  6489. }
  6490. //---------------------------------------------------------------------------
  6491. TStrings * __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  6492. TPanelExport Export)
  6493. {
  6494. TCustomDirView * DirView = this->DirView(Side);
  6495. std::unique_ptr<TStrings> ExportData(new TStringList());
  6496. switch (Export)
  6497. {
  6498. case pePath:
  6499. ExportData->Add(DirView->PathName);
  6500. break;
  6501. case peFileList:
  6502. case peFullFileList:
  6503. {
  6504. bool FullPath = (Export == peFullFileList);
  6505. DirView->CreateFileList(false, FullPath, ExportData.get());
  6506. for (int Index = 0; Index < ExportData->Count; Index++)
  6507. {
  6508. if (ExportData->Strings[Index].Pos(L" ") > 0)
  6509. {
  6510. ExportData->Strings[Index] = FORMAT(L"\"%s\"", (ExportData->Strings[Index]));
  6511. }
  6512. }
  6513. }
  6514. break;
  6515. default:
  6516. DebugFail();
  6517. }
  6518. return ExportData.release();
  6519. }
  6520. //---------------------------------------------------------------------------
  6521. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  6522. TPanelExport Export, TPanelExportDestination Destination)
  6523. {
  6524. std::unique_ptr<TStrings> ExportData(PanelExport(Side, Export));
  6525. PanelExportStore(Side, Export, Destination, ExportData.get());
  6526. }
  6527. //---------------------------------------------------------------------------
  6528. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  6529. TPanelExport /*Export*/, TPanelExportDestination Destination,
  6530. TStrings * ExportData)
  6531. {
  6532. if (Destination == pedClipboard)
  6533. {
  6534. TInstantOperationVisualizer Visualizer;
  6535. CopyToClipboard(ExportData);
  6536. }
  6537. else
  6538. {
  6539. DebugFail();
  6540. }
  6541. }
  6542. //---------------------------------------------------------------------------
  6543. void __fastcall TCustomScpExplorerForm::Filter(TOperationSide Side)
  6544. {
  6545. TCustomDirView * DirView = this->DirView(Side);
  6546. TFileFilter Filter;
  6547. DefaultFileFilter(Filter);
  6548. Filter.Masks = DirView->Mask;
  6549. if (DoFilterMaskDialog(DirView, &Filter))
  6550. {
  6551. DirView->Mask = TFileMasks::NormalizeMask(Filter.Masks);
  6552. }
  6553. }
  6554. //---------------------------------------------------------------------------
  6555. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  6556. {
  6557. return FQueueController->DefaultOperation();
  6558. }
  6559. //---------------------------------------------------------------------------
  6560. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  6561. TQueueOperation Operation, void ** Param)
  6562. {
  6563. switch (Operation)
  6564. {
  6565. case qoPreferences:
  6566. return true;
  6567. case qoGoTo:
  6568. return ComponentVisible[fcQueueView] && QueueView3->Enabled;
  6569. case qoOnceEmpty:
  6570. return !FQueueController->Empty;
  6571. default:
  6572. return FQueueController->AllowOperation(Operation, Param);
  6573. }
  6574. }
  6575. //---------------------------------------------------------------------------
  6576. void __fastcall TCustomScpExplorerForm::GoToQueue()
  6577. {
  6578. if (DebugAlwaysTrue(QueueView3->Visible))
  6579. {
  6580. QueueView3->SetFocus();
  6581. }
  6582. }
  6583. //---------------------------------------------------------------------------
  6584. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  6585. TQueueOperation Operation, void * Param)
  6586. {
  6587. if (Operation == qoGoTo)
  6588. {
  6589. GoToQueue();
  6590. }
  6591. else if (Operation == qoPreferences)
  6592. {
  6593. PreferencesDialog(pmQueue);
  6594. }
  6595. else
  6596. {
  6597. FQueueController->ExecuteOperation(Operation, Param);
  6598. }
  6599. }
  6600. //---------------------------------------------------------------------------
  6601. bool __fastcall TCustomScpExplorerForm::GetQueueEnabled()
  6602. {
  6603. return (Queue != NULL) && Queue->Enabled;
  6604. }
  6605. //---------------------------------------------------------------------------
  6606. void __fastcall TCustomScpExplorerForm::ToggleQueueEnabled()
  6607. {
  6608. DebugAssert(Queue != NULL);
  6609. if (Queue != NULL)
  6610. {
  6611. Queue->Enabled = !Queue->Enabled;
  6612. }
  6613. }
  6614. //---------------------------------------------------------------------------
  6615. void __fastcall TCustomScpExplorerForm::QueueView3ContextPopup(
  6616. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  6617. {
  6618. FQueueActedItem = QueueView3->ItemFocused;
  6619. }
  6620. //---------------------------------------------------------------------------
  6621. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  6622. {
  6623. return TopDock->Height + QueueSplitter->Height;
  6624. }
  6625. //---------------------------------------------------------------------------
  6626. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  6627. TObject * /*Sender*/, int & NewSize, bool & Accept)
  6628. {
  6629. // when queue is hidden by double-clicking splitter, stray attempt to
  6630. // resize the panel with strange value arrives, make sure it is ignored
  6631. if (ComponentVisible[fcQueueView])
  6632. {
  6633. int HeightLimit = ClientHeight - GetStaticComponentsHeight() -
  6634. RemotePanel->Constraints->MinHeight;
  6635. if (NewSize > HeightLimit)
  6636. {
  6637. NewSize = HeightLimit;
  6638. }
  6639. }
  6640. else
  6641. {
  6642. Accept = false;
  6643. }
  6644. }
  6645. //---------------------------------------------------------------------------
  6646. void __fastcall TCustomScpExplorerForm::QueueView3StartDrag(TObject * /*Sender*/,
  6647. TDragObject *& /*DragObject*/)
  6648. {
  6649. FQueueActedItem = QueueView3->ItemFocused;
  6650. }
  6651. //---------------------------------------------------------------------------
  6652. void __fastcall TCustomScpExplorerForm::QueueView3DragOver(TObject * /*Sender*/,
  6653. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  6654. {
  6655. Accept = true;
  6656. if (Source == QueueView3)
  6657. {
  6658. TListItem * DropTarget = QueueView3->GetItemAt(X, Y);
  6659. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  6660. if (Accept)
  6661. {
  6662. TQueueItemProxy * QueueItem;
  6663. TQueueItemProxy * DestQueueItem;
  6664. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  6665. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  6666. Accept = (QueueItem != DestQueueItem) &&
  6667. (QueueItem->Status == TQueueItem::qsPending) &&
  6668. (DestQueueItem->Status == TQueueItem::qsPending);
  6669. }
  6670. }
  6671. }
  6672. //---------------------------------------------------------------------------
  6673. void __fastcall TCustomScpExplorerForm::QueueView3DragDrop(TObject * /*Sender*/,
  6674. TObject * /*Source*/, int /*X*/, int /*Y*/)
  6675. {
  6676. if ((FQueueActedItem != NULL) && (QueueView3->DropTarget != NULL))
  6677. {
  6678. TQueueItemProxy * QueueItem;
  6679. TQueueItemProxy * DestQueueItem;
  6680. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  6681. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView3->DropTarget->Data);
  6682. QueueItem->Move(DestQueueItem);
  6683. }
  6684. }
  6685. //---------------------------------------------------------------------------
  6686. void __fastcall TCustomScpExplorerForm::QueueView3Enter(TObject * /*Sender*/)
  6687. {
  6688. if ((QueueView3->ItemFocused == NULL) &&
  6689. (QueueView3->Items->Count > 0))
  6690. {
  6691. QueueView3->ItemFocused = QueueView3->Items->Item[0];
  6692. }
  6693. QueueLabelUpdateStatus();
  6694. }
  6695. //---------------------------------------------------------------------------
  6696. void __fastcall TCustomScpExplorerForm::QueueView3Exit(TObject * /*Sender*/)
  6697. {
  6698. QueueLabelUpdateStatus();
  6699. }
  6700. //---------------------------------------------------------------------------
  6701. void __fastcall TCustomScpExplorerForm::QueueLabelUpdateStatus()
  6702. {
  6703. QueueLabel->UpdateStatus();
  6704. }
  6705. //---------------------------------------------------------------------------
  6706. void __fastcall TCustomScpExplorerForm::QueueView3SelectItem(
  6707. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  6708. {
  6709. if (Selected)
  6710. {
  6711. NonVisualDataModule->UpdateNonVisibleActions();
  6712. }
  6713. }
  6714. //---------------------------------------------------------------------------
  6715. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  6716. {
  6717. TDragDropFilesEx * Result = NULL;
  6718. if (Sender == SessionsPageControl)
  6719. {
  6720. Result = FSessionsDragDropFilesEx;
  6721. }
  6722. else if (Sender == QueueView3)
  6723. {
  6724. Result = FQueueDragDropFilesEx;
  6725. }
  6726. else
  6727. {
  6728. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  6729. if (DirView != NULL)
  6730. {
  6731. Result = DirView->DragDropFilesEx;
  6732. }
  6733. else
  6734. {
  6735. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  6736. if (DriveView != NULL)
  6737. {
  6738. Result = DriveView->DragDropFilesEx;
  6739. }
  6740. }
  6741. }
  6742. DebugAssert(Result != NULL);
  6743. return Result;
  6744. }
  6745. //---------------------------------------------------------------------------
  6746. bool __fastcall TCustomScpExplorerForm::SelectedAllFilesInDirView(TCustomDirView * DView)
  6747. {
  6748. return (DView->SelCount == DView->FilesCount);
  6749. }
  6750. //---------------------------------------------------------------------------
  6751. bool __fastcall TCustomScpExplorerForm::DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList)
  6752. {
  6753. return HasDirView[Side] && (DropSourceControl == DirView(Side)) && (FileList->Count == DirView(Side)->FilesCount);
  6754. }
  6755. //---------------------------------------------------------------------------
  6756. void __fastcall TCustomScpExplorerForm::RemoteFileControlDragDropFileOperation(
  6757. TObject * Sender, int Effect, UnicodeString TargetPath, bool ForceQueue)
  6758. {
  6759. TFileOperation Operation;
  6760. switch (Effect)
  6761. {
  6762. case DROPEFFECT_MOVE:
  6763. Operation = foMove;
  6764. break;
  6765. case DROPEFFECT_COPY:
  6766. // occures on WinXP (reported by user)
  6767. default:
  6768. Operation = foCopy;
  6769. break;
  6770. };
  6771. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  6772. // see a comment in TUnixDirView::PerformItemDragDropOperation
  6773. if (DragDropFilesEx->FileList->Count > 0)
  6774. {
  6775. TStrings * FileList = new TStringList();
  6776. try
  6777. {
  6778. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  6779. {
  6780. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  6781. }
  6782. FDragDropOperation = true;
  6783. TTransferOperationParam Param;
  6784. Param.TargetDirectory = TargetPath;
  6785. // upload, no temp dirs
  6786. Param.Temp = false;
  6787. Param.DragDrop = true;
  6788. Param.Options =
  6789. FLAGMASK(DraggingAllFilesFromDirView(osLocal, FileList), coAllFiles);
  6790. if (ForceQueue)
  6791. {
  6792. Param.Queue = asOn;
  6793. }
  6794. if (ExecuteFileOperation(Operation, osLocal, FileList,
  6795. (WinConfiguration->DDTransferConfirmation == asOff), &Param))
  6796. {
  6797. if (IsFileControl(DropSourceControl, osLocal))
  6798. {
  6799. Configuration->Usage->Inc(L"UploadsDragDropInternal");
  6800. }
  6801. else
  6802. {
  6803. Configuration->Usage->Inc(L"UploadsDragDropExternal");
  6804. }
  6805. }
  6806. }
  6807. __finally
  6808. {
  6809. FDragDropOperation = false;
  6810. delete FileList;
  6811. }
  6812. }
  6813. }
  6814. //---------------------------------------------------------------------------
  6815. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  6816. TObject * Sender, int Effect, UnicodeString /*SourcePath*/,
  6817. UnicodeString TargetPath, bool & /*DoOperation*/)
  6818. {
  6819. RemoteFileControlDragDropFileOperation(Sender, Effect, TargetPath, false);
  6820. }
  6821. //---------------------------------------------------------------------------
  6822. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  6823. TObject * Sender, int grfKeyState, int & dwEffect)
  6824. {
  6825. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  6826. if ((dwEffect != DROPEFFECT_None) &&
  6827. IsFileControl(DropSourceControl, osRemote))
  6828. {
  6829. // do not allow drop on remote panel (on free space, still allow drop on directories)
  6830. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  6831. (RemoteDirView->DropTarget == NULL))
  6832. {
  6833. dwEffect = DROPEFFECT_None;
  6834. }
  6835. else
  6836. {
  6837. if (dwEffect == DROPEFFECT_Copy)
  6838. {
  6839. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  6840. // currently we support copying always (at least via temporary directory);
  6841. // remove associated checks once this all proves stable and working
  6842. bool CopyCapable = true;
  6843. // if we do not support neither of operations, there's no discussion
  6844. if (!MoveCapable && !CopyCapable)
  6845. {
  6846. dwEffect = DROPEFFECT_None;
  6847. }
  6848. // when moving is disabled, we need to keep effect to "copy",
  6849. // which will be later interpretted as move (with slipped-in cursor)
  6850. else if (!WinConfiguration->DDAllowMoveInit && FLAGCLEAR(grfKeyState, MK_CONTROL))
  6851. {
  6852. // no-op, keep copy
  6853. }
  6854. else
  6855. {
  6856. // The default effect inside remote panel is move,
  6857. // unless we do not support it, but support copy
  6858. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  6859. {
  6860. dwEffect = MoveCapable ? DROPEFFECT_Move : DROPEFFECT_Copy;
  6861. }
  6862. else
  6863. {
  6864. // with ctrl-down, we want copy unless it is not supported
  6865. dwEffect = CopyCapable ? DROPEFFECT_Copy : DROPEFFECT_None;
  6866. }
  6867. }
  6868. }
  6869. }
  6870. }
  6871. }
  6872. //---------------------------------------------------------------------------
  6873. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  6874. TObject * Sender, TRemoteFile * File, UnicodeString & FileName)
  6875. {
  6876. if (FDDTotalSize >= 0)
  6877. {
  6878. if (File->IsDirectory)
  6879. {
  6880. FDDTotalSize = -1;
  6881. }
  6882. else
  6883. {
  6884. FDDTotalSize += File->Size;
  6885. }
  6886. }
  6887. DebugAssert(!FDragTempDir.IsEmpty());
  6888. // TODO: this is quite ineffective
  6889. // TODO: what if invalid character replacement is disabled?
  6890. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  6891. UnicodeString TransferFileName;
  6892. if (Sender == RemoteDriveView)
  6893. {
  6894. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  6895. }
  6896. else
  6897. {
  6898. TransferFileName = File->FileName;
  6899. }
  6900. FDDFileList->AddObject(TransferFileName, File);
  6901. }
  6902. //---------------------------------------------------------------------------
  6903. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  6904. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  6905. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  6906. {
  6907. // sometimes we do not get DDEnd so the list is not released
  6908. SAFE_DESTROY(FDDFileList);
  6909. FDDFileList = new TStringList();
  6910. FDragTempDir = WinConfiguration->TemporaryDir();
  6911. FDDTotalSize = 0;
  6912. FDragDropSshTerminate = L"";
  6913. FDragDropOnceDoneOperation = odoIdle;
  6914. }
  6915. //---------------------------------------------------------------------------
  6916. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  6917. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  6918. HRESULT & Result)
  6919. {
  6920. if (Result == DRAGDROP_S_DROP)
  6921. {
  6922. try
  6923. {
  6924. GlobalDragImageList->HideDragImage();
  6925. try
  6926. {
  6927. RemoteFileControlDDTargetDrop();
  6928. }
  6929. catch(ESshTerminate & E)
  6930. {
  6931. DebugAssert(E.MoreMessages == NULL); // not supported
  6932. DebugAssert(!E.Message.IsEmpty());
  6933. FDragDropSshTerminate = E.Message;
  6934. FDragDropOnceDoneOperation = E.Operation;
  6935. }
  6936. }
  6937. catch (Exception &E)
  6938. {
  6939. // If downloading fails we need to cancel drag&drop, otherwise
  6940. // Explorer shows error
  6941. // But by the way exception probably never reach this point as
  6942. // it's catched on way.
  6943. // Fatal exceptions get here (like when opening a secondary shell extension for file duplication fails).
  6944. Result = DRAGDROP_S_CANCEL;
  6945. ShowExtendedException(Terminal, &E);
  6946. }
  6947. }
  6948. }
  6949. //---------------------------------------------------------------------------
  6950. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  6951. TObject * /*Sender*/, UnicodeString FileName, bool Directory, __int64 Size,
  6952. TDateTime Modification, UnicodeString Masks, bool & Matches, bool AllowImplicitMatches)
  6953. {
  6954. TFileMasks::TParams MaskParams;
  6955. MaskParams.Size = Size;
  6956. MaskParams.Modification = Modification;
  6957. // this does not re-parse the mask if it is the same as the last time
  6958. FDirViewMatchMask = Masks;
  6959. bool ImplicitMatch;
  6960. Matches =
  6961. // RecurseInclude parameter has no effect as the Path is empty
  6962. FDirViewMatchMask.Matches(FileName, Directory, UnicodeString(L""), &MaskParams, true, ImplicitMatch) &&
  6963. (AllowImplicitMatches || !ImplicitMatch);
  6964. }
  6965. //---------------------------------------------------------------------------
  6966. void __fastcall TCustomScpExplorerForm::DirViewGetOverlay(
  6967. TObject * Sender, TListItem * Item, WORD & Indexes)
  6968. {
  6969. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  6970. UnicodeString Ext;
  6971. if (DirView == RemoteDirView)
  6972. {
  6973. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  6974. }
  6975. else
  6976. {
  6977. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  6978. }
  6979. if (SameText(Ext, Configuration->PartialExt))
  6980. {
  6981. Indexes |= oiPartial;
  6982. }
  6983. }
  6984. //---------------------------------------------------------------------------
  6985. bool __fastcall TCustomScpExplorerForm::CanPasteToDirViewFromClipBoard()
  6986. {
  6987. return
  6988. DirViewEnabled(osCurrent) &&
  6989. DirView(osCurrent)->CanPasteFromClipBoard();
  6990. }
  6991. //---------------------------------------------------------------------------
  6992. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  6993. {
  6994. bool Result = false;
  6995. if (CanPasteToDirViewFromClipBoard())
  6996. {
  6997. Result = true;
  6998. }
  6999. else
  7000. {
  7001. UnicodeString ClipboardText;
  7002. if (NonEmptyTextFromClipboard(ClipboardText))
  7003. {
  7004. if (StoredSessions->IsUrl(ClipboardText))
  7005. {
  7006. Result = true;
  7007. }
  7008. else
  7009. {
  7010. Result = DirViewEnabled(osCurrent);
  7011. }
  7012. }
  7013. }
  7014. return Result;
  7015. }
  7016. //---------------------------------------------------------------------------
  7017. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  7018. {
  7019. if (CanPasteToDirViewFromClipBoard())
  7020. {
  7021. DirView(osCurrent)->PasteFromClipBoard();
  7022. }
  7023. else
  7024. {
  7025. UnicodeString ClipboardText;
  7026. if (NonEmptyTextFromClipboard(ClipboardText))
  7027. {
  7028. if (StoredSessions->IsUrl(ClipboardText))
  7029. {
  7030. NewSession(false, ClipboardText);
  7031. }
  7032. else
  7033. {
  7034. DirView(osCurrent)->Path = ClipboardText;
  7035. }
  7036. }
  7037. }
  7038. }
  7039. //---------------------------------------------------------------------------
  7040. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  7041. {
  7042. // TBD
  7043. }
  7044. //---------------------------------------------------------------------------
  7045. void __fastcall TCustomScpExplorerForm::SelectSameExt(bool Select)
  7046. {
  7047. TCustomDirView * CurrentDirView = DirView(osCurrent);
  7048. if (DebugAlwaysTrue(CurrentDirView->ItemFocused != NULL))
  7049. {
  7050. UnicodeString FileName = CurrentDirView->ItemFileName(CurrentDirView->ItemFocused);
  7051. UnicodeString Ext;
  7052. if (GetSide(osCurrent) == osRemote)
  7053. {
  7054. Ext = UnixExtractFileExt(FileName);
  7055. }
  7056. else
  7057. {
  7058. Ext = ExtractFileExt(FileName);
  7059. }
  7060. if (Ext.IsEmpty())
  7061. {
  7062. Ext = L".";
  7063. }
  7064. TFileFilter Filter;
  7065. Filter.Masks = FORMAT(L"*%s", (Ext));
  7066. Filter.Directories = false;
  7067. CurrentDirView->SelectFiles(Filter, Select);
  7068. }
  7069. }
  7070. //---------------------------------------------------------------------------
  7071. UnicodeString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  7072. const TStatusFileInfo & FileInfo, TOperationSide Side)
  7073. {
  7074. UnicodeString Result;
  7075. if ((Side == osRemote) && (Terminal == NULL))
  7076. {
  7077. // noop
  7078. }
  7079. else
  7080. {
  7081. Result =
  7082. FMTLOAD(FILE_INFO_FORMAT,
  7083. (FormatBytes(FileInfo.SelectedSize),
  7084. FormatBytes(FileInfo.FilesSize),
  7085. FormatNumber(FileInfo.SelectedCount),
  7086. FormatNumber(FileInfo.FilesCount)));
  7087. }
  7088. return Result;
  7089. }
  7090. //---------------------------------------------------------------------------
  7091. void __fastcall TCustomScpExplorerForm::FileStatusBarPanelClick(
  7092. TTBXStatusPanel * Panel, TOperationSide Side)
  7093. {
  7094. if (Panel->Index == 1)
  7095. {
  7096. ToggleShowHiddenFiles();
  7097. }
  7098. else if (Panel->Index == 2)
  7099. {
  7100. Filter(Side);
  7101. }
  7102. }
  7103. //---------------------------------------------------------------------------
  7104. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  7105. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, TOperationSide Side)
  7106. {
  7107. DebugAssert(!StatusBar->SimplePanel);
  7108. StatusBar->Panels->Items[0]->Caption = FileStatusBarText(FileInfo, Side);
  7109. UpdateFileStatusExtendedPanels(StatusBar, FileInfo);
  7110. }
  7111. //---------------------------------------------------------------------------
  7112. void __fastcall TCustomScpExplorerForm::UpdateFileStatusExtendedPanels(
  7113. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo)
  7114. {
  7115. DebugAssert(StatusBar->Panels->Count >= 3);
  7116. TTBXStatusPanel * HiddenFilesPanel = StatusBar->Panels->Items[1];
  7117. if (FileInfo.HiddenCount > 0)
  7118. {
  7119. HiddenFilesPanel->Caption = FMTLOAD(FILE_INFO_HIDDEN2, (FormatNumber(FileInfo.HiddenCount)));
  7120. HiddenFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7121. }
  7122. else
  7123. {
  7124. HiddenFilesPanel->ViewPriority = 0;
  7125. // not really necessary, just to cleanup no-longer-valid data
  7126. HiddenFilesPanel->Caption = L"";
  7127. }
  7128. TTBXStatusPanel * FilteredFilesPanel = StatusBar->Panels->Items[2];
  7129. if (FileInfo.FilteredCount > 0)
  7130. {
  7131. FilteredFilesPanel->Caption = FMTLOAD(FILE_INFO_FILTERED2, (FormatNumber(FileInfo.FilteredCount)));
  7132. FilteredFilesPanel->ViewPriority = 90; // <100 allows hiding panel when it does not fit
  7133. }
  7134. else
  7135. {
  7136. FilteredFilesPanel->ViewPriority = 0;
  7137. // not really necessary, just to cleanup no-longer-valid data
  7138. FilteredFilesPanel->Caption = L"";
  7139. }
  7140. }
  7141. //---------------------------------------------------------------------------
  7142. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  7143. TObject * /*Sender*/)
  7144. {
  7145. if (RemoteDirView->Enabled)
  7146. {
  7147. RemoteDirView->SetFocus();
  7148. }
  7149. }
  7150. //---------------------------------------------------------------------------
  7151. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  7152. {
  7153. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  7154. switch (Config.Show)
  7155. {
  7156. case qvShow:
  7157. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  7158. {
  7159. Config.Show = qvHide;
  7160. }
  7161. else
  7162. {
  7163. Config.Show = Config.LastHideShow;
  7164. }
  7165. break;
  7166. case qvHideWhenEmpty:
  7167. if (ComponentVisible[fcQueueView])
  7168. {
  7169. Config.Show = qvHide;
  7170. }
  7171. else
  7172. {
  7173. Config.LastHideShow = Config.Show;
  7174. Config.Show = qvShow;
  7175. }
  7176. break;
  7177. case qvHide:
  7178. Config.LastHideShow = Config.Show;
  7179. Config.Show = qvShow;
  7180. break;
  7181. }
  7182. WinConfiguration->QueueView = Config;
  7183. }
  7184. //---------------------------------------------------------------------------
  7185. UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
  7186. {
  7187. UnicodeString Result;
  7188. if (FTerminal != NULL)
  7189. {
  7190. switch (WinConfiguration->PathInCaption)
  7191. {
  7192. case picShort:
  7193. {
  7194. Result = UnixExtractFileName(FTerminal->CurrentDirectory);
  7195. if (Result.IsEmpty())
  7196. {
  7197. Result = FTerminal->CurrentDirectory;
  7198. }
  7199. }
  7200. break;
  7201. case picFull:
  7202. Result = FTerminal->CurrentDirectory;
  7203. break;
  7204. }
  7205. }
  7206. return Result;
  7207. }
  7208. //---------------------------------------------------------------------------
  7209. void __fastcall TCustomScpExplorerForm::UpdateControls()
  7210. {
  7211. TTerminalManager::Instance()->UpdateAppTitle();
  7212. // WORAKRDOUND: Disabling list view when it is not showing yet does not set its
  7213. // background to gray on Windows 7 (works on Windows 10).
  7214. // See also EnableControl
  7215. if (Showing)
  7216. {
  7217. bool HasTerminal = (Terminal != NULL);
  7218. if (HasTerminal)
  7219. {
  7220. if (!RemoteDirView->Enabled)
  7221. {
  7222. RemoteDirView->Enabled = true;
  7223. if (FRemoteDirViewWasFocused)
  7224. {
  7225. ActiveControl = RemoteDirView;
  7226. }
  7227. }
  7228. RemoteDriveView->Enabled = true;
  7229. RemoteDirView->Color = (FSessionColor != 0 ? FSessionColor : clWindow);
  7230. RemoteDriveView->Color = RemoteDirView->Color;
  7231. }
  7232. else
  7233. {
  7234. if (RemoteDirView->Enabled)
  7235. {
  7236. // This is first called when the form is being constructed
  7237. // (not anymore due to Showing test above)
  7238. // but the false is overriden in the constructor later.
  7239. // An even later in TScpCommanderForm::DoShow()
  7240. FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
  7241. EnableControl(RemoteDirView, false);
  7242. }
  7243. EnableControl(RemoteDriveView, false);
  7244. }
  7245. EnableControl(QueueView3, HasTerminal);
  7246. QueueLabelUpdateStatus();
  7247. reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
  7248. }
  7249. }
  7250. //---------------------------------------------------------------------------
  7251. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  7252. {
  7253. UpdateControls();
  7254. }
  7255. //---------------------------------------------------------------------------
  7256. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  7257. TObject * Sender)
  7258. {
  7259. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  7260. DebugAssert(DirView != NULL);
  7261. DoDirViewLoaded(DirView);
  7262. TransferPresetAutoSelect();
  7263. }
  7264. //---------------------------------------------------------------------------
  7265. void __fastcall TCustomScpExplorerForm::StartUpdates()
  7266. {
  7267. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  7268. // first run after installation
  7269. if (double(Updates.LastCheck) == 0)
  7270. {
  7271. // make sure next time there will be an update (if enabled)
  7272. Updates.LastCheck = TDateTime(1);
  7273. WinConfiguration->Updates = Updates;
  7274. }
  7275. else if ((double(Updates.Period) > 0) &&
  7276. (Now() - Updates.LastCheck >= Updates.Period))
  7277. {
  7278. StartUpdateThread(UpdatesChecked);
  7279. }
  7280. }
  7281. //---------------------------------------------------------------------------
  7282. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  7283. {
  7284. UnicodeString Message;
  7285. bool New;
  7286. TQueryType Type;
  7287. GetUpdatesMessage(Message, New, Type, false);
  7288. if (!Message.IsEmpty())
  7289. {
  7290. if (New)
  7291. {
  7292. Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
  7293. }
  7294. if (!New && (Type != qtWarning))
  7295. {
  7296. PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
  7297. }
  7298. else
  7299. {
  7300. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  7301. }
  7302. if (New)
  7303. {
  7304. Configuration->Usage->Inc(L"UpdateNotifications");
  7305. }
  7306. }
  7307. }
  7308. //---------------------------------------------------------------------------
  7309. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  7310. {
  7311. RestoreApp();
  7312. if (!NonVisualDataModule->Busy)
  7313. {
  7314. Configuration->Usage->Inc(L"UpdateNotificationsClicked");
  7315. CheckForUpdates(true);
  7316. }
  7317. }
  7318. //---------------------------------------------------------------------------
  7319. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  7320. TCopyParamRuleData & Data)
  7321. {
  7322. DebugAssert(Terminal != NULL);
  7323. Data.HostName = Terminal->SessionData->HostNameExpanded;
  7324. Data.UserName = Terminal->SessionData->UserNameExpanded;
  7325. Data.RemoteDirectory = RemoteDirView->PathName;
  7326. }
  7327. //---------------------------------------------------------------------------
  7328. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  7329. {
  7330. // Terminal can be null when we are changing local directory implicitly,
  7331. // because it has been deleted, while no session is connected
  7332. // (Login dialog is open)
  7333. if (FAllowTransferPresetAutoSelect && (Terminal != NULL))
  7334. {
  7335. TCopyParamRuleData Data;
  7336. GetTransferPresetAutoSelectData(Data);
  7337. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  7338. UnicodeString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  7339. if (CopyParamIndex < 0)
  7340. {
  7341. // there is no preset that matches autoselection
  7342. // set preset that we consider "default"
  7343. FCopyParamAutoSelected = L""; // forget last autoselected preset
  7344. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  7345. }
  7346. else
  7347. {
  7348. // there is preset matching autoselection
  7349. UnicodeString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  7350. if (CopyParamName == FCopyParamAutoSelected)
  7351. {
  7352. // autoselected the same preset as the last time
  7353. // make no change (i.e. preserve custom user preset, if any)
  7354. }
  7355. else
  7356. {
  7357. // autoselected the different preset then the last time (or there
  7358. // was default preset set)
  7359. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  7360. GUIConfiguration->CopyParamCurrent = CopyParamName;
  7361. }
  7362. }
  7363. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  7364. {
  7365. if (CopyParamIndex >= 0)
  7366. {
  7367. Configuration->Usage->Inc(L"CopyParamAutoSelects");
  7368. }
  7369. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  7370. try
  7371. {
  7372. int Fmt =
  7373. (CopyParamIndex < 0) ?
  7374. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  7375. COPY_PARAM_AUTOSELECTED;
  7376. UnicodeString Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  7377. Data->Message = MainInstructions(Message);
  7378. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  7379. UnicodeString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr(L"\n",
  7380. CopyParamAttrs);
  7381. if (CopyParamIndex >= 0)
  7382. {
  7383. DebugAssert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  7384. Info = FORMAT(L"%s\n \n%s", (Info,
  7385. FMTLOAD(COPY_PARAM_RULE,
  7386. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr(L"\n")))));
  7387. }
  7388. Data->Message += L"\n\n" + Info;
  7389. if (WinConfiguration->CopyParamAutoSelectNotice)
  7390. {
  7391. TransferPresetNoteMessage(Data, true);
  7392. }
  7393. else
  7394. {
  7395. PostNote(Message, 0, TransferPresetNoteClicked, Data);
  7396. Data = NULL; // ownership passed
  7397. }
  7398. }
  7399. __finally
  7400. {
  7401. delete Data;
  7402. }
  7403. }
  7404. }
  7405. }
  7406. //---------------------------------------------------------------------------
  7407. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  7408. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  7409. {
  7410. DebugAssert(NoteData != NULL);
  7411. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  7412. TQueryButtonAlias Aliases[1];
  7413. Aliases[0].Button = qaIgnore; // "ignore" is after "ok"
  7414. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  7415. Params.Aliases = Aliases;
  7416. Params.AliasesCount = LENOF(Aliases);
  7417. unsigned int Result =
  7418. MoreMessageDialog(NoteData->Message, NULL, qtInformation,
  7419. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  7420. switch (Result)
  7421. {
  7422. case qaNeverAskAgain:
  7423. DebugAssert(AllowNeverAskAgain);
  7424. WinConfiguration->CopyParamAutoSelectNotice = false;
  7425. break;
  7426. case qaIgnore:
  7427. PreferencesDialog(pmPresets);
  7428. break;
  7429. }
  7430. }
  7431. //---------------------------------------------------------------------------
  7432. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * Sender)
  7433. {
  7434. // as of now useless, as this is used for notes only, never for balloons, ...
  7435. RestoreApp();
  7436. // .. and we should never be busy here
  7437. if (DebugAlwaysTrue(!NonVisualDataModule->Busy))
  7438. {
  7439. TransferPresetNoteMessage(DebugNotNull(dynamic_cast<TTransferPresetNoteData *>(Sender)), false);
  7440. }
  7441. }
  7442. //---------------------------------------------------------------------------
  7443. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  7444. TPreferencesMode APreferencesMode)
  7445. {
  7446. std::unique_ptr<TPreferencesDialogData> PreferencesData;
  7447. TCopyParamRuleData Data;
  7448. if (Terminal != NULL)
  7449. {
  7450. PreferencesData.reset(new TPreferencesDialogData());
  7451. GetTransferPresetAutoSelectData(Data);
  7452. PreferencesData->CopyParamRuleData = &Data;
  7453. }
  7454. DoPreferencesDialog(APreferencesMode, PreferencesData.get());
  7455. }
  7456. //---------------------------------------------------------------------------
  7457. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  7458. const TCustomCommandType & Command)
  7459. {
  7460. if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
  7461. {
  7462. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (Command.Command)));
  7463. }
  7464. }
  7465. //---------------------------------------------------------------------------
  7466. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  7467. {
  7468. bool RemoteAllowed = CustomCommandRemoteAllowed();
  7469. TCustomCommandType Command;
  7470. // make sure we use local custom command when remote are not supported
  7471. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  7472. {
  7473. Command = FLastCustomCommand;
  7474. }
  7475. else
  7476. {
  7477. Command.Params = Command.Params | ccLocal;
  7478. }
  7479. Command.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  7480. FEditingFocusedAdHocCommand = OnFocused;
  7481. bool LocalSide = (FCurrentSide == osLocal);
  7482. int Options =
  7483. FLAGMASK((!RemoteAllowed || LocalSide), ccoDisableRemote) |
  7484. FLAGMASK(LocalSide, ccoDisableRemoteFiles);
  7485. if (DoCustomCommandDialog(Command, WinConfiguration->CustomCommandList,
  7486. ccmAdHoc, Options, AdHocCustomCommandValidate, NULL))
  7487. {
  7488. FLastCustomCommand = Command;
  7489. UpdateCustomCommandsToolbar();
  7490. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Command);
  7491. }
  7492. }
  7493. //---------------------------------------------------------------------------
  7494. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  7495. {
  7496. DebugAssert(!FLastCustomCommand.Command.IsEmpty());
  7497. int State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  7498. DebugAssert(State > 0);
  7499. if (State <= 0)
  7500. {
  7501. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (FLastCustomCommand.Command)));
  7502. }
  7503. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  7504. }
  7505. //---------------------------------------------------------------------------
  7506. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  7507. TCustomCommandType & Command, int & State)
  7508. {
  7509. bool Result = !FLastCustomCommand.Command.IsEmpty();
  7510. if (Result)
  7511. {
  7512. Command = FLastCustomCommand;
  7513. State = CustomCommandState(FLastCustomCommand, OnFocused, ccltAll);
  7514. }
  7515. return Result;
  7516. }
  7517. //---------------------------------------------------------------------------
  7518. void __fastcall TCustomScpExplorerForm::WhatsThis()
  7519. {
  7520. SendMessage(Handle, WM_SYSCOMMAND, SC_CONTEXTHELP, 0);
  7521. }
  7522. //---------------------------------------------------------------------------
  7523. void __fastcall TCustomScpExplorerForm::BeforeAction()
  7524. {
  7525. if (RemoteDirView->ItemFocused != NULL)
  7526. {
  7527. RemoteDirView->ItemFocused->CancelEdit();
  7528. }
  7529. }
  7530. //---------------------------------------------------------------------------
  7531. void __fastcall TCustomScpExplorerForm::PostComponentHide(Byte Component)
  7532. {
  7533. DebugAssert(ComponentVisible[Component]);
  7534. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  7535. }
  7536. //---------------------------------------------------------------------------
  7537. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  7538. {
  7539. // when queue panel is resized here directly, the status bar is stretched
  7540. // over whole space the panel occupied
  7541. PostComponentHide(fcQueueView);
  7542. }
  7543. //---------------------------------------------------------------------------
  7544. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  7545. {
  7546. TMessage * M = static_cast<TMessage*>(Message);
  7547. switch (M->Msg)
  7548. {
  7549. case CM_DIALOGCHAR:
  7550. CMDialogChar(*M);
  7551. break;
  7552. case WM_APPCOMMAND:
  7553. WMAppCommand(*M);
  7554. break;
  7555. case WM_SYSCOMMAND:
  7556. WMSysCommand(*M);
  7557. break;
  7558. case WM_QUERYENDSESSION:
  7559. WMQueryEndSession(*M);
  7560. break;
  7561. case WM_ENDSESSION:
  7562. WMEndSession(*reinterpret_cast<TWMEndSession *>(M));
  7563. break;
  7564. case WM_COMPONENT_HIDE:
  7565. {
  7566. Byte Component = static_cast<Byte>(M->WParam);
  7567. // sanity check
  7568. if (ComponentVisible[Component])
  7569. {
  7570. // special treatment
  7571. if (Component == fcQueueView)
  7572. {
  7573. ToggleQueueVisibility();
  7574. DebugAssert(!ComponentVisible[fcQueueView]);
  7575. }
  7576. else
  7577. {
  7578. ComponentVisible[Component] = false;
  7579. }
  7580. }
  7581. }
  7582. break;
  7583. case WM_COPYDATA:
  7584. WMCopyData(*M);
  7585. break;
  7586. case WM_MANAGES_CAPTION:
  7587. // caption managed in TTerminalManager::UpdateAppTitle()
  7588. M->Result = 1;
  7589. break;
  7590. case WM_WANTS_MOUSEWHEEL:
  7591. M->Result = 1;
  7592. break;
  7593. case CM_SHOWINGCHANGED:
  7594. CMShowingChanged(*M);
  7595. break;
  7596. case WM_CLOSE:
  7597. WMClose(*M);
  7598. break;
  7599. default:
  7600. TForm::Dispatch(Message);
  7601. break;
  7602. }
  7603. }
  7604. //---------------------------------------------------------------------------
  7605. void __fastcall TCustomScpExplorerForm::WMClose(TMessage & Message)
  7606. {
  7607. // Cannot close window while we are busy.
  7608. // We cannot test this in FormCloseQuery as that is called also from
  7609. // Close(), which is called by CloseApplicationAction. So we can be busy
  7610. // there already even, when it is legitimate to close the application.
  7611. // Possibly a better place to handle this would be WMSysCommand.
  7612. if (NonVisualDataModule->Busy)
  7613. {
  7614. Message.Result = 1;
  7615. }
  7616. else
  7617. {
  7618. TForm::Dispatch(&Message);
  7619. }
  7620. }
  7621. //---------------------------------------------------------------------------
  7622. void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
  7623. {
  7624. TForm::Dispatch(&Message);
  7625. if (Showing && (Terminal == NULL))
  7626. {
  7627. // When we are starting minimized (i.e. from an installer),
  7628. // postpone showing Login dialog until we get restored.
  7629. // Otherwise the Login dialog (and Authentication window) show restored
  7630. // over invidible (minimized) main window.
  7631. if (WindowState == wsMinimized)
  7632. {
  7633. FNeedSession = true;
  7634. }
  7635. else
  7636. {
  7637. // This happens before application ever goes idle, so the toolbars would
  7638. // stay enabled (initial state) until the Login dialog is dismissed.
  7639. UpdateActions();
  7640. NonVisualDataModule->StartBusy();
  7641. try
  7642. {
  7643. // Need to process WM_ACTIVATEAPP before showing the Login dialog,
  7644. // otherwise the dialog does not receive focus.
  7645. // With Commander interface the ProcessMessages is called already
  7646. // by TDriveView, but with Explorer interface, we need to call it explicily
  7647. Application->ProcessMessages();
  7648. // do not reload sessions, they have been loaded just now (optimization)
  7649. NeedSession(false);
  7650. }
  7651. __finally
  7652. {
  7653. NonVisualDataModule->EndBusy();
  7654. }
  7655. }
  7656. }
  7657. }
  7658. //---------------------------------------------------------------------------
  7659. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  7660. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  7661. int & MaxHeight)
  7662. {
  7663. // workaround for bug in TWinControl.CalcConstraints
  7664. // Check for empty rect (restore from iconic state) is done there only after
  7665. // call to AdjustClientRect, which enlarges the rect (for forms).
  7666. TRect R = GetClientRect();
  7667. // when restoring from iconic state, place no restrictions
  7668. if (IsRectEmpty(R))
  7669. {
  7670. MinWidth = 0;
  7671. MinHeight = 0;
  7672. MaxWidth = 32000;
  7673. MaxHeight = 32000;
  7674. }
  7675. }
  7676. //---------------------------------------------------------------------------
  7677. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const UnicodeString Path,
  7678. TSpaceAvailable & ASpaceAvailable, bool & Close)
  7679. {
  7680. // terminal can be already closed (e.g. dropped connection)
  7681. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  7682. {
  7683. Configuration->Usage->Inc(L"SpaceAvailableChecks");
  7684. try
  7685. {
  7686. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  7687. }
  7688. catch(...)
  7689. {
  7690. if (!Terminal->Active)
  7691. {
  7692. Close = true;
  7693. }
  7694. throw;
  7695. }
  7696. }
  7697. }
  7698. //---------------------------------------------------------------------------
  7699. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  7700. {
  7701. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  7702. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  7703. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  7704. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  7705. {
  7706. OnGetSpaceAvailable = GetSpaceAvailable;
  7707. }
  7708. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  7709. OnGetSpaceAvailable);
  7710. }
  7711. //---------------------------------------------------------------------------
  7712. TSessionData * __fastcall TCustomScpExplorerForm::SessionDataForCode()
  7713. {
  7714. std::unique_ptr<TSessionData> Data(CloneCurrentSessionData());
  7715. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  7716. Data->HostKey = SessionInfo.HostKeyFingerprint;
  7717. return Data.release();
  7718. }
  7719. //---------------------------------------------------------------------------
  7720. void __fastcall TCustomScpExplorerForm::GenerateUrl(TStrings * Paths)
  7721. {
  7722. std::unique_ptr<TSessionData> Data(SessionDataForCode());
  7723. DoGenerateUrlDialog(Data.get(), Paths);
  7724. }
  7725. //---------------------------------------------------------------------------
  7726. void __fastcall TCustomScpExplorerForm::SessionGenerateUrl()
  7727. {
  7728. GenerateUrl(NULL);
  7729. }
  7730. //---------------------------------------------------------------------------
  7731. void __fastcall TCustomScpExplorerForm::FileGenerateUrl()
  7732. {
  7733. std::unique_ptr<TStrings> Paths(new TStringList());
  7734. DirView(osCurrent)->CreateFileList(false, true, Paths.get());
  7735. GenerateUrl(Paths.get());
  7736. }
  7737. //---------------------------------------------------------------------------
  7738. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  7739. {
  7740. if (value != FSessionColor)
  7741. {
  7742. FSessionColor = value;
  7743. TColor C = (value != 0 ? value : Vcl::Graphics::clNone);
  7744. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  7745. static_cast<TObject *>(GetComponent(fcColorMenu)));
  7746. DebugAssert(ColorItem != NULL);
  7747. ColorItem->Color = C;
  7748. NonVisualDataModule->ColorMenuItem->Color = C;
  7749. // Is null when called from LastTerminalClosed
  7750. if (Terminal != NULL)
  7751. {
  7752. SessionsPageControl->ActivePage->ImageIndex = AddSessionColor(value);
  7753. }
  7754. UpdateControls();
  7755. }
  7756. }
  7757. //---------------------------------------------------------------------------
  7758. bool __fastcall TCustomScpExplorerForm::CancelNote(bool Force)
  7759. {
  7760. bool Result = FNoteTimer->Enabled;
  7761. if (Result)
  7762. {
  7763. // cannot cancel note too early
  7764. bool NotEarly =
  7765. (Now() - FNoteShown >
  7766. EncodeTimeVerbose(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0));
  7767. if (Force || NotEarly)
  7768. {
  7769. FNoteTimer->Enabled = false;
  7770. FNote = L"";
  7771. SAFE_DESTROY(FNoteData);
  7772. FOnNoteClick = NULL;
  7773. FNoteHints = FNotes->Text;
  7774. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  7775. UpdateStatusBar();
  7776. }
  7777. }
  7778. return Result;
  7779. }
  7780. //---------------------------------------------------------------------------
  7781. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  7782. {
  7783. DebugAssert(FNoteTimer->Enabled);
  7784. CancelNote(true);
  7785. }
  7786. //---------------------------------------------------------------------------
  7787. void __fastcall TCustomScpExplorerForm::AddNote(UnicodeString Note, bool UpdateNow)
  7788. {
  7789. int P = Note.Pos(L"\n");
  7790. if (P > 0)
  7791. {
  7792. Note.SetLength(P - 1);
  7793. }
  7794. FNotes->Add(FORMAT(L"[%s] %s",
  7795. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  7796. while (FNotes->Count > 10)
  7797. {
  7798. FNotes->Delete(0);
  7799. }
  7800. if (UpdateNow)
  7801. {
  7802. FNoteHints = FNotes->Text;
  7803. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  7804. UpdateStatusBar();
  7805. }
  7806. }
  7807. //---------------------------------------------------------------------------
  7808. void __fastcall TCustomScpExplorerForm::PostNote(UnicodeString Note,
  7809. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  7810. {
  7811. int P = Note.Pos(L"\n");
  7812. if (P > 0)
  7813. {
  7814. Note.SetLength(P - 1);
  7815. }
  7816. FNoteHints = FNotes->Text;
  7817. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  7818. FNote = Note;
  7819. SAFE_DESTROY(FNoteData);
  7820. FNoteData = NoteData;
  7821. FOnNoteClick = OnNoteClick;
  7822. AddNote(Note, false);
  7823. UpdateStatusBar();
  7824. FNoteShown = Now();
  7825. FNoteTimer->Enabled = false;
  7826. if (Seconds == 0)
  7827. {
  7828. Seconds = WinConfiguration->NotificationsTimeout;
  7829. }
  7830. FNoteTimer->Interval = Seconds * MSecsPerSec;
  7831. FNoteTimer->Enabled = true;
  7832. }
  7833. //---------------------------------------------------------------------------
  7834. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  7835. {
  7836. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  7837. }
  7838. //---------------------------------------------------------------------------
  7839. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  7840. {
  7841. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked)
  7842. {
  7843. Configuration->Usage->Inc(L"SynchronizeBrowsingEnabled");
  7844. }
  7845. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  7846. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  7847. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  7848. 0, NULL, NULL);
  7849. }
  7850. //---------------------------------------------------------------------------
  7851. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  7852. {
  7853. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  7854. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  7855. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  7856. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  7857. }
  7858. //---------------------------------------------------------------------------
  7859. void __fastcall TCustomScpExplorerForm::SetFormatSizeBytes(TFormatBytesStyle Style)
  7860. {
  7861. WinConfiguration->FormatSizeBytes = Style;
  7862. }
  7863. //---------------------------------------------------------------------------
  7864. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  7865. {
  7866. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  7867. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  7868. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  7869. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  7870. }
  7871. //---------------------------------------------------------------------------
  7872. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  7873. TTBXCustomStatusBar * Sender, TTBXStatusPanel * Panel)
  7874. {
  7875. if (Panel->Index == 0)
  7876. {
  7877. if (FOnNoteClick != NULL)
  7878. {
  7879. // prevent the user data from being freed by possible call
  7880. // to CancelNote or PostNote during call to OnNoteClick
  7881. std::unique_ptr<TObject> NoteData(FNoteData);
  7882. TNotifyEvent OnNoteClick = FOnNoteClick;
  7883. FNoteData = NULL;
  7884. // need to cancel the note as we are going to delete its user data
  7885. CancelNote(true);
  7886. OnNoteClick(NoteData.get());
  7887. }
  7888. }
  7889. if (Panel->Index >= Sender->Panels->Count - SessionPanelCount)
  7890. {
  7891. FileSystemInfo();
  7892. }
  7893. }
  7894. //---------------------------------------------------------------------------
  7895. void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
  7896. {
  7897. // workaround:
  7898. // 1) for unknown reason, disabling window, while minimized,
  7899. // prevents it from restoring, even if it was enabled again meanwhile
  7900. // 2) when disabling the main window, while another has focus
  7901. // minimize is no longer possible
  7902. // ("keep up to date" dialog - though does not seem to be the case with "find file" -
  7903. // so it has probably something to do with the semi-modalness of the "keep up to date" dialog)
  7904. // Shouldn't we use IsApplicationMinimized() here?
  7905. if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
  7906. {
  7907. Enabled = false;
  7908. }
  7909. FLockLevel++;
  7910. }
  7911. //---------------------------------------------------------------------------
  7912. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  7913. {
  7914. DebugAssert(FLockLevel > 0);
  7915. FLockLevel--;
  7916. if (FLockLevel == 0)
  7917. {
  7918. DebugAssert(FLockSuspendLevel == 0);
  7919. Enabled = true;
  7920. }
  7921. }
  7922. //---------------------------------------------------------------------------
  7923. void __fastcall TCustomScpExplorerForm::SuspendWindowLock()
  7924. {
  7925. // We need to make sure that window is enabled when the last modal window closes
  7926. // otherwise focus is not restored correctly.
  7927. // So we re-enable the window when modal window opens and
  7928. // disable it back after is closes
  7929. if (FLockLevel > 0)
  7930. {
  7931. // while we have nesting counter, we know that we never be called
  7932. // recursivelly as Application->OnModalBegin is called only
  7933. // for the top-level modal window
  7934. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  7935. {
  7936. // won't be disabled when conditions in LockWindow() were not satisfied
  7937. FDisabledOnLockSuspend = !Enabled;
  7938. // When minimized to tray (or actually when set to SW_HIDE),
  7939. // setting Enabled makes the window focusable even when there's
  7940. // modal window over it
  7941. if (!FTrayIcon->Visible)
  7942. {
  7943. Enabled = true;
  7944. }
  7945. }
  7946. FLockSuspendLevel++;
  7947. }
  7948. }
  7949. //---------------------------------------------------------------------------
  7950. void __fastcall TCustomScpExplorerForm::ResumeWindowLock()
  7951. {
  7952. if (FLockSuspendLevel > 0)
  7953. {
  7954. DebugAssert(FLockLevel > 0);
  7955. FLockSuspendLevel--;
  7956. // see comment in SuspendWindowLock
  7957. if (DebugAlwaysTrue(FLockSuspendLevel == 0))
  7958. {
  7959. // Note that window can be enabled here, when we were minized to tray when
  7960. // was SuspendWindowLock() called.
  7961. // We should possibly do the same check as in LockWindow(),
  7962. // if it is ever possible that the consitions change between
  7963. // SuspendWindowLock() and ResumeWindowLock()
  7964. Enabled = !FDisabledOnLockSuspend;
  7965. }
  7966. }
  7967. }
  7968. //---------------------------------------------------------------------------
  7969. void __fastcall TCustomScpExplorerForm::UpdateRemotePathComboBox(bool TextOnly)
  7970. {
  7971. if (!TextOnly)
  7972. {
  7973. TTBXComboBoxItem * RemotePathComboBox =
  7974. reinterpret_cast<TTBXComboBoxItem *>(GetComponent(fcRemotePathComboBox));
  7975. TStrings * Items = RemotePathComboBox->Strings;
  7976. Items->BeginUpdate();
  7977. try
  7978. {
  7979. Items->Clear();
  7980. if (Terminal != NULL)
  7981. {
  7982. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  7983. while (!IsUnixRootPath(APath))
  7984. {
  7985. int P = APath.LastDelimiter(L'/');
  7986. DebugAssert(P >= 0);
  7987. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  7988. APath.SetLength(P - 1);
  7989. }
  7990. Items->Insert(0, Customunixdirview_SUnixDefaultRootName);
  7991. }
  7992. }
  7993. __finally
  7994. {
  7995. RemotePathComboBox->ItemIndex = Items->Count - 1;
  7996. // Setting ItemIndex to -1 does not reset its text
  7997. if (Items->Count == 0)
  7998. {
  7999. RemotePathComboBox->Text = L"";
  8000. }
  8001. Items->EndUpdate();
  8002. }
  8003. }
  8004. }
  8005. //---------------------------------------------------------------------------
  8006. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxAdjustImageIndex(
  8007. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int AIndex,
  8008. int & ImageIndex)
  8009. {
  8010. if (AIndex < 0)
  8011. {
  8012. AIndex = Sender->ItemIndex;
  8013. }
  8014. ImageIndex = (AIndex < Sender->Strings->Count - 1 ? StdDirIcon : StdDirSelIcon);
  8015. }
  8016. //---------------------------------------------------------------------------
  8017. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxDrawItem(
  8018. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, TRect & ARect, int AIndex,
  8019. int /*AHoverIndex*/, bool & /*DrawDefault*/)
  8020. {
  8021. ARect.Left += (10 * AIndex);
  8022. }
  8023. //---------------------------------------------------------------------------
  8024. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxMeasureWidth(
  8025. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, int AIndex, int &AWidth)
  8026. {
  8027. AWidth += (10 * AIndex);
  8028. }
  8029. //---------------------------------------------------------------------------
  8030. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxItemClick(
  8031. TObject * Sender)
  8032. {
  8033. TTBXComboBoxItem * RemotePathComboBox = dynamic_cast<TTBXComboBoxItem*>(Sender);
  8034. UnicodeString APath = UnixExcludeTrailingBackslash(RemoteDirView->Path);
  8035. int Index = RemotePathComboBox->ItemIndex;
  8036. while (Index < RemotePathComboBox->Strings->Count - 1)
  8037. {
  8038. APath = UnixExtractFileDir(APath);
  8039. Index++;
  8040. }
  8041. // VanDyke style paths
  8042. if (APath.IsEmpty())
  8043. {
  8044. DebugAssert(RemotePathComboBox->ItemIndex == 0);
  8045. APath = ROOTDIRECTORY;
  8046. }
  8047. if (RemoteDirView->Path != APath)
  8048. {
  8049. RemoteDirView->Path = APath;
  8050. }
  8051. }
  8052. //---------------------------------------------------------------------------
  8053. void __fastcall TCustomScpExplorerForm::RemotePathComboBoxCancel(TObject * Sender)
  8054. {
  8055. DebugAssert(Sender == GetComponent(fcRemotePathComboBox));
  8056. DebugUsedParam(Sender);
  8057. UpdateRemotePathComboBox(true);
  8058. }
  8059. //---------------------------------------------------------------------------
  8060. void __fastcall TCustomScpExplorerForm::DirViewEditing(
  8061. TObject * Sender, TListItem * Item, bool & /*AllowEdit*/)
  8062. {
  8063. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  8064. DebugAssert(DirView != NULL);
  8065. if (!WinConfiguration->RenameWholeName && !DirView->ItemIsDirectory(Item))
  8066. {
  8067. HWND Edit = ListView_GetEditControl(DirView->Handle);
  8068. // OnEditing is called also from TCustomListView::CanEdit
  8069. if (Edit != NULL)
  8070. {
  8071. EditSelectBaseName(Edit);
  8072. }
  8073. }
  8074. }
  8075. //---------------------------------------------------------------------------
  8076. //---------------------------------------------------------------------------
  8077. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::CreateDragDropFilesEx()
  8078. {
  8079. TDragDropFilesEx * Result = new TDragDropFilesEx(this);
  8080. Result->AutoDetectDnD = false;
  8081. Result->NeedValid = TFileExMustDnDSet() << nvFilename;
  8082. Result->RenderDataOn = rdoEnterAndDropSync;
  8083. Result->TargetEffects = TDropEffectSet() << deCopy << deMove;
  8084. return Result;
  8085. }
  8086. //---------------------------------------------------------------------------
  8087. void __fastcall TCustomScpExplorerForm::CreateWnd()
  8088. {
  8089. TForm::CreateWnd();
  8090. if (FSessionsDragDropFilesEx == NULL)
  8091. {
  8092. FSessionsDragDropFilesEx = CreateDragDropFilesEx();
  8093. FSessionsDragDropFilesEx->OnDragOver = SessionsDDDragOver;
  8094. FSessionsDragDropFilesEx->OnProcessDropped = SessionsDDProcessDropped;
  8095. FSessionsDragDropFilesEx->OnDragEnter = SessionsDDDragEnter;
  8096. FSessionsDragDropFilesEx->OnDragLeave = SessionsDDDragLeave;
  8097. }
  8098. if (FQueueDragDropFilesEx == NULL)
  8099. {
  8100. FQueueDragDropFilesEx = CreateDragDropFilesEx();
  8101. // No need to set OnDragOver as we do not have any restrictions
  8102. FQueueDragDropFilesEx->OnProcessDropped = QueueDDProcessDropped;
  8103. FQueueDragDropFilesEx->OnDragEnter = QueueDDDragEnter;
  8104. FQueueDragDropFilesEx->OnDragLeave = QueueDDDragLeave;
  8105. }
  8106. }
  8107. //---------------------------------------------------------------------------
  8108. void __fastcall TCustomScpExplorerForm::DestroyWnd()
  8109. {
  8110. TForm::DestroyWnd();
  8111. FSessionsDragDropFilesEx->DragDropControl = NULL;
  8112. FQueueDragDropFilesEx->DragDropControl = NULL;
  8113. }
  8114. //---------------------------------------------------------------------------
  8115. void __fastcall TCustomScpExplorerForm::FormShow(TObject * /*Sender*/)
  8116. {
  8117. SideEnter(FCurrentSide);
  8118. FEverShown = true;
  8119. }
  8120. //---------------------------------------------------------------------------
  8121. void __fastcall TCustomScpExplorerForm::DoFindFiles(
  8122. TTerminal * ATerminal, UnicodeString Directory, const TFileMasks & FileMask,
  8123. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile)
  8124. {
  8125. if (!NonVisualDataModule->Busy)
  8126. {
  8127. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8128. Configuration->Usage->Inc(L"FileFinds");
  8129. LockWindow(true);
  8130. NonVisualDataModule->StartBusy();
  8131. WinConfiguration->LockedInterface = true;
  8132. try
  8133. {
  8134. FTerminal->FilesFind(Directory, FileMask, OnFileFound, OnFindingFile);
  8135. }
  8136. __finally
  8137. {
  8138. WinConfiguration->LockedInterface = false;
  8139. NonVisualDataModule->EndBusy();
  8140. UnlockWindow();
  8141. }
  8142. }
  8143. }
  8144. //---------------------------------------------------------------------------
  8145. void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal, const UnicodeString & Path)
  8146. {
  8147. if (!NonVisualDataModule->Busy)
  8148. {
  8149. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8150. SetFocus();
  8151. RemoteDirView->Path = UnixExtractFilePath(Path);
  8152. TListItem * Item = RemoteDirView->FindFileItem(UnixExtractFileName(Path));
  8153. if (Item != NULL)
  8154. {
  8155. RemoteDirView->ItemFocused = Item;
  8156. RemoteDirView->ItemFocused->MakeVisible(false);
  8157. RemoteDirView->SetFocus();
  8158. }
  8159. }
  8160. }
  8161. //---------------------------------------------------------------------------
  8162. void __fastcall TCustomScpExplorerForm::DoDeleteFoundFiles(
  8163. TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
  8164. {
  8165. if (!NonVisualDataModule->Busy)
  8166. {
  8167. TTerminalManager::Instance()->ActiveTerminal = ATerminal;
  8168. DebugAssert(FOnFileOperationFinished == NULL);
  8169. FOnFileOperationFinished = OnFileOperationFinished;
  8170. try
  8171. {
  8172. ExecuteFileOperation(foDelete, osRemote, FileList, false, NULL);
  8173. }
  8174. __finally
  8175. {
  8176. FOnFileOperationFinished = NULL;
  8177. }
  8178. }
  8179. }
  8180. //---------------------------------------------------------------------------
  8181. void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
  8182. {
  8183. FFileFindTerminal = Terminal;
  8184. ShowFileFindDialog(Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles);
  8185. }
  8186. //---------------------------------------------------------------------------
  8187. void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)
  8188. {
  8189. FTaskbarList = TaskbarList;
  8190. }
  8191. //---------------------------------------------------------------------------
  8192. void __fastcall TCustomScpExplorerForm::SessionsPageControlMouseDown(
  8193. TObject * /*Sender*/, TMouseButton Button, TShiftState /*Shift*/, int X, int Y)
  8194. {
  8195. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8196. if (Index >= 0)
  8197. {
  8198. if (Button == mbLeft)
  8199. {
  8200. // "Mouse down" is raised only after tab is switched.
  8201. // If switching tab (switching session) takes long enough for user
  8202. // to actually release the button, "mouse down" is still raised,
  8203. // but we do not get "mouse up" event, so dragging is not cancelled,
  8204. // prevent that by not beginning dragging in the first place.
  8205. if (IsKeyPressed(VK_LBUTTON))
  8206. {
  8207. // when user clicks the "+", we get mouse down only after the session
  8208. // is closed, when new session tab is already on X:Y, so dragging
  8209. // starts, prevent that
  8210. if (MilliSecondsBetween(Now(), FSessionsPageControlNewSessionTime) > 500)
  8211. {
  8212. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8213. if (Terminal != NULL)
  8214. {
  8215. SessionsPageControl->BeginDrag(false);
  8216. }
  8217. }
  8218. }
  8219. }
  8220. else if (Button == mbMiddle)
  8221. {
  8222. // ignore middle-click for "New session tab"
  8223. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8224. if (Terminal != NULL)
  8225. {
  8226. SessionsPageControl->ActivePageIndex = Index;
  8227. // Switch to session tab (has to be session tab, due to previous check)
  8228. if (DebugAlwaysTrue(SessionTabSwitched()))
  8229. {
  8230. CloseSession();
  8231. }
  8232. }
  8233. }
  8234. }
  8235. }
  8236. //---------------------------------------------------------------------------
  8237. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragDrop(
  8238. TObject * /*Sender*/, TObject * /*Source*/, int X, int Y)
  8239. {
  8240. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8241. // do not allow dropping on the "+" tab
  8242. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8243. if ((TargetTerminal != NULL) &&
  8244. (SessionsPageControl->ActivePage->PageIndex != Index))
  8245. {
  8246. Configuration->Usage->Inc(L"SessionTabMoves");
  8247. // this is almost redundant as we would recreate tabs in DoTerminalListChanged,
  8248. // but we want to actually prevent that to avoid flicker
  8249. SessionsPageControl->ActivePage->PageIndex = Index;
  8250. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->ActivePage);
  8251. TTerminalManager::Instance()->Move(Terminal, TargetTerminal);
  8252. }
  8253. }
  8254. //---------------------------------------------------------------------------
  8255. void __fastcall TCustomScpExplorerForm::SessionsPageControlDragOver(
  8256. TObject * Sender, TObject * Source, int X, int Y,
  8257. TDragState /*State*/, bool & Accept)
  8258. {
  8259. Accept = (Sender == Source);
  8260. if (Accept)
  8261. {
  8262. int Index = SessionsPageControl->IndexOfTabAt(X, Y);
  8263. TTerminal * Terminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8264. // do not allow dragging to the "+" tab
  8265. Accept = (Terminal != NULL);
  8266. }
  8267. }
  8268. //---------------------------------------------------------------------------
  8269. void __fastcall TCustomScpExplorerForm::SessionsDDDragOver(int /*KeyState*/,
  8270. const TPoint & Point, int & Effect)
  8271. {
  8272. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  8273. if (Index < 0)
  8274. {
  8275. Effect = DROPEFFECT_None;
  8276. }
  8277. else
  8278. {
  8279. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8280. // do not allow dropping on the "+" tab
  8281. if (TargetTerminal == NULL)
  8282. {
  8283. Effect = DROPEFFECT_None;
  8284. }
  8285. }
  8286. }
  8287. //---------------------------------------------------------------------------
  8288. void __fastcall TCustomScpExplorerForm::SessionsDDProcessDropped(
  8289. TObject * /*Sender*/, int /*KeyState*/, const TPoint & Point, int Effect)
  8290. {
  8291. int Index = SessionsPageControl->IndexOfTabAt(Point.X, Point.Y);
  8292. // do not allow dropping on the "+" tab
  8293. TTerminal * TargetTerminal = GetSessionTabTerminal(SessionsPageControl->Pages[Index]);
  8294. if (TargetTerminal != NULL)
  8295. {
  8296. DebugAssert(!IsFileControl(DropSourceControl, osRemote));
  8297. if (!IsFileControl(DropSourceControl, osRemote))
  8298. {
  8299. TTerminalManager::Instance()->ActiveTerminal = TargetTerminal;
  8300. RemoteFileControlDragDropFileOperation(SessionsPageControl, Effect,
  8301. // Why don't we use Terminal->CurrentDirectory directly?
  8302. TTerminalManager::Instance()->ActiveTerminal->CurrentDirectory, false);
  8303. }
  8304. }
  8305. }
  8306. //---------------------------------------------------------------------------
  8307. void __fastcall TCustomScpExplorerForm::QueueDDProcessDropped(
  8308. TObject * /*Sender*/, int /*KeyState*/, const TPoint & /*Point*/, int Effect)
  8309. {
  8310. // Downloads are handled in RemoteFileControlDDEnd
  8311. if (!IsFileControl(DropSourceControl, osRemote))
  8312. {
  8313. RemoteFileControlDragDropFileOperation(QueueView3, Effect,
  8314. Terminal->CurrentDirectory,
  8315. // force queue
  8316. true);
  8317. }
  8318. }
  8319. //---------------------------------------------------------------------------
  8320. void __fastcall TCustomScpExplorerForm::FormClose(TObject * /*Sender*/, TCloseAction & /*Action*/)
  8321. {
  8322. FShowing = false;
  8323. // Do not save empty workspace
  8324. if (WinConfiguration->AutoSaveWorkspace && (Terminal != NULL))
  8325. {
  8326. std::unique_ptr<TObjectList> DataList(DoCollectWorkspace());
  8327. UnicodeString Name = WorkspaceName();
  8328. DoSaveWorkspace(
  8329. Name, DataList.get(),
  8330. !Configuration->DisablePasswordStoring &&
  8331. WinConfiguration->AutoSaveWorkspacePasswords);
  8332. WinConfiguration->LastStoredSession = Name;
  8333. }
  8334. }
  8335. //---------------------------------------------------------------------------
  8336. void __fastcall TCustomScpExplorerForm::RemoteDirViewRead(TObject * /*Sender*/)
  8337. {
  8338. TManagedTerminal * ManagedTerminal =
  8339. dynamic_cast<TManagedTerminal *>(RemoteDirView->Terminal);
  8340. if (ManagedTerminal != NULL)
  8341. {
  8342. ManagedTerminal->DirectoryLoaded = Now();
  8343. }
  8344. }
  8345. //---------------------------------------------------------------------------
  8346. void __fastcall TCustomScpExplorerForm::DirViewSelectItem(TObject * Sender,
  8347. TListItem * /*Item*/, bool /*Selected*/)
  8348. {
  8349. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  8350. switch (DirView->LastSelectMethod)
  8351. {
  8352. case smKeyboard:
  8353. Configuration->Usage->Inc(L"KeyboardSelections");
  8354. break;
  8355. case smMouse:
  8356. Configuration->Usage->Inc(L"MouseSelections");
  8357. break;
  8358. }
  8359. }
  8360. //---------------------------------------------------------------------------
  8361. int __fastcall TCustomScpExplorerForm::AddSessionColor(TColor Color)
  8362. {
  8363. if (Color != 0)
  8364. {
  8365. AddSessionColorImage(FSessionColors, Color, FSessionColorMaskImageIndex);
  8366. return FSessionColors->Count - 1;
  8367. }
  8368. else
  8369. {
  8370. return FSessionTabImageIndex;
  8371. }
  8372. }
  8373. //---------------------------------------------------------------------------
  8374. int __fastcall TCustomScpExplorerForm::AddFixedSessionImage(int GlyphsSourceIndex)
  8375. {
  8376. TPngImageCollectionItem * Item =
  8377. GlyphsModule->ExplorerImages->PngImages->Items[GlyphsSourceIndex];
  8378. FSessionColors->AddPng(Item->PngImage);
  8379. return FSessionColors->Count - 1;
  8380. }
  8381. //---------------------------------------------------------------------------
  8382. void __fastcall TCustomScpExplorerForm::AddFixedSessionImages()
  8383. {
  8384. FNewSessionTabImageIndex = AddFixedSessionImage(NonVisualDataModule->NewSessionAction->ImageIndex);
  8385. FSessionTabImageIndex = AddFixedSessionImage(SiteImageIndex);
  8386. FSessionColorMaskImageIndex = AddFixedSessionImage(SiteColorMaskImageIndex);
  8387. }
  8388. //---------------------------------------------------------------------------
  8389. void __fastcall TCustomScpExplorerForm::CollectItemsWithTextDisplayMode(TWinControl * Control)
  8390. {
  8391. for (int Index = 0; Index < Control->ControlCount; Index++)
  8392. {
  8393. TControl * AControl = Control->Controls[Index];
  8394. TWinControl * WinControl = dynamic_cast<TWinControl *>(AControl);
  8395. if (WinControl != NULL)
  8396. {
  8397. CollectItemsWithTextDisplayMode(WinControl);
  8398. }
  8399. TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(AControl);
  8400. if (Toolbar != NULL)
  8401. {
  8402. // we care for top-level items only
  8403. TTBCustomItem * Items = Toolbar->Items;
  8404. for (int ItemIndex = 0; ItemIndex < Items->Count; ItemIndex++)
  8405. {
  8406. TTBCustomItem * Item = Items->Items[ItemIndex];
  8407. if (((Item->DisplayMode == nbdmImageAndText) ||
  8408. (dynamic_cast<TTBXLabelItem *>(Item) != NULL)) &&
  8409. EligibleForImageDisplayMode(Item))
  8410. {
  8411. FItemsWithTextDisplayMode.insert(Item);
  8412. }
  8413. }
  8414. }
  8415. }
  8416. }
  8417. //---------------------------------------------------------------------------
  8418. bool __fastcall TCustomScpExplorerForm::EligibleForImageDisplayMode(TTBCustomItem * /*Item*/)
  8419. {
  8420. return true;
  8421. }
  8422. //---------------------------------------------------------------------------
  8423. bool __fastcall TCustomScpExplorerForm::UpdateToolbarDisplayMode()
  8424. {
  8425. bool SelectiveToolbarText = WinConfiguration->SelectiveToolbarText;
  8426. TTBItemDisplayMode DisplayMode = (SelectiveToolbarText ? nbdmImageAndText : nbdmDefault);
  8427. typedef std::set<TTBCustomItem *> TItemsWithTextDisplayMode;
  8428. TItemsWithTextDisplayMode::iterator i = FItemsWithTextDisplayMode.begin();
  8429. bool Result = true;
  8430. while (Result && (i != FItemsWithTextDisplayMode.end()))
  8431. {
  8432. TTBCustomItem * Item = *i;
  8433. TTBXLabelItem * Label = dynamic_cast<TTBXLabelItem *>(Item);
  8434. if (Label != NULL)
  8435. {
  8436. // optimization
  8437. if (Label->Visible == SelectiveToolbarText)
  8438. {
  8439. Result = false;
  8440. }
  8441. else
  8442. {
  8443. Label->Visible = SelectiveToolbarText;
  8444. }
  8445. }
  8446. else
  8447. {
  8448. // optimization
  8449. if (Item->DisplayMode == DisplayMode)
  8450. {
  8451. Result = false;
  8452. }
  8453. else
  8454. {
  8455. Item->DisplayMode = DisplayMode;
  8456. }
  8457. }
  8458. ++i;
  8459. }
  8460. if (Result)
  8461. {
  8462. UpdateNewSessionTab();
  8463. }
  8464. return Result;
  8465. }
  8466. //---------------------------------------------------------------------------
  8467. void __fastcall TCustomScpExplorerForm::DisplaySystemContextMenu()
  8468. {
  8469. DebugFail();
  8470. }
  8471. //---------------------------------------------------------------------------
  8472. bool __fastcall TCustomScpExplorerForm::IsBusy()
  8473. {
  8474. // Among other, a lock level is non zero, while directory is being loaded,
  8475. // even when it happens as a result of dirview navigation,
  8476. // i.e. when TNonVisualDataModule is NOT FBusy.
  8477. // That's why the TNonVisualDataModule::GetBusy calls this method.
  8478. // Among other this prevents a panel auto update to occur while
  8479. // directory is changing.
  8480. return (FLockLevel > 0) || DirView(osCurrent)->IsEditing();
  8481. }
  8482. //---------------------------------------------------------------------------
  8483. Boolean __fastcall TCustomScpExplorerForm::AllowedAction(TAction * /*Action*/, TActionAllowed Allowed)
  8484. {
  8485. // While the window is disabled, we still seem to process menu shortcuts at least,
  8486. // so stop it at least here.
  8487. // See also TCustomScpExplorerForm::RemoteDirViewBusy
  8488. return
  8489. (Allowed == aaUpdate) ||
  8490. !NonVisualDataModule->Busy;
  8491. }
  8492. //---------------------------------------------------------------------------
  8493. void __fastcall TCustomScpExplorerForm::EditMenuItemPopup(TTBCustomItem * Sender, bool FromLink)
  8494. {
  8495. NonVisualDataModule->EditMenuItemPopup(Sender, FromLink);
  8496. }
  8497. //---------------------------------------------------------------------------
  8498. void __fastcall TCustomScpExplorerForm::DirViewBusy(TObject * /*Sender*/, int Busy, bool & State)
  8499. {
  8500. // This is somewhat redundant to LockWindow() call from
  8501. // TTerminalManager::TerminalReadDirectoryProgress.
  8502. // But disabling window is known not to block keyboard shorcuts
  8503. // (see TCustomScpExplorerForm::AllowedAction), this hopefully works.
  8504. if (Busy > 0)
  8505. {
  8506. if (NonVisualDataModule->Busy)
  8507. {
  8508. State = false;
  8509. }
  8510. else
  8511. {
  8512. NonVisualDataModule->StartBusy();
  8513. LockWindow();
  8514. }
  8515. }
  8516. else if (Busy < 0)
  8517. {
  8518. UnlockWindow();
  8519. NonVisualDataModule->EndBusy();
  8520. }
  8521. else
  8522. {
  8523. State = NonVisualDataModule->Busy;
  8524. }
  8525. }
  8526. //---------------------------------------------------------------------------
  8527. void __fastcall TCustomScpExplorerForm::SessionsPageControlContextPopup(TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  8528. {
  8529. int Index = SessionsPageControl->IndexOfTabAt(MousePos.X, MousePos.Y);
  8530. // no context menu for "New session tab"
  8531. if ((Index >= 0) && (GetSessionTabTerminal(SessionsPageControl->Pages[Index]) != NULL))
  8532. {
  8533. SessionsPageControl->ActivePageIndex = Index;
  8534. if (DebugAlwaysTrue(SessionTabSwitched()))
  8535. {
  8536. // copied from TControl.WMContextMenu
  8537. SendCancelMode(SessionsPageControl);
  8538. // explicit popup instead of using PopupMenu property
  8539. // to avoid menu to popup somewhere within SessionTabSwitched above,
  8540. // while connecting yet not-connected session and hence
  8541. // allowing an access to commands over not-completelly connected session
  8542. TPoint Point = SessionsPageControl->ClientToScreen(MousePos);
  8543. TPopupMenu * PopupMenu = NonVisualDataModule->SessionsPopup;
  8544. PopupMenu->PopupComponent = SessionsPageControl;
  8545. PopupMenu->Popup(Point.x, Point.y);
  8546. }
  8547. }
  8548. Handled = true;
  8549. }
  8550. //---------------------------------------------------------------------------