CustomScpExplorer.cpp 280 KB

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