CustomScpExplorer.cpp 154 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include "CustomScpExplorer.h"
  6. #include <Interface.h>
  7. #include <Net.h>
  8. #include <ScpMain.h>
  9. #include <FileSystems.h>
  10. #include <TextsCore.h>
  11. #include <TextsWin.h>
  12. #include <HelpWin.h>
  13. #include <VCLCommon.h>
  14. #include <Log.h>
  15. #include <Progress.h>
  16. #include <SynchronizeProgress.h>
  17. #include <OperationStatus.h>
  18. #include <Queue.h>
  19. #include <DragExt.h>
  20. #include "GUITools.h"
  21. #include "NonVisual.h"
  22. #include "Glyphs.h"
  23. #include "Tools.h"
  24. #include "WinConfiguration.h"
  25. #include "TerminalManager.h"
  26. #include "EditorManager.h"
  27. #include "Setup.h"
  28. //---------------------------------------------------------------------------
  29. #pragma package(smart_init)
  30. #pragma link "CustomDirView"
  31. #pragma link "CustomUnixDirView"
  32. #pragma link "IEListView"
  33. #pragma link "NortonLikeListView"
  34. #pragma link "UnixDirView"
  35. #pragma link "CustomDriveView"
  36. #pragma link "UnixDriveView"
  37. #pragma link "CustomDriveView"
  38. #pragma link "TB2Dock"
  39. #pragma link "TBXStatusBars"
  40. #pragma link "TB2Item"
  41. #pragma link "TB2Toolbar"
  42. #pragma resource "*.dfm"
  43. //---------------------------------------------------------------------------
  44. #define SAVE_SELECTION(DIRVIEW) \
  45. AnsiString FocusFile = ""; \
  46. AnsiString LastFocusedFile = ""; \
  47. if (DIRVIEW->ItemFocused) LastFocusedFile = DIRVIEW->ItemFocused->Caption; \
  48. { TListItem * ClosestUnselected = DIRVIEW->ClosestUnselected(DIRVIEW->ItemFocused); \
  49. if (ClosestUnselected) FocusFile = ClosestUnselected->Caption; }
  50. #define RESTORE_SELECTION(DIRVIEW) \
  51. if (!LastFocusedFile.IsEmpty() && \
  52. (!DIRVIEW->ItemFocused || (DIRVIEW->ItemFocused->Caption != LastFocusedFile))) \
  53. { \
  54. TListItem *ItemToSelect = DIRVIEW->FindFileItem(FocusFile); \
  55. if (ItemToSelect) \
  56. { \
  57. DIRVIEW->ItemFocused = ItemToSelect; \
  58. DIRVIEW->ItemFocused->MakeVisible(False); \
  59. } \
  60. }
  61. //---------------------------------------------------------------------------
  62. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  63. //---------------------------------------------------------------------------
  64. class TMutexGuard
  65. {
  66. public:
  67. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  68. int Timeout = 5000)
  69. {
  70. FMutex = NULL;
  71. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  72. if (WaitResult == WAIT_TIMEOUT)
  73. {
  74. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  75. }
  76. else
  77. {
  78. FMutex = AMutex;
  79. }
  80. }
  81. ~TMutexGuard()
  82. {
  83. if (FMutex != NULL)
  84. {
  85. ReleaseMutex(FMutex);
  86. }
  87. }
  88. private:
  89. HANDLE FMutex;
  90. };
  91. //---------------------------------------------------------------------------
  92. struct TTransferOperationParam
  93. {
  94. TTransferOperationParam();
  95. AnsiString TargetDirectory;
  96. bool Temp;
  97. bool DragDrop;
  98. };
  99. //---------------------------------------------------------------------------
  100. TTransferOperationParam::TTransferOperationParam()
  101. {
  102. Temp = false;
  103. DragDrop = false;
  104. }
  105. //---------------------------------------------------------------------------
  106. __fastcall TExporerState::TExporerState()
  107. {
  108. Local = NULL;
  109. Remote = NULL;
  110. }
  111. //---------------------------------------------------------------------------
  112. __fastcall TExporerState::~TExporerState()
  113. {
  114. delete Local;
  115. delete Remote;
  116. }
  117. //---------------------------------------------------------------------------
  118. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  119. FFormRestored(False), TForm(Owner)
  120. {
  121. CALLSTACK;
  122. FCurrentSide = osRemote;
  123. FDocks = new TList();
  124. RestoreParams();
  125. ConfigurationChanged();
  126. RemoteDirView->Invalidate();
  127. assert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  128. NonVisualDataModule->ScpExplorer = this;
  129. Application->OnHint = ApplicationHint;
  130. FAutoOperation = false;
  131. FForceExecution = false;
  132. FShowStatusBarHint = false;
  133. FIgnoreNextSysCommand = false;
  134. FErrorList = NULL;
  135. FSynchronizeProgressForm = NULL;
  136. FProgressForm = NULL;
  137. FRefreshLocalDirectory = false;
  138. FRefreshRemoteDirectory = false;
  139. FDDMoveSlipped = false;
  140. FDDExtMapFile = NULL;
  141. FDDExtMutex = CreateMutex(NULL, false, DRAG_EXT_MUTEX);
  142. assert(FDDExtMutex != NULL);
  143. FDDTargetControl = NULL;
  144. FDelayedDeletionTimer = NULL;
  145. FDelayedDeletionList = new TStringList();
  146. FDDFileList = NULL;
  147. FPendingTempSpaceWarn = false;
  148. FCapturedLog = NULL;
  149. FDragDropOperation = false;
  150. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  151. FNoTransferPresetAutoSelect = false;
  152. FCopyParamDefault = "";
  153. FSynchronizeController = NULL;
  154. FPendingQueueActionItem = NULL;
  155. FEditorManager = new TEditorManager();
  156. FEditorManager->OnFileChange = ExecutedFileChanged;
  157. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  158. FQueueStatus = NULL;
  159. FQueueStatusSection = new TCriticalSection();
  160. FQueueStatusInvalidated = false;
  161. FQueueItemInvalidated = false;
  162. FQueueActedItem = NULL;
  163. FQueueController = new TQueueController(QueueView);
  164. FUserActionTimer = new TTimer(this);
  165. FUserActionTimer->Enabled = false;
  166. FUserActionTimer->Interval = 10;
  167. FUserActionTimer->OnTimer = UserActionTimer;
  168. FOle32Library = LoadLibrary("Ole32.dll");
  169. FDragMoveCursor = FOle32Library != NULL ?
  170. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  171. UseSystemSettings(this);
  172. TTBXComboBoxItem * SessionCombo = dynamic_cast<TTBXComboBoxItem*>(
  173. static_cast<TObject*>(GetComponent(fcSessionCombo)));
  174. if (SessionCombo != NULL)
  175. {
  176. SessionCombo->OnDrawItem = SessionComboDrawItem;
  177. SessionCombo->OnPopup = SessionComboPopup;
  178. SessionCombo->OnChange = SessionComboChange;
  179. SessionCombo->Hint = NonVisualDataModule->OpenedSessionsAction->Hint;
  180. }
  181. TTBXComboBoxItem * TransferCombo = dynamic_cast<TTBXComboBoxItem*>(
  182. static_cast<TObject*>(GetComponent(fcTransferCombo)));
  183. if (TransferCombo != NULL)
  184. {
  185. TransferCombo->OnChange = TransferComboChange;
  186. }
  187. class TTBXPublicItem : public TTBXCustomItem
  188. {
  189. public:
  190. __property ItemStyle;
  191. };
  192. TTBXPublicItem * ColorMenu = reinterpret_cast<TTBXPublicItem *>(GetComponent(fcColorMenu));
  193. ColorMenu->ItemStyle = ColorMenu->ItemStyle << tbisSubmenu;
  194. RemoteDirView->Font = Screen->IconFont;
  195. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  196. StartUpdates();
  197. }
  198. //---------------------------------------------------------------------------
  199. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  200. {
  201. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  202. delete FEditorManager;
  203. if (FDelayedDeletionTimer)
  204. {
  205. DoDelayedDeletion(NULL);
  206. SAFE_DESTROY(FDelayedDeletionTimer);
  207. }
  208. SAFE_DESTROY(FDelayedDeletionList);
  209. assert(FSynchronizeController == NULL);
  210. CloseHandle(FDDExtMutex);
  211. FDDExtMutex = NULL;
  212. FreeLibrary(FOle32Library);
  213. FOle32Library = NULL;
  214. FDragMoveCursor = NULL;
  215. assert(!FErrorList);
  216. StoreParams();
  217. Terminal = NULL;
  218. Queue = NULL;
  219. assert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  220. NonVisualDataModule->ScpExplorer = NULL;
  221. delete FQueueController;
  222. FQueueController = NULL;
  223. delete FQueueStatusSection;
  224. FQueueStatusSection = NULL;
  225. delete FQueueStatus;
  226. FQueueStatus = NULL;
  227. delete FUserActionTimer;
  228. FUserActionTimer = NULL;
  229. SAFE_DESTROY(FDocks);
  230. SAFE_DESTROY(FHistoryMenu[0][0]);
  231. SAFE_DESTROY(FHistoryMenu[0][1]);
  232. SAFE_DESTROY(FHistoryMenu[1][0]);
  233. SAFE_DESTROY(FHistoryMenu[1][1]);
  234. StopUpdateThread();
  235. }
  236. //---------------------------------------------------------------------------
  237. void __fastcall TCustomScpExplorerForm::SetTerminal(TTerminal * value)
  238. {
  239. if (FTerminal != value)
  240. {
  241. TerminalChanging();
  242. FTerminal = value;
  243. bool PrevNoTransferPresetAutoSelect = FNoTransferPresetAutoSelect;
  244. FNoTransferPresetAutoSelect = true;
  245. try
  246. {
  247. TerminalChanged();
  248. }
  249. __finally
  250. {
  251. FNoTransferPresetAutoSelect = PrevNoTransferPresetAutoSelect;
  252. }
  253. if (Terminal != NULL)
  254. {
  255. TransferPresetAutoSelect();
  256. }
  257. }
  258. }
  259. //---------------------------------------------------------------------------
  260. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  261. {
  262. if (FTerminal != NULL)
  263. {
  264. UpdateSessionData(Terminal->SessionData);
  265. if (WinConfiguration->PreservePanelState)
  266. {
  267. if (Terminal->UserObject == NULL)
  268. {
  269. Terminal->UserObject = new TExporerState;
  270. }
  271. TExporerState * ExplorerState = dynamic_cast<TExporerState *>(Terminal->UserObject);
  272. SAFE_DESTROY(ExplorerState->Remote);
  273. ExplorerState->Remote = RemoteDirView->SaveState();
  274. }
  275. else
  276. {
  277. Terminal->UserObject = NULL;
  278. }
  279. }
  280. }
  281. //---------------------------------------------------------------------------
  282. void __fastcall TCustomScpExplorerForm::TerminalChanged()
  283. {
  284. RemoteDirView->Terminal = Terminal;
  285. Caption = Application->Title;
  286. NonVisualDataModule->QueueDisconnectOnceEmptyAction->Checked = false;
  287. if (Terminal)
  288. {
  289. if (Terminal->Active)
  290. {
  291. Terminal->RefreshDirectory();
  292. }
  293. if (WinConfiguration->PreservePanelState && (Terminal->UserObject != NULL))
  294. {
  295. TExporerState * ExplorerState = dynamic_cast<TExporerState *>(Terminal->UserObject);
  296. assert(ExplorerState != NULL);
  297. RemoteDirView->RestoreState(ExplorerState->Remote);
  298. }
  299. SessionColor = (TColor)Terminal->SessionData->Color;
  300. InitStatusBar();
  301. }
  302. TerminalListChanged(NULL);
  303. UpdateTransferCombo();
  304. }
  305. //---------------------------------------------------------------------------
  306. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  307. {
  308. if (Queue != value)
  309. {
  310. if (FQueue != NULL)
  311. {
  312. FQueue->OnListUpdate = NULL;
  313. FQueue->OnQueueItemUpdate = NULL;
  314. }
  315. FQueue = value;
  316. if (FQueue != NULL)
  317. {
  318. assert(FQueue->OnListUpdate == NULL);
  319. FQueue->OnListUpdate = QueueListUpdate;
  320. assert(FQueue->OnQueueItemUpdate == NULL);
  321. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  322. }
  323. QueueChanged();
  324. }
  325. }
  326. //---------------------------------------------------------------------------
  327. void __fastcall TCustomScpExplorerForm::QueueViewDeletion(TObject * /*Sender*/,
  328. TListItem * Item)
  329. {
  330. if (FQueueActedItem == Item)
  331. {
  332. FQueueActedItem = NULL;
  333. if ((QueueView->PopupMenu != NULL) &&
  334. (QueueView->PopupMenu->PopupComponent == QueueView))
  335. {
  336. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  337. ReleaseCapture();
  338. }
  339. }
  340. if (Item->Data == FPendingQueueActionItem)
  341. {
  342. FPendingQueueActionItem = NULL;
  343. }
  344. }
  345. //---------------------------------------------------------------------------
  346. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool AppIdle)
  347. {
  348. {
  349. TGuard Guard(FQueueStatusSection);
  350. FQueueStatusInvalidated = false;
  351. if (FQueue != NULL)
  352. {
  353. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  354. }
  355. }
  356. FQueueController->UpdateQueueStatus(FQueueStatus);
  357. UpdateQueueView();
  358. if (NonVisualDataModule->QueueDisconnectOnceEmptyAction->Checked &&
  359. FQueueController->Empty &&
  360. (Terminal != NULL))
  361. {
  362. NonVisualDataModule->QueueDisconnectOnceEmptyAction->Checked = false;
  363. if (AppIdle)
  364. {
  365. Terminal->CloseOnCompletion(LoadStr(CLOSED_ON_QUEUE_EMPTY));
  366. }
  367. }
  368. }
  369. //---------------------------------------------------------------------------
  370. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  371. {
  372. ComponentVisible[fcQueueView] =
  373. (WinConfiguration->QueueView.Show == qvShow) ||
  374. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  375. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  376. }
  377. //---------------------------------------------------------------------------
  378. void __fastcall TCustomScpExplorerForm::QueueChanged()
  379. {
  380. if (FQueueStatus != NULL)
  381. {
  382. delete FQueueStatus;
  383. FQueueStatus = NULL;
  384. }
  385. UpdateQueueStatus(false);
  386. }
  387. //---------------------------------------------------------------------------
  388. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  389. {
  390. if (FQueue == Queue)
  391. {
  392. FQueueStatusInvalidated = true;
  393. }
  394. }
  395. //---------------------------------------------------------------------------
  396. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  397. TQueueItem * Item)
  398. {
  399. if (FQueue == Queue)
  400. {
  401. TGuard Guard(FQueueStatusSection);
  402. assert(FQueueStatus != NULL);
  403. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  404. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  405. {
  406. FRefreshLocalDirectory = (QueueItem == NULL) ||
  407. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  408. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  409. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  410. }
  411. if (QueueItem != NULL)
  412. {
  413. QueueItem->UserData = (void*)true;
  414. FQueueItemInvalidated = true;
  415. }
  416. }
  417. }
  418. //---------------------------------------------------------------------------
  419. void __fastcall TCustomScpExplorerForm::RefreshQueueItems(bool AppIdle)
  420. {
  421. if (FQueueStatus != NULL)
  422. {
  423. bool QueueAutoPopup = GUIConfiguration->QueueAutoPopup;
  424. bool Refresh = FQueueItemInvalidated;
  425. FQueueItemInvalidated = false;
  426. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->ActiveCount;
  427. bool Updated = false;
  428. bool Update;
  429. TQueueItemProxy * QueueItem;
  430. bool WasUserAction;
  431. for (int Index = 0; Index < Limit; Index++)
  432. {
  433. Update = false;
  434. QueueItem = FQueueStatus->Items[Index];
  435. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  436. if (AppIdle && QueueAutoPopup && WasUserAction &&
  437. (FPendingQueueActionItem == NULL))
  438. {
  439. FPendingQueueActionItem = QueueItem;
  440. FUserActionTimer->Enabled = true;
  441. }
  442. if ((bool)QueueItem->UserData)
  443. {
  444. QueueItem->UserData = (void*)false;
  445. QueueItem->Update();
  446. bool UserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  447. if (!QueueAutoPopup && UserAction && !WasUserAction)
  448. {
  449. FlashOnBackground();
  450. }
  451. Updated = true;
  452. Update = true;
  453. }
  454. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem))
  455. {
  456. Update = true;
  457. }
  458. if (Update)
  459. {
  460. FQueueController->RefreshQueueItem(QueueItem);
  461. }
  462. }
  463. if (Updated)
  464. {
  465. NonVisualDataModule->UpdateNonVisibleActions();
  466. }
  467. }
  468. }
  469. //---------------------------------------------------------------------------
  470. void __fastcall TCustomScpExplorerForm::UpdateTransferCombo()
  471. {
  472. TTBXComboBoxItem * TransferCombo = dynamic_cast<TTBXComboBoxItem*>(
  473. static_cast<TComponent*>(GetComponent(fcTransferCombo)));
  474. TransferCombo->Strings->BeginUpdate();
  475. try
  476. {
  477. TransferCombo->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  478. TransferCombo->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  479. TransferCombo->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  480. if (FTransferComboHint.IsEmpty())
  481. {
  482. FTransferComboHint = TransferCombo->Hint;
  483. }
  484. TransferCombo->Hint = FORMAT("%s\n \n%s:\n%s|%s",
  485. (FTransferComboHint, TransferCombo->Strings->Strings[TransferCombo->ItemIndex],
  486. GUIConfiguration->CurrentCopyParam.GetInfoStr("; ",
  487. FLAGMASK(Terminal != NULL, Terminal->UsableCopyParamAttrs(0).General)),
  488. FTransferComboHint));
  489. }
  490. __finally
  491. {
  492. TransferCombo->Strings->EndUpdate();
  493. }
  494. }
  495. //---------------------------------------------------------------------------
  496. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  497. {
  498. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  499. assert(Toolbar != NULL);
  500. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  501. }
  502. //---------------------------------------------------------------------------
  503. void __fastcall TCustomScpExplorerForm::UpdateActions()
  504. {
  505. TForm::UpdateActions();
  506. if (ComponentVisible[fcCustomCommandsBand])
  507. {
  508. UpdateCustomCommandsToolbar();
  509. }
  510. }
  511. //---------------------------------------------------------------------------
  512. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  513. {
  514. assert(Configuration && RemoteDirView);
  515. RemoteDirView->DDAllowMove = WinConfiguration->DDAllowMoveInit;
  516. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  517. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  518. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  519. RemoteDriveView->DDAllowMove = WinConfiguration->DDAllowMoveInit;
  520. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  521. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  522. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  523. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  524. UpdateTransferCombo();
  525. if (Terminal != NULL)
  526. {
  527. TransferPresetAutoSelect();
  528. }
  529. UpdateQueueView();
  530. UpdateControls();
  531. // this can be called even before constuctor finishes.
  532. // can we be sure that the FEditorManager is NULL then?
  533. if (FEditorManager != NULL)
  534. {
  535. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  536. }
  537. if (ComponentVisible[fcCustomCommandsBand])
  538. {
  539. UpdateCustomCommandsToolbar();
  540. }
  541. }
  542. //---------------------------------------------------------------------------
  543. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  544. const AnsiString FileName, TEditedFileData & /*Data*/, TObject * Token,
  545. void * /*Arg*/)
  546. {
  547. if (Token != NULL)
  548. {
  549. TForm * Editor = dynamic_cast<TForm*>(Token);
  550. assert(Editor != NULL);
  551. ReconfigureEditorForm(Editor);
  552. }
  553. }
  554. //---------------------------------------------------------------------------
  555. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  556. TTransferDirection Direction, TTransferType Type, bool Temp,
  557. TStrings * FileList, AnsiString & TargetDirectory, TGUICopyParamType & CopyParam,
  558. bool Confirm, bool DragDrop)
  559. {
  560. bool Result = true;
  561. assert(Terminal && Terminal->Active);
  562. // Temp means d&d here so far, may change in future!
  563. if (Temp && (Direction == tdToLocal) && (Type == ttMove) &&
  564. !WinConfiguration->DDAllowMove)
  565. {
  566. TMessageParams Params(mpNeverAskAgainCheck);
  567. int Answer = MessageDialog(LoadStr(DND_DOWNLOAD_MOVE_WARNING), qtWarning,
  568. qaOK | qaCancel, HELP_DND_DOWNLOAD_MOVE_WARNING, &Params);
  569. if (Answer == qaNeverAskAgain)
  570. {
  571. WinConfiguration->DDAllowMove = true;
  572. }
  573. else if (Answer == qaCancel)
  574. {
  575. Result = false;
  576. }
  577. }
  578. // these parameters are known in advance
  579. int Params =
  580. FLAGMASK(Type == ttMove, cpDelete);
  581. bool ToTemp = (Temp && (Direction == tdToLocal));
  582. if (Result && Confirm)
  583. {
  584. bool DisableNewerOnly =
  585. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  586. ToTemp;
  587. int Options =
  588. FLAGMASK(DisableNewerOnly, coDisableNewerOnly) |
  589. FLAGMASK(ToTemp, coTemp) |
  590. FLAGMASK(DragDrop, coDoNotShowAgain);
  591. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  592. int CopyParamAttrs = (Direction == tdToRemote ?
  593. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download);
  594. int OutputOptions = 0;
  595. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  596. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, &OutputOptions);
  597. if (Result && DragDrop && FLAGSET(OutputOptions, cooDoNotShowAgain))
  598. {
  599. WinConfiguration->DDTransferConfirmation = false;
  600. }
  601. }
  602. if (Result && CopyParam.Queue && !ToTemp)
  603. {
  604. assert(Queue != NULL);
  605. // these parameter are known only after transfer dialog
  606. Params |=
  607. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0) |
  608. (CopyParam.NewerOnly ? cpNewerOnly : 0);
  609. TQueueItem * QueueItem;
  610. if (Direction == tdToRemote)
  611. {
  612. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  613. &CopyParam, Params);
  614. }
  615. else
  616. {
  617. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  618. &CopyParam, Params);
  619. }
  620. Queue->AddItem(QueueItem);
  621. Result = false;
  622. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  623. if (HasDirView[Side])
  624. {
  625. DirView(Side)->SelectAll(smNone);
  626. }
  627. }
  628. return Result;
  629. }
  630. //---------------------------------------------------------------------------
  631. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  632. {
  633. }
  634. //---------------------------------------------------------------------------
  635. void __fastcall TCustomScpExplorerForm::RestoreParams()
  636. {
  637. assert(FDocks != NULL);
  638. for (int Index = 0; Index < ComponentCount; Index++)
  639. {
  640. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  641. if ((Dock != NULL) && (Dock->Tag == 0))
  642. {
  643. FDocks->Add(Dock);
  644. }
  645. }
  646. // IDE often looses this link
  647. RemoteDirView->HeaderImages = GlyphsModule->ArrowImages;
  648. ConfigurationChanged();
  649. QueuePanel->Height = WinConfiguration->QueueView.Height;
  650. LoadListViewStr(QueueView, WinConfiguration->QueueView.Layout);
  651. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  652. }
  653. //---------------------------------------------------------------------------
  654. void __fastcall TCustomScpExplorerForm::StoreParams()
  655. {
  656. WinConfiguration->QueueView.Height = QueuePanel->Height;
  657. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView);
  658. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  659. }
  660. //---------------------------------------------------------------------------
  661. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  662. {
  663. if (!FFormRestored)
  664. {
  665. FFormRestored = true;
  666. RestoreFormParams();
  667. }
  668. TForm::CreateParams(Params);
  669. }
  670. //---------------------------------------------------------------------------
  671. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  672. {
  673. assert(FDocks != NULL);
  674. for (int Index = 0; Index < FDocks->Count; Index++)
  675. {
  676. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  677. }
  678. }
  679. //---------------------------------------------------------------------------
  680. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(AnsiString LayoutStr)
  681. {
  682. SetDockAllowDrag(true);
  683. ::LoadToolbarsLayoutStr(this, LayoutStr);
  684. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  685. }
  686. //---------------------------------------------------------------------------
  687. AnsiString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  688. {
  689. AnsiString Result;
  690. SetDockAllowDrag(true);
  691. Result = ::GetToolbarsLayoutStr(this);
  692. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  693. return Result;
  694. }
  695. //---------------------------------------------------------------------------
  696. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  697. TFileOperationProgressType & ProgressData, TCancelStatus & /*Cancel*/)
  698. {
  699. // Download to temporary local directory
  700. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  701. {
  702. bool Continue = true;
  703. FPendingTempSpaceWarn = false;
  704. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  705. if (!Continue)
  706. {
  707. Abort();
  708. }
  709. }
  710. // operation is being executed and we still didn't show up progress form
  711. if (ProgressData.InProgress && !FProgressForm)
  712. {
  713. //assert(Screen && Screen->ActiveCustomForm);
  714. FProgressForm = new TProgressForm(Application);
  715. FProgressForm->DeleteToRecycleBin = (ProgressData.Side == osLocal ?
  716. WinConfiguration->DeleteToRecycleBin :
  717. Terminal->SessionData->DeleteToRecycleBin);
  718. // When main window is hidden, synchronisation form does not exist,
  719. // we suppose "/upload" or URL download mode
  720. if (!Visible && (ProgressData.Operation != foCalculateSize) &&
  721. (FSynchronizeProgressForm == NULL))
  722. {
  723. FProgressForm->DisconnectWhenComplete = true;
  724. }
  725. }
  726. // operation is finished (or terminated), so we hide progress form
  727. else if (!ProgressData.InProgress && FProgressForm)
  728. {
  729. SAFE_DESTROY(FProgressForm);
  730. if ((ProgressData.Operation != foCalculateSize) &&
  731. (ProgressData.Cancel == csContinue) &&
  732. !FAutoOperation)
  733. {
  734. OperationComplete(ProgressData.StartTime);
  735. }
  736. }
  737. if (FProgressForm)
  738. {
  739. FProgressForm->SetProgressData(ProgressData);
  740. if (FProgressForm->Cancel > ProgressData.Cancel)
  741. {
  742. ProgressData.Cancel = FProgressForm->Cancel;
  743. }
  744. }
  745. }
  746. //---------------------------------------------------------------------------
  747. void __fastcall TCustomScpExplorerForm::OperationComplete(
  748. const TDateTime & StartTime)
  749. {
  750. if (GUIConfiguration->BeepOnFinish &&
  751. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  752. {
  753. MessageBeep(MB_OK);
  754. }
  755. }
  756. //---------------------------------------------------------------------------
  757. void __fastcall TCustomScpExplorerForm::OperationProgress(
  758. TFileOperationProgressType & ProgressData, TCancelStatus & Cancel)
  759. {
  760. FileOperationProgress(ProgressData, Cancel);
  761. }
  762. //---------------------------------------------------------------------------
  763. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  764. bool DragDrop)
  765. {
  766. return (!DragDrop && (DropSourceControl == NULL)) ||
  767. (DropSourceControl == RemoteDirView);
  768. }
  769. //---------------------------------------------------------------------------
  770. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  771. TFileOperation Operation, TOperationSide Side,
  772. bool /*Temp*/, const AnsiString FileName, bool Success,
  773. bool & DisconnectWhenComplete)
  774. {
  775. if (!FAutoOperation)
  776. {
  777. // no selection on "/upload", form servers only as event handler
  778. // (it is not displayed)
  779. if (PanelOperation(Side, FDragDropOperation) &&
  780. Visible && (Operation != foCalculateSize) &&
  781. (Operation != foGetProperties))
  782. {
  783. TCustomDirView * DView = DirView(Side);
  784. AnsiString FileNameOnly = (Side == osRemote) ?
  785. UnixExtractFileName(FileName) : ExtractFileName(FileName);
  786. TListItem *Item = DView->FindFileItem(FileNameOnly);
  787. // this can happen when local drive is unplugged in the middle of the operation
  788. if (Item != NULL)
  789. {
  790. if (Success) Item->Selected = false;
  791. if (DView->ViewStyle == vsReport)
  792. {
  793. TRect DisplayRect = Item->DisplayRect(drBounds);
  794. if (DisplayRect.Bottom > DView->ClientHeight)
  795. {
  796. DView->Scroll(0, Item->Top - DView->TopItem->Top);
  797. }
  798. }
  799. Item->MakeVisible(false);
  800. }
  801. }
  802. }
  803. if (Success && (FSynchronizeController != NULL))
  804. {
  805. if (Operation == foCopy)
  806. {
  807. assert(Side == osLocal);
  808. FSynchronizeController->LogOperation(soUpload, FileName);
  809. }
  810. else if (Operation == foDelete)
  811. {
  812. assert(Side == osRemote);
  813. FSynchronizeController->LogOperation(soDelete, FileName);
  814. }
  815. }
  816. if (FProgressForm)
  817. {
  818. DisconnectWhenComplete = FProgressForm->DisconnectWhenComplete;
  819. }
  820. }
  821. //---------------------------------------------------------------------------
  822. void __fastcall TCustomScpExplorerForm::OperationFinished(
  823. TFileOperation Operation, TOperationSide Side,
  824. bool Temp, const AnsiString FileName, Boolean Success,
  825. bool & DisconnectWhenComplete)
  826. {
  827. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  828. DisconnectWhenComplete);
  829. }
  830. //---------------------------------------------------------------------------
  831. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  832. {
  833. assert(GetSide(Side) == osRemote);
  834. USEDPARAM(Side);
  835. return RemoteDirView;
  836. }
  837. //---------------------------------------------------------------------------
  838. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  839. TOperationSide Side, int FilesOnly)
  840. {
  841. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0));
  842. }
  843. //---------------------------------------------------------------------------
  844. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  845. TOperationSide Side, int FilesOnly)
  846. {
  847. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0));
  848. }
  849. //---------------------------------------------------------------------------
  850. struct THistoryItemData
  851. {
  852. // TOperationSide has 1 byte, but whole structure seems padded to 4 bytes,
  853. // just like "int"
  854. TOperationSide Side;
  855. short int Index;
  856. };
  857. //---------------------------------------------------------------------------
  858. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  859. {
  860. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  861. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  862. DirView(Data.Side)->HistoryGo(Data.Index);
  863. }
  864. //---------------------------------------------------------------------------
  865. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  866. bool Back)
  867. {
  868. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  869. {
  870. TCustomDirView * DView = DirView(Side);
  871. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  872. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  873. if (ICount > 10)
  874. {
  875. ICount = 10;
  876. }
  877. Menu->Items->Clear();
  878. THistoryItemData Data;
  879. Data.Side = Side;
  880. for (short int i = 1; i <= ICount; i++)
  881. {
  882. TTBCustomItem * Item = new TTBXItem(Menu);
  883. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  884. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, (Side == osRemote));
  885. Item->Hint = DView->HistoryPath[Data.Index];
  886. assert(sizeof(int) == sizeof(THistoryItemData));
  887. Item->Tag = *reinterpret_cast<int*>(&Data);
  888. Item->OnClick = HistoryItemClick;
  889. Menu->Items->Add(Item);
  890. }
  891. }
  892. }
  893. //---------------------------------------------------------------------------
  894. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  895. TOperationSide Side, bool Back)
  896. {
  897. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  898. {
  899. FHistoryMenu[Side == osLocal][Back] = new TTBXPopupMenu(this);
  900. UpdateHistoryMenu(Side, Back);
  901. }
  902. return FHistoryMenu[Side == osLocal][Back];
  903. }
  904. //---------------------------------------------------------------------------
  905. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  906. TCustomDirView *Sender)
  907. {
  908. TOperationSide Side = (Sender == DirView(osRemote) ? osRemote : osLocal);
  909. UpdateHistoryMenu(Side, true);
  910. UpdateHistoryMenu(Side, false);
  911. }
  912. //---------------------------------------------------------------------------
  913. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  914. const AnsiString & Command, int Params, bool OnFocused)
  915. {
  916. int Result;
  917. TFileCustomCommand RemoteCustomCommand;
  918. TLocalCustomCommand LocalCustomCommand;
  919. TFileCustomCommand * NonInteractiveCustomCommand =
  920. FLAGCLEAR(Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  921. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  922. AnsiString Cmd = InteractiveCustomCommand.Complete(Command, false);
  923. // custom command that does not operate with files can be executed anytime ...
  924. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  925. {
  926. // ... but do not show such command in remote file menu
  927. // (TODO, currently custom commands are in file menu only, so we cannot hide
  928. // such command, because it won't be accessible from elsewhere)
  929. Result = OnFocused ? /*-1*/ true : true;
  930. }
  931. else if (FLAGCLEAR(Params, ccLocal))
  932. {
  933. // remote custom commands can be executed only on remote side
  934. Result = (FCurrentSide == osRemote) && EnableSelectedOperation[osRemote];
  935. }
  936. else
  937. {
  938. if (LocalCustomCommand.HasLocalFileName(Cmd))
  939. {
  940. // special case is "diff"-style command that can be executed over any side,
  941. // if we have both sides
  942. Result = (HasDirView[osLocal] && EnableSelectedOperation[osLocal]) &&
  943. EnableSelectedOperation[osRemote];
  944. }
  945. else
  946. {
  947. // other local custom commands can be executed only on remote side
  948. Result = (FCurrentSide == osRemote) && EnableSelectedOperation[osRemote];
  949. }
  950. }
  951. return Result;
  952. }
  953. //---------------------------------------------------------------------------
  954. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  955. const AnsiString & Description, bool OnFocused)
  956. {
  957. AnsiString Command = WinConfiguration->CustomCommands->Values[Description];
  958. int Params = WinConfiguration->CustomCommands->Params[Description];
  959. return CustomCommandState(Command, Params, OnFocused);
  960. }
  961. //---------------------------------------------------------------------------
  962. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  963. AnsiString Name, AnsiString Command, int Params)
  964. {
  965. if (FLAGCLEAR(Params, ccLocal))
  966. {
  967. if (EnsureCommandSessionFallback(fcAnyCommand))
  968. {
  969. TRemoteCustomCommand RemoteCustomCommand;
  970. TWinInteractiveCustomCommand InteractiveCustomCommand(
  971. &RemoteCustomCommand, Name);
  972. Command = InteractiveCustomCommand.Complete(Command, false);
  973. bool Capture = FLAGSET(Params, ccShowResults) || FLAGSET(Params, ccCopyResults);
  974. TLogAddLineEvent OutputEvent = NULL;
  975. assert(FCapturedLog == NULL);
  976. if (Capture)
  977. {
  978. FCapturedLog = new TStringList();
  979. OutputEvent = TerminalCaptureLog;
  980. }
  981. try
  982. {
  983. if (!RemoteCustomCommand.IsFileCommand(Command))
  984. {
  985. // Complete just replaces !! with !
  986. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  987. OutputEvent);
  988. }
  989. else
  990. {
  991. Terminal->CustomCommandOnFiles(Command, Params, FileList, OutputEvent);
  992. }
  993. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  994. {
  995. if (FLAGSET(Params, ccCopyResults))
  996. {
  997. CopyToClipboard(FCapturedLog);
  998. }
  999. if (FLAGSET(Params, ccShowResults))
  1000. {
  1001. DoConsoleDialog(Terminal, "", FCapturedLog);
  1002. }
  1003. }
  1004. }
  1005. __finally
  1006. {
  1007. SAFE_DESTROY(FCapturedLog);
  1008. }
  1009. }
  1010. }
  1011. else
  1012. {
  1013. TLocalCustomCommand LocalCustomCommand;
  1014. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1015. &LocalCustomCommand, Name);
  1016. Command = InteractiveCustomCommand.Complete(Command, false);
  1017. if (!LocalCustomCommand.IsFileCommand(Command))
  1018. {
  1019. // Complete just replaces !! with !
  1020. ExecuteShellAndWait(LocalCustomCommand.Complete(Command, true));
  1021. }
  1022. else
  1023. {
  1024. TStrings * LocalFileList = NULL;
  1025. TStrings * RemoteFileList = NULL;
  1026. try
  1027. {
  1028. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  1029. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  1030. if (LocalFileCommand)
  1031. {
  1032. assert(HasDirView[osLocal]);
  1033. assert(EnableSelectedOperation[osLocal]);
  1034. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1035. if (FileListCommand)
  1036. {
  1037. if (LocalFileList->Count != 1)
  1038. {
  1039. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1040. }
  1041. }
  1042. else
  1043. {
  1044. if ((LocalFileList->Count != 1) &&
  1045. (FileList->Count != 1) &&
  1046. (LocalFileList->Count != FileList->Count))
  1047. {
  1048. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1049. }
  1050. }
  1051. }
  1052. AnsiString TempDir;
  1053. TemporarilyDownloadFiles(FileList, false, TempDir, false, false);
  1054. try
  1055. {
  1056. RemoteFileList = new TStringList();
  1057. TMakeLocalFileListParams MakeFileListParam;
  1058. MakeFileListParam.FileList = RemoteFileList;
  1059. MakeFileListParam.IncludeDirs = FLAGSET(Params, ccApplyToDirectories);
  1060. MakeFileListParam.Recursive =
  1061. FLAGSET(Params, ccRecursive) && !FileListCommand;
  1062. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1063. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1064. Progress.Start(foCustomCommand, osRemote, FileListCommand ? 1 : FileList->Count);
  1065. assert(FProgressForm != NULL);
  1066. FProgressForm->ReadOnly = true;
  1067. try
  1068. {
  1069. if (FileListCommand)
  1070. {
  1071. AnsiString LocalFile;
  1072. // MakeFileList does not delimit filenames
  1073. AnsiString FileList = MakeFileList(RemoteFileList);
  1074. if (LocalFileCommand)
  1075. {
  1076. assert(LocalFileList->Count == 1);
  1077. LocalFile = LocalFileList->Strings[0];
  1078. }
  1079. TLocalCustomCommand CustomCommand("", LocalFile, FileList);
  1080. ExecuteShellAndWait(CustomCommand.Complete(Command, true));
  1081. }
  1082. else if (LocalFileCommand)
  1083. {
  1084. if (LocalFileList->Count == 1)
  1085. {
  1086. AnsiString LocalFile = LocalFileList->Strings[0];
  1087. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1088. {
  1089. AnsiString FileName = RemoteFileList->Strings[Index];
  1090. TLocalCustomCommand CustomCommand
  1091. (FileName, LocalFile, "");
  1092. ExecuteShellAndWait(CustomCommand.Complete(Command, true));
  1093. }
  1094. }
  1095. else if (RemoteFileList->Count == 1)
  1096. {
  1097. AnsiString FileName = RemoteFileList->Strings[0];
  1098. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1099. {
  1100. TLocalCustomCommand CustomCommand
  1101. (FileName, LocalFileList->Strings[Index], "");
  1102. ExecuteShellAndWait(CustomCommand.Complete(Command, true));
  1103. }
  1104. }
  1105. else
  1106. {
  1107. if (LocalFileList->Count != RemoteFileList->Count)
  1108. {
  1109. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1110. }
  1111. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1112. {
  1113. AnsiString FileName = RemoteFileList->Strings[Index];
  1114. TLocalCustomCommand CustomCommand
  1115. (FileName, LocalFileList->Strings[Index], "");
  1116. ExecuteShellAndWait(CustomCommand.Complete(Command, true));
  1117. }
  1118. }
  1119. }
  1120. else
  1121. {
  1122. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1123. {
  1124. TLocalCustomCommand CustomCommand
  1125. (RemoteFileList->Strings[Index], "", "");
  1126. ExecuteShellAndWait(CustomCommand.Complete(Command, true));
  1127. }
  1128. }
  1129. }
  1130. __finally
  1131. {
  1132. Progress.Stop();
  1133. }
  1134. }
  1135. __finally
  1136. {
  1137. RecursiveDeleteFile(ExcludeTrailingBackslash(TempDir), false);
  1138. }
  1139. }
  1140. __finally
  1141. {
  1142. delete RemoteFileList;
  1143. delete LocalFileList;
  1144. }
  1145. }
  1146. }
  1147. }
  1148. //---------------------------------------------------------------------------
  1149. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(TObject* /*Sender*/,
  1150. TLogLineType Type, const AnsiString AddedLine)
  1151. {
  1152. if ((Type == llOutput) || (Type == llStdError))
  1153. {
  1154. assert(FCapturedLog != NULL);
  1155. FCapturedLog->Add(AddedLine);
  1156. }
  1157. }
  1158. //---------------------------------------------------------------------------
  1159. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  1160. TOperationSide Side)
  1161. {
  1162. return (Side == osRemote) &&
  1163. ((Control == RemoteDirView) || (Control == RemoteDriveView));
  1164. }
  1165. //---------------------------------------------------------------------------
  1166. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  1167. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  1168. {
  1169. TListItem * Item = RemoteDirView->ItemFocused;
  1170. if ((RemoteDirView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  1171. RemoteDirView->AnyFileSelected(true, false))
  1172. {
  1173. TPoint ScreenPoint, ClientPoint;
  1174. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  1175. TPoint(0, 0) : MousePos;
  1176. ScreenPoint = RemoteDirView->ClientToScreen(ClientPoint);
  1177. #define DEFAULTITEM(ITEM, DEFAULT) \
  1178. { \
  1179. TTBItemOptions O; \
  1180. O = NonVisualDataModule->ITEM->Options; \
  1181. if ((DEFAULT) && Terminal->ResolvingSymlinks && \
  1182. !RemoteDirView->ItemIsDirectory(Item)) \
  1183. NonVisualDataModule->ITEM->Options = O << tboDefault; \
  1184. else \
  1185. NonVisualDataModule->ITEM->Options = O >> tboDefault; \
  1186. }
  1187. DEFAULTITEM(CurrentOpenMenuItem, WinConfiguration->DoubleClickAction == dcaOpen);
  1188. DEFAULTITEM(CurrentEditMenuItem, WinConfiguration->DoubleClickAction == dcaEdit);
  1189. DEFAULTITEM(CurrentCopyMenuItem, WinConfiguration->DoubleClickAction == dcaCopy);
  1190. #undef DEFAULTITEM
  1191. NonVisualDataModule->CurrentOpenMenuItem->Visible = WinConfiguration->ExpertMode;
  1192. NonVisualDataModule->CurrentEditMenuItem->Visible = WinConfiguration->ExpertMode;
  1193. reinterpret_cast<TPopupMenu*>(GetComponent(fcRemotePopup))->Popup(
  1194. ScreenPoint.x, ScreenPoint.y);
  1195. }
  1196. Handled = true;
  1197. }
  1198. //---------------------------------------------------------------------------
  1199. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const AnsiString Directory)
  1200. {
  1201. }
  1202. //---------------------------------------------------------------------------
  1203. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  1204. {
  1205. assert(FErrorList == NULL);
  1206. if (WinConfiguration->ContinueOnError)
  1207. {
  1208. FErrorList = new TStringList();
  1209. }
  1210. }
  1211. //---------------------------------------------------------------------------
  1212. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  1213. {
  1214. if (FErrorList)
  1215. {
  1216. HandleErrorList(FErrorList);
  1217. }
  1218. }
  1219. //---------------------------------------------------------------------------
  1220. void __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  1221. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  1222. {
  1223. void * BatchStorage;
  1224. BatchStart(BatchStorage);
  1225. try
  1226. {
  1227. if ((Operation == foCopy) || (Operation == foMove))
  1228. {
  1229. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  1230. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  1231. AnsiString TargetDirectory;
  1232. bool Temp = false;
  1233. bool DragDrop = false;
  1234. if (Param != NULL)
  1235. {
  1236. TTransferOperationParam& TParam =
  1237. *static_cast<TTransferOperationParam*>(Param);
  1238. TargetDirectory = TParam.TargetDirectory;
  1239. Temp = TParam.Temp;
  1240. DragDrop = TParam.DragDrop;
  1241. }
  1242. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  1243. if (CopyParamDialog(Direction, Type, Temp, FileList, TargetDirectory,
  1244. CopyParam, !NoConfirmation, DragDrop))
  1245. {
  1246. assert(Terminal);
  1247. bool SelectionRestored = false;
  1248. TCustomDirView * DView = NULL;
  1249. if (HasDirView[Side])
  1250. {
  1251. DView = DirView(Side);
  1252. DView->SaveSelection();
  1253. DView->SaveSelectedNames();
  1254. }
  1255. try
  1256. {
  1257. if (Side == osLocal)
  1258. {
  1259. int Params =
  1260. FLAGMASK(Operation == foMove, cpDelete) |
  1261. FLAGMASK(CopyParam.NewerOnly, cpNewerOnly) |
  1262. FLAGMASK(Temp, cpTemporary);
  1263. Terminal->CopyToRemote(FileList, TargetDirectory, &CopyParam, Params);
  1264. if (Operation == foMove)
  1265. {
  1266. ReloadLocalDirectory();
  1267. if (DView != NULL)
  1268. {
  1269. DView->RestoreSelection();
  1270. }
  1271. SelectionRestored = true;
  1272. }
  1273. }
  1274. else
  1275. {
  1276. try
  1277. {
  1278. int Params =
  1279. (Operation == foMove ? cpDelete : 0) |
  1280. (CopyParam.NewerOnly ? cpNewerOnly : 0);
  1281. Terminal->CopyToLocal(FileList, TargetDirectory, &CopyParam,
  1282. Params);
  1283. }
  1284. __finally
  1285. {
  1286. if (Operation == foMove)
  1287. {
  1288. if (DView != NULL)
  1289. {
  1290. DView->RestoreSelection();
  1291. }
  1292. SelectionRestored = true;
  1293. }
  1294. ReloadLocalDirectory(TargetDirectory);
  1295. }
  1296. }
  1297. }
  1298. __finally
  1299. {
  1300. if (!SelectionRestored && (DView != NULL))
  1301. {
  1302. DView->DiscardSavedSelection();
  1303. }
  1304. }
  1305. }
  1306. }
  1307. else if (Operation == foRename)
  1308. {
  1309. assert(DirView(Side)->ItemFocused);
  1310. DirView(Side)->ItemFocused->EditCaption();
  1311. }
  1312. else if (Operation == foDelete)
  1313. {
  1314. assert(FileList->Count);
  1315. bool Confirmed = !WinConfiguration->ConfirmDeleting;
  1316. if (!Confirmed)
  1317. {
  1318. AnsiString Query;
  1319. if (FileList->Count == 1)
  1320. {
  1321. if (Side == osLocal)
  1322. {
  1323. Query = ExtractFileName(FileList->Strings[0]);
  1324. }
  1325. else
  1326. {
  1327. Query = UnixExtractFileName(FileList->Strings[0]);
  1328. }
  1329. Query = FMTLOAD(CONFIRM_DELETE_FILE, (Query));
  1330. }
  1331. else
  1332. {
  1333. Query = FMTLOAD(CONFIRM_DELETE_FILES, (FileList->Count));
  1334. }
  1335. TMessageParams Params(mpNeverAskAgainCheck);
  1336. int Answer = MessageDialog(Query, qtConfirmation,
  1337. qaOK | qaCancel, HELP_NONE, &Params);
  1338. if (Answer == qaNeverAskAgain)
  1339. {
  1340. Confirmed = true;
  1341. WinConfiguration->ConfirmDeleting = false;
  1342. }
  1343. else
  1344. {
  1345. Confirmed = (Answer == qaOK);
  1346. }
  1347. }
  1348. if (Confirmed) DeleteFiles(Side, FileList);
  1349. }
  1350. else if (Operation == foSetProperties)
  1351. {
  1352. RemoteDirView->SaveSelectedNames();
  1353. SetProperties(Side, FileList);
  1354. }
  1355. else if (Operation == foCustomCommand)
  1356. {
  1357. assert(Param);
  1358. assert(Side == osRemote);
  1359. RemoteDirView->SaveSelectedNames();
  1360. TCustomCommandParam * AParam = static_cast<TCustomCommandParam*>(Param);
  1361. CustomCommand(FileList, AParam->Name, AParam->Command, AParam->Params);
  1362. }
  1363. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  1364. {
  1365. assert(Side == osRemote);
  1366. RemoteTransferFiles(FileList, NoConfirmation, (Operation == foRemoteMove));
  1367. }
  1368. else
  1369. {
  1370. assert(false);
  1371. }
  1372. }
  1373. __finally
  1374. {
  1375. BatchEnd(BatchStorage);
  1376. }
  1377. }
  1378. //---------------------------------------------------------------------------
  1379. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  1380. {
  1381. if (Side == osCurrent)
  1382. {
  1383. Side = FCurrentSide;
  1384. }
  1385. return Side;
  1386. }
  1387. //---------------------------------------------------------------------------
  1388. void __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  1389. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  1390. {
  1391. Side = GetSide(Side);
  1392. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, (Side == osLocal), NULL);
  1393. try
  1394. {
  1395. ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  1396. }
  1397. __finally
  1398. {
  1399. delete FileList;
  1400. }
  1401. }
  1402. //---------------------------------------------------------------------------
  1403. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  1404. {
  1405. try
  1406. {
  1407. if (ErrorList->Count)
  1408. {
  1409. if (MessageDialog(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)), qtError,
  1410. qaOK | qaCancel, HELP_NONE) == qaOK)
  1411. {
  1412. int Answer;
  1413. int Index = 0;
  1414. do
  1415. {
  1416. assert(Index >= 0 && Index < ErrorList->Count);
  1417. TQueryButtonAlias Aliases[2];
  1418. Aliases[0].Button = qaYes;
  1419. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  1420. Aliases[1].Button = qaNo;
  1421. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  1422. TMessageParams Params;
  1423. Params.Aliases = Aliases;
  1424. Params.AliasesCount = LENOF(Aliases);
  1425. Answer = MoreMessageDialog(
  1426. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  1427. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  1428. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  1429. qaOK, HELP_NONE, &Params);
  1430. if (Answer == qaNo)
  1431. {
  1432. Index++;
  1433. }
  1434. if (Answer == qaYes)
  1435. {
  1436. Index--;
  1437. }
  1438. }
  1439. while (Answer != qaOK);
  1440. }
  1441. }
  1442. }
  1443. __finally
  1444. {
  1445. TStrings * List = ErrorList;
  1446. ErrorList = NULL;
  1447. for (int i = 0; i < List->Count; i++)
  1448. {
  1449. delete List->Objects[i];
  1450. }
  1451. delete List;
  1452. }
  1453. }
  1454. //---------------------------------------------------------------------------
  1455. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  1456. {
  1457. assert(!WinConfiguration->DisableOpenEdit);
  1458. Side = GetSide(Side);
  1459. AnsiString Name = LoadStr(NEW_FILE);
  1460. if (InputDialog(LoadStr(NEW_FILE_CAPTION), LoadStr(NEW_FILE_PROMPT), Name,
  1461. HELP_EDIT_NEW))
  1462. {
  1463. AnsiString TargetFileName;
  1464. AnsiString LocalFileName;
  1465. AnsiString TempDir;
  1466. if (Side == osRemote)
  1467. {
  1468. TempDir = WinConfiguration->TemporaryDir();
  1469. if (!ForceDirectories(TempDir))
  1470. {
  1471. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TempDir)));
  1472. }
  1473. TargetFileName = UnixExtractFileName(Name);
  1474. LocalFileName = TempDir +
  1475. GUIConfiguration->CurrentCopyParam.ChangeFileName(TargetFileName, osRemote, false);
  1476. }
  1477. else
  1478. {
  1479. if (ExtractFilePath(Name).IsEmpty())
  1480. {
  1481. LocalFileName = IncludeTrailingBackslash(DirView(Side)->PathName) + Name;
  1482. }
  1483. else
  1484. {
  1485. LocalFileName = ExpandFileName(Name);
  1486. }
  1487. TargetFileName = ExtractFileName(Name);
  1488. }
  1489. if (!FileExists(LocalFileName))
  1490. {
  1491. int File = FileCreate(LocalFileName);
  1492. if (File < 0)
  1493. {
  1494. if (!TempDir.IsEmpty())
  1495. {
  1496. RemoveDir(TempDir);
  1497. }
  1498. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  1499. }
  1500. else
  1501. {
  1502. FileClose(File);
  1503. }
  1504. }
  1505. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  1506. const TEditorPreferences * ExternalEditor = NULL;
  1507. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName, false);
  1508. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  1509. ExternalEditor);
  1510. }
  1511. }
  1512. //---------------------------------------------------------------------------
  1513. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  1514. TExecuteFileBy ExecuteFileBy, const TEditorPreferences * ExternalEditor)
  1515. {
  1516. assert((ExecuteFileBy == efExternalEditor) ==
  1517. ((ExternalEditor != NULL) && (ExternalEditor->Data.Editor == edExternal)));
  1518. assert(ExecuteFileBy != efDefaultEditor);
  1519. return
  1520. ((ExecuteFileBy == efInternalEditor)) ||
  1521. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->Data.ExternalEditorText);
  1522. }
  1523. //---------------------------------------------------------------------------
  1524. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  1525. TExecuteFileBy ExecuteFileBy, AnsiString FileName, AnsiString OriginalFileName,
  1526. const TEditorPreferences * ExternalEditor)
  1527. {
  1528. assert(!WinConfiguration->DisableOpenEdit);
  1529. assert((ExecuteFileBy == efExternalEditor) ==
  1530. ((ExternalEditor != NULL) && (ExternalEditor->Data.Editor == edExternal)));
  1531. assert(ExecuteFileBy != efDefaultEditor);
  1532. Side = GetSide(Side);
  1533. TEditedFileData Data;
  1534. if (Side == osRemote)
  1535. {
  1536. Data.Terminal = Terminal;
  1537. Data.Queue = Queue;
  1538. Data.ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  1539. Data.RemoteDirectory = RemoteDirView->PathName;
  1540. Data.SessionName = Terminal->SessionData->SessionName;
  1541. Data.OriginalFileName = OriginalFileName;
  1542. Data.Command = ""; // will be changed later for external editor
  1543. }
  1544. bool SingleEditor = WinConfiguration->Editor.SingleEditor;
  1545. TOperationStatusForm * StatusForm = NULL;
  1546. try
  1547. {
  1548. bool CloseFlag = false;
  1549. bool * PCloseFlag = NULL;
  1550. if ((Side == osRemote) && SingleEditor)
  1551. {
  1552. StatusForm = new TOperationStatusForm(Application);
  1553. StatusForm->Status = LoadStr(DOCUMENT_WAIT);
  1554. StatusForm->ShowAsModal();
  1555. PCloseFlag = &CloseFlag;
  1556. }
  1557. if (ExecuteFileBy == efInternalEditor)
  1558. {
  1559. if (Side == osRemote)
  1560. {
  1561. AnsiString Caption = RemoteDirView->Path + OriginalFileName +
  1562. " - " + Terminal->SessionData->SessionName;
  1563. TForm * Editor = ShowEditorForm(FileName, this, FEditorManager->FileChanged,
  1564. FEditorManager->FileClosed, Caption, !SingleEditor);
  1565. FEditorManager->AddFileInternal(FileName, Data, PCloseFlag, Editor);
  1566. }
  1567. else
  1568. {
  1569. ShowEditorForm(FileName, this, NULL, NULL, "", true);
  1570. }
  1571. }
  1572. else
  1573. {
  1574. HANDLE Process;
  1575. if (ExecuteFileBy == efExternalEditor)
  1576. {
  1577. AnsiString Program, Params, Dir;
  1578. Data.Command = ExternalEditor->Data.ExternalEditor;
  1579. ReformatFileNameCommand(Data.Command);
  1580. SplitCommand(Data.Command, Program, Params, Dir);
  1581. Params = ExpandFileNameCommand(Params, FileName);
  1582. if (!ExecuteShell(Program, Params, Process))
  1583. {
  1584. throw Exception(FMTLOAD(EDITOR_ERROR, (Program)));
  1585. }
  1586. }
  1587. else
  1588. {
  1589. assert(Side == osRemote);
  1590. if (!ExecuteShell(FileName, "", Process))
  1591. {
  1592. throw Exception(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  1593. }
  1594. }
  1595. if ((Side == osLocal) ||
  1596. ((ExecuteFileBy == efExternalEditor) && !SingleEditor &&
  1597. ExternalEditor->Data.MDIExternalEditor))
  1598. {
  1599. // no need for handle
  1600. if (Process != NULL)
  1601. {
  1602. CHECK(CloseHandle(Process));
  1603. }
  1604. Process = INVALID_HANDLE_VALUE;
  1605. }
  1606. else
  1607. {
  1608. if (Process == NULL)
  1609. {
  1610. throw Exception(LoadStr(OPEN_FILE_NO_PROCESS2));
  1611. }
  1612. }
  1613. if (Side == osRemote)
  1614. {
  1615. FEditorManager->AddFileExternal(FileName, Data, PCloseFlag, Process);
  1616. }
  1617. }
  1618. if (StatusForm != NULL)
  1619. {
  1620. do
  1621. {
  1622. Application->ProcessMessages();
  1623. }
  1624. while (!Application->Terminated && !CloseFlag);
  1625. }
  1626. }
  1627. __finally
  1628. {
  1629. if (StatusForm != NULL)
  1630. {
  1631. delete StatusForm;
  1632. }
  1633. }
  1634. }
  1635. //---------------------------------------------------------------------------
  1636. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  1637. TStrings * FileList, bool ForceText, AnsiString & TempDir, bool AllFiles,
  1638. bool GetTargetNames)
  1639. {
  1640. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  1641. if (ForceText)
  1642. {
  1643. CopyParam.TransferMode = tmAscii;
  1644. }
  1645. // do not forget to add additional options to ExecutedFileChanged, FAR and SS
  1646. CopyParam.FileNameCase = ncNoChange;
  1647. CopyParam.PreserveReadOnly = false;
  1648. CopyParam.ResumeSupport = rsOff;
  1649. CopyParam.ReplaceInvalidChars = true;
  1650. CopyParam.FileMask = "";
  1651. if (AllFiles)
  1652. {
  1653. CopyParam.ExcludeFileMask = TFileMasks();
  1654. }
  1655. if (TempDir.IsEmpty())
  1656. {
  1657. TempDir = WinConfiguration->TemporaryDir();
  1658. if (!ForceDirectories(TempDir))
  1659. {
  1660. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TempDir)));
  1661. }
  1662. }
  1663. FAutoOperation = true;
  1664. Terminal->ExceptionOnFail = true;
  1665. try
  1666. {
  1667. try
  1668. {
  1669. // turn off confirmations, as for MDI editors we may possibly download
  1670. // the same file over
  1671. Terminal->CopyToLocal(FileList, TempDir, &CopyParam,
  1672. cpNoConfirmation | cpTemporary);
  1673. if (GetTargetNames)
  1674. {
  1675. for (int i = 0; i < FileList->Count; i++)
  1676. {
  1677. FileList->Strings[i] =
  1678. CopyParam.ChangeFileName(FileList->Strings[i], osRemote, false);
  1679. }
  1680. }
  1681. }
  1682. catch(...)
  1683. {
  1684. try
  1685. {
  1686. RecursiveDeleteFile(ExcludeTrailingBackslash(TempDir), false);
  1687. }
  1688. catch(...)
  1689. {
  1690. }
  1691. throw;
  1692. }
  1693. }
  1694. __finally
  1695. {
  1696. FAutoOperation = false;
  1697. Terminal->ExceptionOnFail = false;
  1698. }
  1699. }
  1700. //---------------------------------------------------------------------------
  1701. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  1702. TExecuteFileBy & ExecuteFileBy, const TEditorPreferences *& ExternalEditor,
  1703. const AnsiString & FileName, bool Local)
  1704. {
  1705. if (ExecuteFileBy == efDefaultEditor)
  1706. {
  1707. ExternalEditor = WinConfiguration->DefaultEditorForFile(FileName, Local);
  1708. if ((ExternalEditor == NULL) || (ExternalEditor->Data.Editor == edInternal))
  1709. {
  1710. ExecuteFileBy = efInternalEditor;
  1711. ExternalEditor = NULL;
  1712. }
  1713. else
  1714. {
  1715. ExecuteFileBy = efExternalEditor;
  1716. }
  1717. }
  1718. }
  1719. //---------------------------------------------------------------------------
  1720. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  1721. TExecuteFileBy ExecuteFileBy, const TEditorPreferences * ExternalEditor,
  1722. bool AllSelected, bool OnFocused)
  1723. {
  1724. assert(!WinConfiguration->DisableOpenEdit);
  1725. assert((ExecuteFileBy == efExternalEditor) ==
  1726. ((ExternalEditor != NULL) && (ExternalEditor->Data.Editor == edExternal)));
  1727. Side = GetSide(Side);
  1728. TCustomDirView * DView = DirView(Side);
  1729. if (WinConfiguration->Editor.SingleEditor)
  1730. {
  1731. AllSelected = false;
  1732. }
  1733. TStrings * FileList = AllSelected ?
  1734. DView->CreateFileList(OnFocused, Side == osLocal) :
  1735. DView->CreateFocusedFileList(Side == osLocal);
  1736. try
  1737. {
  1738. assert(AllSelected || (FileList->Count == 1));
  1739. for (int i = 0; i < FileList->Count; i++)
  1740. {
  1741. AnsiString ListFileName = FileList->Strings[i];
  1742. AnsiString FileNameOnly = (Side == osRemote) ?
  1743. UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  1744. TListItem * Item = DView->FindFileItem(FileNameOnly);
  1745. if (!DView->ItemIsDirectory(Item))
  1746. {
  1747. AnsiString OriginalFileName;
  1748. AnsiString FullFileName;
  1749. AnsiString FileName;
  1750. if (Side == osRemote)
  1751. {
  1752. OriginalFileName = ListFileName;
  1753. FullFileName = RemoteDirView->Path + ListFileName;
  1754. }
  1755. else
  1756. {
  1757. OriginalFileName = ExtractFileName(ListFileName);
  1758. FullFileName = ListFileName;
  1759. }
  1760. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  1761. (Side == osLocal));
  1762. if (Side == osRemote)
  1763. {
  1764. TObject * Token = NULL;
  1765. AnsiString TempDir; // path to already edited file in MDI editor
  1766. if (!FEditorManager->CanAddFile(RemoteDirView->PathName, OriginalFileName,
  1767. Terminal->SessionData->SessionName, Token, TempDir))
  1768. {
  1769. if (Token != NULL)
  1770. {
  1771. TForm * Form = dynamic_cast<TForm *>(Token);
  1772. Form->SetFocus();
  1773. Abort();
  1774. }
  1775. else
  1776. {
  1777. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY, (OriginalFileName)));
  1778. }
  1779. }
  1780. TStringList * FileList1 = new TStringList();
  1781. try
  1782. {
  1783. FileList1->AddObject(ListFileName, FileList->Objects[i]);
  1784. TemporarilyDownloadFiles(FileList1,
  1785. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor), TempDir, true, true);
  1786. }
  1787. __finally
  1788. {
  1789. delete FileList1;
  1790. }
  1791. FileName = TempDir + FileList->Strings[i];
  1792. }
  1793. else
  1794. {
  1795. FileName = FileList->Strings[i];
  1796. }
  1797. CustomExecuteFile(Side, ExecuteFileBy, FileName, OriginalFileName, ExternalEditor);
  1798. }
  1799. }
  1800. }
  1801. __finally
  1802. {
  1803. delete FileList;
  1804. }
  1805. }
  1806. //---------------------------------------------------------------------------
  1807. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const AnsiString FileName,
  1808. const TEditedFileData & Data, HANDLE UploadCompleteEvent)
  1809. {
  1810. if ((Data.Terminal == NULL) || !Data.Terminal->Active)
  1811. {
  1812. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED,
  1813. (ExtractFileName(FileName), Data.SessionName)));
  1814. }
  1815. TStrings * FileList = new TStringList();
  1816. try
  1817. {
  1818. FileList->Add(FileName);
  1819. // consider using the same settings (preset) as when the file was downloaded
  1820. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  1821. if (Data.ForceText)
  1822. {
  1823. CopyParam.TransferMode = tmAscii;
  1824. }
  1825. // do not forget to add additional options to TemporarilyDownloadFiles, FAR and SS
  1826. CopyParam.FileNameCase = ncNoChange;
  1827. CopyParam.PreserveRights = false;
  1828. CopyParam.ResumeSupport = rsOff;
  1829. // so i do not need to worry if masking algorithm works in all cases
  1830. // ("" means "copy file name", no masking is actually done)
  1831. if (ExtractFileName(FileName) == Data.OriginalFileName)
  1832. {
  1833. CopyParam.FileMask = "";
  1834. }
  1835. else
  1836. {
  1837. CopyParam.FileMask = DelimitFileNameMask(Data.OriginalFileName);
  1838. }
  1839. CopyParam.ReplaceInvalidChars = true; // not used for uploads anyway
  1840. CopyParam.ExcludeFileMask = TFileMasks();
  1841. if (WinConfiguration->Editor.SingleEditor)
  1842. {
  1843. FAutoOperation = true;
  1844. Data.Terminal->ExceptionOnFail = true;
  1845. try
  1846. {
  1847. Data.Terminal->CopyToRemote(FileList, RemoteDirView->PathName,
  1848. &CopyParam, cpNoConfirmation | cpTemporary);
  1849. }
  1850. __finally
  1851. {
  1852. FAutoOperation = false;
  1853. Data.Terminal->ExceptionOnFail = false;
  1854. if (UploadCompleteEvent != INVALID_HANDLE_VALUE)
  1855. {
  1856. SetEvent(UploadCompleteEvent);
  1857. }
  1858. }
  1859. }
  1860. else
  1861. {
  1862. assert(Queue != NULL);
  1863. int Params = cpNoConfirmation | cpTemporary;
  1864. TQueueItem * QueueItem = new TUploadQueueItem(Data.Terminal, FileList,
  1865. Data.RemoteDirectory, &CopyParam, Params);
  1866. QueueItem->CompleteEvent = UploadCompleteEvent;
  1867. Data.Queue->AddItem(QueueItem);
  1868. }
  1869. }
  1870. __finally
  1871. {
  1872. delete FileList;
  1873. }
  1874. }
  1875. //---------------------------------------------------------------------------
  1876. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  1877. const TEditedFileData & Data, bool * CloseFlag, bool & KeepOpen)
  1878. {
  1879. // CloseFlag is set for single editors only.
  1880. if (CloseFlag == NULL)
  1881. {
  1882. // Command is set for external editors only (not for "shell" open).
  1883. if (!Data.Command.IsEmpty())
  1884. {
  1885. bool AnyFound = false;
  1886. bool AnyMDI = false;
  1887. bool AnyNonMDI = false;
  1888. bool AnyDetect = false;
  1889. TEditorList * EditorList = new TEditorList();
  1890. try
  1891. {
  1892. *EditorList = *WinConfiguration->EditorList;
  1893. for (int i = 0; i < EditorList->Count; i++)
  1894. {
  1895. const TEditorPreferences * Editor = EditorList->Editors[i];
  1896. if ((Editor->Data.Editor == edExternal) &&
  1897. (Editor->Data.ExternalEditor == Data.Command))
  1898. {
  1899. AnyFound = true;
  1900. if (!Editor->Data.MDIExternalEditor)
  1901. {
  1902. AnyNonMDI = true;
  1903. if (Editor->Data.DetectMDIExternalEditor)
  1904. {
  1905. AnyDetect = true;
  1906. }
  1907. }
  1908. else
  1909. {
  1910. AnyMDI = true;
  1911. }
  1912. }
  1913. }
  1914. bool EnableMDI = false;
  1915. bool DisableDetect = false;
  1916. if (AnyMDI)
  1917. {
  1918. KeepOpen = true;
  1919. if (AnyNonMDI)
  1920. {
  1921. // there is at least one instance of the editor with MDI support enabled,
  1922. // and one with disabled, enable it for all instances
  1923. EnableMDI = true;
  1924. }
  1925. }
  1926. else if (AnyFound && !AnyDetect)
  1927. {
  1928. // at least once instance found but all have MDI autodetection disabled
  1929. // => close the file (default action)
  1930. }
  1931. else
  1932. {
  1933. // no instance of the editor has MDI support enabled
  1934. TMessageParams Params;
  1935. if (AnyFound)
  1936. {
  1937. // there is at least one instance of the editor with enabled
  1938. // MDI autodetection
  1939. Params.Params |= mpNeverAskAgainCheck;
  1940. }
  1941. int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED, (Data.OriginalFileName)), qtWarning,
  1942. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  1943. switch (Answer)
  1944. {
  1945. case qaNeverAskAgain:
  1946. DisableDetect = true;
  1947. break;
  1948. case qaNo:
  1949. EnableMDI = true;
  1950. KeepOpen = true;
  1951. break;
  1952. }
  1953. }
  1954. if (AnyFound && (EnableMDI || DisableDetect))
  1955. {
  1956. bool Changed = false;
  1957. for (int i = 0; i < EditorList->Count; i++)
  1958. {
  1959. const TEditorPreferences * Editor = EditorList->Editors[i];
  1960. if ((Editor->Data.Editor == edExternal) &&
  1961. (Editor->Data.ExternalEditor == Data.Command) &&
  1962. ((EnableMDI && !Editor->Data.MDIExternalEditor) ||
  1963. (DisableDetect && Editor->Data.DetectMDIExternalEditor)))
  1964. {
  1965. Changed = true;
  1966. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  1967. if (EnableMDI)
  1968. {
  1969. UpdatedEditor->Data.MDIExternalEditor = true;
  1970. }
  1971. if (DisableDetect)
  1972. {
  1973. UpdatedEditor->Data.DetectMDIExternalEditor = false;
  1974. }
  1975. EditorList->Change(i, UpdatedEditor);
  1976. }
  1977. }
  1978. if (Changed)
  1979. {
  1980. WinConfiguration->EditorList = EditorList;
  1981. }
  1982. }
  1983. }
  1984. __finally
  1985. {
  1986. delete EditorList;
  1987. }
  1988. }
  1989. else
  1990. {
  1991. // "open" case
  1992. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data.OriginalFileName)), qtWarning,
  1993. qaOK, HELP_APP_EARLY_CLOSED);
  1994. }
  1995. }
  1996. }
  1997. //---------------------------------------------------------------------------
  1998. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  1999. {
  2000. SideEnter(osRemote);
  2001. }
  2002. //---------------------------------------------------------------------------
  2003. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  2004. {
  2005. MakeNextInTabOrder(RemoteDirView, RemoteDriveView);
  2006. SideEnter(osRemote);
  2007. }
  2008. //---------------------------------------------------------------------------
  2009. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  2010. {
  2011. FCurrentSide = Side;
  2012. UpdateControls();
  2013. }
  2014. //---------------------------------------------------------------------------
  2015. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  2016. TStrings * FileList)
  2017. {
  2018. assert(Terminal);
  2019. TCustomDirView * DView = DirView(Side);
  2020. DView->SaveSelection();
  2021. DView->SaveSelectedNames();
  2022. try
  2023. {
  2024. if (Side == osRemote)
  2025. {
  2026. Terminal->DeleteFiles(FileList);
  2027. }
  2028. else
  2029. {
  2030. try
  2031. {
  2032. Terminal->DeleteLocalFiles(FileList);
  2033. }
  2034. __finally
  2035. {
  2036. ReloadLocalDirectory();
  2037. }
  2038. }
  2039. }
  2040. catch(...)
  2041. {
  2042. DView->DiscardSavedSelection();
  2043. throw;
  2044. }
  2045. DView->RestoreSelection();
  2046. }
  2047. //---------------------------------------------------------------------------
  2048. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TStrings * FileList,
  2049. AnsiString & Target, AnsiString & FileMask, bool NoConfirmation, bool Move)
  2050. {
  2051. if (RemoteDriveView->DropTarget != NULL)
  2052. {
  2053. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  2054. }
  2055. else if (RemoteDirView->DropTarget != NULL)
  2056. {
  2057. assert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  2058. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  2059. }
  2060. else
  2061. {
  2062. Target = RemoteDirView->Path;
  2063. }
  2064. Target = UnixIncludeTrailingBackslash(Target);
  2065. FileMask = "*.*";
  2066. bool Result = true;
  2067. if (!NoConfirmation)
  2068. {
  2069. Result = DoRemoteTransferDialog(FileList, Target, FileMask, Move);
  2070. }
  2071. return Result;
  2072. }
  2073. //---------------------------------------------------------------------------
  2074. void __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  2075. TStrings * FileList, bool NoConfirmation, bool Move)
  2076. {
  2077. AnsiString Target, FileMask;
  2078. if ((Move || EnsureCommandSessionFallback(fcRemoteCopy)) &&
  2079. RemoteTransferDialog(FileList, Target, FileMask, NoConfirmation, Move))
  2080. {
  2081. RemoteDirView->SaveSelection();
  2082. RemoteDirView->SaveSelectedNames();
  2083. try
  2084. {
  2085. if (Move)
  2086. {
  2087. Terminal->MoveFiles(FileList, Target, FileMask);
  2088. }
  2089. else
  2090. {
  2091. Terminal->CopyFiles(FileList, Target, FileMask);
  2092. }
  2093. }
  2094. catch(...)
  2095. {
  2096. RemoteDirView->DiscardSavedSelection();
  2097. throw;
  2098. }
  2099. RemoteDirView->RestoreSelection();
  2100. }
  2101. }
  2102. //---------------------------------------------------------------------------
  2103. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  2104. {
  2105. Side = GetSide(Side);
  2106. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  2107. TRemoteProperties * AProperties = (Side == osRemote ? &Properties : NULL);
  2108. AnsiString Name = LoadStr(NEW_FOLDER);
  2109. bool SaveSettings = false;
  2110. if (DoCreateDirectoryDialog(Name, AProperties, SaveSettings))
  2111. {
  2112. if (Side == osRemote)
  2113. {
  2114. if (SaveSettings)
  2115. {
  2116. GUIConfiguration->NewDirectoryProperties = Properties;
  2117. }
  2118. RemoteDirView->CreateDirectoryEx(Name, &Properties);
  2119. }
  2120. else
  2121. {
  2122. DirView(Side)->CreateDirectory(Name);
  2123. }
  2124. }
  2125. }
  2126. //---------------------------------------------------------------------------
  2127. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  2128. {
  2129. DoOpenDirectoryDialog(odBrowse, Side);
  2130. }
  2131. //---------------------------------------------------------------------------
  2132. void __fastcall TCustomScpExplorerForm::RemoteDirViewGetSelectFilter(
  2133. TCustomDirView *Sender, bool Select, TFileFilter &Filter)
  2134. {
  2135. assert(Sender);
  2136. if (!DoSelectMaskDialog(Sender, Select, &Filter, Configuration)) Abort();
  2137. }
  2138. //---------------------------------------------------------------------------
  2139. void __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  2140. {
  2141. if (Side == osRemote)
  2142. {
  2143. TRemoteProperties CurrentProperties;
  2144. if (Terminal->LoadFilesProperties(FileList))
  2145. {
  2146. RemoteDirView->Invalidate();
  2147. }
  2148. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  2149. int Flags = 0;
  2150. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  2151. if (Terminal->IsCapable[fcOwnerChanging]) Flags |= cpOwner;
  2152. if (Terminal->IsCapable[fcGroupChanging]) Flags |= cpGroup;
  2153. TRemoteProperties NewProperties = CurrentProperties;
  2154. if (DoPropertiesDialog(FileList, RemoteDirView->PathName,
  2155. Terminal->Groups, Terminal->Users, &NewProperties, Flags, Terminal))
  2156. {
  2157. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  2158. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  2159. }
  2160. }
  2161. else
  2162. {
  2163. DirView(Side)->DisplayPropertiesMenu();
  2164. }
  2165. }
  2166. //---------------------------------------------------------------------------
  2167. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  2168. {
  2169. if (QueueView->Focused() && (QueueView->OnKeyDown != NULL))
  2170. {
  2171. QueueView->OnKeyDown(QueueView, Key, Shift);
  2172. }
  2173. if (!DirView(osCurrent)->IsEditing())
  2174. {
  2175. TShortCut KeyShortCut = ShortCut(Key, Shift);
  2176. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  2177. {
  2178. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  2179. if (((Action->ShortCut == KeyShortCut) ||
  2180. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  2181. AllowedAction(Action, aaShortCut))
  2182. {
  2183. Key = 0;
  2184. Action->Execute();
  2185. return;
  2186. }
  2187. }
  2188. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  2189. {
  2190. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  2191. {
  2192. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  2193. FIgnoreNextSysCommand = true;
  2194. return;
  2195. }
  2196. }
  2197. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  2198. {
  2199. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  2200. Key = 0;
  2201. }
  2202. }
  2203. TForm::KeyDown(Key, Shift);
  2204. }
  2205. //---------------------------------------------------------------------------
  2206. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  2207. {
  2208. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  2209. assert(Terminal);
  2210. int Index = SessionStatusBar->Tag;
  2211. if (SessionStatusBar->Tag > 0)
  2212. {
  2213. SessionStatusBar->Panels->Items[0]->Hint = LoadStr(STATUS_FILEINFO_HINT);
  2214. }
  2215. SessionStatusBar->Panels->Items[Index]->Hint = LoadStr(STATUS_RECEIVED_HINT);
  2216. SessionStatusBar->Panels->Items[Index + 1]->Hint = LoadStr(STATUS_SENT_HINT);
  2217. SessionStatusBar->Panels->Items[Index + 2]->ImageIndex = Terminal->SshVersion - 1;
  2218. SessionStatusBar->Panels->Items[Index + 2]->Hint = FMTLOAD(STATUS_VERSION_HINT, (Terminal->SshVersion));
  2219. SessionStatusBar->Panels->Items[Index + 3]->ImageIndex = 2 + (Terminal->CSCompression || Terminal->SCCompression);
  2220. if (Terminal->CSCompression == Terminal->SCCompression)
  2221. {
  2222. SessionStatusBar->Panels->Items[Index + 3]->Hint =
  2223. FMTLOAD(STATUS_COMPRESSION_HINT, (BooleanToStr(Terminal->CSCompression)));
  2224. }
  2225. else
  2226. {
  2227. SessionStatusBar->Panels->Items[Index + 3]->Hint = FMTLOAD(STATUS_COMPRESSION2_HINT,
  2228. (BooleanToStr(Terminal->CSCompression), BooleanToStr(Terminal->SCCompression)));
  2229. }
  2230. SessionStatusBar->Panels->Items[Index + 4]->Caption = CipherNames[Terminal->CSCipher];
  2231. SessionStatusBar->Panels->Items[Index + 4]->ImageIndex = 4;
  2232. if (Terminal->CSCompression == Terminal->SCCompression)
  2233. {
  2234. SessionStatusBar->Panels->Items[Index + 4]->Hint =
  2235. FMTLOAD(STATUS_ENCRYPTION_HINT, (CipherNames[Terminal->CSCipher]));
  2236. }
  2237. else
  2238. {
  2239. SessionStatusBar->Panels->Items[Index + 4]->Hint = FMTLOAD(STATUS_ENCRYPTION2_HINT,
  2240. (CipherNames[Terminal->CSCipher], CipherNames[Terminal->SCCipher]));
  2241. }
  2242. SessionStatusBar->Panels->Items[Index + 5]->Caption = Terminal->ProtocolName;
  2243. SessionStatusBar->Panels->Items[Index + 5]->Hint =
  2244. FMTLOAD(STATUS_FS_PROTOCOL, (Terminal->ProtocolName));
  2245. UpdateStatusBar();
  2246. }
  2247. //---------------------------------------------------------------------------
  2248. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  2249. {
  2250. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  2251. assert(SessionStatusBar && (SessionStatusBar->Panels->Count >= 3));
  2252. if (FShowStatusBarHint)
  2253. {
  2254. SessionStatusBar->SimplePanel = true;
  2255. SessionStatusBar->SimpleText = FStatusBarHint;
  2256. }
  2257. else if (!Terminal || !Terminal->Active || Terminal->Status < sshReady)
  2258. {
  2259. // note: (Terminal->Status < sshReady) currently never happens here,
  2260. // so STATUS_CONNECTING is never used
  2261. SessionStatusBar->SimplePanel = true;
  2262. SessionStatusBar->SimpleText = LoadStr(
  2263. !Terminal || !Terminal->Active ? STATUS_DISCONNECTED : STATUS_CONNECTING);
  2264. }
  2265. else
  2266. {
  2267. assert(Terminal);
  2268. SessionStatusBar->SimplePanel = false;
  2269. int Index = SessionStatusBar->Tag;
  2270. SessionStatusBar->Panels->Items[Index]->Caption = FormatBytes(Terminal->BytesReceived);
  2271. SessionStatusBar->Panels->Items[Index + 1]->Caption = FormatBytes(Terminal->BytesSent);
  2272. SessionStatusBar->Panels->Items[Index + 6]->Caption =
  2273. FormatDateTimeSpan(Configuration->TimeFormat, Terminal->Duration);
  2274. }
  2275. }
  2276. //---------------------------------------------------------------------------
  2277. void __fastcall TCustomScpExplorerForm::Idle(bool AppIdle)
  2278. {
  2279. FEditorManager->Check();
  2280. // terminal may not be active here, when connection is closed by remote side
  2281. // and coresponding error message is being displayed
  2282. if (Terminal && Terminal->Active)
  2283. {
  2284. Terminal->Idle();
  2285. // queue may be still NULL if idle() occures while terminal is being set
  2286. if (FQueue != NULL)
  2287. {
  2288. FQueue->Idle();
  2289. }
  2290. }
  2291. if (AppIdle)
  2292. {
  2293. if (FRefreshRemoteDirectory)
  2294. {
  2295. if ((Terminal != NULL) && Terminal->Active)
  2296. {
  2297. Terminal->RefreshDirectory();
  2298. }
  2299. FRefreshRemoteDirectory = false;
  2300. }
  2301. if (FRefreshLocalDirectory)
  2302. {
  2303. ReloadLocalDirectory();
  2304. FRefreshLocalDirectory = false;
  2305. }
  2306. }
  2307. if (FQueueStatusInvalidated)
  2308. {
  2309. UpdateQueueStatus(AppIdle);
  2310. }
  2311. RefreshQueueItems(AppIdle);
  2312. UpdateStatusBar();
  2313. FIgnoreNextSysCommand = false;
  2314. }
  2315. //---------------------------------------------------------------------------
  2316. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  2317. {
  2318. try
  2319. {
  2320. FUserActionTimer->Enabled = false;
  2321. if (GUIConfiguration->QueueAutoPopup && (FPendingQueueActionItem != NULL))
  2322. {
  2323. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  2324. {
  2325. FPendingQueueActionItem->ProcessUserAction();
  2326. }
  2327. }
  2328. }
  2329. __finally
  2330. {
  2331. FPendingQueueActionItem = NULL;
  2332. }
  2333. }
  2334. //---------------------------------------------------------------------------
  2335. void __fastcall TCustomScpExplorerForm::ApplicationHint(TObject * /*Sender*/)
  2336. {
  2337. assert(GetComponent(fcStatusBar) && Application);
  2338. AnsiString AHint = GetLongHint(Application->Hint);
  2339. FShowStatusBarHint = Active && !AHint.IsEmpty() && (AHint != "X");
  2340. if (FShowStatusBarHint)
  2341. {
  2342. FStatusBarHint = AHint != "E" ? AHint : AnsiString("");
  2343. }
  2344. else
  2345. {
  2346. FStatusBarHint = "";
  2347. }
  2348. UpdateStatusBar();
  2349. }
  2350. //---------------------------------------------------------------------------
  2351. void __fastcall TCustomScpExplorerForm::NewSession()
  2352. {
  2353. TTerminalManager::Instance()->NewSession();
  2354. }
  2355. //---------------------------------------------------------------------------
  2356. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  2357. {
  2358. assert(FQueue != NULL);
  2359. return (FQueue->IsEmpty ||
  2360. (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK));
  2361. }
  2362. //---------------------------------------------------------------------------
  2363. void __fastcall TCustomScpExplorerForm::CloseSession()
  2364. {
  2365. if (CanCloseQueue())
  2366. {
  2367. TTerminalManager::Instance()->FreeActiveTerminal();
  2368. }
  2369. }
  2370. //---------------------------------------------------------------------------
  2371. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  2372. {
  2373. TTerminalManager * Manager = TTerminalManager::Instance();
  2374. TTerminal * Terminal = Manager->NewTerminal(Data);
  2375. Manager->ActiveTerminal = Terminal;
  2376. Manager->ConnectActiveTerminal();
  2377. }
  2378. //---------------------------------------------------------------------------
  2379. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  2380. bool &CanClose)
  2381. {
  2382. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  2383. {
  2384. int Result;
  2385. TMessageParams Params(mpNeverAskAgainCheck);
  2386. AnsiString Message;
  2387. if (TTerminalManager::Instance()->Count > 1)
  2388. {
  2389. Message = LoadStr(CLOSE_SESSIONS);
  2390. }
  2391. else
  2392. {
  2393. Message = FMTLOAD(CLOSE_SESSION, (Terminal->SessionData->SessionName));
  2394. }
  2395. Result = MessageDialog(Message, qtConfirmation,
  2396. qaOK | qaCancel, HELP_NONE, &Params);
  2397. if (Result == qaNeverAskAgain)
  2398. {
  2399. WinConfiguration->ConfirmClosingSession = false;
  2400. }
  2401. CanClose = (Result == qaOK || Result == qaNeverAskAgain);
  2402. }
  2403. if (CanClose)
  2404. {
  2405. CanClose = CanCloseQueue();
  2406. }
  2407. if (CanClose)
  2408. {
  2409. CanClose = FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  2410. FEditorManager->CloseExternalFilesWithoutProcess() &&
  2411. (FEditorManager->Empty(true) ||
  2412. (MessageDialog(LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel,
  2413. HELP_NONE) == qaIgnore));
  2414. }
  2415. }
  2416. //---------------------------------------------------------------------------
  2417. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  2418. {
  2419. TForm * Form = dynamic_cast<TForm *>(Sender);
  2420. assert(Form != NULL);
  2421. Form->Close();
  2422. }
  2423. //---------------------------------------------------------------------------
  2424. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  2425. {
  2426. TForm * Form = dynamic_cast<TForm *>(Sender);
  2427. delete Form;
  2428. }
  2429. //---------------------------------------------------------------------------
  2430. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  2431. TObject *Sender)
  2432. {
  2433. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  2434. try
  2435. {
  2436. SetProperties(osRemote, FileList);
  2437. }
  2438. __finally
  2439. {
  2440. delete FileList;
  2441. }
  2442. }
  2443. //---------------------------------------------------------------------------
  2444. void __fastcall TCustomScpExplorerForm::ComponentShowing(Word Component, bool value)
  2445. {
  2446. if (value)
  2447. {
  2448. if (Component == fcCustomCommandsBand)
  2449. {
  2450. UpdateCustomCommandsToolbar();
  2451. }
  2452. }
  2453. }
  2454. //---------------------------------------------------------------------------
  2455. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Word Component, Boolean value)
  2456. {
  2457. TControl * Control = GetComponent(Component);
  2458. assert(Control);
  2459. bool Changed = (Control->Visible != value);
  2460. if (Changed)
  2461. {
  2462. ComponentShowing(Component, value);
  2463. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  2464. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  2465. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  2466. if (value)
  2467. {
  2468. int RemainingHeight = Control->Parent->ClientHeight;
  2469. int RemainingWidth = Control->Parent->ClientWidth;
  2470. for (int i = 0; i < Control->Parent->ControlCount; i++)
  2471. {
  2472. TControl * ChildControl = Control->Parent->Controls[i];
  2473. if (ChildControl->Visible)
  2474. {
  2475. switch (ChildControl->Align)
  2476. {
  2477. case alTop:
  2478. case alBottom:
  2479. RemainingHeight -= ChildControl->Height;
  2480. break;
  2481. case alLeft:
  2482. case alRight:
  2483. RemainingWidth -= ChildControl->Width;
  2484. break;
  2485. }
  2486. }
  2487. }
  2488. static int Reserve = 32;
  2489. // queue in explorer, trees in commander
  2490. if (Control->Height > RemainingHeight - Reserve)
  2491. {
  2492. Control->Height = RemainingHeight / 2;
  2493. }
  2494. if (Control->Width > RemainingWidth - Reserve)
  2495. {
  2496. Control->Width = RemainingWidth / 2;
  2497. }
  2498. }
  2499. Control->Visible = value;
  2500. if (WasFocused && Visible)
  2501. {
  2502. DirView(osCurrent)->SetFocus();
  2503. }
  2504. FixControlsPlacement();
  2505. }
  2506. }
  2507. //---------------------------------------------------------------------------
  2508. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Word Component)
  2509. {
  2510. TControl * Control = GetComponent(Component);
  2511. if (Control == NULL)
  2512. {
  2513. return false;
  2514. }
  2515. else
  2516. {
  2517. return Control->Visible;
  2518. }
  2519. }
  2520. //---------------------------------------------------------------------------
  2521. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  2522. {
  2523. CALLSTACK;
  2524. if (RemoteDirView->ItemFocused != NULL)
  2525. {
  2526. RemoteDirView->ItemFocused->MakeVisible(false);
  2527. }
  2528. QueueSplitter->Visible = QueuePanel->Visible;
  2529. RemotePanelSplitter->Visible = RemoteDriveView->Visible;
  2530. }
  2531. //---------------------------------------------------------------------------
  2532. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  2533. {
  2534. switch (Component) {
  2535. case fcStatusBar: return RemoteStatusBar;
  2536. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  2537. case fcQueueView: return QueuePanel;
  2538. case fcQueueToolbar: return QueueDock;
  2539. case fcRemoteTree: return RemoteDriveView;
  2540. default: return NULL;
  2541. }
  2542. }
  2543. //---------------------------------------------------------------------------
  2544. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  2545. TObject *Sender, TListColumn *Column, TPoint &Point)
  2546. {
  2547. assert(NonVisualDataModule && Column && Sender);
  2548. NonVisualDataModule->ListColumn = Column;
  2549. TPoint ScreenPoint = ((TControl*)Sender)->ClientToScreen(Point);
  2550. TPopupMenu * DirViewColumnMenu;
  2551. if (Sender == RemoteDirView)
  2552. {
  2553. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  2554. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  2555. (Column->Index == uvName);
  2556. }
  2557. else
  2558. {
  2559. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  2560. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  2561. (Column->Index == dvName);
  2562. }
  2563. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  2564. }
  2565. //---------------------------------------------------------------------------
  2566. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  2567. TObject *Sender, TListItem *Item, bool &AllowExec)
  2568. {
  2569. DoDirViewExecFile(Sender, Item, AllowExec);
  2570. }
  2571. //---------------------------------------------------------------------------
  2572. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  2573. TListItem * Item, bool & AllowExec)
  2574. {
  2575. assert(Sender && Item && Configuration);
  2576. assert(AllowExec);
  2577. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  2578. bool Remote = (ADirView == DirView(osRemote));
  2579. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks;
  2580. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  2581. // on files only (not directories)
  2582. // and only when symlinks are resolved (apply to remote panel only)
  2583. if (!ADirView->ItemIsDirectory(Item) &&
  2584. (ResolvedSymlinks || FForceExecution))
  2585. {
  2586. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  2587. !FForceExecution &&
  2588. ResolvedSymlinks)
  2589. {
  2590. if (WinConfiguration->DoubleClickAction == dcaCopy)
  2591. {
  2592. ExecuteFileOperation(foCopy,
  2593. (ADirView == DirView(osRemote) ? osRemote : osLocal),
  2594. true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  2595. AllowExec = false;
  2596. }
  2597. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  2598. {
  2599. if (!Remote || !WinConfiguration->DisableOpenEdit)
  2600. {
  2601. ExecuteFile(osCurrent, efDefaultEditor);
  2602. AllowExec = false;
  2603. }
  2604. }
  2605. else
  2606. {
  2607. assert(false);
  2608. }
  2609. }
  2610. // if we have not done anything special, fall back to default behaviour
  2611. if (AllowExec)
  2612. {
  2613. if (Remote && !WinConfiguration->DisableOpenEdit)
  2614. {
  2615. ExecuteFile(osRemote, efShell);
  2616. AllowExec = false;
  2617. }
  2618. }
  2619. }
  2620. }
  2621. //---------------------------------------------------------------------------
  2622. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  2623. {
  2624. return ((Side == osRemote) || (Side == osCurrent));
  2625. }
  2626. //---------------------------------------------------------------------------
  2627. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  2628. {
  2629. assert(false);
  2630. }
  2631. //---------------------------------------------------------------------------
  2632. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  2633. {
  2634. assert(false);
  2635. }
  2636. //---------------------------------------------------------------------------
  2637. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  2638. AnsiString & LocalDirectory, AnsiString & RemoteDirectory)
  2639. {
  2640. TSynchronizeParamType Params;
  2641. Params.LocalDirectory = LocalDirectory;
  2642. Params.RemoteDirectory = RemoteDirectory;
  2643. int UnusedParams =
  2644. (GUIConfiguration->SynchronizeParams &
  2645. (spPreviewChanges | spTimestamp | spNotByTime | spBySize));
  2646. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  2647. Params.Options = GUIConfiguration->SynchronizeOptions;
  2648. bool SaveSettings = false;
  2649. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  2650. &DoSynchronizeTooManyDirectories);
  2651. assert(FSynchronizeController == NULL);
  2652. FSynchronizeController = &Controller;
  2653. bool Result;
  2654. try
  2655. {
  2656. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2657. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  2658. int Options =
  2659. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  2660. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  2661. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions);
  2662. if (Result)
  2663. {
  2664. if (SaveSettings)
  2665. {
  2666. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  2667. GUIConfiguration->SynchronizeOptions = Params.Options;
  2668. }
  2669. LocalDirectory = Params.LocalDirectory;
  2670. RemoteDirectory = Params.RemoteDirectory;
  2671. }
  2672. }
  2673. __finally
  2674. {
  2675. FSynchronizeController = NULL;
  2676. }
  2677. return Result;
  2678. }
  2679. //---------------------------------------------------------------------------
  2680. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  2681. TSynchronizeController * /*Sender*/, const AnsiString LocalDirectory,
  2682. const AnsiString RemoteDirectory, const TCopyParamType & CopyParam,
  2683. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  2684. TSynchronizeOptions * Options, bool Full)
  2685. {
  2686. try
  2687. {
  2688. int PParams = Params.Params;
  2689. if (!Full)
  2690. {
  2691. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache |
  2692. TTerminal::spDelayProgress | TTerminal::spSubDirs;
  2693. }
  2694. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  2695. PParams, Checklist, Options);
  2696. }
  2697. catch(Exception & E)
  2698. {
  2699. ShowExtendedExceptionEx(Terminal, &E);
  2700. throw;
  2701. }
  2702. }
  2703. //---------------------------------------------------------------------------
  2704. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  2705. TSynchronizeController * /*Sender*/, const AnsiString Directory,
  2706. const AnsiString ErrorStr)
  2707. {
  2708. if (!Directory.IsEmpty())
  2709. {
  2710. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  2711. }
  2712. else
  2713. {
  2714. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  2715. }
  2716. }
  2717. //---------------------------------------------------------------------------
  2718. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  2719. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  2720. {
  2721. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  2722. {
  2723. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  2724. }
  2725. else
  2726. {
  2727. TMessageParams Params(mpNeverAskAgainCheck);
  2728. int Result = MessageDialog(
  2729. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  2730. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  2731. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  2732. {
  2733. MaxDirectories *= 2;
  2734. if (Result == qaNeverAskAgain)
  2735. {
  2736. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  2737. }
  2738. }
  2739. else
  2740. {
  2741. Abort();
  2742. }
  2743. }
  2744. }
  2745. //---------------------------------------------------------------------------
  2746. void __fastcall TCustomScpExplorerForm::Synchronize(const AnsiString LocalDirectory,
  2747. const AnsiString RemoteDirectory, TSynchronizeMode Mode,
  2748. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  2749. TSynchronizeOptions * Options)
  2750. {
  2751. assert(!FAutoOperation);
  2752. void * BatchStorage;
  2753. BatchStart(BatchStorage);
  2754. FAutoOperation = true;
  2755. TSynchronizeChecklist * AChecklist = NULL;
  2756. try
  2757. {
  2758. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  2759. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  2760. {
  2761. FSynchronizeProgressForm->Start();
  2762. }
  2763. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  2764. static_cast<TTerminal::TSynchronizeMode>(Mode),
  2765. &CopyParam, Params | spNoConfirmation, TerminalSynchronizeDirectory,
  2766. Options);
  2767. SAFE_DESTROY(FSynchronizeProgressForm);
  2768. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, false);
  2769. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  2770. {
  2771. FSynchronizeProgressForm->Start();
  2772. }
  2773. Terminal->SynchronizeApply(AChecklist, LocalDirectory, RemoteDirectory,
  2774. &CopyParam, Params | spNoConfirmation, TerminalSynchronizeDirectory);
  2775. }
  2776. __finally
  2777. {
  2778. if (Checklist == NULL)
  2779. {
  2780. delete AChecklist;
  2781. }
  2782. else
  2783. {
  2784. *Checklist = AChecklist;
  2785. }
  2786. FAutoOperation = false;
  2787. SAFE_DESTROY(FSynchronizeProgressForm);
  2788. BatchEnd(BatchStorage);
  2789. ReloadLocalDirectory();
  2790. }
  2791. }
  2792. //---------------------------------------------------------------------------
  2793. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  2794. {
  2795. // can be called from command line
  2796. return Visible &&
  2797. ((DirView(osRemote)->SelCount > 0) ||
  2798. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  2799. }
  2800. //---------------------------------------------------------------------------
  2801. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  2802. int Params, TSynchronizeOptions & Options)
  2803. {
  2804. if (FLAGSET(Params, spSelectedOnly) && SynchronizeAllowSelectedOnly())
  2805. {
  2806. Options.Filter = new TStringList();
  2807. Options.Filter->CaseSensitive = false;
  2808. Options.Filter->Duplicates = dupAccept;
  2809. if (DirView(osRemote)->SelCount > 0)
  2810. {
  2811. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  2812. }
  2813. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  2814. {
  2815. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  2816. }
  2817. Options.Filter->Sort();
  2818. }
  2819. }
  2820. //---------------------------------------------------------------------------
  2821. bool __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  2822. AnsiString & LocalDirectory, AnsiString & RemoteDirectory,
  2823. TSynchronizeMode & Mode, bool & SaveMode)
  2824. {
  2825. bool Result;
  2826. int Params = GUIConfiguration->SynchronizeParams;
  2827. bool SaveSettings = false;
  2828. int Options =
  2829. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  2830. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  2831. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2832. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  2833. Result = DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  2834. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs);
  2835. if (Result)
  2836. {
  2837. TSynchronizeOptions SynchronizeOptions;
  2838. GetSynchronizeOptions(Params, SynchronizeOptions);
  2839. if (SaveSettings)
  2840. {
  2841. GUIConfiguration->SynchronizeParams = Params;
  2842. }
  2843. else
  2844. {
  2845. SaveMode = false;
  2846. }
  2847. TDateTime StartTime = Now();
  2848. TSynchronizeChecklist * Checklist = NULL;
  2849. try
  2850. {
  2851. assert(!FAutoOperation);
  2852. FAutoOperation = true;
  2853. try
  2854. {
  2855. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  2856. FSynchronizeProgressForm->Start();
  2857. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  2858. static_cast<TTerminal::TSynchronizeMode>(Mode),
  2859. &CopyParam, Params | spNoConfirmation, TerminalSynchronizeDirectory,
  2860. &SynchronizeOptions);
  2861. }
  2862. __finally
  2863. {
  2864. FAutoOperation = false;
  2865. SAFE_DESTROY(FSynchronizeProgressForm);
  2866. }
  2867. if (Checklist->Count == 0)
  2868. {
  2869. MessageDialog(LoadStr(COMPARE_NO_DIFFERENCES), qtInformation, qaOK,
  2870. HELP_SYNCHRONIZE_NO_DIFFERENCES);
  2871. }
  2872. else if (FLAGCLEAR(Params, spPreviewChanges) ||
  2873. DoSynchronizeChecklistDialog(Checklist, Mode, Params,
  2874. LocalDirectory, RemoteDirectory))
  2875. {
  2876. assert(!FAutoOperation);
  2877. void * BatchStorage;
  2878. BatchStart(BatchStorage);
  2879. FAutoOperation = true;
  2880. if (FLAGSET(Params, spPreviewChanges))
  2881. {
  2882. StartTime = Now();
  2883. }
  2884. try
  2885. {
  2886. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, false);
  2887. FSynchronizeProgressForm->Start();
  2888. Terminal->SynchronizeApply(Checklist, LocalDirectory, RemoteDirectory,
  2889. &CopyParam, Params | spNoConfirmation, TerminalSynchronizeDirectory);
  2890. }
  2891. __finally
  2892. {
  2893. FAutoOperation = false;
  2894. SAFE_DESTROY(FSynchronizeProgressForm);
  2895. BatchEnd(BatchStorage);
  2896. ReloadLocalDirectory();
  2897. }
  2898. }
  2899. }
  2900. __finally
  2901. {
  2902. delete Checklist;
  2903. }
  2904. OperationComplete(StartTime);
  2905. }
  2906. return Result;
  2907. }
  2908. //---------------------------------------------------------------------------
  2909. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  2910. const AnsiString LocalDirectory, const AnsiString RemoteDirectory, bool & Continue)
  2911. {
  2912. assert(FSynchronizeProgressForm != NULL);
  2913. if (!FSynchronizeProgressForm->Started)
  2914. {
  2915. FSynchronizeProgressForm->Start();
  2916. }
  2917. FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Continue);
  2918. }
  2919. //---------------------------------------------------------------------------
  2920. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  2921. {
  2922. assert(false);
  2923. }
  2924. //---------------------------------------------------------------------------
  2925. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  2926. {
  2927. AnsiString SessionName;
  2928. SessionName = Terminal->SessionData->SessionName;
  2929. SessionName = DoSaveSessionDialog(StoredSessions, SessionName);
  2930. if (!SessionName.IsEmpty())
  2931. {
  2932. TSessionData * SessionData = new TSessionData("");
  2933. try
  2934. {
  2935. SessionData->Assign(Terminal->SessionData);
  2936. UpdateSessionData(SessionData);
  2937. StoredSessions->NewSession(SessionName, SessionData);
  2938. StoredSessions->Save();
  2939. }
  2940. __finally
  2941. {
  2942. delete SessionData;
  2943. }
  2944. }
  2945. }
  2946. //---------------------------------------------------------------------------
  2947. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  2948. {
  2949. assert(Terminal && Terminal->SessionData);
  2950. if (!Data)
  2951. {
  2952. Data = Terminal->SessionData;
  2953. }
  2954. // cannot use RemoteDirView->Path, because it is empty if connection
  2955. // was already closed
  2956. Data->RemoteDirectory = Terminal->CurrentDirectory;
  2957. Data->Color = SessionColor;
  2958. }
  2959. //---------------------------------------------------------------------------
  2960. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  2961. {
  2962. CALLSTACK;
  2963. TTBXToolbar * ToolBar = dynamic_cast<TTBXToolbar*>(Sender);
  2964. assert(ToolBar != NULL);
  2965. if (ToolBar->Items->Count == 1)
  2966. {
  2967. TTBControlItem * Item = dynamic_cast<TTBControlItem *>(ToolBar->Items->Items[0]);
  2968. assert(Item != NULL);
  2969. // seems that Item->Control can be NULL when closing window
  2970. if (Item->Control != NULL)
  2971. {
  2972. Item->Control->Width = ToolBar->Width - ToolBar->NonClientWidth;
  2973. }
  2974. }
  2975. else
  2976. {
  2977. int ControlWidth;
  2978. TControl * ResizeControl = NULL;
  2979. TTBXComboBoxItem * ResizeComboBox = NULL;
  2980. for (int i = 0; i < ToolBar->Items->Count; i++)
  2981. {
  2982. TTBControlItem * ControlItem;
  2983. ControlItem = dynamic_cast<TTBControlItem *>(ToolBar->Items->Items[i]);
  2984. // seems that Item->Control can be NULL when closing window
  2985. if ((ControlItem != NULL) && (ControlItem->Control != NULL) &&
  2986. (ControlItem->Control->Tag != 0))
  2987. {
  2988. ResizeControl = ControlItem->Control;
  2989. ControlWidth = ResizeControl->Width;
  2990. break;
  2991. }
  2992. // currently never used
  2993. TTBXComboBoxItem * ComboBoxItem;
  2994. ComboBoxItem = dynamic_cast<TTBXComboBoxItem *>(ToolBar->Items->Items[i]);
  2995. if (ComboBoxItem != NULL)
  2996. {
  2997. ResizeComboBox = ComboBoxItem;
  2998. ControlWidth = ResizeComboBox->EditWidth;
  2999. break;
  3000. }
  3001. }
  3002. ControlWidth = ToolBar->Width - (ToolBar->View->BaseSize.x -
  3003. ControlWidth) - ToolBar->NonClientWidth;
  3004. if (ResizeControl != NULL)
  3005. {
  3006. ResizeControl->Width = ControlWidth;
  3007. }
  3008. // currently never used
  3009. if (ResizeComboBox != NULL)
  3010. {
  3011. ResizeComboBox->EditWidth = ControlWidth;
  3012. }
  3013. }
  3014. }
  3015. //---------------------------------------------------------------------------
  3016. void __fastcall TCustomScpExplorerForm::AddressToolbarGetBaseSize(
  3017. TTBCustomToolbar * Toolbar, TPoint & ASize)
  3018. {
  3019. CALLSTACK;
  3020. for (int i = 0; i < Toolbar->Items->Count; i++)
  3021. {
  3022. TTBControlItem * ControlItem;
  3023. ControlItem = dynamic_cast<TTBControlItem *>(Toolbar->Items->Items[i]);
  3024. if (ControlItem != NULL)
  3025. {
  3026. ASize.x = ASize.x - ControlItem->Control->Width +
  3027. ControlItem->Control->Constraints->MinWidth;
  3028. }
  3029. // currently never used
  3030. TTBXComboBoxItem * ComboBoxItem;
  3031. ComboBoxItem = dynamic_cast<TTBXComboBoxItem *>(Toolbar->Items->Items[i]);
  3032. if (ComboBoxItem != NULL)
  3033. {
  3034. ASize.x = ASize.x - ComboBoxItem->EditWidth + ComboBoxItem->Tag;
  3035. }
  3036. }
  3037. }
  3038. //---------------------------------------------------------------------------
  3039. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  3040. const AnsiString Path, __int64 RequiredSpace, bool & Continue)
  3041. {
  3042. if (WinConfiguration->DDWarnLackOfTempSpace)
  3043. {
  3044. AnsiString ADrive = ExtractFileDrive(ExpandFileName(Path));
  3045. if (!ADrive.IsEmpty())
  3046. {
  3047. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  3048. assert(RequiredSpace >= 0);
  3049. __int64 RequiredWithReserve;
  3050. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  3051. if (FreeSpace < RequiredWithReserve)
  3052. {
  3053. int Result;
  3054. TMessageParams Params(mpNeverAskAgainCheck);
  3055. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  3056. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  3057. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  3058. if (Result == qaNeverAskAgain)
  3059. {
  3060. WinConfiguration->DDWarnLackOfTempSpace = false;
  3061. }
  3062. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  3063. }
  3064. }
  3065. }
  3066. }
  3067. //---------------------------------------------------------------------------
  3068. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  3069. {
  3070. DoOpenDirectoryDialog(odAddBookmark, Side);
  3071. }
  3072. //---------------------------------------------------------------------------
  3073. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  3074. {
  3075. TStringList * VisitedDirectories = new TStringList();
  3076. try
  3077. {
  3078. TCustomDirView * DView = DirView(Side);
  3079. VisitedDirectories->Duplicates = dupIgnore;
  3080. // we should better use TCustomDirView::FCaseSensitive, but it is private
  3081. VisitedDirectories->CaseSensitive = (Side == osRemote);
  3082. VisitedDirectories->Sorted = true;
  3083. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  3084. {
  3085. VisitedDirectories->Add(DView->HistoryPath[Index]);
  3086. }
  3087. }
  3088. catch (...)
  3089. {
  3090. delete VisitedDirectories;
  3091. throw;
  3092. }
  3093. return VisitedDirectories;
  3094. }
  3095. //---------------------------------------------------------------------------
  3096. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  3097. TOpenDirectoryMode Mode, TOperationSide Side)
  3098. {
  3099. if (Mode != odAddBookmark ||
  3100. (MessageDialog(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)),
  3101. qtConfirmation, qaYes | qaNo, HELP_ADD_BOOKMARK_CONFIRM) == qaYes))
  3102. {
  3103. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  3104. try
  3105. {
  3106. AnsiString Name = DirView(Side)->PathName;
  3107. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  3108. HasDirView[osLocal]))
  3109. {
  3110. DirView(Side)->Path = Name;
  3111. }
  3112. }
  3113. __finally
  3114. {
  3115. delete VisitedDirectories;
  3116. }
  3117. }
  3118. }
  3119. //---------------------------------------------------------------------------
  3120. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  3121. {
  3122. bool Result = FTerminal->IsCapable[Capability] ||
  3123. FTerminal->CommandSessionOpened;
  3124. if (!Result)
  3125. {
  3126. if (!GUIConfiguration->ConfirmCommandSession)
  3127. {
  3128. Result = true;
  3129. }
  3130. else
  3131. {
  3132. TMessageParams Params(mpNeverAskAgainCheck);
  3133. int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION,
  3134. (Terminal->ProtocolName, Terminal->ProtocolName)), qtConfirmation,
  3135. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  3136. if (Answer == qaNeverAskAgain)
  3137. {
  3138. GUIConfiguration->ConfirmCommandSession = false;
  3139. Result = true;
  3140. }
  3141. else if (Answer == qaOK)
  3142. {
  3143. Result = true;
  3144. }
  3145. }
  3146. if (Result)
  3147. {
  3148. try
  3149. {
  3150. TTerminalManager::ConnectTerminal(FTerminal->CommandSession, false);
  3151. }
  3152. catch(Exception & E)
  3153. {
  3154. ShowExtendedExceptionEx(FTerminal->CommandSession, &E);
  3155. Result = false;
  3156. }
  3157. }
  3158. }
  3159. return Result;
  3160. }
  3161. //---------------------------------------------------------------------------
  3162. void __fastcall TCustomScpExplorerForm::OpenConsole(AnsiString Command)
  3163. {
  3164. if (EnsureCommandSessionFallback(fcAnyCommand))
  3165. {
  3166. DoConsoleDialog(Terminal, Command);
  3167. }
  3168. }
  3169. //---------------------------------------------------------------------------
  3170. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  3171. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  3172. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  3173. {
  3174. if (IsFileControl(DropSourceControl, osRemote) &&
  3175. (FDDExtMapFile != NULL))
  3176. {
  3177. Accept = true;
  3178. }
  3179. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  3180. assert(FDDTargetControl != NULL);
  3181. }
  3182. //---------------------------------------------------------------------------
  3183. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  3184. TObject *Sender)
  3185. {
  3186. USEDPARAM(Sender);
  3187. assert(FDDTargetControl == Sender);
  3188. FDDTargetControl = NULL;
  3189. }
  3190. //---------------------------------------------------------------------------
  3191. void __fastcall TCustomScpExplorerForm::AddEditLink(bool Add)
  3192. {
  3193. assert(FCurrentSide == osRemote);
  3194. bool Edit = false;
  3195. TRemoteFile * File = NULL;
  3196. AnsiString FileName;
  3197. AnsiString PointTo;
  3198. bool SymbolicLink = true;
  3199. if (RemoteDirView->ItemFocused)
  3200. {
  3201. assert(RemoteDirView->ItemFocused->Data);
  3202. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  3203. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  3204. if (Edit)
  3205. {
  3206. FileName = File->FileName;
  3207. PointTo = File->LinkTo;
  3208. }
  3209. else
  3210. {
  3211. PointTo = File->FileName;
  3212. }
  3213. }
  3214. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  3215. Terminal->IsCapable[fcHardLink]))
  3216. {
  3217. if (Edit)
  3218. {
  3219. assert(File->FileName == FileName);
  3220. bool Recursive = false;
  3221. Terminal->ExceptionOnFail = true;
  3222. try
  3223. {
  3224. Terminal->DeleteFile("", File, &Recursive);
  3225. }
  3226. __finally
  3227. {
  3228. Terminal->ExceptionOnFail = false;
  3229. }
  3230. }
  3231. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  3232. }
  3233. }
  3234. //---------------------------------------------------------------------------
  3235. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  3236. {
  3237. assert(!WinConfiguration->DisableOpenEdit);
  3238. FForceExecution = true;
  3239. try
  3240. {
  3241. DirView(osCurrent)->ExecuteCurrentFile();
  3242. }
  3243. __finally
  3244. {
  3245. FForceExecution = false;
  3246. }
  3247. }
  3248. //---------------------------------------------------------------------------
  3249. void __fastcall TCustomScpExplorerForm::TerminalClosed(TObject * Sender)
  3250. {
  3251. FEditorManager->ProcessFiles(FileTerminalClosed, Sender);
  3252. }
  3253. //---------------------------------------------------------------------------
  3254. void __fastcall TCustomScpExplorerForm::FileTerminalClosed(const AnsiString FileName,
  3255. TEditedFileData & Data, TObject * /*Token*/, void * Arg)
  3256. {
  3257. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  3258. assert(Terminal != NULL);
  3259. if (Data.Terminal == Terminal)
  3260. {
  3261. Data.Terminal = NULL;
  3262. }
  3263. }
  3264. //---------------------------------------------------------------------------
  3265. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  3266. {
  3267. try
  3268. {
  3269. NewSession();
  3270. }
  3271. __finally
  3272. {
  3273. if (!Terminal || !Terminal->Active)
  3274. {
  3275. Application->Terminate();
  3276. }
  3277. }
  3278. }
  3279. //---------------------------------------------------------------------------
  3280. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  3281. {
  3282. TTBXComboBoxItem * SessionCombo = dynamic_cast<TTBXComboBoxItem*>(
  3283. static_cast<TComponent*>(GetComponent(fcSessionCombo)));
  3284. if (SessionCombo != NULL)
  3285. {
  3286. SessionCombo->Strings = TTerminalManager::Instance()->TerminalList;
  3287. SessionCombo->ItemIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  3288. }
  3289. if ((TTerminalManager::Instance()->ActiveCount >= 2) &&
  3290. !WinConfiguration->SessionToolbarAutoShown &&
  3291. !ComponentVisible[fcSessionToolbar])
  3292. {
  3293. ComponentVisible[fcSessionToolbar] = true;
  3294. WinConfiguration->SessionToolbarAutoShown = true;
  3295. }
  3296. }
  3297. //---------------------------------------------------------------------------
  3298. void __fastcall TCustomScpExplorerForm::SessionComboPopup(TTBCustomItem * Sender,
  3299. bool /*FromLink*/)
  3300. {
  3301. TTBXComboBoxItem * SessionCombo = dynamic_cast<TTBXComboBoxItem *>(Sender);
  3302. assert(SessionCombo);
  3303. HDC DC = GetDC(0);
  3304. TCanvas * Canvas = new TCanvas();
  3305. try
  3306. {
  3307. Canvas->Handle = DC;
  3308. Canvas->Font = ToolbarFont;
  3309. int MaxWidth = 0, Width;
  3310. for (int i = 0; i < SessionCombo->Strings->Count; i++)
  3311. {
  3312. // TTBXComboBoxItem has no canvas, so we use Form's canvas
  3313. Width = Canvas->TextExtent(SessionCombo->Strings->Strings[i]).cx;
  3314. TShortCut ShortCut = NonVisualDataModule->OpenSessionShortCut(i);
  3315. if (ShortCut != scNone)
  3316. {
  3317. Width += Canvas->TextExtent(ShortCutToText(ShortCut) + " ").cx;
  3318. }
  3319. if (Width > MaxWidth)
  3320. {
  3321. MaxWidth = Width;
  3322. }
  3323. }
  3324. if (SessionCombo->Strings->Count > SessionCombo->MaxVisibleItems)
  3325. {
  3326. MaxWidth += GetSystemMetrics(SM_CXVSCROLL);
  3327. }
  3328. SessionCombo->MinListWidth = MaxWidth + 8 + 8 + 1;
  3329. }
  3330. __finally
  3331. {
  3332. Canvas->Handle = NULL;
  3333. ReleaseDC(0, DC);
  3334. delete Canvas;
  3335. }
  3336. }
  3337. //---------------------------------------------------------------------------
  3338. void __fastcall TCustomScpExplorerForm::SessionComboDrawItem(
  3339. TTBXCustomList * Sender, TCanvas * Canvas, const TRect & ARect, int Index,
  3340. int AHoverIndex, bool & DrawDefault)
  3341. {
  3342. TTBXStringList * SessionCombo = dynamic_cast<TTBXStringList *>(Sender);
  3343. assert(SessionCombo);
  3344. if (Index >= 0)
  3345. {
  3346. int ShortCutWidth = 0;
  3347. AnsiString ShortCutStr;
  3348. TShortCut ShortCut = NonVisualDataModule->OpenSessionShortCut(Index);
  3349. if (ShortCut != scNone)
  3350. {
  3351. ShortCutStr = " " + ShortCutToText(ShortCut);
  3352. ShortCutWidth = Canvas->TextExtent(ShortCutStr).cx;
  3353. }
  3354. if (Index != AHoverIndex)
  3355. {
  3356. TTerminal * Terminal =
  3357. dynamic_cast<TTerminal *>(SessionCombo->Strings->Objects[Index]);
  3358. assert(Terminal != NULL);
  3359. TColor Color =
  3360. TColor(Terminal == this->Terminal ? SessionColor : Terminal->SessionData->Color);
  3361. if (Color != 0)
  3362. {
  3363. Canvas->Brush->Color = Color;
  3364. Canvas->Brush->Style = bsSolid;
  3365. Canvas->FillRect(ARect);
  3366. }
  3367. }
  3368. TRect R = ARect;
  3369. InflateRect(&R, -4, 1);
  3370. R.Right -= ShortCutWidth + 2;
  3371. AnsiString S = SessionCombo->Strings->Strings[Index];
  3372. DrawText(Canvas->Handle, S.c_str(), S.Length(), &R,
  3373. DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX);
  3374. R = ARect;
  3375. InflateRect(&R, -4, 1);
  3376. R.Left = R.Right - ShortCutWidth;
  3377. DrawText(Canvas->Handle, ShortCutStr.c_str(), ShortCutStr.Length(), &R,
  3378. DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX);
  3379. }
  3380. DrawDefault = false;
  3381. }
  3382. //---------------------------------------------------------------------------
  3383. void __fastcall TCustomScpExplorerForm::SessionComboChange(TObject * Sender,
  3384. const AnsiString Text)
  3385. {
  3386. TTBXComboBoxItem * SessionCombo = dynamic_cast<TTBXComboBoxItem *>(Sender);
  3387. assert(SessionCombo);
  3388. TTerminal * Terminal;
  3389. Terminal = dynamic_cast<TTerminal *>(SessionCombo->Strings->Objects[SessionCombo->ItemIndex]);
  3390. assert(Terminal);
  3391. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  3392. }
  3393. //---------------------------------------------------------------------------
  3394. void __fastcall TCustomScpExplorerForm::TransferComboChange(TObject * Sender,
  3395. const AnsiString Text)
  3396. {
  3397. TTBXComboBoxItem * TransferCombo = dynamic_cast<TTBXComboBoxItem *>(Sender);
  3398. assert(TransferCombo != NULL);
  3399. AnsiString Name;
  3400. if (TransferCombo->ItemIndex <= 0)
  3401. {
  3402. Name = "";
  3403. }
  3404. else
  3405. {
  3406. Name = GUIConfiguration->CopyParamList->Names[TransferCombo->ItemIndex - 1];
  3407. }
  3408. if (FCopyParamAutoSelected.IsEmpty())
  3409. {
  3410. // if previous preset was not autoselected, make new preset the "default"
  3411. FCopyParamDefault = Name;
  3412. }
  3413. GUIConfiguration->CopyParamCurrent = Name;
  3414. }
  3415. //---------------------------------------------------------------------------
  3416. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  3417. {
  3418. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  3419. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  3420. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  3421. {
  3422. if (Command == _APPCOMMAND_BROWSER_FAVORITES)
  3423. {
  3424. OpenDirectory(GetSide(osCurrent));
  3425. Message.Result = 1;
  3426. }
  3427. else
  3428. {
  3429. TForm::Dispatch(&Message);
  3430. }
  3431. }
  3432. else
  3433. {
  3434. TForm::Dispatch(&Message);
  3435. }
  3436. }
  3437. //---------------------------------------------------------------------------
  3438. void __fastcall TCustomScpExplorerForm::CMAppSysCommand(TMessage & Message)
  3439. {
  3440. TWMSysCommand * SysCommand = (TWMSysCommand *)Message.LParam;
  3441. if (SysCommand->CmdType != SC_KEYMENU || !FIgnoreNextSysCommand)
  3442. {
  3443. FIgnoreNextSysCommand = false;
  3444. TForm::Dispatch(&Message);
  3445. }
  3446. else
  3447. {
  3448. Message.Result = 1;
  3449. }
  3450. }
  3451. //---------------------------------------------------------------------------
  3452. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  3453. {
  3454. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  3455. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  3456. // 61730 - restore thru double click - undocumented
  3457. // 61490 - maximize thru double click - undocumented
  3458. if ((Message.WParam == SC_RESTORE) || (Message.WParam == SC_MAXIMIZE) ||
  3459. (Message.WParam == SC_MINIMIZE) || (Message.WParam == SC_DEFAULT) ||
  3460. (Message.WParam == 61730) || (Message.WParam == 61490))
  3461. {
  3462. SysResizing(Message.WParam);
  3463. }
  3464. TForm::Dispatch(&Message);
  3465. }
  3466. //---------------------------------------------------------------------------
  3467. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  3468. {
  3469. }
  3470. //---------------------------------------------------------------------------
  3471. void __fastcall TCustomScpExplorerForm::DoShow()
  3472. {
  3473. CALLSTACK;
  3474. // only now are the controls resized finally, so the size constraints
  3475. // will not conflict with possibly very small window size
  3476. RestoreFormParams();
  3477. FixControlsPlacement();
  3478. if (Position == poDefaultPosOnly)
  3479. {
  3480. CutFormToDesktop(this);
  3481. }
  3482. TForm::DoShow();
  3483. }
  3484. //---------------------------------------------------------------------------
  3485. int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const AnsiString Message,
  3486. TStrings * MoreMessages, TQueryType Type, int Answers,
  3487. AnsiString HelpKeyword, const TMessageParams * Params)
  3488. {
  3489. if (WinConfiguration->ContinueOnError &&
  3490. (Params != NULL) && (Params->Params & mpAllowContinueOnError) &&
  3491. FErrorList)
  3492. {
  3493. TStringList * MoreMessagesCopy = NULL;
  3494. if (MoreMessages)
  3495. {
  3496. MoreMessagesCopy = new TStringList();
  3497. MoreMessagesCopy->Assign(MoreMessages);
  3498. }
  3499. FErrorList->AddObject(Message, MoreMessagesCopy);
  3500. if (Answers & qaSkip) return qaSkip;
  3501. else
  3502. if (Answers & qaIgnore) return qaIgnore;
  3503. else
  3504. if (Answers & qaOK) return qaOK;
  3505. else
  3506. if (Answers & qaYes) return qaYes;
  3507. else
  3508. if (Answers & qaRetry) return qaRetry;
  3509. else
  3510. {
  3511. assert(false);
  3512. return qaYes;
  3513. }
  3514. }
  3515. else
  3516. {
  3517. return ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  3518. }
  3519. }
  3520. //---------------------------------------------------------------------------
  3521. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  3522. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  3523. {
  3524. if (FDDExtMapFile != NULL)
  3525. {
  3526. CloseHandle(FDDExtMapFile);
  3527. FDDExtMapFile = NULL;
  3528. }
  3529. if (WinConfiguration->DDExtEnabled)
  3530. {
  3531. if (!WinConfiguration->DDExtInstalled)
  3532. {
  3533. throw Exception(LoadStr(DRAGEXT_TARGET_NOT_INSTALLED));
  3534. }
  3535. DDExtInitDrag(FileList, Created);
  3536. }
  3537. }
  3538. //---------------------------------------------------------------------------
  3539. void __fastcall TCustomScpExplorerForm::DDExtInitDrag(TFileList * FileList,
  3540. bool & Created)
  3541. {
  3542. FDragExtFakeDirectory =
  3543. ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  3544. if (!ForceDirectories(FDragExtFakeDirectory))
  3545. {
  3546. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (FDragExtFakeDirectory)));
  3547. }
  3548. FileList->AddItem(NULL, FDragExtFakeDirectory);
  3549. Created = true;
  3550. FDDExtMapFile = CreateFileMapping((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  3551. 0, sizeof(TDragExtCommStruct), DRAG_EXT_MAPPING);
  3552. {
  3553. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  3554. TDragExtCommStruct* CommStruct;
  3555. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  3556. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  3557. assert(CommStruct != NULL);
  3558. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  3559. CommStruct->Dragging = true;
  3560. strncpy(CommStruct->DropDest, FDragExtFakeDirectory.c_str(),
  3561. sizeof(CommStruct->DropDest));
  3562. CommStruct->DropDest[sizeof(CommStruct->DropDest) - 1] = '\0';
  3563. UnmapViewOfFile(CommStruct);
  3564. }
  3565. FDDMoveSlipped = false;
  3566. }
  3567. //---------------------------------------------------------------------------
  3568. void __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  3569. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  3570. {
  3571. if (Sender == RemoteDirView)
  3572. {
  3573. ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  3574. }
  3575. else
  3576. {
  3577. assert(Sender == RemoteDriveView);
  3578. TStrings * FileList = RemoteDriveView->DragFileList();
  3579. try
  3580. {
  3581. ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  3582. }
  3583. __finally
  3584. {
  3585. delete FileList;
  3586. }
  3587. }
  3588. if (FDDTargetControl == RemoteDriveView)
  3589. {
  3590. RemoteDriveView->UpdateDropTarget();
  3591. }
  3592. if ((Operation == foMove) && (DropSourceControl == RemoteDriveView))
  3593. {
  3594. RemoteDriveView->UpdateDropSource();
  3595. }
  3596. }
  3597. //---------------------------------------------------------------------------
  3598. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  3599. {
  3600. SAFE_DESTROY(FDDFileList);
  3601. if (FDDExtMapFile != NULL)
  3602. {
  3603. try
  3604. {
  3605. TDragResult DDResult = (Sender == RemoteDirView) ?
  3606. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  3607. if ((DDResult == drCopy) || (DDResult == drMove))
  3608. {
  3609. AnsiString TargetDirectory;
  3610. TFileOperation Operation;
  3611. Operation = (DDResult == drMove) ? foMove : foCopy;
  3612. if (FDDMoveSlipped)
  3613. {
  3614. Operation = foMove;
  3615. }
  3616. TTransferOperationParam Param;
  3617. DDGetTarget(Param.TargetDirectory);
  3618. // download using ddext
  3619. Param.Temp = false;
  3620. Param.DragDrop = true;
  3621. RemoteFileControlFileOperation(Sender, Operation,
  3622. !WinConfiguration->DDTransferConfirmation, &Param);
  3623. }
  3624. }
  3625. __finally
  3626. {
  3627. CloseHandle(FDDExtMapFile);
  3628. FDDExtMapFile = NULL;
  3629. RemoveDir(FDragExtFakeDirectory);
  3630. FDragExtFakeDirectory = "";
  3631. }
  3632. }
  3633. if (!FDragDropSshTerminate.IsEmpty())
  3634. {
  3635. throw ESshTerminate(NULL, FDragDropSshTerminate);
  3636. }
  3637. }
  3638. //---------------------------------------------------------------------------
  3639. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  3640. TObject * Sender, int dwEffect, HRESULT & /*Result*/)
  3641. {
  3642. HCURSOR SlippedCopyCursor;
  3643. FDDMoveSlipped =
  3644. (FDragMoveCursor != NULL) &&
  3645. (!WinConfiguration->DDAllowMoveInit) && (dwEffect == DROPEFFECT_Copy) &&
  3646. ((IsFileControl(FDDTargetControl, osRemote) && (GetKeyState(VK_CONTROL) >= 0)) ||
  3647. (IsFileControl(FDDTargetControl, osLocal) && (GetKeyState(VK_SHIFT) < 0)));
  3648. SlippedCopyCursor = FDDMoveSlipped ? FDragMoveCursor : Dragdrop::DefaultCursor;
  3649. DragDropFiles(Sender)->CHCopy = SlippedCopyCursor;
  3650. DragDropFiles(Sender)->CHScrollCopy = SlippedCopyCursor;
  3651. // Remember drop effect so we know (when user dropes files), if we copy or move
  3652. FLastDropEffect = dwEffect;
  3653. }
  3654. //---------------------------------------------------------------------------
  3655. void __fastcall TCustomScpExplorerForm::DDGetTarget(AnsiString & Directory)
  3656. {
  3657. bool Result = false;
  3658. Enabled = false;
  3659. try
  3660. {
  3661. int Timer = 0;
  3662. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  3663. {
  3664. {
  3665. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  3666. TDragExtCommStruct* CommStruct;
  3667. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  3668. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  3669. assert(CommStruct != NULL);
  3670. Result = !CommStruct->Dragging;
  3671. if (Result)
  3672. {
  3673. Directory = ExtractFilePath(CommStruct->DropDest);
  3674. }
  3675. UnmapViewOfFile(CommStruct);
  3676. }
  3677. if (!Result)
  3678. {
  3679. Sleep(50);
  3680. Timer += 50;
  3681. Application->ProcessMessages();
  3682. }
  3683. }
  3684. }
  3685. __finally
  3686. {
  3687. Enabled = true;
  3688. }
  3689. if (!Result)
  3690. {
  3691. throw Exception(LoadStr(DRAGEXT_TARGET_UNKNOWN));
  3692. }
  3693. }
  3694. //---------------------------------------------------------------------------
  3695. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  3696. const AnsiString TempDir, int SecDelay)
  3697. {
  3698. TDateTime Alarm = Now() + (double)SecDelay*(double(1)/24/60/60);
  3699. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  3700. if (FDelayedDeletionTimer == NULL)
  3701. {
  3702. assert(HandleAllocated());
  3703. FDelayedDeletionTimer = new TTimer(this);
  3704. FDelayedDeletionTimer->Interval = 10000;
  3705. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  3706. }
  3707. else
  3708. {
  3709. FDelayedDeletionTimer->Enabled = true;
  3710. }
  3711. }
  3712. //---------------------------------------------------------------------------
  3713. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  3714. {
  3715. assert(FDelayedDeletionList != NULL);
  3716. TDateTime N = Now();
  3717. TDateTime Alert;
  3718. AnsiString Directory;
  3719. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  3720. {
  3721. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  3722. if ((N >= Alert) || (Sender == NULL))
  3723. {
  3724. Directory = FDelayedDeletionList->Strings[Index];
  3725. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  3726. {
  3727. FDelayedDeletionList->Delete(Index);
  3728. }
  3729. }
  3730. }
  3731. if (FDelayedDeletionList->Count == 0)
  3732. {
  3733. FDelayedDeletionTimer->Enabled = false;
  3734. }
  3735. }
  3736. //---------------------------------------------------------------------------
  3737. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  3738. {
  3739. if (IsFileControl(FDDTargetControl, osRemote))
  3740. {
  3741. TTransferOperationParam Param;
  3742. Param.DragDrop = true;
  3743. // when move from remote side is disabled, we allow coying inside the remote
  3744. // panel, but we interpret is as moving (we also slip in the move cursor)
  3745. if ((FLastDropEffect == DROPEFFECT_MOVE) ||
  3746. (!WinConfiguration->DDAllowMoveInit && (FLastDropEffect == DROPEFFECT_COPY) &&
  3747. FDDMoveSlipped))
  3748. {
  3749. RemoteFileControlFileOperation(DropSourceControl,
  3750. foRemoteMove, !WinConfiguration->DDTransferConfirmation, &Param);
  3751. }
  3752. else if (FLastDropEffect == DROPEFFECT_COPY)
  3753. {
  3754. RemoteFileControlFileOperation(DropSourceControl,
  3755. foRemoteCopy, !WinConfiguration->DDTransferConfirmation, &Param);
  3756. }
  3757. // abort drag&drop
  3758. Abort();
  3759. }
  3760. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE))
  3761. {
  3762. assert(!FDragTempDir.IsEmpty());
  3763. TTransferType Type;
  3764. AnsiString TempDir = FDragTempDir;
  3765. // We clear FDragTempDir before calling
  3766. // just in case it fail (raises exception)
  3767. FDragTempDir = "";
  3768. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  3769. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  3770. // empty directory parameter means temp directory -> don't display it!
  3771. AnsiString TargetDir = "";
  3772. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  3773. TargetDir, CopyParams, WinConfiguration->DDTransferConfirmation, true))
  3774. {
  3775. Abort();
  3776. }
  3777. // TargetDir is set when dropped on local file control
  3778. // (this was workaround for legacy dirview event handling, now it should be
  3779. // made prettier)
  3780. if (TargetDir.IsEmpty())
  3781. {
  3782. TargetDir = TempDir;
  3783. if (ForceDirectories(TargetDir))
  3784. {
  3785. assert(Terminal && !TargetDir.IsEmpty());
  3786. // do not attempt to warn unless we know total transfer size
  3787. FPendingTempSpaceWarn = CopyParams.CalculateSize;
  3788. try
  3789. {
  3790. FDragDropOperation = true;
  3791. // cpNewerOnly has no efect here,
  3792. // as we download to empty temp directory
  3793. int Params = cpTemporary |
  3794. (Type == ttMove ? cpDelete : 0);
  3795. Terminal->CopyToLocal(FDDFileList, TargetDir, &CopyParams,
  3796. Params);
  3797. }
  3798. __finally
  3799. {
  3800. FDragDropOperation = false;
  3801. FPendingTempSpaceWarn = false;
  3802. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  3803. }
  3804. }
  3805. else
  3806. {
  3807. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  3808. }
  3809. }
  3810. }
  3811. }
  3812. //---------------------------------------------------------------------------
  3813. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  3814. {
  3815. public:
  3816. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  3817. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename)
  3818. {
  3819. }
  3820. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  3821. {
  3822. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  3823. TDataObjectFilesEx::AllowData(FormatEtc);
  3824. }
  3825. };
  3826. //---------------------------------------------------------------------------
  3827. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  3828. TObject * Sender, TDataObject *& DataObject)
  3829. {
  3830. if (FDDExtMapFile != NULL)
  3831. {
  3832. TFileList * FileList = DragDropFiles(Sender)->FileList;
  3833. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  3834. {
  3835. Abort();
  3836. }
  3837. if (FileList->Count > 0)
  3838. {
  3839. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  3840. if (!FilesObject->IsValid(true, true))
  3841. {
  3842. FilesObject->_Release();
  3843. }
  3844. else
  3845. {
  3846. DataObject = FilesObject;
  3847. }
  3848. }
  3849. }
  3850. }
  3851. //---------------------------------------------------------------------------
  3852. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  3853. {
  3854. assert(false);
  3855. }
  3856. //---------------------------------------------------------------------------
  3857. void __fastcall TCustomScpExplorerForm::GoToTree()
  3858. {
  3859. ComponentVisible[fcRemoteTree] = true;
  3860. RemoteDriveView->SetFocus();
  3861. }
  3862. //---------------------------------------------------------------------------
  3863. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  3864. TPanelExport Export, TPanelExportDestination Destination, bool OnFocused)
  3865. {
  3866. Side = GetSide(Side);
  3867. TCustomDirView * DirView = this->DirView(Side);
  3868. TStringList * ExportData = new TStringList();
  3869. try
  3870. {
  3871. switch (Export)
  3872. {
  3873. case pePath:
  3874. ExportData->Add(DirView->PathName);
  3875. break;
  3876. case peFileList:
  3877. case peFullFileList:
  3878. {
  3879. bool FullPath = (Export == peFullFileList);
  3880. DirView->CreateFileList(OnFocused, FullPath, ExportData);
  3881. AnsiString FileName;
  3882. for (int Index = 0; Index < ExportData->Count; Index++)
  3883. {
  3884. if (ExportData->Strings[Index].Pos(" ") > 0)
  3885. {
  3886. ExportData->Strings[Index] = FORMAT("\"%s\"", (ExportData->Strings[Index]));
  3887. }
  3888. }
  3889. }
  3890. break;
  3891. case peUrl:
  3892. {
  3893. assert(DirView == RemoteDirView);
  3894. DirView->CreateFileList(OnFocused, true, ExportData);
  3895. for (int Index = 0; Index < ExportData->Count; Index++)
  3896. {
  3897. ExportData->Strings[Index] =
  3898. FTerminal->FileUrl(ExportData->Strings[Index]);
  3899. }
  3900. }
  3901. break;
  3902. default:
  3903. assert(false);
  3904. }
  3905. PanelExportStore(Side, Export, Destination, ExportData);
  3906. }
  3907. __finally
  3908. {
  3909. delete ExportData;
  3910. }
  3911. }
  3912. //---------------------------------------------------------------------------
  3913. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  3914. TPanelExport /*Export*/, TPanelExportDestination Destination,
  3915. TStringList * ExportData)
  3916. {
  3917. if (Destination == pedClipboard)
  3918. {
  3919. CopyToClipboard(ExportData);
  3920. }
  3921. else
  3922. {
  3923. assert(false);
  3924. }
  3925. }
  3926. //---------------------------------------------------------------------------
  3927. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  3928. {
  3929. return FQueueController->DefaultOperation();
  3930. }
  3931. //---------------------------------------------------------------------------
  3932. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  3933. TQueueOperation Operation)
  3934. {
  3935. switch (Operation)
  3936. {
  3937. case qoPreferences:
  3938. return true;
  3939. case qoGoTo:
  3940. return ComponentVisible[fcQueueView];
  3941. case qoDisconnectOnceEmpty:
  3942. return !FQueueController->Empty;
  3943. default:
  3944. return FQueueController->AllowOperation(Operation);
  3945. }
  3946. }
  3947. //---------------------------------------------------------------------------
  3948. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  3949. TQueueOperation Operation)
  3950. {
  3951. if (Operation == qoGoTo)
  3952. {
  3953. assert(QueueView->Visible);
  3954. QueueView->SetFocus();
  3955. }
  3956. else if (Operation == qoPreferences)
  3957. {
  3958. PreferencesDialog(pmQueue);
  3959. }
  3960. else
  3961. {
  3962. FQueueController->ExecuteOperation(Operation);
  3963. }
  3964. }
  3965. //---------------------------------------------------------------------------
  3966. void __fastcall TCustomScpExplorerForm::QueueViewContextPopup(
  3967. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  3968. {
  3969. FQueueActedItem = QueueView->ItemFocused;
  3970. }
  3971. //---------------------------------------------------------------------------
  3972. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  3973. {
  3974. return TopDock->Height + QueueSplitter->Height;
  3975. }
  3976. //---------------------------------------------------------------------------
  3977. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  3978. TObject * /*Sender*/, int & NewSize, bool & Accept)
  3979. {
  3980. // when queue is hidden by double-clicking splitter, stray attempt to
  3981. // resize the panel with strange value arrives, make sure it is ignored
  3982. if (ComponentVisible[fcQueueView])
  3983. {
  3984. int HeightLimit = ClientHeight - GetStaticComponentsHeight() -
  3985. RemotePanel->Constraints->MinHeight;
  3986. if (NewSize > HeightLimit)
  3987. {
  3988. NewSize = HeightLimit;
  3989. }
  3990. }
  3991. else
  3992. {
  3993. Accept = false;
  3994. }
  3995. }
  3996. //---------------------------------------------------------------------------
  3997. void __fastcall TCustomScpExplorerForm::QueueViewStartDrag(TObject * /*Sender*/,
  3998. TDragObject *& /*DragObject*/)
  3999. {
  4000. FQueueActedItem = QueueView->ItemFocused;
  4001. }
  4002. //---------------------------------------------------------------------------
  4003. void __fastcall TCustomScpExplorerForm::QueueViewDragOver(TObject * /*Sender*/,
  4004. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  4005. {
  4006. Accept = true;
  4007. if (Source == QueueView)
  4008. {
  4009. TListItem * DropTarget = QueueView->GetItemAt(X, Y);
  4010. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  4011. if (Accept)
  4012. {
  4013. TQueueItemProxy * QueueItem;
  4014. TQueueItemProxy * DestQueueItem;
  4015. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  4016. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  4017. Accept = (QueueItem != DestQueueItem) &&
  4018. (QueueItem->Status == TQueueItem::qsPending) &&
  4019. (DestQueueItem->Status == TQueueItem::qsPending);
  4020. }
  4021. }
  4022. }
  4023. //---------------------------------------------------------------------------
  4024. void __fastcall TCustomScpExplorerForm::QueueViewDragDrop(TObject * /*Sender*/,
  4025. TObject * /*Source*/, int /*X*/, int /*Y*/)
  4026. {
  4027. if ((FQueueActedItem != NULL) && (QueueView->DropTarget != NULL))
  4028. {
  4029. TQueueItemProxy * QueueItem;
  4030. TQueueItemProxy * DestQueueItem;
  4031. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  4032. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView->DropTarget->Data);
  4033. QueueItem->Move(DestQueueItem);
  4034. }
  4035. }
  4036. //---------------------------------------------------------------------------
  4037. void __fastcall TCustomScpExplorerForm::QueueViewEnter(TObject * /*Sender*/)
  4038. {
  4039. if ((QueueView->ItemFocused == NULL) &&
  4040. (QueueView->Items->Count > 0))
  4041. {
  4042. QueueView->ItemFocused = QueueView->Items->Item[0];
  4043. }
  4044. }
  4045. //---------------------------------------------------------------------------
  4046. void __fastcall TCustomScpExplorerForm::QueueViewSelectItem(
  4047. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  4048. {
  4049. if (Selected)
  4050. {
  4051. NonVisualDataModule->UpdateNonVisibleActions();
  4052. }
  4053. }
  4054. //---------------------------------------------------------------------------
  4055. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  4056. {
  4057. TDragDropFilesEx * Result = NULL;
  4058. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  4059. if (DirView != NULL)
  4060. {
  4061. Result = DirView->DragDropFilesEx;
  4062. }
  4063. else
  4064. {
  4065. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  4066. if (DriveView != NULL)
  4067. {
  4068. Result = DriveView->DragDropFilesEx;
  4069. }
  4070. }
  4071. assert(Result != NULL);
  4072. return Result;
  4073. }
  4074. //---------------------------------------------------------------------------
  4075. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  4076. TObject * Sender, int Effect, AnsiString /*SourcePath*/,
  4077. AnsiString TargetPath, bool & /*DoOperation*/)
  4078. {
  4079. TFileOperation Operation;
  4080. switch (Effect)
  4081. {
  4082. case DROPEFFECT_MOVE:
  4083. Operation = foMove;
  4084. break;
  4085. case DROPEFFECT_COPY:
  4086. // occures on WinXP (reported by user)
  4087. default:
  4088. Operation = foCopy;
  4089. break;
  4090. };
  4091. TStrings * FileList = new TStringList();
  4092. try
  4093. {
  4094. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  4095. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  4096. {
  4097. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  4098. }
  4099. FDragDropOperation = true;
  4100. TTransferOperationParam Param;
  4101. Param.TargetDirectory = TargetPath;
  4102. // upload, no temp dirs
  4103. Param.Temp = false;
  4104. Param.DragDrop = true;
  4105. ExecuteFileOperation(Operation, osLocal, FileList,
  4106. !WinConfiguration->DDTransferConfirmation, &Param);
  4107. }
  4108. __finally
  4109. {
  4110. FDragDropOperation = false;
  4111. delete FileList;
  4112. }
  4113. }
  4114. //---------------------------------------------------------------------------
  4115. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  4116. TObject * Sender, int grfKeyState, int & dwEffect)
  4117. {
  4118. if ((DropSourceControl == RemoteDriveView) &&
  4119. (RemoteDriveView->DragNode == RemoteDriveView->DropTarget))
  4120. {
  4121. dwEffect = DROPEFFECT_None;
  4122. }
  4123. else if (IsFileControl(DropSourceControl, osRemote))
  4124. {
  4125. if (((Sender == RemoteDriveView) && (RemoteDriveView->DropTarget != NULL)) ||
  4126. ((Sender == RemoteDirView) &&
  4127. ((RemoteDirView->DropTarget != NULL) || (DropSourceControl != RemoteDirView))))
  4128. {
  4129. // Hack: when moving is disabled, we at least allow to accept copy
  4130. // but it should be interpreted as move
  4131. dwEffect =
  4132. (WinConfiguration->DDAllowMoveInit && FLAGCLEAR(grfKeyState, MK_CONTROL)) ?
  4133. DROPEFFECT_Move : DROPEFFECT_Copy;
  4134. }
  4135. else
  4136. {
  4137. dwEffect = DROPEFFECT_None;
  4138. }
  4139. }
  4140. }
  4141. //---------------------------------------------------------------------------
  4142. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  4143. TObject * Sender, TRemoteFile * File, AnsiString & FileName)
  4144. {
  4145. if (FDDTotalSize >= 0)
  4146. {
  4147. if (File->IsDirectory)
  4148. {
  4149. FDDTotalSize = -1;
  4150. }
  4151. else
  4152. {
  4153. FDDTotalSize += File->Size;
  4154. }
  4155. }
  4156. assert(!FDragTempDir.IsEmpty());
  4157. // TODO: this is quite ineffective
  4158. // TODO: what if invalid character replacement is disabled?
  4159. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  4160. AnsiString TransferFileName;
  4161. if (Sender == RemoteDriveView)
  4162. {
  4163. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  4164. }
  4165. else
  4166. {
  4167. TransferFileName = File->FileName;
  4168. }
  4169. FDDFileList->AddObject(TransferFileName, File);
  4170. }
  4171. //---------------------------------------------------------------------------
  4172. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  4173. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  4174. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  4175. {
  4176. FDDFileList = new TStringList();
  4177. FDragTempDir = WinConfiguration->TemporaryDir();
  4178. FDDTotalSize = 0;
  4179. FDragDropSshTerminate = "";
  4180. }
  4181. //---------------------------------------------------------------------------
  4182. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  4183. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  4184. HRESULT & Result)
  4185. {
  4186. if (Result == DRAGDROP_S_DROP)
  4187. {
  4188. try
  4189. {
  4190. GlobalDragImageList->HideDragImage();
  4191. try
  4192. {
  4193. RemoteFileControlDDTargetDrop();
  4194. }
  4195. catch(ESshTerminate & E)
  4196. {
  4197. assert(E.MoreMessages == NULL); // not supported
  4198. assert(!E.Message.IsEmpty());
  4199. FDragDropSshTerminate = E.Message;
  4200. }
  4201. }
  4202. catch (Exception &E)
  4203. {
  4204. // If downloading fails we need to cancel drag&drop, othwerwise
  4205. // Explorer shows error
  4206. // But by the way exception probably never reach this point as
  4207. // it's catched on way
  4208. Result = DRAGDROP_S_CANCEL;
  4209. assert(Terminal != NULL);
  4210. Terminal->DoShowExtendedException(&E);
  4211. }
  4212. }
  4213. }
  4214. //---------------------------------------------------------------------------
  4215. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  4216. TObject * /*Sender*/, AnsiString FileName, bool Directory, AnsiString Masks,
  4217. bool & Matches)
  4218. {
  4219. TFileMasks M(Masks);
  4220. Matches = M.Matches(FileName, Directory);
  4221. }
  4222. //---------------------------------------------------------------------------
  4223. void __fastcall TCustomScpExplorerForm::RemoteDirViewGetOverlay(
  4224. TObject * Sender, TListItem * Item, WORD & Indexes)
  4225. {
  4226. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  4227. AnsiString Ext;
  4228. if (DirView == RemoteDirView)
  4229. {
  4230. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  4231. }
  4232. else
  4233. {
  4234. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  4235. }
  4236. if (SameText(Ext, Configuration->PartialExt))
  4237. {
  4238. Indexes |= oiPartial;
  4239. }
  4240. }
  4241. //---------------------------------------------------------------------------
  4242. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  4243. {
  4244. return
  4245. IsFormatInClipboard(CF_TEXT) ||
  4246. DirView(osCurrent)->CanPasteFromClipBoard();
  4247. }
  4248. //---------------------------------------------------------------------------
  4249. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  4250. {
  4251. if (DirView(osCurrent)->CanPasteFromClipBoard())
  4252. {
  4253. DirView(osCurrent)->PasteFromClipBoard();
  4254. }
  4255. else
  4256. {
  4257. AnsiString Path;
  4258. if (TextFromClipboard(Path) && !Path.IsEmpty())
  4259. {
  4260. DirView(osCurrent)->Path = Path;
  4261. }
  4262. }
  4263. }
  4264. //---------------------------------------------------------------------------
  4265. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  4266. {
  4267. // TBD
  4268. }
  4269. //---------------------------------------------------------------------------
  4270. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  4271. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, int Panel)
  4272. {
  4273. AnsiString Text =
  4274. FMTLOAD(FILE_INFO_FORMAT,
  4275. (FormatBytes(FileInfo.SelectedSize),
  4276. FormatBytes(FileInfo.FilesSize),
  4277. FormatFloat("#,##0", FileInfo.SelectedCount),
  4278. FormatFloat("#,##0", FileInfo.FilesCount)));
  4279. if (StatusBar->SimplePanel)
  4280. {
  4281. assert(Panel == 0);
  4282. StatusBar->SimpleText = Text;
  4283. }
  4284. else
  4285. {
  4286. StatusBar->Panels->Items[Panel]->Caption = Text;
  4287. }
  4288. }
  4289. //---------------------------------------------------------------------------
  4290. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  4291. TObject * /*Sender*/)
  4292. {
  4293. RemoteDirView->SetFocus();
  4294. }
  4295. //---------------------------------------------------------------------------
  4296. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  4297. {
  4298. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  4299. switch (Config.Show)
  4300. {
  4301. case qvShow:
  4302. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  4303. {
  4304. Config.Show = qvHide;
  4305. }
  4306. else
  4307. {
  4308. Config.Show = Config.LastHideShow;
  4309. }
  4310. break;
  4311. case qvHideWhenEmpty:
  4312. if (ComponentVisible[fcQueueView])
  4313. {
  4314. Config.Show = qvHide;
  4315. }
  4316. else
  4317. {
  4318. Config.LastHideShow = Config.Show;
  4319. Config.Show = qvShow;
  4320. }
  4321. break;
  4322. case qvHide:
  4323. Config.LastHideShow = Config.Show;
  4324. Config.Show = qvShow;
  4325. break;
  4326. }
  4327. WinConfiguration->QueueView = Config;
  4328. }
  4329. //---------------------------------------------------------------------------
  4330. AnsiString __fastcall TCustomScpExplorerForm::PathForCaption()
  4331. {
  4332. AnsiString Result;
  4333. if (FTerminal != NULL)
  4334. {
  4335. switch (WinConfiguration->PathInCaption)
  4336. {
  4337. case picShort:
  4338. {
  4339. Result = UnixExtractFileName(FTerminal->CurrentDirectory);
  4340. if (Result.IsEmpty())
  4341. {
  4342. Result = FTerminal->CurrentDirectory;
  4343. }
  4344. }
  4345. break;
  4346. case picFull:
  4347. Result = FTerminal->CurrentDirectory;
  4348. break;
  4349. }
  4350. }
  4351. return Result;
  4352. }
  4353. //---------------------------------------------------------------------------
  4354. void __fastcall TCustomScpExplorerForm::UpdateControls()
  4355. {
  4356. // beware that app title can contain progress indicator that we do not want to
  4357. // see in window title. we rely here on fact that this should be never called
  4358. // during operation
  4359. Caption = TTerminalManager::Instance()->UpdateAppTitle();
  4360. RemoteDirView->Color = (FSessionColor != 0 ? FSessionColor : clWindow);
  4361. RemoteDriveView->Color = RemoteDirView->Color;
  4362. }
  4363. //---------------------------------------------------------------------------
  4364. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  4365. {
  4366. UpdateControls();
  4367. }
  4368. //---------------------------------------------------------------------------
  4369. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  4370. TObject * Sender)
  4371. {
  4372. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  4373. assert(DirView != NULL);
  4374. DoDirViewLoaded(DirView);
  4375. TransferPresetAutoSelect();
  4376. }
  4377. //---------------------------------------------------------------------------
  4378. void __fastcall TCustomScpExplorerForm::StartUpdates()
  4379. {
  4380. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  4381. // first run after installation
  4382. if (double(Updates.LastCheck) == 0)
  4383. {
  4384. // make sure next time there will be an update (if enabled)
  4385. Updates.LastCheck = TDateTime(1);
  4386. WinConfiguration->Updates = Updates;
  4387. }
  4388. else if ((double(Updates.Period) > 0) &&
  4389. (Now() - Updates.LastCheck >= Updates.Period))
  4390. {
  4391. StartUpdateThread();
  4392. }
  4393. }
  4394. //---------------------------------------------------------------------------
  4395. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  4396. TCopyParamRuleData & Data)
  4397. {
  4398. assert(Terminal != NULL);
  4399. Data.HostName = Terminal->SessionData->HostName;
  4400. Data.UserName = Terminal->SessionData->UserName;
  4401. Data.RemoteDirectory = RemoteDirView->PathName;
  4402. }
  4403. //---------------------------------------------------------------------------
  4404. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  4405. {
  4406. if (!FNoTransferPresetAutoSelect)
  4407. {
  4408. assert(Terminal != NULL);
  4409. TCopyParamRuleData Data;
  4410. GetTransferPresetAutoSelectData(Data);
  4411. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  4412. AnsiString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  4413. if (CopyParamIndex < 0)
  4414. {
  4415. // there is no preset that matches autoselection
  4416. // set preset that we consider "default"
  4417. FCopyParamAutoSelected = ""; // forget last autoselected preset
  4418. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  4419. }
  4420. else
  4421. {
  4422. // there is preset matching autoselection
  4423. AnsiString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  4424. if (CopyParamName == FCopyParamAutoSelected)
  4425. {
  4426. // autoselected the same preset as the last time
  4427. // make no change (i.e. preserve custom user preset, if any)
  4428. }
  4429. else
  4430. {
  4431. // autoselected the different preset then the last time (or there
  4432. // was default preset set)
  4433. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  4434. GUIConfiguration->CopyParamCurrent = CopyParamName;
  4435. }
  4436. }
  4437. if (WinConfiguration->CopyParamAutoSelectNotice &&
  4438. (GUIConfiguration->CopyParamCurrent != CopyParamCurrent))
  4439. {
  4440. int Fmt =
  4441. (CopyParamIndex < 0) ?
  4442. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  4443. COPY_PARAM_AUTOSELECTED;
  4444. TMessageParams Params(mpNeverAskAgainCheck);
  4445. TStrings * More = new TStringList();
  4446. try
  4447. {
  4448. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  4449. AnsiString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr("\n",
  4450. CopyParamAttrs);
  4451. if (CopyParamIndex >= 0)
  4452. {
  4453. assert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  4454. Info = FORMAT("%s\n \n%s", (Info,
  4455. FMTLOAD(COPY_PARAM_RULE,
  4456. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr("\n")))));
  4457. }
  4458. More->Text = Info;
  4459. if (MoreMessageDialog(FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent))),
  4460. More, qtInformation, qaOK, HELP_COPY_PARAM_AUTOSELECTED, &Params) ==
  4461. qaNeverAskAgain)
  4462. {
  4463. WinConfiguration->CopyParamAutoSelectNotice = false;
  4464. }
  4465. }
  4466. __finally
  4467. {
  4468. delete More;
  4469. }
  4470. }
  4471. }
  4472. }
  4473. //---------------------------------------------------------------------------
  4474. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  4475. TPreferencesMode APreferencesMode)
  4476. {
  4477. TCopyParamRuleData Data;
  4478. GetTransferPresetAutoSelectData(Data);
  4479. TPreferencesDialogData PreferencesData;
  4480. PreferencesData.CopyParamRuleData = &Data;
  4481. DoPreferencesDialog(APreferencesMode, &PreferencesData);
  4482. }
  4483. //---------------------------------------------------------------------------
  4484. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  4485. const AnsiString & Command, int Params)
  4486. {
  4487. if (CustomCommandState(Command, Params, FEditingFocusedAdHocCommand) <= 0)
  4488. {
  4489. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (Command)));
  4490. }
  4491. }
  4492. //---------------------------------------------------------------------------
  4493. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  4494. {
  4495. TCustomCommandParam Param;
  4496. Param.Params = 0;
  4497. Param.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  4498. FEditingFocusedAdHocCommand = OnFocused;
  4499. if (DoCustomCommandDialog(Param.Name, Param.Command, Param.Params,
  4500. WinConfiguration->CustomCommands, ccmAdHoc, AdHocCustomCommandValidate))
  4501. {
  4502. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Param);
  4503. }
  4504. }
  4505. //---------------------------------------------------------------------------
  4506. void __fastcall TCustomScpExplorerForm::WhatsThis()
  4507. {
  4508. SendMessage(Handle, WM_SYSCOMMAND, SC_CONTEXTHELP, 0);
  4509. }
  4510. //---------------------------------------------------------------------------
  4511. void __fastcall TCustomScpExplorerForm::BeforeAction()
  4512. {
  4513. if (RemoteDirView->ItemFocused != NULL)
  4514. {
  4515. RemoteDirView->ItemFocused->CancelEdit();
  4516. }
  4517. }
  4518. //---------------------------------------------------------------------------
  4519. void __fastcall TCustomScpExplorerForm::PostComponentHide(unsigned short Component)
  4520. {
  4521. assert(ComponentVisible[Component]);
  4522. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  4523. }
  4524. //---------------------------------------------------------------------------
  4525. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  4526. {
  4527. // when queue panel is resized here directly, the status bar is stretched
  4528. // over whole space the panel occupied
  4529. PostComponentHide(fcQueueView);
  4530. }
  4531. //---------------------------------------------------------------------------
  4532. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  4533. {
  4534. TMessage * M = static_cast<TMessage*>(Message);
  4535. switch (M->Msg)
  4536. {
  4537. case CM_APPSYSCOMMAND:
  4538. CMAppSysCommand(*M);
  4539. break;
  4540. case _WM_APPCOMMAND:
  4541. WMAppCommand(*M);
  4542. break;
  4543. case WM_SYSCOMMAND:
  4544. WMSysCommand(*M);
  4545. break;
  4546. case WM_COMPONENT_HIDE:
  4547. {
  4548. unsigned short Component = static_cast<unsigned short>(M->WParam);
  4549. // sanity check
  4550. if (ComponentVisible[Component])
  4551. {
  4552. // special treatment
  4553. if (Component == fcQueueView)
  4554. {
  4555. ToggleQueueVisibility();
  4556. assert(!ComponentVisible[fcQueueView]);
  4557. }
  4558. else
  4559. {
  4560. ComponentVisible[Component] = false;
  4561. }
  4562. }
  4563. }
  4564. break;
  4565. default:
  4566. TForm::Dispatch(Message);
  4567. break;
  4568. }
  4569. }
  4570. //---------------------------------------------------------------------------
  4571. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  4572. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  4573. int & MaxHeight)
  4574. {
  4575. // workaround for bug in TWinControl.CalcConstraints
  4576. // Check for empty rect (restore from iconinc state) is done there only after
  4577. // call to AdjustClientRect, which enlarges the rect (for forms).
  4578. TRect R = GetClientRect();
  4579. // when restoring from iconic state, place no restrictions
  4580. if (IsRectEmpty(R))
  4581. {
  4582. MinWidth = 0;
  4583. MinHeight = 0;
  4584. MaxWidth = 0;
  4585. MaxHeight = 0;
  4586. }
  4587. }
  4588. //---------------------------------------------------------------------------
  4589. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const AnsiString Path,
  4590. TSpaceAvailable & ASpaceAvailable, bool & Close)
  4591. {
  4592. // terminal can be already closed (e.g. dropped connection)
  4593. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  4594. {
  4595. try
  4596. {
  4597. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  4598. }
  4599. catch(...)
  4600. {
  4601. if (!Terminal->Active)
  4602. {
  4603. Close = true;
  4604. }
  4605. throw;
  4606. }
  4607. }
  4608. }
  4609. //---------------------------------------------------------------------------
  4610. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  4611. {
  4612. TFileSystemInfo FileSystemInfo;
  4613. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  4614. Terminal->FileSystemInfo(FileSystemInfo);
  4615. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  4616. {
  4617. OnGetSpaceAvailable = GetSpaceAvailable;
  4618. }
  4619. DoFileSystemInfoDialog(FileSystemInfo, Terminal->CurrentDirectory, OnGetSpaceAvailable);
  4620. }
  4621. //---------------------------------------------------------------------------
  4622. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  4623. {
  4624. if (value != FSessionColor)
  4625. {
  4626. FSessionColor = value;
  4627. TColor C = (value != 0 ? value : clNone);
  4628. TTBXColorPalette * ColorPalette = dynamic_cast<TTBXColorPalette *>(
  4629. static_cast<TObject *>(GetComponent(fcColorPalette)));
  4630. assert(ColorPalette != NULL);
  4631. ColorPalette->Color = C;
  4632. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  4633. static_cast<TObject *>(GetComponent(fcColorMenu)));
  4634. assert(ColorItem != NULL);
  4635. ColorItem->Color = C;
  4636. UpdateControls();
  4637. }
  4638. }
  4639. //---------------------------------------------------------------------------
  4640. void __fastcall TCustomScpExplorerForm::SessionColorPick()
  4641. {
  4642. TColorDialog * Dialog = new TColorDialog(this);
  4643. try
  4644. {
  4645. Dialog->Options = Dialog->Options << cdFullOpen;
  4646. Dialog->Color = (FSessionColor != 0 ? FSessionColor : clSkyBlue);
  4647. if (Dialog->Execute())
  4648. {
  4649. SessionColor = Dialog->Color;
  4650. }
  4651. }
  4652. __finally
  4653. {
  4654. delete Dialog;
  4655. }
  4656. }
  4657. //---------------------------------------------------------------------------
  4658. void __fastcall TCustomScpExplorerForm::SessionColorPaletteChange(
  4659. TObject * Sender)
  4660. {
  4661. TTBXColorPalette * ColorPalette = dynamic_cast<TTBXColorPalette *>(Sender);
  4662. assert(ColorPalette != NULL);
  4663. SessionColor = (ColorPalette->Color != clNone ? ColorPalette->Color : (TColor)0);
  4664. }
  4665. //---------------------------------------------------------------------------