1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Common.h"
- #include "WinConfiguration.h"
- #include "Exceptions.h"
- #include "Bookmarks.h"
- #include "Terminal.h"
- #include "TextsWin.h"
- #include "WinInterface.h"
- #include "GUITools.h"
- #include "Tools.h"
- #include "Setup.h"
- #include "Security.h"
- #include "TerminalManager.h"
- #include "Cryptography.h"
- #include <VCLCommon.h>
- #include <InitGUID.h>
- #include <DragExt.h>
- #include <Math.hpp>
- #include <StrUtils.hpp>
- #include <Generics.Defaults.hpp>
- #include <OperationWithTimeout.hpp>
- #include "FileInfo.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- //---------------------------------------------------------------------------
- TWinConfiguration * WinConfiguration = NULL;
- //---------------------------------------------------------------------------
- static UnicodeString NotepadName(L"notepad.exe");
- static UnicodeString ToolbarsLayoutKey(L"ToolbarsLayout2");
- static UnicodeString ToolbarsLayoutOldKey(L"ToolbarsLayout");
- //---------------------------------------------------------------------------
- static const wchar_t FileColorDataSeparator = L':';
- TFileColorData::TFileColorData() :
- Color(TColor())
- {
- }
- //---------------------------------------------------------------------------
- void TFileColorData::Load(const UnicodeString & S)
- {
- UnicodeString Buf(S);
- Color = RestoreColor(CutToChar(Buf, FileColorDataSeparator, true));
- FileMask = Buf;
- }
- //---------------------------------------------------------------------------
- UnicodeString TFileColorData::Save() const
- {
- UnicodeString Result = StoreColor(Color) + FileColorDataSeparator + FileMask.Masks;
- return Result;
- }
- //---------------------------------------------------------------------------
- void TFileColorData::LoadList(const UnicodeString & S, TList & List)
- {
- std::unique_ptr<TStringList> Strings(new TStringList());
- Strings->CommaText = S;
- List.clear();
- for (int Index = 0; Index < Strings->Count; Index++)
- {
- TFileColorData FileColorData;
- FileColorData.Load(Strings->Strings[Index]);
- List.push_back(FileColorData);
- }
- }
- //---------------------------------------------------------------------------
- UnicodeString TFileColorData::SaveList(const TList & List)
- {
- std::unique_ptr<TStringList> Strings(new TStringList());
- for (TFileColorData::TList::const_iterator Iter = List.begin(); Iter != List.end(); Iter++)
- {
- Strings->Add((*Iter).Save());
- }
- return Strings->CommaText;
- }
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------
- __fastcall TEditorData::TEditorData() :
- FileMask(AnyMask),
- Editor(edInternal),
- ExternalEditor(L""),
- ExternalEditorText(false),
- SDIExternalEditor(false),
- DetectMDIExternalEditor(false)
- {
- }
- //---------------------------------------------------------------------------
- __fastcall TEditorData::TEditorData(const TEditorData & Source) :
- FileMask(Source.FileMask),
- Editor(Source.Editor),
- ExternalEditor(Source.ExternalEditor),
- ExternalEditorText(Source.ExternalEditorText),
- SDIExternalEditor(Source.SDIExternalEditor),
- DetectMDIExternalEditor(Source.DetectMDIExternalEditor)
- {
- }
- //---------------------------------------------------------------------------
- #define C(Property) (Property == rhd.Property)
- bool __fastcall TEditorData::operator==(const TEditorData & rhd) const
- {
- return
- C(FileMask) &&
- C(Editor) &&
- C(ExternalEditor) &&
- C(ExternalEditorText) &&
- C(SDIExternalEditor) &&
- C(DetectMDIExternalEditor) &&
- true;
- }
- #undef C
- //---------------------------------------------------------------------------
- void __fastcall TEditorData::ExternalEditorOptionsAutodetect()
- {
- // By default we use default transfer mode (binary),
- // as all reasonable 3rd party editors support all EOL styles.
- // A notable exception is Windows Notepad, so here's an exception for it.
- // Notepad support unix line endings since Windows 10 1809. Once that's widespread, remove this.
- UnicodeString Command = ExternalEditor;
- ReformatFileNameCommand(Command);
- UnicodeString ProgramName = ExtractProgramName(Command);
- // We explicitly do not use TEditorPreferences::GetDefaultExternalEditor(),
- // as we need to explicitly refer to the Notepad, even if the default external
- // editor ever changes
- UnicodeString NotepadProgramName = ExtractProgramName(NotepadName);
- if (SameText(ProgramName, NotepadProgramName))
- {
- ExternalEditorText = true;
- SDIExternalEditor = true;
- }
- }
- //---------------------------------------------------------------------------
- __fastcall TEditorPreferences::TEditorPreferences()
- {
- }
- //---------------------------------------------------------------------------
- __fastcall TEditorPreferences::TEditorPreferences(const TEditorData & Data) :
- FData(Data)
- {
- }
- //---------------------------------------------------------------------------
- bool __fastcall TEditorPreferences::operator==(const TEditorPreferences & rhp) const
- {
- return (FData == rhp.FData);
- }
- #undef C
- //---------------------------------------------------------------------------
- bool __fastcall TEditorPreferences::Matches(const UnicodeString FileName,
- bool Local, const TFileMasks::TParams & Params) const
- {
- return FData.FileMask.Matches(FileName, Local, false, &Params);
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TEditorPreferences::GetDefaultExternalEditor()
- {
- return NotepadName;
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorPreferences::LegacyDefaults()
- {
- FData.ExternalEditor = GetDefaultExternalEditor();
- FData.ExternalEditorOptionsAutodetect();
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TEditorPreferences::ExtractExternalEditorName() const
- {
- DebugAssert(FData.Editor == edExternal);
- UnicodeString ExternalEditor = FData.ExternalEditor;
- ReformatFileNameCommand(ExternalEditor);
- // Trim is a workaround for unknown problem with "notepad " (2 trailing spaces)
- return ExtractProgramName(ExternalEditor).Trim();
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorPreferences::Load(THierarchicalStorage * Storage, bool Legacy)
- {
- if (!Legacy)
- {
- FData.FileMask = Storage->ReadString(L"FileMask", FData.FileMask.Masks);
- }
- FData.Editor = (TEditor)Storage->ReadInteger(L"Editor", FData.Editor);
- FData.ExternalEditor = Storage->ReadString(L"ExternalEditor", FData.ExternalEditor);
- FData.ExternalEditorText = Storage->ReadBool(L"ExternalEditorText", FData.ExternalEditorText);
- FData.SDIExternalEditor = Storage->ReadBool(L"SDIExternalEditor", FData.SDIExternalEditor);
- FData.DetectMDIExternalEditor = Storage->ReadBool(L"DetectMDIExternalEditor", FData.DetectMDIExternalEditor);
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorPreferences::Save(THierarchicalStorage * Storage) const
- {
- Storage->WriteString(L"FileMask", FData.FileMask.Masks);
- Storage->WriteInteger(L"Editor", FData.Editor);
- Storage->WriteString(L"ExternalEditor", FData.ExternalEditor);
- Storage->WriteBool(L"ExternalEditorText", FData.ExternalEditorText);
- Storage->WriteBool(L"SDIExternalEditor", FData.SDIExternalEditor);
- Storage->WriteBool(L"DetectMDIExternalEditor", FData.DetectMDIExternalEditor);
- }
- //---------------------------------------------------------------------------
- TEditorData * __fastcall TEditorPreferences::GetData()
- {
- // returning non-const data, possible data change, invalidate cached name
- FName = L"";
- return &FData;
- };
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TEditorPreferences::GetName() const
- {
- if (FName.IsEmpty())
- {
- if (FData.Editor == edInternal)
- {
- // StripHotkey is relic from times when INTERNAL_EDITOR_NAME was used
- // also for the menu item caption
- FName = StripHotkey(LoadStr(INTERNAL_EDITOR_NAME));
- }
- else if (FData.Editor == edOpen)
- {
- FName = StripHotkey(LoadStr(OPEN_EDITOR_NAME));
- }
- else
- {
- UnicodeString Program, Params, Dir;
- UnicodeString ExternalEditor = FData.ExternalEditor;
- ReformatFileNameCommand(ExternalEditor);
- SplitCommand(ExternalEditor, Program, Params, Dir);
- FName = ExtractFileName(Program);
- int P = FName.LastDelimiter(L".");
- if (P > 0)
- {
- FName.SetLength(P - 1);
- }
- if (FName.ByteType(1) == mbSingleByte)
- {
- if (FName.UpperCase() == FName)
- {
- FName = FName.LowerCase();
- }
- if (FName.LowerCase() == FName)
- {
- FName = FName.SubString(1, 1).UpperCase() +
- FName.SubString(2, FName.Length() - 1);
- }
- }
- }
- }
- return FName;
- }
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------
- __fastcall TEditorList::TEditorList()
- {
- Init();
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorList::Init()
- {
- FEditors = new TList();
- FModified = false;
- }
- //---------------------------------------------------------------------------
- __fastcall TEditorList::~TEditorList()
- {
- Clear();
- delete FEditors;
- }
- //---------------------------------------------------------------------
- void __fastcall TEditorList::Modify()
- {
- FModified = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorList::Saved()
- {
- FModified = false;
- }
- //---------------------------------------------------------------------------
- TEditorList & __fastcall TEditorList::operator=(const TEditorList & rhl)
- {
- Clear();
- for (int Index = 0; Index < rhl.Count; Index++)
- {
- Add(new TEditorPreferences(*rhl.Editors[Index]));
- }
- // there should be comparison of with the assigned list, but we rely on caller
- // to do it instead (TWinConfiguration::SetEditorList)
- Modify();
- return *this;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TEditorList::operator==(const TEditorList & rhl) const
- {
- bool Result = (Count == rhl.Count);
- if (Result)
- {
- int i = 0;
- while ((i < Count) && Result)
- {
- Result = (*Editors[i]) == (*rhl.Editors[i]);
- i++;
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorList::Clear()
- {
- for (int i = 0; i < Count; i++)
- {
- delete Editors[i];
- }
- FEditors->Clear();
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorList::Add(TEditorPreferences * Editor)
- {
- Insert(Count, Editor);
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorList::Insert(int Index, TEditorPreferences * Editor)
- {
- FEditors->Insert(Index, reinterpret_cast<TObject *>(Editor));
- Modify();
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorList::Change(int Index, TEditorPreferences * Editor)
- {
- if (!((*Editors[Index]) == *Editor))
- {
- delete Editors[Index];
- FEditors->Items[Index] = (reinterpret_cast<TObject *>(Editor));
- Modify();
- }
- else
- {
- delete Editor;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorList::Move(int CurIndex, int NewIndex)
- {
- if (CurIndex != NewIndex)
- {
- FEditors->Move(CurIndex, NewIndex);
- Modify();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorList::Delete(int Index)
- {
- DebugAssert((Index >= 0) && (Index < Count));
- delete Editors[Index];
- FEditors->Delete(Index);
- Modify();
- }
- //---------------------------------------------------------------------------
- const TEditorPreferences * __fastcall TEditorList::Find(
- const UnicodeString FileName, bool Local, const TFileMasks::TParams & Params) const
- {
- const TEditorPreferences * Result = NULL;
- int i = 0;
- while ((i < FEditors->Count) && (Result == NULL))
- {
- Result = Editors[i];
- if (!Result->Matches(FileName, Local, Params))
- {
- Result = NULL;
- }
- i++;
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorList::Load(THierarchicalStorage * Storage)
- {
- int Index = 0;
- bool Next;
- do
- {
- UnicodeString Name = IntToStr(Index);
- TEditorPreferences * Editor = NULL;
- try
- {
- Next = Storage->OpenSubKey(Name, false);
- if (Next)
- {
- try
- {
- Editor = new TEditorPreferences();
- Editor->Load(Storage, false);
- }
- __finally
- {
- Storage->CloseSubKey();
- }
- }
- }
- catch(...)
- {
- delete Editor;
- throw;
- }
- if (Editor != NULL)
- {
- FEditors->Add(reinterpret_cast<TObject *>(Editor));
- }
- Index++;
- }
- while (Next);
- FModified = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TEditorList::Save(THierarchicalStorage * Storage) const
- {
- Storage->ClearSubKeys();
- for (int Index = 0; Index < Count; Index++)
- {
- if (Storage->OpenSubKey(IntToStr(Index), true))
- {
- try
- {
- Editors[Index]->Save(Storage);
- }
- __finally
- {
- Storage->CloseSubKey();
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- int __fastcall TEditorList::GetCount() const
- {
- int X = FEditors->Count;
- return X;
- }
- //---------------------------------------------------------------------------
- const TEditorPreferences * __fastcall TEditorList::GetEditor(int Index) const
- {
- return reinterpret_cast<TEditorPreferences *>(FEditors->Items[Index]);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TEditorList::IsDefaultList() const
- {
- bool Result = true;
- for (int Index = 0; Result && (Index < Count); Index++)
- {
- const TEditorPreferences * Editor = GetEditor(Index);
- if (Editor->Data->Editor == edInternal)
- {
- // noop (keeps Result true)
- }
- else if (Editor->Data->Editor == edExternal)
- {
- UnicodeString ExternalEditor = Editor->ExtractExternalEditorName();
- UnicodeString DefaultExternalEditor = ExtractProgramName(TEditorPreferences::GetDefaultExternalEditor());
- Result = SameText(ExternalEditor, DefaultExternalEditor);
- }
- else
- {
- Result = false;
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------
- __fastcall TWinConfiguration::TWinConfiguration(): TCustomWinConfiguration()
- {
- ResetSysDarkTheme();
- FInvalidDefaultTranslationMessage = L"";
- FDDExtInstalled = -1;
- FBookmarks = new TBookmarks();
- FCustomCommandList = new TCustomCommandList();
- FExtensionList = new TCustomCommandList();
- FEditorList = new TEditorList();
- FDefaultUpdatesPeriod = 0;
- FDontDecryptPasswords = 0;
- FMasterPasswordSession = 0;
- FMasterPasswordSessionAsked = false;
- FCustomCommandOptions.reset(new TStringList());
- FCustomCommandOptionsModified = false;
- FExtensionTranslations.reset(new TStringList());
- Default();
- // This matters only if the translations are in the executable folder and auto-loaded by VCL (System.Pas - DelayLoadResourceModule)
- try
- {
- UnicodeString ResourceModuleName = GetResourceModuleName(Application->Name, ModuleFileName().c_str());
- CheckTranslationVersion(ResourceModuleName, true);
- }
- catch(Exception & E)
- {
- FInvalidDefaultTranslationMessage = E.Message;
- }
- // Load complete locale according to the UI language
- SetLocaleInternal(NULL, true, true);
- FDefaultLocale = AppliedLocale;
- }
- //---------------------------------------------------------------------------
- __fastcall TWinConfiguration::~TWinConfiguration()
- {
- if (!FTemporarySessionFile.IsEmpty()) DeleteFile(ApiPath(FTemporarySessionFile));
- ClearTemporaryLoginData();
- ReleaseExtensionTranslations();
- delete FBookmarks;
- delete FCustomCommandList;
- delete FExtensionList;
- delete FEditorList;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::Default()
- {
- FCustomCommandsDefaults = true;
- FCustomCommandOptionsModified = false;
- TCustomWinConfiguration::Default();
- int WorkAreaWidthScaled = DimensionToDefaultPixelsPerInch(Screen->WorkAreaWidth);
- int WorkAreaHeightScaled = DimensionToDefaultPixelsPerInch(Screen->WorkAreaHeight);
- UnicodeString PixelsPerInchToolbarValue = "PixelsPerInch=" + SaveDefaultPixelsPerInch();
- FDDTransferConfirmation = asAuto;
- FDDTemporaryDirectory = L"";
- FDDDrives = L"";
- FDDWarnLackOfTempSpace = true;
- FDDWarnLackOfTempSpaceRatio = 1.1;
- FDDFakeFile = true;
- FDDExtTimeout = MSecsPerSec;
- FDeleteToRecycleBin = true;
- FSelectDirectories = false;
- FSelectMask = AnyMask;
- FShowHiddenFiles = false;
- FFormatSizeBytes = fbKilobytes;
- FPanelSearch = isNameStartOnly;
- FShowInaccesibleDirectories = true;
- FConfirmTransferring = true;
- FConfirmDeleting = true;
- FConfirmRecycling = true;
- FConfirmClosingSession = true;
- FDoubleClickAction = dcaEdit;
- FCopyOnDoubleClickConfirmation = false;
- FDimmHiddenFiles = true;
- FRenameWholeName = false;
- FAutoStartSession = L"";
- FExpertMode = true;
- FUseLocationProfiles = false;
- FUseSharedBookmarks = false;
- FDefaultDirIsHome = true;
- FDDDeleteDelay = 120;
- FTemporaryDirectoryAppendSession = false;
- FTemporaryDirectoryDeterministic = false;
- FTemporaryDirectoryAppendPath = true;
- FTemporaryDirectoryCleanup = true;
- FConfirmTemporaryDirectoryCleanup = true;
- FPreservePanelState = true;
- FDarkTheme = asAuto;
- FLastStoredSession = L"";
- // deliberately not being saved, so that when saving ad-hoc workspace,
- // we do not offer to overwrite the last saved workspace, what may be undesirable
- FLastWorkspace = L"";
- FAutoSaveWorkspace = false;
- FAutoSaveWorkspacePasswords = false;
- FAutoWorkspace = L"";
- FPathInCaption = picShort;
- FSessionTabNameFormat = stnfShortPathTrunc;
- FMinimizeToTray = false;
- FBalloonNotifications = true;
- FNotificationsTimeout = 10;
- FNotificationsStickTime = 2;
- FCopyParamAutoSelectNotice = true;
- FLockToolbars = false;
- FSelectiveToolbarText = true;
- FAutoOpenInPutty = false;
- FRefreshRemotePanel = false;
- FRefreshRemotePanelInterval = TDateTime(0, 1, 0, 0);
- FPanelFont.FontName = L"";
- FPanelFont.FontSize = 0;
- FPanelFont.FontStyle = 0;
- FPanelFont.FontCharset = DEFAULT_CHARSET;
- FNaturalOrderNumericalSorting = true;
- FFullRowSelect = false;
- FOfferedEditorAutoConfig = false;
- FVersionHistory = L"";
- AddVersionToHistory();
- FUseMasterPassword = false;
- FPlainMasterPasswordEncrypt = L"";
- FPlainMasterPasswordDecrypt = L"";
- FMasterPasswordVerifier = L"";
- FOpenedStoredSessionFolders = L"";
- FAutoImportedFromPuttyOrFilezilla = false;
- FGenerateUrlComponents = -1;
- FGenerateUrlCodeTarget = guctUrl;
- FGenerateUrlScriptFormat = sfScriptFile;
- FGenerateUrlAssemblyLanguage = alCSharp;
- FExternalSessionInExistingInstance = true;
- FShowLoginWhenNoSession = true;
- FKeepOpenWhenNoSession = true;
- FLocalIconsByExt = false;
- FBidiModeOverride = lfoLanguageIfRecommended;
- FFlipChildrenOverride = lfoLanguageIfRecommended;
- FShowTips = true;
- FTipsSeen = L"";
- FTipsShown = Now();
- FFileColors = L"";
- FRunsSinceLastTip = 0;
- FExtensionsDeleted = L"";
- FLockedInterface = false;
- HonorDrivePolicy = true;
- TimeoutShellOperations = true;
- TimeoutShellIconRetrieval = false;
- UseIconUpdateThread = true;
- AllowWindowPrint = false;
- FEditor.Font.FontName = DefaultFixedWidthFontName;
- FEditor.Font.FontSize = DefaultFixedWidthFontSize;
- FEditor.Font.FontStyle = 0;
- FEditor.Font.FontCharset = DEFAULT_CHARSET;
- FEditor.FontColor = TColor(0);
- FEditor.BackgroundColor = TColor(0);
- FEditor.WordWrap = false;
- FEditor.FindText = L"";
- FEditor.ReplaceText = L"";
- FEditor.FindMatchCase = false;
- FEditor.FindWholeWord = false;
- FEditor.FindDown = true;
- FEditor.TabSize = 8;
- FEditor.MaxEditors = 500;
- FEditor.EarlyClose = 2; // seconds
- FEditor.SDIShellEditor = false;
- FEditor.WindowParams = L"";
- FEditor.Encoding = CP_ACP;
- FEditor.WarnOnEncodingFallback = true;
- FEditor.WarnOrLargeFileSize = true;
- FQueueView.Height = 140;
- FQueueView.HeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
- // with 1000 pixels wide screen, both interfaces are wide enough to fit wider queue
- FQueueView.Layout =
- UnicodeString((WorkAreaWidthScaled > 1000) ? L"70,250,250,80,80,80,100" : L"70,160,160,80,80,80,100") +
- // WORKAROUND (the comma), see GetListViewStr
- L",;" + SaveDefaultPixelsPerInch();
- FQueueView.Show = qvHideWhenEmpty;
- FQueueView.LastHideShow = qvHideWhenEmpty;
- FQueueView.ToolBar = true;
- FQueueView.Label = true;
- FEnableQueueByDefault = true;
- FUpdates.Period = FDefaultUpdatesPeriod;
- FUpdates.LastCheck = 0;
- FUpdates.HaveResults = false;
- FUpdates.ShownResults = false;
- FUpdates.BetaVersions = asAuto;
- FUpdates.ShowOnStartup = true;
- FUpdates.AuthenticationEmail = L"";
- // for backward compatibility the default is decided based on value of ProxyHost
- FUpdates.ConnectionType = (TConnectionType)-1;
- FUpdates.ProxyHost = L""; // keep empty (see above)
- FUpdates.ProxyPort = 8080;
- FUpdates.Results.Reset();
- FUpdates.DotNetVersion = L"";
- FUpdates.ConsoleVersion = L"";
- int ExplorerWidth = Min(WorkAreaWidthScaled - 40, 960);
- int ExplorerHeight = Min(WorkAreaHeightScaled - 30, 720);
- FScpExplorer.WindowParams = FormatDefaultWindowParams(ExplorerWidth, ExplorerHeight);
- // WORKAROUND (the semicolon, see TCustomListViewColProperties.GetParamsStr, and see other instances below)
- FScpExplorer.DirViewParams = L"0;1;0|150,1;70,1;150,1;79,1;62,1;55,0;20,0;150,0;125,0;@" + SaveDefaultPixelsPerInch() + L"|6;7;8;0;1;2;3;4;5";
- FScpExplorer.ToolbarsLayout =
- UnicodeString(
- L"Queue=1::0+-1,"
- "Menu=1:TopDock:0+0,"
- "Buttons=1:TopDock:2+0,"
- "Selection=0:TopDock:3+0,"
- "Session=0:TopDock:6+0,"
- "Preferences=1:TopDock:4+0,"
- "Sort=0:TopDock:5+0,"
- "Address=1:TopDock:1+0,"
- "Updates=1:TopDock:4+416,"
- "Transfer=1:TopDock:4+194,"
- "CustomCommands=0:TopDock:7+0,") +
- PixelsPerInchToolbarValue;
- FScpExplorer.ToolbarsButtons = UnicodeString();
- FScpExplorer.SessionsTabs = true;
- FScpExplorer.StatusBar = true;
- FScpExplorer.LastLocalTargetDirectory = GetPersonalFolder();
- FScpExplorer.ViewStyle = 0; /* vsIcon */
- FScpExplorer.ShowFullAddress = true;
- FScpExplorer.DriveView = true;
- FScpExplorer.DriveViewWidth = 180;
- FScpExplorer.DriveViewWidthPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
- int CommanderWidth = Min(WorkAreaWidthScaled - 40, 1090);
- int CommanderHeight = Min(WorkAreaHeightScaled - 30, 700);
- FScpCommander.WindowParams = FormatDefaultWindowParams(CommanderWidth, CommanderHeight);
- FScpCommander.LocalPanelWidth = 0.5;
- FScpCommander.SwappedPanels = false;
- FScpCommander.SessionsTabs = true;
- FScpCommander.StatusBar = true;
- FScpCommander.NortonLikeMode = nlKeyboard;
- FScpCommander.PreserveLocalDirectory = false;
- FScpCommander.ToolbarsLayout =
- UnicodeString(
- L"Queue=1::0+-1,"
- "Menu=1:TopDock:0+0,"
- "Preferences=1:TopDock:1+228,"
- "Session=0:TopDock:1+602,"
- "Sort=0:TopDock:2+0,"
- "Commands=1:TopDock:1+0,"
- "Updates=1:TopDock:1+619,"
- "Transfer=1:TopDock:1+364,"
- "CustomCommands=0:TopDock:3+0,"
- "RemoteHistory=1:RemoteTopDock:0+172,"
- "RemoteNavigation=1:RemoteTopDock:0+252,"
- "RemotePath=1:RemoteTopDock:0+0,"
- "RemoteFile=1:RemoteTopDock:1+0,"
- "RemoteSelection=1:RemoteTopDock:1+345,"
- "LocalHistory=1:LocalTopDock:0+207,"
- "LocalNavigation=1:LocalTopDock:0+287,"
- "LocalPath=1:LocalTopDock:0+0,"
- "LocalFile=1:LocalTopDock:1+0,"
- "LocalSelection=1:LocalTopDock:1+329,"
- "Toolbar2=0:BottomDock:1+0,"
- "CommandLine=0:BottomDock:0+0,") +
- PixelsPerInchToolbarValue;
- FScpCommander.ToolbarsButtons = UnicodeString();
- FScpCommander.CurrentPanel = osLocal;
- FScpCommander.CompareByTime = true;
- FScpCommander.CompareBySize = false;
- FScpCommander.TreeOnLeft = false;
- FScpCommander.ExplorerKeyboardShortcuts = false;
- FScpCommander.SystemContextMenu = false;
- FScpCommander.RemotePanel.DirViewParams = L"0;1;0|150,1;70,1;150,1;79,1;62,1;55,0;20,0;150,0;125,0;@" + SaveDefaultPixelsPerInch() + L"|6;7;8;0;1;2;3;4;5";
- FScpCommander.RemotePanel.StatusBar = true;
- FScpCommander.RemotePanel.DriveView = false;
- FScpCommander.RemotePanel.DriveViewHeight = 100;
- FScpCommander.RemotePanel.DriveViewHeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
- FScpCommander.RemotePanel.DriveViewWidth = 100;
- FScpCommander.RemotePanel.DriveViewWidthPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
- FScpCommander.RemotePanel.LastPath = UnicodeString();
- FScpCommander.LocalPanel.DirViewParams = L"0;1;0|150,1;70,1;120,1;150,1;55,0;55,0;@" + SaveDefaultPixelsPerInch() + L"|5;0;1;2;3;4";
- FScpCommander.LocalPanel.StatusBar = true;
- FScpCommander.LocalPanel.DriveView = false;
- FScpCommander.LocalPanel.DriveViewHeight = 100;
- FScpCommander.LocalPanel.DriveViewHeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
- FScpCommander.LocalPanel.DriveViewWidth = 100;
- FScpCommander.LocalPanel.DriveViewWidthPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
- FScpCommander.LocalPanel.LastPath = UnicodeString();
- FBookmarks->Clear();
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::DefaultLocalized()
- {
- TGUIConfiguration::DefaultLocalized();
- if (FCustomCommandsDefaults)
- {
- FCustomCommandList->Clear();
- FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_EXECUTE), L"\"./!\"", 0);
- FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_TOUCH), L"touch \"!\"", ccApplyToDirectories | ccRecursive);
- FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_TAR),
- FORMAT(L"tar -cz -f \"!?%s?archive.tgz!\" !&",
- (LoadStr(CUSTOM_COMMAND_TAR_ARCHIVE))), ccApplyToDirectories);
- FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_UNTAR),
- FORMAT(L"tar -xz --directory=\"!?%s?.!\" -f \"!\"",
- (LoadStr(CUSTOM_COMMAND_UNTAR_DIRECTORY))), 0);
- FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_GREP),
- FORMAT(L"grep \"!?%s?!\" !&", (LoadStr(CUSTOM_COMMAND_GREP_PATTERN))),
- ccShowResults);
- FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_PRINT), L"notepad.exe /p \"!\"", ccLocal);
- FCustomCommandList->Reset();
- FCustomCommandsDefaults = true;
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::DetectRegistryStorage(HKEY RootKey)
- {
- bool Result = false;
- TRegistryStorage * Storage = new TRegistryStorage(RegistryStorageKey, RootKey);
- try
- {
- if (Storage->OpenRootKey(false))
- {
- Result = true;
- Storage->CloseSubKey();
- }
- }
- __finally
- {
- delete Storage;
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::CanWriteToStorage()
- {
- bool Result = false;
- try
- {
- THierarchicalStorage * Storage = CreateConfigStorage();
- try
- {
- Storage->AccessMode = smReadWrite;
- // This is actually not very good test, as we end up potentially with
- // the very same config, and TIniFileStorage file won't even try to
- // write the file then. Luckily, we use this for empty config only,
- // so we end up with at least an empty section.
- if (Storage->OpenSubKey(ConfigurationSubKey, true))
- {
- Storage->WriteBool(L"WriteTest", true);
- Storage->DeleteValue(L"WriteTest");
- }
- Storage->Flush();
- }
- __finally
- {
- delete Storage;
- }
- Result = true;
- }
- catch(...)
- {
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- TStorage __fastcall TWinConfiguration::GetStorage()
- {
- if (FStorage == stDetect)
- {
- if (FindResourceEx(NULL, RT_RCDATA, L"WINSCP_SESSION",
- MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)))
- {
- FTemporarySessionFile =
- IncludeTrailingBackslash(SystemTemporaryDirectory()) + L"winscps.tmp";
- DumpResourceToFile(L"WINSCP_SESSION", FTemporarySessionFile);
- FEmbeddedSessions = true;
- FTemporaryKeyFile =
- IncludeTrailingBackslash(SystemTemporaryDirectory()) + L"winscpk.tmp";
- if (!DumpResourceToFile(L"WINSCP_KEY", FTemporaryKeyFile))
- {
- FTemporaryKeyFile = L"";
- }
- }
- FStorage = stIniFile;
- if (!FileExists(ApiPath(IniFileStorageNameForReading)))
- {
- if (DetectRegistryStorage(HKEY_CURRENT_USER) ||
- DetectRegistryStorage(HKEY_LOCAL_MACHINE) ||
- // FStorage is now stIniFile, so this tests writing to an INI file.
- // As we fall back to user profile folder, when application folder
- // is not writtable, it is actually unlikely that the below test ever fails.
- !CanWriteToStorage())
- {
- FStorage = stRegistry;
- }
- }
- }
- TStorage Result = TCustomWinConfiguration::GetStorage();
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::Saved()
- {
- TCustomWinConfiguration::Saved();
- FBookmarks->ModifyAll(false);
- FCustomCommandList->Reset();
- FEditorList->Saved();
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::RecryptPasswords(TStrings * RecryptPasswordErrors)
- {
- TCustomWinConfiguration::RecryptPasswords(RecryptPasswordErrors);
- try
- {
- TTerminalManager * Manager = TTerminalManager::Instance(false);
- DebugAssert(Manager != NULL);
- if (Manager != NULL)
- {
- Manager->RecryptPasswords();
- }
- }
- catch (Exception & E)
- {
- UnicodeString Message;
- if (ExceptionMessage(&E, Message))
- {
- // we do not expect this really to happen,
- // so we do not bother providing context
- RecryptPasswordErrors->Add(Message);
- }
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::GetUseMasterPassword()
- {
- return FUseMasterPassword;
- }
- //---------------------------------------------------------------------------
- THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool & SessionList)
- {
- // Detect embedded session, if not checked yet
- GetStorage();
- THierarchicalStorage * Result;
- if (SessionList && !FTemporarySessionFile.IsEmpty())
- {
- Result = TIniFileStorage::CreateFromPath(FTemporarySessionFile);
- // This is session-list specific store, so the only instance,
- // we do not reset the SessionList argument
- // (compare TConfiguration::CreateScpStorage)
- }
- else
- {
- Result = TCustomWinConfiguration::CreateScpStorage(SessionList);
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- // duplicated from core\configuration.cpp
- #define BLOCK(KEY, CANCREATE, BLOCK) \
- if (Storage->OpenSubKeyPath(KEY, CANCREATE)) try { BLOCK } __finally { Storage->CloseSubKeyPath(); }
- #define KEY(TYPE, VAR) KEYEX(TYPE, VAR, PropertyToKey(TEXT(#VAR)))
- #define REGCONFIG(CANCREATE) \
- BLOCK(L"Interface", CANCREATE, \
- KEYEX(Integer,DoubleClickAction, L"CopyOnDoubleClick"); \
- KEY(Bool, CopyOnDoubleClickConfirmation); \
- KEYEX(Integer, DDTransferConfirmation, L"DDTransferConfirmation2"); \
- KEY(String, DDTemporaryDirectory); \
- KEY(String, DDDrives); \
- KEY(Bool, DDWarnLackOfTempSpace); \
- KEY(Float, DDWarnLackOfTempSpaceRatio); \
- KEY(Bool, DeleteToRecycleBin); \
- KEY(Bool, DimmHiddenFiles); \
- KEY(Bool, RenameWholeName); \
- KEY(Bool, SelectDirectories); \
- KEY(String, SelectMask); \
- KEY(Bool, ShowHiddenFiles); \
- KEY(Integer, FormatSizeBytes); \
- KEY(Integer, PanelSearch); \
- KEY(Bool, ShowInaccesibleDirectories); \
- KEY(Bool, ConfirmTransferring); \
- KEY(Bool, ConfirmDeleting); \
- KEY(Bool, ConfirmRecycling); \
- KEY(Bool, ConfirmClosingSession); \
- KEY(String, AutoStartSession); \
- KEY(Bool, UseLocationProfiles); \
- KEY(Bool, UseSharedBookmarks); \
- KEY(Integer, LocaleSafe); \
- KEY(Bool, DDFakeFile); \
- KEY(Integer, DDExtTimeout); \
- KEY(Bool, DefaultDirIsHome); \
- KEY(Bool, TemporaryDirectoryAppendSession); \
- KEY(Bool, TemporaryDirectoryAppendPath); \
- KEY(Bool, TemporaryDirectoryDeterministic); \
- KEY(Bool, TemporaryDirectoryCleanup); \
- KEY(Bool, ConfirmTemporaryDirectoryCleanup); \
- KEY(Bool, PreservePanelState); \
- KEY(Integer, DarkTheme); \
- KEY(String, LastStoredSession); \
- KEY(Bool, AutoSaveWorkspace); \
- KEY(Bool, AutoSaveWorkspacePasswords); \
- KEY(String, AutoWorkspace); \
- KEY(Integer, PathInCaption); \
- KEY(Integer, SessionTabNameFormat); \
- KEY(Bool, MinimizeToTray); \
- KEY(Bool, BalloonNotifications); \
- KEY(Integer, NotificationsTimeout); \
- KEY(Integer, NotificationsStickTime); \
- KEY(Bool, CopyParamAutoSelectNotice); \
- KEY(Bool, LockToolbars); \
- KEY(Bool, SelectiveToolbarText); \
- KEY(Bool, AutoOpenInPutty); \
- KEY(Bool, RefreshRemotePanel); \
- KEY(DateTime, RefreshRemotePanelInterval); \
- KEYEX(String, PanelFont.FontName, L"PanelFontName"); \
- KEYEX(Integer,PanelFont.FontSize, L"PanelFontSize"); \
- KEYEX(Integer,PanelFont.FontStyle, L"PanelFontStyle"); \
- KEYEX(Integer,PanelFont.FontCharset, L"PanelFontCharset"); \
- KEY(Bool, NaturalOrderNumericalSorting); \
- KEY(Bool, FullRowSelect); \
- KEY(Bool, OfferedEditorAutoConfig); \
- KEY(Integer, LastMonitor); \
- KEY(String, VersionHistory); \
- KEY(Bool, EnableQueueByDefault); \
- KEY(String, OpenedStoredSessionFolders); \
- KEY(Bool, AutoImportedFromPuttyOrFilezilla); \
- KEY(Integer, GenerateUrlComponents); \
- KEY(Integer, GenerateUrlCodeTarget); \
- KEY(Integer, GenerateUrlScriptFormat); \
- KEY(Integer, GenerateUrlAssemblyLanguage); \
- KEY(Bool, ExternalSessionInExistingInstance); \
- KEY(Bool, ShowLoginWhenNoSession); \
- KEY(Bool, KeepOpenWhenNoSession); \
- KEY(Bool, LocalIconsByExt); \
- KEY(Integer, BidiModeOverride); \
- KEY(Integer, FlipChildrenOverride); \
- KEY(Bool, ShowTips); \
- KEY(String, TipsSeen); \
- KEY(DateTime, TipsShown); \
- KEY(String, FileColors); \
- KEY(Integer, RunsSinceLastTip); \
- KEY(Bool, HonorDrivePolicy); \
- KEY(Integer, LastMachineInstallations); \
- KEY(String, FExtensionsDeleted); \
- KEY(String, FExtensionsOrder); \
- KEY(String, FExtensionsShortCuts); \
- KEY(Bool, TimeoutShellOperations); \
- KEY(Bool, TimeoutShellIconRetrieval); \
- KEY(Bool, UseIconUpdateThread); \
- KEY(Bool, AllowWindowPrint); \
- ); \
- BLOCK(L"Interface\\Editor", CANCREATE, \
- KEYEX(String, Editor.Font.FontName, L"FontName2"); \
- KEY(Integer, Editor.Font.FontSize); \
- KEY(Integer, Editor.Font.FontStyle); \
- KEY(Integer, Editor.Font.FontCharset); \
- KEY(Integer, Editor.FontColor); \
- KEY(Integer, Editor.BackgroundColor); \
- KEY(Bool, Editor.WordWrap); \
- KEY(String, Editor.FindText); \
- KEY(String, Editor.ReplaceText); \
- KEY(Bool, Editor.FindMatchCase); \
- KEY(Bool, Editor.FindWholeWord); \
- KEY(Bool, Editor.FindDown); \
- KEY(Integer, Editor.TabSize); \
- KEY(Integer, Editor.MaxEditors); \
- KEY(Integer, Editor.EarlyClose); \
- KEY(Bool, Editor.SDIShellEditor); \
- KEY(String, Editor.WindowParams); \
- KEY(Integer, Editor.Encoding); \
- KEY(Bool, Editor.WarnOnEncodingFallback); \
- KEY(Bool, Editor.WarnOrLargeFileSize); \
- ); \
- BLOCK(L"Interface\\QueueView", CANCREATE, \
- KEY(Integer, QueueView.Height); \
- KEY(Integer, QueueView.HeightPixelsPerInch); \
- KEY(String, QueueView.Layout); \
- KEY(Integer, QueueView.Show); \
- KEY(Integer, QueueView.LastHideShow); \
- KEY(Bool, QueueView.ToolBar); \
- KEY(Bool, QueueView.Label); \
- ); \
- BLOCK(L"Interface\\Updates", CANCREATE, \
- KEY(Integer, FUpdates.Period); \
- KEY(DateTime, FUpdates.LastCheck); \
- KEY(Integer, FUpdates.HaveResults); \
- KEY(Integer, FUpdates.ShownResults); \
- KEY(Integer, FUpdates.BetaVersions); \
- KEY(Bool, FUpdates.ShowOnStartup); \
- KEY(String, FUpdates.AuthenticationEmail); \
- KEY(Integer, FUpdates.ConnectionType); \
- KEY(String, FUpdates.ProxyHost); \
- KEY(Integer, FUpdates.ProxyPort); \
- KEY(Integer, FUpdates.Results.ForVersion); \
- KEY(Integer, FUpdates.Results.Version); \
- KEY(String, FUpdates.Results.Message); \
- KEY(Integer, FUpdates.Results.Critical); \
- KEY(String, FUpdates.Results.Release); \
- KEY(Bool, FUpdates.Results.Disabled); \
- KEY(String, FUpdates.Results.Url); \
- KEY(String, FUpdates.Results.UrlButton); \
- KEY(String, FUpdates.Results.NewsUrl); \
- KEYEX(Integer,FUpdates.Results.NewsSize.Width, L"NewsWidth"); \
- KEYEX(Integer,FUpdates.Results.NewsSize.Height, L"NewsHeight"); \
- KEY(String, FUpdates.Results.DownloadUrl); \
- KEY(Int64, FUpdates.Results.DownloadSize); \
- KEY(String, FUpdates.Results.DownloadSha256); \
- KEY(String, FUpdates.Results.AuthenticationError); \
- KEY(Bool, FUpdates.Results.OpenGettingStarted); \
- KEY(String, FUpdates.Results.DownloadingUrl); \
- KEYEX(Integer,FUpdates.Results.TipsSize.Width, L"TipsWidth"); \
- KEYEX(Integer,FUpdates.Results.TipsSize.Height, L"TipsHeight"); \
- KEY(String, FUpdates.Results.TipsUrl); \
- KEY(String, FUpdates.Results.Tips); \
- KEY(Integer, FUpdates.Results.TipsIntervalDays); \
- KEY(Integer, FUpdates.Results.TipsIntervalRuns); \
- KEY(String, FUpdates.DotNetVersion); \
- KEY(String, FUpdates.ConsoleVersion); \
- ); \
- BLOCK(L"Interface\\Explorer", CANCREATE, \
- KEYEX(String, ScpExplorer.ToolbarsLayout, ToolbarsLayoutKey); \
- KEY(String, ScpExplorer.ToolbarsButtons); \
- KEY(String, ScpExplorer.DirViewParams); \
- KEY(String, ScpExplorer.LastLocalTargetDirectory); \
- KEY(Bool, ScpExplorer.SessionsTabs); \
- KEY(Bool, ScpExplorer.StatusBar); \
- KEY(String, ScpExplorer.WindowParams); \
- KEY(Integer, ScpExplorer.ViewStyle); \
- KEY(Bool, ScpExplorer.ShowFullAddress); \
- KEY(Bool, ScpExplorer.DriveView); \
- KEY(Integer, ScpExplorer.DriveViewWidth); \
- KEY(Integer, ScpExplorer.DriveViewWidthPixelsPerInch); \
- ); \
- BLOCK(L"Interface\\Commander", CANCREATE, \
- KEYEX(String, ScpCommander.ToolbarsLayout, ToolbarsLayoutKey); \
- KEY(String, ScpCommander.ToolbarsButtons); \
- KEY(Integer, ScpCommander.CurrentPanel); \
- KEY(Float, ScpCommander.LocalPanelWidth); \
- KEY(Bool, ScpCommander.SwappedPanels); \
- KEY(Bool, ScpCommander.SessionsTabs); \
- KEY(Bool, ScpCommander.StatusBar); \
- KEY(String, ScpCommander.WindowParams); \
- KEYEX(Integer, ScpCommander.NortonLikeMode, L"ExplorerStyleSelection"); \
- KEY(Bool, ScpCommander.PreserveLocalDirectory); \
- KEY(Bool, ScpCommander.CompareByTime); \
- KEY(Bool, ScpCommander.CompareBySize); \
- KEY(Bool, ScpCommander.TreeOnLeft); \
- KEY(Bool, ScpCommander.ExplorerKeyboardShortcuts); \
- KEY(Bool, ScpCommander.SystemContextMenu); \
- ); \
- BLOCK(L"Interface\\Commander\\LocalPanel", CANCREATE, \
- KEY(String, ScpCommander.LocalPanel.DirViewParams); \
- KEY(Bool, ScpCommander.LocalPanel.StatusBar); \
- KEY(Bool, ScpCommander.LocalPanel.DriveView); \
- KEY(Integer, ScpCommander.LocalPanel.DriveViewHeight); \
- KEY(Integer, ScpCommander.LocalPanel.DriveViewHeightPixelsPerInch); \
- KEY(Integer, ScpCommander.LocalPanel.DriveViewWidth); \
- KEY(Integer, ScpCommander.LocalPanel.DriveViewWidthPixelsPerInch); \
- KEY(String, ScpCommander.LocalPanel.LastPath); \
- ); \
- BLOCK(L"Interface\\Commander\\RemotePanel", CANCREATE, \
- KEY(String, ScpCommander.RemotePanel.DirViewParams); \
- KEY(Bool, ScpCommander.RemotePanel.StatusBar); \
- KEY(Bool, ScpCommander.RemotePanel.DriveView); \
- KEY(Integer, ScpCommander.RemotePanel.DriveViewHeight); \
- KEY(Integer, ScpCommander.RemotePanel.DriveViewHeightPixelsPerInch); \
- KEY(Integer, ScpCommander.RemotePanel.DriveViewWidth); \
- KEY(Integer, ScpCommander.RemotePanel.DriveViewWidthPixelsPerInch); \
- KEY(String, ScpCommander.RemotePanel.LastPath); \
- ); \
- BLOCK(L"Security", CANCREATE, \
- KEY(Bool, FUseMasterPassword); \
- KEY(String, FMasterPasswordVerifier); \
- );
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SaveData(THierarchicalStorage * Storage, bool All)
- {
- TCustomWinConfiguration::SaveData(Storage, All);
- // duplicated from core\configuration.cpp
- #define KEYEX(TYPE, VAR, NAME) Storage->Write ## TYPE(NAME, VAR)
- REGCONFIG(true);
- #undef KEYEX
- if (Storage->OpenSubKey(L"Bookmarks", true))
- {
- FBookmarks->Save(Storage, All);
- Storage->CloseSubKey();
- }
- if ((All && !FCustomCommandsDefaults) || FCustomCommandList->Modified)
- {
- FCustomCommandList->Save(Storage);
- }
- if ((All || FCustomCommandOptionsModified) &&
- Storage->OpenSubKey(L"CustomCommandOptions", true))
- {
- Storage->ClearValues();
- Storage->WriteValues(FCustomCommandOptions.get(), true);
- Storage->CloseSubKey();
- FCustomCommandOptionsModified = false;
- }
- if ((All || FEditorList->Modified) &&
- Storage->OpenSubKeyPath(L"Interface\\Editor", true))
- try
- {
- FEditorList->Save(Storage);
- }
- __finally
- {
- Storage->CloseSubKeyPath();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::LoadFrom(THierarchicalStorage * Storage)
- {
- FLegacyEditor = new TEditorPreferences();
- try
- {
- FLegacyEditor->LegacyDefaults();
- TCustomWinConfiguration::LoadFrom(Storage);
- // Following needs to be done even if there's no Configuration key in the storage,
- // so it cannot be in LoadData
- int EditorCount = FEditorList->Count;
- if (EditorCount == 0)
- {
- TEditorPreferences * AlternativeEditor = NULL;
- try
- {
- if (FLegacyEditor->Data->Editor == edInternal)
- {
- if (!FLegacyEditor->Data->ExternalEditor.IsEmpty())
- {
- AlternativeEditor = new TEditorPreferences(*FLegacyEditor);
- AlternativeEditor->GetData()->Editor = edExternal;
- FLegacyEditor->GetData()->ExternalEditor = L"";
- }
- }
- else
- {
- if (FLegacyEditor->Data->ExternalEditor.IsEmpty())
- {
- FLegacyEditor->GetData()->Editor = edInternal;
- }
- else
- {
- AlternativeEditor = new TEditorPreferences(*FLegacyEditor);
- AlternativeEditor->GetData()->Editor = edInternal;
- }
- }
- }
- catch(...)
- {
- delete AlternativeEditor;
- throw;
- }
- FEditorList->Add(FLegacyEditor);
- FLegacyEditor = NULL;
- if (AlternativeEditor != NULL)
- {
- FEditorList->Add(AlternativeEditor);
- }
- }
- // Additionally, this needs to be after Locale is loaded
- LoadExtensionTranslations();
- // and this after the ExtensionsDeleted, ExtensionsOrder and ExtensionsShortCuts are loaded
- LoadExtensionList();
- }
- __finally
- {
- delete FLegacyEditor;
- FLegacyEditor = NULL;
- }
- if (FUpdates.ConnectionType == -1)
- {
- FUpdates.ConnectionType = (FUpdates.ProxyHost.IsEmpty() ? ctAuto : ctProxy);
- }
- AddVersionToHistory();
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::DoLoadExtensionList(
- const UnicodeString & Path, const UnicodeString & PathId, TStringList * DeletedExtensions)
- {
- TSearchRecOwned SearchRec;
- int FindAttrs = faReadOnly | faArchive;
- if (FindFirstUnchecked(IncludeTrailingBackslash(Path) + L"*.*", FindAttrs, SearchRec) == 0)
- {
- do
- {
- UnicodeString Id = TCustomCommandType::GetExtensionId(SearchRec.Name);
- if (!Id.IsEmpty())
- {
- Id = IncludeTrailingBackslash(PathId) + Id;
- if (DeletedExtensions->IndexOf(Id) >= 0)
- {
- // reconstruct the list, so that we remove the commands that no longer exists
- AddToList(FExtensionsDeleted, Id, L"|");
- }
- else
- {
- std::unique_ptr<TCustomCommandType> CustomCommand(new TCustomCommandType());
- CustomCommand->Id = Id;
- try
- {
- CustomCommand->LoadExtension(IncludeTrailingBackslash(Path) + SearchRec.Name);
- FExtensionList->Add(CustomCommand.release());
- }
- catch (...)
- {
- // skip invalid extension files
- }
- }
- }
- }
- while (FindNextChecked(SearchRec) == 0);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall ParseExtensionList(TStrings * Strings, UnicodeString S)
- {
- while (!S.IsEmpty())
- {
- UnicodeString Extension = CutToChar(S, L'|', false);
- Strings->Add(Extension);
- }
- }
- //---------------------------------------------------------------------------
- const UnicodeString ExtensionsSubFolder(L"Extensions");
- const UnicodeString ExtensionsCommonPathId(L"common");
- const UnicodeString ExtensionsCommonExtPathId(L"commonext");
- const UnicodeString ExtensionsUserExtPathId(L"userext");
- //---------------------------------------------------------------------------
- static UnicodeString __fastcall ExtractExtensionBaseName(const UnicodeString & FileName)
- {
- UnicodeString S = ExtractFileName(FileName);
- // ExtractFileNameOnly trims the last extension only, we want to trim all extensions
- UnicodeString Result = CutToChar(S, L'.', true);
- return Result;
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TWinConfiguration::GetProvisionaryExtensionId(const UnicodeString & FileName)
- {
- return IncludeTrailingBackslash(ExtensionsUserExtPathId) + ExtractExtensionBaseName(FileName);
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TWinConfiguration::GetUserExtensionsPath()
- {
- return IncludeTrailingBackslash(GetShellFolderPath(CSIDL_APPDATA)) + L"WinSCP\\" + ExtensionsSubFolder;
- }
- //---------------------------------------------------------------------------
- TStrings * __fastcall TWinConfiguration::GetExtensionsPaths()
- {
- std::unique_ptr<TStrings> Result(new TStringList());
- UnicodeString ExeParentPath = ExcludeTrailingBackslash(ExtractFilePath(Application->ExeName));
- Result->Values[ExtensionsCommonPathId] = ExeParentPath;
- UnicodeString CommonExtensions = IncludeTrailingBackslash(ExeParentPath) + ExtensionsSubFolder;
- Result->Values[ExtensionsCommonExtPathId] = CommonExtensions;
- Result->Values[ExtensionsUserExtPathId] = GetUserExtensionsPath();
- return Result.release();
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TWinConfiguration::GetExtensionId(const UnicodeString & ExtensionPath)
- {
- UnicodeString Path = ExcludeTrailingBackslash(ExtractFilePath(ExtensionPath));
- UnicodeString NameId = TCustomCommandType::GetExtensionId(ExtractFileName(ExtensionPath));
- if (!NameId.IsEmpty())
- {
- std::unique_ptr<TStrings> ExtensionsPaths(GetExtensionsPaths());
- for (int Index = 0; Index < ExtensionsPaths->Count; Index++)
- {
- if (IsPathToSameFile(Path, ExtensionsPaths->ValueFromIndex[Index]))
- {
- return IncludeTrailingBackslash(ExtensionsPaths->Names[Index]) + NameId;
- }
- }
- }
- return L"";
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::ReleaseExtensionTranslations()
- {
- for (int Index = 0; Index < FExtensionTranslations->Count; Index++)
- {
- delete FExtensionTranslations->Objects[Index];
- }
- FExtensionTranslations->Clear();
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::LoadExtensionTranslations()
- {
- ReleaseExtensionTranslations();
- FExtensionTranslations.reset(new TStringList());
- int Index = EXTENSION_STRINGS;
- UnicodeString S;
- while (!((S = LoadStr(Index)).IsEmpty()))
- {
- UnicodeString ExtensionName = CutToChar(S, L'.', false);
- UnicodeString Original = CutToChar(S, L'=', false);
- UnicodeString Translation = S;
- int ExtensionIndex = FExtensionTranslations->IndexOf(ExtensionName);
- if (ExtensionIndex < 0)
- {
- ExtensionIndex = FExtensionTranslations->AddObject(ExtensionName, new TStringList());
- }
- TStringList * ExtensionTranslation = DebugNotNull(dynamic_cast<TStringList *>(FExtensionTranslations->Objects[ExtensionIndex]));
- ExtensionTranslation->Values[Original] = Translation;
- Index++;
- }
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TWinConfiguration::UniqueExtensionName(const UnicodeString & ExtensionName, int Counter)
- {
- // See how the digits are removed in the ExtensionStringTranslation
- return ExtensionName + IntToStr(Counter);
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TWinConfiguration::ExtensionStringTranslation(const UnicodeString & ExtensionId, const UnicodeString & S)
- {
- UnicodeString Result = S;
- if (!ExtensionId.IsEmpty())
- {
- UnicodeString ExtensionName = ExtractFileName(ExtensionId);
- int ExtensionIndex;
- bool Retry;
- do
- {
- ExtensionIndex = FExtensionTranslations->IndexOf(ExtensionName);
- // Try without trailing digits, possibly added by UniqueExtensionName
- Retry = (ExtensionIndex < 0) && !ExtensionName.IsEmpty() && IsDigit(*ExtensionName.LastChar());
- if (Retry)
- {
- ExtensionName.SetLength(ExtensionName.Length() - 1);
- }
- }
- while (Retry);
- if (ExtensionIndex >= 0)
- {
- TStrings * ExtensionTranslation = DebugNotNull(dynamic_cast<TStrings *>(FExtensionTranslations->Objects[ExtensionIndex]));
- int StringIndex = ExtensionTranslation->IndexOfName(S);
- if (StringIndex >= 0)
- {
- Result = ExtensionTranslation->ValueFromIndex[StringIndex];
- }
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::LoadExtensionList()
- {
- FExtensionList->Clear();
- std::unique_ptr<TStringList> DeletedExtensions(CreateSortedStringList());
- ParseExtensionList(DeletedExtensions.get(), FExtensionsDeleted);
- // will reconstruct the list in DoLoadExtensionList
- FExtensionsDeleted = L"";
- std::unique_ptr<TStrings> ExtensionsPaths(GetExtensionsPaths());
- for (int Index = 0; Index < ExtensionsPaths->Count; Index++)
- {
- DoLoadExtensionList(ExtensionsPaths->ValueFromIndex[Index], ExtensionsPaths->Names[Index], DeletedExtensions.get());
- }
- std::unique_ptr<TStringList> OrderedExtensions(new TStringList());
- ParseExtensionList(OrderedExtensions.get(), FExtensionsOrder);
- FExtensionList->SortBy(OrderedExtensions.get());
- UnicodeString ShortCuts = FExtensionsShortCuts;
- while (!ShortCuts.IsEmpty())
- {
- UnicodeString S = CutToChar(ShortCuts, L'|', false);
- TShortCut ShortCut = static_cast<TShortCut>(StrToInt(CutToChar(S, L'=', false)));
- for (int Index = 0; Index < FExtensionList->Count; Index++)
- {
- if (FExtensionList->Commands[Index]->Id == S)
- {
- const_cast<TCustomCommandType *>(FExtensionList->Commands[Index])->ShortCut = ShortCut;
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- static UnicodeString KeyName(THierarchicalStorage * Storage, const UnicodeString & Name)
- {
- UnicodeString Result = Name;
- if ((Result == ToolbarsLayoutKey) && !Storage->KeyExists(Result) && Storage->KeyExists(ToolbarsLayoutOldKey))
- {
- Result = ToolbarsLayoutOldKey;
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::LoadData(THierarchicalStorage * Storage)
- {
- TCustomWinConfiguration::LoadData(Storage);
- // duplicated from core\configuration.cpp
- #define KEYEX(TYPE, VAR, NAME) VAR = Storage->Read ## TYPE(KeyName(Storage, NAME), VAR)
- #pragma warn -eas
- REGCONFIG(false);
- #pragma warn +eas
- #undef KEYEX
- // to reflect changes to PanelFont
- UpdateIconFont();
- if (Storage->OpenSubKey(L"Bookmarks", false))
- {
- FBookmarks->Load(Storage);
- Storage->CloseSubKey();
- }
- if (Storage->KeyExists(L"CustomCommands"))
- {
- FCustomCommandList->Load(Storage);
- FCustomCommandsDefaults = false;
- }
- else if (FCustomCommandList->Modified)
- {
- // can this (=reloading of configuration) even happen?
- // if it does, shouldn't we reset default commands?
- DebugFail();
- FCustomCommandList->Clear();
- FCustomCommandsDefaults = false;
- }
- FCustomCommandList->Reset();
- if (Storage->OpenSubKey(L"CustomCommandOptions", false))
- {
- Storage->ReadValues(FCustomCommandOptions.get(), true);
- Storage->CloseSubKey();
- FCustomCommandOptionsModified = false;
- }
- if (Storage->OpenSubKeyPath(L"Interface\\Editor", false))
- try
- {
- FEditorList->Clear();
- FEditorList->Load(Storage);
- }
- __finally
- {
- Storage->CloseSubKeyPath();
- }
- // load legacy editor configuration
- DebugAssert(FLegacyEditor != NULL);
- if (Storage->OpenSubKeyPath(L"Interface\\Editor", false))
- {
- try
- {
- FLegacyEditor->Load(Storage, true);
- }
- __finally
- {
- Storage->CloseSubKeyPath();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::LoadAdmin(THierarchicalStorage * Storage)
- {
- TCustomWinConfiguration::LoadAdmin(Storage);
- FDisableOpenEdit = Storage->ReadBool(L"DisableOpenEdit", FDisableOpenEdit);
- FDefaultUpdatesPeriod = Storage->ReadInteger(L"DefaultUpdatesPeriod", FDefaultUpdatesPeriod);
- FMachineInstallations = Storage->ReadInteger(L"Installations", 0);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::CopyData(THierarchicalStorage * Source, THierarchicalStorage * Target)
- {
- TCustomWinConfiguration::CopyData(Source, Target);
- if (CopySubKey(Source, Target, ConfigurationSubKey))
- {
- Target->WriteString(L"JumpList", Source->ReadString(L"JumpList", L""));
- Target->WriteString(L"JumpListWorkspaces", Source->ReadString(L"JumpListWorkspaces", L""));
- Target->CloseSubKey();
- Source->CloseSubKey();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::ClearTemporaryLoginData()
- {
- if (!FTemporaryKeyFile.IsEmpty())
- {
- DeleteFile(ApiPath(FTemporaryKeyFile));
- FTemporaryKeyFile = L"";
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::AddVersionToHistory()
- {
- int CurrentVersion = CompoundVersion;
- DebugAssert(ZeroBuildNumber(CurrentVersion) == CurrentVersion);
- int From = 1;
- bool CurrentVersionPresent = false;
- while (!CurrentVersionPresent && (From < FVersionHistory.Length()))
- {
- UnicodeString VersionInfo = CopyToChars(FVersionHistory, From, L";", true);
- UnicodeString VersionStr = CutToChar(VersionInfo, L',', true);
- int Version;
- if (TryStrToInt(VersionStr, Version))
- {
- Version = ZeroBuildNumber(Version);
- if (Version == CurrentVersion)
- {
- CurrentVersionPresent = true;
- }
- }
- }
- if (!CurrentVersionPresent)
- {
- UnicodeString CurrentVersionInfo =
- IntToStr(CurrentVersion) + L"," + GetReleaseType();
- AddToList(FVersionHistory, CurrentVersionInfo, L';');
- }
- Usage->Set(L"AnyBetaUsed", AnyBetaInVersionHistory);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::DoIsBeta(const UnicodeString & ReleaseType)
- {
- // What about "Development" release type?
- return SameText(ReleaseType, L"beta") || SameText(ReleaseType, L"rc");
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::GetIsBeta()
- {
- return DoIsBeta(GetReleaseType());
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::GetAnyBetaInVersionHistory()
- {
- int From = 1;
- bool AnyBeta = false;
- while (!AnyBeta && (From < VersionHistory.Length()))
- {
- UnicodeString VersionInfo = CopyToChars(VersionHistory, From, L";", true);
- CutToChar(VersionInfo, L',', true);
- UnicodeString ReleaseType = CutToChar(VersionInfo, ',', true);
- if (DoIsBeta(ReleaseType))
- {
- AnyBeta = true;
- }
- }
- return AnyBeta;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::GetDDExtInstalled()
- {
- if (FDDExtInstalled < 0)
- {
- if (IsWin64())
- {
- // WORKAROUND
- // We cannot load 64-bit COM class into 32-bit process,
- // so we fallback to querying registration keys
- #define CLSID_SIZE 39
- wchar_t ClassID[CLSID_SIZE];
- StringFromGUID2(CLSID_ShellExtension, ClassID, LENOF(ClassID));
- NULL_TERMINATE(ClassID);
- UnicodeString SubKey = UnicodeString(L"CLSID\\") + ClassID;
- HKEY HKey;
- LONG Result = RegOpenKeyEx(HKEY_CLASSES_ROOT, SubKey.c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &HKey);
- if (Result == ERROR_SUCCESS)
- {
- RegCloseKey(HKey);
- FDDExtInstalled = 1;
- }
- else
- {
- FDDExtInstalled = 0;
- }
- }
- else
- {
- void * DragExtRef;
- int CreateResult =
- CoCreateInstance(CLSID_ShellExtension, NULL,
- CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IUnknown,
- &DragExtRef);
- bool Result = (CreateResult == S_OK);
- FDDExtInstalled = (Result ? 1 : 0);
- if (Result)
- {
- reinterpret_cast<IUnknown *>(DragExtRef)->Release();
- CoFreeUnusedLibraries();
- }
- }
- }
- return (FDDExtInstalled > 0);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::IsDDExtRunning()
- {
- bool Result;
- if (!DDExtInstalled)
- {
- Result = false;
- }
- else
- {
- HANDLE H = OpenMutex(SYNCHRONIZE, False, DRAG_EXT_RUNNING_MUTEX);
- Result = (H != NULL);
- CloseHandle(H);
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::IsDDExtBroken()
- {
- int Build = GetWindowsBuild();
- return (Build >= 17134) && (Build < 17763);
- }
- //---------------------------------------------------------------------------
- RawByteString __fastcall TWinConfiguration::StronglyRecryptPassword(RawByteString Password, UnicodeString Key)
- {
- RawByteString Dummy;
- RawByteString Result;
- if (GetExternalEncryptedPassword(Password, Dummy) ||
- !FUseMasterPassword)
- {
- // already-strongly encrypted
- // or no master password set, so we cannot strongly-encrypt it
- Result = Password;
- }
- else
- {
- UnicodeString PasswordText =
- TCustomWinConfiguration::DecryptPassword(Password, Key);
- if (!PasswordText.IsEmpty())
- {
- // Can be not set for instance, when editing=>saving site with no prior password.
- // Though it should not actually happen, as we call AskForMasterPasswordIfNotSetAndNeededToPersistSessionData in DoSaveSession.
- AskForMasterPasswordIfNotSet();
- Password = ScramblePassword(PasswordText);
- AES256EncyptWithMAC(Password, FPlainMasterPasswordEncrypt, Result);
- Result = SetExternalEncryptedPassword(Result);
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TWinConfiguration::DecryptPassword(RawByteString Password, UnicodeString Key)
- {
- UnicodeString Result;
- RawByteString Buf;
- if (GetExternalEncryptedPassword(Password, Buf))
- {
- if (FDontDecryptPasswords == 0)
- {
- // As opposite to AskForMasterPasswordIfNotSet, we test here
- // for decrypt password. This is important while recrypting password,
- // when clearing master password, when encrypt password is already empty.
- if (FPlainMasterPasswordDecrypt.IsEmpty())
- {
- AskForMasterPassword();
- }
- if (!AES256DecryptWithMAC(Buf, FPlainMasterPasswordDecrypt, Buf) ||
- !UnscramblePassword(Buf, Result))
- {
- throw Exception(LoadStr(DECRYPT_PASSWORD_ERROR));
- }
- }
- else
- {
- Abort();
- }
- }
- else
- {
- Result = TCustomWinConfiguration::DecryptPassword(Password, Key);
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetMasterPassword(UnicodeString value)
- {
- // just stores the plain-text version of the password
- // we can get here even if master password is off,
- // when we encounter stray encrypted password (e.g. manually imported site),
- // make sure we do not set encrypt password to avoid starting encrypting
- // new passwords
- // (this is bit of edge case, not really well tested)
- if (!FUseMasterPassword)
- {
- FPlainMasterPasswordDecrypt = value;
- }
- else if (DebugAlwaysTrue(FUseMasterPassword) &&
- DebugAlwaysTrue(ValidateMasterPassword(value)))
- {
- FPlainMasterPasswordEncrypt = value;
- FPlainMasterPasswordDecrypt = value;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::ChangeMasterPassword(
- UnicodeString value, TStrings * RecryptPasswordErrors)
- {
- RawByteString Verifier;
- AES256CreateVerifier(value, Verifier);
- FMasterPasswordVerifier = BytesToHex(Verifier);
- FPlainMasterPasswordEncrypt = value;
- FUseMasterPassword = true;
- try
- {
- RecryptPasswords(RecryptPasswordErrors);
- }
- __finally
- {
- FPlainMasterPasswordDecrypt = value;
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::ValidateMasterPassword(UnicodeString value)
- {
- DebugAssert(UseMasterPassword);
- DebugAssert(!FMasterPasswordVerifier.IsEmpty());
- bool Result = AES256Verify(value, HexToBytes(FMasterPasswordVerifier));
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::ClearMasterPassword(TStrings * RecryptPasswordErrors)
- {
- FMasterPasswordVerifier = L"";
- FUseMasterPassword = false;
- Shred(FPlainMasterPasswordEncrypt);
- try
- {
- RecryptPasswords(RecryptPasswordErrors);
- }
- __finally
- {
- Shred(FPlainMasterPasswordDecrypt);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::AskForMasterPassword()
- {
- if (FMasterPasswordSession > 0)
- {
- if (FMasterPasswordSessionAsked)
- {
- Abort();
- }
- // set before call to OnMasterPasswordPrompt as it may abort
- FMasterPasswordSessionAsked = true;
- }
- if (FOnMasterPasswordPrompt == NULL)
- {
- throw Exception(L"Master password handler not set");
- }
- else
- {
- FOnMasterPasswordPrompt();
- DebugAssert(!FPlainMasterPasswordDecrypt.IsEmpty());
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::AskForMasterPasswordIfNotSet()
- {
- if (FPlainMasterPasswordEncrypt.IsEmpty())
- {
- AskForMasterPassword();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::BeginMasterPasswordSession()
- {
- // We do not expect nesting
- DebugAssert(FMasterPasswordSession == 0);
- DebugAssert(!FMasterPasswordSessionAsked || (FMasterPasswordSession > 0));
- // This should better be thread-specific
- FMasterPasswordSession++;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::EndMasterPasswordSession()
- {
- if (DebugAlwaysTrue(FMasterPasswordSession > 0))
- {
- FMasterPasswordSession--;
- }
- FMasterPasswordSessionAsked = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDDTransferConfirmation(TAutoSwitch value)
- {
- SET_CONFIG_PROPERTY(DDTransferConfirmation);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDDTemporaryDirectory(UnicodeString value)
- {
- SET_CONFIG_PROPERTY(DDTemporaryDirectory);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDDDrives(UnicodeString value)
- {
- SET_CONFIG_PROPERTY(DDDrives);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDDFakeFile(bool value)
- {
- SET_CONFIG_PROPERTY(DDFakeFile);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDDExtTimeout(int value)
- {
- SET_CONFIG_PROPERTY(DDExtTimeout);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpace(bool value)
- {
- SET_CONFIG_PROPERTY(DDWarnLackOfTempSpace);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpaceRatio(double value)
- {
- SET_CONFIG_PROPERTY(DDWarnLackOfTempSpaceRatio);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetScpExplorer(TScpExplorerConfiguration value)
- {
- SET_CONFIG_PROPERTY(ScpExplorer);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetScpCommander(TScpCommanderConfiguration value)
- {
- SET_CONFIG_PROPERTY(ScpCommander);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetEditor(TEditorConfiguration value)
- {
- SET_CONFIG_PROPERTY(Editor);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetQueueView(TQueueViewConfiguration value)
- {
- SET_CONFIG_PROPERTY(QueueView);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetEnableQueueByDefault(bool value)
- {
- SET_CONFIG_PROPERTY(EnableQueueByDefault);
- }
- //---------------------------------------------------------------------------
- TUpdatesConfiguration __fastcall TWinConfiguration::GetUpdates()
- {
- TUpdatesConfiguration Result;
- {
- TGuard Guard(FCriticalSection);
- Result = FUpdates;
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetUpdates(TUpdatesConfiguration value)
- {
- TGuard Guard(FCriticalSection);
- // do not use SET_CONFIG_PROPERTY to avoid OnChange handler call (not synchronized)
- FUpdates = value;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetVersionHistory(UnicodeString value)
- {
- SET_CONFIG_PROPERTY(VersionHistory);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDeleteToRecycleBin(bool value)
- {
- SET_CONFIG_PROPERTY(DeleteToRecycleBin);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetSelectDirectories(bool value)
- {
- SET_CONFIG_PROPERTY(SelectDirectories);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetShowHiddenFiles(bool value)
- {
- SET_CONFIG_PROPERTY(ShowHiddenFiles);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetFormatSizeBytes(TFormatBytesStyle value)
- {
- SET_CONFIG_PROPERTY(FormatSizeBytes);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetPanelSearch(TIncrementalSearch value)
- {
- SET_CONFIG_PROPERTY(PanelSearch);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetShowInaccesibleDirectories(bool value)
- {
- SET_CONFIG_PROPERTY(ShowInaccesibleDirectories);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetConfirmTransferring(bool value)
- {
- SET_CONFIG_PROPERTY(ConfirmTransferring);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetConfirmDeleting(bool value)
- {
- SET_CONFIG_PROPERTY(ConfirmDeleting);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetConfirmRecycling(bool value)
- {
- SET_CONFIG_PROPERTY(ConfirmRecycling);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetUseLocationProfiles(bool value)
- {
- SET_CONFIG_PROPERTY(UseLocationProfiles);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetUseSharedBookmarks(bool value)
- {
- SET_CONFIG_PROPERTY(UseSharedBookmarks);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetConfirmClosingSession(bool value)
- {
- SET_CONFIG_PROPERTY(ConfirmClosingSession);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDoubleClickAction(TDoubleClickAction value)
- {
- SET_CONFIG_PROPERTY(DoubleClickAction);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetCopyOnDoubleClickConfirmation(bool value)
- {
- SET_CONFIG_PROPERTY(CopyOnDoubleClickConfirmation);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDimmHiddenFiles(bool value)
- {
- SET_CONFIG_PROPERTY(DimmHiddenFiles);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetRenameWholeName(bool value)
- {
- SET_CONFIG_PROPERTY(RenameWholeName);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetAutoStartSession(UnicodeString value)
- {
- SET_CONFIG_PROPERTY(AutoStartSession);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetExpertMode(bool value)
- {
- SET_CONFIG_PROPERTY(ExpertMode);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDefaultDirIsHome(bool value)
- {
- SET_CONFIG_PROPERTY(DefaultDirIsHome);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetTemporaryDirectoryAppendSession(bool value)
- {
- SET_CONFIG_PROPERTY(TemporaryDirectoryAppendSession);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetTemporaryDirectoryAppendPath(bool value)
- {
- SET_CONFIG_PROPERTY(TemporaryDirectoryAppendPath);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetTemporaryDirectoryDeterministic(bool value)
- {
- SET_CONFIG_PROPERTY(TemporaryDirectoryDeterministic);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetTemporaryDirectoryCleanup(bool value)
- {
- SET_CONFIG_PROPERTY(TemporaryDirectoryCleanup);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetConfirmTemporaryDirectoryCleanup(bool value)
- {
- SET_CONFIG_PROPERTY(ConfirmTemporaryDirectoryCleanup);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetPreservePanelState(bool value)
- {
- SET_CONFIG_PROPERTY(PreservePanelState);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDarkTheme(TAutoSwitch value)
- {
- SET_CONFIG_PROPERTY_EX(DarkTheme, ConfigureInterface());
- }
- //---------------------------------------------------------------------------
- static int __fastcall SysDarkTheme(HKEY RootKey)
- {
- std::unique_ptr<TRegistry> Registry(new TRegistry());
- Registry->RootKey = RootKey;
- UnicodeString ThemesPersonalizeKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
- UnicodeString AppsUseLightThemeValue = L"AppsUseLightTheme";
- int Result = -1;
- if (Registry->OpenKeyReadOnly(ThemesPersonalizeKey) &&
- Registry->ValueExists(AppsUseLightThemeValue))
- {
- Result = Registry->ReadBool(AppsUseLightThemeValue) ? 0 : 1;
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::ResetSysDarkTheme()
- {
- FSysDarkTheme = -1;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::UseDarkTheme()
- {
- if (FSysDarkTheme < 0)
- {
- FSysDarkTheme = SysDarkTheme(HKEY_CURRENT_USER);
- if (FSysDarkTheme < 0)
- {
- FSysDarkTheme = SysDarkTheme(HKEY_LOCAL_MACHINE);
- if (FSysDarkTheme < 0)
- {
- FSysDarkTheme = 0;
- }
- }
- }
- switch (WinConfiguration->DarkTheme)
- {
- case asOn:
- return true;
- case asOff:
- return false;
- default:
- return (FSysDarkTheme > 0);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetLastStoredSession(UnicodeString value)
- {
- SET_CONFIG_PROPERTY(LastStoredSession);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetAutoSaveWorkspace(bool value)
- {
- SET_CONFIG_PROPERTY(AutoSaveWorkspace);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetAutoSaveWorkspacePasswords(bool value)
- {
- SET_CONFIG_PROPERTY(AutoSaveWorkspacePasswords);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetAutoWorkspace(UnicodeString value)
- {
- SET_CONFIG_PROPERTY(AutoWorkspace);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetPathInCaption(TPathInCaption value)
- {
- SET_CONFIG_PROPERTY(PathInCaption);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetMinimizeToTray(bool value)
- {
- SET_CONFIG_PROPERTY(MinimizeToTray);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetBalloonNotifications(bool value)
- {
- SET_CONFIG_PROPERTY(BalloonNotifications);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetNotificationsTimeout(unsigned int value)
- {
- SET_CONFIG_PROPERTY(NotificationsTimeout);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetNotificationsStickTime(unsigned int value)
- {
- SET_CONFIG_PROPERTY(NotificationsStickTime);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetCopyParamAutoSelectNotice(bool value)
- {
- SET_CONFIG_PROPERTY(CopyParamAutoSelectNotice);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetLockToolbars(bool value)
- {
- SET_CONFIG_PROPERTY(LockToolbars);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetSelectiveToolbarText(bool value)
- {
- SET_CONFIG_PROPERTY(SelectiveToolbarText);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetAutoOpenInPutty(bool value)
- {
- SET_CONFIG_PROPERTY(AutoOpenInPutty);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetRefreshRemotePanel(bool value)
- {
- SET_CONFIG_PROPERTY(RefreshRemotePanel);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetRefreshRemotePanelInterval(TDateTime value)
- {
- SET_CONFIG_PROPERTY(RefreshRemotePanelInterval);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::UpdateIconFont()
- {
- UpdateDesktopFont();
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetPanelFont(const TFontConfiguration & value)
- {
- SET_CONFIG_PROPERTY_EX(PanelFont, UpdateIconFont());
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetNaturalOrderNumericalSorting(bool value)
- {
- SET_CONFIG_PROPERTY(NaturalOrderNumericalSorting);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetFullRowSelect(bool value)
- {
- SET_CONFIG_PROPERTY(FullRowSelect);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetOfferedEditorAutoConfig(bool value)
- {
- SET_CONFIG_PROPERTY(OfferedEditorAutoConfig);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetOpenedStoredSessionFolders(UnicodeString value)
- {
- SET_CONFIG_PROPERTY(OpenedStoredSessionFolders);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetAutoImportedFromPuttyOrFilezilla(bool value)
- {
- SET_CONFIG_PROPERTY(AutoImportedFromPuttyOrFilezilla);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetGenerateUrlComponents(int value)
- {
- SET_CONFIG_PROPERTY(GenerateUrlComponents);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetGenerateUrlCodeTarget(TGenerateUrlCodeTarget value)
- {
- SET_CONFIG_PROPERTY(GenerateUrlCodeTarget);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetGenerateUrlScriptFormat(TScriptFormat value)
- {
- SET_CONFIG_PROPERTY(GenerateUrlScriptFormat);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetGenerateUrlAssemblyLanguage(TAssemblyLanguage value)
- {
- SET_CONFIG_PROPERTY(GenerateUrlAssemblyLanguage);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetExternalSessionInExistingInstance(bool value)
- {
- SET_CONFIG_PROPERTY(ExternalSessionInExistingInstance);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetShowLoginWhenNoSession(bool value)
- {
- SET_CONFIG_PROPERTY(ShowLoginWhenNoSession);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetKeepOpenWhenNoSession(bool value)
- {
- SET_CONFIG_PROPERTY(KeepOpenWhenNoSession);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetLocalIconsByExt(bool value)
- {
- SET_CONFIG_PROPERTY(LocalIconsByExt);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetBidiModeOverride(TLocaleFlagOverride value)
- {
- SET_CONFIG_PROPERTY(BidiModeOverride);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetFlipChildrenOverride(TLocaleFlagOverride value)
- {
- SET_CONFIG_PROPERTY(FlipChildrenOverride);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetShowTips(bool value)
- {
- SET_CONFIG_PROPERTY(ShowTips);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetTipsSeen(UnicodeString value)
- {
- SET_CONFIG_PROPERTY(TipsSeen);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetTipsShown(TDateTime value)
- {
- SET_CONFIG_PROPERTY(TipsShown);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetFileColors(UnicodeString value)
- {
- SET_CONFIG_PROPERTY(FileColors);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetRunsSinceLastTip(int value)
- {
- SET_CONFIG_PROPERTY(RunsSinceLastTip);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::GetHonorDrivePolicy()
- {
- return DriveInfo->HonorDrivePolicy;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetHonorDrivePolicy(bool value)
- {
- if (HonorDrivePolicy != value)
- {
- DriveInfo->HonorDrivePolicy = value;
- Changed();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetCustomCommandList(TCustomCommandList * value)
- {
- DebugAssert(FCustomCommandList);
- if (!FCustomCommandList->Equals(value))
- {
- FCustomCommandList->Assign(value);
- FCustomCommandsDefaults = false;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetExtensionList(TCustomCommandList * value)
- {
- if (!ExtensionList->Equals(value))
- {
- std::unique_ptr<TStringList> DeletedExtensions(CreateSortedStringList());
- ParseExtensionList(DeletedExtensions.get(), FExtensionsDeleted);
- for (int Index = 0; Index < ExtensionList->Count; Index++)
- {
- const TCustomCommandType * CustomCommand = ExtensionList->Commands[Index];
- int Index = value->FindIndexByFileName(CustomCommand->FileName);
- if (Index < 0)
- {
- if (FileExists(CustomCommand->FileName) &&
- !DeleteFile(CustomCommand->FileName))
- {
- DeletedExtensions->Add(CustomCommand->Id);
- }
- }
- }
- FExtensionsOrder = L"";
- for (int Index = 0; Index < value->Count; Index++)
- {
- const TCustomCommandType * CustomCommand = value->Commands[Index];
- AddToList(FExtensionsOrder, CustomCommand->Id, L"|");
- int DeletedIndex = DeletedExtensions->IndexOf(CustomCommand->Id);
- if (DeletedIndex >= 0)
- {
- DeletedExtensions->Delete(DeletedIndex);
- }
- }
- FExtensionList->Assign(value);
- FExtensionsDeleted = L"";
- for (int Index = 0; Index < DeletedExtensions->Count; Index++)
- {
- AddToList(FExtensionsDeleted, DeletedExtensions->Strings[Index], L"|");
- }
- FExtensionsShortCuts = L"";
- for (int Index = 0; Index < value->Count; Index++)
- {
- const TCustomCommandType * Extension = value->Commands[Index];
- if (Extension->HasCustomShortCut())
- {
- AddToList(FExtensionsShortCuts, FORMAT(L"%d=%s", (Extension->ShortCut, Extension->Id)), L"|");
- }
- }
- Changed();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::CustomCommandShortCuts(TShortCuts & ShortCuts) const
- {
- CustomCommandList->ShortCuts(ShortCuts);
- ExtensionList->ShortCuts(ShortCuts);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetBookmarks(UnicodeString Key,
- TBookmarkList * value)
- {
- FBookmarks->Bookmarks[Key] = value;
- Changed();
- }
- //---------------------------------------------------------------------------
- TBookmarkList * __fastcall TWinConfiguration::GetBookmarks(UnicodeString Key)
- {
- return FBookmarks->Bookmarks[Key];
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetSharedBookmarks(TBookmarkList * value)
- {
- FBookmarks->SharedBookmarks = value;
- Changed();
- }
- //---------------------------------------------------------------------------
- TBookmarkList * __fastcall TWinConfiguration::GetSharedBookmarks()
- {
- return FBookmarks->SharedBookmarks;
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TWinConfiguration::GetDefaultKeyFile()
- {
- return (!FDefaultKeyFile.IsEmpty() ? FDefaultKeyFile : FTemporaryKeyFile);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetLastMonitor(int value)
- {
- ::SetLastMonitor(value);
- }
- //---------------------------------------------------------------------------
- int __fastcall TWinConfiguration::GetLastMonitor()
- {
- return ::GetLastMonitor();
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TWinConfiguration::ExpandedTemporaryDirectory()
- {
- UnicodeString Result =
- ExpandFileName(ExpandEnvironmentVariables(DDTemporaryDirectory));
- if (Result.IsEmpty())
- {
- Result = SystemTemporaryDirectory();
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TWinConfiguration::TemporaryDir(bool Mask)
- {
- return UniqTempDir(ExpandedTemporaryDirectory(), L"scp", Mask);
- }
- //---------------------------------------------------------------------------
- TStrings * __fastcall TWinConfiguration::DoFindTemporaryFolders(bool OnlyFirst)
- {
- std::unique_ptr<TStrings> Result(new TStringList());
- TSearchRecOwned SRec;
- UnicodeString Mask = TemporaryDir(true);
- UnicodeString Directory = ExtractFilePath(Mask);
- if (FindFirstUnchecked(Mask, faDirectory | faHidden, SRec) == 0)
- {
- do
- {
- if (SRec.IsDirectory())
- {
- Result->Add(Directory + SRec.Name);
- }
- }
- while ((FindNextChecked(SRec) == 0) && (!OnlyFirst || Result->Count == 0));
- }
- if (Result->Count == 0)
- {
- Result.reset(NULL);
- }
- return Result.release();
- }
- //---------------------------------------------------------------------------
- TStrings * __fastcall TWinConfiguration::FindTemporaryFolders()
- {
- return DoFindTemporaryFolders(false);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::AnyTemporaryFolders()
- {
- std::unique_ptr<TStrings> Folders(DoFindTemporaryFolders(true));
- return (Folders.get() != NULL);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::CleanupTemporaryFolders()
- {
- std::unique_ptr<TStrings> Folders(FindTemporaryFolders());
- if (Folders.get() != NULL)
- {
- CleanupTemporaryFolders(Folders.get());
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::CleanupTemporaryFolders(TStrings * Folders)
- {
- if (DebugAlwaysTrue(Folders->Count > 0))
- {
- Usage->Inc(L"TemporaryDirectoryCleanups");
- }
- UnicodeString ErrorList;
- for (int i = 0; i < Folders->Count; i++)
- {
- if (!DeleteDirectory(Folders->Strings[i]))
- {
- if (!ErrorList.IsEmpty())
- {
- ErrorList += L"\n";
- }
- ErrorList += Folders->Strings[i];
- }
- }
- if (!ErrorList.IsEmpty())
- {
- throw ExtException(LoadStr(CLEANUP_TEMP_ERROR), ErrorList);
- }
- }
- //---------------------------------------------------------------------------
- int __fastcall TWinConfiguration::GetResourceModuleCompleteness(HINSTANCE Module)
- {
- UnicodeString CompletenessStr = LoadStrFrom(Module, TRANSLATION_COMPLETENESS);
- return StrToIntDef(CompletenessStr, -1);
- }
- //---------------------------------------------------------------------------
- int __fastcall TWinConfiguration::GetLocaleCompletenessTreshold()
- {
- return 80;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::IsTranslationComplete(HINSTANCE Module)
- {
- return (GetResourceModuleCompleteness(Module) >= LocaleCompletenessTreshold);
- }
- //---------------------------------------------------------------------------
- HINSTANCE __fastcall TWinConfiguration::LoadNewResourceModule(LCID ALocale,
- UnicodeString & FileName)
- {
- HINSTANCE Instance = TCustomWinConfiguration::LoadNewResourceModule(ALocale, FileName);
- if (Instance != NULL)
- {
- try
- {
- CheckTranslationVersion(FileName, false);
- }
- catch(...)
- {
- FreeResourceModule(Instance);
- throw;
- }
- }
- return Instance;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::CheckTranslationVersion(const UnicodeString FileName,
- bool InternalLocaleOnError)
- {
- UnicodeString TranslationProductVersion = GetFileProductVersion(FileName);
- UnicodeString TranslationProductName = GetFileProductName(FileName);
- if ((ProductName != TranslationProductName) ||
- (ProductVersion != TranslationProductVersion))
- {
- if (InternalLocaleOnError)
- {
- LocaleSafe = InternalLocale();
- }
- if (TranslationProductName.IsEmpty() || TranslationProductVersion.IsEmpty())
- {
- throw Exception(FMTLOAD(UNKNOWN_TRANSLATION, (FileName)));
- }
- else
- {
- throw Exception(FMTLOAD(INCOMPATIBLE_TRANSLATION,
- (FileName, TranslationProductName, TranslationProductVersion)));
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::CheckDefaultTranslation()
- {
- if (!FInvalidDefaultTranslationMessage.IsEmpty())
- {
- MoreMessageDialog(FMTLOAD(INVALID_DEFAULT_TRANSLATION,
- (FInvalidDefaultTranslationMessage)), NULL, qtWarning, qaOK, HELP_NONE);
- }
- }
- //---------------------------------------------------------------------------
- const TEditorPreferences * __fastcall TWinConfiguration::DefaultEditorForFile(
- const UnicodeString FileName, bool Local, const TFileMasks::TParams & MaskParams)
- {
- return FEditorList->Find(FileName, Local, MaskParams);
- }
- //---------------------------------------------------------------------------
- const TEditorList * __fastcall TWinConfiguration::GetEditorList()
- {
- return FEditorList;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetEditorList(const TEditorList * value)
- {
- if (!(*FEditorList == *value))
- {
- *FEditorList = *value;
- Changed();
- }
- }
- //---------------------------------------------------------------------------
- TStrings * __fastcall TWinConfiguration::GetCustomCommandOptions()
- {
- return FCustomCommandOptions.get();
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetCustomCommandOptions(TStrings * value)
- {
- if (!FCustomCommandOptions->Equals(value))
- {
- FCustomCommandOptions->Assign(value);
- FCustomCommandOptionsModified = true;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetLockedInterface(bool value)
- {
- SET_CONFIG_PROPERTY(LockedInterface);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::GetTimeoutShellOperations()
- {
- return ::TimeoutShellOperations;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetTimeoutShellOperations(bool value)
- {
- ::TimeoutShellOperations = value;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetTimeoutShellIconRetrieval(bool value)
- {
- SET_CONFIG_PROPERTY(TimeoutShellIconRetrieval);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetUseIconUpdateThread(bool value)
- {
- SET_CONFIG_PROPERTY(UseIconUpdateThread);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetAllowWindowPrint(bool value)
- {
- SET_CONFIG_PROPERTY(AllowWindowPrint);
- }
- //---------------------------------------------------------------------------
- TStringList * __fastcall TWinConfiguration::LoadJumpList(
- THierarchicalStorage * Storage, UnicodeString Name)
- {
- UnicodeString JumpList = Storage->ReadString(Name, L"");
- std::unique_ptr<TStringList> List(new TStringList());
- List->CaseSensitive = false;
- List->CommaText = JumpList;
- return List.release();
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SaveJumpList(
- THierarchicalStorage * Storage, UnicodeString Name, TStringList * List)
- {
- UnicodeString JumpList = Storage->ReadString(Name, L"");
- UnicodeString NewJumpList = List->CommaText;
- if (NewJumpList != JumpList)
- {
- Storage->WriteString(Name, NewJumpList);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::TrimJumpList(TStringList * List)
- {
- while (List->Count > 30)
- {
- List->Delete(List->Count - 1);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::UpdateEntryInJumpList(
- bool Session, const UnicodeString & Name, bool Add)
- {
- try
- {
- std::auto_ptr<THierarchicalStorage> Storage(CreateConfigStorage());
- TAutoNestingCounter DontDecryptPasswordsCounter(FDontDecryptPasswords);
- Storage->AccessMode = smReadWrite;
- // For initial call from UpdateJumpList, do not create the key if it does ot exist yet.
- // To avoid creating the key if we are being started just for a maintenance task.
- if (Storage->OpenSubKey(ConfigurationSubKey, !Name.IsEmpty()))
- {
- std::unique_ptr<TStringList> ListSessions(LoadJumpList(Storage.get(), L"JumpList"));
- std::unique_ptr<TStringList> ListWorkspaces(LoadJumpList(Storage.get(), L"JumpListWorkspaces"));
- if (!Name.IsEmpty())
- {
- TStringList * List = (Session ? ListSessions : ListWorkspaces).get();
- int Index = List->IndexOf(Name);
- if (Index >= 0)
- {
- List->Delete(Index);
- }
- if (Add)
- {
- List->Insert(0, Name);
- }
- }
- TrimJumpList(ListSessions.get());
- TrimJumpList(ListWorkspaces.get());
- ::UpdateJumpList(ListSessions.get(), ListWorkspaces.get());
- SaveJumpList(Storage.get(), L"JumpList", ListSessions.get());
- SaveJumpList(Storage.get(), L"JumpListWorkspaces", ListWorkspaces.get());
- }
- }
- catch (Exception & E)
- {
- throw ExtException(&E, MainInstructions(LoadStr(JUMPLIST_ERROR)));
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::AddSessionToJumpList(UnicodeString SessionName)
- {
- UpdateEntryInJumpList(true, SessionName, true);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::DeleteSessionFromJumpList(UnicodeString SessionName)
- {
- UpdateEntryInJumpList(true, SessionName, false);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::AddWorkspaceToJumpList(UnicodeString Workspace)
- {
- UpdateEntryInJumpList(false, Workspace, true);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::DeleteWorkspaceFromJumpList(UnicodeString Workspace)
- {
- UpdateEntryInJumpList(false, Workspace, false);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::UpdateJumpList()
- {
- AddSessionToJumpList(L"");
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::UpdateStaticUsage()
- {
- // This is here because of TStoredSessionList::UpdateStaticUsage() call
- // from TConfiguration::UpdateStaticUsage()
- TAutoNestingCounter DontDecryptPasswordsAutoCounter(FDontDecryptPasswords);
- TCustomWinConfiguration::UpdateStaticUsage();
- Usage->Set(L"Beta", IsBeta);
- Usage->Set(L"Interface", Interface);
- Usage->Set(L"ThemeDark", UseDarkTheme());
- Usage->Set(L"CustomCommandsCount", (FCustomCommandsDefaults ? 0 : FCustomCommandList->Count));
- Usage->Set(L"UsingLocationProfiles", UseLocationProfiles);
- Usage->Set(L"UsingMasterPassword", UseMasterPassword);
- Usage->Set(L"UsingAutoSaveWorkspace", AutoSaveWorkspace);
- Usage->Set(L"TreeVisible",
- (Interface == ifExplorer) ?
- ScpExplorer.DriveView :
- (ScpCommander.LocalPanel.DriveView || ScpCommander.RemotePanel.DriveView));
- Usage->Set(L"MinimizeToTray", MinimizeToTray);
- UnicodeString ToolbarsButtons = (Interface == ifExplorer) ? ScpExplorer.ToolbarsButtons : ScpCommander.ToolbarsButtons;
- Usage->Set(L"AnyHiddenToolbarButtons", !ToolbarsButtons.IsEmpty());
- Usage->Set(L"FileColors", !FileColors.IsEmpty());
- Usage->Set(L"DragDropDrives", !DDDrives.IsEmpty());
- Usage->Set(L"ShowingTips", ShowTips);
- Usage->Set(L"KeepingOpenWhenNoSession", KeepOpenWhenNoSession);
- Usage->Set(L"ShowingLoginWhenNoSession", ShowLoginWhenNoSession);
- TipsUpdateStaticUsage();
- Usage->Set(L"CommanderNortonLikeMode", int(ScpCommander.NortonLikeMode));
- Usage->Set(L"CommanderExplorerKeyboardShortcuts", ScpCommander.ExplorerKeyboardShortcuts);
- Usage->Set(L"ExplorerViewStyle", ScpExplorer.ViewStyle);
- Usage->Set(L"LastMonitor", LastMonitor);
- UnicodeString ExternalEditors;
- for (int Index = 0; Index < EditorList->Count; Index++)
- {
- const TEditorPreferences * Editor = EditorList->Editors[Index];
- if (Editor->Data->Editor == edExternal)
- {
- AddToList(ExternalEditors, Editor->ExtractExternalEditorName(), ",");
- }
- }
- Usage->Set(L"ExternalEditors", ExternalEditors);
- if (LastMachineInstallations < FMachineInstallations)
- {
- Usage->Inc(L"InstallationsMachine", (FMachineInstallations - LastMachineInstallations));
- LastMachineInstallations = FMachineInstallations;
- }
- int ExtensionsPortable = 0;
- int ExtensionsInstalled = 0;
- int ExtensionsUser = 0;
- for (int Index = 0; Index < FExtensionList->Count; Index++)
- {
- const TCustomCommandType * CustomCommand = FExtensionList->Commands[Index];
- UnicodeString PathId = ExcludeTrailingBackslash(ExtractFilePath(CustomCommand->Id));
- if (SameText(PathId, ExtensionsCommonPathId))
- {
- ExtensionsPortable++;
- }
- else if (SameText(PathId, ExtensionsCommonExtPathId))
- {
- ExtensionsInstalled++;
- }
- else if (SameText(PathId, ExtensionsUserExtPathId))
- {
- ExtensionsUser++;
- }
- }
- Usage->Set(L"ExtensionsPortableCount", (ExtensionsPortable));
- Usage->Set(L"ExtensionsInstalledCount", (ExtensionsInstalled));
- Usage->Set(L"ExtensionsUserCount", (ExtensionsUser));
- std::unique_ptr<TStringList> DeletedExtensions(CreateSortedStringList());
- ParseExtensionList(DeletedExtensions.get(), FExtensionsDeleted);
- Usage->Set(L"ExtensionsDeleted", (DeletedExtensions->Count));
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::RestoreFont(
- const TFontConfiguration & Configuration, TFont * Font)
- {
- Font->Name = Configuration.FontName;
- Font->Size = Configuration.FontSize;
- Font->Charset = Configuration.FontCharset;
- Font->Style = IntToFontStyles(Configuration.FontStyle);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::StoreFont(
- TFont * Font, TFontConfiguration & Configuration)
- {
- Configuration.FontName = Font->Name;
- Configuration.FontSize = Font->Size;
- Configuration.FontCharset = Font->Charset;
- Configuration.FontStyle = FontStylesToInt(Font->Style);
- }
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------
- __fastcall TCustomCommandType::TCustomCommandType() :
- FParams(0), FShortCut(0), FShortCutOriginal(0)
- {
- }
- //---------------------------------------------------------------------------
- __fastcall TCustomCommandType::TCustomCommandType(const TCustomCommandType & Other) :
- FName(Other.FName),
- FCommand(Other.FCommand),
- FParams(Other.FParams),
- FShortCut(Other.FShortCut),
- FShortCutOriginal(Other.FShortCutOriginal),
- FId(Other.FId),
- FFileName(Other.FFileName),
- FDescription(Other.FDescription),
- FHomePage(Other.FHomePage),
- FOptionsPage(Other.FOptionsPage),
- FOptions(Other.FOptions)
- {
- }
- //---------------------------------------------------------------------------
- TCustomCommandType & TCustomCommandType::operator=(const TCustomCommandType & Other)
- {
- FName = Other.FName;
- FCommand = Other.FCommand;
- FParams = Other.FParams;
- FShortCut = Other.FShortCut;
- FShortCutOriginal = Other.FShortCutOriginal;
- FId = Other.FId;
- FFileName = Other.FFileName;
- FDescription = Other.FDescription;
- FHomePage = Other.FHomePage;
- FOptionsPage = Other.FOptionsPage;
- FOptions = Other.FOptions;
- return *this;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomCommandType::Equals(const TCustomCommandType * Other) const
- {
- return
- (FName == Other->FName) &&
- (FCommand == Other->FCommand) &&
- (FParams == Other->FParams) &&
- (FShortCut == Other->FShortCut) &&
- (FShortCutOriginal == Other->FShortCutOriginal) &&
- (FId == Other->FId) &&
- (FFileName == Other->FFileName) &&
- (FDescription == Other->FDescription) &&
- (FHomePage == Other->FHomePage) &&
- (FOptionsPage == Other->FOptionsPage) &&
- (FOptions == Other->FOptions);
- }
- //---------------------------------------------------------------------------
- const UnicodeString ExtensionNameDirective(L"name");
- const UnicodeString ExtensionCommandDirective(L"command");
- const wchar_t ExtensionMark = L'@';
- const UnicodeString WinSCPExtensionExt(L".WinSCPextension");
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TCustomCommandType::GetExtensionId(const UnicodeString & Name)
- {
- UnicodeString Result;
- int P = Pos(UpperCase(WinSCPExtensionExt), UpperCase(Name));
- // Ends with Ext or there's another extension after it
- if ((P > 1) &&
- ((Name.Length() == (P + WinSCPExtensionExt.Length() - 1)) || (Name[P + WinSCPExtensionExt.Length()] == L'.')))
- {
- Result = Name.SubString(1, P - 1);
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommandType::LoadExtension(const UnicodeString & Path)
- {
- std::unique_ptr<TStringList> Lines(new TStringList());
- FileName = Path;
- LoadScriptFromFile(Path, Lines.get());
- LoadExtension(Lines.get(), Path);
- Command = ReplaceStr(Command, L"%EXTENSION_PATH%", Path);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommandType::LoadExtension(TStrings * Lines, const UnicodeString & PathForBaseName)
- {
- Params = ccLocal;
- bool AnythingFound = false;
- std::set<UnicodeString> OptionIds;
- UnicodeString ExtensionBaseName = ExtractExtensionBaseName(PathForBaseName);
- UnicodeString ExtensionLine;
- bool Break = false;
- for (int Index = 0; !Break && (Index < Lines->Count); Index++)
- {
- UnicodeString Line = Lines->Strings[Index].Trim();
- if (!Line.IsEmpty())
- {
- Line = ReplaceChar(Line, L'\t', L' ');
- bool IsComment = false;
- if (StartsText(ExtensionMark, Line))
- {
- IsComment = true;
- }
- else if (StartsText(L"rem ", Line))
- {
- IsComment = true;
- Line.Delete(1, 4);
- }
- else if (StartsText(L"#", Line) || StartsText(L";", Line) || StartsText(L"'", Line))
- {
- IsComment = true;
- Line.Delete(1, 1);
- }
- else if (StartsText(L"//", Line))
- {
- IsComment = true;
- Line.Delete(1, 2);
- }
- if (!IsComment)
- {
- Break = true;
- // ignore this and later lines, but finish processing the previous line with ^, if any
- Line = L"";
- }
- else
- {
- Line = Line.Trim();
- }
- }
- bool Continuation = (Line.Length() > 0) && (Line[Line.Length()] == L'^');
- if (Continuation)
- {
- Line = Line.SubString(1, Line.Length() - 1).Trim();
- }
- AddToList(ExtensionLine, Line, L" ");
- if (!Continuation)
- {
- int P;
- if (!ExtensionLine.IsEmpty() && (ExtensionLine[1] == ExtensionMark) && ((P = Pos(L" ", ExtensionLine)) >= 2))
- {
- UnicodeString Key = ExtensionLine.SubString(2, P - 2).LowerCase();
- UnicodeString Directive = UnicodeString(ExtensionMark) + Key;
- UnicodeString Value = ExtensionLine.SubString(P + 1, ExtensionLine.Length() - P).Trim();
- bool KnownKey = true;
- if (Key == ExtensionNameDirective)
- {
- Name = WinConfiguration->ExtensionStringTranslation(Id, Value);
- }
- else if (Key == ExtensionCommandDirective)
- {
- Command = Value;
- }
- else if (Key == L"require")
- {
- UnicodeString DependencyVersion = Value;
- UnicodeString Dependency = CutToChar(Value, L' ', true).LowerCase();
- Value = Value.Trim();
- bool Failed;
- if (Dependency == L"winscp")
- {
- int Version = StrToCompoundVersion(Value);
- Failed = (Version > WinConfiguration->CompoundVersion);
- }
- else if (Dependency == L".net")
- {
- Failed = (CompareVersion(Value, GetNetVersionStr()) > 0);
- }
- else if (Dependency == L"powershell")
- {
- Failed = (CompareVersion(Value, GetPowerShellVersionStr()) > 0);
- }
- else if (Dependency == L"windows")
- {
- Failed = (CompareVersion(Value, WindowsVersion()) > 0);
- }
- else
- {
- Failed = true;
- }
- if (Failed)
- {
- throw Exception(MainInstructions(FMTLOAD(EXTENSION_DEPENDENCY_ERROR, (DependencyVersion))));
- }
- }
- else if (Key == L"side")
- {
- if (SameText(Value, L"Local"))
- {
- Params |= ccLocal;
- }
- else if (SameText(Value, L"Remote"))
- {
- Params &= ~ccLocal;
- }
- else
- {
- throw Exception(MainInstructions(FMTLOAD(EXTENSION_DIRECTIVE_ERROR, (Value, Directive))));
- }
- }
- else if (Key == L"flag")
- {
- if (SameText(Value, L"ApplyToDirectories"))
- {
- Params |= ccApplyToDirectories;
- }
- else if (SameText(Value, L"Recursive"))
- {
- Params |= ccRecursive;
- }
- else if (SameText(Value, L"ShowResults"))
- {
- Params |= ccShowResults;
- }
- else if (SameText(Value, L"CopyResults"))
- {
- Params |= ccCopyResults;
- }
- else if (SameText(Value, L"RemoteFiles"))
- {
- Params |= ccRemoteFiles;
- }
- else if (SameText(Value, L"ShowResultsInMsgBox"))
- {
- Params |= ccShowResultsInMsgBox;
- }
- else
- {
- throw Exception(MainInstructions(FMTLOAD(EXTENSION_DIRECTIVE_ERROR, (Value, Directive))));
- }
- }
- else if (Key == L"shortcut")
- {
- TShortCut AShortCut = TextToShortCut(Value);
- if (IsCustomShortCut(AShortCut))
- {
- ShortCut = AShortCut;
- FShortCutOriginal = AShortCut;
- }
- else
- {
- throw Exception(MainInstructions(FMTLOAD(EXTENSION_DIRECTIVE_ERROR, (Value, Directive))));
- }
- }
- else if (Key == L"option")
- {
- TOption Option;
- if (!ParseOption(Value, Option, ExtensionBaseName) ||
- (Option.IsControl && (OptionIds.find(Option.Id.LowerCase()) != OptionIds.end())))
- {
- throw Exception(MainInstructions(FMTLOAD(EXTENSION_DIRECTIVE_ERROR, (Value, Directive))));
- }
- else
- {
- FOptions.push_back(Option);
- if (!Option.IsControl)
- {
- OptionIds.insert(Option.Id.LowerCase());
- }
- }
- }
- else if (Key == L"description")
- {
- Description = WinConfiguration->ExtensionStringTranslation(Id, Value);
- }
- else if (Key == L"author")
- {
- // noop
- }
- else if (Key == L"version")
- {
- // noop
- }
- else if (Key == L"homepage")
- {
- HomePage = Value;
- }
- else if (Key == L"optionspage")
- {
- OptionsPage = Value;
- }
- else if (Key == L"source")
- {
- // noop
- }
- else
- {
- KnownKey = false;
- }
- if (KnownKey)
- {
- AnythingFound = true;
- }
- }
- ExtensionLine = L"";
- }
- }
- if (!AnythingFound)
- {
- throw Exception(MainInstructions(LoadStr(EXTENSION_NOT_FOUND)));
- }
- if (Name.IsEmpty())
- {
- throw Exception(MainInstructions(FMTLOAD(EXTENSION_DIRECTIVE_MISSING, (UnicodeString(ExtensionMark) + ExtensionNameDirective))));
- }
- if (Command.IsEmpty())
- {
- throw Exception(MainInstructions(FMTLOAD(EXTENSION_DIRECTIVE_MISSING, (UnicodeString(ExtensionMark) + ExtensionCommandDirective))));
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomCommandType::ParseOption(const UnicodeString & Value, TOption & Option, const UnicodeString & ExtensionBaseName)
- {
- UnicodeString Buf = Value;
- UnicodeString KindName;
- bool Result = CutTokenEx(Buf, Option.Id);
- if (Result)
- {
- Option.Flags = 0;
- UnicodeString FlagName;
- while (CutTokenEx(Buf, FlagName) && (FlagName.SubString(1, 1) == L"-"))
- {
- FlagName = FlagName.LowerCase();
- if (FlagName == L"-run")
- {
- Option.Flags |= ofRun;
- }
- else if (FlagName == L"-config")
- {
- Option.Flags |= ofConfig;
- }
- else if (FlagName == L"-site")
- {
- Option.Flags |= ofSite;
- }
- else
- {
- Result = false;
- }
- }
- if ((Option.Flags & (ofRun | ofConfig)) == 0)
- {
- Option.Flags |= ofConfig;
- }
- KindName = FlagName;
- if (Result)
- {
- UnicodeString DefaultCaption;
- UnicodeString DefaultDefault;
- TOption::TParams DefaultParams;
- KindName = KindName.LowerCase();
- if (KindName == L"label")
- {
- Option.Kind = okLabel;
- Result = !Option.IsControl;
- }
- else if (KindName == L"link")
- {
- Option.Kind = okLink;
- Result = !Option.IsControl;
- }
- else if (KindName == L"separator")
- {
- Option.Kind = okSeparator;
- Result = !Option.IsControl;
- }
- else if (KindName == L"group")
- {
- Option.Kind = okGroup;
- Result = !Option.IsControl;
- }
- else if (KindName == L"textbox")
- {
- Option.Kind = okTextBox;
- Result = Option.IsControl;
- }
- else if (KindName == L"file")
- {
- Option.Kind = okFile;
- Result = Option.IsControl;
- }
- else if (KindName == L"sessionlogfile")
- {
- Option.Kind = okFile;
- Result = Option.IsControl;
- DefaultCaption = LoadStr(EXTENSION_SESSIONLOG_FILE);
- Option.FileCaption = LoadStr(EXTENSION_SESSIONLOG_CAPTION);
- Option.FileFilter = LoadStr(EXTENSION_SESSIONLOG_FILTER);
- // Similar to TConfiguration::GetDefaultLogFileName
- Option.FileInitial = L"%TEMP%\\" + ExtensionBaseName + L".log";
- Option.FileExt = L"log";
- }
- else if (KindName == L"dropdownlist")
- {
- Option.Kind = okDropDownList;
- Result = Option.IsControl;
- }
- else if (KindName == L"combobox")
- {
- Option.Kind = okComboBox;
- Result = Option.IsControl;
- }
- else if (KindName == L"checkbox")
- {
- Option.Kind = okCheckBox;
- Result = Option.IsControl;
- }
- else if (KindName == L"pausecheckbox")
- {
- Option.Kind = okCheckBox;
- Result = Option.IsControl;
- DefaultCaption = LoadStr(EXTENSION_PAUSE_CHECKBOX);
- DefaultDefault = L"-pause";
- DefaultParams.push_back(L"-pause");
- }
- else
- {
- Option.Kind = okUnknown;
- }
- if ((Option.Kind != okUnknown) &&
- (Option.Kind != okSeparator))
- {
- Result =
- CutTokenEx(Buf, Option.Caption);
- if (!Result && !DefaultCaption.IsEmpty())
- {
- Option.Caption = DefaultCaption;
- Result = true;
- }
- if (Result)
- {
- Option.Caption = WinConfiguration->ExtensionStringTranslation(Id, Option.Caption);
- if (CutTokenEx(Buf, Option.Default))
- {
- UnicodeString Param;
- while (CutTokenEx(Buf, Param))
- {
- Option.Params.push_back(Param);
- }
- }
- else
- {
- Option.Default = DefaultDefault;
- }
- if (Option.Params.size() == 0)
- {
- Option.Params = DefaultParams;
- }
- }
- }
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- int __fastcall TCustomCommandType::GetOptionsCount() const
- {
- return FOptions.size();
- }
- //---------------------------------------------------------------------------
- const TCustomCommandType::TOption & __fastcall TCustomCommandType::GetOption(int Index) const
- {
- return FOptions[Index];
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TCustomCommandType::GetOptionKey(
- const TCustomCommandType::TOption & Option, const UnicodeString & Site) const
- {
- UnicodeString Result = Id + L"\\" + Option.Id;
- if (FLAGSET(Option.Flags, ofSite))
- {
- Result += L"\\" + Site;
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomCommandType::AnyOptionWithFlag(unsigned int Flag) const
- {
- bool Result = false;
- for (int Index = 0; !Result && (Index < OptionsCount); Index++)
- {
- const TCustomCommandType::TOption & Option = GetOption(Index);
- Result = FLAGSET(Option.Flags, Flag);
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TCustomCommandType::GetCommandWithExpandedOptions(
- TStrings * CustomCommandOptions, const UnicodeString & Site) const
- {
- UnicodeString Result = Command;
- for (int Index = 0; Index < OptionsCount; Index++)
- {
- const TCustomCommandType::TOption & Option = GetOption(Index);
- if (Option.IsControl)
- {
- UnicodeString OptionKey = GetOptionKey(Option, Site);
- UnicodeString OptionValue;
- if (CustomCommandOptions->IndexOfName(OptionKey) >= 0)
- {
- OptionValue = CustomCommandOptions->Values[OptionKey];
- }
- else
- {
- OptionValue = Option.Default;
- }
- UnicodeString OptionCommand = GetOptionCommand(Option, OptionValue);
- OptionCommand = TCustomCommand::Escape(OptionCommand);
- Result = ReplaceText(Result, FORMAT(L"%%%s%%", (Option.Id)), OptionCommand);
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TCustomCommandType::GetOptionCommand(const TOption & Option, const UnicodeString & Value) const
- {
- UnicodeString Result = Value;
- switch (Option.Kind)
- {
- case okUnknown:
- case okTextBox:
- case okDropDownList:
- case okComboBox:
- case okCheckBox:
- // noop
- break;
- case okFile:
- Result = ExpandEnvironmentVariables(Result);
- break;
- case okLabel:
- case okLink:
- case okSeparator:
- case okGroup:
- default:
- DebugFail();
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomCommandType::HasCustomShortCut() const
- {
- return (ShortCut != FShortCutOriginal);
- }
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------
- bool __fastcall TCustomCommandType::TOption::GetIsControl() const
- {
- return (Id != L"-");
- }
- //---------------------------------------------------------------------------
- bool TCustomCommandType::TOption::HasPatterns(TCustomCommand * CustomCommandForOptions) const
- {
- bool CanHavePatterns;
- switch (Kind)
- {
- case okTextBox:
- case okFile:
- CanHavePatterns = true;
- break;
- default:
- CanHavePatterns = false;
- break;
- }
- bool Result =
- CanHavePatterns &&
- FLAGSET(Flags, TCustomCommandType::ofRun) &&
- FLAGCLEAR(Flags, TCustomCommandType::ofConfig) &&
- CustomCommandForOptions->HasAnyPatterns(Default);
- return Result;
- }
- //---------------------------------------------------------------------------
- bool TCustomCommandType::TOption::operator==(const TCustomCommandType::TOption & Other) const
- {
- // needed by vector<> but probably never used
- return
- (Id == Other.Id) &&
- (Flags == Other.Flags) &&
- (Kind == Other.Kind) &&
- (Caption == Other.Caption) &&
- (Default == Other.Default) &&
- (Params == Other.Params) &&
- (FileCaption == Other.FileCaption) &&
- (FileFilter == Other.FileFilter) &&
- (FileInitial == Other.FileInitial) &&
- (FileExt == Other.FileExt);
- }
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------
- __fastcall TCustomCommandList::TCustomCommandList()
- {
- FCommands = new TList();
- FModified = false;
- }
- //---------------------------------------------------------------------------
- __fastcall TCustomCommandList::~TCustomCommandList()
- {
- Clear();
- delete FCommands;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommandList::Reset()
- {
- FModified = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommandList::Modify()
- {
- FModified = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommandList::Load(THierarchicalStorage * Storage)
- {
- Clear();
- if (Storage->OpenSubKey(L"CustomCommands", false))
- {
- TStrings * Names = new TStringList();
- try
- {
- Storage->ReadValues(Names, true);
- for (int Index = 0; Index < Names->Count; Index++)
- {
- TCustomCommandType * Command = new TCustomCommandType();
- Command->Name = Names->Names[Index];
- Command->Command = Names->Values[Names->Names[Index]];
- FCommands->Add(Command);
- }
- Storage->CloseSubKey();
- }
- __finally
- {
- delete Names;
- }
- }
- if (Storage->OpenSubKey(L"CustomCommandsParams", false))
- {
- for (int Index = 0; Index < FCommands->Count; Index++)
- {
- TCustomCommandType * Command = GetCommand(Index);
- Command->Params = Storage->ReadInteger(Command->Name, Command->Params);
- }
- Storage->CloseSubKey();
- }
- if (Storage->OpenSubKey(L"CustomCommandsShortCuts", false))
- {
- for (int Index = 0; Index < FCommands->Count; Index++)
- {
- TCustomCommandType * Command = GetCommand(Index);
- Command->ShortCut = (Word)Storage->ReadInteger(Command->Name, Command->ShortCut);
- }
- Storage->CloseSubKey();
- }
- Reset();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommandList::Save(THierarchicalStorage * Storage)
- {
- if (Storage->OpenSubKey(L"CustomCommands", true))
- {
- Storage->ClearValues();
- for (int Index = 0; Index < FCommands->Count; Index++)
- {
- const TCustomCommandType * Command = Commands[Index];
- Storage->WriteString(Command->Name, Command->Command);
- }
- Storage->CloseSubKey();
- }
- if (Storage->OpenSubKey(L"CustomCommandsParams", true))
- {
- Storage->ClearValues();
- for (int Index = 0; Index < FCommands->Count; Index++)
- {
- const TCustomCommandType * Command = Commands[Index];
- Storage->WriteInteger(Command->Name, Command->Params);
- }
- Storage->CloseSubKey();
- }
- if (Storage->OpenSubKey(L"CustomCommandsShortCuts", true))
- {
- Storage->ClearValues();
- for (int Index = 0; Index < FCommands->Count; Index++)
- {
- const TCustomCommandType * Command = Commands[Index];
- if (Command->ShortCut != 0)
- {
- Storage->WriteInteger(Command->Name, Command->ShortCut);
- }
- }
- Storage->CloseSubKey();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommandList::Clear()
- {
- for (int Index = 0; Index < FCommands->Count; Index++)
- {
- delete Commands[Index];
- }
- FCommands->Clear();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommandList::Add(const UnicodeString Name,
- const UnicodeString ACommand, int Params)
- {
- TCustomCommandType * Command = new TCustomCommandType();
- Command->Name = Name;
- Command->Command = ACommand;
- Command->Params = Params;
- Add(Command);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommandList::Add(TCustomCommandType * Command)
- {
- Insert(Count, Command);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommandList::Insert(int Index, TCustomCommandType * Command)
- {
- FCommands->Insert(Index, Command);
- Modify();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommandList::Change(int Index, TCustomCommandType * ACommand)
- {
- TCustomCommandType * Command = GetCommand(Index);
- if (!Command->Equals(ACommand))
- {
- delete Command;
- FCommands->Items[Index] = ACommand;
- Modify();
- }
- else
- {
- delete ACommand;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommandList::Move(int CurIndex, int NewIndex)
- {
- if (CurIndex != NewIndex)
- {
- FCommands->Move(CurIndex, NewIndex);
- Modify();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommandList::Delete(int Index)
- {
- DebugAssert((Index >= 0) && (Index < Count));
- delete GetCommand(Index);
- FCommands->Delete(Index);
- Modify();
- }
- //---------------------------------------------------------------------------
- class TCustomCommandCompareFunc : public TCppInterfacedObject<TListSortCompareFunc>
- {
- public:
- TCustomCommandCompareFunc(TStrings * Ids)
- {
- FIds = Ids;
- }
- virtual int __fastcall Invoke(void * Item1, void * Item2)
- {
- TCustomCommandType * CustomCommand1 = static_cast<TCustomCommandType *>(Item1);
- TCustomCommandType * CustomCommand2 = static_cast<TCustomCommandType *>(Item2);
- int Index1 = FIds->IndexOf(CustomCommand1->Id);
- int Index2 = FIds->IndexOf(CustomCommand2->Id);
- int Result;
- // new items to the end
- if ((Index1 < 0) && (Index2 >= 0))
- {
- Result = 1;
- }
- else if ((Index2 < 0) && (Index1 >= 0))
- {
- Result = -1;
- }
- // fallback to comparing by name
- else if ((Index1 < 0) && (Index2 < 0))
- {
- Result = TComparer__1<UnicodeString>::Default()->Compare(CustomCommand1->Name, CustomCommand2->Name);
- }
- else
- {
- Result = TComparer__1<int>::Default()->Compare(Index1, Index2);
- }
- return Result;
- }
- private:
- TStrings * FIds;
- };
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommandList::SortBy(TStrings * Ids)
- {
- TCustomCommandCompareFunc * Func = new TCustomCommandCompareFunc(Ids);
- FCommands->SortList(Func);
- }
- //---------------------------------------------------------------------------
- int __fastcall TCustomCommandList::GetCount() const
- {
- return FCommands->Count;
- }
- //---------------------------------------------------------------------------
- const TCustomCommandType * __fastcall TCustomCommandList::GetConstCommand(int Index) const
- {
- return static_cast<TCustomCommandType *>(FCommands->Items[Index]);
- }
- //---------------------------------------------------------------------------
- TCustomCommandType * __fastcall TCustomCommandList::GetCommand(int Index)
- {
- return static_cast<TCustomCommandType *>(FCommands->Items[Index]);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomCommandList::Equals(const TCustomCommandList * Other) const
- {
- bool Result = (Count == Other->Count);
- for (int Index = 0; Result && (Index < Count); Index++)
- {
- Result = Commands[Index]->Equals(Other->Commands[Index]);
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommandList::Assign(const TCustomCommandList * Other)
- {
- Clear();
- for (int Index = 0; Index < Other->Count; Index++)
- {
- Add(new TCustomCommandType(*Other->Commands[Index]));
- }
- // there should be comparison of with the assigned list, be we rely on caller
- // to do it instead (TGUIConfiguration::SetCopyParamList)
- Modify();
- }
- //---------------------------------------------------------------------------
- const TCustomCommandType * TCustomCommandList::Find(const UnicodeString Name) const
- {
- for (int Index = 0; Index < FCommands->Count; Index++)
- {
- if (Commands[Index]->Name == Name)
- {
- return Commands[Index];
- }
- }
- return NULL;
- }
- //---------------------------------------------------------------------------
- const TCustomCommandType * TCustomCommandList::Find(TShortCut ShortCut) const
- {
- for (int Index = 0; Index < FCommands->Count; Index++)
- {
- if (Commands[Index]->ShortCut == ShortCut)
- {
- return Commands[Index];
- }
- }
- return NULL;
- }
- //---------------------------------------------------------------------------
- int TCustomCommandList::FindIndexByFileName(const UnicodeString & FileName) const
- {
- for (int Index = 0; Index < FCommands->Count; Index++)
- {
- if (IsPathToSameFile(Commands[Index]->FileName, FileName))
- {
- return Index;
- }
- }
- return -1;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommandList::ShortCuts(TShortCuts & ShortCuts) const
- {
- for (int Index = 0; Index < FCommands->Count; Index++)
- {
- const TCustomCommandType * Command = Commands[Index];
- if (Command->ShortCut != 0)
- {
- ShortCuts.Add(Command->ShortCut);
- }
- }
- }
|