CustomScpExplorer.cpp 294 KB

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