CustomScpExplorer.cpp 289 KB

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