CustomScpExplorer.cpp 294 KB

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