CustomScpExplorer.cpp 250 KB

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