CustomScpExplorer.cpp 286 KB

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