CustomScpExplorer.cpp 295 KB

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