CustomScpExplorer.cpp 294 KB

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