CustomScpExplorer.cpp 291 KB

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