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