CustomScpExplorer.cpp 246 KB

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